From patchwork Wed Feb 1 19:50:47 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 138980 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 95E421007D1 for ; Thu, 2 Feb 2012 06:52:01 +1100 (EST) Received: from localhost ([::1]:55497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDj-0000dy-OS for incoming@patchwork.ozlabs.org; Wed, 01 Feb 2012 14:51:55 -0500 Received: from eggs.gnu.org ([140.186.70.92]:37470) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDT-0000GH-Re for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RsgDP-00061T-JW for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:39 -0500 Received: from cpe-70-123-132-139.austin.res.rr.com ([70.123.132.139]:52874 helo=localhost6.localdomain6) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsgDP-00061H-B7 for qemu-devel@nongnu.org; Wed, 01 Feb 2012 14:51:35 -0500 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by localhost6.localdomain6 (8.14.4/8.14.4/Debian-2ubuntu1) with ESMTP id q11JpUF6006341; Wed, 1 Feb 2012 13:51:30 -0600 Received: (from anthony@localhost) by localhost6.localdomain6 (8.14.4/8.14.4/Submit) id q11JpSAd006338; Wed, 1 Feb 2012 13:51:28 -0600 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 1 Feb 2012 13:50:47 -0600 Message-Id: <1328125863-6203-7-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1328125863-6203-1-git-send-email-aliguori@us.ibm.com> References: <1328125863-6203-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 70.123.132.139 Cc: Paolo Bonzini , Anthony Liguori , Andreas Faerber , Peter Maydell Subject: [Qemu-devel] [PATCH 06/22] qdev: refactor device creation to allow bus_info to be set only in class 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 As we use class_init to set class members, DeviceInfo no longer holds this information. Signed-off-by: Anthony Liguori --- hw/qdev.c | 42 +++++++++++++++++++----------------------- 1 files changed, 19 insertions(+), 23 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index c9f890c..bba84e2 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -119,21 +119,29 @@ const char *qdev_fw_name(DeviceState *dev) return object_get_typename(OBJECT(dev)); } -void qdev_register_subclass(DeviceInfo *info, const char *parent) +static void qdev_do_register_subclass(DeviceInfo *info, const char *parent, + const char *name) { TypeInfo type_info = {}; assert(info->size >= sizeof(DeviceState)); assert(!info->next); - type_info.name = info->name; + type_info.name = name; type_info.parent = parent; type_info.instance_size = info->size; type_info.class_init = qdev_subclass_init; type_info.class_data = info; type_register_static(&type_info); +} +void qdev_register_subclass(DeviceInfo *info, const char *parent) +{ + qdev_do_register_subclass(info, parent, info->name); + if (info->alias) { + qdev_do_register_subclass(info, parent, info->alias); + } info->next = device_info_list; device_info_list = info; } @@ -173,12 +181,12 @@ bool qdev_exists(const char *name) static void qdev_property_add_legacy(DeviceState *dev, Property *prop, Error **errp); -static DeviceState *qdev_create_from_info(BusState *bus, DeviceInfo *info) +static DeviceState *qdev_create_from_info(BusState *bus, const char *typename) { DeviceState *dev; Property *prop; - dev = DEVICE(object_new(info->name)); + dev = DEVICE(object_new(typename)); dev->parent_bus = bus; qdev_prop_set_defaults(dev, qdev_get_props(dev)); qdev_prop_set_defaults(dev, dev->parent_bus->info->props); @@ -230,18 +238,11 @@ DeviceState *qdev_create(BusState *bus, const char *name) DeviceState *qdev_try_create(BusState *bus, const char *name) { - DeviceInfo *info; - if (!bus) { bus = sysbus_get_default(); } - info = qdev_find_info(bus->info, name); - if (!info) { - return NULL; - } - - return qdev_create_from_info(bus, info); + return qdev_create_from_info(bus, name); } static void qdev_print_devinfo(DeviceInfo *info) @@ -352,8 +353,8 @@ static DeviceState *qdev_get_peripheral_anon(void) DeviceState *qdev_device_add(QemuOpts *opts) { + DeviceClass *k; const char *driver, *path, *id; - DeviceInfo *info; DeviceState *qdev; BusState *bus; @@ -364,12 +365,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) } /* find driver */ - info = qdev_find_info(NULL, driver); - if (!info || info->no_user) { - qerror_report(QERR_INVALID_PARAMETER_VALUE, "driver", "a driver name"); - error_printf_unless_qmp("Try with argument '?' for a list.\n"); - return NULL; - } + k = DEVICE_CLASS(object_class_by_name(driver)); /* find bus */ path = qemu_opt_get(opts, "bus"); @@ -378,16 +374,16 @@ DeviceState *qdev_device_add(QemuOpts *opts) if (!bus) { return NULL; } - if (bus->info != info->bus_info) { + if (bus->info != k->bus_info) { qerror_report(QERR_BAD_BUS_FOR_DEVICE, driver, bus->info->name); return NULL; } } else { - bus = qbus_find_recursive(main_system_bus, NULL, info->bus_info); + bus = qbus_find_recursive(main_system_bus, NULL, k->bus_info); if (!bus) { qerror_report(QERR_NO_BUS_FOR_DEVICE, - info->name, info->bus_info->name); + driver, k->bus_info->name); return NULL; } } @@ -397,7 +393,7 @@ DeviceState *qdev_device_add(QemuOpts *opts) } /* create device, set properties */ - qdev = qdev_create_from_info(bus, info); + qdev = qdev_create_from_info(bus, driver); id = qemu_opts_id(opts); if (id) { qdev->id = id;