UEFI驱动代码
UEFI驱动模型
UEFI一个完整得驱动分为:
- EFI Driver Binding Protocol
 - 驱动服务
 - EFI Component Protocol 为用户提供接口
 
EFI Driver Binding Protocol
结构体描述
typedef struct _EFI_DRIVER_BINDING_PROTOCOL EFI_DRIVER_BINDING_PROTOCOL;struct _EFI_DRIVER_BINDING_PROTOCOL {EFI_DRIVER_BINDING_SUPPORTED Supported; // 检测某一个设备是否支持该驱动EFI_DRIVER_BINDING_START Start; // 驱动安装接口EFI_DRIVER_BINDING_STOP Stop; // 驱动卸载接口UINT32 Version; // EDBP版本号EFI_HANDLE ImageHandle; // EDBP映像文件句柄EFI_HANDLE DriverBindingHandle; // 安装EDBP得Handle};
驱动加载接口
edk2\MdeModulePkg\Core\Dxe\Hand 目录提供了以下几个接口
EFI_STATUS EFIAPICoreConnectController (IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE *DriverImageHandle OPTIONAL,IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,IN BOOLEAN Recursive);EFI_STATUSCoreConnectSingleController (IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE *ContextDriverImageHandles OPTIONAL,IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL);EFI_STATUSEFIAPICoreDisconnectController (IN EFI_HANDLE ControllerHandle,IN EFI_HANDLE DriverImageHandle OPTIONAL,IN EFI_HANDLE ChildHandle OPTIONAL);
PCI驱动
协议注册
//// PCI Bus Driver Global Variables//EFI_DRIVER_BINDING_PROTOCOL gPciBusDriverBinding = {PciBusDriverBindingSupported,PciBusDriverBindingStart,PciBusDriverBindingStop,0xa,NULL,NULL};
初始化代码
PciBusDriverBindingStartPciEnumeratorPciHostBridgeEnumerator
打印信息
PCI Bus First ScanningPciBus: Discovered PCI @ [00|00|00]PciBus: Discovered PCI @ [00|01|00]PciBus: Discovered PCI @ [00|01|01]BAR[4]: Type = Io32; Alignment = 0xF; Length = 0x10; Offset = 0x20PciBus: Discovered PCI @ [00|01|03]PciBus: Discovered PCI @ [00|02|00]BAR[0]: Type = PMem32; Alignment = 0xFFFFFF; Length = 0x1000000; Offset = 0x10BAR[2]: Type = Mem32; Alignment = 0xFFF; Length = 0x1000; Offset = 0x18PciBus: Discovered PCI @ [00|03|00]BAR[0]: Type = Mem32; Alignment = 0x1FFFF; Length = 0x20000; Offset = 0x10BAR[1]: Type = Io32; Alignment = 0x3F; Length = 0x40; Offset = 0x14PCI Bus Second ScanningPciBus: Discovered PCI @ [00|00|00]PciBus: Discovered PCI @ [00|01|00]PciBus: Discovered PCI @ [00|01|01]BAR[4]: Type = Io32; Alignment = 0xF; Length = 0x10; Offset = 0x20PciBus: Discovered PCI @ [00|01|03]PciBus: Discovered PCI @ [00|02|00]BAR[0]: Type = PMem32; Alignment = 0xFFFFFF; Length = 0x1000000; Offset = 0x10BAR[2]: Type = Mem32; Alignment = 0xFFF; Length = 0x1000; Offset = 0x18PciBus: Discovered PCI @ [00|03|00]BAR[0]: Type = Mem32; Alignment = 0x1FFFF; Length = 0x20000; Offset = 0x10BAR[1]: Type = Io32; Alignment = 0x3F; Length = 0x40; Offset = 0x14PciBus: Discovered PCI @ [00|00|00]PciBus: Discovered PCI @ [00|01|00]PciBus: Discovered PCI @ [00|01|01]BAR[4]: Type = Io32; Alignment = 0xF; Length = 0x10; Offset = 0x20PciBus: Discovered PCI @ [00|01|03]PciBus: Discovered PCI @ [00|02|00]BAR[0]: Type = PMem32; Alignment = 0xFFFFFF; Length = 0x1000000; Offset = 0x10BAR[2]: Type = Mem32; Alignment = 0xFFF; Length = 0x1000; Offset = 0x18PciBus: Discovered PCI @ [00|03|00]BAR[0]: Type = Mem32; Alignment = 0x1FFFF; Length = 0x20000; Offset = 0x10BAR[1]: Type = Io32; Alignment = 0x3F; Length = 0x40; Offset = 0x14PciHostBridge: SubmitResources for PciRoot(0x0)I/O: Granularity/SpecificFlag = 0 / 01Length/Alignment = 0x1000 / 0xFFFMem: Granularity/SpecificFlag = 32 / 00Length/Alignment = 0x1100000 / 0xFFFFFFPciBus: HostBridge->SubmitResources() - SuccessPciHostBridge: NotifyPhase (AllocateResources)RootBridge: PciRoot(0x0)Mem: Base/Length/Alignment = 80000000/1100000/FFFFFF - SuccessI/O: Base/Length/Alignment = C000/1000/FFF - SuccessPciBus: HostBridge->NotifyPhase(AllocateResources) - SuccessPciBus: Resource Map for Root Bridge PciRoot(0x0)Type = Io16; Base = 0xC000; Length = 0x1000; Alignment = 0xFFFBase = 0xC000; Length = 0x40; Alignment = 0x3F; Owner = PCI [00|03|00:14]Base = 0xC040; Length = 0x10; Alignment = 0xF; Owner = PCI [00|01|01:20]Type = Mem32; Base = 0x80000000; Length = 0x1100000; Alignment = 0xFFFFFFBase = 0x80000000; Length = 0x1000000; Alignment = 0xFFFFFF; Owner = PCI [00|02|00:10]; Type = PMem32Base = 0x81000000; Length = 0x20000; Alignment = 0x1FFFF; Owner = PCI [00|03|00:10]Base = 0x81020000; Length = 0x1000; Alignment = 0xFFF; Owner = PCI [00|02|00:18]
