/* Finds the protocol entry for the requested protocol. */
PROTOCOL_ENTRY* SmmFindProtocolEntry(IN EFI_GUID *Protocol, IN BOOLEAN Create)
/* Finds the protocol entry for the requested protocol. */
PROTOCOL_ENTRY* SmmFindProtocolEntry(IN EFI_GUID *Protocol, IN BOOLEAN Create)
{
  LIST_ENTRY      *Link;
  PROTOCOL_ENTRY  *Item;
  PROTOCOL_ENTRY  *ProtEntry;
  ProtEntry = NULL;
  for (Link = mProtocolDatabase.ForwardLink;
       Link != &mProtocolDatabase;
       Link = Link->ForwardLink)
  {
    Item = CR (Link, PROTOCOL_ENTRY, AllEntries, PROTOCOL_ENTRY_SIGNATURE);
    if (CompareGuid (&Item->ProtocolID, Protocol)) {
      ProtEntry = Item;
      break;
    }
  }
  if ((ProtEntry == NULL) && Create) {
    ProtEntry = AllocatePool (sizeof (PROTOCOL_ENTRY));
    if (ProtEntry != NULL) {
      ProtEntry->Signature = PROTOCOL_ENTRY_SIGNATURE;
      CopyGuid ((VOID *)&ProtEntry->ProtocolID, Protocol);
      InitializeListHead (&ProtEntry->Protocols);
      InitializeListHead (&ProtEntry->Notify);
      InsertTailList (&mProtocolDatabase, &ProtEntry->AllEntries);
    }
  }
  return ProtEntry;
}