How should I read disk configuration information with AHCI?

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
shore
Posts: 15
Joined: Wed Sep 04, 2019 9:00 pm

How should I read disk configuration information with AHCI?

Post by shore »

Hi I wrote the AHCI drive with the help of https://wiki.osdev.org/AHCI.

It successfully read and write sectors.

However there is no information on how to read disk configuration info.

All after all, how should I know how many sectors in the disk?

Can anyone help?? Thanks a lot!

BTW, I'm using Qemu as my emulator, the command of running:

Code: Select all

qemu-system-x86_64 -machine q35 -cpu Broadwell -accel kvm -smp 4,cores=2,threads=2,sockets=1 -m 1G -hda Boot.disk -hdb hdb.disk
Octocontrabass
Member
Member
Posts: 5578
Joined: Mon Mar 25, 2013 7:01 pm

Re: How should I read disk configuration information with AH

Post by Octocontrabass »

Issue a host-to-device register FIS with the IDENTIFY DEVICE command (0xEC). Note that this is a PIO command, so you may need to do some additional work to support that if you've only been using DMA commands so far.

A draft of ACS-4 can be found here (PDF) which includes a description of the data the drive will return.
shore
Posts: 15
Joined: Wed Sep 04, 2019 9:00 pm

Re: How should I read disk configuration information with AH

Post by shore »

Octocontrabass wrote:Issue a host-to-device register FIS with the IDENTIFY DEVICE command (0xEC). Note that this is a PIO command, so you may need to do some additional work to support that if you've only been using DMA commands so far.

A draft of ACS-4 can be found here (PDF) which includes a description of the data the drive will return.
Hi thanks a lot. May I further ask one more question that with the PIO command, does it mean I'll have to read the data from port 0x1F0??
shore
Posts: 15
Joined: Wed Sep 04, 2019 9:00 pm

Re: How should I read disk configuration information with AH

Post by shore »

I tried directly send FIS and it actaully returns the identity information with DMA method. Seems like I do not need to read it from port........
User avatar
BenLunt
Member
Member
Posts: 941
Joined: Sat Nov 22, 2014 6:33 pm
Location: USA
Contact:

Re: How should I read disk configuration information with AH

Post by BenLunt »

Octocontrabass wrote:Note that this is a PIO command, ...
Octocontrabass,

You are correct, however, I believe this is only with ATA and ATAPI devices, not AHCI (SATA) devices.

With ATA and ATAPI controllers and devices, yes, you must use Port I/O reads for this command.

However, with SATA controllers and devices (AHCI as shown in the OP's request), this is not the case, since you use PRD Tables.

However, please correct me if I am wrong.

Ben
Octocontrabass
Member
Member
Posts: 5578
Joined: Mon Mar 25, 2013 7:01 pm

Re: How should I read disk configuration information with AH

Post by Octocontrabass »

BenLunt wrote:With ATA and ATAPI controllers and devices, yes, you must use Port I/O reads for this command.

However, with SATA controllers and devices (AHCI as shown in the OP's request), this is not the case, since you use PRD Tables.

However, please correct me if I am wrong.
I think you're mixing up the physical devices with the programming interface. The type of device (parallel vs serial) is irrelevant, all that matters is the controller's programming interface (IDE vs AHCI). A SATA controller may support either programming interface. In theory, a parallel ATA controller may also support either programming interface, though in practice you'll only ever see IDE.

The ATA specifications define a few classes of commands, including PIO commands and DMA commands. With a controller using the IDE programming interface, you must use programmed I/O for PIO commands. I'm not especially familiar with AHCI, but it looks like AHCI controllers will perform DMA on your behalf when you issue a PIO command.
Post Reply