Home | History | Annotate | Line # | Download | only in usb
ehcivar.h revision 1.24.14.2
      1 /*	$NetBSD: ehcivar.h,v 1.24.14.2 2008/05/21 05:01:45 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 /* for aux memory */
     79 #define EHCI_AUX_CHUNK_SIZE		4096
     80 #define EHCI_MAX_PKT_SIZE		1024	/* USB 2.0 specification */
     81 #define EHCI_AUX_PER_CHUNK(maxp)	(EHCI_AUX_CHUNK_SIZE/(maxp))
     82 #define EHCI_NCHUNK(naux, maxp)	\
     83 	(((naux) + EHCI_AUX_PER_CHUNK(maxp) - 1) / EHCI_AUX_PER_CHUNK(maxp))
     84 struct ehci_aux_mem {
     85 	usb_dma_t aux_chunk_dma[EHCI_NCHUNK(USB_DMA_NSEG-1, EHCI_MAX_PKT_SIZE)];
     86 	int	aux_nchunk;	/* number of allocated chunk */
     87 	int	aux_curchunk;	/* current chunk */
     88 	int	aux_chunkoff;	/* offset in current chunk */
     89 	int	aux_naux;	/* number of aux */
     90 };
     91 
     92 struct ehci_xfer {
     93 	struct usbd_xfer xfer;
     94 	struct usb_task	abort_task;
     95 	LIST_ENTRY(ehci_xfer) inext; /* list of active xfers */
     96 	ehci_soft_qtd_t *sqtdstart;
     97 	ehci_soft_qtd_t *sqtdend;
     98 	u_int32_t ehci_xfer_flags;
     99 	struct usb_buffer_dma dmabuf;
    100 	int rsvd_tds;
    101 	struct ehci_aux_mem aux;
    102 #ifdef DIAGNOSTIC
    103 	int isdone;
    104 #endif
    105 };
    106 #define EHCI_XFER_ABORTING	0x0001	/* xfer is aborting. */
    107 #define EHCI_XFER_ABORTWAIT	0x0002	/* abort completion is being awaited. */
    108 
    109 #if 1	/* make sure the argument is actually an xfer pointer */
    110 #define EXFER(xfer) ((void)&(xfer)->hcpriv, (struct ehci_xfer *)(xfer))
    111 #else
    112 #define EXFER(xfer) ((struct ehci_xfer *)(xfer))
    113 #endif
    114 
    115 /*
    116  * Information about an entry in the interrupt list.
    117  */
    118 struct ehci_soft_islot {
    119 	ehci_soft_qh_t *sqh;		/* Queue Head. */
    120 };
    121 
    122 #define EHCI_FRAMELIST_MAXCOUNT	1024
    123 #define EHCI_IPOLLRATES		8	/* Poll rates (1ms, 2, 4, 8 ... 128) */
    124 #define EHCI_INTRQHS		((1 << EHCI_IPOLLRATES) - 1)
    125 #define EHCI_MAX_POLLRATE	(1 << (EHCI_IPOLLRATES - 1))
    126 #define EHCI_IQHIDX(lev, pos)	\
    127 	((((pos) & ((1 << (lev)) - 1)) | (1 << (lev))) - 1)
    128 #define EHCI_ILEV_IVAL(lev)	(1 << (lev))
    129 
    130 #define EHCI_HASH_SIZE 128
    131 #define EHCI_COMPANION_MAX 8
    132 
    133 #define EHCI_SCFLG_DONEINIT	0x0001	/* ehci_init() has been called. */
    134 #define EHCI_SCFLG_LOSTINTRBUG	0x0002	/* workaround for VIA / ATI chipsets */
    135 
    136 typedef struct ehci_softc {
    137 	struct usbd_bus sc_bus;		/* base device */
    138 	bus_space_tag_t iot;
    139 	bus_space_handle_t ioh;
    140 	bus_size_t sc_size;
    141 #if defined(__FreeBSD__)
    142 	void *ih;
    143 
    144 	struct resource *io_res;
    145 	struct resource *irq_res;
    146 #endif
    147 	u_int sc_offs;			/* offset to operational regs */
    148 	int sc_flags;			/* misc flags */
    149 #define EHCIF_DROPPED_INTR_WORKAROUND	0x01
    150 
    151 	char sc_vendor[32];		/* vendor string for root hub */
    152 	int sc_id_vendor;		/* vendor ID for root hub */
    153 
    154 	u_int32_t sc_cmd;		/* shadow of cmd reg during suspend */
    155 #if defined(__NetBSD__) || defined(__OpenBSD__)
    156 	void *sc_powerhook;		/* cookie from power hook */
    157 	void *sc_shutdownhook;		/* cookie from shutdown hook */
    158 #endif
    159 
    160 	u_int sc_ncomp;
    161 	u_int sc_npcomp;
    162 	struct usbd_bus *sc_comps[EHCI_COMPANION_MAX];
    163 
    164 	usb_dma_tag_t sc_dmatag;
    165 	usb_dma_t sc_fldma;
    166 	ehci_link_t *sc_flist;
    167 	u_int sc_flsize;
    168 #ifndef __FreeBSD__
    169 	u_int sc_rand;			/* XXX need proper intr scheduling */
    170 #endif
    171 
    172 	struct ehci_soft_islot sc_islots[EHCI_INTRQHS];
    173 
    174 	LIST_HEAD(, ehci_xfer) sc_intrhead;
    175 
    176 	SIMPLEQ_HEAD(ehci_mdescs, ehci_mem_desc) sc_sqh_chunks, sc_sqtd_chunks;
    177 
    178 	ehci_soft_qh_t *sc_freeqhs;
    179 	ehci_soft_qtd_t *sc_freeqtds;
    180 	int sc_nfreeqtds;
    181 
    182 	int sc_noport;
    183 	u_int8_t sc_hasppc;		/* has Port Power Control */
    184 	u_int8_t sc_addr;		/* device address */
    185 	u_int8_t sc_conf;		/* device configuration */
    186 	usbd_xfer_handle sc_intrxfer;
    187 	char sc_isreset[EHCI_MAX_PORTS];
    188 #ifdef USB_USE_SOFTINTR
    189 	char sc_softwake;
    190 #endif /* USB_USE_SOFTINTR */
    191 
    192 	u_int32_t sc_eintrs;
    193 	ehci_soft_qh_t *sc_async_head;
    194 
    195 	SIMPLEQ_HEAD(, usbd_xfer) sc_free_xfers; /* free xfers */
    196 
    197 	struct lock sc_doorbell_lock;
    198 
    199 	usb_callout_t sc_tmo_intrlist;
    200 
    201 #if defined(__NetBSD__) || defined(__OpenBSD__)
    202 	device_t sc_child;		/* /dev/usb# device */
    203 #endif
    204 	char sc_dying;
    205 } ehci_softc_t;
    206 
    207 #define EREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (a))
    208 #define EREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (a))
    209 #define EREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (a))
    210 #define EWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (a), (x))
    211 #define EWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (a), (x))
    212 #define EWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (a), (x))
    213 #define EOREAD1(sc, a) bus_space_read_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    214 #define EOREAD2(sc, a) bus_space_read_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    215 #define EOREAD4(sc, a) bus_space_read_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a))
    216 #define EOWRITE1(sc, a, x) bus_space_write_1((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    217 #define EOWRITE2(sc, a, x) bus_space_write_2((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    218 #define EOWRITE4(sc, a, x) bus_space_write_4((sc)->iot, (sc)->ioh, (sc)->sc_offs+(a), (x))
    219 
    220 usbd_status	ehci_init(ehci_softc_t *);
    221 int		ehci_intr(void *);
    222 int		ehci_detach(ehci_softc_t *, int);
    223 #if defined(__NetBSD__) || defined(__OpenBSD__)
    224 int		ehci_activate(device_t, enum devact);
    225 #endif
    226 void		ehci_power(int state, void *priv);
    227 void		ehci_shutdown(void *v);
    228 
    229 #define MS_TO_TICKS(ms) ((ms) * hz / 1000)
    230 
    231