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 EFIAPI
CoreConnectController (
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE *DriverImageHandle OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
IN BOOLEAN Recursive
);
EFI_STATUS
CoreConnectSingleController (
IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE *ContextDriverImageHandles OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
);
EFI_STATUS
EFIAPI
CoreDisconnectController (
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
};
初始化代码
PciBusDriverBindingStart
PciEnumerator
PciHostBridgeEnumerator
打印信息
PCI Bus First Scanning
PciBus: 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 = 0x20
PciBus: Discovered PCI @ [00|01|03]
PciBus: Discovered PCI @ [00|02|00]
BAR[0]: Type = PMem32; Alignment = 0xFFFFFF; Length = 0x1000000; Offset = 0x10
BAR[2]: Type = Mem32; Alignment = 0xFFF; Length = 0x1000; Offset = 0x18
PciBus: Discovered PCI @ [00|03|00]
BAR[0]: Type = Mem32; Alignment = 0x1FFFF; Length = 0x20000; Offset = 0x10
BAR[1]: Type = Io32; Alignment = 0x3F; Length = 0x40; Offset = 0x14
PCI Bus Second Scanning
PciBus: 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 = 0x20
PciBus: Discovered PCI @ [00|01|03]
PciBus: Discovered PCI @ [00|02|00]
BAR[0]: Type = PMem32; Alignment = 0xFFFFFF; Length = 0x1000000; Offset = 0x10
BAR[2]: Type = Mem32; Alignment = 0xFFF; Length = 0x1000; Offset = 0x18
PciBus: Discovered PCI @ [00|03|00]
BAR[0]: Type = Mem32; Alignment = 0x1FFFF; Length = 0x20000; Offset = 0x10
BAR[1]: Type = Io32; Alignment = 0x3F; Length = 0x40; Offset = 0x14
PciBus: 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 = 0x20
PciBus: Discovered PCI @ [00|01|03]
PciBus: Discovered PCI @ [00|02|00]
BAR[0]: Type = PMem32; Alignment = 0xFFFFFF; Length = 0x1000000; Offset = 0x10
BAR[2]: Type = Mem32; Alignment = 0xFFF; Length = 0x1000; Offset = 0x18
PciBus: Discovered PCI @ [00|03|00]
BAR[0]: Type = Mem32; Alignment = 0x1FFFF; Length = 0x20000; Offset = 0x10
BAR[1]: Type = Io32; Alignment = 0x3F; Length = 0x40; Offset = 0x14
PciHostBridge: SubmitResources for PciRoot(0x0)
I/O: Granularity/SpecificFlag = 0 / 01
Length/Alignment = 0x1000 / 0xFFF
Mem: Granularity/SpecificFlag = 32 / 00
Length/Alignment = 0x1100000 / 0xFFFFFF
PciBus: HostBridge->SubmitResources() - Success
PciHostBridge: NotifyPhase (AllocateResources)
RootBridge: PciRoot(0x0)
Mem: Base/Length/Alignment = 80000000/1100000/FFFFFF - Success
I/O: Base/Length/Alignment = C000/1000/FFF - Success
PciBus: HostBridge->NotifyPhase(AllocateResources) - Success
PciBus: Resource Map for Root Bridge PciRoot(0x0)
Type = Io16; Base = 0xC000; Length = 0x1000; Alignment = 0xFFF
Base = 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 = 0xFFFFFF
Base = 0x80000000; Length = 0x1000000; Alignment = 0xFFFFFF; Owner = PCI [00|02|00:10]; Type = PMem32
Base = 0x81000000; Length = 0x20000; Alignment = 0x1FFFF; Owner = PCI [00|03|00:10]
Base = 0x81020000; Length = 0x1000; Alignment = 0xFFF; Owner = PCI [00|02|00:18]