The HBA_MEM.cap register returns abnormal value

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
shore
Posts: 15
Joined: Wed Sep 04, 2019 9:00 pm

The HBA_MEM.cap register returns abnormal value

Post by shore »

Hi I am following a tutorial from https://wiki.osdev.org/AHCI to write an AHCI driver.

I was able to locate the ABAR by scanning PCIE device for "ClassCode = 0x01" and "SubClass = 0x06", with the offset "0x24" as follow:

Code: Select all

if(BaseClass == 0x01 && SubClass == 0x06){//AHCI controller
    AHCI.ABAR = (HBA_MEM *)((unsigned long)PCI_CONF_Read(bus, device, function, 0x24) + PAGE_OFFSET);
}
And the code for reading PCI:

Code: Select all

unsigned int PCI_CONF_Read(unsigned int bus, unsigned int slot, unsigned int func, unsigned int offset)
{
    unsigned int address;
    unsigned int tmp = 0, i;
    
    if(ACPI.PCI_CONF_BASE){
        for(i=0;i<ACPI.No_PCI_Base;i++){
            if(ACPI.PCI_CONF_BASE[i].Start_Bus <= bus && ACPI.PCI_CONF_BASE[i].End_Bus){
                tmp = *(unsigned int *)((ACPI.PCI_CONF_BASE[i].Base_Addr + PAGE_OFFSET) +
                    ((bus - ACPI.PCI_CONF_BASE[i].Start_Bus)<<20 | slot << 15 | func << 12 | (offset & 0xfc)));
            }
        }
    }else{
        address = (unsigned int)((bus << 16) | (slot << 11) | (func << 8) | (offset & 0xfc) | ((unsigned int)0x80000000));
        io_out32(0xCF8, address);
        tmp = io_in32(0xCFC);
    }
    return (tmp);
}
The obtained address is "0xFEBD5000" and I added the PAGE_OFFSET to convert it into relative liner address.

However, when I trying to retrieve information from the address it does not follow the tutorial.

As told, the first 4 byte should be HBA_MEM.cap which "must be within 1 and 32", but the first 4 byte I got is "0xC0141F05".

So I would like to ask if it is some kind of mistake or not. Thanks a lot!!!

My platform:

Qemu 4.2.0-1
Manjaro 18
gcc 9.2.0
Post Reply