Home | History | Annotate | Line # | Download | only in usb
uhcivar.h revision 1.16
      1 /*	$NetBSD: uhcivar.h,v 1.16 1999/10/13 08:10:56 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 typedef union {
     59 	struct uhci_soft_qh *sqh;
     60 	struct uhci_soft_td *std;
     61 } uhci_soft_td_qh_t;
     62 
     63 /*
     64  * An interrupt info struct contains the information needed to
     65  * execute a requested routine when the controller generates an
     66  * interrupt.  Since we cannot know which transfer generated
     67  * the interrupt all structs are linked together so they can be
     68  * searched at interrupt time.
     69  */
     70 typedef struct uhci_intr_info {
     71 	struct uhci_softc *sc;
     72 	usbd_request_handle reqh;
     73 	uhci_soft_td_t *stdstart;
     74 	uhci_soft_td_t *stdend;
     75 	LIST_ENTRY(uhci_intr_info) list;
     76 #if defined(__FreeBSD__)
     77 	struct callout_handle timeout_handle;
     78 #endif /* defined(__FreeBSD__) */
     79 #ifdef DIAGNOSTIC
     80 	int isdone;
     81 #endif
     82 } uhci_intr_info_t;
     83 
     84 /*
     85  * Extra information that we need for a TD.
     86  */
     87 struct uhci_soft_td {
     88 	uhci_td_t td;			/* The real TD, must be first */
     89 	uhci_soft_td_qh_t link; 	/* soft version of the td_link field */
     90 	uhci_physaddr_t physaddr;	/* TD's physical address. */
     91 };
     92 /*
     93  * Make the size such that it is a multiple of UHCI_TD_ALIGN.  This way
     94  * we can pack a number of soft TD together and have the real TS well
     95  * aligned.
     96  * NOTE: Minimum size is 32 bytes.
     97  */
     98 #define UHCI_STD_SIZE ((sizeof (struct uhci_soft_td) + UHCI_TD_ALIGN - 1) / UHCI_TD_ALIGN * UHCI_TD_ALIGN)
     99 #define UHCI_STD_CHUNK 128 /*(PAGE_SIZE / UHCI_TD_SIZE)*/
    100 
    101 /*
    102  * Extra information that we need for a QH.
    103  */
    104 struct uhci_soft_qh {
    105 	uhci_qh_t qh;			/* The real QH, must be first */
    106 	uhci_soft_qh_t *hlink;		/* soft version of qh_hlink */
    107 	uhci_soft_td_t *elink;		/* soft version of qh_elink */
    108 	uhci_physaddr_t physaddr;	/* QH's physical address. */
    109 	int pos;			/* Timeslot position */
    110 	uhci_intr_info_t *intr_info;	/* Who to call on completion. */
    111 /* XXX should try to shrink with 4 bytes to fit into 32 bytes */
    112 };
    113 /* See comment about UHCI_STD_SIZE. */
    114 #define UHCI_SQH_SIZE ((sizeof (struct uhci_soft_qh) + UHCI_QH_ALIGN - 1) / UHCI_QH_ALIGN * UHCI_QH_ALIGN)
    115 #define UHCI_SQH_CHUNK 128 /*(PAGE_SIZE / UHCI_QH_SIZE)*/
    116 
    117 /*
    118  * Information about an entry in the virtial frame list.
    119  */
    120 struct uhci_vframe {
    121 	uhci_soft_td_t *htd;		/* pointer to dummy TD */
    122 	uhci_soft_td_t *etd;		/* pointer to last TD */
    123 	uhci_soft_qh_t *hqh;		/* pointer to dummy QH */
    124 	uhci_soft_qh_t *eqh;		/* pointer to last QH */
    125 	u_int bandwidth;		/* max bandwidth used by this frame */
    126 };
    127 
    128 typedef struct uhci_softc {
    129 	struct usbd_bus sc_bus;		/* base device */
    130 	bus_space_tag_t iot;
    131 	bus_space_handle_t ioh;
    132 
    133 	uhci_physaddr_t *sc_pframes;
    134 	usb_dma_t sc_dma;
    135 	struct uhci_vframe sc_vframes[UHCI_VFRAMELIST_COUNT];
    136 
    137 	uhci_soft_qh_t *sc_ctl_start;	/* dummy QH for control */
    138 	uhci_soft_qh_t *sc_ctl_end;	/* last control QH */
    139 	uhci_soft_qh_t *sc_bulk_start;	/* dummy QH for bulk */
    140 	uhci_soft_qh_t *sc_bulk_end;	/* last bulk transfer */
    141 
    142 	uhci_soft_td_t *sc_freetds;
    143 	uhci_soft_qh_t *sc_freeqhs;
    144 
    145 	u_int8_t sc_addr;		/* device address */
    146 	u_int8_t sc_conf;		/* device configuration */
    147 
    148 	char sc_isreset;
    149 
    150 	char sc_suspend;
    151 	usbd_request_handle sc_has_timo;
    152 
    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 	char sc_vendor[16];
    163 	int sc_id_vendor;
    164 
    165 	void *sc_powerhook;
    166 	device_ptr_t sc_child;
    167 } uhci_softc_t;
    168 
    169 usbd_status	uhci_init __P((uhci_softc_t *));
    170 int		uhci_intr __P((void *));
    171 int		uhci_detach __P((uhci_softc_t *, int));
    172 int		uhci_activate __P((device_ptr_t, enum devact));
    173 
    174