Skip to content

Commit

Permalink
0.1.7 Release
Browse files Browse the repository at this point in the history
Improved CPU Support
More Debug Tracing Messages
psyq321 committed Dec 13, 2021
1 parent 4f13eae commit de92efb
Showing 6 changed files with 179 additions and 69 deletions.
17 changes: 12 additions & 5 deletions PowerMonkeyApp/CpuData.c
Original file line number Diff line number Diff line change
@@ -47,6 +47,10 @@ CPUCONFIGTABLE gCpuConfigTable[] = {
// Special entry for undetected CPUs

{ {0, 0, 0} , "Unknown", 0, 10, 0, 0 },

//
// "Known" CPUs (not necessarily supported or tested)

{ {6, 26, 1} , "Nehalem", 0, 10, 0, 0 },
{ {6, 26, 2} , "Nehalem-EP", 0, 10, 0, 0 },
{ {6, 26, 4} , "Bloomfield", 0, 10, 0, 0 },
@@ -104,9 +108,11 @@ CPUCONFIGTABLE gCpuConfigTable[] = {
{ {6, 95, 1} , "Denverton", 0, 10, 0, 0 },
{ {6, 102, 3} , "Cannon Lake-U", 0, 10, 0, 0 },
{ {6, 117, 10} , "Spreadtrum", 0, 10, 0, 0 },
{ {6, 106, 0} , "IceLake-SP", 0, 10, 0, 0 }, // QEMU (debug)
{ {6, 106, 6} , "IceLake-SP", 0, 10, 0, 0 },
{ {6, 122, 1} , "Gemini Lake-D", 0, 10, 0, 0 },
{ {6, 122, 8} , "GoldmontPlus", 0, 10, 0, 0 },
{ {6, 126, 5} , "IceLakeY", 0, 10, 0, 0 },
{ {6, 126, 5} , "IceLakeY", 0, 10, 0, 0 },
{ {6, 138, 1} , "Lakefield", 0, 10, 0, 0 },
{ {6, 140, 1} , "TigerLake", 0, 10, 1, 0 },
{ {6, 141, 1} , "TigerLake", 0, 10, 1, 0 },
@@ -127,7 +133,10 @@ CPUCONFIGTABLE gCpuConfigTable[] = {
{ {6, 167, 0} , "RocketLake", 0, 10, 1, 0 }, // RKL-S ES
{ {6, 167, 1} , "RocketLake", 0, 10, 1, 0 }, // RKL-S QS/PRQ
{ {6, 151, 2} , "AlderLake-S", 0, 11, 1, 1 }, // ADL-S QS/PRQ
{ {6, 154, 1} , "AlderLake-P", 0, 11, 1, 1 }, // ADL-P ES
{ {6, 151, 4} , "AlderLake-S", 0, 11, 1, 1 }, // ADL-S
{ {6, 151, 5} , "AlderLake-S", 0, 11, 1, 1 }, // ADL-S
{ {6, 154, 2} , "AlderLake-P", 0, 11, 1, 1 }, // ADL-P
{ {6, 154, 3} , "AlderLake-P", 0, 11, 1, 1 }, // ADL-P
};


@@ -143,8 +152,6 @@ CPUCONFIGTABLE* gActiveCpuData = &gCpuConfigTable[0];

BOOLEAN DetectCpu()
{
BOOLEAN found = FALSE;

//
// CPUID

@@ -172,5 +179,5 @@ BOOLEAN DetectCpu()
}
}

return found;
return FALSE;
}
107 changes: 61 additions & 46 deletions PowerMonkeyApp/Platform.c
Original file line number Diff line number Diff line change
@@ -218,33 +218,33 @@ EFI_STATUS ProbePackage(IN OUT PACKAGE* pkg)
// CPUID //
///////////

GetCpuInfo(&pkg->CpuInfo); /// <- H*A*C*K.

AsmCpuid(0x01,
&pkg->CpuID,
NULL, NULL, NULL);

//////////////////////
// Individual cores //
//////////////////////
if (pkg->probed != 1) {

GetCpuInfo(&pkg->CpuInfo);

DiscoverVRTopology(pkg);
AsmCpuid(0x01,
&pkg->CpuID,
NULL, NULL, NULL);

//////////////////////////
// Discover VR Topology //
//////////////////////////

//////////////////////////
// Discover VR Topology //
//////////////////////////
DiscoverVRTopology(pkg);
}

DiscoverVRTopology(pkg);

////////////////////////
// Initialize domains //
////////////////////////

for (UINT8 didx = 0; didx < MAX_DOMAINS; didx++) {
if (DomainSupported(didx)) {
DOMAIN* dom = pkg->planes + didx;
dom->parent = (void*)pkg;

if (pkg->probed != 1) {
dom->parent = (void*)pkg;
}

IAPERF_ProbeDomainVF(didx, dom);
}
}
@@ -276,6 +276,8 @@ EFI_STATUS ProbePackage(IN OUT PACKAGE* pkg)
&pkg->PkgTimeUnits,
&pkg->PkgEnergyUnits);

pkg->probed = 1;

return status;
}

@@ -540,10 +542,37 @@ EFI_STATUS DetectPackages(IN OUT PLATFORM* psys)
return status;
}

/*******************************************************************************
* ProbePackages
******************************************************************************/

EFI_STATUS EFIAPI ProbePackages(IN OUT PLATFORM* ppd)
{
EFI_STATUS status = EFI_SUCCESS;

//
// Probe each package in its own context

for (UINTN pidx = 0; pidx < ppd->PkgCnt; pidx++)
{
PACKAGE* pac = ppd->packages + pidx;

status = RunOnPackageOrCore(ppd, pac->FirstCoreNumber, ProbePackage, pac);

if (EFI_ERROR(status)) {
Print(L"[ERROR] CPU package %u, status code: 0x%x\n",
pac->FirstCoreNumber,
status);

return status;
}
}

return status;
}

/*******************************************************************************
* DiscoverPlatform
*
* TODO/TBD/HACK: multi-socket code needs rework.
******************************************************************************/

EFI_STATUS EFIAPI DiscoverPlatform(IN OUT PLATFORM** ppsys)
@@ -592,24 +621,8 @@ EFI_STATUS EFIAPI DiscoverPlatform(IN OUT PLATFORM** ppsys)

DetectPackages(ppd);

//
// Probe each package in its own context

for (UINTN pidx = 0; pidx < ppd->PkgCnt; pidx++)
{
PACKAGE* pac = ppd->packages + pidx;

status = RunOnPackageOrCore(ppd, pac->FirstCoreNumber, ProbePackage, pac);

if (EFI_ERROR(status)) {
Print(L"[ERROR] CPU package %u, status code: 0x%x\n",
pac->FirstCoreNumber,
status);

return status;
}
}

ProbePackages(ppd);

return EFI_SUCCESS;
}

@@ -683,7 +696,7 @@ EFI_STATUS EFIAPI ProgramCoreKnobs(PLATFORM* psys)
// Overclocking Lock

if (gPostProgrammingOcLock) {
IaCore_OcLock();
IaCore_OcLock();
}

return EFI_SUCCESS;
@@ -727,12 +740,7 @@ EFI_STATUS EFIAPI ApplyPolicy(IN EFI_SYSTEM_TABLE* SystemTable,
PMUNUSED(SystemTable);
EFI_STATUS status = EFI_SUCCESS;

/////////////////////
// PRINT (CURRENT) //
/////////////////////

PrintPlatformSettings(sys);

/////////////////
// PROGRAMMING //
/////////////////
@@ -791,10 +799,17 @@ EFI_STATUS EFIAPI ApplyPolicy(IN EFI_SYSTEM_TABLE* SystemTable,
RunOnPackageOrCore(sys, pk->FirstCoreNumber, ProgramPackage_Stage2, pk);
}

//
//

PrintVFPoints(sys);
////////////////////
// PRINT SETTINGS //
////////////////////

{
ProbePackages(sys);

PrintPlatformSettings(sys);

PrintVFPoints(sys);
}

return status;
}
1 change: 1 addition & 0 deletions PowerMonkeyApp/Platform.h
Original file line number Diff line number Diff line change
@@ -315,6 +315,7 @@ typedef struct _PACKAGE

UINT64 idx;
VOID* parent; // Parent platform object
UINT64 probed;

} PACKAGE;

88 changes: 87 additions & 1 deletion PowerMonkeyApp/PowerMonkey.c
Original file line number Diff line number Diff line change
@@ -167,6 +167,80 @@ BOOLEAN EmergencyExit(VOID)
return FALSE;
}

/*******************************************************************************
* UnknownCpuWarning
******************************************************************************/

BOOLEAN UnknownCpuWarning(VOID)
{
EFI_STATUS Status;
EFI_EVENT TimerEvent;
EFI_EVENT WaitList[2];
EFI_INPUT_KEY Key;
UINTN Index;

gST->ConOut->SetAttribute(gST->ConOut, EFI_RED);

Print(
L"\n WARNING: Detected CPU (model: %u, family: %u, stepping: %u) is not known!\n"
L" It is likely that proceeding further with hardware programming will result\n"
L" result in unpredictable behavior or with the system hang/reboot.\n\n",
gCpuInfo.model,
gCpuInfo.family,
gCpuInfo.stepping );

Print(
L" If you are a BIOS engineer or otherwise familiar with the detected CPU params\n"
L" please edit CpuData.c and extend it with the detected CPU model/family/stepping\n"
);

Print(
L" and its capabilities. Further changes to the PowerMonkey code might be necessary.\n\n"
L" Press F10 key within the next 30 seconds to IGNORE this warning.\n"
L" Otherwise, PowerMonkey will exit with no changes to the system.\n\n"
);

gST->ConOut->SetAttribute(gST->ConOut, EFI_LIGHTGRAY);

Status = gBS->CreateEvent(
EVT_TIMER, TPL_NOTIFY, NULL, NULL, &TimerEvent);

//
// 3 second timeout

Status = gBS->SetTimer(
TimerEvent, TimerRelative, 300000000);

//
// Wait for a keystroke OR timeout

WaitList[0] = gST->ConIn->WaitForKey;
WaitList[1] = TimerEvent;

Status = gBS->WaitForEvent(2, WaitList, &Index);

if (!EFI_ERROR(Status) && Index == 1) {
Status = EFI_TIMEOUT;
}

gBS->CloseEvent(TimerEvent);
gST->ConIn->ReadKeyStroke(gST->ConIn, &Key);

if (Key.ScanCode == SCAN_F10) {
AsciiPrint(
" Overriding unknown CPU detection...\n");

return TRUE;
}
else {
AsciiPrint(
" Programming aborted.\n");
}

return FALSE;
}


/*******************************************************************************
* PrintBanner
******************************************************************************/
@@ -188,7 +262,7 @@ VOID PrintBanner(VOID)
" | ____// _ \\ | | | | / _ ) / __)| || || | / _ \\ | _ \\ | | / )/ _ )| | | |\n"
" | | | |_| || | | |( (/ / | | | || || || |_| || | | || |< (( (/ / | |_| |\n"
" |_| \\___/ \\____| \\____)|_| |_||_||_| \\___/ |_| |_||_| \\_)\\____) \\__ |\n"
" Version 0.1.6 (____/\n"
" Version 0.1.7 (____/\n"
);

AsciiPrint(
@@ -230,6 +304,18 @@ EFI_STATUS EFIAPI UefiMain(

gCpuDetected = DetectCpu();

if (!gCpuDetected) {

//
// Throw warning for UNKNOWN CPUs

BOOLEAN ovrd = UnknownCpuWarning();

if (ovrd == FALSE) {
return EFI_ABORTED;
}
}

///
/// Set-up TSC timing
/// NOTE: not MP-proofed - multiple packages will use the same calibration
19 changes: 9 additions & 10 deletions PowerMonkeyApp/PrintStats.c
Original file line number Diff line number Diff line change
@@ -130,7 +130,7 @@ VOID PrintPlatformSettings(IN PLATFORM* psys)
PACKAGE* pac = psys->packages + pidx;

Print(
L"+---------------------------------------------------------------------------+\n"
L"+---------------------------------------------------------------------+\n"
);

Print(L"| Package %u | ", pidx);
@@ -140,9 +140,9 @@ VOID PrintPlatformSettings(IN PLATFORM* psys)


Print(
L"+-----------+------+------+--------+----------+-----------+----------+------+\n"
L"| Vt Domain | VR | SVID | IccMax | VoltMode | Vtarget | Voffset | Mult |\n"
L"|-----------|------|------|--------|----------|-----------|----------|------|\n"
L"+-----------+------+------+--------+----------+-----------+----------+\n"
L"| Vt Domain | VR | SVID | IccMax | VoltMode | Vtarget | Voffset |\n"
L"|-----------|------|------|--------|----------|-----------|----------|\n"
);

for (UINTN didx = 0; didx < MAX_DOMAINS; didx++) {
@@ -151,8 +151,8 @@ VOID PrintPlatformSettings(IN PLATFORM* psys)

Print(
(dom->OffsetVolts < 0) ?
L"|%s| 0x%02x |%s| %03u A |%s| %04u mV | %04d mV | %03ux |\n" :
L"|%s| 0x%02x |%s| %03u A |%s| %04u mV | %03d mV | %03ux |\n",
L"|%s| 0x%02x |%s| %03u A |%s| %04u mV | %04d mV |\n" :
L"|%s| 0x%02x |%s| %03u A |%s| %04u mV | %03d mV |\n",

vrDomainColStr[didx & 0x7],

@@ -164,15 +164,14 @@ VOID PrintPlatformSettings(IN PLATFORM* psys)
&voltModeColStr[dom->VoltMode & 0x1][0],

(UINT32)dom->TargetVolts,
(INT32)dom->OffsetVolts,
(UINT32)dom->MaxRatio
(INT32)dom->OffsetVolts
);
}
}

Print(
L"+-----------+------+------+--------+----------+-----------+----------+------+\n"
L"\n\n");
L"+-----------+------+------+--------+----------+-----------+----------+\n"
L"\n");
}
}
}
Loading
Oops, something went wrong.

0 comments on commit de92efb

Please sign in to comment.