hci_t * ehci_init (pcidev_t addr) { int i; hci_t *controller = new_controller (); if (!controller) usb_fatal("Could not create USB controller instance.\n"); controller->instance = malloc (sizeof (ehci_t)); if(!controller->instance) usb_fatal("Not enough memory creating USB controller instance.\n"); #define PCI_COMMAND 4 #define PCI_COMMAND_IO 1 #define PCI_COMMAND_MEMORY 2 #define PCI_COMMAND_MASTER 4 u32 pci_command = pci_read_config32(addr, PCI_COMMAND); pci_command = (pci_command | PCI_COMMAND_MEMORY) & ~PCI_COMMAND_IO ; pci_write_config32(addr, PCI_COMMAND, pci_command); controller->start = ehci_start; controller->stop = ehci_stop; controller->reset = ehci_reset; controller->shutdown = ehci_shutdown; controller->bulk = ehci_bulk; controller->control = ehci_control; controller->create_intr_queue = ehci_create_intr_queue; controller->destroy_intr_queue = ehci_destroy_intr_queue; controller->poll_intr_queue = ehci_poll_intr_queue; for (i = 0; i < 128; i++) { controller->devices[i] = 0; } init_device_entry (controller, 0); EHCI_INST(controller)->capabilities = phys_to_virt(pci_read_config32(addr, USBBASE)); EHCI_INST(controller)->operation = (hc_op_t *)(phys_to_virt(pci_read_config32(addr, USBBASE)) + EHCI_INST(controller)->capabilities->caplength); /* default value for frame length adjust */ pci_write_config8(addr, FLADJ, FLADJ_framelength(60000)); /* Enable operation of controller */ controller->start(controller); /* take over all ports. USB1 should be blind now */ EHCI_INST(controller)->operation->configflag = 1; /* TODO lots of stuff missing */ controller->devices[0]->controller = controller; controller->devices[0]->init = ehci_rh_init; controller->devices[0]->init (controller->devices[0]); return controller; }
void xhci_rh_init (usbdev_t *dev) { int i; dev->destroy = xhci_rh_destroy; dev->poll = xhci_rh_poll; dev->data = malloc (sizeof (rh_inst_t)); if (!dev->data) usb_fatal ("Not enough memory for XHCI RH.\n"); RH_INST (dev)->numports = XHCI_INST (dev->controller)->capreg->MaxPorts; RH_INST (dev)->port = malloc(sizeof(int) * RH_INST (dev)->numports); debug("%d ports registered\n", RH_INST (dev)->numports); for (i = 0; i < RH_INST (dev)->numports; i++) { xhci_rh_enable_port (dev, i); RH_INST (dev)->port[i] = -1; } /* we can set them here because a root hub _really_ shouldn't appear elsewhere */ dev->address = 0; dev->hub = -1; dev->port = -1; debug("rh init done\n"); }