test: more detailed logging for USB so we can test xhci

This commit is contained in:
K. Lange 2021-08-21 08:04:59 +09:00
parent b216e05f74
commit b8f2f93dee
3 changed files with 32 additions and 6 deletions

View File

@ -126,7 +126,7 @@ run-vga: system
test: system
${EMU} -M q35 -m $(RAM) -smp $(SMP) ${EMU_KVM} -kernel misaka-kernel -initrd ramdisk.igz,util/init.krk -append "root=/dev/ram0 init=/dev/ram1" \
-nographic -no-reboot -audiodev none,id=id -serial null -serial mon:stdio \
-device qemu-xhci,p2=1,p3=0 -device usb-tablet
-device qemu-xhci -device usb-tablet -trace "usb*"
shell: system
${EMU} -m $(RAM) -smp $(SMP) ${EMU_KVM} -cdrom image.iso \

View File

@ -30,8 +30,8 @@ struct xhci_op_regs {
volatile uint32_t op_dnctrl;
volatile uint32_t op_crcr;
volatile uint32_t op__pad2[5];
volatile uint32_t op_dcbaap;
volatile uint32_t op__pad3[1];
volatile uint32_t op_dcbaap_lo;
volatile uint32_t op_dcbaap_hi;
volatile uint32_t op_config;
} __attribute__((packed));
@ -119,15 +119,40 @@ static void find_xhci(uint32_t device, uint16_t v, uint16_t d, void * extra) {
fprintf(stderr, "xhci: available slots: %d\n", controller->cregs->cap_hcsparams1 & 0xFF);
fprintf(stderr, "xhci: available ports: %d\n", controller->cregs->cap_hcsparams1 >> 24);
fprintf(stderr, "xhci: resetting controller\n");
controller->oregs->op_usbcmd |= (1 << 1);
fprintf(stderr, "xhci: waiting for controller to stop...\n");
while ((controller->oregs->op_usbcmd & (1 << 1)));
controller->oregs->op_usbcmd = 0;
while (!(controller->oregs->op_usbsts & (1 << 0)));
fprintf(stderr, "xhci: controller is halted...\n");
fprintf(stderr, "xhci: restarting controller...\n");
controller->oregs->op_usbcmd = (1 << 1);
while ((controller->oregs->op_usbcmd & (1 << 1)));
while ((controller->oregs->op_usbsts & (1 << 11)));
fprintf(stderr, "xhci: controller is ready.\n");
fprintf(stderr, "xhci: slot config %#x -> %#x\n",
controller->oregs->op_config, controller->cregs->cap_hcsparams1 & 0xFF);
controller->oregs->op_config = controller->cregs->cap_hcsparams1 & 0xFF;
fprintf(stderr, "xhci: clearing interrupts?\n");
uint32_t sts = controller->oregs->op_usbsts;
controller->oregs->op_usbsts = sts;
controller->oregs->op_dnctrl = 0;
fprintf(stderr, "xhci: context size is %d\n",
(controller->cregs->cap_hccparams1 & (1 << 1)) ? 64 : 32);
uintptr_t dcbaap = mmu_allocate_n_frames(1) << 12;
char * baseCtx = mmu_map_mmio_region(dcbaap, 0x1000);
memset(baseCtx, 0, 0x1000);
controller->oregs->op_dcbaap_lo = dcbaap & 0xFFFFFFFF;
controller->oregs->op_dcbaap_hi = dcbaap >> 32UL;
controller->oregs->op_dcbaap_lo = dcbaap & 0xFFFFFFFF;
controller->oregs->op_dcbaap_hi = dcbaap >> 32UL;
char devName[20] = "/dev/xhciN";
snprintf(devName, 19, "/dev/xhci%d", _counter);

View File

@ -15,6 +15,7 @@ print("====")
# Perform tests
os.system("/bin/insmod /mod/xhci.ko")
os.system("/bin/cat /dev/xhci0")
# Reboot
print("====")