From patchwork Mon May 9 17:47:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 9048751 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B3FBC9F1C3 for ; Mon, 9 May 2016 17:48:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 190A020114 for ; Mon, 9 May 2016 17:48:04 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5B04720103 for ; Mon, 9 May 2016 17:48:03 +0000 (UTC) Received: from localhost ([::1]:42687 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpHm-00038h-KH for patchwork-qemu-devel@patchwork.kernel.org; Mon, 09 May 2016 13:48:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42980) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpHY-0002z2-TA for qemu-devel@nongnu.org; Mon, 09 May 2016 13:47:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azpHR-00045J-M6 for qemu-devel@nongnu.org; Mon, 09 May 2016 13:47:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56010) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpHR-000456-GX for qemu-devel@nongnu.org; Mon, 09 May 2016 13:47:41 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 052DF37E64 for ; Mon, 9 May 2016 17:47:41 +0000 (UTC) Received: from work.redhat.com (vpn-203-24.tlv.redhat.com [10.35.203.24]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u49HlaY6028811; Mon, 9 May 2016 13:47:39 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Mon, 9 May 2016 20:47:34 +0300 Message-Id: <1462816056-17463-2-git-send-email-marcel@redhat.com> In-Reply-To: <1462816056-17463-1-git-send-email-marcel@redhat.com> References: <1462816056-17463-1-git-send-email-marcel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 09 May 2016 17:47:41 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH RFC 1/3] qdev: add device creation priority flag X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: marcel@redhat.com, pbonzini@redhat.com, mst@redhat.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Some devices need to be created before others. Add a flag to DeviceClass and the means to query it. Signed-off-by: Marcel Apfelbaum --- include/hw/qdev-core.h | 13 +++++++++++++ include/monitor/qdev.h | 1 + qdev-monitor.c | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 1ce02b2..f885d6c 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -29,6 +29,13 @@ typedef enum DeviceCategory { DEVICE_CATEGORY_MAX } DeviceCategory; + +typedef enum DeviceCreationPriority { + DEVICE_PRIO_NORMAL, + DEVICE_PRIO_BRIDGE, + DEVICE_PRIO_HOSTBRIDGE +} DeviceCreationPriority; + typedef int (*qdev_initfn)(DeviceState *dev); typedef int (*qdev_event)(DeviceState *dev); typedef void (*qdev_resetfn)(DeviceState *dev); @@ -139,6 +146,12 @@ typedef struct DeviceClass { qdev_initfn init; /* TODO remove, once users are converted to realize */ qdev_event exit; /* TODO remove, once users are converted to unrealize */ const char *bus_type; + + /* + * Some devices need to be created before others. Devices with higher + * priority will be created first. + */ + DeviceCreationPriority creation_priority; } DeviceClass; typedef struct NamedGPIOList NamedGPIOList; diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h index c4b8a05..7f35ee5 100644 --- a/include/monitor/qdev.h +++ b/include/monitor/qdev.h @@ -12,5 +12,6 @@ void qmp_device_add(QDict *qdict, QObject **ret_data, Error **errp); int qdev_device_help(QemuOpts *opts); DeviceState *qdev_device_add(QemuOpts *opts, Error **errp); +int qdev_device_get_priority(QemuOpts *opts, Error **errp); #endif diff --git a/qdev-monitor.c b/qdev-monitor.c index e19617f..0edba77 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -626,6 +626,25 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) return dev; } +int qdev_device_get_priority(QemuOpts *opts, Error **errp) +{ + DeviceClass *dc; + const char *driver; + + driver = qemu_opt_get(opts, "driver"); + if (!driver) { + error_setg(errp, QERR_MISSING_PARAMETER, "driver"); + return -1; + } + + /* find driver */ + dc = qdev_get_device_class(&driver, errp); + if (!dc) { + return -1; + } + + return dc->creation_priority; +} #define qdev_printf(fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__) static void qbus_print(Monitor *mon, BusState *bus, int indent);