]> git.proxmox.com Git - mirror_edk2.git/blob - EmulatorPkg/AutoScanPei/AutoScanPei.c
EmulatorPkg: Replace BSD License with BSD+Patent License
[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 Routine Description:
30 Perform a call-back into the SEC simulator to get a memory value
31
32 Arguments:
33 FfsHeader - General purpose data available to every PEIM
34 PeiServices - General purpose services available to every PEIM.
35
36 Returns:
37 None
38
39 **/
40 {
41 EFI_STATUS Status;
42 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
43 EMU_THUNK_PPI *Thunk;
44 UINT64 MemorySize;
45 EFI_PHYSICAL_ADDRESS MemoryBase;
46 UINTN Index;
47 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
48
49
50 DEBUG ((EFI_D_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 Index++;
95 } while (!EFI_ERROR (Status));
96
97 //
98 // Build the CPU hob with 57-bit addressing and 16-bits of IO space.
99 //
100 BuildCpuHob (57, 16);
101
102 return Status;
103 }