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