Should we read BAR type before writing all F's to the BAR or before that?

0

I am working on a PCI express driver. I am reading the BAR of the root complex device to find the memory type and the size it requires. I know that to find the size of memory we need to write all F's to the BAR and read it back, clear the last 4 bits, invert it and then add 1. I am confused about when to read the last 4 bytes to know the type of BAR. Should I read it before writing all F's or after that?

For example in my case when I read the bar before writing F's, I get 0x0000000C. It means that it is a 64 bit prefetchable memory bar. But when I read it after writing all 1's, it returns 0xffff000f. According to the last 4 bits here, it is an I/O bar.

Can someone please guide me which of these BAR types is the correct one.

driver
pci-e
asked on Stack Overflow Feb 14, 2018 by Amna • edited Feb 14, 2018 by Vadim Kotov

1 Answer

0

It doesn't matter whether you check the low four bits before or after you write F's. Those bits are not writable. If they change, then there is something wrong with the device. But first check your code; it is more likely to be something wrong in your code.

answered on Stack Overflow Feb 14, 2018 by prl

User contributions licensed under CC BY-SA 3.0