3 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>
4 Copyright (c) 2011 Hewlett Packard Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 PEIM to provide fake memory init
26 // The package level header files this module uses
30 // The protocols, PPI and GUID defintions for this module
34 // The Library classes this module consumes
36 #include <Library/DebugLib.h>
37 #include <Library/PeimEntryPoint.h>
38 #include <Library/PcdLib.h>
39 #include <Library/HobLib.h>
40 #include <Library/ArmLib.h>
46 #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
47 #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
51 OUT UINT32
*PhysicalBase
,
55 EFI_PEI_HOB_POINTERS NextHob
;
57 // look at the resource descriptor hobs, choose the first system memory one
58 NextHob
.Raw
= GetHobList ();
59 while ((NextHob
.Raw
= GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, NextHob
.Raw
)) != NULL
) {
60 if(NextHob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
)
62 *PhysicalBase
= (UINT32
)NextHob
.ResourceDescriptor
->PhysicalStart
;
63 *Length
= (UINT32
)NextHob
.ResourceDescriptor
->ResourceLength
;
67 NextHob
.Raw
= GET_NEXT_HOB (NextHob
);
78 UINT32 CacheAttributes
;
79 UINT32 SystemMemoryBase
;
80 UINT32 SystemMemoryLength
;
81 UINT32 SystemMemoryLastAddress
;
82 ARM_MEMORY_REGION_DESCRIPTOR MemoryTable
[4];
83 VOID
*TranslationTableBase
;
84 UINTN TranslationTableSize
;
86 if (FeaturePcdGet(PcdCacheEnable
) == TRUE
) {
87 CacheAttributes
= DDR_ATTRIBUTES_CACHED
;
89 CacheAttributes
= DDR_ATTRIBUTES_UNCACHED
;
95 Status
= FindMainMemory (&SystemMemoryBase
, &SystemMemoryLength
);
96 ASSERT_EFI_ERROR (Status
);
98 SystemMemoryLastAddress
= SystemMemoryBase
+ (SystemMemoryLength
-1);
100 // if system memory does not begin at 0
101 if(SystemMemoryBase
> 0) {
102 MemoryTable
[Idx
].PhysicalBase
= 0;
103 MemoryTable
[Idx
].VirtualBase
= 0;
104 MemoryTable
[Idx
].Length
= SystemMemoryBase
;
105 MemoryTable
[Idx
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
109 MemoryTable
[Idx
].PhysicalBase
= SystemMemoryBase
;
110 MemoryTable
[Idx
].VirtualBase
= SystemMemoryBase
;
111 MemoryTable
[Idx
].Length
= SystemMemoryLength
;
112 MemoryTable
[Idx
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)CacheAttributes
;
115 // if system memory does not go to the last address (0xFFFFFFFF)
116 if( SystemMemoryLastAddress
< MAX_ADDRESS
) {
117 MemoryTable
[Idx
].PhysicalBase
= SystemMemoryLastAddress
+ 1;
118 MemoryTable
[Idx
].VirtualBase
= MemoryTable
[Idx
].PhysicalBase
;
119 MemoryTable
[Idx
].Length
= MAX_ADDRESS
- MemoryTable
[Idx
].PhysicalBase
+ 1;
120 MemoryTable
[Idx
].Attributes
= ARM_MEMORY_REGION_ATTRIBUTE_DEVICE
;
125 MemoryTable
[Idx
].PhysicalBase
= 0;
126 MemoryTable
[Idx
].VirtualBase
= 0;
127 MemoryTable
[Idx
].Length
= 0;
128 MemoryTable
[Idx
].Attributes
= (ARM_MEMORY_REGION_ATTRIBUTES
)0;
130 DEBUG ((EFI_D_INFO
, "Enabling MMU, setting 0x%08x + %d MB to %a\n",
131 SystemMemoryBase
, SystemMemoryLength
/1024/1024,
132 (CacheAttributes
== DDR_ATTRIBUTES_CACHED
) ? "cacheable" : "uncacheable"));
134 ArmConfigureMmu (MemoryTable
, &TranslationTableBase
, &TranslationTableSize
);
136 BuildMemoryAllocationHob((EFI_PHYSICAL_ADDRESS
)(UINTN
)TranslationTableBase
, TranslationTableSize
, EfiBootServicesData
);
143 IN EFI_PEI_FILE_HANDLE FileHandle
,
144 IN CONST EFI_PEI_SERVICES
**PeiServices
154 FileHandle - Handle of the file being invoked.
155 PeiServices - Describes the list of possible PEI Services.
159 Status - EFI_SUCCESS if the boot mode could be set
163 // Enable program flow prediction, if supported.
164 ArmEnableBranchPrediction ();
166 // publish the CPU memory and io spaces sizes
167 BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize
), PcdGet8 (PcdPrePiCpuIoSize
));