]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ArmPkg/CpuPei: Get the System Memory from the Resource Memory HOB
authoroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 20 Jun 2011 21:32:46 +0000 (21:32 +0000)
committeroliviermartin <oliviermartin@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 20 Jun 2011 21:32:46 +0000 (21:32 +0000)
Declare the system memory provided by the first Resource Memory HOB
as cached memory to the MMU.
All the remaining memory space is declared as Device Memory.

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@11861 6f19259b-4bc3-4df7-8a09-765794883524

ArmPkg/Drivers/CpuPei/CpuPei.c
ArmPkg/Drivers/CpuPei/CpuPei.inf

index 5e26244354ecb24a5e14792720d6d4ea77d6729d..d06ecd743eb62d8fe2069577253c06e1d97b1b16 100755 (executable)
@@ -1,6 +1,7 @@
 /**@file\r
 \r
 Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2011 Hewlett Packard Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials                          \r
 are licensed and made available under the terms and conditions of the BSD License         \r
 which accompanies this distribution.  The full text of the license may be found at        \r
@@ -45,11 +46,40 @@ Abstract:
 #define DDR_ATTRIBUTES_CACHED                ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK\r
 #define DDR_ATTRIBUTES_UNCACHED              ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED\r
 \r
+EFI_STATUS\r
+FindMainMemory(\r
+  OUT UINT32    *PhysicalBase,\r
+  OUT UINT32    *Length\r
+  )\r
+{\r
+  EFI_PEI_HOB_POINTERS      NextHob;\r
+\r
+  // look at the resource descriptor hobs, choose the first system memory one\r
+  NextHob.Raw = GetHobList ();\r
+  while ((NextHob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, NextHob.Raw)) != NULL) {\r
+    if(NextHob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY)\r
+    {\r
+      *PhysicalBase = (UINT32)NextHob.ResourceDescriptor->PhysicalStart;\r
+      *Length = (UINT32)NextHob.ResourceDescriptor->ResourceLength;\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    NextHob.Raw = GET_NEXT_HOB (NextHob);\r
+  }\r
+\r
+  return EFI_NOT_FOUND;\r
+}\r
+\r
 VOID\r
-JamArmMmuConfig ( VOID )\r
+ConfigureMmu ( VOID )\r
 {\r
+  EFI_STATUS                 Status;\r
+  UINTN                         Idx;\r
   UINT32                        CacheAttributes;\r
-  ARM_MEMORY_REGION_DESCRIPTOR  MemoryTable[3];\r
+  UINT32                        SystemMemoryBase;\r
+  UINT32                        SystemMemoryLength;\r
+  UINT32                        SystemMemoryLastAddress;\r
+  ARM_MEMORY_REGION_DESCRIPTOR  MemoryTable[4];\r
   VOID                          *TranslationTableBase;\r
   UINTN                         TranslationTableSize;\r
 \r
@@ -59,24 +89,48 @@ JamArmMmuConfig ( VOID )
     CacheAttributes = DDR_ATTRIBUTES_UNCACHED;\r
   }\r
 \r
-  // DDR\r
-  MemoryTable[0].PhysicalBase = 0;\r
-  MemoryTable[0].VirtualBase  = 0;\r
-  MemoryTable[0].Length       = 0x10000000;\r
-  MemoryTable[0].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;\r
+  Idx = 0;\r
+  \r
+  // Main Memory\r
+  Status = FindMainMemory (&SystemMemoryBase, &SystemMemoryLength);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  SystemMemoryLastAddress = SystemMemoryBase + (SystemMemoryLength-1);\r
+\r
+  // if system memory does not begin at 0\r
+  if(SystemMemoryBase > 0) {\r
+    MemoryTable[Idx].PhysicalBase = 0;\r
+    MemoryTable[Idx].VirtualBase  = 0;\r
+    MemoryTable[Idx].Length       = SystemMemoryBase;\r
+    MemoryTable[Idx].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
+    Idx++;\r
+  }\r
 \r
-  // SOC Registers. L3 interconnects\r
-  MemoryTable[1].PhysicalBase = 0x10000000;\r
-  MemoryTable[1].VirtualBase  = 0x10000000;\r
-  MemoryTable[1].Length       = 0xF0000000;\r
-  MemoryTable[1].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
+  MemoryTable[Idx].PhysicalBase = SystemMemoryBase;\r
+  MemoryTable[Idx].VirtualBase  = SystemMemoryBase;\r
+  MemoryTable[Idx].Length       = SystemMemoryLength;\r
+  MemoryTable[Idx].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)CacheAttributes;\r
+  Idx++;\r
+\r
+  // if system memory does not go to the last address (0xFFFFFFFF)\r
+  if( SystemMemoryLastAddress < MAX_ADDRESS ) {\r
+    MemoryTable[Idx].PhysicalBase = SystemMemoryLastAddress + 1;\r
+    MemoryTable[Idx].VirtualBase  = MemoryTable[Idx].PhysicalBase;\r
+    MemoryTable[Idx].Length       = MAX_ADDRESS - MemoryTable[Idx].PhysicalBase + 1;\r
+    MemoryTable[Idx].Attributes   = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;\r
+    Idx++;\r
+  }\r
 \r
   // End of Table\r
-  MemoryTable[2].PhysicalBase = 0;\r
-  MemoryTable[2].VirtualBase  = 0;\r
-  MemoryTable[2].Length       = 0;\r
-  MemoryTable[2].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)0;\r
-  \r
+  MemoryTable[Idx].PhysicalBase = 0;\r
+  MemoryTable[Idx].VirtualBase  = 0;\r
+  MemoryTable[Idx].Length       = 0;\r
+  MemoryTable[Idx].Attributes   = (ARM_MEMORY_REGION_ATTRIBUTES)0;\r
+   \r
+  DEBUG ((EFI_D_INFO, "Enabling MMU, setting 0x%08x + %d MB to %a\n",\r
+    SystemMemoryBase, SystemMemoryLength/1024/1024,\r
+    (CacheAttributes == DDR_ATTRIBUTES_CACHED) ? "cacheable" : "uncacheable"));\r
+\r
   ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
   \r
   BuildMemoryAllocationHob((EFI_PHYSICAL_ADDRESS)(UINTN)TranslationTableBase, TranslationTableSize, EfiBootServicesData);\r
@@ -109,7 +163,7 @@ Returns:
   // Enable program flow prediction, if supported.\r
   ArmEnableBranchPrediction ();\r
 \r
-  JamArmMmuConfig();\r
+  ConfigureMmu();\r
 \r
   return EFI_SUCCESS;\r
 }\r
index 3ed8ef9a6c5c4d66486fa7b321b4a2a3859abdc8..4237d365f90b72b3a8c14466e873de9ff5795fce 100755 (executable)
@@ -26,7 +26,7 @@
 #\r
 # The following information is for reference only and not required by the build tools.\r
 #\r
-#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC\r
+#  VALID_ARCHITECTURES           = ARM\r
 #\r
 \r
 [Sources]\r