Page 1 of 1

Writing simple HDD driver (some questions).

Posted: Sun Dec 12, 2021 6:35 am
by JustVic
As I understand ATA PIO Mode driver is the easiest way to write hdd driver. Is it right? What do I need to start working with ATA? Do I need PCI driver ready first or something else?

Re: Writing simple HDD driver (some questions).

Posted: Sun Dec 12, 2021 6:49 am
by vhaudiquet
ATA PIO Mode driver is the easiest way to write hdd driver. Is it right?
I think so, yes.
Do I need PCI driver ready first or something else?
You don't <need> a PCI driver, because you can use standard ATA ports (0x1F0, 0x3F6, 0x170, 0x376, cf wiki).
However, in theory, a computer could have ATA controllers on other ports, that would be described in the PCI bars.
But if you only want to build a driver, you can for now hardcode the ports and later use PCI to detect all controllers on the device.
If you want to do more advanced stuff, like power managment (putting the drives to sleep when not used, etc...) you will need an ACPI driver ; but that is really complicated stuff (you will need an AML parser, more details on the ACPI wiki page) and not needed at all for a basic driver.

If i can give you an advice, try to read the ATA specifications, don't rely only on the wiki ; the wiki is here to help you know what you have to do and give you an overview of how ATA works, but when implementing a driver, you want to stay as close to the specs as possible. (when i implemented my first ATA driver, i was too lazy to read specs, and i ended up copying the IDENTIFY data structure from somewhere on the web, and it turned out to have wrong fields, and not being the size it is supposed to be...)

Good luck !

Re: Writing simple HDD driver (some questions).

Posted: Sun Dec 12, 2021 7:39 am
by JustVic
vhaudiquet wrote:
ATA PIO Mode driver is the easiest way to write hdd driver. Is it right?
I think so, yes.
Do I need PCI driver ready first or something else?
You don't <need> a PCI driver, because you can use standard ATA ports (0x1F0, 0x3F6, 0x170, 0x376, cf wiki).
However, in theory, a computer could have ATA controllers on other ports, that would be described in the PCI bars.
But if you only want to build a driver, you can for now hardcode the ports and later use PCI to detect all controllers on the device.
If you want to do more advanced stuff, like power managment (putting the drives to sleep when not used, etc...) you will need an ACPI driver ; but that is really complicated stuff (you will need an AML parser, more details on the ACPI wiki page) and not needed at all for a basic driver.

If i can give you an advice, try to read the ATA specifications, don't rely only on the wiki ; the wiki is here to help you know what you have to do and give you an overview of how ATA works, but when implementing a driver, you want to stay as close to the specs as possible. (when i implemented my first ATA driver, i was too lazy to read specs, and i ended up copying the IDENTIFY data structure from somewhere on the web, and it turned out to have wrong fields, and not being the size it is supposed to be...)

Good luck !

Thank you for the useful information. Will try to find and read specification first.