1 | /*
|
---|
2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
3 | * Copyright (c) 2011 Jan Vesely
|
---|
4 | * Copyright (c) 2018 Ondrej Hlavaty
|
---|
5 | * All rights reserved.
|
---|
6 | *
|
---|
7 | * Redistribution and use in source and binary forms, with or without
|
---|
8 | * modification, are permitted provided that the following conditions
|
---|
9 | * are met:
|
---|
10 | *
|
---|
11 | * - Redistributions of source code must retain the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer.
|
---|
13 | * - Redistributions in binary form must reproduce the above copyright
|
---|
14 | * notice, this list of conditions and the following disclaimer in the
|
---|
15 | * documentation and/or other materials provided with the distribution.
|
---|
16 | * - The name of the author may not be used to endorse or promote products
|
---|
17 | * derived from this software without specific prior written permission.
|
---|
18 | *
|
---|
19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
29 | */
|
---|
30 |
|
---|
31 | /** @addtogroup drvusbuhci
|
---|
32 | * @{
|
---|
33 | */
|
---|
34 | /** @file
|
---|
35 | * @brief UHCI host controller driver structure
|
---|
36 | */
|
---|
37 |
|
---|
38 | #ifndef DRV_UHCI_HC_H
|
---|
39 | #define DRV_UHCI_HC_H
|
---|
40 |
|
---|
41 | #include <device/hw_res_parsed.h>
|
---|
42 | #include <fibril.h>
|
---|
43 | #include <macros.h>
|
---|
44 | #include <member.h>
|
---|
45 | #include <stdbool.h>
|
---|
46 | #include <ddi.h>
|
---|
47 | #include <usb/host/hcd.h>
|
---|
48 | #include <usb/host/usb2_bus.h>
|
---|
49 | #include <usb/host/usb_transfer_batch.h>
|
---|
50 |
|
---|
51 | #include "uhci_rh.h"
|
---|
52 | #include "transfer_list.h"
|
---|
53 | #include "hw_struct/link_pointer.h"
|
---|
54 |
|
---|
55 | /** UHCI I/O registers layout */
|
---|
56 | typedef struct uhci_regs {
|
---|
57 | /** Command register, controls HC behaviour */
|
---|
58 | ioport16_t usbcmd;
|
---|
59 | #define UHCI_CMD_MAX_PACKET (1 << 7)
|
---|
60 | #define UHCI_CMD_CONFIGURE (1 << 6)
|
---|
61 | #define UHCI_CMD_DEBUG (1 << 5)
|
---|
62 | #define UHCI_CMD_FORCE_GLOBAL_RESUME (1 << 4)
|
---|
63 | #define UHCI_CMD_FORCE_GLOBAL_SUSPEND (1 << 3)
|
---|
64 | #define UHCI_CMD_GLOBAL_RESET (1 << 2)
|
---|
65 | #define UHCI_CMD_HCRESET (1 << 1)
|
---|
66 | #define UHCI_CMD_RUN_STOP (1 << 0)
|
---|
67 |
|
---|
68 | /** Status register, 1 means interrupt is asserted (if enabled) */
|
---|
69 | ioport16_t usbsts;
|
---|
70 | #define UHCI_STATUS_HALTED (1 << 5)
|
---|
71 | #define UHCI_STATUS_PROCESS_ERROR (1 << 4)
|
---|
72 | #define UHCI_STATUS_SYSTEM_ERROR (1 << 3)
|
---|
73 | #define UHCI_STATUS_RESUME (1 << 2)
|
---|
74 | #define UHCI_STATUS_ERROR_INTERRUPT (1 << 1)
|
---|
75 | #define UHCI_STATUS_INTERRUPT (1 << 0)
|
---|
76 | #define UHCI_STATUS_NM_INTERRUPTS \
|
---|
77 | (UHCI_STATUS_PROCESS_ERROR | UHCI_STATUS_SYSTEM_ERROR)
|
---|
78 |
|
---|
79 | /** Interrupt enabled registers */
|
---|
80 | ioport16_t usbintr;
|
---|
81 | #define UHCI_INTR_SHORT_PACKET (1 << 3)
|
---|
82 | #define UHCI_INTR_COMPLETE (1 << 2)
|
---|
83 | #define UHCI_INTR_RESUME (1 << 1)
|
---|
84 | #define UHCI_INTR_CRC (1 << 0)
|
---|
85 |
|
---|
86 | /** Register stores frame number used in SOF packet */
|
---|
87 | ioport16_t frnum;
|
---|
88 |
|
---|
89 | /** Pointer(physical) to the Frame List */
|
---|
90 | ioport32_t flbaseadd;
|
---|
91 |
|
---|
92 | /** SOF modification to match external timers */
|
---|
93 | ioport8_t sofmod;
|
---|
94 |
|
---|
95 | PADD8(3);
|
---|
96 | ioport16_t ports[];
|
---|
97 | } uhci_regs_t;
|
---|
98 |
|
---|
99 | #define UHCI_FRAME_LIST_COUNT 1024
|
---|
100 | #define UHCI_DEBUGER_TIMEOUT 5000000
|
---|
101 | #define UHCI_ALLOWED_HW_FAIL 5
|
---|
102 |
|
---|
103 | /** Main UHCI driver structure */
|
---|
104 | typedef struct hc {
|
---|
105 | /* Common hc_device header */
|
---|
106 | hc_device_t base;
|
---|
107 |
|
---|
108 | uhci_rh_t rh;
|
---|
109 | bus_t bus;
|
---|
110 | usb2_bus_helper_t bus_helper;
|
---|
111 |
|
---|
112 | /** Addresses of I/O registers */
|
---|
113 | uhci_regs_t *registers;
|
---|
114 |
|
---|
115 | /** Frame List contains 1024 link pointers */
|
---|
116 | link_pointer_t *frame_list;
|
---|
117 |
|
---|
118 | /** List and queue of interrupt transfers */
|
---|
119 | transfer_list_t transfers_interrupt;
|
---|
120 | /** List and queue of low speed control transfers */
|
---|
121 | transfer_list_t transfers_control_slow;
|
---|
122 | /** List and queue of full speed bulk transfers */
|
---|
123 | transfer_list_t transfers_bulk_full;
|
---|
124 | /** List and queue of full speed control transfers */
|
---|
125 | transfer_list_t transfers_control_full;
|
---|
126 |
|
---|
127 | /** Pointer table to the above lists, helps during scheduling */
|
---|
128 | transfer_list_t *transfers[2][4];
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * Guard for the pending list. Can be locked under EP guard, but not
|
---|
132 | * vice versa.
|
---|
133 | */
|
---|
134 | fibril_mutex_t guard;
|
---|
135 | /** List of endpoints with a transfer scheduled */
|
---|
136 | list_t pending_endpoints;
|
---|
137 |
|
---|
138 | /** Number of hw failures detected. */
|
---|
139 | unsigned hw_failures;
|
---|
140 | } hc_t;
|
---|
141 |
|
---|
142 | typedef struct uhci_endpoint {
|
---|
143 | endpoint_t base;
|
---|
144 |
|
---|
145 | bool toggle;
|
---|
146 | } uhci_endpoint_t;
|
---|
147 |
|
---|
148 | static inline hc_t *hcd_to_hc(hc_device_t *hcd)
|
---|
149 | {
|
---|
150 | assert(hcd);
|
---|
151 | return (hc_t *) hcd;
|
---|
152 | }
|
---|
153 |
|
---|
154 | static inline hc_t *bus_to_hc(bus_t *bus)
|
---|
155 | {
|
---|
156 | assert(bus);
|
---|
157 | return member_to_inst(bus, hc_t, bus);
|
---|
158 | }
|
---|
159 |
|
---|
160 | int hc_unschedule_batch(usb_transfer_batch_t *);
|
---|
161 |
|
---|
162 | extern errno_t hc_add(hc_device_t *, const hw_res_list_parsed_t *);
|
---|
163 | extern errno_t hc_gen_irq_code(irq_code_t *, hc_device_t *, const hw_res_list_parsed_t *, int *);
|
---|
164 | extern errno_t hc_start(hc_device_t *);
|
---|
165 | extern errno_t hc_setup_roothub(hc_device_t *);
|
---|
166 | extern errno_t hc_gone(hc_device_t *);
|
---|
167 | extern errno_t hc_quiesce(hc_device_t *);
|
---|
168 |
|
---|
169 | #endif
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * @}
|
---|
173 | */
|
---|