Home | History | Annotate | Line # | Download | only in usb
ehcivar.h revision 1.24.14.1
      1  1.24.14.1     itohy /*	$NetBSD: ehcivar.h,v 1.24.14.1 2007/05/22 14:57:35 itohy Exp $ */
      2  1.24.14.1     itohy /*	$FreeBSD: /repoman/r/ncvs/src/sys/dev/usb/ehcivar.h,v 1.16 2006/09/07 00:06:41 imp Exp $	*/
      3        1.1  augustss 
      4  1.24.14.1     itohy /*-
      5        1.4  augustss  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      6        1.1  augustss  * All rights reserved.
      7        1.1  augustss  *
      8        1.1  augustss  * This code is derived from software contributed to The NetBSD Foundation
      9        1.1  augustss  * by Lennart Augustsson (lennart (at) augustsson.net).
     10        1.1  augustss  *
     11        1.1  augustss  * Redistribution and use in source and binary forms, with or without
     12        1.1  augustss  * modification, are permitted provided that the following conditions
     13        1.1  augustss  * are met:
     14        1.1  augustss  * 1. Redistributions of source code must retain the above copyright
     15        1.1  augustss  *    notice, this list of conditions and the following disclaimer.
     16        1.1  augustss  * 2. Redistributions in binary form must reproduce the above copyright
     17        1.1  augustss  *    notice, this list of conditions and the following disclaimer in the
     18        1.1  augustss  *    documentation and/or other materials provided with the distribution.
     19        1.1  augustss  * 3. All advertising materials mentioning features or use of this software
     20        1.1  augustss  *    must display the following acknowledgement:
     21        1.1  augustss  *        This product includes software developed by the NetBSD
     22        1.1  augustss  *        Foundation, Inc. and its contributors.
     23        1.1  augustss  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24        1.1  augustss  *    contributors may be used to endorse or promote products derived
     25        1.1  augustss  *    from this software without specific prior written permission.
     26        1.1  augustss  *
     27        1.1  augustss  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28        1.1  augustss  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29        1.1  augustss  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30        1.1  augustss  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31        1.1  augustss  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32        1.1  augustss  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33        1.1  augustss  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34        1.1  augustss  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35        1.1  augustss  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36        1.1  augustss  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37        1.1  augustss  * POSSIBILITY OF SUCH DAMAGE.
     38        1.1  augustss  */
     39        1.1  augustss 
     40  1.24.14.1     itohy struct ehci_mem_desc {
     41  1.24.14.1     itohy 	caddr_t		em_top;
     42  1.24.14.1     itohy 	ehci_physaddr_t	em_topdma;
     43  1.24.14.1     itohy 	usb_dma_t	em_dma;
     44  1.24.14.1     itohy 	SIMPLEQ_ENTRY(ehci_mem_desc) em_next;
     45  1.24.14.1     itohy };
     46  1.24.14.1     itohy 
     47        1.7  augustss typedef struct ehci_soft_qtd {
     48        1.7  augustss 	ehci_qtd_t qtd;
     49        1.7  augustss 	struct ehci_soft_qtd *nextqtd; /* mirrors nextqtd in TD */
     50  1.24.14.1     itohy 	struct ehci_mem_desc *et_mdesc;
     51        1.7  augustss 	usbd_xfer_handle xfer;
     52        1.7  augustss 	LIST_ENTRY(ehci_soft_qtd) hnext;
     53        1.7  augustss 	u_int16_t len;
     54        1.7  augustss } ehci_soft_qtd_t;
     55        1.7  augustss #define EHCI_SQTD_SIZE ((sizeof (struct ehci_soft_qtd) + EHCI_QTD_ALIGN - 1) / EHCI_QTD_ALIGN * EHCI_QTD_ALIGN)
     56  1.24.14.1     itohy #define EHCI_SQTD_CHUNK ((EHCI_PAGE_SIZE - sizeof(struct ehci_mem_desc)) / EHCI_SQTD_SIZE)
     57  1.24.14.1     itohy #define EHCI_SQTD_DMAADDR(d)	\
     58  1.24.14.1     itohy 	((d)->et_mdesc->em_topdma + ((caddr_t)(d) - (d)->et_mdesc->em_top))
     59  1.24.14.1     itohy #define EHCI_SQTD_SYNC(sc, d, ops)	\
     60  1.24.14.1     itohy 	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        1.7  augustss 
     62        1.7  augustss typedef struct ehci_soft_qh {
     63        1.7  augustss 	ehci_qh_t qh;
     64        1.7  augustss 	struct ehci_soft_qh *next;
     65  1.24.14.1     itohy 	struct ehci_soft_qh *prev;
     66        1.9  augustss 	struct ehci_soft_qtd *sqtd;
     67  1.24.14.1     itohy 	struct ehci_soft_qtd *inactivesqtd;
     68  1.24.14.1     itohy 	struct ehci_mem_desc *eh_mdesc;
     69  1.24.14.1     itohy 	int islot;		/* Interrupt list slot. */
     70        1.7  augustss } ehci_soft_qh_t;
     71        1.7  augustss #define EHCI_SQH_SIZE ((sizeof (struct ehci_soft_qh) + EHCI_QH_ALIGN - 1) / EHCI_QH_ALIGN * EHCI_QH_ALIGN)
     72  1.24.14.1     itohy #define EHCI_SQH_CHUNK ((EHCI_PAGE_SIZE - sizeof(struct ehci_mem_desc)) / EHCI_SQH_SIZE)
     73  1.24.14.1     itohy #define EHCI_SQH_DMAADDR(d)	\
     74  1.24.14.1     itohy 	((d)->eh_mdesc->em_topdma + ((caddr_t)(d) - (d)->eh_mdesc->em_top))
     75  1.24.14.1     itohy #define EHCI_SQH_SYNC(sc, d, ops)	\
     76  1.24.14.1     itohy 	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        1.7  augustss 
     78       1.11  augustss struct ehci_xfer {
     79       1.11  augustss 	struct usbd_xfer xfer;
     80       1.11  augustss 	struct usb_task	abort_task;
     81       1.11  augustss 	LIST_ENTRY(ehci_xfer) inext; /* list of active xfers */
     82       1.11  augustss 	ehci_soft_qtd_t *sqtdstart;
     83       1.11  augustss 	ehci_soft_qtd_t *sqtdend;
     84  1.24.14.1     itohy 	u_int32_t ehci_xfer_flags;
     85  1.24.14.1     itohy 	struct usb_buffer_dma dmabuf;
     86  1.24.14.1     itohy 	int rsvd_tds;
     87  1.24.14.1     itohy #ifdef DIAGNOSTIC
     88  1.24.14.1     itohy 	int isdone;
     89  1.24.14.1     itohy #endif
     90       1.11  augustss };
     91  1.24.14.1     itohy #define EHCI_XFER_ABORTING	0x0001	/* xfer is aborting. */
     92  1.24.14.1     itohy #define EHCI_XFER_ABORTWAIT	0x0002	/* abort completion is being awaited. */
     93  1.24.14.1     itohy 
     94  1.24.14.1     itohy #if 1	/* make sure the argument is actually an xfer pointer */
     95  1.24.14.1     itohy #define EXFER(xfer) ((void)&(xfer)->hcpriv, (struct ehci_xfer *)(xfer))
     96  1.24.14.1     itohy #else
     97       1.11  augustss #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
     98  1.24.14.1     itohy #endif
     99       1.11  augustss 
    100  1.24.14.1     itohy /*
    101  1.24.14.1     itohy  * Information about an entry in the interrupt list.
    102  1.24.14.1     itohy  */
    103       1.15  augustss struct ehci_soft_islot {
    104  1.24.14.1     itohy 	ehci_soft_qh_t *sqh;		/* Queue Head. */
    105       1.15  augustss };
    106       1.15  augustss 
    107       1.15  augustss #define EHCI_FRAMELIST_MAXCOUNT	1024
    108  1.24.14.1     itohy #define EHCI_IPOLLRATES		8	/* Poll rates (1ms, 2, 4, 8 ... 128) */
    109       1.15  augustss #define EHCI_INTRQHS		((1 << EHCI_IPOLLRATES) - 1)
    110       1.18  augustss #define EHCI_MAX_POLLRATE	(1 << (EHCI_IPOLLRATES - 1))
    111  1.24.14.1     itohy #define EHCI_IQHIDX(lev, pos)	\
    112       1.15  augustss 	((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
    113       1.15  augustss #define EHCI_ILEV_IVAL(lev)	(1 << (lev))
    114       1.15  augustss 
    115        1.7  augustss #define EHCI_HASH_SIZE 128
    116        1.3  augustss #define EHCI_COMPANION_MAX 8
    117        1.7  augustss 
    118  1.24.14.1     itohy #define EHCI_SCFLG_DONEINIT	0x0001	/* ehci_init() has been called. */
    119  1.24.14.1     itohy #define EHCI_SCFLG_LOSTINTRBUG	0x0002	/* workaround for VIA / ATI chipsets */
    120  1.24.14.1     itohy 
    121        1.1  augustss typedef struct ehci_softc {
    122        1.1  augustss 	struct usbd_bus sc_bus;		/* base device */
    123        1.1  augustss 	bus_space_tag_t iot;
    124        1.1  augustss 	bus_space_handle_t ioh;
    125        1.1  augustss 	bus_size_t sc_size;
    126  1.24.14.1     itohy #if defined(__FreeBSD__)
    127  1.24.14.1     itohy 	void *ih;
    128  1.24.14.1     itohy 
    129  1.24.14.1     itohy 	struct resource *io_res;
    130  1.24.14.1     itohy 	struct resource *irq_res;
    131  1.24.14.1     itohy #endif
    132        1.2  augustss 	u_int sc_offs;			/* offset to operational regs */
    133       1.23   xtraeme 	int sc_flags;			/* misc flags */
    134       1.23   xtraeme #define EHCIF_DROPPED_INTR_WORKAROUND	0x01
    135        1.1  augustss 
    136       1.19  augustss 	char sc_vendor[32];		/* vendor string for root hub */
    137        1.1  augustss 	int sc_id_vendor;		/* vendor ID for root hub */
    138        1.1  augustss 
    139       1.13  augustss 	u_int32_t sc_cmd;		/* shadow of cmd reg during suspend */
    140  1.24.14.1     itohy #if defined(__NetBSD__) || defined(__OpenBSD__)
    141        1.1  augustss 	void *sc_powerhook;		/* cookie from power hook */
    142        1.1  augustss 	void *sc_shutdownhook;		/* cookie from shutdown hook */
    143  1.24.14.1     itohy #endif
    144        1.1  augustss 
    145        1.3  augustss 	u_int sc_ncomp;
    146        1.5  augustss 	u_int sc_npcomp;
    147        1.3  augustss 	struct usbd_bus *sc_comps[EHCI_COMPANION_MAX];
    148        1.3  augustss 
    149  1.24.14.1     itohy 	usb_dma_tag_t sc_dmatag;
    150        1.3  augustss 	usb_dma_t sc_fldma;
    151       1.15  augustss 	ehci_link_t *sc_flist;
    152        1.3  augustss 	u_int sc_flsize;
    153  1.24.14.1     itohy #ifndef __FreeBSD__
    154       1.15  augustss 	u_int sc_rand;			/* XXX need proper intr scheduling */
    155  1.24.14.1     itohy #endif
    156       1.15  augustss 
    157       1.15  augustss 	struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
    158        1.3  augustss 
    159       1.11  augustss 	LIST_HEAD(, ehci_xfer) sc_intrhead;
    160       1.11  augustss 
    161  1.24.14.1     itohy 	SIMPLEQ_HEAD(ehci_mdescs, ehci_mem_desc) sc_sqh_chunks, sc_sqtd_chunks;
    162  1.24.14.1     itohy 
    163        1.7  augustss 	ehci_soft_qh_t *sc_freeqhs;
    164        1.7  augustss 	ehci_soft_qtd_t *sc_freeqtds;
    165  1.24.14.1     itohy 	int sc_nfreeqtds;
    166        1.7  augustss 
    167        1.4  augustss 	int sc_noport;
    168       1.21  augustss 	u_int8_t sc_hasppc;		/* has Port Power Control */
    169        1.4  augustss 	u_int8_t sc_addr;		/* device address */
    170        1.4  augustss 	u_int8_t sc_conf;		/* device configuration */
    171        1.4  augustss 	usbd_xfer_handle sc_intrxfer;
    172       1.21  augustss 	char sc_isreset[EHCI_MAX_PORTS];
    173       1.14  augustss #ifdef USB_USE_SOFTINTR
    174       1.12  augustss 	char sc_softwake;
    175       1.14  augustss #endif /* USB_USE_SOFTINTR */
    176        1.5  augustss 
    177        1.5  augustss 	u_int32_t sc_eintrs;
    178        1.9  augustss 	ehci_soft_qh_t *sc_async_head;
    179        1.4  augustss 
    180        1.4  augustss 	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
    181        1.8  augustss 
    182        1.8  augustss 	struct lock sc_doorbell_lock;
    183        1.5  augustss 
    184       1.23   xtraeme 	usb_callout_t sc_tmo_intrlist;
    185        1.4  augustss 
    186       1.17       imp #if defined(__NetBSD__) || defined(__OpenBSD__)
    187  1.24.14.1     itohy 	device_t sc_child;		/* /dev/usb# device */
    188       1.17       imp #endif
    189        1.4  augustss 	char sc_dying;
    190        1.1  augustss } ehci_softc_t;
    191        1.2  augustss 
    192        1.3  augustss #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
    193        1.3  augustss #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
    194        1.3  augustss #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
    195        1.3  augustss #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
    196        1.3  augustss #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
    197        1.3  augustss #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
    198        1.2  augustss #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    199        1.2  augustss #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    200        1.2  augustss #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    201        1.2  augustss #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    202        1.2  augustss #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    203        1.2  augustss #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    204        1.1  augustss 
    205        1.1  augustss usbd_status	ehci_init(ehci_softc_t *);
    206        1.1  augustss int		ehci_intr(void *);
    207        1.1  augustss int		ehci_detach(ehci_softc_t *, int);
    208  1.24.14.1     itohy #if defined(__NetBSD__) || defined(__OpenBSD__)
    209  1.24.14.1     itohy int		ehci_activate(device_t, enum devact);
    210  1.24.14.1     itohy #endif
    211  1.24.14.1     itohy void		ehci_power(int state, void *priv);
    212  1.24.14.1     itohy void		ehci_shutdown(void *v);
    213  1.24.14.1     itohy 
    214  1.24.14.1     itohy #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
    215  1.24.14.1     itohy 
    216