diff --git a/src/add-ons/kernel/busses/usb/ehci.cpp b/src/add-ons/kernel/busses/usb/ehci.cpp index 9c6bd23a85..d583e7c76d 100644 --- a/src/add-ons/kernel/busses/usb/ehci.cpp +++ b/src/add-ons/kernel/busses/usb/ehci.cpp @@ -110,6 +110,93 @@ print_queue(ehci_qh *queueHead) // +status_t +EHCI::AddTo(Stack *stack) +{ + if (!sPCIModule) { + status_t status = get_module(B_PCI_MODULE_NAME, + (module_info **)&sPCIModule); + if (status != B_OK) { + TRACE_MODULE_ERROR("getting pci module failed! 0x%08" B_PRIx32 + "\n", status); + return status; + } + } + + TRACE_MODULE("searching devices\n"); + bool found = false; + pci_info *item = new(std::nothrow) pci_info; + if (!item) { + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + return B_NO_MEMORY; + } + + // Try to get the PCI x86 module as well so we can enable possible MSIs. + if (sPCIx86Module == NULL && get_module(B_PCI_X86_MODULE_NAME, + (module_info **)&sPCIx86Module) != B_OK) { + // If it isn't there, that's not critical though. + TRACE_MODULE_ERROR("failed to get pci x86 module\n"); + sPCIx86Module = NULL; + } + + for (int32 i = 0; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { + if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb + && item->class_api == PCI_usb_ehci) { + if (item->u.h0.interrupt_line == 0 + || item->u.h0.interrupt_line == 0xFF) { + TRACE_MODULE_ERROR("found device with invalid IRQ - " + "check IRQ assignement\n"); + continue; + } + + TRACE_MODULE("found device at IRQ %u\n", item->u.h0.interrupt_line); + EHCI *bus = new(std::nothrow) EHCI(item, stack); + if (!bus) { + delete item; + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + if (sPCIx86Module != NULL) { + sPCIx86Module = NULL; + put_module(B_PCI_X86_MODULE_NAME); + } + return B_NO_MEMORY; + } + + if (bus->InitCheck() != B_OK) { + TRACE_MODULE_ERROR("bus failed init check\n"); + delete bus; + continue; + } + + // the bus took it away + item = new(std::nothrow) pci_info; + + if (bus->Start() != B_OK) { + delete bus; + continue; + } + found = true; + } + } + + if (!found) { + TRACE_MODULE_ERROR("no devices found\n"); + delete item; + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + if (sPCIx86Module != NULL) { + sPCIx86Module = NULL; + put_module(B_PCI_X86_MODULE_NAME); + } + return ENODEV; + } + + delete item; + return B_OK; +} + + EHCI::EHCI(pci_info *info, Stack *stack) : BusManager(stack), fCapabilityRegisters(NULL), @@ -1150,97 +1237,6 @@ EHCI::NotifyPipeChange(Pipe *pipe, usb_change change) } -status_t -EHCI::AddTo(Stack *stack) -{ -#ifdef TRACE_USB - set_dprintf_enabled(true); -#endif - - if (!sPCIModule) { - status_t status = get_module(B_PCI_MODULE_NAME, - (module_info **)&sPCIModule); - if (status != B_OK) { - TRACE_MODULE_ERROR("getting pci module failed! 0x%08" B_PRIx32 - "\n", status); - return status; - } - } - - TRACE_MODULE("searching devices\n"); - bool found = false; - pci_info *item = new(std::nothrow) pci_info; - if (!item) { - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - return B_NO_MEMORY; - } - - // Try to get the PCI x86 module as well so we can enable possible MSIs. - if (sPCIx86Module == NULL && get_module(B_PCI_X86_MODULE_NAME, - (module_info **)&sPCIx86Module) != B_OK) { - // If it isn't there, that's not critical though. - TRACE_MODULE_ERROR("failed to get pci x86 module\n"); - sPCIx86Module = NULL; - } - - for (int32 i = 0; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { - if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb - && item->class_api == PCI_usb_ehci) { - if (item->u.h0.interrupt_line == 0 - || item->u.h0.interrupt_line == 0xFF) { - TRACE_MODULE_ERROR("found device with invalid IRQ - " - "check IRQ assignement\n"); - continue; - } - - TRACE_MODULE("found device at IRQ %u\n", item->u.h0.interrupt_line); - EHCI *bus = new(std::nothrow) EHCI(item, stack); - if (!bus) { - delete item; - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - if (sPCIx86Module != NULL) { - sPCIx86Module = NULL; - put_module(B_PCI_X86_MODULE_NAME); - } - return B_NO_MEMORY; - } - - if (bus->InitCheck() != B_OK) { - TRACE_MODULE_ERROR("bus failed init check\n"); - delete bus; - continue; - } - - // the bus took it away - item = new(std::nothrow) pci_info; - - if (bus->Start() != B_OK) { - delete bus; - continue; - } - found = true; - } - } - - if (!found) { - TRACE_MODULE_ERROR("no devices found\n"); - delete item; - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - if (sPCIx86Module != NULL) { - sPCIx86Module = NULL; - put_module(B_PCI_X86_MODULE_NAME); - } - return ENODEV; - } - - delete item; - return B_OK; -} - - status_t EHCI::GetPortStatus(uint8 index, usb_port_status *status) { diff --git a/src/add-ons/kernel/busses/usb/ehci.h b/src/add-ons/kernel/busses/usb/ehci.h index fc50521773..2c92120377 100644 --- a/src/add-ons/kernel/busses/usb/ehci.h +++ b/src/add-ons/kernel/busses/usb/ehci.h @@ -51,6 +51,8 @@ typedef struct isochronous_transfer_data { class EHCI : public BusManager { public: +static status_t AddTo(Stack *stack); + EHCI(pci_info *info, Stack *stack); ~EHCI(); @@ -73,8 +75,6 @@ virtual status_t CancelQueuedTransfers(Pipe *pipe, bool force); virtual status_t NotifyPipeChange(Pipe *pipe, usb_change change); -static status_t AddTo(Stack *stack); - // Port operations for root hub uint8 PortCount() { return fPortCount; } status_t GetPortStatus(uint8 index, usb_port_status *status); diff --git a/src/add-ons/kernel/busses/usb/ohci.cpp b/src/add-ons/kernel/busses/usb/ohci.cpp index ded588e16a..dc4df8170f 100644 --- a/src/add-ons/kernel/busses/usb/ohci.cpp +++ b/src/add-ons/kernel/busses/usb/ohci.cpp @@ -57,6 +57,102 @@ module_info *modules[] = { }; +// +// #pragma mark - +// + + +status_t +OHCI::AddTo(Stack *stack) +{ + if (!sPCIModule) { + status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); + if (status < B_OK) { + TRACE_MODULE_ERROR("getting pci module failed! 0x%08" B_PRIx32 "\n", + status); + return status; + } + } + + TRACE_MODULE("searching devices\n"); + bool found = false; + pci_info *item = new(std::nothrow) pci_info; + if (!item) { + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + return B_NO_MEMORY; + } + + // Try to get the PCI x86 module as well so we can enable possible MSIs. + if (sPCIx86Module == NULL && get_module(B_PCI_X86_MODULE_NAME, + (module_info **)&sPCIx86Module) != B_OK) { + // If it isn't there, that's not critical though. + TRACE_MODULE_ERROR("failed to get pci x86 module\n"); + sPCIx86Module = NULL; + } + + for (uint32 i = 0 ; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { + if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb + && item->class_api == PCI_usb_ohci) { + if (item->u.h0.interrupt_line == 0 + || item->u.h0.interrupt_line == 0xFF) { + TRACE_MODULE_ERROR("found device with invalid IRQ -" + " check IRQ assignement\n"); + continue; + } + + TRACE_MODULE("found device at IRQ %u\n", + item->u.h0.interrupt_line); + OHCI *bus = new(std::nothrow) OHCI(item, stack); + if (!bus) { + delete item; + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + + if (sPCIx86Module != NULL) { + sPCIx86Module = NULL; + put_module(B_PCI_X86_MODULE_NAME); + } + + return B_NO_MEMORY; + } + + if (bus->InitCheck() < B_OK) { + TRACE_MODULE_ERROR("bus failed init check\n"); + delete bus; + continue; + } + + // the bus took it away + item = new(std::nothrow) pci_info; + + if (bus->Start() != B_OK) { + delete bus; + continue; + } + found = true; + } + } + + if (!found) { + TRACE_MODULE_ERROR("no devices found\n"); + delete item; + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + + if (sPCIx86Module != NULL) { + sPCIx86Module = NULL; + put_module(B_PCI_X86_MODULE_NAME); + } + + return ENODEV; + } + + delete item; + return B_OK; +} + + OHCI::OHCI(pci_info *info, Stack *stack) : BusManager(stack), fPCIInfo(info), @@ -579,101 +675,6 @@ OHCI::NotifyPipeChange(Pipe *pipe, usb_change change) } -status_t -OHCI::AddTo(Stack *stack) -{ -#ifdef TRACE_USB - set_dprintf_enabled(true); -#endif - - if (!sPCIModule) { - status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); - if (status < B_OK) { - TRACE_MODULE_ERROR("getting pci module failed! 0x%08" B_PRIx32 "\n", - status); - return status; - } - } - - TRACE_MODULE("searching devices\n"); - bool found = false; - pci_info *item = new(std::nothrow) pci_info; - if (!item) { - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - return B_NO_MEMORY; - } - - // Try to get the PCI x86 module as well so we can enable possible MSIs. - if (sPCIx86Module == NULL && get_module(B_PCI_X86_MODULE_NAME, - (module_info **)&sPCIx86Module) != B_OK) { - // If it isn't there, that's not critical though. - TRACE_MODULE_ERROR("failed to get pci x86 module\n"); - sPCIx86Module = NULL; - } - - for (uint32 i = 0 ; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { - if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb - && item->class_api == PCI_usb_ohci) { - if (item->u.h0.interrupt_line == 0 - || item->u.h0.interrupt_line == 0xFF) { - TRACE_MODULE_ERROR("found device with invalid IRQ -" - " check IRQ assignement\n"); - continue; - } - - TRACE_MODULE("found device at IRQ %u\n", - item->u.h0.interrupt_line); - OHCI *bus = new(std::nothrow) OHCI(item, stack); - if (!bus) { - delete item; - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - - if (sPCIx86Module != NULL) { - sPCIx86Module = NULL; - put_module(B_PCI_X86_MODULE_NAME); - } - - return B_NO_MEMORY; - } - - if (bus->InitCheck() < B_OK) { - TRACE_MODULE_ERROR("bus failed init check\n"); - delete bus; - continue; - } - - // the bus took it away - item = new(std::nothrow) pci_info; - - if (bus->Start() != B_OK) { - delete bus; - continue; - } - found = true; - } - } - - if (!found) { - TRACE_MODULE_ERROR("no devices found\n"); - delete item; - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - - if (sPCIx86Module != NULL) { - sPCIx86Module = NULL; - put_module(B_PCI_X86_MODULE_NAME); - } - - return ENODEV; - } - - delete item; - return B_OK; -} - - status_t OHCI::GetPortStatus(uint8 index, usb_port_status *status) { diff --git a/src/add-ons/kernel/busses/usb/ohci.h b/src/add-ons/kernel/busses/usb/ohci.h index 73276530d7..f67710d09c 100644 --- a/src/add-ons/kernel/busses/usb/ohci.h +++ b/src/add-ons/kernel/busses/usb/ohci.h @@ -34,6 +34,8 @@ typedef struct transfer_data { class OHCI : public BusManager { public: +static status_t AddTo(Stack *stack); + OHCI(pci_info *info, Stack *stack); ~OHCI(); @@ -45,8 +47,6 @@ virtual status_t CancelQueuedTransfers(Pipe *pipe, virtual status_t NotifyPipeChange(Pipe *pipe, usb_change change); -static status_t AddTo(Stack *stack); - // Port operations uint8 PortCount() { return fPortCount; }; status_t GetPortStatus(uint8 index, diff --git a/src/add-ons/kernel/busses/usb/uhci.cpp b/src/add-ons/kernel/busses/usb/uhci.cpp index ade4ca7114..27cb57b1ea 100644 --- a/src/add-ons/kernel/busses/usb/uhci.cpp +++ b/src/add-ons/kernel/busses/usb/uhci.cpp @@ -298,6 +298,87 @@ Queue::PrintToStream() // +status_t +UHCI::AddTo(Stack *stack) +{ + if (!sPCIModule) { + status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); + if (status < B_OK) { + TRACE_MODULE_ERROR("AddTo(): getting pci module failed! 0x%08" + B_PRIx32 "\n", status); + return status; + } + } + + TRACE_MODULE("AddTo(): setting up hardware\n"); + + bool found = false; + pci_info *item = new(std::nothrow) pci_info; + if (!item) { + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + return B_NO_MEMORY; + } + + // Try to get the PCI x86 module as well so we can enable possible MSIs. + if (sPCIx86Module == NULL && get_module(B_PCI_X86_MODULE_NAME, + (module_info **)&sPCIx86Module) != B_OK) { + // If it isn't there, that's not critical though. + TRACE_MODULE_ERROR("failed to get pci x86 module\n"); + sPCIx86Module = NULL; + } + + for (int32 i = 0; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { + + if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb + && item->class_api == PCI_usb_uhci) { + if (item->u.h0.interrupt_line == 0 + || item->u.h0.interrupt_line == 0xFF) { + TRACE_MODULE_ERROR("AddTo(): found with invalid IRQ - check IRQ assignement\n"); + continue; + } + + TRACE_MODULE("AddTo(): found at IRQ %u\n", + item->u.h0.interrupt_line); + UHCI *bus = new(std::nothrow) UHCI(item, stack); + if (!bus) { + delete item; + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + return B_NO_MEMORY; + } + + if (bus->InitCheck() < B_OK) { + TRACE_MODULE_ERROR("AddTo(): InitCheck() failed 0x%08" B_PRIx32 + "\n", bus->InitCheck()); + delete bus; + continue; + } + + // the bus took it away + item = new(std::nothrow) pci_info; + + if (bus->Start() != B_OK) { + delete bus; + continue; + } + found = true; + } + } + + if (!found) { + TRACE_MODULE_ERROR("no devices found\n"); + delete item; + sPCIModule = NULL; + put_module(B_PCI_MODULE_NAME); + return ENODEV; + } + + delete item; + return B_OK; +} + + UHCI::UHCI(pci_info *info, Stack *stack) : BusManager(stack), fPCIInfo(info), @@ -1859,91 +1940,6 @@ UHCI::Interrupt() } -status_t -UHCI::AddTo(Stack *stack) -{ -#ifdef TRACE_USB - set_dprintf_enabled(true); -#endif - - if (!sPCIModule) { - status_t status = get_module(B_PCI_MODULE_NAME, (module_info **)&sPCIModule); - if (status < B_OK) { - TRACE_MODULE_ERROR("AddTo(): getting pci module failed! 0x%08" - B_PRIx32 "\n", status); - return status; - } - } - - TRACE_MODULE("AddTo(): setting up hardware\n"); - - bool found = false; - pci_info *item = new(std::nothrow) pci_info; - if (!item) { - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - return B_NO_MEMORY; - } - - // Try to get the PCI x86 module as well so we can enable possible MSIs. - if (sPCIx86Module == NULL && get_module(B_PCI_X86_MODULE_NAME, - (module_info **)&sPCIx86Module) != B_OK) { - // If it isn't there, that's not critical though. - TRACE_MODULE_ERROR("failed to get pci x86 module\n"); - sPCIx86Module = NULL; - } - - for (int32 i = 0; sPCIModule->get_nth_pci_info(i, item) >= B_OK; i++) { - - if (item->class_base == PCI_serial_bus && item->class_sub == PCI_usb - && item->class_api == PCI_usb_uhci) { - if (item->u.h0.interrupt_line == 0 - || item->u.h0.interrupt_line == 0xFF) { - TRACE_MODULE_ERROR("AddTo(): found with invalid IRQ - check IRQ assignement\n"); - continue; - } - - TRACE_MODULE("AddTo(): found at IRQ %u\n", - item->u.h0.interrupt_line); - UHCI *bus = new(std::nothrow) UHCI(item, stack); - if (!bus) { - delete item; - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - return B_NO_MEMORY; - } - - if (bus->InitCheck() < B_OK) { - TRACE_MODULE_ERROR("AddTo(): InitCheck() failed 0x%08" B_PRIx32 - "\n", bus->InitCheck()); - delete bus; - continue; - } - - // the bus took it away - item = new(std::nothrow) pci_info; - - if (bus->Start() != B_OK) { - delete bus; - continue; - } - found = true; - } - } - - if (!found) { - TRACE_MODULE_ERROR("no devices found\n"); - delete item; - sPCIModule = NULL; - put_module(B_PCI_MODULE_NAME); - return ENODEV; - } - - delete item; - return B_OK; -} - - status_t UHCI::CreateFilledTransfer(Transfer *transfer, uhci_td **_firstDescriptor, uhci_qh **_transferQueue) diff --git a/src/add-ons/kernel/busses/usb/uhci.h b/src/add-ons/kernel/busses/usb/uhci.h index d46d4809fb..88beb91711 100644 --- a/src/add-ons/kernel/busses/usb/uhci.h +++ b/src/add-ons/kernel/busses/usb/uhci.h @@ -94,6 +94,8 @@ typedef struct isochronous_transfer_data { class UHCI : public BusManager { public: +static status_t AddTo(Stack *stack); + UHCI(pci_info *info, Stack *stack); ~UHCI(); @@ -109,8 +111,6 @@ virtual status_t CancelQueuedTransfers(Pipe *pipe, bool force); status_t SubmitRequest(Transfer *transfer); status_t SubmitIsochronous(Transfer *transfer); -static status_t AddTo(Stack *stack); - // Port operations status_t GetPortStatus(uint8 index, usb_port_status *status); status_t SetPortFeature(uint8 index, uint16 feature);