[haiku-commits] haiku: hrev53065 - src/add-ons/kernel/busses/usb

  • From: waddlesplash <waddlesplash@xxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 12 Apr 2019 16:16:59 -0400 (EDT)

hrev53065 adds 2 changesets to branch 'master'
old head: 5dcd02dff29b7f7302a27a7dfbe17c9c9064fd8b
new head: 67b05100d24245964653dbd7e1efb518b1aee274
overview: 
https://git.haiku-os.org/haiku/log/?qt=range&q=67b05100d242+%5E5dcd02dff29b

----------------------------------------------------------------------------

5c6d92d72fba: busses/usb: Move ::AddTo to be above the class constructors.
  
  It is called before them (and is responsible for calling them),
  so having it in the middle of the file does not make a lot of sense.
  
  Already done for XHCI. Only one functional change -- removing the
  set_dprintf_enabled call. Drivers probably shouldn't spuriously
  re-enable that if it was specifically disabled.

67b05100d242: busses/usb: Don't reject devices with "invalid" IRQs immediately.
  
  We may be able to allocate an MSI for them. This was done for XHCI
  already in hrev52742.
  
  Probably fixes #15004.

                              [ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

6 files changed, 265 insertions(+), 277 deletions(-)
src/add-ons/kernel/busses/usb/ehci.cpp | 177 +++++++++++++--------------
src/add-ons/kernel/busses/usb/ehci.h   |   4 +-
src/add-ons/kernel/busses/usb/ohci.cpp | 189 ++++++++++++++---------------
src/add-ons/kernel/busses/usb/ohci.h   |   4 +-
src/add-ons/kernel/busses/usb/uhci.cpp | 164 ++++++++++++-------------
src/add-ons/kernel/busses/usb/uhci.h   |   4 +-

############################################################################

Commit:      5c6d92d72fba996d4770e5aa98977d0bff043cf2
URL:         https://git.haiku-os.org/haiku/commit/?id=5c6d92d72fba
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Apr 12 20:05:35 2019 UTC

busses/usb: Move ::AddTo to be above the class constructors.

It is called before them (and is responsible for calling them),
so having it in the middle of the file does not make a lot of sense.

Already done for XHCI. Only one functional change -- removing the
set_dprintf_enabled call. Drivers probably shouldn't spuriously
re-enable that if it was specifically disabled.

----------------------------------------------------------------------------

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);

############################################################################

Revision:    hrev53065
Commit:      67b05100d24245964653dbd7e1efb518b1aee274
URL:         https://git.haiku-os.org/haiku/commit/?id=67b05100d242
Author:      Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date:        Fri Apr 12 20:14:26 2019 UTC

Ticket:      https://dev.haiku-os.org/ticket/15004

busses/usb: Don't reject devices with "invalid" IRQs immediately.

We may be able to allocate an MSI for them. This was done for XHCI
already in hrev52742.

Probably fixes #15004.

----------------------------------------------------------------------------

diff --git a/src/add-ons/kernel/busses/usb/ehci.cpp 
b/src/add-ons/kernel/busses/usb/ehci.cpp
index d583e7c76d..2e0b6584d5 100644
--- a/src/add-ons/kernel/busses/usb/ehci.cpp
+++ b/src/add-ons/kernel/busses/usb/ehci.cpp
@@ -143,14 +143,8 @@ EHCI::AddTo(Stack *stack)
        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);
+                       TRACE_MODULE("found device at PCI:%d:%d:%d\n",
+                               item->bus, item->device, item->function);
                        EHCI *bus = new(std::nothrow) EHCI(item, stack);
                        if (!bus) {
                                delete item;
@@ -465,6 +459,11 @@ EHCI::EHCI(pci_info *info, Stack *stack)
                        }
                }
 
+               if (fIRQ == 0 || fIRQ == 0xFF) {
+                       TRACE_MODULE_ERROR("device was assigned an invalid 
IRQ\n");
+                       return;
+               }
+
                // install the interrupt handler and enable interrupts
                install_io_interrupt_handler(fIRQ, InterruptHandler,
                        (void *)this, 0);
diff --git a/src/add-ons/kernel/busses/usb/ohci.cpp 
b/src/add-ons/kernel/busses/usb/ohci.cpp
index dc4df8170f..fc0652f465 100644
--- a/src/add-ons/kernel/busses/usb/ohci.cpp
+++ b/src/add-ons/kernel/busses/usb/ohci.cpp
@@ -94,15 +94,8 @@ OHCI::AddTo(Stack *stack)
        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);
+                       TRACE_MODULE("found device at PCI:%d:%d:%d\n",
+                               item->bus, item->device, item->function);
                        OHCI *bus = new(std::nothrow) OHCI(item, stack);
                        if (!bus) {
                                delete item;
@@ -444,6 +437,11 @@ OHCI::OHCI(pci_info *info, Stack *stack)
                }
        }
 
+       if (fIRQ == 0 || fIRQ == 0xFF) {
+               TRACE_MODULE_ERROR("device was assigned an invalid IRQ\n");
+               return;
+       }
+
        // Install the interrupt handler
        TRACE("installing interrupt handler\n");
        install_io_interrupt_handler(fIRQ, _InterruptHandler, (void *)this, 0);
diff --git a/src/add-ons/kernel/busses/usb/uhci.cpp 
b/src/add-ons/kernel/busses/usb/uhci.cpp
index 27cb57b1ea..c894cd8785 100644
--- a/src/add-ons/kernel/busses/usb/uhci.cpp
+++ b/src/add-ons/kernel/busses/usb/uhci.cpp
@@ -329,17 +329,10 @@ UHCI::AddTo(Stack *stack)
        }
 
        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);
+                       TRACE_MODULE("found device at PCI:%d:%d:%d\n",
+                               item->bus, item->device, item->function);
                        UHCI *bus = new(std::nothrow) UHCI(item, stack);
                        if (!bus) {
                                delete item;
@@ -577,6 +570,11 @@ UHCI::UHCI(pci_info *info, Stack *stack)
                }
        }
 
+       if (fIRQ == 0 || fIRQ == 0xFF) {
+               TRACE_MODULE_ERROR("device was assigned an invalid IRQ\n");
+               return;
+       }
+
        // Install the interrupt handler
        TRACE("installing interrupt handler\n");
        install_io_interrupt_handler(fIRQ, InterruptHandler, (void *)this, 0);


Other related posts:

  • » [haiku-commits] haiku: hrev53065 - src/add-ons/kernel/busses/usb - waddlesplash