Home | History | Annotate | Line # | Download | only in usb
uhcivar.h revision 1.7
      1 /*	$NetBSD: uhcivar.h,v 1.7 1999/06/26 08:30:18 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 /* Only used for buffer free list. */
    100 struct uhci_buffer {
    101 	struct uhci_buffer *next;
    102 };
    103 #define UHCI_BUFFER_SIZE 64
    104 #define UHCI_BUFFER_CHUNK 64 	/*(PAGE_SIZE / UHCI_BUFFER_SIZE)*/
    105 
    106 /*
    107  * Information about an entry in the virtial frame list.
    108  */
    109 struct uhci_vframe {
    110 	uhci_soft_td_t *htd;		/* pointer to dummy TD */
    111 	uhci_soft_td_t *etd;		/* pointer to last TD */
    112 	uhci_soft_qh_t *hqh;		/* pointer to dummy QH */
    113 	uhci_soft_qh_t *eqh;		/* pointer to last QH */
    114 	u_int bandwidth;		/* max bandwidth used by this frame */
    115 };
    116 
    117 typedef struct uhci_softc {
    118 	struct usbd_bus sc_bus;		/* base device */
    119 #if defined(__NetBSD__)
    120 	void *sc_ih;			/* interrupt vectoring */
    121 	bus_space_tag_t iot;
    122 	bus_space_handle_t ioh;
    123 
    124 	bus_dma_tag_t sc_dmatag;	/* DMA tag */
    125 	/* XXX should keep track of all DMA memory */
    126 #elif defined(__FreeBSD__)
    127 	int		sc_iobase;
    128 	int		unit;
    129 #endif /* defined(__FreeBSD__) */
    130 
    131 	uhci_physaddr_t *sc_pframes;
    132 	usb_dma_t sc_dma;
    133 	struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
    134 
    135 	uhci_soft_qh_t *sc_ctl_start;	/* dummy QH for control */
    136 	uhci_soft_qh_t *sc_ctl_end;	/* last control QH */
    137 	uhci_soft_qh_t *sc_bulk_start;	/* dummy QH for bulk */
    138 	uhci_soft_qh_t *sc_bulk_end;	/* last bulk transfer */
    139 
    140 	uhci_soft_td_t *sc_freetds;
    141 	uhci_soft_qh_t *sc_freeqhs;
    142 	struct uhci_buffer *sc_freebuffers;
    143 
    144 	u_int8_t sc_addr;		/* device address */
    145 	u_int8_t sc_conf;		/* device configuration */
    146 
    147 	char sc_isreset;
    148 
    149 	char sc_suspend;
    150 	usbd_request_handle sc_has_timo;
    151 
    152 	int sc_intrs;
    153 	LIST_HEAD(, uhci_intr_info) sc_intrhead;
    154 
    155 	/* Info for the root hub interrupt channel. */
    156 	int sc_ival;
    157 
    158 	char sc_vflock;
    159 #define UHCI_HAS_LOCK 1
    160 #define UHCI_WANT_LOCK 2
    161 
    162 #if defined(__NetBSD__)
    163 	usb_dma_t *sc_mallocs;
    164 #endif
    165 
    166 	char sc_vendor[16];
    167 	int sc_id_vendor;
    168 } uhci_softc_t;
    169 
    170 usbd_status	uhci_init __P((uhci_softc_t *));
    171 int		uhci_intr __P((void *));
    172 #if 0
    173 void		uhci_reset __P((void *));
    174 #endif
    175 
    176 #ifdef USB_DEBUG
    177 #define DPRINTF(x)	if (uhcidebug) printf x
    178 #define DPRINTFN(n,x)	if (uhcidebug>(n)) printf x
    179 extern int uhcidebug;
    180 #else
    181 #define DPRINTF(x)
    182 #define DPRINTFN(n,x)
    183 #endif
    184 
    185