From patchwork Mon Aug 31 10:27:35 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 32618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by bilbo.ozlabs.org (Postfix) with ESMTPS id 2BE07B70B0 for ; Mon, 31 Aug 2009 20:31:41 +1000 (EST) Received: from localhost ([127.0.0.1]:41266 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mi4Ai-0006RW-54 for incoming@patchwork.ozlabs.org; Mon, 31 Aug 2009 06:31:36 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mi476-0005Ed-3t for qemu-devel@nongnu.org; Mon, 31 Aug 2009 06:27:52 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mi471-0005DO-A6 for qemu-devel@nongnu.org; Mon, 31 Aug 2009 06:27:51 -0400 Received: from [199.232.76.173] (port=56572 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mi471-0005DG-5f for qemu-devel@nongnu.org; Mon, 31 Aug 2009 06:27:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:8047) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mi470-0003Un-Iz for qemu-devel@nongnu.org; Mon, 31 Aug 2009 06:27:46 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n7VARiOT000885 for ; Mon, 31 Aug 2009 06:27:45 -0400 Received: from zweiblum.home.kraxel.org (vpn2-8-244.ams2.redhat.com [10.36.8.244]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n7VARfbu012230; Mon, 31 Aug 2009 06:27:43 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 1CB96700E1; Mon, 31 Aug 2009 12:27:39 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 31 Aug 2009 12:27:35 +0200 Message-Id: <1251714459-2467-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1251714459-2467-1-git-send-email-kraxel@redhat.com> References: <1251714459-2467-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/5] qdev: device capabilities X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org This patch adds device capabilities to qdev devices. This is the core code, following patches will add the individual capabilities and tag drivers. The capabilities will be printed by '-device ?' and 'info qdm", so users and management apps can use it. Future plans: I plan to use them to get rid off some hard-coded lists in qemu by using capabilities instead: pci nic list, watchdog list, maybe more. Signed-off-by: Gerd Hoffmann --- hw/qdev.c | 19 ++++++++++++++++++- hw/qdev.h | 5 +++++ 2 files changed, 23 insertions(+), 1 deletions(-) diff --git a/hw/qdev.c b/hw/qdev.c index ff2f096..0d21152 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -107,8 +107,11 @@ DeviceState *qdev_create(BusState *bus, const char *name) static int qdev_print_devinfo(DeviceInfo *info, char *dest, int len) { + static const char *capname[] = { + }; + const char *sep; int pos = 0; - int ret; + int ret,i; ret = snprintf(dest+pos, len-pos, "name \"%s\", bus %s", info->name, info->bus_info->name); @@ -125,6 +128,20 @@ static int qdev_print_devinfo(DeviceInfo *info, char *dest, int len) ret = snprintf(dest+pos, len-pos, ", no-user"); pos += MIN(len-pos,ret); } + if (info->caps) { + ret = snprintf(dest+pos, len-pos, ", caps \""); + pos += MIN(len-pos,ret); + sep = ""; + for (i = 0; i < ARRAY_SIZE(capname); i++) { + if (!(info->caps & (1 << i))) + continue; + ret = snprintf(dest+pos, len-pos, "%s%s", sep, capname[i]); + pos += MIN(len-pos,ret); + sep = ","; + } + ret = snprintf(dest+pos, len-pos, "\""); + pos += MIN(len-pos,ret); + } return pos; } diff --git a/hw/qdev.h b/hw/qdev.h index af735d7..3d07a24 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -102,6 +102,10 @@ typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info); typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv, int unit); +enum DeviceCapBits { + dummy +}; + struct DeviceInfo { const char *name; const char *alias; @@ -109,6 +113,7 @@ struct DeviceInfo { size_t size; Property *props; int no_user; + uint32_t caps; /* Private to qdev / bus. */ qdev_initfn init;