From nobody Fri Dec 19 16:59:29 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1594246602; cv=none; d=zohomail.com; s=zohoarc; b=ZMXzRSy0s6zIPWuHa+Uo+uGqhwznejbEo0Zcp1Muxx7QK4CTzy16asV7d4fkKaRgMtpOIYk68eZiGhZ56XQap4EA81+38EwE/7PYnnAsyD4lfp4Azn43m9IduoyvdbJZiw/OxVJ8pFR2cse9OgiZhw0/LkRML5gfen+pYZIlYoM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594246602; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=v4uhjNGnAQMFkLG05VfEYjwnS7zj/yCgK71U9QUEwOY=; b=TnwH8gepAtVCIV6vdbOgd5zu4w4SKMiQ1Ddyt6Rove8lsrhyTTrNXX2A6TrPNlumFtkYdM7gwVG3CnzeVpWbJRgUVNI6FxBuj+vO/p8ejML12Y68xHtGXhxq2r7s/qSM6v0xFmpmMeTNoqtTbgdWMNv42O2qHB1zLzUecoUNhJo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1594246602475147.62568363635205; Wed, 8 Jul 2020 15:16:42 -0700 (PDT) Received: from localhost ([::1]:54038 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jtIMr-0007gy-3b for importer@patchew.org; Wed, 08 Jul 2020 18:16:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41010) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jtI15-00074T-2h for qemu-devel@nongnu.org; Wed, 08 Jul 2020 17:54:11 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:25537 helo=us-smtp-delivery-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jtI12-0005PL-9D for qemu-devel@nongnu.org; Wed, 08 Jul 2020 17:54:10 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-105-BxonDbzXM-6hBoX93yWc8g-1; Wed, 08 Jul 2020 14:52:29 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4C716107ACF3; Wed, 8 Jul 2020 18:52:28 +0000 (UTC) Received: from t480s.redhat.com (ovpn-113-117.ams2.redhat.com [10.36.113.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24DC25D9F3; Wed, 8 Jul 2020 18:52:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594245247; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v4uhjNGnAQMFkLG05VfEYjwnS7zj/yCgK71U9QUEwOY=; b=LM44NXiHrRtUn7e9Oumz+tqQv3gqRROUWTYbv/MTHZWbs/oapYVsmSxxVo6RlQ7MYo8jZP cjqh+WyGtc3dY6ycP+SG8fSh/XDgDGnGOiWJFibfJv2JXzLfLFgyt6FsQzTZKMAAdVNRnz BYy9CDalmHRxo4KdXtNWfmpo1c+Sq+k= X-MC-Unique: BxonDbzXM-6hBoX93yWc8g-1 From: David Hildenbrand To: qemu-devel@nongnu.org Subject: [PATCH RFC 4/5] s390x: implement virtio-mem-ccw Date: Wed, 8 Jul 2020 20:51:34 +0200 Message-Id: <20200708185135.46694-5-david@redhat.com> In-Reply-To: <20200708185135.46694-1-david@redhat.com> References: <20200708185135.46694-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.61; envelope-from=david@redhat.com; helo=us-smtp-delivery-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/07/07 17:25:10 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -40 X-Spam_score: -4.1 X-Spam_bar: ---- X-Spam_report: (-4.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-1, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Janosch Frank , "Michael S . Tsirkin" , Cornelia Huck , Heiko Carstens , Halil Pasic , Christian Borntraeger , qemu-s390x@nongnu.org, David Hildenbrand , Claudio Imbrenda , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Add a proper CCW proxy device, similar to the PCI variant. Signed-off-by: David Hildenbrand --- hw/s390x/virtio-ccw-mem.c | 165 ++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 13 +++ 2 files changed, 178 insertions(+) create mode 100644 hw/s390x/virtio-ccw-mem.c diff --git a/hw/s390x/virtio-ccw-mem.c b/hw/s390x/virtio-ccw-mem.c new file mode 100644 index 0000000000..ae856d7ad4 --- /dev/null +++ b/hw/s390x/virtio-ccw-mem.c @@ -0,0 +1,165 @@ +/* + * Virtio MEM CCW device + * + * Copyright (C) 2020 Red Hat, Inc. + * + * Authors: + * David Hildenbrand + * + * This work is licensed under the terms of the GNU GPL, version 2. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/virtio.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "virtio-ccw.h" +#include "hw/mem/memory-device.h" +#include "qapi/qapi-events-misc.h" + +static void virtio_ccw_mem_realize(VirtioCcwDevice *ccw_dev, Error **errp) +{ + VirtIOMEMCcw *ccw_mem =3D VIRTIO_MEM_CCW(ccw_dev); + DeviceState *vdev =3D DEVICE(&ccw_mem->vdev); + + qdev_realize(vdev, BUS(&ccw_dev->bus), errp); +} + +static void virtio_ccw_mem_set_addr(MemoryDeviceState *md, uint64_t addr, + Error **errp) +{ + object_property_set_uint(OBJECT(md), addr, VIRTIO_MEM_ADDR_PROP, errp); +} + +static uint64_t virtio_ccw_mem_get_addr(const MemoryDeviceState *md) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_ADDR_PROP, + &error_abort); +} + +static MemoryRegion *virtio_ccw_mem_get_memory_region(MemoryDeviceState *m= d, + Error **errp) +{ + VirtIOMEMCcw *ccw_mem =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D VIRTIO_MEM(&ccw_mem->vdev); + VirtIOMEMClass *vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + + return vmc->get_memory_region(vmem, errp); +} + +static uint64_t virtio_ccw_mem_get_plugged_size(const MemoryDeviceState *m= d, + Error **errp) +{ + return object_property_get_uint(OBJECT(md), VIRTIO_MEM_SIZE_PROP, + errp); +} + +static void virtio_ccw_mem_fill_device_info(const MemoryDeviceState *md, + MemoryDeviceInfo *info) +{ + VirtioMEMDeviceInfo *vi =3D g_new0(VirtioMEMDeviceInfo, 1); + VirtIOMEMCcw *ccw_mem =3D VIRTIO_MEM_CCW(md); + VirtIOMEM *vmem =3D VIRTIO_MEM(&ccw_mem->vdev); + VirtIOMEMClass *vpc =3D VIRTIO_MEM_GET_CLASS(vmem); + DeviceState *dev =3D DEVICE(md); + + if (dev->id) { + vi->has_id =3D true; + vi->id =3D g_strdup(dev->id); + } + + /* let the real device handle everything else */ + vpc->fill_device_info(vmem, vi); + + info->u.virtio_mem.data =3D vi; + info->type =3D MEMORY_DEVICE_INFO_KIND_VIRTIO_MEM; +} + +static void virtio_ccw_mem_size_change_notify(Notifier *notifier, void *da= ta) +{ + VirtIOMEMCcw *ccw_mem =3D container_of(notifier, VirtIOMEMCcw, + size_change_notifier); + DeviceState *dev =3D DEVICE(ccw_mem); + const uint64_t * const size_p =3D data; + const char *id =3D NULL; + + if (dev->id) { + id =3D g_strdup(dev->id); + } + + qapi_event_send_memory_device_size_change(!!id, id, *size_p); +} + +static void virtio_ccw_mem_instance_init(Object *obj) +{ + VirtIOMEMCcw *ccw_mem =3D VIRTIO_MEM_CCW(obj); + VirtIOMEMClass *vmc; + VirtIOMEM *vmem; + + virtio_instance_init_common(obj, &ccw_mem->vdev, sizeof(ccw_mem->vdev), + TYPE_VIRTIO_MEM); + + ccw_mem->size_change_notifier.notify =3D virtio_ccw_mem_size_change_no= tify; + vmem =3D VIRTIO_MEM(&ccw_mem->vdev); + vmc =3D VIRTIO_MEM_GET_CLASS(vmem); + /* + * We never remove the notifier again, as we expect both devices to + * disappear at the same time. + */ + vmc->add_size_change_notifier(vmem, &ccw_mem->size_change_notifier); + + object_property_add_alias(obj, VIRTIO_MEM_BLOCK_SIZE_PROP, + OBJECT(&ccw_mem->vdev), + VIRTIO_MEM_BLOCK_SIZE_PROP); + object_property_add_alias(obj, VIRTIO_MEM_SIZE_PROP, OBJECT(&ccw_mem->= vdev), + VIRTIO_MEM_SIZE_PROP); + object_property_add_alias(obj, VIRTIO_MEM_REQUESTED_SIZE_PROP, + OBJECT(&ccw_mem->vdev), + VIRTIO_MEM_REQUESTED_SIZE_PROP); +} + +static Property virtio_ccw_mem_properties[] =3D { + DEFINE_PROP_BIT("ioeventfd", VirtioCcwDevice, flags, + VIRTIO_CCW_FLAG_USE_IOEVENTFD_BIT, true), + DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, + VIRTIO_CCW_MAX_REV), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_ccw_mem_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtIOCCWDeviceClass *k =3D VIRTIO_CCW_DEVICE_CLASS(klass); + MemoryDeviceClass *mdc =3D MEMORY_DEVICE_CLASS(klass); + + k->realize =3D virtio_ccw_mem_realize; + device_class_set_props(dc, virtio_ccw_mem_properties); + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + + mdc->get_addr =3D virtio_ccw_mem_get_addr; + mdc->set_addr =3D virtio_ccw_mem_set_addr; + mdc->get_plugged_size =3D virtio_ccw_mem_get_plugged_size; + mdc->get_memory_region =3D virtio_ccw_mem_get_memory_region; + mdc->fill_device_info =3D virtio_ccw_mem_fill_device_info; +} + +static const TypeInfo virtio_ccw_mem =3D { + .name =3D TYPE_VIRTIO_MEM_CCW, + .parent =3D TYPE_VIRTIO_CCW_DEVICE, + .instance_size =3D sizeof(VirtIOMEMCcw), + .instance_init =3D virtio_ccw_mem_instance_init, + .class_init =3D virtio_ccw_mem_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_MEMORY_DEVICE }, + { } + }, +}; + +static void virtio_ccw_mem_register(void) +{ + type_register_static(&virtio_ccw_mem); +} + +type_init(virtio_ccw_mem_register) diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h index c0e3355248..77aa87c41f 100644 --- a/hw/s390x/virtio-ccw.h +++ b/hw/s390x/virtio-ccw.h @@ -29,6 +29,7 @@ #endif /* CONFIG_VHOST_VSOCK */ #include "hw/virtio/virtio-gpu.h" #include "hw/virtio/virtio-input.h" +#include "hw/virtio/virtio-mem.h" =20 #include "hw/s390x/s390_flic.h" #include "hw/s390x/css.h" @@ -256,4 +257,16 @@ typedef struct VirtIOInputHIDCcw { VirtIOInputHID vdev; } VirtIOInputHIDCcw; =20 +/* virtio-mem-ccw */ + +#define TYPE_VIRTIO_MEM_CCW "virtio-mem-ccw" +#define VIRTIO_MEM_CCW(obj) \ + OBJECT_CHECK(VirtIOMEMCcw, (obj), TYPE_VIRTIO_MEM_CCW) + +typedef struct VirtIOMEMCcw { + VirtioCcwDevice parent_obj; + VirtIOMEM vdev; + Notifier size_change_notifier; +} VirtIOMEMCcw; + #endif --=20 2.26.2