From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by mx.groups.io with SMTP id smtpd.web12.3968.1588590962091003678 for ; Mon, 04 May 2020 04:16:02 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=NiCr9g+B; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.218.65, mailfrom: pete@akeo.ie) Received: by mail-ej1-f65.google.com with SMTP id s9so13544087eju.1 for ; Mon, 04 May 2020 04:16:01 -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:mime-version :content-transfer-encoding; bh=lAH5VkA1EfD/SDV7QKuoyOPAPMDDfG9z64lKsW4Xi/I=; b=NiCr9g+BEw52hLGmzeIU1XBVE1GDSn2G4QOIxgMmrAt5nq+C2Nrp9y8e9ptgL3MyCt GulUZh4yWHEUjHwjq7hK+J98yaCBqRy0tkXmim/x9E+821x99mgGLN0S9Iv7AojFo//g QvE6zLRQOeyQ3PbcHaQCNliQZVk+jeHAgFf8esHN7ZPqo8/lg75zIno2U5c8//609ygM g86HyeQpo2MyfVV1ptj6j92QBQNLoUXTe7PhMZV9jyvvYGMSknVdrn5rGEJD2RcNCCFc BFL5qZv3Kh3/2CUHTjBtIMPv5Cmcbbo4n9qPAz4z0xajYR+d8I3rk0bfNBMfj/cxIGSz Z0oA== 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=lAH5VkA1EfD/SDV7QKuoyOPAPMDDfG9z64lKsW4Xi/I=; b=SdYg5MdoSinj6hVUYe/ki6yfClSORo0G08iTYIkzbf5wUht7AFjXdoH908zX2r7AqK +Rw3rtMXh/HnzoMx60EHUytaHLLryywSrrx4q8ifEbcHcU8x/6Mrcux6MgygFAUeuxnA O6hsNNf14xlo0iTB3AbsVfI8Gz/WFS2w1RCe7ZrjFkeVpG+Vhqyjb6nRoTJs8r0vA//G voNbDMkjBTbduZFmJFeZ3xboGcT3WpCYzuBxfSDFmKeyS51nZKrBoWxjwk59N6NpkiWJ qrqB2NwefNh2E5soGQ36bbD0xL9TVV+l8cZwnZ7QrOV8D6CRz8kfzKnqpM3E6IGRbNVd kj3A== X-Gm-Message-State: AGi0PuaEXaiyfZtY9up1JTA7AL8IBjjUCAN+knU1KIGfYP2rl6OmkEbU NPcsUs4dwgHcrPmhXOqt0IxuOxPW2oE= X-Google-Smtp-Source: APiQypK8kcgyGH5WUCLAtxxRsPdn2ZAr4iHbbzX4FQJAkWK7e0/ubTz3z/e7lAVEfvnazE+jsNgeDw== X-Received: by 2002:a17:907:214f:: with SMTP id rk15mr14477118ejb.301.1588590960270; Mon, 04 May 2020 04:16:00 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([84.203.75.87]) by smtp.gmail.com with ESMTPSA id gf12sm1470894ejb.62.2020.05.04.04.15.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 May 2020 04:15:59 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@arm.com, leif@nuviainc.com, awarkentin@vmware.com Subject: [edk2-platforms][PATCH 0/3] Platform/RPi: Fix compatibility with recent start.elf Date: Mon, 4 May 2020 12:15:45 +0100 Message-Id: <20200504111548.11112-1-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit As per https://github.com/raspberrypi/firmware/issues/1376 we found two issues with recent versions of the Raspberry Pi Foundation's start.elf on the Pi 3: 1. Our timeout delay for mbox reply was too short, leading to loss of USB due to USB mbox power state request not being applied. 2. The MiniUART baudrate shifted from the expected value due to the Raspberry Pi Foundation deviating from their official documentation and increasing the default core clock (which the MiniUART bases its baudrate divisor on) to 400 MHz, instead using a fixed 250 MHz, when 'enable_uart=1' is in effect. Fixing the first issue is fairly straightforward, and is done in patch 1/3, where we also take this opportunity to improve the overall mbox code. Fixing the second issue requires a little more involvement as we want to ensure that we no longer depend on a fixed PCD clock rate to derive the MiniUART baudrate divisor, but instead use the actual core clock frequency retreived from mbox. However, because there basically exists two instances of DualSerialLib in the firmware (one in PEI phase and one in DXE) and the serial initialization is done very early, we have to use the following process: 1. ArmPlatformPeiBootAction set the core clock of the PEI instance of DualSerialLib, which enables the PEI serial instance to be set with a proper baudrate. 2. A newly introduced PlatformPeiLib provides a PlatformPeim () call that reads the global value from the PEI serial instance and stores it into a GUID Hob. 3. In DXE phase, when the DXE instance of DualSerialLib attempts to read the core clock value for the first time, it detects that it has not been set and sets its value from the GUID Hob. It needs to be pointed out however that we can't use HobLib helper functions such as GetFirstGuidHob () or even GetHobList () directly because DualSerialLib gets instantiated before the DXE version of HobLib. However we work around that by using PrePeiGetHobList (). This serial baudrate fixup is accomplished in patch 2/3. We also take this opportunity to improve the Pi 4 code, which currently doesn't use the core clock frequency at all, andt instead applies a variable 12.12 fixed divisor (which we can always access without mbox transactions) onto a 1 GHz fixed clock. It should be noted that, with 2/3 applied, users of the Pi firmware have the new capability of being able to override the core frequency to whichever value they like (by adding 'core_freq=###' in their 'config.txt') without losing MiniUART baudrate, as was the case without this patch. Finally, considering that the knowing the actual core frequency the system booted with can be useful during early init, we add patch 3/3 to display this value for DEBUG builds. Andrei Warkentin (2): Platform/RPi: Fortify mailbox code Platform/RPi/DualSerialPortLib: Fix miniUART serial divisor computation Pete Batard (1): Platform/RPi: Report core clock frequency during early init Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 11 +- Platform/RaspberryPi/Include/Guid/DualSerialPortLibHobGuid.h | 22 ++++ Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h | 11 +- Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.c | 106 +++++++++++++++++--- Platform/RaspberryPi/Library/DualSerialPortLib/DualSerialPortLib.inf | 6 ++ Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S | 83 ++++++++------- Platform/RaspberryPi/Library/PlatformLib/RaspberryPiMem.c | 8 +- Platform/RaspberryPi/Library/PlatformPeiLib/PlatformPeiLib.c | 33 ++++++ Platform/RaspberryPi/Library/PlatformPeiLib/PlatformPeiLib.inf | 47 +++++++++ Platform/RaspberryPi/RPi3/RPi3.dsc | 8 +- Platform/RaspberryPi/RPi4/RPi4.dsc | 9 +- Platform/RaspberryPi/RaspberryPi.dec | 1 + 12 files changed, 278 insertions(+), 67 deletions(-) create mode 100644 Platform/RaspberryPi/Include/Guid/DualSerialPortLibHobGuid.h create mode 100644 Platform/RaspberryPi/Library/PlatformPeiLib/PlatformPeiLib.c create mode 100644 Platform/RaspberryPi/Library/PlatformPeiLib/PlatformPeiLib.inf -- 2.21.0.windows.1