uhcivar.h revision 1.40.40.1 1 /* $NetBSD: uhcivar.h,v 1.40.40.1 2007/05/22 14:57:42 itohy Exp $ */
2 /* $FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.43 2006/09/07 00:06:41 imp Exp $ */
3
4 /*-
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart (at) augustsson.net) at
10 * Carlstedt Research & Technology.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. All advertising materials mentioning features or use of this software
21 * must display the following acknowledgement:
22 * This product includes software developed by the NetBSD
23 * Foundation, Inc. and its contributors.
24 * 4. Neither the name of The NetBSD Foundation nor the names of its
25 * contributors may be used to endorse or promote products derived
26 * from this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
39 */
40
41 /*
42 * To avoid having 1024 TDs for each isochronous transfer we introduce
43 * a virtual frame list. Every UHCI_VFRAMELIST_COUNT entries in the real
44 * frame list points to a non-active TD. These, in turn, form the
45 * starts of the virtual frame list. This also has the advantage that it
46 * simplifies linking in/out of TDs/QHs in the schedule.
47 * Furthermore, initially each of the inactive TDs point to an inactive
48 * QH that forms the start of the interrupt traffic for that slot.
49 * Each of these QHs point to the same QH that is the start of control
50 * traffic. This QH points at another QH which is the start of the
51 * bulk traffic.
52 *
53 * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
54 */
55 #define UHCI_VFRAMELIST_COUNT 128
56
57 typedef struct uhci_soft_qh uhci_soft_qh_t;
58 typedef struct uhci_soft_td uhci_soft_td_t;
59
60 typedef union {
61 struct uhci_soft_qh *sqh;
62 struct uhci_soft_td *std;
63 } uhci_soft_td_qh_t;
64
65 /*
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.
71 */
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 #ifdef DIAGNOSTIC
79 int isdone;
80 #endif
81 } uhci_intr_info_t;
82
83 /* for aux memory */
84 #define UHCI_AUX_CHUNK_SIZE 4096
85 #define UHCI_MAX_PKT_SIZE 1023 /* USB 1.1 specification */
86 #define UHCI_AUX_PER_CHUNK(maxp) (UHCI_AUX_CHUNK_SIZE/(maxp))
87 #define UHCI_NCHUNK(naux, maxp) \
88 (((naux) + UHCI_AUX_PER_CHUNK(maxp) - 1) / UHCI_AUX_PER_CHUNK(maxp))
89 struct uhci_aux_mem {
90 usb_dma_t aux_chunk_dma[UHCI_NCHUNK(USB_DMA_NSEG-1, UHCI_MAX_PKT_SIZE)];
91 int aux_nchunk; /* number of allocated chunk */
92 int aux_curchunk; /* current chunk */
93 int aux_chunkoff; /* offset in current chunk */
94 int aux_naux; /* number of aux */
95 };
96
97 struct uhci_xfer {
98 struct usbd_xfer xfer;
99 uhci_intr_info_t iinfo;
100 struct usb_task abort_task;
101 int curframe;
102 u_int32_t uhci_xfer_flags;
103 struct usb_buffer_dma dmabuf;
104 int rsvd_tds;
105 struct uhci_aux_mem aux;
106 };
107
108 #define UHCI_XFER_ABORTING 0x0001 /* xfer is aborting. */
109 #define UHCI_XFER_ABORTWAIT 0x0002 /* abort completion is being awaited. */
110
111 #if 1 /* make sure the argument is actually an xfer pointer */
112 #define UXFER(xfer) ((void)&(xfer)->hcpriv, (struct uhci_xfer *)(xfer))
113 #else
114 #define UXFER(xfer) ((struct uhci_xfer *)(xfer))
115 #endif
116
117 struct uhci_mem_desc {
118 caddr_t um_top;
119 uhci_physaddr_t um_topdma;
120 usb_dma_t um_dma;
121 SIMPLEQ_ENTRY(uhci_mem_desc) um_next;
122 };
123
124 /*
125 * Extra information that we need for a TD.
126 */
127 struct uhci_soft_td {
128 uhci_td_t td; /* The real TD, must be first */
129 uhci_soft_td_qh_t link; /* soft version of the td_link field */
130 struct uhci_mem_desc *ut_mdesc; /* DMA memory desc */
131 uhci_physaddr_t aux_dma; /* Auxillary storage if needed. */
132 void *aux_kern;
133 void *aux_data; /* Original aux data virtual address. */
134 int aux_len; /* Auxillary storage size. */
135 };
136 /*
137 * Make the size such that it is a multiple of UHCI_TD_ALIGN. This way
138 * we can pack a number of soft TD together and have the real TD well
139 * aligned.
140 * NOTE: Minimum size is 32 bytes.
141 */
142 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
143 #define UHCI_STD_CHUNK ((PAGE_SIZE - sizeof(struct uhci_mem_desc)) / UHCI_STD_SIZE)
144 #define UHCI_STD_DMAADDR(d) \
145 ((d)->ut_mdesc->um_topdma + ((caddr_t)(d) - (d)->ut_mdesc->um_top))
146 #define UHCI_STD_SYNC(sc, d, ops) \
147 USB_MEM_SYNC2(&(sc)->sc_dmatag, &(d)->ut_mdesc->um_dma, (caddr_t)(d) - (d)->ut_mdesc->um_top , sizeof(uhci_td_t), (ops))
148
149 /*
150 * Extra information that we need for a QH.
151 */
152 struct uhci_soft_qh {
153 uhci_qh_t qh; /* The real QH, must be first */
154 uhci_soft_qh_t *hlink; /* soft version of qh_hlink */
155 uhci_soft_td_t *elink; /* soft version of qh_elink */
156 struct uhci_mem_desc *uq_mdesc; /* DMA memory desc */
157 int pos; /* Timeslot position */
158 };
159 /* See comment about UHCI_STD_SIZE. */
160 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
161 #define UHCI_SQH_CHUNK ((PAGE_SIZE - sizeof(struct uhci_mem_desc)) / UHCI_SQH_SIZE)
162 #define UHCI_SQH_DMAADDR(d) \
163 ((d)->uq_mdesc->um_topdma + ((caddr_t)(d) - (d)->uq_mdesc->um_top))
164 #define UHCI_SQH_SYNC(sc, d, ops) \
165 USB_MEM_SYNC2(&(sc)->sc_dmatag, &(d)->uq_mdesc->um_dma, (caddr_t)(d) - (d)->uq_mdesc->um_top , sizeof(uhci_qh_t), (ops))
166
167 /*
168 * Information about an entry in the virtual frame list.
169 */
170 struct uhci_vframe {
171 uhci_soft_td_t *htd; /* pointer to dummy TD */
172 uhci_soft_td_t *etd; /* pointer to last TD */
173 uhci_soft_qh_t *hqh; /* pointer to dummy QH */
174 uhci_soft_qh_t *eqh; /* pointer to last QH */
175 u_int bandwidth; /* max bandwidth used by this frame */
176 };
177
178 #define UHCI_SCFLG_DONEINIT 0x0001 /* uhci_init() done */
179
180 typedef struct uhci_softc {
181 struct usbd_bus sc_bus; /* base device */
182 int sc_flags;
183 bus_space_tag_t iot;
184 bus_space_handle_t ioh;
185 bus_size_t sc_size;
186 #if defined(__FreeBSD__)
187 void *ih;
188
189 struct resource *io_res;
190 struct resource *irq_res;
191 #endif
192
193 usb_dma_tag_t sc_dmatag;
194 uhci_physaddr_t *sc_pframes;
195 usb_dma_t sc_dma;
196 struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
197
198 uhci_soft_qh_t *sc_lctl_start; /* dummy QH for low speed control */
199 uhci_soft_qh_t *sc_lctl_end; /* last control QH */
200 uhci_soft_qh_t *sc_hctl_start; /* dummy QH for high speed control */
201 uhci_soft_qh_t *sc_hctl_end; /* last control QH */
202 uhci_soft_qh_t *sc_bulk_start; /* dummy QH for bulk */
203 uhci_soft_qh_t *sc_bulk_end; /* last bulk transfer */
204 uhci_soft_qh_t *sc_last_qh; /* dummy QH at the end */
205 u_int32_t sc_loops; /* number of QHs that wants looping */
206
207 uhci_soft_td_t *sc_freetds; /* TD free list */
208 uhci_soft_qh_t *sc_freeqhs; /* QH free list */
209 int sc_nfreetds;
210
211 SIMPLEQ_HEAD(uhci_mdescs, uhci_mem_desc)
212 sc_std_chunks, sc_sqh_chunks;
213
214 SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
215
216 u_int8_t sc_addr; /* device address */
217 u_int8_t sc_conf; /* device configuration */
218
219 u_int8_t sc_saved_sof;
220 u_int16_t sc_saved_frnum;
221
222 #ifdef USB_USE_SOFTINTR
223 char sc_softwake;
224 #endif /* USB_USE_SOFTINTR */
225
226 char sc_isreset;
227 char sc_suspend;
228 char sc_dying;
229
230 LIST_HEAD(, uhci_intr_info) sc_intrhead;
231
232 /* Info for the root hub interrupt channel. */
233 int sc_ival; /* time between root hub intrs */
234 usbd_xfer_handle sc_intr_xfer; /* root hub interrupt transfer */
235 usb_callout_t sc_poll_handle;
236
237 char sc_vendor[32]; /* vendor string for root hub */
238 int sc_id_vendor; /* vendor ID for root hub */
239
240 #if defined(__NetBSD__)
241 void *sc_powerhook; /* cookie from power hook */
242 void *sc_shutdownhook; /* cookie from shutdown hook */
243 #endif
244
245 #if defined(__NetBSD__) || defined(__OpenBSD__)
246 device_t sc_child; /* /dev/usb# device */
247 #endif
248 } uhci_softc_t;
249
250 usbd_status uhci_init(uhci_softc_t *);
251 int uhci_intr(void *);
252 int uhci_detach(uhci_softc_t *, int);
253 #if defined(__NetBSD__) || defined(__OpenBSD__)
254 int uhci_activate(device_t, enum devact);
255 #endif
256
257 void uhci_shutdown(void *v);
258 void uhci_power(int state, void *priv);
259
260