xhci.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #pragma once
  2. #include <driver/usb/usb.h>
  3. #include <driver/pci/pci.h>
  4. // xhci Capability Registers offset
  5. #define XHCI_CAPS_CAPLENGTH 0x00 // Cap 寄存器组的长度
  6. #define XHCI_CAPS_RESERVED 0x01
  7. #define XHCI_CAPS_HCIVERSION 0x02 // 接口版本号
  8. #define XHCI_CAPS_HCSPARAMS1 0x04
  9. #define XHCI_CAPS_HCSPARAMS2 0x08
  10. #define XHCI_CAPS_HCSPARAMS3 0x0c
  11. #define XHCI_CAPS_HCCPARAMS1 0x10 // capability params 1
  12. #define XHCI_CAPS_DBOFF 0x14 // Doorbell offset
  13. #define XHCI_CAPS_RTSOFF 0x18 // Runtime register space offset
  14. #define XHCI_CAPS_HCCPARAMS2 0x1c // capability params 2
  15. struct xhci_caps_HCSPARAMS1_reg_t
  16. {
  17. unsigned max_slots : 8; // 最大插槽数
  18. unsigned max_intrs : 11; // 最大中断数
  19. unsigned reserved : 5;
  20. unsigned max_ports : 8; // 最大端口数
  21. }__attribute__((packed));
  22. /**
  23. * @brief xhci端口信息
  24. *
  25. */
  26. struct xhci_port_info_t
  27. {
  28. uint8_t flags; // port flags
  29. uint8_t paired_port_num; // 与当前端口所配对的另一个端口(相同物理接口的不同速度的port)
  30. uint8_t offset; // offset of this port within this protocal
  31. uint8_t reserved;
  32. } __attribute__((packed));
  33. struct xhci_controller_t
  34. {
  35. struct pci_device_structure_general_device_t *pci_dev_hdr; // 指向pci header结构体的指针
  36. int controller_id; // 操作系统给controller的编号
  37. int vbase; // 虚拟地址base(bar0映射到的虚拟地址)
  38. struct xhci_port_info_t *ports; // 指向端口信息数组的指针
  39. };
  40. /**
  41. * @brief 初始化xhci控制器
  42. *
  43. * @param header 指定控制器的pci device头部
  44. */
  45. void xhci_init(struct pci_device_structure_general_device_t *header);