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.
This commit is contained in:
Augustin Cavalier
2019-04-12 16:05:35 -04:00
parent 5dcd02dff2
commit 5c6d92d72f
6 changed files with 270 additions and 277 deletions
+87 -91
View File
@@ -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)
{
+2 -2
View File
@@ -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);
+96 -95
View File
@@ -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)
{
+2 -2
View File
@@ -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,
+81 -85
View File
@@ -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)
+2 -2
View File
@@ -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);