xref: /openbsd/sys/dev/usb/uhcivar.h (revision 72bb8292)
1 /*	$OpenBSD: uhcivar.h,v 1.24 2010/12/14 16:13:16 jakemsr Exp $ */
2 /*	$NetBSD: uhcivar.h,v 1.36 2002/12/31 00:39:11 augustss Exp $	*/
3 /*	$FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.14 1999/11/17 22:33:42 n_hibma Exp $	*/
4 
5 /*
6  * Copyright (c) 1998 The NetBSD Foundation, Inc.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to The NetBSD Foundation
10  * by Lennart Augustsson (lennart@augustsson.net) at
11  * Carlstedt Research & Technology.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 /*
36  * To avoid having 1024 TDs for each isochronous transfer we introduce
37  * a virtual frame list.  Every UHCI_VFRAMELIST_COUNT entries in the real
38  * frame list points to a non-active TD.  These, in turn, form the
39  * starts of the virtual frame list.  This also has the advantage that it
40  * simplifies linking in/out of TDs/QHs in the schedule.
41  * Furthermore, initially each of the inactive TDs point to an inactive
42  * QH that forms the start of the interrupt traffic for that slot.
43  * Each of these QHs point to the same QH that is the start of control
44  * traffic.  This QH points at another QH which is the start of the
45  * bulk traffic.
46  *
47  * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
48  */
49 #define UHCI_VFRAMELIST_COUNT 128
50 
51 typedef struct uhci_soft_qh uhci_soft_qh_t;
52 typedef struct uhci_soft_td uhci_soft_td_t;
53 
54 typedef union {
55 	struct uhci_soft_qh *sqh;
56 	struct uhci_soft_td *std;
57 } uhci_soft_td_qh_t;
58 
59 /*
60  * An interrupt info struct contains the information needed to
61  * execute a requested routine when the controller generates an
62  * interrupt.  Since we cannot know which transfer generated
63  * the interrupt all structs are linked together so they can be
64  * searched at interrupt time.
65  */
66 typedef struct uhci_intr_info {
67 	struct uhci_softc *sc;
68 	usbd_xfer_handle xfer;
69 	uhci_soft_td_t *stdstart;
70 	uhci_soft_td_t *stdend;
71 	LIST_ENTRY(uhci_intr_info) list;
72 #ifdef DIAGNOSTIC
73 	int isdone;
74 #endif
75 } uhci_intr_info_t;
76 
77 struct uhci_xfer {
78 	struct usbd_xfer xfer;
79 	uhci_intr_info_t iinfo;
80 	struct usb_task	abort_task;
81 	int curframe;
82 };
83 
84 #define UXFER(xfer) ((struct uhci_xfer *)(xfer))
85 
86 /*
87  * Extra information that we need for a TD.
88  */
89 struct uhci_soft_td {
90 	uhci_td_t td;			/* The real TD, must be first */
91 	uhci_soft_td_qh_t link; 	/* soft version of the td_link field */
92 	uhci_physaddr_t physaddr;	/* TD's physical address. */
93 };
94 /*
95  * Make the size such that it is a multiple of UHCI_TD_ALIGN.  This way
96  * we can pack a number of soft TD together and have the real TD well
97  * aligned.
98  * NOTE: Minimum size is 32 bytes.
99  */
100 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
101 #define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
102 
103 /*
104  * Extra information that we need for a QH.
105  */
106 struct uhci_soft_qh {
107 	uhci_qh_t qh;			/* The real QH, must be first */
108 	uhci_soft_qh_t *hlink;		/* soft version of qh_hlink */
109 	uhci_soft_td_t *elink;		/* soft version of qh_elink */
110 	uhci_physaddr_t physaddr;	/* QH's physical address. */
111 	int pos;			/* Timeslot position */
112 };
113 /* See comment about UHCI_STD_SIZE. */
114 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
115 #define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
116 
117 /*
118  * Information about an entry in the virtual frame list.
119  */
120 struct uhci_vframe {
121 	uhci_soft_td_t *htd;		/* pointer to dummy TD */
122 	uhci_soft_td_t *etd;		/* pointer to last TD */
123 	uhci_soft_qh_t *hqh;		/* pointer to dummy QH */
124 	uhci_soft_qh_t *eqh;		/* pointer to last QH */
125 	u_int bandwidth;		/* max bandwidth used by this frame */
126 };
127 
128 typedef struct uhci_softc {
129 	struct usbd_bus sc_bus;		/* base device */
130 	bus_space_tag_t iot;
131 	bus_space_handle_t ioh;
132 	bus_size_t sc_size;
133 
134 	uhci_physaddr_t *sc_pframes;
135 	usb_dma_t sc_dma;
136 	struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
137 
138 	uhci_soft_qh_t *sc_lctl_start;	/* dummy QH for low speed control */
139 	uhci_soft_qh_t *sc_lctl_end;	/* last control QH */
140 	uhci_soft_qh_t *sc_hctl_start;	/* dummy QH for high speed control */
141 	uhci_soft_qh_t *sc_hctl_end;	/* last control QH */
142 	uhci_soft_qh_t *sc_bulk_start;	/* dummy QH for bulk */
143 	uhci_soft_qh_t *sc_bulk_end;	/* last bulk transfer */
144 	uhci_soft_qh_t *sc_last_qh;	/* dummy QH at the end */
145 	u_int32_t sc_loops;		/* number of QHs that wants looping */
146 
147 	uhci_soft_td_t *sc_freetds;	/* TD free list */
148 	uhci_soft_qh_t *sc_freeqhs;	/* QH free list */
149 
150 	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
151 
152 	u_int8_t sc_addr;		/* device address */
153 	u_int8_t sc_conf;		/* device configuration */
154 
155 	u_int8_t sc_saved_sof;
156 	u_int16_t sc_saved_frnum;
157 
158 	char sc_softwake;
159 
160 	char sc_isreset;
161 	char sc_suspend;
162 
163 	LIST_HEAD(, uhci_intr_info) sc_intrhead;
164 
165 	/* Info for the root hub interrupt "pipe". */
166 	int sc_ival;			/* time between root hub intrs */
167 	usbd_xfer_handle sc_intr_xfer;	/* root hub interrupt transfer */
168 	struct timeout 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 	void *sc_shutdownhook;		/* cookie from shutdown hook */
174 
175 	struct device *sc_child;		/* /dev/usb# device */
176 } uhci_softc_t;
177 
178 usbd_status	uhci_init(uhci_softc_t *);
179 usbd_status	uhci_run(uhci_softc_t *, int run);
180 int		uhci_intr(void *);
181 int		uhci_detach(uhci_softc_t *, int);
182 int		uhci_activate(struct device *, int);
183