\r
Copyright (c) 2006, Intel Corporation. All rights reserved.<BR>\r
Copyright (c) 2011 Hewlett Packard Corporation. All rights reserved.<BR>\r
-Copyright (c) 2011, ARM Limited. All rights reserved.<BR>\r
+Copyright (c) 2011-2013, ARM Limited. All rights reserved.<BR>\r
\r
This program and the accompanying materials \r
are licensed and made available under the terms and conditions of the BSD License \r
SystemMemoryBase, SystemMemoryLength/1024/1024,\r
(CacheAttributes == DDR_ATTRIBUTES_CACHED) ? "cacheable" : "uncacheable"));\r
\r
- ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
+ Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU (error code: %r)\n", Status));\r
+ }\r
\r
BuildMemoryAllocationHob((EFI_PHYSICAL_ADDRESS)(UINTN)TranslationTableBase, TranslationTableSize, EfiBootServicesData);\r
}\r
VOID\r
);\r
\r
-VOID\r
+RETURN_STATUS\r
EFIAPI\r
ArmConfigureMmu (\r
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,\r
- OUT VOID **TranslationTableBase OPTIONAL,\r
+ OUT VOID **TranslationTableBase OPTIONAL,\r
OUT UINTN *TranslationTableSize OPTIONAL\r
);\r
\r
/** @file\r
\r
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+ Copyright (c) 2011 - 2013, ARM Limited. All rights reserved.\r
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
}\r
}\r
\r
-VOID\r
+RETURN_STATUS\r
EFIAPI\r
ArmConfigureMmu (\r
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,\r
- OUT VOID **TranslationTableBase OPTIONAL,\r
- OUT UINTN *TranslationTableSize OPTIONAL\r
+ OUT VOID **TranslationTableBase OPTIONAL,\r
+ OUT UINTN *TranslationTableSize OPTIONAL\r
)\r
{\r
VOID *TranslationTable;\r
\r
// Allocate pages for translation table.\r
- TranslationTable = AllocatePages(EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_SIZE + TRANSLATION_TABLE_ALIGNMENT));\r
+ TranslationTable = AllocatePages (EFI_SIZE_TO_PAGES (TRANSLATION_TABLE_SIZE + TRANSLATION_TABLE_ALIGNMENT));\r
+ if (TranslationTable == NULL) {\r
+ return RETURN_OUT_OF_RESOURCES;\r
+ }\r
TranslationTable = (VOID *)(((UINTN)TranslationTable + TRANSLATION_TABLE_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_ALIGNMENT_MASK);\r
\r
if (TranslationTableBase != NULL) {\r
\r
ArmEnableInstructionCache();\r
ArmEnableDataCache();\r
- ArmEnableMmu(); \r
-}\r
-\r
-\r
-\r
+ ArmEnableMmu();\r
\r
+ return RETURN_SUCCESS;\r
+}\r
/** @file\r
\r
Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>\r
+ Copyright (c) 2011 - 2013, ARM Limited. All rights reserved.\r
\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
}\r
}\r
\r
-VOID\r
+RETURN_STATUS\r
EFIAPI\r
ArmConfigureMmu (\r
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,\r
- OUT VOID **TranslationTableBase OPTIONAL,\r
- OUT UINTN *TranslationTableSize OPTIONAL\r
+ OUT VOID **TranslationTableBase OPTIONAL,\r
+ OUT UINTN *TranslationTableSize OPTIONAL\r
)\r
{\r
VOID *TranslationTable;\r
\r
// Allocate pages for translation table.\r
- TranslationTable = AllocatePages(EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_SIZE + TRANSLATION_TABLE_ALIGNMENT));\r
+ TranslationTable = AllocatePages (EFI_SIZE_TO_PAGES (TRANSLATION_TABLE_SIZE + TRANSLATION_TABLE_ALIGNMENT));\r
+ if (TranslationTable == NULL) {\r
+ return RETURN_OUT_OF_RESOURCES;\r
+ }\r
TranslationTable = (VOID *)(((UINTN)TranslationTable + TRANSLATION_TABLE_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_ALIGNMENT_MASK);\r
\r
if (TranslationTableBase != NULL) {\r
ArmEnableInstructionCache();\r
ArmEnableDataCache();\r
ArmEnableMmu();\r
-}\r
-\r
-\r
\r
+ return RETURN_SUCCESS;\r
+}\r
/** @file\r
* File managing the MMU for ARMv7 architecture\r
*\r
-* Copyright (c) 2011-2012, ARM Limited. All rights reserved.\r
+* Copyright (c) 2011-2013, ARM Limited. All rights reserved.\r
* \r
* This program and the accompanying materials \r
* are licensed and made available under the terms and conditions of the BSD License \r
}\r
}\r
\r
-VOID\r
+RETURN_STATUS\r
EFIAPI\r
ArmConfigureMmu (\r
IN ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable,\r
- OUT VOID **TranslationTableBase OPTIONAL,\r
- OUT UINTN *TranslationTableSize OPTIONAL\r
+ OUT VOID **TranslationTableBase OPTIONAL,\r
+ OUT UINTN *TranslationTableSize OPTIONAL\r
)\r
{\r
- UINTN TranslationTable;\r
+ VOID* TranslationTable;\r
ARM_MEMORY_REGION_ATTRIBUTES TranslationTableAttribute;\r
UINT32 TTBRAttributes;\r
\r
// Allocate pages for translation table.\r
- TranslationTable = (UINTN)AllocatePages (EFI_SIZE_TO_PAGES(TRANSLATION_TABLE_SECTION_SIZE + TRANSLATION_TABLE_SECTION_ALIGNMENT));\r
- TranslationTable = ((UINTN)TranslationTable + TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK;\r
+ TranslationTable = AllocatePages (EFI_SIZE_TO_PAGES (TRANSLATION_TABLE_SECTION_SIZE + TRANSLATION_TABLE_SECTION_ALIGNMENT));\r
+ if (TranslationTable == NULL) {\r
+ return RETURN_OUT_OF_RESOURCES;\r
+ }\r
+ TranslationTable = (VOID*)(((UINTN)TranslationTable + TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK);\r
\r
if (TranslationTableBase != NULL) {\r
- *TranslationTableBase = (VOID *)TranslationTable;\r
+ *TranslationTableBase = TranslationTable;\r
}\r
\r
if (TranslationTableSize != NULL) {\r
*TranslationTableSize = TRANSLATION_TABLE_SECTION_SIZE;\r
}\r
\r
- ZeroMem ((VOID *)TranslationTable, TRANSLATION_TABLE_SECTION_SIZE);\r
+ ZeroMem (TranslationTable, TRANSLATION_TABLE_SECTION_SIZE);\r
\r
ArmCleanInvalidateDataCache ();\r
ArmInvalidateInstructionCache ();\r
ArmCleanInvalidateDataCache ();\r
ArmInvalidateInstructionCache ();\r
\r
- TranslationTableAttribute = (ARM_MEMORY_REGION_ATTRIBUTES)0;\r
+ // By default, mark the translation table as belonging to a uncached region\r
+ TranslationTableAttribute = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;\r
while (MemoryTable->Length != 0) {\r
// Find the memory attribute for the Translation Table\r
- if ((TranslationTable >= MemoryTable->PhysicalBase) && (TranslationTable <= MemoryTable->PhysicalBase - 1 + MemoryTable->Length)) {\r
+ if (((UINTN)TranslationTable >= MemoryTable->PhysicalBase) && ((UINTN)TranslationTable <= MemoryTable->PhysicalBase - 1 + MemoryTable->Length)) {\r
TranslationTableAttribute = MemoryTable->Attributes;\r
}\r
\r
- FillTranslationTable ((VOID *)TranslationTable, MemoryTable);\r
+ FillTranslationTable (TranslationTable, MemoryTable);\r
MemoryTable++;\r
}\r
\r
(TranslationTableAttribute == ARM_MEMORY_REGION_ATTRIBUTE_NONSECURE_WRITE_THROUGH)) {\r
TTBRAttributes = TTBR_WRITE_THROUGH_NO_ALLOC;\r
} else {\r
- //TODO: We should raise an error here\r
- TTBRAttributes = TTBR_NON_CACHEABLE;\r
+ ASSERT (0); // No support has been found for the attributes of the memory region that the translation table belongs to.\r
+ return RETURN_UNSUPPORTED;\r
}\r
\r
- ArmSetTTBR0 ((VOID *)(UINTN)((TranslationTable & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) | (TTBRAttributes & 0x7F)));\r
+ ArmSetTTBR0 ((VOID *)(UINTN)(((UINTN)TranslationTable & ~TRANSLATION_TABLE_SECTION_ALIGNMENT_MASK) | (TTBRAttributes & 0x7F)));\r
\r
ArmSetDomainAccessControl (DOMAIN_ACCESS_CONTROL_NONE(15) |\r
DOMAIN_ACCESS_CONTROL_NONE(14) |\r
ArmEnableInstructionCache();\r
ArmEnableDataCache();\r
ArmEnableMmu();\r
+ return RETURN_SUCCESS;\r
}\r
ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;\r
VOID *TranslationTableBase;\r
UINTN TranslationTableSize;\r
+ RETURN_STATUS Status;\r
\r
// Get Virtual Memory Map from the Platform Library\r
ArmPlatformGetVirtualMemoryMap (&MemoryTable);\r
\r
//Note: Because we called PeiServicesInstallPeiMemory() before to call InitMmu() the MMU Page Table resides in\r
// DRAM (even at the top of DRAM as it is the first permanent memory allocation)\r
- ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
+ Status = ArmConfigureMmu (MemoryTable, &TranslationTableBase, &TranslationTableSize);\r
+ if (EFI_ERROR (Status)) {\r
+ DEBUG ((EFI_D_ERROR, "Error: Failed to enable MMU\n"));\r
+ }\r
}\r
\r
/*++\r