Voxia OS v0.0.1
Hobby Project Operating System Targeting x86-64
Loading...
Searching...
No Matches
ehci.hpp
Go to the documentation of this file.
1#ifndef __EHCI__EHCI_HPP__
2#define __EHCI__EHCI_HPP__
6#include <type.h>
9#define EHCI_VENDOR_ID 0x8086
10#define EHCI_DEVICE_ID 0x24cd
12/* Interrupt Control */
13#define EHCI_INTERRUPT_ENABLE 0x1
14
15/* USB Command Register Bits */
16#define EHCI_CONTROLLER_START 1
17#define EHCI_CONTROLLER_RESET (1 << 1)
18#define EHCI_START_PERIODIC_SCHEDULE (1 << 4)
19#define EHCI_START_ASYNC_SCHEDULE (1 << 5)
20
21/* USB Status Register Bits */
22#define EHCI_HC_HALTED_STATUS (1 << 12)
23
24/* Schedule Enable Bits */
25#define EHCI_PERIODIC_SCHEDULE_ENABLE (1 << 4)
26#define EHCI_ASYNC_SCHEDULE_ENABLE (5 << 4)
27
28/* Port Control Bits */
29#define EHCI_PORT_ENABLED (1 << 2)
30#define EHCI_PORT_RESET (1 << 8)
31
32/* Frame List Interval Values */
33#define EHCI_1_MICRO_FRAME (1 << 16)
34#define EHCI_2_MICRO_FRAME (2 << 16)
35#define EHCI_4_MICRO_FRAME (4 << 16)
36#define EHCI_8_MICRO_FRAME (8 << 16)
37#define EHCI_16_MICRO_FRAME (16 << 16)
38#define EHCI_32_MICRO_FRAME (32 << 16)
39#define EHCI_64_MICRO_FRAME (64 << 16)
40
41/*
42 * Queue Head Definitions
43 */
44
45/* Queue Head Link Pointer Bits */
46#define EHCI_QUEUE_HEAD_TERMINATE 1
47#define EHCI_QUEUE_HEAD_TOKEN_HALTED (1 << 6)
48
49/* Queue Head Types */
50#define EHCI_QUEUE_HEAD_TYPE_QTD (0 << 1)
51#define EHCI_QUEUE_HEAD_TYPE_QH (1 << 1)
52#define EHCI_QUEUE_HEAD_TYPE_SITD (2 << 1)
53#define EHCI_QUEUE_HEAD_TYPE_FSTN (3 << 1)
54
55/* Queue Head Capability Bits */
56#define EHCI_QH_CAP_DTC (1 << 14)
57#define EHCI_QH_CAP_HEAD_OF_RECLAMATION (1 << 15)
58#define EHCI_QH_CAP_MAX_PACKET_LENGTH(x) (x << 16)
59#define EHCI_QH_EPS_MASK (3 << 12)
60
61/*
62 * Queue Transfer Descriptor Definitions
63 */
64
65/* QTD Link Pointer Bits */
66#define EHCI_QTD_TERMINATE 1
67
68/* QTD Token Bits */
69#define EHCI_QTD_TOKEN_LENGTH(l) (l << 16)
70#define EHCI_QTD_TOKEN_DATA (1 << 31)
71#define EHCI_QTD_TOKEN_IOC (1 << 15)
72
73/* Queue Type Selector */
76 EHCI_Q_SELECT_QH = (1 << 1),
79};
80
81/* QTD PID Codes */
87
88/* QTD Status Bits */
96
97/* QTD Error Count Values */
104
105/* Queue Head Capability Multiplier */
111
113 volatile uint32_t usbcmd; /* USB Command Register */
114 volatile uint32_t usbsts; /* USB Status Register */
115 /*
116 This register enables and disables reporting of the corresponding interrupt to the software. When a bit is set
117and the corresponding interrupt is active, an interrupt is generated to the host. Interrupt sources that are
118disabled in this register still appear in the USBSTS to allow the software to poll for events.
119 */
120 volatile uint32_t usbintr; /* USB Interrupt Enable Register */
121 /*
122 This register is used by the host controller to index into the periodic frame list. The register updates every
123125 microseconds (once each micro-frame). Bits [N:3] are used to select a particular entry in the Periodic
124Frame List during periodic schedule execution. The number of bits used for the index depends on the size of
125the frame list as set by system software in the Frame List Size field in the USBCMD register (see Table 2-9).
126This register must be written as a DWord. Byte writes produce undefined results. This register cannot be
127written unless the Host Controller is in the Halted state as indicated by the HCHalted bit (USBSTS register
128Section 2.3.2). A write to this register while the Run/Stop bit is set to a one (USBCMD register, Section
1292.3.1) produces undefined results. Writes to this register also affect the SOF value. See Section 4.5 for
130details.
131 */
133 volatile uint32_t ctrldssegment; /* 4G Segment Selector */
134 volatile uint32_t periodiclistbase; /* Frame List Base Address */
135 volatile uint32_t asynclistaddr; /* Next Async List Address */
136 volatile uint32_t reserved[9]; /* Reserved */
137 volatile uint32_t configflag; /* Configure Flag Register */
138 volatile uint32_t portsc[]; /* Port Status/Control Registers */
139};
140
142 volatile uint32_t qhlp; /* Queue Head Link Pointer */
143 volatile uint32_t ch; /* Endpoint Characteristics */
144 volatile uint32_t cap; /* Endpoint Capabilities */
145 volatile uint32_t currentTD; /* Current TD Pointer */
146
147 volatile uint32_t nextTD; /* Next TD Pointer */
148 volatile uint32_t altTD; /* Alternate Next TD Pointer */
149 volatile uint32_t token; /* Token */
150 volatile uint32_t buffer[5]; /* Buffer Pointers */
151 volatile uint32_t extbuffer[5]; /* Extended Buffer Pointers */
152
154} __attribute__((aligned(32)));
155
162
164 volatile uint32_t link; /* Next QTD Pointer */
165 volatile uint32_t altlink; /* Alternate Next QTD Pointer */
166 volatile uint32_t token; /* QTD Token */
167 volatile uint32_t buffer[5]; /* Buffer Page Pointers */
168 volatile uint32_t extbuffer[5]; /* Extended Buffer Page Pointers */
169
170 boolean_t used; /* Whether this QTD is in use */
171 uint32_t next; /* Next QTD in chain */
172} __attribute__((aligned(32)));
173
176
182
191
192//
193class EHCIModule : public IOforgePCI {
194 public:
195 EHCIModule();
196 void setup();
197 void load();
198 void unload();
199 void reset_device();
200 void stop_device();
201 void start_device();
202 void init_periodic();
203 void start_periodic();
204 void stop_periodic();
205 void probe();
206 void port_reset(int port);
207
209 uint32_t data_phys, size_t size,
210 uint32_t response, size_t response_size);
211
212 void
213 insert_periodic(ehci_queue_head_node_t* qh_node, uint16_t interval_ms);
214
216 void assign_address(int address);
219 static void fireHandler();
220 static EHCIModule* getInstance();
223 size_t size);
224 void init_controller();
225
226 // cache
231
232 private:
238
241
244
245 // qh utils
246 void push_to_qh(ehci_queue_head_node_t* qh_node);
248
250
251 private:
253};
254
255#endif //__EHCI__EHCI_HPP__
void set_controller(ioforge_usb_controller_service *controller)
Definition ehci.cpp:892
boolean_t retrieve_qtd(ehci_queue_task_descriptor_node_t **out)
Definition ehci.cpp:913
void call_completion_callback(ioforge_device *dev)
Definition ehci.cpp:827
void load()
Definition init.cpp:12
uintptr_t qh2_paddr
Definition ehci.hpp:242
void probe()
Definition ehci.cpp:284
void init_periodic()
Definition ehci.cpp:200
boolean_t retrieve_qh(ehci_queue_head_node_t **out)
Definition ehci.cpp:897
void store_qtd(ehci_queue_task_descriptor_node_t **in)
Definition ehci.cpp:953
void insert_periodic(ehci_queue_head_node_t *qh_node, uint16_t interval_ms)
Definition ehci.cpp:234
void start_periodic()
Definition ehci.cpp:251
boolean_t is_trasaction_is_running
Definition ehci.hpp:237
void usb_get_string_descriptor(uint8_t addr, uint8_t index, char *data, size_t size)
Definition ehci.cpp:261
void assign_address(int address)
Definition ehci.cpp:781
void stop_periodic()
Definition ehci.cpp:255
void setup()
uint32_t * framelist
Definition ehci.hpp:243
ehci_operation * ehci_op
Definition ehci.hpp:234
ioforge_pci_device * device
Definition ehci.hpp:233
void unload()
void start_device()
Definition ehci.cpp:193
uint32_t * hcsparam
Definition ehci.hpp:235
static void fireHandler()
Definition ehci.cpp:868
uint32_t * hccparam
Definition ehci.hpp:236
void usb_get_descriptor(uint8_t addr, uint8_t type, uint8_t index, uint8_t len, uint8_t *data)
Definition ehci.cpp:800
void init_controller()
Definition ehci.cpp:33
ioforge_usb_controller_service * controller
Definition ehci.hpp:252
void push_to_qh(ehci_queue_head_node_t *qh_node)
Definition ehci.cpp:979
ehci_queue_head * qh1
Definition ehci.hpp:239
void reset_device()
Definition ehci.cpp:166
void send_async_with_response(uint8_t addr, uint8_t endpoint, uint32_t data_phys, size_t size, uint32_t response, size_t response_size)
Definition ehci.cpp:578
void port_reset(int port)
Definition ehci.cpp:569
void stop_device()
Definition ehci.cpp:177
uintptr_t qh1_paddr
Definition ehci.hpp:242
static EHCIModule * getInstance()
Definition init.cpp:10
EHCIModule()
Definition init.cpp:8
void store_qh(ehci_queue_head_node_t **in)
Definition ehci.cpp:929
ehci_queue_head * qh2
Definition ehci.hpp:240
void procces_async(ehci_queue_task_descriptor *qtd)
Definition ehci.cpp:742
void pop_from_qh(ehci_queue_head_node_t *qh)
IOforgePCI(const char *mod)
volatile uint64_t addr
Definition e1000.hpp:0
struct ehci_queue_head_node ehci_queue_head_node_t
Definition ehci.hpp:156
EHCI_QTD_TOKEN_ERROR_COUNT
Definition ehci.hpp:98
@ EHCI_QTD_TOKEN_ERROR_COUNT_2
Definition ehci.hpp:101
@ EHCI_QTD_TOKEN_ERROR_COUNT_1
Definition ehci.hpp:100
@ EHCI_QTD_TOKEN_ERROR_COUNT_3
Definition ehci.hpp:102
@ EHCI_QTD_TOKEN_ERROR_COUNT_0
Definition ehci.hpp:99
EHCI_Q_SELECT
Definition ehci.hpp:74
@ EHCI_Q_SELECT_FSTN
Definition ehci.hpp:78
@ EHCI_Q_SELECT_QH
Definition ehci.hpp:76
@ EHCI_Q_SELECT_ITD
Definition ehci.hpp:75
@ EHCI_Q_SELECT_SITD
Definition ehci.hpp:77
EHCI_QH_CAP_MULT
Definition ehci.hpp:106
@ EHCI_QH_CAP_MULT_1
Definition ehci.hpp:107
@ EHCI_QH_CAP_MULT_3
Definition ehci.hpp:109
@ EHCI_QH_CAP_MULT_2
Definition ehci.hpp:108
struct ehci_queue_task_descriptor_node ehci_queue_task_descriptor_node_t
Definition ehci.hpp:174
struct ehci_queue_head_node __attribute__
EHCI_QTD_TOKEN_PID
Definition ehci.hpp:82
@ EHCI_QTD_TOKEN_PID_IN
Definition ehci.hpp:84
@ EHCI_QTD_TOKEN_PID_OUT
Definition ehci.hpp:83
@ EHCI_QTD_TOKEN_PID_SETUP
Definition ehci.hpp:85
EHCI_QTD_TOKEN_STATUS
Definition ehci.hpp:89
@ EHCI_QTD_TOKEN_STATUS_BUFFER_ERROR
Definition ehci.hpp:92
@ EHCI_QTD_TOKEN_STATUS_HALTED
Definition ehci.hpp:91
@ EHCI_QTD_TOKEN_STATUS_TRANSACTION_ERROR
Definition ehci.hpp:94
@ EHCI_QTD_TOKEN_STATUS_ACTIVE
Definition ehci.hpp:90
@ EHCI_QTD_TOKEN_STATUS_BABBLE_DETECTED
Definition ehci.hpp:93
struct fs_data data
Definition filesystem.h:1
uint64_t address
Definition hpet.h:4
size_t len
Definition oct2bin.h:7
volatile uint32_t usbintr
Definition ehci.hpp:120
volatile uint32_t usbcmd
Definition ehci.hpp:113
volatile uint32_t configflag
Definition ehci.hpp:137
volatile uint32_t frindex
Definition ehci.hpp:132
volatile uint32_t periodiclistbase
Definition ehci.hpp:134
volatile uint32_t ctrldssegment
Definition ehci.hpp:133
volatile uint32_t usbsts
Definition ehci.hpp:114
volatile uint32_t asynclistaddr
Definition ehci.hpp:135
volatile uint32_t reserved[9]
Definition ehci.hpp:136
volatile uint32_t portsc[]
Definition ehci.hpp:138
ehci_queue_task_descriptor_node_t * data_node
Definition ehci.hpp:185
ehci_queue_head_node_t * qh_node
Definition ehci.hpp:184
struct ehci_queue_head * head
Definition ehci.hpp:158
ehci_queue_head_node_t * next
Definition ehci.hpp:160
uint32_t physaddr
Definition ehci.hpp:159
volatile uint32_t buffer[5]
Definition ehci.hpp:150
uint32_t _pad[7]
Definition ehci.hpp:153
volatile uint32_t currentTD
Definition ehci.hpp:145
volatile uint32_t qhlp
Definition ehci.hpp:142
volatile uint32_t extbuffer[5]
Definition ehci.hpp:151
volatile uint32_t cap
Definition ehci.hpp:144
volatile uint32_t token
Definition ehci.hpp:149
volatile uint32_t altTD
Definition ehci.hpp:148
volatile uint32_t ch
Definition ehci.hpp:143
volatile uint32_t nextTD
Definition ehci.hpp:147
struct ehci_queue_task_descriptor * task_descriptor
Definition ehci.hpp:178
ehci_queue_task_descriptor_node_t * next
Definition ehci.hpp:180
volatile uint32_t buffer[5]
Definition ehci.hpp:167
volatile uint32_t link
Definition ehci.hpp:164
volatile uint32_t token
Definition ehci.hpp:166
volatile uint32_t altlink
Definition ehci.hpp:165
volatile uint32_t extbuffer[5]
Definition ehci.hpp:168
unsigned short uint16_t
Definition type.h:13
unsigned int uint32_t
Definition type.h:19
uint8_t boolean_t
Definition type.h:89
unsigned long uintptr_t
Definition type.h:73
unsigned char uint8_t
Definition type.h:7
uint8_t type
Definition vnode.h:2
size_t size
Definition vnode.h:3