Re: [ATA DMA Impl.] Content of BAR4 corrupted ?

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
fiveayem
Member
Member
Posts: 51
Joined: Sun Aug 14, 2011 8:01 am

Re: [ATA DMA Impl.] Content of BAR4 corrupted ?

Post by fiveayem »

Hi,

I am currently working on the ATA R/W operations using DMA, and I encountered a little problem while following the tutorial from this website. Indeed, I managed to get the BAR4 value from the IDE controller's PCI Configuration Space (for me, this value is 0x0000C001), but when I try to read a byte, a word or a dword from this address, it returns 0xFF (or 0xFFFF, ...).

It seems an error occured somewhere... I provide you with my code (read functions) :

Code: Select all

u8 PCIreadByte(u8 bus, u8 dev, u8 fn, u8 off)
{
  u32 addr = 0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (off & 0xFC);
  outl(CONFIG_ADDRESS_PORT_BASE, addr);
  return inb(CONFIG_DATA_PORT_BASE + (off & 3));
}

u16 PCIreadWord(u8 bus, u8 dev, u8 fn, u8 off)
{
  u32 addr = 0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (off & 0xFC);
  outl(CONFIG_ADDRESS_PORT_BASE, addr);
  return inw(CONFIG_DATA_PORT_BASE + (off & 2));
}

u32 PCIreadDword(u8 bus, u8 dev, u8 fn, u8 off)
{
  u32 addr = 0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (off & 0xFC);
  outl(CONFIG_ADDRESS_PORT_BASE, addr);
  return inl(CONFIG_DATA_PORT_BASE);
}

u8 PCIreadByteFromRawAddress(u32 addr)
{
  outl(CONFIG_ADDRESS_PORT_BASE, addr & 0xFC);
  return inb(CONFIG_DATA_PORT_BASE + (addr & 3));
}

u16 PCIreadWordFromRawAddress(u32 addr)
{
  outl(CONFIG_ADDRESS_PORT_BASE, addr & 0xFC);
  return inw(CONFIG_DATA_PORT_BASE + (addr & 2));
}

u32 PCIreadDwordFromRawAddress(u32 addr)
{
  outl(CONFIG_ADDRESS_PORT_BASE, addr & 0xFC);
  return inl(CONFIG_DATA_PORT_BASE);
}
Thank you for your help.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: [ATA DMA Impl.] Content of BAR4 corrupted ?

Post by Combuster »

for me, this value is 0x0000C001), but when I try to read a byte, a word or a dword from this address, it returns 0xFF (or 0xFFFF, ...)
I do hope you know not to read from port C001 but from port C000? The last bits of BARs are used as additional information.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
fiveayem
Member
Member
Posts: 51
Joined: Sun Aug 14, 2011 8:01 am

Re: [ATA DMA Impl.] Content of BAR4 corrupted ?

Post by fiveayem »

Yes, I do read from 0x0000C000 because the two least significant bits are cleared to get the base address. Actually, here is how I perform the call to the function :

Code: Select all

PCIreadDwordFromRawAddress(0x80000000 | (tmpBAR4 & 0xFFFFFFFC));
I also set the enable bit, as it is not set by the function.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: [ATA DMA Impl.] Content of BAR4 corrupted ?

Post by Combuster »

Reading from port 0xC000 is not the same as reading from port 0x0CFC either :roll:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
fiveayem
Member
Member
Posts: 51
Joined: Sun Aug 14, 2011 8:01 am

Re: [ATA DMA Impl.] Content of BAR4 corrupted ?

Post by fiveayem »

So 0xC000 is a port, and not a PCI address ? I don't understand... Why do you say I read from port 0x0CFC ?
Post Reply