From patchwork Fri Nov 22 10:49:56 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: 180032 Delivered-To: patch@linaro.org Received: by 2002:a92:38d5:0:0:0:0:0 with SMTP id g82csp66625ilf; Fri, 22 Nov 2019 03:16:10 -0800 (PST) X-Google-Smtp-Source: APXvYqxsHfWHuAQmqAFH1OnSplggofBypDa1/95ZV3N9/gcFwiJXQV1ZP5Cl1iqnvWqmY+wm0aTd X-Received: by 2002:a17:906:d96c:: with SMTP id rp12mr21878309ejb.253.1574421370406; Fri, 22 Nov 2019 03:16:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574421370; cv=none; d=google.com; s=arc-20160816; b=He8DI+LozNHskDGdODq9afR3IY5Njx5r+OpgwS5Wg+flXTNOhZPHVejMt5jJy6QbEi q816vKVsBsVjmvlJ9R7bJ4h4Hgx/hc7np9HaOLrSHe+loXstZ0cUMYSURPylrUOX8HSy NW2iJjwS8C9FEtnBME/C4zFapfgoWf1HqFc0Xcc9KU3Zj9eT7rBuoxtttmCfhtV+aQC2 kWSAW+G6Nj5q7U0uAG0eoA/9Kd5M2+CkUdCbBxGf0KzVI1ofbeoc0nSdUgU3vB6pUFw6 w/bvYx+xJyK1gdIEaKfcz4AOHy899KiBB66hME/89e2hVX6JB2T4QxkLWpGmcoR7+XCX igbA== 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=O8FVNRvH5irJ2zDaBsxloUo7UX0pFrVUzjUZiLfKvwU=; b=OXrfA4hIA7ds6OjAdFDr0igFveCATm0/1uQHGd4PwQ9w+qjsQCXoI/r+agcw3KLP/N xaSXFZtxcI9kB3tp6xPXmzL2W21X6FgSVupRwX6GkfLU+QGRtI6DPDw9lk3QAYCvmPXF axHc/QEs/5UliYx940GaqruNFaK1WvlltsH3sR5oLOoClQx8IDlE9iCI6mMYDr8C2LgD hkd/lL0bLnAb/ijwC4Mtf6GNooMO2JGv3PPnQgwqIZmZcP+ZWE1m1sDlZAK51E9AyBX0 H4EoO5YVvvhdYDypjR0s3c8XzMPpEt9x+2m3SculYa6YmNvEiyMmLwqU1/LAPlbKaP17 6l7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=KE4FZyVJ; 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.10; Fri, 22 Nov 2019 03:16:10 -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=KE4FZyVJ; 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 S1728651AbfKVLQJ (ORCPT + 7 others); Fri, 22 Nov 2019 06:16:09 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:46977 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729602AbfKVKvF (ORCPT ); Fri, 22 Nov 2019 05:51:05 -0500 Received: by mail-wr1-f65.google.com with SMTP id z7so4622806wrl.13 for ; Fri, 22 Nov 2019 02:51:03 -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=O8FVNRvH5irJ2zDaBsxloUo7UX0pFrVUzjUZiLfKvwU=; b=KE4FZyVJ7oTMaqEmjpbPlG5DZcuerskPQmr4Oz+oBjjiJHvGL6H8exZ0GXrlPmDu4L fjock0LX/ANKXLc2tQLf8axKFLTKAmNc1cOarXAmF0mUTryD4ji2KpaeIUDw6KdwzCw2 MxmVyNC6Z760rlRWN+O0jtt5nJoCB5GWkiGoJq9XOXrGI1Q2/py21NNS6EZZJTYshlH1 dixx5JojDpj/FfGb3I7ZZgOUrdLQ8kn2WEIgbTcnNR0ah1Bdppb6CTCz4NURwPA8aLfS EJmBtSrx3Y1mMzNCGoqbw/42Xt3due4SSZ7dusRabMT5A8dSeghZrBgyRs8JtWKzrXen CdDw== 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=O8FVNRvH5irJ2zDaBsxloUo7UX0pFrVUzjUZiLfKvwU=; b=UcaPVKuH16ZTcMm4OmFeP5/c5Ysg1ILpq1VEV1H9i8UIwxxDcCNG0CyFAPCmqAZLqw FcxbXHaYVq4OVRFF1vOkBm0vCtl165VaGa6q2oK1+2NGHNpIWlivo9pIL9d7p4R4rNbu ECJlkFLGYlvd7Yo9tOqrKB7ywK+W5+enNa810CMb1ovs+ZX6BUzjpUrQfCtZ8enn9xSq vrppkjGj58FWFG2fBKaZTYFOpz/0Pni640J+Acml0CSz4zDlpFhYCbVRLLgzJ4CrgiXz 3xNzCuG4xEydHd3XS98vf64liL8kqciqRSXIy//q3rBBTeree9F6nt3Nyi6RCJmgOX3w I9Ew== X-Gm-Message-State: APjAAAVHgQLz4dRkpl+Q7wsCCWVtJZczA9bafperpksy9rq9bIJ9flzz nyYX+a/MKmctzS6dtR7oD+5goh5VqLU= X-Received: by 2002:adf:de0a:: with SMTP id b10mr17179236wrm.268.1574419862914; Fri, 22 Nov 2019 02:51:02 -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.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Nov 2019 02:51:02 -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 09/13] iommu/virtio: Create fwnode if necessary Date: Fri, 22 Nov 2019 11:49:56 +0100 Message-Id: <20191122105000.800410-10-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 The presence of a fwnode on a PCI device depends on the platform. QEMU q35, for example, creates an ACPI description for each PCI slot, but QEMU virt (aarch64) doesn't. Since the IOMMU subsystem relies heavily on fwnode to discover the DMA topology, create a fwnode for the virtio-iommu if necessary, using the software_node framework. Signed-off-by: Jean-Philippe Brucker --- drivers/iommu/virtio-iommu.c | 56 ++++++++++++++++++++++++++++++++---- 1 file changed, 51 insertions(+), 5 deletions(-) -- 2.24.0 diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c index 3ea9d7682999..8efa368134c0 100644 --- a/drivers/iommu/virtio-iommu.c +++ b/drivers/iommu/virtio-iommu.c @@ -966,6 +966,48 @@ static struct iommu_ops viommu_ops = { .of_xlate = viommu_of_xlate, }; +static int viommu_set_fwnode(struct viommu_dev *viommu) +{ + /* + * viommu->dev is the virtio device, its parent is the associated + * transport device. + */ + struct device *dev = viommu->dev->parent; + + /* + * With device tree a fwnode is always present. With ACPI, on some + * platforms a PCI device has a DSDT node describing the slot. On other + * platforms, no fwnode is created and we have to do it ourselves. + */ + if (!dev->fwnode) { + struct fwnode_handle *fwnode; + + fwnode = fwnode_create_software_node(NULL, NULL); + if (IS_ERR(fwnode)) + return PTR_ERR(fwnode); + + set_primary_fwnode(dev, fwnode); + } + + iommu_device_set_fwnode(&viommu->iommu, dev->fwnode); + return 0; +} + +static void viommu_clear_fwnode(struct viommu_dev *viommu) +{ + struct device *dev = viommu->dev->parent; + + if (!dev->fwnode) + return; + + if (is_software_node(dev->fwnode)) { + struct fwnode_handle *fwnode = dev->fwnode; + + set_primary_fwnode(dev, NULL); + fwnode_remove_software_node(fwnode); + } +} + static int viommu_init_vqs(struct viommu_dev *viommu) { struct virtio_device *vdev = dev_to_virtio(viommu->dev); @@ -1004,7 +1046,6 @@ static int viommu_fill_evtq(struct viommu_dev *viommu) static int viommu_probe(struct virtio_device *vdev) { - struct device *parent_dev = vdev->dev.parent; struct viommu_dev *viommu = NULL; struct device *dev = &vdev->dev; u64 input_start = 0; @@ -1084,9 +1125,11 @@ static int viommu_probe(struct virtio_device *vdev) if (ret) goto err_free_vqs; - iommu_device_set_ops(&viommu->iommu, &viommu_ops); - iommu_device_set_fwnode(&viommu->iommu, parent_dev->fwnode); + ret = viommu_set_fwnode(viommu); + if (ret) + goto err_sysfs_remove; + iommu_device_set_ops(&viommu->iommu, &viommu_ops); iommu_device_register(&viommu->iommu); #ifdef CONFIG_PCI @@ -1119,8 +1162,10 @@ static int viommu_probe(struct virtio_device *vdev) return 0; err_unregister: - iommu_device_sysfs_remove(&viommu->iommu); iommu_device_unregister(&viommu->iommu); + viommu_clear_fwnode(viommu); +err_sysfs_remove: + iommu_device_sysfs_remove(&viommu->iommu); err_free_vqs: vdev->config->del_vqs(vdev); @@ -1131,8 +1176,9 @@ static void viommu_remove(struct virtio_device *vdev) { struct viommu_dev *viommu = vdev->priv; - iommu_device_sysfs_remove(&viommu->iommu); iommu_device_unregister(&viommu->iommu); + viommu_clear_fwnode(viommu); + iommu_device_sysfs_remove(&viommu->iommu); /* Stop all virtqueues */ vdev->config->reset(vdev);