Home | History | Annotate | Line # | Download | only in usb
uhcivar.h revision 1.10
      1 /*	$NetBSD: uhcivar.h,v 1.10 1999/08/22 20:12:39 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Lennart Augustsson (augustss (at) carlstedt.se) at
      9  * Carlstedt Research & Technology.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *        This product includes software developed by the NetBSD
     22  *        Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * To avoid having 1024 TDs for each isochronous transfer we introduce
     42  * a virtual frame list.  Every UHCI_VFRAMELIST_COUNT entries in the real
     43  * frame list points to a non-active TD.  These, in turn, which form the
     44  * starts of the virtual frame list.  This also has the advantage that it
     45  * simplifies linking in/out TD/QH in the schedule.
     46  * Furthermore, initially each of the inactive TDs point to an inactive
     47  * QH that forms the start of the interrupt traffic for that slot.
     48  * Each of these QHs point to the same QH that is the start of control
     49  * traffic.
     50  *
     51  * UHCI_VFRAMELIST_COUNT should be a power of 2 and <= UHCI_FRAMELIST_COUNT.
     52  */
     53 #define UHCI_VFRAMELIST_COUNT 128
     54 
     55 typedef struct uhci_soft_qh uhci_soft_qh_t;
     56 typedef struct uhci_soft_td uhci_soft_td_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_request_handle reqh;
     68 	uhci_soft_td_t *stdstart;
     69 	uhci_soft_td_t *stdend;
     70 	LIST_ENTRY(uhci_intr_info) list;
     71 #if defined(__FreeBSD__)
     72 	struct callout_handle timeout_handle;
     73 #endif /* defined(__FreeBSD__) */
     74 #ifdef DIAGNOSTIC
     75 	int isdone;
     76 #endif
     77 } uhci_intr_info_t;
     78 
     79 /*
     80  * Extra information that we need for a TD.
     81  */
     82 struct uhci_soft_td {
     83 	uhci_td_t *td;			/* The real TD */
     84 	uhci_physaddr_t physaddr;	/* and its physical address. */
     85 };
     86 #define UHCI_TD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
     87 
     88 /*
     89  * Extra information that we need for a QH.
     90  */
     91 struct uhci_soft_qh {
     92 	uhci_qh_t *qh;			/* The real QH */
     93 	uhci_physaddr_t physaddr;	/* and its physical address. */
     94 	int pos;			/* Timeslot position */
     95 	uhci_intr_info_t *intr_info;	/* Who to call on completion. */
     96 };
     97 #define UHCI_QH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
     98 
     99 #define UHCI_BUFFER_SIZE 64
    100 #define UHCI_BUFFER_CHUNK 64 	/*(PAGE_SIZE / UHCI_BUFFER_SIZE)*/
    101 
    102 /*
    103  * Information about an entry in the virtial frame list.
    104  */
    105 struct uhci_vframe {
    106 	uhci_soft_td_t *htd;		/* pointer to dummy TD */
    107 	uhci_soft_td_t *etd;		/* pointer to last TD */
    108 	uhci_soft_qh_t *hqh;		/* pointer to dummy QH */
    109 	uhci_soft_qh_t *eqh;		/* pointer to last QH */
    110 	u_int bandwidth;		/* max bandwidth used by this frame */
    111 };
    112 
    113 typedef struct uhci_softc {
    114 	struct usbd_bus sc_bus;		/* base device */
    115 	bus_space_tag_t iot;
    116 	bus_space_handle_t ioh;
    117 #if defined(__NetBSD__) || defined(__OpenBSD__)
    118 	void *sc_ih;			/* interrupt vectoring */
    119 
    120 	bus_dma_tag_t sc_dmatag;	/* DMA tag */
    121 	/* XXX should keep track of all DMA memory */
    122 #endif /* defined(__FreeBSD__) */
    123 
    124 	uhci_physaddr_t *sc_pframes;
    125 	usb_dma_t sc_dma;
    126 	struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
    127 
    128 	uhci_soft_qh_t *sc_ctl_start;	/* dummy QH for control */
    129 	uhci_soft_qh_t *sc_ctl_end;	/* last control QH */
    130 	uhci_soft_qh_t *sc_bulk_start;	/* dummy QH for bulk */
    131 	uhci_soft_qh_t *sc_bulk_end;	/* last bulk transfer */
    132 
    133 	uhci_soft_td_t *sc_freetds;
    134 	uhci_soft_qh_t *sc_freeqhs;
    135 
    136 	u_int8_t sc_addr;		/* device address */
    137 	u_int8_t sc_conf;		/* device configuration */
    138 
    139 	char sc_isreset;
    140 
    141 	char sc_suspend;
    142 	usbd_request_handle sc_has_timo;
    143 
    144 	int sc_intrs;
    145 	LIST_HEAD(, uhci_intr_info) sc_intrhead;
    146 
    147 	/* Info for the root hub interrupt channel. */
    148 	int sc_ival;
    149 
    150 	char sc_vflock;
    151 #define UHCI_HAS_LOCK 1
    152 #define UHCI_WANT_LOCK 2
    153 
    154 #if defined(__NetBSD__) || defined(__OpenBSD__)
    155 	usb_dma_t *sc_mallocs;
    156 #endif
    157 
    158 	char sc_vendor[16];
    159 	int sc_id_vendor;
    160 } uhci_softc_t;
    161 
    162 usbd_status	uhci_init __P((uhci_softc_t *));
    163 int		uhci_intr __P((void *));
    164 #if 0
    165 void		uhci_reset __P((void *));
    166 #endif
    167 
    168 #ifdef USB_DEBUG
    169 #define DPRINTF(x)	if (uhcidebug) printf x
    170 #define DPRINTFN(n,x)	if (uhcidebug>(n)) printf x
    171 extern int uhcidebug;
    172 #else
    173 #define DPRINTF(x)
    174 #define DPRINTFN(n,x)
    175 #endif
    176 
    177