diff --git a/Docs/Sample.plist b/Docs/Sample.plist index 46caece0ddb..0d56750475c 100644 --- a/Docs/Sample.plist +++ b/Docs/Sample.plist @@ -1108,6 +1108,8 @@ Address 268435456 + Type + Reserved Comment HD3000: IGPU memory corruption errata Enabled @@ -1115,6 +1117,18 @@ Size 268435456 + + Address + 569344 + Type + RuntimeCode + Comment + Fix black screen on wake from hibernation for Lenovo Thinkpad T490 + Enabled + + Size + 4096 + diff --git a/Docs/SampleCustom.plist b/Docs/SampleCustom.plist index 52d7f066d00..f5109091f56 100644 --- a/Docs/SampleCustom.plist +++ b/Docs/SampleCustom.plist @@ -1211,6 +1211,8 @@ Address 268435456 + Type + Reserved Comment HD3000: IGPU memory corruption errata Enabled diff --git a/Include/Acidanthera/Library/OcConfigurationLib.h b/Include/Acidanthera/Library/OcConfigurationLib.h index c0b5e8082f2..96074107800 100644 --- a/Include/Acidanthera/Library/OcConfigurationLib.h +++ b/Include/Acidanthera/Library/OcConfigurationLib.h @@ -601,6 +601,7 @@ typedef enum { _(UINT64 , Address , , 0 , () ) \ _(UINT64 , Size , , 0 , () ) \ _(BOOLEAN , Enabled , , FALSE , () ) \ + _(OC_STRING , Type , , OC_STRING_CONSTR ("Reserved", _, __), OC_DESTR (OC_STRING) ) \ _(OC_STRING , Comment , , OC_STRING_CONSTR ("", _, __), OC_DESTR (OC_STRING) ) OC_DECLARE (OC_UEFI_RSVD_ENTRY) diff --git a/Include/Acidanthera/Library/OcMemoryLib.h b/Include/Acidanthera/Library/OcMemoryLib.h index c425fa7003c..5ab4cbd10a9 100644 --- a/Include/Acidanthera/Library/OcMemoryLib.h +++ b/Include/Acidanthera/Library/OcMemoryLib.h @@ -50,6 +50,76 @@ **/ #define OC_DEFAULT_MEMORY_MAP_SIZE (EFI_PAGE_SIZE*3) +#define OC_MEMORY_TYPE_DESC_COUNT 16 + +typedef struct { + CHAR8 *Name; + EFI_MEMORY_TYPE Type; +} OC_MEMORY_TYPE_DESC; + +STATIC OC_MEMORY_TYPE_DESC OcMemoryTypeString [OC_MEMORY_TYPE_DESC_COUNT] = { + { + "Reserved", + EfiReservedMemoryType + }, + { + "LoaderCode", + EfiLoaderCode + }, + { + "LoaderData", + EfiLoaderData + }, + { + "BootServiceCode", + EfiBootServicesCode + }, + { + "BootServiceData", + EfiBootServicesData + }, + { + "RuntimeCode", + EfiRuntimeServicesCode + }, + { + "RuntimeData", + EfiRuntimeServicesData + }, + { + "Available", + EfiConventionalMemory + }, + { + "Persistent", + EfiPersistentMemory + }, + { + "UnusableMemory", + EfiUnusableMemory + }, + { + "ACPIReclaimMemory", + EfiACPIReclaimMemory + }, + { + "ACPIMemoryNVS", + EfiACPIMemoryNVS + }, + { + "MemoryMappedIO", + EfiMemoryMappedIO + }, + { + "MemoryMappedIOPortSpace", + EfiMemoryMappedIOPortSpace + }, + { + "PalCode", + EfiPalCode + } +}; + /** Lock the legacy region specified to enable modification. @@ -322,7 +392,7 @@ OcGetMemoryAttributes ( Refresh memory attributes entry containing the specified address. @param[in] Address Address contained in the updated entry. - @param[in] GetMemoryMap + @param[in] GetMemoryMap @retval EFI_SUCCESS on success. @retval EFI_NOT_FOUND no entry contains the specified address. @@ -395,6 +465,22 @@ OcGetPhysicalAddress ( OUT EFI_PHYSICAL_ADDRESS *PhysicalAddr ); +/** + Return EFI memory type for given type description + + @param[in] MemoryTypeDesc Memory type string representation. + @param[out] MemoryType EFI memory type to return. + + @retval EFI_NOT_FOUND on unsuccessful lookup. + @retval EFI_INVALID_PARAMETER on wrong passed agruments. + @retval EFI_SUCCESS on successful lookup. +**/ +EFI_STATUS +OcDescToMemoryType ( + IN CHAR8 *MemoryTypeDesc, + OUT EFI_MEMORY_TYPE *MemoryType + ); + /** Virtual memory context **/ diff --git a/Library/OcConfigurationLib/OcConfigurationLib.c b/Library/OcConfigurationLib/OcConfigurationLib.c index 48cd553babf..d2e6e6de100 100644 --- a/Library/OcConfigurationLib/OcConfigurationLib.c +++ b/Library/OcConfigurationLib/OcConfigurationLib.c @@ -664,6 +664,7 @@ mUefiReservedMemoryEntrySchema[] = { OC_SCHEMA_STRING_IN ("Comment", OC_UEFI_RSVD_ENTRY, Comment), OC_SCHEMA_BOOLEAN_IN ("Enabled", OC_UEFI_RSVD_ENTRY, Enabled), OC_SCHEMA_INTEGER_IN ("Size", OC_UEFI_RSVD_ENTRY, Size), + OC_SCHEMA_STRING_IN ("Type", OC_UEFI_RSVD_ENTRY, Type), }; STATIC diff --git a/Library/OcMemoryLib/VirtualMemory.c b/Library/OcMemoryLib/VirtualMemory.c index 60484c12009..f8bec59ceff 100755 --- a/Library/OcMemoryLib/VirtualMemory.c +++ b/Library/OcMemoryLib/VirtualMemory.c @@ -20,6 +20,32 @@ #include #include + +EFI_STATUS +OcDescToMemoryType ( + IN CHAR8 *MemoryTypeDesc, + OUT EFI_MEMORY_TYPE *MemoryType + ) +{ + UINTN Index; + EFI_STATUS Status = EFI_INVALID_PARAMETER; + + if (MemoryTypeDesc != NULL && MemoryType !=NULL) { + for (Index = 0; Index < OC_MEMORY_TYPE_DESC_COUNT; Index++) { + if (AsciiStrCmp (MemoryTypeDesc, OcMemoryTypeString[Index].Name) == 0) { + Status = EFI_SUCCESS; + *MemoryType=OcMemoryTypeString[Index].Type; + break; + } + } + if (EFI_ERROR (Status)) { + Status = EFI_NOT_FOUND; + } + } + + return Status; +} + PAGE_MAP_AND_DIRECTORY_POINTER * OcGetCurrentPageTable ( OUT UINTN *Flags OPTIONAL diff --git a/OpenCorePkg.dsc b/OpenCorePkg.dsc index 6a901d9879b..9e622965806 100755 --- a/OpenCorePkg.dsc +++ b/OpenCorePkg.dsc @@ -3,13 +3,13 @@ # Copyright (C) 2018, Download-Fritz. All rights reserved.
# # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -# +# # 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -# +# # 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. -# +# # 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. -# +# # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # ## diff --git a/Platform/OpenCore/OpenCoreMisc.c b/Platform/OpenCore/OpenCoreMisc.c index c5ed8345b6c..a281844eb7a 100644 --- a/Platform/OpenCore/OpenCoreMisc.c +++ b/Platform/OpenCore/OpenCoreMisc.c @@ -140,7 +140,7 @@ ProduceDebugReport ( Status = AcpiDumpTables (SubReport); SubReport->Close (SubReport); } - DEBUG ((DEBUG_INFO, "OC: ACPI dumping - %r\n", Status)); + DEBUG ((DEBUG_INFO, "OC: ACPI dumping - %r\n", Status)); Status = SafeFileOpen ( SysReport, @@ -154,7 +154,7 @@ ProduceDebugReport ( Status = OcSmbiosDump (SubReport); SubReport->Close (SubReport); } - DEBUG ((DEBUG_INFO, "OC: ACPI dumping - %r\n", Status)); + DEBUG ((DEBUG_INFO, "OC: ACPI dumping - %r\n", Status)); SysReport->Close (SysReport); Fs->Close (Fs); diff --git a/Platform/OpenCore/OpenCoreUefi.c b/Platform/OpenCore/OpenCoreUefi.c index 5f53341ba1a..d3d59be1097 100644 --- a/Platform/OpenCore/OpenCoreUefi.c +++ b/Platform/OpenCore/OpenCoreUefi.c @@ -42,6 +42,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include #include #include +#include #include #include #include @@ -498,6 +499,55 @@ OcLoadBooterUefiSupport ( OcAbcInitialize (&AbcSettings); } + +VOID +OcReserveMemory ( + IN OC_GLOBAL_CONFIG *Config + ) +{ + EFI_STATUS Status; + UINTN Index; + EFI_PHYSICAL_ADDRESS ReservedAddress; + EFI_MEMORY_TYPE RsvdMemoryType; + CHAR8 *RsvdMemoryTypeStr; + + for (Index = 0; Index < Config->Uefi.ReservedMemory.Count; ++Index) { + if (!Config->Uefi.ReservedMemory.Values[Index]->Enabled) { + continue; + } + + if ((Config->Uefi.ReservedMemory.Values[Index]->Address & (BASE_4KB - 1)) != 0 + || (Config->Uefi.ReservedMemory.Values[Index]->Size & (BASE_4KB - 1)) != 0) { + Status = EFI_INVALID_PARAMETER; + } else { + RsvdMemoryTypeStr = OC_BLOB_GET (&Config->Uefi.ReservedMemory.Values[Index]->Type); + + Status = OcDescToMemoryType (RsvdMemoryTypeStr, &RsvdMemoryType); + if (EFI_ERROR (Status)){ + DEBUG ((DEBUG_INFO, "OC: Invalid ReservedMemory Type: %a\n", RsvdMemoryTypeStr)); + RsvdMemoryType = EfiReservedMemoryType; + } + + ReservedAddress = Config->Uefi.ReservedMemory.Values[Index]->Address; + Status = gBS->AllocatePages ( + AllocateAddress, + RsvdMemoryType, + (UINTN) EFI_SIZE_TO_PAGES (Config->Uefi.ReservedMemory.Values[Index]->Size), + &ReservedAddress + ); + } + + DEBUG (( + DEBUG_INFO, + "OC: Reserving region %Lx of %Lx size - %r\n", + Config->Uefi.ReservedMemory.Values[Index]->Address, + Config->Uefi.ReservedMemory.Values[Index]->Size, + Status + )); + } +} + + VOID OcLoadUefiSupport ( IN OC_STORAGE_CONTEXT *Storage, @@ -505,14 +555,11 @@ OcLoadUefiSupport ( IN OC_CPU_INFO *CpuInfo ) { - EFI_STATUS Status; EFI_HANDLE *DriversToConnect; - UINTN Index; UINT16 *BootOrder; UINTN BootOrderCount; BOOLEAN BootOrderChanged; EFI_EVENT Event; - EFI_PHYSICAL_ADDRESS ReservedAddress; OcReinstallProtocols (Config); @@ -584,32 +631,10 @@ OcLoadUefiSupport ( OcMiscUefiQuirksLoaded (Config); - for (Index = 0; Index < Config->Uefi.ReservedMemory.Count; ++Index) { - if (!Config->Uefi.ReservedMemory.Values[Index]->Enabled) { - continue; - } - - if ((Config->Uefi.ReservedMemory.Values[Index]->Address & (BASE_4KB - 1)) != 0 - || (Config->Uefi.ReservedMemory.Values[Index]->Size & (BASE_4KB - 1)) != 0) { - Status = EFI_INVALID_PARAMETER; - } else { - ReservedAddress = Config->Uefi.ReservedMemory.Values[Index]->Address; - Status = gBS->AllocatePages ( - AllocateAddress, - EfiReservedMemoryType, - (UINTN) EFI_SIZE_TO_PAGES (Config->Uefi.ReservedMemory.Values[Index]->Size), - &ReservedAddress - ); - } - - DEBUG (( - DEBUG_INFO, - "OC: Reserving region %Lx of %Lx size - %r\n", - Config->Uefi.ReservedMemory.Values[Index]->Address, - Config->Uefi.ReservedMemory.Values[Index]->Size, - Status - )); - } + // + // Reserve requested memory regions + // + OcReserveMemory (Config); if (Config->Uefi.ConnectDrivers) { OcLoadDrivers (Storage, Config, &DriversToConnect);