From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-x236.google.com (mail-wm0-x236.google.com [IPv6:2a00:1450:400c:c09::236]) (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 BD87A81D07 for ; Tue, 8 Nov 2016 05:04:57 -0800 (PST) Received: by mail-wm0-x236.google.com with SMTP id t79so237949604wmt.0 for ; Tue, 08 Nov 2016 05:05:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=cadGOnNk+DZWETlx+GVtDGFrxINeH9iA30d5Uk1lm28=; b=iDR2Xl8mHOsaq4rAPKnYoOLb0Lc3R4wCd+kmHByQi8nMHf3fe98osMtJCbvZdxcfAy gLqGlURSQWyxwJzMSGpVpR202Ks2bBd23jaRH4FYDH0IGknXDSwzvhtT+EvAhY/vtESi 3/5x/PDl6I+uMnmmOvAtjNX/iJZYqCojLBu28= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=cadGOnNk+DZWETlx+GVtDGFrxINeH9iA30d5Uk1lm28=; b=k37Ffat+0h8+Rt+UVq3/RN/bJJMY65UxsdTv+9dCTQI/s14VaNQuSyjIKdbJ/OeJKr S2PKu8+gLWrOsZBJAl1ZmFoF2FoqaoncSVmjy7HGN3IzuHnKue8ab2doOPxps3UImGqd SuoFTcSFXVGyIDYuzIxKTKnLQMFUzV7YUwAlIs9R+WC3ZFG3Dh+L/zdfPy8zRsBQ3RaS xovsJA93lsAh555ZvyFJHI+QQOA4v6P3Fm0urY5o01gfIlJGng/EVz6vrlP3tY11NbnW xzoVWN2FzsMCES7o7UAEhX27/TMEQ34KQHrgwpuFbUs6+3075PHZTu+4DeZwkac9/vvY h0DQ== X-Gm-Message-State: ABUngveeEDmmMicVbG7HdvwN2eSw7C0cWADA2aNobxhHMiU2RWsX/VJdk/eqso10Jv1gsxDk X-Received: by 10.28.172.3 with SMTP id v3mr1344914wme.133.1478610299198; Tue, 08 Nov 2016 05:04:59 -0800 (PST) Received: from localhost.localdomain ([105.139.36.22]) by smtp.gmail.com with ESMTPSA id hb5sm36978153wjc.5.2016.11.08.05.04.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Nov 2016 05:04:58 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org Cc: Ard Biesheuvel Date: Tue, 8 Nov 2016 13:04:55 +0000 Message-Id: <1478610295-22065-1-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 Subject: [PATCH] ArmPkg/ArmDmaLib: add support for fixed host-to-device DMA offset X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 08 Nov 2016 13:04:58 -0000 Some devices, such as the Raspberry Pi3, have a fixed offset between memory addresses as seen by the host and as seen by the other bus masters. So add a new PCD that allows this fixed offset to be recorded, and to be used when returning device addresses from the DmaLib mapping routines. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPkg/ArmPkg.dec | 6 ++++++ ArmPkg/Library/ArmDmaLib/ArmDmaLib.c | 13 +++++++++++-- ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf | 1 + 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/ArmPkg/ArmPkg.dec b/ArmPkg/ArmPkg.dec index 3cdb5da3d4f3..b2d59a168337 100644 --- a/ArmPkg/ArmPkg.dec +++ b/ArmPkg/ArmPkg.dec @@ -134,6 +134,12 @@ [PcdsFixedAtBuild.common] gArmTokenSpaceGuid.PcdFdSize|0|UINT32|0x0000002C gArmTokenSpaceGuid.PcdFvSize|0|UINT32|0x0000002E + # + # Value to add to a host address to obtain a device address + # (using unsigned 64-bit integer arithmetic on both ARM and AArch64) + # + gArmTokenSpaceGuid.PcdArmDmaDeviceOffset|0x0|UINT64|0x0000044 + [PcdsFixedAtBuild.common, PcdsPatchableInModule.common] gArmTokenSpaceGuid.PcdFdBaseAddress|0|UINT64|0x0000002B gArmTokenSpaceGuid.PcdFvBaseAddress|0|UINT64|0x0000002D diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c index d48d6ff6dbbb..d6dee78a254d 100644 --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.c @@ -39,6 +39,15 @@ typedef struct { EFI_CPU_ARCH_PROTOCOL *gCpu; UINTN gCacheAlignment = 0; +STATIC +PHYSICAL_ADDRESS +HostToDeviceAddress ( + IN PHYSICAL_ADDRESS HostAddress + ) +{ + return HostAddress + PcdGet64 (PcdArmDmaDeviceOffset); +} + /** Provides the DMA controller-specific addresses needed to access system memory. @@ -82,7 +91,7 @@ DmaMap ( return EFI_INVALID_PARAMETER; } - *DeviceAddress = ConvertToPhysicalAddress (HostAddress); + *DeviceAddress = HostToDeviceAddress (ConvertToPhysicalAddress (HostAddress)); // Remember range so we can flush on the other side Map = AllocatePool (sizeof (MAP_INFO_INSTANCE)); @@ -129,7 +138,7 @@ DmaMap ( CopyMem (Buffer, HostAddress, *NumberOfBytes); } - *DeviceAddress = (PHYSICAL_ADDRESS)(UINTN)Buffer; + *DeviceAddress = HostToDeviceAddress ((PHYSICAL_ADDRESS)(UINTN)Buffer); } else { Map->DoubleBuffer = FALSE; } diff --git a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf index 95c13006eaac..36c23f486974 100644 --- a/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf +++ b/ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf @@ -46,6 +46,7 @@ [Protocols] [Guids] [Pcd] + gArmTokenSpaceGuid.PcdArmDmaDeviceOffset [Depex] gEfiCpuArchProtocolGuid -- 2.7.4