Home | History | Annotate | Line # | Download | only in usb
ehcivar.h revision 1.24.14.1
      1 /*	$NetBSD: ehcivar.h,v 1.24.14.1 2007/05/22 14:57:35 itohy Exp $ */
      2 /*	$FreeBSD: /repoman/r/ncvs/src/sys/dev/usb/ehcivar.h,v 1.16 2006/09/07 00:06:41 imp Exp $	*/
      3 
      4 /*-
      5  * Copyright (c) 2001 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).
     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 struct ehci_mem_desc {
     41 	caddr_t		em_top;
     42 	ehci_physaddr_t	em_topdma;
     43 	usb_dma_t	em_dma;
     44 	SIMPLEQ_ENTRY(ehci_mem_desc) em_next;
     45 };
     46 
     47 typedef struct ehci_soft_qtd {
     48 	ehci_qtd_t qtd;
     49 	struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
     50 	struct ehci_mem_desc *et_mdesc;
     51 	usbd_xfer_handle xfer;
     52 	LIST_ENTRY(ehci_soft_qtd) hnext;
     53 	u_int16_t len;
     54 } ehci_soft_qtd_t;
     55 #define EHCI_SQTD_SIZE ((sizeof (struct ehci_soft_qtd) + EHCI_QTD_ALIGN - 1) / EHCI_QTD_ALIGN * EHCI_QTD_ALIGN)
     56 #define EHCI_SQTD_CHUNK ((EHCI_PAGE_SIZE - sizeof(struct ehci_mem_desc)) / EHCI_SQTD_SIZE)
     57 #define EHCI_SQTD_DMAADDR(d)	\
     58 	((d)->et_mdesc->em_topdma + ((caddr_t)(d) - (d)->et_mdesc->em_top))
     59 #define EHCI_SQTD_SYNC(sc, d, ops)	\
     60 	USB_MEM_SYNC2(&(sc)->sc_dmatag, &(d)->et_mdesc->em_dma, (caddr_t)(d) - (d)->et_mdesc->em_top , sizeof(ehci_qtd_t), (ops))
     61 
     62 typedef struct ehci_soft_qh {
     63 	ehci_qh_t qh;
     64 	struct ehci_soft_qh *next;
     65 	struct ehci_soft_qh *prev;
     66 	struct ehci_soft_qtd *sqtd;
     67 	struct ehci_soft_qtd *inactivesqtd;
     68 	struct ehci_mem_desc *eh_mdesc;
     69 	int islot;		/* Interrupt list slot. */
     70 } ehci_soft_qh_t;
     71 #define EHCI_SQH_SIZE ((sizeof (struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN)
     72 #define EHCI_SQH_CHUNK ((EHCI_PAGE_SIZE - sizeof(struct ehci_mem_desc)) / EHCI_SQH_SIZE)
     73 #define EHCI_SQH_DMAADDR(d)	\
     74 	((d)->eh_mdesc->em_topdma + ((caddr_t)(d) - (d)->eh_mdesc->em_top))
     75 #define EHCI_SQH_SYNC(sc, d, ops)	\
     76 	USB_MEM_SYNC2(&(sc)->sc_dmatag, &(d)->eh_mdesc->em_dma, (caddr_t)(d) - (d)->eh_mdesc->em_top , sizeof(ehci_qh_t), (ops))
     77 
     78 struct ehci_xfer {
     79 	struct usbd_xfer xfer;
     80 	struct usb_task	abort_task;
     81 	LIST_ENTRY(ehci_xfer) inext; /* list of active xfers */
     82 	ehci_soft_qtd_t *sqtdstart;
     83 	ehci_soft_qtd_t *sqtdend;
     84 	u_int32_t ehci_xfer_flags;
     85 	struct usb_buffer_dma dmabuf;
     86 	int rsvd_tds;
     87 #ifdef DIAGNOSTIC
     88 	int isdone;
     89 #endif
     90 };
     91 #define EHCI_XFER_ABORTING	0x0001	/* xfer is aborting. */
     92 #define EHCI_XFER_ABORTWAIT	0x0002	/* abort completion is being awaited. */
     93 
     94 #if 1	/* make sure the argument is actually an xfer pointer */
     95 #define EXFER(xfer) ((void)&(xfer)->hcpriv, (struct ehci_xfer *)(xfer))
     96 #else
     97 #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
     98 #endif
     99 
    100 /*
    101  * Information about an entry in the interrupt list.
    102  */
    103 struct ehci_soft_islot {
    104 	ehci_soft_qh_t *sqh;		/* Queue Head. */
    105 };
    106 
    107 #define EHCI_FRAMELIST_MAXCOUNT	1024
    108 #define EHCI_IPOLLRATES		8	/* Poll rates (1ms, 2, 4, 8 ... 128) */
    109 #define EHCI_INTRQHS		((1 << EHCI_IPOLLRATES) - 1)
    110 #define EHCI_MAX_POLLRATE	(1 << (EHCI_IPOLLRATES - 1))
    111 #define EHCI_IQHIDX(lev, pos)	\
    112 	((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
    113 #define EHCI_ILEV_IVAL(lev)	(1 << (lev))
    114 
    115 #define EHCI_HASH_SIZE 128
    116 #define EHCI_COMPANION_MAX 8
    117 
    118 #define EHCI_SCFLG_DONEINIT	0x0001	/* ehci_init() has been called. */
    119 #define EHCI_SCFLG_LOSTINTRBUG	0x0002	/* workaround for VIA / ATI chipsets */
    120 
    121 typedef struct ehci_softc {
    122 	struct usbd_bus sc_bus;		/* base device */
    123 	bus_space_tag_t iot;
    124 	bus_space_handle_t ioh;
    125 	bus_size_t sc_size;
    126 #if defined(__FreeBSD__)
    127 	void *ih;
    128 
    129 	struct resource *io_res;
    130 	struct resource *irq_res;
    131 #endif
    132 	u_int sc_offs;			/* offset to operational regs */
    133 	int sc_flags;			/* misc flags */
    134 #define EHCIF_DROPPED_INTR_WORKAROUND	0x01
    135 
    136 	char sc_vendor[32];		/* vendor string for root hub */
    137 	int sc_id_vendor;		/* vendor ID for root hub */
    138 
    139 	u_int32_t sc_cmd;		/* shadow of cmd reg during suspend */
    140 #if defined(__NetBSD__) || defined(__OpenBSD__)
    141 	void *sc_powerhook;		/* cookie from power hook */
    142 	void *sc_shutdownhook;		/* cookie from shutdown hook */
    143 #endif
    144 
    145 	u_int sc_ncomp;
    146 	u_int sc_npcomp;
    147 	struct usbd_bus *sc_comps[EHCI_COMPANION_MAX];
    148 
    149 	usb_dma_tag_t sc_dmatag;
    150 	usb_dma_t sc_fldma;
    151 	ehci_link_t *sc_flist;
    152 	u_int sc_flsize;
    153 #ifndef __FreeBSD__
    154 	u_int sc_rand;			/* XXX need proper intr scheduling */
    155 #endif
    156 
    157 	struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
    158 
    159 	LIST_HEAD(, ehci_xfer) sc_intrhead;
    160 
    161 	SIMPLEQ_HEAD(ehci_mdescs, ehci_mem_desc) sc_sqh_chunks, sc_sqtd_chunks;
    162 
    163 	ehci_soft_qh_t *sc_freeqhs;
    164 	ehci_soft_qtd_t *sc_freeqtds;
    165 	int sc_nfreeqtds;
    166 
    167 	int sc_noport;
    168 	u_int8_t sc_hasppc;		/* has Port Power Control */
    169 	u_int8_t sc_addr;		/* device address */
    170 	u_int8_t sc_conf;		/* device configuration */
    171 	usbd_xfer_handle sc_intrxfer;
    172 	char sc_isreset[EHCI_MAX_PORTS];
    173 #ifdef USB_USE_SOFTINTR
    174 	char sc_softwake;
    175 #endif /* USB_USE_SOFTINTR */
    176 
    177 	u_int32_t sc_eintrs;
    178 	ehci_soft_qh_t *sc_async_head;
    179 
    180 	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
    181 
    182 	struct lock sc_doorbell_lock;
    183 
    184 	usb_callout_t sc_tmo_intrlist;
    185 
    186 #if defined(__NetBSD__) || defined(__OpenBSD__)
    187 	device_t sc_child;		/* /dev/usb# device */
    188 #endif
    189 	char sc_dying;
    190 } ehci_softc_t;
    191 
    192 #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
    193 #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
    194 #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
    195 #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
    196 #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
    197 #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
    198 #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    199 #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    200 #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    201 #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    202 #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    203 #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    204 
    205 usbd_status	ehci_init(ehci_softc_t *);
    206 int		ehci_intr(void *);
    207 int		ehci_detach(ehci_softc_t *, int);
    208 #if defined(__NetBSD__) || defined(__OpenBSD__)
    209 int		ehci_activate(device_t, enum devact);
    210 #endif
    211 void		ehci_power(int state, void *priv);
    212 void		ehci_shutdown(void *v);
    213 
    214 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
    215 
    216