Prontocol:两者通信间协议
简介;
由于C没有class的类型因而{
typedef struct 模拟 class
函数指针模拟this指针(自己手动添加)
}
内核中表示:
通过EFI_HANDLE来指向某个对象,而每个EFI_HANDLE在UEFI中都有一个Protocols链表,所有的EFI_HANDLE通过ALLHANDLES连接起来
只要得到PROTOCOL_INTERFACE就可以得到GUID
如何使用:
1、通过gBS->OpenProtocol找出Protocol对象
2、使用这个Protocols
3、通过gBS->CloseProtocol关闭打开的Protoco
OpenProtocol
typedef EFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL)
{
IN EFI_HANDLE Handle, //指定的HANDLE,查询并安装
IN EFI_GUID *Prontocol, //要打开的Protocol
OUT VOID **Interface, OPTIONAL //返回打开的对象
IN EFI_HANDLE AgentHandle, //打开Image
IN EFI_HANDLE ControllerHandle, //使用控制器
IN UINT32 Attribute //打开方式
};
Demo:
Status = gBS->OpenProtocol (
Controller,
&gEfiVgaMiniPortProtocolGuid,
NULL,
NULL,
NULL,
EFI_OPEN_PROTOCOL_TEST_PROTOCOL
);
HandleProtocol:简化的OpenProtocol
typedef EFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)
{
IN EFI_HANDLE Handle, //指定的HANDLE,查询并安装
IN EFI_GUID *Prontocol, //要打开的Protocol
OUT VOID **Interface, OPTIONAL //返回打开的对象
};
Demo:
Status = gBS->HandleProtocol (
Controller,
&gEfiVgaMiniPortProtocolGuid,
NULL,
);
LocateProtocol:USER定位Protocol的第一个实例
typedef EFI_STATUS(EFIAPI *EFI_LOCATE_PROTOCOL)
{
IN EFI_GUID *Protocol, //带查询的Protocol
IN VOID *Registration,OPTIONAL //可选参数,从RegisterProtocolNotify()获得key
OUT VOID **Interface //返回第一个匹配到的实例
}
gBS->LocateProtocol (&gEfiPcdProtocolGuid, NULL, (VOID **) &mPiPcd);
LocateHandleBuffer:支持某个Protocol的所以设备
typdef EFI_STATUS(EFIAPI* EFI_LOCATE_HANDLE_BUFFER)
{
IN EFI_LOCATE_SEARCH_TYPE SearchType, //查找方式 ALLHandles\ByRegisterNotify\ByProtocol
IN EFI_GID *Protocol OPTIONAL, //指定的Protocol
IN VOID *Searchkey , //PROTOCOL_NOTIFY的类型
IN OUT UINT *NoHandle, //返回数量
OUT EFI_HANDLE *Buffer //分配Handle数组并返回
}
Demo:
gBS->LocateHandleBuffer (
ByProtocol,
&gEfiSimpleFileSystemProtocolGuid,
NULL,
&NumberSimpleFileSystemHandles,
&SimpleFileSystemHandles
);
typdef EFI_STATUS(EFIAPI EFI_LOCATE)
{
IN EFI_LOCATE_SEARCH_TYPE SearchType, //查找方式
IN EFI_GID *Protocol OPTIONAL, //指定的Protocol
IN VOID *Searchkey , //PROTOCOL_NOTIFY的类型
IN OUT UINT *BufferSize, //返回数量
OUT EFI_HANDLE *Buffer //返回Handle
};
ProntocolPerHandle:获取指定设备支持的所以Protocol
typedef EFI_STATUS(EFIAPI *EFI_PROTOCOL_PER_HANDLE)
{
IN EFI_HANDLE Handle, //找出所有的Protocol
OUT EFI_GUID ***ProtocolBuffer, //返回GUID数组
OUT UINTN *ProntocolBufferCount //返回Protocol数目
};
OpenProtocolInformation:获得指定Protocol打开信息
typdef EFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL_INFORMATION)
{
IN EFI_HANDLE Handle, //设备句柄
IN EFI_GUID *Protocol, //带查询的Protocol
OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer, //打开信息通过此数组返回
OUT UINTN *EntryCount //EntryBuffer数组元素个数
};
typdef struct
{
EFI_HANDLE AgentHandle;
EFI_HANDLE ControllerHandle;
UINT32 Attribute;
UINT32 OpenCount;
}EFI_OPEN_PROTOCOL_INFORMATION_ENTRY ;
CloseProtocol:关闭打开的Protocol(这里只能关闭没有指定的AgentHandle)
typedef EFI_STATUS(EFIAPI *EFI_CLOSE_PROTOCOL)
{
IN EFI_HANDLE Handle,
IN EFI_GUID *Prontocol,
IN EFI_HANDLE AgentHandle,
IN EFI_HANDLE Controller
};
————————————————
版权声明:本文为CSDN博主「干饭人的心,」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_42651654/article/details/124835321