xref: /openbsd/sys/dev/usb/uhcivar.h (revision ca68072a)
1 /*	$OpenBSD: uhcivar.h,v 1.33 2014/05/18 17:10:27 mpi 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 struct uhci_soft_qh;
52 struct uhci_soft_td;
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 struct uhci_xfer {
67 	struct usbd_xfer xfer;
68 	LIST_ENTRY(uhci_xfer) inext;
69 	struct uhci_soft_td *stdstart;
70 	struct uhci_soft_td *stdend;
71 	int curframe;
72 #ifdef DIAGNOSTIC
73 	int isdone;
74 #endif
75 };
76 
77 /*
78  * Extra information that we need for a TD.
79  */
80 struct uhci_soft_td {
81 	struct uhci_td td;		/* The real TD, must be first */
82 	uhci_soft_td_qh_t link; 	/* soft version of the td_link field */
83 	uhci_physaddr_t physaddr;	/* TD's physical address. */
84 };
85 /*
86  * Make the size such that it is a multiple of UHCI_TD_ALIGN.  This way
87  * we can pack a number of soft TD together and have the real TD well
88  * aligned.
89  * NOTE: Minimum size is 32 bytes.
90  */
91 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
92 #define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
93 
94 /*
95  * Extra information that we need for a QH.
96  */
97 struct uhci_soft_qh {
98 	struct uhci_qh qh;		/* The real QH, must be first */
99 	struct uhci_soft_qh *hlink;	/* soft version of qh_hlink */
100 	struct uhci_soft_td *elink;	/* soft version of qh_elink */
101 	uhci_physaddr_t physaddr;	/* QH's physical address. */
102 	int pos;			/* Timeslot position */
103 };
104 /* See comment about UHCI_STD_SIZE. */
105 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
106 #define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
107 
108 /*
109  * Information about an entry in the virtual frame list.
110  */
111 struct uhci_vframe {
112 	struct uhci_soft_td *htd;	/* pointer to dummy TD */
113 	struct uhci_soft_td *etd;	/* pointer to last TD */
114 	struct uhci_soft_qh *hqh;	/* pointer to dummy QH */
115 	struct uhci_soft_qh *eqh;	/* pointer to last QH */
116 	u_int bandwidth;		/* max bandwidth used by this frame */
117 };
118 
119 struct uhci_softc {
120 	struct usbd_bus sc_bus;		/* base device */
121 	bus_space_tag_t iot;
122 	bus_space_handle_t ioh;
123 	bus_size_t sc_size;
124 
125 	uhci_physaddr_t *sc_pframes;
126 	struct usb_dma sc_dma;
127 	struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
128 
129 	struct uhci_soft_qh *sc_lctl_start; /* dummy QH for low speed control */
130 	struct uhci_soft_qh *sc_lctl_end; /* last control QH */
131 	struct uhci_soft_qh *sc_hctl_start;/* dummy QH for high speed control */
132 	struct uhci_soft_qh *sc_hctl_end; /* last control QH */
133 	struct uhci_soft_qh *sc_bulk_start; /* dummy QH for bulk */
134 	struct uhci_soft_qh *sc_bulk_end; /* last bulk transfer */
135 	struct uhci_soft_qh *sc_last_qh; /* dummy QH at the end */
136 	u_int32_t sc_loops;		/* number of QHs that wants looping */
137 
138 	struct uhci_soft_td *sc_freetds; /* TD free list */
139 	struct uhci_soft_qh *sc_freeqhs; /* QH free list */
140 
141 	u_int8_t sc_conf;		/* device configuration */
142 
143 	u_int8_t sc_saved_sof;
144 	u_int16_t sc_saved_frnum;
145 
146 	char sc_softwake;
147 
148 	char sc_isreset;
149 	char sc_suspend;
150 
151 	LIST_HEAD(, uhci_xfer) sc_intrhead;
152 
153 	/* Info for the root hub interrupt "pipe". */
154 	struct usbd_xfer	*sc_intrxfer;
155 	struct timeout		 sc_root_intr;
156 
157 	char sc_vendor[32];		/* vendor string for root hub */
158 	int sc_id_vendor;		/* vendor ID for root hub */
159 };
160 
161 usbd_status	uhci_init(struct uhci_softc *);
162 usbd_status	uhci_run(struct uhci_softc *, int run);
163 int		uhci_intr(void *);
164 int		uhci_detach(struct device *, int);
165 int		uhci_activate(struct device *, int);
166