You are on page 1of 14

AHCI: ATAport Miniport Example

Outline

AHCI Features
Goals
Basics
AHCI ATA Miniport Design Philosophy
Memory Structures and Resources
Enumeration
IO Creation
Error Handling
Role of AHCI

Industry transitioning to SATA, AHCI provides a


standard interface and is facilitating adoption
Implementing AHCI interface in a controller
doesnt prevent the controller from implementing
8038i/PCIIDE
AHCI follows advancements in PCI
PCI 2.3, power management, MSI, etc.
AHCI comprehends SATA features
Feature Basics
8038i/PCIIDE (PATA) AHCI 1.0 (SATA)
Controller Resources Controller Resources
IO Port Memory Mapped
2 channel per controller 32 channels per controller
2 devices per channel 15 devices per channel
Interrupt Capabilities Interrupt Capabilities
Interrupt per channel Selective interrupt hierarchy
No hot plug Hot plug supported
No power management Link power management
No notification Asynchronous notification
IO Capabilities IO Capabilities
PIO interrupt per DRQ PIO through DMA
Software queuing Hardware queuing
Tagged Command Queuing Native Command Queueing
AHCI Design: Memory Structures and Resources
Controller Extension
ABAR
AdapterControl w/ IdeStart receives ABAR as part of
ControllerConfiguration->ControllerResources
Channel Extension
One per channel
Uncached Extension
One per channel
Page aligned
Contains Command List and FIS Receive Buffer
IRB Extension
Contains Command Table
First IRBs Extension is Page aligned, all other IRB
Extensions are IRB Extension size aligned
AHCI Design: Synchronization

Per channel, only one channel entry point will be


running at a time
AdapterControl
The port driver ensures that there is no outstanding I/O
on the adapter before invoking this routine.
Interrupts are enabled just before the HwControl
w/ IdeStart is called. If Interrupts are enabled, the
Interrupt routine may be called after this.
AHCI Design: IRB Return Values
If the IRB status is not
IRB_STATUS_DEVICE_ERROR, the port
assumes that the miniport has done the error
translation already and so the Error register is
ignored.
IRB_STATUS_PENDING is used internally to
signal waiting on interrupt. The miniport should
not complete IRB if it is still waiting on an
interrupt.
IRB_STATUS_DATALENGTH_MISMATCH
Return the actual byteCount
Irb->DataTransferLength -=
GetBytesLeft(ChannelExtension, Irb);
Dont set this on RequestSense IRBs, as the amount of
data expected is unknown
AHCI Design: IRB Return Values (cont)

IRB_STATUS_BUSY should be used when


device is busy and the miniport wants the
ATAport driver to retry the command.
Use BUSY with AtaPortCompleteAllActiveRequests
Always pause ATAport queues with
AtaPortDeviceBusy() when returning BUSY
IRB_STATUS_SELECTION_TIMEOUT should be
used when the controller is not capable of
handling IO. The ATAport driver will not retry the
command.
IRB_STATUS_BUS_RESET
IRB_STATUS_INVALID_REQUEST
IRB_STATUS_SUCCESS
AHCI Design: Enumeration

Port sends ID_DEVICE, then


ID_PACKET_DEVICE (or vice versa)
IRBs completed with IRB_STATUS_BUSY will be
retried
All other IRB status values will be interpreted as
enumeration failure
Status 0xFF, 0xFE will be interpreted as no device
Enabling an AHCI channel (CMD.ST) may take
milliseconds. Pausing ATAport queues can be an
effective StallTimer if attempts to move the
controller to P:Running are made from StartIo.
AHCI Design: Creating IO

Miniports create IRBs only in uncommon


circumstances
Request Sense
AtaPortBuildRequestSenseIrb (ChannelExtension, root IRB)
Request Sense IrbExtension is the same as the Request
Sense root IRBs IrbExtension
Dont use SGList, use IRB Data Buffer
Read Log Ext
Used to determine NCQ failures
Set Features
HwInitialize
AtaPortCompleteAllActiveRequests do not
complete miniport created IRBs
however it will complete Request Sense root IRBs
AHCI Design: Crashdump

Must be handled at any time


The miniport driver is reloaded
Only kernel, ATAport and miniport are running,
therefore initialization is very fast
The port driver will only enable the channel that
contains the device with the page file
The controller is very likely enabled (AE = 1) and
handling IO, in which case it must be stopped
and restarted
AHCI Design: Miscellaneous

Hotplug
Interrupt routine should use AtaPortDeviceArrived and
AtaPortDeviceRemoved for hotplug events
Causes ATAport to invalidate device relations
appropriately
Reset/Error Handling
AtaPortCompleteAllActiveRequests is very handy.
Complete everything with BUSY, restore stability, and
let the ATAport driver handle retrying commands
Additional Resources

ATA Miniport Interface


Documented in the WDK
List of Specifications
ATA: http://www.t13.org
SATA: http://www.serialata.org
SCSI: http://www.t10.org
AHCI:
http://developer.intel.com/technology/serialata/ahci.htm
WhitePapers
ATA Miniport Design Guide
MSI Guidance
http://download.microsoft.com/download/5/7/7/577a568
4-8a83-43ae-9272-ff260a9c20e2/MSI.doc
2005 Microsoft Corporation. All rights reserved.
This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary.

You might also like