commit 8511061dc757f79b9a660fe821dea1ef84dffb20
parent aba51baeb01f4d6930ec568bd6e452d015ac53ad
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 17 Apr 2024 15:43:41 +0900
add xhc structs. something wrong
Diffstat:
5 files changed, 62 insertions(+), 7 deletions(-)
diff --git a/sys/include/pci.h b/sys/include/pci.h
@@ -1,5 +1,6 @@
// #include <libc.h>
+// TODO: need the attribute 'packed'?
typedef struct PCIDev {
uint16 vendor_id;
uint16 device_id;
diff --git a/sys/include/xhc.h b/sys/include/xhc.h
@@ -5,3 +5,45 @@ typedef struct Xhc {
} Xhc;
extern Xhc xhc;
+
+typedef struct xhc_capability_registers {
+ uint8 CAPLENGTH;
+ uint8 Rsvd0;
+ uint16 HCIVERSION;
+ uint32 HCSPARAMS1;
+ uint32 HCSPARAMS2;
+ uint32 HCSPARAMS3;
+ uint32 HCCPARAMS1;
+ uint32 DBOFF;
+ uint32 RTSOFF;
+ uint32 HCCPARAMS2;
+} xhc_capability_registers;
+
+typedef struct xhc_operational_registers {
+ uint32 USBCMD;
+ uint32 USBSTS;
+ uint32 PAGESIZE;
+ uint8 RsvdZ0[8];
+ uint32 NDCTRL;
+ uint32 CRCR;
+ uint8 RsvdZ1[16];
+ uint64 DCBAAP;
+ uint32 CONFIG;
+} xhc_operational_registers;
+
+typedef struct xhc_runtime_registers {
+ uint32 MFINDEX;
+ uint8 RsvdZ[28];
+ struct interrupt_register_set {
+ uint32 IMAN;
+ uint32 IMOD;
+ uint32 ERSTSZ;
+ uint32 RsvdP;
+ uint64 ERSTBA;
+ uint64 ERDP;
+ } IR[1024];
+} xhc_runtime_registers;
+
+typedef struct xhc_doorbell_registers {
+ // TODO: implement.
+} xhc_doorbell_registers;
diff --git a/sys/src/kernel/console.c b/sys/src/kernel/console.c
@@ -116,7 +116,7 @@ cons_printf(Console *con, char *fmt, ...)
}
break;
case 'x':
- u0 = va_arg(ap, unsigned int);
+ u0 = va_arg(ap, uint64);
if (u0 == 0) {
*buf++ = '0';
break;
diff --git a/sys/src/kernel/main.c b/sys/src/kernel/main.c
@@ -61,7 +61,17 @@ kernel_main(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop)
for (int i = 0; i < num_pci_dev; i++) {
if (pci_dev[i].base_class == 0xc && pci_dev[i].sub_class == 0x3 &&
pci_dev[i].prog == 0x30) {
- cons_printf(&con0, "sizeof PCIDev: %d\n", sizeof(PCIDev));
+ uintptr xhc_base = ((uintptr) pci_dev[i].t0.base_address_register[1]) << 32 | pci_dev[i].t0.base_address_register[0];
+ cons_printf(&con0, "xhc_base: %x\n", xhc_base);
+ xhc_capability_registers *xhccr = (xhc_capability_registers *) xhc_base;
+ xhc_operational_registers *xhcor = (xhc_operational_registers *) (xhc_base + xhccr->CAPLENGTH);
+ xhc_runtime_registers *xhcrr = (xhc_runtime_registers *) (xhc_base + xhccr->RTSOFF);
+ xhc_doorbell_registers *xhcdr = (xhc_doorbell_registers *) (xhc_base + xhccr->DBOFF);
+ cons_printf(&con0, "CAPLENGTH: %x\n", xhccr->CAPLENGTH);
+ cons_printf(&con0, "HCIVERSION: %x\n", xhccr->HCIVERSION);
+ cons_printf(&con0, "HCSPARAMS1: %x\n", xhccr->HCSPARAMS1);
+ cons_printf(&con0, "USBCMD: %x\n", xhcor->USBCMD);
+ cons_printf(&con0, "USBSTS: %x\n", xhcor->USBSTS);
}
}
diff --git a/sys/src/kernel/pci.c b/sys/src/kernel/pci.c
@@ -63,14 +63,16 @@ int
pci_scan_func(uint8 bus, uint8 dev, uint8 func)
{
uint8 sub_bus;
+ int i;
if (num_pci_dev >= MaxPCIDev) {
return -1;
}
- pci_dev[num_pci_dev].vendor_id = pci_config_read16(bus, dev, func, 0x0);
- pci_dev[num_pci_dev].device_id = pci_config_read16(bus, dev, func, 0x2);
- pci_dev[num_pci_dev].base_class = pci_config_read16(bus, dev, func, 0xa) >> 8;
- pci_dev[num_pci_dev].sub_class = pci_config_read16(bus, dev, func, 0xa);
- pci_dev[num_pci_dev].prog = pci_config_read16(bus, dev, func, 0x8) >> 8;
+ // populate the PCIDev struct.
+ for (i = 0; i < (sizeof(PCIDev) + 3) / 4; i++) {
+ // TODO: endianness?
+ ((uint32 *)&pci_dev[num_pci_dev])[i] =
+ pci_config_read32(bus, dev, func, i * 4);
+ }
num_pci_dev++;
// pci-pci bridge