OSDev.org

The Place to Start for Operating System Developers
It is currently Mon May 20, 2024 1:55 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: The HBA_MEM.cap register returns abnormal value
PostPosted: Tue Feb 18, 2020 4:04 am 
Offline

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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 24 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group