EFI_STATUS EFIAPI iTpmMemoryDiscoveredPpiCallback ( IN EFI_PEI_SERVICES **PeiServices, IN EFI_PEI_NOTIFY_DESCRIPTOR *NotifyDesc, IN VOID *InvokePpi ) { EFI_STATUS Status; EFI_PHYSICAL_ADDRESS iTpmCommandBuffer; EFI_PHYSICAL_ADDRESS iTpmResponseBuffer; PSP_DEBUG ("Psp.iTpmPei.MemoryDiscoveredPpiCallback\n"); //Send PSP mailbox command to ensure Ctrl Area have been initialed Status = CheckITPMSupported (); if (Status == EFI_SUCCESS) { Status = (*PeiServices)->AllocatePages ( PeiServices, EfiBootServicesData, EFI_SIZE_TO_PAGES (iTPM_COMMAND_BUFFER_SIZE + \ iTPM_RESPONSE_BUFFER_SIZE), &iTpmCommandBuffer ); if (EFI_ERROR (Status)) { PSP_DEBUG ("Allocate Memory fail\n"); return Status; } iTpmResponseBuffer = iTpmCommandBuffer + iTPM_COMMAND_BUFFER_SIZE; EfiCommonLibSetMem ((VOID *) (UINTN) iTpmCommandBuffer, iTPM_COMMAND_BUFFER_SIZE + iTPM_RESPONSE_BUFFER_SIZE, 0); Status = iTpmAssignMemory ( (UINTN)iTpmCommandBuffer, iTPM_COMMAND_BUFFER_SIZE, (UINTN)iTpmResponseBuffer, iTPM_RESPONSE_BUFFER_SIZE ); PSP_DEBUG ("\tAllocate CmdBuf:0x%x ResBuf:0x%x\n", iTpmCommandBuffer, iTpmResponseBuffer); } return Status; }
EFI_BOOTSERVICE EFI_STATUS EFIAPI CoreCreateEventEx ( IN UINT32 Type, IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction, IN VOID *NotifyContext, IN CONST EFI_GUID *EventGroup, OPTIONAL OUT EFI_EVENT *Event ) /*++ Routine Description: Creates a general-purpose event structure Arguments: Type - The type of event to create and its mode and attributes NotifyTpl - The task priority level of event notifications NotifyFunction - Pointer to the events notification function NotifyContext - Pointer to the notification functions context; corresponds to parameter "Context" in the notification function EventGroup - GUID for EventGroup if NULL act the same as gBS->CreateEvent(). Event - Pointer to the newly created event if the call succeeds; undefined otherwise Returns: EFI_SUCCESS - The event structure was created EFI_INVALID_PARAMETER - One of the parameters has an invalid value EFI_OUT_OF_RESOURCES - The event could not be allocated --*/ { EFI_STATUS Status; IEVENT *IEvent; INTN Index; if ((Event == NULL) || (NotifyTpl == EFI_TPL_APPLICATION)) { return EFI_INVALID_PARAMETER; } // // For event group, type EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES and EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE // are not valid // if (EventGroup != NULL) { if ((Type == EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES) || (Type == EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE)) { return EFI_INVALID_PARAMETER; } } // // Check to make sure no reserved flags are set // Status = EFI_INVALID_PARAMETER; for (Index = 0; Index < (sizeof (mEventTable) / sizeof (UINT32)); Index++) { if (Type == mEventTable[Index]) { Status = EFI_SUCCESS; break; } } if(EFI_ERROR (Status)) { return EFI_INVALID_PARAMETER; } // // Convert Event type for pre-defined Event groups // if (EventGroup != NULL) { if (EfiCompareGuid ((VOID *) EventGroup, &gEfiEventExitBootServicesGuid)) { Type = EFI_EVENT_SIGNAL_EXIT_BOOT_SERVICES; } else if (EfiCompareGuid ((VOID *) EventGroup, &gEfiEventVirtualAddressChangeGuid)) { Type = EFI_EVENT_SIGNAL_VIRTUAL_ADDRESS_CHANGE; } } // // If it's a notify type of event, check its parameters // if ((Type & (EFI_EVENT_NOTIFY_WAIT | EFI_EVENT_NOTIFY_SIGNAL))) { // // Check for an invalid NotifyFunction or NotifyTpl // if ((NotifyFunction == NULL) || (NotifyTpl < EFI_TPL_APPLICATION) || (NotifyTpl >= EFI_TPL_HIGH_LEVEL)) { return EFI_INVALID_PARAMETER; } } else { // // No notification needed, zero ignored values // NotifyTpl = 0; NotifyFunction = NULL; NotifyContext = NULL; } // // Allcoate and initialize a new event structure. // Status = CoreAllocatePool ( (Type & EFI_EVENT_RUNTIME) ? EfiRuntimeServicesData: EfiBootServicesData, sizeof (IEVENT), (VOID **)&IEvent ); if (EFI_ERROR (Status)) { return EFI_OUT_OF_RESOURCES; } EfiCommonLibSetMem (IEvent, sizeof (IEVENT), 0); IEvent->Signature = EVENT_SIGNATURE; IEvent->Type = Type; IEvent->NotifyTpl = NotifyTpl; IEvent->NotifyFunction = NotifyFunction; IEvent->NotifyContext = (VOID *)NotifyContext; if (EventGroup != NULL) { EfiCommonLibCopyMem (&IEvent->EventGroup, (VOID*)EventGroup, sizeof (EFI_GUID)); IEvent->ExFlag = TRUE; } *Event = IEvent; if (Type & EFI_EVENT_RUNTIME) { // // Keep a list of all RT events so we can tell the RT AP. // IEvent->RuntimeData.Type = Type; IEvent->RuntimeData.NotifyTpl = NotifyTpl; IEvent->RuntimeData.NotifyFunction = NotifyFunction; IEvent->RuntimeData.NotifyContext = NotifyContext; IEvent->RuntimeData.Event = (EFI_EVENT *) IEvent; InsertTailList (&gRuntime->EventHead, &IEvent->RuntimeData.Link); } CoreAcquireEventLock (); if ((Type & EFI_EVENT_NOTIFY_SIGNAL) != 0x00000000) { // // The Event's NotifyFunction must be queued whenever the event is signaled // InsertHeadList (&gEventSignalQueue, &IEvent->SignalLink); } CoreReleaseEventLock (); // // Done // return EFI_SUCCESS; }