memorystatuscode.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 511 行 · 第 1/2 页
C
511 行
/*++
Copyright (c) 2004 - 2006, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
MemoryStatusCode.c
Abstract:
Lib to provide memory journal status code reporting Routines.
--*/
#include "MemoryStatusCode.h"
#include "PeiLib.h"
#include "MonoStatusCode.h"
//
// Global variable. Not accessible while running from flash.
// After we relocate ourselves into memory, we update this
// and use it to determine if we are running from flash or memory.
//
BOOLEAN mRunningFromMemory = FALSE;
//
// Global variable used to replace the PPI once we start running from memory.
//
PEI_STATUS_CODE_MEMORY_PPI mStatusCodeMemoryPpi = { 0, 0, 0, 0 };
//
// PPI descriptor for the MonoStatusCode PEIM, see MonoStatusCode.c
//
extern EFI_PEI_PPI_DESCRIPTOR mPpiListStatusCode;
VOID
EFIAPI
MemoryInitializeStatusCode (
IN EFI_FFS_FILE_HEADER *FfsHeader,
IN EFI_PEI_SERVICES **PeiServices
)
/*++
Routine Description:
Initialization routine.
Allocates heap space for storing Status Codes.
Installs a PPI to point to that heap space.
Installs a callback to switch to memory.
Installs a callback to
Arguments:
FfsHeader - FV this PEIM was loaded from.
PeiServices - General purpose services available to every PEIM.
Returns:
None
--*/
{
EFI_STATUS Status;
MEMORY_STATUS_CODE_INSTANCE *PrivateData;
PEI_STATUS_CODE_MEMORY_PPI *StatusCodeMemoryPpi;
PEI_STATUS_CODE_PPI *ReportStatusCodePpi;
EFI_PHYSICAL_ADDRESS Buffer;
VOID *StartPointer;
UINTN Length;
UINTN LastEntry;
EFI_PEI_PPI_DESCRIPTOR *ReportStatusCodeDescriptor;
EFI_PEI_PPI_DESCRIPTOR *StatusCodeMemoryDescriptor;
//
// Determine if we are being called after relocation into memory.
//
if (!mRunningFromMemory) {
//
// If we are not running from memory, we need to allocate some heap and
// install the PPI
//
//
// Allocate heap storage for the journal
//
Status = (*PeiServices)->AllocatePool (
PeiServices,
PEI_STATUS_CODE_HEAP_LENGTH,
&StartPointer
);
//
// This is not a required feature to boot.
//
if (EFI_ERROR (Status)) {
return ;
}
//
// Allocate heap storage for private data
// The private data contains the FFS header for this PEIM,
// a PPI containing information about the status code journal, and
// a notification for the LoadFile service, to relocate the PEIM into
// memory.
//
Status = (*PeiServices)->AllocatePool (
PeiServices,
sizeof (MEMORY_STATUS_CODE_INSTANCE),
&PrivateData
);
//
// This is not a required feature to boot.
//
if (EFI_ERROR (Status)) {
return ;
}
//
// Update the contents of the private data.
//
PrivateData->Signature = MEMORY_STATUS_CODE_SIGNATURE;
PrivateData->This = PrivateData;
PrivateData->FfsHeader = FfsHeader;
PrivateData->PpiDescriptor.Flags = (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST);
PrivateData->PpiDescriptor.Guid = &gPeiStatusCodeMemoryPpiGuid;
PrivateData->PpiDescriptor.Ppi = &PrivateData->StatusCodeMemoryPpi;
PrivateData->StatusCodeMemoryPpi.FirstEntry = 0;
PrivateData->StatusCodeMemoryPpi.LastEntry = 0;
PrivateData->StatusCodeMemoryPpi.Address = (EFI_PHYSICAL_ADDRESS) (UINTN) StartPointer;
PrivateData->StatusCodeMemoryPpi.Length = PEI_STATUS_CODE_HEAP_LENGTH;
PrivateData->NotifyDescriptor.Flags =
(
EFI_PEI_PPI_DESCRIPTOR_NOTIFY_CALLBACK |
EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST
);
PrivateData->NotifyDescriptor.Guid = &gPeiFvFileLoaderPpiGuid;
PrivateData->NotifyDescriptor.Notify = LoadImageCallback;
//
// Publish the PPI
//
Status = (*PeiServices)->InstallPpi (PeiServices, &PrivateData->PpiDescriptor);
if (EFI_ERROR (Status)) {
return ;
}
//
// Post a callback to relocate to memory
//
Status = (**PeiServices).NotifyPpi (PeiServices, &PrivateData->NotifyDescriptor);
if (EFI_ERROR (Status)) {
return ;
}
} else {
//
// If we are running from memory, we need to copy from the heap to a RT
// memory buffer.
//
//
// Locate Journal
//
Status = (*PeiServices)->LocatePpi (
PeiServices,
&gPeiStatusCodeMemoryPpiGuid,
0,
&StatusCodeMemoryDescriptor,
&StatusCodeMemoryPpi
);
if (EFI_ERROR (Status)) {
return ;
}
//
// Get private data
//
PrivateData = MEMORY_STATUS_CODE_FROM_DESCRIPTOR_THIS (StatusCodeMemoryDescriptor);
//
// At this point, we need to fix up any addresses that we have as the heap
// has moved.
//
PrivateData->PpiDescriptor.Ppi = &PrivateData->StatusCodeMemoryPpi;
PrivateData->PpiDescriptor.Guid = &gPeiStatusCodeMemoryPpiGuid;
PrivateData->StatusCodeMemoryPpi.Address = PrivateData->StatusCodeMemoryPpi.Address +
(UINTN) PrivateData - (UINTN) PrivateData->This;
PrivateData->NotifyDescriptor.Guid = &gPeiFvFileLoaderPpiGuid;
PrivateData->NotifyDescriptor.Notify = LoadImageCallback;
PrivateData->This = PrivateData;
//
// Allocate RT memory.
//
Status = (*PeiServices)->AllocatePages (
PeiServices,
EfiRuntimeServicesData,
PEI_STATUS_CODE_RT_PAGES,
&Buffer
);
if (EFI_ERROR (Status)) {
return ;
}
DEBUG_CODE (
EfiCommonLibZeroMem ((VOID *) (UINTN) Buffer, PEI_STATUS_CODE_RT_LENGTH);
)
//
// Copy the heap to the allocated memory.
// Unwind the rolling queue to start at 0 in the new space. We need to do
// this because the new queue is much bigger than the heap allocation.
//
if (PEI_STATUS_CODE_RT_LENGTH <= PEI_STATUS_CODE_HEAP_LENGTH) {
return ;
}
if (StatusCodeMemoryPpi->LastEntry >= StatusCodeMemoryPpi->FirstEntry) {
LastEntry = StatusCodeMemoryPpi->LastEntry - StatusCodeMemoryPpi->FirstEntry;
StartPointer = (VOID *) ((UINTN) StatusCodeMemoryPpi->Address + (StatusCodeMemoryPpi->FirstEntry * sizeof (EFI_STATUS_CODE_ENTRY)));
Length = (StatusCodeMemoryPpi->LastEntry - StatusCodeMemoryPpi->FirstEntry) * sizeof (EFI_STATUS_CODE_ENTRY);
(*PeiServices)->CopyMem ((VOID *) (UINTN) Buffer, StartPointer, Length);
} else {
//
// The last entry will be the new last entry after moving heap to buffer
//
LastEntry = (PEI_STATUS_CODE_MAX_HEAP_ENTRY - StatusCodeMemoryPpi->FirstEntry) + StatusCodeMemoryPpi->LastEntry;
//
// Copy from the first entry to the end of the heap
//
StartPointer = (VOID *) ((UINTN) StatusCodeMemoryPpi->Address + (StatusCodeMemoryPpi->FirstEntry * sizeof (EFI_STATUS_CODE_ENTRY)));
Length = PEI_STATUS_CODE_HEAP_LENGTH - (StatusCodeMemoryPpi->FirstEntry * sizeof (EFI_STATUS_CODE_ENTRY));
(*PeiServices)->CopyMem ((VOID *) (UINTN) Buffer, StartPointer, Length);
//
// Copy from the start to the heap to the last entry
//
StartPointer = (VOID *) (UINTN) StatusCodeMemoryPpi->Address;
(*PeiServices)->CopyMem (
(VOID *) (UINTN) (Buffer + Length),
StartPointer,
(StatusCodeMemoryPpi->LastEntry * sizeof (EFI_STATUS_CODE_ENTRY))
);
};
//
// Update the PPI to NULL, so it will not be used.
//
StatusCodeMemoryPpi->FirstEntry = 0;
StatusCodeMemoryPpi->LastEntry = 0;
StatusCodeMemoryPpi->Address = 0;
StatusCodeMemoryPpi->Length = 0;
//
// Update in memory version of PPI that will be used.
//
mStatusCodeMemoryPpi.FirstEntry = 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?