ATA drivers

Leonardo Passos lnrdpss at gmail.com
Mon Sep 16 02:04:38 UTC 2013


Hi there,

I am currently investigating drivers in FreeBSD, with a particular focus on
ATA. However some doubts came up, and since I could not find my answers in
existing documentation, I would like to clarify some points. In particular,
I would like to verify whether my current understanding is correct.

Suppose I want to implement a "foo" driver in two specific scenarios:

Scenario 1) Support for an ATA bus

"To support an ATA-based device, I needed a proper driver. The driver, in
this case, is a driver for an ATA bus. My driver has to work with specific
controllers, which must be checked in the probe function of the driver.
Upon successful probe, the attach function is called, in which case my
driver sets specific configurations that are dependent on the previously
checked controller. In the end of the probe, method, I register the the new
device (e.g., a hardisk) by calling ata_attach".

Example driver: sys/powerpc/powermac/ata_macio.c

Scenario2) Support for ATA on top of PCI

"In this case, my driver stands for an ATA-controller that is plugged into
the PCI bus. In such a case, my driver must use ATA_DECLARE_DRIVER(foo),
instead of the DRIVER_MODULE macro (as it occurred in scenario 1). Further,
I must declare a function foo_probe, as required by the ATA_DECLARE_DRIVER
(see ata-pci.h). In the probe function, I verify whether the device (an ATA
controller, not a disk) is supported, and if so, set its chipinit function
pointer (this field is part of ata_pci_controller instance, gotten by
calling device_get_softc on the newly identified controller). In the
chipinit function, I set an attach function for that ATA controller (this
is performed by setting the ch_attach field over the ata_pci_controller
instance). The registered attach function will be called whenever new disks
are attached to the bus of the added ATA controller. That function in turn,
will set any configuration parameters and add a new disk into the system,
by calling ata_pci_ch_attach".

Example drivers:
sys/dev/ata/chipsets/ata-amd.c
sys/dev/ata/chipsets/ata-intel.c

Is the workflow just described correct? Stated otherwise, when supporting
ATA devices, should I only be concerned with implementing proper bus
support, that in turn, will register its managed disks? In that sense, I,
as a driver developer, do not need to concern about how IO is actually
performed, as the driver infrastructure of the kernel will handle any
attached disk once it is configured by a bus driver?

Thanks,

Leo.


More information about the freebsd-drivers mailing list