1 /* $NetBSD: ehcivar.h,v 1.19 2005/04/29 15:04:29 augustss Exp $ */
5 * Copyright (c) 2001 The NetBSD Foundation, Inc.
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net).
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
40 typedef struct ehci_soft_qtd {
42 struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
43 ehci_physaddr_t physaddr;
44 usbd_xfer_handle xfer;
45 LIST_ENTRY(ehci_soft_qtd) hnext;
48 #define EHCI_SQTD_SIZE ((sizeof (struct ehci_soft_qtd) + EHCI_QTD_ALIGN - 1) / EHCI_QTD_ALIGN * EHCI_QTD_ALIGN)
49 #define EHCI_SQTD_CHUNK (EHCI_PAGE_SIZE / EHCI_SQTD_SIZE)
51 typedef struct ehci_soft_qh {
53 struct ehci_soft_qh *next;
54 struct ehci_soft_qh *prev;
55 struct ehci_soft_qtd *sqtd;
56 struct ehci_soft_qtd *inactivesqtd;
57 ehci_physaddr_t physaddr;
58 int islot; /* Interrupt list slot. */
60 #define EHCI_SQH_SIZE ((sizeof (struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN)
61 #define EHCI_SQH_CHUNK (EHCI_PAGE_SIZE / EHCI_SQH_SIZE)
64 struct usbd_xfer xfer;
65 struct usb_task abort_task;
66 LIST_ENTRY(ehci_xfer) inext; /* list of active xfers */
67 ehci_soft_qtd_t *sqtdstart;
68 ehci_soft_qtd_t *sqtdend;
69 u_int32_t ehci_xfer_flags;
74 #define EHCI_XFER_ABORTING 0x0001 /* xfer is aborting. */
75 #define EHCI_XFER_ABORTWAIT 0x0002 /* abort completion is being awaited. */
77 #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
80 * Information about an entry in the interrupt list.
82 struct ehci_soft_islot {
83 ehci_soft_qh_t *sqh; /* Queue Head. */
86 #define EHCI_FRAMELIST_MAXCOUNT 1024
87 #define EHCI_IPOLLRATES 8 /* Poll rates (1ms, 2, 4, 8 ... 128) */
88 #define EHCI_INTRQHS ((1 << EHCI_IPOLLRATES) - 1)
89 #define EHCI_MAX_POLLRATE (1 << (EHCI_IPOLLRATES - 1))
90 #define EHCI_IQHIDX(lev, pos) \
91 ((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
92 #define EHCI_ILEV_IVAL(lev) (1 << (lev))
94 #define EHCI_HASH_SIZE 128
95 #define EHCI_COMPANION_MAX 8
97 #define EHCI_SCFLG_DONEINIT 0x0001 /* ehci_init() has been called. */
98 #define EHCI_SCFLG_LOSTINTRBUG 0x0002 /* workaround for VIA / ATI chipsets */
100 typedef struct ehci_softc {
101 struct usbd_bus sc_bus; /* base device */
104 bus_space_handle_t ioh;
106 #if defined(__FreeBSD__)
109 struct resource *io_res;
110 struct resource *irq_res;
112 u_int sc_offs; /* offset to operational regs */
114 char sc_vendor[32]; /* vendor string for root hub */
115 int sc_id_vendor; /* vendor ID for root hub */
117 u_int32_t sc_cmd; /* shadow of cmd reg during suspend */
118 #if defined(__NetBSD__) || defined(__OpenBSD__)
119 void *sc_powerhook; /* cookie from power hook */
120 void *sc_shutdownhook; /* cookie from shutdown hook */
125 struct usbd_bus *sc_comps[EHCI_COMPANION_MAX];
128 ehci_link_t *sc_flist;
131 u_int sc_rand; /* XXX need proper intr scheduling */
134 struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
136 LIST_HEAD(, ehci_xfer) sc_intrhead;
138 ehci_soft_qh_t *sc_freeqhs;
139 ehci_soft_qtd_t *sc_freeqtds;
142 u_int8_t sc_addr; /* device address */
143 u_int8_t sc_conf; /* device configuration */
144 usbd_xfer_handle sc_intrxfer;
146 #ifdef USB_USE_SOFTINTR
148 #endif /* USB_USE_SOFTINTR */
151 ehci_soft_qh_t *sc_async_head;
153 STAILQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
155 struct lock sc_doorbell_lock;
157 struct callout sc_tmo_pcd;
158 struct callout sc_tmo_intrlist;
161 #if defined(__NetBSD__)
162 struct usb_dma_reserve sc_dma_reserve;
166 #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
167 #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
168 #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
169 #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
170 #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
171 #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
172 #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
173 #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
174 #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
175 #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
176 #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
177 #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
179 usbd_status ehci_init(ehci_softc_t *);
180 int ehci_intr(void *);
181 int ehci_detach(ehci_softc_t *, int);
182 #if defined(__NetBSD__) || defined(__OpenBSD__)
183 int ehci_activate(device_t, enum devact);
185 void ehci_power(int state, void *priv);
186 void ehci_shutdown(void *v);
188 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)