Skip to content

Commit

Permalink
EHCI USB: process the extended capabilities chain
Browse files Browse the repository at this point in the history
...instead of the first one only.
  • Loading branch information
korli authored and pulkomandy committed Mar 12, 2018
1 parent 8bcb934 commit 137135a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
69 changes: 34 additions & 35 deletions src/add-ons/kernel/busses/usb/ehci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,54 +252,53 @@ EHCI::EHCI(pci_info *info, Stack *stack)

uint32 extendedCapPointer = ReadCapReg32(EHCI_HCCPARAMS) >> EHCI_ECP_SHIFT;
extendedCapPointer &= EHCI_ECP_MASK;
if (extendedCapPointer > 0) {
for (uint32 eec = extendedCapPointer; eec != 0; extendedCapPointer = EHCI_EECP_NEXT(eec)) {
TRACE("extended capabilities register at %" B_PRIu32 "\n",
extendedCapPointer);

uint32 legacySupport = sPCIModule->read_pci_config(fPCIInfo->bus,
eec = sPCIModule->read_pci_config(fPCIInfo->bus,
fPCIInfo->device, fPCIInfo->function, extendedCapPointer, 4);
if ((legacySupport & EHCI_LEGSUP_CAPID_MASK) == EHCI_LEGSUP_CAPID) {
if ((legacySupport & EHCI_LEGSUP_BIOSOWNED) != 0) {
TRACE_ALWAYS("the host controller is bios owned, claiming"
" ownership\n");

sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
fPCIInfo->function, extendedCapPointer + 3, 1, 1);
if ((eec & EHCI_LEGSUP_CAPID_MASK) != EHCI_LEGSUP_CAPID)
continue;

for (int32 i = 0; i < 20; i++) {
legacySupport = sPCIModule->read_pci_config(fPCIInfo->bus,
fPCIInfo->device, fPCIInfo->function,
extendedCapPointer, 4);
uint32 legacySupport = eec;

if ((legacySupport & EHCI_LEGSUP_BIOSOWNED) == 0)
break;
if ((legacySupport & EHCI_LEGSUP_BIOSOWNED) != 0) {
TRACE_ALWAYS("the host controller is bios owned, claiming"
" ownership\n");

TRACE_ALWAYS("controller is still bios owned, waiting\n");
snooze(50000);
}
}
sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
fPCIInfo->function, extendedCapPointer + 3, 1, 1);

if (legacySupport & EHCI_LEGSUP_BIOSOWNED) {
TRACE_ERROR("bios won't give up control over the host "
"controller (ignoring)\n");
} else if (legacySupport & EHCI_LEGSUP_OSOWNED) {
TRACE_ALWAYS(
"successfully took ownership of the host controller\n");
for (int32 i = 0; i < 20; i++) {
legacySupport = sPCIModule->read_pci_config(fPCIInfo->bus,
fPCIInfo->device, fPCIInfo->function,
extendedCapPointer, 4);

if ((legacySupport & EHCI_LEGSUP_BIOSOWNED) == 0)
break;

TRACE_ALWAYS("controller is still bios owned, waiting\n");
snooze(50000);
}
}

// Force off the BIOS owned flag, and clear all SMIs. Some BIOSes
// do indicate a successful handover but do not remove their SMIs
// and then freeze the system when interrupts are generated.
sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
fPCIInfo->function, extendedCapPointer + 2, 1, 0);
sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
fPCIInfo->function, extendedCapPointer + 4, 4, 0);
} else {
if (legacySupport & EHCI_LEGSUP_BIOSOWNED) {
TRACE_ERROR("bios won't give up control over the host "
"controller (ignoring)\n");
} else if (legacySupport & EHCI_LEGSUP_OSOWNED) {
TRACE_ALWAYS(
"extended capability is not a legacy support register\n");
"successfully took ownership of the host controller\n");
}
} else {
TRACE_ALWAYS("no extended capabilities register\n");

// Force off the BIOS owned flag, and clear all SMIs. Some BIOSes
// do indicate a successful handover but do not remove their SMIs
// and then freeze the system when interrupts are generated.
sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
fPCIInfo->function, extendedCapPointer + 2, 1, 0);
sPCIModule->write_pci_config(fPCIInfo->bus, fPCIInfo->device,
fPCIInfo->function, extendedCapPointer + 4, 4, 0);
}

// disable interrupts
Expand Down
1 change: 1 addition & 0 deletions src/add-ons/kernel/busses/usb/ehci_hardware.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
// Extended Capabilities
#define EHCI_ECP_SHIFT 8 // Extended Capability Pointer
#define EHCI_ECP_MASK 0xff
#define EHCI_EECP_NEXT(x) (((x) >> 8) & 0xff)
#define EHCI_LEGSUP_CAPID_MASK 0xff
#define EHCI_LEGSUP_CAPID 0x01
#define EHCI_LEGSUP_OSOWNED (1 << 24) // OS Owned Semaphore
Expand Down

0 comments on commit 137135a

Please sign in to comment.