ehcivar.h revision 1.24.14.2 1 1.24.14.2 itohy /* $NetBSD: ehcivar.h,v 1.24.14.2 2008/05/21 05:01:45 itohy Exp $ */
2 1.24.14.1 itohy /* $FreeBSD: /repoman/r/ncvs/src/sys/dev/usb/ehcivar.h,v 1.16 2006/09/07 00:06:41 imp Exp $ */
3 1.1 augustss
4 1.24.14.1 itohy /*-
5 1.4 augustss * Copyright (c) 2001 The NetBSD Foundation, Inc.
6 1.1 augustss * All rights reserved.
7 1.1 augustss *
8 1.1 augustss * This code is derived from software contributed to The NetBSD Foundation
9 1.1 augustss * by Lennart Augustsson (lennart (at) augustsson.net).
10 1.1 augustss *
11 1.1 augustss * Redistribution and use in source and binary forms, with or without
12 1.1 augustss * modification, are permitted provided that the following conditions
13 1.1 augustss * are met:
14 1.1 augustss * 1. Redistributions of source code must retain the above copyright
15 1.1 augustss * notice, this list of conditions and the following disclaimer.
16 1.1 augustss * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 augustss * notice, this list of conditions and the following disclaimer in the
18 1.1 augustss * documentation and/or other materials provided with the distribution.
19 1.1 augustss * 3. All advertising materials mentioning features or use of this software
20 1.1 augustss * must display the following acknowledgement:
21 1.1 augustss * This product includes software developed by the NetBSD
22 1.1 augustss * Foundation, Inc. and its contributors.
23 1.1 augustss * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 augustss * contributors may be used to endorse or promote products derived
25 1.1 augustss * from this software without specific prior written permission.
26 1.1 augustss *
27 1.1 augustss * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 augustss * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 augustss * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 augustss * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 augustss * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 augustss * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 augustss * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 augustss * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 augustss * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 augustss * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 augustss * POSSIBILITY OF SUCH DAMAGE.
38 1.1 augustss */
39 1.1 augustss
40 1.24.14.1 itohy struct ehci_mem_desc {
41 1.24.14.1 itohy caddr_t em_top;
42 1.24.14.1 itohy ehci_physaddr_t em_topdma;
43 1.24.14.1 itohy usb_dma_t em_dma;
44 1.24.14.1 itohy SIMPLEQ_ENTRY(ehci_mem_desc) em_next;
45 1.24.14.1 itohy };
46 1.24.14.1 itohy
47 1.7 augustss typedef struct ehci_soft_qtd {
48 1.7 augustss ehci_qtd_t qtd;
49 1.7 augustss struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
50 1.24.14.1 itohy struct ehci_mem_desc *et_mdesc;
51 1.7 augustss usbd_xfer_handle xfer;
52 1.7 augustss LIST_ENTRY(ehci_soft_qtd) hnext;
53 1.7 augustss u_int16_t len;
54 1.7 augustss } ehci_soft_qtd_t;
55 1.7 augustss #define EHCI_SQTD_SIZE ((sizeof (struct ehci_soft_qtd) + EHCI_QTD_ALIGN - 1) / EHCI_QTD_ALIGN * EHCI_QTD_ALIGN)
56 1.24.14.1 itohy #define EHCI_SQTD_CHUNK ((EHCI_PAGE_SIZE - sizeof(struct ehci_mem_desc)) / EHCI_SQTD_SIZE)
57 1.24.14.1 itohy #define EHCI_SQTD_DMAADDR(d) \
58 1.24.14.1 itohy ((d)->et_mdesc->em_topdma + ((caddr_t)(d) - (d)->et_mdesc->em_top))
59 1.24.14.1 itohy #define EHCI_SQTD_SYNC(sc, d, ops) \
60 1.24.14.1 itohy USB_MEM_SYNC2(&(sc)->sc_dmatag, &(d)->et_mdesc->em_dma, (caddr_t)(d) - (d)->et_mdesc->em_top , sizeof(ehci_qtd_t), (ops))
61 1.7 augustss
62 1.7 augustss typedef struct ehci_soft_qh {
63 1.7 augustss ehci_qh_t qh;
64 1.7 augustss struct ehci_soft_qh *next;
65 1.24.14.1 itohy struct ehci_soft_qh *prev;
66 1.9 augustss struct ehci_soft_qtd *sqtd;
67 1.24.14.1 itohy struct ehci_soft_qtd *inactivesqtd;
68 1.24.14.1 itohy struct ehci_mem_desc *eh_mdesc;
69 1.24.14.1 itohy int islot; /* Interrupt list slot. */
70 1.7 augustss } ehci_soft_qh_t;
71 1.7 augustss #define EHCI_SQH_SIZE ((sizeof (struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN)
72 1.24.14.1 itohy #define EHCI_SQH_CHUNK ((EHCI_PAGE_SIZE - sizeof(struct ehci_mem_desc)) / EHCI_SQH_SIZE)
73 1.24.14.1 itohy #define EHCI_SQH_DMAADDR(d) \
74 1.24.14.1 itohy ((d)->eh_mdesc->em_topdma + ((caddr_t)(d) - (d)->eh_mdesc->em_top))
75 1.24.14.1 itohy #define EHCI_SQH_SYNC(sc, d, ops) \
76 1.24.14.1 itohy USB_MEM_SYNC2(&(sc)->sc_dmatag, &(d)->eh_mdesc->em_dma, (caddr_t)(d) - (d)->eh_mdesc->em_top , sizeof(ehci_qh_t), (ops))
77 1.7 augustss
78 1.24.14.2 itohy /* for aux memory */
79 1.24.14.2 itohy #define EHCI_AUX_CHUNK_SIZE 4096
80 1.24.14.2 itohy #define EHCI_MAX_PKT_SIZE 1024 /* USB 2.0 specification */
81 1.24.14.2 itohy #define EHCI_AUX_PER_CHUNK(maxp) (EHCI_AUX_CHUNK_SIZE/(maxp))
82 1.24.14.2 itohy #define EHCI_NCHUNK(naux, maxp) \
83 1.24.14.2 itohy (((naux) + EHCI_AUX_PER_CHUNK(maxp) - 1) / EHCI_AUX_PER_CHUNK(maxp))
84 1.24.14.2 itohy struct ehci_aux_mem {
85 1.24.14.2 itohy usb_dma_t aux_chunk_dma[EHCI_NCHUNK(USB_DMA_NSEG-1, EHCI_MAX_PKT_SIZE)];
86 1.24.14.2 itohy int aux_nchunk; /* number of allocated chunk */
87 1.24.14.2 itohy int aux_curchunk; /* current chunk */
88 1.24.14.2 itohy int aux_chunkoff; /* offset in current chunk */
89 1.24.14.2 itohy int aux_naux; /* number of aux */
90 1.24.14.2 itohy };
91 1.24.14.2 itohy
92 1.11 augustss struct ehci_xfer {
93 1.11 augustss struct usbd_xfer xfer;
94 1.11 augustss struct usb_task abort_task;
95 1.11 augustss LIST_ENTRY(ehci_xfer) inext; /* list of active xfers */
96 1.11 augustss ehci_soft_qtd_t *sqtdstart;
97 1.11 augustss ehci_soft_qtd_t *sqtdend;
98 1.24.14.1 itohy u_int32_t ehci_xfer_flags;
99 1.24.14.1 itohy struct usb_buffer_dma dmabuf;
100 1.24.14.1 itohy int rsvd_tds;
101 1.24.14.2 itohy struct ehci_aux_mem aux;
102 1.24.14.1 itohy #ifdef DIAGNOSTIC
103 1.24.14.1 itohy int isdone;
104 1.24.14.1 itohy #endif
105 1.11 augustss };
106 1.24.14.1 itohy #define EHCI_XFER_ABORTING 0x0001 /* xfer is aborting. */
107 1.24.14.1 itohy #define EHCI_XFER_ABORTWAIT 0x0002 /* abort completion is being awaited. */
108 1.24.14.1 itohy
109 1.24.14.1 itohy #if 1 /* make sure the argument is actually an xfer pointer */
110 1.24.14.1 itohy #define EXFER(xfer) ((void)&(xfer)->hcpriv, (struct ehci_xfer *)(xfer))
111 1.24.14.1 itohy #else
112 1.11 augustss #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
113 1.24.14.1 itohy #endif
114 1.11 augustss
115 1.24.14.1 itohy /*
116 1.24.14.1 itohy * Information about an entry in the interrupt list.
117 1.24.14.1 itohy */
118 1.15 augustss struct ehci_soft_islot {
119 1.24.14.1 itohy ehci_soft_qh_t *sqh; /* Queue Head. */
120 1.15 augustss };
121 1.15 augustss
122 1.15 augustss #define EHCI_FRAMELIST_MAXCOUNT 1024
123 1.24.14.1 itohy #define EHCI_IPOLLRATES 8 /* Poll rates (1ms, 2, 4, 8 ... 128) */
124 1.15 augustss #define EHCI_INTRQHS ((1 << EHCI_IPOLLRATES) - 1)
125 1.18 augustss #define EHCI_MAX_POLLRATE (1 << (EHCI_IPOLLRATES - 1))
126 1.24.14.1 itohy #define EHCI_IQHIDX(lev, pos) \
127 1.15 augustss ((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
128 1.15 augustss #define EHCI_ILEV_IVAL(lev) (1 << (lev))
129 1.15 augustss
130 1.7 augustss #define EHCI_HASH_SIZE 128
131 1.3 augustss #define EHCI_COMPANION_MAX 8
132 1.7 augustss
133 1.24.14.1 itohy #define EHCI_SCFLG_DONEINIT 0x0001 /* ehci_init() has been called. */
134 1.24.14.1 itohy #define EHCI_SCFLG_LOSTINTRBUG 0x0002 /* workaround for VIA / ATI chipsets */
135 1.24.14.1 itohy
136 1.1 augustss typedef struct ehci_softc {
137 1.1 augustss struct usbd_bus sc_bus; /* base device */
138 1.1 augustss bus_space_tag_t iot;
139 1.1 augustss bus_space_handle_t ioh;
140 1.1 augustss bus_size_t sc_size;
141 1.24.14.1 itohy #if defined(__FreeBSD__)
142 1.24.14.1 itohy void *ih;
143 1.24.14.1 itohy
144 1.24.14.1 itohy struct resource *io_res;
145 1.24.14.1 itohy struct resource *irq_res;
146 1.24.14.1 itohy #endif
147 1.2 augustss u_int sc_offs; /* offset to operational regs */
148 1.23 xtraeme int sc_flags; /* misc flags */
149 1.23 xtraeme #define EHCIF_DROPPED_INTR_WORKAROUND 0x01
150 1.1 augustss
151 1.19 augustss char sc_vendor[32]; /* vendor string for root hub */
152 1.1 augustss int sc_id_vendor; /* vendor ID for root hub */
153 1.1 augustss
154 1.13 augustss u_int32_t sc_cmd; /* shadow of cmd reg during suspend */
155 1.24.14.1 itohy #if defined(__NetBSD__) || defined(__OpenBSD__)
156 1.1 augustss void *sc_powerhook; /* cookie from power hook */
157 1.1 augustss void *sc_shutdownhook; /* cookie from shutdown hook */
158 1.24.14.1 itohy #endif
159 1.1 augustss
160 1.3 augustss u_int sc_ncomp;
161 1.5 augustss u_int sc_npcomp;
162 1.3 augustss struct usbd_bus *sc_comps[EHCI_COMPANION_MAX];
163 1.3 augustss
164 1.24.14.1 itohy usb_dma_tag_t sc_dmatag;
165 1.3 augustss usb_dma_t sc_fldma;
166 1.15 augustss ehci_link_t *sc_flist;
167 1.3 augustss u_int sc_flsize;
168 1.24.14.1 itohy #ifndef __FreeBSD__
169 1.15 augustss u_int sc_rand; /* XXX need proper intr scheduling */
170 1.24.14.1 itohy #endif
171 1.15 augustss
172 1.15 augustss struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
173 1.3 augustss
174 1.11 augustss LIST_HEAD(, ehci_xfer) sc_intrhead;
175 1.11 augustss
176 1.24.14.1 itohy SIMPLEQ_HEAD(ehci_mdescs, ehci_mem_desc) sc_sqh_chunks, sc_sqtd_chunks;
177 1.24.14.1 itohy
178 1.7 augustss ehci_soft_qh_t *sc_freeqhs;
179 1.7 augustss ehci_soft_qtd_t *sc_freeqtds;
180 1.24.14.1 itohy int sc_nfreeqtds;
181 1.7 augustss
182 1.4 augustss int sc_noport;
183 1.21 augustss u_int8_t sc_hasppc; /* has Port Power Control */
184 1.4 augustss u_int8_t sc_addr; /* device address */
185 1.4 augustss u_int8_t sc_conf; /* device configuration */
186 1.4 augustss usbd_xfer_handle sc_intrxfer;
187 1.21 augustss char sc_isreset[EHCI_MAX_PORTS];
188 1.14 augustss #ifdef USB_USE_SOFTINTR
189 1.12 augustss char sc_softwake;
190 1.14 augustss #endif /* USB_USE_SOFTINTR */
191 1.5 augustss
192 1.5 augustss u_int32_t sc_eintrs;
193 1.9 augustss ehci_soft_qh_t *sc_async_head;
194 1.4 augustss
195 1.4 augustss SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
196 1.8 augustss
197 1.8 augustss struct lock sc_doorbell_lock;
198 1.5 augustss
199 1.23 xtraeme usb_callout_t sc_tmo_intrlist;
200 1.4 augustss
201 1.17 imp #if defined(__NetBSD__) || defined(__OpenBSD__)
202 1.24.14.1 itohy device_t sc_child; /* /dev/usb# device */
203 1.17 imp #endif
204 1.4 augustss char sc_dying;
205 1.1 augustss } ehci_softc_t;
206 1.2 augustss
207 1.3 augustss #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
208 1.3 augustss #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
209 1.3 augustss #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
210 1.3 augustss #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
211 1.3 augustss #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
212 1.3 augustss #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
213 1.2 augustss #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
214 1.2 augustss #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
215 1.2 augustss #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
216 1.2 augustss #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
217 1.2 augustss #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
218 1.2 augustss #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
219 1.1 augustss
220 1.1 augustss usbd_status ehci_init(ehci_softc_t *);
221 1.1 augustss int ehci_intr(void *);
222 1.1 augustss int ehci_detach(ehci_softc_t *, int);
223 1.24.14.1 itohy #if defined(__NetBSD__) || defined(__OpenBSD__)
224 1.24.14.1 itohy int ehci_activate(device_t, enum devact);
225 1.24.14.1 itohy #endif
226 1.24.14.1 itohy void ehci_power(int state, void *priv);
227 1.24.14.1 itohy void ehci_shutdown(void *v);
228 1.24.14.1 itohy
229 1.24.14.1 itohy #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
230 1.24.14.1 itohy
231