xref: /aosp_15_r20/external/coreboot/payloads/libpayload/drivers/usb/xhci_debug.c (revision b9411a12aaaa7e1e6a6fb7c5e057f44ee179a49c)
1 /*
2  *
3  * Copyright (C) 2013 secunet Security Networks AG
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <inttypes.h>
30 #include "xhci_private.h"
31 
32 #ifdef XHCI_DUMPS
33 
34 void
xhci_dump_slotctx(const slotctx_t * const sc)35 xhci_dump_slotctx(const slotctx_t *const sc)
36 {
37 	xhci_debug("Slot Context (@%p):\n", sc);
38 	usb_debug(" FIELD1\t0x%08"PRIx32"\n", sc->f1);
39 	usb_debug(" FIELD2\t0x%08"PRIx32"\n", sc->f2);
40 	usb_debug(" FIELD3\t0x%08"PRIx32"\n", sc->f3);
41 	usb_debug(" FIELD4\t0x%08"PRIx32"\n", sc->f4);
42 	SC_DUMP(ROUTE,  sc);
43 	SC_DUMP(SPEED1, sc);
44 	SC_DUMP(MTT,    sc);
45 	SC_DUMP(HUB,    sc);
46 	SC_DUMP(CTXENT, sc);
47 	SC_DUMP(RHPORT, sc);
48 	SC_DUMP(NPORTS, sc);
49 	SC_DUMP(TTID,   sc);
50 	SC_DUMP(TTPORT, sc);
51 	SC_DUMP(TTT,    sc);
52 	SC_DUMP(UADDR,  sc);
53 	SC_DUMP(STATE,  sc);
54 }
55 
56 void
xhci_dump_epctx(const epctx_t * const ec)57 xhci_dump_epctx(const epctx_t *const ec)
58 {
59 	xhci_debug("Endpoint Context (@%p):\n", ec);
60 	usb_debug(" FIELD1\t0x%08"PRIx32"\n", ec->f1);
61 	usb_debug(" FIELD2\t0x%08"PRIx32"\n", ec->f2);
62 	usb_debug(" TRDQ_L\t0x%08"PRIx32"\n", ec->tr_dq_low);
63 	usb_debug(" TRDQ_H\t0x%08"PRIx32"\n", ec->tr_dq_high);
64 	usb_debug(" FIELD5\t0x%08"PRIx32"\n", ec->f5);
65 	EC_DUMP(STATE,  ec);
66 	EC_DUMP(INTVAL, ec);
67 	EC_DUMP(CERR,   ec);
68 	EC_DUMP(TYPE,   ec);
69 	EC_DUMP(MBS,    ec);
70 	EC_DUMP(MPS,    ec);
71 	EC_DUMP(DCS,    ec);
72 	EC_DUMP(AVRTRB, ec);
73 	EC_DUMP(MXESIT, ec);
74 }
75 
76 void
xhci_dump_devctx(const devctx_t * const dc,const u32 ctx_mask)77 xhci_dump_devctx(const devctx_t *const dc, const u32 ctx_mask)
78 {
79 	int i;
80 	if (ctx_mask & 1)
81 		xhci_dump_slotctx(dc->slot);
82 	for (i = 1; i <= SC_GET(CTXENT, dc->slot); ++i) {
83 		if (ctx_mask & (1 << i))
84 			xhci_dump_epctx(dc->ep[i]);
85 	}
86 }
87 
88 void
xhci_dump_inputctx(const inputctx_t * const ic)89 xhci_dump_inputctx(const inputctx_t *const ic)
90 {
91 	xhci_debug("Input Control  add: 0x%08"PRIx32"\n", *ic->add);
92 	xhci_debug("Input Control drop: 0x%08"PRIx32"\n", *ic->drop);
93 	xhci_dump_devctx(&ic->dev, *ic->add);
94 }
95 
96 void
xhci_dump_transfer_trb(const trb_t * const cur)97 xhci_dump_transfer_trb(const trb_t *const cur)
98 {
99 	xhci_debug("Transfer TRB (@%p):\n", cur);
100 	usb_debug(" PTR_L\t0x%08"PRIx32"\n", cur->ptr_low);
101 	usb_debug(" PTR_H\t0x%08"PRIx32"\n", cur->ptr_high);
102 	usb_debug(" STATUS\t0x%08"PRIx32"\n", cur->status);
103 	usb_debug(" CNTRL\t0x%08"PRIx32"\n", cur->control);
104 	TRB_DUMP(TL,	cur);
105 	TRB_DUMP(TDS,	cur);
106 	TRB_DUMP(C,	cur);
107 	TRB_DUMP(ISP,	cur);
108 	TRB_DUMP(CH,	cur);
109 	TRB_DUMP(IOC,	cur);
110 	TRB_DUMP(IDT,	cur);
111 	TRB_DUMP(TT,	cur);
112 	TRB_DUMP(DIR,	cur);
113 }
114 
115 static const trb_t *
xhci_next_trb(const trb_t * const cur)116 xhci_next_trb(const trb_t *const cur)
117 {
118 	if (TRB_GET(TT, cur) == TRB_LINK)
119 		return (!cur->ptr_low) ? NULL : phys_to_virt(cur->ptr_low);
120 	else
121 		return cur + 1;
122 }
123 
124 void
xhci_dump_transfer_trbs(const trb_t * const first,const trb_t * const last)125 xhci_dump_transfer_trbs(const trb_t *const first, const trb_t *const last)
126 {
127 	const trb_t *cur;
128 	for (cur = first; cur; cur = xhci_next_trb(cur)) {
129 		xhci_dump_transfer_trb(cur);
130 		if (cur == last)
131 			break;
132 	}
133 }
134 
135 #endif
136