1/*++ @file 2 3Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR> 4Portions copyright (c) 2011, Apple Inc. All rights reserved. 5This program and the accompanying materials 6are licensed and made available under the terms and conditions of the BSD License 7which accompanies this distribution. The full text of the license may be found at 8http://opensource.org/licenses/bsd-license.php 9 10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13**/ 14 15#include "PiPei.h" 16#include <Ppi/EmuThunk.h> 17#include <Ppi/MemoryDiscovered.h> 18 19#include <Library/DebugLib.h> 20#include <Library/PeimEntryPoint.h> 21#include <Library/BaseLib.h> 22#include <Library/BaseMemoryLib.h> 23#include <Library/HobLib.h> 24#include <Library/PeiServicesLib.h> 25#include <Library/PeiServicesTablePointerLib.h> 26 27EFI_STATUS 28EFIAPI 29PeimInitializeAutoScanPei ( 30 IN EFI_PEI_FILE_HANDLE FileHandle, 31 IN CONST EFI_PEI_SERVICES **PeiServices 32 ) 33/*++ 34 35Routine Description: 36 Perform a call-back into the SEC simulator to get a memory value 37 38Arguments: 39 FfsHeader - General purpose data available to every PEIM 40 PeiServices - General purpose services available to every PEIM. 41 42Returns: 43 None 44 45**/ 46{ 47 EFI_STATUS Status; 48 EFI_PEI_PPI_DESCRIPTOR *PpiDescriptor; 49 EMU_THUNK_PPI *Thunk; 50 UINT64 MemorySize; 51 EFI_PHYSICAL_ADDRESS MemoryBase; 52 UINTN Index; 53 EFI_RESOURCE_ATTRIBUTE_TYPE Attributes; 54 55 56 DEBUG ((EFI_D_ERROR, "Emu Autoscan PEIM Loaded\n")); 57 58 // 59 // Get the PEI UNIX Autoscan PPI 60 // 61 Status = PeiServicesLocatePpi ( 62 &gEmuThunkPpiGuid, // GUID 63 0, // INSTANCE 64 &PpiDescriptor, // EFI_PEI_PPI_DESCRIPTOR 65 (VOID **)&Thunk // PPI 66 ); 67 ASSERT_EFI_ERROR (Status); 68 69 Index = 0; 70 do { 71 Status = Thunk->MemoryAutoScan (Index, &MemoryBase, &MemorySize); 72 if (!EFI_ERROR (Status)) { 73 Attributes = 74 ( 75 EFI_RESOURCE_ATTRIBUTE_PRESENT | 76 EFI_RESOURCE_ATTRIBUTE_INITIALIZED | 77 EFI_RESOURCE_ATTRIBUTE_UNCACHEABLE | 78 EFI_RESOURCE_ATTRIBUTE_WRITE_COMBINEABLE | 79 EFI_RESOURCE_ATTRIBUTE_WRITE_THROUGH_CACHEABLE | 80 EFI_RESOURCE_ATTRIBUTE_WRITE_BACK_CACHEABLE 81 ); 82 83 if (Index == 0) { 84 // 85 // Register the memory with the PEI Core 86 // 87 Status = PeiServicesInstallPeiMemory (MemoryBase, MemorySize); 88 ASSERT_EFI_ERROR (Status); 89 90 Attributes |= EFI_RESOURCE_ATTRIBUTE_TESTED; 91 } 92 93 BuildResourceDescriptorHob ( 94 EFI_RESOURCE_SYSTEM_MEMORY, 95 Attributes, 96 MemoryBase, 97 MemorySize 98 ); 99 } 100 Index++; 101 } while (!EFI_ERROR (Status)); 102 103 // 104 // Build the CPU hob with 36-bit addressing and 16-bits of IO space. 105 // 106 BuildCpuHob (36, 16); 107 108 return Status; 109} 110