1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #include "usb.h"
- #include "xhci/xhci.h"
- #include <common/kprint.h>
- #include <driver/pci/pci.h>
- #include <debug/bug.h>
- #include <process/spinlock.h>
- extern spinlock_t xhci_controller_init_lock;
- #define MAX_USB_NUM 8
- struct pci_device_structure_header_t *usb_pdevs[MAX_USB_NUM];
- static int usb_pdevs_count = 0;
- void usb_init()
- {
- kinfo("Initializing usb driver...");
- spin_init(&xhci_controller_init_lock);
-
- pci_get_device_structure(USB_CLASS, USB_SUBCLASS, usb_pdevs, &usb_pdevs_count);
- if (WARN_ON(usb_pdevs_count == 0))
- {
- kwarn("There is no usb hardware in this computer!");
- return;
- }
-
- for (int i = 0; i < usb_pdevs_count; ++i)
- {
- switch (usb_pdevs[i]->ProgIF)
- {
- case USB_TYPE_UHCI:
- case USB_TYPE_OHCI:
- case USB_TYPE_EHCI:
- case USB_TYPE_UNSPEC:
- case USB_TYPE_DEVICE:
- kwarn("Unsupported usb host type: %#02x", usb_pdevs[i]->ProgIF);
- break;
- case USB_TYPE_XHCI:
-
- xhci_init((struct pci_device_structure_general_device_t *)usb_pdevs[i]);
- break;
- default:
- kerror("Error value of usb_pdevs[%d]->ProgIF: %#02x", i, usb_pdevs[i]->ProgIF);
- return;
- break;
- }
- }
- kinfo("Successfully initialized all usb host controllers!");
- }
|