聊下Override Protocol,不过在此之前先说下版本的问题。假设你需要用到某个driver提供的功能,除了想知道它所能提供的install的protocol之外,或许你还想知道这个driver是遵循UEFI的那一版本的spc来做的,应为每一个版本所提供的服务会有些许差异,那么Driver是如何向其他的driver或者是APP提供这种信息呢,答案就是:Driver Supported EFI Version Protocol。它允许UEFI driver提供一个指示其遵循的UEFI spc的规范的版本,这个版本号的格式于EFI_TABLE_HEADER中的Revision字段的格式保持一致。和其他的protocol一样,需要提供基本的信息和步骤如下,就不细说:
1.Add
global variable for the EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL instance to <<DriverName>>.c
2. Set the FirmwareVersion field of the Driver Supported EFI Version Protocol instance in the driver entry point if the value required is different than the value assigned in the global variable declaration.
3. Install the Driver Supported EFI Version Protocol instance onto the
ImageHandle of the UEFI Driver in the driver entry point.
4. If the UEFI Driver supports the unload feature, uninstall the Driver Supported EFI Version Protocol instance in the Unload() function.
EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL 数据结构:
EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL的install使用:
版本格式列表:
下面正式介绍下几个Override Protocol,一个是
Driver Family Override Protocol另外一个是
Bus-Specific Driver Override Protocol,Platform Driver Override下面一个一个介绍。
Bus-Specific Driver Override Protocol:
是可选的,一般用于,为bus的child device提供uefi driver容器的的总线控制器,目前来说只有PCI总线需要实现Bus-Specific Driver Override Protocol,它的容器就是PCI option ROM。PCI bus driver需要为那些配有pci oprion rom并且rom里面包含了一个以上的可加载的uefi driver的pci设备生产该protocol。如果设备没有没有配PCI option rom或者没有可加载的UEFI driver哪么就不需要实现该protocol。
Bus Specific Driver Override
Protocol实现:
参考实例
参考实例
BusSpecificDriverOverride.c,和其他的普通的protocol一样他需要满足以下的一些基本条件和实现步骤:
1.Add the EFI_BUS_SPECIFIC_DRIVER_OVERRIDE_PROTOCOL instance to the design of the
private context data structure.
2. Add private fields to the design of the private context data structure that support managing the set of driver image handles returned by GetDriver().
3. Update private content data structure initialization to initialize the Bus Specific Driver Override Protocol instance and the private fields used to manage the set of driver image handles returned by GetDriver().
4. Implement the GetDriver() service to return set-of-driver image handles from the private context data structure.
5. Implement private worker functions to add/remove driver image handles from set-of-driver image handles maintained in the private context data structure.
6. Install the Bus Specific Driver Override Protocol onto the
child handle the bus driver produces in the Driver Binding Start() function.
7. Uninstall the Bus Specific Driver Override Protocol from the child handle the bus driver produces in the Driver Binding Stop() function.
Bus Specific Driver Override Protocol提供了一个服务GetDriver(),它能获取到一张从uefi driver容器中加载的driver image handle列表。这张表有很多的实现方式可以使用普通的表格,也可以使用链表。在pci系统中这张表的排序和从oprom rom中加载uefi driver的顺序相同(oprom rom是从低地址到高地址一个一个加载到内存中,并且创建image handle),pci bus driver会以一定的方式扫描所有的pci设备当发现pci设备的时候,它会去检查该设备是否配有optiom rom,如果有一个以上符合pci spc的rom存在存在,就会在rom中索引uefi driver,如果找到了driver就会选择使用Decompress Protocol来解压出rom中的uefi driver到内存,同时使用BS提供的LoadImage() /StartImage()服务来加载驱动。如果LoadImage()成功的话,就好把driver添加到device的driver 列表里末端去。当Bus Specific Driver Override Protocol提供的GetDriver()服务被调用的时候,设备的driver列表就会返回给调用者。
Bus Specific Driver Override Protocol数据结构:
Bus Specific Driver Override Protocol私有数据结构及实现:
device的私有数据结构是在pci bus driver发现设备并创建child handle的时候初始化的,同时在设备的Driver Binding Protocol Start()服务中调用BS服务InstallMultipleProtocolInterfaces来install该protocol到bus driver产生的child handle上面去,在stop()服务Uninstall该protocol中如下图:
Bus Specific Driver Override Protocol的GetDriver()服务实现:
PCI系统中的参考driver image handle列表实现是用的数组,下面的示例是穷举数组找到image handle并返回.
AddDriver()服务是由PCI bus driver在扫描到pci设备的时候调用来往设备的Bus Specific Driver Override Protocol的私有数据里面的driver image handle列表里面添加image handle。
Driver Family Override Protocol:
是UEFI driver modle的driver可选实现的一个protocol,它提供了BS服务onnectController()在connect driver到controller的时候的一个可选的高优先级的connect规则。
它的优先级高于 Bus Specific Driver Override Protocol 但是低于Platform Driver Override 。
Driver Family Override Protocol是被 ,多个版本的driver同时联系着同一个家族中同时存在的功能类似的controller的系统中,同时开发者希望最高的版本的driver控制所有的同一个家族的所有的controller的某个driver产生的。PCI 设备使用到的情况:
假设系统平台有三张来自同一个厂家的PCI SCSI卡,并且希望用最高版本的driver去控制所有的三张卡,那么我们就可以使用Driver Family Override Protocol来提供一个driver版本来供选择,如果没有提供的话,PCI Bus-Specific Driver Override Protocol就会从PCI option rom中选择uefi driver去控制每一张卡。
Driver Family Override Protocol Implementation:
参考实现在UDK的DriverFamilyOverride.c文件中能找到,和其他的普通的protocol一样它需要定义数据结构和基本的步骤:
1.Add
global variable for the EFI_DRIVER_FAMILY_OVERRIDE_PROTOCOL instance to
DriverFamilyOverride.c.
2. Implement the
GetVersion() service of the Driver Family Override Protocol in
DriverFamilyOverride.c.
3.
Install the Driver Family Override Protocol onto the
same handle that the
Driver Binding Protocol is installed.
4.If the UEFI Driver produces
multiple Driver Binding Protocols, install the Driver
Family Override Protocol on the
same handles as that of the Driver Binding
Protocol.
5. If the UEFI Driver supports the unload feature,
uninstall all the Driver Family
Override Protocol instances in the Unload() function.
GetVersion()服务会获取到的driver的版本提供给UEFI Boot Service ConnectController(),并由ConnectController()决定Driver Binding Protocol去start一个controller的顺序。
数据结构定义:
实现示例:
如下,在image handle上使用BS提供的服务install了两个protocol一个是driver binding protocol一个是driver family override protocol。
Driver Family Override Protocol的GetVersion()方法 实现:
至此Driver Family Override Protocol的GetVersion()算是基本介绍完了,下面接着介绍其他的protocol。
Platform Driver Override:(暂缺)

UEFI OverrideProtocol详解
9392

被折叠的 条评论
为什么被折叠?



