Wiki AHCI disk reading example broken?

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
8infy
Member
Member
Posts: 185
Joined: Sun Apr 05, 2020 1:01 pm

Wiki AHCI disk reading example broken?

Post by 8infy »

Looks like osdev wiki example decrements count, and then only writes however much the last PRDT would read. Is that supposed to be that way?

Image

Also, does AHCI use the byte count from the PRDT or (sector count) from this FIS to read sectors? What if I use byte count that's less/not aligned to sector size in PRDT?
Is there any specific reason why this example reads 8k per prdt?

Thanks
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Wiki AHCI disk reading example broken?

Post by Octocontrabass »

8infy wrote:Looks like osdev wiki example decrements count, and then only writes however much the last PRDT would read. Is that supposed to be that way?
That looks like a bug. The command FIS is sent directly over the wire unmodified, so it must tell the drive the total number of sectors to read.
8infy wrote:Also, does AHCI use the byte count from the PRDT or (sector count) from this FIS to read sectors?
The byte count in the PRDT tells the AHCI controller how many bytes it should expect to receive from the drive. The sector count in the CFIS tells the drive how many sectors to send.
8infy wrote:What if I use byte count that's less/not aligned to sector size in PRDT?
All of the entries in your PRDT need to add up to at least the total number of bytes you're going to read, but the individual entries only need to be aligned to 2-byte boundaries.
8infy wrote:Is there any specific reason why this example reads 8k per prdt?
It's probably a misinterpretation of the spec. AHCI controllers are limited to 8kiB per DRQ data block, so you must avoid using PIO commands with larger DRQ data blocks. Most PIO commands transfer only one sector per DRQ data block, so you only need to look out for PACKET (without the DMA bit set) and the READ/WRITE MULTIPLE family of commands. The limit doesn't apply to DMA commands, and it definitely doesn't apply to the PRDT.
8infy
Member
Member
Posts: 185
Joined: Sun Apr 05, 2020 1:01 pm

Re: Wiki AHCI disk reading example broken?

Post by 8infy »

Octocontrabass wrote:
8infy wrote:Looks like osdev wiki example decrements count, and then only writes however much the last PRDT would read. Is that supposed to be that way?
That looks like a bug. The command FIS is sent directly over the wire unmodified, so it must tell the drive the total number of sectors to read.
8infy wrote:Also, does AHCI use the byte count from the PRDT or (sector count) from this FIS to read sectors?
The byte count in the PRDT tells the AHCI controller how many bytes it should expect to receive from the drive. The sector count in the CFIS tells the drive how many sectors to send.
8infy wrote:What if I use byte count that's less/not aligned to sector size in PRDT?
All of the entries in your PRDT need to add up to at least the total number of bytes you're going to read, but the individual entries only need to be aligned to 2-byte boundaries.
8infy wrote:Is there any specific reason why this example reads 8k per prdt?
It's probably a misinterpretation of the spec. AHCI controllers are limited to 8kiB per DRQ data block, so you must avoid using PIO commands with larger DRQ data blocks. Most PIO commands transfer only one sector per DRQ data block, so you only need to look out for PACKET (without the DMA bit set) and the READ/WRITE MULTIPLE family of commands. The limit doesn't apply to DMA commands, and it definitely doesn't apply to the PRDT.
Awesome, thanks for the detailed answer
Post Reply