From patchwork Mon Jun 4 08:52:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 162697 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D2964B6FC3 for ; Mon, 4 Jun 2012 19:59:32 +1000 (EST) Received: from localhost ([::1]:37444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbT2L-0000Q2-VE for incoming@patchwork.ozlabs.org; Mon, 04 Jun 2012 04:53:17 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbT1f-0006lS-QR for qemu-devel@nongnu.org; Mon, 04 Jun 2012 04:52:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbT1Z-00043q-N8 for qemu-devel@nongnu.org; Mon, 04 Jun 2012 04:52:35 -0400 Received: from goliath.siemens.de ([192.35.17.28]:24270) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbT1Z-00042I-Cl for qemu-devel@nongnu.org; Mon, 04 Jun 2012 04:52:29 -0400 Received: from mail1.siemens.de (localhost [127.0.0.1]) by goliath.siemens.de (8.13.6/8.13.6) with ESMTP id q548qRRp029389; Mon, 4 Jun 2012 10:52:27 +0200 Received: from mchn199C.mchp.siemens.de (atpczjyc.ww300.siemens.net [139.22.45.247]) by mail1.siemens.de (8.13.6/8.13.6) with SMTP id q548qMq3019518; Mon, 4 Jun 2012 10:52:27 +0200 From: Jan Kiszka To: "Michael S. Tsirkin" , qemu-devel Date: Mon, 4 Jun 2012 10:52:21 +0200 Message-Id: X-Mailer: git-send-email 1.7.3.4 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 192.35.17.28 Cc: Alex Williamson Subject: [Qemu-devel] [PATCH 13/13] qdev-properties: Add pci-devaddr property 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 Add a property to receive a fully qualified PCI device address. Will be used by KVM device assignment. Signed-off-by: Jan Kiszka --- hw/qdev-properties.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 3 +++ 2 files changed, 51 insertions(+), 0 deletions(-) diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 32e41f1..6634f22 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -946,6 +946,54 @@ PropertyInfo qdev_prop_pci_devfn = { .max = 0xFFFFFFFFULL, }; +static void get_pci_devaddr(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + PCIDeviceAddress *addr = qdev_get_prop_ptr(dev, prop); + char buffer[10 + 3 + 1]; + char *p = buffer; + + snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%02x", + addr->domain, addr->bus, addr->slot, addr->function); + + visit_type_str(v, &p, name, errp); +} + +static void set_pci_devaddr(Object *obj, Visitor *v, void *opaque, + const char *name, Error **errp) +{ + DeviceState *dev = DEVICE(obj); + Property *prop = opaque; + PCIDeviceAddress *addr = qdev_get_prop_ptr(dev, prop); + Error *local_err = NULL; + char *str; + + if (dev->state != DEV_STATE_CREATED) { + error_set(errp, QERR_PERMISSION_DENIED); + return; + } + + visit_type_str(v, &str, name, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + if (qemu_parse_pci_devaddr(str, addr, + PCI_DEVADDR_WITH_DOM_BUS_OPT | + PCI_DEVADDR_WITH_FUNC) < 0) { + error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str); + } +} + +PropertyInfo qdev_prop_pci_devaddr = { + .name = "pci-devaddr", + .get = get_pci_devaddr, + .set = set_pci_devaddr, +}; + /* --- blocksize --- */ static void set_blocksize(Object *obj, Visitor *v, void *opaque, diff --git a/hw/qdev.h b/hw/qdev.h index 15acfca..d2c87a0 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -224,6 +224,7 @@ extern PropertyInfo qdev_prop_drive; extern PropertyInfo qdev_prop_netdev; extern PropertyInfo qdev_prop_vlan; extern PropertyInfo qdev_prop_pci_devfn; +extern PropertyInfo qdev_prop_pci_devaddr; extern PropertyInfo qdev_prop_blocksize; #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \ @@ -288,6 +289,8 @@ extern PropertyInfo qdev_prop_blocksize; LostTickPolicy) #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \ DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t) +#define DEFINE_PROP_PCI_DEVADDR(_n, _s, _f) \ + DEFINE_PROP(_n, _s, _f, qdev_prop_pci_devaddr, PCIDeviceAddress) #define DEFINE_PROP_END_OF_LIST() \ {}