From patchwork Thu Nov 22 16:35:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 10694467 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 077705A4 for ; Thu, 22 Nov 2018 16:37:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E38D32CD31 for ; Thu, 22 Nov 2018 16:37:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D52B62CD40; Thu, 22 Nov 2018 16:37:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 49E9D2CD31 for ; Thu, 22 Nov 2018 16:37:41 +0000 (UTC) Received: from localhost ([::1]:47621 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPrz2-0000N3-0Y for patchwork-qemu-devel@patchwork.kernel.org; Thu, 22 Nov 2018 11:37:40 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59405) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gPrxb-0007eS-Or for qemu-devel@nongnu.org; Thu, 22 Nov 2018 11:36:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gPrxW-0008TE-UB for qemu-devel@nongnu.org; Thu, 22 Nov 2018 11:36:11 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33652 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gPrxW-0008Sc-PW for qemu-devel@nongnu.org; Thu, 22 Nov 2018 11:36:06 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wAMGYGBR103188 for ; Thu, 22 Nov 2018 11:36:06 -0500 Received: from e06smtp02.uk.ibm.com (e06smtp02.uk.ibm.com [195.75.94.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 2nwya82388-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 22 Nov 2018 11:36:06 -0500 Received: from localhost by e06smtp02.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 22 Nov 2018 16:36:04 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp02.uk.ibm.com (192.168.101.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 22 Nov 2018 16:36:00 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wAMGZwjT58785912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 22 Nov 2018 16:35:59 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBEEC4C050; Thu, 22 Nov 2018 16:35:58 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 706074C046; Thu, 22 Nov 2018 16:35:58 +0000 (GMT) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.168]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 22 Nov 2018 16:35:58 +0000 (GMT) From: Pierre Morel To: borntraeger@de.ibm.com Date: Thu, 22 Nov 2018 17:35:51 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1542904555-1136-1-git-send-email-pmorel@linux.ibm.com> References: <1542904555-1136-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18112216-0008-0000-0000-00000296FEAB X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18112216-0009-0000-0000-000022013426 Message-Id: <1542904555-1136-3-git-send-email-pmorel@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-11-22_11:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1811220147 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2 2/6] s390x/vfio: ap: Use the APdevice as a child of the APBus 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: akrowiak@linux.ibm.com, peter.maydell@linaro.org, david@redhat.com, cohuck@redhat.com, qemu-devel@nongnu.org, agraf@suse.de, pasic@linux.ibm.com, eric.auger@redhat.com, qemu-s390x@nongnu.org, mst@redhat.com, pbonzini@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Two good reasons to use the base device as a child of the AP BUS: - We can easily find the device without traversing the qtree. - In case we have different APdevice instantiation, VFIO with interception or emulation, we will need the APDevice as a parent device. Signed-off-by: Pierre Morel --- hw/s390x/ap-device.c | 22 ++++++++++++++++++++++ hw/vfio/ap.c | 16 ++++++---------- include/hw/s390x/ap-device.h | 2 ++ 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/hw/s390x/ap-device.c b/hw/s390x/ap-device.c index f5ac8db..554d5aa 100644 --- a/hw/s390x/ap-device.c +++ b/hw/s390x/ap-device.c @@ -11,13 +11,35 @@ #include "qemu/module.h" #include "qapi/error.h" #include "hw/qdev.h" +#include "hw/s390x/ap-bridge.h" #include "hw/s390x/ap-device.h" +APDevice *s390_get_ap(void) +{ + static DeviceState *apb; + BusState *bus; + BusChild *child; + static APDevice *ap; + + if (ap) { + return ap; + } + + apb = s390_get_ap_bridge(); + /* We have only a single child on the BUS */ + bus = qdev_get_child_bus(apb, TYPE_AP_BUS); + child = QTAILQ_FIRST(&bus->children); + assert(child != NULL); + ap = DO_UPCAST(APDevice, parent_obj, child->child); + return ap; +} + static void ap_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); dc->desc = "AP device class"; + dc->bus_type = TYPE_AP_BUS; dc->hotpluggable = false; } diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c index 65de952..94e5a1a 100644 --- a/hw/vfio/ap.c +++ b/hw/vfio/ap.c @@ -35,9 +35,6 @@ typedef struct VFIOAPDevice { VFIODevice vdev; } VFIOAPDevice; -#define VFIO_AP_DEVICE(obj) \ - OBJECT_CHECK(VFIOAPDevice, (obj), VFIO_AP_DEVICE_TYPE) - static void vfio_ap_compute_needs_reset(VFIODevice *vdev) { vdev->needs_reset = false; @@ -90,8 +87,8 @@ static void vfio_ap_realize(DeviceState *dev, Error **errp) char *mdevid; Error *local_err = NULL; VFIOGroup *vfio_group; - APDevice *apdev = AP_DEVICE(dev); - VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev); + APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev); + VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev); vfio_group = vfio_ap_get_group(vapdev, &local_err); if (!vfio_group) { @@ -120,8 +117,8 @@ out_err: static void vfio_ap_unrealize(DeviceState *dev, Error **errp) { - APDevice *apdev = AP_DEVICE(dev); - VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev); + APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev); + VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev); VFIOGroup *group = vapdev->vdev.group; vfio_ap_put_device(vapdev); @@ -136,8 +133,8 @@ static Property vfio_ap_properties[] = { static void vfio_ap_reset(DeviceState *dev) { int ret; - APDevice *apdev = AP_DEVICE(dev); - VFIOAPDevice *vapdev = VFIO_AP_DEVICE(apdev); + APDevice *apdev = DO_UPCAST(APDevice, parent_obj, dev); + VFIOAPDevice *vapdev = DO_UPCAST(VFIOAPDevice, apdev, apdev); ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET); if (ret) { @@ -163,7 +160,6 @@ static void vfio_ap_class_init(ObjectClass *klass, void *data) dc->unrealize = vfio_ap_unrealize; dc->hotpluggable = false; dc->reset = vfio_ap_reset; - dc->bus_type = TYPE_AP_BUS; } static const TypeInfo vfio_ap_info = { diff --git a/include/hw/s390x/ap-device.h b/include/hw/s390x/ap-device.h index 765e908..5f3c840 100644 --- a/include/hw/s390x/ap-device.h +++ b/include/hw/s390x/ap-device.h @@ -19,4 +19,6 @@ typedef struct APDevice { #define AP_DEVICE(obj) \ OBJECT_CHECK(APDevice, (obj), AP_DEVICE_TYPE) +APDevice *s390_get_ap(void); + #endif /* HW_S390X_AP_DEVICE_H */