toaruos/modules/usbuhci.c

46 lines
966 B
C
Raw Normal View History

2014-04-11 10:22:10 +04:00
#include <module.h>
#include <pci.h>
#include <printf.h>
#include <logging.h>
#include <mod/shell.h>
static uint32_t hub_device = 0;
2014-04-11 10:34:55 +04:00
static void find_usb_device(uint32_t device, uint16_t vendorid, uint16_t deviceid, void * extra) {
2014-04-11 10:22:10 +04:00
if (pci_find_type(device) == 0xc03) {
int prog_if = (int)pci_read_field(device, PCI_PROG_IF, 1);
if (prog_if == 0) {
2014-04-11 10:34:55 +04:00
*((uint32_t *)extra)= device;
2014-04-11 10:22:10 +04:00
}
}
}
DEFINE_SHELL_FUNCTION(usb, "Enumerate USB devices (UHCI)") {
2014-04-11 10:34:55 +04:00
pci_scan(&find_usb_device, -1, &hub_device);
2014-04-11 10:22:10 +04:00
if (!hub_device) {
fprintf(tty, "Failed to locate a UHCI controller.\n");
return 1;
}
fprintf(tty, "Located UHCI controller: %2x:%2x.%d\n",
(int)pci_extract_bus (hub_device),
(int)pci_extract_slot(hub_device),
(int)pci_extract_func(hub_device));
return 0;
}
static int install(void) {
BIND_SHELL_FUNCTION(usb);
return 0;
}
static int uninstall(void) {
return 0;
}
MODULE_DEF(usbuhci, install, uninstall);
MODULE_DEPENDS(debugshell);