Merge from vendor branch BIND:
[dragonfly.git] / sys / bus / usb / ehcivar.h
1 /*
2  * $NetBSD: ehcivar.h,v 1.19 2005/04/29 15:04:29 augustss Exp $
3  * $FreeBSD: src/sys/dev/usb/ehcivar.h,v 1.2 2004/08/01 18:47:42 iedowse Exp $
4  * $DragonFly: src/sys/bus/usb/ehcivar.h,v 1.7 2006/05/02 16:12:01 dillon Exp $
5  */
6
7 /*
8  * Copyright (c) 2001 The NetBSD Foundation, Inc.
9  * All rights reserved.
10  *
11  * This code is derived from software contributed to The NetBSD Foundation
12  * by Lennart Augustsson (lennart@augustsson.net).
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
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.
29  *
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.
41  */
42
43 typedef struct ehci_soft_qtd {
44         ehci_qtd_t 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;
49         u_int16_t len;
50 } ehci_soft_qtd_t;
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)
53
54 typedef struct ehci_soft_qh {
55         ehci_qh_t qh;
56         struct ehci_soft_qh *next;
57         struct ehci_soft_qtd *sqtd;
58         ehci_physaddr_t physaddr;
59         int islot;
60 } ehci_soft_qh_t;
61 #define EHCI_SQH_SIZE ((sizeof (struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN)
62 #define EHCI_SQH_CHUNK (EHCI_PAGE_SIZE / EHCI_SQH_SIZE)
63
64 struct ehci_xfer {
65         struct usbd_xfer xfer;
66         struct usb_task abort_task;
67         LIST_ENTRY(ehci_xfer) inext; /* list of active xfers */
68         ehci_soft_qtd_t *sqtdstart;
69         ehci_soft_qtd_t *sqtdend;
70 #ifdef DIAGNOSTIC
71         int isdone;
72 #endif
73 };
74 #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
75
76 /* Information about an entry in the interrupt list. */
77 struct ehci_soft_islot {
78         ehci_soft_qh_t *sqh;    /* Queue Head. */
79 };
80
81 #define EHCI_FRAMELIST_MAXCOUNT 1024
82 #define EHCI_IPOLLRATES         8 /* Poll rates (1ms, 2, 4, 8 .. 128) */
83 #define EHCI_INTRQHS            ((1 << EHCI_IPOLLRATES) - 1)
84 #define EHCI_MAX_POLLRATE       (1 << (EHCI_IPOLLRATES - 1))
85 #define EHCI_IQHIDX(lev, pos) \
86         ((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
87 #define EHCI_ILEV_IVAL(lev)     (1 << (lev))
88
89
90 #define EHCI_HASH_SIZE 128
91 #define EHCI_COMPANION_MAX 8
92 #define EHCI_SCFLG_LOSTINTRBUG  0x0002  /* workaround for VIA chipsets */
93
94 typedef struct ehci_softc {
95         struct usbd_bus sc_bus;         /* base device */
96         bus_space_tag_t iot;
97         bus_space_handle_t ioh;
98         bus_size_t sc_size;
99 #if defined(__FreeBSD__) || defined(__DragonFly__)
100         void *ih;
101
102         struct resource *io_res;
103         struct resource *irq_res;
104 #endif
105         u_int sc_offs;                  /* offset to operational regs */
106         int sc_flags;                   /* misc flags */
107
108         char sc_vendor[32];             /* vendor string for root hub */
109         int sc_id_vendor;               /* vendor ID for root hub */
110
111 #if defined(__NetBSD__) || defined(__OpenBSD__)
112         u_int32_t sc_cmd;               /* shadow of cmd reg during suspend */
113         void *sc_powerhook;             /* cookie from power hook */
114         void *sc_shutdownhook;          /* cookie from shutdown hook */
115 #endif
116
117         u_int sc_ncomp;
118         u_int sc_npcomp;
119         struct usbd_bus *sc_comps[EHCI_COMPANION_MAX];
120
121         usb_dma_t sc_fldma;
122         ehci_link_t *sc_flist;
123         u_int sc_flsize;
124         u_int sc_rand;                  /* XXX need proper intr scheduling */
125
126         struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
127
128         LIST_HEAD(, ehci_xfer) sc_intrhead;
129
130         ehci_soft_qh_t *sc_freeqhs;
131         ehci_soft_qtd_t *sc_freeqtds;
132
133         int sc_noport;
134         u_int8_t sc_addr;               /* device address */
135         u_int8_t sc_conf;               /* device configuration */
136         usbd_xfer_handle sc_intrxfer;
137         char sc_isreset;
138 #ifdef USB_USE_SOFTINTR
139         char sc_softwake;
140 #endif /* USB_USE_SOFTINTR */
141
142         u_int32_t sc_eintrs;
143         ehci_soft_qh_t *sc_async_head;
144
145         SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
146
147         struct lock sc_doorbell_lock;
148
149         usb_callout_t sc_tmo_pcd;
150         usb_callout_t sc_tmo_intrlist;
151
152 #if defined(__NetBSD__) || defined(__OpenBSD__)
153         device_ptr_t sc_child;          /* /dev/usb# device */
154 #endif
155         char sc_dying;
156 #if defined(__NetBSD__)
157         struct usb_dma_reserve sc_dma_reserve;
158 #endif
159 } ehci_softc_t;
160
161 #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
162 #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
163 #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
164 #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
165 #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
166 #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
167 #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
168 #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
169 #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
170 #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
171 #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
172 #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
173
174 usbd_status     ehci_init(ehci_softc_t *);
175 void            ehci_init_intrs(ehci_softc_t *);
176 int             ehci_intr(void *);
177 #if defined(__NetBSD__) || defined(__OpenBSD__)
178 int             ehci_detach(ehci_softc_t *, int);
179 int             ehci_activate(device_ptr_t, enum devact);
180 #endif
181
182 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
183