3 Secure Encrypted Virtualization (SEV) library helper function
5 Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/BaseLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/MemEncryptSevLib.h>
14 #include <Library/PcdLib.h>
15 #include <Register/QemuSmramSaveStateMap.h>
16 #include <Register/SmramSaveStateMap.h>
17 #include <Uefi/UefiBaseType.h>
20 Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
23 @param[out] BaseAddress The base address of the lowest-address page that
24 covers the initial SMRAM Save State Map.
26 @param[out] NumberOfPages The number of pages in the page range that covers
27 the initial SMRAM Save State Map.
29 @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
32 @retval RETURN_UNSUPPORTED SMM is unavailable.
36 MemEncryptSevLocateInitialSmramSaveStateMapPages (
37 OUT UINTN
*BaseAddress
,
38 OUT UINTN
*NumberOfPages
43 UINTN MapPagesStart
; // MapStart rounded down to page boundary
44 UINTN MapPagesEnd
; // MapEnd rounded up to page boundary
45 UINTN MapPagesSize
; // difference between MapPagesStart and MapPagesEnd
47 if (!FeaturePcdGet (PcdSmmSmramRequire
)) {
48 return RETURN_UNSUPPORTED
;
51 MapStart
= SMM_DEFAULT_SMBASE
+ SMRAM_SAVE_STATE_MAP_OFFSET
;
52 MapEnd
= MapStart
+ sizeof (QEMU_SMRAM_SAVE_STATE_MAP
);
53 MapPagesStart
= MapStart
& ~(UINTN
)EFI_PAGE_MASK
;
54 MapPagesEnd
= ALIGN_VALUE (MapEnd
, EFI_PAGE_SIZE
);
55 MapPagesSize
= MapPagesEnd
- MapPagesStart
;
57 ASSERT ((MapPagesSize
& EFI_PAGE_MASK
) == 0);
59 *BaseAddress
= MapPagesStart
;
60 *NumberOfPages
= MapPagesSize
>> EFI_PAGE_SHIFT
;
62 return RETURN_SUCCESS
;