)\r
{\r
EFI_STATUS Status;\r
+ UINT64 ChunkLength;\r
+\r
+ if (Length == 0) {\r
+ return EFI_SUCCESS;\r
+ }\r
\r
//\r
// Ignore invocations that only modify permission bits\r
return EFI_SUCCESS;\r
}\r
\r
- if(((BaseAddress & 0xFFFFF) == 0) && ((Length & 0xFFFFF) == 0)) {\r
- // Is the base and length a multiple of 1 MB?\r
- DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(): MMU section 0x%x length 0x%x to %lx\n", (UINTN)BaseAddress, (UINTN)Length, Attributes));\r
- Status = UpdateSectionEntries (BaseAddress, Length, Attributes, VirtualMask);\r
- } else {\r
- // Base and/or length is not a multiple of 1 MB\r
- DEBUG ((EFI_D_PAGE, "SetMemoryAttributes(): MMU page 0x%x length 0x%x to %lx\n", (UINTN)BaseAddress, (UINTN)Length, Attributes));\r
- Status = UpdatePageEntries (BaseAddress, Length, Attributes, VirtualMask);\r
+ while (Length > 0) {\r
+ if ((BaseAddress % TT_DESCRIPTOR_SECTION_SIZE == 0) &&\r
+ Length >= TT_DESCRIPTOR_SECTION_SIZE) {\r
+\r
+ ChunkLength = Length - Length % TT_DESCRIPTOR_SECTION_SIZE;\r
+\r
+ DEBUG ((DEBUG_PAGE,\r
+ "SetMemoryAttributes(): MMU section 0x%lx length 0x%lx to %lx\n",\r
+ BaseAddress, ChunkLength, Attributes));\r
+\r
+ Status = UpdateSectionEntries (BaseAddress, ChunkLength, Attributes,\r
+ VirtualMask);\r
+ } else {\r
+\r
+ //\r
+ // Process page by page until the next section boundary, but only if\r
+ // we have more than a section's worth of area to deal with after that.\r
+ //\r
+ ChunkLength = TT_DESCRIPTOR_SECTION_SIZE -\r
+ (BaseAddress % TT_DESCRIPTOR_SECTION_SIZE);\r
+ if (ChunkLength + TT_DESCRIPTOR_SECTION_SIZE > Length) {\r
+ ChunkLength = Length;\r
+ }\r
+\r
+ DEBUG ((DEBUG_PAGE,\r
+ "SetMemoryAttributes(): MMU page 0x%lx length 0x%lx to %lx\n",\r
+ BaseAddress, ChunkLength, Attributes));\r
+\r
+ Status = UpdatePageEntries (BaseAddress, ChunkLength, Attributes,\r
+ VirtualMask);\r
+ }\r
+\r
+ if (EFI_ERROR (Status)) {\r
+ break;\r
+ }\r
+\r
+ BaseAddress += ChunkLength;\r
+ Length -= ChunkLength;\r
}\r
\r
// Flush d-cache so descriptors make it back to uncached memory for subsequent table walks\r