Cstyle的UEFI导读之ATA Driver Stack

   

===================================================================== 

固件C字营·版权所有·欢迎转载
敬请关注微信公众号:“固件C字营”
敬请关注QQ群:1052307
敬请关注CSDN博客:Cstyle_0x007

图片

===================================================================== 

        聊下SATA,可以说SATA是我们最常见的硬盘接口了,目前PC机上除了一些服务器上会使用SCSI接口的硬盘和少数的所谓的超级本上会使用一些SATA的变种msata(miniPCI-E界面)之外基本我们的硬盘都是使用SATA最为传输接口,我们所有的文件传输都必须通过它来进行传输,可见他的重要性。闲话免谈,咱们来说说SATA driver,它还是分成几个层次如下:

 

ATA host controller driver:
    一般的SATA控制器都是挂在PCI总线下,
 所以ATA host controller driver一般是消费host controller handle上的PCI I/O Protocol,生产
TA Pass Thru Protocol 来访问硬盘设备,
Ext SCSI Pass Thru Protocol来访问CD/DVD。
ATA bus driver:
    消费ATA Pass Thru Protocol,为控制器下挂的设备生产出child handle,并为其installDevice Path Protocol,Block I/O Protocol, Block I/O 2 Protocol以及Storage Security Command Protocol.
 、
ATA Host Controller Driver的实现:   
    host controller driver的实现和硬件平台息息相关的,不同的平台有不同的硬件配置,host controller数量也不一样,通常一个host controller driver需要控制多个控制器,所以我们需要确保driver的实现是可重入的,并为每一个控制器分配独立是私有的数据结构空间。实现步骤如下:
1.为每一个 ATA host controller handle Install the ATA Pass Thru Protocol
2. 为每一个 SCSI host controller handle Install Extended SCSI Pass Thru Protocol 
ATA Host Controller Driver :Supported()
    和PCIdriver一样先locate并open EFI_DEVICE_PATH_PROTOCOL 、 EFI_PCI_IO_PROTOCOL然后使用PCI IO Protocol 提供的服务去检测设备的VID、DID,Subclass Code。
ATA Host Controller Driver :Start()
初始化ATA host controller,一般有以下的步骤,他们和其他的driver基本一样:
1.Enable the PCI device.
2.Allocate resources.
3.Construct  data structures for the driver to use.
4. Install the  ATA Pass Thru Protocol instance on the  same handle that has the PCI I/O Protocol.
5. Install the  Extended SCSI Pass Thru Protocol instance on the  same handle thathas the PCI I/O Protocol.
ATA Host Controller Driver :Stop()
完成和start相反的动作:
1.Disable the ATA controller.
2. Release all resources that were allocated for this driver.
3. Close the protocol instances that were opened in the Start()function.
4. Uninstall the protocol interfaces that were attached on the host controller handle.
EFI_ATA_PASS_THRU_PROTOCOL 数据结构:
    EFI_ATA_PASS_THRU_PROTOCOL会被用来获取挂在ATA host controller上的设备的各种信息和传递ATA数据请求包给设备,即使是这个设备不是可启动设备,这个通常可以用来作为一个诊断外设的手段。它还可以为那些需要作为启动设备devide handle的block I/O driver提供底层访问的软件抽象和封装。
EFI_ATA_PASS_THRU_PROTOCOL.Mode
        通常来获取和设定各种参数,EFI_ATA_PASS_THRU_ATTRIBUTES_PHYSICAL|EFI_ATA_PASS_THRU_ATTRIBUTES_NONBLOCKIO|EFI_ATA_PASS_THRU_ATTRIBUTES_NONBLOCKIO|
        EFI_ATA_PASS_THRU_ATTRIBUTES_LOGICAL等等。
EFI_ATA_PASS_THRU_PROTOCOL.GetNextPort()/EFI_ATA_PASS_THRU_PROTOCOL.GetNextDevice(): 用来扫描所有的ATA设备。
EFI_ATA_PASS_THRU_PROTOCOL.BuildDevicePath():建立设备路径.
EFI_ATA_PASS_THRU_PROTOCOL.PassThru():这个是主角,有以下的功能,
    1.Initialize the internal register for command/data transfer.
    2.Put valid ATA commands into hardware-specific memory or register locations.
    3.Start the transfer.
    4.Optionally  wait for completion of the execution.通常使用阻塞的传输模式。

 
ATA bus driver的实现:
使用 ATA Pass Thru Protocol 去扫描 挂在ATA host controller下面的设备并且生产出 child handles,然后完成以下步骤,通常来说bus driver是通用driver我们一般不需要修改,porting到新平台的时候我们只需要修改和硬件平台相关的ATA Host Controller Driver就可以了:
1.Install Device Path Protocol to each child handle.
2. Install Block I/O Protocol on each child handle.
3. Install Block I/O 2 Protocol on each child handle.
4. If the hard drive supports the SPC-4 or ATA8-ACS command set, then install the Storage Security Command Protocol the child handle.
好了ATA部分就先到这里,下次再补上SCSI Pass Thru Protocol的部分,希望通过这个说明能对ATA driver有一个简单的了解。
转载请注明出处Cstyle.z.zhou@gmail.com//http://blog.csdn.net/CStyle_0x007

===================================================================== 

固件C字营·版权所有·欢迎转载
敬请关注微信公众号:“固件C字营”
敬请关注QQ群:1052307
敬请关注CSDN博客:Cstyle_0x007

图片

===================================================================== 

@微信公众号《固件C字营》不定期更新状态,关注&订阅公众号不迷路。

完整PDF版整理中,可以在CSDN下载频道搜索”UEFI内核导读“下载样张......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值