From patchwork Fri Nov 22 10:49:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Philippe Brucker X-Patchwork-Id: 180036 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp66735ilf; Fri, 22 Nov 2019 03:16:15 -0800 (PST) X-Google-Smtp-Source: APXvYqx3JfmbyX4AV4aXdSxnwYsHiEMd1q4KTGLhS3++UPuBfbmK8F/0n3adEdMBaSovBq3NZYBr X-Received: by 2002:aa7:d697:: with SMTP id d23mr376132edr.31.1574421375151; Fri, 22 Nov 2019 03:16:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421375; cv=none; d=google.com; s=arc-20160816; b=SYhlZe77L6NWekfkzJZDLb5DQzD+D720C5q8xnpOUdWftqkw/fm3Aewdaq9gXJbrm5 xXTX1cqctIk3o/0WwRv9uQtd448oD8Fc4Kq9JibgP9qPS0Jd6sG4KJt/UTHNzaGS02t/ knByl6oEkc1XWJkO5rwZNazbzB6hhvAH5EQ8Ympt5ZECmHcNF55ZujtmU7IiRV+C2PN7 pAxbbs70oJrUblBi0maCu+Phdsusc26sxX87Kz87FoZ65UCA5vd7eyDmpCw5FVXXKvnV P2a9pvdHURjr1qIalTIZ10OO8rRxw96apU/M89J3iaOhjcn8OeSFFVEo8BQBAC6GdWWQ yHZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qRDncnEv4s95CgSa1yvYrULV0iuYi2jZhVWKJTRAVu0=; b=A6elE0kn4m/Qx07KpYu0BQ7ZcEVE9qQf8PrJSwAFLESyjtFhFA3+0x1l/yAXT2OLpm uKppnGMdqJC32u2SIUnUfzvAASRTYraqS32PTLmERJxLxpXkZDodtB2OI7OyH+rIlLbU HmWgd9IZTjZ68iFseMWHuZ4mzWIWKYqRTfG14t5ok7WO9ziW1g3J/Ml/Gto0xvuShO3g jtVbVQVkqagfVjkef7mZTk9KzrAD+pDvFVJJ4cr+v2lq8U28eSTHY3isgLCMGuKGMnnM IwWDW3Ch2qofX9uIlSJ8JWjQxnYEhWZgbokgWtW1zN7AgddN30lbBBUCUOBJY2BkpvIS WvOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YNEi/CQb"; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j6si3801343ejb.419.2019.11.22.03.16.14; Fri, 22 Nov 2019 03:16:15 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="YNEi/CQb"; spf=pass (google.com: best guess record for domain of linux-acpi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-acpi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729175AbfKVLQO (ORCPT + 7 others); Fri, 22 Nov 2019 06:16:14 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:34753 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728445AbfKVKu7 (ORCPT ); Fri, 22 Nov 2019 05:50:59 -0500 Received: by mail-wr1-f68.google.com with SMTP id t2so8087772wrr.1 for ; Fri, 22 Nov 2019 02:50:58 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=qRDncnEv4s95CgSa1yvYrULV0iuYi2jZhVWKJTRAVu0=; b=YNEi/CQbRXtkAwf0pPEyl5prqRn8u5HZ5xYtYrRJWWkt3EHX92cjZa+ZJIy6EgzQMY JomcQEQZ9aHxpyPv5xUr8gzpIvqxnMSJDzlZzKuglBou7QBJ8izCjPyAp5gagAMgiSTy 8/Tp82wscT0Sev3YneHxCoFu66z2uQW1GImKYPrOPHwBJ+eCbINzD7/G0fD3TYBod7yi cXSfkjUy19kRIUpzuBATTRkMQ1lFky+4zyrQkjA9B+Fb+7/32I9fa7POnzm7YS7U86Ce NYiXSZoHwEnBnTVK2qCqhRV3tiLJKL/mgFahWAwg2v9n6ttfmUegZHJDqNkVa8wtqyzH PvgQ== 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=qRDncnEv4s95CgSa1yvYrULV0iuYi2jZhVWKJTRAVu0=; b=XmVaJaw7ciX/BqxC82QxpkTL3/Tx4KTCfBHZ1te4gtAqiuT4Axic2UjvJXVdNZuaKx cWoYfvx2AS7RylrYbUhT/3V+VZ78pRB6NATsLiQWOScNBuS8SGIMwRjzm2tVHno24ux7 HgdE7N9SWo0X+/4wzo0NzsApUfb+p2lp3gBDOwY0qkmSCD0WmZw0CB1yB6cJNlIP+q1t Gbx88YhwwPwh/quxh3ZwkXC5fWakwKtY7R/cWbTT5Gm2vRRf4dlQLeSx1VMORTsoMj61 uxCBuu9iVUv64HtW0rvFTldrua0m9dWFI7tqLp+W60mrvIFLspUMmp+hu+zUBPLkDjBy gP+w== X-Gm-Message-State: APjAAAXrkL+AWNVhxNRCXdYkLUvAWPaL/HY6K0FcuBI13KHAzMwoLed+ RCKVKaCs0MdPkqQGxQOyGAbUAOIpYyo= X-Received: by 2002:a5d:49c4:: with SMTP id t4mr10152262wrs.226.1574419857729; Fri, 22 Nov 2019 02:50:57 -0800 (PST) Received: from localhost.localdomain (xdsl-188-155-204-106.adslplus.ch. [188.155.204.106]) by smtp.gmail.com with ESMTPSA id o133sm2088197wmb.4.2019.11.22.02.50.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2019 02:50:57 -0800 (PST) From: Jean-Philippe Brucker To: linux-acpi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, virtualization@lists.linux-foundation.org, linux-pci@vger.kernel.org, virtio-dev@lists.oasis-open.org Cc: rjw@rjwysocki.net, lenb@kernel.org, lorenzo.pieralisi@arm.com, guohanjun@huawei.com, sudeep.holla@arm.com, gregkh@linuxfoundation.org, joro@8bytes.org, bhelgaas@google.com, mst@redhat.com, jasowang@redhat.com, jacob.jun.pan@intel.com, eric.auger@redhat.com, sebastien.boeuf@intel.com, kevin.tian@intel.com Subject: [RFC 05/13] ACPI/IORT: Support VIOT virtio-mmio node Date: Fri, 22 Nov 2019 11:49:52 +0100 Message-Id: <20191122105000.800410-6-jean-philippe@linaro.org> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191122105000.800410-1-jean-philippe@linaro.org> References: <20191122105000.800410-1-jean-philippe@linaro.org> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Add a new type of node to the IORT driver, that describes a virtio-iommu device based on the virtio-mmio transport. The node is only available when the IORT is a sub-table of the VIOT. Signed-off-by: Jean-Philippe Brucker --- drivers/acpi/iort.c | 66 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 4 deletions(-) -- 2.24.0 diff --git a/drivers/acpi/iort.c b/drivers/acpi/iort.c index 1d43fbc0001f..adc5953fffa5 100644 --- a/drivers/acpi/iort.c +++ b/drivers/acpi/iort.c @@ -43,7 +43,8 @@ static bool iort_type_matches(u8 type, enum iort_node_category category) switch (category) { case IORT_IOMMU_TYPE: return type == ACPI_IORT_NODE_SMMU || - type == ACPI_IORT_NODE_SMMU_V3; + type == ACPI_IORT_NODE_SMMU_V3 || + type == ACPI_VIOT_IORT_NODE_VIRTIO_MMIO_IOMMU; case IORT_MSI_TYPE: return type == ACPI_IORT_NODE_ITS_GROUP; default: @@ -868,8 +869,10 @@ static inline bool iort_iommu_driver_enabled(u8 type) return IS_BUILTIN(CONFIG_ARM_SMMU_V3); case ACPI_IORT_NODE_SMMU: return IS_BUILTIN(CONFIG_ARM_SMMU); + case ACPI_VIOT_IORT_NODE_VIRTIO_MMIO_IOMMU: + return IS_ENABLED(CONFIG_VIRTIO_IOMMU); default: - pr_warn("IORT node type %u does not describe an SMMU\n", type); + pr_warn("IORT node type %u does not describe an IOMMU\n", type); return false; } } @@ -1408,6 +1411,46 @@ static int __init arm_smmu_v3_pmcg_add_platdata(struct platform_device *pdev) return platform_device_add_data(pdev, &model, sizeof(model)); } +static int __init viommu_mmio_count_resources(struct acpi_iort_node *node) +{ + /* Mem + IRQ */ + return 2; +} + +static void __init viommu_mmio_init_resources(struct resource *res, + struct acpi_iort_node *node) +{ + int hw_irq, trigger; + struct acpi_viot_iort_virtio_mmio_iommu *viommu; + + viommu = (struct acpi_viot_iort_virtio_mmio_iommu *)node->node_data; + + res[0].start = viommu->base_address; + res[0].end = viommu->base_address + viommu->span - 1; + res[0].flags = IORESOURCE_MEM; + + hw_irq = IORT_IRQ_MASK(viommu->interrupt); + trigger = IORT_IRQ_TRIGGER_MASK(viommu->interrupt); + acpi_iort_register_irq(hw_irq, "viommu", trigger, res + 1); +} + +static void __init viommu_mmio_dma_configure(struct device *dev, + struct acpi_iort_node *node) +{ + enum dev_dma_attr attr; + struct acpi_viot_iort_virtio_mmio_iommu *viommu; + + viommu = (struct acpi_viot_iort_virtio_mmio_iommu *)node->node_data; + + attr = (viommu->flags & ACPI_VIOT_IORT_VIRTIO_MMIO_IOMMU_CACHE_COHERENT) ? + DEV_DMA_COHERENT : DEV_DMA_NON_COHERENT; + + dev->dma_mask = &dev->coherent_dma_mask; + + /* Configure DMA for the page table walker */ + acpi_dma_configure(dev, attr); +} + struct iort_dev_config { const char *name; int (*dev_init)(struct acpi_iort_node *node); @@ -1443,6 +1486,14 @@ static const struct iort_dev_config iort_arm_smmu_v3_pmcg_cfg __initconst = { .dev_add_platdata = arm_smmu_v3_pmcg_add_platdata, }; +static const struct iort_dev_config iort_viommu_mmio_cfg __initconst = { + /* Probe with the generic virtio-mmio driver */ + .name = "virtio-mmio", + .dev_dma_configure = viommu_mmio_dma_configure, + .dev_count_resources = viommu_mmio_count_resources, + .dev_init_resources = viommu_mmio_init_resources, +}; + static __init const struct iort_dev_config *iort_get_dev_cfg( struct acpi_iort_node *node) { @@ -1453,9 +1504,16 @@ static __init const struct iort_dev_config *iort_get_dev_cfg( return &iort_arm_smmu_cfg; case ACPI_IORT_NODE_PMCG: return &iort_arm_smmu_v3_pmcg_cfg; - default: - return NULL; } + + if (iort_table_source == IORT_SOURCE_VIOT) { + switch (node->type) { + case ACPI_VIOT_IORT_NODE_VIRTIO_MMIO_IOMMU: + return &iort_viommu_mmio_cfg; + } + } + + return NULL; } /**