159 lines
3.0 KiB
C
159 lines
3.0 KiB
C
#ifndef _KERNEL_DEVICE_XHCI_H
|
|
#define _KERNEL_DEVICE_XHCI_H
|
|
|
|
#include <aux/compiler.h>
|
|
#include <device/def_device_op.h>
|
|
#include <device/usb/usb.h>
|
|
#include <libk/list.h>
|
|
#include <libk/std.h>
|
|
#include <proc/proc.h>
|
|
#include <proc/reschedule.h>
|
|
#include <proc/suspension_q.h>
|
|
|
|
/* event ring segment table entry */
|
|
struct xhci_erst_entry {
|
|
volatile uint64_t ptr;
|
|
volatile uint32_t size;
|
|
volatile uint32_t _rsvd;
|
|
} PACKED;
|
|
|
|
/* transfer request block */
|
|
struct xhci_trb {
|
|
volatile uint64_t param;
|
|
volatile uint32_t status;
|
|
volatile uint32_t ctrl;
|
|
} PACKED;
|
|
|
|
struct xhci_ctx32 {
|
|
volatile uint32_t dw[8];
|
|
} PACKED;
|
|
|
|
struct xhci_ctx64 {
|
|
volatile uint32_t dw[16];
|
|
} PACKED;
|
|
|
|
struct xhci_input_ctx32 {
|
|
struct xhci_ctx32 ctrl;
|
|
struct xhci_ctx32 slot;
|
|
struct xhci_ctx32 endpoints[31];
|
|
};
|
|
|
|
struct xhci_input_ctx64 {
|
|
struct xhci_ctx64 ctrl;
|
|
struct xhci_ctx64 slot;
|
|
struct xhci_ctx64 endpoints[31];
|
|
};
|
|
|
|
struct xhci_init {
|
|
uintptr_t xhci_mmio_base;
|
|
bool irqs_support;
|
|
uint8_t irq;
|
|
};
|
|
|
|
#define XHCI_PORT_USB2 0
|
|
#define XHCI_PORT_USB3 1
|
|
|
|
struct xhci_port {
|
|
struct list_node_link ports_link;
|
|
uint8_t port_value;
|
|
int type;
|
|
};
|
|
|
|
struct xhci_ring {
|
|
struct xhci_trb* trbs;
|
|
uintptr_t phys;
|
|
uint32_t idx;
|
|
uint32_t size;
|
|
uint8_t cycle_bit;
|
|
};
|
|
|
|
struct xhci_usb_device_config {
|
|
struct usb_config_desc desc;
|
|
};
|
|
|
|
struct xhci_usb_device_if {
|
|
struct usb_if_desc desc;
|
|
};
|
|
|
|
struct xhci_usb_device_endpoint {
|
|
struct usb_endpoint_desc desc;
|
|
struct xhci_ring transfer_ring;
|
|
};
|
|
|
|
#define XHCI_USB_DEVICE_CONFIGS_MAX 16
|
|
#define XHCI_USB_DEVICE_IFS_MAX 16
|
|
#define XHCI_USB_DEVICE_ENDPOINTS_MAX 16
|
|
|
|
struct xhci_usb_device {
|
|
struct list_node_link usb_devices_link;
|
|
struct xhci_port* xhci_port;
|
|
int slot_id;
|
|
|
|
struct xhci_ring endpoint0_ring;
|
|
|
|
struct usb_device_desc device_desc;
|
|
struct usb_config_desc config_desc;
|
|
|
|
struct xhci_usb_device_config configs[XHCI_USB_DEVICE_CONFIGS_MAX];
|
|
size_t configs_count;
|
|
|
|
struct xhci_usb_device_if ifs[XHCI_USB_DEVICE_IFS_MAX];
|
|
size_t ifs_count;
|
|
|
|
struct xhci_usb_device_endpoint endpoints[XHCI_USB_DEVICE_ENDPOINTS_MAX];
|
|
size_t endpoints_count;
|
|
};
|
|
|
|
struct xhci_port_status_change {
|
|
struct list_node_link port_changes_link;
|
|
uint8_t port;
|
|
uint32_t portsc;
|
|
};
|
|
|
|
struct xhci {
|
|
struct device* device;
|
|
|
|
bool irqs_support;
|
|
uint8_t irq;
|
|
|
|
uintptr_t xhci_mmio_base;
|
|
uintptr_t xhci_oper_base;
|
|
uintptr_t xhci_runtime_base;
|
|
uintptr_t xhci_doorbell_base;
|
|
|
|
uintptr_t* xhci_dcbaa;
|
|
uintptr_t xhci_dcbaa_phys;
|
|
|
|
uint32_t max_scratchpad;
|
|
uintptr_t* scratchpads;
|
|
uintptr_t scratchpads_phys;
|
|
|
|
uint32_t max_slots;
|
|
|
|
struct xhci_ring cmd_ring;
|
|
struct xhci_ring event_ring;
|
|
|
|
struct xhci_erst_entry* erst;
|
|
uintptr_t erst_phys;
|
|
|
|
size_t xhci_ctx_size;
|
|
|
|
struct list_node_link* xhci_ports;
|
|
struct list_node_link* xhci_usb_devices;
|
|
|
|
atomic_bool pending;
|
|
uint8_t last_slot_id;
|
|
uint8_t last_cmpl_code;
|
|
struct list_node_link* port_changes;
|
|
|
|
spin_lock_t setup_lock;
|
|
};
|
|
|
|
DEFINE_DEVICE_INIT (xhci_init);
|
|
|
|
DEFINE_DEVICE_FINI (xhci_fini);
|
|
|
|
DEFINE_DEVICE_OP (xhci_poll_driver);
|
|
|
|
#endif // _KERNEL_DEVICE_XHCI_H
|