uhcivar.h revision 1.11 1 /* $NetBSD: uhcivar.h,v 1.11 1999/08/22 23:19:57 augustss Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss (at) carlstedt.se) at
9 * Carlstedt Research & Technology.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
26 *
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.
38 */
39
40 /*
41 * To avoid having 1024 TDs for each isochronous transfer we introduce
42 * a virtual frame list. Every UHCI_VFRAMELIST_COUNT entries in the real
43 * frame list points to a non-active TD. These, in turn, which form the
44 * starts of the virtual frame list. This also has the advantage that it
45 * simplifies linking in/out TD/QH in the schedule.
46 * Furthermore, initially each of the inactive TDs point to an inactive
47 * QH that forms the start of the interrupt traffic for that slot.
48 * Each of these QHs point to the same QH that is the start of control
49 * traffic.
50 *
51 * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
52 */
53 #define UHCI_VFRAMELIST_COUNT 128
54
55 typedef struct uhci_soft_qh uhci_soft_qh_t;
56 typedef struct uhci_soft_td uhci_soft_td_t;
57
58 typedef union {
59 struct uhci_soft_qh *sqh;
60 struct uhci_soft_td *std;
61 } uhci_soft_td_qh_t;
62
63 /*
64 * An interrupt info struct contains the information needed to
65 * execute a requested routine when the controller generates an
66 * interrupt. Since we cannot know which transfer generated
67 * the interrupt all structs are linked together so they can be
68 * searched at interrupt time.
69 */
70 typedef struct uhci_intr_info {
71 struct uhci_softc *sc;
72 usbd_request_handle reqh;
73 uhci_soft_td_t *stdstart;
74 uhci_soft_td_t *stdend;
75 LIST_ENTRY(uhci_intr_info) list;
76 #if defined(__FreeBSD__)
77 struct callout_handle timeout_handle;
78 #endif /* defined(__FreeBSD__) */
79 #ifdef DIAGNOSTIC
80 int isdone;
81 #endif
82 } uhci_intr_info_t;
83
84 /*
85 * Extra information that we need for a TD.
86 */
87 struct uhci_soft_td {
88 uhci_td_t td; /* The real TD, must be first */
89 uhci_soft_td_qh_t link; /* soft version of the td_link field */
90 uhci_physaddr_t physaddr; /* TD's physical address. */
91 };
92 /*
93 * Make the size such that it is a multiple of UHCI_TD_ALIGN. This way
94 * we can pack a number of soft TD together and have the real TS well
95 * aligned.
96 */
97 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
98 #define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
99
100 /*
101 * Extra information that we need for a QH.
102 */
103 struct uhci_soft_qh {
104 uhci_qh_t qh; /* The real QH, must be first */
105 uhci_soft_qh_t *hlink; /* soft version of qh_hlink */
106 uhci_soft_td_t *elink; /* soft version of qh_elink */
107 uhci_physaddr_t physaddr; /* QH's physical address. */
108 int pos; /* Timeslot position */
109 uhci_intr_info_t *intr_info; /* Who to call on completion. */
110 };
111 /* See comment about UHCI_STD_SIZE. */
112 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_td) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
113 #define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
114
115 /*
116 * Information about an entry in the virtial frame list.
117 */
118 struct uhci_vframe {
119 uhci_soft_td_t *htd; /* pointer to dummy TD */
120 uhci_soft_td_t *etd; /* pointer to last TD */
121 uhci_soft_qh_t *hqh; /* pointer to dummy QH */
122 uhci_soft_qh_t *eqh; /* pointer to last QH */
123 u_int bandwidth; /* max bandwidth used by this frame */
124 };
125
126 typedef struct uhci_softc {
127 struct usbd_bus sc_bus; /* base device */
128 bus_space_tag_t iot;
129 bus_space_handle_t ioh;
130 #if defined(__NetBSD__) || defined(__OpenBSD__)
131 void *sc_ih; /* interrupt vectoring */
132
133 bus_dma_tag_t sc_dmatag; /* DMA tag */
134 /* XXX should keep track of all DMA memory */
135 #endif /* defined(__FreeBSD__) */
136
137 uhci_physaddr_t *sc_pframes;
138 usb_dma_t sc_dma;
139 struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
140
141 uhci_soft_qh_t *sc_ctl_start; /* dummy QH for control */
142 uhci_soft_qh_t *sc_ctl_end; /* last control QH */
143 uhci_soft_qh_t *sc_bulk_start; /* dummy QH for bulk */
144 uhci_soft_qh_t *sc_bulk_end; /* last bulk transfer */
145
146 uhci_soft_td_t *sc_freetds;
147 uhci_soft_qh_t *sc_freeqhs;
148
149 u_int8_t sc_addr; /* device address */
150 u_int8_t sc_conf; /* device configuration */
151
152 char sc_isreset;
153
154 char sc_suspend;
155 usbd_request_handle sc_has_timo;
156
157 int sc_intrs;
158 LIST_HEAD(, uhci_intr_info) sc_intrhead;
159
160 /* Info for the root hub interrupt channel. */
161 int sc_ival;
162
163 char sc_vflock;
164 #define UHCI_HAS_LOCK 1
165 #define UHCI_WANT_LOCK 2
166
167 char sc_vendor[16];
168 int sc_id_vendor;
169 } uhci_softc_t;
170
171 usbd_status uhci_init __P((uhci_softc_t *));
172 int uhci_intr __P((void *));
173 #if 0
174 void uhci_reset __P((void *));
175 #endif
176
177 #ifdef USB_DEBUG
178 #define DPRINTF(x) if (uhcidebug) printf x
179 #define DPRINTFN(n,x) if (uhcidebug>(n)) printf x
180 extern int uhcidebug;
181 #else
182 #define DPRINTF(x)
183 #define DPRINTFN(n,x)
184 #endif
185
186