VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/BaseMemEncryptSevLib/PeiDxeMemEncryptSevLibInternal.c@ 105670

Last change on this file since 105670 was 105670, checked in by vboxsync, 7 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
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**/
34RETURN_STATUS
35EFIAPI
36MemEncryptSevLocateInitialSmramSaveStateMapPages (
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}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette