Page 1 of 1

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

Posted: Wed Aug 24, 2011 12:43 pm
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.

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

Posted: Wed Aug 24, 2011 1:13 pm
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.

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

Posted: Wed Aug 24, 2011 3:20 pm
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.

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

Posted: Wed Aug 24, 2011 11:10 pm
by Combuster
Reading from port 0xC000 is not the same as reading from port 0x0CFC either :roll:

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

Posted: Thu Aug 25, 2011 8:24 am
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 ?