From patchwork Tue Jan 3 00:51:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 133932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D07301007D3 for ; Tue, 3 Jan 2012 11:52:57 +1100 (EST) Received: from localhost ([::1]:51434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RhscW-0000y4-Rk for incoming@patchwork.ozlabs.org; Mon, 02 Jan 2012 19:52:52 -0500 Received: from eggs.gnu.org ([140.186.70.92]:51544) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RhscJ-0000pC-Gb for qemu-devel@nongnu.org; Mon, 02 Jan 2012 19:52:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RhscG-0008H3-4f for qemu-devel@nongnu.org; Mon, 02 Jan 2012 19:52:39 -0500 Received: from e6.ny.us.ibm.com ([32.97.182.146]:60413) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RhscF-0008Gu-VM for qemu-devel@nongnu.org; Mon, 02 Jan 2012 19:52:36 -0500 Received: from /spool/local by e6.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 2 Jan 2012 19:52:35 -0500 Received: from d01relay05.pok.ibm.com (9.56.227.237) by e6.ny.us.ibm.com (192.168.1.106) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 2 Jan 2012 19:52:33 -0500 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q030qXeW260588 for ; Mon, 2 Jan 2012 19:52:33 -0500 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q030qW69001412 for ; Mon, 2 Jan 2012 22:52:32 -0200 Received: from titi.austin.rr.com (sig-9-65-105-201.mts.ibm.com [9.65.105.201]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id q030qLpW000958; Mon, 2 Jan 2012 22:52:31 -0200 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Mon, 2 Jan 2012 18:51:57 -0600 Message-Id: <1325551939-24749-9-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1325551939-24749-1-git-send-email-aliguori@us.ibm.com> References: <1325551939-24749-1-git-send-email-aliguori@us.ibm.com> x-cbid: 12010300-1976-0000-0000-0000091A3887 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 32.97.182.146 Cc: Paolo Bonzini , Anthony Liguori , Markus Armbruster , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH 08/30] qdev: integrate with QEMU Object Model (v2) 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 This is a very shallow integration. We register a TYPE_DEVICE but only use QOM as basically a memory allocator. This will make all devices show up as QOM objects but they will all carry the TYPE_DEVICE. Signed-off-by: Anthony Liguori --- v1 -> v2 - update for new location of object.h --- hw/qdev.c | 27 +++++++++++++++++++++++++-- hw/qdev.h | 10 ++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index d0cf66d..2646d8e 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -47,9 +47,17 @@ static BusState *qbus_find(const char *path); /* Register a new device type. */ void qdev_register(DeviceInfo *info) { + TypeInfo type_info = {}; + assert(info->size >= sizeof(DeviceState)); assert(!info->next); + type_info.name = info->name; + type_info.parent = TYPE_DEVICE; + type_info.instance_size = info->size; + + type_register_static(&type_info); + info->next = device_info_list; device_info_list = info; } @@ -89,7 +97,7 @@ static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) Property *prop; assert(bus->info == info->bus_info); - dev = g_malloc0(info->size); + dev = DEVICE(object_new(info->name)); dev->info = info; dev->parent_bus = bus; qdev_prop_set_defaults(dev, dev->info->props); @@ -491,7 +499,7 @@ void qdev_free(DeviceState *dev) prop->info->free(dev, prop); } } - g_free(dev); + object_delete(OBJECT(dev)); } void qdev_machine_creation_done(void) @@ -1535,3 +1543,18 @@ void qdev_machine_init(void) qdev_get_peripheral_anon(); qdev_get_peripheral(); } + +static TypeInfo device_type_info = { + .name = TYPE_DEVICE, + .parent = TYPE_OBJECT, + .instance_size = sizeof(DeviceState), + .abstract = true, + .class_size = sizeof(DeviceClass), +}; + +static void init_qdev(void) +{ + type_register_static(&device_type_info); +} + +device_init(init_qdev); diff --git a/hw/qdev.h b/hw/qdev.h index 2abb767..d45a6e0 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -6,6 +6,7 @@ #include "qemu-char.h" #include "qemu-option.h" #include "qapi/qapi-visit-core.h" +#include "qemu/object.h" typedef struct Property Property; @@ -66,9 +67,18 @@ typedef struct DeviceProperty QTAILQ_ENTRY(DeviceProperty) node; } DeviceProperty; +#define TYPE_DEVICE "device" +#define DEVICE(obj) OBJECT_CHECK(DeviceState, (obj), TYPE_DEVICE) + +typedef struct DeviceClass { + ObjectClass parent_class; +} DeviceClass; + /* This structure should not be accessed directly. We declare it here so that it can be embedded in individual device state structures. */ struct DeviceState { + Object parent_obj; + const char *id; enum DevState state; QemuOpts *opts;