DeactivateLegacySupport does not succeed with some BIOS
Posted: Sat Mar 27, 2010 10:26 am
We at the PrettyOS community are developing an EHCI driver for high speed USB. There we use the function DeactivateLegacySupport(...) which does not succeed with some an AMI BIOS (last version from 2008 flashed) of a notebook. The result is BIOS bit == 1 and OS bit == 1. The manual setting of the SMI as disabled does also not help. We ran thru all the specs, but did not find a hint how to manage that all x86 PC leave the EHCI under the governance of the OS. There you find the code:
What is the ultimate trick to make the BIOS let the EHCI go at each machine?
Code: Select all
void DeactivateLegacySupport(uint32_t num) // num = PCI device enumeration
{
bool failed = false;
eecp = BYTE2(pCapRegs->HCCPARAMS);
printf("\nDeactivateLegacySupport: eecp = %x\n",eecp);
/*
cf. EHCI 1.0 spec, 2.2.4 HCCPARAMS - Capability Parameters, Bit 15:8 (BYTE2)
EHCI Extended Capabilities Pointer (EECP). Default = Implementation Dependent.
This optional field indicates the existence of a capabilities list.
A value of 00h indicates no extended capabilities are implemented.
A non-zero value in this register indicates the offset in PCI configuration space
of the first EHCI extended capability. The pointer value must be 40h or greater
if implemented to maintain the consistency of the PCI header defined for this class of device.
*/
// cf. http://wiki.osdev.org/PCI#PCI_Device_Structure
// eecp // RO - This field identifies the extended capability.
// 01h identifies the capability as Legacy Support.
if (eecp >= 0x40)
{
int32_t eecp_id=0;
while (eecp)
{
uint32_t NextEHCIExtCapPtr; // RO - 00h indicates end of the ext. cap. list.
printf("eecp = %x, ",eecp);
eecp_id = pci_config_read( bus, dev, func, 0x0100/*length 1 byte*/ | (eecp + 0) );
printf("eecp_id = %x\n",eecp_id);
if (eecp_id == 1)
break;
NextEHCIExtCapPtr = eecp + 1;
eecp = pci_config_read( bus, dev, func, 0x0100 | NextEHCIExtCapPtr );
}
uint32_t BIOSownedSemaphore = eecp + 2; // R/W - only Bit 16 (Bit 23:17 Reserved, must be set to zero)
uint32_t OSownedSemaphore = eecp + 3; // R/W - only Bit 24 (Bit 31:25 Reserved, must be set to zero)
uint32_t USBLEGCTLSTS = eecp + 4; // USB Legacy Support Control/Status (DWORD, cf. EHCI 1.0 spec, 2.1.8)
// Legacy-Support-EC found? BIOS-Semaphore set?
if ( (eecp_id == 1) && ( pci_config_read( bus, dev, func, 0x0100 | BIOSownedSemaphore ) & 0x01) )
{
printf("set OS-Semaphore.\n");
pci_config_write_byte( bus, dev, func, OSownedSemaphore, 0x01 );
failed = true;
int32_t timeout=200;
// Wait for BIOS-Semaphore being not set
while ( ( pci_config_read( bus, dev, func, 0x0100 | BIOSownedSemaphore ) & 0x01 ) && ( timeout>0 ) )
{
printf(".");
timeout--;
delay(20000);
}
if ( !( pci_config_read( bus, dev, func, 0x0100 | BIOSownedSemaphore ) & 0x01) ) // not set
{
printf("BIOS-Semaphore being not set.\n");
timeout=200;
while ( !( pci_config_read( bus, dev, func, 0x0100 | OSownedSemaphore ) & 0x01) && (timeout>0) )
{
printf(".");
timeout--;
delay(20000);
}
}
if ( pci_config_read( bus, dev, func, 0x0100 | OSownedSemaphore ) & 0x01 )
{
failed = false;
printf("OS-Semaphore being set.\n");
}
printf("Check: BIOSownedSemaphore: %d OSownedSemaphore: %d\n",
pci_config_read( bus, dev, func, 0x0100 | BIOSownedSemaphore ),
pci_config_read( bus, dev, func, 0x0100 | OSownedSemaphore ) );
// USB SMI Enable R/W. 0=Default.
// The OS tries to set SMI to disabled in case that BIOS bit satys at one.
pci_config_write_dword( bus, dev, func, USBLEGCTLSTS, 0x0 ); // USB SMI disabled
}
else
{
settextcolor(10,0);
printf("\nBIOS did not own the EHCI. No action needed.\n");
settextcolor(15,0);
}
}
else
{
printf("No valid eecp found.\n");
}
}