SATA AHCI Driver GSoC - Week 2 Update

by amaneureka | June 7, 2016

In the first week I gained enough knowledge to kick start the coding part. I started implementation with minimal featured design idea i.e. started implementation of non-optional routines first and in order they are being called by Storport/OS. Listed below
  • DriverEntry: Registered the driver with very standard configurations (that I learned by WDK samples) and with non-optional (required entrypoint for Storport) Hw Routines. Standard configuration includes NeedPhysicalAddresses (TRUE)
    TaggedQueuing (TRUE) MultipleRequestPerLu (TRUE)
    AutoRequestSense (TRUE)
    AdapterInterfaceType (PCIBus)
    MapBuffers (STOR_MAP_NON_READ_WRITE_BUFFERS) Intialized the driver with DeviceExtensionSize.
    Structural Details: typedef struct _AHCI_ADAPTER_EXTENSION { ULONG SystemIoBusNumber; ULONG SlotNumber; ULONG AhciBaseAddress; PULONG IS; // Interrupt Status, In case of MSIM == '1' ULONG PortImplemented;// bit-mapping of ports which are implemented USHORT VendorID; USHORT DeviceID; USHORT RevisionID; ULONG Version; ULONG CAP; ULONG CAP2; PVOID NonCachedExtension;// holds virtual address to noncached buffer allocated for Port Extension BOOLEAN MessagePerPort;// Message Per port or shared port? PAHCI_MEMORY_REGISTERS ABAR_Address; AHCI_PORT_EXTENSION PortExtension[MAXIMUM_AHCI_PORT_COUNT]; } AHCI_ADAPTER_EXTENSION, *PAHCI_ADAPTER_EXTENSION;
  • HwFindAdapter: Reterived Adapter Specific informations like VendorID, DeviceID, RevisionID, AhciBaseAddress, NumberOfPorts, Version, ABAR_Address and Populated adapter extension with this information. Also, Intialized adapter by restarting it to a known state, Allocated Resources (Port Extension) for all the available ports. I faced problem in resource allocation part. Actually there are two type of memory allocation we need here, one is for HBA (Command Header List and Recieved FIS) but for that we can allocate memory through UncachedExtension, Other memory buffer we need for storing port extension details. Due to non-contigous (and limited memory of 30K) nature of UncachedExtension we can't allocate memory through it. And StorAllocatePool is not implemented in earlier (win2k3) versions. After some back and forth emails with my mentor, we settled on idea of allocating all memory in DevicExtension itself, and later if we find as such use of Storport Extended function we will implement StorAllocatePool (in ROS version of Storport) and update the driver. That update would be very easy, because It would require some little changes only. So no harm in having a temporary fix.