Skip to content

Commit

Permalink
Add support for setting a custom ARM frequency
Browse files Browse the repository at this point in the history
  • Loading branch information
mariobalanica authored and andreiw committed Feb 21, 2019
1 parent ee94e73 commit 0a680ae
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 14 deletions.
13 changes: 12 additions & 1 deletion Drivers/ConfigDxe/ConfigDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ SetupVariables (
PcdSet32 (PcdCpuClock, PcdGet32 (PcdCpuClock));
}

Size = sizeof (UINT32);
Status = gRT->GetVariable(L"CustomCpuClockRate",
&gConfigDxeFormSetGuid,
NULL, &Size, &Var32);
if (EFI_ERROR (Status)) {
PcdSet32 (PcdCustomCpuClockRate, PcdGet32 (PcdCustomCpuClockRate));
}

Size = sizeof (UINT32);
Status = gRT->GetVariable(L"SdIsArasan",
&gConfigDxeFormSetGuid,
Expand Down Expand Up @@ -249,6 +257,7 @@ ApplyVariables (
UINTN Gpio48Group;
EFI_STATUS Status;
UINT32 CpuClock = PcdGet32 (PcdCpuClock);
UINT32 CustomCpuClockRate = PcdGet32 (PcdCustomCpuClockRate);
UINT32 Rate = 0;

if (CpuClock != 0) {
Expand All @@ -262,14 +271,16 @@ ApplyVariables (
DEBUG((EFI_D_ERROR, "Couldn't get the max CPU speed, leaving as is: %r\n",
Status));
}
} else if (CpuClock == 3) {
Rate = CustomCpuClockRate * 1000000;
} else {
Rate = 600 * 1000000;
}
}

if (Rate != 0) {
DEBUG((EFI_D_INFO, "Setting CPU speed to %uHz\n", Rate));
Status = mFwProtocol->SetClockRate(RPI_FW_CLOCK_RATE_ARM, Rate);
Status = mFwProtocol->SetClockRate(RPI_FW_CLOCK_RATE_ARM, Rate, 1);
if (Status != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR, "Couldn't set the CPU speed: %r\n",
Status));
Expand Down
4 changes: 4 additions & 0 deletions Drivers/ConfigDxe/ConfigDxeHii.uni
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
#string STR_CHIPSET_CLOCK_CPU_NA #language en-US "Don't Override"
#string STR_CHIPSET_CLOCK_CPU_600MHZ #language en-US "Min (600MHz)"
#string STR_CHIPSET_CLOCK_CPU_MAX #language en-US "Max"
#string STR_CHIPSET_CLOCK_CPU_CUSTOM #language en-US "Custom"

#string STR_CHIPSET_CUSTOM_CPU_CLOCK_RATE_PROMPT #language en-US "CPU Clock Rate (MHz)"
#string STR_CHIPSET_CUSTOM_CPU_CLOCK_RATE_HELP #language en-US "Adjust the CPU speed.\nMin value: 100 MHz\nMax value: 1600 MHz\n\nWarning! Overclocking can make the system unbootable!"

#string STR_CHIPSET_SD_PROMPT #language en-US "uSD Routing"
#string STR_CHIPSET_SD_HELP #language en-US "Choose host controller to drive uSD slot"
Expand Down
21 changes: 21 additions & 0 deletions Drivers/ConfigDxe/ConfigDxeHii.vfr
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ typedef struct {
UINT32 Clock;
} CHIPSET_CPU_CLOCK_VARSTORE_DATA;

typedef struct {
UINT32 Clock;
} CHIPSET_CUSTOM_CPU_CLOCK_RATE_VARSTORE_DATA;

typedef struct {
/*
* 0 - uSD slot routed to Broadcom SDHOST.
Expand Down Expand Up @@ -175,6 +179,11 @@ formset
name = CpuClock,
guid = CONFIGDXE_FORM_SET_GUID;

efivarstore CHIPSET_CUSTOM_CPU_CLOCK_RATE_VARSTORE_DATA,
attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
name = CustomCpuClockRate,
guid = CONFIGDXE_FORM_SET_GUID;

efivarstore CHIPSET_SD_VARSTORE_DATA,
attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
name = SdIsArasan,
Expand Down Expand Up @@ -307,8 +316,20 @@ formset
option text = STRING_TOKEN(STR_CHIPSET_CLOCK_CPU_NA), value = 0, flags = DEFAULT;
option text = STRING_TOKEN(STR_CHIPSET_CLOCK_CPU_600MHZ), value = 1, flags = 0;
option text = STRING_TOKEN(STR_CHIPSET_CLOCK_CPU_MAX), value = 2, flags = 0;
option text = STRING_TOKEN(STR_CHIPSET_CLOCK_CPU_CUSTOM), value = 3, flags = 0;
endoneof;

grayoutif NOT ideqval CpuClock.Clock == 3;
numeric varid = CustomCpuClockRate.Clock,
prompt = STRING_TOKEN(STR_CHIPSET_CUSTOM_CPU_CLOCK_RATE_PROMPT),
help = STRING_TOKEN(STR_CHIPSET_CUSTOM_CPU_CLOCK_RATE_HELP),
flags = DISPLAY_UINT_DEC | NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
minimum = 100,
maximum = 1600,
default = 600,
endnumeric;
endif;

oneof varid = SdIsArasan.Routing,
prompt = STRING_TOKEN(STR_CHIPSET_SD_PROMPT),
help = STRING_TOKEN(STR_CHIPSET_SD_HELP),
Expand Down
4 changes: 3 additions & 1 deletion Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,8 @@ EFI_STATUS
EFIAPI
RpiFirmwareSetClockRate (
IN UINT32 ClockId,
IN UINT32 ClockRate
IN UINT32 ClockRate,
IN UINT32 SkipTurbo
)
{
RPI_FW_SET_CLOCK_RATE_CMD *Cmd;
Expand All @@ -827,6 +828,7 @@ RpiFirmwareSetClockRate (
Cmd->TagHead.TagValueSize = 0;
Cmd->TagBody.ClockId = ClockId;
Cmd->TagBody.ClockRate = ClockRate;
Cmd->TagBody.SkipTurbo = SkipTurbo;
Cmd->EndTag = 0;

Status = MailboxTransaction (Cmd->BufferHead.BufferSize, RPI_FW_MBOX_CHANNEL, &Result);
Expand Down
3 changes: 2 additions & 1 deletion Include/Protocol/RaspberryPiFirmware.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ typedef
EFI_STATUS
(EFIAPI *SET_CLOCK_RATE) (
IN UINT32 ClockId,
OUT UINT32 ClockRate
OUT UINT32 ClockRate,
IN UINT32 SkipTurbo
);

typedef
Expand Down
23 changes: 12 additions & 11 deletions RaspberryPiPkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,15 @@
gRaspberryPiTokenSpaceGuid.PcdHypWindowsDebugHook|0|UINT32|0x0000000b
gRaspberryPiTokenSpaceGuid.PcdHypWin2000Mask|0|UINT32|0x0000000c
gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d
gRaspberryPiTokenSpaceGuid.PcdSdIsArasan|0|UINT32|0x0000000e
gRaspberryPiTokenSpaceGuid.PcdMmcForce1Bit|0|UINT32|0x0000000f
gRaspberryPiTokenSpaceGuid.PcdMmcForceDefaultSpeed|0|UINT32|0x00000010
gRaspberryPiTokenSpaceGuid.PcdMmcSdDefaultSpeedMHz|0|UINT32|0x00000011
gRaspberryPiTokenSpaceGuid.PcdMmcSdHighSpeedMHz|0|UINT32|0x00000012
gRaspberryPiTokenSpaceGuid.PcdMmcDisableMulti|0|UINT32|0x00000013
gRaspberryPiTokenSpaceGuid.PcdDebugEnableJTAG|0|UINT32|0x00000014
gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit|0|UINT32|0x00000015
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|0|UINT32|0x00000016
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes|0|UINT8|0x00000017
gRaspberryPiTokenSpaceGuid.PcdDisplayLogoIndex|0|UINT8|0x00000018
gRaspberryPiTokenSpaceGuid.PcdCustomCpuClockRate|0|UINT32|0x0000000e
gRaspberryPiTokenSpaceGuid.PcdSdIsArasan|0|UINT32|0x0000000f
gRaspberryPiTokenSpaceGuid.PcdMmcForce1Bit|0|UINT32|0x00000010
gRaspberryPiTokenSpaceGuid.PcdMmcForceDefaultSpeed|0|UINT32|0x00000011
gRaspberryPiTokenSpaceGuid.PcdMmcSdDefaultSpeedMHz|0|UINT32|0x00000012
gRaspberryPiTokenSpaceGuid.PcdMmcSdHighSpeedMHz|0|UINT32|0x00000013
gRaspberryPiTokenSpaceGuid.PcdMmcDisableMulti|0|UINT32|0x00000014
gRaspberryPiTokenSpaceGuid.PcdDebugEnableJTAG|0|UINT32|0x00000015
gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit|0|UINT32|0x00000016
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot|0|UINT32|0x00000017
gRaspberryPiTokenSpaceGuid.PcdDisplayEnableScaledVModes|0|UINT8|0x00000018
gRaspberryPiTokenSpaceGuid.PcdDisplayLogoIndex|0|UINT8|0x00000019
1 change: 1 addition & 0 deletions RaspberryPiPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ DEFINE HYP_LOG_MASK = 0xffffffff
#

gRaspberryPiTokenSpaceGuid.PcdCpuClock|L"CpuClock"|gConfigDxeFormSetGuid|0x0|0
gRaspberryPiTokenSpaceGuid.PcdCustomCpuClockRate|L"CustomCpuClockRate"|gConfigDxeFormSetGuid|0x0|600

#
# SD-related.
Expand Down

0 comments on commit 0a680ae

Please sign in to comment.