Page 1 of 1

Wiki AHCI disk reading example broken?

Posted: Fri Feb 19, 2021 4:41 am
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

Re: Wiki AHCI disk reading example broken?

Posted: Fri Feb 19, 2021 8:21 pm
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.

Re: Wiki AHCI disk reading example broken?

Posted: Sat Feb 20, 2021 12:05 am
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