1 /* $NetBSD: uhcivar.h,v 1.21 2000/01/18 20:11:01 augustss Exp $ */
2 /* $FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.16.2.5 2000/10/31 23:23:29 n_hibma Exp $ */
3 /* $DragonFly: src/sys/bus/usb/uhcivar.h,v 1.2 2003/06/17 04:28:32 dillon Exp $ */
6 * Copyright (c) 1998 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
10 * by Lennart Augustsson (lennart@augustsson.net) at
11 * Carlstedt Research & Technology.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. All advertising materials mentioning features or use of this software
22 * must display the following acknowledgement:
23 * This product includes software developed by the NetBSD
24 * Foundation, Inc. and its contributors.
25 * 4. Neither the name of The NetBSD Foundation nor the names of its
26 * contributors may be used to endorse or promote products derived
27 * from this software without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
30 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
31 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
32 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
33 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
34 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
35 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
36 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
37 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
38 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
39 * POSSIBILITY OF SUCH DAMAGE.
43 * To avoid having 1024 TDs for each isochronous transfer we introduce
44 * a virtual frame list. Every UHCI_VFRAMELIST_COUNT entries in the real
45 * frame list points to a non-active TD. These, in turn, which form the
46 * starts of the virtual frame list. This also has the advantage that it
47 * simplifies linking in/out TD/QH in the schedule.
48 * Furthermore, initially each of the inactive TDs point to an inactive
49 * QH that forms the start of the interrupt traffic for that slot.
50 * Each of these QHs point to the same QH that is the start of control
53 * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
55 #define UHCI_VFRAMELIST_COUNT 128
57 typedef struct uhci_soft_qh uhci_soft_qh_t;
58 typedef struct uhci_soft_td uhci_soft_td_t;
61 struct uhci_soft_qh *sqh;
62 struct uhci_soft_td *std;
66 * An interrupt info struct contains the information needed to
67 * execute a requested routine when the controller generates an
68 * interrupt. Since we cannot know which transfer generated
69 * the interrupt all structs are linked together so they can be
70 * searched at interrupt time.
72 typedef struct uhci_intr_info {
73 struct uhci_softc *sc;
74 usbd_xfer_handle xfer;
75 uhci_soft_td_t *stdstart;
76 uhci_soft_td_t *stdend;
77 LIST_ENTRY(uhci_intr_info) list;
78 #if defined(__FreeBSD__)
79 struct callout_handle timeout_handle;
80 #endif /* defined(__FreeBSD__) */
87 * Extra information that we need for a TD.
90 uhci_td_t td; /* The real TD, must be first */
91 uhci_soft_td_qh_t link; /* soft version of the td_link field */
92 uhci_physaddr_t physaddr; /* TD's physical address. */
95 * Make the size such that it is a multiple of UHCI_TD_ALIGN. This way
96 * we can pack a number of soft TD together and have the real TD well
98 * NOTE: Minimum size is 32 bytes.
100 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
101 #define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
104 * Extra information that we need for a QH.
106 struct uhci_soft_qh {
107 uhci_qh_t qh; /* The real QH, must be first */
108 uhci_soft_qh_t *hlink; /* soft version of qh_hlink */
109 uhci_soft_td_t *elink; /* soft version of qh_elink */
110 uhci_physaddr_t physaddr; /* QH's physical address. */
111 int pos; /* Timeslot position */
112 uhci_intr_info_t *intr_info; /* Who to call on completion. */
113 /* XXX should try to shrink with 4 bytes to fit into 32 bytes */
115 /* See comment about UHCI_STD_SIZE. */
116 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
117 #define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
120 * Information about an entry in the virtual frame list.
123 uhci_soft_td_t *htd; /* pointer to dummy TD */
124 uhci_soft_td_t *etd; /* pointer to last TD */
125 uhci_soft_qh_t *hqh; /* pointer to dummy QH */
126 uhci_soft_qh_t *eqh; /* pointer to last QH */
127 u_int bandwidth; /* max bandwidth used by this frame */
130 typedef struct uhci_softc {
131 struct usbd_bus sc_bus; /* base device */
133 bus_space_handle_t ioh;
134 #if defined(__FreeBSD__)
137 struct resource *io_res;
138 struct resource *irq_res;
141 uhci_physaddr_t *sc_pframes;
143 struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
145 uhci_soft_qh_t *sc_ctl_start; /* dummy QH for control */
146 uhci_soft_qh_t *sc_ctl_end; /* last control QH */
147 uhci_soft_qh_t *sc_bulk_start; /* dummy QH for bulk */
148 uhci_soft_qh_t *sc_bulk_end; /* last bulk transfer */
150 uhci_soft_td_t *sc_freetds; /* TD free list */
151 uhci_soft_qh_t *sc_freeqhs; /* QH free list */
153 SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
155 u_int8_t sc_addr; /* device address */
156 u_int8_t sc_conf; /* device configuration */
158 u_int8_t sc_saved_sof;
159 u_int16_t sc_saved_frnum;
164 LIST_HEAD(, uhci_intr_info) sc_intrhead;
166 /* Info for the root hub interrupt channel. */
167 int sc_ival; /* time between root hug intrs */
168 usbd_xfer_handle sc_has_timo; /* root hub interrupt transfer */
170 char sc_vflock; /* for lock virtual frame list */
171 #define UHCI_HAS_LOCK 1
172 #define UHCI_WANT_LOCK 2
174 char sc_vendor[16]; /* vendor string for root hub */
175 int sc_id_vendor; /* vendor ID for root hub */
177 #if defined(__NetBSD__)
178 void *sc_powerhook; /* cookie from power hook */
179 void *sc_shutdownhook; /* cookie from shutdown hook */
182 device_ptr_t sc_child; /* /dev/usb device */
185 usbd_status uhci_init(uhci_softc_t *);
186 int uhci_intr(void *);
187 #if defined(__NetBSD__) || defined(__OpenBSD__)
188 int uhci_detach(uhci_softc_t *, int);
189 int uhci_activate(device_ptr_t, enum devact);
192 void uhci_shutdown(void *v);
193 void uhci_power(int state, void *priv);