DeactivateLegacySupport does not succeed with some BIOS

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
ehenkes
Member
Member
Posts: 124
Joined: Mon Mar 23, 2009 3:15 am
Location: Germany
Contact:

DeactivateLegacySupport does not succeed with some BIOS

Post by ehenkes »

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:

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");
    }
}
What is the ultimate trick to make the BIOS let the EHCI go at each machine?
User avatar
osdnlo
Member
Member
Posts: 136
Joined: Thu Feb 25, 2010 5:39 pm

Re: DeactivateLegacySupport does not succeed with some BIOS

Post by osdnlo »

Do you have a setting in the BIOS titled something like EHCI HandOff? If so, this should be disabled, I think.
Yes, I see that you have proven it, but my question was, 'How did you know that would work?'.
User avatar
ehenkes
Member
Member
Posts: 124
Joined: Mon Mar 23, 2009 3:15 am
Location: Germany
Contact:

Re: DeactivateLegacySupport does not succeed with some BIOS

Post by ehenkes »

Yes, coming from the BIOS side is a good idea. The problem is a notebook with a "closed" BIOS where you can change only some primitive setups. Therefore we look for the system software side. Professional and some open OS can do it, but we do not know how. Anybody starting with EHCI should encounter this topic.
User avatar
osdnlo
Member
Member
Posts: 136
Joined: Thu Feb 25, 2010 5:39 pm

Re: DeactivateLegacySupport does not succeed with some BIOS

Post by osdnlo »

I suggested that mainly to have you check if your BIOS even supports that feature.

I don't know, this is 2 years old too: http://www.microsoft.com/whdc/connect/u ... ermed.mspx

It states that Windows XP doesn't do the EHCI BIOS Hand-Off, so what did they do? Maybe SP2 fixed that? What do they do now? Maybe they take ownership during boot.

Hey, are you and XanClic working together?
Yes, I see that you have proven it, but my question was, 'How did you know that would work?'.
User avatar
ehenkes
Member
Member
Posts: 124
Joined: Mon Mar 23, 2009 3:15 am
Location: Germany
Contact:

Re: DeactivateLegacySupport does not succeed with some BIOS

Post by ehenkes »

XanClic supports our project as an experienced "consultant". :D
ray
Posts: 1
Joined: Mon Mar 29, 2010 11:14 pm

Re: DeactivateLegacySupport does not succeed with some BIOS

Post by ray »

hey,
as far as I know, even Bios bit and OS bit both get set, the bios USB stack should be turned off. So just ignore the abnormal results.:)
Post Reply