Home | History | Annotate | Line # | Download | only in usb
uhcivar.h revision 1.25
      1 /*	$NetBSD: uhcivar.h,v 1.25 2000/03/24 22:03:32 augustss 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 (augustss (at) carlstedt.se) 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, which form the
     45  * starts of the virtual frame list.  This also has the advantage that it
     46  * simplifies linking in/out TD/QH 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.
     51  *
     52  * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
     53  */
     54 #define UHCI_VFRAMELIST_COUNT 128
     55 
     56 typedef struct uhci_soft_qh uhci_soft_qh_t;
     57 typedef struct uhci_soft_td uhci_soft_td_t;
     58 
     59 typedef union {
     60 	struct uhci_soft_qh *sqh;
     61 	struct uhci_soft_td *std;
     62 } uhci_soft_td_qh_t;
     63 
     64 /*
     65  * An interrupt info struct contains the information needed to
     66  * execute a requested routine when the controller generates an
     67  * interrupt.  Since we cannot know which transfer generated
     68  * the interrupt all structs are linked together so they can be
     69  * searched at interrupt time.
     70  */
     71 typedef struct uhci_intr_info {
     72 	struct uhci_softc *sc;
     73 	usbd_xfer_handle xfer;
     74 	uhci_soft_td_t *stdstart;
     75 	uhci_soft_td_t *stdend;
     76 	LIST_ENTRY(uhci_intr_info) list;
     77 	usb_callout_t timeout_handle;
     78 #ifdef DIAGNOSTIC
     79 	int isdone;
     80 #endif
     81 } uhci_intr_info_t;
     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 };
     91 /*
     92  * Make the size such that it is a multiple of UHCI_TD_ALIGN.  This way
     93  * we can pack a number of soft TD together and have the real TD well
     94  * aligned.
     95  * NOTE: Minimum size is 32 bytes.
     96  */
     97 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
     98 #define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
     99 
    100 /*
    101  * Extra information that we need for a QH.
    102  */
    103 struct uhci_soft_qh {
    104 	uhci_qh_t qh;			/* The real QH, must be first */
    105 	uhci_soft_qh_t *hlink;		/* soft version of qh_hlink */
    106 	uhci_soft_td_t *elink;		/* soft version of qh_elink */
    107 	uhci_physaddr_t physaddr;	/* QH's physical address. */
    108 	int pos;			/* Timeslot position */
    109 	uhci_intr_info_t *intr_info;	/* Who to call on completion. */
    110 /* XXX should try to shrink with 4 bytes to fit into 32 bytes */
    111 };
    112 /* See comment about UHCI_STD_SIZE. */
    113 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
    114 #define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
    115 
    116 /*
    117  * Information about an entry in the virtual frame list.
    118  */
    119 struct uhci_vframe {
    120 	uhci_soft_td_t *htd;		/* pointer to dummy TD */
    121 	uhci_soft_td_t *etd;		/* pointer to last TD */
    122 	uhci_soft_qh_t *hqh;		/* pointer to dummy QH */
    123 	uhci_soft_qh_t *eqh;		/* pointer to last QH */
    124 	u_int bandwidth;		/* max bandwidth used by this frame */
    125 };
    126 
    127 typedef struct uhci_softc {
    128 	struct usbd_bus sc_bus;		/* base device */
    129 	bus_space_tag_t iot;
    130 	bus_space_handle_t ioh;
    131 
    132 	uhci_physaddr_t *sc_pframes;
    133 	usb_dma_t sc_dma;
    134 	struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
    135 
    136 	uhci_soft_qh_t *sc_ctl_start;	/* dummy QH for control */
    137 	uhci_soft_qh_t *sc_ctl_end;	/* last control QH */
    138 	uhci_soft_qh_t *sc_bulk_start;	/* dummy QH for bulk */
    139 	uhci_soft_qh_t *sc_bulk_end;	/* last bulk transfer */
    140 
    141 	uhci_soft_td_t *sc_freetds;	/* TD free list */
    142 	uhci_soft_qh_t *sc_freeqhs;	/* QH free list */
    143 
    144 	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
    145 
    146 	u_int8_t sc_addr;		/* device address */
    147 	u_int8_t sc_conf;		/* device configuration */
    148 
    149 	u_int8_t sc_saved_sof;
    150 	u_int16_t sc_saved_frnum;
    151 
    152 	char sc_isreset;
    153 	char sc_suspend;
    154 	char sc_dying;
    155 
    156 	LIST_HEAD(, uhci_intr_info) sc_intrhead;
    157 
    158 	/* Info for the root hub interrupt channel. */
    159 	int sc_ival;			/* time between root hug intrs */
    160 	usbd_xfer_handle sc_has_timo;	/* root hub interrupt transfer */
    161 
    162 	char sc_vflock;			/* for lock virtual frame list */
    163 #define UHCI_HAS_LOCK 1
    164 #define UHCI_WANT_LOCK 2
    165 
    166 	char sc_vendor[16];		/* vendor string for root hub */
    167 	int sc_id_vendor;		/* vendor ID for root hub */
    168 
    169 	void *sc_powerhook;		/* cookie from power hook */
    170 	void *sc_shutdownhook;		/* cookie from shutdown hook */
    171 
    172 	device_ptr_t sc_child;		/* /dev/usb device */
    173 } uhci_softc_t;
    174 
    175 usbd_status	uhci_init __P((uhci_softc_t *));
    176 int		uhci_intr __P((void *));
    177 #if defined(__NetBSD__) || defined(__OpenBSD__)
    178 int		uhci_detach __P((uhci_softc_t *, int));
    179 int		uhci_activate __P((device_ptr_t, enum devact));
    180 #endif
    181 
    182