Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Pete Batard <p...@akeo.ie>
---
 Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.c            | 351 
++++++++++++++++++++
 Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.inf          |  78 +++++
 Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeFormSetGuid.h |  23 ++
 Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeHii.uni       | 100 ++++++
 Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeHii.vfr       | 306 
+++++++++++++++++
 5 files changed, 858 insertions(+)

diff --git a/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.c 
b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.c
new file mode 100644
index 000000000000..b78d7deae402
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.c
@@ -0,0 +1,351 @@
+/** @file
+ *
+ *  Copyright (c) 2018, Andrei Warkentin <andrey.warken...@gmail.com>
+ *
+ *  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.
+ *
+ **/
+
+#include <Uefi.h>
+#include <Library/HiiLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/DevicePathLib.h>
+#include <IndustryStandard/RpiMbox.h>
+#include <IndustryStandard/Bcm2836Gpio.h>
+#include <Library/GpioLib.h>
+#include <Protocol/RpiFirmware.h>
+#include "ConfigDxeFormSetGuid.h"
+
+extern UINT8 ConfigDxeHiiBin[];
+extern UINT8 ConfigDxeStrings[];
+
+STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
+
+typedef struct {
+  VENDOR_DEVICE_PATH VendorDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL End;
+} HII_VENDOR_DEVICE_PATH;
+
+STATIC HII_VENDOR_DEVICE_PATH mVendorDevicePath = {
+  {
+    {
+      HARDWARE_DEVICE_PATH,
+      HW_VENDOR_DP,
+      {
+        (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
+        (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
+      }
+    },
+    CONFIGDXE_FORM_SET_GUID
+  },
+  {
+    END_DEVICE_PATH_TYPE,
+    END_ENTIRE_DEVICE_PATH_SUBTYPE,
+    {
+      (UINT8)(END_DEVICE_PATH_LENGTH),
+      (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
+    }
+  }
+};
+
+
+STATIC EFI_STATUS
+InstallHiiPages (
+  VOID
+  )
+{
+  EFI_STATUS     Status;
+  EFI_HII_HANDLE HiiHandle;
+  EFI_HANDLE     DriverHandle;
+
+  DriverHandle = NULL;
+  Status = gBS->InstallMultipleProtocolInterfaces (&DriverHandle,
+                  &gEfiDevicePathProtocolGuid,
+                  &mVendorDevicePath,
+                  NULL);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  HiiHandle = HiiAddPackages (&gConfigDxeFormSetGuid,
+                DriverHandle,
+                ConfigDxeStrings,
+                ConfigDxeHiiBin,
+                NULL);
+
+  if (HiiHandle == NULL) {
+    gBS->UninstallMultipleProtocolInterfaces (DriverHandle,
+           &gEfiDevicePathProtocolGuid,
+           &mVendorDevicePath,
+           NULL);
+    return EFI_OUT_OF_RESOURCES;
+  }
+  return EFI_SUCCESS;
+}
+
+
+STATIC EFI_STATUS
+SetupVariables (
+  VOID
+  )
+{
+  UINTN Size;
+  UINT32 Var32;
+  EFI_STATUS Status;
+
+  /*
+   * Create the vars with default value.
+   * If we don't, forms won't be able to update.
+   */
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"CpuClock",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdCpuClock, PcdGet32 (PcdCpuClock));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"SdIsArasan",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdSdIsArasan, PcdGet32 (PcdSdIsArasan));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"MmcDisableMulti",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdMmcDisableMulti, PcdGet32 (PcdMmcDisableMulti));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"MmcForce1Bit",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdMmcForce1Bit, PcdGet32 (PcdMmcForce1Bit));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"MmcForceDefaultSpeed",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdMmcForceDefaultSpeed, PcdGet32 (PcdMmcForceDefaultSpeed));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"MmcSdDefaultSpeedMHz",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdMmcSdDefaultSpeedMHz, PcdGet32 (PcdMmcSdDefaultSpeedMHz));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"MmcSdHighSpeedMHz",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdMmcSdHighSpeedMHz, PcdGet32 (PcdMmcSdHighSpeedMHz));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"DebugEnableJTAG",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdDebugEnableJTAG, PcdGet32 (PcdDebugEnableJTAG));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"DebugShowUEFIExit",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdDebugShowUEFIExit, PcdGet32 (PcdDebugShowUEFIExit));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"DisplayEnableVModes",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdDisplayEnableVModes, PcdGet32 (PcdDisplayEnableVModes));
+  }
+
+  Size = sizeof (UINT32);
+  Status = gRT->GetVariable (L"DisplayEnableSShot",
+                  &gConfigDxeFormSetGuid,
+                  NULL, &Size, &Var32);
+  if (EFI_ERROR (Status)) {
+    PcdSet32 (PcdDisplayEnableSShot, PcdGet32 (PcdDisplayEnableSShot));
+  }
+
+  return EFI_SUCCESS;
+}
+
+
+STATIC VOID
+ApplyVariables (
+  VOID
+  )
+{
+  UINTN Gpio34Group;
+  UINTN Gpio48Group;
+  EFI_STATUS Status;
+  UINT32 CpuClock = PcdGet32 (PcdCpuClock);
+  UINT32 Rate = 0;
+
+  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 {
+      Rate = 600 * 1000000;
+    }
+  }
+
+  if (Rate != 0) {
+    DEBUG ((DEBUG_INFO, "Setting CPU speed to %uHz\n", Rate));
+    Status = mFwProtocol->SetClockRate (RPI_MBOX_CLOCK_RATE_ARM, Rate);
+    if (Status != EFI_SUCCESS) {
+      DEBUG ((DEBUG_ERROR, "Couldn't set the CPU speed: %r\n", Status));
+    }
+  }
+
+  Status = mFwProtocol->GetClockRate (RPI_MBOX_CLOCK_RATE_ARM, &Rate);
+  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));
+  }
+
+  /*
+   * Switching two groups around, so disable both first.
+   *
+   * No, I've not seen a problem, but having a group be
+   * routed to two sets of pins seems like asking for trouble.
+   */
+  GpioPinFuncSet (34, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (35, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (36, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (37, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (38, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (39, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (48, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (49, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (50, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (51, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (52, GPIO_FSEL_INPUT);
+  GpioPinFuncSet (53, GPIO_FSEL_INPUT);
+  if (PcdGet32 (PcdSdIsArasan)) {
+    DEBUG ((DEBUG_INFO, "Routing SD to Arasan\n"));
+    Gpio48Group = GPIO_FSEL_ALT3;
+    /*
+     * Route SDIO to SdHost.
+     */
+    Gpio34Group = GPIO_FSEL_ALT0;
+  } else {
+    DEBUG ((DEBUG_INFO, "Routing SD to SdHost\n"));
+    Gpio48Group = GPIO_FSEL_ALT0;
+    /*
+     * Route SDIO to Arasan.
+     */
+    Gpio34Group = GPIO_FSEL_ALT3;
+  }
+  GpioPinFuncSet (34, Gpio34Group);
+  GpioPinFuncSet (35, Gpio34Group);
+  GpioPinFuncSet (36, Gpio34Group);
+  GpioPinFuncSet (37, Gpio34Group);
+  GpioPinFuncSet (38, Gpio34Group);
+  GpioPinFuncSet (39, Gpio34Group);
+  GpioPinFuncSet (48, Gpio48Group);
+  GpioPinFuncSet (49, Gpio48Group);
+  GpioPinFuncSet (50, Gpio48Group);
+  GpioPinFuncSet (51, Gpio48Group);
+  GpioPinFuncSet (52, Gpio48Group);
+  GpioPinFuncSet (53, Gpio48Group);
+
+  /*
+   * JTAG pin    JTAG sig    GPIO      Mode    Header pin
+   * 1           VREF        N/A               1
+   * 3           nTRST       GPIO22    ALT4    15
+   * 4           GND         N/A               9
+   * 5           TDI         GPIO4     ALT5    7
+   * 7           TMS         GPIO27    ALT4    13
+   * 9           TCK         GPIO25    ALT4    22
+   * 11          RTCK        GPIO23    ALT4    16
+   * 13          TDO         GPIO24    ALT4    18
+   */
+  if (PcdGet32 (PcdDebugEnableJTAG)) {
+    GpioPinFuncSet (22, GPIO_FSEL_ALT4);
+    GpioPinFuncSet (4, GPIO_FSEL_ALT5);
+    GpioPinFuncSet (27, GPIO_FSEL_ALT4);
+    GpioPinFuncSet (25, GPIO_FSEL_ALT4);
+    GpioPinFuncSet (23, GPIO_FSEL_ALT4);
+    GpioPinFuncSet (24, GPIO_FSEL_ALT4);
+  } else {
+    GpioPinFuncSet (22, GPIO_FSEL_INPUT);
+    GpioPinFuncSet (4, GPIO_FSEL_INPUT);
+    GpioPinFuncSet (27, GPIO_FSEL_INPUT);
+    GpioPinFuncSet (25, GPIO_FSEL_INPUT);
+    GpioPinFuncSet (23, GPIO_FSEL_INPUT);
+    GpioPinFuncSet (24, GPIO_FSEL_INPUT);
+  }
+}
+
+
+EFI_STATUS
+EFIAPI
+ConfigInitialize (
+  IN EFI_HANDLE ImageHandle,
+  IN EFI_SYSTEM_TABLE *SystemTable
+  )
+{
+  EFI_STATUS Status;
+
+  Status = gBS->LocateProtocol (&gRaspberryPiFirmwareProtocolGuid,
+                  NULL, (VOID**)&mFwProtocol);
+  ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = SetupVariables ();
+  if (Status != EFI_SUCCESS) {
+    DEBUG ((DEBUG_ERROR, "Couldn't not setup NV vars: %r\n", Status));
+  }
+
+  ApplyVariables ();
+  Status = gBS->InstallProtocolInterface (&ImageHandle,
+                  &gRaspberryPiConfigAppliedProtocolGuid,
+                  EFI_NATIVE_INTERFACE,
+                  NULL);
+  ASSERT_EFI_ERROR (Status);
+
+  Status = InstallHiiPages ();
+  if (Status != EFI_SUCCESS) {
+    DEBUG ((DEBUG_ERROR, "Couldn't install ConfigDxe configuration pages: 
%r\n", Status));
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.inf 
b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.inf
new file mode 100644
index 000000000000..d24a0daa0346
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.inf
@@ -0,0 +1,78 @@
+#/** @file
+#
+#  Copyright (c) 2018, Andrei Warkentin <andrey.warken...@gmail.com>
+#
+#  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.
+#
+#**/
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = ConfigDxe
+  FILE_GUID                      = 755cbac2-b23f-4b92-bc8e-fb01ce5907b7
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = ConfigInitialize
+
+#
+# The following information is for reference only and not required by the build
+# tools.
+#
+#  VALID_ARCHITECTURES           = AARCH64
+#
+
+[Sources]
+  ConfigDxe.c
+  ConfigDxeHii.vfr
+  ConfigDxeHii.uni
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  ArmPlatformPkg/ArmPlatformPkg.dec
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  Silicon/Broadcom/Bcm283x/Bcm283x.dec
+  Platform/Raspberry/Pi3/RPi3.dec
+
+[LibraryClasses]
+  BaseLib
+  DebugLib
+  DxeServicesTableLib
+  PcdLib
+  UefiBootServicesTableLib
+  UefiRuntimeServicesTableLib
+  UefiDriverEntryPoint
+  HiiLib
+  GpioLib
+
+[Guids]
+  gConfigDxeFormSetGuid
+
+[Protocols]
+  gRaspberryPiFirmwareProtocolGuid ## CONSUMES
+  gRaspberryPiConfigAppliedProtocolGuid ## PRODUCES
+
+[Pcd]
+  gRaspberryPiTokenSpaceGuid.PcdCpuClock
+  gRaspberryPiTokenSpaceGuid.PcdSdIsArasan
+  gRaspberryPiTokenSpaceGuid.PcdMmcForce1Bit
+  gRaspberryPiTokenSpaceGuid.PcdMmcForceDefaultSpeed
+  gRaspberryPiTokenSpaceGuid.PcdMmcSdDefaultSpeedMHz
+  gRaspberryPiTokenSpaceGuid.PcdMmcSdHighSpeedMHz
+  gRaspberryPiTokenSpaceGuid.PcdMmcDisableMulti
+  gRaspberryPiTokenSpaceGuid.PcdDebugEnableJTAG
+  gRaspberryPiTokenSpaceGuid.PcdDebugShowUEFIExit
+  gRaspberryPiTokenSpaceGuid.PcdDisplayEnableVModes
+  gRaspberryPiTokenSpaceGuid.PcdDisplayEnableSShot
+
+[FeaturePcd]
+
+[Depex]
+  gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid
diff --git a/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeFormSetGuid.h 
b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeFormSetGuid.h
new file mode 100644
index 000000000000..b29ae3a42461
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeFormSetGuid.h
@@ -0,0 +1,23 @@
+/** @file
+ *
+ *  Copyright (c) 2018 Andrei Warkentin <andrey.warken...@gmail.com>
+ *
+ *  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.
+ *
+ **/
+
+#ifndef CONFIGDXE_FORM_SET_GUID_H
+#define CONFIGDXE_FORM_SET_GUID_H
+
+#define CONFIGDXE_FORM_SET_GUID \
+  {0xCD7CC258, 0x31DB, 0x22E6, {0x9F, 0x22, 0x63, 0xB0, 0xB8, 0xEE, 0xD6, 
0xB5}}
+
+extern EFI_GUID gConfigDxeFormSetGuid;
+
+#endif /* CONFIGDXE_FORM_SET_GUID_H */
diff --git a/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeHii.uni 
b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeHii.uni
new file mode 100644
index 000000000000..bf09261d5e4a
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeHii.uni
@@ -0,0 +1,100 @@
+/** @file
+ *
+ *  Copyright (c) 2018, Andrei Warkentin <andrey.warken...@gmail.com>
+ *
+ *  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.
+ *
+ **/
+
+#langdef en-US  "English"
+
+#string STR_NULL_STRING          #language en-US ""
+
+#string STR_FORM_SET_TITLE       #language en-US "Raspberry Pi Configuration"
+#string STR_FORM_SET_TITLE_HELP  #language en-US "Press <Enter> to configure 
system settings."
+
+/*
+ * Chipset config.
+ */
+
+#string STR_CHIPSET_FORM_TITLE      #language en-US "Chipset Configuration"
+#string STR_CHIPSET_FORM_SUBTITLE   #language en-US "Note: OS may override 
settings when booted."
+
+#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_MAX    #language en-US "Max"
+
+#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"
+#string STR_CHIPSET_SD_SDHOST        #language en-US "Broadcom SDHOST"
+#string STR_CHIPSET_SD_ARASAN        #language en-US "Arasan SDHCI"
+
+/*
+ * MMC/SD configuration.
+ */
+
+#string STR_MMC_FORM_TITLE       #language en-US "SD/MMC Tweaks"
+#string STR_MMC_FORM_SUBTITLE    #language en-US "Note: UEFI only, OS will 
override settings when booted."
+
+#string STR_MMC_DISMULTI_PROMPT  #language en-US "Multi-Block Support"
+#string STR_MMC_DISMULTI_HELP    #language en-US "Use CMD18/CMD25 for 
transfers when possible"
+#string STR_MMC_DISMULTI_N       #language en-US "Multi-block transfers"
+#string STR_MMC_DISMULTI_Y       #language en-US "Single-block transfers"
+
+#string STR_MMC_FORCE1BIT_PROMPT #language en-US "uSD Max Bus Width"
+#string STR_MMC_FORCE1BIT_HELP   #language en-US "Tweak for bad media"
+#string STR_MMC_FORCE1BIT_Y      #language en-US "1 Bit Mode"
+#string STR_MMC_FORCE1BIT_N      #language en-US "4 Bit Mode"
+
+#string STR_MMC_FORCEDS_PROMPT   #language en-US "uSD Force Default Speed"
+#string STR_MMC_FORCEDS_HELP     #language en-US "Tweak for bad media"
+#string STR_MMC_FORCEDS_Y        #language en-US "Force Default Speed"
+#string STR_MMC_FORCEDS_N        #language en-US "Allow High Speed"
+
+#string STR_MMC_SD_DS_PROMPT     #language en-US "SD Default Speed (MHz)"
+#string STR_MMC_SD_DS_HELP       #language en-US "Override default 25Mhz"
+
+#string STR_MMC_SD_HS_PROMPT     #language en-US "SD High Speed (MHz)"
+#string STR_MMC_SD_HS_HELP       #language en-US "Override default 50Mhz"
+
+
+/*
+ * Display settings.
+ */
+
+#string STR_DISPLAY_FORM_TITLE      #language en-US "Display"
+#string STR_DISPLAY_FORM_SUBTITLE   #language en-US "UEFI video driver 
settings"
+
+#string STR_DISPLAY_VMODES_PROMPT   #language en-US "Resolutions"
+#string STR_DISPLAY_VMODES_HELP     #language en-US "Support for non-native 
modes"
+#string STR_DISPLAY_VMODES_ENABLE   #language en-US "Also support 640x480, 
800x600, 1024x768, 720p and 1080p"
+#string STR_DISPLAY_VMODES_DISABLE  #language en-US "Only native resolution"
+
+#string STR_DISPLAY_SSHOT_PROMPT    #language en-US "Screenshot Support"
+#string STR_DISPLAY_SSHOT_HELP      #language en-US "Save screen capture as a 
BMP on the first writable file system found"
+#string STR_DISPLAY_SSHOT_ENABLE    #language en-US "Control-Alt-F12"
+#string STR_DISPLAY_SSHOT_DISABLE   #language en-US "Not Enabled"
+
+/*
+ * Debugging settings go here.
+ */
+#string STR_DEBUG_FORM_TITLE        #language en-US "Debugging"
+#string STR_DEBUG_FORM_SUBTITLE     #language en-US "For UEFI/OS Developers"
+
+#string STR_DEBUG_JTAG_PROMPT       #language en-US "JTAG Routing"
+#string STR_DEBUG_JTAG_HELP         #language en-US "Signals (nTRST, TDI, TMS, 
TCK, RTCK, TDO) -> Header pins (15, 7, 13, 22, 16, 18)"
+#string STR_DEBUG_JTAG_ENABLE       #language en-US "Enable JTAG via GPIO"
+#string STR_DEBUG_JTAG_DISABLE      #language en-US "Disable JTAG"
+
+#string STR_DEBUG_EXIT_SHOW_PROMPT  #language en-US "Verbose ExitBootServices"
+#string STR_DEBUG_EXIT_SHOW_HELP    #language en-US "Show message when UEFI 
hands off to OS"
+#string STR_DEBUG_EXIT_SHOW_NO      #language en-US "Do nothing"
+#string STR_DEBUG_EXIT_SHOW_YES     #language en-US "Show farewell message"
diff --git a/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeHii.vfr 
b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeHii.vfr
new file mode 100644
index 000000000000..d3d98acc2edf
--- /dev/null
+++ b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxeHii.vfr
@@ -0,0 +1,306 @@
+/** @file
+ *
+ *  Copyright (c) 2018 Andrei Warkentin <andrey.warken...@gmail.com>
+ *
+ *  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.
+ *
+ **/
+
+#include <Guid/HiiPlatformSetupFormset.h>
+#include "ConfigDxeFormSetGuid.h"
+
+typedef struct {
+  /*
+   * 0 - One mode for the boot resolution.
+   * 1 - Adds additional "typical" resolutions like
+   *     640x480, 800x600, 1024 x 768, 720p and 1080p.
+   */
+   UINT32 Enable;
+} DISPLAY_ENABLE_VMODES_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * 0 - No screenshot support.
+   * 1 - Screenshot support via hotkey.
+   */
+   UINT32 Enable;
+} DISPLAY_ENABLE_SSHOT_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * 0 - No JTAG.
+   * 1 - JTAG mode.
+   */
+   UINT32 Enable;
+} DEBUG_ENABLE_JTAG_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * 0 - Don't show UEFI exit message.
+   * 1 - Show UEFI exit message.
+   */
+   UINT32 Show;
+} DEBUG_SHOW_UEFI_EXIT_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * 0 - don't change the clock rate.
+   * 1 - 600MHz.
+   * 2 - maximum.
+   */
+  UINT32 Clock;
+} CHIPSET_CPU_CLOCK_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * 0 - uSD slot routed to Broadcom SDHOST.
+   * 1 - uSD slot routed to Arasan SDHCI.
+   */
+  UINT32 Routing;
+} CHIPSET_SD_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * 0 - Don't disable multi-block.
+   * 1 - Disable multi-block commands.
+   */
+  UINT32 DisableMulti;
+} MMC_DISMULTI_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * 0 - Don't force 1 bit mode.
+   * 1 - Force 1 bit mode.
+   */
+  UINT32 Force1Bit;
+} MMC_FORCE1BIT_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * 0 - Don't force default speed.
+   * 1 - Force default speed.
+   */
+  UINT32 ForceDS;
+} MMC_FORCEDS_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * Default Speed MHz override (25MHz default).
+   */
+  UINT32 MHz;
+} MMC_SD_DS_MHZ_VARSTORE_DATA;
+
+typedef struct {
+  /*
+   * High Speed MHz override (50MHz default).
+   */
+  UINT32 MHz;
+} MMC_SD_HS_MHZ_VARSTORE_DATA;
+
+//
+// EFI Variable attributes
+//
+#define EFI_VARIABLE_NON_VOLATILE       0x00000001
+#define EFI_VARIABLE_BOOTSERVICE_ACCESS 0x00000002
+#define EFI_VARIABLE_RUNTIME_ACCESS     0x00000004
+#define EFI_VARIABLE_READ_ONLY          0x00000008
+
+formset
+    guid      = CONFIGDXE_FORM_SET_GUID,
+    title     = STRING_TOKEN(STR_FORM_SET_TITLE),
+    help      = STRING_TOKEN(STR_FORM_SET_TITLE_HELP),
+    classguid = EFI_HII_PLATFORM_SETUP_FORMSET_GUID,
+
+    efivarstore CHIPSET_CPU_CLOCK_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = CpuClock,
+      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,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore MMC_DISMULTI_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = MmcDisableMulti,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore MMC_FORCE1BIT_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = MmcForce1Bit,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore MMC_FORCEDS_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = MmcForceDefaultSpeed,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore MMC_SD_DS_MHZ_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = MmcSdDefaultSpeedMHz,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore MMC_SD_HS_MHZ_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = MmcSdHighSpeedMHz,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore DEBUG_ENABLE_JTAG_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = DebugEnableJTAG,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore DEBUG_SHOW_UEFI_EXIT_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = DebugShowUEFIExit,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore DISPLAY_ENABLE_VMODES_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = DisplayEnableVModes,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    efivarstore DISPLAY_ENABLE_SSHOT_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | 
EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = DisplayEnableSShot,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
+    form formid = 1,
+        title  = STRING_TOKEN(STR_FORM_SET_TITLE);
+        subtitle text = STRING_TOKEN(STR_NULL_STRING);
+
+        goto 0x1002,
+           prompt = STRING_TOKEN(STR_CHIPSET_FORM_TITLE),
+           help = STRING_TOKEN(STR_NULL_STRING);
+
+        goto 0x1003,
+           prompt = STRING_TOKEN(STR_MMC_FORM_TITLE),
+           help = STRING_TOKEN(STR_NULL_STRING);
+
+        goto 0x1004,
+            prompt = STRING_TOKEN(STR_DISPLAY_FORM_TITLE),
+            help = STRING_TOKEN(STR_NULL_STRING);
+
+        goto 0x1005,
+            prompt = STRING_TOKEN(STR_DEBUG_FORM_TITLE),
+            help = STRING_TOKEN(STR_NULL_STRING);
+    endform;
+
+    form formid = 0x1002,
+        title  = STRING_TOKEN(STR_CHIPSET_FORM_TITLE);
+        subtitle text = STRING_TOKEN(STR_CHIPSET_FORM_SUBTITLE);
+
+        oneof varid = CpuClock.Clock,
+            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_MAX), value = 2, 
flags = 0;
+        endoneof;
+
+        oneof varid = SdIsArasan.Routing,
+            prompt      = STRING_TOKEN(STR_CHIPSET_SD_PROMPT),
+            help        = STRING_TOKEN(STR_CHIPSET_SD_HELP),
+            flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+            option text = STRING_TOKEN(STR_CHIPSET_SD_ARASAN), value = 1, 
flags = 0;
+            option text = STRING_TOKEN(STR_CHIPSET_SD_SDHOST), value = 0, 
flags = DEFAULT;
+        endoneof;
+    endform;
+
+    form formid = 0x1003,
+        title  = STRING_TOKEN(STR_MMC_FORM_TITLE);
+        subtitle text = STRING_TOKEN(STR_MMC_FORM_SUBTITLE);
+
+        oneof varid = MmcDisableMulti.DisableMulti,
+            prompt      = STRING_TOKEN(STR_MMC_DISMULTI_PROMPT),
+            help        = STRING_TOKEN(STR_MMC_DISMULTI_HELP),
+            flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+            option text = STRING_TOKEN(STR_MMC_DISMULTI_N), value = 0, flags = 
DEFAULT;
+            option text = STRING_TOKEN(STR_MMC_DISMULTI_Y), value = 1, flags = 
0;
+        endoneof;
+
+        oneof varid = MmcForce1Bit.Force1Bit,
+            prompt      = STRING_TOKEN(STR_MMC_FORCE1BIT_PROMPT),
+            help        = STRING_TOKEN(STR_MMC_FORCE1BIT_HELP),
+            flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+            option text = STRING_TOKEN(STR_MMC_FORCE1BIT_N), value = 0, flags 
= DEFAULT;
+            option text = STRING_TOKEN(STR_MMC_FORCE1BIT_Y), value = 1, flags 
= 0;
+        endoneof;
+
+        oneof varid = MmcForceDefaultSpeed.ForceDS,
+            prompt      = STRING_TOKEN(STR_MMC_FORCEDS_PROMPT),
+            help        = STRING_TOKEN(STR_MMC_FORCEDS_HELP),
+            flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+            option text = STRING_TOKEN(STR_MMC_FORCEDS_N), value = 0, flags = 
DEFAULT;
+            option text = STRING_TOKEN(STR_MMC_FORCEDS_Y), value = 1, flags = 
0;
+        endoneof;
+
+        numeric varid = MmcSdDefaultSpeedMHz.MHz,
+             prompt  = STRING_TOKEN(STR_MMC_SD_DS_PROMPT),
+             help    = STRING_TOKEN(STR_MMC_SD_DS_HELP),
+             flags   = DISPLAY_UINT_DEC | NUMERIC_SIZE_4 | INTERACTIVE | 
RESET_REQUIRED,
+             minimum = 25,
+             maximum = 100,
+             default = 25,
+        endnumeric;
+
+        numeric varid = MmcSdHighSpeedMHz.MHz,
+             prompt  = STRING_TOKEN(STR_MMC_SD_HS_PROMPT),
+             help    = STRING_TOKEN(STR_MMC_SD_HS_HELP),
+             flags   = DISPLAY_UINT_DEC | NUMERIC_SIZE_4 | INTERACTIVE | 
RESET_REQUIRED,
+             minimum = 50,
+             maximum = 100,
+             default = 50,
+        endnumeric;
+    endform;
+
+    form formid = 0x1004,
+        title  = STRING_TOKEN(STR_DISPLAY_FORM_TITLE);
+        subtitle text = STRING_TOKEN(STR_DISPLAY_FORM_SUBTITLE);
+
+        oneof varid = DisplayEnableVModes.Enable,
+            prompt      = STRING_TOKEN(STR_DISPLAY_VMODES_PROMPT),
+            help        = STRING_TOKEN(STR_DISPLAY_VMODES_HELP),
+            flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+            option text = STRING_TOKEN(STR_DISPLAY_VMODES_ENABLE), value = 1, 
flags = DEFAULT;
+            option text = STRING_TOKEN(STR_DISPLAY_VMODES_DISABLE), value = 0, 
flags = 0;
+        endoneof;
+
+        oneof varid = DisplayEnableSShot.Enable,
+            prompt      = STRING_TOKEN(STR_DISPLAY_SSHOT_PROMPT),
+            help        = STRING_TOKEN(STR_DISPLAY_SSHOT_HELP),
+            flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+            option text = STRING_TOKEN(STR_DISPLAY_SSHOT_ENABLE), value = 1, 
flags = DEFAULT;
+            option text = STRING_TOKEN(STR_DISPLAY_SSHOT_DISABLE), value = 0, 
flags = 0;
+        endoneof;
+    endform;
+
+    form formid = 0x1005,
+        title  = STRING_TOKEN(STR_DEBUG_FORM_TITLE);
+        subtitle text = STRING_TOKEN(STR_DEBUG_FORM_SUBTITLE);
+
+        oneof varid = DebugEnableJTAG.Enable,
+            prompt      = STRING_TOKEN(STR_DEBUG_JTAG_PROMPT),
+            help        = STRING_TOKEN(STR_DEBUG_JTAG_HELP),
+            flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+            option text = STRING_TOKEN(STR_DEBUG_JTAG_ENABLE), value = 1, 
flags = 0;
+            option text = STRING_TOKEN(STR_DEBUG_JTAG_DISABLE), value = 0, 
flags = DEFAULT;
+        endoneof;
+
+        oneof varid = DebugShowUEFIExit.Show,
+            prompt      = STRING_TOKEN(STR_DEBUG_EXIT_SHOW_PROMPT),
+            help        = STRING_TOKEN(STR_DEBUG_EXIT_SHOW_HELP),
+            flags       = NUMERIC_SIZE_4 | INTERACTIVE,
+            option text = STRING_TOKEN(STR_DEBUG_EXIT_SHOW_NO), value = 0, 
flags = DEFAULT;
+            option text = STRING_TOKEN(STR_DEBUG_EXIT_SHOW_YES), value = 1, 
flags = 0;
+        endoneof;
+    endform;
+endformset;
-- 
2.17.0.windows.1

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to