1 | /** @file
|
---|
2 |
|
---|
3 | Secure Encrypted Virtualization (SEV) library helper function
|
---|
4 |
|
---|
5 | Copyright (c) 2017 - 2020, AMD Incorporated. All rights reserved.<BR>
|
---|
6 |
|
---|
7 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
8 |
|
---|
9 | **/
|
---|
10 |
|
---|
11 | #include <Library/BaseLib.h>
|
---|
12 | #include <Library/DebugLib.h>
|
---|
13 | #include <Library/MemEncryptSevLib.h>
|
---|
14 | #include <Library/PcdLib.h>
|
---|
15 | #include <Register/Amd/SmramSaveStateMap.h>
|
---|
16 | #include <Register/SmramSaveStateMap.h>
|
---|
17 | #include <Uefi/UefiBaseType.h>
|
---|
18 |
|
---|
19 | /**
|
---|
20 | Locate the page range that covers the initial (pre-SMBASE-relocation) SMRAM
|
---|
21 | Save State Map.
|
---|
22 |
|
---|
23 | @param[out] BaseAddress The base address of the lowest-address page that
|
---|
24 | covers the initial SMRAM Save State Map.
|
---|
25 |
|
---|
26 | @param[out] NumberOfPages The number of pages in the page range that covers
|
---|
27 | the initial SMRAM Save State Map.
|
---|
28 |
|
---|
29 | @retval RETURN_SUCCESS BaseAddress and NumberOfPages have been set on
|
---|
30 | output.
|
---|
31 |
|
---|
32 | @retval RETURN_UNSUPPORTED SMM is unavailable.
|
---|
33 | **/
|
---|
34 | RETURN_STATUS
|
---|
35 | EFIAPI
|
---|
36 | MemEncryptSevLocateInitialSmramSaveStateMapPages (
|
---|
37 | OUT UINTN *BaseAddress,
|
---|
38 | OUT UINTN *NumberOfPages
|
---|
39 | )
|
---|
40 | {
|
---|
41 | UINTN MapStart;
|
---|
42 | UINTN MapEnd;
|
---|
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
|
---|
46 |
|
---|
47 | if (!FeaturePcdGet (PcdSmmSmramRequire)) {
|
---|
48 | return RETURN_UNSUPPORTED;
|
---|
49 | }
|
---|
50 |
|
---|
51 | MapStart = SMM_DEFAULT_SMBASE + SMRAM_SAVE_STATE_MAP_OFFSET;
|
---|
52 | MapEnd = MapStart + sizeof (AMD_SMRAM_SAVE_STATE_MAP);
|
---|
53 | MapPagesStart = MapStart & ~(UINTN)EFI_PAGE_MASK;
|
---|
54 | MapPagesEnd = ALIGN_VALUE (MapEnd, EFI_PAGE_SIZE);
|
---|
55 | MapPagesSize = MapPagesEnd - MapPagesStart;
|
---|
56 |
|
---|
57 | ASSERT ((MapPagesSize & EFI_PAGE_MASK) == 0);
|
---|
58 |
|
---|
59 | *BaseAddress = MapPagesStart;
|
---|
60 | *NumberOfPages = MapPagesSize >> EFI_PAGE_SHIFT;
|
---|
61 |
|
---|
62 | return RETURN_SUCCESS;
|
---|
63 | }
|
---|