From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by mx.groups.io with SMTP id smtpd.web11.4322.1583883086660220248 for ; Tue, 10 Mar 2020 16:31:27 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=xcJzFqv6; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.208.68, mailfrom: pete@akeo.ie) Received: by mail-ed1-f68.google.com with SMTP id ca19so512019edb.13 for ; Tue, 10 Mar 2020 16:31:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=akeo-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zLP8SXvKFV5kJuCWkLnWEtTm/2wP5QRBgZ7QZ7rJg+I=; b=xcJzFqv6xH/B5QUExsxXqDh6BzgJHaYUZPfnAUnCBem/DV7I1/HGGSZhkcyxxBUBho 4dudQwWWwbai55t1vTKIgaWPAOR2mN7Zeu/BphMsAFuQ7mIWgwmROsp+ubopGfb/k7vb c9dnDsI9pvzDb6kvVm+XEdcGsbQbsO3MbAuZ1tcz5Jf5TfxwlHEaWzjML7CDcUmkbJ2U DHkevJMdrEOpjrQ+OSyJxf5OaIZw1Q9fAVU9oVkpZUVATct8evaTQo0JUUNLu1jMP0Cc l40wCqbdcId/X7SwCNdkzZSX5Ot8DnH3Ss75P9nuPK0fCQSs95vDukXCk4aQ9AmNw/Il agOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zLP8SXvKFV5kJuCWkLnWEtTm/2wP5QRBgZ7QZ7rJg+I=; b=oQ2NwYV5jNXldb+gtaIqWC/QMIjj0NvdfQGK+UOPTgCTmHXQvsBlyVkIe+pBXOCb5w XJUp3gt3pEbmaKo/ILkHJdmn7IAd/QQHQ90yWQgJp3NaRHKGHPXG+wTC4oNGPIb1x90I zCCbnn+mrbS1yeiKZL3RwPV50aPx5gYAWhSlDDXk/RkshQjJN/Jz0NEAJUkG62VmEVuy HwxiTxir+oc/zDoLjMC/Xt7qtTdPdVgv2c90vichhW6i+QOg6veXyaUkdZVMvTCRHn+f 75jNpRRorCUbgYZabw2yX3DLMIazi3MLGwGVkVzIQzUP0EADHfdXdcpafeBVdlchDYj6 RzPQ== X-Gm-Message-State: ANhLgQ1hF6XuYVCljeXswlRWySHUYSLDAAY5lgQrxnfSMlrgcgJmr7fb 8BpUaYhf2m20iPJvn3VAOaazPX9u6Pg= X-Google-Smtp-Source: ADFU+vvW+IBg7EWjAXjheCGroiQCwnKcTVOWZUkyowFTB3NNFWEPDrEEf+CnFfEGLJL/f+Ir0FaBtQ== X-Received: by 2002:a05:6402:31ab:: with SMTP id dj11mr258972edb.143.1583883084604; Tue, 10 Mar 2020 16:31:24 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([84.203.66.228]) by smtp.gmail.com with ESMTPSA id cx3sm3252285edb.75.2020.03.10.16.31.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 10 Mar 2020 16:31:23 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif@nuviainc.com, philmd@redhat.com, awarkentin@vmware.com Subject: [edk2-devel][PATCH v2 1/1] Platform/RPi/ConfigDxe: Improve CPU Frequency configuration Date: Tue, 10 Mar 2020 23:31:11 +0000 Message-Id: <20200310233111.6732-2-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200310233111.6732-1-pete@akeo.ie> References: <20200310233111.6732-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Improve the CPU frequency settings of the platforms by: - Adding a "Default" option that sets the frequency to the official default for each model/submodel. - Adding a "Low" option, that sets the frequency to a fixed PCD, custom to each platform. - Using fixed PCDs to set the maximum and default values for the custom frequency range, according to the overclocking capabilities of the platform. - Ensuring that the firmware defaults to using the platform's default frequency, instead of a low arbitrary value. Signed-off-by: Pete Batard --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 41 ++++++++++++-------- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf | 5 +++ Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni | 6 +-- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 12 +++--- Platform/RaspberryPi/RPi3/RPi3.dsc | 11 +++++- Platform/RaspberryPi/RPi4/RPi4.dsc | 11 +++++- Platform/RaspberryPi/RaspberryPi.dec | 3 ++ 7 files changed, 60 insertions(+), 29 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index b4b13b6798f9..1091e680ff85 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -24,6 +24,8 @@ #include #include "ConfigDxeFormSetGuid.h" +#define FREQ_1_MHZ 1000000 + extern UINT8 ConfigDxeHiiBin[]; extern UINT8 ConfigDxeStrings[]; @@ -256,28 +258,35 @@ ApplyVariables ( UINT32 Rate = 0; UINT64 SystemMemorySize; - if (CpuClock != 0) { - if (CpuClock == 2) { - /* - * Maximum: 1.2GHz on RPi 3, 1.4GHz on RPi 3B+, unless - * overridden with arm_freq=xxx in config.txt. - */ - Status = mFwProtocol->GetMaxClockRate (RPI_MBOX_CLOCK_RATE_ARM, &Rate); - if (Status != EFI_SUCCESS) { - DEBUG ((DEBUG_ERROR, "Couldn't get the max CPU speed, leaving as is: %r\n", Status)); - } - } else if (CpuClock == 3) { - Rate = CustomCpuClock * 1000000; - } else { - Rate = 600 * 1000000; + switch (CpuClock) { + case 0: // Low + Rate = FixedPcdGet32 (PcdCpuLowSpeedMHz) * FREQ_1_MHZ; + break; + case 1: // Default + /* + * What the Raspberry Pi Foundation calls "max clock rate" is really the default value + * from: https://www.raspberrypi.org/documentation/configuration/config-txt/overclocking.md + */ + Status = mFwProtocol->GetMaxClockRate (RPI_MBOX_CLOCK_RATE_ARM, &Rate); + if (Status != EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR, "Couldn't read default CPU speed %r\n", Status)); } + break; + case 2: // Max + Rate = FixedPcdGet32 (PcdCpuMaxSpeedMHz) * FREQ_1_MHZ; + break; + case 3: // Custom + Rate = CustomCpuClock * FREQ_1_MHZ; + break; } if (Rate != 0) { - DEBUG ((DEBUG_INFO, "Setting CPU speed to %uHz\n", Rate)); + DEBUG ((DEBUG_INFO, "Setting CPU speed to %u MHz\n", Rate / FREQ_1_MHZ)); Status = mFwProtocol->SetClockRate (RPI_MBOX_CLOCK_RATE_ARM, Rate, 1); if (Status != EFI_SUCCESS) { DEBUG ((DEBUG_ERROR, "Couldn't set the CPU speed: %r\n", Status)); + } else { + PcdSet32 (PcdCustomCpuClock, Rate / FREQ_1_MHZ); } } @@ -285,7 +294,7 @@ ApplyVariables ( if (Status != EFI_SUCCESS) { DEBUG ((DEBUG_ERROR, "Couldn't get the CPU speed: %r\n", Status)); } else { - DEBUG ((DEBUG_INFO, "Current CPU speed is %uHz\n", Rate)); + DEBUG ((DEBUG_INFO, "Current CPU speed is %u MHz\n", Rate / FREQ_1_MHZ)); } if (mModelFamily >= 4 && PcdGet32 (PcdRamMoreThan3GB) != 0 && diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf index 736d49df562b..57963baf9c90 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf @@ -57,6 +57,11 @@ [Protocols] gRaspberryPiFirmwareProtocolGuid ## CONSUMES gRaspberryPiConfigAppliedProtocolGuid ## PRODUCES +[FixedPcd] + gRaspberryPiTokenSpaceGuid.PcdCpuLowSpeedMHz + gRaspberryPiTokenSpaceGuid.PcdCpuDefSpeedMHz + gRaspberryPiTokenSpaceGuid.PcdCpuMaxSpeedMHz + [Pcd] gBcm27xxTokenSpaceGuid.PcdBcm27xxRegistersAddress gBcm283xTokenSpaceGuid.PcdBcm283xRegistersAddress diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni index 77eda96d8136..046c75f9bfab 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni @@ -22,13 +22,13 @@ #string STR_CHIPSET_CLOCK_CPU_PROMPT #language en-US "CPU Clock" #string STR_CHIPSET_CLOCK_CPU_HELP #language en-US "CPU Speed" -#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_LOW #language en-US "Low" +#string STR_CHIPSET_CLOCK_CPU_DEF #language en-US "Default" #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_PROMPT #language en-US "CPU Clock Rate (MHz)" -#string STR_CHIPSET_CUSTOM_CPU_CLOCK_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_CUSTOM_CPU_CLOCK_HELP #language en-US "Manually set the CPU Speed\n\nWarning: Overclocking can make the system unbootable!" /* * Advanced configuration. diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr index 9c2fd64a8e27..bab96885b78c 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr @@ -53,8 +53,8 @@ typedef struct { typedef struct { /* - * 0 - don't change the clock rate. - * 1 - 600MHz. + * 0 - low. + * 1 - default. * 2 - maximum. * 3 - custom. */ @@ -253,8 +253,8 @@ formset prompt = STRING_TOKEN(STR_CHIPSET_CLOCK_CPU_PROMPT), help = STRING_TOKEN(STR_CHIPSET_CLOCK_CPU_HELP), flags = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED, - 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_LOW), value = 0, flags = 0; + option text = STRING_TOKEN(STR_CHIPSET_CLOCK_CPU_DEF), value = 1, flags = DEFAULT; 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; @@ -265,8 +265,8 @@ formset help = STRING_TOKEN(STR_CHIPSET_CUSTOM_CPU_CLOCK_HELP), flags = DISPLAY_UINT_DEC | NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED, minimum = 100, - maximum = 1600, - default = 600, + maximum = FixedPcdGet32 (PcdCpuMaxSpeedMHz), + default = FixedPcdGet32 (PcdCpuDefSpeedMHz), endnumeric; endif; endform; diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3/RPi3.dsc index 91d5738afbc6..d92f5cc1863d 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -396,6 +396,13 @@ [PcdsFixedAtBuild.common] gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200 gEfiMdePkgTokenSpaceGuid.PcdUartDefaultReceiveFifoDepth|0 + # + # Fixed CPU settings. + # + gRaspberryPiTokenSpaceGuid.PcdCpuLowSpeedMHz|600 + gRaspberryPiTokenSpaceGuid.PcdCpuDefSpeedMHz|1200 + gRaspberryPiTokenSpaceGuid.PcdCpuMaxSpeedMHz|1500 + ## Default Terminal Type ## 0-PCANSI, 1-VT100, 2-VT00+, 3-UTF8, 4-TTYTERM gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 @@ -412,8 +419,8 @@ [PcdsDynamicHii.common.DEFAULT] # Clock overrides. # - gRaspberryPiTokenSpaceGuid.PcdCpuClock|L"CpuClock"|gConfigDxeFormSetGuid|0x0|0 - gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock|L"CustomCpuClock"|gConfigDxeFormSetGuid|0x0|600 + gRaspberryPiTokenSpaceGuid.PcdCpuClock|L"CpuClock"|gConfigDxeFormSetGuid|0x0|1 + gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock|L"CustomCpuClock"|gConfigDxeFormSetGuid|0x0|gRaspberryPiTokenSpaceGuid.PcdCpuDefSpeedMHz # # SD-related. diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4/RPi4.dsc index 2e98c3e16b91..aabf3566360f 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -435,6 +435,13 @@ [PcdsFixedAtBuild.common] gArmTokenSpaceGuid.PcdGicDistributorBase|0xFF841000 gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0xFF842000 + # + # Fixed CPU settings. + # + gRaspberryPiTokenSpaceGuid.PcdCpuLowSpeedMHz|800 + gRaspberryPiTokenSpaceGuid.PcdCpuDefSpeedMHz|1500 + gRaspberryPiTokenSpaceGuid.PcdCpuMaxSpeedMHz|2200 + ## Default Terminal Type ## 0-PCANSI, 1-VT100, 2-VT00+, 3-UTF8, 4-TTYTERM gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 @@ -451,8 +458,8 @@ [PcdsDynamicHii.common.DEFAULT] # Clock overrides. # - gRaspberryPiTokenSpaceGuid.PcdCpuClock|L"CpuClock"|gConfigDxeFormSetGuid|0x0|0 - gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock|L"CustomCpuClock"|gConfigDxeFormSetGuid|0x0|600 + gRaspberryPiTokenSpaceGuid.PcdCpuClock|L"CpuClock"|gConfigDxeFormSetGuid|0x0|1 + gRaspberryPiTokenSpaceGuid.PcdCustomCpuClock|L"CustomCpuClock"|gConfigDxeFormSetGuid|0x0|gRaspberryPiTokenSpaceGuid.PcdCpuDefSpeedMHz # # SD-related. diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.dec index 1355cdee0534..b51eefeb09fb 100644 --- a/Platform/RaspberryPi/RaspberryPi.dec +++ b/Platform/RaspberryPi/RaspberryPi.dec @@ -44,6 +44,9 @@ [PcdsFixedAtBuild.common] gRaspberryPiTokenSpaceGuid.PcdNvStorageFtwWorkingBase|0x0|UINT32|0x00000007 gRaspberryPiTokenSpaceGuid.PcdExtendedMemoryBase|0x0|UINT32|0x00000008 gRaspberryPiTokenSpaceGuid.PcdFdtSize|0x10000|UINT32|0x00000009 + gRaspberryPiTokenSpaceGuid.PcdCpuLowSpeedMHz|600|UINT32|0x0000000a + gRaspberryPiTokenSpaceGuid.PcdCpuDefSpeedMHz|800|UINT32|0x0000000b + gRaspberryPiTokenSpaceGuid.PcdCpuMaxSpeedMHz|1000|UINT32|0x0000000c [PcdsFixedAtBuild, PcdsPatchableInModule, PcdsDynamic, PcdsDynamicEx] gRaspberryPiTokenSpaceGuid.PcdCpuClock|0|UINT32|0x0000000d -- 2.21.0.windows.1