Protocol是什么
Protocol就是对每一类设备 抽象后得总称。 IHANDLE就是一个个设备句柄。
Protocol得描述
UEFI在扫描总线后,会 为每一个设备建立一个Controller对象,用于描述和控制这个设备
这个  对象句柄就是  EFI_HANDLE(UEFI中,这个句柄事IHANDLE)
EFI_HANDLE 对象句柄描述
typedef struct {UINTN Signature; // handle得类别LIST_ENTRY AllHandles; // 所有设备得IHANDLE 链表, 也就是 所有设备链,遍历设备用。LIST_ENTRY Protocols; // Handle得Protocol链表,查找自己得protocol使用UINTN LocateRequest;UINT64 Key;} IHANDLE;
Prorocol接口描述
////// PROTOCOL_INTERFACE - each protocol installed on a handle is tracked/// with a protocol interface structure///typedef struct {UINTN Signature;/// Link on IHANDLE.ProtocolsLIST_ENTRY Link;/// Back pointerIHANDLE *Handle;/// Link on PROTOCOL_ENTRY.ProtocolsLIST_ENTRY ByProtocol;/// The protocol IDPROTOCOL_ENTRY *Protocol; // 可获取PROTOCOL得GUID/// The interface valueVOID *Interface; // 可获取protocol实例/// OPEN_PROTOCOL_DATA listLIST_ENTRY OpenList;UINTN OpenListCount;} PROTOCOL_INTERFACE;
EFI_HANDLE和Protocol得关系图

protocol得使用
gBS中protocol得方法
EFI_BOOT_SERVICES *gBS;typedef struct { // 协议相关//// !!! Open and Close Protocol Services 最常用得就是 打开,使用,关闭 protocol//EFI_OPEN_PROTOCOL OpenProtocol;EFI_CLOSE_PROTOCOL CloseProtocol;EFI_HANDLE_PROTOCOL HandleProtocol;// Protocol Handler ServicesEFI_INSTALL_PROTOCOL_INTERFACE InstallProtocolInterface;EFI_REINSTALL_PROTOCOL_INTERFACE ReinstallProtocolInterface;EFI_UNINSTALL_PROTOCOL_INTERFACE UninstallProtocolInterface;EFI_HANDLE_PROTOCOL HandleProtocol;VOID *Reserved;EFI_REGISTER_PROTOCOL_NOTIFY RegisterProtocolNotify;EFI_LOCATE_HANDLE LocateHandle;EFI_LOCATE_DEVICE_PATH LocateDevicePath;EFI_INSTALL_CONFIGURATION_TABLE InstallConfigurationTable;// Library ServicesEFI_PROTOCOLS_PER_HANDLE ProtocolsPerHandle;EFI_LOCATE_HANDLE_BUFFER LocateHandleBuffer;EFI_LOCATE_PROTOCOL LocateProtocol;EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces;EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces;}
EFI_STATUS
@retval EFI_SUCCESS An item was added to the open list for the protocol interface, and theprotocol interface was returned in Interface. 成功打开@retval EFI_UNSUPPORTED Handle does not support Protocol. handle不支持Protocol@retval EFI_INVALID_PARAMETER One or more parameters are invalid. 无效参数@retval EFI_ACCESS_DENIED Required attributes can't be supported in current environment. 当前环境不支持attribute属性打开@retval EFI_ALREADY_STARTED Item on the open list already has requierd attributes whose agent Protocol已经被同一个AgentHandle打开handle is the same as AgentHandle.
OPEN 和 CLOSE
/**Queries a handle to determine if it supports a specified protocol. If the protocol is supported by thehandle, it opens the protocol on behalf of the calling agent.@param[in] Handle The handle for the protocol interface that is being opened.@param[in] Protocol The published unique identifier of the protocol.@param[out] Interface Supplies the address where a pointer to the corresponding ProtocolInterface is returned.@param[in] AgentHandle The handle of the agent that is opening the protocol interfacespecified by Protocol and Interface.@param[in] ControllerHandle If the agent that is opening a protocol is a driver that follows theUEFI Driver Model, then this parameter is the controller handlethat requires the protocol interface. If the agent does not followthe UEFI Driver Model, then this parameter is optional and maybe NULL.@param[in] Attributes The open mode of the protocol interface specified by Handleand Protocol.@retval EFI_SUCCESS An item was added to the open list for the protocol interface, and theprotocol interface was returned in Interface.@retval EFI_UNSUPPORTED Handle does not support Protocol.@retval EFI_INVALID_PARAMETER One or more parameters are invalid.@retval EFI_ACCESS_DENIED Required attributes can't be supported in current environment.@retval EFI_ALREADY_STARTED Item on the open list already has requierd attributes whose agenthandle is the same as AgentHandle.**/typedefEFI_STATUS(EFIAPI *EFI_OPEN_PROTOCOL)(IN EFI_HANDLE Handle, // 指定得handle,IN EFI_GUID *Protocol, // 要打开GUID对应得protocolOUT VOID **Interface, OPTIONAL // 返回打开得protocol对象IN EFI_HANDLE AgentHandle, // 打开protocol得ImageIN EFI_HANDLE ControllerHandle, // 使用此protocol得控制器IN UINT32 Attributes // 打开protocol得方式);typedefEFI_STATUS(EFIAPI *EFI_CLOSE_PROTOCOL)(IN EFI_HANDLE Handle,IN EFI_GUID *Protocol,IN EFI_HANDLE AgentHandle,IN EFI_HANDLE ControllerHandle);typedefEFI_STATUS(EFIAPI *EFI_HANDLE_PROTOCOL)(IN EFI_HANDLE Handle,IN EFI_GUID *Protocol,OUT VOID **Interface);
Attributes打开属性
#define EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL 0x00000001#define EFI_OPEN_PROTOCOL_GET_PROTOCOL 0x00000002#define EFI_OPEN_PROTOCOL_TEST_PROTOCOL 0x00000004#define EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER 0x00000008#define EFI_OPEN_PROTOCOL_BY_DRIVER 0x00000010#define EFI_OPEN_PROTOCOL_EXCLUSIVE 0x00000020
