]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Drivers/CpuPei/CpuPei.c
ArmPkg/CpuPei: Get the System Memory from the Resource Memory HOB
[mirror_edk2.git] / ArmPkg / Drivers / CpuPei / CpuPei.c
1 /**@file
2
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
9
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.
12
13 Module Name:
14
15 MemoryInit.c
16
17 Abstract:
18
19 PEIM to provide fake memory init
20
21 **/
22
23
24
25 //
26 // The package level header files this module uses
27 //
28 #include <PiPei.h>
29 //
30 // The protocols, PPI and GUID defintions for this module
31 //
32
33 //
34 // The Library classes this module consumes
35 //
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>
41
42 //
43 // Module globals
44 //
45
46 #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
47 #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
48
49 EFI_STATUS
50 FindMainMemory(
51 OUT UINT32 *PhysicalBase,
52 OUT UINT32 *Length
53 )
54 {
55 EFI_PEI_HOB_POINTERS NextHob;
56
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)
61 {
62 *PhysicalBase = (UINT32)NextHob.ResourceDescriptor->PhysicalStart;
63 *Length = (UINT32)NextHob.ResourceDescriptor->ResourceLength;
64 return EFI_SUCCESS;
65 }
66
67 NextHob.Raw = GET_NEXT_HOB (NextHob);
68 }
69
70 return EFI_NOT_FOUND;
71 }
72
73 VOID
74 ConfigureMmu ( VOID )
75 {
76 EFI_STATUS Status;
77 UINTN Idx;
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;
85
86 if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
87 CacheAttributes = DDR_ATTRIBUTES_CACHED;
88 } else {
89 CacheAttributes = DDR_ATTRIBUTES_UNCACHED;
90 }
91
92 Idx = 0;
93
94 // Main Memory
95 Status = FindMainMemory (&SystemMemoryBase, &SystemMemoryLength);
96 ASSERT_EFI_ERROR (Status);
97
98 SystemMemoryLastAddress = SystemMemoryBase + (SystemMemoryLength-1);
99
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;
106 Idx++;
107 }
108
109 MemoryTable[Idx].PhysicalBase = SystemMemoryBase;
110 MemoryTable[Idx].VirtualBase = SystemMemoryBase;
111 MemoryTable[Idx].Length = SystemMemoryLength;
112 MemoryTable[Idx].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;
113 Idx++;
114
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;
121 Idx++;
122 }
123
124 // End of Table
125 MemoryTable[Idx].PhysicalBase = 0;
126 MemoryTable[Idx].VirtualBase = 0;
127 MemoryTable[Idx].Length = 0;
128 MemoryTable[Idx].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;
129
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"));
133
134 ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);
135
136 BuildMemoryAllocationHob((EFI_PHYSICAL_ADDRESS)(UINTN)TranslationTableBase, TranslationTableSize, EfiBootServicesData);
137 }
138
139
140 EFI_STATUS
141 EFIAPI
142 InitializeCpuPeim (
143 IN EFI_PEI_FILE_HANDLE FileHandle,
144 IN CONST EFI_PEI_SERVICES **PeiServices
145 )
146 /*++
147
148 Routine Description:
149
150
151
152 Arguments:
153
154 FileHandle - Handle of the file being invoked.
155 PeiServices - Describes the list of possible PEI Services.
156
157 Returns:
158
159 Status - EFI_SUCCESS if the boot mode could be set
160
161 --*/
162 {
163 // Enable program flow prediction, if supported.
164 ArmEnableBranchPrediction ();
165
166 ConfigureMmu();
167
168 return EFI_SUCCESS;
169 }