From patchwork Mon Feb 24 09:23:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Or Goshen X-Patchwork-Id: 323514 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 93A932C00D0 for ; Mon, 24 Feb 2014 20:24:10 +1100 (EST) Received: from localhost ([::1]:56450 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHrlg-0001ow-Fg for incoming@patchwork.ozlabs.org; Mon, 24 Feb 2014 04:24:08 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49130) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHrlL-0001or-Sp for qemu-devel@nongnu.org; Mon, 24 Feb 2014 04:23:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WHrlG-0005yk-K1 for qemu-devel@nongnu.org; Mon, 24 Feb 2014 04:23:47 -0500 Received: from mail-ea0-x22b.google.com ([2a00:1450:4013:c01::22b]:64431) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WHrlG-0005ye-CI for qemu-devel@nongnu.org; Mon, 24 Feb 2014 04:23:42 -0500 Received: by mail-ea0-f171.google.com with SMTP id f15so2908515eak.16 for ; Mon, 24 Feb 2014 01:23:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=TGPG7Evwg3d7+4v7pNkrPeKOedXpzcEoDLooCd5P84g=; b=XhhVrtY1CylLUpPoJ/0uT4Xz7AisWBDVbaYGB2FY1QBOGVr3BoBfSUEboVErQk8/0u FNJX2OFkMq6xmPKzl6moVQwYy3h3R4kIOJISgzg3j0tBsGS7D5ohJ9sw+bMMNnon7UMs NZJwoGo6TTsP3fDp0UKLSS6o3a9Y1HJSMKmou/wroR3sZ3YyQs9bPjSX1BvJT4Mrq/gM mPw9B9TWSywLMUL+NS1bnotPmQeO0pM8vFVKpu+uqeC2TorDtIF2Ka6JlUi75MB2ecNE fCV9ydCv/P4/25t2itw5/F8Tjad5Ph7lVXqIim9R7vs3s5b8vLffCFmyOpbHlaqeFyGQ ROpQ== X-Received: by 10.15.23.66 with SMTP id g42mr16468850eeu.9.1393233821442; Mon, 24 Feb 2014 01:23:41 -0800 (PST) Received: from localhost.localdomain ([109.64.16.176]) by mx.google.com with ESMTPSA id f45sm61523002eeg.5.2014.02.24.01.23.37 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Feb 2014 01:23:40 -0800 (PST) From: Or Goshen To: Luiz Capitulino Date: Mon, 24 Feb 2014 11:23:16 +0200 Message-Id: <1393233796-1328-1-git-send-email-orx.goshen@intel.com> X-Mailer: git-send-email 1.7.9 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c01::22b Cc: qemu-devel@nongnu.org, Or Goshen Subject: [Qemu-devel] [PATCH] Add a command to QMP to list the supported devices 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 From: Or Goshen Was done on behalf of Intel Corp. --- qapi-schema.json | 26 ++++++++++++++++++++++++++ qdev-monitor.c | 28 ++++++++++++++++++++++++++++ qmp-commands.hx | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+), 0 deletions(-) diff --git a/qapi-schema.json b/qapi-schema.json index 05ced9d..cae1200 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -526,6 +526,32 @@ { 'command': 'query-commands', 'returns': ['CommandInfo'] } ## +# @DeviceInfo: +# +# Information about a device +# +# @name: The command name +# @bus: The bus it is connected to +# @alias: Device alias +# @desc: Description of the device +# +# Since: 1.6.0 +## +{ 'type': 'DeviceInfo', 'data': {'name': 'str', 'bus': 'str', 'alias': 'str', 'desc': 'str'} } + +## +# @query-devices: +# +# Return a list of supported devices +# +# Returns: A list of @DeviceInfo for all supported devices +# +# Since: 1.6.0 +## +{ 'command': 'query-devices', 'returns': ['DeviceInfo'] } + + +## # @EventInfo: # # Information about a QMP event diff --git a/qdev-monitor.c b/qdev-monitor.c index 1d3b68d..0a59fd9 100644 --- a/qdev-monitor.c +++ b/qdev-monitor.c @@ -644,6 +644,34 @@ void do_info_qtree(Monitor *mon, const QDict *qdict) qbus_print(mon, sysbus_get_default(), 0); } +static void qdev_list_devinfo(ObjectClass *klass, void *data) +{ + DeviceInfoList *e, **pret = data; + DeviceInfo *info; + DeviceClass *dc = (DeviceClass *)object_class_dynamic_cast(klass, TYPE_DEVICE); + if (!dc) return; + + info = g_malloc0(sizeof(*info)); + info->name = g_strdup(object_class_get_name(klass)); + info->bus = g_strdup(dc->bus_type ? dc->bus_type : ""); + info->alias = g_strdup(qdev_class_has_alias(dc) ? qdev_class_get_alias(dc) : ""); + info->desc = g_strdup(dc->desc ? dc->desc : ""); + + e = g_malloc0(sizeof(*e)); + e->value = info; + e->next = *pret; + *pret = e; +} + +DeviceInfoList * qmp_query_devices(Error **errp) +{ + DeviceInfoList *list = NULL; + + object_class_foreach(qdev_list_devinfo, TYPE_DEVICE, false, &list); + + return list; +} + void do_info_qdm(Monitor *mon, const QDict *qdict) { qdev_print_devinfos(true); diff --git a/qmp-commands.hx b/qmp-commands.hx index cce6b81..be4451d 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -1851,6 +1851,46 @@ EQMP }, SQMP +query-devices +-------------- + +List supported devices + +Each device is represented by a json-object, the returned value is a json-array +of all devices. + +Each json-object contain: + +- "name": device's name (json-string) +- "bus": bus the device connects to (json-string) +- "alias": device's alias (json-string) +- "desc": device's description (json-string) + +Example: + +-> { "execute": "query-devices" } +<- { + "return":[ + { + "name":"pci-bridge", + "bus":"PCI", + "alias":"", + "desc":"Standard PCI Bridge" + } + ] + } + +Note: This example has been shortened as the real response is too long. + +EQMP + + { + .name = "query-devices", + .args_type = "", + .mhandler.cmd_new = qmp_marshal_input_query_devices, + }, + +SQMP query-events --------------