Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
xhci.hpp
Go to the documentation of this file.
1#ifndef __XHCI__XHCI_HPP__
2#define __XHCI__XHCI_HPP__
6#include <type.h>
8#define XHCI_VENDOR_ID 0x1b36
9#define XHCI_DEVICE_ID 0x000d // QEMU XHCI
10
11// Capability Registers
24
25// Operational Registers
37
38// Runtime Registers
40 volatile uint32_t iman;
41 volatile uint32_t imod;
42 volatile uint32_t erstsz;
44 volatile uint64_t erstba;
45 volatile uint64_t erdp;
46} __attribute__((packed));
47
49 volatile uint32_t mfindex;
51 struct xhci_intr_regs ir[1024]; // Max 1024 interrupters
52} __attribute__((packed));
53
54// Port Status and Control Register
55#define XHCI_PORT_CCS (1 << 0)
56#define XHCI_PORT_PED (1 << 1)
57#define XHCI_PORT_PR (1 << 4)
58#define XHCI_PORT_PLS_MASK (0xF << 5)
59#define XHCI_PORT_PP (1 << 9)
60#define XHCI_PORT_SPEED_MASK (0xF << 10)
61#define XHCI_PORT_CSC (1 << 17)
62#define XHCI_PORT_PRC (1 << 21)
63
64// USBCMD bits
65#define XHCI_CMD_RS (1 << 0)
66#define XHCI_CMD_HCRST (1 << 1)
67#define XHCI_CMD_INTE (1 << 2)
68
69// USBSTS bits
70#define XHCI_STS_HCH (1 << 0)
71#define XHCI_STS_CNR (1 << 11)
72
73// TRB types
74#define XHCI_TRB_NORMAL 1
75#define XHCI_TRB_SETUP_STAGE 2
76#define XHCI_TRB_DATA_STAGE 3
77#define XHCI_TRB_STATUS_STAGE 4
78#define XHCI_TRB_LINK 6
79#define XHCI_TRB_ENABLE_SLOT_CMD 9
80#define XHCI_TRB_ADDRESS_DEVICE_CMD 11
81#define XHCI_TRB_CONFIGURE_ENDPOINT_CMD 12
82#define XHCI_TRB_TRANSFER_EVENT 32
83#define XHCI_TRB_COMMAND_COMPLETION_EVENT 33
84#define XHCI_TRB_PORT_STATUS_CHANGE_EVENT 34
85
91
98
106
110} __attribute__((packed));
111
117
122
123class XHCIModule : public IOforgePCI {
124public:
125 XHCIModule();
126 void load() override;
127 void unload() override;
128
129 static XHCIModule* getInstance();
130 static void fireHandler();
131
132 void set_controller(ioforge_usb_controller_device* ctrl) { controller = ctrl; }
133
134 // Data Transfer API
136 uint32_t data_phys, size_t size,
137 uint32_t response_phys, size_t response_size);
138
139private:
140 void reset_controller();
141 void init_controller();
142 void probe_ports();
143
144 // Internal Ring Management
145 void send_command(struct xhci_trb* trb);
147
149 void address_device(uint8_t slot_id, uint8_t port_id);
150
152
158
162
165
170
194
195 ioforge_usb_controller_device* controller;
196
199
200#endif // __XHCI__XHCI_HPP__
IOforgePCI(const char *mod)
uint8_t enable_slot()
Definition xhci.cpp:161
uint32_t max_intrs
Definition xhci.hpp:161
uintptr_t cmd_ring_phys
Definition xhci.hpp:167
void address_device(uint8_t slot_id, uint8_t port_id)
Definition xhci.cpp:168
XHCIModule()
Definition init.cpp:10
struct xhci_trb * create_transfer_ring(uintptr_t *phys)
Definition xhci.cpp:215
struct xhci_trb * cmd_ring
Definition xhci.hpp:166
ioforge_pci_device * device
Definition xhci.hpp:153
void set_controller(ioforge_usb_controller_device *ctrl)
Definition xhci.hpp:132
static XHCIModule instance
Definition xhci.hpp:197
volatile uint32_t * doorbell_regs
Definition xhci.hpp:157
struct xhci_trb * event_ring
Definition xhci.hpp:171
uintptr_t dcbaa_phys
Definition xhci.hpp:164
void send_async_with_response(uint8_t addr, uint8_t endpoint, uint32_t data_phys, size_t size, uint32_t response_phys, size_t response_size)
Definition xhci.cpp:222
void probe_ports()
Definition xhci.cpp:82
void unload() override
struct XHCIModule::xhci_slot slots[256]
ioforge_usb_controller_device * controller
Definition xhci.hpp:195
uint32_t num_ports
Definition xhci.hpp:160
uint64_t * dcbaa
Definition xhci.hpp:163
void send_command(struct xhci_trb *trb)
Definition xhci.cpp:113
uint8_t event_ring_pcs
Definition xhci.hpp:174
void reset_controller()
Definition xhci.cpp:6
struct xhci_op_regs * op_regs
Definition xhci.hpp:155
void load() override
Definition init.cpp:17
struct xhci_trb wait_for_event(uint8_t type)
Definition xhci.cpp:132
static XHCIModule * getInstance()
Definition init.cpp:13
uint32_t event_ring_index
Definition xhci.hpp:173
struct xhci_cap_regs * cap_regs
Definition xhci.hpp:154
uintptr_t event_ring_phys
Definition xhci.hpp:172
uint32_t num_slots
Definition xhci.hpp:159
struct xhci_runtime_regs * runtime_regs
Definition xhci.hpp:156
void init_controller()
Definition xhci.cpp:24
uintptr_t erst_phys
Definition xhci.hpp:193
uint32_t cmd_ring_index
Definition xhci.hpp:168
static void fireHandler()
Definition init.cpp:78
uint8_t cmd_ring_pcs
Definition xhci.hpp:169
volatile uint64_t addr
Definition e1000.hpp:0
Definition xhci.hpp:188
uint32_t size
Definition xhci.hpp:190
uint64_t ba
Definition xhci.hpp:189
uint32_t reserved
Definition xhci.hpp:191
struct xhci_trb * rings[32]
Definition xhci.hpp:182
uint32_t ring_indices[32]
Definition xhci.hpp:184
uintptr_t ctx_phys
Definition xhci.hpp:181
struct xhci_device_ctx * ctx
Definition xhci.hpp:180
uint8_t ring_pcs[32]
Definition xhci.hpp:185
uintptr_t rings_phys[32]
Definition xhci.hpp:183
uint32_t hcsparams3
Definition xhci.hpp:18
uint32_t dboff
Definition xhci.hpp:20
uint32_t hccparams2
Definition xhci.hpp:22
uint32_t hcsparams2
Definition xhci.hpp:17
uint16_t hciversion
Definition xhci.hpp:15
uint32_t hccparams1
Definition xhci.hpp:19
uint8_t caplength
Definition xhci.hpp:13
uint8_t reserved
Definition xhci.hpp:14
uint32_t hcsparams1
Definition xhci.hpp:16
uint32_t rtsoff
Definition xhci.hpp:21
struct xhci_slot_ctx slot
Definition xhci.hpp:108
struct xhci_endpoint_ctx ep[31]
Definition xhci.hpp:109
uint32_t reserved[3]
Definition xhci.hpp:104
uint64_t trdp
Definition xhci.hpp:102
uint32_t info2
Definition xhci.hpp:101
uint32_t info3
Definition xhci.hpp:103
uint32_t info
Definition xhci.hpp:100
uint32_t reserved[6]
Definition xhci.hpp:115
struct xhci_device_ctx device
Definition xhci.hpp:120
struct xhci_input_control_ctx input_control
Definition xhci.hpp:119
volatile uint32_t erstsz
Definition xhci.hpp:42
uint32_t reserved
Definition xhci.hpp:43
volatile uint32_t imod
Definition xhci.hpp:41
volatile uint64_t erdp
Definition xhci.hpp:45
volatile uint32_t iman
Definition xhci.hpp:40
volatile uint64_t erstba
Definition xhci.hpp:44
uint32_t reserved2[4]
Definition xhci.hpp:33
volatile uint32_t pagesize
Definition xhci.hpp:29
volatile uint32_t config
Definition xhci.hpp:35
volatile uint32_t usbcmd
Definition xhci.hpp:27
volatile uint64_t crcr
Definition xhci.hpp:32
uint32_t reserved1[2]
Definition xhci.hpp:30
volatile uint32_t dnctrl
Definition xhci.hpp:31
volatile uint32_t usbsts
Definition xhci.hpp:28
volatile uint64_t dcbaap
Definition xhci.hpp:34
uint32_t reserved[7]
Definition xhci.hpp:50
volatile uint32_t mfindex
Definition xhci.hpp:49
struct xhci_intr_regs ir[1024]
Definition xhci.hpp:51
uint32_t info
Definition xhci.hpp:93
uint32_t reserved[2]
Definition xhci.hpp:95
uint32_t reserved2[4]
Definition xhci.hpp:96
uint32_t info2
Definition xhci.hpp:94
uint64_t ptr
Definition xhci.hpp:87
uint32_t status
Definition xhci.hpp:88
uint32_t control
Definition xhci.hpp:89
unsigned short uint16_t
Definition type.h:13
unsigned int uint32_t
Definition type.h:19
unsigned long uintptr_t
Definition type.h:73
unsigned long uint64_t
Definition type.h:25
unsigned char uint8_t
Definition type.h:7
uint8_t type
Definition vnode.h:2
size_t size
Definition vnode.h:3
XHCIModule __attribute__