2 * $NetBSD: uhcivar.h,v 1.33 2002/02/11 11:41:30 augustss Exp $
3 * $FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.36 2003/07/15 23:19:49 jmg Exp $
4 * $DragonFly: src/sys/bus/usb/uhcivar.h,v 1.4 2004/02/11 15:17:26 joerg Exp $
8 * Copyright (c) 1998 The NetBSD Foundation, Inc.
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Lennart Augustsson (lennart@augustsson.net) at
13 * Carlstedt Research & Technology.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. All advertising materials mentioning features or use of this software
24 * must display the following acknowledgement:
25 * This product includes software developed by the NetBSD
26 * Foundation, Inc. and its contributors.
27 * 4. Neither the name of The NetBSD Foundation nor the names of its
28 * contributors may be used to endorse or promote products derived
29 * from this software without specific prior written permission.
31 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
32 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
33 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
35 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGE.
45 * To avoid having 1024 TDs for each isochronous transfer we introduce
46 * a virtual frame list. Every UHCI_VFRAMELIST_COUNT entries in the real
47 * frame list points to a non-active TD. These, in turn, form the
48 * starts of the virtual frame list. This also has the advantage that it
49 * simplifies linking in/out of TDs/QHs in the schedule.
50 * Furthermore, initially each of the inactive TDs point to an inactive
51 * QH that forms the start of the interrupt traffic for that slot.
52 * Each of these QHs point to the same QH that is the start of control
53 * traffic. This QH points at another QH which is the start of the
56 * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
58 #define UHCI_VFRAMELIST_COUNT 128
60 typedef struct uhci_soft_qh uhci_soft_qh_t;
61 typedef struct uhci_soft_td uhci_soft_td_t;
64 struct uhci_soft_qh *sqh;
65 struct uhci_soft_td *std;
69 * An interrupt info struct contains the information needed to
70 * execute a requested routine when the controller generates an
71 * interrupt. Since we cannot know which transfer generated
72 * the interrupt all structs are linked together so they can be
73 * searched at interrupt time.
75 typedef struct uhci_intr_info {
76 struct uhci_softc *sc;
77 usbd_xfer_handle xfer;
78 uhci_soft_td_t *stdstart;
79 uhci_soft_td_t *stdend;
80 LIST_ENTRY(uhci_intr_info) list;
87 struct usbd_xfer xfer;
88 uhci_intr_info_t iinfo;
89 struct usb_task abort_task;
93 #define UXFER(xfer) ((struct uhci_xfer *)(xfer))
96 * Extra information that we need for a TD.
99 uhci_td_t td; /* The real TD, must be first */
100 uhci_soft_td_qh_t link; /* soft version of the td_link field */
101 uhci_physaddr_t physaddr; /* TD's physical address. */
104 * Make the size such that it is a multiple of UHCI_TD_ALIGN. This way
105 * we can pack a number of soft TD together and have the real TD well
107 * NOTE: Minimum size is 32 bytes.
109 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
110 #define UHCI_STD_CHUNK (PAGE_SIZE / UHCI_STD_SIZE)
113 * Extra information that we need for a QH.
115 struct uhci_soft_qh {
116 uhci_qh_t qh; /* The real QH, must be first */
117 uhci_soft_qh_t *hlink; /* soft version of qh_hlink */
118 uhci_soft_td_t *elink; /* soft version of qh_elink */
119 uhci_physaddr_t physaddr; /* QH's physical address. */
120 int pos; /* Timeslot position */
122 /* See comment about UHCI_STD_SIZE. */
123 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
124 #define UHCI_SQH_CHUNK (PAGE_SIZE / UHCI_SQH_SIZE)
127 * Information about an entry in the virtual frame list.
130 uhci_soft_td_t *htd; /* pointer to dummy TD */
131 uhci_soft_td_t *etd; /* pointer to last TD */
132 uhci_soft_qh_t *hqh; /* pointer to dummy QH */
133 uhci_soft_qh_t *eqh; /* pointer to last QH */
134 u_int bandwidth; /* max bandwidth used by this frame */
137 typedef struct uhci_softc {
138 struct usbd_bus sc_bus; /* base device */
140 bus_space_handle_t ioh;
142 #if defined(__FreeBSD__) || defined(__DragonFly__)
145 struct resource *io_res;
146 struct resource *irq_res;
149 uhci_physaddr_t *sc_pframes;
151 struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
153 uhci_soft_qh_t *sc_lctl_start; /* dummy QH for low speed control */
154 uhci_soft_qh_t *sc_lctl_end; /* last control QH */
155 uhci_soft_qh_t *sc_hctl_start; /* dummy QH for high speed control */
156 uhci_soft_qh_t *sc_hctl_end; /* last control QH */
157 uhci_soft_qh_t *sc_bulk_start; /* dummy QH for bulk */
158 uhci_soft_qh_t *sc_bulk_end; /* last bulk transfer */
159 uhci_soft_qh_t *sc_last_qh; /* dummy QH at the end */
160 u_int32_t sc_loops; /* number of QHs that wants looping */
162 uhci_soft_td_t *sc_freetds; /* TD free list */
163 uhci_soft_qh_t *sc_freeqhs; /* QH free list */
165 SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
167 u_int8_t sc_addr; /* device address */
168 u_int8_t sc_conf; /* device configuration */
170 u_int8_t sc_saved_sof;
171 u_int16_t sc_saved_frnum;
173 #ifdef USB_USE_SOFTINTR
175 #endif /* USB_USE_SOFTINTR */
181 LIST_HEAD(, uhci_intr_info) sc_intrhead;
183 /* Info for the root hub interrupt channel. */
184 int sc_ival; /* time between root hub intrs */
185 usbd_xfer_handle sc_intr_xfer; /* root hub interrupt transfer */
186 usb_callout_t sc_poll_handle;
188 char sc_vendor[16]; /* vendor string for root hub */
189 int sc_id_vendor; /* vendor ID for root hub */
191 #if defined(__NetBSD__)
192 void *sc_powerhook; /* cookie from power hook */
193 void *sc_shutdownhook; /* cookie from shutdown hook */
196 device_ptr_t sc_child; /* /dev/usb# device */
199 usbd_status uhci_init(uhci_softc_t *);
200 int uhci_intr(void *);
201 #if defined(__NetBSD__) || defined(__OpenBSD__)
202 int uhci_detach(uhci_softc_t *, int);
203 int uhci_activate(device_ptr_t, enum devact);
206 void uhci_shutdown(void *v);
207 void uhci_power(int state, void *priv);