XenevaOS
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
usb3.h File Reference
#include <stdint.h>
#include "xhci.h"
#include <Hal\x86_64_sched.h>
#include <list.h>
#include <Sync\spinlock.h>
Include dependency graph for usb3.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _usb_dev_
 
struct  __usb_msg__
 
struct  USB_REQUEST_PACKET
 
struct  _dev_desc_
 
struct  _interface_desc_
 
struct  _qualifier_desc_
 
struct  _config_desc_
 
struct  _string_desc_
 
struct  _endpoint_desc_
 
struct  _usb_desc_
 

Macros

#define USB_BM_REQUEST_OUTPUT   0
 
#define USB_BM_REQUEST_INPUT   0x80
 
#define USB_BM_REQUEST_STANDARD   0
 
#define USB_BM_REQUEST_CLASS   0x20
 
#define USB_BM_REQUEST_VENDOR   0x40
 
#define USB_BM_REQUEST_DEVICE   0
 
#define USB_BM_REQUEST_INTERFACE   1
 
#define USB_BM_REQUEST_ENDPOINT   2
 
#define USB_BM_REQUEST_OTHER   3
 
#define USB_BM_REQUEST_VENDORSPEC   0x1F
 
#define USB_BREQUEST_GET_STATUS   0
 
#define USB_BREQUEST_CLEAR_FEATURE   1
 
#define USB_BREQUEST_SET_FEATURE   3
 
#define USB_BREQUEST_SET_ADDRESS   5
 
#define USB_BREQUEST_GET_DESCRIPTOR   6
 
#define USB_BREQUEST_SET_DESCRIPTOR   7
 
#define USB_BREQUEST_GET_CONFIGURATION   8
 
#define USB_BREQUEST_SET_CONFIGURATION   9
 
#define USB_BREQUEST_GET_INTERFACE   10
 
#define USB_BREQUEST_SET_INTERFACE   11
 
#define USB_DESCRIPTOR_DEVICE   1
 
#define USB_DESCRIPTOR_CONFIGURATION   2
 
#define USB_DESCRIPTOR_STRING   3
 
#define USB_DESCRIPTOR_INTERFACE   4
 
#define USB_DESCRIPTOR_ENDPOINT   5
 
#define USB_DESCRIPTOR_SUPERSPEED_ENDP_CMP   48
 
#define USB_DESCRIPTOR_WVALUE(type, index)   ((type << 8) | index)
 
#define USB_AUDIO_DEV_CLASS   0x01
 
#define USB_COMMUNICATION_CDC_CTRL_CLASS   0x02
 
#define USB_HID_DEV_CLASS   0x03
 
#define USB_PHYSICAL_DEV_CLASS   0x05
 
#define USB_IMAGE_DEV_CLASS   0x06
 
#define USB_PRINTER_DEV_CLASS   0x07
 
#define USB_MASS_STORAGE_DEV_CLASS   0x08
 
#define USB_HUB_DEV_CLASS   0x09
 
#define USB_CDC_DATA_DEV_CLASS   0x0A
 
#define USB_SMART_CARD_DEV_CLASS   0x0B
 
#define USB_CONTENT_SECURITY_DEV_CLASS   0x0D
 
#define USB_VIDEO_DEV_CLASS   0x0E
 
#define USB_PERSONAL_HEALTHCARE_DEV_CLASS   0x0F
 
#define USB_AUDIO_VIDEO_DEV_CLASS   0x10
 
#define USB_BILLBOARD_DEV_CLASS   0x11
 
#define USB_TYPE_C_BRIDGE_CLASS   0x12
 
#define USB_I3C_DEV_CLASS   0x3C
 
#define USB_DIAGNOSTIC_DEV_CLASS   0xDC
 
#define USB_WIRELESS_CONTROLLER_DEV_CLASS   0xE0
 
#define USB_MISCELLANEOUS_DEV_CLASS   0xEF
 
#define ENDPOINT_TRANSFER_TYPE_CONTROL   0
 
#define ENDPOINT_TRANSFER_TYPE_ISOCH   1
 
#define ENDPOINT_TRANSFER_TYPE_BULK   2
 
#define ENDPOINT_TRANSFER_TYPE_INT   3
 

Typedefs

typedef struct _usb_dev_ USBDevice
 
typedef struct __usb_msg__ USBMessage
 
typedef struct _dev_desc_ usb_dev_desc_t
 
typedef struct _interface_desc_ usb_if_desc_t
 
typedef struct _qualifier_desc_ usb_qualifier_desc_t
 
typedef struct _config_desc_ usb_config_desc_t
 
typedef struct _string_desc_ usb_string_desc_t
 
typedef struct _endpoint_desc_ usb_endpoint_desc_t
 
typedef struct _usb_desc_ usb_descriptor_t
 

Functions

void USBGetDeviceDesc (USBDevice *dev, XHCISlot *slot, uint8_t slot_id, uint64_t buffer, uint16_t len)
 
void USBGetStringDesc (USBDevice *dev, XHCISlot *slot, uint8_t slot_id, uint64_t buffer, uint16_t id)
 
void USBGetConfigDesc (USBDevice *dev, XHCISlot *slot, uint8_t slot_id, uint64_t buffer, uint16_t len, uint8_t id)
 
void USBSetConfigDesc (USBDevice *dev, XHCISlot *slot, uint8_t slot_id, uint8_t configval)
 
int XHCIPollEvent (USBDevice *usb_device, int trb_type)
 
void XHCISendCommand (USBDevice *dev, uint32_t param1, uint32_t param2, uint32_t status, uint32_t ctrl)
 
void XHCISendCommandSlot (XHCISlot *slot, uint32_t param1, uint32_t param2, uint32_t status, uint32_t ctrl)
 
void XHCISendCommandEndpoint (XHCISlot *slot, uint8_t endp_num, uint32_t param1, uint32_t param2, uint32_t status, uint32_t ctrl)
 
void XHCIRingDoorbell (USBDevice *dev)
 
void XHCIRingDoorbellSlot (USBDevice *dev, uint8_t slot, uint32_t endpoint)
 
void XHCISendCommandMultiple (USBDevice *dev, xhci_trb_t *trb, int num_count)
 
void XHCIReset (USBDevice *dev)
 
void XHCIDeviceContextInit (USBDevice *dev)
 
void XHCICommandRingInit (USBDevice *dev)
 
void XHCIProtocolInit (USBDevice *dev)
 
void XHCIEventRingInit (USBDevice *dev)
 
void XHCIStartDefaultPorts (USBDevice *dev)
 
void XHCIPortInitialize (USBDevice *dev, unsigned int port)
 
XHCISlotXHCIGetSlotByID (USBDevice *dev, uint8_t slot_id)
 
XHCIEndpointXHCISlotGetEP_DCI (XHCISlot *slot, uint8_t endp_num)
 
USBDeviceUSBGetMainDevice ()
 
XHCIEndpointXHCISlotGetEP (XHCISlot *slot, uint8_t endp_num)
 
usb_descriptor_tUSBGetDescriptor (XHCISlot *slot, uint8_t type)
 
void USBScheduleInterrupt (USBDevice *dev, XHCISlot *slot, XHCIEndpoint *ep, uint64_t physdata)
 

Macro Definition Documentation

◆ ENDPOINT_TRANSFER_TYPE_BULK

#define ENDPOINT_TRANSFER_TYPE_BULK   2

◆ ENDPOINT_TRANSFER_TYPE_CONTROL

#define ENDPOINT_TRANSFER_TYPE_CONTROL   0

◆ ENDPOINT_TRANSFER_TYPE_INT

#define ENDPOINT_TRANSFER_TYPE_INT   3

◆ ENDPOINT_TRANSFER_TYPE_ISOCH

#define ENDPOINT_TRANSFER_TYPE_ISOCH   1

◆ USB_AUDIO_DEV_CLASS

#define USB_AUDIO_DEV_CLASS   0x01

◆ USB_AUDIO_VIDEO_DEV_CLASS

#define USB_AUDIO_VIDEO_DEV_CLASS   0x10

◆ USB_BILLBOARD_DEV_CLASS

#define USB_BILLBOARD_DEV_CLASS   0x11

◆ USB_BM_REQUEST_CLASS

#define USB_BM_REQUEST_CLASS   0x20

◆ USB_BM_REQUEST_DEVICE

#define USB_BM_REQUEST_DEVICE   0

◆ USB_BM_REQUEST_ENDPOINT

#define USB_BM_REQUEST_ENDPOINT   2

◆ USB_BM_REQUEST_INPUT

#define USB_BM_REQUEST_INPUT   0x80

◆ USB_BM_REQUEST_INTERFACE

#define USB_BM_REQUEST_INTERFACE   1

◆ USB_BM_REQUEST_OTHER

#define USB_BM_REQUEST_OTHER   3

◆ USB_BM_REQUEST_OUTPUT

#define USB_BM_REQUEST_OUTPUT   0

◆ USB_BM_REQUEST_STANDARD

#define USB_BM_REQUEST_STANDARD   0

◆ USB_BM_REQUEST_VENDOR

#define USB_BM_REQUEST_VENDOR   0x40

◆ USB_BM_REQUEST_VENDORSPEC

#define USB_BM_REQUEST_VENDORSPEC   0x1F

◆ USB_BREQUEST_CLEAR_FEATURE

#define USB_BREQUEST_CLEAR_FEATURE   1

◆ USB_BREQUEST_GET_CONFIGURATION

#define USB_BREQUEST_GET_CONFIGURATION   8

◆ USB_BREQUEST_GET_DESCRIPTOR

#define USB_BREQUEST_GET_DESCRIPTOR   6

◆ USB_BREQUEST_GET_INTERFACE

#define USB_BREQUEST_GET_INTERFACE   10

◆ USB_BREQUEST_GET_STATUS

#define USB_BREQUEST_GET_STATUS   0

◆ USB_BREQUEST_SET_ADDRESS

#define USB_BREQUEST_SET_ADDRESS   5

◆ USB_BREQUEST_SET_CONFIGURATION

#define USB_BREQUEST_SET_CONFIGURATION   9

◆ USB_BREQUEST_SET_DESCRIPTOR

#define USB_BREQUEST_SET_DESCRIPTOR   7

◆ USB_BREQUEST_SET_FEATURE

#define USB_BREQUEST_SET_FEATURE   3

◆ USB_BREQUEST_SET_INTERFACE

#define USB_BREQUEST_SET_INTERFACE   11

◆ USB_CDC_DATA_DEV_CLASS

#define USB_CDC_DATA_DEV_CLASS   0x0A

◆ USB_COMMUNICATION_CDC_CTRL_CLASS

#define USB_COMMUNICATION_CDC_CTRL_CLASS   0x02

◆ USB_CONTENT_SECURITY_DEV_CLASS

#define USB_CONTENT_SECURITY_DEV_CLASS   0x0D

◆ USB_DESCRIPTOR_CONFIGURATION

#define USB_DESCRIPTOR_CONFIGURATION   2

◆ USB_DESCRIPTOR_DEVICE

#define USB_DESCRIPTOR_DEVICE   1

◆ USB_DESCRIPTOR_ENDPOINT

#define USB_DESCRIPTOR_ENDPOINT   5

◆ USB_DESCRIPTOR_INTERFACE

#define USB_DESCRIPTOR_INTERFACE   4

◆ USB_DESCRIPTOR_STRING

#define USB_DESCRIPTOR_STRING   3

◆ USB_DESCRIPTOR_SUPERSPEED_ENDP_CMP

#define USB_DESCRIPTOR_SUPERSPEED_ENDP_CMP   48

◆ USB_DESCRIPTOR_WVALUE

#define USB_DESCRIPTOR_WVALUE (   type,
  index 
)    ((type << 8) | index)

◆ USB_DIAGNOSTIC_DEV_CLASS

#define USB_DIAGNOSTIC_DEV_CLASS   0xDC

◆ USB_HID_DEV_CLASS

#define USB_HID_DEV_CLASS   0x03

◆ USB_HUB_DEV_CLASS

#define USB_HUB_DEV_CLASS   0x09

◆ USB_I3C_DEV_CLASS

#define USB_I3C_DEV_CLASS   0x3C

◆ USB_IMAGE_DEV_CLASS

#define USB_IMAGE_DEV_CLASS   0x06

◆ USB_MASS_STORAGE_DEV_CLASS

#define USB_MASS_STORAGE_DEV_CLASS   0x08

◆ USB_MISCELLANEOUS_DEV_CLASS

#define USB_MISCELLANEOUS_DEV_CLASS   0xEF

◆ USB_PERSONAL_HEALTHCARE_DEV_CLASS

#define USB_PERSONAL_HEALTHCARE_DEV_CLASS   0x0F

◆ USB_PHYSICAL_DEV_CLASS

#define USB_PHYSICAL_DEV_CLASS   0x05

◆ USB_PRINTER_DEV_CLASS

#define USB_PRINTER_DEV_CLASS   0x07

◆ USB_SMART_CARD_DEV_CLASS

#define USB_SMART_CARD_DEV_CLASS   0x0B

◆ USB_TYPE_C_BRIDGE_CLASS

#define USB_TYPE_C_BRIDGE_CLASS   0x12

◆ USB_VIDEO_DEV_CLASS

#define USB_VIDEO_DEV_CLASS   0x0E

◆ USB_WIRELESS_CONTROLLER_DEV_CLASS

#define USB_WIRELESS_CONTROLLER_DEV_CLASS   0xE0

Typedef Documentation

◆ usb_config_desc_t

◆ usb_descriptor_t

typedef struct _usb_desc_ usb_descriptor_t

◆ usb_dev_desc_t

typedef struct _dev_desc_ usb_dev_desc_t

◆ usb_endpoint_desc_t

◆ usb_if_desc_t

◆ usb_qualifier_desc_t

◆ usb_string_desc_t

◆ USBDevice

typedef struct _usb_dev_ USBDevice

BSD 2-Clause License

Copyright (c) 2022-2023, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

◆ USBMessage

typedef struct __usb_msg__ USBMessage

Function Documentation

◆ USBGetConfigDesc()

void USBGetConfigDesc ( USBDevice dev,
XHCISlot slot,
uint8_t  slot_id,
uint64_t  buffer,
uint16_t  len,
uint8_t  id 
)

◆ USBGetDescriptor()

usb_descriptor_t * USBGetDescriptor ( XHCISlot slot,
uint8_t  type 
)
extern

◆ USBGetDeviceDesc()

void USBGetDeviceDesc ( USBDevice dev,
XHCISlot slot,
uint8_t  slot_id,
uint64_t  buffer,
uint16_t  len 
)
extern

BSD 2-Clause License

Copyright (c) 2022-2023, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

◆ USBGetMainDevice()

USBDevice * USBGetMainDevice ( )
extern

◆ USBGetStringDesc()

void USBGetStringDesc ( USBDevice dev,
XHCISlot slot,
uint8_t  slot_id,
uint64_t  buffer,
uint16_t  id 
)
extern

◆ USBScheduleInterrupt()

void USBScheduleInterrupt ( USBDevice dev,
XHCISlot slot,
XHCIEndpoint ep,
uint64_t  physdata 
)
extern

◆ USBSetConfigDesc()

void USBSetConfigDesc ( USBDevice dev,
XHCISlot slot,
uint8_t  slot_id,
uint8_t  configval 
)

◆ XHCICommandRingInit()

void XHCICommandRingInit ( USBDevice dev)
extern

◆ XHCIDeviceContextInit()

void XHCIDeviceContextInit ( USBDevice dev)
extern

◆ XHCIEventRingInit()

void XHCIEventRingInit ( USBDevice dev)
extern

◆ XHCIGetSlotByID()

XHCISlot * XHCIGetSlotByID ( USBDevice dev,
uint8_t  slot_id 
)
extern

◆ XHCIPollEvent()

int XHCIPollEvent ( USBDevice usb_device,
int  trb_type 
)
extern
  • here we need a delay, while using VirtualBox *‍/

◆ XHCIPortInitialize()

void XHCIPortInitialize ( USBDevice dev,
unsigned int  port 
)
extern

◆ XHCIProtocolInit()

void XHCIProtocolInit ( USBDevice dev)
extern

◆ XHCIReset()

void XHCIReset ( USBDevice dev)
extern

◆ XHCIRingDoorbell()

void XHCIRingDoorbell ( USBDevice dev)
extern

◆ XHCIRingDoorbellSlot()

void XHCIRingDoorbellSlot ( USBDevice dev,
uint8_t  slot,
uint32_t  endpoint 
)
extern

◆ XHCISendCommand()

void XHCISendCommand ( USBDevice dev,
uint32_t  param1,
uint32_t  param2,
uint32_t  status,
uint32_t  ctrl 
)
extern

◆ XHCISendCommandEndpoint()

void XHCISendCommandEndpoint ( XHCISlot slot,
uint8_t  endp_num,
uint32_t  param1,
uint32_t  param2,
uint32_t  status,
uint32_t  ctrl 
)

◆ XHCISendCommandMultiple()

void XHCISendCommandMultiple ( USBDevice dev,
xhci_trb_t trb,
int  num_count 
)
extern

◆ XHCISendCommandSlot()

void XHCISendCommandSlot ( XHCISlot slot,
uint32_t  param1,
uint32_t  param2,
uint32_t  status,
uint32_t  ctrl 
)
extern

◆ XHCISlotGetEP()

XHCIEndpoint * XHCISlotGetEP ( XHCISlot slot,
uint8_t  endp_num 
)
extern

◆ XHCISlotGetEP_DCI()

XHCIEndpoint * XHCISlotGetEP_DCI ( XHCISlot slot,
uint8_t  endp_num 
)
extern

BSD 2-Clause License

Copyright (c) 2022-2025, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

◆ XHCIStartDefaultPorts()

void XHCIStartDefaultPorts ( USBDevice dev)
extern