Received: from eggs.gnu.org ([2001:4830:134:3::10]:51921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8SDg-0003Ou-4M for qemu-devel@nongnu.org; Thu, 02 Jun 2016 08:59:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8SDa-0004sp-4g for qemu-devel@nongnu.org; Thu, 02 Jun 2016 08:59:27 -0400 From: Bogdan Purcareata Date: Thu, 2 Jun 2016 12:26:22 +0000 Message-ID: <1464870382-385-3-git-send-email-bogdan.purcareata@nxp.com> In-Reply-To: <1464870382-385-1-git-send-email-bogdan.purcareata@nxp.com> References: <1464870382-385-1-git-send-email-bogdan.purcareata@nxp.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [PATCH 2/2] arm/virt: Mark pcie controller node as dma-coherent List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: eric.auger@linaro.org, crosthwaite.peter@gmail.com, agraf@suse.de, peter.maydell@linaro.org Cc: qemu-arm@nongnu.org, qemu-devel@nongnu.org A PCI device is marked either as coherent or non-coherent based on the pcie controller "dma-coherent" property. This is further used when configuring the IOMMU ops for the device DMA resources (e.g. descriptor rings, for e1000e). This dma-coherent property needs to be configured in the guest environment, in case there's a directly assigned VFIO PCI device. Since the guest only receives one emulated pcie controller bus - regardless of the host configuration - add this property if there's at least one host pcie host controller that is DMA coherent (this implies that the host interconnect is coherent as well). Signed-off-by: Bogdan Purcareata --- hw/arm/virt.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 371e3a7..b640174 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -867,6 +867,32 @@ static void create_pcie_irq_map(const VirtBoardInfo *vbi, uint32_t gic_phandle, 0x7 /* PCI irq */); } +static bool is_host_pcie_dma_coherent(void) +{ + void *host_fdt; + char **node_path; + bool ret = false; + + host_fdt = load_device_tree_from_sysfs(); + + node_path = qemu_fdt_node_path_prop(host_fdt, "pcie", "dma-coherent", + NULL, 0, &error_fatal); + + /* no pcie controllers found on host, therefore non dma-coherent */ + if (!node_path || !node_path[0]) { + goto out; + } + + /* for now, if at least one pcie node is dma-coherent, + * it is considered that the host is dma-coherent with respect to pcie */ + ret = true; + +out: + g_strfreev(node_path); + g_free(host_fdt); + return ret; +} + static void create_pcie(const VirtBoardInfo *vbi, qemu_irq *pic, bool use_highmem) { @@ -981,6 +1007,11 @@ static void create_pcie(const VirtBoardInfo *vbi, qemu_irq *pic, } qemu_fdt_setprop_cell(vbi->fdt, nodename, "#interrupt-cells", 1); + + if (is_host_pcie_dma_coherent()) { + qemu_fdt_setprop(vbi->fdt, nodename, "dma-coherent", NULL, 0); + } + create_pcie_irq_map(vbi, vbi->gic_phandle, irq, nodename); g_free(nodename); -- 1.9.1