From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by mx.groups.io with SMTP id smtpd.web12.233.1580232010238174668 for ; Tue, 28 Jan 2020 09:20:10 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=L47dWVpN; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.221.68, mailfrom: pete@akeo.ie) Received: by mail-wr1-f68.google.com with SMTP id y11so16951882wrt.6 for ; Tue, 28 Jan 2020 09:20:10 -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:mime-version :content-transfer-encoding; bh=J+wZwCMOIByElrJjQr8GlWeaF/GLLPiD3u5ipmrHXlg=; b=L47dWVpNlJLR9babmoyMTU0gjfsgRcIBP3POGkN5rbTv6h0jeSj+aiGziflCtwtd/h 57FW5WJ91DiO92zPZ3/qVzMLZvQVzkKhQXsiNtW8E5K8G3en/K9CzC3bXGDONbSz1bTt 7+MspcyO8UN8O5vMOHlthl1UNCTLhTCS0Hl5YZqycBHaXWJPC9UMLcW6kembD37ia4+L MBhQVEoJTu7/+V9F/fQs1R2s2pbsHlzdpBzYW90EvaQjk6g1b9/oq0i7H8MqJeiDmnWv TdEZ1BnfcawkVPf9BmM1/STRnMoLqZpGbviNsvx5gXwfUd69EsedSJ6iUIQYeXnRgJ4z kFAA== 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:mime-version :content-transfer-encoding; bh=J+wZwCMOIByElrJjQr8GlWeaF/GLLPiD3u5ipmrHXlg=; b=kAD6/ATXp3Gfdbv9unHpkU0Am6vC3/8w03VRD7Xh5kD0Q/7FjpYL/2lDh1ExdHh//a PTDlI2TBQvYlTVRrUy3cOlmZ27el7tpwSTycmeTiCjEDImVIkVdPiMsDdKYYtbHVYelo IcCjux9m8GpN5oqHHAIKFI8nwRIBjBNof7GfX4WjcS+vPbiUn6OdSYG86kva+CwAae59 m9yka0lGRyoyHiy+FHOxBiwfBY5t6lQoB5swAf9WMyfAjmbO17eZkc+mmZE01hN4syG0 dcbaDKv6GVJxuV61CeHbHQBlckZdUcDOXeEhlEJKPNGrNKBVFPdjq6ba3RkD6AJZmDIF g+ZQ== X-Gm-Message-State: APjAAAVzW7lV+fmNIccSKJoHImsnHOS0iR0Gp0JGxFRxN+TWLM6vIcvC rHTITWgfb09c6O1pSC2yhMnavY0nHls= X-Google-Smtp-Source: APXvYqx/sZKtjMXWw/U92hBs5RKdEsM05MV/FLPhGt0GnT6c5lsR4tp4/vmrZubXdkaOVkoLKAvA5Q== X-Received: by 2002:a5d:534d:: with SMTP id t13mr31271732wrv.77.1580232008451; Tue, 28 Jan 2020 09:20:08 -0800 (PST) Return-Path: Received: from localhost.localdomain ([84.203.49.247]) by smtp.gmail.com with ESMTPSA id 205sm4000853wmd.42.2020.01.28.09.20.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Jan 2020 09:20:07 -0800 (PST) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif@nuviainc.com, philmd@redhat.com Subject: [edk2-platforms][PATCH 0/4] Platform/RPi: Automate runtime UART selection Date: Tue, 28 Jan 2020 17:19:52 +0000 Message-Id: <20200128171956.9680-1-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit The Raspberry Pi platform contains two UARTs, one PL011-based and the other (called miniUART) 16650-compatible, that are pinmuxed to the GPIO serial port according to whether a Device Tree overlay is present in config.txt or not. In most cases, it takes only the user commenting or uncommenting an overlay line in their config to switch between PL011 and miniUART. As such, the use of a build time option to select the UART should be avoided when it is effectively possible to detect which of the UART is in use at runtime, through an MMIO call. This series of patches achieves just this by: * Adding the relevant clock manager constant to Silicon (which we'll need to retrieve the VPU divisor, needed to set the 16550 baudrate). * Adding a new DualSerialPortLibrary that handles runtime detection and switching between PL011 and 16650. * Enabling the use of DualSerialPortLibrar for both the RPi3 and RPi4. Important notes: * This patch does not cover ACPI serial bindings, as this requires switching to using DynamicTablesPkg / ConfigurationManagerDxe to generate the ACPI tables at runtime. As such, each of the RPi platforms is currently hardcoded to use one of the UARTs for ACPI: miniUART for RPi3 and PL011 for RPi4. Of course, there is no issue for Device Tree usage, since the relevant UART overlay will have been applied then. We don't see the current ACPI UART hardcoding as a major issue, as this doesn't change anything for RPi3 and we expect RPi4 users to prefer PL011 over miniUART anyway, but we will look into using DynamicTablesPkg once we see clearer in terms of ACPI for RPi4. * There is work underway to produce a PL011 vs miniUART aware TF-A, which we hope will be completed by the next TF-A release. Once that release has occurred, we will update the TF-A blobs in non-osi, since the ones we have right now are hardcoded to output through one UART only. * One the subject of TF-A usage, there appears to be an issue when using a 16650 (miniUART) based TF-A in a PL011 configuration as the system freezes then. This issue does not occur when using a PL011 based TF-A in a 16650/miniUART configuration (which is one of the the reason why we picked the PL011 TF-A binary over the 16650 one for RPi4). What this means is that, unless you replace the current RPi3 TF-A blobs from non-osi with a version that outputs to PL011, and attempt to use a Raspberry Pi 3 in PL011 mode, then a boot freezout will happen before the UEFI firmware gets a chance to apply UART runtime selection. This is an issue that will of course resolve itself once we replace the current TF-A blobs with the upcoming runtime selection version. However, I can also produce a patch that replaces the current 16650-based RPI3 TF-A in non-osi with PL011-based ones, if we think it's needed before we get the upcoming runtime selection TF-A binaries. * It appears that we are issuing serial write calls before the UARTs are initialized, which is a problem if 16650 is being used instead of PL011 (produces a freezout similar to what occurs when using 16650 TF-A in a PL011 enabled conf). As such, we do perform miniUART vs PL011 detection in both initialize and write. * The 16650 code applies the recent bugfix from Ashish Singhal in https://edk2.groups.io/g/devel/message/53487. Regards, /Pete Pete Batard (4): Silicon/Broadcom/Bcm283x: Add clock manager constants Platform/RPi: Add serial lib for runtime PL011 vs miniUART detection Platform/RPi3: Enable the use of DualSerialPortLib Platform/RPi4: Enable the use of DualSerialPortLib Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c | 836 ++++++++++++++++++++ Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.inf | 55 ++ Platform/RaspberryPi/RPi3/RPi3.dsc | 15 +- Platform/RaspberryPi/RPi3/Readme.md | 7 + Platform/RaspberryPi/RPi4/AcpiTables/AcpiTables.inf | 7 + Platform/RaspberryPi/RPi4/RPi4.dsc | 26 +- Platform/RaspberryPi/RPi4/RPi4.fdf | 4 - Platform/RaspberryPi/RPi4/Readme.md | 21 +- Silicon/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h | 22 + 9 files changed, 944 insertions(+), 49 deletions(-) create mode 100644 Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c create mode 100644 Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.inf -- 2.21.0.windows.1