xref: /netbsd-src/sys/dev/usb/xhcivar.h (revision b7b7574d3bf8eeb51a1fa3977b59142ec6434a55)
1 /*	$NetBSD: xhcivar.h,v 1.4 2014/03/10 13:12:02 skrll Exp $	*/
2 
3 /*
4  * Copyright (c) 2013 Jonathan A. Kollasch
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #ifndef _DEV_USB_XHCIVAR_H_
30 #define _DEV_USB_XHCIVAR_H_
31 
32 #include <sys/pool.h>
33 
34 struct xhci_xfer {
35 	struct usbd_xfer xx_xfer;
36 	struct usb_task xx_abort_task;
37 	struct xhci_trb xx_trb[20];
38 };
39 
40 struct xhci_ring {
41 	usb_dma_t xr_dma;
42 	kmutex_t xr_lock;
43 	struct xhci_trb * xr_trb;
44 	void **xr_cookies;
45 	u_int xr_ntrb;			/* number of elements for above */
46 	u_int xr_ep;			/* enqueue pointer */
47 	u_int xr_cs;			/* cycle state */
48 	bool is_halted;
49 };
50 
51 struct xhci_endpoint {
52 	struct xhci_ring xe_tr;		/* transfer ring */
53 };
54 
55 struct xhci_slot {
56 	usb_dma_t xs_dc_dma;		/* device context page */
57 	usb_dma_t xs_ic_dma;		/* input context page */
58 	struct xhci_endpoint xs_ep[32]; /* endpoints */
59 	u_int xs_idx;			/* slot index */
60 };
61 
62 struct xhci_softc {
63 	device_t sc_dev;
64 	device_t sc_child;
65 	void *sc_ih;
66 	bus_size_t sc_ios;
67 	bus_space_tag_t sc_iot;
68 	bus_space_handle_t sc_ioh;	/* Base */
69 	bus_space_handle_t sc_cbh;	/* Capability Base */
70 	bus_space_handle_t sc_obh;	/* Operational Base */
71 	bus_space_handle_t sc_rbh;	/* Runtime Base */
72 	bus_space_handle_t sc_dbh;	/* Doorbell Registers */
73 	struct usbd_bus sc_bus;
74 
75 	kmutex_t sc_lock;
76 	kmutex_t sc_intr_lock;
77 	kcondvar_t sc_softwake_cv;
78 
79 	usbd_xfer_handle sc_intrxfer;
80 
81 	pool_cache_t sc_xferpool;
82 
83 	bus_size_t sc_pgsz;		/* xHCI page size */
84 	uint32_t sc_ctxsz;
85 	int sc_maxslots;
86 	int sc_maxintrs;
87 	int sc_maxports;
88 	int sc_maxspbuf;
89 
90 	/* XXX suboptimal */
91 	int sc_hs_port_start;
92 	int sc_hs_port_count;
93 	int sc_ss_port_start;
94 	int sc_ss_port_count;
95 
96 	struct xhci_slot * sc_slots;
97 
98 	struct xhci_ring sc_cr;		/* command ring */
99 	struct xhci_ring sc_er;		/* event ring */
100 
101 	usb_dma_t sc_eventst_dma;
102 	usb_dma_t sc_dcbaa_dma;
103 	usb_dma_t sc_spbufarray_dma;
104 	usb_dma_t *sc_spbuf_dma;
105 
106 	//struct usb_dma_reserve sc_dma_reserve;
107 
108 	kcondvar_t sc_command_cv;
109 	bus_addr_t sc_command_addr;
110 	struct xhci_trb sc_result_trb;
111 
112 	bool sc_ac64;
113 	bool sc_dying;
114 
115 	uint8_t sc_addr;
116 	uint8_t sc_conf;
117 };
118 
119 int	xhci_init(struct xhci_softc *);
120 int	xhci_intr(void *);
121 int	xhci_detach(struct xhci_softc *, int);
122 int	xhci_activate(device_t, enum devact);
123 void	xhci_childdet(device_t, device_t);
124 bool	xhci_suspend(device_t, const pmf_qual_t *);
125 bool	xhci_resume(device_t, const pmf_qual_t *);
126 bool	xhci_shutdown(device_t, int);
127 
128 #define XHCI_TRANSFER_RING_TRBS 256
129 
130 #endif /* _DEV_USB_XHCIVAR_H_ */
131