From patchwork Mon Aug 14 21:57:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Habkost X-Patchwork-Id: 801345 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) 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 3xWV0T1yy0z9sRq for ; Tue, 15 Aug 2017 08:00:25 +1000 (AEST) Received: from localhost ([::1]:58699 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhNPK-0002a0-R5 for incoming@patchwork.ozlabs.org; Mon, 14 Aug 2017 18:00:22 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43175) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dhNOV-0002Xu-IR for qemu-devel@nongnu.org; Mon, 14 Aug 2017 17:59:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dhNOQ-0002vx-Re for qemu-devel@nongnu.org; Mon, 14 Aug 2017 17:59:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:9513) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dhNOQ-0002vX-Iq for qemu-devel@nongnu.org; Mon, 14 Aug 2017 17:59:26 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B545C04D938 for ; Mon, 14 Aug 2017 21:59:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 7B545C04D938 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=ehabkost@redhat.com Received: from localhost (ovpn-116-38.gru2.redhat.com [10.97.116.38]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD38460BEC; Mon, 14 Aug 2017 21:59:17 +0000 (UTC) From: Eduardo Habkost To: Eric Blake , qemu-devel@nongnu.org, Markus Armbruster , "Michael S. Tsirkin" , Marcel Apfelbaum , Laine Stump Date: Mon, 14 Aug 2017 18:57:45 -0300 Message-Id: <20170814215748.5158-11-ehabkost@redhat.com> In-Reply-To: <20170814215748.5158-1-ehabkost@redhat.com> References: <20170814215748.5158-1-ehabkost@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Mon, 14 Aug 2017 21:59:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [RFC v4 10/13] pci: device-number & function properties 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: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" The "addr" property on PCI devices has some magic for parsing it as a single PCI device number (called "slot" internally), or a "." string. Add simple integer properties that can represent the device address with no special parsing. Cc: "Michael S. Tsirkin" Cc: Marcel Apfelbaum Signed-off-by: Eduardo Habkost --- hw/pci/pci.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index ead9cbf..5753af3 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -41,6 +41,7 @@ #include "hw/hotplug.h" #include "hw/boards.h" #include "qemu/cutils.h" +#include "qapi-visit.h" //#define DEBUG_PCI #ifdef DEBUG_PCI @@ -2504,6 +2505,55 @@ MemoryRegion *pci_address_space_io(PCIDevice *dev) return dev->bus->address_space_io; } +static void pci_device_get_devnr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCIDevice *dev = PCI_DEVICE(obj); + uint32_t devnr = PCI_SLOT(dev->devfn); + + visit_type_uint32(v, "device-number", &devnr, errp); +} + +static void pci_device_set_devnr(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCIDevice *dev = PCI_DEVICE(obj); + uint32_t devnr; + Error *local_err = NULL; + + visit_type_uint32(v, "device-number", &devnr, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + + dev->devfn = PCI_DEVFN(devnr, PCI_FUNC(dev->devfn)); +} + +static void pci_device_get_function(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCIDevice *dev = PCI_DEVICE(obj); + uint32_t function = PCI_FUNC(dev->devfn); + + visit_type_uint32(v, "function", &function, errp); +} + +static void pci_device_set_function(Object *obj, Visitor *v, const char *name, + void *opaque, Error **errp) +{ + PCIDevice *dev = PCI_DEVICE(obj); + uint32_t function; + Error *local_err = NULL; + + visit_type_uint32(v, "function", &function, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } + dev->devfn = PCI_DEVFN(PCI_SLOT(dev->devfn), function); +} + static void pci_device_class_init(ObjectClass *klass, void *data) { DeviceClass *k = DEVICE_CLASS(klass); @@ -2514,6 +2564,19 @@ static void pci_device_class_init(ObjectClass *klass, void *data) k->bus_type = TYPE_PCI_BUS; k->props = pci_props; pc->realize = pci_default_realize; + + /* Internally, bits 3:8 of devfn are called "slots", but: + * - they can be confused with physical slot numbers; + * - TYPE_PCIE_SLOT objects already have a "slot" property. + * So we use the terminology used in the PCI specifiction: + * "device number". + */ + object_class_property_add(klass, "device-number", "uint32", + pci_device_get_devnr, pci_device_set_devnr, + NULL, NULL, &error_abort); + object_class_property_add(klass, "function", "uint32", + pci_device_get_function, pci_device_set_function, + NULL, NULL, &error_abort); } AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)