What about PCI mmio access alignment?
Hi, guys,
I have a basic quesion about the alignment when access PCI bar mmio space. Is the address accessed must be DW aligned and count must be DW aligned?
As far as I know, The address field of TLB ignore lower 2 bits and the unit of length field also is DW. So does it mean above question is Yes? Else will CPU handle unaligned access for mmio space?
I want to know wether below access illegal or not:
- readb(bar0)
- readb(bar0 + 1)
- readl(bar0)
Thanks,
Changbin Du
Quoted 2 lines · Changbin
I have a basic quesion about the alignment when access PCI bar mmio space. Is the address accessed must be DW aligned and count must be DW aligned?
I guess the best answer is PCI architecture specification. Book I have nearby tells me IIDnMS that yes, you have to follow alignment.
Quoted 3 lines
As far as I know, The address field of TLB ignore lower 2 bits and the unit of length field also is DW. So does it mean above question is Yes? Else will CPU handle unaligned access for mmio space?
Here you perhaps meant the bus, not the CPU. PCI allows it as long as actual device allows it.
(I recall patch series that tries to micro optimize PCI config space access by grouping some bytes into words or even dwords, and it was rejected).
Quoted 4 lines
I want to know wether below access illegal or not:
- readb(bar0)
- readb(bar0 + 1)
- readl(bar0)
It depends.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Thank you. I have some experiment on my PC. The result is:
o I always can get expected value if the unaligned access doesn't across a DWORD boundary, like readw(bar0+1). I suspect that the chipset should read a whole DWORD in behind. This may trigger unexpected behaviour on device.
o If read across DWORD boundary, I get some intersting value, like readl(bar0+2). For some device, I get a cyclic shifted value of the first DWORD, while some device return all FF.
So my conclusion is that no unaligned access and at least access one DWORD size.
Quoted 28 lines · Andy Shevchenko
Quoted 2 lines · Changbin
I have a basic quesion about the alignment when access PCI bar mmio space. Is the address accessed must be DW aligned and count must be DW aligned?
I guess the best answer is PCI architecture specification. Book I have nearby tells me IIDnMS that yes, you have to follow alignment.
Quoted 3 lines
As far as I know, The address field of TLB ignore lower 2 bits and the unit of length field also is DW. So does it mean above question is Yes? Else will CPU handle unaligned access for mmio space?
Here you perhaps meant the bus, not the CPU. PCI allows it as long as actual device allows it.
(I recall patch series that tries to micro optimize PCI config space access by grouping some bytes into words or even dwords, and it was rejected).
Quoted 4 lines
I want to know wether below access illegal or not:
- readb(bar0)
- readb(bar0 + 1)
- readl(bar0)It depends.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Signature · 2 lines
Thanks, Changbin Du