From patchwork Tue Dec 13 11:17:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= X-Patchwork-Id: 633502 Delivered-To: patch@linaro.org Received: by 2002:a17:522:c983:b0:460:3032:e3c4 with SMTP id kr3csp3012742pvb; Tue, 13 Dec 2022 03:19:41 -0800 (PST) X-Google-Smtp-Source: AA0mqf59zOzMFd7iHmJwdIQDrVpvqSXvp5cYEaabT3eo3T6/u2fc6hrEex67klt3HhQfvckaNjMG X-Received: by 2002:a05:622a:4c0a:b0:3a8:26b1:336a with SMTP id ey10-20020a05622a4c0a00b003a826b1336amr1240155qtb.17.1670930380898; Tue, 13 Dec 2022 03:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670930380; cv=none; d=google.com; s=arc-20160816; b=j0EQ8Tu3/mbbEum3Hbi37bbASOML7EGTMGRTy/IEfoCdZQiomAvNNp4w62h8w6APi7 K7JJdNqBAUDfc7SNVzUup13FmEpYQOrKFEDs6v2b8MGV5oz4a/8teX/zYTGOYj7Ssecb 6EDbPZNmM7iJWqoac3xLL3ciPCHjfySjdgmf5h+tpMcopSzeCjsEHMsqGvGmCEopEQV1 8AxWK5fOz2/BYQnirDB+rJi8tW5E1NvFSjna7ylqP8I19paJRFPr3jhR43cJZQnIxqvU 9/VeDfjGgH/2pxnWUJFzYK6krqWBuxUNOWFPRnZ3me5gUcF7ZfG0dnU8KfJG8Uy493r0 QNeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=20qiCSyBuRvA2agy+mA00cXv9PUs69i2cg2fmTzeXmk=; b=SF7U80LVGA9phYxn/KEeE0a0kXfV4z+dADsy+WRhTYeS/0OuYPUvvPafb7qIIAkmBK SqVktTaGhfQsPuvO3pVlKbElLo5b2WOOleChQVjmBg5hRRQIZruMBmebaKLrp8Oko6mA MxXT/DPPIFxOsC6KxZAr+G3+VgPDNcafxGqyjEeJ5E0cXbultHcTqHRXBjUBg6OIPaF+ 82hATWDqGb10h1PbmZn6NiF8sS3h5hoOt01f342N12SohYRACV47WUt1Qn7CJu/t3/li vUfgKeaWhPmUFzEvdZB94je1dNAf/SlB1gy+yKNZca7Vc9VUpOwF9Ihrr1S36mUczq74 DLiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qCwRXET8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id c15-20020ac8518f000000b0039cc35ab4d0si6815029qtn.784.2022.12.13.03.19.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 13 Dec 2022 03:19:40 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qCwRXET8; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p53I6-0004OV-Dv; Tue, 13 Dec 2022 06:17:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p53I4-0004MP-4v for qemu-devel@nongnu.org; Tue, 13 Dec 2022 06:17:40 -0500 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p53I1-0002Nh-54 for qemu-devel@nongnu.org; Tue, 13 Dec 2022 06:17:39 -0500 Received: by mail-wm1-x333.google.com with SMTP id ay14-20020a05600c1e0e00b003cf6ab34b61so7607713wmb.2 for ; Tue, 13 Dec 2022 03:17:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=20qiCSyBuRvA2agy+mA00cXv9PUs69i2cg2fmTzeXmk=; b=qCwRXET8S+LYlnlzSCVTuDEURl7xqRahEkmfauAGjOttw+Pq8bVE9J0ndXfvyN84wj cUyAYjk+HLpLBmlpODzywqNMkALe4CIHa07rOJ47a9D8oGGKR7gUrp9ksuVICSeKqV+0 u423UfYZ1YsGdqhvKb8yD2PJPNstJKV2xQlrcTCj/xy8d27E283NRhQokFbVdJnaN/ve W0cYVv0+JtIBM0RtyePH2mEhBV9TAqlHrTITyPH4HMDO+jx3YmK04Tjg7ipkUY/Em86m WtqizH/RAmQDZeI3Om+0ioMbhUxqiRpcYvnldpNSs7Mh7E9mLdQ0QvapBqwpaeOin8tL 1MPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=20qiCSyBuRvA2agy+mA00cXv9PUs69i2cg2fmTzeXmk=; b=EmeaK3igtIm4dQtFQqjrzijsz9SFmeOjhML0iAhQemz8m6uUySmyKg8tFZ/t6rg3ua mURaQvv55fkMyK9CxTXKX1xXPkvAXPEf13eQevxrG3SGqupaGVQ2QYy1xoxvN70zXNjN KO1hZmN9+RgxmTnBt0cxuFfbAbtseya7QOCyZTcpM9dvwX9U9Tnzbhj4y/nv5qHy8H9M LvIMEiqK8k3ZyHzBHsP4sk3l45ZVB/34o/LE5L92d+WJtw8de8U+ETQsuNk99vAR2tE2 lhMh64GqA5x4whyxuZA6sF74hHNBsrnAM84pPOps2BvfISCfij+3l+Dkp2z5cP/xnCft 12Gg== X-Gm-Message-State: ANoB5pnjqwpckTojjhhFU1xc4GyEWbaNo4mZGRuIuXBUkhzv7//mkmFN nHSiEpjIw5mMPYtfpUUHtGT3HW0xzgcobCtucyg= X-Received: by 2002:a05:600c:3514:b0:3cf:a83c:184a with SMTP id h20-20020a05600c351400b003cfa83c184amr15091197wmq.24.1670930255541; Tue, 13 Dec 2022 03:17:35 -0800 (PST) Received: from localhost.localdomain ([81.0.6.76]) by smtp.gmail.com with ESMTPSA id az25-20020a05600c601900b003cf9bf5208esm13122809wmb.19.2022.12.13.03.17.34 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 13 Dec 2022 03:17:35 -0800 (PST) From: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org, Jonah Palmer , Thomas Huth , Laurent Vivier Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , "Michael S. Tsirkin" , Greg Kurz , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PATCH-for-8.0 v2 5/6] hw/virtio: Extract config read/write accessors to virtio-config-io.c Date: Tue, 13 Dec 2022 12:17:06 +0100 Message-Id: <20221213111707.34921-6-philmd@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221213111707.34921-1-philmd@linaro.org> References: <20221213111707.34921-1-philmd@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::333; envelope-from=philmd@linaro.org; helo=mail-wm1-x333.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org These config helpers use the target-dependent LD/ST API. Signed-off-by: Philippe Mathieu-Daudé --- hw/virtio/meson.build | 1 + hw/virtio/virtio-config-io.c | 204 +++++++++++++++++++++++++++++++++++ hw/virtio/virtio.c | 190 -------------------------------- 3 files changed, 205 insertions(+), 190 deletions(-) create mode 100644 hw/virtio/virtio-config-io.c diff --git a/hw/virtio/meson.build b/hw/virtio/meson.build index 23a980efaa..4a3b00d3bf 100644 --- a/hw/virtio/meson.build +++ b/hw/virtio/meson.build @@ -5,6 +5,7 @@ softmmu_virtio_ss.add(when: 'CONFIG_VIRTIO_MMIO', if_true: files('virtio-mmio.c' specific_virtio_ss = ss.source_set() specific_virtio_ss.add(files('virtio.c')) +specific_virtio_ss.add(files('virtio-config-io.c')) if have_vhost specific_virtio_ss.add(files('vhost.c', 'vhost-backend.c', 'vhost-iova-tree.c')) diff --git a/hw/virtio/virtio-config-io.c b/hw/virtio/virtio-config-io.c new file mode 100644 index 0000000000..ad78e0b9bc --- /dev/null +++ b/hw/virtio/virtio-config-io.c @@ -0,0 +1,204 @@ +/* + * Virtio Support + * + * Copyright IBM, Corp. 2007 + * + * Authors: + * Anthony Liguori + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/virtio/virtio.h" +#include "cpu.h" + +uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint8_t val; + + if (addr + sizeof(val) > vdev->config_len) { + return (uint32_t)-1; + } + + k->get_config(vdev, vdev->config); + + val = ldub_p(vdev->config + addr); + return val; +} + +uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint16_t val; + + if (addr + sizeof(val) > vdev->config_len) { + return (uint32_t)-1; + } + + k->get_config(vdev, vdev->config); + + val = lduw_p(vdev->config + addr); + return val; +} + +uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint32_t val; + + if (addr + sizeof(val) > vdev->config_len) { + return (uint32_t)-1; + } + + k->get_config(vdev, vdev->config); + + val = ldl_p(vdev->config + addr); + return val; +} + +void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint8_t val = data; + + if (addr + sizeof(val) > vdev->config_len) { + return; + } + + stb_p(vdev->config + addr, val); + + if (k->set_config) { + k->set_config(vdev, vdev->config); + } +} + +void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint16_t val = data; + + if (addr + sizeof(val) > vdev->config_len) { + return; + } + + stw_p(vdev->config + addr, val); + + if (k->set_config) { + k->set_config(vdev, vdev->config); + } +} + +void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint32_t val = data; + + if (addr + sizeof(val) > vdev->config_len) { + return; + } + + stl_p(vdev->config + addr, val); + + if (k->set_config) { + k->set_config(vdev, vdev->config); + } +} + +uint32_t virtio_config_modern_readb(VirtIODevice *vdev, uint32_t addr) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint8_t val; + + if (addr + sizeof(val) > vdev->config_len) { + return (uint32_t)-1; + } + + k->get_config(vdev, vdev->config); + + val = ldub_p(vdev->config + addr); + return val; +} + +uint32_t virtio_config_modern_readw(VirtIODevice *vdev, uint32_t addr) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint16_t val; + + if (addr + sizeof(val) > vdev->config_len) { + return (uint32_t)-1; + } + + k->get_config(vdev, vdev->config); + + val = lduw_le_p(vdev->config + addr); + return val; +} + +uint32_t virtio_config_modern_readl(VirtIODevice *vdev, uint32_t addr) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint32_t val; + + if (addr + sizeof(val) > vdev->config_len) { + return (uint32_t)-1; + } + + k->get_config(vdev, vdev->config); + + val = ldl_le_p(vdev->config + addr); + return val; +} + +void virtio_config_modern_writeb(VirtIODevice *vdev, + uint32_t addr, uint32_t data) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint8_t val = data; + + if (addr + sizeof(val) > vdev->config_len) { + return; + } + + stb_p(vdev->config + addr, val); + + if (k->set_config) { + k->set_config(vdev, vdev->config); + } +} + +void virtio_config_modern_writew(VirtIODevice *vdev, + uint32_t addr, uint32_t data) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint16_t val = data; + + if (addr + sizeof(val) > vdev->config_len) { + return; + } + + stw_le_p(vdev->config + addr, val); + + if (k->set_config) { + k->set_config(vdev, vdev->config); + } +} + +void virtio_config_modern_writel(VirtIODevice *vdev, + uint32_t addr, uint32_t data) +{ + VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); + uint32_t val = data; + + if (addr + sizeof(val) > vdev->config_len) { + return; + } + + stl_le_p(vdev->config + addr, val); + + if (k->set_config) { + k->set_config(vdev, vdev->config); + } +} + diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index f2298bb437..01d043b3c6 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -18,7 +18,6 @@ #include "qapi/qapi-commands-qom.h" #include "qapi/qapi-visit-virtio.h" #include "qapi/qmp/qjson.h" -#include "cpu.h" #include "trace.h" #include "qemu/error-report.h" #include "qemu/log.h" @@ -2580,195 +2579,6 @@ void virtio_reset(void *opaque) } } -uint32_t virtio_config_readb(VirtIODevice *vdev, uint32_t addr) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint8_t val; - - if (addr + sizeof(val) > vdev->config_len) { - return (uint32_t)-1; - } - - k->get_config(vdev, vdev->config); - - val = ldub_p(vdev->config + addr); - return val; -} - -uint32_t virtio_config_readw(VirtIODevice *vdev, uint32_t addr) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint16_t val; - - if (addr + sizeof(val) > vdev->config_len) { - return (uint32_t)-1; - } - - k->get_config(vdev, vdev->config); - - val = lduw_p(vdev->config + addr); - return val; -} - -uint32_t virtio_config_readl(VirtIODevice *vdev, uint32_t addr) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint32_t val; - - if (addr + sizeof(val) > vdev->config_len) { - return (uint32_t)-1; - } - - k->get_config(vdev, vdev->config); - - val = ldl_p(vdev->config + addr); - return val; -} - -void virtio_config_writeb(VirtIODevice *vdev, uint32_t addr, uint32_t data) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint8_t val = data; - - if (addr + sizeof(val) > vdev->config_len) { - return; - } - - stb_p(vdev->config + addr, val); - - if (k->set_config) { - k->set_config(vdev, vdev->config); - } -} - -void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint16_t val = data; - - if (addr + sizeof(val) > vdev->config_len) { - return; - } - - stw_p(vdev->config + addr, val); - - if (k->set_config) { - k->set_config(vdev, vdev->config); - } -} - -void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint32_t val = data; - - if (addr + sizeof(val) > vdev->config_len) { - return; - } - - stl_p(vdev->config + addr, val); - - if (k->set_config) { - k->set_config(vdev, vdev->config); - } -} - -uint32_t virtio_config_modern_readb(VirtIODevice *vdev, uint32_t addr) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint8_t val; - - if (addr + sizeof(val) > vdev->config_len) { - return (uint32_t)-1; - } - - k->get_config(vdev, vdev->config); - - val = ldub_p(vdev->config + addr); - return val; -} - -uint32_t virtio_config_modern_readw(VirtIODevice *vdev, uint32_t addr) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint16_t val; - - if (addr + sizeof(val) > vdev->config_len) { - return (uint32_t)-1; - } - - k->get_config(vdev, vdev->config); - - val = lduw_le_p(vdev->config + addr); - return val; -} - -uint32_t virtio_config_modern_readl(VirtIODevice *vdev, uint32_t addr) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint32_t val; - - if (addr + sizeof(val) > vdev->config_len) { - return (uint32_t)-1; - } - - k->get_config(vdev, vdev->config); - - val = ldl_le_p(vdev->config + addr); - return val; -} - -void virtio_config_modern_writeb(VirtIODevice *vdev, - uint32_t addr, uint32_t data) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint8_t val = data; - - if (addr + sizeof(val) > vdev->config_len) { - return; - } - - stb_p(vdev->config + addr, val); - - if (k->set_config) { - k->set_config(vdev, vdev->config); - } -} - -void virtio_config_modern_writew(VirtIODevice *vdev, - uint32_t addr, uint32_t data) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint16_t val = data; - - if (addr + sizeof(val) > vdev->config_len) { - return; - } - - stw_le_p(vdev->config + addr, val); - - if (k->set_config) { - k->set_config(vdev, vdev->config); - } -} - -void virtio_config_modern_writel(VirtIODevice *vdev, - uint32_t addr, uint32_t data) -{ - VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(vdev); - uint32_t val = data; - - if (addr + sizeof(val) > vdev->config_len) { - return; - } - - stl_le_p(vdev->config + addr, val); - - if (k->set_config) { - k->set_config(vdev, vdev->config); - } -} - void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr) { if (!vdev->vq[n].vring.num) {