From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f68.google.com (mail-ed1-f68.google.com [209.85.208.68]) by mx.groups.io with SMTP id smtpd.web11.35104.1585223624756359499 for ; Thu, 26 Mar 2020 04:53:45 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@akeo-ie.20150623.gappssmtp.com header.s=20150623 header.b=DD7zhfIG; spf=none, err=permanent DNS error (domain: akeo.ie, ip: 209.85.208.68, mailfrom: pete@akeo.ie) Received: by mail-ed1-f68.google.com with SMTP id i24so6486372eds.1 for ; Thu, 26 Mar 2020 04:53:44 -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=FaztIxFQLExfdXvSZiRHvVen7Cp/vhj+leEy5jENSTY=; b=DD7zhfIGuryxKKqcnMMOlSz4HwKyn43hC2TjNChkHGNbtuA6hdRVaMyrqYkr9Ch72v WI8NjYMwcTUA6oMn+3Cv3GGjyIxlB7mysW9uDd9XlZwInlwiM2K5chM8DbQygck6ikuV BCa0emshgVUNVU1hXV/fkJttJJs10qfJumIEL91qsjDeedPdZCbC87C6+1/mHT3tAFvy T4QsR13itvz2tGNqv0qCY9gGbbaQRHmaEEdpw2JTuU3oJaTHW7pIWhcnpYyoA2ZNP22s sCp7pmeE2lENj7Y4j6hz1UgfUDpQhc9n8oHzOIsx4lDkreN1X47bmzjpwLFIOPWhlwff RnrQ== 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=FaztIxFQLExfdXvSZiRHvVen7Cp/vhj+leEy5jENSTY=; b=h1okOf45gWXFIYH4Sml+WZbs4KdK24KYbgiLsEyyLb2ZQBcCQjUBqpEieWQB90KFiJ VGs4k3Mi2ar5SJDWRshqmxwCD3jo5lZSEYKBOwvfJd/Yi1lfusrgAWDarsgb/9oWXA7j 8WGlPQBlMmobkrTWP0sOdi2zVdADAdzo2B9THadrkmBzHd+TT90WyVpe7tqNktTM4BpA v+FPDIlpmMqYdZ1kDa6JtYYusQiHLLrwLa8mp//3MYZ9ar5RY8/zibd+8iK294lxvEf2 Znp7Os1nTXodG5BOzdBckIAg/lo5/ZncU8uECewUJXeW0q6Ae440ENBvWtEJzE61IRRX Yz0g== X-Gm-Message-State: ANhLgQ2jy5WSkqBqlkBrcax6W1A3vfXXkGw+GpZ7QQZtl4RZtckc2Iju 5u313SXGONa+TLxxYCUgr2UAoAw1E3PziQ== X-Google-Smtp-Source: ADFU+vvIUiKPnpaTdGBEX6wS08ZpHbERezgH+EoPMwCnERa5ddI5q2fPJvlWGaZ5W+d6GHTuSw8NIA== X-Received: by 2002:aa7:c64a:: with SMTP id z10mr7811901edr.126.1585223622671; Thu, 26 Mar 2020 04:53:42 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([84.203.78.33]) by smtp.gmail.com with ESMTPSA id bs8sm240534ejb.92.2020.03.26.04.53.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Mar 2020 04:53:42 -0700 (PDT) From: "Pete Batard" To: devel@edk2.groups.io Cc: ard.biesheuvel@linaro.org, leif@nuviainc.com, philmd@redhat.com, awarkentin@vmware.com Subject: [edk2-platforms][PATCH 6/6] Platform/RPi/AcpiTables: Describe DMA constraints for devices behind GPU Date: Thu, 26 Mar 2020 11:53:22 +0000 Message-Id: <20200326115322.2880-7-pete@akeo.ie> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20200326115322.2880-1-pete@akeo.ie> References: <20200326115322.2880-1-pete@akeo.ie> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrei Warkentin Legacy devices on a Raspberry Pi sit behind GPU/VideoCore and can only address the first GB of RAM. This address range of 0xc0000000-0xffffffff requires a translation, since it is aliased to the first GB of memory 0x00000000-0x3fffffff, which is what this commit accomplishes by introducing a new "GDV0" device along with a "_DMA" ResourceTemplate that performs the address translation. Note that this translation does not apply to the ARM cores, PCIe, GENET, and 40-bit DMA channels, that all have a wider view of the address space. Signed-off-by: Pete Batard --- Platform/RaspberryPi/AcpiTables/Dsdt.asl | 139 +++++++++++++++++++- Platform/RaspberryPi/AcpiTables/GpuDevs.asl | 24 ++-- 2 files changed, 149 insertions(+), 14 deletions(-) diff --git a/Platform/RaspberryPi/AcpiTables/Dsdt.asl b/Platform/RaspberryPi/AcpiTables/Dsdt.asl index 6b0fb7161718..95766b007404 100644 --- a/Platform/RaspberryPi/AcpiTables/Dsdt.asl +++ b/Platform/RaspberryPi/AcpiTables/Dsdt.asl @@ -3,7 +3,7 @@ * Differentiated System Definition Table (DSDT) * * Copyright (c) 2020, Pete Batard - * Copyright (c) 2018, Andrey Warkentin + * Copyright (c) 2018-2020, Andrey Warkentin * Copyright (c) Microsoft Corporation. All rights reserved. * * SPDX-License-Identifier: BSD-2-Clause-Patent @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include #include "AcpiTables.h" @@ -25,6 +27,25 @@ #define BCM_ALT4 0x3 #define BCM_ALT5 0x2 +// +// The ASL compiler does not support argument arithmetic in functions +// like QWordMemory (). So we need to instantiate dummy qword regions +// that we can then update the Min, Max and Length attributes of. +// The two macros below help accomplish this. +// +#define QWORDMEMORYBUF(Index) \ + QWordMemory (ResourceProducer,, \ + MinFixed, MaxFixed, NonCacheable, ReadWrite, \ + 0x0, 0x0, 0x0, 0x0, 0x1,,, RB ## Index) + +#define QWORDMEMORYSET(Index, Offset, Length) \ + CreateQwordField (RBUF, RB ## Index._MIN, MI ## Index) \ + CreateQwordField (RBUF, RB ## Index._MAX, MA ## Index) \ + CreateQwordField (RBUF, RB ## Index._LEN, LE ## Index) \ + Store (Length, LE ## Index) \ + Add (BCM2836_SOC_REGISTERS, Offset, MI ## Index) \ + Add (MI ## Index, LE ## Index - 1, MA ## Index) + DefinitionBlock ("Dsdt.aml", "DSDT", 5, "RPIFDN", "RPI", 2) { Scope (\_SB_) @@ -74,7 +95,121 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 5, "RPIFDN", "RPI", 2) } } - include ("GpuDevs.asl") + // + // GPU device container describes the DMA translation required + // when a device behind the GPU wants to access Arm memory. + // Only the first GB can be addressed. + // + Device (GDV0) + { + Name (_HID, "ACPI0004") + Name (_UID, 0x1) + Name (_CCA, 0x0) + + Method (_CRS, 0, Serialized) { + // + // Container devices with _DMA must have _CRS, meaning GDV0 + // to provide all resources that GpuDevs.asl consume (except + // interrupts). + // + Name (RBUF, ResourceTemplate () { + QWORDMEMORYBUF(01) + QWORDMEMORYBUF(02) + QWORDMEMORYBUF(03) + // QWORDMEMORYBUF(04) + // QWORDMEMORYBUF(05) + QWORDMEMORYBUF(06) + QWORDMEMORYBUF(07) + QWORDMEMORYBUF(08) + QWORDMEMORYBUF(09) + QWORDMEMORYBUF(10) + QWORDMEMORYBUF(11) + QWORDMEMORYBUF(12) + QWORDMEMORYBUF(13) + QWORDMEMORYBUF(14) + QWORDMEMORYBUF(15) + // QWORDMEMORYBUF(16) + QWORDMEMORYBUF(17) + QWORDMEMORYBUF(18) + QWORDMEMORYBUF(19) + QWORDMEMORYBUF(20) + QWORDMEMORYBUF(21) + QWORDMEMORYBUF(22) + QWORDMEMORYBUF(23) + QWORDMEMORYBUF(24) + QWORDMEMORYBUF(25) + }) + + // USB + QWORDMEMORYSET(01, BCM2836_USB_OFFSET, BCM2836_USB_LENGTH) + + // GPU + QWORDMEMORYSET(02, BCM2836_V3D_BUS_OFFSET, BCM2836_V3D_BUS_LENGTH) + QWORDMEMORYSET(03, BCM2836_HVS_OFFSET, BCM2836_HVS_LENGTH) + // QWORDMEMORYSET(04, BCM2836_PV0_OFFSET, BCM2836_PV0_LENGTH) + // QWORDMEMORYSET(05, BCM2836_PV1_OFFSET, BCM2836_PV1_LENGTH) + QWORDMEMORYSET(06, BCM2836_PV2_OFFSET, BCM2836_PV2_LENGTH) + QWORDMEMORYSET(07, BCM2836_HDMI0_OFFSET, BCM2836_HDMI0_LENGTH) + QWORDMEMORYSET(08, BCM2836_HDMI1_OFFSET, BCM2836_HDMI1_LENGTH) + + // Mailbox + QWORDMEMORYSET(09, BCM2836_MBOX_OFFSET, BCM2836_MBOX_LENGTH) + + // VCHIQ + QWORDMEMORYSET(10, BCM2836_VCHIQ_OFFSET, BCM2836_VCHIQ_LENGTH) + + // GPIO + QWORDMEMORYSET(11, GPIO_OFFSET, GPIO_LENGTH) + + // I2C + QWORDMEMORYSET(12, BCM2836_I2C1_OFFSET, BCM2836_I2C1_LENGTH) + QWORDMEMORYSET(13, BCM2836_I2C2_OFFSET, BCM2836_I2C2_LENGTH) + + // SPI + QWORDMEMORYSET(14, BCM2836_SPI0_OFFSET, BCM2836_SPI0_LENGTH) + QWORDMEMORYSET(15, BCM2836_SPI1_OFFSET, BCM2836_SPI1_LENGTH) + // QWORDMEMORYSET(16, BCM2836_SPI2_OFFSET, BCM2836_SPI2_LENGTH) + + // PWM + QWORDMEMORYSET(17, BCM2836_PWM_DMA_OFFSET, BCM2836_PWM_DMA_LENGTH) + QWORDMEMORYSET(18, BCM2836_PWM_CTRL_OFFSET, BCM2836_PWM_CTRL_LENGTH) + QWORDMEMORYSET(19, BCM2836_PWM_BUS_BASE_ADDRESS, BCM2836_PWM_BUS_LENGTH) + QWORDMEMORYSET(20, BCM2836_PWM_CTRL_UNCACHED_BASE_ADDRESS, BCM2836_PWM_CTRL_UNCACHED_LENGTH) + QWORDMEMORYSET(21, BCM2836_PWM_CLK_OFFSET, BCM2836_PWM_CLK_LENGTH) + + // UART + QWORDMEMORYSET(22, BCM2836_PL011_UART_OFFSET, BCM2836_PL011_UART_LENGTH) + QWORDMEMORYSET(23, BCM2836_MINI_UART_OFFSET, BCM2836_MINI_UART_LENGTH) + + // SDC + QWORDMEMORYSET(24, MMCHS1_OFFSET, MMCHS1_LENGTH) + QWORDMEMORYSET(25, SDHOST_OFFSET, SDHOST_LENGTH) + + Return (RBUF) + } + + Name (_DMA, ResourceTemplate() { + // + // Only the first GB is available. + // Bus 0xC0000000 -> CPU 0x00000000. + // + QWordMemory (ResourceConsumer, + , + MinFixed, + MaxFixed, + NonCacheable, + ReadWrite, + 0x0, + 0x00000000C0000000, // MIN + 0x00000000FFFFFFFF, // MAX + 0xFFFFFFFF40000000, // TRA + 0x0000000040000000, // LEN + , + , + ) + }) + include ("GpuDevs.asl") + } #if (RPI_MODEL == 4) Device (ETH0) diff --git a/Platform/RaspberryPi/AcpiTables/GpuDevs.asl b/Platform/RaspberryPi/AcpiTables/GpuDevs.asl index 99f03333abcf..966a94cdb5b5 100644 --- a/Platform/RaspberryPi/AcpiTables/GpuDevs.asl +++ b/Platform/RaspberryPi/AcpiTables/GpuDevs.asl @@ -75,8 +75,8 @@ Device (GPU0) // Interrupt (ResourceConsumer, Level, ActiveHigh, Exclusive) { BCM2836_HDMI1_INTERRUPT } // HDMI DDC connection - I2CSerialBus (0x50,, 100000,, "\\_SB.I2C2",,,,) // EDID - I2CSerialBus (0x30,, 100000,, "\\_SB.I2C2",,,,) // E-DDC Segment Pointer + I2CSerialBus (0x50,, 100000,, "\\_SB.GDV0.I2C2",,,,) // EDID + I2CSerialBus (0x30,, 100000,, "\\_SB.GDV0.I2C2",,,,) // E-DDC Segment Pointer }) Method (_CRS, 0x0, Serialized) { @@ -167,7 +167,7 @@ Device (VCIQ) Name (_CID, "VCIQ") Name (_UID, 0) Name (_CCA, 0x0) - Name (_DEP, Package() { \_SB.RPIQ }) + Name (_DEP, Package() { \_SB.GDV0.RPIQ }) Method (_STA) { Return (0xf) @@ -192,7 +192,7 @@ Device (VCSM) Name (_CID, "VCSM") Name (_UID, 0) Name (_CCA, 0x0) - Name (_DEP, Package() { \_SB.VCIQ }) + Name (_DEP, Package() { \_SB.GDV0.VCIQ }) Method (_STA) { Return (0xf) @@ -241,7 +241,7 @@ Device (I2C1) { MEMORY32FIXED (ReadWrite, 0, BCM2836_I2C1_LENGTH, RMEM) Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) { BCM2836_I2C1_INTERRUPT } - PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GPI0", 0, ResourceConsumer, , ) { 2, 3 } + PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 2, 3 } }) Method (_CRS, 0x0, Serialized) { @@ -289,9 +289,9 @@ Device (SPI0) { MEMORY32FIXED (ReadWrite, 0, BCM2836_SPI0_LENGTH, RMEM) Interrupt (ResourceConsumer, Level, ActiveHigh, Shared) { BCM2836_SPI0_INTERRUPT } - PinFunction (Exclusive, PullDown, BCM_ALT0, "\\_SB.GPI0", 0, ResourceConsumer, , ) { 9, 10, 11 } // MISO, MOSI, SCLK - PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GPI0", 0, ResourceConsumer, , ) { 8 } // CE0 - PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GPI0", 0, ResourceConsumer, , ) { 7 } // CE1 + PinFunction (Exclusive, PullDown, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 9, 10, 11 } // MISO, MOSI, SCLK + PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 8 } // CE0 + PinFunction (Exclusive, PullUp, BCM_ALT0, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 7 } // CE1 }) Method (_CRS, 0x0, Serialized) @@ -307,7 +307,7 @@ Device (SPI1) Name (_CID, "BCMAUXSPI") Name (_UID, 0x1) Name (_CCA, 0x0) - Name (_DEP, Package() { \_SB.RPIQ }) + Name (_DEP, Package() { \_SB.GDV0.RPIQ }) Method (_STA) { Return (0xf) @@ -316,8 +316,8 @@ Device (SPI1) { MEMORY32FIXED (ReadWrite, 0, BCM2836_SPI1_LENGTH, RMEM) Interrupt (ResourceConsumer, Level, ActiveHigh, Shared,) { BCM2836_SPI1_INTERRUPT } - PinFunction (Exclusive, PullDown, BCM_ALT4, "\\_SB.GPI0", 0, ResourceConsumer, , ) { 19, 20, 21 } // MISO, MOSI, SCLK - PinFunction (Exclusive, PullDown, BCM_ALT4, "\\_SB.GPI0", 0, ResourceConsumer, , ) { 16 } // CE2 + PinFunction (Exclusive, PullDown, BCM_ALT4, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 19, 20, 21 } // MISO, MOSI, SCLK + PinFunction (Exclusive, PullDown, BCM_ALT4, "\\_SB.GDV0.GPI0", 0, ResourceConsumer, , ) { 16 } // CE2 }) Method (_CRS, 0x0, Serialized) @@ -334,7 +334,7 @@ Device (SPI1) // Name (_CID, "BCMAUXSPI") // Name (_UID, 0x2) // Name (_CCA, 0x0) -// Name (_DEP, Package() { \_SB.RPIQ }) +// Name (_DEP, Package() { \_SB.GDV0.RPIQ }) // Method (_STA) // { // Return (0xf) // Disabled -- 2.21.0.windows.1