]> git.proxmox.com Git - mirror_edk2.git/blob - UnixPkg/UnixAutoScanPei/UnixAutoScan.c
Apply PeiServicesLib
[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_PEI_FILE_HANDLE FileHandle,
39 IN CONST 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 = PeiServicesLocatePpi (
72 &gPeiUnixAutoScanPpiGuid, // GUID
73 0, // INSTANCE
74 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
75 (VOID **)&PeiUnixService // PPI
76 );
77 ASSERT_EFI_ERROR (Status);
78
79 //
80 // Get the Memory Test PPI
81 //
82 Status = PeiServicesLocatePpi (
83 &gPeiBaseMemoryTestPpiGuid,
84 0,
85 NULL,
86 (VOID**)&MemoryTestPpi
87 );
88 ASSERT_EFI_ERROR (Status);
89
90 Index = 0;
91 do {
92 Status = PeiUnixService->UnixAutoScan (Index, &MemoryBase, &MemorySize);
93 if (!EFI_ERROR (Status)) {
94 Attributes =
95 (
96 EFI_RESOURCE_ATTRIBUTE_PRESENT |
97 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
98 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
99 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
100 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
101 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
102 );
103
104 if (Index == 0) {
105 //
106 // For the first area register it as PEI tested memory
107 //
108 Status = MemoryTestPpi->BaseMemoryTest (
109 PeiServices,
110 MemoryTestPpi,
111 MemoryBase,
112 MemorySize,
113 Quick,
114 &ErrorAddress
115 );
116 ASSERT_EFI_ERROR (Status);
117
118 //
119 // Register the "tested" memory with the PEI Core
120 //
121 Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);
122 ASSERT_EFI_ERROR (Status);
123
124 Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;
125 }
126
127 BuildResourceDescriptorHob (
128 EFI_RESOURCE_SYSTEM_MEMORY,
129 Attributes,
130 MemoryBase,
131 MemorySize
132 );
133 }
134 Index++;
135 } while (!EFI_ERROR (Status));
136
137 //
138 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
139 //
140 BuildCpuHob (36, 16);
141
142 return Status;
143 }