uhcivar.h revision 1.52.14.11 1 /* $NetBSD: uhcivar.h,v 1.52.14.11 2015/10/27 14:05:29 skrll 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 (lennart (at) augustsson.net) 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #ifndef _UHCIVAR_H_
34 #define _UHCIVAR_H_
35
36 #include <sys/pool.h>
37
38 /*
39 * To avoid having 1024 TDs for each isochronous transfer we introduce
40 * a virtual frame list. Every UHCI_VFRAMELIST_COUNT entries in the real
41 * frame list points to a non-active TD. These, in turn, form the
42 * starts of the virtual frame list. This also has the advantage that it
43 * simplifies linking in/out of TDs/QHs in the schedule.
44 * Furthermore, initially each of the inactive TDs point to an inactive
45 * QH that forms the start of the interrupt traffic for that slot.
46 * Each of these QHs point to the same QH that is the start of control
47 * traffic. This QH points at another QH which is the start of the
48 * bulk traffic.
49 *
50 * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
51 */
52 #define UHCI_VFRAMELIST_COUNT 128
53
54 typedef struct uhci_soft_qh uhci_soft_qh_t;
55 typedef struct uhci_soft_td uhci_soft_td_t;
56
57 typedef union {
58 struct uhci_soft_qh *sqh;
59 struct uhci_soft_td *std;
60 } uhci_soft_td_qh_t;
61
62 struct uhci_xfer {
63 struct usbd_xfer xfer;
64 struct usb_task abort_task;
65 uhci_soft_td_t *stdstart;
66 uhci_soft_td_t *stdend;
67 TAILQ_ENTRY(uhci_xfer) list;
68 int curframe;
69 bool isdone; /* used only when DIAGNOSTIC is defined */
70 };
71
72 #define UHCI_BUS2SC(bus) ((bus)->ub_hcpriv)
73 #define UHCI_PIPE2SC(pipe) UHCI_BUS2SC((pipe)->up_dev->ud_bus)
74 #define UHCI_XFER2SC(xfer) UHCI_BUS2SC((xfer)->ux_bus)
75 #define UHCI_UPIPE2SC(d) UHCI_BUS2SC((d)->pipe.up_dev->ud_bus)
76
77 #define UHCI_XFER2UXFER(xfer) ((struct uhci_xfer *)(xfer))
78
79 /*
80 * Extra information that we need for a TD.
81 */
82 struct uhci_soft_td {
83 uhci_td_t td; /* The real TD, must be first */
84 uhci_soft_td_qh_t link; /* soft version of the td_link field */
85 uhci_physaddr_t physaddr; /* TD's physical address. */
86 usb_dma_t dma; /* TD's DMA infos */
87 int offs; /* TD's offset in usb_dma_t */
88 };
89 /*
90 * Make the size such that it is a multiple of UHCI_TD_ALIGN. This way
91 * we can pack a number of soft TD together and have the real TD well
92 * aligned.
93 * NOTE: Minimum size is 32 bytes.
94 */
95 #define UHCI_STD_SIZE ((sizeof(struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
96 #define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
97
98 /*
99 * Extra information that we need for a QH.
100 */
101 struct uhci_soft_qh {
102 uhci_qh_t qh; /* The real QH, must be first */
103 uhci_soft_qh_t *hlink; /* soft version of qh_hlink */
104 uhci_soft_td_t *elink; /* soft version of qh_elink */
105 uhci_physaddr_t physaddr; /* QH's physical address. */
106 int pos; /* Timeslot position */
107 usb_dma_t dma; /* QH's DMA infos */
108 int offs; /* QH's offset in usb_dma_t */
109 };
110 /* See comment about UHCI_STD_SIZE. */
111 #define UHCI_SQH_SIZE ((sizeof(struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
112 #define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
113
114 /*
115 * Information about an entry in the virtual frame list.
116 */
117 struct uhci_vframe {
118 uhci_soft_td_t *htd; /* pointer to dummy TD */
119 uhci_soft_td_t *etd; /* pointer to last TD */
120 uhci_soft_qh_t *hqh; /* pointer to dummy QH */
121 uhci_soft_qh_t *eqh; /* pointer to last QH */
122 u_int bandwidth; /* max bandwidth used by this frame */
123 };
124
125 typedef struct uhci_softc {
126 device_t sc_dev;
127 struct usbd_bus sc_bus;
128 bus_space_tag_t iot;
129 bus_space_handle_t ioh;
130 bus_size_t sc_size;
131
132 kmutex_t sc_lock;
133 kmutex_t sc_intr_lock;
134 kcondvar_t sc_softwake_cv;
135
136 uhci_physaddr_t *sc_pframes;
137 usb_dma_t sc_dma;
138 struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
139
140 uhci_soft_qh_t *sc_lctl_start; /* dummy QH for low speed control */
141 uhci_soft_qh_t *sc_lctl_end; /* last control QH */
142 uhci_soft_qh_t *sc_hctl_start; /* dummy QH for high speed control */
143 uhci_soft_qh_t *sc_hctl_end; /* last control QH */
144 uhci_soft_qh_t *sc_bulk_start; /* dummy QH for bulk */
145 uhci_soft_qh_t *sc_bulk_end; /* last bulk transfer */
146 uhci_soft_qh_t *sc_last_qh; /* dummy QH at the end */
147 uint32_t sc_loops; /* number of QHs that wants looping */
148
149 uhci_soft_td_t *sc_freetds; /* TD free list */
150 uhci_soft_qh_t *sc_freeqhs; /* QH free list */
151
152 pool_cache_t sc_xferpool; /* free xfer pool */
153
154 uint8_t sc_saved_sof;
155 uint16_t sc_saved_frnum;
156
157 char sc_softwake;
158
159 char sc_isreset;
160 char sc_suspend;
161 char sc_dying;
162
163 TAILQ_HEAD(, uhci_xfer) sc_intrhead;
164
165 /* Info for the root hub interrupt "pipe". */
166 int sc_ival; /* time between root hub intrs */
167 struct usbd_xfer *sc_intr_xfer; /* root hub interrupt transfer */
168 struct callout sc_poll_handle;
169
170 char sc_vendor[32]; /* vendor string for root hub */
171 int sc_id_vendor; /* vendor ID for root hub */
172
173 device_t sc_child; /* /dev/usb# device */
174 } uhci_softc_t;
175
176 int uhci_init(uhci_softc_t *);
177 int uhci_intr(void *);
178 int uhci_detach(uhci_softc_t *, int);
179 void uhci_childdet(device_t, device_t);
180 int uhci_activate(device_t, enum devact);
181 bool uhci_resume(device_t, const pmf_qual_t *);
182 bool uhci_suspend(device_t, const pmf_qual_t *);
183
184 #endif /* _UHCIVAR_H_ */
185