From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: None (no SPF record) identity=mailfrom; client-ip=2a00:1450:4864:20::544; helo=mail-ed1-x544.google.com; envelope-from=pete@akeo.ie; receiver=edk2-devel@lists.01.org Received: from mail-ed1-x544.google.com (mail-ed1-x544.google.com [IPv6:2a00:1450:4864:20::544]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 868252194D387 for ; Mon, 28 Jan 2019 04:45:16 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id y56so12866238edd.11 for ; Mon, 28 Jan 2019 04:45:16 -0800 (PST) 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; bh=/kD4Z4Kel/raETUeWbUcaRWBG6l3jQPhDflvHhw7FAU=; b=iQ7qjRIr03chhnJZGAV5+dFNN96Y+x/O/bGPf32x6EgA5DHl1cDuYtqNvkHNBVVv/b qK/QRBosPAvbOvkk1NSTyjBK/RMYybSBYBuIe1jWJHQo4wxTifobkmKiOPvo0DkZK0QQ wAs6/IXsM3zn2GRgCa50dENflJK8kzuCRAMayczDGPjLkL1fZ0OjlM8MSKsh6DuLYAjV vF7ypbBihzG9t7WhwtHvBQi9N1bQLnTmnFvv397WeZJIpAtM/iBPL8F+LWxVzZvjK1lx DFRcYujztB1gHrjp7aXE7P0/rRTTvJTsTx6+qZvO4Ja15w8lz3yWIoo/PrSTCCLMGn4e VxRQ== 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; bh=/kD4Z4Kel/raETUeWbUcaRWBG6l3jQPhDflvHhw7FAU=; b=IuNhSpLEehNlFE0lhgRYrDg8q/lDY6oVSyLmYEvdMgUYdjmP4cfn0MziD6opBKCryf AzTkips1xz8PDZGgSameLZ4C4fmfDxqDNYl4u6ppFnlYcXH9ppZ2UV2cW0/4j88D3xft JVpH176ddxAIMT2S7Q4KhacfAPekifKBd0hRQSFlW8+Wc5E60yGtmXXfLncmVPKxgpYv XyLkUwxBXA4m9d09KVyEPGr/4PJYeEAj7krPNgD3yoBzu1fx/SwH1zCc2e9lzjBWYvh3 CueFkZSF2rquzMzci/aTwinmpHodkmgN0mr4E1MxqxJ3b7+rvHNa3ZBl9Yuku/WNUaRl v/cg== X-Gm-Message-State: AJcUukfmGBe/jh8z/u2rhBIGel8XmjI39uUqVh+LN8WSnnf9DViel1Eh f64qlQERcAJIFbsjY8hv8m0y7/bihLo= X-Google-Smtp-Source: ALg8bN6xmADb2+hmkJQSw8huX4oSzC0Jqd/wNgf9ajQJUawYGwaYyX+UqTwAzXcwR55ZINMsIQRAfg== X-Received: by 2002:a17:906:3e49:: with SMTP id t9mr4701245eji.245.1548679514249; Mon, 28 Jan 2019 04:45:14 -0800 (PST) Received: from localhost.localdomain ([84.203.95.186]) by smtp.gmail.com with ESMTPSA id y16sm13757367edb.41.2019.01.28.04.45.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 28 Jan 2019 04:45:13 -0800 (PST) From: Pete Batard To: edk2-devel@lists.01.org Date: Mon, 28 Jan 2019 12:44:30 +0000 Message-Id: <20190128124445.9868-9-pete@akeo.ie> X-Mailer: git-send-email 2.17.0.windows.1 In-Reply-To: <20190128124445.9868-1-pete@akeo.ie> References: <20190128124445.9868-1-pete@akeo.ie> Subject: [PATCH v3 edk2-platforms 08/23] Platform/Raspberry/Pi3: Add platform config driver X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 X-List-Received-Date: Mon, 28 Jan 2019 12:45:17 -0000 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard --- Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.c | 350 ++++++++++++++++++++ Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.inf | 77 +++++ 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, 856 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..9c0e2214b7f5 --- /dev/null +++ b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.c @@ -0,0 +1,350 @@ +/** @file + * + * Copyright (c) 2018, Andrei Warkentin + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#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..ffa74db72d1f --- /dev/null +++ b/Platform/Raspberry/Pi3/Drivers/ConfigDxe/ConfigDxe.inf @@ -0,0 +1,77 @@ +#/** @file +# +# Copyright (c) 2018, Andrei Warkentin +# +# 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 + 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 + * + * 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 + * + * 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 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 + * + * 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 +#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