未验证 提交 81ec3311 编写于 作者: P PMheart 提交者: GitHub

OcSmbiosLib: Report actual MemoryFormFactor in SMBIOS (#225)

closes acidanthera/bugtracker#1537
上级 27b036c4
......@@ -5100,6 +5100,12 @@ be used. Version with macOS specific enhancements can be downloaded from
When \texttt{CustomMemory} is \texttt{false}, this value is automatically set
based on Mac product name.
When \texttt{Automatic} is \texttt{true}, the original value from the the corresponding Mac model will be set if available.
Otherwise, the value from \texttt{OcMacInfoLib} will be set.
When \texttt{Automatic} is \texttt{false}, a user-specified value will be set if available.
Otherwise, the original value from the firmware will be set.
If no value is provided, the fallback value (\texttt{zero}) will be set.
\begin{itemize}
\tightlist
\item
......
......@@ -97,6 +97,10 @@ typedef struct OC_SMBIOS_DATA_ {
CONST UINT16 *MemoryDataWidth;
OC_SMBIOS_MEMORY_DEVICE_DATA *MemoryDevices;
CONST UINT8 *MemoryFormFactor;
//
// Forcibly override MemoryFormFactor on non-Automatic mode when TRUE.
//
BOOLEAN ForceMemoryFormFactor;
CONST UINT16 *MemoryTotalWidth;
CONST UINT8 *MemoryType;
CONST UINT16 *MemoryTypeDetail;
......
......@@ -185,6 +185,11 @@ OcPlatformUpdateSmbios (
ZeroMem (&Data, sizeof (Data));
//
// Forcibly use MemoryFormFactor on non-Automatic mode.
//
Data.ForceMemoryFormFactor = !Config->PlatformInfo.Automatic;
if (MacInfo == NULL) {
//
// Manual mode, read data from SMBIOS.
......
......@@ -105,6 +105,62 @@ SmbiosGetOriginalStructureCount (
return SmbiosGetStructureCount (mOriginalTable, mOriginalTableSize, Type);
}
STATIC
BOOLEAN
SmbiosHasValidOemFormFactor (
IN APPLE_SMBIOS_STRUCTURE_POINTER Original
)
{
return Original.Raw != NULL
&& SMBIOS_ACCESSIBLE (Original, Standard.Type17->FormFactor)
&& Original.Standard.Type17->FormFactor != 0;
}
STATIC
UINT8
SmbiosGetFormFactor (
IN OC_SMBIOS_DATA *Data,
IN APPLE_SMBIOS_STRUCTURE_POINTER Original
)
{
BOOLEAN IsAutomatic;
IsAutomatic = !Data->ForceMemoryFormFactor;
if (IsAutomatic) {
//
// Try to use the original value if valid first.
//
if (SmbiosHasValidOemFormFactor (Original)) {
return Original.Standard.Type17->FormFactor;
}
//
// If not, use the value from database.
//
if (Data->MemoryFormFactor != NULL) {
return *Data->MemoryFormFactor;
}
}
//
// Under non-Automatic mode, simply use the value from config.
//
if (Data->MemoryFormFactor != NULL) {
return *Data->MemoryFormFactor;
}
//
// If the value is not available from config, then try to use the original value.
//
if (SmbiosHasValidOemFormFactor (Original)) {
return Original.Standard.Type17->FormFactor;
}
//
// If not valid at all, fall back to zero.
//
return 0;
}
/** Type 0
@param[in] Table Pointer to location containing the current address within the buffer.
......@@ -755,10 +811,12 @@ PatchMemoryDevice (
{
UINT8 MinLength;
UINT8 StringIndex;
UINT8 FormFactor;
*Handle = OcSmbiosInvalidHandle;
MinLength = sizeof (*Original.Standard.Type17);
StringIndex = 0;
FormFactor = SmbiosGetFormFactor (Data, Original);
if (EFI_ERROR (SmbiosInitialiseStruct (Table, SMBIOS_TYPE_MEMORY_DEVICE, MinLength, Index))) {
return;
......@@ -770,7 +828,7 @@ PatchMemoryDevice (
SMBIOS_OVERRIDE_V (Table, Standard.Type17->TotalWidth, Original, NULL, NULL);
SMBIOS_OVERRIDE_V (Table, Standard.Type17->DataWidth, Original, NULL, NULL);
SMBIOS_OVERRIDE_V (Table, Standard.Type17->Size, Original, NULL, NULL);
SMBIOS_OVERRIDE_V (Table, Standard.Type17->FormFactor, Original, Data->MemoryFormFactor, NULL);
SMBIOS_OVERRIDE_V (Table, Standard.Type17->FormFactor, Original, &FormFactor, NULL);
SMBIOS_OVERRIDE_V (Table, Standard.Type17->DeviceSet, Original, NULL, NULL);
SMBIOS_OVERRIDE_S (Table, Standard.Type17->DeviceLocator, Original, NULL, &StringIndex, NULL);
SMBIOS_OVERRIDE_S (Table, Standard.Type17->BankLocator, Original, NULL, &StringIndex, NULL);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册