|
ginnOS
The reference: libc, the libraries and the kernel
|
#include "xhci.h"#include "kernel/sync/spinlock.h"#include "arch/arch.h"#include "arch/x86/cpu/io.h"#include "common/memory.h"#include "drivers/keyboard/keyboard.h"#include "drivers/pci/pci.h"#include "drivers/pci/pci_irq.h"#include "drivers/usb/hid.h"#include "kernel/input/input.h"#include "kernel/klog/klog.h"#include "kernel/memory/mmio.h"#include "kernel/memory/page.h"#include "kernel/memory/pmm.h"#include "kernel/time/timer.h"Macros | |
| #define | MAX_CONTROLLERS 4 |
| a small xHCI driver for USB keyboards and pointing devices (eXtensible Host Controller Interface 1.2; USB HID 1.11). | |
| #define | MAX_HID_DEVICES 8 |
| #define | RING_TRBS 256 |
| #define | SPIN_LIMIT 50000000u |
| #define | CAP_LENGTH 0x00 |
| #define | CAP_HCS1 0x04 |
| #define | CAP_HCS2 0x08 |
| #define | CAP_HCC1 0x10 |
| #define | CAP_DBOFF 0x14 |
| #define | CAP_RTSOFF 0x18 |
| #define | OP_USBCMD 0x00 |
| #define | OP_USBSTS 0x04 |
| #define | OP_CRCR 0x18 |
| #define | OP_DCBAAP 0x30 |
| #define | OP_CONFIG 0x38 |
| #define | OP_PORTS 0x400 |
| #define | USBCMD_RUN 0x1u |
| #define | USBCMD_RESET 0x2u |
| #define | USBCMD_INTE 0x4u |
| #define | USBSTS_HALTED 0x1u |
| #define | USBSTS_EINT 0x8u |
| #define | USBSTS_NOT_READY (1u << 11) |
| #define | PORT_CONNECTED (1u << 0) |
| #define | PORT_ENABLED (1u << 1) |
| #define | PORT_RESET (1u << 4) |
| #define | PORT_POWER (1u << 9) |
| #define | PORT_RESET_DONE (1u << 21) |
| #define | PORT_CHANGE_BITS 0x00FE0000u |
| #define | PORT_SPEED(v) |
| #define | HCC1_PORT_POWER (1u << 3) |
| #define | SPEED_FULL 1 |
| #define | SPEED_LOW 2 |
| #define | SPEED_HIGH 3 |
| #define | SPEED_SUPER 4 |
| #define | IR0_IMAN 0x20 |
| #define | IR0_IMOD 0x24 |
| #define | IR0_ERSTSZ 0x28 |
| #define | IR0_ERSTBA 0x30 |
| #define | IR0_ERDP 0x38 |
| #define | ERDP_BUSY 0x8u |
| #define | IMAN_IP 0x1u |
| #define | IMAN_IE 0x2u |
| #define | TRB_NORMAL 1 |
| #define | TRB_SETUP 2 |
| #define | TRB_DATA 3 |
| #define | TRB_STATUS 4 |
| #define | TRB_LINK 6 |
| #define | TRB_ENABLE_SLOT 9 |
| #define | TRB_ADDRESS_DEV 11 |
| #define | TRB_CONFIGURE_EP 12 |
| #define | TRB_EVALUATE_CTX 13 |
| #define | TRB_TRANSFER_EVT 32 |
| #define | TRB_COMMAND_EVT 33 |
| #define | TRB_CYCLE (1u << 0) |
| #define | TRB_TOGGLE (1u << 1) |
| #define | TRB_IOC (1u << 5) |
| #define | TRB_IDT (1u << 6) |
| #define | TRB_TYPE(t) |
| #define | TRB_DIR_IN (1u << 16) |
| #define | COMPLETION_SUCCESS 1 |
| #define | COMPLETION_SHORT 13 |
| #define | EP_TYPE_CONTROL 4 |
| #define | EP_TYPE_INT_IN 7 |
| #define | XCAP_LEGACY 1 |
| #define | LEGACY_BIOS_OWNS (1u << 16) |
| #define | LEGACY_OS_OWNS (1u << 24) |
| #define | REPEAT_DELAY 50 |
| #define | REPEAT_RATE 3 |
| #define | PAGE_INPUT 0x000 |
| #define | PAGE_OUTPUT 0x800 |
| #define | PAGE_DATA 0xC00 |
| #define | DATA_MAX 0x400 |
Typedefs | |
| typedef struct xhci | xhci_t |
Enumerations | |
| enum | hid_kind_t { HID_KEYBOARD , HID_MOUSE , HID_POINTER } |
Functions | |
| uint32_t | xhci_init (void) |
| set up the xHCI controllers and their input devices. | |
| #define MAX_CONTROLLERS 4 |
a small xHCI driver for USB keyboards and pointing devices (eXtensible Host Controller Interface 1.2; USB HID 1.11).
keyboards and mice use the HID boot protocol (fixed reports). other pointing devices (QEMU's tablet, for example) send the report their report descriptor describes (hid.c). keys go to the keyboard driver as PS/2 scan codes; buttons, motion and the wheel go to /dev/input.
the controller works with rings of 16-byte TRBs in RAM. the driver puts commands on the command ring, transfers on each endpoint's transfer ring, and reads the results from the event ring. a cycle bit in each TRB marks which side owns it; it changes each time a ring wraps (through a link TRB on the command and transfer rings).
during boot (interrupts off) the driver polls the event ring. after boot the controller interrupts (MSI-X, MSI or INTx) for each event; a controller without an interrupt is polled from the timer interrupt. the timer also repeats a held key. each controller has one page for each ring, the device context array, and one page per device for its contexts and its data.
| #define MAX_HID_DEVICES 8 |
| #define RING_TRBS 256 |
| #define SPIN_LIMIT 50000000u |
| #define CAP_LENGTH 0x00 |
| #define CAP_HCS1 0x04 |
| #define CAP_HCS2 0x08 |
| #define CAP_HCC1 0x10 |
| #define CAP_DBOFF 0x14 |
| #define CAP_RTSOFF 0x18 |
| #define OP_USBCMD 0x00 |
| #define OP_USBSTS 0x04 |
| #define OP_CRCR 0x18 |
| #define OP_DCBAAP 0x30 |
| #define OP_CONFIG 0x38 |
| #define OP_PORTS 0x400 |
| #define USBCMD_RUN 0x1u |
| #define USBCMD_RESET 0x2u |
| #define USBCMD_INTE 0x4u |
| #define USBSTS_HALTED 0x1u |
| #define USBSTS_EINT 0x8u |
| #define USBSTS_NOT_READY (1u << 11) |
| #define PORT_CONNECTED (1u << 0) |
| #define PORT_ENABLED (1u << 1) |
| #define PORT_RESET (1u << 4) |
| #define PORT_POWER (1u << 9) |
| #define PORT_RESET_DONE (1u << 21) |
| #define PORT_CHANGE_BITS 0x00FE0000u |
| #define PORT_SPEED | ( | v | ) |
| #define HCC1_PORT_POWER (1u << 3) |
| #define SPEED_FULL 1 |
| #define SPEED_LOW 2 |
| #define SPEED_HIGH 3 |
| #define SPEED_SUPER 4 |
| #define IR0_IMAN 0x20 |
| #define IR0_IMOD 0x24 |
| #define IR0_ERSTSZ 0x28 |
| #define IR0_ERSTBA 0x30 |
| #define IR0_ERDP 0x38 |
| #define ERDP_BUSY 0x8u |
| #define IMAN_IP 0x1u |
| #define IMAN_IE 0x2u |
| #define TRB_NORMAL 1 |
| #define TRB_SETUP 2 |
| #define TRB_DATA 3 |
| #define TRB_STATUS 4 |
| #define TRB_LINK 6 |
| #define TRB_ENABLE_SLOT 9 |
| #define TRB_ADDRESS_DEV 11 |
| #define TRB_CONFIGURE_EP 12 |
| #define TRB_EVALUATE_CTX 13 |
| #define TRB_TRANSFER_EVT 32 |
| #define TRB_COMMAND_EVT 33 |
| #define TRB_CYCLE (1u << 0) |
| #define TRB_TOGGLE (1u << 1) |
| #define TRB_IOC (1u << 5) |
| #define TRB_IDT (1u << 6) |
| #define TRB_DIR_IN (1u << 16) |
| #define COMPLETION_SUCCESS 1 |
| #define COMPLETION_SHORT 13 |
| #define EP_TYPE_CONTROL 4 |
| #define EP_TYPE_INT_IN 7 |
| #define XCAP_LEGACY 1 |
| #define LEGACY_BIOS_OWNS (1u << 16) |
| #define LEGACY_OS_OWNS (1u << 24) |
| #define REPEAT_DELAY 50 |
| #define REPEAT_RATE 3 |
| #define PAGE_INPUT 0x000 |
| #define PAGE_OUTPUT 0x800 |
| #define PAGE_DATA 0xC00 |
| #define DATA_MAX 0x400 |
| typedef struct xhci xhci_t |
| enum hid_kind_t |
| uint32_t xhci_init | ( | void | ) |
set up the xHCI controllers and their input devices.
call after pci_init and mmio_init, with interrupts off.