xhci 寄存器介绍
查看linux 代码:
1733 /* There is one xhci_hcd structure per controller */
1734 struct xhci_hcd {
1735 struct usb_hcd *main_hcd;
1736 struct usb_hcd *shared_hcd;
1737 /* glue to PCI and HCD framework */
1738 struct xhci_cap_regs __iomem *cap_regs;
1739 struct xhci_op_regs __iomem *op_regs;
1740 struct xhci_run_regs __iomem *run_regs;
1741 struct xhci_doorbell_array __iomem *dba;
1742 /* Our HCD's current interrupter register set */
1743 struct xhci_intr_reg __iomem *ir_set;
主要寄存器是:xhci_cap_regs, xhci_op_regs, xhci_run_regs,xhci_doorbell_array
50 struct xhci_cap_regs {
51 __le32 hc_capbase;
52 __le32 hcs_params1;
53 __le32 hcs_params2;
54 __le32 hcs_params3;
55 __le32 hcc_params;
56 __le32 db_off;
57 __le32 run_regs_off;
58 __le32 hcc_params2; /* xhci 1.1 */
59 /* Reserved up to (CAPLENGTH - 0x1C) */
60 };
对应手册是
176 struct xhci_op_regs {
177 __le32 command;
178 __le32 status;
179 __le32 page_size;
180 __le32 reserved1;
181 __le32 reserved2;
182 __le32 dev_notification;
183 __le64 cmd_ring;
184 /* rsvd: offset 0x20-2F */
185 __le32 reserved3[4];
186 __le64 dcbaa_ptr;
187 __le32 config_reg;
188 /* rsvd: offset 0x3C-3FF */
189 __le32 reserved4[241];
190 /* port 1 registers, which serve as a base address for other ports */
191 __le32 port_status_base;
192 __le32 port_power_base;
193 __le32 port_link_base;
194 __le32 reserved5;
195 /* registers for ports 2-255 */
196 __le32 reserved6[NUM_PORT_REGS*254];
197 };
对用手册是:
其中端口寄存器:
寄存器读写实操
root@raoxu-PC:/sys# lspci | grep -i usb
00:14.0 USB controller: Intel Corporation Comet Lake PCH-V USB Controller
root@raoxu-PC:/sys# lspci -s 00:14.0 -v
00:14.0 USB controller: Intel Corporation Comet Lake PCH-V USB Controller (prog-if 30 [XHCI])
Subsystem: ASRock Incorporation Device a3af
Flags: bus master, medium devsel, latency 0, IRQ 122
Memory at 99330000 (64-bit, non-prefetchable) [size=64K]
Capabilities: [70] Power Management version 2
Capabilities: [80] MSI: Enable+ Count=1/8 Maskable- 64bit+
Kernel driver in use: xhci_hcd
首先查看xhci 寄存器基地址为:0x99330000
也可以通过其他方式获取到:
cat /proc/iomem | grep xhci
99330000-9933ffff : xhci-hcd
读取 Operational Register Space 首地址:
根据代码和手册可以找到,需要找到Host Controller Operational Registers的地址偏移为:
root@raoxu-PC:/sys# busybox devmem 0x99330000
0x01000080
读出来的偏移值0x80
那么偏移地址就是0x99330080
那么如何得到port的地址呢:
根据介绍,我们只需要根据port num 进行计算就可以了。
以我插入的鼠标为例:
/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/8p, 5000M
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
|__ Port 1: Dev 2, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
|__ Port 5: Dev 3, If 0, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 5: Dev 3, If 1, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 10: Dev 4, If 0, Class=Hub, Driver=hub/4p, 480M
|__ Port 3: Dev 8, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
如何port 为 10
那么基地址为:addr = 0x99330080 + (0x400 + 0x10 * (10 -1)) = 0x99330510
那么读取状态:
root@raoxu-PC:/sys# busybox devmem 0x99330510
0x00000E03
最高位写1 进行复位
root@raoxu-PC:/sys# busybox devmem 0x99330510 32 0x80000E03
root@raoxu-PC:/sys# busybox devmem 0x99330510
0x000006E1
输入命令可以看到设备复位了