1 /* $NetBSD: uhcivar.h,v 1.50 2012/03/06 02:49:03 mrg 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 50 typedef struct uhci_soft_qh uhci_soft_qh_t; 51 typedef struct uhci_soft_td uhci_soft_td_t; 52 53 typedef 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 */ 65 typedef 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 74 struct 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 */ 86 struct 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 */ 105 struct 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 */ 121 struct 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 129 typedef 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 char sc_softwake; 161 162 char sc_isreset; 163 char sc_suspend; 164 char sc_dying; 165 166 LIST_HEAD(, uhci_intr_info) sc_intrhead; 167 168 /* Info for the root hub interrupt "pipe". */ 169 int sc_ival; /* time between root hub intrs */ 170 usbd_xfer_handle sc_intr_xfer; /* root hub interrupt transfer */ 171 struct callout sc_poll_handle; 172 173 char sc_vendor[32]; /* vendor string for root hub */ 174 int sc_id_vendor; /* vendor ID for root hub */ 175 176 device_t sc_child; /* /dev/usb# device */ 177 struct usb_dma_reserve sc_dma_reserve; 178 } uhci_softc_t; 179 180 usbd_status uhci_init(uhci_softc_t *); 181 int uhci_intr(void *); 182 int uhci_detach(uhci_softc_t *, int); 183 void uhci_childdet(device_t, device_t); 184 int uhci_activate(device_t, enum devact); 185 bool uhci_resume(device_t, const pmf_qual_t *); 186 bool uhci_suspend(device_t, const pmf_qual_t *); 187