]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixAutoScanPei/UnixAutoScan.c
Port EdkUnixPkg to UnixPkg. The changes are listed as follows:
[mirror_edk2.git] / UnixPkg / UnixAutoScanPei / UnixAutoScan.c
1 /*++
2
3 Copyright (c) 2006 - 2008, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 Module Name:
13 UnixAutoscan.c
14
15 Abstract:
16 This PEIM to abstract memory auto-scan in an Unix environment.
17
18 Revision History
19
20 --*/
21
22 #include "PiPei.h"
23 #include <Ppi/UnixAutoScan.h>
24 #include <Ppi/BaseMemoryTest.h>
25 #include <Ppi/MemoryDiscovered.h>
26
27 #include <Library/DebugLib.h>
28 #include <Library/PeimEntryPoint.h>
29 #include <Library/BaseLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/HobLib.h>
32 #include <Library/PeiServicesLib.h>
33 #include <Library/PeiServicesTablePointerLib.h>
34
35 EFI_STATUS
36 EFIAPI
37 PeimInitializeUnixAutoScan (
38 IN EFI_FFS_FILE_HEADER *FfsHeader,
39 IN EFI_PEI_SERVICES **PeiServices
40 )
41 /*++
42
43 Routine Description:
44 Perform a call-back into the SEC simulator to get a memory value
45
46 Arguments:
47 FfsHeader - General purpose data available to every PEIM
48 PeiServices - General purpose services available to every PEIM.
49
50 Returns:
51 None
52
53 --*/
54 {
55 EFI_STATUS Status;
56 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
57 PEI_UNIX_AUTOSCAN_PPI *PeiUnixService;
58 UINT64 MemorySize;
59 EFI_PHYSICAL_ADDRESS MemoryBase;
60 PEI_BASE_MEMORY_TEST_PPI *MemoryTestPpi;
61 EFI_PHYSICAL_ADDRESS ErrorAddress;
62 UINTN Index;
63 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
64
65
66 DEBUG ((EFI_D_ERROR, "Unix Autoscan PEIM Loaded\n"));
67
68 //
69 // Get the PEI UNIX Autoscan PPI
70 //
71 Status = (**PeiServices).LocatePpi (
72 PeiServices,
73 &gPeiUnixAutoScanPpiGuid, // GUID
74 0, // INSTANCE
75 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
76 (VOID **)&PeiUnixService // PPI
77 );
78 ASSERT_EFI_ERROR (Status);
79
80 //
81 // Get the Memory Test PPI
82 //
83 Status = (**PeiServices).LocatePpi (
84 PeiServices,
85 &gPeiBaseMemoryTestPpiGuid,
86 0,
87 NULL,
88 (VOID **)&MemoryTestPpi
89 );
90 ASSERT_EFI_ERROR (Status);
91
92 Index = 0;
93 do {
94 Status = PeiUnixService->UnixAutoScan (Index, &MemoryBase, &MemorySize);
95 if (!EFI_ERROR (Status)) {
96 Attributes =
97 (
98 EFI_RESOURCE_ATTRIBUTE_PRESENT |
99 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
100 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
101 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
102 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
103 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
104 );
105
106 if (Index == 0) {
107 //
108 // For the first area register it as PEI tested memory
109 //
110 Status = MemoryTestPpi->BaseMemoryTest (
111 PeiServices,
112 MemoryTestPpi,
113 MemoryBase,
114 MemorySize,
115 Quick,
116 &ErrorAddress
117 );
118 ASSERT_EFI_ERROR (Status);
119
120 //
121 // Register the "tested" memory with the PEI Core
122 //
123 Status = (**PeiServices).InstallPeiMemory (PeiServices, MemoryBase, MemorySize);
124 ASSERT_EFI_ERROR (Status);
125
126 Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;
127 }
128
129 BuildResourceDescriptorHob (
130 EFI_RESOURCE_SYSTEM_MEMORY,
131 Attributes,
132 MemoryBase,
133 MemorySize
134 );
135 }
136 Index++;
137 } while (!EFI_ERROR (Status));
138
139 //
140 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
141 //
142 BuildCpuHob (36, 16);
143
144 return Status;
145 }