From nobody Fri May 3 21:05:30 2024 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=linux.ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630061643523418.8594451994468; Fri, 27 Aug 2021 03:54:03 -0700 (PDT) Received: from localhost ([::1]:47846 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJZUo-0006G2-72 for importer@patchew.org; Fri, 27 Aug 2021 06:54:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60866) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJZRz-0001zA-TW; Fri, 27 Aug 2021 06:51:07 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:41702) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJZRv-000645-3u; Fri, 27 Aug 2021 06:51:07 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RAYeex021253; Fri, 27 Aug 2021 06:50:59 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apwpm9hea-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:50:59 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RAnEfw081251; Fri, 27 Aug 2021 06:50:59 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apwpm9hdj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:50:59 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RAlj8X004901; Fri, 27 Aug 2021 10:50:56 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3ajs493bf0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:50:56 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAoqXE51380710 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:50:52 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1E8011C08D; Fri, 27 Aug 2021 10:50:52 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5063811C066; Fri, 27 Aug 2021 10:50:52 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:50:52 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=7mbDcDn+MlPyFLz/8Gszh7vWTzqiYc3M9dMMY/Fc+ig=; b=fZ4AJbcKXSTkNfDHLXtC1ebyUL6fUHOxkd17ZzsG7FeoEbsXR0NIiygr44HqY1VwHzbv sauMnB3jP5pC3DL94ZAbmnqjy2m2rxECXT9BnCdSr1DKDs8VTvN7iv0TJQdoUV5yuNfC /JzqyB2+RGuT9W8dwDBD5GlzM3zTp+l+/llYL8P9ORxt5IWsyTePQV1ty1WhQPW8SiE0 vyq1cLB6JgQhx2W3wvNH9LsMZYGyVlt/OJPk/A3cF41f0oXPS5m22/t15V4R2gu+/ByX wwxPvTewkKD5Id+O5CGZesaBu1M1tvliFqFyqMAemy48WHqBFLqFLR10sEX+g1/2ywRW Ig== From: Pierre Morel To: kvm@vger.kernel.org Subject: [PATCH 1/2] virtio: Linux: Update of virtio_ids Date: Fri, 27 Aug 2021 12:50:49 +0200 Message-Id: <1630061450-18744-2-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630061450-18744-1-git-send-email-pmorel@linux.ibm.com> References: <1630061450-18744-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: LQoShVuGnUdr_j1VKVidlSTTAB-dPrZS X-Proofpoint-GUID: xqCbOqo5rabwHEShRRQ5s_gqmyAbqChF X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-08-27_03:2021-08-26, 2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 mlxscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 suspectscore=0 adultscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270066 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=148.163.156.1; envelope-from=pmorel@linux.ibm.com; helo=mx0a-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: thuth@redhat.com, frankja@linux.ibm.com, david@redhat.com, cohuck@redhat.com, richard.henderson@linaro.org, drjones@redhat.com, qemu-devel@nongnu.org, pasic@linux.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, mst@redhat.com, imbrenda@linux.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1630061644086100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The virtio IDs depends on Linux tree... Signed-off-by: Pierre Morel --- include/standard-headers/linux/virtio_ids.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/standard-headers/linux/virtio_ids.h b/include/standard= -headers/linux/virtio_ids.h index 4fe842c3a3..bf61801eeb 100644 --- a/include/standard-headers/linux/virtio_ids.h +++ b/include/standard-headers/linux/virtio_ids.h @@ -55,6 +55,7 @@ #define VIRTIO_ID_FS 26 /* virtio filesystem */ #define VIRTIO_ID_PMEM 27 /* virtio pmem */ #define VIRTIO_ID_MAC80211_HWSIM 29 /* virtio mac80211-hwsim */ +#define VIRTIO_ID_PONG 30 /* virtio pong */ #define VIRTIO_ID_BT 40 /* virtio bluetooth */ =20 #endif /* _LINUX_VIRTIO_IDS_H */ --=20 2.25.1 From nobody Fri May 3 21:05:30 2024 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=linux.ibm.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630061555757981.1615305366627; Fri, 27 Aug 2021 03:52:35 -0700 (PDT) Received: from localhost ([::1]:43786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJZTO-0003XE-9c for importer@patchew.org; Fri, 27 Aug 2021 06:52:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60840) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJZRy-0001ym-5p; Fri, 27 Aug 2021 06:51:06 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:15822) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJZRt-00063c-TT; Fri, 27 Aug 2021 06:51:05 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RAXlgd181479; Fri, 27 Aug 2021 06:51:00 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apwhkhv7f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:51:00 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RAXqFV182147; Fri, 27 Aug 2021 06:50:59 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apwhkhv6m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:50:59 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RAlmPe004909; Fri, 27 Aug 2021 10:50:57 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04ams.nl.ibm.com with ESMTP id 3ajs493bf1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:50:57 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAor6q47251752 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:50:53 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5E08411C080; Fri, 27 Aug 2021 10:50:53 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D75A211C083; Fri, 27 Aug 2021 10:50:52 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:50:52 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=sGO8g0KMsH6opJeOVtLKteOeyxh9rwi8TyZ1xjiJRLs=; b=NYGZtX/zgaZ7geFy/sNx31bMv4AZET7nsQqRVhh74+f0zf5OTfNhft0ccqoitaEq/Ie/ AZzRd4HaL69vJc1FEYLwinOzYMyxQTSZryimNomjFmtWxmGfH/LXVIXWzH+CqismB40W tmfGIolJT9McGgrlP4Ev7B4AjoN4YG4+AKgRGesqcZdTS3Z7pbqd/VK25NmxxK30262r vbLQh7NE1A0pjrx/goemX4HnivTaqCiwcDeukpkZ413EK3GwHxEKMVJ3p4U1V20OcsB4 WBFfcw8h9RIQ3nuGE6OD8GllcFB/ulSDi6v6OisO8iDkiyuEnSWML46m6BVkdYwBcbJX yw== From: Pierre Morel To: kvm@vger.kernel.org Subject: [PATCH 2/2] s390x: ccw: A simple test device for virtio CCW Date: Fri, 27 Aug 2021 12:50:50 +0200 Message-Id: <1630061450-18744-3-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630061450-18744-1-git-send-email-pmorel@linux.ibm.com> References: <1630061450-18744-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 1I3366asKwpTgqmLvGB7k3pTnXNdlUsY X-Proofpoint-ORIG-GUID: XWlvv3Mh8leEylLEUqcjgXzmww1Boo97 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-08-27_03:2021-08-26, 2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 impostorscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 suspectscore=0 mlxscore=0 bulkscore=0 malwarescore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270066 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=148.163.158.5; envelope-from=pmorel@linux.ibm.com; helo=mx0b-001b2d01.pphosted.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham 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: thuth@redhat.com, frankja@linux.ibm.com, david@redhat.com, cohuck@redhat.com, richard.henderson@linaro.org, drjones@redhat.com, qemu-devel@nongnu.org, pasic@linux.ibm.com, borntraeger@de.ibm.com, qemu-s390x@nongnu.org, mst@redhat.com, imbrenda@linux.ibm.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1630061556636100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This VIRTIO device receives data on its input channel and emit a simple checksum for these data on its output channel. This allows a simple VIRTIO device driver to check the VIRTIO initialization and various data transfer. Signed-off-by: Pierre Morel --- hw/s390x/meson.build | 1 + hw/s390x/virtio-ccw-pong.c | 66 +++++++++++++ hw/s390x/virtio-ccw.h | 13 +++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/virtio-pong.c | 161 ++++++++++++++++++++++++++++++++ include/hw/virtio/virtio-pong.h | 34 +++++++ 7 files changed, 281 insertions(+) create mode 100644 hw/s390x/virtio-ccw-pong.c create mode 100644 hw/virtio/virtio-pong.c create mode 100644 include/hw/virtio/virtio-pong.h diff --git a/hw/s390x/meson.build b/hw/s390x/meson.build index 74678861cf..e9edf1d196 100644 --- a/hw/s390x/meson.build +++ b/hw/s390x/meson.build @@ -18,6 +18,7 @@ s390x_ss.add(files( 'sclpcpu.c', 'sclpquiesce.c', 'tod.c', + 'virtio-ccw-pong.c', )) s390x_ss.add(when: 'CONFIG_KVM', if_true: files( 'tod-kvm.c', diff --git a/hw/s390x/virtio-ccw-pong.c b/hw/s390x/virtio-ccw-pong.c new file mode 100644 index 0000000000..c4e343b776 --- /dev/null +++ b/hw/s390x/virtio-ccw-pong.c @@ -0,0 +1,66 @@ +/* + * virtio ccw PONG device + * + * Copyright 2020, IBM Corp. + * Author(s): Pierre Morel + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. 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" + +static void virtio_ccw_pong_realize(VirtioCcwDevice *ccw_dev, Error **errp) +{ + VirtIOPONGCcw *dev =3D VIRTIO_PONG_CCW(ccw_dev); + DeviceState *vdev =3D DEVICE(&dev->vdev); + + if (!qdev_realize(vdev, BUS(&ccw_dev->bus), errp)) { + return; + } +} + +static void virtio_ccw_pong_instance_init(Object *obj) +{ + VirtIOPONGCcw *dev =3D VIRTIO_PONG_CCW(obj); + + virtio_instance_init_common(obj, &dev->vdev, sizeof(dev->vdev), + TYPE_VIRTIO_PONG); +} + +static Property virtio_ccw_pong_properties[] =3D { + DEFINE_PROP_UINT32("max_revision", VirtioCcwDevice, max_rev, + VIRTIO_CCW_MAX_REV), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_ccw_pong_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtIOCCWDeviceClass *k =3D VIRTIO_CCW_DEVICE_CLASS(klass); + + k->realize =3D virtio_ccw_pong_realize; + device_class_set_props(dc, virtio_ccw_pong_properties); + set_bit(DEVICE_CATEGORY_MISC, dc->categories); +} + +static const TypeInfo virtio_ccw_pong =3D { + .name =3D TYPE_VIRTIO_PONG_CCW, + .parent =3D TYPE_VIRTIO_CCW_DEVICE, + .instance_size =3D sizeof(VirtIOPONGCcw), + .instance_init =3D virtio_ccw_pong_instance_init, + .class_init =3D virtio_ccw_pong_class_init, +}; + +static void virtio_ccw_pong_register(void) +{ + type_register_static(&virtio_ccw_pong); +} + +type_init(virtio_ccw_pong_register) diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h index 0168232e3b..f718ad32c2 100644 --- a/hw/s390x/virtio-ccw.h +++ b/hw/s390x/virtio-ccw.h @@ -31,6 +31,8 @@ #include "hw/virtio/virtio-gpu.h" #include "hw/virtio/virtio-input.h" =20 +#include "hw/virtio/virtio-pong.h" + #include "hw/s390x/s390_flic.h" #include "hw/s390x/css.h" #include "ccw-device.h" @@ -176,6 +178,17 @@ struct VirtIORNGCcw { VirtIORNG vdev; }; =20 +/* virtio-pong-ccw */ + +#define TYPE_VIRTIO_PONG_CCW "virtio-pong-ccw" +#define VIRTIO_PONG_CCW(obj) \ + OBJECT_CHECK(VirtIOPONGCcw, (obj), TYPE_VIRTIO_PONG_CCW) + +typedef struct VirtIOPONGCcw { + VirtioCcwDevice parent_obj; + VirtIOPONG vdev; +} VirtIOPONGCcw; + /* virtio-crypto-ccw */ =20 #define TYPE_VIRTIO_CRYPTO_CCW "virtio-crypto-ccw" diff --git a/hw/virtio/Kconfig b/hw/virtio/Kconfig index 35ab45e209..f73c87d953 100644 --- a/hw/virtio/Kconfig +++ b/hw/virtio/Kconfig @@ -4,6 +4,11 @@ config VHOST config VIRTIO bool =20 +config VIRTIO_PONG + bool + default y + depends on VIRTIO + config VIRTIO_RNG bool default y diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index bc352a6009..1ba4dcc454 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -6,6 +6,7 @@ softmmu_virtio_ss.add(when: 'CONFIG_VHOST', if_false: files= ('vhost-stub.c')) =20 softmmu_ss.add_all(when: 'CONFIG_VIRTIO', if_true: softmmu_virtio_ss) softmmu_ss.add(when: 'CONFIG_VIRTIO', if_false: files('vhost-stub.c')) +softmmu_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-pong.c')) =20 softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) =20 diff --git a/hw/virtio/virtio-pong.c b/hw/virtio/virtio-pong.c new file mode 100644 index 0000000000..c15100dd43 --- /dev/null +++ b/hw/virtio/virtio-pong.c @@ -0,0 +1,161 @@ +/* + * A virtio device implementing a PONG device + * + * Copyright 2020 IBM. + * Copyright 2020 Pierre Morel + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/iov.h" +#include "qemu/module.h" +#include "sysemu/runstate.h" +#include "hw/virtio/virtio.h" +#include "hw/qdev-properties.h" +#include "standard-headers/linux/virtio_ids.h" +#include "hw/virtio/virtio-pong.h" +#include "qom/object_interfaces.h" +#include "trace.h" +#include "qemu/error-report.h" + +static char *buffer; +static unsigned int cksum; + +static unsigned int simple_checksum(char *buf, unsigned long len) +{ + unsigned int sum =3D 0; + + while (len--) { + sum +=3D *buf * *buf + 7 * *buf + 3; + buf++; + } + return sum; +} + +static void handle_output(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtIOPONG *vpong =3D VIRTIO_PONG(vdev); + VirtQueueElement *elem; + + if (!virtio_queue_ready(vq)) { + return; + } + if (virtio_queue_empty(vq)) { + return; + } + + while ((elem =3D virtqueue_pop(vq, sizeof(*elem))) !=3D NULL) { + buffer =3D g_malloc(elem->out_sg->iov_len); + iov_to_buf(elem->out_sg, elem->out_num, 0, buffer, + elem->out_sg->iov_len); + + if (vpong->cksum) { + cksum =3D simple_checksum(buffer, elem->out_sg->iov_len); + } + virtqueue_push(vq, elem, 0); + g_free(buffer); + g_free(elem); + } + + virtio_notify(vdev, vq); +} + +static void handle_input(VirtIODevice *vdev, VirtQueue *vq) +{ + VirtQueueElement *elem; + + if (!virtio_queue_ready(vq)) { + return; + } + if (virtio_queue_empty(vq)) { + return; + } + + while ((elem =3D virtqueue_pop(vq, sizeof(*elem))) !=3D NULL) { + int len =3D 0; + + len =3D iov_from_buf(elem->out_sg, elem->out_num, + 0, &cksum, sizeof(cksum)); + + virtqueue_push(vq, elem, len); + g_free(elem); + } + + virtio_notify(vdev, vq); + +} + +static uint64_t get_features(VirtIODevice *vdev, uint64_t f, Error **errp) +{ + VirtIOPONG *vpong =3D VIRTIO_PONG(vdev); + + if (vpong->cksum) { + f |=3D 1ull << VIRTIO_PONG_F_CKSUM; + } + return f; +} + +static void virtio_pong_set_status(VirtIODevice *vdev, uint8_t status) +{ + if (!vdev->vm_running) { + return; + } + vdev->status =3D status; +} + +static void virtio_pong_device_realize(DeviceState *dev, Error **errp) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIOPONG *vpong =3D VIRTIO_PONG(dev); + + virtio_init(vdev, "virtio-pong", VIRTIO_ID_PONG, 0); + + vpong->vq_in =3D virtio_add_queue(vdev, 8, handle_input); + vpong->vq_out =3D virtio_add_queue(vdev, 8, handle_output); +} + +static void virtio_pong_device_unrealize(DeviceState *dev) +{ + VirtIODevice *vdev =3D VIRTIO_DEVICE(dev); + VirtIOPONG *vpong =3D VIRTIO_PONG(dev); + + qemu_del_vm_change_state_handler(vpong->vmstate); + virtio_del_queue(vdev, 0); + virtio_cleanup(vdev); +} + +static Property virtio_pong_properties[] =3D { + DEFINE_PROP_UINT64("cksum", VirtIOPONG, cksum, 1), + DEFINE_PROP_END_OF_LIST(), +}; + +static void virtio_pong_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_CLASS(klass); + + device_class_set_props(dc, virtio_pong_properties); + set_bit(DEVICE_CATEGORY_MISC, dc->categories); + vdc->realize =3D virtio_pong_device_realize; + vdc->unrealize =3D virtio_pong_device_unrealize; + vdc->get_features =3D get_features; + vdc->set_status =3D virtio_pong_set_status; +} + +static const TypeInfo virtio_pong_info =3D { + .name =3D TYPE_VIRTIO_PONG, + .parent =3D TYPE_VIRTIO_DEVICE, + .instance_size =3D sizeof(VirtIOPONG), + .class_init =3D virtio_pong_class_init, +}; + +static void virtio_register_types(void) +{ + type_register_static(&virtio_pong_info); +} + +type_init(virtio_register_types) diff --git a/include/hw/virtio/virtio-pong.h b/include/hw/virtio/virtio-pon= g.h new file mode 100644 index 0000000000..ff44f2fead --- /dev/null +++ b/include/hw/virtio/virtio-pong.h @@ -0,0 +1,34 @@ +/* + * Virtio PONG Support + * + * Copyright IBM 2020 + * Copyright Pierre Morel + * + * This work is licensed under the terms of the GNU GPL, version 2 or + * (at your option) any later version. See the COPYING file in the + * top-level directory. + */ + +#ifndef QEMU_VIRTIO_PONG_H +#define QEMU_VIRTIO_PONG_H + +#include "hw/virtio/virtio.h" + +#define TYPE_VIRTIO_PONG "virtio-pong-device" +#define VIRTIO_PONG(obj) \ + OBJECT_CHECK(VirtIOPONG, (obj), TYPE_VIRTIO_PONG) +#define VIRTIO_PONG_GET_PARENT_CLASS(obj) \ + OBJECT_GET_PARENT_CLASS(obj, TYPE_VIRTIO_PONG) + +typedef struct VirtIOPONG { + VirtIODevice parent_obj; + VirtQueue *vq_in; + VirtQueue *vq_out; + VMChangeStateEntry *vmstate; + uint64_t cksum; +} VirtIOPONG; + +/* Feature bits */ +#define VIRTIO_PONG_F_CKSUM 1 /* Indicates pong using checksum */ + +#endif --=20 2.25.1