From nobody Sat Feb 7 09:04:18 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1770321739; cv=none; d=zohomail.com; s=zohoarc; b=CIorXpF09AysWjfN8yuwM5SrWv1zwTJi0Okd7h2uOkWkCppclvf4eGUPb7PEo4QNwmfVulB7VhSHl7Aw3+MM6DrhhQPlz41Wwtg2L8u0xG1nvaUSV8Oj8Qa/ibUu6iJyjwozfKDWxiIi7K590zgfuFmdQlnWLBoGoajc/Me0IdY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321739; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=uFKD2gCbF2L2yObzjuIkLcm5lMIH03Mpqiwzu3nD9ZU=; b=d/4iLIDT87A05vcDd9LnjVvXLt0ktxOHK7HNfpgdCNC9HGraf/lkmGeF8RWqeCsL6eq4DghW9cQ9VJJ8kVJBG4xGwThuoyT77pdptIAeF2UZtJkOqoQgVXhP2asfBfyljd6yQ0WK5HLZpUfuq7hNsjVIfUKbZQv8kRal2lI1sNM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1770321739069560.8967461081576; Thu, 5 Feb 2026 12:02:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vd-0006v8-I2; Thu, 05 Feb 2026 14:59:25 -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 1vo5VZ-0006sR-6o for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:21 -0500 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VW-00039T-Qv for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:20 -0500 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-482f454be5bso20143135e9.0 for ; Thu, 05 Feb 2026 11:59:16 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321555; x=1770926355; darn=nongnu.org; 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=uFKD2gCbF2L2yObzjuIkLcm5lMIH03Mpqiwzu3nD9ZU=; b=FlvYscnu7klN4jf9BVzu8sOHXQHQ4cht6Tb9J0M/HVpl7MTN7pcwtmHeG1K53yRLvj jTvQ0vXIW/hwi0hKcnX8HFCEJdWmkmgAjn5LJJwYmLfr4pAL0ojXhC1yHbswEiL0Qf6N HJ5fZfKqKSKhZ8OULwBDIPwnjbtnpnLzWVp21MyaiZ0Mh7qqIbmlOV36yLThCgpcV2YJ CuNkfJ56qRzV3Zjg8KPsvaVKXwIuDxugErzP1k9zK/Xp3uuNNIhRayNYqt/mMjys29Nq GrBP3sE7fLQDUV9liUd/MuZRJ2mrKE2eP6t744rlfEpH0pYJDhbDPR/Ow92dXO7bO1F0 ZaeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321555; x=1770926355; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=uFKD2gCbF2L2yObzjuIkLcm5lMIH03Mpqiwzu3nD9ZU=; b=Vdlqkrl+R3BqsKi91Jjfa7EUz0aZCLjhLWpz+qUih5W3f1nDt9FUjhnVmL/6aSwyvI PGOYslqEycRQwxlv6AC/V8koZmOO1fiuXoo0Lj5OzBGobnFdjnsjqdrnMHQ7iWAaRXcv 4DBHhgkoo1GERjH6UUVhAzedUALZq4ATr7S8+M69/WsTgIa+dMBg6vHFAkTVMcjmXVnf 4wHDUnscs92TFmQ9gPnr3YKV9w8LUmrqhYnfILkeCBYrIyWy90zo60eDowaNIVLZqm9g OJR3Vfqq445sVki8Jjpl3cE4Ymh9BwS1jSfEZwB2efBFoGqb0hIJBQKZ6tbrs54qeJHG VLQg== X-Gm-Message-State: AOJu0YzmjPu5qI4BGB93PQooWB4eIDrwG6IxdgWwWtpM45+rHZiUA2AB D7Gp6bdGorx7PkbIVxFjqeSzX9tEvTNuM2+VbuaYG61Opp1Yt/PdschZhOB/vnO6XvM= X-Gm-Gg: AZuq6aI/4r5B8UG9VU5YvxqXaAv6CjB13RmQ6F8SvQSj4yQwXIgfZ7Jir5/AEd9xbL+ /hyPWCq/lsn/UIBpmehspPWB7jmkMHSLkAVPXUiKBFWa8KagS7UaDYYN/lJTdLkIiMrkUP0bRLg v+mtYtYPepfnw0NNWMfYZdBca6NsIIOcmkofbu3csHNSzIIAn/Pv5axPxbAaGiJdga8Cj+CJgAt Uw+bJ0Z+p6FK2nmbjN8IaJPjf63b+MUb6GUo4yqxwYpBnzLLsW+E62mPCXNuHiPxdaPa879DTjR 7aE51GS7qhdF6xKjYhL7Nj5VfppeUWkSadvyDKQoSFMDieqlazMQbeSX+K/cDb4CSXAUUQv/I1O QyVQp8Wz39Td5GJRrEsPgadpqBaRaq0HW0+gIjSTvx8q5C6W5ME4fzhqgquwpKfpe+FCSMEvXeu gmTp7nZlQnqY5WIcHep3Q= X-Received: by 2002:a05:6000:200e:b0:435:932e:f924 with SMTP id ffacd0b85a97d-43629034d76mr777534f8f.2.1770321555303; Thu, 05 Feb 2026 11:59:15 -0800 (PST) From: Ruslan Ruslichenko To: qemu-devel@nongnu.org Cc: qemu-arm@nongnu.org, peter.maydell@linaro.org, artem_mygaiev@epam.com, volodymyr_babchuk@epam.com, takahiro.nakata.wr@renesas.com, "Edgar E . Iglesias" , francisco.iglesias@amd.com, Ruslan_Ruslichenko@epam.com, "Edgar E . Iglesias" Subject: [PATCH 21/29] hw/core: Add Remote Port Stream device Date: Thu, 5 Feb 2026 20:58:16 +0100 Message-ID: <20260205195824.2610192-22-ruslichenko.r@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260205195824.2610192-1-ruslichenko.r@gmail.com> References: <20260205195824.2610192-1-ruslichenko.r@gmail.com> MIME-Version: 1.0 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=2a00:1450:4864:20::329; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x329.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, FREEMAIL_FROM=0.001, 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: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1770321741641154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Introduce the 'remote-port-stream' device to bridge QEMU StreamSink interfaces with the Remote Port protocol. The patch implements the logic to translate local stream push operations into Remote Port bus-access packets and vice-versa. This enables bi-directional data streaming between QEMU and external simulators. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-stream.c | 239 +++++++++++++++++++++++++++++++++++ hw/core/trace-events | 4 + 2 files changed, 243 insertions(+) create mode 100644 hw/core/remote-port-stream.c diff --git a/hw/core/remote-port-stream.c b/hw/core/remote-port-stream.c new file mode 100644 index 0000000000..6baaf68f08 --- /dev/null +++ b/hw/core/remote-port-stream.c @@ -0,0 +1,239 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2013 Xilinx Inc + * Copyright (c) 2013 Peter Crosthwaite + * Copyright (c) 2013 Edgar E. Iglesias + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ + +#include "qemu/osdep.h" +#include "hw/core/sysbus.h" +#include "qemu/log.h" + +#include "qemu/bitops.h" +#include "qapi/qmp/qerror.h" +#include "hw/core/stream.h" +#include "qapi/error.h" +#include "migration/vmstate.h" +#include "hw/core/qdev-properties.h" +#include "hw/core/remote-port.h" +#include "trace.h" + +#ifndef REMOTE_PORT_STREAM_ERR_DEBUG +#define REMOTE_PORT_STREAM_ERR_DEBUG 0 +#endif + +#define TYPE_REMOTE_PORT_STREAM "remote-port-stream" + +#define REMOTE_PORT_STREAM(obj) \ + OBJECT_CHECK(RemotePortStream, (obj), TYPE_REMOTE_PORT_STREAM) + +typedef struct RemotePortStream RemotePortStream; + +struct RemotePortStream { + DeviceState parent_obj; + + RemotePort *rp; + uint32_t rp_dev; + uint16_t stream_width; + + StreamSink *tx_dev; + + StreamCanPushNotifyFn notify; + void *notify_opaque; + + uint8_t *buf; + struct rp_pkt pkt; + + bool rsp_pending; + uint32_t current_id; +}; + +static void rp_stream_notify(void *opaque) +{ + RemotePortStream *s =3D REMOTE_PORT_STREAM(opaque); + + /* FIXME: This is completely bogus. */ + if (s->buf && stream_can_push(s->tx_dev, rp_stream_notify, s)) { + RemotePortDynPkt rsp; + struct rp_encode_busaccess_in in =3D {0}; + size_t pktlen =3D sizeof(struct rp_pkt_busaccess_ext_base); + size_t enclen; + int64_t delay =3D 0; /* FIXME - Implement */ + + size_t ret =3D stream_push(s->tx_dev, s->buf, 4, 0); + assert(ret =3D=3D 4); + s->buf =3D NULL; + + memset(&rsp, 0, sizeof(rsp)); + rp_dpkt_alloc(&rsp, pktlen); + rp_encode_busaccess_in_rsp_init(&in, &s->pkt); + in.clk =3D s->pkt.busaccess.timestamp + delay; + enclen =3D rp_encode_busaccess(rp_get_peer(s->rp), + &rsp.pkt->busaccess_ext_base, + &in); + assert(enclen <=3D pktlen); + trace_remote_port_stream_tx_busaccess(rp_cmd_to_string(in.cmd), + in.id, in.flags, in.dev, in.addr, in.size, in.attr); + + rp_write(s->rp, (void *)rsp.pkt, pktlen); + } +} + +static void rp_stream_write(RemotePortDevice *obj, struct rp_pkt *pkt) +{ + RemotePortStream *s =3D REMOTE_PORT_STREAM(obj); + + trace_remote_port_stream_rx_busaccess(rp_cmd_to_string(pkt->hdr.cmd), + pkt->hdr.id, pkt->hdr.flags, pkt->hdr.dev, pkt->busaccess.addr, + pkt->busaccess.len, pkt->busaccess.attributes); + + assert(pkt->busaccess.width =3D=3D 0); + assert(pkt->busaccess.stream_width =3D=3D pkt->busaccess.len); + assert(pkt->busaccess.addr =3D=3D 0); + + if (pkt->hdr.flags & RP_PKT_FLAGS_response) { + /* FXIME - probably need to do syncs and stuff */ + assert(s->rsp_pending); + s->rsp_pending =3D false; + if (s->notify) { + StreamCanPushNotifyFn notify =3D s->notify; + s->notify =3D NULL; + notify(s->notify_opaque); + } + } else { + assert(!s->buf); + s->buf =3D g_memdup2(pkt + 1, 4); + s->pkt =3D *pkt; + rp_stream_notify(s); + } +} + +static bool rp_stream_stream_can_push(StreamSink *obj, + StreamCanPushNotifyFn notify, + void *notify_opaque) +{ + RemotePortStream *s =3D REMOTE_PORT_STREAM(obj); + + if (s->rsp_pending) { + s->notify =3D notify; + s->notify_opaque =3D notify_opaque; + return false; + } + return true; +} + +static size_t rp_stream_stream_push(StreamSink *obj, uint8_t *buf, + size_t len, bool eop) +{ + RemotePortStream *s =3D REMOTE_PORT_STREAM(obj); + RemotePortDynPkt rsp; + struct rp_pkt_busaccess_ext_base pkt; + struct rp_encode_busaccess_in in =3D {0}; + uint64_t rp_attr =3D eop ? RP_BUS_ATTR_EOP : 0; + int64_t clk; + int enclen; + + clk =3D rp_normalized_vmclk(s->rp); + + in.cmd =3D RP_CMD_write; + in.id =3D rp_new_id(s->rp); + in.dev =3D s->rp_dev; + in.clk =3D clk; + in.attr =3D rp_attr; + in.size =3D len; + in.stream_width =3D s->stream_width; + enclen =3D rp_encode_busaccess(rp_get_peer(s->rp), &pkt, &in); + + trace_remote_port_stream_tx_busaccess(rp_cmd_to_string(in.cmd), + in.id, in.flags, in.dev, in.addr, in.size, in.attr); + + rp_rsp_mutex_lock(s->rp); + rp_write(s->rp, (void *) &pkt, enclen); + rp_write(s->rp, buf, len); + rsp =3D rp_wait_resp(s->rp); + assert(rsp.pkt->hdr.id =3D=3D be32_to_cpu(pkt.hdr.id)); + + trace_remote_port_stream_rx_busaccess( + rp_cmd_to_string(rsp.pkt->hdr.cmd), rsp.pkt->hdr.id, + rsp.pkt->hdr.flags, rsp.pkt->hdr.dev, rsp.pkt->busaccess.addr, + rsp.pkt->busaccess.len, rsp.pkt->busaccess.attributes); + + rp_dpkt_invalidate(&rsp); + rp_rsp_mutex_unlock(s->rp); + rp_restart_sync_timer(s->rp); + return len; +} + +static void rp_prop_allow_set_link(const Object *obj, const char *name, + Object *val, Error **errp) +{ +} + +static void rp_stream_init(Object *obj) +{ + RemotePortStream *s =3D REMOTE_PORT_STREAM(obj); + + object_property_add_link(obj, "axistream-connected", TYPE_STREAM_SINK, + (Object **)&s->tx_dev, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_STRONG); + object_property_add_link(obj, "rp-adaptor0", "remote-port", + (Object **)&s->rp, + rp_prop_allow_set_link, + OBJ_PROP_LINK_STRONG); +} + +static Property rp_properties[] =3D { + DEFINE_PROP_UINT32("rp-chan0", RemotePortStream, rp_dev, 0), + DEFINE_PROP_UINT16("stream-width", RemotePortStream, stream_width, 4), +}; + +static void rp_stream_class_init(ObjectClass *oc, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + StreamSinkClass *ssc =3D STREAM_SINK_CLASS(oc); + RemotePortDeviceClass *rpdc =3D REMOTE_PORT_DEVICE_CLASS(oc); + + ssc->push =3D rp_stream_stream_push; + ssc->can_push =3D rp_stream_stream_can_push; + device_class_set_props_n(dc, rp_properties, ARRAY_SIZE(rp_properties)); + rpdc->ops[RP_CMD_write] =3D rp_stream_write; +} + +static const TypeInfo rp_stream_info =3D { + .name =3D TYPE_REMOTE_PORT_STREAM, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(RemotePortStream), + .class_init =3D rp_stream_class_init, + .instance_init =3D rp_stream_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_STREAM_SINK }, + { TYPE_REMOTE_PORT_DEVICE }, + { }, + } +}; + +static void rp_stream_register_types(void) +{ + type_register_static(&rp_stream_info); +} + +type_init(rp_stream_register_types) diff --git a/hw/core/trace-events b/hw/core/trace-events index fb3125b0eb..5b4e5029fe 100644 --- a/hw/core/trace-events +++ b/hw/core/trace-events @@ -44,3 +44,7 @@ remote_port_memory_slave_rx_busaccess(const char *cmd, ui= nt32_t id, uint32_t fla # remote-port-memory-gpio.c remote_port_gpio_tx_interrupt(uint32_t id, uint32_t flags, uint32_t dev, u= int64_t vector, uint32_t irq, uint32_t val) "id=3D0x%"PRIx32", flags=3D0x%"= PRIx32", dev=3D0x%"PRIx32", vector=3D0x%"PRIx64", irq=3D0x%"PRIx32", level= =3D0x%"PRIx32 remote_port_gpio_rx_interrupt(uint32_t id, uint32_t flags, uint32_t dev, u= int64_t vector, uint32_t irq, uint32_t val) "id=3D0x%"PRIx32", flags=3D0x%"= PRIx32", dev=3D0x%"PRIx32", vector=3D0x%"PRIx64", irq=3D0x%"PRIx32", level= =3D0x%"PRIx32 + +# remote-port-stream.c +remote_port_stream_tx_busaccess(const char *cmd, uint32_t id, uint32_t fla= gs, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd=3D%s, i= d=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%"PRIx64"= , len=3D0x%"PRIx32", attr=3D0x%"PRIx64 +remote_port_stream_rx_busaccess(const char *cmd, uint32_t id, uint32_t fla= gs, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd=3D%s, i= d=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%"PRIx64"= , len=3D0x%"PRIx32", attr=3D0x%"PRIx64 --=20 2.43.0