]> git.proxmox.com Git - mirror_edk2.git/blob - Nt32Pkg/WinNtAutoScanPei/WinNtAutoScan.c
9591c39fcfb6843b46dca8a31064d13ab1e8fd27
[mirror_edk2.git] / Nt32Pkg / WinNtAutoScanPei / WinNtAutoScan.c
1 /**@file
2
3 Copyright (c) 2006, 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 WinNtAutoscan.c
14
15 Abstract:
16 This PEIM to abstract memory auto-scan in a Windows NT environment.
17
18 Revision History
19
20 **/
21
22 //
23 // The package level header files this module uses
24 //
25 #include <PiPei.h>
26 #include <WinNtPeim.h>
27 //
28 // The protocols, PPI and GUID defintions for this module
29 //
30 #include <Ppi/BaseMemoryTest.h>
31 #include <Ppi/NtAutoscan.h>
32 //
33 // The Library classes this module consumes
34 //
35 #include <Library/DebugLib.h>
36 #include <Library/PeimEntryPoint.h>
37 #include <Library/HobLib.h>
38 #include <Library/PeiServicesLib.h>
39
40 EFI_STATUS
41 EFIAPI
42 PeimInitializeWinNtAutoScan (
43 IN EFI_PEI_FILE_HANDLE FileHandle,
44 IN CONST EFI_PEI_SERVICES **PeiServices
45 )
46 /*++
47
48 Routine Description:
49 Perform a call-back into the SEC simulator to get a memory value
50
51 Arguments:
52 FfsHeader - General purpose data available to every PEIM
53 PeiServices - General purpose services available to every PEIM.
54
55 Returns:
56 None
57
58 --*/
59 {
60 EFI_STATUS Status;
61 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor;
62 PEI_NT_AUTOSCAN_PPI *PeiNtService;
63 UINT64 MemorySize;
64 EFI_PHYSICAL_ADDRESS MemoryBase;
65 PEI_BASE_MEMORY_TEST_PPI *MemoryTestPpi;
66 EFI_PHYSICAL_ADDRESS ErrorAddress;
67 UINTN Index;
68 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes;
69
70
71 DEBUG ((EFI_D_ERROR, "NT 32 Autoscan PEIM Loaded\n"));
72
73 //
74 // Get the PEI NT Autoscan PPI
75 //
76 Status = PeiServicesLocatePpi (
77 &gPeiNtAutoScanPpiGuid, // GUID
78 0, // INSTANCE
79 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR
80 (VOID**)&PeiNtService // PPI
81 );
82 ASSERT_EFI_ERROR (Status);
83
84 //
85 // Get the Memory Test PPI
86 //
87 Status = PeiServicesLocatePpi (
88 &gPeiBaseMemoryTestPpiGuid,
89 0,
90 NULL,
91 (VOID**)&MemoryTestPpi
92 );
93 ASSERT_EFI_ERROR (Status);
94
95 Index = 0;
96 do {
97 Status = PeiNtService->NtAutoScan (Index, &MemoryBase, &MemorySize);
98 if (!EFI_ERROR (Status)) {
99 Attributes =
100 (
101 EFI_RESOURCE_ATTRIBUTE_PRESENT |
102 EFI_RESOURCE_ATTRIBUTE_INITIALIZED |
103 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE |
104 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE |
105 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE |
106 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE
107 );
108
109 if (Index == 0) {
110 //
111 // For the first area register it as PEI tested memory
112 //
113 Status = MemoryTestPpi->BaseMemoryTest (
114 (EFI_PEI_SERVICES **) PeiServices,
115 MemoryTestPpi,
116 MemoryBase,
117 MemorySize,
118 Quick,
119 &ErrorAddress
120 );
121 ASSERT_EFI_ERROR (Status);
122
123 //
124 // Register the "tested" memory with the PEI Core
125 //
126 Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize);
127 ASSERT_EFI_ERROR (Status);
128
129 Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED;
130 }
131
132 BuildResourceDescriptorHob (
133 EFI_RESOURCE_SYSTEM_MEMORY,
134 Attributes,
135 MemoryBase,
136 MemorySize
137 );
138 }
139 Index++;
140 } while (!EFI_ERROR (Status));
141
142 //
143 // Build the CPU hob with 36-bit addressing and 16-bits of IO space.
144 //
145 BuildCpuHob (36, 16);
146
147 return Status;
148 }