1 | /*
|
---|
2 | * Copyright (c) 2017 Ondrej Hlavaty
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup drvusbxhci
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | * @brief The host controller data bookkeeping.
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef XHCI_HC_H
|
---|
37 | #define XHCI_HC_H
|
---|
38 |
|
---|
39 | #include <usb/host/usb_transfer_batch.h>
|
---|
40 | #include "hw_struct/regs.h"
|
---|
41 | #include "hw_struct/context.h"
|
---|
42 | #include "scratchpad.h"
|
---|
43 | #include "trb_ring.h"
|
---|
44 | #include "rh.h"
|
---|
45 |
|
---|
46 | typedef struct xhci_virt_device_ctx {
|
---|
47 | xhci_device_ctx_t *dev_ctx;
|
---|
48 | xhci_trb_ring_t *trs[XHCI_EP_COUNT];
|
---|
49 | } xhci_virt_device_ctx_t;
|
---|
50 |
|
---|
51 | /**
|
---|
52 | * xHCI lets the controller define speeds of ports it controls.
|
---|
53 | */
|
---|
54 | typedef struct xhci_port_speed {
|
---|
55 | uint64_t rx_bps, tx_bps;
|
---|
56 | } xhci_port_speed_t;
|
---|
57 |
|
---|
58 | typedef struct xhci_hc {
|
---|
59 | /* MMIO range */
|
---|
60 | addr_range_t mmio_range;
|
---|
61 | void *base;
|
---|
62 |
|
---|
63 | /* Mapped register sets */
|
---|
64 | xhci_cap_regs_t *cap_regs;
|
---|
65 | xhci_op_regs_t *op_regs;
|
---|
66 | xhci_rt_regs_t *rt_regs;
|
---|
67 | xhci_doorbell_t *db_arry;
|
---|
68 | xhci_extcap_t *xecp; /**< First extended capability */
|
---|
69 | xhci_legsup_t *legsup; /**< Legacy support capability */
|
---|
70 |
|
---|
71 | /* Structures in allocated memory */
|
---|
72 | xhci_trb_ring_t command_ring;
|
---|
73 | xhci_event_ring_t event_ring;
|
---|
74 | uint64_t *dcbaa;
|
---|
75 | xhci_virt_device_ctx_t **dcbaa_virt;
|
---|
76 | xhci_scratchpad_t *scratchpad;
|
---|
77 |
|
---|
78 | /* Root hub emulation */
|
---|
79 | xhci_rh_t rh;
|
---|
80 |
|
---|
81 | /* Cached capabilities */
|
---|
82 | xhci_port_speed_t speeds [16];
|
---|
83 | unsigned max_slots;
|
---|
84 | bool ac64;
|
---|
85 |
|
---|
86 | /* Command list */
|
---|
87 | list_t commands;
|
---|
88 | } xhci_hc_t;
|
---|
89 |
|
---|
90 | int hc_init_mmio(xhci_hc_t *, const hw_res_list_parsed_t *);
|
---|
91 | int hc_init_memory(xhci_hc_t *);
|
---|
92 | int hc_claim(xhci_hc_t *, ddf_dev_t *);
|
---|
93 | int hc_irq_code_gen(irq_code_t *, xhci_hc_t *, const hw_res_list_parsed_t *);
|
---|
94 | int hc_start(xhci_hc_t *, bool);
|
---|
95 | int hc_schedule(xhci_hc_t *hc, usb_transfer_batch_t *batch);
|
---|
96 | int hc_status(xhci_hc_t *, uint32_t *);
|
---|
97 | void hc_interrupt(xhci_hc_t *, uint32_t);
|
---|
98 | void hc_fini(xhci_hc_t *);
|
---|
99 |
|
---|
100 | #endif
|
---|
101 |
|
---|
102 | /**
|
---|
103 | * @}
|
---|
104 | */
|
---|