From: Geert Uytterhoeven <geert+renesas@glider.be>
To: Peter Maydell <peter.maydell@linaro.org>,
Alex Williamson <alex.williamson@redhat.com>
Cc: Auger Eric <eric.auger@redhat.com>,
Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>,
Arnd Bergmann <arnd@arndb.de>, Alexander Graf <agraf@suse.de>,
Magnus Damm <magnus.damm@gmail.com>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Wolfram Sang <wsa+renesas@sang-engineering.com>,
qemu-arm@nongnu.org, qemu-devel@nongnu.org,
linux-renesas-soc@vger.kernel.org,
Geert Uytterhoeven <geert+renesas@glider.be>
Subject: [Qemu-devel] [PATCH/RFC 2/5] hw/arm/sysbus-fdt: Allow device matching with compat string
Date: Fri, 9 Feb 2018 16:17:33 +0100 [thread overview]
Message-ID: <1518189456-2873-3-git-send-email-geert+renesas@glider.be> (raw)
In-Reply-To: <1518189456-2873-1-git-send-email-geert+renesas@glider.be>
From: Auger Eric <eric.auger@redhat.com>
Up to now we have relied on the device type to identify a device tree
node creation function. Since we would like the VFIO-PLATFORM
device to be instantiable with different compatibility strings
we introduce the capability to specialize the node creation depending
on a manufacturer/model combo.
NodeCreationPair is renamed into BindingEntry. The struct is enhanced
with manufacturer, model and match_fn() fields. We introduce a new
matching function adapted to vfio-platform generic device.
>From now on, the AMD XGBE can be instantiated with either manner, ie:
-device vfio-amd-xgbe,host=e0900000.xgmac
or new option line:
-device vfio-platform,host=e0900000.xgmac,manufacturer=amd,model=xgbe-seattle-v1a
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
hw/arm/sysbus-fdt.c | 61 +++++++++++++++++++++++++++++++++++++++++------------
1 file changed, 48 insertions(+), 13 deletions(-)
diff --git a/hw/arm/sysbus-fdt.c b/hw/arm/sysbus-fdt.c
index d68e3dcdbd260895..c5d4fd5604c28118 100644
--- a/hw/arm/sysbus-fdt.c
+++ b/hw/arm/sysbus-fdt.c
@@ -58,11 +58,14 @@ typedef struct PlatformBusFDTNotifierParams {
ARMPlatformBusFDTParams *fdt_params;
} PlatformBusFDTNotifierParams;
-/* struct that associates a device type name and a node creation function */
-typedef struct NodeCreationPair {
+/* struct that allows to match a device and create its FDT node */
+typedef struct BindingEntry {
const char *typename;
- int (*add_fdt_node_fn)(SysBusDevice *sbdev, void *opaque);
-} NodeCreationPair;
+ const char *manufacturer;
+ const char *model;
+ int (*add_fn)(SysBusDevice *sbdev, void *opaque);
+ bool (*match_fn)(SysBusDevice *sbdev, const struct BindingEntry *combo);
+} BindingEntry;
/* helpers */
@@ -413,15 +416,46 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev, void *opaque)
return 0;
}
+/* manufacturer/model matching */
+static bool vfio_platform_match(SysBusDevice *sbdev,
+ const BindingEntry *entry)
+{
+ VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(sbdev);
+
+ if (strcmp(entry->model, vdev->model)) {
+ return false;
+ }
+
+ if (entry->manufacturer) {
+ if (!vdev->manufacturer) {
+ return false;
+ }
+ return !strcmp(entry->manufacturer, vdev->manufacturer);
+ }
+ return true;
+}
+
+#define VFIO_PLATFORM_BINDING(manuf, model, add_fn) \
+ {TYPE_VFIO_PLATFORM, (manuf), (model), (add_fn), vfio_platform_match}
+
#endif /* CONFIG_LINUX */
-/* list of supported dynamic sysbus devices */
-static const NodeCreationPair add_fdt_node_functions[] = {
+/* Device type based matching */
+static bool type_match(SysBusDevice *sbdev, const BindingEntry *entry)
+{
+ return !strcmp(object_get_typename(OBJECT(sbdev)), entry->typename);
+}
+
+#define TYPE_BINDING(type, add_fn) {(type), NULL, NULL, (add_fn), type_match}
+
+/* list of supported dynamic sysbus bindings */
+static const BindingEntry bindings[] = {
#ifdef CONFIG_LINUX
- {TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node},
- {TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node},
+ TYPE_BINDING(TYPE_VFIO_CALXEDA_XGMAC, add_calxeda_midway_xgmac_fdt_node),
+ TYPE_BINDING(TYPE_VFIO_AMD_XGBE, add_amd_xgbe_fdt_node),
+ VFIO_PLATFORM_BINDING("amd", "xgbe-seattle-v1a", add_amd_xgbe_fdt_node),
#endif
- {"", NULL}, /* last element */
+ TYPE_BINDING("", NULL), /* last element */
};
/* Generic Code */
@@ -440,10 +474,11 @@ static void add_fdt_node(SysBusDevice *sbdev, void *opaque)
{
int i, ret;
- for (i = 0; i < ARRAY_SIZE(add_fdt_node_functions); i++) {
- if (!strcmp(object_get_typename(OBJECT(sbdev)),
- add_fdt_node_functions[i].typename)) {
- ret = add_fdt_node_functions[i].add_fdt_node_fn(sbdev, opaque);
+ for (i = 0; i < ARRAY_SIZE(bindings); i++) {
+ const BindingEntry *iter = &bindings[i];
+
+ if (iter->match_fn(sbdev, iter)) {
+ ret = iter->add_fn(sbdev, opaque);
assert(!ret);
return;
}
--
2.7.4
next prev parent reply other threads:[~2018-02-09 15:52 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-09 15:17 [Qemu-devel] [PATCH/RFC 0/5] R-Car Gen3 GPIO Pass-Through Prototype (QEMU) Geert Uytterhoeven
2018-02-09 15:17 ` [Qemu-devel] [PATCH/RFC 1/5] vfio/platform: make the vfio-platform device non abstract Geert Uytterhoeven
2018-02-09 15:17 ` Geert Uytterhoeven [this message]
2018-02-09 15:17 ` [Qemu-devel] [PATCH/RFC 3/5] hw/arm/virt: Allow dynamic sysbus devices again Geert Uytterhoeven
2018-02-09 15:27 ` Peter Maydell
2018-02-09 15:37 ` Geert Uytterhoeven
2018-02-09 15:46 ` Peter Maydell
2018-02-14 10:37 ` Auger Eric
2018-04-12 12:50 ` Geert Uytterhoeven
2018-02-09 15:17 ` [Qemu-devel] [PATCH/RFC 4/5] vfio: No-IOMMU mode support Geert Uytterhoeven
2018-02-09 15:50 ` Alex Williamson
2018-02-09 16:06 ` Geert Uytterhoeven
2018-02-09 17:06 ` Alex Williamson
2018-02-09 15:17 ` [Qemu-devel] [PATCH/RFC 5/5] hw/arm/sysbus-fdt: Enable rcar-gen3-gpio dynamic instantiation Geert Uytterhoeven
2018-02-14 10:52 ` Auger Eric
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=1518189456-2873-3-git-send-email-geert+renesas@glider.be \
--to=geert+renesas@glider.be \
--cc=agraf@suse.de \
--cc=alex.williamson@redhat.com \
--cc=arnd@arndb.de \
--cc=eric.auger@redhat.com \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=renxiaof@linux.vnet.ibm.com \
--cc=wsa+renesas@sang-engineering.com \
/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;
as well as URLs for NNTP newsgroup(s).