StandaloneMmPkg/Core: Implementation of Standalone MM Core Module.
Management Mode (MM) is a generic term used to describe a secure
execution environment provided by the CPU and related silicon that is
entered when the CPU detects a MMI. For x86 systems, this can be
implemented with System Management Mode (SMM). For ARM systems, this can
be implemented with TrustZone (TZ).
A MMI can be a CPU instruction or interrupt. Upon detection of a MMI, a
CPU will jump to the MM Entry Point and save some portion of its state
(the "save state") such that execution can be resumed.
The MMI can be generated synchronously by software or asynchronously by
a hardware event. Each MMI source can be detected, cleared and disabled.
Some systems provide for special memory (Management Mode RAM or MMRAM)
which is set aside for software running in MM. Usually the MMRAM is
hidden during normal CPU execution, but this is not required. Usually,
after MMRAM is hidden it cannot be exposed until the next system reset.
The MM Core Interface Specification describes three pieces of the PI
Management Mode architecture:
1. MM Dispatch
During DXE, the DXE Foundation works with the MM Foundation to
schedule MM drivers for execution in the discovered firmware volumes.
2. MM Initialization
MM related code opens MMRAM, creates the MMRAM memory map, and
launches the MM Foundation, which provides the necessary services to
launch MM-related drivers. Then, sometime before boot, MMRAM is
closed and locked. This piece may be completed during the
SEC, PEI or DXE phases.
3. MMI Management
When an MMI generated, the MM environment is created and then the MMI
sources are detected and MMI handlers called.
This patch implements the MM Core.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sughosh Ganu <sughosh.ganu@arm.com>
Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2018-07-13 17:05:27 +02:00
|
|
|
/**@file
|
|
|
|
|
|
|
|
Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>
|
|
|
|
Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.<BR>
|
|
|
|
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.
|
|
|
|
|
|
|
|
**/
|
|
|
|
|
|
|
|
#include "StandaloneMmCore.h"
|
|
|
|
#include <Library/FvLib.h>
|
2019-01-01 16:57:44 +01:00
|
|
|
#include <Library/ExtractGuidedSectionLib.h>
|
StandaloneMmPkg/Core: Implementation of Standalone MM Core Module.
Management Mode (MM) is a generic term used to describe a secure
execution environment provided by the CPU and related silicon that is
entered when the CPU detects a MMI. For x86 systems, this can be
implemented with System Management Mode (SMM). For ARM systems, this can
be implemented with TrustZone (TZ).
A MMI can be a CPU instruction or interrupt. Upon detection of a MMI, a
CPU will jump to the MM Entry Point and save some portion of its state
(the "save state") such that execution can be resumed.
The MMI can be generated synchronously by software or asynchronously by
a hardware event. Each MMI source can be detected, cleared and disabled.
Some systems provide for special memory (Management Mode RAM or MMRAM)
which is set aside for software running in MM. Usually the MMRAM is
hidden during normal CPU execution, but this is not required. Usually,
after MMRAM is hidden it cannot be exposed until the next system reset.
The MM Core Interface Specification describes three pieces of the PI
Management Mode architecture:
1. MM Dispatch
During DXE, the DXE Foundation works with the MM Foundation to
schedule MM drivers for execution in the discovered firmware volumes.
2. MM Initialization
MM related code opens MMRAM, creates the MMRAM memory map, and
launches the MM Foundation, which provides the necessary services to
launch MM-related drivers. Then, sometime before boot, MMRAM is
closed and locked. This piece may be completed during the
SEC, PEI or DXE phases.
3. MMI Management
When an MMI generated, the MM environment is created and then the MMI
sources are detected and MMI handlers called.
This patch implements the MM Core.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sughosh Ganu <sughosh.ganu@arm.com>
Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2018-07-13 17:05:27 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// List of file types supported by dispatcher
|
|
|
|
//
|
|
|
|
EFI_FV_FILETYPE mMmFileTypes[] = {
|
|
|
|
EFI_FV_FILETYPE_MM,
|
|
|
|
0xE, //EFI_FV_FILETYPE_MM_STANDALONE,
|
|
|
|
//
|
|
|
|
// Note: DXE core will process the FV image file, so skip it in MM core
|
|
|
|
// EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE
|
|
|
|
//
|
|
|
|
};
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
MmAddToDriverList (
|
|
|
|
IN EFI_HANDLE FvHandle,
|
|
|
|
IN VOID *Pe32Data,
|
|
|
|
IN UINTN Pe32DataSize,
|
|
|
|
IN VOID *Depex,
|
|
|
|
IN UINTN DepexSize,
|
|
|
|
IN EFI_GUID *DriverName
|
|
|
|
);
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
FvHasBeenProcessed (
|
|
|
|
IN EFI_HANDLE FvHandle
|
|
|
|
);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FvIsBeingProcesssed (
|
|
|
|
IN EFI_HANDLE FvHandle
|
|
|
|
);
|
|
|
|
|
|
|
|
EFI_STATUS
|
|
|
|
MmCoreFfsFindMmDriver (
|
|
|
|
IN EFI_FIRMWARE_VOLUME_HEADER *FwVolHeader
|
|
|
|
)
|
|
|
|
/*++
|
|
|
|
|
|
|
|
Routine Description:
|
|
|
|
Given the pointer to the Firmware Volume Header find the
|
|
|
|
MM driver and return it's PE32 image.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
FwVolHeader - Pointer to memory mapped FV
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
other - Failure
|
|
|
|
|
|
|
|
--*/
|
|
|
|
{
|
2019-01-01 16:57:44 +01:00
|
|
|
EFI_STATUS Status;
|
|
|
|
EFI_STATUS DepexStatus;
|
|
|
|
EFI_FFS_FILE_HEADER *FileHeader;
|
|
|
|
EFI_FV_FILETYPE FileType;
|
|
|
|
VOID *Pe32Data;
|
|
|
|
UINTN Pe32DataSize;
|
|
|
|
VOID *Depex;
|
|
|
|
UINTN DepexSize;
|
|
|
|
UINTN Index;
|
|
|
|
EFI_COMMON_SECTION_HEADER *Section;
|
|
|
|
VOID *SectionData;
|
|
|
|
UINTN SectionDataSize;
|
|
|
|
UINT32 DstBufferSize;
|
|
|
|
VOID *ScratchBuffer;
|
|
|
|
UINT32 ScratchBufferSize;
|
|
|
|
VOID *DstBuffer;
|
|
|
|
UINT16 SectionAttribute;
|
|
|
|
UINT32 AuthenticationStatus;
|
|
|
|
EFI_FIRMWARE_VOLUME_HEADER *InnerFvHeader;
|
StandaloneMmPkg/Core: Implementation of Standalone MM Core Module.
Management Mode (MM) is a generic term used to describe a secure
execution environment provided by the CPU and related silicon that is
entered when the CPU detects a MMI. For x86 systems, this can be
implemented with System Management Mode (SMM). For ARM systems, this can
be implemented with TrustZone (TZ).
A MMI can be a CPU instruction or interrupt. Upon detection of a MMI, a
CPU will jump to the MM Entry Point and save some portion of its state
(the "save state") such that execution can be resumed.
The MMI can be generated synchronously by software or asynchronously by
a hardware event. Each MMI source can be detected, cleared and disabled.
Some systems provide for special memory (Management Mode RAM or MMRAM)
which is set aside for software running in MM. Usually the MMRAM is
hidden during normal CPU execution, but this is not required. Usually,
after MMRAM is hidden it cannot be exposed until the next system reset.
The MM Core Interface Specification describes three pieces of the PI
Management Mode architecture:
1. MM Dispatch
During DXE, the DXE Foundation works with the MM Foundation to
schedule MM drivers for execution in the discovered firmware volumes.
2. MM Initialization
MM related code opens MMRAM, creates the MMRAM memory map, and
launches the MM Foundation, which provides the necessary services to
launch MM-related drivers. Then, sometime before boot, MMRAM is
closed and locked. This piece may be completed during the
SEC, PEI or DXE phases.
3. MMI Management
When an MMI generated, the MM environment is created and then the MMI
sources are detected and MMI handlers called.
This patch implements the MM Core.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sughosh Ganu <sughosh.ganu@arm.com>
Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2018-07-13 17:05:27 +02:00
|
|
|
|
|
|
|
DEBUG ((DEBUG_INFO, "MmCoreFfsFindMmDriver - 0x%x\n", FwVolHeader));
|
|
|
|
|
|
|
|
if (FvHasBeenProcessed (FwVolHeader)) {
|
|
|
|
return EFI_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
FvIsBeingProcesssed (FwVolHeader);
|
|
|
|
|
2019-01-01 16:57:44 +01:00
|
|
|
//
|
|
|
|
// First check for encapsulated compressed firmware volumes
|
|
|
|
//
|
|
|
|
FileHeader = NULL;
|
|
|
|
do {
|
|
|
|
Status = FfsFindNextFile (EFI_FV_FILETYPE_FIRMWARE_VOLUME_IMAGE,
|
|
|
|
FwVolHeader, &FileHeader);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Status = FfsFindSectionData (EFI_SECTION_GUID_DEFINED, FileHeader,
|
|
|
|
&SectionData, &SectionDataSize);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Section = (EFI_COMMON_SECTION_HEADER *)(FileHeader + 1);
|
|
|
|
Status = ExtractGuidedSectionGetInfo (Section, &DstBufferSize,
|
|
|
|
&ScratchBufferSize, &SectionAttribute);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate scratch buffer
|
|
|
|
//
|
|
|
|
ScratchBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (ScratchBufferSize));
|
|
|
|
if (ScratchBuffer == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Allocate destination buffer, extra one page for adjustment
|
|
|
|
//
|
|
|
|
DstBuffer = (VOID *)(UINTN)AllocatePages (EFI_SIZE_TO_PAGES (DstBufferSize));
|
|
|
|
if (DstBuffer == NULL) {
|
|
|
|
return EFI_OUT_OF_RESOURCES;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Call decompress function
|
|
|
|
//
|
|
|
|
Status = ExtractGuidedSectionDecode (Section, &DstBuffer, ScratchBuffer,
|
|
|
|
&AuthenticationStatus);
|
|
|
|
FreePages (ScratchBuffer, EFI_SIZE_TO_PAGES (ScratchBufferSize));
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FreeDstBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG ((DEBUG_INFO,
|
|
|
|
"Processing compressed firmware volume (AuthenticationStatus == %x)\n",
|
|
|
|
AuthenticationStatus));
|
|
|
|
|
|
|
|
Status = FindFfsSectionInSections (DstBuffer, DstBufferSize,
|
|
|
|
EFI_SECTION_FIRMWARE_VOLUME_IMAGE, &Section);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FreeDstBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
InnerFvHeader = (VOID *)(Section + 1);
|
|
|
|
Status = MmCoreFfsFindMmDriver (InnerFvHeader);
|
|
|
|
if (EFI_ERROR (Status)) {
|
|
|
|
goto FreeDstBuffer;
|
|
|
|
}
|
|
|
|
} while (TRUE);
|
|
|
|
|
StandaloneMmPkg/Core: Implementation of Standalone MM Core Module.
Management Mode (MM) is a generic term used to describe a secure
execution environment provided by the CPU and related silicon that is
entered when the CPU detects a MMI. For x86 systems, this can be
implemented with System Management Mode (SMM). For ARM systems, this can
be implemented with TrustZone (TZ).
A MMI can be a CPU instruction or interrupt. Upon detection of a MMI, a
CPU will jump to the MM Entry Point and save some portion of its state
(the "save state") such that execution can be resumed.
The MMI can be generated synchronously by software or asynchronously by
a hardware event. Each MMI source can be detected, cleared and disabled.
Some systems provide for special memory (Management Mode RAM or MMRAM)
which is set aside for software running in MM. Usually the MMRAM is
hidden during normal CPU execution, but this is not required. Usually,
after MMRAM is hidden it cannot be exposed until the next system reset.
The MM Core Interface Specification describes three pieces of the PI
Management Mode architecture:
1. MM Dispatch
During DXE, the DXE Foundation works with the MM Foundation to
schedule MM drivers for execution in the discovered firmware volumes.
2. MM Initialization
MM related code opens MMRAM, creates the MMRAM memory map, and
launches the MM Foundation, which provides the necessary services to
launch MM-related drivers. Then, sometime before boot, MMRAM is
closed and locked. This piece may be completed during the
SEC, PEI or DXE phases.
3. MMI Management
When an MMI generated, the MM environment is created and then the MMI
sources are detected and MMI handlers called.
This patch implements the MM Core.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sughosh Ganu <sughosh.ganu@arm.com>
Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2018-07-13 17:05:27 +02:00
|
|
|
for (Index = 0; Index < sizeof (mMmFileTypes) / sizeof (mMmFileTypes[0]); Index++) {
|
|
|
|
DEBUG ((DEBUG_INFO, "Check MmFileTypes - 0x%x\n", mMmFileTypes[Index]));
|
|
|
|
FileType = mMmFileTypes[Index];
|
|
|
|
FileHeader = NULL;
|
|
|
|
do {
|
|
|
|
Status = FfsFindNextFile (FileType, FwVolHeader, &FileHeader);
|
|
|
|
if (!EFI_ERROR (Status)) {
|
|
|
|
Status = FfsFindSectionData (EFI_SECTION_PE32, FileHeader, &Pe32Data, &Pe32DataSize);
|
|
|
|
DEBUG ((DEBUG_INFO, "Find PE data - 0x%x\n", Pe32Data));
|
|
|
|
DepexStatus = FfsFindSectionData (EFI_SECTION_MM_DEPEX, FileHeader, &Depex, &DepexSize);
|
|
|
|
if (!EFI_ERROR (DepexStatus)) {
|
|
|
|
MmAddToDriverList (FwVolHeader, Pe32Data, Pe32DataSize, Depex, DepexSize, &FileHeader->Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!EFI_ERROR (Status));
|
|
|
|
}
|
|
|
|
|
2019-01-01 16:57:44 +01:00
|
|
|
return EFI_SUCCESS;
|
|
|
|
|
|
|
|
FreeDstBuffer:
|
|
|
|
FreePages (DstBuffer, EFI_SIZE_TO_PAGES (DstBufferSize));
|
|
|
|
|
StandaloneMmPkg/Core: Implementation of Standalone MM Core Module.
Management Mode (MM) is a generic term used to describe a secure
execution environment provided by the CPU and related silicon that is
entered when the CPU detects a MMI. For x86 systems, this can be
implemented with System Management Mode (SMM). For ARM systems, this can
be implemented with TrustZone (TZ).
A MMI can be a CPU instruction or interrupt. Upon detection of a MMI, a
CPU will jump to the MM Entry Point and save some portion of its state
(the "save state") such that execution can be resumed.
The MMI can be generated synchronously by software or asynchronously by
a hardware event. Each MMI source can be detected, cleared and disabled.
Some systems provide for special memory (Management Mode RAM or MMRAM)
which is set aside for software running in MM. Usually the MMRAM is
hidden during normal CPU execution, but this is not required. Usually,
after MMRAM is hidden it cannot be exposed until the next system reset.
The MM Core Interface Specification describes three pieces of the PI
Management Mode architecture:
1. MM Dispatch
During DXE, the DXE Foundation works with the MM Foundation to
schedule MM drivers for execution in the discovered firmware volumes.
2. MM Initialization
MM related code opens MMRAM, creates the MMRAM memory map, and
launches the MM Foundation, which provides the necessary services to
launch MM-related drivers. Then, sometime before boot, MMRAM is
closed and locked. This piece may be completed during the
SEC, PEI or DXE phases.
3. MMI Management
When an MMI generated, the MM environment is created and then the MMI
sources are detected and MMI handlers called.
This patch implements the MM Core.
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Sughosh Ganu <sughosh.ganu@arm.com>
Signed-off-by: Supreeth Venkatesh <supreeth.venkatesh@arm.com>
Reviewed-by: Jiewen Yao <jiewen.yao@intel.com>
2018-07-13 17:05:27 +02:00
|
|
|
return Status;
|
|
|
|
}
|