FreeBSD kernel usb device Code
uhci.h
Go to the documentation of this file.
1/* $FreeBSD$ */
2/*-
3 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 *
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
34#ifndef _UHCI_H_
35#define _UHCI_H_
37#define UHCI_MAX_DEVICES MIN(USB_MAX_DEVICES, 128)
38
39#define UHCI_FRAMELIST_COUNT 1024 /* units */
40#define UHCI_FRAMELIST_ALIGN 4096 /* bytes */
42/* Structures alignment (bytes) */
43#define UHCI_TD_ALIGN 16
44#define UHCI_QH_ALIGN 16
46#if ((USB_PAGE_SIZE < UHCI_TD_ALIGN) || (UHCI_TD_ALIGN == 0) || \
47 (USB_PAGE_SIZE < UHCI_QH_ALIGN) || (UHCI_QH_ALIGN == 0))
48#error "Invalid USB page size!"
49#endif
50
51typedef uint32_t uhci_physaddr_t;
52
53#define UHCI_PTR_T 0x00000001
54#define UHCI_PTR_TD 0x00000000
55#define UHCI_PTR_QH 0x00000002
56#define UHCI_PTR_VF 0x00000004
57
58/*
59 * The Queue Heads (QH) and Transfer Descriptors (TD) are accessed by
60 * both the CPU and the USB-controller which run concurrently. Great
61 * care must be taken. When the data-structures are linked into the
62 * USB controller's frame list, the USB-controller "owns" the
63 * td_status and qh_elink fields, which will not be written by the
64 * CPU.
65 *
66 */
67
68struct uhci_td {
69/*
70 * Data used by the UHCI controller.
71 * volatile is used in order to mantain struct members ordering.
72 */
73 volatile uint32_t td_next;
74 volatile uint32_t td_status;
75#define UHCI_TD_GET_ACTLEN(s) (((s) + 1) & 0x3ff)
76#define UHCI_TD_ZERO_ACTLEN(t) ((t) | 0x3ff)
77#define UHCI_TD_BITSTUFF 0x00020000
78#define UHCI_TD_CRCTO 0x00040000
79#define UHCI_TD_NAK 0x00080000
80#define UHCI_TD_BABBLE 0x00100000
81#define UHCI_TD_DBUFFER 0x00200000
82#define UHCI_TD_STALLED 0x00400000
83#define UHCI_TD_ACTIVE 0x00800000
84#define UHCI_TD_IOC 0x01000000
85#define UHCI_TD_IOS 0x02000000
86#define UHCI_TD_LS 0x04000000
87#define UHCI_TD_GET_ERRCNT(s) (((s) >> 27) & 3)
88#define UHCI_TD_SET_ERRCNT(n) ((n) << 27)
89#define UHCI_TD_SPD 0x20000000
90 volatile uint32_t td_token;
91#define UHCI_TD_PID 0x000000ff
92#define UHCI_TD_PID_IN 0x00000069
93#define UHCI_TD_PID_OUT 0x000000e1
94#define UHCI_TD_PID_SETUP 0x0000002d
95#define UHCI_TD_GET_PID(s) ((s) & 0xff)
96#define UHCI_TD_SET_DEVADDR(a) ((a) << 8)
97#define UHCI_TD_GET_DEVADDR(s) (((s) >> 8) & 0x7f)
98#define UHCI_TD_SET_ENDPT(e) (((e) & 0xf) << 15)
99#define UHCI_TD_GET_ENDPT(s) (((s) >> 15) & 0xf)
100#define UHCI_TD_SET_DT(t) ((t) << 19)
101#define UHCI_TD_GET_DT(s) (((s) >> 19) & 1)
102#define UHCI_TD_SET_MAXLEN(l) (((l)-1U) << 21)
103#define UHCI_TD_GET_MAXLEN(s) ((((s) >> 21) + 1) & 0x7ff)
104#define UHCI_TD_MAXLEN_MASK 0xffe00000
105 volatile uint32_t td_buffer;
106/*
107 * Extra information needed:
108 */
109 struct uhci_td *next;
110 struct uhci_td *prev;
114 uint32_t td_self;
115 uint16_t len;
117
118typedef struct uhci_td uhci_td_t;
119
120#define UHCI_TD_ERROR (UHCI_TD_BITSTUFF | UHCI_TD_CRCTO | \
121 UHCI_TD_BABBLE | UHCI_TD_DBUFFER | UHCI_TD_STALLED)
122
123#define UHCI_TD_SETUP(len, endp, dev) (UHCI_TD_SET_MAXLEN(len) | \
124 UHCI_TD_SET_ENDPT(endp) | \
125 UHCI_TD_SET_DEVADDR(dev) | \
126 UHCI_TD_PID_SETUP)
127
128#define UHCI_TD_OUT(len, endp, dev, dt) (UHCI_TD_SET_MAXLEN(len) | \
129 UHCI_TD_SET_ENDPT(endp) | \
130 UHCI_TD_SET_DEVADDR(dev) | \
131 UHCI_TD_PID_OUT | UHCI_TD_SET_DT(dt))
132
133#define UHCI_TD_IN(len, endp, dev, dt) (UHCI_TD_SET_MAXLEN(len) | \
134 UHCI_TD_SET_ENDPT(endp) | \
135 UHCI_TD_SET_DEVADDR(dev) | \
136 UHCI_TD_PID_IN | UHCI_TD_SET_DT(dt))
137
138struct uhci_qh {
139/*
140 * Data used by the UHCI controller.
141 */
142 volatile uint32_t qh_h_next;
143 volatile uint32_t qh_e_next;
144/*
145 * Extra information needed:
146 */
152 uint32_t qh_self;
153 uint16_t intr_pos;
155
156typedef struct uhci_qh uhci_qh_t;
157
158/* Maximum number of isochronous TD's and QH's interrupt */
159#define UHCI_VFRAMELIST_COUNT 128
160#define UHCI_IFRAMELIST_COUNT (2 * UHCI_VFRAMELIST_COUNT)
161
162#if (((UHCI_VFRAMELIST_COUNT & (UHCI_VFRAMELIST_COUNT-1)) != 0) || \
163 (UHCI_VFRAMELIST_COUNT > UHCI_FRAMELIST_COUNT))
164#error "UHCI_VFRAMELIST_COUNT is not power of two"
165#error "or UHCI_VFRAMELIST_COUNT > UHCI_FRAMELIST_COUNT"
166#endif
167
168#if (UHCI_VFRAMELIST_COUNT < USB_MAX_FS_ISOC_FRAMES_PER_XFER)
169#error "maximum number of full-speed isochronous frames is higher than supported!"
170#endif
171
177
181 uint8_t temp[128];
182};
183
193
202};
203
204typedef struct uhci_softc {
206 struct usb_bus sc_bus; /* base device */
209
211 /* pointer to last TD for isochronous */
213 /* pointer to last QH for interrupt */
215 /* pointer to last QH for low speed control */
217 /* pointer to last QH for full speed control */
219 /* pointer to last QH for bulk */
224 struct resource *sc_io_res;
225 struct resource *sc_irq_res;
227 device_t sc_dev;
228 bus_size_t sc_io_size;
229 bus_space_tag_t sc_io_tag;
230 bus_space_handle_t sc_io_hdl;
231
232 uint32_t sc_loops; /* number of QHs that wants looping */
233
235
236 uint8_t sc_addr; /* device address */
237 uint8_t sc_conf; /* device configuration */
238 uint8_t sc_isreset; /* bits set if a root hub is reset */
239 uint8_t sc_isresumed; /* bits set if a port was resumed */
240 uint8_t sc_hub_idata[1];
241
242 char sc_vendor[16]; /* vendor string for root hub */
244
246
248void uhci_reset(uhci_softc_t *sc);
250
251#endif /* _UHCI_H_ */
struct usb_interface_descriptor ifcd
Definition: uhci.h:174
struct usb_endpoint_descriptor endpd
Definition: uhci.h:175
struct usb_config_descriptor confd
Definition: uhci.h:173
struct usb_page last_td_pg
Definition: uhci.h:201
struct usb_page bulk_start_pg
Definition: uhci.h:199
struct usb_page last_qh_pg
Definition: uhci.h:200
struct usb_page pframes_pg
Definition: uhci.h:194
struct usb_page intr_start_pg[UHCI_IFRAMELIST_COUNT]
Definition: uhci.h:196
struct usb_page_cache ls_ctl_start_pc
Definition: uhci.h:188
struct usb_page_cache last_qh_pc
Definition: uhci.h:191
struct usb_page_cache fs_ctl_start_pc
Definition: uhci.h:189
struct usb_page ls_ctl_start_pg
Definition: uhci.h:197
struct usb_page isoc_start_pg[UHCI_VFRAMELIST_COUNT]
Definition: uhci.h:195
struct usb_page_cache intr_start_pc[UHCI_IFRAMELIST_COUNT]
Definition: uhci.h:187
struct usb_page_cache pframes_pc
Definition: uhci.h:185
struct usb_page_cache bulk_start_pc
Definition: uhci.h:190
struct usb_page fs_ctl_start_pg
Definition: uhci.h:198
struct usb_page_cache isoc_start_pc[UHCI_VFRAMELIST_COUNT]
Definition: uhci.h:186
struct usb_page_cache last_td_pc
Definition: uhci.h:192
Definition: uhci.h:138
volatile uint32_t qh_h_next
Definition: uhci.h:142
volatile uint32_t qh_e_next
Definition: uhci.h:143
struct uhci_qh * h_next
Definition: uhci.h:147
struct uhci_td * e_next
Definition: uhci.h:150
uint32_t qh_self
Definition: uhci.h:152
struct uhci_qh * obj_next
Definition: uhci.h:149
uint16_t intr_pos
Definition: uhci.h:153
struct uhci_qh * h_prev
Definition: uhci.h:148
struct usb_page_cache * page_cache
Definition: uhci.h:151
uint8_t sc_addr
Definition: uhci.h:236
uint8_t sc_isreset
Definition: uhci.h:238
device_t sc_dev
Definition: uhci.h:227
union uhci_hub_desc sc_hub_desc
Definition: uhci.h:207
struct uhci_qh * sc_fs_ctl_p_last
Definition: uhci.h:218
struct usb_bus sc_bus
Definition: uhci.h:206
struct resource * sc_irq_res
Definition: uhci.h:225
bus_space_handle_t sc_io_hdl
Definition: uhci.h:230
struct uhci_qh * sc_last_qh_p
Definition: uhci.h:222
void * sc_intr_hdl
Definition: uhci.h:226
struct uhci_qh * sc_ls_ctl_p_last
Definition: uhci.h:216
uint8_t sc_isresumed
Definition: uhci.h:239
struct uhci_td * sc_isoc_p_last[UHCI_VFRAMELIST_COUNT]
Definition: uhci.h:212
uint32_t sc_loops
Definition: uhci.h:232
uint16_t sc_intr_stat[UHCI_IFRAMELIST_COUNT]
Definition: uhci.h:234
struct usb_device * sc_devices[UHCI_MAX_DEVICES]
Definition: uhci.h:210
bus_space_tag_t sc_io_tag
Definition: uhci.h:229
char sc_vendor[16]
Definition: uhci.h:242
struct uhci_qh * sc_intr_p_last[UHCI_IFRAMELIST_COUNT]
Definition: uhci.h:214
struct uhci_qh * sc_bulk_p_last
Definition: uhci.h:220
struct uhci_qh * sc_reclaim_qh_p
Definition: uhci.h:221
struct resource * sc_io_res
Definition: uhci.h:224
struct uhci_td * sc_last_td_p
Definition: uhci.h:223
struct uhci_hw_softc sc_hw
Definition: uhci.h:205
uint8_t sc_conf
Definition: uhci.h:237
uint8_t sc_hub_idata[1]
Definition: uhci.h:240
bus_size_t sc_io_size
Definition: uhci.h:228
struct usb_callout sc_root_intr
Definition: uhci.h:208
Definition: uhci.h:68
struct uhci_td * prev
Definition: uhci.h:110
volatile uint32_t td_buffer
Definition: uhci.h:105
uint16_t len
Definition: uhci.h:115
uint32_t td_self
Definition: uhci.h:114
struct usb_page_cache * page_cache
Definition: uhci.h:112
struct usb_page_cache * fix_pc
Definition: uhci.h:113
volatile uint32_t td_token
Definition: uhci.h:90
struct uhci_td * obj_next
Definition: uhci.h:111
volatile uint32_t td_status
Definition: uhci.h:74
struct uhci_td * next
Definition: uhci.h:109
volatile uint32_t td_next
Definition: uhci.h:73
usb_error_t uhci_init(uhci_softc_t *sc)
Definition: uhci.c:450
struct uhci_softc uhci_softc_t
#define UHCI_QH_ALIGN
Definition: uhci.h:44
usb_bus_mem_cb_t uhci_iterate_hw_softc
Definition: uhci.h:245
#define UHCI_MAX_DEVICES
Definition: uhci.h:37
struct uhci_td __aligned(UHCI_TD_ALIGN)
struct uhci_config_desc __packed
uint32_t uhci_physaddr_t
Definition: uhci.h:51
#define UHCI_IFRAMELIST_COUNT
Definition: uhci.h:160
void uhci_interrupt(uhci_softc_t *sc)
Definition: uhci.c:1414
void uhci_reset(uhci_softc_t *sc)
Definition: uhci.c:314
#define UHCI_VFRAMELIST_COUNT
Definition: uhci.h:159
#define UHCI_TD_ALIGN
Definition: uhci.h:43
uint8_t temp[128]
Definition: uhci.h:181
struct usb_port_status ps
Definition: uhci.h:180
struct usb_status stat
Definition: uhci.h:179
void() usb_bus_mem_cb_t(struct usb_bus *bus, usb_bus_mem_sub_cb_t *scb)
usb_error_t
Definition: usbdi.h:45