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 130C321197056 for ; Mon, 10 Dec 2018 04:39:10 -0800 (PST) Received: by mail-ed1-x544.google.com with SMTP id o10so9306554edt.13 for ; Mon, 10 Dec 2018 04:39:09 -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=BUHf8SyHg3iB7gQKwLNocYd478DgcuOXFeJPOre5LI8=; b=jMA5A42F5e+VzOHgI8Zql/lhTYqk/s0bqQNYEwEyZ1zBK7SLMnLbTOQ71WtW5/ansC grOZnslbthU4ICsOPP4dMGRMXaNwQerVYMXiVucQug6ytpk4EuG1AknHNkfPwE7jX/YF q3xDyyHwiSn4dlUGjCHM4ClmLfnD4K1ecM0IUcEustf+Vx4u3E0ebvILNBHF1cIdaPpg XA0rR7/D72e2cZY1CMSGHSm0JgRjCvdS3enA6iNFS8uJmCD5cZEglOYjwNzqFmNRVVAW 81bJ09ZDfxfHmqrIQtJyddgMhBrCFVBCt0qNLVfZ7hJOEGZFfFbgrZb8pvMRPhV3Eq4b nW+Q== 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=BUHf8SyHg3iB7gQKwLNocYd478DgcuOXFeJPOre5LI8=; b=Y1MvnPjKRApQNhA+YK8MglHyuU8e5uMcJXfDlvqzK7bl/E/o0XgibqsKlSm9Q9cKax 58i3pYkgYXtCwaH1AsT88IyuwG36GmJIaBPOKW+2W3MYdfGIyCMmN9w+HEaqIu1RNkhn Sz7owcO7/YuJvgFXDjUqwQr7OhntIMKFURPLnYAnS4FxDQkqPms0xWiXZQnuwSgU/z48 Zuf6gIaUmC3aKk0ftoxnQhJd27j69UUccfEaO0AeCSv72BXo8OkXBGPIMiYSEfLwQoc2 ouK/CL3f0XwkojBEbBAV8GMcGWsybRYhFwRjpKHdSmvIAJAkLwALgwDhvvjAZMNtM60t /6UQ== X-Gm-Message-State: AA+aEWbchJB5uGCyCvRRfvGY4T3/ptCbppQmvW0DLgxr+kRS13wcLCyz P4FZN3Z3vPK+5DheJQwMKn6Fa9mBj30= X-Google-Smtp-Source: AFSGD/W6vCo3L+le9XbHllXjw0RG1V4REKMqmYPSg8Pi1IClFw7OAmdidpm3x0nyThZzVoKCIqG3Qg== X-Received: by 2002:a17:906:195b:: with SMTP id b27-v6mr9769188eje.220.1544445547865; Mon, 10 Dec 2018 04:39:07 -0800 (PST) Received: from localhost.localdomain ([84.203.68.105]) by smtp.gmail.com with ESMTPSA id e14sm3296949edb.79.2018.12.10.04.39.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Dec 2018 04:39:07 -0800 (PST) From: Pete Batard To: edk2-devel@lists.01.org Date: Mon, 10 Dec 2018 12:38:35 +0000 Message-Id: <20181210123853.4864-3-pete@akeo.ie> X-Mailer: git-send-email 2.17.0.windows.1 In-Reply-To: <20181210123853.4864-1-pete@akeo.ie> References: <20181210123853.4864-1-pete@akeo.ie> Subject: [PATCH v2 edk2-platforms 02/20] Platform/Broadcom/RPi3: Add Platform library 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, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 X-List-Received-Date: Mon, 10 Dec 2018 12:39:10 -0000 Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pete Batard --- Platform/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h | 70 +++++++++ Platform/Broadcom/Bcm283x/Include/IndustryStandard/RpiFirmware.h | 93 ++++++++++++ Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/AArch64/RaspberryPiHelper.S | 107 +++++++++++++ Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPi.c | 99 ++++++++++++ Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPiMem.c | 160 ++++++++++++++++++++ Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPiPlatformLib.inf | 64 ++++++++ 6 files changed, 593 insertions(+) diff --git a/Platform/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h b/Platform/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h new file mode 100644 index 000000000000..bd30324ff073 --- /dev/null +++ b/Platform/Broadcom/Bcm283x/Include/IndustryStandard/Bcm2836.h @@ -0,0 +1,70 @@ +/** @file + * + * Copyright (c) 2017, Andrei Warkentin + * Copyright (c) 2016, Linaro Limited. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of ARM nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **/ + +/* + * Both "core" and SoC perpherals (1M each). + */ +#define BCM2836_SOC_REGISTERS 0x3f000000 +#define BCM2836_SOC_REGISTER_LENGTH 0x02000000 + +/* Synopsis DW2/DWC USB 2.0 OTG. */ +#define BCM2836_USB_DW2_BASE_ADDRESS 0x3f980000 + +/* + * Offset between the CPU's view and the VC's view of system memory. + */ +#define BCM2836_DMA_DEVICE_OFFSET 0xc0000000 + +/* watchdog constants */ +#define BCM2836_WDOG_BASE_ADDRESS 0x3f100000 +#define BCM2836_WDOG_PASSWORD 0x5a000000 +#define BCM2836_WDOG_RSTC_OFFSET 0x0000001c +#define BCM2836_WDOG_WDOG_OFFSET 0x00000024 +#define BCM2836_WDOG_RSTC_WRCFG_MASK 0x00000030 +#define BCM2836_WDOG_RSTC_WRCFG_FULL_RESET 0x00000020 + +/* mailbox interface constants */ +#define BCM2836_MBOX_BASE_ADDRESS 0x3f00b880 +#define BCM2836_MBOX_READ_OFFSET 0x00000000 +#define BCM2836_MBOX_STATUS_OFFSET 0x00000018 +#define BCM2836_MBOX_CONFIG_OFFSET 0x0000001c +#define BCM2836_MBOX_WRITE_OFFSET 0x00000020 + +#define BCM2836_MBOX_STATUS_FULL 0x1f +#define BCM2836_MBOX_STATUS_EMPTY 0x1e + +#define BCM2836_MBOX_NUM_CHANNELS 16 + +/* interrupt controller constants */ +#define BCM2836_INTC_TIMER_CONTROL_OFFSET 0x00000040 +#define BCM2836_INTC_TIMER_PENDING_OFFSET 0x00000060 diff --git a/Platform/Broadcom/Bcm283x/Include/IndustryStandard/RpiFirmware.h b/Platform/Broadcom/Bcm283x/Include/IndustryStandard/RpiFirmware.h new file mode 100644 index 000000000000..83f8633c26cf --- /dev/null +++ b/Platform/Broadcom/Bcm283x/Include/IndustryStandard/RpiFirmware.h @@ -0,0 +1,93 @@ +/** @file + * + * Copyright (c) 2016, Linaro Limited. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * Neither the name of ARM nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific + * prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + **/ + +#define RPI_FW_MBOX_CHANNEL 0x00000008 + +#define RPI_FW_RESP_SUCCESS 0x80000000 +#define RPI_FW_RESP_FAILURE 0x80000001 + +#define RPI_FW_VALUE_SIZE_RESPONSE_MASK BIT31 + +#define RPI_FW_GET_REVISION 0x00000001 +#define RPI_FW_GET_BOARD_MODEL 0x00010001 +#define RPI_FW_GET_BOARD_REVISION 0x00010002 +#define RPI_FW_GET_MAC_ADDRESS 0x00010003 +#define RPI_FW_GET_BOARD_SERIAL 0x00010004 +#define RPI_FW_GET_ARM_MEMSIZE 0x00010005 + +#define RPI_FW_SET_POWER_STATE 0x00028001 + +#define RPI_FW_POWER_STATE_SDHCI 0x00000000 +#define RPI_FW_POWER_STATE_UART0 0x00000001 +#define RPI_FW_POWER_STATE_UART1 0x00000002 +#define RPI_FW_POWER_STATE_USB_HCD 0x00000003 +#define RPI_FW_POWER_STATE_I2C0 0x00000004 +#define RPI_FW_POWER_STATE_I2C1 0x00000005 +#define RPI_FW_POWER_STATE_I2C2 0x00000006 +#define RPI_FW_POWER_STATE_SPI 0x00000007 +#define RPI_FW_POWER_STATE_CCP2TX 0x00000008 + +#define RPI_FW_GET_CLOCK_RATE 0x00030002 +#define RPI_FW_GET_MAX_CLOCK_RATE 0x00030004 +#define RPI_FW_GET_MIN_CLOCK_RATE 0x00030007 + +#define RPI_FW_SET_CLOCK_RATE 0x00038002 +#define RPI_FW_SET_GPIO 0x00038041 + +#define RPI_FW_GET_FB_GEOMETRY 0x00040003 +#define RPI_FW_GET_FB_LINELENGTH 0x00040008 +#define RPI_FW_GET_FB_COLOR_DEPTH 0x00040005 +#define RPI_FW_GET_FB_REGION 0x00040001 + +#define RPI_FW_SET_FB_PGEOM 0x00048003 +#define RPI_FW_SET_FB_VGEOM 0x00048004 +#define RPI_FW_SET_FB_DEPTH 0x00048005 +#define RPI_FW_ALLOC_FB 0x00040001 +#define RPI_FW_FREE_FB 0x00048001 + +#define RPI_FW_GET_COMMAND_LINE 0x00050001 + +#define RPI_FW_POWER_STATE_ENABLE BIT0 +#define RPI_FW_POWER_STATE_WAIT BIT1 + +#define RPI_FW_CLOCK_RATE_EMMC 0x000000001 +#define RPI_FW_CLOCK_RATE_UART 0x000000002 +#define RPI_FW_CLOCK_RATE_ARM 0x000000003 +#define RPI_FW_CLOCK_RATE_CORE 0x000000004 +#define RPI_FW_CLOCK_RATE_V3D 0x000000005 +#define RPI_FW_CLOCK_RATE_H264 0x000000006 +#define RPI_FW_CLOCK_RATE_ISP 0x000000007 +#define RPI_FW_CLOCK_RATE_SDRAM 0x000000008 +#define RPI_FW_CLOCK_RATE_PIXEL 0x000000009 +#define RPI_FW_CLOCK_RATE_PWM 0x00000000a + +#define RPI_FB_MBOX_CHANNEL 0x1 diff --git a/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/AArch64/RaspberryPiHelper.S b/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/AArch64/RaspberryPiHelper.S new file mode 100644 index 000000000000..91567de8bb78 --- /dev/null +++ b/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/AArch64/RaspberryPiHelper.S @@ -0,0 +1,107 @@ +/** @file + * + * Copyright (c) 2016, Linaro Limited. All rights reserved. + * Copyright (c) 2011-2013, ARM Limited. All rights reserved. + * + * 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 + +#define MAX_TRIES 0x100000 + + .macro drain + mov x5, #MAX_TRIES +0: ldr w6, [x4, #BCM2836_MBOX_STATUS_OFFSET] + tbnz w6, #BCM2836_MBOX_STATUS_EMPTY, 1f + dmb ld + ldr wzr, [x4, #BCM2836_MBOX_READ_OFFSET] + subs x5, x5, #1 + b.ne 0b +1: + .endm + + .macro poll, status + mov x5, #MAX_TRIES +0: ldr w6, [x4, #BCM2836_MBOX_STATUS_OFFSET] + tbz w6, #\status, 1f + dmb ld + subs x5, x5, #1 + b.ne 0b +1: + .endm + +ASM_FUNC(ArmPlatformPeiBootAction) + adr x0, .Lmeminfo_buffer + mov x1, #FixedPcdGet64 (PcdDmaDeviceOffset) + orr x0, x0, #RPI_FW_MBOX_CHANNEL + 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 + + ldr w0, .Lmemsize + sub x0, x0, #1 + adr x1, mSystemMemoryEnd + str x0, [x1] + ret + + .align 4 +.Lmeminfo_buffer: + .long .Lbuffer_size + .long 0x0 + .long RPI_FW_GET_ARM_MEMSIZE + .long 8 // buf size + .long 0 // input len + .long 0 // mem base +.Lmemsize: + .long 0 // mem size + .long 0 // end tag + .set .Lbuffer_size, . - .Lmeminfo_buffer + +//UINTN +//ArmPlatformGetPrimaryCoreMpId ( +// VOID +// ); +ASM_FUNC(ArmPlatformGetPrimaryCoreMpId) + MOV32 (w0, FixedPcdGet32 (PcdArmPrimaryCore)) + ret + +//UINTN +//ArmPlatformIsPrimaryCore ( +// IN UINTN MpId +// ); +ASM_FUNC(ArmPlatformIsPrimaryCore) + mov x0, #1 + ret + +//UINTN +//ArmPlatformGetCorePosition ( +// IN UINTN MpId +// ); +// With this function: CorePos = (ClusterId * 4) + CoreId +ASM_FUNC(ArmPlatformGetCorePosition) + and x1, x0, #ARM_CORE_MASK + and x0, x0, #ARM_CLUSTER_MASK + add x0, x1, x0, LSR #6 + ret + +ASM_FUNCTION_REMOVE_IF_UNREFERENCED diff --git a/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPi.c b/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPi.c new file mode 100644 index 000000000000..ae0b7680f3c3 --- /dev/null +++ b/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPi.c @@ -0,0 +1,99 @@ +/** @file + * + * Copyright (c) 2014-2016, Linaro Limited. All rights reserved. + * Copyright (c) 2014, Red Hat, Inc. + * Copyright (c) 2011-2013, ARM Limited. All rights reserved. + * + * + * 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 + +/** + Return the current Boot Mode + + This function returns the boot reason on the platform + + @return Return the current Boot Mode of the platform + +**/ +EFI_BOOT_MODE +ArmPlatformGetBootMode ( + VOID + ) +{ + return BOOT_WITH_FULL_CONFIGURATION; +} + +/** + This function is called by PrePeiCore, in the SEC phase. +**/ +RETURN_STATUS +ArmPlatformInitialize ( + IN UINTN MpId + ) +{ + return RETURN_SUCCESS; +} + +VOID +ArmPlatformInitializeSystemMemory ( + VOID + ) +{ +} + +STATIC ARM_CORE_INFO mRpi3InfoTable[] = { + { 0x0, 0x0, }, // Cluster 0, Core 0 + { 0x0, 0x1, }, // Cluster 0, Core 1 + { 0x0, 0x2, }, // Cluster 0, Core 2 + { 0x0, 0x3, }, // Cluster 0, Core 3 +}; + +STATIC +EFI_STATUS +PrePeiCoreGetMpCoreInfo ( + OUT UINTN *CoreCount, + OUT ARM_CORE_INFO **ArmCoreTable + ) +{ + // Only support one cluster + *CoreCount = sizeof(mRpi3InfoTable) / sizeof(ARM_CORE_INFO); + *ArmCoreTable = mRpi3InfoTable; + + return EFI_SUCCESS; +} + +STATIC ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { + PrePeiCoreGetMpCoreInfo +}; +STATIC EFI_PEI_PPI_DESCRIPTOR mPlatformPpiTable[] = { + { + EFI_PEI_PPI_DESCRIPTOR_PPI, + &gArmMpCoreInfoPpiGuid, + &mMpCoreInfoPpi + } +}; + +VOID +ArmPlatformGetPlatformPpiList ( + OUT UINTN *PpiListSize, + OUT EFI_PEI_PPI_DESCRIPTOR **PpiList + ) +{ + *PpiListSize = sizeof(mPlatformPpiTable); + *PpiList = mPlatformPpiTable; +} diff --git a/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPiMem.c b/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPiMem.c new file mode 100644 index 000000000000..69821e405134 --- /dev/null +++ b/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPiMem.c @@ -0,0 +1,160 @@ +/** @file + * + * Copyright (c) 2017-2018, Andrey Warkentin + * Copyright (c) 2014, Linaro Limited. All rights reserved. + * + * 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 + +extern UINT64 mSystemMemoryEnd; +extern UINT64 mGPUMemoryBase; +extern UINT64 mGPUMemoryLength; + +#define VariablesSize (FixedPcdGet32(PcdFlashNvStorageVariableSize) + \ + FixedPcdGet32(PcdFlashNvStorageFtwWorkingSize) + \ + FixedPcdGet32(PcdFlashNvStorageFtwSpareSize) + \ + FixedPcdGet32(PcdNvStorageEventLogSize)) + +#define VariablesBase (FixedPcdGet64(PcdFdBaseAddress) + \ + FixedPcdGet32(PcdFdSize) - \ + VariablesSize) + +#define ATFBase (FixedPcdGet64(PcdFdBaseAddress) + FixedPcdGet32(PcdFdSize)) + +STATIC ARM_MEMORY_REGION_DESCRIPTOR RaspberryPiMemoryRegionDescriptor[] = { + { + /* Firmware Volume. */ + FixedPcdGet64(PcdFdBaseAddress), FixedPcdGet64(PcdFdBaseAddress), + FixedPcdGet32(PcdFdSize) - VariablesSize, + ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK + }, + { + /* Variables Volume. */ + VariablesBase, VariablesBase, + VariablesSize, + ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK + }, + { + /* ATF reserved RAM. */ + ATFBase, ATFBase, + FixedPcdGet64(PcdSystemMemoryBase) - ATFBase, + ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK + }, + { + /* System RAM. */ + FixedPcdGet64(PcdSystemMemoryBase), FixedPcdGet64(PcdSystemMemoryBase), + 0, + ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK + }, + { + /* Reserved GPU RAM. */ + 0, + 0, + 0, + ARM_MEMORY_REGION_ATTRIBUTE_DEVICE + }, + { + /* SOC registers. */ + BCM2836_SOC_REGISTERS, + BCM2836_SOC_REGISTERS, + BCM2836_SOC_REGISTER_LENGTH, + ARM_MEMORY_REGION_ATTRIBUTE_DEVICE + }, + { + } +}; + +/** + Return the Virtual Memory Map of your platform + + This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU + on your platform. + + @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR + describing a Physical-to-Virtual Memory + mapping. This array must be ended by a + zero-filled entry + +**/ +VOID +ArmPlatformGetVirtualMemoryMap ( + IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap + ) +{ + RaspberryPiMemoryRegionDescriptor[3].Length = mSystemMemoryEnd + 1 - + FixedPcdGet64(PcdSystemMemoryBase); + + RaspberryPiMemoryRegionDescriptor[4].PhysicalBase = + RaspberryPiMemoryRegionDescriptor[3].PhysicalBase + + RaspberryPiMemoryRegionDescriptor[3].Length; + + RaspberryPiMemoryRegionDescriptor[4].VirtualBase = + RaspberryPiMemoryRegionDescriptor[4].PhysicalBase; + + RaspberryPiMemoryRegionDescriptor[4].Length = + RaspberryPiMemoryRegionDescriptor[5].PhysicalBase - + RaspberryPiMemoryRegionDescriptor[4].PhysicalBase; + + DEBUG ((DEBUG_INFO, "FD:\n" + "\tPhysicalBase: 0x%lX\n" + "\tVirtualBase: 0x%lX\n" + "\tLength: 0x%lX\n", + RaspberryPiMemoryRegionDescriptor[0].PhysicalBase, + RaspberryPiMemoryRegionDescriptor[0].VirtualBase, + RaspberryPiMemoryRegionDescriptor[0].Length + + RaspberryPiMemoryRegionDescriptor[1].Length)); + + DEBUG ((DEBUG_INFO, "Variables (part of FD):\n" + "\tPhysicalBase: 0x%lX\n" + "\tVirtualBase: 0x%lX\n" + "\tLength: 0x%lX\n", + RaspberryPiMemoryRegionDescriptor[1].PhysicalBase, + RaspberryPiMemoryRegionDescriptor[1].VirtualBase, + RaspberryPiMemoryRegionDescriptor[1].Length)); + + DEBUG ((DEBUG_INFO, "ATF RAM:\n" + "\tPhysicalBase: 0x%lX\n" + "\tVirtualBase: 0x%lX\n" + "\tLength: 0x%lX\n", + RaspberryPiMemoryRegionDescriptor[2].PhysicalBase, + RaspberryPiMemoryRegionDescriptor[2].VirtualBase, + RaspberryPiMemoryRegionDescriptor[2].Length)); + + DEBUG ((DEBUG_INFO, "System RAM:\n" + "\tPhysicalBase: 0x%lX\n" + "\tVirtualBase: 0x%lX\n" + "\tLength: 0x%lX\n", + RaspberryPiMemoryRegionDescriptor[3].PhysicalBase, + RaspberryPiMemoryRegionDescriptor[3].VirtualBase, + RaspberryPiMemoryRegionDescriptor[3].Length)); + + DEBUG ((DEBUG_INFO, "GPU Reserved:\n" + "\tPhysicalBase: 0x%lX\n" + "\tVirtualBase: 0x%lX\n" + "\tLength: 0x%lX\n", + RaspberryPiMemoryRegionDescriptor[4].PhysicalBase, + RaspberryPiMemoryRegionDescriptor[4].VirtualBase, + RaspberryPiMemoryRegionDescriptor[4].Length)); + + DEBUG ((DEBUG_INFO, "SoC reserved:\n" + "\tPhysicalBase: 0x%lX\n" + "\tVirtualBase: 0x%lX\n" + "\tLength: 0x%lX\n", + RaspberryPiMemoryRegionDescriptor[5].PhysicalBase, + RaspberryPiMemoryRegionDescriptor[5].VirtualBase, + RaspberryPiMemoryRegionDescriptor[5].Length)); + + *VirtualMemoryMap = RaspberryPiMemoryRegionDescriptor; +} diff --git a/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPiPlatformLib.inf b/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPiPlatformLib.inf new file mode 100644 index 000000000000..2ee4450d79e4 --- /dev/null +++ b/Platform/Broadcom/Bcm283x/Library/RaspberryPiPlatformLib/RaspberryPiPlatformLib.inf @@ -0,0 +1,64 @@ +#/** @file +# +# Copyright (c) 2017-2018, Andrei Warkentin +# Copyright (c) 2014-2016, Linaro Limited. All rights reserved. +# Copyright (c) 2011-2014, ARM Limited. All rights reserved. +# +# 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 = 0x00010005 + BASE_NAME = RaspberryPiPlatformLib + FILE_GUID = 050182ef-f708-4148-b4bc-256cabf74fea + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmPlatformLib|SEC PEIM + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + Platform/Broadcom/Bcm283x/RaspberryPiPkg.dec + +[LibraryClasses] + ArmLib + FdtLib + IoLib + MemoryAllocationLib + PcdLib + PrintLib + +[Sources.common] + RaspberryPi.c + RaspberryPiMem.c + +[Sources.AARCH64] + AArch64/RaspberryPiHelper.S + +[FixedPcd] + gArmTokenSpaceGuid.PcdFdBaseAddress + gArmTokenSpaceGuid.PcdFvBaseAddress + gArmPlatformTokenSpaceGuid.PcdCoreCount + gArmTokenSpaceGuid.PcdArmPrimaryCoreMask + gArmTokenSpaceGuid.PcdArmPrimaryCore + gArmTokenSpaceGuid.PcdFdSize + gEmbeddedTokenSpaceGuid.PcdDmaDeviceOffset + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + gRaspberryPiTokenSpaceGuid.PcdNvStorageEventLogSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingSize + gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize + +[Ppis] + gArmMpCoreInfoPpiGuid -- 2.17.0.windows.1