Home | History | Annotate | Line # | Download | only in usb
uhcivar.h revision 1.40.38.1
      1 /*	$NetBSD: uhcivar.h,v 1.40.38.1 2008/09/04 08:46:45 skrll 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 (at) 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 	int isdone;	/* used only when DIAGNOSTIC is defined */
     79 } uhci_intr_info_t;
     80 
     81 struct uhci_xfer {
     82 	struct usbd_xfer xfer;
     83 	uhci_intr_info_t iinfo;
     84 	struct usb_task	abort_task;
     85 	int curframe;
     86 };
     87 
     88 #define UXFER(xfer) ((struct uhci_xfer *)(xfer))
     89 
     90 /*
     91  * Extra information that we need for a TD.
     92  */
     93 struct uhci_soft_td {
     94 	uhci_td_t td;			/* The real TD, must be first */
     95 	uhci_soft_td_qh_t link; 	/* soft version of the td_link field */
     96 	uhci_physaddr_t physaddr;	/* TD's physical address. */
     97 	usb_dma_t dma;			/* TD's DMA infos */
     98 	int offs;			/* TD's offset in usb_dma_t */
     99 };
    100 /*
    101  * Make the size such that it is a multiple of UHCI_TD_ALIGN.  This way
    102  * we can pack a number of soft TD together and have the real TD well
    103  * aligned.
    104  * NOTE: Minimum size is 32 bytes.
    105  */
    106 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
    107 #define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
    108 
    109 /*
    110  * Extra information that we need for a QH.
    111  */
    112 struct uhci_soft_qh {
    113 	uhci_qh_t qh;			/* The real QH, must be first */
    114 	uhci_soft_qh_t *hlink;		/* soft version of qh_hlink */
    115 	uhci_soft_td_t *elink;		/* soft version of qh_elink */
    116 	uhci_physaddr_t physaddr;	/* QH's physical address. */
    117 	int pos;			/* Timeslot position */
    118 	usb_dma_t dma;			/* QH's DMA infos */
    119 	int offs;			/* QH's offset in usb_dma_t */
    120 };
    121 /* See comment about UHCI_STD_SIZE. */
    122 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
    123 #define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
    124 
    125 /*
    126  * Information about an entry in the virtual frame list.
    127  */
    128 struct uhci_vframe {
    129 	uhci_soft_td_t *htd;		/* pointer to dummy TD */
    130 	uhci_soft_td_t *etd;		/* pointer to last TD */
    131 	uhci_soft_qh_t *hqh;		/* pointer to dummy QH */
    132 	uhci_soft_qh_t *eqh;		/* pointer to last QH */
    133 	u_int bandwidth;		/* max bandwidth used by this frame */
    134 };
    135 
    136 typedef struct uhci_softc {
    137 	struct usbd_bus sc_bus;		/* base device */
    138 	bus_space_tag_t iot;
    139 	bus_space_handle_t ioh;
    140 	bus_size_t sc_size;
    141 
    142 	uhci_physaddr_t *sc_pframes;
    143 	usb_dma_t sc_dma;
    144 	struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
    145 
    146 	uhci_soft_qh_t *sc_lctl_start;	/* dummy QH for low speed control */
    147 	uhci_soft_qh_t *sc_lctl_end;	/* last control QH */
    148 	uhci_soft_qh_t *sc_hctl_start;	/* dummy QH for high speed control */
    149 	uhci_soft_qh_t *sc_hctl_end;	/* last control QH */
    150 	uhci_soft_qh_t *sc_bulk_start;	/* dummy QH for bulk */
    151 	uhci_soft_qh_t *sc_bulk_end;	/* last bulk transfer */
    152 	uhci_soft_qh_t *sc_last_qh;	/* dummy QH at the end */
    153 	u_int32_t sc_loops;		/* number of QHs that wants looping */
    154 
    155 	uhci_soft_td_t *sc_freetds;	/* TD free list */
    156 	uhci_soft_qh_t *sc_freeqhs;	/* QH free list */
    157 
    158 	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
    159 
    160 	u_int8_t sc_addr;		/* device address */
    161 	u_int8_t sc_conf;		/* device configuration */
    162 
    163 	u_int8_t sc_saved_sof;
    164 	u_int16_t sc_saved_frnum;
    165 
    166 #ifdef USB_USE_SOFTINTR
    167 	char sc_softwake;
    168 #endif /* USB_USE_SOFTINTR */
    169 
    170 	char sc_isreset;
    171 	char sc_suspend;
    172 	char sc_dying;
    173 
    174 	LIST_HEAD(, uhci_intr_info) sc_intrhead;
    175 
    176 	/* Info for the root hub interrupt "pipe". */
    177 	int sc_ival;			/* time between root hub intrs */
    178 	usbd_xfer_handle sc_intr_xfer;	/* root hub interrupt transfer */
    179 	usb_callout_t sc_poll_handle;
    180 
    181 	char sc_vendor[32];		/* vendor string for root hub */
    182 	int sc_id_vendor;		/* vendor ID for root hub */
    183 
    184 	void *sc_powerhook;		/* cookie from power hook */
    185 	void *sc_shutdownhook;		/* cookie from shutdown hook */
    186 
    187 #if defined(__NetBSD__) || defined(__OpenBSD__)
    188 	device_ptr_t sc_child;		/* /dev/usb# device */
    189 #endif
    190 #ifdef __NetBSD__
    191 	struct usb_dma_reserve sc_dma_reserve;
    192 #endif
    193 } uhci_softc_t;
    194 
    195 usbd_status	uhci_init(uhci_softc_t *);
    196 int		uhci_intr(void *);
    197 #if defined(__NetBSD__) || defined(__OpenBSD__)
    198 int		uhci_detach(uhci_softc_t *, int);
    199 int		uhci_activate(device_ptr_t, enum devact);
    200 #endif
    201 
    202