Linux IOMMU Development
 help / color / mirror / Atom feed
From: Baptiste Reynal <b.reynal-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
To: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org,
	qemu-devel-qX2TKyscuCcdnm+yROfE0A@public.gmane.org
Cc: tech-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org,
	will.deacon-5wv7dgnIgG8@public.gmane.org,
	Peter Maydell
	<peter.maydell-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
Subject: [RFC 6/6] hw/arm/sysbus-fdt: add smmu masters in device tree
Date: Fri, 12 Jun 2015 16:20:10 +0200	[thread overview]
Message-ID: <1434118810-28219-7-git-send-email-b.reynal@virtualopensystems.com> (raw)
In-Reply-To: <1434118810-28219-1-git-send-email-b.reynal-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>

This patch adds a function to bind a device as an SMMU master in the
device tree. Currently, only one device is supported.

A device can be set as SMMU master by using the "x-iommu" argument on
the command line:

-device pl330,x-iommu=true

Signed-off-by: Baptiste Reynal <b.reynal-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
---
 hw/arm/sysbus-fdt.c             | 35 +++++++++++++++++++++++++++++++++++
 hw/vfio/platform.c              |  1 +
 include/hw/vfio/vfio-platform.h |  1 +
 3 files changed, 37 insertions(+)

diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
index 67f4425..356f644 100644
--- a/hw/arm/sysbus-fdt.c
+++ b/hw/arm/sysbus-fdt.c
@@ -101,6 +101,38 @@ static const NodeCreationPair add_fdt_node_functions[] = {
     {"", NULL}, /* last element */
 };
 
+static int add_smmu_master(SysBusDevice *sbdev, void *opaque)
+{
+    if (object_dynamic_cast(OBJECT(sbdev), TYPE_VFIO_PLATFORM) &&
+	    VFIO_PLATFORM_DEVICE(sbdev)->iommu_master) {
+        int master[2];
+        char *smmu_nodename, *master_nodename;
+        uint64_t mmio_base;
+        PlatformBusFDTData *data = opaque;
+        PlatformBusDevice *pbus = data->pbus;
+        void *fdt = data->fdt;
+        VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
+        VFIODevice *vbasedev = &vdev->vbasedev;
+        const char *parent_node = data->pbus_node_name;
+
+        smmu_nodename = g_strdup_printf("/smmu@%" PRIx64, vsmmu->base);
+        mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
+
+        master_nodename = g_strdup_printf("%s/%s@%" PRIx64, parent_node,
+                vbasedev->name,
+                mmio_base);
+
+        master[0] = cpu_to_be32(qemu_fdt_get_phandle(fdt, master_nodename));
+        master[1] = cpu_to_be32(vbasedev->group->groupid);
+
+        qemu_fdt_setprop(fdt, smmu_nodename, "mmu-masters",
+                master, 2*sizeof(int));
+
+    }
+
+    return 0;
+}
+
 /**
  * add_fdt_node - add the device tree node of a dynamic sysbus device
  *
@@ -193,6 +225,9 @@ static void add_all_platform_bus_fdt_nodes(ARMPlatformBusFDTParams *fdt_params)
 
     /* Loop through all dynamic sysbus devices and create their node */
     foreach_dynamic_sysbus_device(add_fdt_node, &data);
+    if (vsmmu) {
+        foreach_dynamic_sysbus_device(add_smmu_master, &data);
+    }
 
     g_free(node);
 }
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 6192458..d4ea297 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -585,6 +585,7 @@ static Property vfio_platform_dev_properties[] = {
     DEFINE_PROP_BOOL("x-mmap", VFIOPlatformDevice, vbasedev.allow_mmap, true),
     DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
                        mmap_timeout, 1100),
+    DEFINE_PROP_BOOL("x-iommu", VFIOPlatformDevice, iommu_master, false),
     DEFINE_PROP_END_OF_LIST(),
 };
 
diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h
index 26b2ad6..8f5d980 100644
--- a/include/hw/vfio/vfio-platform.h
+++ b/include/hw/vfio/vfio-platform.h
@@ -57,6 +57,7 @@ typedef struct VFIOPlatformDevice {
     uint32_t mmap_timeout; /* delay to re-enable mmaps after interrupt */
     QEMUTimer *mmap_timer; /* allows fast-path resume after IRQ hit */
     QemuMutex intp_mutex; /* protect the intp_list IRQ state */
+    bool iommu_master; /* is the device a master to the vSMMU ? */
 } VFIOPlatformDevice;
 
 typedef struct VFIOPlatformDeviceClass {
-- 
2.4.3

  parent reply	other threads:[~2015-06-12 14:20 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 14:20 [RFC 0/6] vSMMU initialization Baptiste Reynal
     [not found] ` <1434118810-28219-1-git-send-email-b.reynal-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org>
2015-06-12 14:20   ` [RFC 1/6] headers sync Baptiste Reynal
2015-06-12 14:20   ` [RFC 2/6] hw/core/platform-bus: initialization notifier Baptiste Reynal
2015-06-12 14:20   ` [RFC 3/6] hw/core/platform-bus: add base_address field Baptiste Reynal
2015-06-12 14:20   ` [RFC 4/6] hw/vfio: vsmmu device Baptiste Reynal
2015-06-12 14:20   ` [RFC 5/6] hw/arm/sysbus-fdt: enable vsmmu dynamic instantiation Baptiste Reynal
2015-06-12 14:20   ` Baptiste Reynal [this message]
2015-06-12 14:23   ` [RFC 0/6] vSMMU initialization Will Deacon
     [not found]     ` <20150612142328.GF12174-5wv7dgnIgG8@public.gmane.org>
2015-07-14  2:21       ` Varun Sethi
     [not found]         ` <BN1PR0301MB06274ACB3A193799F40BE9F4EA9B0-RQSpjbwlmjSD1ymB6+i1+JwN6zqB+hSMnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2015-07-14 11:04           ` Will Deacon
     [not found]             ` <20150714110416.GD16213-5wv7dgnIgG8@public.gmane.org>
2015-07-15 13:38               ` Baptiste Reynal
     [not found]                 ` <CAN9JPjF1E0Dg_KAQcc4C+jKDuOHEATVhN+1NPa66jLrP8RieKA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-07-15 13:42                   ` Will Deacon
2015-07-15 16:41                   ` Varun Sethi
2015-07-15 17:28               ` Varun Sethi
     [not found]                 ` <BN1PR0301MB0627944BCFB295564CA1F7AAEA9A0-RQSpjbwlmjSD1ymB6+i1+JwN6zqB+hSMnBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2015-07-15 17:37                   ` Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1434118810-28219-7-git-send-email-b.reynal@virtualopensystems.com \
    --to=b.reynal-lrhrjnjw1ufhk3s98ze1ajgjjy/sre9j@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=peter.maydell-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=qemu-devel-qX2TKyscuCcdnm+yROfE0A@public.gmane.org \
    --cc=tech-lrHrjnjw1UfHK3s98zE1ajGjJy/sRE9J@public.gmane.org \
    --cc=will.deacon-5wv7dgnIgG8@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox