io base and mem base?

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
szhou42
Member
Member
Posts: 67
Joined: Thu Apr 28, 2016 12:40 pm
Contact:

io base and mem base?

Post by szhou42 »

Hi, I am following this tutorial trying to implement networking for my os.
http://wiki.osdev.org/Intel_Ethernet_i217

I am not sure how it reads the io_base and mem_base because the constant PCI_BAR_IO and PCI_BAR_MEM is not known.
Is it just extracting the base address from bar0?

I am also very confused that there are 6 BARs, how one knows which is the right one to get info about base address and bar_type?

Code: Select all

E1000::E1000(PCIConfigHeader * p_pciConfigHeader) : NetworkDriver(p_pciConfigHeader)
{
    // Get BAR0 type, io_base address and MMIO base address
    bar_type = pciConfigHeader->getPCIBarType(0);
    io_base = pciConfigHeader->getPCIBar(PCI_BAR_IO) & ~1;
    mem_base = pciConfigHeader->getPCIBar( PCI_BAR_MEM) & ~3;    
 
    // Off course you will need here to map the memory address into you page tables and use corresponding virtual addresses
 
    // Enable bus mastering
    pciConfigHeader->enablePCIBusMastering();
    eerprom_exists = false;
}
Thanks in advance :)
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: io base and mem base?

Post by Kevin »

szhou42 wrote:I am also very confused that there are 6 BARs, how one knows which is the right one to get info about base address and bar_type?
It just depends on the hardware. If you read the spec of a PCI device, it will tell you which BAR is used for what. If the wiki article is right, this specific PCI device uses BAR0 to map its registers.
I am not sure how it reads the io_base and mem_base because the constant PCI_BAR_IO and PCI_BAR_MEM is not known.
Is it just extracting the base address from bar0
The call looks weird to me, but essentially you need to read the BAR from the config space, check the flags to find out whether it's I/O ports or MMIO, and mask out the flags and reserved bits to get the base address. Normally the spec tells you whether it uses I/O ports or MMIO, but apparently for this device, different models use different BAR types, so you'd have to detect it.
Developer of tyndur - community OS of Lowlevel (German)
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: io base and mem base?

Post by SpyderTL »

In your case, PCI_BAR_IO and PCI_BAR_MEM should both be hexadecimal values 0x10. Probably.

The source code to PCIConfigHeader isn't included on this wiki article...
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
Post Reply