* [Qemu-devel] [RFC v2 0/2] Allow direct vfio-platform device instantiation
@ 2017-02-21 21:10 Eric Auger
2017-02-21 21:10 ` [Qemu-devel] [RFC v2 1/2] vfio/platform: make the vfio-platform device non abstract Eric Auger
2017-02-21 21:10 ` [Qemu-devel] [RFC v2 2/2] hw/arm/sysbus-fdt: Allow device matching with compat string Eric Auger
0 siblings, 2 replies; 3+ messages in thread
From: Eric Auger @ 2017-02-21 21:10 UTC (permalink / raw)
To: eric.auger.pro, eric.auger, peter.maydell, alex.williamson,
qemu-arm, qemu-devel
Cc: shankerd, okaya, vikrams, agraf, pelcan
Up to now, supporting a new VFIO-PLATFORM device has requested
to create a dummy derived device. The type of the derived
device was used to match the device tree node creation function.
Since the actual adaptation fits within this node creation function
and not anywhere else at the moment, let's allow to instantiate the
VFIO-PLATFORM device and pass the compatibility string with 2 separate
options, manufacturer and model. sysbus-fdt is adapted to associate
a node creation function with this combo.
The removal of the abstract characteristics was discussed on the ML
(https://lists.gnu.org/archive/html/qemu-devel/2016-08/msg03326.html)
in the context of HiDma integration.
This change should ease the integration of new devices and limit the
amount of adaptation code to the minimum, ie. the node creation
function).
The AMD XGBE is the first device that can be instantiated that way:
-device vfio-platform,host=e0900000.xgmac,manufacturer=amd,model=xgbe-seattle-v1a
Note the legacy option still is available:
-device vfio-amd-xgbe,host=e0900000.xgmac
History:
PATCH -> RFC v2
- Fixed compilation issue when CONFIG_LINUX is not set
- moved to RFC since it needs more discussion and cannot apply to 2.9
Eric Auger (2):
vfio/platform: make the vfio-platform device non abstract
hw/arm/sysbus-fdt: Allow device matching with compat string
hw/arm/sysbus-fdt.c | 61 ++++++++++++++++++++++++++++++++---------
hw/vfio/platform.c | 18 ++++++++++--
include/hw/vfio/vfio-platform.h | 2 ++
3 files changed, 66 insertions(+), 15 deletions(-)
--
2.5.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Qemu-devel] [RFC v2 1/2] vfio/platform: make the vfio-platform device non abstract
2017-02-21 21:10 [Qemu-devel] [RFC v2 0/2] Allow direct vfio-platform device instantiation Eric Auger
@ 2017-02-21 21:10 ` Eric Auger
2017-02-21 21:10 ` [Qemu-devel] [RFC v2 2/2] hw/arm/sysbus-fdt: Allow device matching with compat string Eric Auger
1 sibling, 0 replies; 3+ messages in thread
From: Eric Auger @ 2017-02-21 21:10 UTC (permalink / raw)
To: eric.auger.pro, eric.auger, peter.maydell, alex.williamson,
qemu-arm, qemu-devel
Cc: shankerd, okaya, vikrams, agraf, pelcan
Up to now the vfio-platform device has been abstract and could not be
instantiated. The integration of a new vfio platform device required
to create a dummy derived device which only set the compatibility
string.
Following the few vfio-platform device integration we have seen
the actual requested adaptation happens on device tree node creation
(sysbus-fdt).
So this patch removes the abstract setting and defines 2 new options,
manufacturer and model that are used to build a compatibility string.
This latter will be used to match the device tree node creation
function
sysbus-fdt does not support the instantiation of the vfio-platform
device yet.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
hw/vfio/platform.c | 18 ++++++++++++++++--
include/hw/vfio/vfio-platform.h | 2 ++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index a4663c9..73c0489 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -637,7 +637,20 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp)
VFIOPlatformDevice *vdev = VFIO_PLATFORM_DEVICE(dev);
SysBusDevice *sbdev = SYS_BUS_DEVICE(dev);
VFIODevice *vbasedev = &vdev->vbasedev;
- int i, ret;
+ int i, ret = -EINVAL;
+
+ if (!vdev->compat) {
+ if (!vdev->model) {
+ error_setg(errp, "no usable compatible string");
+ goto out;
+ }
+ if (!vdev->manufacturer) {
+ vdev->compat = g_strdup(vdev->model);
+ } else {
+ vdev->compat = g_strjoin(",", vdev->manufacturer,
+ vdev->model, NULL);
+ }
+ }
vbasedev->type = VFIO_DEVICE_TYPE_PLATFORM;
vbasedev->ops = &vfio_platform_ops;
@@ -678,6 +691,8 @@ static const VMStateDescription vfio_platform_vmstate = {
static Property vfio_platform_dev_properties[] = {
DEFINE_PROP_STRING("host", VFIOPlatformDevice, vbasedev.name),
DEFINE_PROP_STRING("sysfsdev", VFIOPlatformDevice, vbasedev.sysfsdev),
+ DEFINE_PROP_STRING("manufacturer", VFIOPlatformDevice, manufacturer),
+ DEFINE_PROP_STRING("model", VFIOPlatformDevice, model),
DEFINE_PROP_BOOL("x-no-mmap", VFIOPlatformDevice, vbasedev.no_mmap, false),
DEFINE_PROP_UINT32("mmap-timeout-ms", VFIOPlatformDevice,
mmap_timeout, 1100),
@@ -704,7 +719,6 @@ static const TypeInfo vfio_platform_dev_info = {
.instance_size = sizeof(VFIOPlatformDevice),
.class_init = vfio_platform_class_init,
.class_size = sizeof(VFIOPlatformDeviceClass),
- .abstract = true,
};
static void register_vfio_platform_dev_type(void)
diff --git a/include/hw/vfio/vfio-platform.h b/include/hw/vfio/vfio-platform.h
index 9baaa2db..31b9a98 100644
--- a/include/hw/vfio/vfio-platform.h
+++ b/include/hw/vfio/vfio-platform.h
@@ -55,6 +55,8 @@ typedef struct VFIOPlatformDevice {
/* queue of pending IRQs */
QSIMPLEQ_HEAD(pending_intp_queue, VFIOINTp) pending_intp_queue;
char *compat; /* compatibility string */
+ char *manufacturer; /* manufacturer (1st part of the compatible property) */
+ char *model; /* model (2d part of the compatible property) */
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 */
--
2.5.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [Qemu-devel] [RFC v2 2/2] hw/arm/sysbus-fdt: Allow device matching with compat string
2017-02-21 21:10 [Qemu-devel] [RFC v2 0/2] Allow direct vfio-platform device instantiation Eric Auger
2017-02-21 21:10 ` [Qemu-devel] [RFC v2 1/2] vfio/platform: make the vfio-platform device non abstract Eric Auger
@ 2017-02-21 21:10 ` Eric Auger
1 sibling, 0 replies; 3+ messages in thread
From: Eric Auger @ 2017-02-21 21:10 UTC (permalink / raw)
To: eric.auger.pro, eric.auger, peter.maydell, alex.williamson,
qemu-arm, qemu-devel
Cc: shankerd, okaya, vikrams, agraf, pelcan
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>
---
v1 -> v2:
- fix the compilation issue when CONFIG_LINUX is not set
---
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 d68e3dc..c5d4fd5 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.5.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-02-21 21:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-21 21:10 [Qemu-devel] [RFC v2 0/2] Allow direct vfio-platform device instantiation Eric Auger
2017-02-21 21:10 ` [Qemu-devel] [RFC v2 1/2] vfio/platform: make the vfio-platform device non abstract Eric Auger
2017-02-21 21:10 ` [Qemu-devel] [RFC v2 2/2] hw/arm/sysbus-fdt: Allow device matching with compat string Eric Auger
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).