From patchwork Tue Nov 22 18:46:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 9441935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A1760600BA for ; Tue, 22 Nov 2016 18:48:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 96E47284AE for ; Tue, 22 Nov 2016 18:48:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B9F0285B4; Tue, 22 Nov 2016 18:48:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4F655284B7 for ; Tue, 22 Nov 2016 18:48:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c9G5L-00028R-7r; Tue, 22 Nov 2016 18:46:27 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1c9G5J-00026v-HG for xen-devel@lists.xenproject.org; Tue, 22 Nov 2016 18:46:25 +0000 Received: from [85.158.137.68] by server-6.bemta-3.messagelabs.com id 86/3D-25811-08294385; Tue, 22 Nov 2016 18:46:24 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrDLMWRWlGSWpSXmKPExsVybKJsh27DJJM Ig5bzrBbft0xmcmD0OPzhCksAYxRrZl5SfkUCa0b7tiMsBa/VKh78n87cwNip0MXIxSEkMJVR 4ur/5ywQznYmiY7Th9m6GDk52AQMJf4+2QRmiwiISZzePY0JpIhZ4BCjxOcHmxlBEsICNhItT yeC2SwCqhL7L75gB7F5BdwkFl89wQpiSwjISZw8NhnM5hRwl7jS+JMNYls7o8TmCz+ZIIoyJO b1zIFq8JJYdOMSlK0mcfXcJuYJjHwLGBlWMaoXpxaVpRbpGuolFWWmZ5TkJmbm6BoaGOvlphY XJ6an5iQmFesl5+duYgSGCgMQ7GBc/tHpEKMkB5OSKO/hpUYRQnxJ+SmVGYnFGfFFpTmpxYcY ZTg4lCR4EyeaRAgJFqWmp1akZeYAgxYmLcHBoyTCOxEkzVtckJhbnJkOkTrFqCglzqsBkhAAS WSU5sG1wSLlEqOslDAvI9AhQjwFqUW5mSWo8q8YxTkYlYR5VUGm8GTmlcBNfwW0mAloseQ3Y5 DFJYkIKakGxhkM5YLm7G9qzxX+7+/jan2xa8OnOVPflSVNT2QtPqp7TK0le+YS3wc89i+nsr5 +f0XRZVaQA3vqS/Ep/v9ZTLMeSBVmvHzddOM5/52KmDPTlffoLPpmGT1brCRh29UM7WyL6ddW F5ko92eYfb69MTp+SeCLOw3bvLY4cn8/y/VoU4Rh1yRpXiWW4oxEQy3mouJEAOWZKm6PAgAA X-Env-Sender: sstabellini@kernel.org X-Msg-Ref: server-5.tower-31.messagelabs.com!1479840382!69128232!1 X-Originating-IP: [198.145.29.136] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.0.16; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30664 invoked from network); 22 Nov 2016 18:46:23 -0000 Received: from mail.kernel.org (HELO mail.kernel.org) (198.145.29.136) by server-5.tower-31.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 22 Nov 2016 18:46:23 -0000 Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4F7282024F; Tue, 22 Nov 2016 18:46:21 +0000 (UTC) Received: from sstabellini-ThinkPad-X260.hsd1.ca.comcast.net (96-82-76-110-static.hfc.comcastbusiness.net [96.82.76.110]) (using TLSv1.2 with cipher AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 005A620259; Tue, 22 Nov 2016 18:46:19 +0000 (UTC) From: Stefano Stabellini To: stefanha@gmail.com Date: Tue, 22 Nov 2016 10:46:08 -0800 Message-Id: <1479840369-19503-4-git-send-email-sstabellini@kernel.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1479840369-19503-1-git-send-email-sstabellini@kernel.org> References: <1479840369-19503-1-git-send-email-sstabellini@kernel.org> X-Virus-Scanned: ClamAV using ClamSMTP Cc: Juergen Gross , peter.maydell@linaro.org, sstabellini@kernel.org, qemu-devel@nongnu.org, stefanha@redhat.com, anthony.perard@citrix.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [PULL 4/5] xen: create qdev for each backend device X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Juergen Gross Create a qdev plugged to the xen-sysbus for each new backend device. This device can be used as a parent for all needed devices of that backend. The id of the new device will be "xen--" with being the xen backend type (e.g. "qdisk") and the xen backend number of the type under which it is to be found in xenstore. Signed-off-by: Juergen Gross Reviewed-by: Stefano Stabellini Signed-off-by: Stefano Stabellini --- hw/xen/xen_backend.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ hw/xen/xen_pvdev.c | 4 +++- include/hw/xen/xen_backend.h | 4 ++++ include/hw/xen/xen_pvdev.h | 1 + 4 files changed, 55 insertions(+), 1 deletion(-) diff --git a/hw/xen/xen_backend.c b/hw/xen/xen_backend.c index 5ad3caa..d119004 100644 --- a/hw/xen/xen_backend.c +++ b/hw/xen/xen_backend.c @@ -27,11 +27,13 @@ #include "hw/hw.h" #include "hw/sysbus.h" +#include "hw/boards.h" #include "sysemu/char.h" #include "qemu/log.h" #include "qapi/error.h" #include "hw/xen/xen_backend.h" #include "hw/xen/xen_pvdev.h" +#include "monitor/qdev.h" #include @@ -121,6 +123,12 @@ static struct XenDevice *xen_be_get_xendev(const char *type, int dom, int dev, /* init new xendev */ xendev = g_malloc0(ops->size); + object_initialize(&xendev->qdev, ops->size, TYPE_XENBACKEND); + qdev_set_parent_bus(&xendev->qdev, xen_sysbus); + qdev_set_id(&xendev->qdev, g_strdup_printf("xen-%s-%d", type, dev)); + qdev_init_nofail(&xendev->qdev); + object_unref(OBJECT(&xendev->qdev)); + xendev->type = type; xendev->dom = dom; xendev->dev = dev; @@ -541,6 +549,15 @@ err: return -1; } +static void xen_set_dynamic_sysbus(void) +{ + Object *machine = qdev_get_machine(); + ObjectClass *oc = object_get_class(machine); + MachineClass *mc = MACHINE_CLASS(oc); + + mc->has_dynamic_sysbus = true; +} + int xen_be_register(const char *type, struct XenDevOps *ops) { char path[50]; @@ -562,6 +579,8 @@ int xen_be_register(const char *type, struct XenDevOps *ops) void xen_be_register_common(void) { + xen_set_dynamic_sysbus(); + xen_be_register("console", &xen_console_ops); xen_be_register("vkbd", &xen_kbdmouse_ops); xen_be_register("qdisk", &xen_blkdev_ops); @@ -588,9 +607,36 @@ int xen_be_bind_evtchn(struct XenDevice *xendev) } +static Property xendev_properties[] = { + DEFINE_PROP_END_OF_LIST(), +}; + +static void xendev_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->props = xendev_properties; + set_bit(DEVICE_CATEGORY_MISC, dc->categories); +} + +static const TypeInfo xendev_type_info = { + .name = TYPE_XENBACKEND, + .parent = TYPE_XENSYSDEV, + .class_init = xendev_class_init, + .instance_size = sizeof(struct XenDevice), +}; + +static void xen_sysbus_class_init(ObjectClass *klass, void *data) +{ + HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass); + + hc->unplug = qdev_simple_device_unplug_cb; +} + static const TypeInfo xensysbus_info = { .name = TYPE_XENSYSBUS, .parent = TYPE_BUS, + .class_init = xen_sysbus_class_init, .interfaces = (InterfaceInfo[]) { { TYPE_HOTPLUG_HANDLER }, { } @@ -627,6 +673,7 @@ static void xenbe_register_types(void) { type_register_static(&xensysbus_info); type_register_static(&xensysdev_info); + type_register_static(&xendev_type_info); } type_init(xenbe_register_types) diff --git a/hw/xen/xen_pvdev.c b/hw/xen/xen_pvdev.c index 5212bc6..aed783e 100644 --- a/hw/xen/xen_pvdev.c +++ b/hw/xen/xen_pvdev.c @@ -19,6 +19,7 @@ #include "qemu/osdep.h" #include "qemu/log.h" +#include "hw/qdev-core.h" #include "hw/xen/xen_backend.h" #include "hw/xen/xen_pvdev.h" @@ -307,7 +308,8 @@ void xen_pv_del_xendev(struct XenDevice *xendev) } QTAILQ_REMOVE(&xendevs, xendev, next); - g_free(xendev); + + qdev_unplug(&xendev->qdev, NULL); } void xen_pv_insert_xendev(struct XenDevice *xendev) diff --git a/include/hw/xen/xen_backend.h b/include/hw/xen/xen_backend.h index 38f730e..4f4799a 100644 --- a/include/hw/xen/xen_backend.h +++ b/include/hw/xen/xen_backend.h @@ -8,6 +8,10 @@ #define TYPE_XENSYSDEV "xen-sysdev" #define TYPE_XENSYSBUS "xen-sysbus" +#define TYPE_XENBACKEND "xen-backend" + +#define XENBACKEND_DEVICE(obj) \ + OBJECT_CHECK(XenDevice, (obj), TYPE_XENBACKEND) /* variables */ extern xc_interface *xen_xc; diff --git a/include/hw/xen/xen_pvdev.h b/include/hw/xen/xen_pvdev.h index 083f0a9..d473e9b 100644 --- a/include/hw/xen/xen_pvdev.h +++ b/include/hw/xen/xen_pvdev.h @@ -29,6 +29,7 @@ struct XenDevOps { }; struct XenDevice { + DeviceState qdev; const char *type; int dom; int dev;