]>
Commit | Line | Data |
---|---|---|
afdfe8f0 | 1 | /**@file\r |
2 | \r | |
3 | Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r | |
fbcd5cea | 4 | Copyright (c) 2011 Hewlett Packard Corporation. All rights reserved.<BR>\r |
afdfe8f0 | 5 | This program and the accompanying materials \r |
6 | are licensed and made available under the terms and conditions of the BSD License \r | |
7 | which accompanies this distribution. The full text of the license may be found at \r | |
8 | http://opensource.org/licenses/bsd-license.php \r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r | |
12 | \r | |
13 | Module Name:\r | |
14 | \r | |
15 | MemoryInit.c\r | |
16 | \r | |
17 | Abstract:\r | |
18 | \r | |
19 | PEIM to provide fake memory init\r | |
20 | \r | |
21 | **/\r | |
22 | \r | |
23 | \r | |
24 | \r | |
25 | //\r | |
26 | // The package level header files this module uses\r | |
27 | //\r | |
28 | #include <PiPei.h>\r | |
29 | //\r | |
30 | // The protocols, PPI and GUID defintions for this module\r | |
31 | //\r | |
32 | \r | |
33 | //\r | |
34 | // The Library classes this module consumes\r | |
35 | //\r | |
36 | #include <Library/DebugLib.h>\r | |
37 | #include <Library/PeimEntryPoint.h>\r | |
38 | #include <Library/PcdLib.h>\r | |
39 | #include <Library/HobLib.h>\r | |
40 | #include <Library/ArmLib.h>\r | |
41 | \r | |
42 | //\r | |
43 | // Module globals\r | |
44 | //\r | |
45 | \r | |
46 | #define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK\r | |
47 | #define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED\r | |
48 | \r | |
fbcd5cea | 49 | EFI_STATUS\r |
50 | FindMainMemory(\r | |
51 | OUT UINT32 *PhysicalBase,\r | |
52 | OUT UINT32 *Length\r | |
53 | )\r | |
54 | {\r | |
55 | EFI_PEI_HOB_POINTERS NextHob;\r | |
56 | \r | |
57 | // look at the resource descriptor hobs, choose the first system memory one\r | |
58 | NextHob.Raw = GetHobList ();\r | |
59 | while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r | |
60 | if(NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY)\r | |
61 | {\r | |
62 | *PhysicalBase = (UINT32)NextHob.ResourceDescriptor->PhysicalStart;\r | |
63 | *Length = (UINT32)NextHob.ResourceDescriptor->ResourceLength;\r | |
64 | return EFI_SUCCESS;\r | |
65 | }\r | |
66 | \r | |
67 | NextHob.Raw = GET_NEXT_HOB (NextHob);\r | |
68 | }\r | |
69 | \r | |
70 | return EFI_NOT_FOUND;\r | |
71 | }\r | |
72 | \r | |
afdfe8f0 | 73 | VOID\r |
fbcd5cea | 74 | ConfigureMmu ( VOID )\r |
afdfe8f0 | 75 | {\r |
fbcd5cea | 76 | EFI_STATUS Status;\r |
77 | UINTN Idx;\r | |
afdfe8f0 | 78 | UINT32 CacheAttributes;\r |
fbcd5cea | 79 | UINT32 SystemMemoryBase;\r |
80 | UINT32 SystemMemoryLength;\r | |
81 | UINT32 SystemMemoryLastAddress;\r | |
82 | ARM_MEMORY_REGION_DESCRIPTOR MemoryTable[4];\r | |
afdfe8f0 | 83 | VOID *TranslationTableBase;\r |
84 | UINTN TranslationTableSize;\r | |
85 | \r | |
86 | if (FeaturePcdGet(PcdCacheEnable) == TRUE) {\r | |
87 | CacheAttributes = DDR_ATTRIBUTES_CACHED;\r | |
88 | } else {\r | |
89 | CacheAttributes = DDR_ATTRIBUTES_UNCACHED;\r | |
90 | }\r | |
91 | \r | |
fbcd5cea | 92 | Idx = 0;\r |
93 | \r | |
94 | // Main Memory\r | |
95 | Status = FindMainMemory (&SystemMemoryBase, &SystemMemoryLength);\r | |
96 | ASSERT_EFI_ERROR (Status);\r | |
97 | \r | |
98 | SystemMemoryLastAddress = SystemMemoryBase + (SystemMemoryLength-1);\r | |
99 | \r | |
100 | // if system memory does not begin at 0\r | |
101 | if(SystemMemoryBase > 0) {\r | |
102 | MemoryTable[Idx].PhysicalBase = 0;\r | |
103 | MemoryTable[Idx].VirtualBase = 0;\r | |
104 | MemoryTable[Idx].Length = SystemMemoryBase;\r | |
105 | MemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r | |
106 | Idx++;\r | |
107 | }\r | |
afdfe8f0 | 108 | \r |
fbcd5cea | 109 | MemoryTable[Idx].PhysicalBase = SystemMemoryBase;\r |
110 | MemoryTable[Idx].VirtualBase = SystemMemoryBase;\r | |
111 | MemoryTable[Idx].Length = SystemMemoryLength;\r | |
112 | MemoryTable[Idx].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;\r | |
113 | Idx++;\r | |
114 | \r | |
115 | // if system memory does not go to the last address (0xFFFFFFFF)\r | |
116 | if( SystemMemoryLastAddress < MAX_ADDRESS ) {\r | |
117 | MemoryTable[Idx].PhysicalBase = SystemMemoryLastAddress + 1;\r | |
118 | MemoryTable[Idx].VirtualBase = MemoryTable[Idx].PhysicalBase;\r | |
119 | MemoryTable[Idx].Length = MAX_ADDRESS - MemoryTable[Idx].PhysicalBase + 1;\r | |
120 | MemoryTable[Idx].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r | |
121 | Idx++;\r | |
122 | }\r | |
afdfe8f0 | 123 | \r |
124 | // End of Table\r | |
fbcd5cea | 125 | MemoryTable[Idx].PhysicalBase = 0;\r |
126 | MemoryTable[Idx].VirtualBase = 0;\r | |
127 | MemoryTable[Idx].Length = 0;\r | |
128 | MemoryTable[Idx].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;\r | |
129 | \r | |
130 | DEBUG ((EFI_D_INFO, "Enabling MMU, setting 0x%08x + %d MB to %a\n",\r | |
131 | SystemMemoryBase, SystemMemoryLength/1024/1024,\r | |
132 | (CacheAttributes == DDR_ATTRIBUTES_CACHED) ? "cacheable" : "uncacheable"));\r | |
133 | \r | |
afdfe8f0 | 134 | ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r |
135 | \r | |
136 | BuildMemoryAllocationHob((EFI_PHYSICAL_ADDRESS)(UINTN)TranslationTableBase, TranslationTableSize, EfiBootServicesData);\r | |
137 | }\r | |
138 | \r | |
139 | \r | |
140 | EFI_STATUS\r | |
141 | EFIAPI\r | |
142 | InitializeCpuPeim (\r | |
143 | IN EFI_PEI_FILE_HANDLE FileHandle,\r | |
144 | IN CONST EFI_PEI_SERVICES **PeiServices\r | |
145 | )\r | |
146 | /*++\r | |
147 | \r | |
148 | Routine Description:\r | |
149 | \r | |
150 | \r | |
151 | \r | |
152 | Arguments:\r | |
153 | \r | |
154 | FileHandle - Handle of the file being invoked.\r | |
155 | PeiServices - Describes the list of possible PEI Services.\r | |
156 | \r | |
157 | Returns:\r | |
158 | \r | |
159 | Status - EFI_SUCCESS if the boot mode could be set\r | |
160 | \r | |
161 | --*/\r | |
162 | {\r | |
163 | // Enable program flow prediction, if supported.\r | |
164 | ArmEnableBranchPrediction ();\r | |
165 | \r | |
149daa61 | 166 | // publish the CPU memory and io spaces sizes\r |
167 | BuildCpuHob (PcdGet8 (PcdPrePiCpuMemorySize), PcdGet8 (PcdPrePiCpuIoSize));\r | |
168 | \r | |
fbcd5cea | 169 | ConfigureMmu();\r |
afdfe8f0 | 170 | \r |
171 | return EFI_SUCCESS;\r | |
172 | }\r |