2 * $NetBSD: ehcivar.h,v 1.12 2001/12/31 12:16:57 augustss Exp $
3 * $FreeBSD: src/sys/dev/usb/ehcivar.h,v 1.1 2003/04/14 14:04:07 ticso Exp $
4 * $DragonFly: src/sys/bus/usb/ehcivar.h,v 1.2 2004/02/11 15:17:26 joerg Exp $
8 * Copyright (c) 2001 The NetBSD Foundation, Inc.
11 * This code is derived from software contributed to The NetBSD Foundation
12 * by Lennart Augustsson (lennart@augustsson.net).
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. All advertising materials mentioning features or use of this software
23 * must display the following acknowledgement:
24 * This product includes software developed by the NetBSD
25 * Foundation, Inc. and its contributors.
26 * 4. Neither the name of The NetBSD Foundation nor the names of its
27 * contributors may be used to endorse or promote products derived
28 * from this software without specific prior written permission.
30 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
31 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
32 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
34 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
43 typedef struct ehci_soft_qtd {
45 struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
46 ehci_physaddr_t physaddr;
47 usbd_xfer_handle xfer;
48 LIST_ENTRY(ehci_soft_qtd) hnext;
51 #define EHCI_SQTD_SIZE ((sizeof (struct ehci_soft_qtd) + EHCI_QTD_ALIGN - 1) / EHCI_QTD_ALIGN * EHCI_QTD_ALIGN)
52 #define EHCI_SQTD_CHUNK (EHCI_PAGE_SIZE / EHCI_SQTD_SIZE)
54 typedef struct ehci_soft_qh {
56 struct ehci_soft_qh *next;
57 struct ehci_soft_qtd *sqtd;
58 ehci_physaddr_t physaddr;
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;
73 #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
76 #define EHCI_HASH_SIZE 128
77 #define EHCI_COMPANION_MAX 8
79 typedef struct ehci_softc {
80 struct usbd_bus sc_bus; /* base device */
82 bus_space_handle_t ioh;
84 #if defined(__FreeBSD__) || defined(__DragonFly__)
87 struct resource *io_res;
88 struct resource *irq_res;
90 u_int sc_offs; /* offset to operational regs */
92 char sc_vendor[16]; /* vendor string for root hub */
93 int sc_id_vendor; /* vendor ID for root hub */
95 #if defined(__NetBSD__) || defined(__OpenBSD__)
96 void *sc_powerhook; /* cookie from power hook */
97 void *sc_shutdownhook; /* cookie from shutdown hook */
102 struct usbd_bus *sc_comps[EHCI_COMPANION_MAX];
107 LIST_HEAD(, ehci_xfer) sc_intrhead;
109 ehci_soft_qh_t *sc_freeqhs;
110 ehci_soft_qtd_t *sc_freeqtds;
113 u_int8_t sc_addr; /* device address */
114 u_int8_t sc_conf; /* device configuration */
115 usbd_xfer_handle sc_intrxfer;
117 #ifdef USB_USE_SOFTINTR
119 #endif /* USB_USE_SOFTINTR */
122 ehci_soft_qh_t *sc_async_head;
124 SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
126 struct lock sc_doorbell_lock;
128 usb_callout_t sc_tmo_pcd;
130 device_ptr_t sc_child; /* /dev/usb# device */
135 #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
136 #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
137 #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
138 #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
139 #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
140 #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
141 #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
142 #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
143 #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
144 #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
145 #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
146 #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
148 usbd_status ehci_init(ehci_softc_t *);
149 int ehci_intr(void *);
150 #if defined(__NetBSD__) || defined(__OpenBSD__)
151 int ehci_detach(ehci_softc_t *, int);
152 int ehci_activate(device_ptr_t, enum devact);
155 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)