bloggerads

2015年7月6日 星期一

UEFI : DXE Driver


● 何謂Protocol:  
typedef的結構。在UEFI下會綁定GUID,並且透過Driver來安裝Protocol instancehandle. 上層若要控制device,必須透過呼叫Protocol instance來達成。
● Bus Driver Vs. Device Driver: 
Bus Driver會Create Child handle 但Device Driver不會。如果Bus Driver Create的 Child handle是Physical device, Bus Driver 必須安裝Device Path Protocol instance到Child handle
● Driver Initialization:

Driver Image會從儲存裝置(Rom, flash,...)中載入,也就是說,一旦在儲存裝置中找到Driver Image, 就會使用Boot ServiceLoadImage(), Driver Image載入到System Memory. 同時該driver會生成自己的Handle,並且在該Handle下安裝EFI_LOADED_IMAGE_PROTOCOL

typedef
EFI_STATUS
LoadImage (
  IN BOOLEAN BootPolicy,
  IN EFI_HANDLE ParentImageHandle,
  IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, // The DeviceHandle specific file path from which the image is loaded.
  IN VOID *SourceBuffer OPTIONAL,
  IN UINTN SourceSize,
  OUT EFI_HANDLE *ImageHandle // Pointer to the returned image handle that is created when the image is successfully loaded.
  );


裝了EFI_LOADED_IMAGE_PROTOCOL Handle稱之為Image Handle

接著,透過Boot ServiceStartImage()來啟動driverdriver會在Image Handle上安裝其它的Protocol,如果是EFI Driver Modeldriver,那麼會安裝EFI_DRIVER_BINDING_PROTOCOL, 如下,這時Driver Image才真正被當作Driver來處理

//
// Interface structure for the ControllerHandle Driver Protocol
//
typedef struct _EFI_DRIVER_BINDING_PROTOCOL {
  EFI_DRIVER_BINDING_SUPPORTED  Supported;
  EFI_DRIVER_BINDING_START      Start;
  EFI_DRIVER_BINDING_STOP       Stop;
  UINT32                        Version;
  EFI_HANDLE                    ImageHandle;
  EFI_HANDLE                    DriverBindingHandle;
} EFI_DRIVER_BINDING_PROTOCOL;

LoadImage()StartImage()做完之後driver會等待被Boot ServiceConnectController()調用(invoked)去連接到某個Controller。這時在System Memory中已經Load了很多的Driver都在等待被connect到Controller,這時ConnectController()會以Polling的方式去調用每個Driver Handle中的EFI_DRIVER_BINDING_PROTOCOL.Supported(),如果回EFI_SUCCESS,那麼該driver就會被connectcontroller上。之後會透過EFI_DRIVER_BINDING_PROTOCOL.Start()來初始化以及安裝特定的Protocol到此Controller。

沒有留言:

張貼留言