From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) by mx.groups.io with SMTP id smtpd.web11.3953.1588590963368187498 for ; Mon, 04 May 2020 04:16:03 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=m9T4DN+K; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.218.53, mailfrom: pete@akeo.ie) Received: by mail-ej1-f53.google.com with SMTP id a2so13541111ejx.5 for ; Mon, 04 May 2020 04:16:03 -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=tqByaF06HqTz8tIdghEkZLAfusHSWGqXGJVbL51eeKQ=; b=m9T4DN+KuUNsk1bFNgEHu4RgOMt3MOTAjLWanRLVNSLEV9hxJ+1VjMM8G+vCv2mi3i tT3w5sKVHYehoq+fzb8DNcgKGzc1d0svjMx/F/h3yWxVLOoIxdxAToPIM6EVzKkJFjdQ Pslo01dbnSeXnTI7FqvfNShjqh0AqyBCHvjOK9RAbybcrAXCSHDq4IVrbsELwtjqjs6s Yp2lijZ7V7tXnZReKgXrmwcYGCg3OD4iibjg9tnqzfScJdlHFefKRHBe6VJJuRITYL4w BQKJQ/gzzH6wQals5aXEa7P0D5hML1/+n5o0qcY7FSQ/uMBd0+wE1Bz+MykBvOoAm1PE 4S7w== 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=tqByaF06HqTz8tIdghEkZLAfusHSWGqXGJVbL51eeKQ=; b=KTLhkA64WDsRYg3sohw/Y5V6oyssEbW4OwiTNBwwl4IjXaniWtqzHuzasjIPzAaqYM NLJe44edqRZmp/qzTqeNUOqKbHX+WYjo8ezg2KZX/OQETl+IX34Jlqjl1lWRqp8T81aO tcJr1mBqntRDiM9cNVI+x3ru+ntDBGS3MqavjhwvPgaowHR7lOl1qyo7nWUmvJzzUCwx Ur7RD5xR7vatGJhQ/A8j0TaxTd0Z+FXhHuTSzQWCmhS1FCyMWyjtVcLifj7AZ6yiH/E/ DvG2rovHvdnl1NFw5/k+k8D+U/biFjOFby5nECMh0UquZ/DjXI7dmLoBk6tJE8bGmhvZ agPQ== X-Gm-Message-State: AGi0PuboWa7XqvqDIN8XTLiFnjqu+dd/K0cnncvBFWXCLo7ab+alQTxK ZAV+vl7fWssygNF9JVrIBFBjSyQLwkc= X-Google-Smtp-Source: APiQypIhtL98+LWoSvr58UQxfxLEP/eDAoQjInIg15BMvAYhM2AgNPhKg2p3KoTYg+Hj63/jHl5vew== X-Received: by 2002:a17:906:3da:: with SMTP id c26mr14622111eja.290.1588590961568; Mon, 04 May 2020 04:16:01 -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.16.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 04 May 2020 04:16:01 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@arm.com, leif@nuviainc.com, awarkentin@vmware.com, Andrei Warkentin Subject: [edk2-platforms][PATCH 1/3] Platform/RPi: Fortify mailbox code Date: Mon, 4 May 2020 12:15:46 +0100 Message-Id: <20200504111548.11112-2-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200504111548.11112-1-pete@akeo.ie> References: <20200504111548.11112-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrei Warkentin As part of the analysis done in: https://github.com/raspberrypi/firmware/issues/1376: * Bump up max tries, to avoid command time-outs. * Macro-ify RaspberryPiHelper.S some more to make code more maintainable. * Add ".align 4" before every command buffer. Co-authored-by: Pete Batard Co-authored-by: Andrei Warkentin Signed-off-by: Pete Batard --- Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c | 11 +--- Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h | 11 +++- Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S | 60 ++++++++------------ 3 files changed, 37 insertions(+), 45 deletions(-) diff --git a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c index 40c78b5d57cf..6c45cf47f082 100644 --- a/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c +++ b/Platform/RaspberryPi/Drivers/RpiFirmwareDxe/RpiFirmwareDxe.c @@ -1,5 +1,6 @@ /** @file * + * Copyright (c) 2020, Pete Batard * Copyright (c) 2019, ARM Limited. All rights reserved. * Copyright (c) 2017-2018, Andrei Warkentin * Copyright (c) 2016, Linaro, Ltd. All rights reserved. @@ -30,12 +31,6 @@ // #define NUM_PAGES 1 -// -// The number of iterations to perform when waiting for the mailbox -// status to change -// -#define MAX_TRIES 0x100000 - STATIC VOID *mDmaBuffer; STATIC VOID *mDmaBufferMapping; STATIC UINTN mDmaBufferBusAddress; @@ -62,7 +57,7 @@ DrainMailbox ( } ArmDataSynchronizationBarrier (); MmioRead32 (BCM2836_MBOX_BASE_ADDRESS + BCM2836_MBOX_READ_OFFSET); - } while (++Tries < MAX_TRIES); + } while (++Tries < RPI_MBOX_MAX_TRIES); return FALSE; } @@ -86,7 +81,7 @@ MailboxWaitForStatusCleared ( return TRUE; } ArmDataSynchronizationBarrier (); - } while (++Tries < MAX_TRIES); + } while (++Tries < RPI_MBOX_MAX_TRIES); return FALSE; } diff --git a/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h b/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h index 584786a61dfd..3328be582df1 100644 --- a/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h +++ b/Platform/RaspberryPi/Include/IndustryStandard/RpiMbox.h @@ -1,6 +1,6 @@ /** @file * - * Copyright (c) 2019, Pete Batard + * Copyright (c) 2019-2020, Pete Batard * Copyright (c) 2016, Linaro Limited. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent @@ -10,6 +10,15 @@ #ifndef __RASPBERRY_PI_MAILBOX_H__ #define __RASPBERRY_PI_MAILBOX_H__ +/* + * Number of iterations to perform when waiting for the mailbox. + * + * This number was arrived at empirically, following discussion + * at https://github.com/raspberrypi/firmware/issues/1376, to + * avoid mailbox time-outs on some commands. + */ +#define RPI_MBOX_MAX_TRIES 0x8000000 + /* Mailbox channels */ #define RPI_MBOX_PM_CHANNEL 0 #define RPI_MBOX_FB_CHANNEL 1 diff --git a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S index cc58406e1bfc..91dfe1bb981e 100644 --- a/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S +++ b/Platform/RaspberryPi/Library/PlatformLib/AArch64/RaspberryPiHelper.S @@ -1,6 +1,7 @@ /** @file * - * Copyright (c) 2019, Pete Batard + * Copyright (c) 2020, Andrei Warkentin + * Copyright (c) 2019-2020, Pete Batard * Copyright (c) 2016, Linaro Limited. All rights reserved. * Copyright (c) 2011-2013, ARM Limited. All rights reserved. * @@ -13,10 +14,8 @@ #include #include -#define MAX_TRIES 0x100000 - .macro drain - mov x5, #MAX_TRIES + mov x5, #RPI_MBOX_MAX_TRIES 0: ldr w6, [x4, #BCM2836_MBOX_STATUS_OFFSET] tbnz w6, #BCM2836_MBOX_STATUS_EMPTY, 1f dmb ld @@ -27,7 +26,7 @@ .endm .macro poll, status - mov x5, #MAX_TRIES + mov x5, #RPI_MBOX_MAX_TRIES 0: ldr w6, [x4, #BCM2836_MBOX_STATUS_OFFSET] tbz w6, #\status, 1f dmb ld @@ -36,23 +35,30 @@ 1: .endm + .macro run, command_buffer + adr x0, \command_buffer + orr x0, x0, #RPI_MBOX_VC_CHANNEL + add x0, x0, x1 + + poll BCM2836_MBOX_STATUS_FULL + str w0, [x4, #BCM2836_MBOX_WRITE_OFFSET] + dmb sy + poll BCM2836_MBOX_STATUS_EMPTY + dmb sy + ldr wzr, [x4, #BCM2836_MBOX_READ_OFFSET] + dmb ld + .endm + ASM_FUNC (ArmPlatformPeiBootAction) - adr x0, .Lmeminfo_buffer mov x1, #FixedPcdGet64 (PcdDmaDeviceOffset) orr x0, x0, #RPI_MBOX_VC_CHANNEL // x1 holds the value of PcdDmaDeviceOffset throughout this function - add x0, x0, x1 MOV32 (x4, BCM2836_MBOX_BASE_ADDRESS) drain - poll BCM2836_MBOX_STATUS_FULL - str w0, [x4, #BCM2836_MBOX_WRITE_OFFSET] - dmb sy - poll BCM2836_MBOX_STATUS_EMPTY - dmb sy - ldr wzr, [x4, #BCM2836_MBOX_READ_OFFSET] - dmb ld + + run .Lmeminfo_buffer ldr w0, .Lmembase adr x2, mSystemMemoryBase @@ -63,17 +69,7 @@ ASM_FUNC (ArmPlatformPeiBootAction) adr x2, mSystemMemoryEnd str x0, [x2] - adr x0, .Lvcinfo_buffer - orr x0, x0, #RPI_MBOX_VC_CHANNEL - add x0, x0, x1 - - poll BCM2836_MBOX_STATUS_FULL - str w0, [x4, #BCM2836_MBOX_WRITE_OFFSET] - dmb sy - poll BCM2836_MBOX_STATUS_EMPTY - dmb sy - ldr wzr, [x4, #BCM2836_MBOX_READ_OFFSET] - dmb ld + run .Lvcinfo_buffer ldr w0, .Lvcbase adr x2, mVideoCoreBase @@ -83,17 +79,7 @@ ASM_FUNC (ArmPlatformPeiBootAction) adr x2, mVideoCoreSize str x0, [x2] - adr x0, .Lrevinfo_buffer - orr x0, x0, #RPI_MBOX_VC_CHANNEL - add x0, x0, x1 - - poll BCM2836_MBOX_STATUS_FULL - str w0, [x4, #BCM2836_MBOX_WRITE_OFFSET] - dmb sy - poll BCM2836_MBOX_STATUS_EMPTY - dmb sy - ldr wzr, [x4, #BCM2836_MBOX_READ_OFFSET] - dmb ld + run .Lrevinfo_buffer ldr w0, .Lrevision adr x2, mBoardRevision @@ -115,6 +101,7 @@ ASM_FUNC (ArmPlatformPeiBootAction) .long 0 // end tag .set .Lmeminfo_size, . - .Lmeminfo_buffer + .align 4 .Lvcinfo_buffer: .long .Lvcinfo_size .long 0x0 @@ -128,6 +115,7 @@ ASM_FUNC (ArmPlatformPeiBootAction) .long 0 // end tag .set .Lvcinfo_size, . - .Lvcinfo_buffer + .align 4 .Lrevinfo_buffer: .long .Lrevinfo_size .long 0x0 -- 2.21.0.windows.1