2019-09-03 11:58:42 +02:00
/**
smbios . c
original idea of SMBIOS patching by mackerintel
implementation for UEFI smbios table patching
Slice 2011.
portion copyright Intel
Copyright ( c ) 2009 - 2010 , Intel Corporation . All rights reserved . < BR >
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution . The full text of the license may be found at
http : //opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN " AS IS " BASIS ,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND , EITHER EXPRESS OR IMPLIED .
Module Name :
SmbiosGen . c
* */
2021-04-28 20:30:34 +02:00
# define DONT_DEFINE_GLOBALS
2020-08-17 21:40:52 +02:00
# include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
2021-02-06 18:16:46 +01:00
# include <Efi.h>
2020-04-16 09:48:13 +02:00
# include "smbios.h"
2020-04-16 09:15:26 +02:00
# include "platformdata.h"
# include "AcpiPatcher.h"
2020-09-23 15:47:47 +02:00
# include "guid.h"
2021-04-28 20:30:34 +02:00
# include "../Platform/CloverVersion.h"
2020-04-10 16:35:24 +02:00
2019-09-03 11:58:42 +02:00
# ifndef DEBUG_ALL
# define DEBUG_SMBIOS 1
# else
# define DEBUG_SMBIOS DEBUG_ALL
# endif
# if DEBUG_SMBIOS == 0
# define DBG(...)
# else
# define DBG(...) DebugLog(DEBUG_SMBIOS, __VA_ARGS__)
# endif
2020-04-16 09:48:13 +02:00
# define REMAP_SMBIOS_TABLE_GUID { 0xeb9d2d35, 0x2d88, 0x11d3, {0x9a, 0x16, 0x0, 0x90, 0x27, 0x3f, 0xc1, 0x4d } }
2019-09-03 11:58:42 +02:00
# define MAX_OEM_STRING 256
2020-04-16 11:09:22 +02:00
# define ROUND_PAGE(x) ((((unsigned)(x)) + EFI_PAGE_SIZE - 1) & ~(EFI_PAGE_SIZE - 1))
2022-04-26 00:55:56 +02:00
EFI_GUID gTableGuidArray [ ] = { gEfiSmbiosTableGuid , gEfiSmbios3TableGuid } ;
2020-04-09 19:01:23 +02:00
2021-04-08 17:07:05 +02:00
constexpr LString8 unknown = " unknown " _XS8 ;
2021-04-28 20:30:34 +02:00
SmbiosDiscoveredSettings g_SmbiosDiscoveredSettings ;
SmbiosInjectedSettings g_SmbiosInjectedSettings ;
const RAM_SLOT_INFO nullRAM_SLOT_INFO ;
const SLOT_DEVICE nullSLOT_DEVICE ;
2019-09-03 11:58:42 +02:00
//
// syscl: implement Dell truncate fix
// remap EFI_SMBIOS_TABLE_1 to new guid to fix Dell
// SMBIOS Table 1 truncate issue credit David Passmore
//
EFI_GUID gRemapEfiSmbiosTableGuid = REMAP_SMBIOS_TABLE_GUID ;
//EFI_PHYSICAL_ADDRESS *smbiosTable;
2020-10-03 19:02:31 +02:00
void * Smbios ; //pointer to SMBIOS data
2019-09-03 11:58:42 +02:00
SMBIOS_TABLE_ENTRY_POINT * EntryPoint ; //SmbiosEps original
SMBIOS_TABLE_ENTRY_POINT * SmbiosEpsNew ; //new SmbiosEps
//for patching
APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTable ;
APPLE_SMBIOS_STRUCTURE_POINTER newSmbiosTable ;
UINT16 NumberOfRecords ;
UINT16 MaxStructureSize ;
UINT8 * Current ; //pointer to the current end of tables
EFI_SMBIOS_TABLE_HEADER * Record ;
EFI_SMBIOS_HANDLE Handle ;
EFI_SMBIOS_TYPE Type ;
UINTN stringNumber ;
UINTN TableSize ;
UINT16 CoreCache = 0 ;
UINT16 L1 , L2 , L3 ;
UINT32 MaxMemory = 0 ;
UINT32 mTotalSystemMemory ;
UINT64 gTotalMemory ;
UINT16 mHandle3 ;
UINT16 mHandle16 = 0x1000 ;
2021-10-02 19:44:16 +02:00
//UINT16 mHandle17[MAX_RAM_SLOTS];
2019-09-03 11:58:42 +02:00
UINT16 mHandle19 ;
2021-10-02 19:44:16 +02:00
//UINT64 mInstalled[MAX_RAM_SLOTS];
//UINT64 mEnabled[MAX_RAM_SLOTS];
2021-09-28 15:54:31 +02:00
XBool gMobile ;
2019-09-03 11:58:42 +02:00
UINT8 gBootStatus ;
2021-09-28 15:54:31 +02:00
XBool Once ;
2019-09-03 11:58:42 +02:00
MEM_STRUCTURE gRAM ;
# define MAX_HANDLE 0xFEFF
# define SMBIOS_PTR SIGNATURE_32('_','S','M','_')
# define MAX_TABLE_SIZE 512
2022-08-12 21:09:53 +02:00
//#define smbios_offsetof(s,m) ( (SMBIOS_TABLE_STRING) ((UINT8*)&((s*)0)->m - (UINT8*)0))
# ifndef smbios_offsetof
# define smbios_offsetof(TYPE, MEMBER) ((SMBIOS_TABLE_STRING)((size_t) &((TYPE *)0)->MEMBER))
# endif
2019-09-03 11:58:42 +02:00
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE0_STR_IDX [ ] = {
smbios_offsetof ( SMBIOS_TABLE_TYPE0 , Vendor ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE0 , BiosVersion ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE0 , BiosReleaseDate ) ,
0x00
} ; // offsets of structures that values are strings for type 0 Bios
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE1_STR_IDX [ ] = {
smbios_offsetof ( SMBIOS_TABLE_TYPE1 , Manufacturer ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE1 , ProductName ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE1 , Version ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE1 , SerialNumber ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE1 , SKUNumber ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE1 , Family ) ,
0x00
} ; // offsets of structures that values are strings for type 1 System
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE2_STR_IDX [ ] = {
smbios_offsetof ( SMBIOS_TABLE_TYPE2 , Manufacturer ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE2 , ProductName ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE2 , Version ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE2 , SerialNumber ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE2 , AssetTag ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE2 , LocationInChassis ) ,
0x00
} ; // offsets of structures that values are strings for type 2 BaseBoard
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE3_STR_IDX [ ] = {
smbios_offsetof ( SMBIOS_TABLE_TYPE3 , Manufacturer ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE3 , Version ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE3 , SerialNumber ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE3 , AssetTag ) ,
0x00
} ; // offsets of structures that values are strings for type 3 Chassis
SMBIOS_TABLE_STRING SMBIOS_TABLE_TYPE4_STR_IDX [ ] = {
smbios_offsetof ( SMBIOS_TABLE_TYPE4 , Socket ) ,
2021-09-23 12:36:41 +02:00
smbios_offsetof ( SMBIOS_TABLE_TYPE4 , ProcessorManufacturer ) ,
2019-09-03 11:58:42 +02:00
smbios_offsetof ( SMBIOS_TABLE_TYPE4 , ProcessorVersion ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE4 , SerialNumber ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE4 , AssetTag ) ,
smbios_offsetof ( SMBIOS_TABLE_TYPE4 , PartNumber ) ,
0x00
} ; // offsets of structures that values are strings for type 3 Chassis
/* Functions */
// validate the SMBIOS entry point structure
2021-09-28 10:28:45 +02:00
XBool IsEntryPointStructureValid ( IN SMBIOS_TABLE_ENTRY_POINT * EntryPointStructure )
2019-09-03 11:58:42 +02:00
{
UINTN I ;
UINT8 Length ;
UINT8 Checksum = 0 ;
UINT8 * BytePtr ;
if ( ! EntryPointStructure )
2021-09-28 10:28:45 +02:00
return false ;
2019-09-03 11:58:42 +02:00
BytePtr = ( UINT8 * ) EntryPointStructure ;
Length = EntryPointStructure - > EntryPointLength ;
for ( I = 0 ; I < Length ; I + + ) {
Checksum = Checksum + ( UINT8 ) BytePtr [ I ] ;
}
// a valid SMBIOS EPS must have checksum of 0
return ( Checksum = = 0 ) ;
}
2020-10-03 19:02:31 +02:00
void * FindOemSMBIOSPtr ( void )
2019-09-03 11:58:42 +02:00
{
UINTN Address ;
// Search 0x0f0000 - 0x0fffff for SMBIOS Ptr
for ( Address = 0xf0000 ; Address < 0xfffff ; Address + = 0x10 ) {
if ( * ( UINT32 * ) ( Address ) = = SMBIOS_PTR & & IsEntryPointStructureValid ( ( SMBIOS_TABLE_ENTRY_POINT * ) Address ) ) {
2020-10-03 19:02:31 +02:00
return ( void * ) Address ;
2019-09-03 11:58:42 +02:00
}
}
return NULL ;
}
2020-10-03 19:02:31 +02:00
void * GetSmbiosTablesFromHob ( void )
2019-09-03 11:58:42 +02:00
{
EFI_PHYSICAL_ADDRESS * Table ;
EFI_PEI_HOB_POINTERS GuidHob ;
2022-04-26 00:55:56 +02:00
GuidHob . Raw = ( __typeof_am__ ( GuidHob . Raw ) ) GetFirstGuidHob ( gEfiSmbiosTableGuid ) ;
2019-09-03 11:58:42 +02:00
if ( GuidHob . Raw ! = NULL ) {
2020-02-20 15:28:24 +01:00
Table = ( __typeof__ ( Table ) ) GET_GUID_HOB_DATA ( GuidHob . Guid ) ;
2019-09-03 11:58:42 +02:00
if ( Table ! = NULL ) {
2020-10-03 19:02:31 +02:00
return ( void * ) ( UINTN ) * Table ;
2019-09-03 11:58:42 +02:00
}
}
2022-04-26 00:55:56 +02:00
GuidHob . Raw = ( __typeof_am__ ( GuidHob . Raw ) ) GetFirstGuidHob ( gEfiSmbios3TableGuid ) ;
2019-09-03 11:58:42 +02:00
if ( GuidHob . Raw ! = NULL ) {
2020-02-21 22:22:30 +01:00
Table = ( __typeof_am__ ( Table ) ) GET_GUID_HOB_DATA ( GuidHob . Guid ) ;
2019-09-03 11:58:42 +02:00
if ( Table ! = NULL ) {
2020-10-03 19:02:31 +02:00
return ( void * ) ( UINTN ) * Table ;
2019-09-03 11:58:42 +02:00
}
}
return NULL ;
}
2020-10-03 19:02:31 +02:00
void * GetSmbiosTablesFromConfigTables ( void )
2019-09-03 11:58:42 +02:00
{
EFI_STATUS Status ;
EFI_PHYSICAL_ADDRESS * Table ;
2020-10-03 19:02:31 +02:00
Status = EfiGetSystemConfigurationTable ( & gEfiSmbiosTableGuid , ( void * * ) & Table ) ;
2019-09-03 11:58:42 +02:00
if ( EFI_ERROR ( Status ) | | Table = = NULL ) {
Table = NULL ;
2020-10-03 19:02:31 +02:00
Status = EfiGetSystemConfigurationTable ( & gEfiSmbios3TableGuid , ( void * * ) & Table ) ;
2019-09-03 11:58:42 +02:00
if ( EFI_ERROR ( Status ) ) {
Table = NULL ;
}
}
return Table ;
}
// This function determines ascii string length ending by space.
// search restricted to MaxLen, for example
// iStrLen("ABC ", 20) == 3
// if MaxLen=0 then as usual strlen but bugless
2020-02-17 21:41:09 +01:00
UINTN iStrLen ( CONST CHAR8 * String , UINTN MaxLen )
2019-09-03 11:58:42 +02:00
{
UINTN Len = 0 ;
2020-02-17 21:41:09 +01:00
CONST CHAR8 * BA ;
2019-09-03 11:58:42 +02:00
if ( MaxLen > 0 ) {
for ( Len = 0 ; Len < MaxLen ; Len + + ) {
if ( String [ Len ] = = 0 ) {
break ;
}
}
BA = & String [ Len - 1 ] ;
while ( ( Len ! = 0 ) & & ( ( * BA = = ' ' ) | | ( * BA = = 0 ) ) ) {
BA - - ; Len - - ;
}
} else {
BA = String ;
while ( * BA ) { BA + + ; Len + + ; }
}
return Len ;
}
// Internal functions for flat SMBIOS
UINT16 SmbiosTableLength ( APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN )
{
CHAR8 * AChar ;
UINT16 Length ;
AChar = ( CHAR8 * ) ( SmbiosTableN . Raw + SmbiosTableN . Hdr - > Length ) ;
while ( ( * AChar ! = 0 ) | | ( * ( AChar + 1 ) ! = 0 ) ) {
AChar + + ; //stop at 00 - first 0
}
Length = ( UINT16 ) ( ( UINTN ) AChar - ( UINTN ) SmbiosTableN . Raw + 2 ) ; //length includes 00
return Length ;
}
EFI_SMBIOS_HANDLE LogSmbiosTable ( APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN )
{
UINT16 Length = SmbiosTableLength ( SmbiosTableN ) ;
if ( Length > MaxStructureSize ) {
MaxStructureSize = Length ;
}
CopyMem ( Current , SmbiosTableN . Raw , Length ) ;
Current + = Length ;
NumberOfRecords + + ;
return SmbiosTableN . Hdr - > Handle ;
}
2020-04-09 19:01:23 +02:00
// the procedure insert Buffer into SmbiosTable by copy and update Field
// the Buffer restricted by zero or by space
2020-08-15 15:47:56 +02:00
EFI_STATUS UpdateSmbiosString ( OUT APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN ,
SMBIOS_TABLE_STRING * Field , const XString8 & Buffer )
2019-09-03 11:58:42 +02:00
{
CHAR8 * AString ;
CHAR8 * C1 ; //pointers for copy
CHAR8 * C2 ;
UINTN Length = SmbiosTableLength ( SmbiosTableN ) ;
UINTN ALength , BLength ;
UINT8 IndexStr = 1 ;
2020-08-15 15:47:56 +02:00
if ( ( SmbiosTableN . Raw = = NULL ) | | Buffer . isEmpty ( ) | | ! Field ) {
2019-09-03 11:58:42 +02:00
return EFI_NOT_FOUND ;
}
AString = ( CHAR8 * ) ( SmbiosTableN . Raw + SmbiosTableN . Hdr - > Length ) ; //first string
while ( IndexStr ! = * Field ) {
if ( * AString ) {
IndexStr + + ;
}
while ( * AString ! = 0 ) AString + + ; //skip string at index
AString + + ; //next string
if ( * AString = = 0 ) {
//this is end of the table
if ( * Field = = 0 ) {
AString [ 1 ] = 0 ; //one more zero
}
* Field = IndexStr ; //index of the next string that is empty
if ( IndexStr = = 1 ) {
AString - - ; //first string has no leading zero
}
break ;
}
}
// AString is at place to copy
ALength = iStrLen ( AString , 0 ) ;
2020-08-15 15:47:56 +02:00
BLength = iStrLen ( Buffer . c_str ( ) , MAX_OEM_STRING ) ;
2019-09-03 11:58:42 +02:00
// DBG("Table type %d field %d\n", SmbiosTable.Hdr->Type, *Field);
// DBG("Old string length=%d new length=%d\n", ALength, BLength);
if ( BLength > ALength ) {
//Shift right
C1 = ( CHAR8 * ) SmbiosTableN . Raw + Length ; //old end
C2 = C1 + BLength - ALength ; //new end
* C2 = 0 ;
while ( C1 ! = AString ) * ( - - C2 ) = * ( - - C1 ) ;
} else if ( BLength < ALength ) {
//Shift left
C1 = AString + ALength ; //old start
C2 = AString + BLength ; //new start
while ( C1 ! = ( ( CHAR8 * ) SmbiosTableN . Raw + Length ) ) {
* C2 + + = * C1 + + ;
}
* C2 = 0 ;
* ( - - C2 ) = 0 ; //end of table
}
2020-11-18 22:49:02 +01:00
//DBG("UpdateSmbiosString() -> CopyMem %s %lld\n", Buffer.c_str(), BLength);
2020-08-15 15:47:56 +02:00
CopyMem ( AString , Buffer . c_str ( ) , BLength ) ;
2019-09-03 11:58:42 +02:00
* ( AString + BLength ) = 0 ; // not sure there is 0
return EFI_SUCCESS ;
}
APPLE_SMBIOS_STRUCTURE_POINTER GetSmbiosTableFromType ( SMBIOS_TABLE_ENTRY_POINT * SmbiosPoint ,
UINT8 SmbiosType , UINTN IndexTable )
{
APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN ;
UINTN SmbiosTypeIndex ;
SmbiosTypeIndex = 0 ;
SmbiosTableN . Raw = ( UINT8 * ) ( ( UINTN ) SmbiosPoint - > TableAddress ) ;
if ( SmbiosTableN . Raw = = NULL ) {
return SmbiosTableN ;
}
while ( ( SmbiosTypeIndex ! = IndexTable ) | | ( SmbiosTableN . Hdr - > Type ! = SmbiosType ) ) {
if ( SmbiosTableN . Hdr - > Type = = SMBIOS_TYPE_END_OF_TABLE ) {
SmbiosTableN . Raw = NULL ;
return SmbiosTableN ;
}
if ( SmbiosTableN . Hdr - > Type = = SmbiosType ) {
SmbiosTypeIndex + + ;
}
SmbiosTableN . Raw = ( UINT8 * ) ( SmbiosTableN . Raw + SmbiosTableLength ( SmbiosTableN ) ) ;
}
return SmbiosTableN ;
}
CHAR8 * GetSmbiosString ( APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN , SMBIOS_TABLE_STRING StringN )
{
CHAR8 * AString ;
UINT8 Ind ;
Ind = 1 ;
AString = ( CHAR8 * ) ( SmbiosTableN . Raw + SmbiosTableN . Hdr - > Length ) ; //first string
while ( Ind ! = StringN ) {
while ( * AString ! = 0 ) {
AString + + ;
}
AString + + ; //skip zero ending
if ( * AString = = 0 ) {
return AString ; //this is end of the table
}
Ind + + ;
}
return AString ; //return pointer to Ascii string
}
2020-10-03 19:02:31 +02:00
void AddSmbiosEndOfTable ( )
2019-09-03 11:58:42 +02:00
{
SMBIOS_STRUCTURE * StructurePtr = ( SMBIOS_STRUCTURE * ) Current ;
StructurePtr - > Type = SMBIOS_TYPE_END_OF_TABLE ;
StructurePtr - > Length = sizeof ( SMBIOS_STRUCTURE ) ;
StructurePtr - > Handle = SMBIOS_TYPE_INACTIVE ; //spec 2.7 p.120
Current + = sizeof ( SMBIOS_STRUCTURE ) ;
* Current + + = 0 ;
* Current + + = 0 ; //double 0 at the end
NumberOfRecords + + ;
}
2020-10-03 19:02:31 +02:00
void UniquifySmbiosTableStr ( APPLE_SMBIOS_STRUCTURE_POINTER SmbiosTableN , SMBIOS_TABLE_STRING * str_idx )
2019-09-03 11:58:42 +02:00
{
INTN i , j ;
SMBIOS_TABLE_STRING cmp_idx ;
SMBIOS_TABLE_STRING cmp_str ;
SMBIOS_TABLE_STRING ref_str ;
if ( 0 = = str_idx [ 0 ] ) return ; // SMBIOS doesn't have string structures, just return;
for ( i = 1 ; ; i + + ) {
cmp_idx = str_idx [ i ] ;
if ( 0 = = cmp_idx ) break ;
cmp_str = SmbiosTableN . Raw [ cmp_idx ] ;
if ( 0 = = cmp_str ) continue ; // if string is undefine, continue
for ( j = 0 ; j < i ; j + + ) {
ref_str = SmbiosTableN . Raw [ str_idx [ j ] ] ;
if ( cmp_str = = ref_str ) {
SmbiosTableN . Raw [ cmp_idx ] = 0 ; // pretend the string doesn't exist
// UpdateSmbiosString(SmbiosTableN, &SmbiosTableN.Raw[cmp_idx], GetSmbiosString(SmbiosTableN, ref_str));
break ;
}
}
}
}
/* Patching Functions */
2021-04-28 20:30:34 +02:00
void PatchTableType0 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// BIOS information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_BIOS_INFORMATION , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
// DBG("SmbiosTable: Type 0 (Bios Information) not found!\n");
return ;
}
TableSize = SmbiosTableLength ( SmbiosTable ) ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type0 , MAX_TABLE_SIZE ) ;
CopyMem ( ( void * ) newSmbiosTable . Type0 , ( void * ) SmbiosTable . Type0 , TableSize ) ; //can't point to union
2019-09-03 11:58:42 +02:00
/* Real Mac
BIOS Information ( Type 0 )
Raw Data :
Header and Data :
00 18 2 E 00 01 02 00 00 03 7F 80 98 01 00 00 00
00 00 C1 02 00 01 FF FF
Strings :
Apple Inc .
MBP81 .88 Z .0047 . B22 .1109281426
09 / 28 / 11
*/
newSmbiosTable . Type0 - > BiosSegment = 0 ; //like in Mac
newSmbiosTable . Type0 - > SystemBiosMajorRelease = 0 ;
newSmbiosTable . Type0 - > SystemBiosMinorRelease = 1 ;
// newSmbiosTable.Type0->BiosCharacteristics.BiosCharacteristicsNotSupported = 0;
// newSmbiosTable.Type0->BIOSCharacteristicsExtensionBytes[1] |= 8; //UefiSpecificationSupported;
//Slice: ----------------------
//there is a bug in AppleSMBIOS-42 v1.7
//to eliminate this I have to zero first byte in the field
* ( UINT8 * ) & newSmbiosTable . Type0 - > BiosCharacteristics = 0 ;
//dunno about latest version but there is a way to set good characteristics
//if use patched AppleSMBIOS
//----------------
2021-09-28 10:28:45 +02:00
Once = true ;
2019-09-03 11:58:42 +02:00
UniquifySmbiosTableStr ( newSmbiosTable , SMBIOS_TABLE_TYPE0_STR_IDX ) ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BiosVendor . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type0 - > Vendor , smbiosSettings . BiosVendor ) ;
2021-04-03 16:42:49 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BiosVersionUsed . notEmpty ( ) ) {
if ( smbiosSettings . EfiVersionUsed . notEmpty ( ) ) {
DBG ( " UpdateSmbiosString : BiosVersion=EfiVersion=%s \n " , smbiosSettings . EfiVersionUsed . c_str ( ) ) ;
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type0 - > BiosVersion , smbiosSettings . EfiVersionUsed ) ;
2019-09-03 11:58:42 +02:00
} else {
2021-04-28 20:30:34 +02:00
DBG ( " UpdateSmbiosString : BiosVersion=RomVersion=%s \n " , smbiosSettings . BiosVersionUsed . c_str ( ) ) ;
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type0 - > BiosVersion , smbiosSettings . BiosVersionUsed ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-05 10:57:55 +02:00
} else {
DBG ( " UpdateSmbiosString : BiosVersion no update \n " ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . ReleaseDateUsed . notEmpty ( ) ) {
DBG ( " UpdateSmbiosString : ReleaseDate=%s \n " , smbiosSettings . ReleaseDateUsed . c_str ( ) ) ;
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type0 - > BiosReleaseDate , smbiosSettings . ReleaseDateUsed ) ;
2021-04-05 10:57:55 +02:00
} else {
DBG ( " UpdateSmbiosString : ReleaseDate no update \n " ) ;
2019-09-03 11:58:42 +02:00
}
Handle = LogSmbiosTable ( newSmbiosTable ) ;
}
2021-04-28 20:30:34 +02:00
void GetTableType1 ( SmbiosDiscoveredSettings * smbiosSettings )
2019-09-03 11:58:42 +02:00
{
CHAR8 * s ;
// System Information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_SYSTEM_INFORMATION , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
DBG ( " SmbiosTable: Type 1 (System Information) not found! \n " ) ;
return ;
}
2022-05-03 05:38:54 +02:00
// smbiosSettings.SmUUID = GuidLEToXString8(SmbiosTable.Type1->Uuid); // is this is a bug, this uuid might be BE, not LE, or should we use the "variant" field
2019-09-03 11:58:42 +02:00
s = GetSmbiosString ( SmbiosTable , SmbiosTable . Type1 - > ProductName ) ;
2021-04-28 20:30:34 +02:00
smbiosSettings - > OEMProductFromSmbios . strncpy ( s , iStrLen ( s , 64 ) ) ; //strncpy take care of ending zero
2019-09-03 11:58:42 +02:00
return ;
}
2022-04-26 00:55:56 +02:00
EFI_GUID getSmUUIDFromSmbios ( )
2021-04-28 20:30:34 +02:00
{
// System Information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_SYSTEM_INFORMATION , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
DBG ( " SmbiosTable: Type 1 (System Information) not found! \n " ) ;
2022-04-26 00:55:56 +02:00
return nullGuid ;
2021-04-28 20:30:34 +02:00
}
2022-05-17 18:43:08 +02:00
// EFI_GUID TmpGuid;
2019-09-03 11:58:42 +02:00
2022-05-03 05:38:54 +02:00
// XString8 g = GuidBeToXString8(SmbiosTable.Type1->Uuid); // should we use the "variant" field to know if it's LE or BE
2022-05-14 21:54:27 +02:00
XString8 guidBE = SmbiosTable . Type1 - > Uuid . toXString8 ( true ) ; // This is the difference between PC and Mac. the UUID will be swapped (read as a LE, sent as a BE).
2022-05-03 05:38:54 +02:00
2022-05-14 21:54:27 +02:00
DBG ( " got BE smUUID as:%s \n " , guidBE . c_str ( ) ) ;
return GUID ( ) . takeValueFrom ( guidBE ) ;
2021-04-28 20:30:34 +02:00
}
2019-09-03 11:58:42 +02:00
2021-04-28 20:30:34 +02:00
void PatchTableType1 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// System Information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_SYSTEM_INFORMATION , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
return ;
}
//Increase table size
2021-04-28 20:30:34 +02:00
UINTN Size = SmbiosTable . Type1 - > Hdr . Length ; //old size
2019-09-03 11:58:42 +02:00
TableSize = SmbiosTableLength ( SmbiosTable ) ; //including strings
2021-04-28 20:30:34 +02:00
UINTN NewSize = 27 ; //sizeof(SMBIOS_TABLE_TYPE1);
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type1 , MAX_TABLE_SIZE ) ;
CopyMem ( ( void * ) newSmbiosTable . Type1 , ( void * ) SmbiosTable . Type1 , Size ) ; //copy main table
2019-09-03 11:58:42 +02:00
CopyMem ( ( CHAR8 * ) newSmbiosTable . Type1 + NewSize , ( CHAR8 * ) SmbiosTable . Type1 + Size , TableSize - Size ) ; //copy strings
newSmbiosTable . Type1 - > Hdr . Length = ( UINT8 ) NewSize ;
UniquifySmbiosTableStr ( newSmbiosTable , SMBIOS_TABLE_TYPE1_STR_IDX ) ;
newSmbiosTable . Type1 - > WakeUpType = SystemWakeupTypePowerSwitch ;
2021-09-28 10:28:45 +02:00
Once = true ;
2019-09-03 11:58:42 +02:00
2021-04-28 20:30:34 +02:00
// macOs take all guid as BE guid, irrespective to the variant.
2022-04-26 00:55:56 +02:00
if ( ( smbiosSettings . SmUUID . Data3 & 0xF000 ) ! = 0 ) {
CopyMem ( ( void * ) & newSmbiosTable . Type1 - > Uuid , ( void * ) & smbiosSettings . SmUUID , sizeof ( smbiosSettings . SmUUID ) ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . ManufactureName . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type1 - > Manufacturer , smbiosSettings . ManufactureName ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . ProductName . notEmpty ( ) ) {
DBG ( " %s : UpdateSmbiosString ProductName=%s \n " , __PRETTY_FUNCTION__ , smbiosSettings . ProductName . c_str ( ) ) ;
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type1 - > ProductName , smbiosSettings . ProductName ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . SystemVersion . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type1 - > Version , smbiosSettings . SystemVersion ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . SerialNr . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type1 - > SerialNumber , smbiosSettings . SerialNr ) ;
//DBG("%s : UpdateSmbiosString SerialNr=%s\n", __PRETTY_FUNCTION__, smbiosSettings.SerialNr.c_str());
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BoardNumber . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type1 - > SKUNumber , smbiosSettings . BoardNumber ) ; //iMac17,1 - there is nothing
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . FamilyName . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type1 - > Family , smbiosSettings . FamilyName ) ;
2019-09-03 11:58:42 +02:00
}
Handle = LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2021-04-28 20:30:34 +02:00
void GetTableType2 ( SmbiosDiscoveredSettings * smbiosSettings )
2019-09-03 11:58:42 +02:00
{
CHAR8 * s ;
// System Information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
return ;
}
s = GetSmbiosString ( SmbiosTable , SmbiosTable . Type2 - > ProductName ) ;
2021-04-28 20:30:34 +02:00
smbiosSettings - > OEMBoardFromSmbios . strncpy ( s , iStrLen ( s , 64 ) + 1 ) ;
2019-09-03 11:58:42 +02:00
s = GetSmbiosString ( SmbiosTable , SmbiosTable . Type2 - > Manufacturer ) ;
2021-04-28 20:30:34 +02:00
smbiosSettings - > OEMVendorFromSmbios . strncpy ( s , iStrLen ( s , 64 ) + 1 ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
void PatchTableType2 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// BaseBoard Information
//
2021-04-28 20:30:34 +02:00
UINTN NewSize = 0x10 ; //sizeof(SMBIOS_TABLE_TYPE2);
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type2 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_BASEBOARD_INFORMATION , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
MsgLog ( " SmbiosTable: Type 2 (BaseBoard Information) not found, create new \n " ) ;
//Create new one
newSmbiosTable . Type2 - > Hdr . Type = 2 ;
newSmbiosTable . Type2 - > Hdr . Handle = 0x0200 ; //common rule
} else {
2021-04-28 20:30:34 +02:00
UINTN Size = SmbiosTable . Type2 - > Hdr . Length ; //old size
2019-09-03 11:58:42 +02:00
TableSize = SmbiosTableLength ( SmbiosTable ) ; //including strings
if ( NewSize > Size ) {
2020-10-03 19:02:31 +02:00
CopyMem ( ( void * ) newSmbiosTable . Type2 , ( void * ) SmbiosTable . Type2 , Size ) ; //copy main table
2019-09-03 11:58:42 +02:00
CopyMem ( ( CHAR8 * ) newSmbiosTable . Type2 + NewSize , ( CHAR8 * ) SmbiosTable . Type2 + Size , TableSize - Size ) ; //copy strings
} else {
2020-10-03 19:02:31 +02:00
CopyMem ( ( void * ) newSmbiosTable . Type2 , ( void * ) SmbiosTable . Type2 , TableSize ) ; //copy full table
2019-09-03 11:58:42 +02:00
}
}
newSmbiosTable . Type2 - > Hdr . Length = ( UINT8 ) NewSize ;
newSmbiosTable . Type2 - > ChassisHandle = mHandle3 ; //from GetTableType3
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type2 - > BoardType = smbiosSettings . BoardType ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) & newSmbiosTable . Type2 - > FeatureFlag , sizeof ( BASE_BOARD_FEATURE_FLAGS ) ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type2 - > FeatureFlag . Motherboard = 1 ;
newSmbiosTable . Type2 - > FeatureFlag . Replaceable = 1 ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BoardType = = 11 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type2 - > FeatureFlag . Removable = 1 ;
}
2021-09-28 10:28:45 +02:00
Once = true ;
2019-09-03 11:58:42 +02:00
UniquifySmbiosTableStr ( newSmbiosTable , SMBIOS_TABLE_TYPE2_STR_IDX ) ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BoardManufactureName . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type2 - > Manufacturer , smbiosSettings . BoardManufactureName ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BoardNumber . notEmpty ( ) ) {
DBG ( " %s : UpdateSmbiosString ProductName=BoardNumber=%s \n " , __PRETTY_FUNCTION__ , smbiosSettings . BoardNumber . c_str ( ) ) ;
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type2 - > ProductName , smbiosSettings . BoardNumber ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BoardVersion . notEmpty ( ) ) {
DBG ( " %s : UpdateSmbiosString Version=BoardVersion=%s \n " , __PRETTY_FUNCTION__ , smbiosSettings . BoardVersion . c_str ( ) ) ;
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type2 - > Version , smbiosSettings . BoardVersion ) ; //iMac17,1 - there is ProductName
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BoardSerialNumber . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type2 - > SerialNumber , smbiosSettings . BoardSerialNumber ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . LocationInChassis . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type2 - > LocationInChassis , smbiosSettings . LocationInChassis ) ;
2019-09-03 11:58:42 +02:00
}
//what about Asset Tag??? Not used in real mac. till now.
//Slice - for the table2 one patch more needed
/* spec
Field 0x0E - Identifies the number ( 0 to 255 ) of Contained Object Handles that follow
Field 0x0F - A list of handles of other structures ( for example , Baseboard , Processor , Port , System Slots , Memory Device ) that are contained by this baseboard
It may be good before our patching but changed after . We should at least check if all tables mentioned here are present in final structure
I just set 0 as in iMac11
*/
newSmbiosTable . Type2 - > NumberOfContainedObjectHandles = 0 ;
Handle = LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2021-09-28 15:54:31 +02:00
XBool getMobileFromSmbios ( )
2021-04-28 20:30:34 +02:00
{
// System Chassis Information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
//DBG("SmbiosTable: Type 3 (System Chassis Information) not found!\n");
return false ;
}
mHandle3 = SmbiosTable . Type3 - > Hdr . Handle ;
2022-04-14 18:06:34 +02:00
//DBG("getMobileFromSmbios (SmbiosTable.Type3->Type=%d) %d\n", SmbiosTable.Type3->Type, ((SmbiosTable.Type3->Type) >= 8) && (SmbiosTable.Type3->Type != 0x0D));
2021-04-28 20:30:34 +02:00
return ( ( SmbiosTable . Type3 - > Type ) > = 8 ) & & ( SmbiosTable . Type3 - > Type ! = 0x0D ) ; //iMac is desktop!
}
void GetTableType3 ( SmbiosDiscoveredSettings * smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// System Chassis Information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
DBG ( " SmbiosTable: Type 3 (System Chassis Information) not found! \n " ) ;
2021-09-28 10:28:45 +02:00
gMobile = false ; //default value
2019-09-03 11:58:42 +02:00
return ;
}
mHandle3 = SmbiosTable . Type3 - > Hdr . Handle ;
gMobile = ( ( SmbiosTable . Type3 - > Type ) > = 8 ) & & ( SmbiosTable . Type3 - > Type ! = 0x0D ) ; //iMac is desktop!
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType3 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// System Chassis Information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_SYSTEM_ENCLOSURE , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
// DBG("SmbiosTable: Type 3 (System Chassis Information) not found!\n");
return ;
}
2021-04-28 20:30:34 +02:00
UINTN Size = SmbiosTable . Type3 - > Hdr . Length ; //old size
2019-09-03 11:58:42 +02:00
TableSize = SmbiosTableLength ( SmbiosTable ) ; //including strings
2021-04-28 20:30:34 +02:00
UINTN NewSize = 0x15 ; //sizeof(SMBIOS_TABLE_TYPE3);
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type3 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
if ( NewSize > Size ) {
2020-10-03 19:02:31 +02:00
CopyMem ( ( void * ) newSmbiosTable . Type3 , ( void * ) SmbiosTable . Type3 , Size ) ; //copy main table
2019-09-03 11:58:42 +02:00
CopyMem ( ( CHAR8 * ) newSmbiosTable . Type3 + NewSize , ( CHAR8 * ) SmbiosTable . Type3 + Size , TableSize - Size ) ; //copy strings
newSmbiosTable . Type3 - > Hdr . Length = ( UINT8 ) NewSize ;
} else {
2020-10-03 19:02:31 +02:00
CopyMem ( ( void * ) newSmbiosTable . Type3 , ( void * ) SmbiosTable . Type3 , TableSize ) ; //copy full table
2019-09-03 11:58:42 +02:00
}
newSmbiosTable . Type3 - > BootupState = ChassisStateSafe ;
newSmbiosTable . Type3 - > PowerSupplyState = ChassisStateSafe ;
newSmbiosTable . Type3 - > ThermalState = ChassisStateOther ;
newSmbiosTable . Type3 - > SecurityStatus = ChassisSecurityStatusOther ; //ChassisSecurityStatusNone;
newSmbiosTable . Type3 - > NumberofPowerCords = 1 ;
newSmbiosTable . Type3 - > ContainedElementCount = 0 ;
newSmbiosTable . Type3 - > ContainedElementRecordLength = 0 ;
2021-09-28 10:28:45 +02:00
Once = true ;
2019-09-03 11:58:42 +02:00
UniquifySmbiosTableStr ( newSmbiosTable , SMBIOS_TABLE_TYPE3_STR_IDX ) ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . ChassisType ! = 0 ) {
newSmbiosTable . Type3 - > Type = smbiosSettings . ChassisType ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . ChassisManufacturer . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type3 - > Manufacturer , smbiosSettings . ChassisManufacturer ) ;
2019-09-03 11:58:42 +02:00
}
//SIC! According to iMac there must be the BoardNumber
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BoardNumber . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type3 - > Version , smbiosSettings . BoardNumber ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . SerialNr . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type3 - > SerialNumber , smbiosSettings . SerialNr ) ;
//DBG("%s : UpdateSmbiosString SerialNr=%s\n", __PRETTY_FUNCTION__, smbiosSettings.SerialNr.c_str());
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . ChassisAssetTag . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type3 - > AssetTag , smbiosSettings . ChassisAssetTag ) ;
2019-09-03 11:58:42 +02:00
}
Handle = LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2021-04-28 20:30:34 +02:00
void GetTableType4 ( SmbiosDiscoveredSettings * smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// Processor Information
//
INTN res = 0 ;
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
DBG ( " SmbiosTable: Type 4 (Processor Information) not found! \n " ) ;
return ;
}
res = ( SmbiosTable . Type4 - > ExternalClock * 3 + 2 ) % 100 ;
if ( res > 2 ) {
res = 0 ;
} else {
res = SmbiosTable . Type4 - > ExternalClock % 10 ;
}
2021-04-28 20:30:34 +02:00
smbiosSettings - > ExternalClock = ( UINT32 ) ( ( SmbiosTable . Type4 - > ExternalClock * 1000 ) + ( res * 110 ) ) ; //MHz->kHz
2019-09-03 11:58:42 +02:00
2021-04-28 20:30:34 +02:00
//snwprintf(gSettings.BusSpeed, 10, "%d", smbiosSettings.ExternalClock);
//gSettings.BusSpeed = smbiosSettings.ExternalClock; //why duplicate??
smbiosSettings - > CurrentSpeed = SmbiosTable . Type4 - > CurrentSpeed ;
smbiosSettings - > MaxSpeed = SmbiosTable . Type4 - > MaxSpeed ;
2019-09-03 11:58:42 +02:00
2020-08-25 17:35:19 +02:00
size_t off = OFFSET_OF ( SMBIOS_TABLE_TYPE4 , EnabledCoreCount ) ;
if ( SmbiosTable . Type4 - > Hdr . Length > off ) { //Smbios >= 2.5
2021-04-28 20:30:34 +02:00
smbiosSettings - > EnabledCores = SmbiosTable . Type4 - > EnabledCoreCount ;
2019-09-03 11:58:42 +02:00
} else {
2021-04-28 20:30:34 +02:00
smbiosSettings - > EnabledCores = 0 ; //to change later
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
//snwprintf(gSettings.CpuFreqMHz, 10, "%d", smbiosSettings.CurrentSpeed);
//gSettings.CpuFreqMHz = smbiosSettings.CurrentSpeed;
2019-09-03 11:58:42 +02:00
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType4 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// Processor Information
//
UINTN AddBrand = 0 ;
UINT16 ProcChar = 0 ;
//Note. iMac11,2 has four tables for CPU i3
UINTN CpuNumber ;
2020-03-25 19:32:44 +01:00
// DBG("BrandString=%s\n", BrandStr);
2021-04-28 20:30:34 +02:00
for ( CpuNumber = 0 ; CpuNumber < smbiosSettings . Cores ; CpuNumber + + ) {
2019-09-03 11:58:42 +02:00
// Get Table Type4
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION , CpuNumber ) ;
if ( SmbiosTable . Raw = = NULL ) {
break ;
}
// we make SMBios v2.4 while it may be older so we have to increase size
2021-04-28 20:30:34 +02:00
UINTN Size = SmbiosTable . Type4 - > Hdr . Length ; //old size
2019-09-03 11:58:42 +02:00
TableSize = SmbiosTableLength ( SmbiosTable ) ; //including strings
AddBrand = 0 ;
if ( SmbiosTable . Type4 - > ProcessorVersion = = 0 ) { //if no BrandString we can add
AddBrand = 48 ;
}
2021-04-28 20:30:34 +02:00
UINTN NewSize = sizeof ( SMBIOS_TABLE_TYPE4 ) ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type4 , MAX_TABLE_SIZE ) ;
CopyMem ( ( void * ) newSmbiosTable . Type4 , ( void * ) SmbiosTable . Type4 , Size ) ; //copy main table
2019-09-03 11:58:42 +02:00
CopyMem ( ( CHAR8 * ) newSmbiosTable . Type4 + NewSize , ( CHAR8 * ) SmbiosTable . Type4 + Size , TableSize - Size ) ; //copy strings
newSmbiosTable . Type4 - > Hdr . Length = ( UINT8 ) NewSize ;
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type4 - > MaxSpeed = ( UINT16 ) smbiosSettings . MaxSpeed ;
2019-09-03 11:58:42 +02:00
//old version has no such fields. Fill now
if ( Size < = 0x20 ) {
//sanity check and clear
newSmbiosTable . Type4 - > SerialNumber = 0 ;
newSmbiosTable . Type4 - > AssetTag = 0 ;
newSmbiosTable . Type4 - > PartNumber = 0 ;
}
if ( Size < = 0x23 ) { //Smbios <=2.3
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type4 - > CoreCount = smbiosSettings . Cores ;
newSmbiosTable . Type4 - > ThreadCount = smbiosSettings . Threads ;
newSmbiosTable . Type4 - > ProcessorCharacteristics = ( UINT16 ) smbiosSettings . Features ;
2019-09-03 11:58:42 +02:00
} //else we propose DMI data is better then cpuid().
// if (newSmbiosTable.Type4->CoreCount < newSmbiosTable.Type4->EnabledCoreCount) {
2021-04-28 20:30:34 +02:00
// newSmbiosTable.Type4->EnabledCoreCount = smbiosSettings.Cores;
2019-09-03 11:58:42 +02:00
// }
2021-04-28 20:30:34 +02:00
//DBG("insert ExternalClock: %d MHz\n", (INT32)(DivU64x32(smbiosSettings.ExternalClock, Kilo)));
newSmbiosTable . Type4 - > ExternalClock = ( UINT16 ) DivU64x32 ( smbiosSettings . ExternalClock , Kilo ) ;
newSmbiosTable . Type4 - > EnabledCoreCount = smbiosSettings . EnabledCores ;
2019-09-03 11:58:42 +02:00
//some verifications
if ( ( newSmbiosTable . Type4 - > ThreadCount < newSmbiosTable . Type4 - > CoreCount ) | |
newSmbiosTable . Type4 - > ThreadCount > newSmbiosTable . Type4 - > CoreCount * 2 ) {
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type4 - > ThreadCount = smbiosSettings . Threads ;
2019-09-03 11:58:42 +02:00
}
UniquifySmbiosTableStr ( newSmbiosTable , SMBIOS_TABLE_TYPE4_STR_IDX ) ;
// TODO: Set SmbiosTable.Type4->ProcessorFamily for all implemented CPU models
2021-09-28 10:28:45 +02:00
Once = true ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Model = = CPU_MODEL_ATOM ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelAtom ;
}
2021-04-28 20:30:34 +02:00
if ( ( smbiosSettings . Model = = CPU_MODEL_DOTHAN ) | |
( smbiosSettings . Model = = CPU_MODEL_YONAH ) ) {
if ( smbiosSettings . Mobile ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorUpgrade = ProcessorUpgradeSocket478 ;
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCoreSoloMobile ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Cores = = 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCoreDuoMobile ;
}
} else {
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCoreSolo ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Cores = = 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCoreDuo ;
}
}
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Model = = CPU_MODEL_MEROM ) {
if ( smbiosSettings . Mobile ) {
if ( smbiosSettings . Cores = = 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2DuoMobile ;
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Cores = = 1 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2SoloMobile ;
}
} else { // Conroe
newSmbiosTable . Type4 - > ProcessorUpgrade = ProcessorUpgradeSocketLGA775 ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Cores > 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2Quad ;
} else
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Cores = = 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2Extreme ;
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Cores = = 1 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2Solo ;
}
}
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Model = = CPU_MODEL_PENRYN ) {
if ( smbiosSettings . Mobile ) {
if ( smbiosSettings . Cores > 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2ExtremeMobile ;
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Cores = = 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2DuoMobile ;
}
} else {
newSmbiosTable . Type4 - > ProcessorUpgrade = ProcessorUpgradeSocketLGA775 ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Cores > 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2Quad ;
2021-04-28 20:30:34 +02:00
} else if ( smbiosSettings . Cores = = 2 ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2 ;
} else {
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2Solo ;
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BrandString . contains ( " Celeron " ) ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyDualCoreIntelCeleron ;
2021-04-28 20:30:34 +02:00
} else if ( smbiosSettings . BrandString . contains ( " Extreme " ) ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2Extreme ;
}
}
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Model > = CPU_MODEL_NEHALEM ) {
if ( smbiosSettings . BrandString . contains ( " i3 " ) )
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCoreI3 ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BrandString . contains ( " i5 " ) )
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCoreI5 ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . BrandString . contains ( " i7 " ) )
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCoreI7 ;
}
//spec 2.7 page 48 note 3
if ( ( newSmbiosTable . Type4 - > ProcessorFamily = = ProcessorFamilyIntelCore2 )
2021-04-28 20:30:34 +02:00
& & smbiosSettings . Mobile ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorFamily = ProcessorFamilyIntelCore2DuoMobile ;
}
// Set CPU Attributes
newSmbiosTable . Type4 - > L1CacheHandle = L1 ;
newSmbiosTable . Type4 - > L2CacheHandle = L2 ;
newSmbiosTable . Type4 - > L3CacheHandle = L3 ;
newSmbiosTable . Type4 - > ProcessorType = CentralProcessor ;
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type4 - > ProcessorId . Signature . ProcessorSteppingId = smbiosSettings . Stepping ;
newSmbiosTable . Type4 - > ProcessorId . Signature . ProcessorModel = ( smbiosSettings . Model & 0xF ) ;
newSmbiosTable . Type4 - > ProcessorId . Signature . ProcessorFamily = smbiosSettings . Family ;
newSmbiosTable . Type4 - > ProcessorId . Signature . ProcessorType = smbiosSettings . Type ;
newSmbiosTable . Type4 - > ProcessorId . Signature . ProcessorXModel = smbiosSettings . Extmodel ;
newSmbiosTable . Type4 - > ProcessorId . Signature . ProcessorXFamily = smbiosSettings . Extfamily ;
// CopyMem((void*)&newSmbiosTable.Type4->ProcessorId.FeatureFlags, (void*)&smbiosSettings.Features, 4);
// newSmbiosTable.Type4->ProcessorId.FeatureFlags = (PROCESSOR_FEATURE_FLAGS)(UINT32)smbiosSettings.Features;
2019-09-03 11:58:42 +02:00
if ( Size < = 0x26 ) {
newSmbiosTable . Type4 - > ProcessorFamily2 = newSmbiosTable . Type4 - > ProcessorFamily ;
2021-04-28 20:30:34 +02:00
ProcChar | = ( smbiosSettings . ExtFeatures & CPUID_EXTFEATURE_EM64T ) ? 0x04 : 0 ;
ProcChar | = ( smbiosSettings . Cores > 1 ) ? 0x08 : 0 ;
ProcChar | = ( smbiosSettings . Cores < smbiosSettings . Threads ) ? 0x10 : 0 ;
ProcChar | = ( smbiosSettings . ExtFeatures & CPUID_EXTFEATURE_XD ) ? 0x20 : 0 ;
ProcChar | = ( smbiosSettings . Features & CPUID_FEATURE_VMX ) ? 0x40 : 0 ;
ProcChar | = ( smbiosSettings . Features & CPUID_FEATURE_EST ) ? 0x80 : 0 ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type4 - > ProcessorCharacteristics = ProcChar ;
}
2020-08-15 15:47:56 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type4 - > Socket , " U2E1 " _XS8 ) ;
2019-09-03 11:58:42 +02:00
2020-08-15 15:47:56 +02:00
XString8 BrandStr ;
2021-04-28 20:30:34 +02:00
BrandStr . takeValueFrom ( smbiosSettings . BrandString ) ;
2019-09-03 11:58:42 +02:00
if ( AddBrand ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type4 - > ProcessorVersion , BrandStr ) ;
}
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type4 - > AssetTag , BrandStr ) ; //like mac
// looks to be MicroCode revision
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . MicroCode > 0 ) {
BrandStr . S8Printf ( " %llX " , smbiosSettings . MicroCode ) ;
2019-09-03 11:58:42 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type4 - > SerialNumber , BrandStr ) ;
}
2021-04-28 20:30:34 +02:00
2021-10-02 19:44:16 +02:00
//#ifdef JIEF_DEBUG
//DBG("newSmbiosTable.Type4->AssetTag=%d\n", newSmbiosTable.Type4->AssetTag);
//DBG("newSmbiosTable.Type4->CoreCount=%d\n", newSmbiosTable.Type4->CoreCount);
//DBG("newSmbiosTable.Type4->CoreCount2=%d\n", newSmbiosTable.Type4->CoreCount2);
//DBG("newSmbiosTable.Type4->CurrentSpeed=%d\n", newSmbiosTable.Type4->CurrentSpeed);
//DBG("newSmbiosTable.Type4->EnabledCoreCount=%d\n", newSmbiosTable.Type4->EnabledCoreCount);
//DBG("newSmbiosTable.Type4->EnabledCoreCount2=%d\n", newSmbiosTable.Type4->EnabledCoreCount2);
//DBG("newSmbiosTable.Type4->ExternalClock=%d\n", newSmbiosTable.Type4->ExternalClock);
//DBG("newSmbiosTable.Type4->L1CacheHandle=%d\n", newSmbiosTable.Type4->L1CacheHandle);
//DBG("newSmbiosTable.Type4->L2CacheHandle=%d\n", newSmbiosTable.Type4->L2CacheHandle);
//DBG("newSmbiosTable.Type4->L3CacheHandle=%d\n", newSmbiosTable.Type4->L3CacheHandle);
//DBG("newSmbiosTable.Type4->MaxSpeed=%d\n", newSmbiosTable.Type4->MaxSpeed);
//DBG("newSmbiosTable.Type4->PartNumber=%d\n", newSmbiosTable.Type4->PartNumber);
//DBG("newSmbiosTable.Type4->ProcessorCharacteristics=%d\n", newSmbiosTable.Type4->ProcessorCharacteristics);
//DBG("newSmbiosTable.Type4->ProcessorFamily=%d\n", newSmbiosTable.Type4->ProcessorFamily);
//DBG("newSmbiosTable.Type4->ProcessorFamily2=%d\n", newSmbiosTable.Type4->ProcessorFamily2);
//DBG("newSmbiosTable.Type4->ProcessorId.FeatureFlags=%d\n", *(UINT32*)&newSmbiosTable.Type4->ProcessorId.FeatureFlags);
//DBG("newSmbiosTable.Type4->ProcessorId.Signatur=%d\n", *(UINT32*)&newSmbiosTable.Type4->ProcessorId.Signature);
//DBG("newSmbiosTable.Type4->ProcessorManufacturer=%d\n", newSmbiosTable.Type4->ProcessorManufacturer);
//DBG("newSmbiosTable.Type4->ProcessorType=%d\n", newSmbiosTable.Type4->ProcessorType);
//DBG("newSmbiosTable.Type4->ProcessorUpgrade=%d\n", newSmbiosTable.Type4->ProcessorUpgrade);
//DBG("newSmbiosTable.Type4->ProcessorVersion=%d\n", newSmbiosTable.Type4->ProcessorVersion);
//DBG("newSmbiosTable.Type4->SerialNumber=%d\n", newSmbiosTable.Type4->SerialNumber);
//DBG("newSmbiosTable.Type4->Socket=%d\n", newSmbiosTable.Type4->Socket);
//DBG("newSmbiosTable.Type4->Status=%d\n", newSmbiosTable.Type4->Status);
//DBG("newSmbiosTable.Type4->ThreadCount=%d\n", newSmbiosTable.Type4->ThreadCount);
//DBG("newSmbiosTable.Type4->ThreadCount2=%d\n", newSmbiosTable.Type4->ThreadCount2);
//DBG("newSmbiosTable.Type4->Voltage=%d\n", *(UINT8*)&newSmbiosTable.Type4->Voltage);
//#endif
2019-09-03 11:58:42 +02:00
Handle = LogSmbiosTable ( newSmbiosTable ) ;
}
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType6 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
UINT8 SizeField = 0 ;
//
// MemoryModule (TYPE 6)
// This table is obsolete accoding to Spec but Apple still using it so
// copy existing table if found, no patches will be here
// we can have more then 1 module.
2021-04-28 20:30:34 +02:00
for ( size_t Index = 0 ; Index < MAX_RAM_SLOTS ; Index + + ) {
2019-09-03 11:58:42 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_MEMORY_MODULE_INFORMATON , Index ) ;
if ( SmbiosTable . Raw = = NULL ) {
// MsgLog("SMBIOS Table 6 index %d not found\n", Index);
continue ;
}
SizeField = SmbiosTable . Type6 - > InstalledSize . InstalledOrEnabledSize & 0x7F ;
2021-10-02 19:44:16 +02:00
UINT64 mInstalled = 0 ;
2019-09-03 11:58:42 +02:00
if ( SizeField < 0x7D ) {
2021-10-02 19:44:16 +02:00
mInstalled = LShiftU64 ( 1ULL , 20 + SizeField ) ;
2019-09-03 11:58:42 +02:00
} else if ( SizeField = = 0x7F ) {
2021-10-02 19:44:16 +02:00
mInstalled = 0 ;
} else {
mInstalled = 4096ULL * ( 1024ULL * 1024ULL ) ;
}
MsgLog ( " Table 6 MEMORY_MODULE %zu Installed %llX " , Index , mInstalled ) ;
UINT64 mEnabled = 0 ;
2019-09-03 11:58:42 +02:00
if ( SizeField > = 0x7D ) {
2021-10-02 19:44:16 +02:00
mEnabled = 0 ;
} else {
mEnabled = LShiftU64 ( 1ULL , 20 + ( ( UINT8 ) SmbiosTable . Type6 - > EnabledSize . InstalledOrEnabledSize & 0x7F ) ) ;
}
MsgLog ( " ... enabled %llX \n " , mEnabled ) ;
2019-09-03 11:58:42 +02:00
LogSmbiosTable ( SmbiosTable ) ;
}
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType7 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// Cache Information
//
//TODO - should be separate table for each CPU core
//new handle for each core and attach Type4 tables for individual Type7
// Handle = 0x0700 + CoreN<<2 + CacheN (4-level cache is supported
// L1[CoreN] = Handle
2021-09-28 10:28:45 +02:00
XBool correctSD = false ;
2019-09-03 11:58:42 +02:00
//according to spec for Smbios v2.0 max handle is 0xFFFE, for v>2.0 (we made 2.6) max handle=0xFEFF.
// Value 0xFFFF means no cache
L1 = 0xFFFF ; // L1 Cache
L2 = 0xFFFF ; // L2 Cache
L3 = 0xFFFF ; // L3 Cache
// Get Table Type7 and set CPU Caches
2021-04-28 20:30:34 +02:00
for ( size_t Index = 0 ; Index < MAX_CACHE_COUNT ; Index + + ) {
2019-09-03 11:58:42 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_CACHE_INFORMATION , Index ) ;
if ( SmbiosTable . Raw = = NULL ) {
break ;
}
TableSize = SmbiosTableLength ( SmbiosTable ) ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type7 , MAX_TABLE_SIZE ) ;
CopyMem ( ( void * ) newSmbiosTable . Type7 , ( void * ) SmbiosTable . Type7 , TableSize ) ;
2019-09-03 11:58:42 +02:00
correctSD = ( newSmbiosTable . Type7 - > SocketDesignation = = 0 ) ;
CoreCache = newSmbiosTable . Type7 - > CacheConfiguration & 3 ;
2021-09-28 10:28:45 +02:00
Once = true ;
2019-09-03 11:58:42 +02:00
//SSocketD = "L1-Cache";
if ( correctSD ) {
2020-08-15 15:47:56 +02:00
XString8 SSocketD = S8Printf ( " L%c-Cache " , 0x31 + CoreCache ) ;
2019-09-03 11:58:42 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type7 - > SocketDesignation , SSocketD ) ;
}
Handle = LogSmbiosTable ( newSmbiosTable ) ;
switch ( CoreCache ) {
case 0 :
L1 = Handle ;
break ;
case 1 :
L2 = Handle ;
break ;
case 2 :
L3 = Handle ;
break ;
default :
break ;
}
}
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType9 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
//
// System Slots (Type 9)
/*
SlotDesignation : PCI1
System Slot Type : PCI
System Slot Data Bus Width : 32 bit
System Slot Current Usage : Available
System Slot Length : Short length
System Slot Type : PCI
Slot Id : the value present in the Slot Number field of the PCI Interrupt Routing table entry that is associated with this slot is : 1
Slot characteristics 1 : Provides 3.3 Volts | Slot ' s opening is shared with another slot , e . g . PCI / EISA shared slot . |
Slot characteristics 2 : PCI slot supports Power Management Enable ( PME # ) signal |
SegmentGroupNum : 0x4350
BusNum : 0x49
DevFuncNum : 0x31
Real Mac always contain Airport table 9 as
09 0 D xx xx 01 A5 08 03 03 00 00 04 06 " AirPort "
*/
//usage in macOS:
// SlotID == value of Name(_SUN, SlotID) 8bit
// SlotDesignation == name to "AAPL,slot-name"
// SlotType = 32bit PCI/SlotTypePciExpressX1/x4/x16
// real PC -> PCI, real Mac -> PCIe
2021-10-02 19:44:16 +02:00
//#ifdef JIEF_DEBUG
// for (uint8_t Index = 0; Index <= 15; Index++) {
// DBG("SlotDevice[%hhu].BusNum = %d\n", Index, smbiosSettings.SlotDevices.getSlotForIndex(Index).BusNum);
// DBG("SlotDevice[%hhu].DevFuncNum = %d\n", Index, smbiosSettings.SlotDevices.getSlotForIndex(Index).DevFuncNum);
// DBG("SlotDevice[%hhu].SegmentGroupNum = %d\n", Index, smbiosSettings.SlotDevices.getSlotForIndex(Index).SegmentGroupNum);
// DBG("SlotDevice[%hhu].SlotID = %hhd\n", Index, smbiosSettings.SlotDevices.getSlotForIndex(Index).SlotID);
// DBG("SlotDevice[%hhu].SlotType = %d\n", Index, smbiosSettings.SlotDevices.getSlotForIndex(Index).SlotType);
// DBG("SlotDevice[%hhu].SlotName = %s\n", Index, smbiosSettings.SlotDevices.getSlotForIndex(Index).SlotName.c_str());
// DBG("SlotDevice[%hhu].Valid = %d\n", Index, (bool)smbiosSettings.SlotDevices.isSlotForIndexValid(Index));
// }
//#endif
2021-04-28 20:00:28 +02:00
2021-05-08 11:34:17 +02:00
for ( uint8_t Index = 0 ; Index < 15 ; Index + + ) {
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . SlotDevices . isSlotForIndexValid ( Index ) ) {
2019-09-03 11:58:42 +02:00
INTN Dev , Func ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type9 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type9 - > Hdr . Type = EFI_SMBIOS_TYPE_SYSTEM_SLOTS ;
newSmbiosTable . Type9 - > Hdr . Length = sizeof ( SMBIOS_TABLE_TYPE9 ) ;
newSmbiosTable . Type9 - > Hdr . Handle = ( UINT16 ) ( 0x0900 + Index ) ;
newSmbiosTable . Type9 - > SlotDesignation = 1 ;
2021-05-08 11:34:17 +02:00
newSmbiosTable . Type9 - > SlotType = ( uint8_t ) smbiosSettings . SlotDevices . getSlotForIndex ( Index ) . SlotType ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type9 - > SlotDataBusWidth = SlotDataBusWidth1X ;
newSmbiosTable . Type9 - > CurrentUsage = SlotUsageAvailable ;
newSmbiosTable . Type9 - > SlotLength = SlotLengthShort ;
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type9 - > SlotID = smbiosSettings . SlotDevices . getSlotForIndex ( Index ) . SlotID ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type9 - > SlotCharacteristics1 . Provides33Volts = 1 ;
newSmbiosTable . Type9 - > SlotCharacteristics2 . HotPlugDevicesSupported = 1 ;
// take this from PCI bus for WiFi card
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type9 - > SegmentGroupNum = smbiosSettings . SlotDevices . getSlotForIndex ( Index ) . SegmentGroupNum ;
newSmbiosTable . Type9 - > BusNum = smbiosSettings . SlotDevices . getSlotForIndex ( Index ) . BusNum ;
newSmbiosTable . Type9 - > DevFuncNum = smbiosSettings . SlotDevices . getSlotForIndex ( Index ) . DevFuncNum ;
2019-09-03 11:58:42 +02:00
//
2021-04-28 20:30:34 +02:00
Dev = smbiosSettings . SlotDevices . getSlotForIndex ( Index ) . DevFuncNum > > 3 ;
Func = smbiosSettings . SlotDevices . getSlotForIndex ( Index ) . DevFuncNum & 7 ;
2020-03-25 19:32:44 +01:00
DBG ( " insert table 9 for dev %llX:%llX \n " , Dev , Func ) ;
2021-04-28 20:30:34 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type9 - > SlotDesignation , smbiosSettings . SlotDevices . getSlotForIndex ( Index ) . SlotName ) ;
2019-09-03 11:58:42 +02:00
LogSmbiosTable ( newSmbiosTable ) ;
}
}
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType11 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// CHAR8 *OEMString = "Apple inc. uses Clover"; //something else here?
// System Information
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_OEM_STRINGS , 0 ) ;
if ( SmbiosTable . Raw ! = NULL ) {
MsgLog ( " Table 11 present, but rewritten for us \n " ) ;
}
// TableSize = SmbiosTableLength(SmbiosTable);
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type11 , MAX_TABLE_SIZE ) ;
// CopyMem((void*)newSmbiosTable.Type11, (void*)SmbiosTable.Type11, 5); //minimum, other bytes = 0
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type11 - > Hdr . Type = EFI_SMBIOS_TYPE_OEM_STRINGS ;
newSmbiosTable . Type11 - > Hdr . Length = 5 ;
newSmbiosTable . Type11 - > Hdr . Handle = 0x0B00 ; //common rule
newSmbiosTable . Type11 - > StringCount = 1 ;
//
2020-08-15 15:47:56 +02:00
// ZeroMem(OEMString, MAX_OEM_STRING);
// AsciiStrCatS(OEMString, MAX_OEM_STRING, "Apple ROM Version.\n");
// //AsciiStrCatS(OEMString, MAX_OEM_STRING, " BIOS ID:");
2021-04-28 20:30:34 +02:00
// //AsciiStrnCatS(OEMString, MAX_OEM_STRING, smbiosSettings.RomVersion, iStrLen(smbiosSettings.RomVersion, 64));
2020-08-15 15:47:56 +02:00
// // AsciiStrCatS(OEMString, MAX_OEM_STRING, "\n EFI Version:");
2021-04-28 20:30:34 +02:00
// // AsciiStrnCatS(OEMString, MAX_OEM_STRING, smbiosSettings.EfiVersion, iStrLen(smbiosSettings.EfiVersion, 64));
2020-08-15 15:47:56 +02:00
// AsciiStrCatS(OEMString, MAX_OEM_STRING, " Board-ID : ");
2021-04-28 20:30:34 +02:00
// AsciiStrnCatS(OEMString, MAX_OEM_STRING, smbiosSettings.BoardNumber, iStrLen(smbiosSettings.BoardNumber, 64));
2020-08-15 15:47:56 +02:00
// snprintf(TempRev, MAX_OEM_STRING, "\n⌘ Powered by %s\n", gRevisionStr);
// AsciiStrCatS(OEMString, MAX_OEM_STRING, TempRev);
2021-04-01 10:06:53 +02:00
# ifdef JIEF_DEBUG
XString8 OEMString = S8Printf ( " ⌘ Powered by %s \n " , gBuildId . c_str ( ) ) ;
# else
2021-04-28 20:30:34 +02:00
XString8 OEMString = S8Printf ( " Apple ROM Version. \n Board-ID : %s \n ⌘ Powered by %s \n " , smbiosSettings . BoardNumber . c_str ( ) , gRevisionStr ) ;
2021-04-01 10:06:53 +02:00
# endif
2019-09-03 11:58:42 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type11 - > StringCount , OEMString ) ;
LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2020-05-15 05:23:33 +02:00
//some unused but interesting tables. Just log as is
# define NUM_OTHER_TYPES 14
const UINT8 tableTypes [ ] = { 8 , 10 , 13 , 18 , 21 , 22 , 27 , 28 , 32 , 33 , 41 , 129 , 217 , 219 } ;
2020-10-03 19:02:31 +02:00
void PatchTableTypeSome ( )
2019-09-03 11:58:42 +02:00
{
2020-05-15 05:23:33 +02:00
for ( UINTN IndexType = 0 ; IndexType < sizeof ( tableTypes ) ; IndexType + + ) {
2021-04-28 20:30:34 +02:00
for ( size_t Index = 0 ; Index < 32 ; Index + + ) {
2019-09-03 11:58:42 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , tableTypes [ IndexType ] , Index ) ;
if ( SmbiosTable . Raw = = NULL ) {
continue ;
}
LogSmbiosTable ( SmbiosTable ) ;
}
}
return ;
}
2021-04-28 20:30:34 +02:00
void GetTableType16 ( SmbiosDiscoveredSettings * smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// Physical Memory Array
//
mTotalSystemMemory = 0 ; //later we will add to the value, here initialize it
2021-04-28 20:30:34 +02:00
smbiosSettings - > RamSlotCount = 0 ;
for ( size_t Index = 0 ; Index < 8 ; Index + + ) { //how many tables there may be?
2019-09-03 11:58:42 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY , Index ) ;
if ( SmbiosTable . Raw = = NULL ) {
// DBG("SmbiosTable: Type 16 (Physical Memory Array) not found!\n");
continue ;
}
2021-04-28 20:30:34 +02:00
DBG ( " Type 16 Index = %zu \n " , Index ) ;
2021-10-02 19:44:16 +02:00
if ( SmbiosTable . Type16 - > NumberOfMemoryDevices > numeric_limits < decltype ( smbiosSettings - > RamSlotCount ) > : : max ( ) ) {
DBG ( " SmbiosTable.Type16->NumberOfMemoryDevices report too many devices (%d). Maxing out smbiosSettings->RamSlotCount to %d. \n " , SmbiosTable . Type16 - > NumberOfMemoryDevices , MAX_RAM_SLOTS ) ;
smbiosSettings - > RamSlotCount = MAX_RAM_SLOTS ;
break ;
}
if ( SmbiosTable . Type16 - > NumberOfMemoryDevices > numeric_limits < decltype ( smbiosSettings - > RamSlotCount ) > : : max ( ) - smbiosSettings - > RamSlotCount ) {
DBG ( " smbiosSettings->RamSlotCount(%d) + SmbiosTable.Type16->NumberOfMemoryDevices(%d) is too many devices. Maxing out smbiosSettings->RamSlotCount to %d. \n " , smbiosSettings - > RamSlotCount , SmbiosTable . Type16 - > NumberOfMemoryDevices , MAX_RAM_SLOTS ) ;
smbiosSettings - > RamSlotCount = MAX_RAM_SLOTS ;
break ;
}
2021-04-28 20:30:34 +02:00
smbiosSettings - > RamSlotCount + = SmbiosTable . Type16 - > NumberOfMemoryDevices ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings - > RamSlotCount = = 0 ) {
DBG ( " Total Memory Slots Count is adjusted from 0 to %d \n " , MAX_RAM_SLOTS ) ;
smbiosSettings - > RamSlotCount = MAX_RAM_SLOTS ;
} else {
//Jief_Machak: VMWare report 64 memory slots !!! MAX_RAM_SLOTS is currently 24. Crash is PatchTable17.
if ( smbiosSettings - > RamSlotCount > MAX_RAM_SLOTS ) {
DBG ( " Total Memory Slots Count is adjusted from %d to %d \n " , smbiosSettings - > RamSlotCount , MAX_RAM_SLOTS ) ;
smbiosSettings - > RamSlotCount = MAX_RAM_SLOTS ;
} else {
DBG ( " Total Memory Slots Count = %d \n " , smbiosSettings - > RamSlotCount ) ;
}
2019-09-03 11:58:42 +02:00
}
}
2021-04-28 20:30:34 +02:00
void PatchTableType16 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// Physical Memory Array
//
// Get Table Type16 and set Device Count
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_PHYSICAL_MEMORY_ARRAY , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
DBG ( " SmbiosTable: Type 16 (Physical Memory Array) not found! \n " ) ;
return ;
}
TableSize = SmbiosTableLength ( SmbiosTable ) ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type16 , MAX_TABLE_SIZE ) ;
CopyMem ( ( void * ) newSmbiosTable . Type16 , ( void * ) SmbiosTable . Type16 , TableSize ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type16 - > Hdr . Handle = mHandle16 ;
2019-11-15 13:50:12 +01:00
// Slice - I am not sure if I want these values
2019-09-03 11:58:42 +02:00
// newSmbiosTable.Type16->Location = MemoryArrayLocationProprietaryAddonCard;
// newSmbiosTable.Type16->Use = MemoryArrayUseSystemMemory;
// newSmbiosTable.Type16->MemoryErrorCorrection = MemoryErrorCorrectionMultiBitEcc;
// MemoryErrorInformationHandle
newSmbiosTable . Type16 - > MemoryErrorInformationHandle = 0xFFFF ;
2021-10-02 19:44:16 +02:00
newSmbiosTable . Type16 - > NumberOfMemoryDevices = smbiosSettings . RamSlotCount ; // RamSlotCount is <= MAX_RAM_SLOTS), see GetTableType16()
DBG ( " NumberOfMemoryDevices = %d \n " , smbiosSettings . RamSlotCount ) ;
2019-09-03 11:58:42 +02:00
LogSmbiosTable ( newSmbiosTable ) ;
}
2021-04-28 20:30:34 +02:00
void GetTableType17 ( SmbiosDiscoveredSettings * smbiosSettings )
2019-09-03 11:58:42 +02:00
{
2021-10-02 19:44:16 +02:00
//#ifdef JIEF_DEBUG
//{
// RAM_SLOT_INFO* rsiPtr = NULL;
// rsiPtr = new RAM_SLOT_INFO;
// RAM_SLOT_INFO& rsi = *rsiPtr;
// rsi.Frequency = 2587;
// rsi.ModuleSize = 8192;
// rsi.PartNo.takeValueFrom("M393A1K43BB1-CTD");
// rsi.SerialNo.takeValueFrom("24B63C90");
// rsi.SlotIndex = 0;
// rsi.Type = 17;
// rsi.Vendor.takeValueFrom("Samsung");
// gRAM.SMBIOS.AddReference(rsiPtr, true);
//}
//{
// RAM_SLOT_INFO* rsiPtr = NULL;
// rsiPtr = new RAM_SLOT_INFO;
// RAM_SLOT_INFO& rsi = *rsiPtr;
// rsi.Frequency = 2587;
// rsi.ModuleSize = 8192;
// rsi.PartNo.takeValueFrom("M393A1K43BB1-CTD");
// rsi.SerialNo.takeValueFrom("24B63C91");
// rsi.SlotIndex = 1;
// rsi.Type = 17;
// rsi.Vendor.takeValueFrom("Samsung");
// gRAM.SMBIOS.AddReference(rsiPtr, true);
//}
// DBG("JIEF_DEBUG : force memory modules\n");
// return;
//#endif
2019-09-03 11:58:42 +02:00
// Memory Device
//
2021-10-02 19:44:16 +02:00
XBool FoundOneTable ;
2019-09-03 11:58:42 +02:00
// Get Table Type17 and count Size
2021-04-28 20:30:34 +02:00
for ( size_t Index = 0 ; Index < smbiosSettings - > RamSlotCount ; Index + + ) { //how many tables there may be?
2019-09-03 11:58:42 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_MEMORY_DEVICE , Index ) ;
if ( SmbiosTable . Raw = = NULL ) {
// DBG("SmbiosTable: Type 17 (Memory Device number %d) not found!\n", Index);
continue ;
}
2021-10-02 19:44:16 +02:00
FoundOneTable = true ;
//#ifndef JIEF_DEBUG // it's all 0 in VMWare
2021-04-28 20:30:34 +02:00
DBG ( " Type 17 Index = %zu \n " , Index ) ;
2021-10-02 19:44:16 +02:00
//#endif
2019-09-03 11:58:42 +02:00
//gDMI->CntMemorySlots++;
if ( SmbiosTable . Type17 - > MemoryErrorInformationHandle < 0xFFFE ) {
DBG ( " Table has error information, checking \n " ) ; //why skipping?
// Why trust it if it has an error? I guess we could look
// up the error handle and determine certain errors may
// be skipped where others may not but it seems easier
// to just skip all entries that have an error - apianti
// will try
2021-10-02 19:44:16 +02:00
XBool Found = false ;
2020-05-15 05:23:33 +02:00
for ( INTN Index2 = 0 ; Index2 < 24 ; Index2 + + ) {
2019-09-03 11:58:42 +02:00
newSmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_32BIT_MEMORY_ERROR_INFORMATION , Index2 ) ;
if ( newSmbiosTable . Raw = = NULL ) {
continue ;
}
if ( newSmbiosTable . Type18 - > Hdr . Handle = = SmbiosTable . Type17 - > MemoryErrorInformationHandle ) {
2021-09-28 10:28:45 +02:00
Found = true ;
2020-04-09 19:01:23 +02:00
DBG ( " Found memory information in table 18/%lld, type=0x%X, operation=0x%X syndrome=0x%X \n " , Index2 ,
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type18 - > ErrorType ,
newSmbiosTable . Type18 - > ErrorOperation ,
newSmbiosTable . Type18 - > VendorSyndrome ) ;
switch ( newSmbiosTable . Type18 - > ErrorType ) {
case MemoryErrorOk :
DBG ( " ...memory OK \n " ) ;
break ;
case MemoryErrorCorrected :
DBG ( " ...memory errors corrected \n " ) ;
break ;
case MemoryErrorChecksum :
DBG ( " ...error type: Checksum \n " ) ;
break ;
default :
DBG ( " ...error type not shown \n " ) ;
break ;
}
break ;
}
}
if ( Found ) {
if ( ( newSmbiosTable . Type18 - > ErrorType ! = MemoryErrorOk ) & &
( newSmbiosTable . Type18 - > ErrorType ! = MemoryErrorCorrected ) ) {
DBG ( " skipping wrong module \n " ) ;
continue ;
}
}
}
2021-10-02 19:44:16 +02:00
RAM_SLOT_INFO * rsiPtr = NULL ;
2019-09-03 11:58:42 +02:00
// Determine if slot has size
if ( SmbiosTable . Type17 - > Size > 0 ) {
2021-10-02 19:44:16 +02:00
rsiPtr = new RAM_SLOT_INFO ;
RAM_SLOT_INFO & rsi = * rsiPtr ;
rsi . ModuleSize = SmbiosTable . Type17 - > Size ;
2019-11-15 13:17:19 +01:00
if ( SmbiosTable . Type17 - > Size = = 0x7FFF ) {
2021-10-02 19:44:16 +02:00
rsi . ModuleSize = SmbiosTable . Type17 - > ExtendedSize ;
2019-11-15 13:17:19 +01:00
}
2019-09-03 11:58:42 +02:00
}
// Determine if module frequency is sane value
if ( ( SmbiosTable . Type17 - > Speed > 0 ) & & ( SmbiosTable . Type17 - > Speed < = MAX_RAM_FREQUENCY ) ) {
2021-10-02 19:44:16 +02:00
if ( rsiPtr = = NULL ) rsiPtr = new RAM_SLOT_INFO ;
RAM_SLOT_INFO & rsi = * rsiPtr ;
rsi . Frequency = SmbiosTable . Type17 - > Speed ;
2019-09-03 11:58:42 +02:00
if ( SmbiosTable . Type17 - > Speed > gRAM . Frequency ) {
gRAM . Frequency = SmbiosTable . Type17 - > Speed ;
}
} else {
2020-11-12 22:25:56 +01:00
# ifndef JIEF_DEBUG // always the case in VMWare
2019-09-03 11:58:42 +02:00
DBG ( " Ignoring insane frequency value %dMHz \n " , SmbiosTable . Type17 - > Speed ) ;
2020-11-12 22:25:56 +01:00
# endif
2019-09-03 11:58:42 +02:00
}
// Fill rest of information if in use
2021-10-02 19:44:16 +02:00
if ( rsiPtr ! = NULL ) {
//++(gRAM.SMBIOSInUse);
RAM_SLOT_INFO & rsi = * rsiPtr ;
rsi . SlotIndex = Index ;
rsi . Vendor . takeValueFrom ( GetSmbiosString ( SmbiosTable , SmbiosTable . Type17 - > Manufacturer ) ) ;
rsi . Vendor . trim ( ) ;
rsi . SerialNo . takeValueFrom ( GetSmbiosString ( SmbiosTable , SmbiosTable . Type17 - > SerialNumber ) ) ;
rsi . SerialNo . trim ( ) ;
rsi . PartNo . takeValueFrom ( GetSmbiosString ( SmbiosTable , SmbiosTable . Type17 - > PartNumber ) ) ;
rsi . PartNo . trim ( ) ;
gRAM . SMBIOS . AddReference ( rsiPtr , true ) ;
DBG ( " SmbiosTable.Type17->SlotIndex = %d \n " , rsi . SlotIndex ) ;
DBG ( " SmbiosTable.Type17->ModuleSize = %dMB \n " , rsi . ModuleSize ) ;
2021-10-03 08:53:30 +02:00
DBG ( " SmbiosTable.Type17->Type = %d \n " , rsi . Type ) ;
2021-10-02 19:44:16 +02:00
DBG ( " SmbiosTable.Type17->Frequency = %dMHz \n " , rsi . Frequency ) ;
2020-08-25 17:35:19 +02:00
DBG ( " SmbiosTable.Type17->Bank/Device = %s %s \n " , GetSmbiosString ( SmbiosTable , SmbiosTable . Type17 - > BankLocator ) , GetSmbiosString ( SmbiosTable , SmbiosTable . Type17 - > DeviceLocator ) ) ;
2021-10-02 19:44:16 +02:00
DBG ( " SmbiosTable.Type17->Vendor = %s \n " , rsi . Vendor . c_str ( ) ) ;
DBG ( " SmbiosTable.Type17->SerialNo = %s \n " , rsi . SerialNo . c_str ( ) ) ;
DBG ( " SmbiosTable.Type17->PartNo = %s \n " , rsi . PartNo . c_str ( ) ) ;
2020-08-25 17:35:19 +02:00
}
2019-09-03 11:58:42 +02:00
/*
if ( ( SmbiosTable . Type17 - > Size & 0x8000 ) = = 0 ) {
mTotalSystemMemory + = SmbiosTable . Type17 - > Size ; //Mb
2021-10-02 19:44:16 +02:00
m Memory17 [ Index ] = ( UINT16 ) ( SmbiosTable . Type17 - > Size > 0 ? mTotalSystemMemory : 0 ) ;
2019-09-03 11:58:42 +02:00
}
DBG ( " mTotalSystemMemory = %d \n " , mTotalSystemMemory ) ;
*/
}
2021-10-02 19:44:16 +02:00
if ( ! FoundOneTable ) {
DBG ( " No table 17 found \n " ) ;
}
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
void PatchTableType17 ( const SmbiosInjectedSettings & smbiosSettings , XArray < UINT16 > * mMemory17Ptr , XArray < UINT16 > * mHandle17Ptr )
2019-09-03 11:58:42 +02:00
{
2021-10-02 19:44:16 +02:00
XArray < UINT16 > & mMemory17 = * mMemory17Ptr ;
XArray < UINT16 > & mHandle17 = * mHandle17Ptr ;
2020-08-15 15:47:56 +02:00
XString8 deviceLocator ;
XString8 bankLocator ;
2021-10-02 19:44:16 +02:00
UINT8 channelMap [ mMemory17 . size ( ) ] ; // mMemory17.size() == SlotCounts
2019-09-03 11:58:42 +02:00
UINT8 expectedCount = 0 ;
UINT8 channels = 2 ;
2021-09-28 10:28:45 +02:00
XBool insertingEmpty = true ;
2021-10-02 19:44:16 +02:00
XBool trustSMBIOS = ( gRAM . SPD . size ( ) = = 0 | | smbiosSettings . TrustSMBIOS ) ;
2021-09-28 10:28:45 +02:00
XBool wrongSMBIOSBanks = false ;
XBool isMacPro = false ;
2021-10-02 19:44:16 +02:00
2021-10-18 21:06:19 +02:00
MacModel Model = GetModelFromString ( smbiosSettings . ProductName ) ;
2021-10-02 19:44:16 +02:00
if ( ( Model = = MacPro31 ) | | ( Model = = MacPro41 ) | | ( Model = = MacPro51 ) | | ( Model = = MacPro61 ) | | ( Model = = MacPro71 ) ) {
2021-09-28 10:28:45 +02:00
isMacPro = true ;
2019-09-03 11:58:42 +02:00
}
// Inject user memory tables
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . InjectMemoryTables )
{
2019-09-03 11:58:42 +02:00
DBG ( " Injecting user memory modules to SMBIOS \n " ) ;
2021-10-02 19:44:16 +02:00
if ( smbiosSettings . Memory . _User . size ( ) = = 0 ) {
2019-09-03 11:58:42 +02:00
DBG ( " User SMBIOS contains no memory modules \n " ) ;
return ;
}
// Check channels
2021-04-28 20:30:34 +02:00
auto UserChannels = smbiosSettings . Memory . UserChannels ;
if ( UserChannels = = 0 | | UserChannels > 8 ) {
UserChannels = 1 ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
DBG ( " Channels: %d \n " , UserChannels ) ;
2019-09-03 11:58:42 +02:00
// Setup interleaved channel map
if ( channels > = 2 ) {
2021-04-28 20:30:34 +02:00
UINT8 doubleChannels = ( UINT8 ) UserChannels < < 1 ;
2021-10-02 19:44:16 +02:00
for ( size_t Index = 0 ; Index < mMemory17 . size ( ) ; + + Index ) {
2019-09-03 11:58:42 +02:00
channelMap [ Index ] = ( UINT8 ) ( ( ( Index / doubleChannels ) * doubleChannels ) +
2021-04-28 20:30:34 +02:00
( ( Index / UserChannels ) % 2 ) + ( ( Index % UserChannels ) < < 1 ) ) ;
2019-09-03 11:58:42 +02:00
}
} else {
2021-10-02 19:44:16 +02:00
for ( size_t Index = 0 ; Index < mMemory17 . size ( ) ; + + Index ) {
2019-09-03 11:58:42 +02:00
channelMap [ Index ] = ( UINT8 ) Index ;
}
}
DBG ( " Interleave: " ) ;
2021-10-02 19:44:16 +02:00
for ( size_t Index = 0 ; Index < mMemory17 . size ( ) ; + + Index ) {
2019-09-03 11:58:42 +02:00
DBG ( " %d " , channelMap [ Index ] ) ;
}
DBG ( " \n " ) ;
// Memory Device
//
// Inject tables
2021-10-02 19:44:16 +02:00
DBG ( " user SMBIOS data: \n " ) ;
DBG ( " smbiosSettings.RamSlotCount=%d \n " , smbiosSettings . RamSlotCount ) ;
DBG ( " smbiosSettings.Memory.SlotCounts=%d \n " , smbiosSettings . Memory . SlotCount ) ;
DBG ( " smbiosSettings.Memory.UserChannels=%d \n " , smbiosSettings . Memory . UserChannels ) ;
for ( size_t Index = 0 ; Index < smbiosSettings . RamSlotCount ; Index + + ) {
if ( smbiosSettings . Memory . doesSlotForIndexExist ( Index ) ) {
DBG ( " smbiosSettings.Memory slot %zu \n " , Index ) ;
DBG ( " smbiosSettings.Memory[%zu].ModuleSize=%d \n " , Index , smbiosSettings . Memory . getSlotInfoForSlotID ( Index ) . ModuleSize ) ;
DBG ( " smbiosSettings.Memory[%zu].Type=%d \n " , Index , smbiosSettings . Memory . getSlotInfoForSlotID ( Index ) . Type ) ;
DBG ( " smbiosSettings.Memory[%zu].Frequency=%d \n " , Index , smbiosSettings . Memory . getSlotInfoForSlotID ( Index ) . Frequency ) ;
DBG ( " smbiosSettings.Memory[%zu].Vendor=%s \n " , Index , smbiosSettings . Memory . getSlotInfoForSlotID ( Index ) . Vendor . c_str ( ) ) ;
DBG ( " smbiosSettings.Memory[%zu].PartNo=%s \n " , Index , smbiosSettings . Memory . getSlotInfoForSlotID ( Index ) . PartNo . c_str ( ) ) ;
DBG ( " smbiosSettings.Memory[%zu].SerialNo=%s \n " , Index , smbiosSettings . Memory . getSlotInfoForSlotID ( Index ) . SerialNo . c_str ( ) ) ;
} else {
DBG ( " smbiosSettings.Memory slot %zu is not defined \n " , Index ) ;
}
}
2021-04-28 20:30:34 +02:00
2021-10-02 19:44:16 +02:00
for ( size_t Index = 0 ; Index < mMemory17 . size ( ) ; Index + + ) {
2019-09-03 11:58:42 +02:00
UINTN UserIndex = channelMap [ Index ] ;
2021-04-28 20:30:34 +02:00
UINT8 bank = ( UINT8 ) ( Index / UserChannels ) ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type17 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type17 - > Hdr . Type = EFI_SMBIOS_TYPE_MEMORY_DEVICE ;
newSmbiosTable . Type17 - > Hdr . Length = sizeof ( SMBIOS_TABLE_TYPE17 ) ;
newSmbiosTable . Type17 - > TotalWidth = 0xFFFF ;
newSmbiosTable . Type17 - > DataWidth = 0xFFFF ;
newSmbiosTable . Type17 - > Hdr . Handle = ( UINT16 ) ( 0x1100 + UserIndex ) ;
2020-02-27 13:06:01 +01:00
newSmbiosTable . Type17 - > FormFactor = ( UINT8 ) ( gMobile ? MemoryFormFactorSodimm : MemoryFormFactorDimm ) ;
2021-09-28 10:28:45 +02:00
newSmbiosTable . Type17 - > TypeDetail . Synchronous = true ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type17 - > DeviceSet = bank + 1 ;
newSmbiosTable . Type17 - > MemoryArrayHandle = mHandle16 ;
if ( isMacPro ) {
2021-04-28 20:30:34 +02:00
deviceLocator . S8Printf ( " DIMM%zd " , Index + 1 ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-08-15 15:47:56 +02:00
deviceLocator . S8Printf ( " DIMM%d " , bank ) ;
2021-04-28 20:30:34 +02:00
bankLocator . S8Printf ( " BANK %zu " , Index % channels ) ;
2020-08-15 15:47:56 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > BankLocator , bankLocator ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-15 15:47:56 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > DeviceLocator , deviceLocator ) ;
2021-10-02 19:44:16 +02:00
if ( smbiosSettings . Memory . doesSlotForIndexExist ( UserIndex ) & & smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . ModuleSize > 0 )
{
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . Vendor . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > Manufacturer , smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . Vendor ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-04-09 19:01:23 +02:00
2020-02-17 21:41:09 +01:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > Manufacturer , unknown ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . SerialNo . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > SerialNumber , smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . SerialNo ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-02-17 21:41:09 +01:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > SerialNumber , unknown ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . PartNo . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > PartNumber , smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . PartNo ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-02-17 21:41:09 +01:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > PartNumber , unknown ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type17 - > Speed = ( UINT16 ) smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . Frequency ;
if ( smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . ModuleSize > 0x7FFF ) {
2019-11-23 16:33:01 +01:00
newSmbiosTable . Type17 - > Size = 0x7FFF ;
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type17 - > ExtendedSize = smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . ModuleSize ;
2019-12-23 17:46:07 +01:00
mTotalSystemMemory + = newSmbiosTable . Type17 - > ExtendedSize ; //Mb
2019-11-23 16:33:01 +01:00
} else {
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type17 - > Size = ( UINT16 ) smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . ModuleSize ;
2019-12-23 17:46:07 +01:00
mTotalSystemMemory + = newSmbiosTable . Type17 - > Size ; //Mb
2019-11-23 16:33:01 +01:00
}
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type17 - > MemoryType = smbiosSettings . Memory . getSlotInfoForSlotID ( UserIndex ) . Type ;
2019-09-03 11:58:42 +02:00
if ( ( newSmbiosTable . Type17 - > MemoryType ! = MemoryTypeDdr2 ) & &
( newSmbiosTable . Type17 - > MemoryType ! = MemoryTypeDdr4 ) & &
( newSmbiosTable . Type17 - > MemoryType ! = MemoryTypeDdr ) ) {
newSmbiosTable . Type17 - > MemoryType = MemoryTypeDdr3 ;
}
2020-08-15 15:47:56 +02:00
DBG ( " %s %s %dMHz %dMB(Ext:%dMB) \n " , bankLocator . c_str ( ) , deviceLocator . c_str ( ) , newSmbiosTable . Type17 - > Speed ,
2019-11-23 16:33:01 +01:00
newSmbiosTable . Type17 - > Size , newSmbiosTable . Type17 - > ExtendedSize ) ;
2021-04-28 20:30:34 +02:00
mMemory17 [ Index ] = ( UINT16 ) mTotalSystemMemory ;
2019-09-03 11:58:42 +02:00
// DBG("mTotalSystemMemory = %d\n", mTotalSystemMemory);
} else {
2020-08-15 15:47:56 +02:00
DBG ( " %s %s EMPTY \n " , bankLocator . c_str ( ) , deviceLocator . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
}
newSmbiosTable . Type17 - > MemoryErrorInformationHandle = 0xFFFF ;
2021-04-28 20:30:34 +02:00
mHandle17 [ Index ] = LogSmbiosTable ( newSmbiosTable ) ;
2019-09-03 11:58:42 +02:00
}
if ( mTotalSystemMemory > 0 ) {
DBG ( " mTotalSystemMemory = %d \n " , mTotalSystemMemory ) ;
}
return ;
2021-10-02 19:44:16 +02:00
} else {
DBG ( " Do not inject memory table \n " ) ;
2019-09-03 11:58:42 +02:00
}
// Prevent inserting empty tables
2021-10-02 19:44:16 +02:00
if ( ( gRAM . SPD . size ( ) = = 0 ) & & ( gRAM . SMBIOS . size ( ) = = 0 ) ) {
2019-09-03 11:58:42 +02:00
DBG ( " SMBIOS and SPD contain no modules in use \n " ) ;
return ;
}
// Detect whether the SMBIOS is trusted information
if ( trustSMBIOS ) {
2021-10-02 19:44:16 +02:00
if ( gRAM . SMBIOS . size ( ) ! = 0 ) {
if ( gRAM . SPD . size ( ) ! = 0 ) {
if ( gRAM . SPD . size ( ) ! = gRAM . SMBIOS . size ( ) ) {
2019-09-03 11:58:42 +02:00
// Prefer the SPD information
2021-10-02 19:44:16 +02:00
if ( gRAM . SPD . size ( ) > gRAM . SMBIOS . size ( ) ) {
2019-09-03 11:58:42 +02:00
DBG ( " Not trusting SMBIOS because SPD reports more modules... \n " ) ;
2021-09-28 10:28:45 +02:00
trustSMBIOS = false ;
2021-10-02 19:44:16 +02:00
} else if ( gRAM . SPD . doesSlotForIndexExist ( 0 ) | | ! gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) ) {
if ( gRAM . SPD . size ( ) > 1 ) {
2019-09-03 11:58:42 +02:00
DBG ( " Not trusting SMBIOS because SPD reports different modules... \n " ) ;
2021-09-28 10:28:45 +02:00
trustSMBIOS = false ;
2021-10-02 19:44:16 +02:00
} else if ( gRAM . SMBIOS . size ( ) = = 1 ) {
2019-09-03 11:58:42 +02:00
channels = 1 ;
}
2021-10-02 19:44:16 +02:00
} else if ( gRAM . SPD . size ( ) = = 1 ) {
2019-09-03 11:58:42 +02:00
// The SMBIOS may contain table for built-in module
2021-10-02 19:44:16 +02:00
if ( gRAM . SMBIOS . size ( ) < = 2 ) {
if ( ! gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) | | ! gRAM . SPD . doesSlotForIndexExist ( 2 ) | |
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . Frequency ! = gRAM . SPD . getSlotInfoForSlotIndex ( 2 ) . Frequency ) | |
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize ! = gRAM . SPD . getSlotInfoForSlotIndex ( 2 ) . ModuleSize ) ) {
2019-09-03 11:58:42 +02:00
channels = 1 ;
}
} else {
DBG ( " Not trusting SMBIOS because SPD reports only one module... \n " ) ;
2021-09-28 10:28:45 +02:00
trustSMBIOS = false ;
2019-09-03 11:58:42 +02:00
}
} else {
DBG ( " Not trusting SMBIOS because SPD reports less modules... \n " ) ;
2021-09-28 10:28:45 +02:00
trustSMBIOS = false ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
} else if ( gRAM . SPD . doesSlotForIndexExist ( 0 ) ! = gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) ) {
2019-09-03 11:58:42 +02:00
// Never trust a sneaky SMBIOS!
DBG ( " Not trusting SMBIOS because it's being sneaky... \n " ) ;
2021-09-28 10:28:45 +02:00
trustSMBIOS = false ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
} else if ( gRAM . SMBIOS . size ( ) = = 1 ) {
2019-09-03 11:58:42 +02:00
channels = 1 ;
}
}
}
if ( trustSMBIOS ) {
DBG ( " Trusting SMBIOS... \n " ) ;
}
// Determine expected slot count
2021-10-02 19:44:16 +02:00
expectedCount = ( smbiosSettings . RamSlotCount ! = 0 ) ? smbiosSettings . RamSlotCount : gRAM . SPD . getSlotCount ( ) ;
2019-09-03 11:58:42 +02:00
if ( trustSMBIOS ) {
// Use the smbios in use count
2021-10-02 19:44:16 +02:00
if ( expectedCount < gRAM . SMBIOS . getSlotCount ( ) ) {
expectedCount = gRAM . SMBIOS . getSlotCount ( ) ;
2019-09-03 11:58:42 +02:00
}
// Check if smbios has a good total count
2021-04-28 20:30:34 +02:00
if ( ( ! gMobile | | smbiosSettings . RamSlotCount = = 2 ) & & expectedCount < smbiosSettings . RamSlotCount ) {
if ( smbiosSettings . RamSlotCount > MAX_UINT8 ) {
log_technical_bug ( " smbiosSettings.RamSlotCount > MAX_UINT8 " ) ;
expectedCount = MAX_RAM_SLOTS ;
} else {
expectedCount = ( UINT8 ) smbiosSettings . RamSlotCount ;
}
2019-09-03 11:58:42 +02:00
}
} else {
// Use default value of two for mobile or four for desktop
if ( gMobile ) {
if ( expectedCount < 2 ) {
expectedCount = 2 ;
}
} else if ( expectedCount < 4 ) {
expectedCount = 4 ;
}
}
// Check for interleaved channels
if ( channels > = 2 ) {
2021-10-02 19:44:16 +02:00
wrongSMBIOSBanks = ( ( gRAM . SMBIOS . doesSlotForIndexExist ( 1 ) ! = gRAM . SPD . doesSlotForIndexExist ( 1 ) ) | |
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 1 ) . ModuleSize ! = gRAM . SPD . getSlotInfoForSlotIndex ( 1 ) . ModuleSize ) ) ;
2019-09-03 11:58:42 +02:00
}
if ( wrongSMBIOSBanks ) {
DBG ( " Detected alternating SMBIOS channel banks \n " ) ;
}
// Determine if using triple or quadruple channel
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Memory . UserChannels ! = 0 ) {
channels = smbiosSettings . Memory . UserChannels ;
2021-10-02 19:44:16 +02:00
} else if ( gRAM . SPD . size ( ) = = 0 ) {
2019-09-03 11:58:42 +02:00
if ( trustSMBIOS ) {
2021-10-02 19:44:16 +02:00
if ( ( gRAM . SMBIOS . size ( ) % 4 ) = = 0 ) {
2019-09-03 11:58:42 +02:00
// Quadruple channel
if ( ( wrongSMBIOSBanks & &
2021-10-02 19:44:16 +02:00
( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 1 ) ) & &
( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 2 ) ) & &
( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 3 ) ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 1 ) . ModuleSize ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 2 ) . ModuleSize ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 3 ) . ModuleSize ) ) | |
( ( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 2 ) ) & &
( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 4 ) ) & &
( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 6 ) ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 2 ) . ModuleSize ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 4 ) . ModuleSize ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 6 ) . ModuleSize ) ) ) {
2019-09-03 11:58:42 +02:00
channels = 4 ;
}
2021-10-02 19:44:16 +02:00
} else if ( ( gRAM . SMBIOS . size ( ) % 3 ) = = 0 ) {
2019-09-03 11:58:42 +02:00
// Triple channel
if ( ( wrongSMBIOSBanks & &
2021-10-02 19:44:16 +02:00
( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 1 ) ) & &
( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 2 ) ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 1 ) . ModuleSize ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 2 ) . ModuleSize ) ) | |
( ( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 2 ) ) & &
( gRAM . SMBIOS . doesSlotForIndexExist ( 0 ) = = gRAM . SMBIOS . doesSlotForIndexExist ( 4 ) ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 2 ) . ModuleSize ) & &
( gRAM . SMBIOS . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SMBIOS . getSlotInfoForSlotIndex ( 4 ) . ModuleSize ) ) ) {
2019-09-03 11:58:42 +02:00
channels = 3 ;
}
2021-10-02 19:44:16 +02:00
} else if ( ! wrongSMBIOSBanks & & ( ( gRAM . SMBIOS . size ( ) % 2 ) ! = 0 ) ) {
2019-09-03 11:58:42 +02:00
channels = 1 ;
}
}
2021-10-02 19:44:16 +02:00
} else if ( ( gRAM . SPD . size ( ) % 4 ) = = 0 ) {
2019-09-03 11:58:42 +02:00
// Quadruple channel
2021-10-02 19:44:16 +02:00
if ( ( gRAM . SPD . doesSlotForIndexExist ( 0 ) = = gRAM . SPD . doesSlotForIndexExist ( 2 ) ) & &
( gRAM . SPD . doesSlotForIndexExist ( 0 ) = = gRAM . SPD . doesSlotForIndexExist ( 4 ) ) & &
( gRAM . SPD . doesSlotForIndexExist ( 0 ) = = gRAM . SPD . doesSlotForIndexExist ( 6 ) ) & &
( gRAM . SPD . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SPD . getSlotInfoForSlotIndex ( 2 ) . ModuleSize ) & &
( gRAM . SPD . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SPD . getSlotInfoForSlotIndex ( 4 ) . ModuleSize ) & &
( gRAM . SPD . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SPD . getSlotInfoForSlotIndex ( 6 ) . ModuleSize ) ) {
2019-09-03 11:58:42 +02:00
channels = 4 ;
}
2021-10-02 19:44:16 +02:00
} else if ( ( gRAM . SPD . size ( ) % 3 ) = = 0 ) {
2019-09-03 11:58:42 +02:00
// Triple channel
2021-10-02 19:44:16 +02:00
if ( ( gRAM . SPD . doesSlotForIndexExist ( 0 ) = = gRAM . SPD . doesSlotForIndexExist ( 2 ) ) & &
( gRAM . SPD . doesSlotForIndexExist ( 0 ) = = gRAM . SPD . doesSlotForIndexExist ( 4 ) ) & &
( gRAM . SPD . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SPD . getSlotInfoForSlotIndex ( 2 ) . ModuleSize ) & &
( gRAM . SPD . getSlotInfoForSlotIndex ( 0 ) . ModuleSize = = gRAM . SPD . getSlotInfoForSlotIndex ( 4 ) . ModuleSize ) ) {
2019-09-03 11:58:42 +02:00
channels = 3 ;
}
2021-10-02 19:44:16 +02:00
} else if ( ( gRAM . SPD . doesSlotForIndexExist ( 0 ) ! = gRAM . SPD . doesSlotForIndexExist ( 2 ) ) | |
( ( gRAM . SPD . size ( ) % 2 ) ! = 0 ) ) {
2019-09-03 11:58:42 +02:00
channels = 1 ;
}
// Can't have less than the number of channels
if ( expectedCount < channels ) {
expectedCount = channels ;
}
if ( expectedCount > 0 ) {
- - expectedCount ;
}
DBG ( " Channels: %d \n " , channels ) ;
// Setup interleaved channel map
if ( channels > = 2 ) {
UINT8 doubleChannels = ( UINT8 ) channels < < 1 ;
2021-10-02 19:44:16 +02:00
for ( size_t Index = 0 ; Index < mMemory17 . size ( ) ; + + Index ) {
2019-09-03 11:58:42 +02:00
channelMap [ Index ] = ( UINT8 ) ( ( ( Index / doubleChannels ) * doubleChannels ) +
( ( Index / channels ) % 2 ) + ( ( Index % channels ) < < 1 ) ) ;
}
} else {
2021-10-02 19:44:16 +02:00
for ( size_t Index = 0 ; Index < mMemory17 . size ( ) ; + + Index ) {
2019-09-03 11:58:42 +02:00
channelMap [ Index ] = ( UINT8 ) Index ;
}
}
DBG ( " Interleave: " ) ;
2021-10-02 19:44:16 +02:00
for ( size_t Index = 0 ; Index < mMemory17 . size ( ) ; + + Index ) {
2019-09-03 11:58:42 +02:00
DBG ( " %d " , channelMap [ Index ] ) ;
}
DBG ( " \n " ) ;
// Memory Device
//
2021-10-02 19:44:16 +02:00
for ( size_t Index = 0 ; Index < mMemory17 . size ( ) ; Index + + ) {
size_t SMBIOSIndex = wrongSMBIOSBanks ? Index : channelMap [ Index ] ;
size_t SPDIndex = channelMap [ Index ] ;
2019-09-03 11:58:42 +02:00
UINT8 bank = ( UINT8 ) Index / channels ;
2021-04-28 20:30:34 +02:00
if ( ! insertingEmpty & & ( Index > expectedCount ) & &
2021-10-02 19:44:16 +02:00
! gRAM . SPD . doesSlotForIndexExist ( SPDIndex ) & & ( ! trustSMBIOS | | ! gRAM . SMBIOS . doesSlotForIndexExist ( SMBIOSIndex ) ) ) {
2019-09-03 11:58:42 +02:00
continue ;
}
2020-04-10 09:15:36 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_MEMORY_DEVICE , SMBIOSIndex ) ;
2021-10-02 19:44:16 +02:00
if ( trustSMBIOS & & gRAM . SMBIOS . doesSlotForIndexExist ( SMBIOSIndex ) & & ( SmbiosTable . Raw ! = NULL ) ) {
DBG ( " trusted SMBIOS data, table index %zu: \n " , SMBIOSIndex ) ;
DBG ( " gRAM.SMBIOS[%zu]->ModuleSize = %d \n " , SMBIOSIndex , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . ModuleSize ) ;
DBG ( " gRAM.SMBIOS[%zu]->Type = %d \n " , SMBIOSIndex , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Type ) ;
DBG ( " gRAM.SMBIOS[%zu]->Frequency = %d \n " , SMBIOSIndex , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Frequency ) ;
DBG ( " gRAM.SMBIOS[%zu]->Vendor = %s \n " , SMBIOSIndex , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Vendor . c_str ( ) ) ;
DBG ( " gRAM.SMBIOS[%zu]->PartNo = %s \n " , SMBIOSIndex , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . PartNo . c_str ( ) ) ;
DBG ( " gRAM.SMBIOS[%zu]->SerialNo = %s \n " , SMBIOSIndex , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . SerialNo . c_str ( ) ) ;
2020-04-10 09:15:36 +02:00
2019-09-03 11:58:42 +02:00
TableSize = SmbiosTableLength ( SmbiosTable ) ;
2020-10-03 19:02:31 +02:00
CopyMem ( ( void * ) newSmbiosTable . Type17 , ( void * ) SmbiosTable . Type17 , TableSize ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type17 - > AssetTag = 0 ;
2021-10-02 19:44:16 +02:00
if ( gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Vendor . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > Manufacturer , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Vendor ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-02-17 21:41:09 +01:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > Manufacturer , unknown ) ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
if ( gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . SerialNo . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > SerialNumber , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . SerialNo ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-02-17 21:41:09 +01:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > SerialNumber , unknown ) ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
if ( gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . PartNo . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > PartNumber , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . PartNo ) ;
//DBG(" Update PartNumber to %s\n", gRAM.SMBIOS.getSlotInfoForSlotIndex(SMBIOSIndex).PartNo.c_str());
2019-09-03 11:58:42 +02:00
} else {
// newSmbiosTable.Type17->PartNumber = 0;
2021-10-02 19:44:16 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > PartNumber , unknown ) ;
//DBG(" Set PartNumber unknown\n");
2019-09-03 11:58:42 +02:00
}
} else {
2021-10-02 19:44:16 +02:00
DBG ( " !trusted SMBIOS data, Table index %zu: " , SMBIOSIndex ) ;
if ( ! trustSMBIOS ) DBG ( " !trustSMBIOS " ) ;
if ( ! gRAM . SMBIOS . doesSlotForIndexExist ( SMBIOSIndex ) ) DBG ( " !gRAM.SMBIOS.doesSlotForIndexExist(SMBIOSIndex) " ) ;
if ( SmbiosTable . Raw = = NULL ) DBG ( " SmbiosTable.Raw == NULL " ) ;
DBG ( " \n " ) ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type17 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type17 - > Hdr . Type = EFI_SMBIOS_TYPE_MEMORY_DEVICE ;
newSmbiosTable . Type17 - > Hdr . Length = sizeof ( SMBIOS_TABLE_TYPE17 ) ;
newSmbiosTable . Type17 - > TotalWidth = 0xFFFF ;
newSmbiosTable . Type17 - > DataWidth = 0xFFFF ;
}
2021-09-28 10:28:45 +02:00
Once = true ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type17 - > Hdr . Handle = ( UINT16 ) ( 0x1100 + Index ) ;
2020-02-27 13:06:01 +01:00
newSmbiosTable . Type17 - > FormFactor = ( UINT8 ) ( gMobile ? MemoryFormFactorSodimm : MemoryFormFactorDimm ) ;
2021-09-28 10:28:45 +02:00
newSmbiosTable . Type17 - > TypeDetail . Synchronous = true ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type17 - > DeviceSet = bank + 1 ;
newSmbiosTable . Type17 - > MemoryArrayHandle = mHandle16 ;
2021-10-02 19:44:16 +02:00
if ( gRAM . SPD . doesSlotForIndexExist ( SPDIndex ) ) {
2020-04-10 09:15:36 +02:00
DBG ( " SPD data in use: \n " ) ;
2021-10-02 19:44:16 +02:00
DBG ( " gRAM.SPD[%zu]->ModuleSize = %d \n " , SPDIndex , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . ModuleSize ) ;
DBG ( " gRAM.SPD[%zu]->Type = %d \n " , SPDIndex , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Type ) ;
DBG ( " gRAM.SPD[%zu]->Frequency = %d \n " , SPDIndex , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Frequency ) ;
DBG ( " gRAM.SPD[%zu]->Vendor = %s \n " , SPDIndex , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Vendor . c_str ( ) ) ;
DBG ( " gRAM.SPD[%zu]->SerialNo = %s \n " , SPDIndex , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . SerialNo . c_str ( ) ) ;
DBG ( " gRAM.SPD[%zu]->PartNo = %s \n " , SPDIndex , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . PartNo . c_str ( ) ) ;
if ( gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Vendor . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > Manufacturer , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Vendor ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-02-17 21:41:09 +01:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > Manufacturer , unknown ) ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
if ( gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . SerialNo . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > SerialNumber , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . SerialNo ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-02-17 21:41:09 +01:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > SerialNumber , unknown ) ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
if ( gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . PartNo . notEmpty ( ) ) {
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > PartNumber , gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . PartNo ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-02-17 21:41:09 +01:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > PartNumber , unknown ) ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
if ( gRAM . Frequency > gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Frequency ) {
newSmbiosTable . Type17 - > Speed = ( UINT16 ) gRAM . Frequency ; // unsafe cast
2019-09-03 11:58:42 +02:00
} else {
2021-10-02 19:44:16 +02:00
newSmbiosTable . Type17 - > Speed = gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Frequency ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
if ( gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . ModuleSize > 0x7FFF ) {
2019-12-23 17:46:07 +01:00
newSmbiosTable . Type17 - > Size = 0x7FFF ;
2021-10-02 19:44:16 +02:00
newSmbiosTable . Type17 - > ExtendedSize = gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . ModuleSize ;
2019-12-23 17:46:07 +01:00
} else {
2021-10-02 19:44:16 +02:00
newSmbiosTable . Type17 - > Size = gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . ModuleSize ;
2019-12-23 17:46:07 +01:00
}
2021-10-02 19:44:16 +02:00
newSmbiosTable . Type17 - > MemoryType = gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Type ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
if ( trustSMBIOS & & gRAM . SMBIOS . doesSlotForIndexExist ( SMBIOSIndex ) & &
( newSmbiosTable . Type17 - > Speed < gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Frequency ) ) {
DBG ( " Type17->Speed corrected by SMBIOS from %dMHz to %dMHz \n " , newSmbiosTable . Type17 - > Speed , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Frequency ) ;
newSmbiosTable . Type17 - > Speed = gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Frequency ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
if ( trustSMBIOS & & gRAM . SMBIOS . doesSlotForIndexExist ( SMBIOSIndex ) & &
gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Vendor . notEmpty ( ) & &
( gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Vendor . isEmpty ( ) | | gRAM . SPD . getSlotInfoForSlotIndex ( SPDIndex ) . Vendor = = " NoName " _XS8 )
2021-04-03 16:42:49 +02:00
) {
2021-10-02 19:44:16 +02:00
DBG ( " Type17->Manufacturer corrected by SMBIOS from NoName to %s \n " , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Vendor . c_str ( ) ) ;
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > Manufacturer , gRAM . SMBIOS . getSlotInfoForSlotIndex ( SMBIOSIndex ) . Vendor ) ;
2019-09-03 11:58:42 +02:00
}
2021-04-03 16:42:49 +02:00
// gSettings.MemorySpeed.S8Printf("%d", newSmbiosTable.Type17->Speed);
2019-09-03 11:58:42 +02:00
// Assume DDR3 unless explicitly set to DDR2/DDR/DDR4
if ( ( newSmbiosTable . Type17 - > MemoryType ! = MemoryTypeDdr2 ) & &
( newSmbiosTable . Type17 - > MemoryType ! = MemoryTypeDdr4 ) & &
( newSmbiosTable . Type17 - > MemoryType ! = MemoryTypeDdr ) ) {
newSmbiosTable . Type17 - > MemoryType = MemoryTypeDdr3 ;
}
//now I want to update deviceLocator and bankLocator
if ( isMacPro ) {
2021-04-28 20:30:34 +02:00
deviceLocator . S8Printf ( " DIMM%zd " , Index + 1 ) ;
2020-08-15 15:47:56 +02:00
bankLocator . setEmpty ( ) ;
2019-09-03 11:58:42 +02:00
} else {
2020-08-15 15:47:56 +02:00
deviceLocator . S8Printf ( " DIMM%d " , bank ) ;
2021-04-28 20:30:34 +02:00
bankLocator . S8Printf ( " BANK %zu " , Index % channels ) ;
2019-09-03 11:58:42 +02:00
}
2020-08-15 15:47:56 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > DeviceLocator , deviceLocator ) ;
2019-09-03 11:58:42 +02:00
if ( isMacPro ) {
newSmbiosTable . Type17 - > BankLocator = 0 ; //like in MacPro5,1
} else {
2020-08-15 15:47:56 +02:00
UpdateSmbiosString ( newSmbiosTable , & newSmbiosTable . Type17 - > BankLocator , bankLocator ) ;
2019-09-03 11:58:42 +02:00
}
2021-10-02 19:44:16 +02:00
DBG ( " SMBIOS Type 17 Index = %zd => SMBIOSIndex=%zu SPDIndex=%zu: \n " , Index , SMBIOSIndex , SPDIndex ) ;
2019-09-03 11:58:42 +02:00
if ( newSmbiosTable . Type17 - > Size = = 0 ) {
2020-08-15 15:47:56 +02:00
DBG ( " %s %s EMPTY \n " , bankLocator . c_str ( ) , deviceLocator . c_str ( ) ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type17 - > MemoryType = 0 ; //MemoryTypeUnknown;
} else {
2021-09-28 10:28:45 +02:00
insertingEmpty = false ;
2020-08-15 15:47:56 +02:00
DBG ( " %s %s %dMHz %dMB(Ext:%dMB) \n " , bankLocator . c_str ( ) , deviceLocator . c_str ( ) , newSmbiosTable . Type17 - > Speed ,
2019-12-23 17:46:07 +01:00
newSmbiosTable . Type17 - > Size , newSmbiosTable . Type17 - > ExtendedSize ) ;
if ( newSmbiosTable . Type17 - > Size = = 0x7FFF ) {
mTotalSystemMemory + = newSmbiosTable . Type17 - > ExtendedSize ; //Mb
} else {
mTotalSystemMemory + = newSmbiosTable . Type17 - > Size ; //Mb
}
2021-04-28 20:30:34 +02:00
mMemory17 [ Index ] = ( UINT16 ) mTotalSystemMemory ;
2019-09-03 11:58:42 +02:00
// DBG("mTotalSystemMemory = %d\n", mTotalSystemMemory);
}
newSmbiosTable . Type17 - > MemoryErrorInformationHandle = 0xFFFF ;
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . Attribute ! = - 1 ) {
newSmbiosTable . Type17 - > Attributes = smbiosSettings . Attribute ;
2019-11-15 13:17:19 +01:00
}
2021-04-28 20:30:34 +02:00
mHandle17 [ Index ] = LogSmbiosTable ( newSmbiosTable ) ;
2019-09-03 11:58:42 +02:00
}
if ( mTotalSystemMemory > 0 ) {
DBG ( " mTotalSystemMemory = %d \n " , mTotalSystemMemory ) ;
}
}
2020-10-03 19:02:31 +02:00
void
2021-04-28 20:30:34 +02:00
PatchTableType19 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
//
// Generate Memory Array Mapped Address info (TYPE 19)
//
/*
/// This structure provides the address mapping for a Physical Memory Array.
/// One structure is present for each contiguous address range described.
///
typedef struct {
SMBIOS_STRUCTURE Hdr ;
UINT32 StartingAddress ;
UINT32 EndingAddress ;
UINT16 MemoryArrayHandle ;
UINT8 PartitionWidth ;
} SMBIOS_TABLE_TYPE19 ;
*/
//Slice - I created one table as a sum of all other. It is needed for SetupBrowser
UINT32 TotalEnd = 0 ;
UINT8 PartWidth = 1 ;
UINT16 SomeHandle = 0x1300 ; //as a common rule handle=(type<<8 + index)
2021-04-28 20:30:34 +02:00
for ( size_t Index = 0 ; Index < smbiosSettings . RamSlotCount ; Index + + ) {
2019-09-03 11:58:42 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS , Index ) ;
if ( SmbiosTable . Raw = = NULL ) {
continue ;
}
if ( SmbiosTable . Type19 - > EndingAddress > TotalEnd ) {
TotalEnd = SmbiosTable . Type19 - > EndingAddress ;
}
PartWidth = SmbiosTable . Type19 - > PartitionWidth ;
//SomeHandle = SmbiosTable.Type19->Hdr.Handle;
}
if ( TotalEnd = = 0 ) {
TotalEnd = ( UINT32 ) ( LShiftU64 ( mTotalSystemMemory , 10 ) - 1 ) ;
}
gTotalMemory = LShiftU64 ( mTotalSystemMemory , 20 ) ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type19 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type19 - > Hdr . Type = EFI_SMBIOS_TYPE_MEMORY_ARRAY_MAPPED_ADDRESS ;
newSmbiosTable . Type19 - > Hdr . Length = sizeof ( SMBIOS_TABLE_TYPE19 ) ;
newSmbiosTable . Type19 - > Hdr . Handle = SomeHandle ;
newSmbiosTable . Type19 - > MemoryArrayHandle = mHandle16 ;
newSmbiosTable . Type19 - > StartingAddress = 0 ;
newSmbiosTable . Type19 - > EndingAddress = TotalEnd ;
newSmbiosTable . Type19 - > PartitionWidth = PartWidth ;
mHandle19 = LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2021-10-02 19:44:16 +02:00
void PatchTableType20 ( const SmbiosInjectedSettings & smbiosSettings , const XArray < UINT16 > & mMemory17 , const XArray < UINT16 > & mHandle17 )
2019-09-03 11:58:42 +02:00
{
UINTN j = 0 , k = 0 , m = 0 ;
//
// Generate Memory Array Mapped Address info (TYPE 20)
// not needed neither for Apple nor for EFI
m = 0 ;
2021-04-28 20:30:34 +02:00
for ( size_t Index = 0 ; Index < smbiosSettings . RamSlotCount ; Index + + ) {
2019-09-03 11:58:42 +02:00
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_MEMORY_DEVICE_MAPPED_ADDRESS , Index ) ;
if ( SmbiosTable . Raw = = NULL ) {
return ;
}
TableSize = SmbiosTableLength ( SmbiosTable ) ;
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type20 , MAX_TABLE_SIZE ) ;
CopyMem ( ( void * ) newSmbiosTable . Type20 , ( void * ) SmbiosTable . Type20 , TableSize ) ;
2021-04-28 20:30:34 +02:00
for ( j = 0 ; j < smbiosSettings . RamSlotCount ; j + + ) {
2019-09-03 11:58:42 +02:00
//EndingAddress in kb while mMemory in Mb
if ( ( UINT32 ) ( mMemory17 [ j ] < < 10 ) > newSmbiosTable . Type20 - > EndingAddress ) {
newSmbiosTable . Type20 - > MemoryDeviceHandle = mHandle17 [ j ] ;
k = newSmbiosTable . Type20 - > EndingAddress ;
m + = mMemory17 [ j ] ;
2021-10-02 19:44:16 +02:00
DBG ( " Type20[%zu]->End = 0x%llX, Type17[%llu] = %llX \n " , Index , k , j , m ) ;
2020-03-25 19:32:44 +01:00
// DBG(" MemoryDeviceHandle = 0x%X\n", newSmbiosTable.Type20->MemoryDeviceHandle);
2021-10-02 19:44:16 +02:00
//mMemory17[j] = 0; // used
2019-09-03 11:58:42 +02:00
break ;
}
// DBG("\n");
}
newSmbiosTable . Type20 - > MemoryArrayMappedAddressHandle = mHandle19 ;
//
// Record Smbios Type 20
//
LogSmbiosTable ( newSmbiosTable ) ;
}
return ;
}
2021-04-28 20:30:34 +02:00
void GetTableType32 ( SmbiosDiscoveredSettings * smbiosSettings )
2019-09-03 11:58:42 +02:00
{
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , EFI_SMBIOS_TYPE_SYSTEM_BOOT_INFORMATION , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
return ;
}
gBootStatus = SmbiosTable . Type32 - > BootStatus ;
}
/**
* Apple Specific Structures .
* Firmware Table , FirmwareVolume ( TYPE 128 ) .
*/
2021-04-28 20:30:34 +02:00
void PatchTableType128 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
/**
* Useful information .
*
* FW_REGION_RESERVED = 0 ,
* FW_REGION_RECOVERY = 1 ,
* FW_REGION_MAIN = 2 ,
* gHob - > MemoryAbove1MB . PhysicalStart + ResourceLength or fix as 0x200000 - 0x600000 ,
* FW_REGION_NVRAM = 3 ,
* FW_REGION_CONFIG = 4 ,
* FW_REGION_DIAGVAULT = 5.
*/
// Get the existing 128 table if exists.
//SmbiosTable = GetSmbiosTableFromType (EntryPoint, 128, 0);
// initialise new table
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type128 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
// common rules
newSmbiosTable . Type128 - > Hdr . Type = 128 ;
newSmbiosTable . Type128 - > Hdr . Length = sizeof ( SMBIOS_TABLE_TYPE128 ) ;
newSmbiosTable . Type128 - > Hdr . Handle = 0x8000 ;
// set firmware-features, example: 0x80001417, imac11,2 -> 0x1403.
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type128 - > FirmwareFeatures = smbiosSettings . FirmwareFeatures ;
2019-09-03 11:58:42 +02:00
// set firmware-features mask
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type128 - > FirmwareFeaturesMask = smbiosSettings . FirmwareFeaturesMask ;
2019-09-03 11:58:42 +02:00
2021-09-25 13:33:16 +02:00
newSmbiosTable . Type128 - > ExtendedFirmwareFeatures = ( uint32_t ) ( smbiosSettings . ExtendedFirmwareFeatures > > 32 ) ;
newSmbiosTable . Type128 - > ExtendedFirmwareFeaturesMask = ( uint32_t ) ( smbiosSettings . ExtendedFirmwareFeaturesMask > > 32 ) ;
2019-09-03 11:58:42 +02:00
/**
* TODO : I have an idea that region should be the same as Efivar . bin
* @ author Slice
*/
newSmbiosTable . Type128 - > RegionCount = 1 ;
newSmbiosTable . Type128 - > RegionType [ 0 ] = FW_REGION_MAIN ;
//UpAddress = mTotalSystemMemory << 20; //Mb -> b
//gHob->MemoryAbove1MB.PhysicalStart;
newSmbiosTable . Type128 - > FlashMap [ 0 ] . StartAddress = 0xFFE00000 ; //0xF0000;
//gHob->MemoryAbove1MB.PhysicalStart + gHob->MemoryAbove1MB.ResourceLength - 1;
newSmbiosTable . Type128 - > FlashMap [ 0 ] . EndAddress = 0xFFEFFFFF ;
//newSmbiosTable.Type128->RegionType[1] = FW_REGION_NVRAM; //Efivar
//newSmbiosTable.Type128->FlashMap[1].StartAddress = 0x15000; //0xF0000;
//newSmbiosTable.Type128->FlashMap[1].EndAddress = 0x1FFFF;
//region type=1 also present in mac
// log the new, 128, sbmios table
LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType130 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
//
// MemorySPD (TYPE 130)
// TODO: read SPD and place here. But for a what?
//
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , 130 , 0 ) ;
if ( SmbiosTable . Raw = = NULL ) {
return ;
}
//
// Log Smbios Record Type130
//
LogSmbiosTable ( SmbiosTable ) ;
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType131 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
// Get Table Type131
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , 131 , 0 ) ;
if ( SmbiosTable . Raw ! = NULL ) {
2020-07-09 21:06:48 +02:00
MsgLog ( " Table 131 is present, CPUType=%hX \n " , SmbiosTable . Type131 - > ProcessorType . Type ) ;
2021-04-28 20:30:34 +02:00
MsgLog ( " Change to: %hX \n " , smbiosSettings . CpuType ) ;
2019-09-03 11:58:42 +02:00
}
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type131 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type131 - > Hdr . Type = 131 ;
newSmbiosTable . Type131 - > Hdr . Length = sizeof ( SMBIOS_STRUCTURE ) + 2 ;
newSmbiosTable . Type131 - > Hdr . Handle = 0x8300 ; //common rule
// Patch ProcessorType
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type131 - > ProcessorType . Type = smbiosSettings . CpuType ;
2019-09-03 11:58:42 +02:00
Handle = LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType132 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
2021-04-28 20:30:34 +02:00
if ( ! smbiosSettings . SetTable132 ) {
2019-09-03 11:58:42 +02:00
//DBG("disabled Table 132\n");
return ;
}
// Get Table Type132
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , 132 , 0 ) ;
if ( SmbiosTable . Raw ! = NULL ) {
2020-04-17 15:14:24 +02:00
MsgLog ( " Table 132 is present, QPI=%hX \n " , SmbiosTable . Type132 - > ProcessorBusSpeed ) ;
2021-04-28 20:30:34 +02:00
MsgLog ( " Change to: %hX \n " , smbiosSettings . QPI ) ;
2019-09-03 11:58:42 +02:00
}
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type132 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type132 - > Hdr . Type = 132 ;
newSmbiosTable . Type132 - > Hdr . Length = sizeof ( SMBIOS_STRUCTURE ) + 2 ;
newSmbiosTable . Type132 - > Hdr . Handle = 0x8400 ; //ugly
// Patch ProcessorBusSpeed
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . QPI ) {
newSmbiosTable . Type132 - > ProcessorBusSpeed = smbiosSettings . QPI ;
2019-09-03 11:58:42 +02:00
} else {
2021-04-28 20:30:34 +02:00
newSmbiosTable . Type132 - > ProcessorBusSpeed = ( UINT16 ) ( LShiftU64 ( DivU64x32 ( smbiosSettings . ExternalClock , Kilo ) , 2 ) ) ;
2019-09-03 11:58:42 +02:00
}
Handle = LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2021-04-28 20:30:34 +02:00
void PatchTableType133 ( const SmbiosInjectedSettings & smbiosSettings )
2019-09-03 11:58:42 +02:00
{
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . gPlatformFeature = = 0xFFFF ) {
2019-09-03 11:58:42 +02:00
return ;
}
// Get Table Type133
SmbiosTable = GetSmbiosTableFromType ( EntryPoint , 133 , 0 ) ;
if ( SmbiosTable . Raw ! = NULL ) {
2020-03-25 19:32:44 +01:00
MsgLog ( " Table 133 is present, PlatformFeature=%llX \n " , SmbiosTable . Type133 - > PlatformFeature ) ;
2021-04-28 20:30:34 +02:00
MsgLog ( " Change to: %llX \n " , smbiosSettings . gPlatformFeature ) ;
2019-09-03 11:58:42 +02:00
}
2020-10-03 19:02:31 +02:00
ZeroMem ( ( void * ) newSmbiosTable . Type133 , MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
newSmbiosTable . Type133 - > Hdr . Type = 133 ;
newSmbiosTable . Type133 - > Hdr . Length = sizeof ( SMBIOS_STRUCTURE ) + 8 ;
newSmbiosTable . Type133 - > Hdr . Handle = 0x8500 ; //ugly
2021-04-28 20:30:34 +02:00
// newSmbiosTable.Type133->PlatformFeature = smbiosSettings.gPlatformFeature;
CopyMem ( ( void * ) & newSmbiosTable . Type133 - > PlatformFeature , ( void * ) & smbiosSettings . gPlatformFeature , 8 ) ;
2019-09-03 11:58:42 +02:00
Handle = LogSmbiosTable ( newSmbiosTable ) ;
return ;
}
2021-04-28 20:30:34 +02:00
EFI_STATUS PrepatchSmbios ( SmbiosDiscoveredSettings * smbiosSettings )
2019-09-03 11:58:42 +02:00
{
EFI_STATUS Status = EFI_SUCCESS ;
UINTN BufferLen ;
EFI_PHYSICAL_ADDRESS BufferPtr ;
// UINTN Index;
DbgHeader ( " Get Smbios " ) ;
// Get SMBIOS Tables
Smbios = FindOemSMBIOSPtr ( ) ;
// DBG("OEM SMBIOS EPS=%p\n", Smbios);
2020-03-25 19:32:44 +01:00
// DBG("OEM Tables = %X\n", ((SMBIOS_TABLE_ENTRY_POINT*)Smbios)->TableAddress);
2019-09-03 11:58:42 +02:00
if ( ! Smbios ) {
// DBG("Original SMBIOS System Table not found! Getting from Hob...\n");
Smbios = GetSmbiosTablesFromHob ( ) ;
// DBG("HOB SMBIOS EPS=%p\n", Smbios);
if ( ! Smbios ) {
// DBG("And here SMBIOS System Table not found! Trying System table ...\n");
// this should work on any UEFI
Smbios = GetSmbiosTablesFromConfigTables ( ) ;
// DBG("ConfigTables SMBIOS EPS=%p\n", Smbios);
if ( ! Smbios ) {
// DBG("And here SMBIOS System Table not found! Exiting...\n");
return EFI_NOT_FOUND ;
}
}
}
//original EPS and tables
EntryPoint = ( SMBIOS_TABLE_ENTRY_POINT * ) Smbios ; //yes, it is old SmbiosEPS
2020-10-03 19:02:31 +02:00
// Smbios = (void*)(UINT32)EntryPoint->TableAddress; // here is flat Smbios database. Work with it
2019-09-03 11:58:42 +02:00
//how many we need to add for tables 128, 130, 131, 132 and for strings?
BufferLen = 0x20 + EntryPoint - > TableLength + 64 * 10 ;
//new place for EPS and tables. Allocated once for both
BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS ;
Status = gBS - > AllocatePages ( AllocateMaxAddress , EfiACPIMemoryNVS , /*EfiACPIReclaimMemory, */
EFI_SIZE_TO_PAGES ( BufferLen ) , & BufferPtr ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
// DBG("There is error allocating pages in EfiACPIMemoryNVS!\n");
Status = gBS - > AllocatePages ( AllocateMaxAddress , /*EfiACPIMemoryNVS, */ EfiACPIReclaimMemory ,
ROUND_PAGE ( BufferLen ) / EFI_PAGE_SIZE , & BufferPtr ) ;
2020-04-23 11:08:10 +02:00
if ( EFI_ERROR ( Status ) ) {
2019-09-03 11:58:42 +02:00
// DBG("There is error allocating pages in EfiACPIReclaimMemory!\n");
}
}
// DBG("Buffer @ %p\n", BufferPtr);
if ( BufferPtr ) {
SmbiosEpsNew = ( SMBIOS_TABLE_ENTRY_POINT * ) ( UINTN ) BufferPtr ; //this is new EPS
} else {
SmbiosEpsNew = EntryPoint ; //is it possible?!
}
ZeroMem ( SmbiosEpsNew , BufferLen ) ;
// DBG("New EntryPoint = %p\n", SmbiosEpsNew);
NumberOfRecords = 0 ;
MaxStructureSize = 0 ;
//preliminary fill EntryPoint with some data
2020-10-03 19:02:31 +02:00
CopyMem ( ( void * ) SmbiosEpsNew , ( void * ) EntryPoint , sizeof ( SMBIOS_TABLE_ENTRY_POINT ) ) ;
2019-09-03 11:58:42 +02:00
2020-10-03 19:02:31 +02:00
Smbios = ( void * ) ( SmbiosEpsNew + 1 ) ; //this is a C-language trick. I hate it but use. +1 means +sizeof(SMBIOS_TABLE_ENTRY_POINT)
2019-09-03 11:58:42 +02:00
Current = ( UINT8 * ) Smbios ; //begin fill tables from here
SmbiosEpsNew - > TableAddress = ( UINT32 ) ( UINTN ) Current ;
SmbiosEpsNew - > EntryPointLength = sizeof ( SMBIOS_TABLE_ENTRY_POINT ) ; // no matter on other versions
2021-04-28 20:30:34 +02:00
if ( smbiosSettings - > SmbiosVersion ! = 0 ) {
SmbiosEpsNew - > MajorVersion = ( UINT8 ) ( smbiosSettings - > SmbiosVersion > > 8 ) ;
SmbiosEpsNew - > MinorVersion = ( UINT8 ) ( smbiosSettings - > SmbiosVersion & 0xFF ) ;
2019-11-15 13:50:12 +01:00
SmbiosEpsNew - > SmbiosBcdRevision = ( SmbiosEpsNew - > MajorVersion < < 4 ) + SmbiosEpsNew - > MinorVersion ;
}
else {
//old behavior
SmbiosEpsNew - > MajorVersion = 2 ;
SmbiosEpsNew - > MinorVersion = 4 ;
SmbiosEpsNew - > SmbiosBcdRevision = 0x24 ; //Slice - we want to have v2.6 but Apple still uses 2.4, let it be default value
}
2019-09-03 11:58:42 +02:00
//Collect information for use in menu
2021-04-28 20:30:34 +02:00
GetTableType1 ( smbiosSettings ) ;
GetTableType2 ( smbiosSettings ) ;
GetTableType3 ( smbiosSettings ) ;
GetTableType4 ( smbiosSettings ) ;
2021-10-02 19:44:16 +02:00
// GetTableType16() will initialize smbiosSettings->RamSlotCount. Could be MAX_RAM_SLOTS.
2021-04-28 20:30:34 +02:00
GetTableType16 ( smbiosSettings ) ;
GetTableType17 ( smbiosSettings ) ;
GetTableType32 ( smbiosSettings ) ; //get BootStatus here to decide what to do
2020-04-17 15:14:24 +02:00
MsgLog ( " Boot status=%hhX \n " , gBootStatus ) ;
2019-09-03 11:58:42 +02:00
//for example the bootloader may go to Recovery is BootStatus is Fail
return Status ;
}
2021-04-28 20:30:34 +02:00
void PatchSmbios ( const SmbiosInjectedSettings & smbiosSettings ) //continue
2019-09-03 11:58:42 +02:00
{
DbgHeader ( " PatchSmbios " ) ;
2020-08-15 15:47:56 +02:00
newSmbiosTable . Raw = ( UINT8 * ) AllocateZeroPool ( MAX_TABLE_SIZE ) ;
2019-09-03 11:58:42 +02:00
//Slice - order of patching is significant
2021-04-28 20:30:34 +02:00
PatchTableType0 ( smbiosSettings ) ;
PatchTableType1 ( smbiosSettings ) ;
PatchTableType2 ( smbiosSettings ) ;
PatchTableType3 ( smbiosSettings ) ;
PatchTableType7 ( smbiosSettings ) ; //we should know handles before patch Table4
PatchTableType4 ( smbiosSettings ) ;
// PatchTableType6(smbiosSettings);
PatchTableType9 ( smbiosSettings ) ;
if ( ! smbiosSettings . NoRomInfo ) {
PatchTableType11 ( smbiosSettings ) ;
2019-12-12 15:51:55 +01:00
}
2019-09-03 11:58:42 +02:00
PatchTableTypeSome ( ) ;
2021-10-02 19:44:16 +02:00
auto SlotCounts = smbiosSettings . RamSlotCount ;
2021-10-19 12:27:41 +02:00
if ( SlotCounts > MAX_RAM_SLOTS ) {
2021-10-02 19:44:16 +02:00
log_technical_bug ( " GetTableType16() assign smbiosSettings.RamSlotCount a value bigger than MAX_RAM_SLOTS " ) ;
SlotCounts = MAX_RAM_SLOTS ;
}
XArray < UINT16 > mMemory17 ;
mMemory17 . Add ( 0 , SlotCounts ) ;
XArray < UINT16 > mHandle17 ;
mHandle17 . Add ( 0 , SlotCounts ) ;
PatchTableType17 ( smbiosSettings , & mMemory17 , & mHandle17 ) ;
2021-04-28 20:30:34 +02:00
PatchTableType16 ( smbiosSettings ) ;
PatchTableType19 ( smbiosSettings ) ;
2021-10-02 19:44:16 +02:00
PatchTableType20 ( smbiosSettings , mMemory17 , mHandle17 ) ;
2021-04-28 20:30:34 +02:00
PatchTableType128 ( smbiosSettings ) ;
PatchTableType130 ( smbiosSettings ) ;
PatchTableType131 ( smbiosSettings ) ;
PatchTableType132 ( smbiosSettings ) ;
PatchTableType133 ( smbiosSettings ) ;
2019-09-03 11:58:42 +02:00
AddSmbiosEndOfTable ( ) ;
if ( MaxStructureSize > MAX_TABLE_SIZE ) {
// DBG("Too long SMBIOS!\n");
}
2020-10-03 19:02:31 +02:00
FreePool ( ( void * ) newSmbiosTable . Raw ) ;
2019-09-03 11:58:42 +02:00
// there is no need to keep all tables in numeric order. It is not needed
// neither by specs nor by AppleSmbios.kext
}
2021-04-28 20:30:34 +02:00
void FinalizeSmbios ( const SmbiosInjectedSettings & smbiosSettings ) //continue
2019-09-03 11:58:42 +02:00
{
EFI_PEI_HOB_POINTERS GuidHob ;
EFI_PEI_HOB_POINTERS HobStart ;
EFI_PHYSICAL_ADDRESS * Table = NULL ;
//UINTN TableLength = 0;
2021-09-28 10:28:45 +02:00
// XBool FoundTable3 = false;
2019-09-03 11:58:42 +02:00
// Get Hob List
2020-02-21 22:22:30 +01:00
HobStart . Raw = ( __typeof_am__ ( HobStart . Raw ) ) GetHobList ( ) ;
2019-09-03 11:58:42 +02:00
if ( HobStart . Raw ! = NULL ) {
// find SMBIOS in hob
2021-04-28 20:30:34 +02:00
for ( size_t Index = 0 ; Index < sizeof ( gTableGuidArray ) / sizeof ( * gTableGuidArray ) ; + + Index ) {
2020-02-21 22:22:30 +01:00
GuidHob . Raw = ( __typeof_am__ ( HobStart . Raw ) ) GetNextGuidHob ( gTableGuidArray [ Index ] , HobStart . Raw ) ;
2019-09-03 11:58:42 +02:00
if ( GuidHob . Raw ! = NULL ) {
2020-02-21 22:22:30 +01:00
Table = ( __typeof_am__ ( Table ) ) GET_GUID_HOB_DATA ( GuidHob . Guid ) ;
2019-09-03 11:58:42 +02:00
//TableLength = GET_GUID_HOB_DATA_SIZE (GuidHob);
if ( Table ! = NULL ) {
if ( Index ! = 0 ) {
2021-09-28 10:28:45 +02:00
// FoundTable3 = true; //don't know how to use it. Real Mac have table3 in the format of table2
2019-09-03 11:58:42 +02:00
DBG ( " Found SMBIOS3 Table \n " ) ;
}
break ;
}
}
}
}
//
// Install SMBIOS in Config table
SmbiosEpsNew - > TableLength = ( UINT16 ) ( ( UINT32 ) ( UINTN ) Current - ( UINT32 ) ( UINTN ) Smbios ) ;
SmbiosEpsNew - > NumberOfSmbiosStructures = NumberOfRecords ;
SmbiosEpsNew - > MaxStructureSize = MaxStructureSize ;
SmbiosEpsNew - > IntermediateChecksum = 0 ;
SmbiosEpsNew - > IntermediateChecksum = ( UINT8 ) ( 256 - Checksum8 ( ( UINT8 * ) SmbiosEpsNew + 0x10 , SmbiosEpsNew - > EntryPointLength - 0x10 ) ) ;
SmbiosEpsNew - > EntryPointStructureChecksum = 0 ;
SmbiosEpsNew - > EntryPointStructureChecksum = ( UINT8 ) ( 256 - Checksum8 ( ( UINT8 * ) SmbiosEpsNew , SmbiosEpsNew - > EntryPointLength ) ) ;
2020-11-18 22:49:02 +01:00
//DBG("SmbiosEpsNew->TableLength = %d\n", SmbiosEpsNew->TableLength);
//DBG("SmbiosEpsNew->EntryPointLength = %d\n", SmbiosEpsNew->EntryPointLength);
//DBG("SmbiosEpsNew->MaxStructureSize = %d\n", SmbiosEpsNew->MaxStructureSize);
//DBG("DMI checksum = %d\n", Checksum8((UINT8*)SmbiosEpsNew, SmbiosEpsNew->EntryPointLength));
//XString8 tmpDbg;
//XString8 tmptmpDbg;
//tmpDbg.dataSized(SmbiosEpsNew->TableLength*3+5*SmbiosEpsNew->TableLength/32+128);
//for ( size_t i = 0 ; i < SmbiosEpsNew->TableLength ; ) {
// size_t j;
// for ( j = 0 ; j < SmbiosEpsNew->TableLength && j < 32 ; j++ ) {
//// DBG("%02x ", ((UINT8*)(SmbiosEpsNew+1))[i+j] );
// tmptmpDbg.S8Printf("%02x ", ((UINT8*)(SmbiosEpsNew+1))[i+j] );
// tmpDbg.strcat(tmptmpDbg);
// }
//// DBG(" - ");
// tmptmpDbg.S8Printf(" - ");
// tmpDbg.strcat(tmptmpDbg);
// for ( j = 0 ; j < SmbiosEpsNew->TableLength && j < 32 ; j++ ) {
// UINT8 c = ((UINT8*)(SmbiosEpsNew+1))[i+j];
//// DBG("%c ", c > 32 ? c : '.');
// tmptmpDbg.S8Printf("%c", c > 32 ? c : '.');
// tmpDbg.strcat(tmptmpDbg);
// }
//// DBG("\n");
// tmptmpDbg.S8Printf("\n");
// tmpDbg.strcat(tmptmpDbg);
// i += j;
//}
//DBG("%s", tmpDbg.c_str());
//auto foo = SmbiosEpsNew;
2019-09-03 11:58:42 +02:00
//
// syscl: one more step: check if we need remap SMBIOS Table Type 1 Guid
//
// to fix Dell's SMBIOS truncate credit David Passmore
//
2021-04-28 20:30:34 +02:00
if ( smbiosSettings . KPDELLSMBIOS )
2019-09-03 11:58:42 +02:00
{
//
// syscl: remap smbios table 1 guid
//
DBG ( " Remap smbios table type 1 guid. \n " ) ;
2020-10-03 19:02:31 +02:00
gBS - > InstallConfigurationTable ( & gRemapEfiSmbiosTableGuid , ( void * ) SmbiosEpsNew ) ;
2019-09-03 11:58:42 +02:00
}
else
{
//
// use origin smbios guid table
//
DBG ( " Use origin smbios table type 1 guid. \n " ) ;
2020-10-03 19:02:31 +02:00
gBS - > InstallConfigurationTable ( & gEfiSmbiosTableGuid , ( void * ) SmbiosEpsNew ) ;
2019-09-03 11:58:42 +02:00
}
gST - > Hdr . CRC32 = 0 ;
gBS - > CalculateCrc32 ( ( UINT8 * ) & gST - > Hdr , gST - > Hdr . HeaderSize , & gST - > Hdr . CRC32 ) ;
//
// Fix it in Hob list
//
// No smbios in Hob list on Aptio, so no need to update it there.
// But even if it would be there, loading of macOS would overwrite it
// since this list on my board is inside space needed for kernel
// (ha! like many other UEFI stuff).
// It's enough to add it to Conf.table.
//
if ( Table ! = NULL ) {
//PauseForKey(L"installing SMBIOS in Hob\n");
* Table = ( UINT32 ) ( UINTN ) SmbiosEpsNew ;
}
2020-10-17 15:01:33 +02:00
// egSaveFile(NULL, SWPrintf("%ls\\misc\\smbios.bin", self.getCloverDirFullPath().wc_str()).wc_str(), (UINT8*)(UINTN)SmbiosEpsNew, SmbiosEpsNew->TableLength);
2019-09-03 11:58:42 +02:00
return ;
}
2021-04-28 20:30:34 +02:00