1/*	$NetBSD: uhcivar.h,v 1.47 2010/02/24 22:38:09 dyoung Exp $	*/
2/*	$FreeBSD: src/sys/dev/usb/uhcivar.h,v 1.14 1999/11/17 22:33:42 n_hibma Exp $	*/
3
4/*
5 * Copyright (c) 1998 The NetBSD Foundation, Inc.
6 * All rights reserved.
7 *
8 * This code is derived from software contributed to The NetBSD Foundation
9 * by Lennart Augustsson (lennart@augustsson.net) at
10 * Carlstedt Research & Technology.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * To avoid having 1024 TDs for each isochronous transfer we introduce
36 * a virtual frame list.  Every UHCI_VFRAMELIST_COUNT entries in the real
37 * frame list points to a non-active TD.  These, in turn, form the
38 * starts of the virtual frame list.  This also has the advantage that it
39 * simplifies linking in/out of TDs/QHs in the schedule.
40 * Furthermore, initially each of the inactive TDs point to an inactive
41 * QH that forms the start of the interrupt traffic for that slot.
42 * Each of these QHs point to the same QH that is the start of control
43 * traffic.  This QH points at another QH which is the start of the
44 * bulk traffic.
45 *
46 * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
47 */
48#define UHCI_VFRAMELIST_COUNT 128
49
50typedef struct uhci_soft_qh uhci_soft_qh_t;
51typedef struct uhci_soft_td uhci_soft_td_t;
52
53typedef union {
54	struct uhci_soft_qh *sqh;
55	struct uhci_soft_td *std;
56} uhci_soft_td_qh_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 */
65typedef struct uhci_intr_info {
66	struct uhci_softc *sc;
67	usbd_xfer_handle xfer;
68	uhci_soft_td_t *stdstart;
69	uhci_soft_td_t *stdend;
70	LIST_ENTRY(uhci_intr_info) list;
71	int isdone;	/* used only when DIAGNOSTIC is defined */
72} uhci_intr_info_t;
73
74struct uhci_xfer {
75	struct usbd_xfer xfer;
76	uhci_intr_info_t iinfo;
77	struct usb_task	abort_task;
78	int curframe;
79};
80
81#define UXFER(xfer) ((struct uhci_xfer *)(xfer))
82
83/*
84 * Extra information that we need for a TD.
85 */
86struct uhci_soft_td {
87	uhci_td_t td;			/* The real TD, must be first */
88	uhci_soft_td_qh_t link; 	/* soft version of the td_link field */
89	uhci_physaddr_t physaddr;	/* TD's physical address. */
90	usb_dma_t dma;			/* TD's DMA infos */
91	int offs;			/* TD's offset in usb_dma_t */
92};
93/*
94 * Make the size such that it is a multiple of UHCI_TD_ALIGN.  This way
95 * we can pack a number of soft TD together and have the real TD well
96 * aligned.
97 * NOTE: Minimum size is 32 bytes.
98 */
99#define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
100#define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
101
102/*
103 * Extra information that we need for a QH.
104 */
105struct uhci_soft_qh {
106	uhci_qh_t qh;			/* The real QH, must be first */
107	uhci_soft_qh_t *hlink;		/* soft version of qh_hlink */
108	uhci_soft_td_t *elink;		/* soft version of qh_elink */
109	uhci_physaddr_t physaddr;	/* QH's physical address. */
110	int pos;			/* Timeslot position */
111	usb_dma_t dma;			/* QH's DMA infos */
112	int offs;			/* QH's offset in usb_dma_t */
113};
114/* See comment about UHCI_STD_SIZE. */
115#define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
116#define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
117
118/*
119 * Information about an entry in the virtual frame list.
120 */
121struct uhci_vframe {
122	uhci_soft_td_t *htd;		/* pointer to dummy TD */
123	uhci_soft_td_t *etd;		/* pointer to last TD */
124	uhci_soft_qh_t *hqh;		/* pointer to dummy QH */
125	uhci_soft_qh_t *eqh;		/* pointer to last QH */
126	u_int bandwidth;		/* max bandwidth used by this frame */
127};
128
129typedef struct uhci_softc {
130	device_t sc_dev;
131	struct usbd_bus sc_bus;
132	bus_space_tag_t iot;
133	bus_space_handle_t ioh;
134	bus_size_t sc_size;
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	u_int32_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	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
153
154	u_int8_t sc_addr;		/* device address */
155	u_int8_t sc_conf;		/* device configuration */
156
157	u_int8_t sc_saved_sof;
158	u_int16_t sc_saved_frnum;
159
160#ifdef USB_USE_SOFTINTR
161	char sc_softwake;
162#endif /* USB_USE_SOFTINTR */
163
164	char sc_isreset;
165	char sc_suspend;
166	char sc_dying;
167
168	LIST_HEAD(, uhci_intr_info) sc_intrhead;
169
170	/* Info for the root hub interrupt "pipe". */
171	int sc_ival;			/* time between root hub intrs */
172	usbd_xfer_handle sc_intr_xfer;	/* root hub interrupt transfer */
173	struct callout sc_poll_handle;
174
175	char sc_vendor[32];		/* vendor string for root hub */
176	int sc_id_vendor;		/* vendor ID for root hub */
177
178#if defined(__NetBSD__) || defined(__OpenBSD__)
179	device_t sc_child;		/* /dev/usb# device */
180#endif
181#ifdef __NetBSD__
182	struct usb_dma_reserve sc_dma_reserve;
183#endif
184} uhci_softc_t;
185
186usbd_status	uhci_init(uhci_softc_t *);
187int		uhci_intr(void *);
188#if defined(__NetBSD__) || defined(__OpenBSD__)
189int		uhci_detach(uhci_softc_t *, int);
190void		uhci_childdet(device_t, device_t);
191int		uhci_activate(device_t, enum devact);
192bool		uhci_resume(device_t, const pmf_qual_t *);
193bool		uhci_suspend(device_t, const pmf_qual_t *);
194#endif
195
196