From patchwork Wed Apr 5 12:41:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 747280 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 3vym9x5wM5z9s2Q for ; Wed, 5 Apr 2017 22:58:45 +1000 (AEST) Received: from localhost ([::1]:40409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkWJ-0004VF-AN for incoming@patchwork.ozlabs.org; Wed, 05 Apr 2017 08:58:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42275) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cvkHm-0000rB-Ge for qemu-devel@nongnu.org; Wed, 05 Apr 2017 08:43:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cvkHl-0001Ym-G7 for qemu-devel@nongnu.org; Wed, 05 Apr 2017 08:43:42 -0400 Received: from 8.mo177.mail-out.ovh.net ([46.105.61.98]:40253) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cvkHl-0001YC-AQ for qemu-devel@nongnu.org; Wed, 05 Apr 2017 08:43:41 -0400 Received: from player688.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo177.mail-out.ovh.net (Postfix) with ESMTP id 4206749B6D for ; Wed, 5 Apr 2017 14:43:40 +0200 (CEST) Received: from zorba.kaod.org.com (LFbn-1-10647-27.w90-89.abo.wanadoo.fr [90.89.233.27]) (Authenticated sender: clg@kaod.org) by player688.ha.ovh.net (Postfix) with ESMTPSA id 144432009A; Wed, 5 Apr 2017 14:43:33 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: David Gibson Date: Wed, 5 Apr 2017 14:41:42 +0200 Message-Id: <1491396106-26376-18-git-send-email-clg@kaod.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491396106-26376-1-git-send-email-clg@kaod.org> References: <1491396106-26376-1-git-send-email-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 16608149527013395430 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeliedrtddvgdehhecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfqggfjpdevjffgvefmvefgnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 46.105.61.98 Subject: [Qemu-devel] [PATCH 17/21] qdev: Add a hook for a bus to device if it can add devices 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: "Michael S. Tsirkin" , qemu-devel@nongnu.org, qemu-ppc@nongnu.org, =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Marcel Apfelbaum Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Benjamin Herrenschmidt This allows a bus class to tell whether a given bus has room for any new device. max_dev isn't sufficient as the rules can depend on some arguments or can differ between instances of a bus. This will be used by PCI in subsequent patches Signed-off-by: Benjamin Herrenschmidt [clg: updated for qemu-2.9 ] Signed-off-by: Cédric Le Goater --- include/hw/qdev-core.h | 1 + qdev-monitor.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index b44b47676576..867662ba5352 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -201,6 +201,7 @@ struct BusClass { */ char *(*get_fw_dev_path)(DeviceState *dev); void (*reset)(BusState *bus); + bool (*can_add_device)(BusState *bus, QemuOpts *opts); BusRealize realize; BusUnrealize unrealize; diff --git a/qdev-monitor.c b/qdev-monitor.c index 5f2fcdfc4551..c6eca929c473 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -415,7 +415,7 @@ static inline bool qbus_is_full(BusState *bus) * Return the bus if found, else %NULL. */ static BusState *qbus_find_recursive(BusState *bus, const char *name, - const char *bus_typename) + const char *bus_typename, QemuOpts *opts) { BusChild *kid; BusState *pick, *child, *ret; @@ -429,7 +429,10 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name, } if (match && !qbus_is_full(bus)) { - return bus; /* root matches and isn't full */ + BusClass *bc = BUS_GET_CLASS(bus); + if (!bc->can_add_device || bc->can_add_device(bus, opts)) { + return bus; /* root matches and isn't full */ + } } pick = match ? bus : NULL; @@ -437,7 +440,7 @@ static BusState *qbus_find_recursive(BusState *bus, const char *name, QTAILQ_FOREACH(kid, &bus->children, sibling) { DeviceState *dev = kid->child; QLIST_FOREACH(child, &dev->child_bus, sibling) { - ret = qbus_find_recursive(child, name, bus_typename); + ret = qbus_find_recursive(child, name, bus_typename, opts); if (ret && !qbus_is_full(ret)) { return ret; /* a descendant matches and isn't full */ } @@ -467,7 +470,7 @@ static BusState *qbus_find(const char *path, Error **errp) assert(!path[0]); elem[0] = len = 0; } - bus = qbus_find_recursive(sysbus_get_default(), elem, NULL); + bus = qbus_find_recursive(sysbus_get_default(), elem, NULL, NULL); if (!bus) { error_setg(errp, "Bus '%s' not found", elem); return NULL; @@ -591,7 +594,8 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) return NULL; } } else if (dc->bus_type != NULL) { - bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type); + bus = qbus_find_recursive(sysbus_get_default(), NULL, dc->bus_type, + opts); if (!bus || qbus_is_full(bus)) { error_setg(errp, "No '%s' bus found for device '%s'", dc->bus_type, driver);