Home | History | Annotate | Line # | Download | only in usb
      1  1.26   mlelstv /*	$NetBSD: xhcivar.h,v 1.26 2025/08/02 22:53:47 mlelstv Exp $	*/
      2   1.1  jakllsch 
      3   1.1  jakllsch /*
      4   1.1  jakllsch  * Copyright (c) 2013 Jonathan A. Kollasch
      5   1.1  jakllsch  * All rights reserved.
      6   1.1  jakllsch  *
      7   1.1  jakllsch  * Redistribution and use in source and binary forms, with or without
      8   1.1  jakllsch  * modification, are permitted provided that the following conditions
      9   1.1  jakllsch  * are met:
     10   1.1  jakllsch  * 1. Redistributions of source code must retain the above copyright
     11   1.1  jakllsch  *    notice, this list of conditions and the following disclaimer.
     12   1.1  jakllsch  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  jakllsch  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  jakllsch  *    documentation and/or other materials provided with the distribution.
     15   1.1  jakllsch  *
     16   1.1  jakllsch  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     17   1.1  jakllsch  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18   1.1  jakllsch  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19   1.1  jakllsch  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     20   1.1  jakllsch  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     21   1.1  jakllsch  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     22   1.1  jakllsch  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     23   1.1  jakllsch  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     24   1.1  jakllsch  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     25   1.1  jakllsch  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     26   1.1  jakllsch  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27   1.1  jakllsch  */
     28   1.1  jakllsch 
     29   1.1  jakllsch #ifndef _DEV_USB_XHCIVAR_H_
     30   1.1  jakllsch #define _DEV_USB_XHCIVAR_H_
     31   1.1  jakllsch 
     32  1.20  riastrad #include <sys/types.h>
     33  1.20  riastrad 
     34  1.20  riastrad #include <sys/condvar.h>
     35  1.20  riastrad #include <sys/device.h>
     36  1.20  riastrad #include <sys/mutex.h>
     37  1.20  riastrad #include <sys/pmf.h>
     38   1.1  jakllsch #include <sys/pool.h>
     39   1.1  jakllsch 
     40  1.20  riastrad #include <dev/usb/usbdi.h>
     41  1.20  riastrad #include <dev/usb/usbdivar.h>
     42  1.20  riastrad 
     43  1.12     skrll #define XHCI_MAX_DCI	31
     44   1.5     skrll 
     45  1.11  jakllsch struct xhci_soft_trb {
     46  1.11  jakllsch 	uint64_t trb_0;
     47  1.11  jakllsch 	uint32_t trb_2;
     48  1.11  jakllsch 	uint32_t trb_3;
     49  1.11  jakllsch };
     50  1.11  jakllsch 
     51   1.1  jakllsch struct xhci_xfer {
     52   1.1  jakllsch 	struct usbd_xfer xx_xfer;
     53  1.15  jakllsch 	struct xhci_soft_trb *xx_trb;
     54  1.15  jakllsch 	u_int xx_ntrb;
     55  1.17  jakllsch 	u_int xx_isoc_done;
     56   1.1  jakllsch };
     57   1.1  jakllsch 
     58   1.5     skrll #define XHCI_BUS2SC(bus)	((bus)->ub_hcpriv)
     59   1.5     skrll #define XHCI_PIPE2SC(pipe)	XHCI_BUS2SC((pipe)->up_dev->ud_bus)
     60   1.5     skrll #define XHCI_XFER2SC(xfer)	XHCI_BUS2SC((xfer)->ux_bus)
     61   1.7     skrll #define XHCI_XFER2BUS(xfer)	((xfer)->ux_bus)
     62   1.5     skrll #define XHCI_XPIPE2SC(d)	XHCI_BUS2SC((d)->xp_pipe.up_dev->ud_bus)
     63   1.5     skrll 
     64   1.5     skrll #define XHCI_XFER2XXFER(xfer)	((struct xhci_xfer *)(xfer))
     65   1.5     skrll 
     66   1.1  jakllsch struct xhci_ring {
     67   1.1  jakllsch 	usb_dma_t xr_dma;
     68   1.1  jakllsch 	kmutex_t xr_lock;
     69   1.1  jakllsch 	struct xhci_trb * xr_trb;
     70   1.1  jakllsch 	void **xr_cookies;
     71   1.1  jakllsch 	u_int xr_ntrb;			/* number of elements for above */
     72   1.1  jakllsch 	u_int xr_ep;			/* enqueue pointer */
     73   1.1  jakllsch 	u_int xr_cs;			/* cycle state */
     74   1.1  jakllsch 	bool is_halted;
     75   1.1  jakllsch };
     76   1.1  jakllsch 
     77   1.1  jakllsch struct xhci_slot {
     78   1.1  jakllsch 	usb_dma_t xs_dc_dma;		/* device context page */
     79   1.1  jakllsch 	usb_dma_t xs_ic_dma;		/* input context page */
     80  1.12     skrll 	struct xhci_ring *xs_xr[XHCI_MAX_DCI + 1];
     81  1.13     skrll 					/* transfer rings */
     82   1.1  jakllsch 	u_int xs_idx;			/* slot index */
     83   1.1  jakllsch };
     84   1.1  jakllsch 
     85   1.1  jakllsch struct xhci_softc {
     86   1.1  jakllsch 	device_t sc_dev;
     87   1.1  jakllsch 	device_t sc_child;
     88   1.7     skrll 	device_t sc_child2;
     89   1.1  jakllsch 	bus_size_t sc_ios;
     90   1.1  jakllsch 	bus_space_tag_t sc_iot;
     91   1.1  jakllsch 	bus_space_handle_t sc_ioh;	/* Base */
     92   1.1  jakllsch 	bus_space_handle_t sc_cbh;	/* Capability Base */
     93   1.1  jakllsch 	bus_space_handle_t sc_obh;	/* Operational Base */
     94   1.1  jakllsch 	bus_space_handle_t sc_rbh;	/* Runtime Base */
     95   1.1  jakllsch 	bus_space_handle_t sc_dbh;	/* Doorbell Registers */
     96   1.7     skrll 	struct usbd_bus sc_bus;		/* USB 3 bus */
     97   1.7     skrll 	struct usbd_bus sc_bus2;	/* USB 2 bus */
     98   1.1  jakllsch 
     99  1.21  riastrad 	kmutex_t sc_rhlock;
    100   1.1  jakllsch 	kmutex_t sc_lock;
    101   1.1  jakllsch 	kmutex_t sc_intr_lock;
    102   1.1  jakllsch 
    103   1.1  jakllsch 	pool_cache_t sc_xferpool;
    104   1.1  jakllsch 
    105   1.1  jakllsch 	bus_size_t sc_pgsz;		/* xHCI page size */
    106   1.1  jakllsch 	uint32_t sc_ctxsz;
    107   1.1  jakllsch 	int sc_maxslots;
    108   1.1  jakllsch 	int sc_maxintrs;
    109   1.2      matt 	int sc_maxspbuf;
    110  1.26   mlelstv 	int sc_isthresh;		/* value in frames */
    111   1.1  jakllsch 
    112   1.7     skrll 	/*
    113   1.7     skrll 	 * Port routing and root hub - xHCI 4.19.7
    114   1.7     skrll 	 */
    115   1.7     skrll 	int sc_maxports;		/* number of controller ports */
    116  1.22   msaitoh 	int sc_usb3nports;
    117  1.22   msaitoh 	int sc_usb2nports;
    118   1.7     skrll 
    119   1.7     skrll 	uint8_t *sc_ctlrportbus;	/* a bus bit per port */
    120   1.7     skrll 
    121   1.7     skrll 	int *sc_ctlrportmap;
    122   1.7     skrll 	int *sc_rhportmap[2];
    123   1.7     skrll 	int sc_rhportcount[2];
    124   1.7     skrll 	struct usbd_xfer *sc_intrxfer[2];
    125  1.23  riastrad 	bool sc_intrxfer_deferred[2];
    126   1.1  jakllsch 
    127   1.1  jakllsch 	struct xhci_slot * sc_slots;
    128   1.1  jakllsch 
    129  1.12     skrll 	struct xhci_ring *sc_cr;	/* command ring */
    130  1.12     skrll 	struct xhci_ring *sc_er;	/* event ring */
    131   1.1  jakllsch 
    132   1.1  jakllsch 	usb_dma_t sc_eventst_dma;
    133   1.1  jakllsch 	usb_dma_t sc_dcbaa_dma;
    134   1.2      matt 	usb_dma_t sc_spbufarray_dma;
    135   1.2      matt 	usb_dma_t *sc_spbuf_dma;
    136   1.1  jakllsch 
    137   1.7     skrll 	kcondvar_t sc_cmdbusy_cv;
    138   1.1  jakllsch 	kcondvar_t sc_command_cv;
    139   1.1  jakllsch 	bus_addr_t sc_command_addr;
    140  1.11  jakllsch 	struct xhci_soft_trb sc_result_trb;
    141   1.7     skrll 	bool sc_resultpending;
    142   1.1  jakllsch 
    143   1.1  jakllsch 	bool sc_dying;
    144  1.24  riastrad 	bool sc_suspendresume_failed;
    145  1.19  riastrad 	struct lwp *sc_suspender;
    146   1.1  jakllsch 
    147   1.5     skrll 	void (*sc_vendor_init)(struct xhci_softc *);
    148   1.5     skrll 	int (*sc_vendor_port_status)(struct xhci_softc *, uint32_t, int);
    149   1.5     skrll 
    150   1.5     skrll 	int sc_quirks;
    151   1.6     skrll #define XHCI_QUIRK_INTEL	__BIT(0) /* Intel xhci chip */
    152   1.8  jmcneill #define XHCI_DEFERRED_START	__BIT(1)
    153  1.25  jmcneill #define XHCI_32BIT_ACCESS	__BIT(2)
    154  1.16  jakllsch 	uint32_t sc_hcc;		/* copy of HCCPARAMS1 */
    155  1.16  jakllsch 	uint32_t sc_hcc2;		/* copy of HCCPARAMS2 */
    156  1.18  riastrad 
    157  1.18  riastrad 	struct xhci_registers {
    158  1.18  riastrad 		uint32_t	usbcmd;
    159  1.18  riastrad 		uint32_t	dnctrl;
    160  1.18  riastrad 		uint64_t	dcbaap;
    161  1.18  riastrad 		uint32_t	config;
    162  1.18  riastrad 		uint32_t	erstsz0;
    163  1.18  riastrad 		uint64_t	erstba0;
    164  1.18  riastrad 		uint64_t	erdp0;
    165  1.18  riastrad 		uint32_t	iman0;
    166  1.18  riastrad 		uint32_t	imod0;
    167  1.18  riastrad 	} sc_regs;
    168   1.1  jakllsch };
    169   1.1  jakllsch 
    170   1.4     skrll int	xhci_init(struct xhci_softc *);
    171   1.8  jmcneill void	xhci_start(struct xhci_softc *);
    172   1.4     skrll int	xhci_intr(void *);
    173   1.4     skrll int	xhci_detach(struct xhci_softc *, int);
    174   1.4     skrll int	xhci_activate(device_t, enum devact);
    175   1.4     skrll void	xhci_childdet(device_t, device_t);
    176   1.4     skrll bool	xhci_suspend(device_t, const pmf_qual_t *);
    177   1.4     skrll bool	xhci_resume(device_t, const pmf_qual_t *);
    178   1.4     skrll bool	xhci_shutdown(device_t, int);
    179   1.1  jakllsch 
    180   1.1  jakllsch #define XHCI_TRANSFER_RING_TRBS 256
    181   1.1  jakllsch 
    182   1.1  jakllsch #endif /* _DEV_USB_XHCIVAR_H_ */
    183