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.