Add capsule > 4GB support. When capsule data is put above 4GB, IA32 PEI transfers to long mode to get capsule data.
Signed-off-by: li-elvin Reviewed-by: lgao4, mdkinney git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12264 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@@ -20,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#include <Uefi/UefiSpec.h>
|
||||
|
||||
#include <Ppi/Capsule.h>
|
||||
|
||||
#include <Ppi/LoadFile.h>
|
||||
#include <Ppi/ReadOnlyVariable2.h>
|
||||
#include <Guid/CapsuleVendor.h>
|
||||
|
||||
@@ -31,25 +31,71 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
||||
#include <Library/HobLib.h>
|
||||
#include <Library/PeiServicesTablePointerLib.h>
|
||||
#include <Library/PrintLib.h>
|
||||
#include <Library/PeCoffLib.h>
|
||||
#include <Library/PeCoffGetEntryPointLib.h>
|
||||
#include <Library/PcdLib.h>
|
||||
#include <Library/ReportStatusCodeLib.h>
|
||||
#include <IndustryStandard/PeImage.h>
|
||||
#include "Common/CommonHeader.h"
|
||||
|
||||
#pragma pack(1)
|
||||
|
||||
//
|
||||
// We want to avoid using memory at 0 for coalescing, so set a
|
||||
// min address.
|
||||
// Page-Map Level-4 Offset (PML4) and
|
||||
// Page-Directory-Pointer Offset (PDPE) entries 4K & 2MB
|
||||
//
|
||||
#define MIN_COALESCE_ADDR 0x100000
|
||||
#define MAX_SUPPORT_CAPSULE_NUM 50
|
||||
|
||||
typedef union {
|
||||
struct {
|
||||
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
|
||||
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
|
||||
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
|
||||
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
|
||||
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
|
||||
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
|
||||
UINT64 Reserved:1; // Reserved
|
||||
UINT64 MustBeZero:2; // Must Be Zero
|
||||
UINT64 Available:3; // Available for use by system software
|
||||
UINT64 PageTableBaseAddress:40; // Page Table Base Address
|
||||
UINT64 AvabilableHigh:11; // Available for use by system software
|
||||
UINT64 Nx:1; // No Execute bit
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
} PAGE_MAP_AND_DIRECTORY_POINTER;
|
||||
|
||||
//
|
||||
// This capsule PEIM puts its private data at the start of the
|
||||
// coalesced capsule. Here's the structure definition.
|
||||
// Page Table Entry 2MB
|
||||
//
|
||||
#define EFI_CAPSULE_PEIM_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('C', 'a', 'p', 'D')
|
||||
typedef union {
|
||||
struct {
|
||||
UINT64 Present:1; // 0 = Not present in memory, 1 = Present in memory
|
||||
UINT64 ReadWrite:1; // 0 = Read-Only, 1= Read/Write
|
||||
UINT64 UserSupervisor:1; // 0 = Supervisor, 1=User
|
||||
UINT64 WriteThrough:1; // 0 = Write-Back caching, 1=Write-Through caching
|
||||
UINT64 CacheDisabled:1; // 0 = Cached, 1=Non-Cached
|
||||
UINT64 Accessed:1; // 0 = Not accessed, 1 = Accessed (set by CPU)
|
||||
UINT64 Dirty:1; // 0 = Not Dirty, 1 = written by processor on access to page
|
||||
UINT64 MustBe1:1; // Must be 1
|
||||
UINT64 Global:1; // 0 = Not global page, 1 = global page TLB not cleared on CR3 write
|
||||
UINT64 Available:3; // Available for use by system software
|
||||
UINT64 PAT:1; //
|
||||
UINT64 MustBeZero:8; // Must be zero;
|
||||
UINT64 PageTableBaseAddress:31; // Page Table Base Address
|
||||
UINT64 AvabilableHigh:11; // Available for use by system software
|
||||
UINT64 Nx:1; // 0 = Execute Code, 1 = No Code Execution
|
||||
} Bits;
|
||||
UINT64 Uint64;
|
||||
} PAGE_TABLE_ENTRY;
|
||||
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
UINTN CapsuleSize;
|
||||
} EFI_CAPSULE_PEIM_PRIVATE_DATA;
|
||||
#pragma pack()
|
||||
|
||||
#define CAPSULE_TEST_SIGNATURE SIGNATURE_32('T', 'E', 'S', 'T')
|
||||
typedef
|
||||
EFI_STATUS
|
||||
(*COALESCE_ENTRY) (
|
||||
IN EFI_PEI_SERVICES **PeiServices,
|
||||
IN EFI_CAPSULE_BLOCK_DESCRIPTOR *BlockList,
|
||||
IN OUT VOID **MemoryBase,
|
||||
IN OUT UINTN *MemorySize
|
||||
);
|
||||
|
||||
#endif
|
||||
|
@@ -3,7 +3,7 @@
|
||||
#
|
||||
# Capsule update module supports EFI and UEFI.
|
||||
#
|
||||
# Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
|
||||
# Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
|
||||
#
|
||||
# This program and the accompanying materials
|
||||
# are licensed and made available under the terms and conditions
|
||||
@@ -34,6 +34,7 @@
|
||||
[Sources]
|
||||
UefiCapsule.c
|
||||
Capsule.h
|
||||
Common/CapsuleCoalesce.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
@@ -48,6 +49,10 @@
|
||||
DebugLib
|
||||
PeiServicesTablePointerLib
|
||||
PrintLib
|
||||
PeCoffLib
|
||||
PeCoffGetEntryPointLib
|
||||
PcdLib
|
||||
ReportStatusCodeLib
|
||||
|
||||
[Guids]
|
||||
gEfiCapsuleVendorGuid # ALWAYS_CONSUMED
|
||||
@@ -56,7 +61,11 @@
|
||||
[Ppis]
|
||||
gEfiPeiReadOnlyVariable2PpiGuid # PPI ALWAYS_CONSUMED
|
||||
gPeiCapsulePpiGuid # PPI ALWAYS_CONSUMED
|
||||
gEfiPeiLoadFilePpiGuid # PPI ALWAYS_CONSUMED
|
||||
|
||||
[Pcd]
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdCapsuleCoalesceFile
|
||||
gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode
|
||||
|
||||
[Depex]
|
||||
gEfiPeiReadOnlyVariable2PpiGuid
|
||||
|
48
MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
Normal file
48
MdeModulePkg/Universal/CapsulePei/CapsuleX64.inf
Normal file
@@ -0,0 +1,48 @@
|
||||
## @file
|
||||
# Component description file for CapsuleX64 module.
|
||||
#
|
||||
# The X64 entrypoint to process capsule in long mode.
|
||||
# This module is built as X64.
|
||||
#
|
||||
# Copyright (c) 2011, Intel Corporation. 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.
|
||||
#
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = CapsuleX64
|
||||
FILE_GUID = F7FDE4A6-294C-493c-B50F-9734553BB757
|
||||
MODULE_TYPE = PEIM
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = X64
|
||||
#
|
||||
|
||||
[Sources]
|
||||
X64/X64Entry.c
|
||||
Common/CapsuleCoalesce.c
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
MdeModulePkg/MdeModulePkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
BaseLib
|
||||
DebugLib
|
||||
|
||||
[Depex]
|
||||
FALSE
|
||||
|
||||
|
1104
MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c
Normal file
1104
MdeModulePkg/Universal/CapsulePei/Common/CapsuleCoalesce.c
Normal file
File diff suppressed because it is too large
Load Diff
84
MdeModulePkg/Universal/CapsulePei/Common/CommonHeader.h
Normal file
84
MdeModulePkg/Universal/CapsulePei/Common/CommonHeader.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/** @file
|
||||
Common header file.
|
||||
|
||||
Copyright (c) 2011, Intel Corporation. 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.
|
||||
|
||||
**/
|
||||
|
||||
#ifndef _CAPSULE_THUNK_32_TO_64_
|
||||
#define _CAPSULE_THUNK_32_TO_64_
|
||||
|
||||
#include <Uefi.h>
|
||||
#include "PiPei.h"
|
||||
|
||||
//
|
||||
// This capsule PEIM puts its private data at the start of the
|
||||
// coalesced capsule. Here's the structure definition.
|
||||
//
|
||||
#define EFI_CAPSULE_PEIM_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('C', 'a', 'p', 'D')
|
||||
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
UINTN CapsuleSize;
|
||||
} EFI_CAPSULE_PEIM_PRIVATE_DATA;
|
||||
|
||||
#define CAPSULE_TEST_SIGNATURE SIGNATURE_32('T', 'E', 'S', 'T')
|
||||
|
||||
typedef struct {
|
||||
EFI_PHYSICAL_ADDRESS EntryPoint;
|
||||
EFI_PHYSICAL_ADDRESS StackBufferBase;
|
||||
UINT64 StackBufferLength;
|
||||
EFI_PHYSICAL_ADDRESS JumpBuffer;
|
||||
EFI_PHYSICAL_ADDRESS BlockListAddr;
|
||||
EFI_PHYSICAL_ADDRESS MemoryBase64Ptr;
|
||||
EFI_PHYSICAL_ADDRESS MemorySize64Ptr;
|
||||
} SWITCH_32_TO_64_CONTEXT;
|
||||
|
||||
typedef struct {
|
||||
UINT16 ReturnCs;
|
||||
EFI_PHYSICAL_ADDRESS ReturnEntryPoint;
|
||||
UINT64 ReturnStatus;
|
||||
IA32_DESCRIPTOR Gdtr;
|
||||
} SWITCH_64_TO_32_CONTEXT;
|
||||
|
||||
/**
|
||||
The function to coalesce a fragmented capsule in memory.
|
||||
|
||||
@param PeiServices General purpose services available to every PEIM.
|
||||
@param BlockListBuffer Point to the buffer of Capsule Descriptor Variables.
|
||||
@param MemoryBase Pointer to the base of a block of memory that we can walk
|
||||
all over while trying to coalesce our buffers.
|
||||
On output, this variable will hold the base address of
|
||||
a coalesced capsule.
|
||||
@param MemorySize Size of the memory region pointed to by MemoryBase.
|
||||
On output, this variable will contain the size of the
|
||||
coalesced capsule.
|
||||
|
||||
@retval EFI_NOT_FOUND if we can't determine the boot mode
|
||||
if the boot mode is not flash-update
|
||||
if we could not find the capsule descriptors
|
||||
|
||||
@retval EFI_BUFFER_TOO_SMALL
|
||||
if we could not coalesce the capsule in the memory
|
||||
region provided to us
|
||||
|
||||
@retval EFI_SUCCESS if there's no capsule, or if we processed the
|
||||
capsule successfully.
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
CapsuleDataCoalesce (
|
||||
IN EFI_PEI_SERVICES **PeiServices,
|
||||
IN IN EFI_PHYSICAL_ADDRESS *BlockListBuffer,
|
||||
IN OUT VOID **MemoryBase,
|
||||
IN OUT UINTN *MemorySize
|
||||
);
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
66
MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
Normal file
66
MdeModulePkg/Universal/CapsulePei/X64/X64Entry.c
Normal file
@@ -0,0 +1,66 @@
|
||||
/** @file
|
||||
The X64 entrypoint is used to process capsule in long mode.
|
||||
|
||||
Copyright (c) 2011, Intel Corporation. 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 <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
#include "CommonHeader.h"
|
||||
|
||||
/**
|
||||
The X64 entrypoint is used to process capsule in long mode then
|
||||
return to 32-bit protected mode.
|
||||
|
||||
@param EntrypointContext Pointer to the context of long mode.
|
||||
@param ReturnContext Pointer to the context of 32-bit protected mode.
|
||||
|
||||
@retval This function should never return actually.
|
||||
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
_ModuleEntryPoint (
|
||||
SWITCH_32_TO_64_CONTEXT *EntrypointContext,
|
||||
SWITCH_64_TO_32_CONTEXT *ReturnContext
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
|
||||
//
|
||||
// Call CapsuleDataCoalesce to process capsule.
|
||||
//
|
||||
Status = CapsuleDataCoalesce (
|
||||
NULL,
|
||||
(EFI_PHYSICAL_ADDRESS *) (UINTN) EntrypointContext->BlockListAddr,
|
||||
(VOID **) (UINTN) EntrypointContext->MemoryBase64Ptr,
|
||||
(UINTN *) (UINTN) EntrypointContext->MemorySize64Ptr
|
||||
);
|
||||
|
||||
ReturnContext->ReturnStatus = Status;
|
||||
|
||||
//
|
||||
// Finish to coalesce capsule, and return to 32-bit mode.
|
||||
//
|
||||
AsmDisablePaging64 (
|
||||
ReturnContext->ReturnCs,
|
||||
(UINT32) ReturnContext->ReturnEntryPoint,
|
||||
(UINT32) (UINTN) EntrypointContext,
|
||||
(UINT32) (UINTN) ReturnContext,
|
||||
(UINT32) (EntrypointContext->StackBufferBase + EntrypointContext->StackBufferLength)
|
||||
);
|
||||
|
||||
//
|
||||
// Should never be here.
|
||||
//
|
||||
ASSERT (FALSE);
|
||||
return EFI_SUCCESS;
|
||||
}
|
Reference in New Issue
Block a user