]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/usb/uhcivar.h
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / dev / usb / uhcivar.h
1 /*      $NetBSD: uhcivar.h,v 1.33 2002/02/11 11:41:30 augustss Exp $    */
2 /*      $FreeBSD$       */
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  * 3. All advertising materials mentioning features or use of this software
21  *    must display the following acknowledgement:
22  *        This product includes software developed by the NetBSD
23  *        Foundation, Inc. and its contributors.
24  * 4. Neither the name of The NetBSD Foundation nor the names of its
25  *    contributors may be used to endorse or promote products derived
26  *    from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  */
40
41 /*
42  * To avoid having 1024 TDs for each isochronous transfer we introduce
43  * a virtual frame list.  Every UHCI_VFRAMELIST_COUNT entries in the real
44  * frame list points to a non-active TD.  These, in turn, form the
45  * starts of the virtual frame list.  This also has the advantage that it
46  * simplifies linking in/out of TDs/QHs in the schedule.
47  * Furthermore, initially each of the inactive TDs point to an inactive
48  * QH that forms the start of the interrupt traffic for that slot.
49  * Each of these QHs point to the same QH that is the start of control
50  * traffic.  This QH points at another QH which is the start of the
51  * bulk traffic.
52  *
53  * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
54  */
55 #define UHCI_VFRAMELIST_COUNT 128
56
57 typedef struct uhci_soft_qh uhci_soft_qh_t;
58 typedef struct uhci_soft_td uhci_soft_td_t;
59
60 typedef union {
61         struct uhci_soft_qh *sqh;
62         struct uhci_soft_td *std;
63 } uhci_soft_td_qh_t;
64
65 /*
66  * An interrupt info struct contains the information needed to
67  * execute a requested routine when the controller generates an
68  * interrupt.  Since we cannot know which transfer generated
69  * the interrupt all structs are linked together so they can be
70  * searched at interrupt time.
71  */
72 typedef struct uhci_intr_info {
73         struct uhci_softc *sc;
74         usbd_xfer_handle xfer;
75         uhci_soft_td_t *stdstart;
76         uhci_soft_td_t *stdend;
77         LIST_ENTRY(uhci_intr_info) list;
78 #ifdef DIAGNOSTIC
79         int isdone;
80 #endif
81 } uhci_intr_info_t;
82
83 struct uhci_xfer {
84         struct usbd_xfer xfer;
85         uhci_intr_info_t iinfo;
86         struct usb_task abort_task;
87         int curframe;
88         u_int32_t uhci_xfer_flags;
89 };
90
91 #define UHCI_XFER_ABORTING      0x0001  /* xfer is aborting. */
92 #define UHCI_XFER_ABORTWAIT     0x0002  /* abort completion is being awaited. */
93
94 #define UXFER(xfer) ((struct uhci_xfer *)(xfer))
95
96 /*
97  * Extra information that we need for a TD.
98  */
99 struct uhci_soft_td {
100         uhci_td_t td;                   /* The real TD, must be first */
101         uhci_soft_td_qh_t link;         /* soft version of the td_link field */
102         uhci_physaddr_t physaddr;       /* TD's physical address. */
103         usb_dma_t aux_dma;              /* Auxillary storage if needed. */
104         void *aux_data;                 /* Original aux data virtual address. */
105         int aux_len;                    /* Auxillary storage size. */
106 };
107 /*
108  * Make the size such that it is a multiple of UHCI_TD_ALIGN.  This way
109  * we can pack a number of soft TD together and have the real TD well
110  * aligned.
111  * NOTE: Minimum size is 32 bytes.
112  */
113 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
114 #define UHCI_STD_CHUNK (PAGE_SIZE / UHCI_STD_SIZE)
115
116 /*
117  * Extra information that we need for a QH.
118  */
119 struct uhci_soft_qh {
120         uhci_qh_t qh;                   /* The real QH, must be first */
121         uhci_soft_qh_t *hlink;          /* soft version of qh_hlink */
122         uhci_soft_td_t *elink;          /* soft version of qh_elink */
123         uhci_physaddr_t physaddr;       /* QH's physical address. */
124         int pos;                        /* Timeslot position */
125 };
126 /* See comment about UHCI_STD_SIZE. */
127 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
128 #define UHCI_SQH_CHUNK (PAGE_SIZE / UHCI_SQH_SIZE)
129
130 /*
131  * Information about an entry in the virtual frame list.
132  */
133 struct uhci_vframe {
134         uhci_soft_td_t *htd;            /* pointer to dummy TD */
135         uhci_soft_td_t *etd;            /* pointer to last TD */
136         uhci_soft_qh_t *hqh;            /* pointer to dummy QH */
137         uhci_soft_qh_t *eqh;            /* pointer to last QH */
138         u_int bandwidth;                /* max bandwidth used by this frame */
139 };
140
141 #define UHCI_SCFLG_DONEINIT     0x0001  /* uhci_init() done */
142
143 typedef struct uhci_softc {
144         struct usbd_bus sc_bus;         /* base device */
145         int sc_flags;
146         bus_space_tag_t iot;
147         bus_space_handle_t ioh;
148         bus_size_t sc_size;
149         void *ih;
150
151         struct resource *io_res;
152         struct resource *irq_res;
153         uhci_physaddr_t *sc_pframes;
154         usb_dma_t sc_dma;
155         struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
156
157         uhci_soft_qh_t *sc_lctl_start;  /* dummy QH for low speed control */
158         uhci_soft_qh_t *sc_lctl_end;    /* last control QH */
159         uhci_soft_qh_t *sc_hctl_start;  /* dummy QH for high speed control */
160         uhci_soft_qh_t *sc_hctl_end;    /* last control QH */
161         uhci_soft_qh_t *sc_bulk_start;  /* dummy QH for bulk */
162         uhci_soft_qh_t *sc_bulk_end;    /* last bulk transfer */
163         uhci_soft_qh_t *sc_last_qh;     /* dummy QH at the end */
164         u_int32_t sc_loops;             /* number of QHs that wants looping */
165
166         uhci_soft_td_t *sc_freetds;     /* TD free list */
167         uhci_soft_qh_t *sc_freeqhs;     /* QH free list */
168
169         STAILQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
170
171         u_int8_t sc_addr;               /* device address */
172         u_int8_t sc_conf;               /* device configuration */
173
174         u_int8_t sc_saved_sof;
175         u_int16_t sc_saved_frnum;
176
177 #ifdef USB_USE_SOFTINTR
178         char sc_softwake;
179 #endif /* USB_USE_SOFTINTR */
180
181         char sc_isreset;
182         char sc_suspend;
183         char sc_dying;
184
185         LIST_HEAD(, uhci_intr_info) sc_intrhead;
186
187         /* Info for the root hub interrupt channel. */
188         int sc_ival;                    /* time between root hub intrs */
189         usbd_xfer_handle sc_intr_xfer;  /* root hub interrupt transfer */
190         struct callout sc_poll_handle;
191
192         char sc_vendor[16];             /* vendor string for root hub */
193         int sc_id_vendor;               /* vendor ID for root hub */
194
195 #if defined(__NetBSD__)
196         void *sc_powerhook;             /* cookie from power hook */
197         void *sc_shutdownhook;          /* cookie from shutdown hook */
198 #endif
199 } uhci_softc_t;
200
201 usbd_status     uhci_init(uhci_softc_t *);
202 int             uhci_intr(void *);
203 int             uhci_detach(uhci_softc_t *, int);
204 void            uhci_shutdown(void *v);
205 void            uhci_power(int state, void *priv);
206