uhcivar.h revision 1.4 1 /* $NetBSD: uhcivar.h,v 1.4 1998/11/25 22:32:05 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 /*
59 * An interrupt info struct contains the information needed to
60 * execute a requested routine when the controller generates an
61 * interrupt. Since we cannot know which transfer generated
62 * the interrupt all structs are linked together so they can be
63 * searched at interrupt time.
64 */
65 typedef struct uhci_intr_info {
66 struct uhci_softc *sc;
67 usbd_request_handle reqh;
68 uhci_soft_td_t *stdstart;
69 uhci_soft_td_t *stdend;
70 LIST_ENTRY(uhci_intr_info) list;
71 #ifdef DIAGNOSTIC
72 int isdone;
73 #endif
74 } uhci_intr_info_t;
75
76 /*
77 * Extra information that we need for a TD.
78 */
79 struct uhci_soft_td {
80 uhci_td_t *td; /* The real TD */
81 uhci_physaddr_t physaddr; /* and its physical address. */
82 };
83 #define UHCI_TD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
84
85 /*
86 * Extra information that we need for a QH.
87 */
88 struct uhci_soft_qh {
89 uhci_qh_t *qh; /* The real QH */
90 uhci_physaddr_t physaddr; /* and its physical address. */
91 int pos; /* Timeslot position */
92 uhci_intr_info_t *intr_info; /* Who to call on completion. */
93 };
94 #define UHCI_QH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
95
96 /* Only used for buffer free list. */
97 struct uhci_buffer {
98 struct uhci_buffer *next;
99 };
100 #define UHCI_BUFFER_SIZE 64
101 #define UHCI_BUFFER_CHUNK 64 /*(PAGE_SIZE / UHCI_BUFFER_SIZE)*/
102
103 /*
104 * Information about an entry in the virtial frame list.
105 */
106 struct uhci_vframe {
107 uhci_soft_td_t *htd; /* pointer to dummy TD */
108 uhci_soft_td_t *etd; /* pointer to last TD */
109 uhci_soft_qh_t *hqh; /* pointer to dummy QH */
110 uhci_soft_qh_t *eqh; /* pointer to last QH */
111 u_int bandwidth; /* max bandwidth used by this frame */
112 };
113
114 typedef struct uhci_softc {
115 struct usbd_bus sc_bus; /* base device */
116 void *sc_ih; /* interrupt vectoring */
117 bus_space_tag_t iot;
118 bus_space_handle_t ioh;
119
120 bus_dma_tag_t sc_dmatag; /* DMA tag */
121 /* XXX should keep track of all DMA memory */
122
123 uhci_physaddr_t *sc_pframes;
124 struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
125
126 uhci_soft_qh_t *sc_ctl_start; /* dummy QH for control */
127 uhci_soft_qh_t *sc_ctl_end; /* last control QH */
128 uhci_soft_qh_t *sc_bulk_start; /* dummy QH for bulk */
129 uhci_soft_qh_t *sc_bulk_end; /* last bulk transfer */
130
131 uhci_soft_td_t *sc_freetds;
132 uhci_soft_qh_t *sc_freeqhs;
133 struct uhci_buffer *sc_freebuffers;
134
135 u_int8_t sc_addr; /* device address */
136 u_int8_t sc_conf; /* device configuration */
137
138 char sc_isreset;
139
140 int sc_intrs;
141 LIST_HEAD(, uhci_intr_info) sc_intrhead;
142
143 /* Info for the root hub interrupt channel. */
144 int sc_ival;
145
146 char sc_vflock;
147 #define UHCI_HAS_LOCK 1
148 #define UHCI_WANT_LOCK 2
149
150 usb_dma_t *sc_mallocs;
151
152 char sc_vendor[16];
153 } uhci_softc_t;
154
155 usbd_status uhci_init __P((uhci_softc_t *));
156 int uhci_intr __P((void *));
157 #if 0
158 void uhci_reset __P((void *));
159 #endif
160
161 #ifdef USB_DEBUG
162 #define DPRINTF(x) if (uhcidebug) printf x
163 #define DPRINTFN(n,x) if (uhcidebug>(n)) printf x
164 extern int uhcidebug;
165 #else
166 #define DPRINTF(x)
167 #define DPRINTFN(n,x)
168 #endif
169
170