usbuhci.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* vim: tabstop=4 shiftwidth=4 noexpandtab
  2. * This file is part of ToaruOS and is released under the terms
  3. * of the NCSA / University of Illinois License - see LICENSE.md
  4. * Copyright (C) 2014-2018 K. Lange
  5. */
  6. #include <kernel/module.h>
  7. #include <kernel/pci.h>
  8. #include <kernel/printf.h>
  9. #include <kernel/logging.h>
  10. #include <kernel/mod/shell.h>
  11. static uint32_t hub_device = 0;
  12. static void find_usb_device(uint32_t device, uint16_t vendorid, uint16_t deviceid, void * extra) {
  13. if (pci_find_type(device) == 0xc03) {
  14. int prog_if = (int)pci_read_field(device, PCI_PROG_IF, 1);
  15. if (prog_if == 0) {
  16. *((uint32_t *)extra)= device;
  17. }
  18. }
  19. }
  20. DEFINE_SHELL_FUNCTION(usb, "Enumerate USB devices (UHCI)") {
  21. pci_scan(&find_usb_device, -1, &hub_device);
  22. if (!hub_device) {
  23. fprintf(tty, "Failed to locate a UHCI controller.\n");
  24. return 1;
  25. }
  26. fprintf(tty, "Located UHCI controller: %2x:%2x.%d\n",
  27. (int)pci_extract_bus (hub_device),
  28. (int)pci_extract_slot(hub_device),
  29. (int)pci_extract_func(hub_device));
  30. return 0;
  31. }
  32. static int install(void) {
  33. BIND_SHELL_FUNCTION(usb);
  34. return 0;
  35. }
  36. static int uninstall(void) {
  37. return 0;
  38. }
  39. MODULE_DEF(usbuhci, install, uninstall);
  40. MODULE_DEPENDS(debugshell);