13STATIC UINT64 gHandleDatabaseKey = 0;
37 if (UserHandle ==
NULL) {
38 return EFI_INVALID_PARAMETER;
41 for (Link = gHandleList.BackLink; Link != &gHandleList; Link = Link->BackLink) {
43 if (Handle == (
IHANDLE *)UserHandle) {
48 return EFI_INVALID_PARAMETER;
75 for (Link = mProtocolDatabase.ForwardLink;
76 Link != &mProtocolDatabase;
77 Link = Link->ForwardLink)
94 if ((ProtEntry ==
NULL) && Create) {
97 if (ProtEntry !=
NULL) {
101 ProtEntry->Signature = PROTOCOL_ENTRY_SIGNATURE;
146 if (ProtEntry !=
NULL) {
150 for (Link = Handle->Protocols.ForwardLink; Link != &Handle->Protocols; Link = Link->ForwardLink) {
180 for (Link = ProtEntry->Notify.ForwardLink; Link != &ProtEntry->Notify; Link = Link->ForwardLink) {
208 Position->Position = Position->Position->ForwardLink;
215 if (Position->Position != &gHandleList) {
247 ProtNotify = Position->SearchKey;
252 if (ProtNotify !=
NULL) {
253 ASSERT (ProtNotify->Signature == PROTOCOL_NOTIFY_SIGNATURE);
254 Position->SearchKey =
NULL;
259 Link = ProtNotify->
Position->ForwardLink;
260 if (Link != &ProtNotify->Protocol->
Protocols) {
297 Link = Position->Position->ForwardLink;
298 Position->Position = Link;
303 if (Link == &Position->ProtEntry->Protocols) {
319 if (Handle->LocateRequest != mEfiLocateHandleRequest) {
320 Handle->LocateRequest = mEfiLocateHandleRequest;
360 for (Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList; Link = Link->ForwardLink) {
362 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
364 if (!EFI_ERROR (Status)) {
373 if (!EFI_ERROR (Status)) {
377 for (Link = Prot->OpenList.ForwardLink; Link != &Prot->OpenList;) {
379 if ((OpenData->Attributes &
380 (EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL | EFI_OPEN_PROTOCOL_GET_PROTOCOL | EFI_OPEN_PROTOCOL_TEST_PROTOCOL)) != 0)
383 Prot->OpenListCount--;
386 Link = Link->ForwardLink;
394 if (EFI_ERROR (Status) || (Prot->OpenListCount > 0)) {
396 Status = EFI_ACCESS_DENIED;
431 for (Link = ProtEntry->
Notify.ForwardLink; Link != &ProtEntry->
Notify; Link = Link->ForwardLink) {
474 if (EFI_ERROR (Status)) {
478 Handle = (
IHANDLE *)UserHandle;
483 for (Link = Handle->
Protocols.ForwardLink; Link != &Handle->
Protocols; Link = Link->ForwardLink) {
524 VOID *ExistingInterface;
530 if ((UserHandle ==
NULL) || (Protocol ==
NULL)) {
531 return EFI_INVALID_PARAMETER;
535 return EFI_INVALID_PARAMETER;
541 UT_LOG_INFO (
"InstallProtocolInterface: %g %p\n", Protocol, Interface);
543 Status = EFI_OUT_OF_RESOURCES;
547 if (*UserHandle !=
NULL) {
549 if (!EFI_ERROR (Status)) {
550 return EFI_INVALID_PARAMETER;
558 if (ProtEntry ==
NULL) {
567 Status = EFI_OUT_OF_RESOURCES;
574 Handle = (
IHANDLE *)*UserHandle;
575 if (Handle ==
NULL) {
577 if (Handle ==
NULL) {
578 Status = EFI_OUT_OF_RESOURCES;
585 Handle->Signature = EFI_HANDLE_SIGNATURE;
591 gHandleDatabaseKey++;
592 Handle->
Key = gHandleDatabaseKey;
601 if (EFI_ERROR (Status)) {
602 DEBUG ((DEBUG_ERROR,
"InstallProtocolInterface: input handle at 0x%x is invalid\n", Handle));
615 Prot->Signature = PROTOCOL_INTERFACE_SIGNATURE;
624 Prot->OpenListCount = 0;
648 if (!EFI_ERROR (Status)) {
652 *UserHandle = Handle;
661 DEBUG ((DEBUG_ERROR,
"InstallProtocolInterface: %g %p failed with %r\n", Protocol, Interface, Status));
718 IN VOID *OldInterface,
719 IN VOID *NewInterface
753 if (Protocol ==
NULL) {
754 return EFI_INVALID_PARAMETER;
761 if (EFI_ERROR (Status)) {
770 Status = EFI_NOT_FOUND;
781 if (EFI_ERROR (Status)) {
791 Status = EFI_NOT_FOUND;
792 Handle = (
IHANDLE *)UserHandle;
799 gHandleDatabaseKey++;
800 Handle->
Key = gHandleDatabaseKey;
819 Handle->Signature = 0;
853 EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL
875 OUT VOID **Registration
904 IN VOID *SearchKey OPTIONAL,
912 UNIT_TEST_GET_NEXT GetNext;
918 if (BufferSize ==
NULL) {
919 return EFI_INVALID_PARAMETER;
922 if ((*BufferSize > 0) && (Buffer ==
NULL)) {
923 return EFI_INVALID_PARAMETER;
931 Position.Protocol = Protocol;
932 Position.SearchKey = SearchKey;
933 Position.Position = &gHandleList;
936 ResultBuffer = (
IHANDLE **)Buffer;
942 switch (SearchType) {
951 if (SearchKey ==
NULL) {
952 Status = EFI_INVALID_PARAMETER;
961 if (Protocol ==
NULL) {
962 Status = EFI_INVALID_PARAMETER;
970 if (Position.ProtEntry ==
NULL) {
971 Status = EFI_NOT_FOUND;
975 Position.Position = &Position.ProtEntry->
Protocols;
979 Status = EFI_INVALID_PARAMETER;
983 if (EFI_ERROR (Status)) {
987 ASSERT (GetNext !=
NULL);
991 mEfiLocateHandleRequest += 1;
996 Handle = GetNext (&Position, &Interface);
997 if (
NULL == Handle) {
1005 ResultSize +=
sizeof (Handle);
1006 if (ResultSize <= *BufferSize) {
1007 *ResultBuffer = Handle;
1016 if (ResultSize == 0) {
1017 Status = EFI_NOT_FOUND;
1023 if (ResultSize > *BufferSize) {
1024 Status = EFI_BUFFER_TOO_SMALL;
1027 *BufferSize = ResultSize;
1034 ASSERT (SearchKey !=
NULL);
1035 ProtNotify = SearchKey;
1119 OUT VOID **Interface OPTIONAL,
1122 IN UINT32 Attributes
1137 if (Protocol ==
NULL) {
1138 return EFI_INVALID_PARAMETER;
1144 if ((Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) && (Interface ==
NULL)) {
1145 return EFI_INVALID_PARAMETER;
1152 if (EFI_ERROR (Status)) {
1159 switch (Attributes) {
1160 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1162 if (EFI_ERROR (Status)) {
1167 if (EFI_ERROR (Status)) {
1171 if (UserHandle == ControllerHandle) {
1172 return EFI_INVALID_PARAMETER;
1176 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1177 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1179 if (EFI_ERROR (Status)) {
1184 if (EFI_ERROR (Status)) {
1189 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1191 if (EFI_ERROR (Status)) {
1196 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1197 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1198 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1201 return EFI_INVALID_PARAMETER;
1209 Status = EFI_UNSUPPORTED;
1217 for ( Link = Prot->
OpenList.ForwardLink; Link != &Prot->
OpenList; Link = Link->ForwardLink) {
1219 ExactMatch = (BOOLEAN)((OpenData->AgentHandle == ImageHandle) &&
1220 (OpenData->Attributes == Attributes) &&
1221 (OpenData->ControllerHandle == ControllerHandle));
1222 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
1225 Status = EFI_ALREADY_STARTED;
1230 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_EXCLUSIVE) != 0) {
1232 }
else if (ExactMatch) {
1233 OpenData->OpenCount++;
1246 switch (Attributes) {
1247 case EFI_OPEN_PROTOCOL_BY_DRIVER:
1248 if (Exclusive || ByDriver) {
1249 Status = EFI_ACCESS_DENIED;
1254 case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE:
1255 case EFI_OPEN_PROTOCOL_EXCLUSIVE:
1257 Status = EFI_ACCESS_DENIED;
1264 for (Link = Prot->
OpenList.ForwardLink; Link != &Prot->
OpenList; Link = Link->ForwardLink) {
1266 if ((OpenData->Attributes & EFI_OPEN_PROTOCOL_BY_DRIVER) != 0) {
1269 if (EFI_ERROR (Status)) {
1270 Status = EFI_ACCESS_DENIED;
1277 }
while (Disconnect);
1281 case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER:
1282 case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL:
1283 case EFI_OPEN_PROTOCOL_GET_PROTOCOL:
1284 case EFI_OPEN_PROTOCOL_TEST_PROTOCOL:
1288 if (ImageHandle ==
NULL) {
1297 if (OpenData ==
NULL) {
1298 Status = EFI_OUT_OF_RESOURCES;
1300 OpenData->Signature = OPEN_PROTOCOL_DATA_SIGNATURE;
1301 OpenData->AgentHandle = ImageHandle;
1302 OpenData->ControllerHandle = ControllerHandle;
1303 OpenData->Attributes = Attributes;
1304 OpenData->OpenCount = 1;
1306 Prot->OpenListCount++;
1312 if (Attributes != EFI_OPEN_PROTOCOL_TEST_PROTOCOL) {
1317 if (!EFI_ERROR (Status) || (Status == EFI_ALREADY_STARTED)) {
1326 ASSERT (Prot !=
NULL);
1332 }
else if (Status == EFI_UNSUPPORTED) {
1464 IN VOID *SearchKey OPTIONAL,
1472 if (NumberHandles ==
NULL) {
1473 return EFI_INVALID_PARAMETER;
1476 if (Buffer ==
NULL) {
1477 return EFI_INVALID_PARAMETER;
1496 if (EFI_ERROR (Status) && (Status != EFI_BUFFER_TOO_SMALL)) {
1497 if (Status != EFI_INVALID_PARAMETER) {
1498 Status = EFI_NOT_FOUND;
1505 if (*Buffer ==
NULL) {
1506 return EFI_OUT_OF_RESOURCES;
1517 *NumberHandles = BufferSize /
sizeof (
EFI_HANDLE);
1518 if (EFI_ERROR (Status)) {
1545 IN VOID *Registration OPTIONAL,
1546 OUT VOID **Interface
1611 for (Index = 0, Status =
EFI_SUCCESS; !EFI_ERROR (Status); Index++) {
1616 if (Protocol ==
NULL) {
1620 Interface =
VA_ARG (Args, VOID *);
1634 if (EFI_ERROR (Status)) {
1639 for ( ; Index > 1; Index--) {
1641 Interface =
VA_ARG (Args, VOID *);
1646 Status = EFI_INVALID_PARAMETER;
BOOLEAN EFIAPI IsListEmpty(IN CONST LIST_ENTRY *ListHead)
LIST_ENTRY *EFIAPI InsertHeadList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI RemoveEntryList(IN CONST LIST_ENTRY *Entry)
LIST_ENTRY *EFIAPI InitializeListHead(IN OUT LIST_ENTRY *ListHead)
#define INITIALIZE_LIST_HEAD_VARIABLE(ListHead)
LIST_ENTRY *EFIAPI InsertTailList(IN OUT LIST_ENTRY *ListHead, IN OUT LIST_ENTRY *Entry)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define VA_ARG(Marker, TYPE)
#define VA_START(Marker, Parameter)
#define DEBUG(Expression)
#define CR(Record, TYPE, Field, TestSignature)
#define EFI_NOT_AVAILABLE_YET
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
#define UT_LOG_INFO(Format,...)
EFI_STATUS EFIAPI UnitTestSignalEvent(IN EFI_EVENT UserEvent)
EFI_STATUS EFIAPI UnitTestDisconnectController(IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE DriverImageHandle OPTIONAL, IN EFI_HANDLE ChildHandle OPTIONAL)
EFI_STATUS EFIAPI UnitTestFreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI UnitTestConnectController(IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE *DriverImageHandle OPTIONAL, IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL, IN BOOLEAN Recursive)
EFI_STATUS EFIAPI UnitTestOpenProtocol(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, OUT VOID **Interface OPTIONAL, IN EFI_HANDLE ImageHandle, IN EFI_HANDLE ControllerHandle, IN UINT32 Attributes)
EFI_STATUS EFIAPI UnitTestCloseProtocol(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, IN EFI_HANDLE AgentHandle, IN EFI_HANDLE ControllerHandle)
EFI_STATUS EFIAPI UnitTestRegisterProtocolNotify(IN EFI_GUID *Protocol, IN EFI_EVENT Event, OUT VOID **Registration)
PROTOCOL_INTERFACE * UnitTestFindProtocolInterface(IN IHANDLE *Handle, IN EFI_GUID *Protocol, IN VOID *Interface)
EFI_STATUS EFIAPI UnitTestLocateDevicePath(IN EFI_GUID *Protocol, IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath, OUT EFI_HANDLE *Device)
IHANDLE * UnitTestGetNextLocateByProtocol(IN OUT LOCATE_POSITION *Position, OUT VOID **Interface)
VOID UnitTestNotifyProtocolEntry(IN PROTOCOL_ENTRY *ProtEntry)
EFI_STATUS EFIAPI UnitTestInstallProtocolInterface(IN OUT EFI_HANDLE *UserHandle, IN EFI_GUID *Protocol, IN EFI_INTERFACE_TYPE InterfaceType, IN VOID *Interface)
EFI_STATUS EFIAPI UnitTestLocateHandleBuffer(IN EFI_LOCATE_SEARCH_TYPE SearchType, IN EFI_GUID *Protocol OPTIONAL, IN VOID *SearchKey OPTIONAL, IN OUT UINTN *NumberHandles, OUT EFI_HANDLE **Buffer)
EFI_STATUS UnitTestValidateHandle(IN EFI_HANDLE UserHandle)
EFI_STATUS EFIAPI UnitTestUninstallMultipleProtocolInterfaces(IN EFI_HANDLE Handle,...)
EFI_STATUS EFIAPI UnitTestReinstallProtocolInterface(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, IN VOID *OldInterface, IN VOID *NewInterface)
EFI_STATUS EFIAPI UnitTestUninstallProtocolInterface(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, IN VOID *Interface)
EFI_STATUS EFIAPI UnitTestProtocolsPerHandle(IN EFI_HANDLE UserHandle, OUT EFI_GUID ***ProtocolBuffer, OUT UINTN *ProtocolBufferCount)
PROTOCOL_ENTRY * UnitTestFindProtocolEntry(IN EFI_GUID *Protocol, IN BOOLEAN Create)
IHANDLE * UnitTestGetNextLocateAllHandles(IN OUT LOCATE_POSITION *Position, OUT VOID **Interface)
EFI_STATUS EFIAPI UnitTestOpenProtocolInformation(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, OUT EFI_OPEN_PROTOCOL_INFORMATION_ENTRY **EntryBuffer, OUT UINTN *EntryCount)
EFI_STATUS EFIAPI UnitTestHandleProtocol(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol, OUT VOID **Interface)
PROTOCOL_INTERFACE * UnitTestRemoveInterfaceFromProtocol(IN IHANDLE *Handle, IN EFI_GUID *Protocol, IN VOID *Interface)
EFI_STATUS EFIAPI UnitTestLocateHandle(IN EFI_LOCATE_SEARCH_TYPE SearchType, IN EFI_GUID *Protocol OPTIONAL, IN VOID *SearchKey OPTIONAL, IN OUT UINTN *BufferSize, OUT EFI_HANDLE *Buffer)
PROTOCOL_INTERFACE * UnitTestGetProtocolInterface(IN EFI_HANDLE UserHandle, IN EFI_GUID *Protocol)
EFI_STATUS EFIAPI UnitTestInstallConfigurationTable(IN EFI_GUID *Guid, IN VOID *Table)
EFI_STATUS EFIAPI UnitTestInstallMultipleProtocolInterfaces(IN OUT EFI_HANDLE *Handle,...)
EFI_STATUS UnitTestDisconnectControllersUsingProtocolInterface(IN EFI_HANDLE UserHandle, IN PROTOCOL_INTERFACE *Prot)
IHANDLE * UnitTestGetNextLocateByRegisterNotify(IN OUT LOCATE_POSITION *Position, OUT VOID **Interface)
EFI_STATUS EFIAPI UnitTestLocateProtocol(IN EFI_GUID *Protocol, IN VOID *Registration OPTIONAL, OUT VOID **Interface)
EFI_STATUS UnitTestInstallProtocolInterfaceNotify(IN OUT EFI_HANDLE *UserHandle, IN EFI_GUID *Protocol, IN EFI_INTERFACE_TYPE InterfaceType, IN VOID *Interface, IN BOOLEAN Notify)
LIST_ENTRY AllHandles
All handles list of IHANDLE.
UINT64 Key
The Handle Database Key value when this handle was last created or modified.
LIST_ENTRY Protocols
List of PROTOCOL_INTERFACE's for this handle.
LIST_ENTRY Link
Link on PROTOCOL_INTERFACE.OpenList.
LIST_ENTRY Notify
Registerd notification handlers.
LIST_ENTRY AllEntries
Link Entry inserted to mProtocolDatabase.
EFI_GUID ProtocolID
ID of the protocol.
LIST_ENTRY Protocols
All protocol interfaces.
LIST_ENTRY Link
Link on IHANDLE.Protocols.
IHANDLE * Handle
Back pointer.
LIST_ENTRY OpenList
OPEN_PROTOCOL_DATA list.
PROTOCOL_ENTRY * Protocol
The protocol ID.
VOID * Interface
The interface value.
LIST_ENTRY ByProtocol
Link on PROTOCOL_ENTRY.Protocols.
EFI_EVENT Event
Event to notify.
LIST_ENTRY * Position
Last position notified.