From patchwork Fri Jun 19 08:38:35 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 486620 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 6EEF1140285 for ; Fri, 19 Jun 2015 18:40:48 +1000 (AEST) Received: from localhost ([::1]:56934 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5rqw-0004Kj-LN for incoming@patchwork.ozlabs.org; Fri, 19 Jun 2015 04:40:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5rp6-0001Bj-Ax for qemu-devel@nongnu.org; Fri, 19 Jun 2015 04:38:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z5rp1-0000ZI-TB for qemu-devel@nongnu.org; Fri, 19 Jun 2015 04:38:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z5rp1-0000Z3-Lx for qemu-devel@nongnu.org; Fri, 19 Jun 2015 04:38:47 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 53279C6A17 for ; Fri, 19 Jun 2015 08:38:47 +0000 (UTC) Received: from nilsson.home.kraxel.org (ovpn-116-20.ams2.redhat.com [10.36.116.20]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t5J8cjkp022732; Fri, 19 Jun 2015 04:38:46 -0400 Received: by nilsson.home.kraxel.org (Postfix, from userid 500) id 9CC4381031; Fri, 19 Jun 2015 10:38:44 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 19 Jun 2015 10:38:35 +0200 Message-Id: <1434703117-9939-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1434703117-9939-1-git-send-email-kraxel@redhat.com> References: <1434703117-9939-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH for-2.4 1/3] virtio-input: move properties, use virtio_instance_init_common X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Move properties from virtio-*-pci to virtio-*-device. Also make better use of QOM and attach common properties to the abstract parent classes (virtio-input-device and virtio-input-pci-device). Switch the hid device instance init functions over to use virtio_instance_init_common, so we get the properties of the virtio device aliased properly to the virtio pci proxy. Signed-off-by: Gerd Hoffmann Reviewed-by: Michael S. Tsirkin --- hw/input/virtio-input.c | 8 +++++++- hw/virtio/virtio-pci.c | 27 +++++++++++---------------- include/hw/virtio/virtio-input.h | 9 +-------- 3 files changed, 19 insertions(+), 25 deletions(-) diff --git a/hw/input/virtio-input.c b/hw/input/virtio-input.c index c4f4b3c..7f5b8d6 100644 --- a/hw/input/virtio-input.c +++ b/hw/input/virtio-input.c @@ -216,7 +216,7 @@ static void virtio_input_device_realize(DeviceState *dev, Error **errp) } virtio_input_idstr_config(vinput, VIRTIO_INPUT_CFG_ID_SERIAL, - vinput->input.serial); + vinput->serial); QTAILQ_FOREACH(cfg, &vinput->cfg_list, node) { if (vinput->cfg_size < cfg->config.size) { @@ -248,11 +248,17 @@ static void virtio_input_device_unrealize(DeviceState *dev, Error **errp) virtio_cleanup(vdev); } +static Property virtio_input_properties[] = { + DEFINE_PROP_STRING("serial", VirtIOInput, serial), + DEFINE_PROP_END_OF_LIST(), +}; + static void virtio_input_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass); + dc->props = virtio_input_properties; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); vdc->realize = virtio_input_device_realize; vdc->unrealize = virtio_input_device_unrealize; diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index d7cf34c..1187a58 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -1900,8 +1900,7 @@ static const TypeInfo virtio_rng_pci_info = { /* virtio-input-pci */ -static Property virtio_input_hid_pci_properties[] = { - DEFINE_VIRTIO_INPUT_PROPERTIES(VirtIOInputPCI, vdev.input), +static Property virtio_input_pci_properties[] = { DEFINE_PROP_UINT32("vectors", VirtIOPCIProxy, nvectors, 2), DEFINE_PROP_END_OF_LIST(), }; @@ -1924,19 +1923,13 @@ static void virtio_input_pci_class_init(ObjectClass *klass, void *data) VirtioPCIClass *k = VIRTIO_PCI_CLASS(klass); PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); + dc->props = virtio_input_pci_properties; k->realize = virtio_input_pci_realize; set_bit(DEVICE_CATEGORY_INPUT, dc->categories); pcidev_k->class_id = PCI_CLASS_INPUT_OTHER; } -static void virtio_input_hid_pci_class_init(ObjectClass *klass, void *data) -{ - DeviceClass *dc = DEVICE_CLASS(klass); - - dc->props = virtio_input_hid_pci_properties; -} - static void virtio_input_hid_kbd_pci_class_init(ObjectClass *klass, void *data) { PCIDeviceClass *pcidev_k = PCI_DEVICE_CLASS(klass); @@ -1955,22 +1948,25 @@ static void virtio_input_hid_mouse_pci_class_init(ObjectClass *klass, static void virtio_keyboard_initfn(Object *obj) { VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); - object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_KEYBOARD); - object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_KEYBOARD); } static void virtio_mouse_initfn(Object *obj) { VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); - object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_MOUSE); - object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_MOUSE); } static void virtio_tablet_initfn(Object *obj) { VirtIOInputHIDPCI *dev = VIRTIO_INPUT_HID_PCI(obj); - object_initialize(&dev->vdev, sizeof(dev->vdev), TYPE_VIRTIO_TABLET); - object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_TABLET); } static const TypeInfo virtio_input_pci_info = { @@ -1985,7 +1981,6 @@ static const TypeInfo virtio_input_hid_pci_info = { .name = TYPE_VIRTIO_INPUT_HID_PCI, .parent = TYPE_VIRTIO_INPUT_PCI, .instance_size = sizeof(VirtIOInputHIDPCI), - .class_init = virtio_input_hid_pci_class_init, .abstract = true, }; diff --git a/include/hw/virtio/virtio-input.h b/include/hw/virtio/virtio-input.h index 8134178..8160dd6 100644 --- a/include/hw/virtio/virtio-input.h +++ b/include/hw/virtio/virtio-input.h @@ -50,18 +50,11 @@ typedef struct virtio_input_event virtio_input_event; #define VIRTIO_INPUT_HID_GET_PARENT_CLASS(obj) \ OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_INPUT_HID) -#define DEFINE_VIRTIO_INPUT_PROPERTIES(_state, _field) \ - DEFINE_PROP_STRING("serial", _state, _field.serial) - typedef struct VirtIOInput VirtIOInput; typedef struct VirtIOInputClass VirtIOInputClass; typedef struct VirtIOInputConfig VirtIOInputConfig; typedef struct VirtIOInputHID VirtIOInputHID; -struct virtio_input_conf { - char *serial; -}; - struct VirtIOInputConfig { virtio_input_config config; QTAILQ_ENTRY(VirtIOInputConfig) node; @@ -74,7 +67,7 @@ struct VirtIOInput { uint32_t cfg_size; QTAILQ_HEAD(, VirtIOInputConfig) cfg_list; VirtQueue *evt, *sts; - virtio_input_conf input; + char *serial; virtio_input_event *queue; uint32_t qindex, qsize;