]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/AutoScanPei/AutoScanPei.c
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[mirror_edk2.git] / EmulatorPkg / AutoScanPei / AutoScanPei.c
1 /*++ @file
2
3 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
4 Portions copyright (c) 2011, Apple Inc. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "PiPei.h"
10 #include <Ppi/EmuThunk.h>
11 #include <Ppi/MemoryDiscovered.h>
12
13 #include <Library/DebugLib.h>
14 #include <Library/PeimEntryPoint.h>
15 #include <Library/BaseLib.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/HobLib.h>
18 #include <Library/PeiServicesLib.h>
19 #include <Library/PeiServicesTablePointerLib.h>
20
21 EFI_STATUS
22 EFIAPI
23 PeimInitializeAutoScanPei (
24 IN EFI_PEI_FILE_HANDLE FileHandle,
25 IN CONST EFI_PEI_SERVICES **PeiServices
26 )
27
28 /*++
29
30 Routine Description:
31 Perform a call-back into the SEC simulator to get a memory value
32
33 Arguments:
34 FfsHeader - General purpose data available to every PEIM
35 PeiServices - General purpose services available to every PEIM.
36
37 Returns:
38 None
39
40 **/
41 {
42 EFI_STATUS Status;
43 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
44 EMU_THUNK_PPI *Thunk;
45 UINT64 MemorySize;
46 EFI_PHYSICAL_ADDRESS MemoryBase;
47 UINTN Index;
48 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
49
50 DEBUG ((DEBUG_ERROR, "Emu Autoscan PEIM Loaded\n"));
51
52 //
53 // Get the PEI UNIX Autoscan PPI
54 //
55 Status = PeiServicesLocatePpi (
56 &gEmuThunkPpiGuid, // GUID
57 0, // INSTANCE
58 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
59 (VOID **)&Thunk // PPI
60 );
61 ASSERT_EFI_ERROR (Status);
62
63 Index = 0;
64 do {
65 Status = Thunk->MemoryAutoScan (Index, &MemoryBase, &MemorySize);
66 if (!EFI_ERROR (Status)) {
67 Attributes =
68 (
69 EFI_RESOURCE_ATTRIBUTE_PRESENT |
70 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
71 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
72 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
73 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
74 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
75 );
76
77 if (Index == 0) {
78 //
79 // Register the memory with the PEI Core
80 //
81 Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);
82 ASSERT_EFI_ERROR (Status);
83
84 Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;
85 }
86
87 BuildResourceDescriptorHob (
88 EFI_RESOURCE_SYSTEM_MEMORY,
89 Attributes,
90 MemoryBase,
91 MemorySize
92 );
93 }
94
95 Index++;
96 } while (!EFI_ERROR (Status));
97
98 //
99 // Build the CPU hob with 57-bit addressing and 16-bits of IO space.
100 //
101 BuildCpuHob (57, 16);
102
103 return Status;
104 }