From nobody Sat Feb 7 08:45:11 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=1770321613; cv=none; d=zohomail.com; s=zohoarc; b=A58YwT1CQOtMyLYdz5/+zxDUuouTjNJ131ko0il/gSzcQ97OorbiayVa+o9keJkUDYG1S0gcBQRGJvxcNAOebcrWWcKcHaReNiXcCD1LS5GiXrmByWea3PfjFkwCs7BhNTyW4aApQNDCfPk5zUQcIJ8FfPDi4czym6m4Brf3+hM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321613; 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=hwJ8SbAz2trPDggbZFa9euH7TZu8N5wzkSpK4AYe4+g=; b=jF6Cu8cGENnd+X3alK0yuyN2F2RjiGsfaan01CgElmfw2Aj+l/oAFvpDegO++kFIGbMSJ6GJtn8J+GBOr+Ds+nsD+Enoqmlg/PTfhMTbPa3TrbCL7FAYayWxAjq1HxaWFPqL0kffHD0n+Fj4OYsPtZQ0qYQilaoi/ZmfjByNhtM= 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 17703216135841002.5719948055477; Thu, 5 Feb 2026 12:00:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5V4-0006VQ-2f; Thu, 05 Feb 2026 14:58:50 -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 1vo5V1-0006U7-So for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:47 -0500 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5Uz-000311-D6 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:47 -0500 Received: by mail-wr1-x436.google.com with SMTP id ffacd0b85a97d-42fbc544b09so1266159f8f.1 for ; Thu, 05 Feb 2026 11:58:45 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321523; x=1770926323; 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=hwJ8SbAz2trPDggbZFa9euH7TZu8N5wzkSpK4AYe4+g=; b=fDVPGLmCCL1w9uolhwCfLKFh9mNpgvEEUF4+mfvQwMDV0NiGDd/9INbO2Ji60fb1GY IAFsWBlMU4naF67xCc80qIXujkS1jVs4HRq69pL9DS21XgskY02V4V4jrt1weFdOA2TW ALhX1ULzj0fpT8UI0aS+ex9WwaiFqU+dJo1ZMSCEDmtcOXUlpgHnGXFure72qar02g2J s+z+Uv8dj74WEwa/4TSbEGFokuSNmk4vFd6wsdgohU7cJHu+w/j5IBHcSjg/rtfVtuVG aS/twF4UxfspUpYmtWdkJM+TrtlOTDJpVoOnTlT2qk3tyE5GYSnQpf1dQEAThwKH1yGQ n8AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321523; x=1770926323; 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=hwJ8SbAz2trPDggbZFa9euH7TZu8N5wzkSpK4AYe4+g=; b=jVpc/CtERAtqGoIhcOo8RMhZDZWs2XEU0qodaZXUtIGvNqB9wLh+MUyc+KRgjSBvU8 T+T0Nr05tgHW8B7Fpuw8mNyoy4AWeJszBYEnWhs6kiOHquMO7oPSQaMwOgTc2rfJG6/8 QHqCTVSBc0o+V/M0F2N2JKnHnFcU+SHF5in13ePBlyLDYGQa74k1Kzj1WJq1+ZqGqjXF 5hknc9LRKpua1U+X6j4LBG5rfpvFzzMW+/dIhpsHCkIc7IjCGgKmBQAK/6xcwL5Q5YIM gtlgtVLlYwbwUATf/XUpZRQlSYdhzr20SVQxe5kInftdjzl6iao5pReEB+ovsJqt5gh6 7vkw== X-Gm-Message-State: AOJu0Ywqhfzhv22CcvI0iXjTqCbu8bULgIeKslC7NMdEHAfJYmLEoTSM feJd7tO+TG3hKrjBTfs1ZZFIIX5Q+f9uQjkt651kAd6mawGixvGX6WryCXKCsXov07k= X-Gm-Gg: AZuq6aJgZFLLbvSUwfj5ZLASD5kxkzvPzezi0rUmJpqqOCmwPUjfQHwVIkppgFGtojf 13CV9Dk1bXcjvEUI2Aosc8lMI9+oMrvxe3pbS2OVXiX+jlshG/40zR4X0vshzpn1yZLpNsycQkN WWg2xAO4EP4E/V3mrT3PMQkXcfsRUMt7IhONTgkkvg1HnSzExdYwqrNIYQDGVwf9DzO8vyI0/o/ ZH32OyiZlTCsx5RnowY9a8iTZzWkOZ88hSpPMrdUaho8SyJ777dVrtdhGuHdRplYhC7nbdJ5YCF C8QhO33dnzOWFtTz4seTC0d1e68Ineg4Wvn+M94v9Mi7LCZ4AYyuAGY3ZTYJ4DIf2bEy+jB+gWe ZUecukEZ3k8pNrlrG/1NpoU4Uv3/Awvoyfzgz/WWPxRzR2NOj4fUw32AjLckl/+WMbWpoQJu+3o VXQKswHWKILaKYbZxxBU4= X-Received: by 2002:a5d:64c7:0:b0:429:c851:69ab with SMTP id ffacd0b85a97d-4362937fa27mr590559f8f.55.1770321523040; Thu, 05 Feb 2026 11:58:43 -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 01/29] hw/core: Add Remote Port protocol packet definition Date: Thu, 5 Feb 2026 20:57:56 +0100 Message-ID: <20260205195824.2610192-2-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::436; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x436.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: 1770321615154158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Introduce packet definition for Remote Port protocol. Remote Port is a socket based inter-simulation protocol designed to connect QEMU to external simulator (such as SystemC models, RTL simulators, etc) for hardware co- simulation. The protocol supports bidirectional communication for: - Connection setup, version negotiation (Hello/Cfg packets) - Memory and MMIO transactions (Read/Write packets) - Interrupts and GPIO signaling (Interrupt packets) - Time synchronization (Sync packets) The patch introduces header file with packet definition used by protocol. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- include/hw/core/remote-port-proto.h | 305 ++++++++++++++++++++++++++++ 1 file changed, 305 insertions(+) create mode 100644 include/hw/core/remote-port-proto.h diff --git a/include/hw/core/remote-port-proto.h b/include/hw/core/remote-p= ort-proto.h new file mode 100644 index 0000000000..cbe1498df0 --- /dev/null +++ b/include/hw/core/remote-port-proto.h @@ -0,0 +1,305 @@ +// SPDX-License-Identifier: MIT +/* + * QEMU remote port protocol parts. + * + * Copyright (c) 2013 Xilinx Inc + * Written by 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. + */ +#ifndef REMOTE_PORT_PROTO_H__ +#define REMOTE_PORT_PROTO_H__ + +/* + * Remote-Port (RP) is an inter-simulator protocol. It assumes a reliable + * point to point communcation with the remote simulation environment. + * + * Setup + * In the SETUP phase a mandatory HELLO packet is exchanged with optional + * CFG packets following. HELLO packets are useful to ensure that both + * sides are speaking the same protocol and using compatible versions. + * + * CFG packets are used to negotiate configuration options. At the moment + * these remain unimplemented. + * + * Once the session is up, communication can start through various other + * commands. The list can be found further down this document. + * Commands are carried over RP packets. Every RP packet contains a header + * with length, flags and an ID to track potential responses. + * The header is followed by a packet specific payload. You'll find the + * details of the various commands packet layouts here. Some commands can + * carry data/blobs in their payload. + */ + + +#define RP_VERSION_MAJOR 4 +#define RP_VERSION_MINOR 3 + +#if defined(_WIN32) && defined(__MINGW32__) +/* mingw GCC has a bug with packed attributes. */ +#define PACKED __attribute__ ((gcc_struct, packed)) +#else +#define PACKED __attribute__ ((packed)) +#endif + +/* Could be auto generated. */ +enum rp_cmd { + RP_CMD_nop =3D 0, + RP_CMD_hello =3D 1, + RP_CMD_cfg =3D 2, + RP_CMD_read =3D 3, + RP_CMD_write =3D 4, + RP_CMD_interrupt =3D 5, + RP_CMD_sync =3D 6, + RP_CMD_ats_req =3D 7, + RP_CMD_ats_inv =3D 8, + RP_CMD_max =3D 8 +}; + +enum { + RP_OPT_quantum =3D 0, +}; + +struct rp_cfg_state { + uint64_t quantum; +}; + +enum { + RP_PKT_FLAGS_optional =3D 1 << 0, + RP_PKT_FLAGS_response =3D 1 << 1, + + /* + * Posted hint. + * When set this means that the receiver is not required to respond to + * the message. Since it's just a hint, the sender must be prepared to + * drop responses. Note that since flags are echoed back in responses + * a response to a posted packet will be easy to identify early in the + * protocol stack. + */ + RP_PKT_FLAGS_posted =3D 1 << 2, +}; + +struct rp_pkt_hdr { + uint32_t cmd; + uint32_t len; + uint32_t id; + uint32_t flags; + uint32_t dev; +} PACKED; + +struct rp_pkt_cfg { + struct rp_pkt_hdr hdr; + uint32_t opt; + uint8_t set; +} PACKED; + +struct rp_version { + uint16_t major; + uint16_t minor; +} PACKED; + +struct rp_capabilities { + /* Offset from start of packet. */ + uint32_t offset; + uint16_t len; + uint16_t reserved0; +} PACKED; + +enum { + CAP_BUSACCESS_EXT_BASE =3D 1, /* New header layout. */ + CAP_BUSACCESS_EXT_BYTE_EN =3D 2, /* Support for Byte Enables. */ + + /* + * Originally, all interrupt/wire updates over remote-port were posted. + * This turned out to be a bad idea. To fix it without breaking backwa= rds + * compatibility, we add the WIRE Posted updates capability. + * + * If the peer supportes this, it will respect the RP_PKT_FLAGS_posted + * flag. If the peer doesn't support this capability, senders need to + * be aware that the peer will not respond to wire updates regardless + * of the posted header-flag. + */ + CAP_WIRE_POSTED_UPDATES =3D 3, + + CAP_ATS =3D 4, /* Address translation services */ +}; + +struct rp_pkt_hello { + struct rp_pkt_hdr hdr; + struct rp_version version; + struct rp_capabilities caps; +} PACKED; + +enum { + /* Remote port responses. */ + RP_RESP_OK =3D 0x0, + RP_RESP_BUS_GENERIC_ERROR =3D 0x1, + RP_RESP_ADDR_ERROR =3D 0x2, + RP_RESP_MAX =3D 0xF, +}; + +enum { + RP_BUS_ATTR_EOP =3D (1 << 0), + RP_BUS_ATTR_SECURE =3D (1 << 1), + RP_BUS_ATTR_EXT_BASE =3D (1 << 2), + RP_BUS_ATTR_PHYS_ADDR =3D (1 << 3), + + /* + * The access targets the I/O address space. + */ + RP_BUS_ATTR_IO_ACCESS =3D (1 << 4), + + /* + * Bits [11:8] are allocated for storing transaction response codes. + * These new response codes are backward compatible as existing + * implementations will not set/read these bits. + * For existing implementations, these bits will be zero which is RESP= _OKAY. + */ + RP_BUS_RESP_SHIFT =3D 8, + RP_BUS_RESP_MASK =3D (RP_RESP_MAX << RP_BUS_RESP_SHIFT), +}; + +struct rp_pkt_busaccess { + struct rp_pkt_hdr hdr; + uint64_t timestamp; + uint64_t attributes; + uint64_t addr; + + /* Length in bytes. */ + uint32_t len; + + /* + * Width of each beat in bytes. Set to zero for unknown (let the remote + * side choose). + */ + uint32_t width; + + /* + * Width of streaming, must be a multiple of width. + * addr should repeat itself around this width. Set to same as len + * for incremental (normal) accesses. In bytes. + */ + uint32_t stream_width; + + /* Implementation specific source or master-id. */ + uint16_t master_id; +} PACKED; + + +/* This is the new extended busaccess packet layout. */ +struct rp_pkt_busaccess_ext_base { + struct rp_pkt_hdr hdr; + uint64_t timestamp; + uint64_t attributes; + uint64_t addr; + + /* Length in bytes. */ + uint32_t len; + + /* + * Width of each beat in bytes. Set to zero for unknown (let the remote + * side choose). + */ + uint32_t width; + + /* + * Width of streaming, must be a multiple of width. + * addr should repeat itself around this width. Set to same as len + * for incremental (normal) accesses. In bytes. + */ + uint32_t stream_width; + + /* Implementation specific source or master-id. */ + uint16_t master_id; + /* ---- End of 4.0 base busaccess. ---- */ + + uint16_t master_id_31_16; /* MasterID bits [31:16]. */ + uint32_t master_id_63_32; /* MasterID bits [63:32]. */ + /* + * --------------------------------------------------- + * Since hdr is 5 x 32bit, we are now 64bit aligned. + */ + + uint32_t data_offset; /* Offset to data from start of pkt. */ + uint32_t next_offset; /* Offset to next extension. 0 if none. */ + + uint32_t byte_enable_offset; + uint32_t byte_enable_len; + + /* ---- End of CAP_BUSACCESS_EXT_BASE. ---- */ + + /* + * If new features are needed that may always occupy space + * in the header, then add a new capability and extend the + * this area with new fields. + * Will help receivers find data_offset and next offset, + * even those that don't know about extended fields. + */ +} PACKED; + +struct rp_pkt_interrupt { + struct rp_pkt_hdr hdr; + uint64_t timestamp; + uint64_t vector; + uint32_t line; + uint8_t val; +} PACKED; + +struct rp_pkt_sync { + struct rp_pkt_hdr hdr; + uint64_t timestamp; +} PACKED; + +enum { + RP_ATS_ATTR_exec =3D 1 << 0, + RP_ATS_ATTR_read =3D 1 << 1, + RP_ATS_ATTR_write =3D 1 << 2, +}; + +enum { + RP_ATS_RESULT_ok =3D 0, + RP_ATS_RESULT_error =3D 1, +}; + +struct rp_pkt_ats { + struct rp_pkt_hdr hdr; + uint64_t timestamp; + uint64_t attributes; + uint64_t addr; + uint64_t len; + uint32_t result; + uint64_t reserved0; + uint64_t reserved1; + uint64_t reserved2; + uint64_t reserved3; +} PACKED; + +struct rp_pkt { + union { + struct rp_pkt_hdr hdr; + struct rp_pkt_hello hello; + struct rp_pkt_busaccess busaccess; + struct rp_pkt_busaccess_ext_base busaccess_ext_base; + struct rp_pkt_interrupt interrupt; + struct rp_pkt_sync sync; + struct rp_pkt_ats ats; + }; +}; + +#endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321597; cv=none; d=zohomail.com; s=zohoarc; b=c0XwD8cD+HJOVPkRCWPeReGvzYSGgRIrSL9Pcgdj/gsV/MCkbF+knSoWKZAkaRg22JLKPfzicBrkFnD4p8yvgK6RDsxJSczoTzqNkUsThuhUpnWZIw1Dj5WGeot4Nd9GyxtgvB5dd4IAU5kUEOHtS5NXdTIDsSvbRuOwW67o5Ho= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321597; 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=BL6hmjytF8QyzFqPZLkSXIPl8zzLGZ1QoCPt5JE4jcA=; b=CMmXyRRzVxs4hdfpkgPdzF5Uf18qVtZQvjBBwDvUHVDigwJP7isFBJQXGx/oWhYIkPA5XVlqZVObZp63cwbG+J/AxlOJrpOSDRA6NmkkqnoRFUHTZptpcsq4RB/+YWYeQh1+D8dTungPn7NGw4NuRQ7GBCdkMYsTno7whraYszI= 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 1770321597788716.6918769813244; Thu, 5 Feb 2026 11:59:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5V4-0006Vo-LH; Thu, 05 Feb 2026 14:58:50 -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 1vo5V3-0006Ul-45 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:49 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5V0-00031D-Im for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:48 -0500 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-436263e31abso778958f8f.1 for ; Thu, 05 Feb 2026 11:58:46 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321525; x=1770926325; 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=BL6hmjytF8QyzFqPZLkSXIPl8zzLGZ1QoCPt5JE4jcA=; b=ZwJ2DNRhtQhXxdb80GzZC8fIJ0SDRPRLs16MxcAvJJ2691WREWrZlHpDnWKe5LsOFy uPkpx9YmHQxIOTbGCjxaJfbHBZlKlrvsHz3OstIV+ef6MTQZXuwBS/ea/lacXSrtumIm 3RJ4O4R6TBvEuqBGQNpc4536vryETcsFKZ8XElthn9EkscEN+oCHxnOph/nwOZr4Rcvs hIJ0qX6mWcwtX9bM4yjdquWwsy0L3Yx9V/Kj884QRd5YsF/05P2B14VJtHKFaU86uFZy G3xjD8IC9AdYgpItn4wCnTtKixmlApVxsrkTxrNGEPUMrrobNoSAu1TGkkouq/j5Vx0U iX7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321525; x=1770926325; 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=BL6hmjytF8QyzFqPZLkSXIPl8zzLGZ1QoCPt5JE4jcA=; b=IjyUccJEdG/+6KCLGlebfTMecbXNao0PrV74TGDA7nwYgLR6oG3TGolGrnEqW4S61M jTULDp0Ky7ED9n/daEpFXH66oYtOB/HNd5lErXoP8KC/PzkDeED8K0aaphyeUv5+Gooc qr7esf2kITq01K+32iEt7NdYEmdWwynP4CfQynbt5a9O7e0WFbWl8S7DsF72eaUCM8v/ jz4oLIwEzwi9z0zgaboeCA9m82t203PwkpinXjGsTEefQdKt4eV/C/rzk1QYEsH0rHxy eBa8MMdowBpF1PVJ3LgsD39+qNgjWnD9CGsfAUbddcDoMiS87SiFaZU8BzIAjnXqQ3aw g93A== X-Gm-Message-State: AOJu0YzBfAF37JKBxDleJSjnzr47sp7vWxL+Kw/i8nR5m8SmxwgIREH9 mQuq3HSr+UO7UncE4V/4V1wsRjeQBeu3RUPnblryK1QjkqRNMF7G98NDqPhp9HGOgKs= X-Gm-Gg: AZuq6aLWKyo88UdLtkrHtybeFc3EqZq4g9jTMpMUbtopeQAMPeaSlxJAntpNqi8oJhP FGP0uPiTZ1r8uuGRpKDqr+GHn0HmZXjTLlwhyst9px0W2eyDVgUwzpgiDf/Lr/nzv8SLiuF2dwE UJFKYR23gjM0q45UzXrAc2c+cgJE0/4qrhxPk1IW6EDEG8NM86vNri12oqLp3xK4UB4BCrD5lCu mtupfOeaUjJzNDr9BwZj7dWrdtrejU8v3uG59d3eCZJORLjkF6bZYyJTGqGPSEbVUm6nHwkJxH0 TmzzT1XHIEOFCJAAWO1vqGqbU07L/qaGTlzJXt2vJGe6XYYK04qV0EVf/uWr+1zOWYDglNYBNCp toDkz8dmV5oQXsGcx/g0Ve18+PLDfbwFGVCrY61r7+K9VpXKK7EGoSx5CHdWPyqUlARHwCYKsEN Y6k9IKqqJWF+h76wUDI1Y= X-Received: by 2002:a05:6000:250f:b0:435:bbda:3f4e with SMTP id ffacd0b85a97d-4362938b19bmr694535f8f.31.1770321524708; Thu, 05 Feb 2026 11:58:44 -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 02/29] hw/core: Add Remote Port header helpers Date: Thu, 5 Feb 2026 20:57:57 +0100 Message-ID: <20260205195824.2610192-3-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::42a; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42a.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=unavailable 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: 1770321599361154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Introduce core packet handling logic for Remote Port protocol. This includes helpers for encoding and decoding packet headers and payload. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-proto.c | 82 +++++++++++++++++++++++++++++ include/hw/core/remote-port-proto.h | 8 +++ 2 files changed, 90 insertions(+) create mode 100644 hw/core/remote-port-proto.c diff --git a/hw/core/remote-port-proto.c b/hw/core/remote-port-proto.c new file mode 100644 index 0000000000..1653fe7b78 --- /dev/null +++ b/hw/core/remote-port-proto.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: MIT +/* + * Remote-port protocol + * + * Copyright (c) 2013 Xilinx Inc + * Written by 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 "qemu/bswap.h" +#include "hw/core/remote-port-proto.h" + +static const char *rp_cmd_names[RP_CMD_max + 1] =3D { + [RP_CMD_nop] =3D "nop", + [RP_CMD_hello] =3D "hello", + [RP_CMD_cfg] =3D "cfg", + [RP_CMD_read] =3D "read", + [RP_CMD_write] =3D "write", + [RP_CMD_interrupt] =3D "interrupt", + [RP_CMD_sync] =3D "sync", + [RP_CMD_ats_req] =3D "ats_request", + [RP_CMD_ats_inv] =3D "ats_invalidation", +}; + +const char *rp_cmd_to_string(enum rp_cmd cmd) +{ + assert(cmd <=3D RP_CMD_max); + return rp_cmd_names[cmd]; +} + +int rp_decode_hdr(struct rp_pkt *pkt) +{ + int used =3D 0; + + pkt->hdr.cmd =3D be32_to_cpu(pkt->hdr.cmd); + pkt->hdr.len =3D be32_to_cpu(pkt->hdr.len); + pkt->hdr.id =3D be32_to_cpu(pkt->hdr.id); + pkt->hdr.flags =3D be32_to_cpu(pkt->hdr.flags); + pkt->hdr.dev =3D be32_to_cpu(pkt->hdr.dev); + used +=3D sizeof pkt->hdr; + return used; +} + +int rp_decode_payload(struct rp_pkt *pkt) +{ + int used =3D 0; + + switch (pkt->hdr.cmd) { + /* TBD */ + default: + break; + } + return used; +} + +void rp_encode_hdr(struct rp_pkt_hdr *hdr, uint32_t cmd, uint32_t id, + uint32_t dev, uint32_t len, uint32_t flags) +{ + hdr->cmd =3D cpu_to_be32(cmd); + hdr->len =3D cpu_to_be32(len); + hdr->id =3D cpu_to_be32(id); + hdr->dev =3D cpu_to_be32(dev); + hdr->flags =3D cpu_to_be32(flags); +} diff --git a/include/hw/core/remote-port-proto.h b/include/hw/core/remote-p= ort-proto.h index cbe1498df0..1d8e1b25da 100644 --- a/include/hw/core/remote-port-proto.h +++ b/include/hw/core/remote-port-proto.h @@ -302,4 +302,12 @@ struct rp_pkt { }; }; =20 +const char *rp_cmd_to_string(enum rp_cmd cmd); +int rp_decode_hdr(struct rp_pkt *pkt); +int rp_decode_payload(struct rp_pkt *pkt); + +void rp_encode_hdr(struct rp_pkt_hdr *hdr, + uint32_t cmd, uint32_t id, uint32_t dev, uint32_t len, + uint32_t flags); + #endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321751; cv=none; d=zohomail.com; s=zohoarc; b=KQe8PJ8zBOgv7iruyg4Sfi/6u9J0dxLI+h24PzpICm5D0cZd2ORX5Q2wwnfU2Djq8VUjS6P7nszlY4XN7ooHYrAKZuFFquMFOc4rj2oNMqxdVgtZd26aKJe/Z43qv6aaPf4WakUO6G343eJnAl8nXV4XBDFTofnJFxf02kavWYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321751; 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=6J2P5pQ/XJxmCYaQi8+PyRlPmOCkYxMPN6R3b9FjYyo=; b=VJnEl2gsLTmpAwUnOl786y1JpkWRISX/algdQsurqUmjN0cqFa0mpZmWprbLnWPWVaJ+63aViucMmEuHusFgx59wvOXq01FkK/d/QJZM3KfZDFw24NHkJv7A5WZehcVOFUkQmAlA3NB5YFbXscf+sdVYXi5qVC2bSKq9aNNm/cg= 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 1770321751936740.8746205995392; Thu, 5 Feb 2026 12:02:31 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5V5-0006WG-EC; Thu, 05 Feb 2026 14:58:51 -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 1vo5V4-0006Vf-Is for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:50 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5V2-00031l-QT for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:50 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4806f80cac9so9429565e9.1 for ; Thu, 05 Feb 2026 11:58:48 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321527; x=1770926327; 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=6J2P5pQ/XJxmCYaQi8+PyRlPmOCkYxMPN6R3b9FjYyo=; b=mDBEBia/Jg1YQumSESUFcPlQ/CiP+Se3Finj+1IGD2iMXqkmcQIqJg2kGtB/j8VIy7 NIHYGB0gJ4RqroX6jFVBczGD/3263AL1LWjnPEXZ01UNvlwOQ0bJI9jwUMoiiWSojL+x 46NEDAR9/CYTo4kcoXCHePiHVXmCjlHbCFsJrYa2B4R+vU1N+ewqjspDYzV7+Ky0EDQg seEzpXvaQtxW9X6FomhAa5NX/BUGUIPPFgRiewcM4UeXG+PnJGKsrWXB90dCbCXDIy+I M2YCplIgeb+Eq19KjdJGymlC6yEHb6guEr+DVwfG9OchL+LVZbOrHxXL5IF2XwkWVxHn zulQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321527; x=1770926327; 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=6J2P5pQ/XJxmCYaQi8+PyRlPmOCkYxMPN6R3b9FjYyo=; b=kJb9zSyG/cm7xarqaeBUeP2+uuH7ds7yK89LWG4wGR+oZ6LrJyKxl62E1Ua2QKwIII VvCfLk/vIfnPOgDRx2lGzpHyoD3sUWSO7I7Z6vTleTrYOMNRH5pAj1DutLkBSA4Y11PJ 2T+MaOtgreG0S/GAmPz+egp4tSigMG5IVMFnEU2ZG00OIRlY7IvzAXOKKtr3+o094zdH C8UTKKHPFD0+FJdchErxO6ueP2TneqqTOTNnP6P90aMa4i9clAZt7rFf6LJe3pJj8VRA KQ37/r5zsR5pSz6nXKetodbAf34LArS1xQiFjxFj9FNp4/JWIzJLtZIhr7DXiCEtayKG a+ng== X-Gm-Message-State: AOJu0Yx61OsjFefY0OmSxUV/kwSIWIvZIVm1nYs1XPAVJnNBtBSVxaRm 4nfgj8TOZbuPsINWGT3NaVyM6URPctXgqsfgBSAVnshAQtADZcvAcU66akDszcuJZM8= X-Gm-Gg: AZuq6aLsSh1fod02HIZYjrDsqf0wEfhPTZaObZv8kaUF9mYdjAI62rk5k7HlCSXUbPK 8SOFB1Ic9Y4j3zXqGc3utxFs5K9vAOgNK2Ruc5dUi0EPhwWT/5cJJOZiGqc4oMkQl+QAV/Ys5xI 5Dg4Yoxs8/vZglrdDoxKf+K+zQtspHvyus2/R+OrflBdPHzxcANLgv2WEZb4yz1cKPxz7XN93TE woSPPvsupFqShPmbU5JDvL/vguH4au1ij62NHlW0g5J1bGDjXrQje/ghWC4pCHsYM90n69efPGo aGR3Wr8soNkZ9pd2GWqEG+esv10LozfI2xEvLw7ph0RrTqRuZ9BSX7fyTgdAm2P3MQyehp78GwF fCS0ZVQmfj0XqhqdUp82K5kNRMnCRL9Hl+xWGEscpBpYa/PUPl4a7SYHTvUFpUYXZQ08HbrE0AG X4Y0U9eo3A1uIAap5WMTM= X-Received: by 2002:a5d:5f50:0:b0:431:b6e:8be3 with SMTP id ffacd0b85a97d-43629380ed0mr692048f8f.38.1770321526648; Thu, 05 Feb 2026 11:58:46 -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 03/29] hw/core: Add Remote Port session state and hello protocol Date: Thu, 5 Feb 2026 20:57:58 +0100 Message-ID: <20260205195824.2610192-4-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::32f; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x32f.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=unavailable 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: 1770321753262154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Implement the session management for Remote Port protocol. Key features implemented are following: - Hello packet handling and capabilities negotiation - Dynamic packet management routines - rp_peer_state struct definition to hold negotiated capabilities. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-proto.c | 134 +++++++++++++++++++++++++++- include/hw/core/remote-port-proto.h | 72 +++++++++++++++ 2 files changed, 205 insertions(+), 1 deletion(-) diff --git a/hw/core/remote-port-proto.c b/hw/core/remote-port-proto.c index 1653fe7b78..969dfc3cb2 100644 --- a/hw/core/remote-port-proto.c +++ b/hw/core/remote-port-proto.c @@ -64,7 +64,43 @@ int rp_decode_payload(struct rp_pkt *pkt) int used =3D 0; =20 switch (pkt->hdr.cmd) { - /* TBD */ + case RP_CMD_hello: + assert(pkt->hdr.len >=3D sizeof pkt->hello.version); + pkt->hello.version.major =3D be16_to_cpu(pkt->hello.version.major); + pkt->hello.version.minor =3D be16_to_cpu(pkt->hello.version.minor); + used +=3D sizeof pkt->hello.version; + + if ((pkt->hdr.len - used) >=3D sizeof pkt->hello.caps) { + void *offset; + int i; + + pkt->hello.caps.offset =3D be32_to_cpu(pkt->hello.caps.offset); + pkt->hello.caps.len =3D be16_to_cpu(pkt->hello.caps.len); + + offset =3D (char *)pkt + pkt->hello.caps.offset; + for (i =3D 0; i < pkt->hello.caps.len; i++) { + uint32_t cap; + + /* + * We don't know if offset is 32bit aligned so use + * memcpy to do the endian conversion. + */ + memcpy(&cap, offset + i * sizeof cap, sizeof cap); + cap =3D be32_to_cpu(cap); + memcpy(offset + i * sizeof cap, &cap, sizeof cap); + } + used +=3D sizeof pkt->hello.caps; + } else { + pkt->hello.caps.offset =3D 0; + pkt->hello.caps.len =3D 0; + } + + /* + * Consume everything ignoring additional headers we do not yet + * know about. + */ + used =3D pkt->hdr.len; + break; default: break; } @@ -80,3 +116,99 @@ void rp_encode_hdr(struct rp_pkt_hdr *hdr, uint32_t cmd= , uint32_t id, hdr->dev =3D cpu_to_be32(dev); hdr->flags =3D cpu_to_be32(flags); } + +size_t rp_encode_hello_caps(uint32_t id, uint32_t dev, struct rp_pkt_hello= *pkt, + uint16_t version_major, uint16_t version_minor, + uint32_t *caps, uint32_t *caps_out, + uint32_t caps_len) +{ + size_t psize =3D sizeof *pkt + sizeof caps[0] * caps_len; + unsigned int i; + + rp_encode_hdr(&pkt->hdr, RP_CMD_hello, id, dev, + psize - sizeof pkt->hdr, 0); + pkt->version.major =3D cpu_to_be16(version_major); + pkt->version.minor =3D cpu_to_be16(version_minor); + + /* Feature list is appeneded right after the hello packet. */ + pkt->caps.offset =3D cpu_to_be32(sizeof *pkt); + pkt->caps.len =3D cpu_to_be16(caps_len); + + for (i =3D 0; i < caps_len; i++) { + uint32_t cap; + + cap =3D caps[i]; + caps_out[i] =3D cpu_to_be32(cap); + } + return sizeof *pkt; +} + +void rp_process_caps(struct rp_peer_state *peer, + void *caps, size_t caps_len) +{ + int i; + + assert(peer->caps.busaccess_ext_base =3D=3D false); + + for (i =3D 0; i < caps_len; i++) { + uint32_t cap; + + memcpy(&cap, caps + i * sizeof cap, sizeof cap); + + switch (cap) { + case CAP_BUSACCESS_EXT_BASE: + peer->caps.busaccess_ext_base =3D true; + break; + case CAP_BUSACCESS_EXT_BYTE_EN: + peer->caps.busaccess_ext_byte_en =3D true; + break; + case CAP_WIRE_POSTED_UPDATES: + peer->caps.wire_posted_updates =3D true; + break; + case CAP_ATS: + peer->caps.ats =3D true; + break; + } + } +} + +void rp_dpkt_alloc(RemotePortDynPkt *dpkt, size_t size) +{ + if (dpkt->size < size) { + char *u8; + dpkt->pkt =3D realloc(dpkt->pkt, size); + u8 =3D (void *) dpkt->pkt; + memset(u8 + dpkt->size, 0, size - dpkt->size); + dpkt->size =3D size; + } +} + +void rp_dpkt_swap(RemotePortDynPkt *a, RemotePortDynPkt *b) +{ + struct rp_pkt *tmp_pkt; + size_t tmp_size; + + tmp_pkt =3D a->pkt; + tmp_size =3D a->size; + a->pkt =3D b->pkt; + a->size =3D b->size; + b->pkt =3D tmp_pkt; + b->size =3D tmp_size; +} + +bool rp_dpkt_is_valid(RemotePortDynPkt *dpkt) +{ + return dpkt->size > 0 && dpkt->pkt->hdr.len; +} + +void rp_dpkt_invalidate(RemotePortDynPkt *dpkt) +{ + assert(rp_dpkt_is_valid(dpkt)); + dpkt->pkt->hdr.len =3D 0; +} + +inline void rp_dpkt_free(RemotePortDynPkt *dpkt) +{ + dpkt->size =3D 0; + free(dpkt->pkt); +} diff --git a/include/hw/core/remote-port-proto.h b/include/hw/core/remote-p= ort-proto.h index 1d8e1b25da..ca1ab2f1d3 100644 --- a/include/hw/core/remote-port-proto.h +++ b/include/hw/core/remote-port-proto.h @@ -302,6 +302,28 @@ struct rp_pkt { }; }; =20 +struct rp_peer_state { + void *opaque; + + struct rp_pkt pkt; + bool hdr_used; + + struct rp_version version; + + struct { + bool busaccess_ext_base; + bool busaccess_ext_byte_en; + bool wire_posted_updates; + bool ats; + } caps; + + /* Used to normalize our clk. */ + int64_t clk_base; + + struct rp_cfg_state local_cfg; + struct rp_cfg_state peer_cfg; +}; + const char *rp_cmd_to_string(enum rp_cmd cmd); int rp_decode_hdr(struct rp_pkt *pkt); int rp_decode_payload(struct rp_pkt *pkt); @@ -310,4 +332,54 @@ void rp_encode_hdr(struct rp_pkt_hdr *hdr, uint32_t cmd, uint32_t id, uint32_t dev, uint32_t len, uint32_t flags); =20 +/* + * caps is a an array of supported capabilities by the implementor. + * caps_out is the encoded (network byte order) version of the + * same array. It should be sent to the peer after the hello packet. + */ +size_t rp_encode_hello_caps(uint32_t id, uint32_t dev, struct rp_pkt_hello= *pkt, + uint16_t version_major, uint16_t version_minor, + uint32_t *caps, uint32_t *features_out, + uint32_t features_len); + +/* rp_encode_hello is deprecated in favor of hello_caps. */ +static inline size_t __attribute__ ((deprecated)) +rp_encode_hello(uint32_t id, uint32_t dev, struct rp_pkt_hello *pkt, + uint16_t version_major, uint16_t version_minor) { + return rp_encode_hello_caps(id, dev, pkt, version_major, version_minor, + NULL, NULL, 0); +} + +void rp_process_caps(struct rp_peer_state *peer, + void *caps, size_t caps_len); + +/* Dynamically resizable remote port pkt. */ + +typedef struct RemotePortDynPkt { + struct rp_pkt *pkt; + size_t size; +} RemotePortDynPkt; + +/* + * Make sure dpkt is allocated and has enough room. + */ + +void rp_dpkt_alloc(RemotePortDynPkt *dpkt, size_t size); + +void rp_dpkt_swap(RemotePortDynPkt *a, RemotePortDynPkt *b); + +/* + * Check if the dpkt is valid. Used for debugging purposes. + */ + +bool rp_dpkt_is_valid(RemotePortDynPkt *dpkt); + +/* + * Invalidate the dpkt. Used for debugging purposes. + */ + +void rp_dpkt_invalidate(RemotePortDynPkt *dpkt); + +void rp_dpkt_free(RemotePortDynPkt *dpkt); + #endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321597; cv=none; d=zohomail.com; s=zohoarc; b=BqnSq7NaBvrZiAJ1ZniOJKJ21Iamii8AyfhQwqiQcaEqr2pd9JzKEzU+wYnuIxM3ppQvN4EKbAzpnwssArHuMeEjK/Fjueha9YQQ+POvfLt37DtHsNumajBMpnDcgT4XwHuZudMFclC3deVAeyaadkNcVJuJHw6DfBT6FnJtefg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321597; 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=d3V9JSkg1WfwLiLRtCGWm57UuYE5ACJQoo8jfnurwO4=; b=BIkjah852JVg41bn8z+lHpS/TZ7zxAsuessDBl+SVY8dzv/4KEpH+8tC1DTQWMVRsfazQnr+fQ7ct6ZkvfBjoUWiWgpnS/4Uhi/2FNxMO+6C0cyCiVtaapgzAGWeJY4Tzz3xQtTzTrttW9UncFPnQYpJJ2ycHujcmB4BGSYGJbY= 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 1770321597913434.5903703377305; Thu, 5 Feb 2026 11:59:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5V7-0006Xi-TI; Thu, 05 Feb 2026 14:58:53 -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 1vo5V6-0006X2-It for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:52 -0500 Received: from mail-wr1-x42b.google.com ([2a00:1450:4864:20::42b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5V4-00032A-EJ for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:52 -0500 Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-435f177a8f7so1401035f8f.1 for ; Thu, 05 Feb 2026 11:58:50 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321528; x=1770926328; 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=d3V9JSkg1WfwLiLRtCGWm57UuYE5ACJQoo8jfnurwO4=; b=ZvmVN64n4x4f73LM9K6Y0SSV1xT1NlXQPajMAy2x/g9moRh6b959IOO8y7JZSApPaU bgI7dMsX63oBi2f/INNWWJl1YR3jX3ZKJjSDJaeFMwbVafs9Y8XoOE9VhReS5dAt5nnE aMeDR2i2AM+9pwVcqzEBPYRKT1BHdHls3+2Zafb7WmUUIhoYqP25b04wwDGOcwdhktUU KAQc6oHpcqMTOlw6SjnH9hXkD+6eccIOZt11qxAPUUdrg1LI6lI3lZGAOHDfCRqqzFW5 +r/2Mu4Wm/qa8Kqx2GE0iNEnF7PB0mh8/VWdQMrHc4dIupgcirPC36BlzTd1B3M8LLBb dg/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321528; x=1770926328; 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=d3V9JSkg1WfwLiLRtCGWm57UuYE5ACJQoo8jfnurwO4=; b=o5ruV3rkloehhJSdRn+u7V0K47HSThfu2e+7YJdw926zUmi+qvmbtEsS+P81Tdd7H1 tSJUzre9NZrbpEXjTZhL1oq7OMUiKYJpNlAsX8y+j1KnJmaAjfVsFhA95/OwiRUye0H7 p5D4Qc6clY2b4RbzNAinuW2yY+m9rr5wcZKDBaSZ4u0XeBzNXo5zMgOYze/O536KOoE4 +yOHSwTyKicc5Hew2JpuzWeRT0WqUQz+aHf+g+XLycon2R0u3uFz99an70OQG0O0fCq3 GZirRO4/+21VqvYQFzqyNXcgfnZFVbRElndPPGa+RZJTs0i0utonj3rcP8CfndMYYja0 kmAA== X-Gm-Message-State: AOJu0Ywj3tftUX/Iuuhi0agS0uIzPKycQH+1049203z99yZeW/dQyC/u RNEFqcRR43JUxiPPUFciQr9U+8TFY821sbjqrnVpkAWqA2Va4+i+PTD2H+wwP0HmxEw= X-Gm-Gg: AZuq6aJYiE5IL9Y3S5MJqzIZUHiQ+KbvZSuy7q1p5R0t09EUJpMLmxRhIm4P+5K5x2d sUzcK9jA7spwZbjImRXE1bR041AkAOvXaX2pJF0nmFSIYQtRzon5ryiSCNCUYXnDHHOv5RnxlE5 lLrNkESqXvw9thHrgNuUZgu07wsOgNxbA4ob6RsIDT1aXjaKi7SHeiovF3N5Ph5IBAoU0QaBlQ5 oDx2PULFOYXGiNu7S5NIs4j/wMes0b7HkkjpL+I6OZFRNV7Ha4/gzK46WBa9At/g+/giDfPG1VO HJ67pbI4KQOUVd72+3uBy+wf6FclUSeS1UvoFU67O6WDtGxCDxC4kzM1isdkML3pldf5okjfyej rl2KTozryT3wIwARcez3PQXnFdYAgV3fXhzxhVHC3URVaM6JACwAKksldZHI8fDg1LiGXjAC9yt 2qOJafgj4mPF8WZ/EmVbKVgNxngIvNyw== X-Received: by 2002:a05:6000:1a87:b0:436:233c:c7c0 with SMTP id ffacd0b85a97d-43629342249mr764437f8f.26.1770321528158; Thu, 05 Feb 2026 11:58:48 -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 04/29] hw/core: Implement Remote Port bus access helpers Date: Thu, 5 Feb 2026 20:57:59 +0100 Message-ID: <20260205195824.2610192-5-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::42b; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42b.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=unavailable 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: 1770321599457154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Add bus access logic for Remote Port memory transactions. The patch add support for read and write commands, which enables data communication via the protocol. This includes support for both legacy and extended packet formats (such as 64-bit Master IDs) based on peer's capabilities. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-proto.c | 152 ++++++++++++++++++++++++++++ include/hw/core/remote-port-proto.h | 133 ++++++++++++++++++++++++ 2 files changed, 285 insertions(+) diff --git a/hw/core/remote-port-proto.c b/hw/core/remote-port-proto.c index 969dfc3cb2..33a6769087 100644 --- a/hw/core/remote-port-proto.c +++ b/hw/core/remote-port-proto.c @@ -62,6 +62,8 @@ int rp_decode_hdr(struct rp_pkt *pkt) int rp_decode_payload(struct rp_pkt *pkt) { int used =3D 0; + /* Master_id has an odd decoding due to historical reasons. */ + uint64_t master_id; =20 switch (pkt->hdr.cmd) { case RP_CMD_hello: @@ -101,6 +103,34 @@ int rp_decode_payload(struct rp_pkt *pkt) */ used =3D pkt->hdr.len; break; + case RP_CMD_write: + case RP_CMD_read: + assert(pkt->hdr.len >=3D sizeof pkt->busaccess - sizeof pkt->hdr); + pkt->busaccess.timestamp =3D be64_to_cpu(pkt->busaccess.timestamp); + pkt->busaccess.addr =3D be64_to_cpu(pkt->busaccess.addr); + pkt->busaccess.attributes =3D be64_to_cpu(pkt->busaccess.attribute= s); + pkt->busaccess.len =3D be32_to_cpu(pkt->busaccess.len); + pkt->busaccess.width =3D be32_to_cpu(pkt->busaccess.width); + pkt->busaccess.stream_width =3D be32_to_cpu(pkt->busaccess.stream_= width); + master_id =3D be16_to_cpu(pkt->busaccess.master_id); + + used +=3D sizeof pkt->busaccess - sizeof pkt->hdr; + + if (pkt->busaccess.attributes & RP_BUS_ATTR_EXT_BASE) { + struct rp_pkt_busaccess_ext_base *pext =3D &pkt->busaccess_ext= _base; + + assert(pkt->hdr.len >=3D sizeof *pext - sizeof pkt->hdr); + master_id |=3D (uint64_t)be16_to_cpu(pext->master_id_31_16) <<= 16; + master_id |=3D (uint64_t)be32_to_cpu(pext->master_id_63_32) <<= 32; + pext->data_offset =3D be32_to_cpu(pext->data_offset); + pext->next_offset =3D be32_to_cpu(pext->next_offset); + pext->byte_enable_offset =3D be32_to_cpu(pext->byte_enable_off= set); + pext->byte_enable_len =3D be32_to_cpu(pext->byte_enable_len); + + used +=3D sizeof *pext - sizeof pkt->busaccess; + } + pkt->busaccess.master_id =3D master_id; + break; default: break; } @@ -143,6 +173,127 @@ size_t rp_encode_hello_caps(uint32_t id, uint32_t dev= , struct rp_pkt_hello *pkt, return sizeof *pkt; } =20 +static void rp_encode_busaccess_common(struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t s= ize, + uint32_t width, uint32_t stream_width) +{ + pkt->timestamp =3D cpu_to_be64(clk); + pkt->master_id =3D cpu_to_be16(master_id); + pkt->addr =3D cpu_to_be64(addr); + pkt->attributes =3D cpu_to_be64(attr); + pkt->len =3D cpu_to_be32(size); + pkt->width =3D cpu_to_be32(width); + pkt->stream_width =3D cpu_to_be32(stream_width); +} + +size_t rp_encode_read(uint32_t id, uint32_t dev, + struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t size, + uint32_t width, uint32_t stream_width) +{ + rp_encode_hdr(&pkt->hdr, RP_CMD_read, id, dev, + sizeof *pkt - sizeof pkt->hdr, 0); + rp_encode_busaccess_common(pkt, clk, master_id, addr, attr, + size, width, stream_width); + return sizeof *pkt; +} + +size_t rp_encode_read_resp(uint32_t id, uint32_t dev, + struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t size, + uint32_t width, uint32_t stream_width) +{ + rp_encode_hdr(&pkt->hdr, RP_CMD_read, id, dev, + sizeof *pkt - sizeof pkt->hdr + size, RP_PKT_FLAGS_respo= nse); + rp_encode_busaccess_common(pkt, clk, master_id, addr, attr, + size, width, stream_width); + return sizeof *pkt + size; +} + +size_t rp_encode_write(uint32_t id, uint32_t dev, + struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t size, + uint32_t width, uint32_t stream_width) +{ + rp_encode_hdr(&pkt->hdr, RP_CMD_write, id, dev, + sizeof *pkt - sizeof pkt->hdr + size, 0); + rp_encode_busaccess_common(pkt, clk, master_id, addr, attr, + size, width, stream_width); + return sizeof *pkt; +} + +size_t rp_encode_write_resp(uint32_t id, uint32_t dev, + struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t size, + uint32_t width, uint32_t stream_width) +{ + rp_encode_hdr(&pkt->hdr, RP_CMD_write, id, dev, + sizeof *pkt - sizeof pkt->hdr, RP_PKT_FLAGS_response); + rp_encode_busaccess_common(pkt, clk, master_id, addr, attr, + size, width, stream_width); + return sizeof *pkt; +} + +/* New API for extended header. */ +size_t rp_encode_busaccess(struct rp_peer_state *peer, + struct rp_pkt_busaccess_ext_base *pkt, + struct rp_encode_busaccess_in *in) { + struct rp_pkt_busaccess *pkt_v4_0 =3D (void *) pkt; + uint32_t hsize =3D 0; + uint32_t ret_size =3D 0; + + /* Allocate packet space. */ + if (in->cmd =3D=3D RP_CMD_write && !(in->flags & RP_PKT_FLAGS_response= )) { + hsize =3D in->size; + } + if (in->cmd =3D=3D RP_CMD_read && (in->flags & RP_PKT_FLAGS_response))= { + hsize =3D in->size; + ret_size =3D in->size; + } + + /* + * If peer does not support the busaccess base extensions, use the + * old layout. For responses, what matters is if we're responding + * to a packet with the extensions. + */ + if (!peer->caps.busaccess_ext_base && !(in->attr & RP_BUS_ATTR_EXT_BAS= E)) { + /* Old layout. */ + assert(in->master_id < UINT16_MAX); + + rp_encode_hdr(&pkt->hdr, in->cmd, in->id, in->dev, + sizeof *pkt_v4_0 - sizeof pkt->hdr + hsize, in->flags); + rp_encode_busaccess_common(pkt_v4_0, in->clk, in->master_id, + in->addr, in->attr, + in->size, in->width, in->stream_width); + return sizeof *pkt_v4_0 + ret_size; + } + + /* Encode the extended fields. */ + pkt->master_id_31_16 =3D cpu_to_be16(in->master_id >> 16); + pkt->master_id_63_32 =3D cpu_to_be32(in->master_id >> 32); + + /* We always put data right after the header. */ + pkt->data_offset =3D cpu_to_be32(sizeof *pkt); + pkt->next_offset =3D 0; + + pkt->byte_enable_offset =3D cpu_to_be32(sizeof *pkt + hsize); + pkt->byte_enable_len =3D cpu_to_be32(in->byte_enable_len); + hsize +=3D in->byte_enable_len; + + rp_encode_hdr(&pkt->hdr, in->cmd, in->id, in->dev, + sizeof *pkt - sizeof pkt->hdr + hsize, in->flags); + rp_encode_busaccess_common(pkt_v4_0, in->clk, in->master_id, in->addr, + in->attr | RP_BUS_ATTR_EXT_BASE, + in->size, in->width, in->stream_width); + + return sizeof *pkt + ret_size; +} + void rp_process_caps(struct rp_peer_state *peer, void *caps, size_t caps_len) { @@ -172,6 +323,7 @@ void rp_process_caps(struct rp_peer_state *peer, } } =20 + void rp_dpkt_alloc(RemotePortDynPkt *dpkt, size_t size) { if (dpkt->size < size) { diff --git a/include/hw/core/remote-port-proto.h b/include/hw/core/remote-p= ort-proto.h index ca1ab2f1d3..f65f82195d 100644 --- a/include/hw/core/remote-port-proto.h +++ b/include/hw/core/remote-port-proto.h @@ -350,6 +350,134 @@ rp_encode_hello(uint32_t id, uint32_t dev, struct rp_= pkt_hello *pkt, NULL, NULL, 0); } =20 +static inline void *__attribute__ ((deprecated)) +rp_busaccess_dataptr(struct rp_pkt_busaccess *pkt) +{ + /* Right after the packet. */ + return pkt + 1; +} + +/* + * rp_busaccess_rx_dataptr + * + * Predicts the dataptr for a packet to be transmitted. + * This should only be used if you are trying to keep + * the entire packet in a linear buffer. + */ +static inline unsigned char * +rp_busaccess_tx_dataptr(struct rp_peer_state *peer, + struct rp_pkt_busaccess_ext_base *pkt) +{ + unsigned char *p =3D (unsigned char *) pkt; + + if (peer->caps.busaccess_ext_base) { + /* We always put our data right after the header. */ + return p + sizeof *pkt; + } else { + /* Right after the old packet layout. */ + return p + sizeof(struct rp_pkt_busaccess); + } +} + +/* + * rp_busaccess_rx_dataptr + * + * Extracts the dataptr from a received packet. + */ +static inline unsigned char * +rp_busaccess_rx_dataptr(struct rp_peer_state *peer, + struct rp_pkt_busaccess_ext_base *pkt) +{ + unsigned char *p =3D (unsigned char *) pkt; + + if (pkt->attributes & RP_BUS_ATTR_EXT_BASE) { + return p + pkt->data_offset; + } else { + /* Right after the old packet layout. */ + return p + sizeof(struct rp_pkt_busaccess); + } +} + +static inline unsigned char * +rp_busaccess_byte_en_ptr(struct rp_peer_state *peer, + struct rp_pkt_busaccess_ext_base *pkt) +{ + unsigned char *p =3D (unsigned char *) pkt; + + if ((pkt->attributes & RP_BUS_ATTR_EXT_BASE) + && pkt->byte_enable_len) { + assert(pkt->byte_enable_offset >=3D sizeof *pkt); + assert(pkt->byte_enable_offset + pkt->byte_enable_len + <=3D pkt->hdr.len + sizeof pkt->hdr); + return p + pkt->byte_enable_offset; + } + return NULL; +} + +size_t __attribute__ ((deprecated)) +rp_encode_read(uint32_t id, uint32_t dev, + struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t size, + uint32_t width, uint32_t stream_width); + +size_t __attribute__ ((deprecated)) +rp_encode_read_resp(uint32_t id, uint32_t dev, + struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t size, + uint32_t width, uint32_t stream_width); + +size_t __attribute__ ((deprecated)) +rp_encode_write(uint32_t id, uint32_t dev, + struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t size, + uint32_t width, uint32_t stream_width); + +size_t __attribute__ ((deprecated)) +rp_encode_write_resp(uint32_t id, uint32_t dev, + struct rp_pkt_busaccess *pkt, + int64_t clk, uint16_t master_id, + uint64_t addr, uint64_t attr, uint32_t size, + uint32_t width, uint32_t stream_width); + +struct rp_encode_busaccess_in { + uint32_t cmd; + uint32_t id; + uint32_t flags; + uint32_t dev; + int64_t clk; + uint64_t master_id; + uint64_t addr; + uint64_t attr; + uint32_t size; + uint32_t width; + uint32_t stream_width; + uint32_t byte_enable_len; +}; + +/* Prepare encode_busaccess input parameters for a packet response. */ +static inline void +rp_encode_busaccess_in_rsp_init(struct rp_encode_busaccess_in *in, + struct rp_pkt *pkt) { + memset(in, 0, sizeof *in); + in->cmd =3D pkt->hdr.cmd; + in->id =3D pkt->hdr.id; + in->flags =3D pkt->hdr.flags | RP_PKT_FLAGS_response; + in->dev =3D pkt->hdr.dev; + /* FIXME: Propagate all master_id fields? */ + in->master_id =3D pkt->busaccess.master_id; + in->addr =3D pkt->busaccess.addr; + in->size =3D pkt->busaccess.len; + in->width =3D pkt->busaccess.width; + in->stream_width =3D pkt->busaccess.stream_width; + in->byte_enable_len =3D 0; +} +size_t rp_encode_busaccess(struct rp_peer_state *peer, + struct rp_pkt_busaccess_ext_base *pkt, + struct rp_encode_busaccess_in *in); + void rp_process_caps(struct rp_peer_state *peer, void *caps, size_t caps_len); =20 @@ -382,4 +510,9 @@ void rp_dpkt_invalidate(RemotePortDynPkt *dpkt); =20 void rp_dpkt_free(RemotePortDynPkt *dpkt); =20 +static inline int rp_get_busaccess_response(struct rp_pkt *pkt) +{ + return (pkt->busaccess_ext_base.attributes & RP_BUS_RESP_MASK) >> + RP_BUS_RESP_SH= IFT; +} #endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321695; cv=none; d=zohomail.com; s=zohoarc; b=a1KrD7JbBqbfZAkDhUFhVXzDZHqi7OMvfPGUEikESqQS4BDKb192mHANg/MgoYHBu7iqu3KqLQ7h+D4RPLT+tYXlVzHx+ZtzD5Lgm3Mio0PN+lm4P6huNNPB7F7Z5IvpYFlNDm0wG1hH1voQbIdUPZDfjeoAocUXVHd1oWQ/HwY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321695; 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=cvKiWELxuJcWRYaqArTcXS0v2Sr7kfuoA6C4G3edWCw=; b=ZCkCZ3DU0EAgxwdKwE4+c27wDm2fF528OTkio71rAXwNkMWPZ2XyZ0M6PyVyG2Wm9ZchRpXDhuS7nqqXj6l4JBJtAUZgG1uiQHEz5hHmAhdeY/PIAKqVL605ppn0kTAxdbjE28//H3qb6qF2krG8PcKePS+a07W1haEDZfB3MDo= 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 1770321695562687.9914207202869; Thu, 5 Feb 2026 12:01:35 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VA-0006Yi-2I; Thu, 05 Feb 2026 14:58:56 -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 1vo5V7-0006XY-Bc for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:53 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5V5-00032V-E0 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:53 -0500 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-42fb2314f52so911970f8f.0 for ; Thu, 05 Feb 2026 11:58:51 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321529; x=1770926329; 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=cvKiWELxuJcWRYaqArTcXS0v2Sr7kfuoA6C4G3edWCw=; b=lul2BWga1UjabqQ3frzPQXkmh+5dRIDYUYKEQOZXnN0PiaxeVy8c0cxrJ5Is63XU+M /UdPinJH5ks1zBX02jucvs4SNAlMYprjNW6DLxWDyF3ygKSEbF4gsdL2F+3/Ew1BkLd1 JqNvxfXvR1FOzvuqbwhpAd4fJPFLLGEwZFdME3d9iDa8NfWt4UdkxnZOaIxTBy0WDwvV pC22iU9SBYnNtHWqGijYTaWrIhuv7+hnQkSdgiH5AhzMV461Q9KYvb5CxmXVe56YCZyJ sR7OkNmYtuNYcySXIMBBaXEe0YMRPb2GOjB97+xsliWdz4WH2JEed9afE3htbHGmTOSK K6Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321529; x=1770926329; 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=cvKiWELxuJcWRYaqArTcXS0v2Sr7kfuoA6C4G3edWCw=; b=G8TdFD4LHDfXH1wrJ02EJyiEy33i22jxKccmjz9sVuC/UndOlHMpkAlMgjmZSKg4/0 OycAweUxF1Tw6JYYKyOnKwOdcUEGS3GbD1vlZuOzlm/IdScTe+pv8ryIN0N4buY6JLnc SzsrKmkP8soY0gPffThuDMWuwieDbpVHj/NTpsPLXyUxFfLLIAQU2GWn7+r7Lt12rT5c tN1a7qhNAByGPY2deEn3Lepf0fdfuzxeIivNvYCS+G3u0slW/eHZGzPj7Taj9HGy4xOe VPlYaVt9OMGl1EkpZnhdQpuQFjPeGP7E3l5csjRwIkkOOanl28PRKuC9whUT9hdRYicc VbGQ== X-Gm-Message-State: AOJu0Yw3KOQykfp8jp8Dsf0Z4JZ4rZUSO15cCWaD9VKrX/pQcAE/QlVh FqcWfqFw+VpVjLowzcTNQzqEGgGKkxr89LKoCX6hZcGetyg1n7TEYs+n/GFFjClt9x4= X-Gm-Gg: AZuq6aJOxODh2a1RJ3XCPCQmh0pADHzCE4cGlkULsv50BSaT/fz2KJ4Zjuy8BEicVHY NG2M8hhdTOI1k9me4SxtAqepxTdPWv8O/tjxY/ad9brGL0mwCQLRNpJ58wRGKWvn5/i4gtpiCnG 5iRW1Eviwb3nOZgCia4IOqekEKcQ4SLSFjn1UBOVCXWLUnxzv6SuWbB3t5AXy4SgIv3E/XGFBDw 73e4PxPHlx+PNkvDO1WowIA4UpyrLpKTwWQWe+DSawBxcBvlExELNqyKP2oA+vxnPhZC788Cq41 5iRhI8aK3LnpkXMRBvjIzJtezhF3HpBzHtFxLPn50ggumKg6jxwfPWdUXkc2J0RFeKPkst/U5Vl UDEba0j7Zh3iTld/8RvEiO/ruIpTPUn3Vr4a91mJSKu8IdK1JreHQGZI9FiIsBhrDmkIzlD1pJJ FfMwcXw5T2NksZeHjoMJs= X-Received: by 2002:a05:6000:220c:b0:436:1a40:a6ae with SMTP id ffacd0b85a97d-4362923ed58mr793959f8f.15.1770321529519; Thu, 05 Feb 2026 11:58:49 -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 05/29] hw/core: Implement Remote Port irq, sync and ATS helpers Date: Thu, 5 Feb 2026 20:58:00 +0100 Message-ID: <20260205195824.2610192-6-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::42c; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42c.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=unavailable 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: 1770321697671158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko The patch add support for encoding and decoding of following commands: - RP_CMD_interrupt: propagate gpio and interrupt lines changes to external peers - RP_CMD_sync: support for synchronization between QEMU and the remote model - RP_CMD_ats_*: handling iommu transactoin request and invalidation accross the link. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-proto.c | 100 ++++++++++++++++++++++++++++ include/hw/core/remote-port-proto.h | 29 ++++++++ 2 files changed, 129 insertions(+) diff --git a/hw/core/remote-port-proto.c b/hw/core/remote-port-proto.c index 33a6769087..65551ad281 100644 --- a/hw/core/remote-port-proto.c +++ b/hw/core/remote-port-proto.c @@ -131,6 +131,24 @@ int rp_decode_payload(struct rp_pkt *pkt) } pkt->busaccess.master_id =3D master_id; break; + case RP_CMD_interrupt: + pkt->interrupt.timestamp =3D be64_to_cpu(pkt->interrupt.timestamp); + pkt->interrupt.vector =3D be64_to_cpu(pkt->interrupt.vector); + pkt->interrupt.line =3D be32_to_cpu(pkt->interrupt.line); + pkt->interrupt.val =3D pkt->interrupt.val; + used +=3D pkt->hdr.len; + break; + case RP_CMD_sync: + pkt->sync.timestamp =3D be64_to_cpu(pkt->interrupt.timestamp); + used +=3D pkt->hdr.len; + break; + case RP_CMD_ats_req: + case RP_CMD_ats_inv: + pkt->ats.attributes =3D be64_to_cpu(pkt->ats.attributes); + pkt->ats.addr =3D be64_to_cpu(pkt->ats.addr); + pkt->ats.len =3D be64_to_cpu(pkt->ats.len); + pkt->ats.result =3D be32_to_cpu(pkt->ats.result); + break; default: break; } @@ -294,6 +312,88 @@ size_t rp_encode_busaccess(struct rp_peer_state *peer, return sizeof *pkt + ret_size; } =20 +size_t rp_encode_interrupt_f(uint32_t id, uint32_t dev, + struct rp_pkt_interrupt *pkt, + int64_t clk, + uint32_t line, uint64_t vector, uint8_t val, + uint32_t flags) +{ + rp_encode_hdr(&pkt->hdr, RP_CMD_interrupt, id, dev, + sizeof *pkt - sizeof pkt->hdr, flags); + pkt->timestamp =3D cpu_to_be64(clk); + pkt->vector =3D cpu_to_be64(vector); + pkt->line =3D cpu_to_be32(line); + pkt->val =3D val; + return sizeof *pkt; +} + +size_t rp_encode_interrupt(uint32_t id, uint32_t dev, + struct rp_pkt_interrupt *pkt, + int64_t clk, + uint32_t line, uint64_t vector, uint8_t val) +{ + return rp_encode_interrupt_f(id, dev, pkt, clk, line, vector, val, 0); +} + +static size_t rp_encode_ats_common(uint32_t cmd, uint32_t id, uint32_t dev, + struct rp_pkt_ats *pkt, + int64_t clk, uint64_t attr, uint64_t addr, + uint64_t len, uint64_t result, uint32_t flags) +{ + rp_encode_hdr(&pkt->hdr, cmd, id, dev, + sizeof *pkt - sizeof pkt->hdr, flags); + pkt->timestamp =3D cpu_to_be64(clk); + pkt->attributes =3D cpu_to_be64(attr); + pkt->addr =3D cpu_to_be64(addr); + pkt->len =3D cpu_to_be64(len); + pkt->result =3D cpu_to_be32(result); + return sizeof *pkt; +} + +size_t rp_encode_ats_req(uint32_t id, uint32_t dev, + struct rp_pkt_ats *pkt, + int64_t clk, uint64_t attr, uint64_t addr, + uint64_t len, uint64_t result, uint32_t flags) +{ + return rp_encode_ats_common(RP_CMD_ats_req, id, dev, + pkt, clk, attr, + addr, len, result, flags); +} + +size_t rp_encode_ats_inv(uint32_t id, uint32_t dev, + struct rp_pkt_ats *pkt, + int64_t clk, uint64_t attr, uint64_t addr, + uint64_t len, uint64_t result, uint32_t flags) +{ + return rp_encode_ats_common(RP_CMD_ats_inv, id, dev, + pkt, clk, attr, + addr, len, result, flags); +} + +static size_t rp_encode_sync_common(uint32_t id, uint32_t dev, + struct rp_pkt_sync *pkt, + int64_t clk, uint32_t flags) +{ + rp_encode_hdr(&pkt->hdr, RP_CMD_sync, id, dev, + sizeof *pkt - sizeof pkt->hdr, flags); + pkt->timestamp =3D cpu_to_be64(clk); + return sizeof *pkt; +} + +size_t rp_encode_sync(uint32_t id, uint32_t dev, + struct rp_pkt_sync *pkt, + int64_t clk) +{ + return rp_encode_sync_common(id, dev, pkt, clk, 0); +} + +size_t rp_encode_sync_resp(uint32_t id, uint32_t dev, + struct rp_pkt_sync *pkt, + int64_t clk) +{ + return rp_encode_sync_common(id, dev, pkt, clk, RP_PKT_FLAGS_response); +} + void rp_process_caps(struct rp_peer_state *peer, void *caps, size_t caps_len) { diff --git a/include/hw/core/remote-port-proto.h b/include/hw/core/remote-p= ort-proto.h index f65f82195d..7322e0e357 100644 --- a/include/hw/core/remote-port-proto.h +++ b/include/hw/core/remote-port-proto.h @@ -478,6 +478,35 @@ size_t rp_encode_busaccess(struct rp_peer_state *peer, struct rp_pkt_busaccess_ext_base *pkt, struct rp_encode_busaccess_in *in); =20 +size_t rp_encode_interrupt_f(uint32_t id, uint32_t dev, + struct rp_pkt_interrupt *pkt, + int64_t clk, + uint32_t line, uint64_t vector, uint8_t val, + uint32_t flags); + +size_t rp_encode_interrupt(uint32_t id, uint32_t dev, + struct rp_pkt_interrupt *pkt, + int64_t clk, + uint32_t line, uint64_t vector, uint8_t val); + +size_t rp_encode_sync(uint32_t id, uint32_t dev, + struct rp_pkt_sync *pkt, + int64_t clk); + +size_t rp_encode_sync_resp(uint32_t id, uint32_t dev, + struct rp_pkt_sync *pkt, + int64_t clk); + +size_t rp_encode_ats_req(uint32_t id, uint32_t dev, + struct rp_pkt_ats *pkt, + int64_t clk, uint64_t attr, uint64_t addr, + uint64_t size, uint64_t result, uint32_t flags); + +size_t rp_encode_ats_inv(uint32_t id, uint32_t dev, + struct rp_pkt_ats *pkt, + int64_t clk, uint64_t attr, uint64_t addr, + uint64_t size, uint64_t result, uint32_t flags); + void rp_process_caps(struct rp_peer_state *peer, void *caps, size_t caps_len); =20 --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321711; cv=none; d=zohomail.com; s=zohoarc; b=YGwcB0HF2x6sTT8tSV530Ya+LUwa5krBW6JUN/rBnypkvbYFvR3zef8cVIVF/i/4wsClgZGWiH3iZOLhJITIjXUUxeMPBAt22i56zyrn2D0t1EEyKd525IzvHT6s9c9l33b7Boc3TF5RwrUPOyO5eN0UtlNYqwE+xgT5RWYnCnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321711; 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=vCYp6e1o8/fOhB4Yb7faE7VFCfaYZvUcACOBcpqqyGA=; b=neAdH2pLJtwgarPHYO3v09W7XFA1J7+P+sAVwOPvFm/GuCfVvcPUhQzSRr4/vu35h7jRQk75Sj0c8xZN4WDdcMyhYdxp9lTp1HICiK+Tj+SIVSCrW/wmJfAbzk2DktlvLRlVjXPbs+64NvES99x17bHGVQKqJGap1JhFcRQuqUA= 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 1770321711945169.3917135567749; Thu, 5 Feb 2026 12:01:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VA-0006Z7-KR; Thu, 05 Feb 2026 14:58:56 -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 1vo5V8-0006YI-Si for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:54 -0500 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5V7-00032r-C4 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:54 -0500 Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-42fb2314f52so911985f8f.0 for ; Thu, 05 Feb 2026 11:58:53 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321531; x=1770926331; 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=vCYp6e1o8/fOhB4Yb7faE7VFCfaYZvUcACOBcpqqyGA=; b=VS3Gvh9ELpLrVeJbVZoHxSIAgx5G9Z6DhvEVqd2YREFM+RHkEU/bpxV3Mhz3WLDRn9 eGbm1/sRpWTrbmOLOrAt/4p7SgqhjibyLn1eP4kyQK1G1C44tzrtTlkd/I2ArErYcxU5 4+diH9/+vxYk0onxg+W7wlPbDtoA7rMBwHzjT18QLq4ujYdz4RCkyEoqUv4iE24H+eAl pgrBi1Ash7SuEPzOSnSW0yHcwK0kE5SgdIsFWoZG9sMv9/WKs2vAA18LLmC5+qvlZzBz tNGxIq89bWOSHL4hENeXOgNcse12L787qPMAxoxfegBaF2qq6jajjoL689rQKqzHyQzL sggg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321531; x=1770926331; 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=vCYp6e1o8/fOhB4Yb7faE7VFCfaYZvUcACOBcpqqyGA=; b=o8qcVn9KfUzCTNB/qzMj7M5LDZkj6JTZa9bqmjdYqXoxDlG0oixlrlxajWNIOE5os7 6qurdTOGPEZxLJvfU53Pn8Ifg4VRwwMdJJCLNQzIuIoN55TBn+zSsl89L1W/enPbWamt ekttmVSwNRpBbO3KPiNfwvkK/9X1lnTy4p6apc4b+zPsyV7UQitaEtEU7S2+u93MTem2 2SsvO3xXmpM6J9+HkSEOascxdYc2vbnxmiPGmgeivlYcsZraTVQlp3ePvkQS4ELTs1bi VeQ8Px/5OLe8w2jFO7jrIcjqi5moSFqd6FTV+Q279Pmo+RvRZMGWPgEQEQ5e1wdXKET9 sSVA== X-Gm-Message-State: AOJu0Yw6EYfIy60a/4t3iGGHjGWUAainijLbjWnbIPNtJH7pPHHhJ6L6 zFTNa5rRNyDj/vOTe+TIz39khynS6FZ20Ry5X3f24vZikzeS2X1P5pt1YFMUv48yLEg= X-Gm-Gg: AZuq6aLmyvB8jQWaIZCOQ7Ttxs1FnqZ1vc8snucI1+NJ7J8gBXLDViR2vfJrbnY2DuU twELkqKjQH07Zf3MujAN0QBMeC42gfFCCtXE6DR3NCC/AsiN+jtdqxn0e2AgzOPGaUbYAu6H+bY ixiNeqlWn4eNRo/kA7epJQ+71G5YpAWHGRfs4we38luSmTXJahsRzokPQPvdM5UfhMSnIaLtF4z KGBPo7nd0uCVCBCpAdpH6G+24icrmvqwPbGlYp11jEELDk6It7hncnTzYwgtduS3qgVI8swB1U8 JIFevsEy8j4GU+dale2RQSI39i/Vaa/dHpUXWVo/FRySlqX1AwY7Gpapsgz4XUOt/83F6KCp2Ws lsu5V+NtH0H6NAKmFDxMkkwqgZamxuqAj8Y8gCz8GyZly3ETKhlTRbOCbgGz3WA5kxBWv5itgVD X0CixS3GCNHAE3YIe3ILI= X-Received: by 2002:a05:6000:2303:b0:435:9612:2d24 with SMTP id ffacd0b85a97d-4362937e1d7mr618106f8f.53.1770321531276; Thu, 05 Feb 2026 11:58:51 -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, Paolo Bonzini , "Edgar E . Iglesias" Subject: [PATCH 06/29] system/vl: Introduce -machine-path command line option Date: Thu, 5 Feb 2026 20:58:01 +0100 Message-ID: <20260205195824.2610192-7-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::430; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x430.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=unavailable 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: 1770321713629158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko This patch adds a new command line option `-machine-path` to specify a directory path for shared machine resources. This path is intended to serve as a base directory for devices or subsystems that need to automatically create coordination files, such as Unix domain sockets, particularly in multi-process simulation environments. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- include/system/system.h | 2 ++ qemu-options.hx | 10 ++++++++++ system/vl.c | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/include/system/system.h b/include/system/system.h index 03a2d0e900..0cd012004d 100644 --- a/include/system/system.h +++ b/include/system/system.h @@ -57,6 +57,8 @@ bool is_mlock_on_fault(MlockState); =20 extern MlockState mlock_state; =20 +extern const char *machine_path; + #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name; diff --git a/qemu-options.hx b/qemu-options.hx index 6dd3e04e38..b7dd2a64f0 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -765,6 +765,16 @@ SRST Preallocate memory when using -mem-path. ERST =20 +DEF("machine-path", HAS_ARG, QEMU_OPTION_machine_path, + "-machine-path DIR A directory in which to create machine nodes\n", + QEMU_ARCH_ALL) +SRST +``-machine-path path`` + Selects the machine path. + Multi-arch machine nodes will be created in . + This option also sets -mem-shared-path to the given path. +ERST + DEF("k", HAS_ARG, QEMU_OPTION_k, "-k language use keyboard layout (for example 'fr' for French)\n", QEMU_ARCH_ALL) diff --git a/system/vl.c b/system/vl.c index c890da586c..4750b1cf69 100644 --- a/system/vl.c +++ b/system/vl.c @@ -182,6 +182,7 @@ static QemuPluginList plugin_list =3D QTAILQ_HEAD_INITI= ALIZER(plugin_list); static BlockdevOptionsQueue bdo_queue =3D QSIMPLEQ_HEAD_INITIALIZER(bdo_qu= eue); static bool nographic =3D false; static int mem_prealloc; /* force preallocation of physical target memory = */ +const char *machine_path; static const char *vga_model =3D NULL; static DisplayOptions dpy; static int num_serial_hds; @@ -3128,6 +3129,9 @@ void qemu_init(int argc, char **argv) case QEMU_OPTION_mem_prealloc: mem_prealloc =3D 1; break; + case QEMU_OPTION_machine_path: + machine_path =3D optarg; + break; case QEMU_OPTION_d: log_mask =3D optarg; break; --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321597; cv=none; d=zohomail.com; s=zohoarc; b=BbJCegd7KE6apl1KVQVqCNLxUuX7ViaPwhQS+eUgB44yi4yErIQqWup+tr8ESnzhUDwwjnEOQShysNCmHzvIcwIxrfseVhueWiVzIePRqtB93rcZ9FHia+tgwTzWFW/QBDj1u9C6Z1ckM7C4yt+VibIUcy2wve8/7p0PeilE4Gg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321597; 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=JeekGzv+w1I6deqskFXYc4GF+MRuiD3S4EOMsfhWNfc=; b=PMWwjk4PWtg7Izr0e3/EI09P/6539f+PrSlGmzt3WiTGiy0Y/9rC+MJe4xlSU6JUw30f01qdoqAepLhRFGZAIHhdoGiSj8rQqDzsIkYyOdkTuaZUtUJSB1xOhu64wBgylrtucD699e7HYDETKtxO7kLR4ubUozmDGkaJNQZtFLI= 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 1770321597753305.4669607690947; Thu, 5 Feb 2026 11:59:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VC-0006ab-2k; Thu, 05 Feb 2026 14:58:58 -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 1vo5VA-0006Z2-El for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:56 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5V8-00034E-NA for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:56 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-4359a302794so1019757f8f.1 for ; Thu, 05 Feb 2026 11:58:54 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321533; x=1770926333; 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=JeekGzv+w1I6deqskFXYc4GF+MRuiD3S4EOMsfhWNfc=; b=nA3ZbbGeybPRw2tvZP164jpg4rWwqnCWTmOH3deTNnuyLmmg7bEvuhkzDR+BL2ZkFU MoxRmQ+8sgI/q3RNsAUDisSLjTfUsoP6R+R+4NXVh1ztxFBqexZxJCHPYf4WKUbO3u0P PDCGaRn4KUtIgAqSgpvwSorT+jGgZBcbdUvEaPbrIAPCLl4sp59tiB3E5YOdCZKJqrsY rLSxKEDW8Xu4/n0QAAifEGkxzOMyREF+/XX3F6hG8SIoOFnZ2/waxONLr+sac7siZuqs z2Dr2xii/nKNxTeT8VqlfbaDWpPo0xc+6Y+jKptG9gg8UkS3aMl9hfYJQqiVSrnaAfCc r6kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321533; x=1770926333; 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=JeekGzv+w1I6deqskFXYc4GF+MRuiD3S4EOMsfhWNfc=; b=hv8VuFypom+rvZQlUf15wu21XLd8YfuvwaxQHvxDI8EUnw0M0F3cBwOwleOAznoXBp O45EZlOUzLp0B8mv966MUbxnkYLmNLjTvaBUyHLvECcvRfU5L3GuR7bWxotKCv/i7W2I DsTE8x+O8yEjvgk4sELU4mg7ZEQV/NoQAznZbcuaoIij9ffPWntj2oECUR129beNGVdM jaMl5obvoyZTATWEEFohXu0tfxAExyGRx3hwKi3dAXufbm2UAXonvCHzQm6ixD+DgjWW pxms0UhFVrNYmOsQmkMIJUc5nOJUH+9mIS2X5M6rQ0gBx6j3v4Navz7vMBnVROop99Yz To1w== X-Gm-Message-State: AOJu0YxVj0lysyXtSG9XjBzDfMJHLJ1WDT6exKXInjgYMxIx8y/U55Mg YNZubtDm3YYFHjw06Bp2iQOhfBJpyoomGz5/lpa3S4YMoEuySEX6Gy6p9OQVmTSKdo8= X-Gm-Gg: AZuq6aKkCED3hn2Itv+5sgEeZGbhveljllBahicqH+TG3JNq8ISPpYvGBI+t0TJQftw MaZWOM9qNts3Pww9bBIJfINJU5vwqY7HHD0kzv4f9ntMr50NgpPNluaNRIbE+P0Bqyo06ZVhW2/ ukDKd5ZncEV2I/fzYvxOPj2xZZNXps4oqiTWiwRHGizbrzyZdU8LwyOETW0JxK0G6Im9YskuwbE X0um3EyorFzhz9kGZ/ev9zfHuZ7tcdCIr4HUc9A/YAInEed662YxTSykQNfIwG/RRcz6B5u1jzg P2vSm613uVtNbj0JIE6QUbrds25WZ8mP0vmXLgEpXsV0DMUBElpGPpz1qY3edrafbqm4M//l6NN sNwMrTD/auIY4HYl0iXqX8CTn8pM4AFLZF7Q2U2ITaH5GuLAXZr8Np89JhGcbdH1hTmXAzYNdZX lZRTRqnIZ0vB/xfsPQZFE= X-Received: by 2002:a05:6000:420e:b0:435:a9ad:d21a with SMTP id ffacd0b85a97d-43629380f81mr723561f8f.40.1770321532712; Thu, 05 Feb 2026 11:58:52 -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 07/29] hw/core: Add Remote Port object skeleton Date: Thu, 5 Feb 2026 20:58:02 +0100 Message-ID: <20260205195824.2610192-8-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::431; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x431.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: 1770321599505154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Introduce the QOM skeleton for the Remote Port subsystem. This patch adds main types required for co-simulation: - remote-port: An object that manages the lifecycle of the co-simulation session and will handle the character device backend in future patches. - remote-port-device: An interface that allows other QEMU devices to be connected to the Remote Port. This infrastructure enables QEMU to be linked with external simulators (e.g. SystemC). Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port.c | 140 ++++++++++++++++++++++++++++++++++ include/hw/core/remote-port.h | 67 ++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100644 hw/core/remote-port.c create mode 100644 include/hw/core/remote-port.h diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c new file mode 100644 index 0000000000..c909a825f3 --- /dev/null +++ b/hw/core/remote-port.c @@ -0,0 +1,140 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * QEMU remote attach + * + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * + * This code is licensed under the GNU GPL. + */ + +#include "qemu/osdep.h" +#include "system/system.h" +#include "chardev/char.h" +#include "system/cpus.h" +#include "system/cpu-timers.h" +#include "system/reset.h" +#include "hw/core/sysbus.h" +#include "hw/core/hw-error.h" +#include "qemu/sockets.h" +#include "qemu/thread.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "migration/vmstate.h" +#include "hw/core/qdev-properties.h" +#include "hw/core/qdev-properties-system.h" +#include "qemu/cutils.h" + +#ifndef _WIN32 +#include +#endif + +#include "hw/core/remote-port-proto.h" +#include "hw/core/remote-port.h" + +#define D(x) +#define SYNCD(x) + +#ifndef REMOTE_PORT_ERR_DEBUG +#define REMOTE_PORT_DEBUG_LEVEL 0 +#else +#define REMOTE_PORT_DEBUG_LEVEL 1 +#endif + +#define DB_PRINT_L(level, ...) do { \ + if (REMOTE_PORT_DEBUG_LEVEL > level) { \ + fprintf(stderr, ": %s: ", __func__); \ + fprintf(stderr, ## __VA_ARGS__); \ + } \ +} while (0) + +#define REMOTE_PORT_CLASS(klass) \ + OBJECT_CLASS_CHECK(RemotePortClass, (klass), TYPE_REMOTE_PORT) + + +static void rp_reset(DeviceState *dev) +{ + RemotePort *s =3D REMOTE_PORT(dev); + + if (s->reset_done) { + return; + } + + s->reset_done =3D true; +} + +static void rp_realize(DeviceState *dev, Error **errp) +{ +} + +static void rp_unrealize(DeviceState *dev) +{ + RemotePort *s =3D REMOTE_PORT(dev); + + s->finalizing =3D true; +} + +static const VMStateDescription vmstate_rp =3D { + .name =3D TYPE_REMOTE_PORT, + .version_id =3D 1, + .minimum_version_id =3D 1, + .fields =3D (VMStateField[]) { + VMSTATE_END_OF_LIST(), + } +}; + +static void rp_prop_allow_set_link(const Object *obj, const char *name, + Object *val, Error **errp) +{ +} + +static void rp_init(Object *obj) +{ + RemotePort *s =3D REMOTE_PORT(obj); + int i; + + for (i =3D 0; i < REMOTE_PORT_MAX_DEVS; ++i) { + char *name =3D g_strdup_printf("remote-port-dev%d", i); + object_property_add_link(obj, name, TYPE_REMOTE_PORT_DEVICE, + (Object **)&s->devs[i], + rp_prop_allow_set_link, + OBJ_PROP_LINK_STRONG); + g_free(name); + } +} + +static void rp_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->legacy_reset =3D rp_reset; + dc->realize =3D rp_realize; + dc->unrealize =3D rp_unrealize; + dc->vmsd =3D &vmstate_rp; +} + +static const TypeInfo rp_info =3D { + .name =3D TYPE_REMOTE_PORT, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(RemotePort), + .instance_init =3D rp_init, + .class_init =3D rp_class_init, + .interfaces =3D (InterfaceInfo[]) { + { }, + }, +}; + +static const TypeInfo rp_device_info =3D { + .name =3D TYPE_REMOTE_PORT_DEVICE, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(RemotePortDeviceClass), +}; + +static void rp_register_types(void) +{ + type_register_static(&rp_info); + type_register_static(&rp_device_info); +} + +type_init(rp_register_types) diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h new file mode 100644 index 0000000000..db71071c8e --- /dev/null +++ b/include/hw/core/remote-port.h @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * QEMU remote port. + * + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * + * This code is licensed under the GNU GPL. + */ +#ifndef REMOTE_PORT_H__ +#define REMOTE_PORT_H__ + +#include +#include "hw/core/remote-port-proto.h" +#include "chardev/char.h" +#include "chardev/char-fe.h" +#include "qobject/qdict.h" + +#define TYPE_REMOTE_PORT_DEVICE "remote-port-device" + +#define REMOTE_PORT_DEVICE_CLASS(klass) \ + OBJECT_CLASS_CHECK(RemotePortDeviceClass, (klass), TYPE_REMOTE_PORT_D= EVICE) +#define REMOTE_PORT_DEVICE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(RemotePortDeviceClass, (obj), TYPE_REMOTE_PORT_DEVICE) +#define REMOTE_PORT_DEVICE(obj) \ + INTERFACE_CHECK(RemotePortDevice, (obj), TYPE_REMOTE_PORT_DEVICE) + +typedef struct RemotePort RemotePort; + +typedef struct RemotePortDevice { + /*< private >*/ + Object parent_obj; +} RemotePortDevice; + +typedef struct RemotePortDeviceClass { + /*< private >*/ + InterfaceClass parent_class; + + /*< public >*/ + /** + * ops - operations to perform when remote port packets are recieved f= or + * this device. Function N will be called for a remote port packet with + * cmd =3D=3D N in the header. + * + * @obj - Remote port device to recieve packet + * @pkt - remote port packets + */ + + void (*ops[RP_CMD_max + 1])(RemotePortDevice *obj, struct rp_pkt *pkt); + +} RemotePortDeviceClass; + +#define TYPE_REMOTE_PORT "remote-port" +#define REMOTE_PORT(obj) OBJECT_CHECK(RemotePort, (obj), TYPE_REMOTE_PORT) + +struct RemotePort { + DeviceState parent; + + bool finalizing; + + bool reset_done; + +#define REMOTE_PORT_MAX_DEVS 1024 + RemotePortDevice *devs[REMOTE_PORT_MAX_DEVS]; +}; + +#endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321759; cv=none; d=zohomail.com; s=zohoarc; b=P/rIuVm922XLo0CAPExYLzhGYy/+pKLmq7ZRTFsU5dMvmySTpEb8kC6f5kIh3RJHke2EjkBbJf86V8t+3REaK7I9cEll6bNH2EEmG1OQxZouDsYfVgFOZhtF5yjvWxaglwWJQxWs7rynPNxYiZgpIDn3MPVGzoJ8rKcDA3VC+xA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321759; 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=KJHws2bGwjwBm9rF5KtccgfLM9W22L+zuBOlFcWoRxA=; b=dLL004u/SD+rCZAYn1NwcbtDizE8DzTF6yZH56ggnAbnyC2R+T9foasMPDoiEeSCTLJbmalFqJ7YmyABUYzTgI7UC5OefMzw5QVTQbfv6x0FWIezXscxv4miXakXhPUPJlaC9lNCjbTkNnIJjalWkBDWBvZRugCLkakuBYMVYrE= 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 1770321759008292.7660053682574; Thu, 5 Feb 2026 12:02:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VE-0006cC-HQ; Thu, 05 Feb 2026 14:59:00 -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 1vo5VC-0006bA-Gb for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:58 -0500 Received: from mail-wm1-x32b.google.com ([2a00:1450:4864:20::32b]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VA-00034q-Mb for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:58 -0500 Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-482f2599980so15691165e9.0 for ; Thu, 05 Feb 2026 11:58:56 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321534; x=1770926334; 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=KJHws2bGwjwBm9rF5KtccgfLM9W22L+zuBOlFcWoRxA=; b=GnLcaF/lEwM/Z/assz+xWQzBGfEq3ZyBAxgrr9lOrdmLP62niD6f/e9PZeI+cBdtwm wLYNBQ5KtREOAPVZghg14ERpDmK+Lv8Y0KFzzXc+E6u4C7aksnZNoIwFlLtWOukeN5XC DaeCSJ9DWo3yW/UIVlweGSh7veiiHAIHCjTwDgyr/JQ7PyIXgNBgBgUg0RC8vHN+vxFo 2ne4dRQ2iPJCq7cxAB7DhmM5Y6GcKrhMcseft5QlD9pa5A+2p4v1qirQfv28Ygs72g1y ell4ut/wS4/YkRLtomQN+/SQ5RREfFjxfAFMPUN0F7Ax3IefIcin5oYmVQ6v+SxEX+1k VhOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321535; x=1770926335; 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=KJHws2bGwjwBm9rF5KtccgfLM9W22L+zuBOlFcWoRxA=; b=JgzJjXpNDijnkfA3eUplCJ6Q80abVk532l+yJrLHpGPB6XlgVKixSuMbA+zd9yBkFu WlqSVATJo7WSgYYD/ejWzGEu5FHUON0Qsi/zygZOj5QJ36L+QJsrlySX3aSY9KUe0YD6 v+c4vP8cBBmIqigSAMMI7NAx4Nwb3B1Eczfr2bHVuHWRafbHmN20flWEbSE15BuEM3Jq cdknFfFDnOdJchDl9Osi0ZtXYlHQt7wktn+fsZ+UbPAqhXIKAvHwWwhk0tqSKauR5MOM O0E51XtW1qFpBGoj+Ic7Puhjywx2g2HyneMEZdb/+w5UV7pD9dpQxsr5gP5gKaj0TRON l4QA== X-Gm-Message-State: AOJu0Yzw7HXDRMxIUwJC3Hit0J6lnBJ+gaO6BphjtBtXAHsQya1DlXg5 GfquTDBImSHCXc3QsI7duwtKeFzRmDyldiMAA6rPcvkTq/KJFUs8K46tBjEmrJlZrIw= X-Gm-Gg: AZuq6aIm6d6TdMOINQ+d9bM9zPLDFqFJnHBoMy1dRSckwA0H0kwvpgLrz+rHr6IP5Lt raMHlJh76E8wPbPfLsepbTpIpwFrVmcwLOkosLAfkAm6JtrBpYKA1sOdtNwUaqo1r4/ghqKf7eL NMlOIvkEPArcwV8PaG3rraDiFLIo1n3mSyMpD4AzNDa1hdnQM9l0MmIKV4934ybDiWzNRAtYEVq ES7V/fY/DRjb7bRa96K982kpJIdFvpFRoyYKN3I4NvTvDe/+mSlWYRap++cmRUfCqu8RLxqs5lI kEMv+jSGI7tJzuL0TrZlI9Hi1V6rd9KYsQvr57/1hH+BkHAsVzseWPboW/iu922ug8RnX5P+8iG /iczQMwIPDxM1u2uvJ81Dy/b7goCAc6c32w3yBOe77srWg+od6t1TROyrixBvE2gBoirKlL/RZU IQ9RqW58LnDWJ1YS58NAo= X-Received: by 2002:a05:600c:45cb:b0:477:8985:4036 with SMTP id 5b1f17b1804b1-483201dd216mr8628225e9.1.1770321534470; Thu, 05 Feb 2026 11:58:54 -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 08/29] hw/core: Setup Remote Port I/O channels Date: Thu, 5 Feb 2026 20:58:03 +0100 Message-ID: <20260205195824.2610192-9-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::32b; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x32b.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=unavailable 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: 1770321761414154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Add initialization of communication channels with remote peer. This includes character device backend, which can be configured based on QOM properties or automatic socket creation based on the machine path. The patch also initializes the signaling event pipes. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port.c | 187 ++++++++++++++++++++++++++++++++++ include/hw/core/remote-port.h | 16 +++ 2 files changed, 203 insertions(+) diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c index c909a825f3..5154c1bc2a 100644 --- a/hw/core/remote-port.c +++ b/hw/core/remote-port.c @@ -52,6 +52,58 @@ #define REMOTE_PORT_CLASS(klass) \ OBJECT_CLASS_CHECK(RemotePortClass, (klass), TYPE_REMOTE_PORT) =20 +static char *rp_sanitize_prefix(RemotePort *s) +{ + char *sanitized_name; + char *c; + + sanitized_name =3D g_strdup(s->prefix); + for (c =3D sanitized_name; *c !=3D '\0'; c++) { + if (*c =3D=3D '/') { + *c =3D '_'; + } + } + return sanitized_name; +} + +static char *rp_autocreate_chardesc(RemotePort *s, bool server) +{ + char *prefix; + char *chardesc; + int r; + + prefix =3D rp_sanitize_prefix(s); + r =3D asprintf(&chardesc, "unix:%s/qemu-rport-%s%s", + machine_path, prefix, server ? ",wait,server" : ""); + assert(r > 0); + free(prefix); + return chardesc; +} + +static Chardev *rp_autocreate_chardev(RemotePort *s, char *name) +{ + Chardev *chr =3D NULL; + char *chardesc; + char *s_path; + int r; + + r =3D asprintf(&s_path, "%s/qemu-rport-%s", machine_path, + rp_sanitize_prefix(s)); + assert(r > 0); + if (g_file_test(s_path, G_FILE_TEST_EXISTS)) { + chardesc =3D rp_autocreate_chardesc(s, false); + chr =3D qemu_chr_new_noreplay(name, chardesc, false, NULL); + free(chardesc); + } + free(s_path); + + if (!chr) { + chardesc =3D rp_autocreate_chardesc(s, true); + chr =3D qemu_chr_new_noreplay(name, chardesc, false, NULL); + free(chardesc); + } + return chr; +} =20 static void rp_reset(DeviceState *dev) { @@ -66,6 +118,127 @@ static void rp_reset(DeviceState *dev) =20 static void rp_realize(DeviceState *dev, Error **errp) { + RemotePort *s =3D REMOTE_PORT(dev); + int r; + Error *err =3D NULL; + + s->prefix =3D object_get_canonical_path(OBJECT(dev)); + + if (!qemu_chr_fe_get_driver(&s->chr)) { + char *name; + Chardev *chr =3D NULL; + static int nr; + + r =3D asprintf(&name, "rport%d", nr); + nr++; + assert(r > 0); + + if (s->chrdev_id) { + chr =3D qemu_chr_find(s->chrdev_id); + } + + if (chr) { + /* Found the chardev via commandline */ + } else if (s->chardesc) { + chr =3D qemu_chr_new(name, s->chardesc, NULL); + } else { + if (!machine_path) { + error_report("%s: Missing chardesc prop." + " Forgot -machine-path?", + s->prefix); + exit(EXIT_FAILURE); + } + chr =3D rp_autocreate_chardev(s, name); + } + + free(name); + if (!chr) { + error_report("%s: Unable to create remort-port channel %s", + s->prefix, s->chardesc); + exit(EXIT_FAILURE); + } + + qdev_prop_set_chr(dev, "chardev", chr); + s->chrdev =3D chr; + } + +#ifdef _WIN32 + /* + * Create a socket connection between two sockets. We auto-bind + * and read out the port selected by the kernel. + */ + { + char *name; + SocketAddress *sock; + int port; + int listen_sk; + + sock =3D socket_parse("127.0.0.1:0", &error_abort); + listen_sk =3D socket_listen(sock, 1, &error_abort); + + if (s->event.pipe.read < 0) { + perror("socket read"); + exit(EXIT_FAILURE); + } + + { + struct sockaddr_in saddr; + socklen_t slen =3D sizeof saddr; + int r; + + r =3D getsockname(listen_sk, (struct sockaddr *) &saddr, &slen= ); + if (r < 0) { + perror("getsockname"); + exit(EXIT_FAILURE); + } + port =3D htons(saddr.sin_port); + } + + name =3D g_strdup_printf("127.0.0.1:%d", port); + s->event.pipe.write =3D inet_connect(name, &error_abort); + g_free(name); + if (s->event.pipe.write < 0) { + perror("socket write"); + exit(EXIT_FAILURE); + } + + for (;;) { + struct sockaddr_in saddr; + socklen_t slen =3D sizeof saddr; + int fd; + + slen =3D sizeof(saddr); + fd =3D qemu_accept(listen_sk, (struct sockaddr *)&saddr, &slen= ); + if (fd < 0 && errno !=3D EINTR) { + close(listen_sk); + return; + } else if (fd >=3D 0) { + close(listen_sk); + s->event.pipe.read =3D fd; + break; + } + } + + if (!qemu_set_blocking(s->event.pipe.read, false, &err)) { + error_report("%s: Unable to set non-block for internal pipes", + s->prefix); + exit(EXIT_FAILURE); + } + } +#else + if (!g_unix_open_pipe(s->event.pipes, FD_CLOEXEC, NULL)) { + error_report("%s: Unable to create remort-port internal pipes", + s->prefix); + exit(EXIT_FAILURE); + } + + if (!qemu_set_blocking(s->event.pipe.read, false, &err)) { + error_report("%s: Unable to set non-block for internal pipes", + s->prefix); + exit(EXIT_FAILURE); + } + +#endif } =20 static void rp_unrealize(DeviceState *dev) @@ -73,6 +246,13 @@ static void rp_unrealize(DeviceState *dev) RemotePort *s =3D REMOTE_PORT(dev); =20 s->finalizing =3D true; + + info_report("%s: Wait for remote-port to disconnect", s->prefix); + qemu_chr_fe_disconnect(&s->chr); + + close(s->event.pipe.read); + close(s->event.pipe.write); + object_unparent(OBJECT(s->chrdev)); } =20 static const VMStateDescription vmstate_rp =3D { @@ -84,6 +264,12 @@ static const VMStateDescription vmstate_rp =3D { } }; =20 +static Property rp_properties[] =3D { + DEFINE_PROP_CHR("chardev", RemotePort, chr), + DEFINE_PROP_STRING("chardesc", RemotePort, chardesc), + DEFINE_PROP_STRING("chrdev-id", RemotePort, chrdev_id), +}; + static void rp_prop_allow_set_link(const Object *obj, const char *name, Object *val, Error **errp) { @@ -112,6 +298,7 @@ static void rp_class_init(ObjectClass *klass, const voi= d *data) dc->realize =3D rp_realize; dc->unrealize =3D rp_unrealize; dc->vmsd =3D &vmstate_rp; + device_class_set_props_n(dc, rp_properties, ARRAY_SIZE(rp_properties)); } =20 static const TypeInfo rp_info =3D { diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index db71071c8e..0f40018cdb 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -56,8 +56,24 @@ typedef struct RemotePortDeviceClass { struct RemotePort { DeviceState parent; =20 + union { + int pipes[2]; + struct { + int read; + int write; + } pipe; + } event; + Chardev *chrdev; + CharFrontend chr; bool finalizing; =20 + char *chardesc; + char *chrdev_id; + + const char *prefix; + const char *remote_prefix; + + uint32_t current_id; bool reset_done; =20 #define REMOTE_PORT_MAX_DEVS 1024 --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321667; cv=none; d=zohomail.com; s=zohoarc; b=oImuAl3caMNeESMVTe47eTrEkhhzoGdPlfybpXtFqb8ZeyG8SIhgn2fk7dRdB9tx7QqBnhw8Ntc6XFOsr71N2Dw6fipRC+dXeDQ1Sooq5F8860ggdMVBKizjF+5UFoOhzORGnDAYZdweoZD4x2aCuLqC2BOJGIlWpENl/peUjWM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321667; 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=CSJ8tOiInHZajPxuGqsMt9qE3I/cEaWxjUiyrEukxUo=; b=S8K2lZcLADnCPLfxhAUj7Z0QevSo6XpLK1vrHFh7LlIb0acd68BlxEMLWyio08C+Ukm5ffP0zCn3pGznmKKvGkLlGsrUREDnbIdIRtuEVdoNGZDqxUogVEpW9d+yYjf90ciRP3FKZVFHZxtmqQEQhsiMhXW9zKayseBtkCIlDk0= 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 1770321667223141.2110960474197; Thu, 5 Feb 2026 12:01:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VE-0006cE-Nq; Thu, 05 Feb 2026 14:59:00 -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 1vo5VE-0006bp-0o for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:00 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VC-00035D-1h for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:58:59 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-42fbc305552so1427559f8f.0 for ; Thu, 05 Feb 2026 11:58:57 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321536; x=1770926336; 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=CSJ8tOiInHZajPxuGqsMt9qE3I/cEaWxjUiyrEukxUo=; b=AzQeLg+8sHNwBGtQ4jN3JbxSwQgjVExpl1bqZpax1j1NBem7BJ/KnuaFqRs/mmUV13 XQI2/e5BwWreY+8E9lUS8hLeN5RUcqR0uoC2ivKsOUcB++oLrLCQ5/tC4P6g9hwiECcl DHGcSFkUYpQqVUjnF6P2zmEzovrSFRCggO4fTQKyiCih616GHzQe4qzVpA710bDkemOa gTAz3XGUvLmGB6PNVMyiOs1/FiDi4YgNJ/hJgNJVoC7/6M/hy31/ucsnaMWSya+gNcat F5d47GSMagucVUPBvW8lq86imkX4b3SLQfcQ14ZYGcPuZYL1/O1wLv0NR4xEBMt6G5Ab z4Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321536; x=1770926336; 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=CSJ8tOiInHZajPxuGqsMt9qE3I/cEaWxjUiyrEukxUo=; b=FA47F5fxm/s3FG1beo3S6gv9VLJoAO64RVnqLlEkKXgRlHC71UFs6iS843p8I9ZU3x PUf1mVRFuXRBUOW5nHBFIJ5kB3G5Mi1HtmZ1pcCvyzo6op7jK6/Vo1EFoEhNETh40UTo q77Ugk5O4pXWiy8n4oxdNbq8v0kSDClWAlMdVieC04aiYBDvcXwixvsLgp/5EdbvcQnT 69zAGfhySo5rdehvvzScVGE+ayB7rqhJ3OS2prH66SO6BWW03cTxOKwE1QdjdadO68SP fffuIs1hRaigcnV6RhG4rjFyvfNqptPxLO5clWNRaeqQZgLfGmKN5noPQgHEvdVdRKX0 6gKA== X-Gm-Message-State: AOJu0YyuPaYDn6OeGKeb/Csy0BLW3MhvxiY/p2SRLpzrcMf0mUzLJlVt Khmcz5OP9aXwoa7p4zv57n9o6I7wgo4+7yb3AnkhOqSbDCKjhIIds5qISVWN0qK4mYw= X-Gm-Gg: AZuq6aJJ8jkVRWLITZb7Yfk8EzmO78Ene7kHY0cgbe4ihCxSkUez/l4ab/S6SeF/wNU CXx202Q4PUNaX1uXbjnu8uKQAidddks35oPlZQUY/hxtWbdqKef5YBJrl0cFuRHdrsoAdFYanDD 2Pd6APXw7Nds58rg6R9nXmxYLyd7K3XSs0QIuyCGWP2v8iu/s3ALusBRIOFJr6CUB9dkhavRVwe 4Z/j1eDOtqQR13pxX6+4pLxJBzOtT/9dMtlZcjkXD7NEkThmUmu/qTP6CTiRiQyMrfOOvCXO9Yh M92NdxSNSH0G6YogwkeZb21HPYmea73/IAU3Zos5hZsWutVyJq1ouBwZ+ZuNDudHh/I8hKbalPn U6Aai/PHmTnFs8s9U8s/WdUOto/oS8cjMRlPMTDMIVg4dH8sB2WxIrwFTVGpmnHvTYkwO/jzF25 NTnAVXR4BvTcqt3OKdd6o= X-Received: by 2002:a05:6000:250a:b0:435:b089:4f46 with SMTP id ffacd0b85a97d-4362938c2f5mr675837f8f.50.1770321536056; Thu, 05 Feb 2026 11:58:56 -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 09/29] hw/core: Add Remote Port protocol thread and handshake Date: Thu, 5 Feb 2026 20:58:04 +0100 Message-ID: <20260205195824.2610192-10-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::431; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x431.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=unavailable 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: 1770321667957154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Introduce main execution loop for the Remote Port protocol. Creates a dedicated thread to manage the communication lifecycle. This includes logic to read packets and manage RX queue. Patch also implements handshake logic to verify protocol versions and negotiate capabilities with remote peer. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port.c | 190 ++++++++++++++++++++++++++++++++++ include/hw/core/remote-port.h | 22 ++++ 2 files changed, 212 insertions(+) diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c index 5154c1bc2a..91b0682884 100644 --- a/hw/core/remote-port.c +++ b/hw/core/remote-port.c @@ -52,6 +52,88 @@ #define REMOTE_PORT_CLASS(klass) \ OBJECT_CLASS_CHECK(RemotePortClass, (klass), TYPE_REMOTE_PORT) =20 +static void rp_pkt_dump(const char *prefix, const char *buf, size_t len) +{ + qemu_hexdump(stdout, prefix, buf, len); +} + +static void rp_fatal_error(RemotePort *s, const char *reason) +{ + error_report("%s: %s", s->prefix, reason); + exit(EXIT_FAILURE); +} + +static ssize_t rp_recv(RemotePort *s, void *buf, size_t count) +{ + ssize_t r; + + r =3D qemu_chr_fe_read_all(&s->chr, buf, count); + if (r <=3D 0) { + return r; + } + if (r !=3D count) { + error_report("%s: Bad read, expected %zd but got %zd", + s->prefix, count, r); + rp_fatal_error(s, "Bad read"); + } + + return r; +} + +ssize_t rp_write(RemotePort *s, const void *buf, size_t count) +{ + ssize_t r; + + qemu_mutex_lock(&s->write_mutex); + r =3D qemu_chr_fe_write_all(&s->chr, buf, count); + qemu_mutex_unlock(&s->write_mutex); + assert(r =3D=3D count); + if (r <=3D 0) { + error_report("%s: Disconnected r=3D%zd buf=3D%p count=3D%zd", + s->prefix, r, buf, count); + rp_fatal_error(s, "Bad write"); + } + return r; +} + +static void rp_cmd_hello(RemotePort *s, struct rp_pkt *pkt) +{ + s->peer.version =3D pkt->hello.version; + if (pkt->hello.version.major !=3D RP_VERSION_MAJOR) { + error_report("remote-port version missmatch remote=3D%d.%d local= =3D%d.%d", + pkt->hello.version.major, pkt->hello.version.minor, + RP_VERSION_MAJOR, RP_VERSION_MINOR); + rp_fatal_error(s, "Bad version"); + } + + if (pkt->hello.caps.len) { + void *caps =3D (char *) pkt + pkt->hello.caps.offset; + + rp_process_caps(&s->peer, caps, pkt->hello.caps.len); + } +} + +static void rp_say_hello(RemotePort *s) +{ + struct rp_pkt_hello pkt; + uint32_t caps[] =3D { + CAP_BUSACCESS_EXT_BASE, + CAP_BUSACCESS_EXT_BYTE_EN, + CAP_WIRE_POSTED_UPDATES, + CAP_ATS, + }; + size_t len; + + len =3D rp_encode_hello_caps(s->current_id++, 0, &pkt, RP_VERSION_MAJO= R, + RP_VERSION_MINOR, + caps, caps, sizeof caps / sizeof caps[0]); + rp_write(s, (void *) &pkt, len); + + if (sizeof caps) { + rp_write(s, caps, sizeof caps); + } +} + static char *rp_sanitize_prefix(RemotePort *s) { char *sanitized_name; @@ -105,6 +187,108 @@ static Chardev *rp_autocreate_chardev(RemotePort *s, = char *name) return chr; } =20 +static bool rp_pt_process_pkt(RemotePort *s, RemotePortDynPkt *dpkt) +{ + struct rp_pkt *pkt =3D dpkt->pkt; + + D(qemu_log("%s: cmd=3D%x id=3D%d dev=3D%d\n", __func__, pkt->hdr.cmd, + pkt->hdr.id, pkt->hdr.dev)); + + if (pkt->hdr.dev >=3D ARRAY_SIZE(s->devs)) { + /* FIXME: Respond with an error. */ + return true; + } + + switch (pkt->hdr.cmd) { + case RP_CMD_hello: + rp_cmd_hello(s, pkt); + break; + case RP_CMD_read: + case RP_CMD_write: + case RP_CMD_interrupt: + case RP_CMD_ats_req: + case RP_CMD_ats_inv: + /* TBD */; + break; + default: + g_assert_not_reached(); + break; + } + return false; +} + +static int rp_read_pkt(RemotePort *s, RemotePortDynPkt *dpkt) +{ + struct rp_pkt *pkt =3D dpkt->pkt; + int used; + int r; + + r =3D rp_recv(s, pkt, sizeof pkt->hdr); + if (r <=3D 0) { + return r; + } + used =3D rp_decode_hdr((void *) &pkt->hdr); + assert(used =3D=3D sizeof pkt->hdr); + + if (pkt->hdr.len) { + rp_dpkt_alloc(dpkt, sizeof pkt->hdr + pkt->hdr.len); + /* pkt may move due to realloc. */ + pkt =3D dpkt->pkt; + r =3D rp_recv(s, &pkt->hdr + 1, pkt->hdr.len); + if (r <=3D 0) { + return r; + } + rp_decode_payload(pkt); + } + + return used + r; +} + +static void *rp_protocol_thread(void *arg) +{ + RemotePort *s =3D REMOTE_PORT(arg); + unsigned int i; + int r; + + /* Make sure we have a decent bufsize to start with. */ + rp_dpkt_alloc(&s->rsp, sizeof s->rsp.pkt->busaccess + 1024); + for (i =3D 0; i < ARRAY_SIZE(s->rx_queue.pkt); i++) { + rp_dpkt_alloc(&s->rx_queue.pkt[i], + sizeof s->rx_queue.pkt[i].pkt->busaccess + 1024); + s->rx_queue.inuse[i] =3D false; + } + + rp_say_hello(s); + + while (1) { + RemotePortDynPkt *dpkt; + unsigned int wpos =3D s->rx_queue.wpos; + bool handled; + + dpkt =3D &s->rx_queue.pkt[wpos]; + s->rx_queue.inuse[wpos] =3D true; + + r =3D rp_read_pkt(s, dpkt); + if (r <=3D 0) { + /* Disconnected. */ + break; + } + if (0) { + rp_pkt_dump("rport-pkt", (void *) dpkt->pkt, + sizeof dpkt->pkt->hdr + dpkt->pkt->hdr.len); + } + handled =3D rp_pt_process_pkt(s, dpkt); + if (handled) { + s->rx_queue.inuse[wpos] =3D false; + } + } + + if (!s->finalizing) { + rp_fatal_error(s, "Disconnected"); + } + return NULL; +} + static void rp_reset(DeviceState *dev) { RemotePort *s =3D REMOTE_PORT(dev); @@ -113,6 +297,9 @@ static void rp_reset(DeviceState *dev) return; } =20 + qemu_thread_create(&s->thread, "remote-port", rp_protocol_thread, s, + QEMU_THREAD_JOINABLE); + s->reset_done =3D true; } =20 @@ -124,6 +311,8 @@ static void rp_realize(DeviceState *dev, Error **errp) =20 s->prefix =3D object_get_canonical_path(OBJECT(dev)); =20 + qemu_mutex_init(&s->write_mutex); + if (!qemu_chr_fe_get_driver(&s->chr)) { char *name; Chardev *chr =3D NULL; @@ -249,6 +438,7 @@ static void rp_unrealize(DeviceState *dev) =20 info_report("%s: Wait for remote-port to disconnect", s->prefix); qemu_chr_fe_disconnect(&s->chr); + qemu_thread_join(&s->thread); =20 close(s->event.pipe.read); close(s->event.pipe.write); diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index 0f40018cdb..b88e523894 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -56,6 +56,7 @@ typedef struct RemotePortDeviceClass { struct RemotePort { DeviceState parent; =20 + QemuThread thread; union { int pipes[2]; struct { @@ -66,9 +67,28 @@ struct RemotePort { Chardev *chrdev; CharFrontend chr; bool finalizing; + /* To serialize writes to fd. */ + QemuMutex write_mutex; =20 char *chardesc; char *chrdev_id; + struct rp_peer_state peer; + +#define RX_QUEUE_SIZE 1024 + struct { + /* This array must be sized minimum 2 and always a power of 2. */ + RemotePortDynPkt pkt[RX_QUEUE_SIZE]; + bool inuse[RX_QUEUE_SIZE]; + QemuSemaphore sem; + unsigned int wpos; + unsigned int rpos; + } rx_queue; + + /* + * rsp holds responses for the remote side. + * Used by the slave. + */ + RemotePortDynPkt rsp; =20 const char *prefix; const char *remote_prefix; @@ -80,4 +100,6 @@ struct RemotePort { RemotePortDevice *devs[REMOTE_PORT_MAX_DEVS]; }; =20 +ssize_t rp_write(RemotePort *s, const void *buf, size_t count); + #endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321773; cv=none; d=zohomail.com; s=zohoarc; b=U291/OvEyRIwGwhLcml4NCwR+gOG+yWGYO55Q8a666bSNCgHbGg7FnVojCNgzjlI5PIkC60mVYCfB/I7o6ADumkcwnaDGJ1T8kDvReDIbYNUmN4k7nAhIEL8tRVaLyNgJjtezxsMF/iAqbNsAD7iyttaOezPLG8vmpP9HWWHceY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321773; 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=3w+4r91XUMpNZ+u0m8QgKhjEv84szY9BFvzEKdmRv4w=; b=XrzpauWNNR6O5nHHhGpr3svDaa7mSumZz4oTKsV/783GPZDbFlR+e/UmJMaEKZTSiAYg0Qb8xkk7nPtL5iC4LBQaWrwoN9X1Is1VZrRK3P/Ec2VZ2lyfX6oxR0oHBbkLRa0yYQnUqP0WSewwWIlWJgShIheMcl2QmX5EtL6JOnA= 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 1770321773080356.88345221879763; Thu, 5 Feb 2026 12:02:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VH-0006el-JX; Thu, 05 Feb 2026 14:59:03 -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 1vo5VF-0006cd-IS for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:01 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VD-00035X-NL for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:01 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-4806dffc64cso11993045e9.1 for ; Thu, 05 Feb 2026 11:58:59 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321538; x=1770926338; 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=3w+4r91XUMpNZ+u0m8QgKhjEv84szY9BFvzEKdmRv4w=; b=Nr8bFFPz3FfH+ZRFcNov9KL66+302VeS/QAHmsdFyHAg6ljcbZlY4TnFapMMJ2bm2v EZFGlsgGC+3VNbe7k6zq7spoTtynlFjNAEul5pEtFEJ1m7GYhwRskme1t02HlxrbLdwB iyHoc1Y/iN43GHoq54+pEnFQ2KmBrEzQ0X0GnnEcSBjWHZu4isQOwpmlHmKKyYX7jjUh pAKVDGnMR5YviMGFRpUlS1235HGjFgjCwiTGb/SWbZFO4z1oUJ8Sf2l/K0M44Mz1ufph oB9Q2+RTAdOIzLy8g6ICwSqbjGXC2VvZHte9GH7XZUpufenmKFQ39OsEfHTOAM+mOpk6 N3jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321538; x=1770926338; 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=3w+4r91XUMpNZ+u0m8QgKhjEv84szY9BFvzEKdmRv4w=; b=AOfE7Pj6ry2Mgjr8RjaJFeETz02/Hg2pg2/M51FdVPTUTBi9fsPrDS4895XR4COQ7k m7uuyBwqkFqKqDcMxchqyvGTMl2dvM5Dvo81Ok9c1rwfEcoISO0Lel10FDgzD6zgn6bR ehJLmtsv7cbmzbumVdUh8Jw2CGmt7++fgvC/JTgnuG+LF6hP+QNAJqv/g66Az5AXclNm wC+3e/aZOl36KeWUQ10WzB0qdCvwE4yfYmaRgiZVZcdQAFWUhGDhjCP//hVEzoGrNBxF pB5jX5U5hF5hbNZbrIsGlZToBS9EkEhTpUxq6OqCzxb0O/0ovUVE+ylmpUEq95awm7j2 M7pg== X-Gm-Message-State: AOJu0Yxrc1XiBumRe3FMm4xPuw5ZJc0jSi8yWDBv9opWxQsJvjC49uwi mtUWD7RoXFsmhrRnbMz/h4IAq7TOiu0YaphTAmHDWvzEGgHhdyB/+ZzlerK0myhlrqI= X-Gm-Gg: AZuq6aJhtpInTFpyUYeGB711QkuIHukhYUq/n6PnkD9aY05C9SbTH/7aXlKEPHzE9FU MfHujHzdXzoJiDHRmVEezjRx5OaeF7X1rs78oAcECnmil4knl4R1cOfPZlMn5kUZCFMfFQrAUC1 eH75SuOnHdSib5/Q3EuNZuTq3CgP99yH5YXDNXtVXxRVsNkORuYLTffQkSRqEHpzAbqfqWXcyZE taq+1vMOzbsYb7ZLawc1zrAl/aA9Y9QQC2gHmTzu+FjMpfiRm32CIn5whfRSyw0c3dXUbnL7bO5 4vLlvv2DQUhu7T2Tm9IrGiHRO/0vgAisajo9uZ2YbFbTAmu4t2VBihdLdCv4qvQqSR2rN3KbDNV xHIEEPDjhfMkHjp7C6GUTN910szKzbLxn6dwPRUZ0usrXvv3lFJdw0k1tbjAcOBdWsC4zhbPbK5 zRmejIX+6drufJukoLRWk= X-Received: by 2002:a05:600c:5307:b0:480:4a4f:c36f with SMTP id 5b1f17b1804b1-4832096671dmr757915e9.21.1770321537557; Thu, 05 Feb 2026 11:58:57 -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 10/29] hw/core: Implement Remote Port packet dispatch logic Date: Thu, 5 Feb 2026 20:58:05 +0100 Message-ID: <20260205195824.2610192-11-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::32d; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x32d.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=unavailable 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: 1770321775670154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Implement the mechanism to transfer packets from the dedicated protocol thread to the main QEMU execution loop for processing. The patch adds the following features: - signaling logic using internal pipe to wake up the main loop - the rp_process handler, which retrieves packets from queue and dispatches them to the target Remote Port device. This enables QEMU device models to handle remote events. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port.c | 148 +++++++++++++++++++++++++++++++++- include/hw/core/remote-port.h | 5 ++ 2 files changed, 152 insertions(+), 1 deletion(-) diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c index 91b0682884..e44d9249c3 100644 --- a/hw/core/remote-port.c +++ b/hw/core/remote-port.c @@ -52,6 +52,8 @@ #define REMOTE_PORT_CLASS(klass) \ OBJECT_CLASS_CHECK(RemotePortClass, (klass), TYPE_REMOTE_PORT) =20 +static void rp_event_read(void *opaque); + static void rp_pkt_dump(const char *prefix, const char *buf, size_t len) { qemu_hexdump(stdout, prefix, buf, len); @@ -96,6 +98,12 @@ ssize_t rp_write(RemotePort *s, const void *buf, size_t = count) return r; } =20 +static unsigned int rp_has_work(RemotePort *s) +{ + unsigned int work =3D s->rx_queue.wpos - s->rx_queue.rpos; + return work; +} + static void rp_cmd_hello(RemotePort *s, struct rp_pkt *pkt) { s->peer.version =3D pkt->hello.version; @@ -187,6 +195,135 @@ static Chardev *rp_autocreate_chardev(RemotePort *s, = char *name) return chr; } =20 +void rp_process(RemotePort *s) +{ + while (true) { + struct rp_pkt *pkt; + unsigned int rpos; + bool actioned =3D false; + RemotePortDevice *dev; + RemotePortDeviceClass *rpdc; + + qemu_mutex_lock(&s->rsp_mutex); + if (!rp_has_work(s)) { + qemu_mutex_unlock(&s->rsp_mutex); + break; + } + rpos =3D s->rx_queue.rpos; + + pkt =3D s->rx_queue.pkt[rpos].pkt; + D(qemu_log("%s: io-thread rpos=3D%d wpos=3D%d cmd=3D%d dev=3D%d\n", + s->prefix, s->rx_queue.rpos, s->rx_queue.wpos, + pkt->hdr.cmd, pkt->hdr.dev)); + + /* + * To handle recursiveness, we need to advance the index + * index before processing the packet. + */ + s->rx_queue.rpos++; + s->rx_queue.rpos %=3D ARRAY_SIZE(s->rx_queue.pkt); + qemu_mutex_unlock(&s->rsp_mutex); + + dev =3D s->devs[pkt->hdr.dev]; + if (dev) { + rpdc =3D REMOTE_PORT_DEVICE_GET_CLASS(dev); + if (rpdc->ops[pkt->hdr.cmd]) { + rpdc->ops[pkt->hdr.cmd](dev, pkt); + actioned =3D true; + } + } + + switch (pkt->hdr.cmd) { + /* TBD */ + default: + assert(actioned); + } + + s->rx_queue.inuse[rpos] =3D false; + qemu_sem_post(&s->rx_queue.sem); + } +} + +static void rp_event_read(void *opaque) +{ + RemotePort *s =3D REMOTE_PORT(opaque); + unsigned char buf[32]; + ssize_t r; + + /* We don't care about the data. Just read it out to clear the event. = */ + do { +#ifdef _WIN32 + r =3D qemu_recv_wrap(s->event.pipe.read, buf, sizeof buf, 0); +#else + r =3D read(s->event.pipe.read, buf, sizeof buf); +#endif + if (r =3D=3D 0) { + return; + } + } while (r =3D=3D sizeof buf || (r < 0 && errno =3D=3D EINTR)); + + rp_process(s); +} + +static void rp_event_notify(RemotePort *s) +{ + unsigned char d =3D 0; + ssize_t r; + +#ifdef _WIN32 + /* Mingw is sensitive about doing write's to socket descriptors. */ + r =3D qemu_send_wrap(s->event.pipe.write, &d, sizeof d, 0); +#else + r =3D qemu_write_full(s->event.pipe.write, &d, sizeof d); +#endif + if (r =3D=3D 0) { + hw_error("%s: pipe closed\n", s->prefix); + } +} + +/* Handover a pkt to CPU or IO-thread context. */ +static void rp_pt_handover_pkt(RemotePort *s, RemotePortDynPkt *dpkt) +{ + bool full; + + /* + * Take the rsp lock around the wpos update, otherwise + * rp_wait_resp will race with us. + */ + qemu_mutex_lock(&s->rsp_mutex); + s->rx_queue.wpos++; + s->rx_queue.wpos %=3D ARRAY_SIZE(s->rx_queue.pkt); + /* + * Ensure rx_queue index update is visible to consumer + * before signaling event, to prevent lost wakeup + */ + smp_mb(); + rp_event_notify(s); + qemu_cond_signal(&s->progress_cond); + qemu_mutex_unlock(&s->rsp_mutex); + + do { + full =3D s->rx_queue.inuse[s->rx_queue.wpos]; + if (full) { + qemu_log("%s: FULL rx queue %d\n", __func__, s->rx_queue.wpos); + if (qemu_sem_timedwait(&s->rx_queue.sem, 2 * 1000) !=3D 0) { +#ifndef _WIN32 + int sval; + +#ifndef CONFIG_SEM_TIMEDWAIT + sval =3D s->rx_queue.sem.count; +#else + sem_getvalue(&s->rx_queue.sem.sem, &sval); +#endif + qemu_log("semwait: %d rpos=3D%u wpos=3D%u\n", sval, + s->rx_queue.rpos, s->rx_queue.wpos); +#endif + qemu_log("Deadlock?\n"); + } + } + } while (full); +} + static bool rp_pt_process_pkt(RemotePort *s, RemotePortDynPkt *dpkt) { struct rp_pkt *pkt =3D dpkt->pkt; @@ -208,7 +345,7 @@ static bool rp_pt_process_pkt(RemotePort *s, RemotePort= DynPkt *dpkt) case RP_CMD_interrupt: case RP_CMD_ats_req: case RP_CMD_ats_inv: - /* TBD */; + rp_pt_handover_pkt(s, dpkt); break; default: g_assert_not_reached(); @@ -312,6 +449,8 @@ static void rp_realize(DeviceState *dev, Error **errp) s->prefix =3D object_get_canonical_path(OBJECT(dev)); =20 qemu_mutex_init(&s->write_mutex); + qemu_mutex_init(&s->rsp_mutex); + qemu_cond_init(&s->progress_cond); =20 if (!qemu_chr_fe_get_driver(&s->chr)) { char *name; @@ -413,6 +552,7 @@ static void rp_realize(DeviceState *dev, Error **errp) s->prefix); exit(EXIT_FAILURE); } + qemu_set_fd_handler(s->event.pipe.read, rp_event_read, NULL, s); } #else if (!g_unix_open_pipe(s->event.pipes, FD_CLOEXEC, NULL)) { @@ -427,7 +567,10 @@ static void rp_realize(DeviceState *dev, Error **errp) exit(EXIT_FAILURE); } =20 + qemu_set_fd_handler(s->event.pipe.read, rp_event_read, NULL, s); #endif + + qemu_sem_init(&s->rx_queue.sem, ARRAY_SIZE(s->rx_queue.pkt) - 1); } =20 static void rp_unrealize(DeviceState *dev) @@ -436,6 +579,9 @@ static void rp_unrealize(DeviceState *dev) =20 s->finalizing =3D true; =20 + /* Unregister handler. */ + qemu_set_fd_handler(s->event.pipe.read, NULL, NULL, s); + info_report("%s: Wait for remote-port to disconnect", s->prefix); qemu_chr_fe_disconnect(&s->chr); qemu_thread_join(&s->thread); diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index b88e523894..21dfbe89cd 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -74,6 +74,9 @@ struct RemotePort { char *chrdev_id; struct rp_peer_state peer; =20 + QemuMutex rsp_mutex; + QemuCond progress_cond; + #define RX_QUEUE_SIZE 1024 struct { /* This array must be sized minimum 2 and always a power of 2. */ @@ -100,6 +103,8 @@ struct RemotePort { RemotePortDevice *devs[REMOTE_PORT_MAX_DEVS]; }; =20 +void rp_process(RemotePort *s); + ssize_t rp_write(RemotePort *s, const void *buf, size_t count); =20 #endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321597; cv=none; d=zohomail.com; s=zohoarc; b=dPGFI8QC+UlYV6HH9kv124dhULYzijUyjz8ejXfwuE/FqTU2yL2U9RQRz6uvi21CAcHnURlzN609gMOtQdPxVXgNhOi5rYehCW9RpCVepPTIMjM3UbQwgOda+qwrQ+ZvmCFezLEePwk1Ck89DuN+Wkwos1u9Pl/wwDXpOoYNqr0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321597; 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=df/wFs+q0Kaqn119+4MxF9ugWU2c1oPewnTOVYoyE5k=; b=MoW1lN8/MLfR1RTMULwKYB8IQ4Ik9APvPEEiwjwpHdoUQgpucTEWk6uzw21zLi31+wpMat9bZ6Hy+ohlI1uF8NrOkaN/0NJXi/1GR5dTzAPo2IY+gVU0SEFsG/0t2pT2vY90zYBCWJwv9kc9BJ4m6nsrasxHy+pB6jO/USCpTm4= 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 17703215978411007.178611179296; Thu, 5 Feb 2026 11:59:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VJ-0006i2-5d; Thu, 05 Feb 2026 14:59:05 -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 1vo5VH-0006eV-Cl for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:03 -0500 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VF-00035x-Ip for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:03 -0500 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-4362507f396so846559f8f.0 for ; Thu, 05 Feb 2026 11:59:01 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:58:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321539; x=1770926339; 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=df/wFs+q0Kaqn119+4MxF9ugWU2c1oPewnTOVYoyE5k=; b=DZAr8CVi8yZrUN7thYQlMAnwtgba8g+M/Ei8He6yI33I/wc7RAwmxFOVAH7iUMw9cb pl2KihRiyiOQtz/m4u4HnuTgQ+USrWUDZDgYsgsxYWTowxca6/Ii6/lKQIWuVUAyNE8Y ko6shiwvUkmXcD2BdQgTkrdNIcRXXXOGWytoZMhYitkoqye37b3IVskjOryZ0jrRTI99 crxz/mqPcWvVSHERvM6a7J3QYPHS3TVO5kQY8nOewS+QOmagWpcQdJeGZCUVHTzxv/F1 nzzSK5R7q6FJciXJJ3iWYoPMO8EVbZVVf+HXcPMn7wjWITBLAEQ+o7qWTCMG+EavFe7l 3sSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321539; x=1770926339; 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=df/wFs+q0Kaqn119+4MxF9ugWU2c1oPewnTOVYoyE5k=; b=EBWw8idFfYq+qDRAOih23Lsxsvfd4EJYBcAqzQ9FvEtXaCmOI1Hq4AxZY5azfaUGIK 3GifAm42VweL8zLgO7xWZQo6iGCEJ8qnsYjbYXmwT6cJ/8LYmrKJpFmyMzFuOuBYZTPM nuDnxrk/fV4oMqzZDJ1/Mf7jJw2rFqGnTJH38yimg/JnPGUQ0RjbRbrzI1IyTlKUjFO5 FB41nooPeSGaM2uaf04US7WjQG2/wUEOJMCAKV1TMnU3GXNFjedTE2dY8VcA5fwFfYJw fyY8CE8QhNPh4ZoY/YLz5Ov4XbZxsDY2jZIyaZK8GURpesuNa9tSurOyibHslZxMb6E/ j9LA== X-Gm-Message-State: AOJu0Ywv0tBSRG28mLlP0f+PvS1MbGiV/e0uHvpM2AvSiVHtzvWrLdxb BnPVlxQe5O+O3sq4Swvb28q4SFNhBzPLCzu7177M+0K9vQaxtP9UvpaCDGyO0vKKRB8= X-Gm-Gg: AZuq6aIMX2+wg2joNehqU2IF2NdAdKGCPXCrTCE+GU/hOrDGqufpTn4Ne/StcpwjHUr E8HrriUCTWdtxSc4DLmow1GNNyo6jtcp+SSyPdImozzK3aB9mKUz/788zDLfJU4DHv5m7J4FPlA E9PdnJUyfcNUpXVzXMSiej/jmJdqmMi2kl0B6mK+dKTStEfzirHtMmwnnUupZCl4K2dnWE2Y3tQ Pp5q/7PlWUc9JKBLd/0sUf6pjOSwk5yd9Np63s9Oz+zvdFxwbBbP0bt5dqesNdmIa3LmcOsTjeN eV1oWymhuAzgiY+iKbIPVMd86tEY4hymeaedlz0xiiYIAuxzkFQOX69o3jbKYW4E1ORzf4iWM6I YdNNd83PAY9VG2KBsPsGf3m3MklWVDcLWGG22a1/7NKqE9Nc85ubDQrgfFtH7tql7JAmZN5B3ls Mo9DQu5LWCyWVlLbFtcyQ= X-Received: by 2002:a5d:584c:0:b0:435:db9b:5883 with SMTP id ffacd0b85a97d-4362933a9b5mr679016f8f.2.1770321539186; Thu, 05 Feb 2026 11:58:59 -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 11/29] hw/core: Implement Remote Port response handling Date: Thu, 5 Feb 2026 20:58:06 +0100 Message-ID: <20260205195824.2610192-12-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::42e; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42e.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=unavailable 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: 1770321599435154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Add infrastructure to handle transaction responses from remote peers. This patch enables QEMU to wait for replies when it initiates a memory access (Read/Write). It implements a mechanism to track outstanding transaction IDs and block the execution thread until the patching response is received. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port.c | 136 +++++++++++++++++++++++++++++++++- include/hw/core/remote-port.h | 29 ++++++++ 2 files changed, 163 insertions(+), 2 deletions(-) diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c index e44d9249c3..00c9529348 100644 --- a/hw/core/remote-port.c +++ b/hw/core/remote-port.c @@ -59,6 +59,16 @@ static void rp_pkt_dump(const char *prefix, const char *= buf, size_t len) qemu_hexdump(stdout, prefix, buf, len); } =20 +void rp_rsp_mutex_lock(RemotePort *s) +{ + qemu_mutex_lock(&s->rsp_mutex); +} + +void rp_rsp_mutex_unlock(RemotePort *s) +{ + qemu_mutex_unlock(&s->rsp_mutex); +} + static void rp_fatal_error(RemotePort *s, const char *reason) { error_report("%s: %s", s->prefix, reason); @@ -104,6 +114,80 @@ static unsigned int rp_has_work(RemotePort *s) return work; } =20 +/* Response handling. */ +RemotePortRespSlot *rp_dev_timed_wait_resp(RemotePort *s, uint32_t dev, + uint32_t id, int timems) +{ + int i; + + assert(s->devs[dev]); + + /* Find a free slot. */ + for (i =3D 0; i < ARRAY_SIZE(s->dev_state[dev].rsp_queue); i++) { + if (s->dev_state[dev].rsp_queue[i].used =3D=3D false) { + break; + } + } + + if (i =3D=3D ARRAY_SIZE(s->dev_state[dev].rsp_queue) || + s->dev_state[dev].rsp_queue[i].used =3D=3D true) { + error_report("Number of outstanding transactions exceeded! %d", + RP_MAX_OUTSTANDING_TRANSACTIONS); + rp_fatal_error(s, "Internal error"); + } + + /* Got a slot, fill it in. */ + s->dev_state[dev].rsp_queue[i].id =3D id; + s->dev_state[dev].rsp_queue[i].valid =3D false; + s->dev_state[dev].rsp_queue[i].used =3D true; + + while (!s->dev_state[dev].rsp_queue[i].valid) { + rp_rsp_mutex_unlock(s); + rp_event_read(s); + rp_rsp_mutex_lock(s); + if (s->dev_state[dev].rsp_queue[i].valid) { + break; + } + if (!rp_has_work(s)) { + if (timems) { + if (!qemu_cond_timedwait(&s->progress_cond, &s->rsp_mutex, + timems)) { + /* + * TimeOut! + */ + break; + } + } else { + qemu_cond_wait(&s->progress_cond, &s->rsp_mutex); + } + } + } + return &s->dev_state[dev].rsp_queue[i]; +} + +RemotePortRespSlot *rp_dev_wait_resp(RemotePort *s, uint32_t dev, uint32_t= id) +{ + return rp_dev_timed_wait_resp(s, dev, id, 0); +} + +RemotePortDynPkt rp_wait_resp(RemotePort *s) +{ + while (!rp_dpkt_is_valid(&s->rspqueue)) { + rp_rsp_mutex_unlock(s); + rp_event_read(s); + rp_rsp_mutex_lock(s); + /* Need to recheck the condition with the rsp lock taken. */ + if (rp_dpkt_is_valid(&s->rspqueue)) { + break; + } + D(qemu_log("%s: wait for progress\n", __func__)); + if (!rp_has_work(s)) { + qemu_cond_wait(&s->progress_cond, &s->rsp_mutex); + } + } + return s->rspqueue; +} + static void rp_cmd_hello(RemotePort *s, struct rp_pkt *pkt) { s->peer.version =3D pkt->hello.version; @@ -328,14 +412,52 @@ static bool rp_pt_process_pkt(RemotePort *s, RemotePo= rtDynPkt *dpkt) { struct rp_pkt *pkt =3D dpkt->pkt; =20 - D(qemu_log("%s: cmd=3D%x id=3D%d dev=3D%d\n", __func__, pkt->hdr.cmd, - pkt->hdr.id, pkt->hdr.dev)); + D(qemu_log("%s: cmd=3D%x id=3D%d dev=3D%d rsp=3D%d\n", __func__, pkt->= hdr.cmd, + pkt->hdr.id, pkt->hdr.dev, + pkt->hdr.flags & RP_PKT_FLAGS_response)); =20 if (pkt->hdr.dev >=3D ARRAY_SIZE(s->devs)) { /* FIXME: Respond with an error. */ return true; } =20 + if (pkt->hdr.flags & RP_PKT_FLAGS_response) { + uint32_t dev =3D pkt->hdr.dev; + uint32_t id =3D pkt->hdr.id; + int i; + + if (pkt->hdr.flags & RP_PKT_FLAGS_posted) { + printf("Drop response for posted packets\n"); + return true; + } + + qemu_mutex_lock(&s->rsp_mutex); + + /* Try to find a per-device slot first. */ + for (i =3D 0; i < ARRAY_SIZE(s->dev_state[dev].rsp_queue); i++) { + if (s->devs[dev] && s->dev_state[dev].rsp_queue[i].used =3D=3D= true + && s->dev_state[dev].rsp_queue[i].id =3D=3D id) { + break; + } + } + + if (i < ARRAY_SIZE(s->dev_state[dev].rsp_queue)) { + /* Found a per device one. */ + assert(s->dev_state[dev].rsp_queue[i].valid =3D=3D false); + + rp_dpkt_swap(&s->dev_state[dev].rsp_queue[i].rsp, dpkt); + s->dev_state[dev].rsp_queue[i].valid =3D true; + + qemu_cond_signal(&s->progress_cond); + } else { + rp_dpkt_swap(&s->rspqueue, dpkt); + qemu_cond_signal(&s->progress_cond); + } + + qemu_mutex_unlock(&s->rsp_mutex); + return true; + } + switch (pkt->hdr.cmd) { case RP_CMD_hello: rp_cmd_hello(s, pkt); @@ -389,6 +511,7 @@ static void *rp_protocol_thread(void *arg) =20 /* Make sure we have a decent bufsize to start with. */ rp_dpkt_alloc(&s->rsp, sizeof s->rsp.pkt->busaccess + 1024); + rp_dpkt_alloc(&s->rspqueue, sizeof s->rspqueue.pkt->busaccess + 1024); for (i =3D 0; i < ARRAY_SIZE(s->rx_queue.pkt); i++) { rp_dpkt_alloc(&s->rx_queue.pkt[i], sizeof s->rx_queue.pkt[i].pkt->busaccess + 1024); @@ -614,6 +737,7 @@ static void rp_prop_allow_set_link(const Object *obj, c= onst char *name, static void rp_init(Object *obj) { RemotePort *s =3D REMOTE_PORT(obj); + int t; int i; =20 for (i =3D 0; i < REMOTE_PORT_MAX_DEVS; ++i) { @@ -623,6 +747,14 @@ static void rp_init(Object *obj) rp_prop_allow_set_link, OBJ_PROP_LINK_STRONG); g_free(name); + + + for (t =3D 0; t < RP_MAX_OUTSTANDING_TRANSACTIONS; t++) { + s->dev_state[i].rsp_queue[t].used =3D false; + s->dev_state[i].rsp_queue[t].valid =3D false; + rp_dpkt_alloc(&s->dev_state[i].rsp_queue[t].rsp, + sizeof s->dev_state[i].rsp_queue[t].rsp.pkt->busaccess + 10= 24); + } } } =20 diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index 21dfbe89cd..c1b21eb573 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -53,6 +53,13 @@ typedef struct RemotePortDeviceClass { #define TYPE_REMOTE_PORT "remote-port" #define REMOTE_PORT(obj) OBJECT_CHECK(RemotePort, (obj), TYPE_REMOTE_PORT) =20 +typedef struct RemotePortRespSlot { + RemotePortDynPkt rsp; + uint32_t id; + bool used; + bool valid; +} RemotePortRespSlot; + struct RemotePort { DeviceState parent; =20 @@ -93,6 +100,13 @@ struct RemotePort { */ RemotePortDynPkt rsp; =20 + /* + * rspqueue holds received responses from the remote side. + * Only one for the moment but it might grow. + * Used by the master. + */ + RemotePortDynPkt rspqueue; + const char *prefix; const char *remote_prefix; =20 @@ -100,9 +114,24 @@ struct RemotePort { bool reset_done; =20 #define REMOTE_PORT_MAX_DEVS 1024 +#define RP_MAX_OUTSTANDING_TRANSACTIONS 32 + struct { + RemotePortRespSlot rsp_queue[RP_MAX_OUTSTANDING_TRANSACTIONS]; + } dev_state[REMOTE_PORT_MAX_DEVS]; + RemotePortDevice *devs[REMOTE_PORT_MAX_DEVS]; }; =20 + +void rp_rsp_mutex_lock(RemotePort *s); +void rp_rsp_mutex_unlock(RemotePort *s); + +RemotePortDynPkt rp_wait_resp(RemotePort *s); + +RemotePortRespSlot *rp_dev_wait_resp(RemotePort *s, uint32_t dev, uint32_t= id); +RemotePortRespSlot *rp_dev_timed_wait_resp(RemotePort *s, uint32_t dev, + uint32_t id, int timems); + void rp_process(RemotePort *s); =20 ssize_t rp_write(RemotePort *s, const void *buf, size_t count); --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321649; cv=none; d=zohomail.com; s=zohoarc; b=f+B4Zx8Z6ZDr+Epz3XcZqccixb+Unm8YtgyFv3WfZfa/2ffLd68ciNSyvURTIlI7r6RA5BVDoTaskrz1SbAldYO2nsAUo3hOfnlAHOnVFpk/okvicPki9eSQzg2Bh96LEAj0BV3ngUFXuHfLL7yBBy6vm8Faqszd/wVajNNYBAA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321649; 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=P9GRLpbU+w5RLZs68eRIVOxMR5IAudT3xSniNO4i5TI=; b=G+0Joy/0I8r7lcocdRI1OD/4HPyLDoXfPRYx5ksx4gvX2DYEkbuvms6eQc6SVoDFBjeSkncQ5HAC6RHeZDCD9jNfzwoK5RsiTTu3f3GbQGckyq5g3SxJ/ARqYG3Q+P+wUdMITx+rLeLAXmW94OSz74xrvK0Uz8bx3J3Yln+w7FQ= 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 1770321649135602.2168107045784; Thu, 5 Feb 2026 12:00:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VK-0006iG-2v; Thu, 05 Feb 2026 14:59:06 -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 1vo5VI-0006gO-Pb for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:04 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VG-00036F-TL for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:04 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-4359108fd24so915083f8f.2 for ; Thu, 05 Feb 2026 11:59:02 -0800 (PST) Received: from thinkpad-t470s.. ([93.140.16.93]) by smtp.googlemail.com with ESMTPSA id ffacd0b85a97d-436297450b4sm514079f8f.34.2026.02.05.11.58.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321541; x=1770926341; 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=P9GRLpbU+w5RLZs68eRIVOxMR5IAudT3xSniNO4i5TI=; b=TSn5wWvaLcvln52i2FtyYJd/KInnGBUKI4O9JfnDwhM0H/YS4fXd4/8HV54En49Hj3 fneAEDMAJjWzlSRib9lpj2N+9iYFuehStMZu8VNGvnubJHsuIR+fwizNyY5xJ8GjDXp3 tNKUbLqUpzq96d1tG0ez4ArJjwAxD2DsOMiC4BbPfW7QxVMOK0bOJ2QQneJhNLqv/QW9 jyu07gDemp+RJDMGLKGaQA82+V4DWCWdAxv5NhAKLFuGxM+Gt/GjF2E9imT5T7akN0Zh cX1CL166ZzeelZNfJpwnK2j35HpwAz3ZLZuMx9dVLWlXXb4h1J0GQ4UKKyZ8E+dI3BOG FKtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321541; x=1770926341; 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=P9GRLpbU+w5RLZs68eRIVOxMR5IAudT3xSniNO4i5TI=; b=XOdIlFb/oDryt9o3UJw/sGgS4Gxi/5j3H8ZSguC8C8hGWaqhHyNmApGXW5lEDutO0T W4WoM3ghvu7N4a5/grekwH9rh0V/9l0WJwihTlLYHCmG8eLA4PqfpC+ItK8QLEiJrqKA +3znxyaAo5Abhy7jiTdByI6LRJGpeL9Z4KlVI+Sb8SpH3p0RLnkeyazu3IOKSkrB10CP zea2tidmr4XIsPwhoUatk28eorg/ffZ6ZCX+SUZyX5aIl3wwkult594rd+/tZQ+Fi1ZM j1q9BaSlr1WWCLeK5T1oBj148oj4H0oYG82OEbJRpwHq7pNeh0dD7qqo7rfbA2FwEljV URjw== X-Gm-Message-State: AOJu0Yy1Y97dzKdLlw7mcahQKYKzJ3WbDjoFZqSgtnG2qCUR9gT9rpAp /52+c7FuYfuijQbMP3gtxtLC6u2qt4YsS/jw+K9EF70H8uBYFWE2PdN4PfclAKrPxQA= X-Gm-Gg: AZuq6aJjqNI8th9QRb2OuHATqQSCO9fDX/1zcMLqJ7rdPUfpoVSRNMzV29beSKpOJ+P +N42j7kio3vWoUoWT2AXL4Sk6DyEFpmqZF5d+n61l0Zhk5EtPRTrRIfXZFbOmu6/i0zcJhq5CxS 6KSHag5gohf3Y3l+aY/A8Rn5E9OdoGxvmZjUc2PTIZocyl2JWKkauDUafraMXGYIH1UlVUkcFJL SfUwCQP9QQ1pTGcs2IkiXXR7kiJ4yKHE4efiWeAZRGJV2FGKTLaVrt2BPiU+ZJgRTK51GZZX0C6 dME6gsCKeSvr9nOjrnAEcaHta8YkSoiF4U73IaUOUehlXWGvQs6JteAbzuwlfP7iY0uTq+cxweq WhL5EJAFFFMiAwpKlkiY257LeQny1B/7Jd5cgZsdIvuznzrJINP6VlRCY37Y9VHuckVhrklwwX3 q2uaRFFSrJakS5RcGkJaU= X-Received: by 2002:a5d:5f83:0:b0:435:a3c5:a526 with SMTP id ffacd0b85a97d-43629658283mr524308f8f.14.1770321540754; Thu, 05 Feb 2026 11:59:00 -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 12/29] hw/core: Implement Remote Port time synchronization Date: Thu, 5 Feb 2026 20:58:07 +0100 Message-ID: <20260205195824.2610192-13-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::429; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x429.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=unavailable 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: 1770321651367158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Add logic to synchronize QEMU's virtual time with the remote peer. The patch uses timers to periodically send sync requests to the peer and handle incoming sync requests to defer the response if the peer is ahead of QEMU's current time. This also adds the 'sync' and 'sync-quantum' QOM properties to configure this behavior. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port.c | 184 +++++++++++++++++++++++++++++++++- include/hw/core/remote-port.h | 15 +++ 2 files changed, 197 insertions(+), 2 deletions(-) diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c index 00c9529348..6a1933a5a6 100644 --- a/hw/core/remote-port.c +++ b/hw/core/remote-port.c @@ -13,6 +13,7 @@ #include "chardev/char.h" #include "system/cpus.h" #include "system/cpu-timers.h" +#include "exec/icount.h" #include "system/reset.h" #include "hw/core/sysbus.h" #include "hw/core/hw-error.h" @@ -53,6 +54,8 @@ OBJECT_CLASS_CHECK(RemotePortClass, (klass), TYPE_REMOTE_PORT) =20 static void rp_event_read(void *opaque); +static void sync_timer_hit(void *opaque); +static void syncresp_timer_hit(void *opaque); =20 static void rp_pkt_dump(const char *prefix, const char *buf, size_t len) { @@ -69,9 +72,42 @@ void rp_rsp_mutex_unlock(RemotePort *s) qemu_mutex_unlock(&s->rsp_mutex); } =20 +int64_t rp_normalized_vmclk(RemotePort *s) +{ + int64_t clk; + + clk =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + clk -=3D s->peer.clk_base; + return clk; +} + +static void rp_restart_sync_timer_bare(RemotePort *s) +{ + if (!s->do_sync) { + return; + } + + if (s->sync.quantum) { + ptimer_stop(s->sync.ptimer); + ptimer_set_limit(s->sync.ptimer, s->sync.quantum, 1); + ptimer_run(s->sync.ptimer, 1); + } +} + +void rp_restart_sync_timer(RemotePort *s) +{ + if (s->doing_sync) { + return; + } + ptimer_transaction_begin(s->sync.ptimer); + rp_restart_sync_timer_bare(s); + ptimer_transaction_commit(s->sync.ptimer); +} + static void rp_fatal_error(RemotePort *s, const char *reason) { - error_report("%s: %s", s->prefix, reason); + int64_t clk =3D rp_normalized_vmclk(s); + error_report("%s: %s clk=3D%" PRIu64 " ns", s->prefix, reason, clk); exit(EXIT_FAILURE); } =20 @@ -205,6 +241,39 @@ static void rp_cmd_hello(RemotePort *s, struct rp_pkt = *pkt) } } =20 +static void rp_cmd_sync(RemotePort *s, struct rp_pkt *pkt) +{ + size_t enclen; + int64_t clk; + int64_t diff; + + assert(!(pkt->hdr.flags & RP_PKT_FLAGS_response)); + + clk =3D rp_normalized_vmclk(s); + diff =3D pkt->sync.timestamp - clk; + + enclen =3D rp_encode_sync_resp(pkt->hdr.id, pkt->hdr.dev, &s->sync.rsp= .sync, + pkt->sync.timestamp); + assert(enclen =3D=3D sizeof s->sync.rsp.sync); + + /* We have temporarily disabled blocking syncs into QEMU. */ + if (diff <=3D 0LL || true) { + /* We are already a head of time. Respond and issue a sync. */ + SYNCD(printf("%s: sync resp %lu\n", s->prefix, pkt->sync.timestamp= )); + rp_write(s, (void *) &s->sync.rsp, enclen); + return; + } + + SYNCD(printf("%s: delayed sync resp - start diff=3D%ld (ts=3D%lu clk= =3D%lu)\n", + s->prefix, pkt->sync.timestamp - clk, pkt->sync.timestamp, clk)); + + ptimer_transaction_begin(s->sync.ptimer_resp); + ptimer_set_limit(s->sync.ptimer_resp, diff, 1); + ptimer_run(s->sync.ptimer_resp, 1); + s->sync.resp_timer_enabled =3D true; + ptimer_transaction_commit(s->sync.ptimer_resp); +} + static void rp_say_hello(RemotePort *s) { struct rp_pkt_hello pkt; @@ -226,6 +295,56 @@ static void rp_say_hello(RemotePort *s) } } =20 +static void rp_say_sync(RemotePort *s, int64_t clk) +{ + struct rp_pkt_sync pkt; + size_t len; + + len =3D rp_encode_sync(s->current_id++, 0, &pkt, clk); + rp_write(s, (void *) &pkt, len); +} + +static void syncresp_timer_hit(void *opaque) +{ + RemotePort *s =3D REMOTE_PORT(opaque); + + s->sync.resp_timer_enabled =3D false; + SYNCD(printf("%s: delayed sync response - send\n", s->prefix)); + rp_write(s, (void *) &s->sync.rsp, sizeof s->sync.rsp.sync); + memset(&s->sync.rsp, 0, sizeof s->sync.rsp); +} + +static void sync_timer_hit(void *opaque) +{ + RemotePort *s =3D REMOTE_PORT(opaque); + int64_t clk; + RemotePortDynPkt rsp; + + clk =3D rp_normalized_vmclk(s); + if (s->sync.resp_timer_enabled) { + SYNCD(printf("%s: sync while delaying a resp! clk=3D%lu\n", + s->prefix, clk)); + s->sync.need_sync =3D true; + rp_restart_sync_timer_bare(s); + return; + } + + /* Sync. */ + s->doing_sync =3D true; + s->sync.need_sync =3D false; + qemu_mutex_lock(&s->rsp_mutex); + /* Send the sync. */ + rp_say_sync(s, clk); + + SYNCD(printf("%s: syncing wait for resp %lu\n", s->prefix, clk)); + rsp =3D rp_wait_resp(s); + rp_dpkt_invalidate(&rsp); + qemu_mutex_unlock(&s->rsp_mutex); + s->doing_sync =3D false; + + rp_restart_sync_timer_bare(s); +} + static char *rp_sanitize_prefix(RemotePort *s) { char *sanitized_name; @@ -318,7 +437,9 @@ void rp_process(RemotePort *s) } =20 switch (pkt->hdr.cmd) { - /* TBD */ + case RP_CMD_sync: + rp_cmd_sync(s, pkt); + break; default: assert(actioned); } @@ -408,6 +529,33 @@ static void rp_pt_handover_pkt(RemotePort *s, RemotePo= rtDynPkt *dpkt) } while (full); } =20 +static bool rp_pt_cmd_sync(RemotePort *s, struct rp_pkt *pkt) +{ + size_t enclen; + int64_t clk; + int64_t diff =3D 0; + struct rp_pkt rsp; + + assert(!(pkt->hdr.flags & RP_PKT_FLAGS_response)); + + if (use_icount) { + clk =3D rp_normalized_vmclk(s); + diff =3D pkt->sync.timestamp - clk; + } + enclen =3D rp_encode_sync_resp(pkt->hdr.id, pkt->hdr.dev, &rsp.sync, + pkt->sync.timestamp); + assert(enclen =3D=3D sizeof rsp.sync); + + if (!use_icount || diff < s->sync.quantum) { + /* We are still OK. */ + rp_write(s, (void *) &rsp, enclen); + return true; + } + + /* We need IO or CPU thread sync. */ + return false; +} + static bool rp_pt_process_pkt(RemotePort *s, RemotePortDynPkt *dpkt) { struct rp_pkt *pkt =3D dpkt->pkt; @@ -462,6 +610,11 @@ static bool rp_pt_process_pkt(RemotePort *s, RemotePor= tDynPkt *dpkt) case RP_CMD_hello: rp_cmd_hello(s, pkt); break; + case RP_CMD_sync: + if (rp_pt_cmd_sync(s, pkt)) { + return true; + } + /* Fall-through. */ case RP_CMD_read: case RP_CMD_write: case RP_CMD_interrupt: @@ -560,6 +713,7 @@ static void rp_reset(DeviceState *dev) qemu_thread_create(&s->thread, "remote-port", rp_protocol_thread, s, QEMU_THREAD_JOINABLE); =20 + rp_restart_sync_timer(s); s->reset_done =3D true; } =20 @@ -571,6 +725,8 @@ static void rp_realize(DeviceState *dev, Error **errp) =20 s->prefix =3D object_get_canonical_path(OBJECT(dev)); =20 + s->peer.clk_base =3D qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); + qemu_mutex_init(&s->write_mutex); qemu_mutex_init(&s->rsp_mutex); qemu_cond_init(&s->progress_cond); @@ -693,6 +849,27 @@ static void rp_realize(DeviceState *dev, Error **errp) qemu_set_fd_handler(s->event.pipe.read, rp_event_read, NULL, s); #endif =20 + + /* + * Pick up the quantum from the local property setup. + * After config negotiation with the peer, sync.quantum value might + * change. + */ + s->sync.quantum =3D s->peer.local_cfg.quantum; + + s->sync.ptimer =3D ptimer_init(sync_timer_hit, s, PTIMER_POLICY_LEGACY= ); + s->sync.ptimer_resp =3D ptimer_init(syncresp_timer_hit, s, + PTIMER_POLICY_LEGACY); + + /* The Sync-quantum is expressed in nano-seconds. */ + ptimer_transaction_begin(s->sync.ptimer); + ptimer_set_freq(s->sync.ptimer, 1000 * 1000 * 1000); + ptimer_transaction_commit(s->sync.ptimer); + + ptimer_transaction_begin(s->sync.ptimer_resp); + ptimer_set_freq(s->sync.ptimer_resp, 1000 * 1000 * 1000); + ptimer_transaction_commit(s->sync.ptimer_resp); + qemu_sem_init(&s->rx_queue.sem, ARRAY_SIZE(s->rx_queue.pkt) - 1); } =20 @@ -727,6 +904,9 @@ static Property rp_properties[] =3D { DEFINE_PROP_CHR("chardev", RemotePort, chr), DEFINE_PROP_STRING("chardesc", RemotePort, chardesc), DEFINE_PROP_STRING("chrdev-id", RemotePort, chrdev_id), + DEFINE_PROP_BOOL("sync", RemotePort, do_sync, false), + DEFINE_PROP_UINT64("sync-quantum", RemotePort, peer.local_cfg.quantum, + 1000000), }; =20 static void rp_prop_allow_set_link(const Object *obj, const char *name, diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index c1b21eb573..1d8b64925a 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -15,6 +15,7 @@ #include "chardev/char.h" #include "chardev/char-fe.h" #include "qobject/qdict.h" +#include "hw/core/ptimer.h" =20 #define TYPE_REMOTE_PORT_DEVICE "remote-port-device" =20 @@ -73,6 +74,8 @@ struct RemotePort { } event; Chardev *chrdev; CharFrontend chr; + bool do_sync; + bool doing_sync; bool finalizing; /* To serialize writes to fd. */ QemuMutex write_mutex; @@ -81,6 +84,15 @@ struct RemotePort { char *chrdev_id; struct rp_peer_state peer; =20 + struct { + ptimer_state *ptimer; + ptimer_state *ptimer_resp; + bool resp_timer_enabled; + bool need_sync; + struct rp_pkt rsp; + uint64_t quantum; + } sync; + QemuMutex rsp_mutex; QemuCond progress_cond; =20 @@ -131,6 +143,9 @@ RemotePortDynPkt rp_wait_resp(RemotePort *s); RemotePortRespSlot *rp_dev_wait_resp(RemotePort *s, uint32_t dev, uint32_t= id); RemotePortRespSlot *rp_dev_timed_wait_resp(RemotePort *s, uint32_t dev, uint32_t id, int timems); +void rp_restart_sync_timer(RemotePort *s); + +int64_t rp_normalized_vmclk(RemotePort *s); =20 void rp_process(RemotePort *s); =20 --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321764; cv=none; d=zohomail.com; s=zohoarc; b=FQRP5asYp8QzpLlnxW15I1o74/ytfAGqDVzkWyDb8ajTvbyrVy8TFsN8uyka7hbwdW3m5KemvMMg86dopQTuKbqQqMHZy47v0HMBHwT4DbdBiJgSmqcb/dSUKApWkj5jqx680RSS6Pf0w0cmEOR6P/UiARxpOy24ZmHphatZh/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321764; 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=5qvuMaHRp0wLKOuMUSBaArgy1/39Q2HJlclOT444aA8=; b=I1+VEdzx2C63qOF9FXL/iG7NotamM8SPQO3k25VQuZeeWOuUkCNjeTH+Ne0DN12JdeTZbm+8vzYmLUSqlkI8XHa8miOiVC3UsxF6BdBuwWtkkpiXBul1l6stQyJyuntMYXxnEIp8phR6r2OL+qRCk938lIkqaebUbQJNIl8gO20= 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 1770321764295918.0941766398539; Thu, 5 Feb 2026 12:02:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VM-0006k4-UF; Thu, 05 Feb 2026 14:59:08 -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 1vo5VK-0006ii-Jq for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:06 -0500 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VJ-00036r-1H for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:06 -0500 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-4362197d174so828581f8f.3 for ; Thu, 05 Feb 2026 11:59:04 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321543; x=1770926343; 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=5qvuMaHRp0wLKOuMUSBaArgy1/39Q2HJlclOT444aA8=; b=jpHbZtTem+jq5SEi4byKQZXOv/h6irGjWKppFzxaB3papJIh241zBCFPuaJ7BKcIQ/ mxjgtDudIy/I56i+/hFZn0NhMTGPcX8VVO8V7vhLH+Jekw1RUdy6jMQbr/m8HBo+ATkO DaprmqrpjgF6ZMNFXQiDgR7FHBQqURmrr+XtvIFZMowdzeoPickVKk3jBy0OhA0yXnfY MltOi/oAnltcEO+kSuDqd9ZSy5w5FDPpS8bc3NJfpFcbZWmSehRgSrqoRfdbO7LiVcSP iBxrN4ejOgn2DCMpXsrRgLXe2m0KRAmTznc8wANjF3hjWwV1hXBFGQlmGeNdQ8xjVhR/ 7ICQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321543; x=1770926343; 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=5qvuMaHRp0wLKOuMUSBaArgy1/39Q2HJlclOT444aA8=; b=pUjQuY9eIpH+iGsIcSN8Pr4OZ3jOx6qmUCrt0Ka1tyav9VhY6PQg1wooHi/Ly1IUy4 yEEOOm3r1nt+QtnJfvRBxHX9R+flRdETaH+AZ7pxasjs1H4Ta9lIzjA4vbCw3tkpWWaQ Bxwm90UWJE/cxjjXhp/UWNphCcCkFOo59KScu0F+l/nTfxitxCFjHsJC0LOxJV9WRl9M LcVf0b9J82NUeUTZdZEwzi8/KjXWt1hlXGlD1PgBWrJWiQJJQk+JeaQioKe4jazZePmE XiHoB/p4dGsqhU77kj/ybV6fdGYK7Grnm8DWMLH+zW4+/wYGNYpVoK1mLwVkGuZmjseF tQYA== X-Gm-Message-State: AOJu0YzyizQsH3jArKX1OHzi0Srmbuy2VVJWBTD9eHdH0Q2Hc1d7EyJv NvlK/pfJrwguyOjSNCfvmp8rrYvtKInWeXCTIvoDd+9xSpb+B1pSUqnVbLLnQCTK2go= X-Gm-Gg: AZuq6aJeYsKhvEl/2dRwY8zqgA2jjUl6bhxSkjwTacTtQw53dbbb0n8AEgYohiN3rS7 jbiRBOLWXvPFIQrcxiqMlOcY/eHeutNhJpQcVd1+A7o0HCKjWnPTu4PSWUxqfW1qjGNufM/7QBk 5ZHFONkVcYBwLG4EfeICER3z+MFaqOw6/4ADl3Txbf+X9vQKD8ghSFQkLaJ9RHMfo2P0Yy4e0Uf CbRj1xTk4kpOqO4oMxtc3UfYVSjqy28jr3w6WqYACGPKLZQ1hGH9gyk03WPZquK6sh6Kd6BNVq9 OiW6SSvqlZDhhmyJg8MFR3L+NxuilmYzj2Cn+MtsNrhjpoFEKNJ0PItasGSm2Sj0sBTkq6esm7x uexoNCBTvGGHLUYar+Uj2sVlUrXDaGrv/1XOdHRKUZMnr5Ao1plDNOalJ2rJqH+f966deOIUMYa d/txcifcFdPH8w0V6vG9IEENqQTXM3lQ== X-Received: by 2002:a05:6000:2889:b0:436:1a24:df81 with SMTP id ffacd0b85a97d-4362904b702mr635949f8f.2.1770321543005; Thu, 05 Feb 2026 11:59:03 -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, Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" Subject: [PATCH 13/29] system/memory: Introduce unified MemoryTransaction and .access callback Date: Thu, 5 Feb 2026 20:58:08 +0100 Message-ID: <20260205195824.2610192-14-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::431; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x431.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=unavailable 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: 1770321767409154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Introduce a unified 'MemoryTransaction' structure to encapsulate all parameters of a memory access, including address, data, size, and attributes. The logic in memory_region_dispatch_read/write is updated to prioritize the new 'access' callback when available. This change simplifies the integration of transaction-based subsystems, such as the Remote Port, by providing a standard container for memory access metadata. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- include/system/memory.h | 23 ++++++++++++++ system/memory.c | 66 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 87 insertions(+), 2 deletions(-) diff --git a/include/system/memory.h b/include/system/memory.h index 0562af3136..e1fb82608d 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -84,6 +84,28 @@ extern unsigned int global_dirty_tracking; =20 typedef struct MemoryRegionOps MemoryRegionOps; =20 +typedef struct MemoryTransaction { + union { + /* + * Data is passed by values up to 64bit sizes. Beyond + * that, a pointer is passed in p8. + * + * Note that p8 has no alignment restrictions. + */ + uint8_t *p8; + uint64_t u64; + uint32_t u32; + uint16_t u16; + uint8_t u8; + } data; + bool rw; + hwaddr addr; + unsigned int size; + MemTxAttrs attr; + void *opaque; +} MemoryTransaction; + + struct ReservedRegion { Range range; unsigned type; @@ -298,6 +320,7 @@ static inline void iommu_notifier_init(IOMMUNotifier *n= , IOMMUNotify fn, * Memory region callbacks */ struct MemoryRegionOps { + MemTxResult (*access)(MemoryTransaction *tr); /* Read from the memory region. @addr is relative to @mr; @size is * in bytes. */ uint64_t (*read)(void *opaque, diff --git a/system/memory.c b/system/memory.c index 0b1462f028..4f62796cd3 100644 --- a/system/memory.c +++ b/system/memory.c @@ -431,6 +431,31 @@ static int get_cpu_index(void) return -1; } =20 +static MemTxResult memory_region_read_accessor_attr(MemoryRegion *mr, + hwaddr addr, + uint64_t *value, + unsigned size, + signed shift, + uint64_t mask, + MemTxAttrs attrs) +{ + MemoryTransaction tr =3D { { 0 } }; + MemTxResult ret; + + if (mr->flush_coalesced_mmio) { + qemu_flush_coalesced_mmio_buffer(); + } + + tr.opaque =3D mr->opaque; + tr.addr =3D addr; + tr.size =3D size; + tr.attr =3D attrs; + ret =3D mr->ops->access(&tr); + *value |=3D (tr.data.u64 & mask) << shift; + + return ret; +} + static MemTxResult memory_region_read_accessor(MemoryRegion *mr, hwaddr addr, uint64_t *value, @@ -476,6 +501,31 @@ static MemTxResult memory_region_read_with_attrs_acces= sor(MemoryRegion *mr, return r; } =20 +static MemTxResult memory_region_write_accessor_attr(MemoryRegion *mr, + hwaddr addr, + uint64_t *value, + unsigned size, + signed shift, + uint64_t mask, + MemTxAttrs attrs) +{ + MemoryTransaction tr =3D { { 0 } }; + + if (mr->flush_coalesced_mmio) { + qemu_flush_coalesced_mmio_buffer(); + } + + tr.opaque =3D mr->opaque; + tr.rw =3D true; + tr.addr =3D addr; + tr.size =3D size; + tr.attr =3D attrs; + tr.data.u64 =3D (*value >> shift) & mask; + trace_memory_region_ops_write(get_cpu_index(), mr, tr.addr, tr.data.u6= 4, + tr.size, memory_region_name(mr)); + return mr->ops->access(&tr); +} + static MemTxResult memory_region_write_accessor(MemoryRegion *mr, hwaddr addr, uint64_t *value, @@ -1603,7 +1653,13 @@ static MemTxResult memory_region_dispatch_read1(Memo= ryRegion *mr, { *pval =3D 0; =20 - if (mr->ops->read) { + if (mr->ops->access) { + return access_with_adjusted_size(addr, pval, size, + mr->ops->impl.min_access_size, + mr->ops->impl.max_access_size, + memory_region_read_accessor_attr, + mr, attrs); + } else if (mr->ops->read) { return access_with_adjusted_size(addr, pval, size, mr->ops->impl.min_access_size, mr->ops->impl.max_access_size, @@ -1698,7 +1754,13 @@ MemTxResult memory_region_dispatch_write(MemoryRegio= n *mr, return MEMTX_OK; } =20 - if (mr->ops->write) { + if (mr->ops->access) { + return access_with_adjusted_size(addr, &data, size, + mr->ops->impl.min_access_size, + mr->ops->impl.max_access_size, + memory_region_write_accessor_attr, + mr, attrs); + } else if (mr->ops->write) { return access_with_adjusted_size(addr, &data, size, mr->ops->impl.min_access_size, mr->ops->impl.max_access_size, --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321672; cv=none; d=zohomail.com; s=zohoarc; b=IpLBIyq0adHRJSC9b7y+IjhuD60uVa/pUxYdYnBKYiZgOTR4nYB7N474e+b6bVPSBUuS1DRdrbeMyIM37bsxCj6wcxhoB6ZuAetDH9R/2XD4uI/vPunLx7lE3ihVPw5GAOV65qL7DcPB9NNSAksXjabXnDoniM7cRNZOd1ga9CQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321672; 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=okCHnQwuhdSjTOfJI68bWJdfyGo5v7fjnvg4A5+IdxA=; b=dedT2CwgByFpr4UTcfA2ShhfAbkvBVo8PeMhJ7+UZayWonNYCtbydoFM0H1Ii7T8JRPzbmzeYqGnqqN09DjnpSmVQt+b4ipbgYIkmFg1I/ta4WOfQdg3efMx9DWaGfsnegMPnu2QRiI4mtff1NtmtE6BAbIRdYRUZiE1dIhs9o4= 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 1770321672312494.9047545092817; Thu, 5 Feb 2026 12:01:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VO-0006kM-Bl; Thu, 05 Feb 2026 14:59:10 -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 1vo5VM-0006jd-E6 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:08 -0500 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VK-00037A-Gi for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:08 -0500 Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-4359108fd24so915109f8f.2 for ; Thu, 05 Feb 2026 11:59:06 -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.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321545; x=1770926345; 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=okCHnQwuhdSjTOfJI68bWJdfyGo5v7fjnvg4A5+IdxA=; b=F8ixgkHd76PM/ZsJQ1C0SXLp5+SGbKtrR4BaY49Qp3ir3H7psfnE6e70rGt49LCF/i 3X2OMMo/uh0hz26tgfNDkIfKasmVH3AqozkIpNiF5jJ0a9joC9+6Eu2MOWkqu+EZh/97 NbJX3rTkQ+xMzbumSqCp8wYkzhf89SfhXOXLGiRDxrfPEoh5Wk+eYKqe2dN1u0hyY7LA Y7/e+5q/R799D3NR7iS6VJ1JzefjJcbeCQc/G6Kmw1dOD/nG70Bvwcl1AXeHzJSIhJyj LpWBZiLsheNOPrQIxQL0ansUWJ3vsEyJIyNroRSKoE2H7gi3oT8lCafKgW5niNz6+LSM Hgqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321545; x=1770926345; 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=okCHnQwuhdSjTOfJI68bWJdfyGo5v7fjnvg4A5+IdxA=; b=k/k8+tz2Pj/mACz37/aH+UqIDejffj7nEWitvoF8a/snAefIVFohvB/zc3Jf3in2Y0 Meo33IVbSaLdOQBDBitpJxJ5VUeQyFuDKIh/aZ5i4zabaDDB6kapavg8hlMoZNWikS6z EdF0bSiuP3MW3U9jZWkVK4FedbE4ITyHYnfX/QljP2ZAVarrZD/pQESVjG3W74RVssVb r7HgCxOD0I4/P7O/AUFY0CUDEzUTedUVZslxyU4hbZkO/iXvhpOLbealOMs9I2uryXYB t9d18QkpXh31Tzo/VXVxdGZ0GT6PahMCbbky0Jh52gKmrv0U5jppB+dljVOBeVivgAyQ VR2Q== X-Gm-Message-State: AOJu0YxudPQxcVV3SkaS/XfY9N8nxgAPmdV2ckNHO5sz2nNeow/54rdT amOowezj3Puvm1iZ9PZ/saaxqZS0BJOFCIhPpEgSZ8rHIT9cPXCUw2rGhsrOzzDG+Cw= X-Gm-Gg: AZuq6aKlBNiyZEaTmDvMCS/cYVbPnGv2uzSBsm6cE6iPhUqNaLhpciMT30UaR+RFaFJ oal1QwzeSO/dzhgkNZpmCMH4/IEJH/jDNcYkCQVfkAiDAaFJATR7UXEngoYheZr78RJ6ncsADkQ 9By1Wl8gpBxrUr5cvVsHlOISe/5w1p0NSEKKuRIICm2yFZgWAym6G2rFPcDpCv1I0TKYYLOYPRY sOg4uGALuVZyZhWT9vCI/m9lWZempzLhBT9s4oEtNr+8+19cnlk6XjbUHnicbxrWeJSZkW5AkuH i5vdy7723OUDGNj9LI4GMdSEjKQLnNwhJ0GshKk43NNrnntoisS+XThgSQbBTy5CpY+OO0RDJNe s3iVKSJK+Rg+HgEH8XAGYhAozPaOPW3wIquI1cj4h6x9JIgeCL4hmEtzKPgBvgG6d9nueniqXmT 0u6CWBpRaEaWKEBqyp0eE= X-Received: by 2002:a05:6000:2c13:b0:435:a0f5:c271 with SMTP id ffacd0b85a97d-4362967ded6mr532453f8f.31.1770321544577; Thu, 05 Feb 2026 11:59:04 -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 14/29] hw/core: Add Remote Port Memory Master object skeleton Date: Thu, 5 Feb 2026 20:58:09 +0100 Message-ID: <20260205195824.2610192-15-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::433; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x433.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=unavailable 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: 1770321673464158501 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Introduce 'remote-port-memory-master' device skeleton. This device exposes a MemoryRegion within QEMU that represents resources located in the external simulator. When implemented fully, read/write accesses to the region will be encapsulated into Remote Port packets and transmitted to the peer. This enables QEMU to map remote peripherals or memory into its own address space. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-memory-master.c | 151 ++++++++++++++++++++ hw/core/remote-port.c | 5 + include/hw/core/remote-port-memory-master.h | 59 ++++++++ include/hw/core/remote-port.h | 2 + 4 files changed, 217 insertions(+) create mode 100644 hw/core/remote-port-memory-master.c create mode 100644 include/hw/core/remote-port-memory-master.h diff --git a/hw/core/remote-port-memory-master.c b/hw/core/remote-port-memo= ry-master.c new file mode 100644 index 0000000000..d714f66ddf --- /dev/null +++ b/hw/core/remote-port-memory-master.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * QEMU remote port memory master. + * + * Copyright (c) 2014 Xilinx Inc + * Written by Edgar E. Iglesias + * + * This code is licensed under the GNU GPL. + */ + +#include "qemu/osdep.h" +#include "system/system.h" +#include "qemu/log.h" +#include "qapi/qmp/qerror.h" +#include "qapi/error.h" +#include "hw/core/sysbus.h" +#include "migration/vmstate.h" +#include "hw/core/qdev-properties.h" +#include "trace.h" + +#include "hw/core/remote-port-proto.h" +#include "hw/core/remote-port.h" +#include "hw/core/remote-port-memory-master.h" + +#ifndef REMOTE_PORT_ERR_DEBUG +#define REMOTE_PORT_DEBUG_LEVEL 0 +#else +#define REMOTE_PORT_DEBUG_LEVEL 1 +#endif + +#define DB_PRINT_L(level, ...) do { \ + if (REMOTE_PORT_DEBUG_LEVEL > level) { \ + fprintf(stderr, ": %s: ", __func__); \ + fprintf(stderr, ## __VA_ARGS__); \ + } \ +} while (0) + +#define REMOTE_PORT_MEMORY_MASTER_PARENT_CLASS \ + object_class_get_parent( \ + object_class_by_name(TYPE_REMOTE_PORT_MEMORY_MASTER)) + +#define RP_MAX_ACCESS_SIZE 4096 + +static MemTxResult rp_access(MemoryTransaction *tr) +{ + /* TBD */ + return MEMTX_OK; +} + +static const MemoryRegionOps rp_ops_template =3D { + .access =3D rp_access, + .valid.max_access_size =3D RP_MAX_ACCESS_SIZE, + .valid.unaligned =3D true, + .impl.max_access_size =3D RP_MAX_ACCESS_SIZE, + .impl.unaligned =3D false, + .endianness =3D DEVICE_LITTLE_ENDIAN, +}; + +static void rp_memory_master_realize(DeviceState *dev, Error **errp) +{ + RemotePortMemoryMaster *s =3D REMOTE_PORT_MEMORY_MASTER(dev); + int i; + + /* Sanity check max access size. */ + if (s->max_access_size > RP_MAX_ACCESS_SIZE) { + error_setg(errp, "%s: max-access-size %d too large! MAX is %d", + TYPE_REMOTE_PORT_MEMORY_MASTER, s->max_access_size, + RP_MAX_ACCESS_SIZE); + return; + } + + if (s->max_access_size < 4) { + error_setg(errp, "%s: max-access-size %d too small! MIN is 4", + TYPE_REMOTE_PORT_MEMORY_MASTER, s->max_access_size); + return; + } + + assert(s->rp); + s->peer =3D rp_get_peer(s->rp); + + /* Create a single static region if configuration says so. */ + if (s->map_num) { + /* Initialize rp_ops from template. */ + s->rp_ops =3D g_malloc(sizeof *s->rp_ops); + memcpy(s->rp_ops, &rp_ops_template, sizeof *s->rp_ops); + s->rp_ops->valid.max_access_size =3D s->max_access_size; + s->rp_ops->impl.max_access_size =3D s->max_access_size; + + s->mmaps =3D g_new0(typeof(*s->mmaps), s->map_num); + for (i =3D 0; i < s->map_num; ++i) { + char *name =3D g_strdup_printf("rp-%d", i); + + s->mmaps[i].offset =3D s->map_offset; + memory_region_init_io(&s->mmaps[i].iomem, OBJECT(dev), s->rp_o= ps, + &s->mmaps[i], name, s->map_size); + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmaps[i].iomem); + s->mmaps[i].parent =3D s; + g_free(name); + } + } +} + +static void rp_prop_allow_set_link(const Object *obj, const char *name, + Object *val, Error **errp) +{ +} + +static void rp_memory_master_init(Object *obj) +{ + RemotePortMemoryMaster *rpms =3D REMOTE_PORT_MEMORY_MASTER(obj); + object_property_add_link(obj, "rp-adaptor0", "remote-port", + (Object **)&rpms->rp, + rp_prop_allow_set_link, + OBJ_PROP_LINK_STRONG); +} + +static Property rp_properties[] =3D { + DEFINE_PROP_UINT32("map-num", RemotePortMemoryMaster, map_num, 0), + DEFINE_PROP_UINT64("map-offset", RemotePortMemoryMaster, map_offset, 0= ), + DEFINE_PROP_UINT64("map-size", RemotePortMemoryMaster, map_size, 0), + DEFINE_PROP_UINT32("rp-chan0", RemotePortMemoryMaster, rp_dev, 0), + DEFINE_PROP_BOOL("relative", RemotePortMemoryMaster, relative, false), + DEFINE_PROP_UINT32("max-access-size", RemotePortMemoryMaster, + max_access_size, RP_MAX_ACCESS_SIZE), +}; + +static void rp_memory_master_class_init(ObjectClass *oc, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(oc); + device_class_set_props_n(dc, rp_properties, ARRAY_SIZE(rp_properties)); + dc->realize =3D rp_memory_master_realize; +} + +static const TypeInfo rp_info =3D { + .name =3D TYPE_REMOTE_PORT_MEMORY_MASTER, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(RemotePortMemoryMaster), + .instance_init =3D rp_memory_master_init, + .class_init =3D rp_memory_master_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_REMOTE_PORT_DEVICE }, + { }, + }, +}; + +static void rp_register_types(void) +{ + type_register_static(&rp_info); +} + +type_init(rp_register_types) diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c index 6a1933a5a6..c783a12153 100644 --- a/hw/core/remote-port.c +++ b/hw/core/remote-port.c @@ -938,6 +938,11 @@ static void rp_init(Object *obj) } } =20 +struct rp_peer_state *rp_get_peer(RemotePort *s) +{ + return &s->peer; +} + static void rp_class_init(ObjectClass *klass, const void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); diff --git a/include/hw/core/remote-port-memory-master.h b/include/hw/core/= remote-port-memory-master.h new file mode 100644 index 0000000000..70f7c38c35 --- /dev/null +++ b/include/hw/core/remote-port-memory-master.h @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * QEMU remote port memory master. Read and write transactions + * recieved from QEMU are transmitted over remote-port. + * + * Copyright (c) 2020 Xilinx Inc + * Written by Edgar E. Iglesias + * + * This code is licensed under the GNU GPL. + */ +#ifndef REMOTE_PORT_MEMORY_MASTER_H +#define REMOTE_PORT_MEMORY_MASTER_H + +#include "hw/core/remote-port.h" + +#define TYPE_REMOTE_PORT_MEMORY_MASTER "remote-port-memory-master" +#define REMOTE_PORT_MEMORY_MASTER(obj) \ + OBJECT_CHECK(RemotePortMemoryMaster, (obj), \ + TYPE_REMOTE_PORT_MEMORY_MASTER) + +typedef struct RemotePortMemoryMaster RemotePortMemoryMaster; + +typedef struct RemotePortMap { + void *parent; + MemoryRegion iomem; + uint32_t rp_dev; + uint64_t offset; +} RemotePortMap; + +struct RemotePortMemoryMaster { + /* private */ + SysBusDevice parent; + + MemoryRegionOps *rp_ops; + RemotePortMap *mmaps; + + /* public */ + uint32_t map_num; + uint64_t map_offset; + uint64_t map_size; + uint32_t rp_dev; + bool relative; + uint32_t max_access_size; + struct RemotePort *rp; + struct rp_peer_state *peer; + int rp_timeout; +}; + +MemTxResult rp_mm_access(RemotePort *rp, uint32_t rp_dev, + struct rp_peer_state *peer, + MemoryTransaction *tr, + bool relative, uint64_t offset); + +MemTxResult rp_mm_access_with_def_attr(RemotePort *rp, uint32_t rp_dev, + struct rp_peer_state *peer, + MemoryTransaction *tr, + bool relative, uint64_t offset, + uint32_t def_attr); +#endif diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index 1d8b64925a..e5dfaf7c3b 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -151,4 +151,6 @@ void rp_process(RemotePort *s); =20 ssize_t rp_write(RemotePort *s, const void *buf, size_t count); =20 +struct rp_peer_state *rp_get_peer(RemotePort *s); + #endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321598; cv=none; d=zohomail.com; s=zohoarc; b=HXL83HJdN+VUjL1RZl20caP8/9hix1irUDFFFwXNUShObY5sCfJzSfHcOKnjFhz83h+FTI+ixpQbaEhD2burV75Hdq6eKEUYrei32axb9dyZsFS1FkWRrxVnmAKDgOR4xqYCq1pWU8hGZAAnYm7VLo0s+TCygsP62stAQLaNWT8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321598; 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=WJgihbxir9TVndoVLKFcaPLnULrfVxu1EQyax/iuZuY=; b=ltidCyNw3mlbx1jdI6JPt7pAkwh9DqOtSWQD4wG+Mpw1CW7KLE7ourqHMfEf1Tf051tSLi7bEmuT3p80hyJUNNs93WmmDtSld0wNoJ2+kNh000u+sYyYMKK+qMa862sK26zUR/PZpXcn1lQUl6gsQFy1hBajs/mmeJXEdbu682g= 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 1770321598809423.08024363956304; Thu, 5 Feb 2026 11:59:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VR-0006n1-Ox; Thu, 05 Feb 2026 14:59:13 -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 1vo5VQ-0006lO-L7 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:12 -0500 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VM-00037U-5P for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:12 -0500 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-47ee76e8656so20249285e9.0 for ; Thu, 05 Feb 2026 11:59:07 -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.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321546; x=1770926346; 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=WJgihbxir9TVndoVLKFcaPLnULrfVxu1EQyax/iuZuY=; b=dxP0q/aN7suTqBcdTW+rHZUGQKT9hWcUakT4BrWXNBAp/LIfEqDnE7YHL3JcJ+niqa IwG5vqWeL/VmfeRzf61C+T+F87kD0ERSKy8MuX7WiZjiq1Sin8f/Lb2viiYwxAmSAiPV ccgCWYQjOobuC8rZg/v/DrqO8G3kNNmuBuKu7Zre6LSLgXbwB32E00Tl4gay77INsdpf GnfWNBf2oPNsn2m1yQEu4MXiZN8l1QjOkO0V9GIDLPNwovTN+ArpSx2mV6AxdI7BMWrE qdHSrsDRS9EnGIYb0XzYnwVj+GLU7xnD5HecCbb7vfvNRGezL/EfhKphkAfOmvGXAzWO 6BvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321546; x=1770926346; 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=WJgihbxir9TVndoVLKFcaPLnULrfVxu1EQyax/iuZuY=; b=XSkOFDi9dgxnsd/PTAN7XFKQwEnrG0YtJ+jIKVeaUGRPPW8VAbYuJ0AStY7cai8ehO +XlPoLNEqjpRfNEFsiHOZOryFF81PvgoVt3IWXT+g5bXZKbIn+9M7HnG0czloZlm1j6Q 2EIJWv0lYxCNR1V6e/z9NPtCoTJTLP0BfbIVRuKbEQFYkNFGzRh+su4FGFcvk3hOag6o 3nqAcKLRkNfgqrVFkH7CMuycO1FJB1+/ksU4abnHV1CcxHQKj3SBFZL6rr4Q3GqfDpdK qLBLj56bSJsfBMLe8oXOwkNYq6iri+aCpr9R3bKS/sT8KIdc9Hq60U5wTNmLeqv6Lg5+ eGJQ== X-Gm-Message-State: AOJu0YyJBDvvdKTf/1IhuWD+DmrUGmls45+6NomJ12YvvV7DCXkmwkaU Q8OZxoB2A4gec4MAgc020wFPrWMnpxFFfzHczngISaHpQi4rjCS/GmWLgT9axMCeUTo= X-Gm-Gg: AZuq6aIDemGreN9D9Nnqm1odCP2crRjxS9xm/93pAFbOLZfAX0DF8ltULtiZ9MoXv50 zKzq9rYYV60nzH3UWoRc5EksF89ksObDUZdXPOXYSeFxm1vL0Cwq4fG9Gj3S2/XUw5VbzfM0gSl yvTughzr08ZzeZtHGtVbofrt1UegxPIlTL92LXWbpOAyjMB2ElzY833v4fiir9ax+fqdsecY8wt 7rfPl0eLmLFJWyTLQJYnKYzLI8d296Z+XnGT1HerXr4QqIHqvV0zQ+dJZfCcdW/4S7wmVML2w04 dnmsLPQCKRAIOl6UuoWroPYS8fneKSDAksp9VShky8Pnv1ocqU/7Sy1AwxKqKUulCOFeuk8CwlA wfyz37LV47keXlQKbDP/TCap5vcFv1wiEi0f2fkopGfmf0h8TtqvB1RfKFtd55KS5nUqcsUEgJ9 5IHkJ8An4ev7er7hip0l5EACQoQ+3dmQ== X-Received: by 2002:a05:600c:6285:b0:47e:e87b:af8 with SMTP id 5b1f17b1804b1-48320231170mr7487375e9.21.1770321546222; Thu, 05 Feb 2026 11:59:06 -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 15/29] hw/core: Implement Remote Port Memory Master bus transactions Date: Thu, 5 Feb 2026 20:58:10 +0100 Message-ID: <20260205195824.2610192-16-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::32a; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x32a.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=unavailable 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: 1770321601553158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Implement the core access handlers for the Remote Port Memory Master device, which enables QEMU to initiate memory-mapped transaction to remote peers. The patch adds support for: - Translation of QEMU MemoryTransactions into Remote Port read/write packets - Support for propagating of transaction attributes (Secure, MasterID) - Synchronous response waiting with optional timeout - Add trace events for monitoring TX/RX bus transactions Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-memory-master.c | 167 +++++++++++++++++++++++++++- hw/core/remote-port.c | 5 + hw/core/trace-events | 4 + include/hw/core/remote-port.h | 11 ++ 4 files changed, 185 insertions(+), 2 deletions(-) diff --git a/hw/core/remote-port-memory-master.c b/hw/core/remote-port-memo= ry-master.c index d714f66ddf..4a6c43423d 100644 --- a/hw/core/remote-port-memory-master.c +++ b/hw/core/remote-port-memory-master.c @@ -41,10 +41,173 @@ =20 #define RP_MAX_ACCESS_SIZE 4096 =20 +static int rp_mm_get_timeout(MemoryTransaction *tr) +{ + RemotePortMap *map =3D tr->opaque; + RemotePortMemoryMaster *s; + + if (!map || !map->parent || + !object_dynamic_cast(OBJECT(map->parent), + TYPE_REMOTE_PORT_MEMORY_MASTER)) { + return 0; + } + s =3D REMOTE_PORT_MEMORY_MASTER(map->parent); + return s->rp_timeout; +} + +MemTxResult rp_mm_access_with_def_attr(RemotePort *rp, uint32_t rp_dev, + struct rp_peer_state *peer, + MemoryTransaction *tr, + bool relative, uint64_t offset, + uint32_t def_attr) +{ + uint64_t addr =3D tr->addr; + RemotePortRespSlot *rsp_slot; + RemotePortDynPkt *rsp; + struct { + struct rp_pkt_busaccess_ext_base pkt; + uint8_t reserved[RP_MAX_ACCESS_SIZE]; + } pay; + uint8_t *data =3D rp_busaccess_tx_dataptr(peer, &pay.pkt); + struct rp_encode_busaccess_in in =3D {0}; + int i; + int len; + int rp_timeout =3D rp_mm_get_timeout(tr); + MemTxResult ret; + + if (rp_timeout) { + return MEMTX_ERROR; + } + DB_PRINT_L(0, "addr: %" HWADDR_PRIx " data: %" PRIx64 "\n", + addr, tr->data.u64); + + if (tr->rw) { + /* Data up to 8 bytes is passed as values. */ + if (tr->size <=3D 8) { + for (i =3D 0; i < tr->size; i++) { + data[i] =3D tr->data.u64 >> (i * 8); + } + } else { + memcpy(data, tr->data.p8, tr->size); + } + } + + addr +=3D relative ? 0 : offset; + + in.cmd =3D tr->rw ? RP_CMD_write : RP_CMD_read; + in.id =3D rp_new_id(rp); + in.dev =3D rp_dev; + in.clk =3D rp_normalized_vmclk(rp); + in.master_id =3D tr->attr.requester_id; + in.addr =3D addr; + in.attr =3D def_attr; + in.attr |=3D tr->attr.secure ? RP_BUS_ATTR_SECURE : 0; + in.size =3D tr->size; + in.stream_width =3D tr->size; + len =3D rp_encode_busaccess(peer, &pay.pkt, &in); + len +=3D tr->rw ? tr->size : 0; + + trace_remote_port_memory_master_tx_busaccess(rp_cmd_to_string(in.cmd), + in.id, in.flags, in.dev, in.addr, in.size, in.attr); + + rp_rsp_mutex_lock(rp); + rp_write(rp, (void *) &pay, len); + + if (!rp_timeout) { + rsp_slot =3D rp_dev_wait_resp(rp, in.dev, in.id); + } else { + rsp_slot =3D rp_dev_timed_wait_resp(rp, in.dev, in.id, rp_timeout); + if (rsp_slot->valid =3D=3D false) { + /* + * Timeout error + */ + rp_rsp_mutex_unlock(rp); + return MEMTX_ERROR; + } + } + rsp =3D &rsp_slot->rsp; + + /* We dont support out of order answers yet. */ + assert(rsp->pkt->hdr.id =3D=3D in.id); + + switch (rp_get_busaccess_response(rsp->pkt)) { + case RP_RESP_OK: + ret =3D MEMTX_OK; + break; + case RP_RESP_ADDR_ERROR: + ret =3D MEMTX_DECODE_ERROR; + break; + default: + ret =3D MEMTX_ERROR; + break; + } + + if (ret =3D=3D MEMTX_OK && !tr->rw) { + data =3D rp_busaccess_rx_dataptr(peer, &rsp->pkt->busaccess_ext_ba= se); + /* Data up to 8 bytes is return as values. */ + if (tr->size <=3D 8) { + for (i =3D 0; i < tr->size; i++) { + tr->data.u64 |=3D ((uint64_t) data[i]) << (i * 8); + } + } else { + memcpy(tr->data.p8, data, tr->size); + } + } + + trace_remote_port_memory_master_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); + + if (rp_timeout) { + for (i =3D 0; i < ARRAY_SIZE(rp->dev_state[rp_dev].rsp_queue); i++= ) { + if (rp->dev_state[rp_dev].rsp_queue[i].used && + rp->dev_state[rp_dev].rsp_queue[i].valid) { + rp_resp_slot_done(rp, &rp->dev_state[rp_dev].rsp_queue[i]); + } + } + } else { + rp_resp_slot_done(rp, rsp_slot); + } + rp_rsp_mutex_unlock(rp); + + /* + * For strongly ordered or transactions that don't allow Early Acking, + * we need to drain the pending RP processing queue here. This is + * because RP handles responses in parallel with normal requests so + * they may get reordered. This becomes visible for example with reads + * to read-to-clear registers that clear interrupts. Even though the + * lowering of the interrupt-wires arrives to us before the read-resp, + * we may handle the response before the wire update, resulting in + * spurious interrupts. + * + * This has some room for optimization but for now we use the big hamm= er + * and drain the entire qeueue. + */ + rp_process(rp); + + /* Reads are sync-points, roll the sync timer. */ + rp_restart_sync_timer(rp); + DB_PRINT_L(1, "\n"); + return ret; +} + +MemTxResult rp_mm_access(RemotePort *rp, uint32_t rp_dev, + struct rp_peer_state *peer, + MemoryTransaction *tr, + bool relative, uint64_t offset) +{ + return rp_mm_access_with_def_attr(rp, rp_dev, peer, tr, relative, offs= et, + 0); +} + static MemTxResult rp_access(MemoryTransaction *tr) { - /* TBD */ - return MEMTX_OK; + RemotePortMap *map =3D tr->opaque; + RemotePortMemoryMaster *s =3D map->parent; + + return rp_mm_access(s->rp, s->rp_dev, s->peer, tr, s->relative, + map->offset); } =20 static const MemoryRegionOps rp_ops_template =3D { diff --git a/hw/core/remote-port.c b/hw/core/remote-port.c index c783a12153..41ac1b46dc 100644 --- a/hw/core/remote-port.c +++ b/hw/core/remote-port.c @@ -62,6 +62,11 @@ static void rp_pkt_dump(const char *prefix, const char *= buf, size_t len) qemu_hexdump(stdout, prefix, buf, len); } =20 +uint32_t rp_new_id(RemotePort *s) +{ + return qatomic_fetch_inc(&s->current_id); +} + void rp_rsp_mutex_lock(RemotePort *s) { qemu_mutex_lock(&s->rsp_mutex); diff --git a/hw/core/trace-events b/hw/core/trace-events index 2cf085ac66..6332002d65 100644 --- a/hw/core/trace-events +++ b/hw/core/trace-events @@ -32,3 +32,7 @@ clock_set_mul_div(const char *clk, uint32_t oldmul, uint3= 2_t mul, uint32_t olddi =20 # cpu-common.c cpu_reset(int cpu_index) "%d" + +# remote-port-memory-master.c +remote_port_memory_master_tx_busaccess(const char *cmd, uint32_t id, uint3= 2_t flags, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd= =3D%s, id=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%= "PRIx64", len=3D0x%"PRIx32", attr=3D0x%"PRIx64 +remote_port_memory_master_rx_busaccess(const char *cmd, uint32_t id, uint3= 2_t flags, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd= =3D%s, id=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%= "PRIx64", len=3D0x%"PRIx32", attr=3D0x%"PRIx64 diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index e5dfaf7c3b..172c4b6204 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -153,4 +153,15 @@ ssize_t rp_write(RemotePort *s, const void *buf, size_= t count); =20 struct rp_peer_state *rp_get_peer(RemotePort *s); =20 +uint32_t rp_new_id(RemotePort *s); + +static inline void rp_resp_slot_done(RemotePort *s, + RemotePortRespSlot *rsp_slot) +{ + rp_dpkt_invalidate(&rsp_slot->rsp); + rsp_slot->id =3D ~0; + rsp_slot->used =3D false; + rsp_slot->valid =3D false; +} + #endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321699; cv=none; d=zohomail.com; s=zohoarc; b=KaM3pGTnkEZqRpCjaFh7LZdRsOnlBrGR0x7pyzXZPhksSZouDsr5LH4vATGUQ8RBzMXvUn8EPcSjZojI7MMwZ6w2QN2rusMyF0Jzlyn4+ItDf7CU/vJPVeN+J6cPADuJoExrfdcWmI21KVd41N2h/OK2O7Rftbu1smmm9fZqoxo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321699; 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=7JwGWXxuqSsQ++iisL/fCPRsKkpwKEoJ4MeC9qZ22M0=; b=E3+QlS5aZrq1DxteRLkIzWf4UmmoOTOKx3sKUoA67VsZCXxvrklTX7qP/HC9ruUrGOQkILQXOA1ALPTbSDnq7tcfSjqgkK1ZRmWlLyyzOdwxMYiqp0aZN0OooFTAEaHnGwyHFIJMSrLhIMScdOHgVQdJOTtbfXQGhKB3DLC9FD4= 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 1770321699111490.1457567518445; Thu, 5 Feb 2026 12:01:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VX-0006p1-0d; Thu, 05 Feb 2026 14:59:19 -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 1vo5VR-0006nT-Rs for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:13 -0500 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VN-00037n-JO for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:13 -0500 Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-483100e97d8so8450675e9.2 for ; Thu, 05 Feb 2026 11:59:09 -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.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321548; x=1770926348; 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=7JwGWXxuqSsQ++iisL/fCPRsKkpwKEoJ4MeC9qZ22M0=; b=Zv+HXhmO+OblBs4KnpgFY4jGJihlkiX2Iy/Gxgw/eSN8rsuuD5H4aAPiuGJMQEJZCR pM3hAcmrXs5mZ2Rt4CdU1UgUnUw/KjreB8pdBtkSF7j121sJjgtjlM44LlhOJjmTT/Se JelB9lmTiiE7mlc4jg+qyLz+2nlJyR86PKem+q+8JgJJnsuN+8BCjcdcHCOpNwlvq7gH Am+YdtHV/enxYw7+mrgBTpPieuaXeuHwfpoOSP31tfzqoHXSQkdm6HNDIHqtTF8zcmyF 0NCgUSypEPtsraD/ifSludBOG5MkzvQlgjbLkHxVyWQNHQ5HMKtdRGIgnw8oOC6r9wIt E0vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321548; x=1770926348; 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=7JwGWXxuqSsQ++iisL/fCPRsKkpwKEoJ4MeC9qZ22M0=; b=msUlsQE3ULj329yY4rewuEPSs0WiPfPjQP7r73cmQEiH28caJJO93NgZqld62OdXIJ Sec83+jgrxoq7mQgPoUayfzboTwTlUPBxrpyBqebRbiA5PXt6XRAsJbu6BW89xncMPh7 1KmPSs0yCHWhbjTQvtHl+eHSZpJFU4oqXbgnkkR3cia4d9zo/KdpZB8F9hX4nXBNvhlo dxQx8Nx7lvsqL5izIZ+1vEcVIANXPCXJ4pNOzOD2FV4githT/nW51nhOwseYeloLPxh8 B9opS++ncWj+ckYbn8J3me+YWWTVSTKgWyKJtFs8LYBB+9TOuBoMyWb4qe7eWPwhgXaT bpwg== X-Gm-Message-State: AOJu0YxMLAwfXa9pukQVciGtEHLxSKirlc67nXBXPXlC0dju7TrozvSO sVrI7amhzCmduvmHY2FAkjHzioGlQqiBF5yVBnXzPBaKcmrX/D/oUjv3tNyfDosFod4= X-Gm-Gg: AZuq6aKh+18EftyghgTgyN+hl8P0Gt5xGGO8heXBQr8dl0fjAnjZkstcGe6zUtfrfII r+CK3POJm2bzw2Ajf9CcdhiePK9y18SZ7WOp1V14mVzuDErBKT7O4PsfMvu4JYBXG+wD4pkvKPu PI3xicAuz+eg4ilec/BbFxoackKhZ36y8cbMNrih2RY17rTi+ddkpIGGbjCTEJyi/nMFG+R4E2W uiupOh+edyIxpfcREMITHRJi86ahFeXs/bEMpxaOlQG2+DiAlrCTBD5msirBXljoMR0el2OJn65 4lKlBz/JA+m4mtcTMwg1UpzLpuaGREtjgIZIQhnfcYJ9n634jNXnxcRBxgGcUQ3o9AGqE2jPeNO jSume9qWzFU1KbVyLh3AMKMHzANJKuDvWFc/pGRfw5N2Hmeq4PRFRckuCfvpzxDTR52C+ORiYmT b8BEluNKo/3V3n1XIpe14= X-Received: by 2002:a05:6000:2087:b0:435:ab90:6f34 with SMTP id ffacd0b85a97d-4362933ef81mr701258f8f.16.1770321547762; Thu, 05 Feb 2026 11:59:07 -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, Paolo Bonzini , Peter Xu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Edgar E . Iglesias" Subject: [PATCH 16/29] system/physmem: Add ats_do_translate helper Date: Thu, 5 Feb 2026 20:58:11 +0100 Message-ID: <20260205195824.2610192-17-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::32e; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x32e.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=unavailable 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: 1770321699561158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Add 'ats_do_translate' method to enable manual IOMMU address translation. This allows the Remote Port subsystem to resolve guest virtual addresses to physical addresses by querying the QEMU IOMMU translation pipeline. This is required for the Remote Port subsystem to support translation requests from external masters in a co-simulation environment. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- include/system/memory.h | 8 +++++++ system/physmem.c | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/include/system/memory.h b/include/system/memory.h index e1fb82608d..c787c544ce 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -2895,6 +2895,14 @@ static inline MemoryRegion *address_space_translate(= AddressSpace *as, addr, xlat, len, is_write, attrs); } =20 +MemoryRegion *ats_do_translate(AddressSpace *as, + hwaddr addr, + hwaddr *xlat, + hwaddr *plen_out, + AddressSpace **target_as, + int *prot, + MemTxAttrs attrs); + /* address_space_access_valid: check for validity of accessing an address * space range * diff --git a/system/physmem.c b/system/physmem.c index 2fb0c25c93..b4c18f3a01 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -527,6 +527,59 @@ static MemoryRegionSection flatview_do_translate(FlatV= iew *fv, return *section; } =20 +/* This function is called from RCU critical section */ +MemoryRegion *ats_do_translate(AddressSpace *as, + hwaddr addr, + hwaddr *xlat, + hwaddr *plen_out, + AddressSpace **target_as, + int *prot, + MemTxAttrs attrs) +{ + MemoryRegionSection *section; + IOMMUMemoryRegion *iommu_mr; + hwaddr plen =3D (hwaddr)(-1); + FlatView *fv =3D address_space_to_flatview(as); + IOMMUMemoryRegionClass *imrc; + IOMMUTLBEntry iotlb; + int iommu_idx =3D 0; + + if (!plen_out) { + plen_out =3D &plen; + } + + /* This can be MMIO, so setup MMIO bit. */ + section =3D address_space_translate_internal( + flatview_to_dispatch(fv), addr, xlat, + plen_out, true); + + /* Illegal translation */ + if (section->mr =3D=3D &io_mem_unassigned) { + return NULL; + } + + iommu_mr =3D memory_region_get_iommu(section->mr); + if (!iommu_mr) { + return NULL; + } + + imrc =3D memory_region_get_iommu_class_nocheck(iommu_mr); + + if (imrc->attrs_to_index) { + iommu_idx =3D imrc->attrs_to_index(iommu_mr, attrs); + } + + iotlb =3D imrc->translate(iommu_mr, addr, IOMMU_RO, iommu_idx); + + *xlat =3D ((iotlb.translated_addr & ~iotlb.addr_mask) + | (addr & iotlb.addr_mask)); + *plen_out =3D MIN(*plen_out, (addr | iotlb.addr_mask) - addr + 1); + *prot =3D iotlb.perm; + *target_as =3D iotlb.target_as; + + return section->mr; +} + /* Called from RCU critical section */ IOMMUTLBEntry address_space_get_iotlb_entry(AddressSpace *as, hwaddr addr, bool is_write, MemTxAttrs attr= s) --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321627; cv=none; d=zohomail.com; s=zohoarc; b=fCRoN7OwQ3BBuJgCBHfQAqNwAfXnLF2NR/yURyG/cc9ILN+JS/hNsNbQL8FAiHFtg8shSqLr6akKi2PPlw5lYDKJWM/2prhVZ1BJjjOJ/oy+sbwfEgXFlrbTnQ6Ul55LHwA2n+Ff6flIBoRTkXUXmLmtcPC+BB93yobdPy3FvVE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321627; 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=o+nwsgAJTHvM+0L73DFIwTvl7Jx6GKbrKwt9jyk9QLg=; b=N7xvEGmvGp/qsmSZWgmrlJhv566aVhA+6qokmZYf3+MdBvUyn68OFGJHnK8WQPisf0XcIbnU65akbOVKcTJWweNwHB1PVS87VgGEQMviZg/fERij4vyzzJpojFOzp/F6Pu+W5frgYAqJbuicMy29my6qBzwu6jErNsvoCRqYHGU= 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 1770321627725252.89872237115435; Thu, 5 Feb 2026 12:00:27 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VX-0006qM-Kc; Thu, 05 Feb 2026 14:59:19 -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 1vo5VS-0006oE-Eo for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:14 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VP-00037y-6y for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:14 -0500 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-435903c4040so993672f8f.3 for ; Thu, 05 Feb 2026 11:59:10 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321549; x=1770926349; 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=o+nwsgAJTHvM+0L73DFIwTvl7Jx6GKbrKwt9jyk9QLg=; b=Qzb584sXSuCasOdrjwe4xfKUT6bDvd+UeHQnH9iHlC8mATD8XLQq8XkRZ/fW/YwG09 Nt3J7cpbD0rspOjz32uxDkaTQWRI3d+bT1R+oHVYrOSd+T8kJHn4nKYR4z20jE2enYS6 kdE1kEzboX3VfnfPSPwYNuad4iDs5WGwkwJRGypVDP6mWAD6JlhGSKizHYiSXMn1OQNL mR29quYAYBYccIFlWKYN+VALzKQmXOP3lA6OigfqRgG/XvsNwCEDXdAJ/+tY3owKGna0 DDgxf5cw6uouA7HOI3xXk3O+2sZuRUb1LhnAH93N+QLSV5YSNw5LeITwc9HpNrAmENSZ GfLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321549; x=1770926349; 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=o+nwsgAJTHvM+0L73DFIwTvl7Jx6GKbrKwt9jyk9QLg=; b=MtlnnN9HxlXIS/QEBfsFb0VlVIQ/MJx+kG626s14p9XOBLcAQ4VyQArVwxdhu34S74 rwXVgYT4pccXEjvdc1el2cscKnUJv0uhEBf6O4Lw6Sa+iYOryCOlCwGKy3CZbzrfCC4Z z6GfHmYTPRRjNBFad/s/8YcyNyYkurcaoFTAGNfGbx36B0LhY9RBKjZKh7/dOyzSIcXX IZ+gVev+csSETOgegkh74zx2O4ySff9pweLk+tdMpBgkeTuZbk6X2c7LNZBSYYUPkpx4 30NPtYLQzxjWgTTT0j9ohPeJvTw83BcUIuabbVzyninIZl9UN71o2mxDOv+p7rBJdVT2 xcrA== X-Gm-Message-State: AOJu0YyNo+8b5A6xLUJGeTxui+BE+OI8fwI0OKnfBFNjviAg8dbG/dyJ c89fCqFm26+rZbSjRm+Z2cAVMJjNY0yfxj4V2jFZNEeykATHDPXMkQvQbjSULmCTfeY= X-Gm-Gg: AZuq6aI4HWNLGTvc04Fn3m20EYTfxA4u5gCi3PATTgelNRooUPaOYQjZma/RGOx40UF nEGDhNXShC43Al2QHhRPhwnpBY8JZ6lJwKIhbZGBCkzPGHMo4jpYajZBrt8TnF/h652p1hDD22G VFd+DEAjPHS3r33QaPEwQCkd/iToyZ1AzWZbOxOiRmm4ytvSTrHEwOmn5g3O57d9KglNyljntzw RuTA2xvurQhakSSWIvi1ewc6K5pAtuHG0AHS5ssdcgerwQ4G2FCoZTMV9wTyU9j8wSlVsq7y15B Btf1FNgt4WIgJcvJfEb8D2GGLFOeHDU73OMFQ+4S2DNSkFbsK627OxDtb3j0O3rt4oosIztdjQN uyMM+RNw88uqNmSTu6Ty/XAHH6PemupMp3eYFnQJ/dz2UTfC6PJ1THf6h5m+pInwnT9W9EilXUy Lpun2T27SYabN4AziXagw= X-Received: by 2002:a05:6000:2601:b0:435:d859:5cf with SMTP id ffacd0b85a97d-4362938a761mr761246f8f.54.1770321549243; Thu, 05 Feb 2026 11:59:09 -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 17/29] hw/core: Add Remote Port ATS device skeleton Date: Thu, 5 Feb 2026 20:58:12 +0100 Message-ID: <20260205195824.2610192-18-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::42c; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42c.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=unavailable 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: 1770321629437154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Inroduce the remote-port-ats device and remote-port-ats-cache interface. This patch provides the QOM definition and basic initialization logic required for Address Translation Services in Remote Port system. Signed-off-by: Francisco Iglesias Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-ats.c | 205 ++++++++++++++++++++++++++++++ include/hw/core/remote-port-ats.h | 75 +++++++++++ 2 files changed, 280 insertions(+) create mode 100644 hw/core/remote-port-ats.c create mode 100644 include/hw/core/remote-port-ats.h diff --git a/hw/core/remote-port-ats.c b/hw/core/remote-port-ats.c new file mode 100644 index 0000000000..c0e8150452 --- /dev/null +++ b/hw/core/remote-port-ats.c @@ -0,0 +1,205 @@ +// SPDX-License-Identifier: MIT +/* + * QEMU remote port ATS + * + * Copyright (c) 2021 Xilinx Inc + * Written by Francisco 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 "system/system.h" +#include "system/dma.h" +#include "qemu/log.h" +#include "qapi/qmp/qerror.h" +#include "qapi/error.h" +#include "hw/core/sysbus.h" +#include "migration/vmstate.h" +#include "hw/core/qdev-properties.h" +#include "trace.h" + +#include "hw/core/remote-port-proto.h" +#include "hw/core/remote-port-ats.h" + +typedef struct ATSIOMMUNotifier { + IOMMUNotifier n; + MemoryRegion *mr; + RemotePortATS *rp_ats; + int iommu_idx; +} ATSIOMMUNotifier; + +IOMMUTLBEntry *rp_ats_cache_lookup_translation(RemotePortATSCache *cache, + hwaddr translated_addr, + hwaddr len) +{ + RemotePortATSCacheClass *c =3D REMOTE_PORT_ATS_CACHE_GET_CLASS(cache); + + return c->lookup_translation(cache, translated_addr, len); +} + +static IOMMUTLBEntry *rp_ats_lookup_translation(RemotePortATSCache *cache, + hwaddr translated_addr, + hwaddr len) +{ + /* TBD */ + return NULL; +} + +static bool ats_translate_address(RemotePortATS *s, struct rp_pkt *pkt, + hwaddr *phys_addr, hwaddr *phys_len) +{ + /* TBD */ + return true; +} + +static void rp_ats_req(RemotePortDevice *dev, struct rp_pkt *pkt) +{ + RemotePortATS *s =3D REMOTE_PORT_ATS(dev); + size_t pktlen =3D sizeof(struct rp_pkt_ats); + hwaddr phys_addr =3D 0; + hwaddr phys_len =3D (hwaddr)(-1); + uint64_t result; + size_t enclen; + int64_t delay; + int64_t clk; + + assert(!(pkt->hdr.flags & RP_PKT_FLAGS_response)); + + rp_dpkt_alloc(&s->rsp, pktlen); + + result =3D ats_translate_address(s, pkt, &phys_addr, &phys_len) ? + RP_ATS_RESULT_ok : RP_ATS_RESULT_error; + + /* + * delay here could be set to the annotated cost of doing issuing + * these accesses. QEMU doesn't support this kind of annotations + * at the moment. So we just clear the delay. + */ + delay =3D 0; + clk =3D pkt->ats.timestamp + delay; + + enclen =3D rp_encode_ats_req(pkt->hdr.id, pkt->hdr.dev, + &s->rsp.pkt->ats, + clk, + pkt->ats.attributes, + phys_addr, + phys_len, + result, + pkt->hdr.flags | RP_PKT_FLAGS_response); + assert(enclen =3D=3D pktlen); + + rp_write(s->rp, (void *)s->rsp.pkt, enclen); +} + +static void rp_ats_realize(DeviceState *dev, Error **errp) +{ + RemotePortATS *s =3D REMOTE_PORT_ATS(dev); + + s->peer =3D rp_get_peer(s->rp); + address_space_init(&s->as, s->mr ? s->mr : get_system_memory(), "ats-a= s"); + + s->iommu_notifiers =3D g_array_new(false, true, sizeof(ATSIOMMUNotifie= r *)); + s->cache =3D g_array_new(false, true, sizeof(IOMMUTLBEntry *)); +} + +static void rp_prop_allow_set_link(const Object *obj, const char *name, + Object *val, Error **errp) +{ +} + +static void rp_ats_init(Object *obj) +{ + RemotePortATS *s =3D REMOTE_PORT_ATS(obj); + + object_property_add_link(obj, "rp-adaptor0", "remote-port", + (Object **)&s->rp, + rp_prop_allow_set_link, + OBJ_PROP_LINK_STRONG); + object_property_add_link(obj, "mr", TYPE_MEMORY_REGION, + (Object **)&s->mr, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_STRONG); +} + +static void rp_ats_unrealize(DeviceState *dev) +{ + RemotePortATS *s =3D REMOTE_PORT_ATS(dev); + ATSIOMMUNotifier *notifier; + int i; + + for (i =3D 0; i < s->iommu_notifiers->len; i++) { + notifier =3D g_array_index(s->iommu_notifiers, ATSIOMMUNotifier *,= i); + memory_region_unregister_iommu_notifier(notifier->mr, ¬ifier->n= ); + g_free(notifier); + } + g_array_free(s->iommu_notifiers, true); + + address_space_destroy(&s->as); + + for (i =3D 0; i < s->cache->len; i++) { + IOMMUTLBEntry *tmp =3D g_array_index(s->cache, IOMMUTLBEntry *, i); + g_free(tmp); + } + g_array_free(s->cache, true); +} + +static Property rp_properties[] =3D { + DEFINE_PROP_UINT32("rp-chan0", RemotePortATS, rp_dev, 0), +}; + +static void rp_ats_class_init(ObjectClass *oc, const void *data) +{ + RemotePortDeviceClass *rpdc =3D REMOTE_PORT_DEVICE_CLASS(oc); + RemotePortATSCacheClass *atscc =3D REMOTE_PORT_ATS_CACHE_CLASS(oc); + DeviceClass *dc =3D DEVICE_CLASS(oc); + + device_class_set_props_n(dc, rp_properties, ARRAY_SIZE(rp_properties)); + + rpdc->ops[RP_CMD_ats_req] =3D rp_ats_req; + dc->realize =3D rp_ats_realize; + dc->unrealize =3D rp_ats_unrealize; + atscc->lookup_translation =3D rp_ats_lookup_translation; +} + +static const TypeInfo rp_ats_info =3D { + .name =3D TYPE_REMOTE_PORT_ATS, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(RemotePortATS), + .instance_init =3D rp_ats_init, + .class_init =3D rp_ats_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_REMOTE_PORT_DEVICE }, + { TYPE_REMOTE_PORT_ATS_CACHE }, + { }, + }, +}; + +static const TypeInfo rp_ats_cache_info =3D { + .name =3D TYPE_REMOTE_PORT_ATS_CACHE, + .parent =3D TYPE_INTERFACE, + .class_size =3D sizeof(RemotePortATSCacheClass), +}; + +static void rp_register_types(void) +{ + type_register_static(&rp_ats_cache_info); + type_register_static(&rp_ats_info); +} + +type_init(rp_register_types) diff --git a/include/hw/core/remote-port-ats.h b/include/hw/core/remote-por= t-ats.h new file mode 100644 index 0000000000..8bdae1bce9 --- /dev/null +++ b/include/hw/core/remote-port-ats.h @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: MIT +/* + * QEMU remote port ATS + * + * Copyright (c) 2021 Xilinx Inc + * Written by Francisco 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. + */ +#ifndef REMOTE_PORT_ATS_H +#define REMOTE_PORT_ATS_H + +#include "hw/core/remote-port.h" + +#define TYPE_REMOTE_PORT_ATS "remote-port-ats" +#define REMOTE_PORT_ATS(obj) \ + OBJECT_CHECK(RemotePortATS, (obj), TYPE_REMOTE_PORT_ATS) + +typedef struct { + /* private */ + SysBusDevice parent; + + /* public */ + struct RemotePort *rp; + struct rp_peer_state *peer; + MemoryRegion *mr; + AddressSpace as; + RemotePortDynPkt rsp; + GArray *iommu_notifiers; + uint32_t rp_dev; + GArray *cache; /* Translation cache */ +} RemotePortATS; + +#define TYPE_REMOTE_PORT_ATS_CACHE "remote-port-ats-cache" + +#define REMOTE_PORT_ATS_CACHE_CLASS(klass) \ + OBJECT_CLASS_CHECK(RemotePortATSCacheClass, (klass), \ + TYPE_REMOTE_PORT_ATS_CACHE) +#define REMOTE_PORT_ATS_CACHE_GET_CLASS(obj) \ + OBJECT_GET_CLASS(RemotePortATSCacheClass, (obj), TYPE_REMOTE_PORT_ATS_= CACHE) +#define REMOTE_PORT_ATS_CACHE(obj) \ + INTERFACE_CHECK(RemotePortATSCache, (obj), TYPE_REMOTE_PORT_ATS_CACHE) + +typedef struct RemotePortATSCache { + Object Parent; +} RemotePortATSCache; + +typedef struct RemotePortATSCacheClass { + InterfaceClass parent; + + IOMMUTLBEntry *(*lookup_translation)(RemotePortATSCache *cache, + hwaddr translated_addr, + hwaddr len); +} RemotePortATSCacheClass; + +IOMMUTLBEntry *rp_ats_cache_lookup_translation(RemotePortATSCache *cache, + hwaddr translated_addr, + hwaddr len); +#endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321759; cv=none; d=zohomail.com; s=zohoarc; b=kxJu0wYTtuE9XQMGA1x3RpSIRi99Teg4wFhkmHPJoxM7nH/bch7vVhuj8cMr/zJ2d0PsXNRdRZYH7y8pgF+c/oTFkx7ZA1smeBfkxPZKCwitekgCcEHo26ZmY5c34yJWCY02C4wrpYuVUoF2WTOewe2Qo1HiS4obGvhMVl1ztSc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321759; 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=YNa6k84+p4NLUcl3AM/SAA8NkXll7Iajqtfasejwd8w=; b=EcUCZuyReoBlCvnydpyPFyvU2RltNYbJ+DrJpqR0jedKTb5DTbrmKztyNLzdtpcSKf8yFiRcMKcRJtsbxyTyGtGVZofWWSWf7JvVSdtqdbPWvMekN9pHe1IwgSOCPKI8GOlHwS0ZjcpNP//LYYMP1no9FRJTx3jcNk3LW1l5l+I= 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 1770321759326422.543972979661; Thu, 5 Feb 2026 12:02:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5VZ-0006sa-Hx; Thu, 05 Feb 2026 14:59:21 -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 1vo5VT-0006pC-7p for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:18 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VQ-000386-M9 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:14 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-4359a316d89so1095515f8f.0 for ; Thu, 05 Feb 2026 11:59:12 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321551; x=1770926351; 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=YNa6k84+p4NLUcl3AM/SAA8NkXll7Iajqtfasejwd8w=; b=cDiVPx7b7HuXo0k+KLaLGPOo36XxNfSNyBsWBXoyFz+ISc0suoZreLPeA766Rh7FtY kIru1nhayRHrpCfLu2aQLVTwVIvfdzSgGTs/SV55IVUwd6kRBagtRGB4bkB+pjQ42tZZ 44zQX/TlecYaAdrYHPBQbJUp8NA/kEQ9rT4myvRWh1Z4a4AuYZ0aN2ulkEMvjnwJ29yr 4htefsBDtI9YufL6qvfaw6C4kVBgZJanYIfvoC5F8TzZTeK7JGWa4KEVthSmJPYbTDHS uCG4y7CKQZw5F7sj7Skmu+5xKYSMh9y1UDYJ14b9039jJW86PrL/xjjSJfole3GB+Q1u 9A2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321551; x=1770926351; 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=YNa6k84+p4NLUcl3AM/SAA8NkXll7Iajqtfasejwd8w=; b=kXJ2COrm4lQ7uI5A1L4IA9kXG9efiaImv5JLFXebw5v/0pgpdA5faPWnig4OH/zg+9 SZoVJKxlk3Er42xNKAa9WIUqyPMmcWrpFSmtamp7V+PsPHVbevBOE744vEs0mmWlCuZ6 Dttjf7VuYME6c95GZ8FpTl7Qr3nWIrF4PUZ7pxBDmn9mTD8tLlbqULDdyIYZN1jmWnq1 X+V7xnKjQrCn+FV3ZdM8iD+GqmYwDjBwrdAQIzuvHeJdRPNAa96b9e98lzrN41owx5m1 cNSEirbcw2sDBKlzReL95/Yc8dAe8pNrVWG1yhmbsh28H1vvvf6GFWyeX/P2AaWt8O3H GUpw== X-Gm-Message-State: AOJu0Ywe+06FenVF8n3ht/kjYPhXHboNbaEeYZl5AQy5aU3Z9I0ErAAI FTs8zlpsaLbOvr1GkuAmgVNCv+R4+74cGN7Pwu7eCRuVxul6TI9pulFKzjDYRJPBVoY= X-Gm-Gg: AZuq6aIadpLzulQa3gFwliBruEx9kqWkYatID9F65i4+AfyoDGsYYtgTY+CgL8YMc3j rVDfjLdDmH0mF7ERlspcNrVxPY0NStuMsnJNUn5nF08o5dGBqx9PBXPtkVoeZQ+jjI8SXYGP9uI 71+W9CAN4liKWu4W3FzIwNAoo9xukmh7h8cm2jlRUZlTYjInXR2yttTR/33s+SyYzVbSwMVGvSQ +MNphBFpnhoGIRKJfjY2iq+FdGDpkuagDqO2yh6yeBL/UPEPLEd05EbDFQJZoJH90qwJhktCor3 mJ22QwWg2JW8bdSUHnuwnD2rx6lbjVLM25h19EQpcZqIQq0MXb4oB2nXXiP9x2L+hF3nwUKjnH0 HMH7wYw5eULjqXl/5nsRqY9Xe/wP3hcQ0HKr58H7Tou3dKTNGZF4dWa4uZF1w6phcn1Ix/EyzxO Vdj/gUHnJ605XCmDasEJs= X-Received: by 2002:a05:6000:2386:b0:433:2f55:7cab with SMTP id ffacd0b85a97d-4362934bff8mr746555f8f.37.1770321550643; Thu, 05 Feb 2026 11:59:10 -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 18/29] hw/core: Implement Remote Port ATS logic and cache management Date: Thu, 5 Feb 2026 20:58:13 +0100 Message-ID: <20260205195824.2610192-19-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::434; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x434.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=unavailable 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: 1770321760004158501 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Complete the Remote Port ATS implementation by adding the translation and cache management logic. This patch implements: - The logic for ats_translate_address to resolve addresses via the QEMU IOMMU translation mechanism. - A local cache management system to store IOMMU entries for remote masters. - Integration with IOMMU notifiers to handle invalidation requests and maintain coherency with the peer. Signed-off-by: Francisco Iglesias Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-ats.c | 207 +++++++++++++++++++++++++++++++++++++- 1 file changed, 205 insertions(+), 2 deletions(-) diff --git a/hw/core/remote-port-ats.c b/hw/core/remote-port-ats.c index c0e8150452..1f6c8d7410 100644 --- a/hw/core/remote-port-ats.c +++ b/hw/core/remote-port-ats.c @@ -57,14 +57,217 @@ static IOMMUTLBEntry *rp_ats_lookup_translation(Remote= PortATSCache *cache, hwaddr translated_addr, hwaddr len) { - /* TBD */ + RemotePortATS *s =3D REMOTE_PORT_ATS(cache); + + for (int i =3D 0; i < s->cache->len; i++) { + IOMMUTLBEntry *iotlb =3D g_array_index(s->cache, IOMMUTLBEntry *, = i); + hwaddr masked_start =3D (translated_addr & ~iotlb->addr_mask); + hwaddr masked_end =3D ((translated_addr + len - 1) & ~iotlb->addr_= mask); + + if (masked_start =3D=3D iotlb->translated_addr && + masked_end =3D=3D iotlb->translated_addr) { + return iotlb; + } + } + return NULL; } =20 +static void rp_ats_cache_remove(RemotePortATS *s, IOMMUTLBEntry *iotlb) +{ + for (int i =3D 0; i < s->cache->len; i++) { + IOMMUTLBEntry *tmp =3D g_array_index(s->cache, IOMMUTLBEntry *, i); + hwaddr masked_start =3D (tmp->iova & ~iotlb->addr_mask); + hwaddr masked_end =3D ((tmp->iova | tmp->addr_mask) & ~iotlb->addr= _mask); + + if (masked_start =3D=3D iotlb->iova || masked_end =3D=3D iotlb->io= va) { + g_array_remove_index_fast(s->cache, i); + } + } +} + +static void rp_ats_invalidate(RemotePortATS *s, IOMMUTLBEntry *iotlb) +{ + size_t pktlen =3D sizeof(struct rp_pkt_ats); + struct rp_pkt_ats pkt; + RemotePortRespSlot *rsp_slot; + RemotePortDynPkt *rsp; + size_t enclen; + int64_t clk; + uint32_t id; + hwaddr len =3D iotlb->addr_mask + 1; + + id =3D rp_new_id(s->rp); + clk =3D rp_normalized_vmclk(s->rp); + + enclen =3D rp_encode_ats_inv(id, s->rp_dev, + &pkt, + clk, + 0, + iotlb->iova, + len, + 0, + 0); + assert(enclen =3D=3D pktlen); + + rp_rsp_mutex_lock(s->rp); + rp_write(s->rp, (void *) &pkt, enclen); + + rsp_slot =3D rp_dev_wait_resp(s->rp, s->rp_dev, id); + rsp =3D &rsp_slot->rsp; + + /* We dont support out of order answers yet. */ + assert(rsp->pkt->hdr.id =3D=3D id); + + rp_resp_slot_done(s->rp, rsp_slot); + rp_rsp_mutex_unlock(s->rp); +} + +static void rp_ats_cache_insert(RemotePortATS *s, + hwaddr iova, + hwaddr translated_addr, + hwaddr mask, + AddressSpace *target_as) +{ + IOMMUTLBEntry *iotlb; + + /* + * Invalidate all current translations that collide with the new one a= nd + * does not have the same target_as. This means that translated_addres= ses + * towards the same addresses but in different target address spaces a= re + * not allowed. + */ + for (int i =3D 0; i < s->cache->len; i++) { + iotlb =3D g_array_index(s->cache, IOMMUTLBEntry *, i); + hwaddr masked_start =3D (translated_addr & ~iotlb->addr_mask); + hwaddr masked_end =3D ((translated_addr | mask) & ~iotlb->addr_mas= k); + bool spans_region =3D masked_start < iotlb->translated_addr && + masked_end > iotlb->translated_addr; + + if (masked_start =3D=3D iotlb->translated_addr || + masked_end =3D=3D iotlb->translated_addr || spans_region) { + hwaddr masked_iova_start; + hwaddr masked_iova_end; + + /* + * Invalidated & remove the mapping if the address range hit i= n the + * cache but the target_as is different. + */ + if (iotlb->target_as !=3D target_as) { + rp_ats_invalidate(s, iotlb); + g_array_remove_index_fast(s->cache, i); + continue; + } + + /* + * Remove duplicates with a smaller range length since the new + * mapping will span over it. + */ + masked_iova_start =3D (iova & ~iotlb->addr_mask); + masked_iova_end =3D ((iova | mask) & ~iotlb->addr_mask); + spans_region =3D masked_iova_start < iotlb->iova && + masked_iova_end > iotlb->iova; + + if (masked_iova_start =3D=3D iotlb->iova || + masked_iova_end =3D=3D iotlb->iova || spans_region) { + + if ((iotlb->addr_mask + 1) < (mask + 1)) { + g_array_remove_index_fast(s->cache, i); + } else { + /* + * The new mapping is smaller or equal in size and is = thus + * already cached. + */ + return; + } + } + } + } + + iotlb =3D g_new0(IOMMUTLBEntry, 1); + iotlb->iova =3D iova; + iotlb->translated_addr =3D translated_addr; + iotlb->addr_mask =3D mask; + iotlb->target_as =3D target_as; + g_array_append_val(s->cache, iotlb); +} + +static void rp_ats_iommu_unmap_notify(IOMMUNotifier *n, IOMMUTLBEntry *iot= lb) +{ + ATSIOMMUNotifier *notifier =3D container_of(n, ATSIOMMUNotifier, n); + RemotePortATS *s =3D notifier->rp_ats; + + rp_ats_invalidate(s, iotlb); + rp_ats_cache_remove(s, iotlb); +} + static bool ats_translate_address(RemotePortATS *s, struct rp_pkt *pkt, hwaddr *phys_addr, hwaddr *phys_len) { - /* TBD */ + MemTxAttrs attrs =3D MEMTXATTRS_UNSPECIFIED; + IOMMUMemoryRegion *iommu_mr; + AddressSpace *target_as; + MemoryRegion *mr; + int prot =3D 0; + + RCU_READ_LOCK_GUARD(); + + mr =3D ats_do_translate(&s->as, pkt->ats.addr, phys_addr, phys_len, + &target_as, &prot, attrs); + if (!mr) { + return false; + } + + iommu_mr =3D memory_region_get_iommu(mr); + if (iommu_mr) { + int iommu_idx =3D memory_region_iommu_attrs_to_index(iommu_mr, att= rs); + ATSIOMMUNotifier *notifier; + int i; + + for (i =3D 0; i < s->iommu_notifiers->len; i++) { + notifier =3D g_array_index(s->iommu_notifiers, ATSIOMMUNotifie= r *, i); + if (notifier->mr =3D=3D mr && notifier->iommu_idx =3D=3D iommu= _idx) { + break; + } + } + + /* Register a notifier if not found. */ + if (i =3D=3D s->iommu_notifiers->len) { + Error *err =3D NULL; + bool ret; + + s->iommu_notifiers =3D g_array_set_size(s->iommu_notifiers, i = + 1); + notifier =3D g_new0(ATSIOMMUNotifier, 1); + g_array_index(s->iommu_notifiers, ATSIOMMUNotifier *, i) =3D n= otifier; + + notifier->mr =3D mr; + notifier->iommu_idx =3D iommu_idx; + notifier->rp_ats =3D s; + + iommu_notifier_init(¬ifier->n, + rp_ats_iommu_unmap_notify, + IOMMU_NOTIFIER_UNMAP, + 0, + HWADDR_MAX, + iommu_idx); + + ret =3D memory_region_register_iommu_notifier(mr, ¬ifier->n= , &err); + if (ret) { + error_report_err(err); + exit(1); + } + } + } + + if (!(prot & IOMMU_RO)) { + pkt->ats.attributes &=3D ~(RP_ATS_ATTR_exec | RP_ATS_ATTR_read); + } + if (!(prot & IOMMU_WO)) { + pkt->ats.attributes &=3D ~(RP_ATS_ATTR_write); + } + + rp_ats_cache_insert(s, pkt->ats.addr, *phys_addr, *phys_len - 1, targe= t_as); + return true; } =20 --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321750; cv=none; d=zohomail.com; s=zohoarc; b=KGrqbhAnPWY52BFoyPkcV6P7XYfrVMq8s+JnjHwV6Gfz+hgot01QRKVFWdWDLr+BpN+nPpzZxuFp4JxGxiFtZuU4wbcyPiD2cHFPynhHA/8OTu7oLY8aZwP0pXJswZHiBnl80ylWe2bKugd+imaPl2oIPh0yfqAhtdMpi+bIHNs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321750; 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=ixQk1sle3klw7RV4vbO5KDu3SkmSly8hO0cVOcN5dSQ=; b=jG6oZnGsf+3GNNyRQKMigbsEh/EmBH3YjrS2MbFPzP6vHHzpf4nvLuj1ppmAjFLdPR9SNKMV+250ttPBqQvd9apWfbsGxLTmc5NLY8YDal61Qn7Th8/kiKMwU/Sq9K51O/BFkt9tWOEHqrXpC6H23JpiSTG2OhWLBTYSd+Rzh8o= 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 1770321750806795.7993408982325; Thu, 5 Feb 2026 12:02:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Va-0006tW-Fk; Thu, 05 Feb 2026 14:59:23 -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 1vo5VX-0006pd-3D for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:19 -0500 Received: from mail-wr1-x42f.google.com ([2a00:1450:4864:20::42f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VS-00038U-F5 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:16 -0500 Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-42fb0fc5aa9so1111669f8f.1 for ; Thu, 05 Feb 2026 11:59:14 -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.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321553; x=1770926353; 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=ixQk1sle3klw7RV4vbO5KDu3SkmSly8hO0cVOcN5dSQ=; b=RK2B80mY5G5DknpuUDoFdzPDJTFVUqCgT+AAaBaATozHEQm9lzF4rtveQKH5mBAHsY waDthAwyGVe38GW+oUHBKhVeLzGbkt51SuuHkJGF8ov2iSnzMR1y8QFFPADlpBIEg/UO +uexuNNYfjeIuMtYk6BUICiH7Kk2N5jgPp70JH/lw8m4TKfhiY41HcCnuFeAmgxarOlq /XGeJIRg+uzq2gdcSjABb6bYTLdrP/4RiQi28ubds2T6ERmzCzu1OeAY3/nzF2datWVW yHIdFDEJ/iDwTp5y6u6ebJ7Gv+kHqrsoOpyTfBQAgsAqAOxeUvEhvBigjGHl4vanuJ5r BqHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321553; x=1770926353; 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=ixQk1sle3klw7RV4vbO5KDu3SkmSly8hO0cVOcN5dSQ=; b=XguwUjt6MKGCuHgIC9H+8iRvnzb2bViZ3F00fnbZjQm6Cno+DibngXzcsJRjzNF5Bw 3lxFaZdwT0Fx2cvoaX8CUHZaf0U44jH9jNMPMAYGUVjvkYDtIJHni9UZmlII+oNH0Rm+ fZvz5SDHoUOmF1SVuCCZM3JEPCrCpO8i+hunBf+7nYzKw7FONt+aqubUf61T9AUpBSX3 Jsds8mn9SZ6x0JplwejSk7JRhEICVhesw6psMh8H15hkvvSyeiOMqyCn6lYZBNuFGvEK /AcwkU6TR9ylwYQPBG363jwkeB1dZxK1RoJQbNGa7i6IPImWZnuPe225D+aYYbt6p8OZ 5a/Q== X-Gm-Message-State: AOJu0YwnEQA0YxRORqCAupQskrYZ8uWShHMnXu5sli34xYaLFhrPuiGZ naOIjKB+rBx4SElmM265rxinu/ximvKy9UygKgezG6GzAwp4wudGkJPeQrYG0+rl6ok= X-Gm-Gg: AZuq6aIZwZijbozUBop0RRPu7EBygmxyhvweTQirmqfcDuGVWrL62CxhGyGSi7BW1+O SiqDpRgGnzSrlz2+Szi17USUKtLfPspUESkd7pQYpQcpRubUvrA3fuv3am275zywqynwOemJ9Bk /UXe6KatguWyNMvFqoJsFRMRRcPB4Z42hFppvyH8hChIdDO30L+xt+5RI+N2RMU0OS8VBz4FSqB my27fveBIy3sIWX4uhGU+ZLQg7o/szYf1NNl1UvApdv+TYJzIgT64fAVJ57tnQFc7yF9Pc+TJmI rRbtqi56D5rL9IVM13OaZLSwo+XNX0Td+I5Ulozv7eFFeb5Ya6Sm9nE2S/OfCWyAht0FrXbHakM oOfU1MooHnUEdy59n1rOi7/yz+SsTtZz3B/6Ks9qtIM5UDhnaDyFGfA5Ix/6qNDJh6PiVhm4zc9 TCDM8URH0viBUthNnsF1Q= X-Received: by 2002:a05:6000:402a:b0:430:f742:fbc7 with SMTP id ffacd0b85a97d-43629378247mr672697f8f.14.1770321552220; Thu, 05 Feb 2026 11:59:12 -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 19/29] hw/core: Add Remote Port memory slave device Date: Thu, 5 Feb 2026 20:58:14 +0100 Message-ID: <20260205195824.2610192-20-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::42f; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42f.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=unavailable 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: 1770321751985158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Introduce the 'remote-port-memory-slave' device to allow remote peers to initiate memory transactions within QEMU. The patch implements the logic to receive Remote Port bus access commands, execute them within the QEMU Address Space, and return the appropriate response. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-memory-slave.c | 263 +++++++++++++++++++++ hw/core/trace-events | 4 + include/hw/core/remote-port-memory-slave.h | 34 +++ 3 files changed, 301 insertions(+) create mode 100644 hw/core/remote-port-memory-slave.c create mode 100644 include/hw/core/remote-port-memory-slave.h diff --git a/hw/core/remote-port-memory-slave.c b/hw/core/remote-port-memor= y-slave.c new file mode 100644 index 0000000000..bb23325469 --- /dev/null +++ b/hw/core/remote-port-memory-slave.c @@ -0,0 +1,263 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * QEMU remote port memory slave. Read and write transactions + * recieved from the remote port are translated into an address space. + * + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * Written by Peter Crosthwaite + * + * This code is licensed under the GNU GPL. + */ + +#include "qemu/osdep.h" +#include "system/system.h" +#include "system/dma.h" +#include "qemu/log.h" +#include "qapi/qmp/qerror.h" +#include "qapi/error.h" +#include "hw/core/sysbus.h" +#include "migration/vmstate.h" +#include "hw/core/qdev-properties.h" +#include "qemu/error-report.h" +#include "trace.h" +#include "qemu/cutils.h" + +#include "hw/core/remote-port-proto.h" +#include "hw/core/remote-port-memory-slave.h" + +#ifndef REMOTE_PORT_ERR_DEBUG +#define REMOTE_PORT_DEBUG_LEVEL 0 +#else +#define REMOTE_PORT_DEBUG_LEVEL 1 +#endif + +#define DB_PRINT_L(level, ...) do { \ + if (REMOTE_PORT_DEBUG_LEVEL > level) { \ + fprintf(stderr, ": %s: ", __func__); \ + fprintf(stderr, ## __VA_ARGS__); \ + } \ +} while (0) + +/* Slow path dealing with odd stuff like byte-enables. */ +static MemTxResult process_data_slow(RemotePortMemorySlave *s, + AddressSpace *as, + struct rp_pkt *pkt, + DMADirection dir, + uint8_t *data, uint8_t *byte_en) +{ + unsigned int i; + unsigned int byte_en_len =3D pkt->busaccess_ext_base.byte_enable_len; + unsigned int sw =3D pkt->busaccess.stream_width; + MemTxResult ret =3D MEMTX_OK; + + assert(sw); + + for (i =3D 0; i < pkt->busaccess.len; i++) { + if (byte_en && !byte_en[i % byte_en_len]) { + continue; + } + + ret =3D dma_memory_rw(as, pkt->busaccess.addr + i % sw, + data + i, 1, dir, s->attr); + + if (ret !=3D MEMTX_OK) { + break; + } + } + + return ret; +} + +static AddressSpace *get_as_for_phys_busaccess(RemotePortMemorySlave *s, + struct rp_pkt *pkt) +{ + if (s->ats_cache) { + IOMMUTLBEntry *iotlb =3D + rp_ats_cache_lookup_translation(s->ats_cache, + pkt->busaccess.addr, + pkt->busaccess.len); + if (iotlb) { + /* Return the matching address space found. */ + return iotlb->target_as; + } + } + /* Emit a warning on errors since this really should not happen. */ + warn_report("Physical address error detected (range address: 0x%" + HWADDR_PRIx ", len: 0x%" PRIx32 " contains untranslated " + "addresses)", pkt->busaccess.addr, pkt->busaccess.len); + return NULL; +} + +static void rp_cmd_rw(RemotePortMemorySlave *s, struct rp_pkt *pkt, + DMADirection dir) +{ + size_t pktlen =3D sizeof(struct rp_pkt_busaccess_ext_base); + struct rp_encode_busaccess_in in =3D {0}; + size_t enclen; + int64_t delay; + uint8_t *data =3D NULL; + uint8_t *byte_en; + MemTxResult ret; + AddressSpace *as; + + byte_en =3D rp_busaccess_byte_en_ptr(s->peer, &pkt->busaccess_ext_base= ); + + if (dir =3D=3D DMA_DIRECTION_TO_DEVICE) { + pktlen +=3D pkt->busaccess.len; + } else { + data =3D rp_busaccess_rx_dataptr(s->peer, &pkt->busaccess_ext_base= ); + } + + assert(pkt->busaccess.width =3D=3D 0); + assert(!(pkt->hdr.flags & RP_PKT_FLAGS_response)); + + rp_dpkt_alloc(&s->rsp, pktlen); + if (dir =3D=3D DMA_DIRECTION_TO_DEVICE) { + data =3D rp_busaccess_tx_dataptr(s->peer, + &s->rsp.pkt->busaccess_ext_base); + } + if (dir =3D=3D DMA_DIRECTION_FROM_DEVICE && REMOTE_PORT_DEBUG_LEVEL > = 0) { + DB_PRINT_L(0, "address: %" PRIx64 "\n", pkt->busaccess.addr); + qemu_hexdump(stderr, ": write: ", + (const char *) data, pkt->busaccess.len); + } + trace_remote_port_memory_slave_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); + + s->attr.secure =3D !!(pkt->busaccess.attributes & RP_BUS_ATTR_SECURE); + s->attr.requester_id =3D pkt->busaccess.master_id; + + if (pkt->busaccess.attributes & RP_BUS_ATTR_PHYS_ADDR) { + as =3D get_as_for_phys_busaccess(s, pkt); + } else { + as =3D &s->as; + } + if (as) { + if (byte_en || pkt->busaccess.stream_width !=3D pkt->busaccess.len= ) { + ret =3D process_data_slow(s, as, pkt, dir, data, byte_en); + } else { + ret =3D dma_memory_rw(as, pkt->busaccess.addr, data, + pkt->busaccess.len, dir, s->attr); + } + } else { + ret =3D MEMTX_ERROR; + } + + if (dir =3D=3D DMA_DIRECTION_TO_DEVICE && REMOTE_PORT_DEBUG_LEVEL > 0)= { + DB_PRINT_L(0, "address: %" PRIx64 "\n", pkt->busaccess.addr); + qemu_hexdump(stderr, ": read: ", + (const char *) data, pkt->busaccess.len); + } + /* + * delay here could be set to the annotated cost of doing issuing + * these accesses. QEMU doesn't support this kind of annotations + * at the moment. So we just clear the delay. + */ + delay =3D 0; + + rp_encode_busaccess_in_rsp_init(&in, pkt); + in.clk =3D pkt->busaccess.timestamp + delay; + + switch (ret) { + case MEMTX_ERROR: + in.attr |=3D RP_RESP_BUS_GENERIC_ERROR << RP_BUS_RESP_SHIFT; + break; + case MEMTX_DECODE_ERROR: + in.attr |=3D RP_RESP_ADDR_ERROR << RP_BUS_RESP_SHIFT; + break; + default: + /* MEMTX_OK maps to RP_RESP_OK. */ + break; + } + + enclen =3D rp_encode_busaccess(s->peer, &s->rsp.pkt->busaccess_ext_bas= e, + &in); + assert(enclen <=3D pktlen); + + trace_remote_port_memory_slave_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 *)s->rsp.pkt, enclen); +} + +static void rp_memory_slave_realize(DeviceState *dev, Error **errp) +{ + RemotePortMemorySlave *s =3D REMOTE_PORT_MEMORY_SLAVE(dev); + + s->peer =3D rp_get_peer(s->rp); + address_space_init(&s->as, s->mr ? s->mr : get_system_memory(), "dma"); +} + +static void rp_memory_slave_write(RemotePortDevice *s, struct rp_pkt *pkt) +{ + return rp_cmd_rw(REMOTE_PORT_MEMORY_SLAVE(s), pkt, + DMA_DIRECTION_FROM_DEVICE); +} + +static void rp_memory_slave_read(RemotePortDevice *s, struct rp_pkt *pkt) +{ + return rp_cmd_rw(REMOTE_PORT_MEMORY_SLAVE(s), pkt, + DMA_DIRECTION_TO_DEVICE); +} + +static void rp_prop_allow_set_link(const Object *obj, const char *name, + Object *val, Error **errp) +{ +} + +static void rp_memory_slave_init(Object *obj) +{ + RemotePortMemorySlave *rpms =3D REMOTE_PORT_MEMORY_SLAVE(obj); + + object_property_add_link(obj, "rp-adaptor0", "remote-port", + (Object **)&rpms->rp, + rp_prop_allow_set_link, + OBJ_PROP_LINK_STRONG); + object_property_add_link(obj, "mr", TYPE_MEMORY_REGION, + (Object **)&rpms->mr, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_STRONG); + object_property_add_link(obj, "rp-ats-cache", TYPE_REMOTE_PORT_ATS_CAC= HE, + (Object **)&rpms->ats_cache, + qdev_prop_allow_set_link_before_realize, + OBJ_PROP_LINK_STRONG); +} + +static void rp_memory_slave_unrealize(DeviceState *dev) +{ + RemotePortMemorySlave *s =3D REMOTE_PORT_MEMORY_SLAVE(dev); + + address_space_destroy(&s->as); +} + +static void rp_memory_slave_class_init(ObjectClass *oc, const void *data) +{ + RemotePortDeviceClass *rpdc =3D REMOTE_PORT_DEVICE_CLASS(oc); + DeviceClass *dc =3D DEVICE_CLASS(oc); + + rpdc->ops[RP_CMD_write] =3D rp_memory_slave_write; + rpdc->ops[RP_CMD_read] =3D rp_memory_slave_read; + dc->realize =3D rp_memory_slave_realize; + dc->unrealize =3D rp_memory_slave_unrealize; +} + +static const TypeInfo rp_info =3D { + .name =3D TYPE_REMOTE_PORT_MEMORY_SLAVE, + .parent =3D TYPE_DEVICE, + .instance_size =3D sizeof(RemotePortMemorySlave), + .instance_init =3D rp_memory_slave_init, + .class_init =3D rp_memory_slave_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_REMOTE_PORT_DEVICE }, + { }, + }, +}; + +static void rp_register_types(void) +{ + type_register_static(&rp_info); +} + +type_init(rp_register_types) diff --git a/hw/core/trace-events b/hw/core/trace-events index 6332002d65..ee77916010 100644 --- a/hw/core/trace-events +++ b/hw/core/trace-events @@ -36,3 +36,7 @@ cpu_reset(int cpu_index) "%d" # remote-port-memory-master.c remote_port_memory_master_tx_busaccess(const char *cmd, uint32_t id, uint3= 2_t flags, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd= =3D%s, id=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%= "PRIx64", len=3D0x%"PRIx32", attr=3D0x%"PRIx64 remote_port_memory_master_rx_busaccess(const char *cmd, uint32_t id, uint3= 2_t flags, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd= =3D%s, id=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%= "PRIx64", len=3D0x%"PRIx32", attr=3D0x%"PRIx64 + +# remote-port-memory-slave.c +remote_port_memory_slave_tx_busaccess(const char *cmd, uint32_t id, uint32= _t flags, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd=3D= %s, id=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%"PR= Ix64", len=3D0x%"PRIx32", attr=3D0x%"PRIx64 +remote_port_memory_slave_rx_busaccess(const char *cmd, uint32_t id, uint32= _t flags, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd=3D= %s, id=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%"PR= Ix64", len=3D0x%"PRIx32", attr=3D0x%"PRIx64 diff --git a/include/hw/core/remote-port-memory-slave.h b/include/hw/core/r= emote-port-memory-slave.h new file mode 100644 index 0000000000..d88e806ed6 --- /dev/null +++ b/include/hw/core/remote-port-memory-slave.h @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * QEMU remote port memory slave. Read and write transactions + * recieved from the remote port are translated into an address space. + * + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * Written by Peter Crosthwaite + * + * This code is licensed under the GNU GPL. + */ +#ifndef REMOTE_PORT_MEMORY_SLAVE_H +#define REMOTE_PORT_MEMORY_SLAVE_H + +#include "hw/core/remote-port-ats.h" + +#define TYPE_REMOTE_PORT_MEMORY_SLAVE "remote-port-memory-slave" +#define REMOTE_PORT_MEMORY_SLAVE(obj) \ + OBJECT_CHECK(RemotePortMemorySlave, (obj), \ + TYPE_REMOTE_PORT_MEMORY_SLAVE) + +typedef struct RemotePortMemorySlave { + /* private */ + SysBusDevice parent; + /* public */ + struct RemotePort *rp; + struct rp_peer_state *peer; + MemoryRegion *mr; + AddressSpace as; + MemTxAttrs attr; + RemotePortDynPkt rsp; + RemotePortATSCache *ats_cache; +} RemotePortMemorySlave; +#endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321793; cv=none; d=zohomail.com; s=zohoarc; b=dRizPnhtwdJynh2ilZG6r8vSpTHqyAU0yqnGWigd3idt/Oors7lyd5lwoD8u5TdbXAE/TEZ1rR/P2hUI886DCBObIr/A9JRZcPTm44waWpsZ4bbnicCHfXwat8pc4J4/wy9lRh2DDvNJlVzQHgyZw26yC5idWsYF14bRxsT1YQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321793; 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=w0FvQWZuLK/AzauXscYjx34OM742bGa2222wnOY24Tk=; b=D5xsTXe2XRXRuFYGiiLtcONxhTW60t5YIh/LlpVJpBaJT520balwksmsQlImsd2pI35uQHNgqVrIuYzPUEw65yyk7Fw2MhASKvbMdu01dOOtcUFkjd70D1Lzhr5X92mBjk3cWpz5Sp/J+2NhyLgESgWUf0Au65JdJ7//+ds99VU= 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 1770321793064229.7037012720616; Thu, 5 Feb 2026 12:03:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vd-0006vX-MJ; 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 1vo5VX-0006q2-72 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:19 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VT-000399-RK for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:17 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-43596062728so1770176f8f.1 for ; Thu, 05 Feb 2026 11:59:15 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321554; x=1770926354; 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=w0FvQWZuLK/AzauXscYjx34OM742bGa2222wnOY24Tk=; b=YXj5O4qoEu1JBJlwPOhn0E9W16M0Bu8QwMEgvL64NPSBO6zw9/gQdap2hhN/E4ggwo kOiia0AX65jOtZZ61OtL7wfa50/cEi4FCGBaukV9ipC4mq5emLXCfoYzcHqq6/S0uS5p fr5mNMM8XCE4jL/QuMAZeoppxgxOruxoA8nD3A1ZZFFUQvjhC1dmi/Ez24OMxnmd4Om1 qGgxGHFVddNBEsfF0UUZNyqfx+Slt52xmMWpF7POliZLEYarCSEFAI8CTYiu4cf7he+7 HIYrKUUsY0YRW3zfAPC80lwi+bl8Y6j1iHmJEE3JgoxBUM/sLDm+GS3WiRndyoy1irq5 DDNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321554; x=1770926354; 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=w0FvQWZuLK/AzauXscYjx34OM742bGa2222wnOY24Tk=; b=cijMJNMf0fKZ0KO2z9r5GUQu7dHtlkoAlQm41CvWUwLk1uENPlSq93DQZRevPy223s 49EVW8ARQSjx0nlPYwce4HTb8scISy7SdFVOVVLMuOpXpQEWu6jcO0Lo1V9IDX6/Vag0 HPh2OoUS9C7XNGG9u5gYbMYx3OOzjQBRZtFJYd5LbVG38oChXVe2YzyCPVVrts8bYNGY OvfGn7R7aDQ65O7U/YD15pFqNA5U4AkmjCn+pynPRp1cMeMdmLop9254K8YGYY3VpDcf DricQEMEtVPj5DrSVjKDNp9XzFk3iZWdbwsG5IOUx5ipKa27/Llw+9VgwnjOun/y855j egXA== X-Gm-Message-State: AOJu0YxvEnxkKfrACkhxX8u/o3IL3oVt4QSXCoMnBcTqoSvtq8Z6hIuc SvYn3IBNI43tY3BOYnTd5xv4RxedQzpSiWoHZ2AYGlniHe9GDPxV+d2FVeb6p9oloCQ= X-Gm-Gg: AZuq6aIX3a3DWtH9cmpCIEJkr7firN5Qmd6xW1uMfVMrbwItwXyf37DWYfQect5SrPl KSiXBi5Kzl7xmSkck7xdnXi/Wo4j3vDA3fZoXLkiblL9tOToCQFSl5ZrZOwDYd/eBxokQE0jNzE WwlTLOk/u8nKZZ/Ct9G1H39pHVVBKk3E/iDryVOoqwQFqWkhDJur2q0sRAUxUHaj9NZTw5d266j k7T/VGSmPzE2/11yTr+wt9n+1b3/4Z3Xm3fgUxmws9P3Q+eFXLw2D8vRizT+osn/M7Bcxg6Hd4U 5AnuPVcZQoQTIxdb9Ul4zEdqKToHfTec52G4O4iCgb/Q0Tqds7fQELa+JHGXeh4AzI9c5rm+vyY wpCFMRVwaSYAoP/NQBn15vFMDkhVYOJ6QqbFvrGoI+kiP7pg+73gHzxYKSXRrrRohh5VrbgmQyj 6ghFOpTvBtEtYkNuTHsyQTBa9afB+9Ow== X-Received: by 2002:a5d:5f93:0:b0:435:dbbb:4516 with SMTP id ffacd0b85a97d-4362934abc9mr694258f8f.29.1770321553698; Thu, 05 Feb 2026 11:59:13 -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 20/29] hw/core: Add Remote Port GPIO/Interrupt bridge Date: Thu, 5 Feb 2026 20:58:15 +0100 Message-ID: <20260205195824.2610192-21-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::432; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x432.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=unavailable 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: 1770321794258158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko This patch adds the `remote-port-gpio` device, which enables GPIO levels exchange between QEMU and the remote peer. It maps QEMU's `qemu_irq` lines (GPIOs) to Remote Port `RP_CMD_interrupt` packets, enabling the synchronization of interrupt lines and logic signals across the simulation. This is essential for wiring up interrupt controllers or discrete logic signals (reset lines, enable pins). Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-gpio.c | 183 +++++++++++++++++++++++++++++ hw/core/trace-events | 4 + include/hw/core/remote-port-gpio.h | 33 ++++++ 3 files changed, 220 insertions(+) create mode 100644 hw/core/remote-port-gpio.c create mode 100644 include/hw/core/remote-port-gpio.h diff --git a/hw/core/remote-port-gpio.c b/hw/core/remote-port-gpio.c new file mode 100644 index 0000000000..b9bdbcc5a5 --- /dev/null +++ b/hw/core/remote-port-gpio.c @@ -0,0 +1,183 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * Written by Peter Crosthwaite + * + * This code is licensed under the GNU GPL. + */ + +#include "qemu/osdep.h" +#include "hw/core/sysbus.h" +#include "system/system.h" +#include "system/dma.h" +#include "qemu/log.h" +#include "qapi/qmp/qerror.h" +#include "qapi/error.h" +#include "migration/vmstate.h" +#include "hw/core/qdev-properties.h" +#include "hw/core/irq.h" +#include "trace.h" + +#include "hw/core/remote-port.h" +#include "hw/core/remote-port-proto.h" +#include "hw/core/remote-port-gpio.h" + +#define CACHE_INVALID -1 + +static void rp_gpio_handler(void *opaque, int irq, int level) +{ + RemotePortGPIO *s =3D opaque; + struct rp_pkt pkt; + size_t len; + int64_t clk; + uint32_t id =3D rp_new_id(s->rp); + uint32_t flags =3D s->posted_updates ? RP_PKT_FLAGS_posted : 0; + + /* If we hit the cache, return early. */ + if (s->cache[irq] !=3D CACHE_INVALID && s->cache[irq] =3D=3D level) { + return; + } + /* Update the cache and update the remote peer. */ + s->cache[irq] =3D level; + + clk =3D rp_normalized_vmclk(s->rp); + len =3D rp_encode_interrupt_f(id, s->rp_dev, &pkt.interrupt, clk, + irq, 0, level, flags); + + trace_remote_port_gpio_tx_interrupt(id, flags, s->rp_dev, 0, irq, leve= l); + + if (s->peer->caps.wire_posted_updates && !s->posted_updates) { + rp_rsp_mutex_lock(s->rp); + } + + rp_write(s->rp, (void *)&pkt, len); + + /* + * If peer supports posted updates it will respect our flag and + * not respond. + */ + if (s->peer->caps.wire_posted_updates && !s->posted_updates) { + RemotePortRespSlot *rsp_slot; + struct rp_pkt_interrupt *intr; + + rsp_slot =3D rp_dev_wait_resp(s->rp, s->rp_dev, id); + assert(rsp_slot->rsp.pkt->hdr.id =3D=3D id); + + intr =3D &rsp_slot->rsp.pkt->interrupt; + trace_remote_port_gpio_rx_interrupt(intr->hdr.id, intr->hdr.flags, + intr->hdr.dev, intr->vector, intr->line, intr->val); + + rp_resp_slot_done(s->rp, rsp_slot); + rp_rsp_mutex_unlock(s->rp); + } +} + +static void rp_gpio_interrupt(RemotePortDevice *rpdev, struct rp_pkt *pkt) +{ + RemotePortGPIO *s =3D REMOTE_PORT_GPIO(rpdev); + + trace_remote_port_gpio_rx_interrupt(pkt->hdr.id, pkt->hdr.flags, + pkt->hdr.dev, pkt->interrupt.vector, pkt->interrupt.line, + pkt->interrupt.val); + + qemu_set_irq(s->gpio_out[pkt->interrupt.line], pkt->interrupt.val); + + if (s->peer->caps.wire_posted_updates + && !(pkt->hdr.flags & RP_PKT_FLAGS_posted)) { + RemotePortDynPkt rsp =3D {0}; + size_t len; + + /* Need to reply. */ + rp_dpkt_alloc(&rsp, sizeof(struct rp_pkt_interrupt)); + len =3D rp_encode_interrupt_f(pkt->hdr.id, pkt->hdr.dev, + &rsp.pkt->interrupt, + pkt->interrupt.timestamp, + pkt->interrupt.line, + pkt->interrupt.vector, + pkt->interrupt.val, + pkt->hdr.flags | RP_PKT_FLAGS_response= ); + + trace_remote_port_gpio_tx_interrupt(pkt->hdr.id, + pkt->hdr.flags | RP_PKT_FLAGS_response, pkt->hdr.dev, + pkt->interrupt.vector, pkt->interrupt.line, pkt->interrupt.val= ); + + rp_write(s->rp, (void *)rsp.pkt, len); + } +} + +static void rp_gpio_reset(DeviceState *dev) +{ + RemotePortGPIO *s =3D REMOTE_PORT_GPIO(dev); + + /* Mark as invalid. */ + memset(s->cache, CACHE_INVALID, s->num_gpios); +} + +static void rp_gpio_realize(DeviceState *dev, Error **errp) +{ + RemotePortGPIO *s =3D REMOTE_PORT_GPIO(dev); + unsigned int i; + + s->peer =3D rp_get_peer(s->rp); + + s->gpio_out =3D g_new0(qemu_irq, s->num_gpios); + qdev_init_gpio_out(dev, s->gpio_out, s->num_gpios); + qdev_init_gpio_in(dev, rp_gpio_handler, s->num_gpios); + + for (i =3D 0; i < s->num_gpios; i++) { + sysbus_init_irq(SYS_BUS_DEVICE(s), &s->gpio_out[i]); + } +} + +static void rp_prop_allow_set_link(const Object *obj, const char *name, + Object *val, Error **errp) +{ +} + +static void rp_gpio_init(Object *obj) +{ + RemotePortGPIO *rpms =3D REMOTE_PORT_GPIO(obj); + + object_property_add_link(obj, "rp-adaptor0", "remote-port", + (Object **)&rpms->rp, + rp_prop_allow_set_link, + OBJ_PROP_LINK_STRONG); +} + +static Property rp_properties[] =3D { + DEFINE_PROP_UINT32("rp-chan0", RemotePortGPIO, rp_dev, 0), + DEFINE_PROP_UINT32("num-gpios", RemotePortGPIO, num_gpios, 16), + DEFINE_PROP_UINT16("cell-offset-irq-num", RemotePortGPIO, + cell_offset_irq_num, 0), + DEFINE_PROP_BOOL("posted-updates", RemotePortGPIO, posted_updates, tru= e), +}; + +static void rp_gpio_class_init(ObjectClass *oc, const void *data) +{ + RemotePortDeviceClass *rpdc =3D REMOTE_PORT_DEVICE_CLASS(oc); + DeviceClass *dc =3D DEVICE_CLASS(oc); + rpdc->ops[RP_CMD_interrupt] =3D rp_gpio_interrupt; + dc->legacy_reset =3D rp_gpio_reset; + dc->realize =3D rp_gpio_realize; + device_class_set_props_n(dc, rp_properties, ARRAY_SIZE(rp_properties)); +} + +static const TypeInfo rp_info =3D { + .name =3D TYPE_REMOTE_PORT_GPIO, + .parent =3D TYPE_SYS_BUS_DEVICE, + .instance_size =3D sizeof(RemotePortGPIO), + .instance_init =3D rp_gpio_init, + .class_init =3D rp_gpio_class_init, + .interfaces =3D (InterfaceInfo[]) { + { TYPE_REMOTE_PORT_DEVICE }, + { }, + }, +}; + +static void rp_register_types(void) +{ + type_register_static(&rp_info); +} + +type_init(rp_register_types) diff --git a/hw/core/trace-events b/hw/core/trace-events index ee77916010..fb3125b0eb 100644 --- a/hw/core/trace-events +++ b/hw/core/trace-events @@ -40,3 +40,7 @@ remote_port_memory_master_rx_busaccess(const char *cmd, u= int32_t id, uint32_t fl # remote-port-memory-slave.c remote_port_memory_slave_tx_busaccess(const char *cmd, uint32_t id, uint32= _t flags, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd=3D= %s, id=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%"PR= Ix64", len=3D0x%"PRIx32", attr=3D0x%"PRIx64 remote_port_memory_slave_rx_busaccess(const char *cmd, uint32_t id, uint32= _t flags, uint32_t dev, uint64_t addr, uint32_t len, uint64_t attr) "cmd=3D= %s, id=3D0x%"PRIx32", flags=3D0x%"PRIx32", dev=3D0x%"PRIx32", addr=3D0x%"PR= Ix64", len=3D0x%"PRIx32", attr=3D0x%"PRIx64 + +# 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 diff --git a/include/hw/core/remote-port-gpio.h b/include/hw/core/remote-po= rt-gpio.h new file mode 100644 index 0000000000..940e2ec4fd --- /dev/null +++ b/include/hw/core/remote-port-gpio.h @@ -0,0 +1,33 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * Written by Peter Crosthwaite + * + * This code is licensed under the GNU GPL. + */ +#ifndef REMOTE_PORT_GPIO_H +#define REMOTE_PORT_GPIO_H + +#define TYPE_REMOTE_PORT_GPIO "remote-port-gpio" +#define REMOTE_PORT_GPIO(obj) \ + OBJECT_CHECK(RemotePortGPIO, (obj), TYPE_REMOTE_PORT_GPIO) + +#define MAX_GPIOS 960 + +typedef struct RemotePortGPIO { + /* private */ + SysBusDevice parent; + /* public */ + + int8_t cache[MAX_GPIOS]; + uint32_t num_gpios; + qemu_irq *gpio_out; + uint16_t cell_offset_irq_num; + + bool posted_updates; + uint32_t rp_dev; + struct RemotePort *rp; + struct rp_peer_state *peer; +} RemotePortGPIO; +#endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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 From nobody Sat Feb 7 08:45:11 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=1770321774; cv=none; d=zohomail.com; s=zohoarc; b=DvBlqvEndSXGVQNhKEyzHmzwayZETX83ZFos4wbGwS0s/IncnlT9mAUEUMxNIAPuSZkfVYE/fQsLlcFMGvcpUpXjKJMTN85SlIRcOKd0aNT5yTKOOyubPBdgV8wA9Aj/yk13A+qSZHw48yd19B0WQAaO5Ywn9ZSS7Tzglze+N/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321774; 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=PPpxu2p+Qu33ItPtwVZLTz+VbMPN1gd77PjFYvkTVkY=; b=W8q3KKSBUq0wyOab2MyzLASTZHiLFFYiBeSKAMg2zkaRerb9Tn33qk681WdmDMPt4xWRKwfNgrVqqkrusca9+pVD7N6RUqWRy6tKVJwk2kZgQM9Y04oHsUczdXnWPqDBeSNpTvRtx82mch6L3LkKDGFUxU+y5+sW9eP1XtJgX+s= 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 1770321774855900.6704512454988; Thu, 5 Feb 2026 12:02:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vd-0006w0-Vp; 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 1vo5Va-0006tX-Eq for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:23 -0500 Received: from mail-wr1-x432.google.com ([2a00:1450:4864:20::432]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VW-00039t-Vn for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:22 -0500 Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-4358fb60802so886107f8f.1 for ; Thu, 05 Feb 2026 11:59:18 -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.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321557; x=1770926357; 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=PPpxu2p+Qu33ItPtwVZLTz+VbMPN1gd77PjFYvkTVkY=; b=bAJVH9cNmYk5zaXbMfkaltHGWv8ywuENhTxtljW822rXSbX7r78+IkTbKhefvOu+8z gKnp4BEZI5gk1EIkkzQvw5xYaC67QkPB1fPvLXyJc9qNoJgaXWZVlEhwt8iRsIV8VAg/ s9tWnaLwK69TdvGloPg9zd0xzyjGz6uqPont8j69rrd7y7+BKJerEsfX/CPukRnxntQF /9F9xE7PdGcpahI5z8qGew7waEecAPN+D8em9OocPQ+FHzwfnrzFMrkqtXpRnqVGfuU0 sXIgizQrs82t3cdEFoN8c+QapcQQil4kTts25W6ZGkn5rEenoIHZ6M0D48g1T7HH/cTg oRAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321557; x=1770926357; 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=PPpxu2p+Qu33ItPtwVZLTz+VbMPN1gd77PjFYvkTVkY=; b=dtOTgqGX15R7Qog5Hsm6JIsQa6pB4QtWPl65WjmH71ghDF5DuZGq1aM1YqyTKvZLXA nC7dRPJA4FVnjHQZGvP4i9f+8ZA5bp4ivIEnTIoCX6bhJftIdvwGbhnvtQ50Ze3SDX9q a7U9grlYshV4SkWeTI8a0tLoxKtvj/wvAb6AsWPpvFb1a+tsbgosKNpElVvK7qttP+Vo e0SeOM2Erf0CBaGMVe9xE8ovy6fyj/Lw13Za2/K6qCOmO2xxZid39QC3zKdm5Lb8kC4r m4ndX7DrHEszhx7DfJP+D7DivVqXsIW1uuU/k5+nAmNjrSL67GdCmTj4MRFpKkDQJbIz IWSA== X-Gm-Message-State: AOJu0YwuQJJa/OVlvnLoZrMNKQHY9XNDWUYWoJl/0rz9dXj2iJMS7MQD YHw7sFOlYVGUvhArV259+3wGL8wJznP/1GXsa/StmAeIrqunNOHOVj3deS6dSXhBs/E= X-Gm-Gg: AZuq6aL198uZqru3IPvvvPK5i08X+DdB0kZwkUIES7a29b2OhDE4LzeBzS2Xb4CcMS1 xNVo3chzvV7CUBefRrIb5rf6mhlpsao0L2py6Ose3BTIboxtxDtyDH7bonNNKiWwc3gVqbnVxOd tZyrEfu3z1SXtrsdgIMDeYmagivmVieWQwSNHiShLc+ou9C8jpTpQIgjI0W9g7sKIFDOBz9/lEc 936A9TwFijcbDVBs8wXgfPlkgTmUeuho58/oX7msroUtdFCtYqolyLZhU4Re9OBEUTkrNAbBwAV vciXmyD0vvQCrol7tTOCSSYrh+jWvrKDAmMICvZsIgEAJERLEkOjxGvAk1Y5XW2P/zcNMdNCDuJ yV2BL2oIu91vxPFhcWj2v3bc6rDgzHdUQJeireMhwJ/nP/SwEP66ugZVxFavdwyV7dtM8jfB4gu Dp8Dkk9m/Sby5eyoF0+jUiVDlW9TaXYg== X-Received: by 2002:a05:6000:250a:b0:432:88c4:e180 with SMTP id ffacd0b85a97d-436209bfc2cmr7362732f8f.15.1770321556829; Thu, 05 Feb 2026 11:59:16 -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, Paolo Bonzini , "Edgar E . Iglesias" Subject: [PATCH 22/29] hw/core: Add Remote Port files to build Date: Thu, 5 Feb 2026 20:58:17 +0100 Message-ID: <20260205195824.2610192-23-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::432; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x432.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: 1770321776002158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Add the Remote Port subsystem source files to the build system. These files are compiled when CONFIG_REMOTE_PORT is enabled. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/Kconfig | 4 ++++ hw/core/meson.build | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/hw/core/Kconfig b/hw/core/Kconfig index d1bdf765ee..25f553e189 100644 --- a/hw/core/Kconfig +++ b/hw/core/Kconfig @@ -38,3 +38,7 @@ config SPLIT_IRQ config EIF bool depends on LIBCBOR && GNUTLS + +config REMOTE_PORT + bool + depends on PTIMER && XILINX_AXI diff --git a/hw/core/meson.build b/hw/core/meson.build index b5ba8160e6..7013638fcf 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -27,6 +27,16 @@ system_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files(= 'stream.c')) system_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c')) system_ss.add(when: 'CONFIG_EIF', if_true: [files('eif.c'), zlib, libcbor,= gnutls]) =20 +system_ss.add(when: 'CONFIG_REMOTE_PORT', if_true: files( + 'remote-port-proto.c', + 'remote-port.c', + 'remote-port-memory-master.c', + 'remote-port-memory-slave.c', + 'remote-port-gpio.c', + 'remote-port-stream.c', + 'remote-port-ats.c', +)) + system_ss.add(files( 'cpu-system.c', 'fdt_generic.c', --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321621; cv=none; d=zohomail.com; s=zohoarc; b=U7qM12hAJR6JmJKSHV5pwZqVjSeLpFbTPAvcIgTj4KmS14LKp8NKzlXqeXuAzBZt+XDGS//aq6L85ak4c+/VDw5QQpbQkR84/FiBA+XCVuxUsmWOSQdlsajDmNmYxLu/IUYlYWrQv41cX/azb/QaikIZjlquyGtX1NvfLceNd5w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321621; 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=4qhxa62Apjpg7nJHeZcMHBxhSVe14XdkTu3eXuhEWd0=; b=fQhCgfoCh1BCgrUTYeY9Qv3nuPaSzsWEHWR46Glq+iVasxMmmgievE244ytN9OZTSeIRG75KeCNAwqd6+JtWIw6dQzn8W6ikQHO079CkrJcal+jtv5ssRLslu1Dl7Jvat9AMiTtDuDkkZYTZvqP/tKjBFUqX9RNL2EnS1il+dkU= 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 1770321621930114.70666438085391; Thu, 5 Feb 2026 12:00:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vi-00071R-RI; Thu, 05 Feb 2026 14:59:32 -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 1vo5Vc-0006ud-9n for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:25 -0500 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VY-0003AR-GA for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:24 -0500 Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-4359108fd24so915198f8f.2 for ; Thu, 05 Feb 2026 11:59:20 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321559; x=1770926359; 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=4qhxa62Apjpg7nJHeZcMHBxhSVe14XdkTu3eXuhEWd0=; b=TaDkkcI2WCJC2FWtP87tphDk7qSXuMFxFQAKHQS6V8gPpkjFcFNhQ1veWrRh0EaAdL VnrSZsvBqgNO/gXiwJzRqnTZpgUFqzr+gMyPlNu0iKyElyrfrpv27VVnEYfUSnmPTi/J vSlW7Y04MqR5udsbHeDI33qKTnISMYYnddVXH4heq/RyuesPiKT3Z7y74GfgqcE1uupl sMUeUZHYvk7ezVq8ZSFz9lRYMY9EtMwKcvXIhB3zksFc+7VFRvf942zcN8/JKyAQnc3G AtBygJRW+R8vH4RaAd1MMexWeylH5xLcs8h7cqwXK1+civh9j8IijEtIksMFvujVowfo Niyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321559; x=1770926359; 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=4qhxa62Apjpg7nJHeZcMHBxhSVe14XdkTu3eXuhEWd0=; b=tA15CuGkc3PG8q4eeY50dp+m/Lae4cVNtz/I6HTelAzBL0YaHdusaYmxr7AJB+jM5B FOSM0bK69tM69vtXfv1BRXwpERQriqb4y2jgSzCjGlGXDRDDIJGKURULEfNj4i3Abav2 Mn52NUFDS068qo2A2se4gRxc9AxZPP67tAACvkdn5OnklH7kkdxzPX4BD5AjtRtb6LOA q8n6YboCiOVYws7ZuWezqlKT7V8K3jU09jlnrFNeiMEXFlROkAeCFs+kAhUTeG86EAQ1 m61zM7ZupXk8ZsjtGbjCsiD++zLNgecRUlfIWl7D7V5FhvtaZg7Gx/idOjoxdSwHwAzZ 9m+g== X-Gm-Message-State: AOJu0Yw5JXMXnhAjreZ/B+ebkqx/BoyO+bVmFHUTDa7XAfKS3wKwGbmY k2viStnEW5ffEValeMcFxEt4JXwJajM5sGjvNwvt70IrOpNNZnhomqlPvxg3XsSpbw8= X-Gm-Gg: AZuq6aKY1LBClZ3kPWoEWWUKc0x3pkENy935uQ3yyMiAcQJ9oiKIthk2WhfiY3rHOtT EwcAVCHKEIWayDzRCa1/wZ0d1gL50Eu/cr3L78HakZ/AiBbALko2yFif7hwbielhdHxgObAoSkx 9OKbnnfOo8qb+LvyTzu3T7qTzfkFFg0X/YtKQdRX4h4J0BPfET5VQx+ileJGe7Zm/NPyJ1MyPOR /s5I4qMKwt+PChPE9blbS80jhMTCU5lk+eauWPRyv1CU9b07h1MGOYM8NiyG0nzACub2sUsXVnL r2prBhaoFzUNLkPMOc4i6fl8E9fU/Yzl5dOHL/3zwoE9KYch24j8xG1gNCLwLcqlV6fo6M76Z7p IznIDI2A53fEeBMfz/y4XkBwobDV54WpkCiX2EMz/5hJZ05rUnh+7CtD+pd3UcuHAeowGmCsXyA G9hoXNVaWC/DbySV4iZjc= X-Received: by 2002:a05:6000:24ca:b0:430:f97a:6f42 with SMTP id ffacd0b85a97d-4362968d49cmr546325f8f.54.1770321558502; Thu, 05 Feb 2026 11:59:18 -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, Paolo Bonzini , "Edgar E . Iglesias" Subject: [PATCH 23/29] system: Introduce -sync-quantum command line option Date: Thu, 5 Feb 2026 20:58:18 +0100 Message-ID: <20260205195824.2610192-24-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::42e; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42e.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=unavailable 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: 1770321625573154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Add a new global option '-sync-quantum' to specify the maximum time interval, in nanoseconds, between synchronizations with remote peers. In co-simulation environments (such as QEMU coupled with a SystemC simulator), time must be synchronized periodically to ensure functional accuracy. The 'sync-quantum' defines the maximum amount of time QEMU can simulate ahead of its remote peers before a mandatory synchronization event (sync packet) occurs. This value is stored in the global 'global_sync_quantum' variable and serves as a default hint for device models and Remote Port instances to manage their simulation time. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- include/system/system.h | 2 ++ qemu-options.hx | 11 +++++++++++ system/vl.c | 8 ++++++++ 3 files changed, 21 insertions(+) diff --git a/include/system/system.h b/include/system/system.h index 0cd012004d..f187544147 100644 --- a/include/system/system.h +++ b/include/system/system.h @@ -59,6 +59,8 @@ extern MlockState mlock_state; =20 extern const char *machine_path; =20 +extern uint64_t global_sync_quantum; + #define MAX_OPTION_ROMS 16 typedef struct QEMUOptionRom { const char *name; diff --git a/qemu-options.hx b/qemu-options.hx index b7dd2a64f0..8ef0c57507 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -765,6 +765,17 @@ SRST Preallocate memory when using -mem-path. ERST =20 +DEF("sync-quantum", HAS_ARG, QEMU_OPTION_sync_quantum, + "-sync-quantum Max time between synchroniation, nanoseconds.\n", + QEMU_ARCH_ALL) +SRST +``-sync-quantum val`` + Maximum time between synchronization . + This value is used to drive periodic synchronization with remote port = peers. + It is also used to set device models sync-quantum properties controlli= ng + the maximum amount of ahead of time simulation that is prefered (only = a hint). +ERST + DEF("machine-path", HAS_ARG, QEMU_OPTION_machine_path, "-machine-path DIR A directory in which to create machine nodes\n", QEMU_ARCH_ALL) diff --git a/system/vl.c b/system/vl.c index 4750b1cf69..467646c3ff 100644 --- a/system/vl.c +++ b/system/vl.c @@ -182,6 +182,7 @@ static QemuPluginList plugin_list =3D QTAILQ_HEAD_INITI= ALIZER(plugin_list); static BlockdevOptionsQueue bdo_queue =3D QSIMPLEQ_HEAD_INITIALIZER(bdo_qu= eue); static bool nographic =3D false; static int mem_prealloc; /* force preallocation of physical target memory = */ +uint64_t global_sync_quantum; const char *machine_path; static const char *vga_model =3D NULL; static DisplayOptions dpy; @@ -3129,6 +3130,13 @@ void qemu_init(int argc, char **argv) case QEMU_OPTION_mem_prealloc: mem_prealloc =3D 1; break; + case QEMU_OPTION_sync_quantum: + if (qemu_strtou64(optarg, &optarg, 10, + &global_sync_quantum)) { + error_report("failed to parse sync_quantum"); + exit(1); + } + break; case QEMU_OPTION_machine_path: machine_path =3D optarg; break; --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321756; cv=none; d=zohomail.com; s=zohoarc; b=Y/UjvG9h0F7mL5ww6pjq1C7ACZ3GoUR8TgjmXrg5yCAmYzbVp/iCRBCfs9l+T6NIf4S2n4L1dzajPTYE8+N0qz5Sj2x5nKkcHtLhlEZJdxyccguZE0FY3yK3SdwcmajTVWVyeeFGM9CAi9DKdS4aZh8RxAjvLgqpOr9atywfX2w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321756; 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=M0CayTsyi6p8w45gl32kyiBwM+aaroeJuLz0N2LnaBc=; b=EaFBvjIa/5HKd1SkLeoG60b+IWoEYLxs3JEeQXuB0k9nddOrjwYlETtB6jO60whnk825zyublKui60lOjfv7lzML5VQdgzFFAMKgFYieg6kts7KaQwJjbxaictxm2Za3+7DDwoQ7cLLVrrgUxzlHAHXQrB0X+yX54XQzgEJk1QM= 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 1770321756367969.7512963019891; Thu, 5 Feb 2026 12:02:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vl-00077o-3y; Thu, 05 Feb 2026 14:59:33 -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 1vo5Vd-0006vV-Io for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:25 -0500 Received: from mail-wr1-x434.google.com ([2a00:1450:4864:20::434]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5VZ-0003Ao-V7 for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:25 -0500 Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-42fbc305552so1427743f8f.0 for ; Thu, 05 Feb 2026 11:59:21 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321560; x=1770926360; 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=M0CayTsyi6p8w45gl32kyiBwM+aaroeJuLz0N2LnaBc=; b=KGj6hoH2tMjOkoSB8NtCX2TxeFPxm33xYdlfKWCb4GpSY4pZHMp/zq1sBiZLlfuk06 BH3fvw1tVqIY5Gtez8bkiYvkeLV8aZ5U/Sn2qpAV2L83XIWbLR6j1GnlKs5kOz5X2Shh yC+qGxz/99YXEE0WIWjczvX1p6ZBcGfp3lr3W0S6LwmrFamPSAXV8klmMzfBSigETD/J yFR99znNsb0ynNrRom+mWAVkx9cjJ//G34tIP3lwI8+kwLr8OXb8dCtSjBe7+/dqqrIF ihZOxS7D0S2n7ppLfJcClXfvetphDbELKZz0Ecw7p2BW5L2KQqXQb4lRvmAfswWMnRW1 4Ivw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321560; x=1770926360; 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=M0CayTsyi6p8w45gl32kyiBwM+aaroeJuLz0N2LnaBc=; b=Gj/Ke5ch1kej2Wh5XiiPdR11j0bnK6L6y4FV3jmzqS65D6C/AvaTEEr/LWZ072TNmE vnD7a3Haa+KF0qqVnXwSMGpkvqdXsx3LF1jx9esvBgUcdIo7JlXbapIyuQ3BhsaP5JhY mcGMbxvwzFd2qv8WR0fEHMH1jTDfW3D23AgxvkeLOkQBchrL+iE3PBA3CvCXWj/kQvW3 VIvE28fEBCOJT6ttrP2YKsxZxYexvHlwuAGex0z05krFao/3W62ZSSzcmGxA1uK6QPaZ eCs3HnamR6P+9kGW4iLLMjkC4fZngzyONqPEFeLFLzCWXSZ++wdpbr7HEtGZ8c7TalPn zfnQ== X-Gm-Message-State: AOJu0YzFZ3k9ySDL7KYi0JjWv+TjwJMPNJwIt2CXsYVr5kxclyEPLWfH 7EdjLZfQ1QpY+/7qAVzZ2+1mz+vqAt1kf1aZyhI65UKZ1Ih1vUGaftttFpNwucLi4wQ= X-Gm-Gg: AZuq6aJDeHvdFJiMvTBtd6TT6icw2E46f7Oh6k/YgPYLASzhDkJTFYlFG9uj8Rugy0Q HRf3evXLPQzQa9UYmQwawmqqXY3GZIdoLJAFkQ5Cx2WbdEQFWML7gYiUVkof7aC3Wcuu5Obt87U Ld/dRHENWmwqnbI8UOVRUreiCw0kqn3pjk1JZCoIdv1pOeVEJvCP0OQoadMLokRVAxp3oKNXI3N KQuACwgtGX7NKpzdUuiPyL0dbDCu4CxgWPkYPjVCfNSRjsTYsFvuYIoqF8O7+1j50PuZOPMYdCI fuxHvxCXl1YfR76Y89CDHI0q2T6BVyzT/fjLXVNC4SuZNuJ/JNNvZ+qvRmo5QV1/S6gWwDFrS+1 TVbkNWv0SXkrYwHzOzjbm1SgY34oJCBGI7bSmfQeIgptNX+uJ0CSG16v09od3PuDbgP7xMTSBZQ /M6Oigfzziw2h17p/+z/ByVvlRqsrrUQ== X-Received: by 2002:a05:6000:310b:b0:436:1973:3b05 with SMTP id ffacd0b85a97d-4362933bdf4mr568935f8f.2.1770321559945; Thu, 05 Feb 2026 11:59:19 -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 24/29] hw/core: Add FDT support to Remote Port GPIO Date: Thu, 5 Feb 2026 20:58:19 +0100 Message-ID: <20260205195824.2610192-25-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::434; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x434.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: 1770321759334154100 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Implement the FDTGenericIntc interface for the Remote Port GPIO device. This enables the device to be recognized as an interrupt controller when instantiated via the fdt-generic framework. It allows other devices defined in the Device Tree to connect their interrupt lines to this GPIO controller using standard FDT properties (e.g., 'interrupts' and 'interrupt-parent'). The implementation maps the interrupt specifier from the Device Tree cells to the corresponding internal GPIO input line based on the configured cell offset. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-gpio.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/hw/core/remote-port-gpio.c b/hw/core/remote-port-gpio.c index b9bdbcc5a5..c17a65f63a 100644 --- a/hw/core/remote-port-gpio.c +++ b/hw/core/remote-port-gpio.c @@ -19,6 +19,8 @@ #include "hw/core/irq.h" #include "trace.h" =20 +#include "hw/core/fdt_generic_util.h" + #include "hw/core/remote-port.h" #include "hw/core/remote-port-proto.h" #include "hw/core/remote-port-gpio.h" @@ -153,14 +155,34 @@ static Property rp_properties[] =3D { DEFINE_PROP_BOOL("posted-updates", RemotePortGPIO, posted_updates, tru= e), }; =20 +static int rp_fdt_get_irq(FDTGenericIntc *obj, qemu_irq *irqs, + uint32_t *cells, int ncells, int max, + Error **errp) +{ + RemotePortGPIO *s =3D REMOTE_PORT_GPIO(obj); + + if (cells[s->cell_offset_irq_num] >=3D s->num_gpios) { + error_setg(errp, "RP-GPIO was setup for %u interrupts: index %" + PRIu32 " requested", s->num_gpios, + cells[s->cell_offset_irq_num]); + return 0; + } + + (*irqs) =3D qdev_get_gpio_in(DEVICE(obj), cells[s->cell_offset_irq_num= ]); + return 1; +}; + static void rp_gpio_class_init(ObjectClass *oc, const void *data) { RemotePortDeviceClass *rpdc =3D REMOTE_PORT_DEVICE_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); + FDTGenericIntcClass *fgic =3D FDT_GENERIC_INTC_CLASS(oc); + rpdc->ops[RP_CMD_interrupt] =3D rp_gpio_interrupt; dc->legacy_reset =3D rp_gpio_reset; dc->realize =3D rp_gpio_realize; device_class_set_props_n(dc, rp_properties, ARRAY_SIZE(rp_properties)); + fgic->get_irq =3D rp_fdt_get_irq; } =20 static const TypeInfo rp_info =3D { @@ -171,6 +193,7 @@ static const TypeInfo rp_info =3D { .class_init =3D rp_gpio_class_init, .interfaces =3D (InterfaceInfo[]) { { TYPE_REMOTE_PORT_DEVICE }, + { TYPE_FDT_GENERIC_INTC }, { }, }, }; --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321734; cv=none; d=zohomail.com; s=zohoarc; b=FE4FZT5i1Wjp2DbaQMMQQpjKclcmZR4hDZSN5bG//Ju/+K/mo69Q5nuea/VjRJeLJvvBQJQW7YNNisBASGudr+tBYymgfkefmfC4ID6qyNKX+WiFXmvNMep35HdpFfvx3PZm8qwdRtZST/iVG3Vu3Ay1+DagS8IeghLz9DETocY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321734; 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=MbMkUUvH+NcjHWVg6Bu6jsxDREeMbXx3rIs90lyP6Y4=; b=PwtWF7b4gxfR2rboncEwAImxmIdhdJIILRdGa2pCVoUtFACgUhL9iU+zZxkuIs3MQAFiwvvSGzkr785KFs4uhgEQMTx05EK7LrzqrJPfK0WIzr1bSNj8hzlfOx9eCZkoIB7Ro41DTgWiDFSNe8iFLa5tUYSw+VrYjhelrhLQNmI= 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 1770321734179776.6913546811375; Thu, 5 Feb 2026 12:02:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vn-00079U-2w; Thu, 05 Feb 2026 14:59:35 -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 1vo5Ve-0006zE-TD for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:27 -0500 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5Vb-0003BO-GJ for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:26 -0500 Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-43622089851so922338f8f.3 for ; Thu, 05 Feb 2026 11:59:23 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321562; x=1770926362; 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=MbMkUUvH+NcjHWVg6Bu6jsxDREeMbXx3rIs90lyP6Y4=; b=PNLfoQMdXD8q2jiwlOX+6m7mXRMFiSHHzBUng+b6fBsFPptoFpE/a4AYJQGh1A8h5A DUAz7bgLY1ftpsdtoWgMNRzezl4cZUgGY8/ZqQDbwwZ9oXweApNd5ttC2k2X8I6WSXsC EKTGpS3KmUtYlC2LnUojezgj37A89DiKN6PcB1dUPVwVGOMCDE8Mt7YgnGB8CnFSdB5i enceppkZdNYUo53cMV+8bQueNgEVMtQvZ7f1/aDtjIh6qkef4L8/WAXTfsGe1Tg2VB2y B9Y09ksDcgRgHK6BeRgMHb1OxT2OriEGNgmTDFbS4Jrsyai3zTpWaDXPBw6NWvyPbE0V RxZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321562; x=1770926362; 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=MbMkUUvH+NcjHWVg6Bu6jsxDREeMbXx3rIs90lyP6Y4=; b=qasf8MZjMSZJ9kIFArAZSsvOrqCwxvCoIy6Dd4PP9I88+/9xyp5VB16qVFu+4Dl9rf kMnLpcz4Jx9IOMb6i8Yt4HptHNIWZPOf9DMXFtZ7kO7ioWApnGG8dahh+FN3g97y9lTx n21R53dpZniukB4pxNH6duutZtvEcLHuf3bFjXWVFmILFVJBlafWuhDJOGcF9ExWdtGb pSzqQBTVq2axZDSSHp+iQ/idWTjZZOeULjrBxzR3GewqwvM553fssr0QripR+fJvSXh4 DoNdGqagsazCmkxGXcCwYY45O7zrN0ElS0n+fY/Azs7NuTTiR7BcRwvT9Ectd6WJL6Nf FAcg== X-Gm-Message-State: AOJu0YxOsUQ8SkyB6FRgzuNovVZLOhpftLeD2yjPZdg2tVtDNiuM4RhC Nbvh/ZP+cbDMXHiCkOd9oOipxrXd5qwFMmIHOc73Sp91aOnkuVUMkumUM1mKqdfRd6U= X-Gm-Gg: AZuq6aJH+r5PS8ivQDIvfWBUJcFIH54+Wws/VmKaaUf9Vuy1QtgYuSJJPiYOLvnpmSt IbYKb/S748r8BQugY/IWflq+uzciy71jqLMvGEZDKioqrnGr0Ktv0xdSVZ+YXaqFL5RmwjDH037 WxNuQSN9G+YduYRo5S45OOQkxYrUyfXY/AAEWYWzCB1CInCYrI3EwL6hYdPUytPODtXi/KXLRc8 Wn0PyMsIFcB6OyElLr7Al/zTxxc1oyNuPBUY9gB/oVsx/UttUlkkEFVzv2kERYH6cfwZJh07cyM rldsnlVmZxeAndAUDPDXsrO7zxRh6Wvfg4VKwx87qoxevzOgv73nFslh5EA4JIt7Y5IopBPaH2q bBrCYgzhsQR5zOpOcnWeMnsfNDS+4Yz6xPYknX0u2/Ok2qpIQNXAJkLaoOnV8UGYRalsMkyJu4X 0n9mE/wxxoWhtQW4TcFQA= X-Received: by 2002:a05:6000:2c05:b0:435:95c9:6891 with SMTP id ffacd0b85a97d-4362938aee7mr762694f8f.42.1770321561485; Thu, 05 Feb 2026 11:59:21 -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 25/29] hw/core: Add FDT support to Remote Port memory master Date: Thu, 5 Feb 2026 20:58:20 +0100 Message-ID: <20260205195824.2610192-26-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::42a; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x42a.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=unavailable 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: 1770321735800158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Implement the FDTGenericMMap interface for the Remote Port Memory Master. This enables the device to dynamically parse memory ranges defined in the Device Tree ('reg' property) and register them as system bus MMIO regions. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-memory-master.c | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/hw/core/remote-port-memory-master.c b/hw/core/remote-port-memo= ry-master.c index 4a6c43423d..854b35e99f 100644 --- a/hw/core/remote-port-memory-master.c +++ b/hw/core/remote-port-memory-master.c @@ -22,6 +22,8 @@ #include "hw/core/remote-port.h" #include "hw/core/remote-port-memory-master.h" =20 +#include "hw/core/fdt_generic_util.h" + #ifndef REMOTE_PORT_ERR_DEBUG #define REMOTE_PORT_DEBUG_LEVEL 0 #else @@ -277,6 +279,35 @@ static void rp_memory_master_init(Object *obj) OBJ_PROP_LINK_STRONG); } =20 +static bool rp_parse_reg(FDTGenericMMap *obj, FDTGenericRegPropInfo reg, + Error **errp) +{ + RemotePortMemoryMaster *s =3D REMOTE_PORT_MEMORY_MASTER(obj); + FDTGenericMMapClass *parent_fmc =3D + FDT_GENERIC_MMAP_CLASS(REMOTE_PORT_MEMORY_MASTER_PARENT_CLASS); + int i; + + /* Initialize rp_ops from template. */ + s->rp_ops =3D g_malloc(sizeof *s->rp_ops); + memcpy(s->rp_ops, &rp_ops_template, sizeof *s->rp_ops); + s->rp_ops->valid.max_access_size =3D s->max_access_size; + s->rp_ops->impl.max_access_size =3D s->max_access_size; + + s->mmaps =3D g_new0(typeof(*s->mmaps), reg.n); + for (i =3D 0; i < reg.n; ++i) { + char *name =3D g_strdup_printf("rp-%d", i); + + s->mmaps[i].offset =3D reg.a[i]; + memory_region_init_io(&s->mmaps[i].iomem, OBJECT(obj), s->rp_ops, + &s->mmaps[i], name, reg.s[i]); + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmaps[i].iomem); + s->mmaps[i].parent =3D s; + g_free(name); + } + + return parent_fmc ? parent_fmc->parse_reg(obj, reg, errp) : false; +} + static Property rp_properties[] =3D { DEFINE_PROP_UINT32("map-num", RemotePortMemoryMaster, map_num, 0), DEFINE_PROP_UINT64("map-offset", RemotePortMemoryMaster, map_offset, 0= ), @@ -289,9 +320,11 @@ static Property rp_properties[] =3D { =20 static void rp_memory_master_class_init(ObjectClass *oc, const void *data) { + FDTGenericMMapClass *fmc =3D FDT_GENERIC_MMAP_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); device_class_set_props_n(dc, rp_properties, ARRAY_SIZE(rp_properties)); dc->realize =3D rp_memory_master_realize; + fmc->parse_reg =3D rp_parse_reg; } =20 static const TypeInfo rp_info =3D { @@ -301,6 +334,7 @@ static const TypeInfo rp_info =3D { .instance_init =3D rp_memory_master_init, .class_init =3D rp_memory_master_class_init, .interfaces =3D (InterfaceInfo[]) { + { TYPE_FDT_GENERIC_MMAP }, { TYPE_REMOTE_PORT_DEVICE }, { }, }, --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321654; cv=none; d=zohomail.com; s=zohoarc; b=hoM5/VA5uXJkSktpO3F9GnpdsLZbSZ/g1gGDdEwKn73sfkWrAN6+Nt3YDGY3GFg4AWejlhtryJ7W4FVw16hoafpd7keaMLBmSZKgXGNLKrf4vfyLhwzkm4E7CZlYHkLJPWAXlt7tpMwgbrw1XzVR+nQIe+ZVUhUNtDNG9sFqRXs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321654; 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=ODPdQ6CGlB8sV1EdByujVoiH2o+cygpKFap6nFlHY6I=; b=er8TW5R4ZkpJAXPhrHEVRC0wqDW+qB59pIvjFjh0ivX/PCqzQrl0YxmKXOmwkxQRsitXkYU1AF6tPU6jkEoXi63eHwKSsLPHUQoTK9WiYlxZpjTFClh3fmZJJ3qJS1Jzr1VkbOoAquwuw7kF56/O03edWvcLyMKOYQbAwWzAUgc= 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 1770321654785578.0816571566697; Thu, 5 Feb 2026 12:00:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vo-0007AB-DJ; Thu, 05 Feb 2026 14:59:36 -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 1vo5Vf-0006zQ-5y for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:28 -0500 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5Vc-0003Bj-Pq for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:26 -0500 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-47ee3a63300so14504485e9.2 for ; Thu, 05 Feb 2026 11:59:24 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321563; x=1770926363; 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=ODPdQ6CGlB8sV1EdByujVoiH2o+cygpKFap6nFlHY6I=; b=Q1OK6GAWjgpO4TFab8dGa1a5elPXISG4JgM2QQF1tK5lZBhbsnpzoeRwDr8HeTdNYG Fv7mG3uf5vYbDr84sW1lU8PldU2MExNqbgD4w1q4I+e2Kkc1wTaDfVblF5dUX5MRb+YK c8pzUOkP5Pq+RuEq/weMZeWwgv/0tygfQjnClwhcNxsvSx6zZSpnonZ9Gw7heKgkexEM uSAsfUkq4mpHAdhZmafAsG+wc3yBRtL5T8P5Rqn1fUEZNTaZfSh4bwQgddBsHB9vdpLa l40MVLpBrnUUYs15h+UPz0vQvoPNGg/ltKgzziyi9EGS9JBOb+vEJc0b+THu3ed/amE0 v9Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321563; x=1770926363; 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=ODPdQ6CGlB8sV1EdByujVoiH2o+cygpKFap6nFlHY6I=; b=Ew1rEIocCewXukShVVeo7s6jrE4mw8Wl2xs9oV+W0xqjkb9QZgaxRARxmOWN8M+mjO mAIbzAiNvewvwm9baeW/ZjflGgP6OY2k7SMpj4mpkXcDdulVODstI23248lYVN5q0+58 sJLqSYs8B8k+qR2B8CEkVwsYWF0jXamCg15dFH9i/V+F1JTa+ARN+MUYSBA267fSTGS7 Ru0IDkjVX/S6vv9Lt8UHlO8uffHxRlxBbXlLn6f6fUq2nDkZO3jUS0xAtAOYab5vwvua Q4PqJNywYwch38abdAekY2LFxKgfP9r6LkFxyKR+qStpaJIOqZLIpwELU2LBoEiZTzLl b2FQ== X-Gm-Message-State: AOJu0Ywre7dS7Wj77Ya5wuMEQnytpTNbmFIo+08/hlRdBJrytNu9nWnF YNbmaeTI+6oFrzCZW+vGAmTKM7g6Xfb+FUyzezUetMlhiU6KBx0fPtyUHHwadhbknv0= X-Gm-Gg: AZuq6aKDVFwx+LEpI5rFo2C6inzatFCZ2lri8I3Vbdz4MLPO6jqVfQ8yY4fm0KMKJYh gpyXZLw+MyI4jxbC6+SegKgyJakYt8BBovCVUEjH0XT6bj+9c3qi+kBzfmRyfF38dmRF24bH1mN 78tWm+m6O7flf2v44/u/g/qKsjJheOAVoZAyj5348c3BIcVu0JjHp7BEhBSTFzzy/R7mL3EneZT 30j/oqCfFgRD2CrE8FeERO/OZIuv1p0sV6I+M50D+HuFMz+1ZM3tsdEWlDE2QBu5uop+6m/mFK4 4Y1MFqBBT5VaT2ULJGjQbtrtflesCbOhaoC4hTjlKvLv96iSwVdigDbu/MVM8AYlyvu9eUug9tw dec0P18EIcEWw5Jo4LKdUdaVAi8P48lsrrWP2VktRShWsDz9G1b5lPYxUKLclnfaPxYQ9wuZwqo GHpgqvmJXHvqG32Ak3/Qo= X-Received: by 2002:a05:6000:1844:b0:432:7d2a:2be4 with SMTP id ffacd0b85a97d-4362938023amr621859f8f.60.1770321562947; Thu, 05 Feb 2026 11:59:22 -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 26/29] hw/core: Add Remote Port connection support to fdt-generic Date: Thu, 5 Feb 2026 20:58:21 +0100 Message-ID: <20260205195824.2610192-27-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::32d; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x32d.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=unavailable 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: 1770321655301158500 Content-Type: text/plain; charset="utf-8" From: Ruslan Ruslichenko Extend the fdt-generic utility to automatically configure Remote Port devices defined in the Device Tree. This patch enables the system to: - Identify Remote Port devices and their configuration parameters directly from the Device Tree description. - Automatically establish connections between these devices and the central Remote Port adaptor. - Register legacy reset handlers for devices instantiated via FDT, as required by specific Remote Port devices to ensure they reset properly. This allows users to define complex co-simulation environments purely through Device Tree data, removing the need for hardcoded initialization. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Ruslan Ruslichenko --- hw/core/fdt_generic_util.c | 120 +++++++++++++++++++++++++++++++++---- 1 file changed, 107 insertions(+), 13 deletions(-) diff --git a/hw/core/fdt_generic_util.c b/hw/core/fdt_generic_util.c index d183a44433..180038baf6 100644 --- a/hw/core/fdt_generic_util.c +++ b/hw/core/fdt_generic_util.c @@ -61,6 +61,9 @@ } \ } while (0) =20 +#include "hw/core/remote-port-memory-slave.h" +#include "hw/core/remote-port.h" + #define PROP_ARRAY_LEN_PREFIX "len-" =20 /* FIXME: wrap direct calls into libfdt */ @@ -1097,6 +1100,20 @@ static int fdt_init_qdev(char *node_path, FDTMachine= Info *fdti, char *compat) } fdt_init_set_opaque(fdti, node_path, dev); =20 + /* + * Set the default sync-quantum based on the global one. Node properti= es + * in the dtb can later override this value. + */ + if (global_sync_quantum) { + ObjectProperty *p; + + p =3D object_property_find(OBJECT(dev), "sync-quantum"); + if (p) { + object_property_set_int(OBJECT(dev), "sync-quantum", + global_sync_quantum, &errp); + } + } + props =3D qemu_devtree_get_props(fdti->fdt, node_path); for (prop =3D props; prop->name; prop++) { const char *propname =3D trim_vendor(prop->name); @@ -1142,25 +1159,99 @@ static int fdt_init_qdev(char *node_path, FDTMachin= eInfo *fdti, char *compat) fdt_init_qdev_scalar_prop(OBJECT(dev), p, fdti, node_path, prop); } =20 + if (object_dynamic_cast(dev, TYPE_REMOTE_PORT_DEVICE)) { + for (i =3D 0; ; ++i) { + char adaptor_node_path[DT_PATH_LENGTH]; + uint32_t adaptor_phandle, chan; + DeviceState *adaptor; + char *name; + + adaptor_phandle =3D qemu_fdt_getprop_cell(fdti->fdt, node_path, + "remote-ports", + 2 * i, false, &errp); + if (errp) { + fprintf(stderr, "cant get phandle from \"remote-ports\" " + "property\n"); + break; + } + if (qemu_devtree_get_node_by_phandle(fdti->fdt, adaptor_node_p= ath, + adaptor_phandle)) { + fprintf(stderr, "cant get node from phandle\n"); + break; + } + while (!fdt_init_has_opaque(fdti, adaptor_node_path)) { + fdt_init_yield(fdti); + } + adaptor =3D DEVICE(fdt_init_get_opaque(fdti, adaptor_node_path= )); + name =3D g_strdup_printf("rp-adaptor%" PRId32, i); + object_property_set_link(OBJECT(dev), name, OBJECT(adaptor), &= errp); + fprintf(stderr, "connecting RP to adaptor %s channel %d", + object_get_canonical_path(OBJECT(adaptor)), i); + g_free(name); + if (errp) { + fprintf(stderr, "cant set adaptor link for device property= \n"); + break; + } + + chan =3D qemu_fdt_getprop_cell(fdti->fdt, node_path, "remote-p= orts", + 2 * i + 1, false, &errp); + if (errp) { + fprintf(stderr, "cant get channel from \"remote-ports\" " + "property\n"); + break; + } + + name =3D g_strdup_printf("rp-chan%" PRId32, i); + object_property_set_int(OBJECT(dev), name, chan, &errp); + /* + * Not critical - device has right to not care about channel + * numbers if its a pure slave (only responses). + */ + if (errp) { + fprintf(stderr, "cant set %s property %s\n", name, + error_get_pretty(errp)); + errp =3D NULL; + } + g_free(name); + + name =3D g_strdup_printf("remote-port-dev%d", chan); + object_property_set_link(OBJECT(adaptor), name, OBJECT(dev), &= errp); + g_free(name); + if (errp) { + fprintf(stderr, "cant set device link for adaptor\n"); + break; + } + } + errp =3D NULL; + } + if (object_dynamic_cast(dev, TYPE_DEVICE)) { + DeviceClass *dc =3D DEVICE_GET_CLASS(dev); const char *short_name =3D qemu_devtree_get_node_name(fdti->fdt, node_path); =20 - /* Connect chardev if we can */ - if (serial_hd(fdt_serial_ports)) { - Chardev *value =3D (Chardev *) serial_hd(fdt_serial_ports); - char *chardev; - - /* Check if the device already has a chardev. */ - chardev =3D object_property_get_str(dev, "chardev", &errp); - if (!errp && !strcmp(chardev, "")) { - object_property_set_str(dev, "chardev", value->label, &err= p); - if (!errp) { - /* It worked, the device is a charecter device */ - fdt_serial_ports++; + /* + * We don't want to connect remote port chardev's to the user faci= ng + * serial devices. + */ + if (!object_dynamic_cast(dev, TYPE_REMOTE_PORT)) { + /* Connect chardev if we can */ + if (serial_hd(fdt_serial_ports)) { + Chardev *value =3D (Chardev *) serial_hd(fdt_serial_ports); + char *chardev; + + /* Check if the device already has a chardev. */ + chardev =3D object_property_get_str(dev, "chardev", &errp); + if (!errp && !strcmp(chardev, "")) { + object_property_set_str(dev, "chardev", value->label, + &errp); + if (!errp) { + /* It worked, the device is a charecter device */ + fdt_serial_ports++; + } } + errp =3D NULL; } - errp =3D NULL; } =20 /* Regular TYPE_DEVICE houskeeping */ @@ -1176,6 +1267,9 @@ static int fdt_init_qdev(char *node_path, FDTMachineI= nfo *fdti, char *compat) } else { object_property_set_bool(OBJECT(dev), "realized", true, &error_fatal); + if (dc->legacy_reset) { + qemu_register_reset((void (*)(void *))dc->legacy_reset, de= v); + } } } =20 --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321598; cv=none; d=zohomail.com; s=zohoarc; b=YZM1dKpNNzFTKIVKGssiLwSpHxnNGBpIzFWtP0mqZtDeDjASDxvxFhBGIDDygvDghzhV6y6rDgYh8+RG0zli9ZKhtk/WK/gcmXrnGDtmcFjbiS6J/AalylwrVuI7HZUf2q78sJ5BHPktBU+4gumyndbL0/7y/Wd5iiXr02/BXfc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321598; 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=sbSmGmcLyJAYSLJVq9qt6emaKelHhhG3medBeM4cN70=; b=MLZ30munkCrB9tViOZWitCwyEq/pKqPJYh9qWmTEH5HuAMV+p8fTWTq7lyOupC7wJS458QzqmVkQDnB6r9hUJYx9GGVPDit1qwOSZMfu3C9QkrUSJv6K5lGO+YPDDa16EbztqJlvIB/KRNYfhYpOZgfMaBkLgT5NLuQwgobxO9E= 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 177032159833073.20806707712052; Thu, 5 Feb 2026 11:59:58 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vo-0007AN-TB; Thu, 05 Feb 2026 14:59:36 -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 1vo5Vg-0006zZ-1r for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:28 -0500 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5Ve-0003CR-DL for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:27 -0500 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-47ee0291921so14048625e9.3 for ; Thu, 05 Feb 2026 11:59:25 -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.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321565; x=1770926365; 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=sbSmGmcLyJAYSLJVq9qt6emaKelHhhG3medBeM4cN70=; b=BXVyWMNashwOht3f4ANa1ekKUGLvenijrutAMBuH5gaUi+qIXXuooa+Auq/1gNLrq6 dpWMRkSqKM5VmcdPCeX4AqtWgqS+WAPAuZavLmxnRLDQim2ShgZ23YPBA97Ktd38KbqV 2wHWUSjn0h6+nAobsldINTESVBp/i70tDxHnkck5AwtJOweqyQVsVa50ZADrHMK4uU6O mIEkKRb35YzokXFqTPBmJw8Muf6UKLvDpQikbAsvwVSCQ9iWqh3hDb3B4KZKt8zYO28L etNBFNE5VjJ0UxUwy6kLwf873MD4ihEDqduMipYTE+kdtshmTuJfsU8QZABg2iQ3mTHG 6rUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321565; x=1770926365; 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=sbSmGmcLyJAYSLJVq9qt6emaKelHhhG3medBeM4cN70=; b=mOp6tsnSIAjGEFtzHYN2+tQwCLsGEEcm8qAoiDMjzF76FlRZsKhmGLzXez5jLi20z9 l4chThcUZWunkRziyJHXdGvBKgSAb42FG9No9F85bil+6XMySJ/wsM0ZBX+z+pIC5oad 04F8MLnFJ1sfab1KXE2OIe8RQgw6mPv+02fzUiPQtE2vSs/waTrR6+3FgIefvHxIBssv YyczBIKKoUqjCjqdmNMBHzmGstgAgW3EIXCr18XCsf8jjhNu0Am99MAtfO7Fp/KA5K+v /k89z8b7CsWzy+KbCCg88ak6af0KQnoRXopipxijXKPobOCrXK/v3kb7GU32s3bRFPes B8ZQ== X-Gm-Message-State: AOJu0YzQiL4EVUzbYb+3+s92wUW6dr+/f1uzRSSoGCx0V5lNWL6W+6il G/s+e6IebwyRlmmHDuBHohkfEbaHIYz8R+ayxTc4gAg7YNUlfdlke1C09pGK2b0YaI4= X-Gm-Gg: AZuq6aLMejdJevaI4Rlg6CNqBpkEW+jyQsTWF+p99UjJmghOrpQpAdjOQxWxpKu/8kM uug/sQoZHkXmAdhXbKlDvjjHZMZuyXUwB3w1L4dKmWobqvOsoBxnJszVc10rxwW+l1EGfWbbGND ArLjZ19T/Ge/amws1Wk/kozr33UwWUkWqEcDmKtQmGlThlvWAkFy15YbjjdsdcnTOm0VBSf2vMs 9nnKdTVx9C5TbniBMfia6jsxoDdTYdcy3RZpvowsHVtAFYxCUp/95taMP4qBj6z03dKZY5He9Bh akUlpTfBF1jxvxub5svBF0RYeHtts2Cg7MzaiNxsWprW8mbIrMrSXLIoiyzeqJKMHI03AVJisqg 5ZZZFfGBVds0EKTg+1C7C/2MehOwNueG8zNfiPUDTwtFNzvjT5pypTUP+YOelmifN20NJmeK2Rq VVaKlnmSyxzWNDlBP0mk4= X-Received: by 2002:a05:6000:2681:b0:42f:8816:a509 with SMTP id ffacd0b85a97d-4362938f3f4mr724935f8f.62.1770321564434; Thu, 05 Feb 2026 11:59:24 -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, Mirsad Ostrakovic Subject: [PATCH 27/29] hw/core: Support IOMMU translation for Remote Port memory slave Date: Thu, 5 Feb 2026 20:58:22 +0100 Message-ID: <20260205195824.2610192-28-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::334; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x334.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=unavailable 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: 1770321601101154100 Content-Type: text/plain; charset="utf-8" From: Mirsad Ostrakovic Update the Remote Port memory slave to support transactions targeting an AddressSpace managed by an IOMMU. This patch: - Adds 'iommu-id' and 'rp-chan0' properties to configure the connection. - Implements logic to retrieve the specific AddressSpace for a given stream ID from the default system bus IOMMU registry. This enables external simulators (connected via Remote Port) to perform DMA operations that are correctly translated by the guest's IOMMU/SMMU logic. Signed-off-by: Mirsad Ostrakovic Signed-off-by: Ruslan Ruslichenko --- hw/core/remote-port-memory-slave.c | 35 +++++++++++++++++++++- include/hw/core/remote-port-memory-slave.h | 3 ++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/hw/core/remote-port-memory-slave.c b/hw/core/remote-port-memor= y-slave.c index bb23325469..0419e75bfa 100644 --- a/hw/core/remote-port-memory-slave.c +++ b/hw/core/remote-port-memory-slave.c @@ -182,12 +182,38 @@ static void rp_cmd_rw(RemotePortMemorySlave *s, struc= t rp_pkt *pkt, rp_write(s->rp, (void *)s->rsp.pkt, enclen); } =20 +static AddressSpace *bus_iommu_address_space(BusState *iommu_bus, + uint32_t iommu_id, uint16_t d= evid) +{ + if (iommu_bus && iommu_bus->iommu[iommu_id].iommu_ops) { + return iommu_bus->iommu[iommu_id].iommu_ops->get_address_space( + iommu_bus, iommu_bus->iommu[iommu_id].iommu_opaque, devid); + } + return &address_space_memory; +} + +static void rp_memory_slave_init_done(Notifier *notifier, void *data) +{ + RemotePortMemorySlave *s =3D container_of(notifier, RemotePortMemorySl= ave, + machine_done); + AddressSpace *as; + + if (s->channel_id) { + as =3D bus_iommu_address_space(sysbus_get_default(), s->iommu_id, + s->rp_stream_id); + address_space_init(&s->as, as->root, "dma"); + } else { + address_space_init(&s->as, s->mr ? s->mr : get_system_memory(), "d= ma"); + } +} + static void rp_memory_slave_realize(DeviceState *dev, Error **errp) { RemotePortMemorySlave *s =3D REMOTE_PORT_MEMORY_SLAVE(dev); =20 s->peer =3D rp_get_peer(s->rp); - address_space_init(&s->as, s->mr ? s->mr : get_system_memory(), "dma"); + s->machine_done.notify =3D rp_memory_slave_init_done; + qemu_add_machine_init_done_notifier(&s->machine_done); } =20 static void rp_memory_slave_write(RemotePortDevice *s, struct rp_pkt *pkt) @@ -232,10 +258,17 @@ static void rp_memory_slave_unrealize(DeviceState *de= v) address_space_destroy(&s->as); } =20 +static Property rp_properties[] =3D { + DEFINE_PROP_UINT32("iommu-id", RemotePortMemorySlave, iommu_id, 0), + DEFINE_PROP_UINT32("rp-chan0", RemotePortMemorySlave, channel_id, 0), + DEFINE_PROP_END_OF_LIST() +}; + static void rp_memory_slave_class_init(ObjectClass *oc, const void *data) { RemotePortDeviceClass *rpdc =3D REMOTE_PORT_DEVICE_CLASS(oc); DeviceClass *dc =3D DEVICE_CLASS(oc); + device_class_set_props_n(dc, rp_properties, ARRAY_SIZE(rp_properties)); =20 rpdc->ops[RP_CMD_write] =3D rp_memory_slave_write; rpdc->ops[RP_CMD_read] =3D rp_memory_slave_read; diff --git a/include/hw/core/remote-port-memory-slave.h b/include/hw/core/r= emote-port-memory-slave.h index d88e806ed6..3161073a3f 100644 --- a/include/hw/core/remote-port-memory-slave.h +++ b/include/hw/core/remote-port-memory-slave.h @@ -23,6 +23,7 @@ typedef struct RemotePortMemorySlave { /* private */ SysBusDevice parent; /* public */ + uint32_t channel_id; struct RemotePort *rp; struct rp_peer_state *peer; MemoryRegion *mr; @@ -30,5 +31,7 @@ typedef struct RemotePortMemorySlave { MemTxAttrs attr; RemotePortDynPkt rsp; RemotePortATSCache *ats_cache; + Notifier machine_done; + uint32_t iommu_id; } RemotePortMemorySlave; #endif --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321654; cv=none; d=zohomail.com; s=zohoarc; b=n+dyUrmfBcl98eP7QvpGwZ1IrDeBiXZi1/gSw6l/hoAAtDtF7jw42K59gZ2dJZKSsWxW/ywtZLnC/NwYzBSgQPdIJ1yoAx6VX8A1t+r6mIcmLVZJLIkaT4udO4hsGMHFlB1z5DbqzjSD5EC3CXo242IMTxAdwMp7ag1PnjfRDKM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321654; 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=EYgtnXWNUJT6Dac5zqSSe5+G0V1Qkagn78Y+hx3iUhk=; b=c5lZojNH04EmdzQKsrVSZpdAt8Tg3WufoPlfNjSVVMsS6STV1HTqWAgR5pJapZRVx9G2wqbMRhFrLxJR3ibpYJzwjRKgf2DH7maOcLDNHVQvp+QSb6zaNraG09EgVz3h/1yDI7Ok8gfNwTGXuPkPeU3fCXnbrepm3sa6zB0vh5M= 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 1770321654787554.6189248267996; Thu, 5 Feb 2026 12:00:54 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vp-0007E3-Md; Thu, 05 Feb 2026 14:59:37 -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 1vo5Vi-000722-CA for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:30 -0500 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5Vg-0003D0-9m for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:29 -0500 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-4806f80cac9so9433495e9.1 for ; Thu, 05 Feb 2026 11:59:27 -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.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321566; x=1770926366; 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=EYgtnXWNUJT6Dac5zqSSe5+G0V1Qkagn78Y+hx3iUhk=; b=nTCDWJlVMWpterN9WMR7KcWlh1EqNO+cb0HedIymucwJy1AQ39CdYB21JV3Boc5KP+ oZa2eNuRJkeUeatfI43dfhwaukriITa58vYLmwu2ISg0SUY06bQs8Lb3Pc2xlhIQ/Sah RaP25peff9s7HjqrfuOkPEMMWWVhWTWcrKRAUepGtmBFDwfQann5xNDwDQFG7HARMYwc m0FLjqWvkbXcL4wi6Di9TN0vNo33MUhoBhFn6rdsU9uSAUIL3VUib/GiUQsPEyb+GFHB 2Ul8DIUIJCVAeQWpdnFWYbApTgk6zGmNUznv2M8psnBJotWJWM/kAm6kUzGUoWYMJ13F v7pQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321566; x=1770926366; 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=EYgtnXWNUJT6Dac5zqSSe5+G0V1Qkagn78Y+hx3iUhk=; b=NdmLL0CFCMD3mVUwsEFnVyMeu3+z1OLVNi3lKChYxSaIfRbV6WogCDffgp029rIbrq sbBdcdfdT0qlJgU1BeJRYRcGT9dbWN/Kvifd/HgxRLOzfT03UUsKCuJZSewrT2hbixCa 4/X1nKrSYm4FAOS4kIE/EXD/YTOLYryWan3ICmD4KlKjwYObClwuRSPkhpctaZaMVvpb +RteWqdSy9Nd3FD2Jh509eiDFnJ1L+GbItlOWE9p8a9ZEzzy2nAPMu8FwadVc9CuVTZv K2V6jcx4GCkw2zcZ0k7T6VlmNCiS+j6rCoNd3fLpLAjhbobwZ0LqiW+ingogZztpOzPo jeWw== X-Gm-Message-State: AOJu0YzlwVH8lLytbVKExENp4eo5n6pgmEVli5xJSY9924f7s8PNNWcd 1+sjnspxkDawT0fAnbJwPIYSRXEu6bWCl0r+upRD44yYlkaCw7ZYrHlmrEWlkn/u0Uw= X-Gm-Gg: AZuq6aKGS/E9XH0ZqZdWpu84l71e52nYxvgumdyoek383LJ0vlqq5LaucZHEX0YCiNe T1/W4tJKuaNFVZqJ7SMqXHryXTL0h9tAsV4U5DvElBzYrK0nfyZleBCfYvSRbkfoSN8CYWKnIPF VqM9zJi5vF9zWnLFPoQkmnuDDoQ5UJ68ahW/CjahyZOQb9uyoV65xmJNLH42KZosX/yfrEgCx5H B9W5pMWSnEjGG1f8RobnZUq5fDTTV7sBB/0HIY1T8I54kG9TOtqeexgyuoKXcMV/0XE/9lFDEfh eKUAfeq2gixEwb4ZmWosCHHylPvKhBr7z0z5EwbgbRPlFn9xtBwHmiffW3DEwBH6R6bEUKiEOoe UTB5JMSsM3SWPNmae/XKt2qN2fPfmNRoNGGluxqYHrCdJbNUDWqDgnrh33HkFHbn7LkDTsH62x6 E5zXrwAN6W8OwyUCtesWI= X-Received: by 2002:a05:6000:2681:b0:42f:8816:a509 with SMTP id ffacd0b85a97d-4362938f3f4mr725064f8f.62.1770321566414; Thu, 05 Feb 2026 11:59:26 -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, Mirsad Ostrakovic , "Edgar E . Iglesias" Subject: [PATCH 28/29] hw/core: Add Remote Port attachment helpers Date: Thu, 5 Feb 2026 20:58:23 +0100 Message-ID: <20260205195824.2610192-29-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::32f; envelope-from=ruslichenko.r@gmail.com; helo=mail-wm1-x32f.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=unavailable 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: 1770321655380158500 Content-Type: text/plain; charset="utf-8" From: Mirsad Ostrakovic Introduce helper functions to dynamically attach and detach Remote Port devices to an adaptor. This patch adds the logic to: - Connect devices to an adaptor via QOM links ('rp_device_attach'). - Parse command-line options ('rp_device_add') to automatically wire up devices using 'rp-adaptor' and 'rp-chan' properties. Signed-off-by: Edgar E. Iglesias Signed-off-by: Takahiro Nakata Signed-off-by: Mirsad Ostrakovic Signed-off-by: Ruslan Ruslichenko --- hw/core/meson.build | 1 + hw/core/remote-port-qdev.c | 181 ++++++++++++++++++++++++++++++++++ include/hw/core/remote-port.h | 27 +++++ 3 files changed, 209 insertions(+) create mode 100644 hw/core/remote-port-qdev.c diff --git a/hw/core/meson.build b/hw/core/meson.build index 7013638fcf..4638106e92 100644 --- a/hw/core/meson.build +++ b/hw/core/meson.build @@ -35,6 +35,7 @@ system_ss.add(when: 'CONFIG_REMOTE_PORT', if_true: files( 'remote-port-gpio.c', 'remote-port-stream.c', 'remote-port-ats.c', + 'remote-port-qdev.c' )) =20 system_ss.add(files( diff --git a/hw/core/remote-port-qdev.c b/hw/core/remote-port-qdev.c new file mode 100644 index 0000000000..35c9a6790d --- /dev/null +++ b/hw/core/remote-port-qdev.c @@ -0,0 +1,181 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * QEMU remote attach + * + * Copyright (c) 2013 Xilinx Inc + * Written by Edgar E. Iglesias + * + * This code is licensed under the GNU GPL. + */ + +#include "qemu/osdep.h" +#include "hw/core/sysbus.h" +#include "monitor/monitor.h" +#include "monitor/qdev.h" +#include "system/arch_init.h" +#include "qapi/error.h" +#include "qemu/config-file.h" +#include "qemu/error-report.h" +#include "qemu/help_option.h" +#include "qemu/cutils.h" +#include "qemu/option.h" + +#include "hw/core/remote-port.h" + +/* RP helper function to attach a device to an adaptor. */ +void rp_device_attach(Object *adaptor, Object *dev, + int rp_nr, int dev_nr, + Error **errp) +{ + Error *err =3D NULL; + uint32_t nr_devs; + char *name; + int i; + + assert(adaptor); + assert(dev); + + /* Verify that the adaptor is of Remote Port type. */ + if (!object_dynamic_cast(adaptor, TYPE_REMOTE_PORT)) { + error_setg(errp, "%s is not a Remote-Port adaptor!", + object_get_canonical_path(adaptor)); + return; + } + + name =3D g_strdup_printf("rp-adaptor%d", rp_nr); + object_property_set_link(dev, name, adaptor, &err); + g_free(name); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } + + name =3D g_strdup_printf("rp-chan%d", rp_nr); + object_property_set_int(dev, name, dev_nr, &err); + g_free(name); + if (err !=3D NULL + && !object_dynamic_cast(dev, TYPE_REMOTE_PORT_DEVICE)) { + /* + * RP devices that only receive requests may not need to + * know their channel/dev number. If not, treat this as + * an error. + */ + error_propagate(errp, err); + return; + } + err =3D NULL; + + nr_devs =3D object_property_get_int(dev, "nr-devs", &err); + if (err) { + nr_devs =3D 1; + err =3D NULL; + } + + /* Multi-channel devs use consecutive numbering. */ + for (i =3D 0; i < nr_devs; i++) { + name =3D g_strdup_printf("remote-port-dev%d", dev_nr + i); + object_property_set_link(adaptor, name, dev, &err); + g_free(name); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } + } +} + +/* RP helper function to detach a device to an adaptor. */ +void rp_device_detach(Object *adaptor, Object *dev, + int rp_nr, int dev_nr, + Error **errp) +{ + Error *err =3D NULL; + uint32_t nr_devs; + char *name; + int i; + + assert(adaptor); + assert(dev); + + name =3D g_strdup_printf("rp-adaptor%d", rp_nr); + object_property_set_link(dev, name, NULL, NULL); + g_free(name); + + nr_devs =3D object_property_get_int(dev, "nr-devs", &err); + if (err) { + nr_devs =3D 1; + err =3D NULL; + } + + for (i =3D 0; i < nr_devs; i++) { + name =3D g_strdup_printf("remote-port-dev%d", dev_nr + i); + object_property_set_link(adaptor, name, NULL, &err); + g_free(name); + if (err !=3D NULL) { + error_propagate(errp, err); + return; + } + } +} + +/* Scan for remote-port links to be setup. */ +bool rp_device_add(const QDict *opts, DeviceState *dev, Error **errp) +{ + Error *err =3D NULL; + Object *adaptor; + bool ambiguous; + const char *path; + char *name; + int i; + + /* + * Find the adaptor this remote-port device is connected to. + * At the moment, we only support one adaptor per device. + */ + name =3D g_strdup_printf("rp-adaptor%d", 0); + path =3D qdict_get_try_str(opts, name); + g_free(name); + if (!path) { + /* This is not a remote-port device. Treat as success. */ + return true; + } + adaptor =3D object_resolve_path(path, &ambiguous); + if (!adaptor) { + error_setg(errp, "Did not find rp adaptor %s!", path); + return false; + } + + /* + * Loop through the channels this device provides and attach + * them to the adaptor. + */ + for (i =3D 0; i < INT_MAX; i++) { + unsigned long dev_nr; + const char *dev_nr_str; + + name =3D g_strdup_printf("rp-chan%d", i); + dev_nr_str =3D qdict_get_try_str(opts, name); + g_free(name); + + if (!dev_nr_str) { + if (i =3D=3D 0) { + /* At least one channel must be provided. */ + error_setg(errp, "Did not find rp-chan%d!", i); + return false; + } + return true; + } + + if (qemu_strtoul(dev_nr_str, NULL, 0, &dev_nr)) { + error_setg(errp, "Invalid rp-chan%d!", i); + return false; + } + + /* Now, attach the device to the adaptor. */ + rp_device_attach(adaptor, OBJECT(dev), 0, dev_nr, &err); + if (err !=3D NULL) { + error_propagate(errp, err); + return false; + } + } + return true; +} diff --git a/include/hw/core/remote-port.h b/include/hw/core/remote-port.h index 172c4b6204..252230961b 100644 --- a/include/hw/core/remote-port.h +++ b/include/hw/core/remote-port.h @@ -134,6 +134,33 @@ struct RemotePort { RemotePortDevice *devs[REMOTE_PORT_MAX_DEVS]; }; =20 +/** + * rp_device_attach: + * @adaptor: The adaptor onto which to attach the device + * @dev: The device to be attached to the adaptor + * @rp_nr: The remote-port adaptor nr. A device may attach to multiple + * adaptors. + * @dev_nr: The device/channel number to bind the device to. + * @errp: returns an error if this function fails + * + * Attaches a device onto an adaptor and binds it to a device number. + */ +void rp_device_attach(Object *adaptor, Object *dev, + int rp_nr, int dev_nr, + Error **errp); +void rp_device_detach(Object *adaptor, Object *dev, + int rp_nr, int dev_nr, + Error **errp); +/** + * rp_device_add + * @opts: qdev opts created by the qdev subsystem + * @dev: The device to be connected + * @errp: Returns an error if the function fails + * + * Function used in qdev-monitor.c to connect remote port devices. + * Returns teue on success and false on failure. + */ +bool rp_device_add(const QDict *opts, DeviceState *dev, Error **errp); =20 void rp_rsp_mutex_lock(RemotePort *s); void rp_rsp_mutex_unlock(RemotePort *s); --=20 2.43.0 From nobody Sat Feb 7 08:45:11 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=1770321775; cv=none; d=zohomail.com; s=zohoarc; b=IeyvLrR+IMfEefvtL1gBNdNJv/qJSscuak9w/GnXDUhkD46H9y6NGcqcPV9yKG/MkndURDcLgIDl0TIaGBsZnS/27bBJ5S6Yel4Ng34jVlTMHObfL+kDEznGl3t+rAawPplr3xRm0et4++uQjKPE4guQf25YiQ51QEUw7FCFW4Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770321775; 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=X7UzQPgmBiRY/upCcfubCk3rZyvcBcdMj1LuFEKqEEs=; b=QtqbC/AOrDgqPjIC5SgYRKAeiA0lY/IsI+KxGrC+3eD9ujG2kItlSM0bctPr90d5CiqDRWAtOk7ROKggjbuZM9OHQvxmH+/MFZUrSnKEjMX3NxH1xsZKonKPvYXlxsb7lalCDuBZssPgOVSHYvDZDflOJMSEm5nHu8USTMsy5AM= 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 1770321775680702.6861990986043; Thu, 5 Feb 2026 12:02:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vo5Vn-00079z-OY; Thu, 05 Feb 2026 14:59:35 -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 1vo5Vk-00075F-Ce for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:32 -0500 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1vo5Vi-0003DM-4Q for qemu-devel@nongnu.org; Thu, 05 Feb 2026 14:59:32 -0500 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-4362ab556f5so16840f8f.3 for ; Thu, 05 Feb 2026 11:59:29 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Feb 2026 11:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770321568; x=1770926368; 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=X7UzQPgmBiRY/upCcfubCk3rZyvcBcdMj1LuFEKqEEs=; b=aACq35yd7CVghLv0MoCHCn9c41VCypCzExQQso5a2Yr1nSTVD2uyEUfTLitJ1XnK0Y U8KYKMzHjiyMADw03E/CUYnIPoTYqDnKLSm1w4iTQiNw3z/cfkYu1QkHGVzGddnwa5XR EDHlT51bLI8cHpEGz6XVbcIA5OXAq4aNg+a8e7LImX4ZGg7bmnxnLGZVen/OxmH8zDt8 8770MeySgFWJols8SgLwgv0TD+Ybcx1S0bY5ba9PBcmoImRtTRtD6oABBPUp/13f1ess OegmIalT6g78KhG9yE2hN5x9jg8TZcBUvm9uFmg4GUNxvg6eBf6K0yAfSq481x3mBynI vDrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770321568; x=1770926368; 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=X7UzQPgmBiRY/upCcfubCk3rZyvcBcdMj1LuFEKqEEs=; b=G2Ge2b55yGnfutjEmsjf0iUBz1SQSC5/ZbOoQ2RSVF441TSkEQO14FXE5evKSwvdPr 7FmHaNB9EDQojvOdTMH+ePpKBT5UTC4PTiqVrzrUYSWDgrlEZPdgLGXneKvDyobeluI1 AB4AYNghH3E9zFBrDPGHlHzV//pSLZ4y1rSbMf2tzcLD1nPUQtY942EkbQZN1nR/uXAi 6Fo0ASFLjVhT7XyMzrzwvVm1ST2+ee92dw8TP7GBIBosDaDjlie3YCBi3znBXriZ69we 9gmQDNETUCRSLqXOMPVKSzW8VSSEsvoahniOMJcEA5r5qMdFwZ3w+V1dBcoNH6Jb2eEE nf3Q== X-Gm-Message-State: AOJu0Yy/3m/gjmE6SfeB+qVvI36GmhrW9uupoMARY0IXrHtpSifHhbns KoNaMbXK/YtUh1R+YbV7V7szoVwZpR2t3nnmQD2K5staEGnBo9f+QPsi8mV5qkEPc4I= X-Gm-Gg: AZuq6aK1JXPIsM6AxVAgi9eqU8MmR0MS+cmBWkOBvOR5M+KIQewzxTuMiVPxjAi23zX TfJe6cJUIYvKNtBP7cOLt8Kkv8sqwuhxkiqEIm5M6lH/z2vwYp+dlLA/h/o7dX71v5BdHNEnY7P kAYXZO+idqy3df/U8TiO5wm1VxlI4egOf1M+d77ifCx1DkXgXg0jEdUmLZ0LgwuEwJEaXAfdGuF P2I8ioWLssRE74gmdVjk8pUvP6Mp8VgUSmY+F66c2EO9JQRe7wIhfmnVyPnWRksp8ivd+cZevjR 28WwyqH7l9JScTams0TsXSSW1OdGX82nbUQX1xNirNmpwIimgqWXhu+9PAGjLlO7Gpu+rqXHxVf yhGsZOv2QIWLbQu+QfohkoRBsF6qSMPLCJNpY+xelTYneHw82hqALKzc5wbf8nfOZ6fNnfNyerR aGGkro/anb468Y4aEboTo= X-Received: by 2002:a5d:5f54:0:b0:435:9ce0:f93c with SMTP id ffacd0b85a97d-4362969509amr574711f8f.62.1770321567939; Thu, 05 Feb 2026 11:59:27 -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, Mirsad Ostrakovic Subject: [PATCH 29/29] hw/core: Add ATS support to Remote Port memory slave Date: Thu, 5 Feb 2026 20:58:24 +0100 Message-ID: <20260205195824.2610192-30-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::429; envelope-from=ruslichenko.r@gmail.com; helo=mail-wr1-x429.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=unavailable 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: 1770321777661154101 Content-Type: text/plain; charset="utf-8" From: Mirsad Ostrakovic Integrate Address Translation Services (ATS) into the Remote Port Memory Sl= ave to support IOMMU translation for remote transactions. This patch implements: - Support for creation of RP ATS as RP Memory Slave subdevice - Dynamic configuration of the ATS device, linking it to the same IOMMU context (iommu-id, stream-id) as the parent memory slave. - Update for FDT generic utility to parse 'remote-port-ats' properties and propagate the configuration to the device. This allows external masters to request address translations via the Remote Port protocol, which are then serviced by the QEMU IOMMU infrastructure. Signed-off-by: Mirsad Ostrakovic Signed-off-by: Ruslan Ruslichenko --- hw/core/fdt_generic_util.c | 10 +++ hw/core/remote-port-ats.c | 97 +++++++++++++++++++++- hw/core/remote-port-memory-slave.c | 36 +++++++- include/hw/core/remote-port-ats.h | 3 + include/hw/core/remote-port-memory-slave.h | 4 +- 5 files changed, 145 insertions(+), 5 deletions(-) diff --git a/hw/core/fdt_generic_util.c b/hw/core/fdt_generic_util.c index 180038baf6..817e7209e1 100644 --- a/hw/core/fdt_generic_util.c +++ b/hw/core/fdt_generic_util.c @@ -1221,6 +1221,16 @@ static int fdt_init_qdev(char *node_path, FDTMachine= Info *fdti, char *compat) fprintf(stderr, "cant set device link for adaptor\n"); break; } + + if (object_dynamic_cast(dev, TYPE_REMOTE_PORT_MEMORY_SLAVE)) { + uint32_t rp_ats_id; + rp_ats_id =3D qemu_fdt_getprop_cell(fdti->fdt, node_path, + "remote-port-ats", 0, + false, &errp); + + object_property_set_int(OBJECT(dev), "rp-ats-id", + rp_ats_id, &errp); + } } errp =3D NULL; } diff --git a/hw/core/remote-port-ats.c b/hw/core/remote-port-ats.c index 1f6c8d7410..27cf8c6c7b 100644 --- a/hw/core/remote-port-ats.c +++ b/hw/core/remote-port-ats.c @@ -33,10 +33,29 @@ #include "migration/vmstate.h" #include "hw/core/qdev-properties.h" #include "trace.h" +#include "qemu/cutils.h" =20 #include "hw/core/remote-port-proto.h" #include "hw/core/remote-port-ats.h" =20 +#define RP_TRACE_LVL_NONE (0u) +#define RR_TRACE_LVL_ERROR (1u) +#define RP_TRACE_LVL_WARN (2u) +#define RP_TRACE_LVL_INFO (3u) + +#define RP_TRACE_LEVEL (RP_TRACE_LVL_INFO) + +#ifndef RP_TRACE_LEVEL +#define RP_TRACE_LEVEL (RP_TRACE_LVL_NONE) +#endif + +#define RP_TRACE(level, ...) do { \ + if (RP_TRACE_LEVEL >=3D level) { \ + fprintf(stderr, "[TRACE] %s(): ", __func__); \ + fprintf(stderr, ## __VA_ARGS__); \ + } \ +} while (0) + typedef struct ATSIOMMUNotifier { IOMMUNotifier n; MemoryRegion *mr; @@ -190,6 +209,17 @@ static void rp_ats_cache_insert(RemotePortATS *s, iotlb->addr_mask =3D mask; iotlb->target_as =3D target_as; g_array_append_val(s->cache, iotlb); + + char *target_as_name =3D strdup(iotlb->target_as->name); + RP_TRACE(RP_TRACE_LVL_INFO, "IOMMUTLBEntry entry added to cache\r\n"); + RP_TRACE(RP_TRACE_LVL_INFO, "iova: 0x%" PRIx64 " translated_addr: 0x%"= \ + PRIx64 " addr_mask: 0x%" PRIx64 " target_as: %s perm: 0x%" PRIx32 "= \r\n", + iotlb->iova, + iotlb->translated_addr, + iotlb->addr_mask, + target_as_name, + iotlb->perm); + free(target_as_name); } =20 static void rp_ats_iommu_unmap_notify(IOMMUNotifier *n, IOMMUTLBEntry *iot= lb) @@ -215,11 +245,20 @@ static bool ats_translate_address(RemotePortATS *s, s= truct rp_pkt *pkt, mr =3D ats_do_translate(&s->as, pkt->ats.addr, phys_addr, phys_len, &target_as, &prot, attrs); if (!mr) { + RP_TRACE(RP_TRACE_LVL_INFO, "Remote Port ATS translation failed\r\= n"); return false; } =20 + RP_TRACE(RP_TRACE_LVL_INFO, + "Remote Port ATS translation succeeded - aka. ats_do_translate()\r= \n"); + RP_TRACE(RP_TRACE_LVL_INFO, + "phys_addr: 0x%" PRIx64 " phys_len: 0x%" PRIx64 "\r\n", + *phys_addr, *phys_len); + iommu_mr =3D memory_region_get_iommu(mr); if (iommu_mr) { + RP_TRACE(RP_TRACE_LVL_INFO, + "Memory region obtained from ats_do_translate() is associated with= IOMMU\r\n"); int iommu_idx =3D memory_region_iommu_attrs_to_index(iommu_mr, att= rs); ATSIOMMUNotifier *notifier; int i; @@ -284,11 +323,23 @@ static void rp_ats_req(RemotePortDevice *dev, struct = rp_pkt *pkt) =20 assert(!(pkt->hdr.flags & RP_PKT_FLAGS_response)); =20 + RP_TRACE(RP_TRACE_LVL_INFO, "Remote Port ATS request is received\r\n") + RP_TRACE(RP_TRACE_LVL_INFO, "cmd 0x%" PRIx32 " len: 0x%" PRIx32 " id: = 0x%" \ + PRIx32 " flags: 0x%" PRIx32 " dev: 0x%" PRIx32 "\r\n", + pkt->hdr.cmd, pkt->hdr.len, pkt->hdr.id, pkt->hdr.flags, pkt->hdr.= dev); + RP_TRACE(RP_TRACE_LVL_INFO, "timestamp 0x%" PRIx64 " attributes: 0x%" = PRIx64 + " addr: 0x%" PRIx64 " len: 0x%" PRIx64 " result: 0x%" PRIx32 "\r\n= ", + pkt->ats.timestamp, pkt->ats.attributes, pkt->ats.addr, pkt->ats.l= en, + pkt->ats.result); + rp_dpkt_alloc(&s->rsp, pktlen); =20 result =3D ats_translate_address(s, pkt, &phys_addr, &phys_len) ? RP_ATS_RESULT_ok : RP_ATS_RESULT_error; =20 + RP_TRACE(RP_TRACE_LVL_INFO, "Remote Port ATS translation is %s\r\n", + ((result =3D=3D RP_ATS_RESULT_ok) ? "successful" : "unsuccessf= ul")); + /* * delay here could be set to the annotated cost of doing issuing * these accesses. QEMU doesn't support this kind of annotations @@ -307,18 +358,60 @@ static void rp_ats_req(RemotePortDevice *dev, struct = rp_pkt *pkt) pkt->hdr.flags | RP_PKT_FLAGS_response); assert(enclen =3D=3D pktlen); =20 + RP_TRACE(RP_TRACE_LVL_INFO, "Remote Port ATS response is generated\r\n= ") + RP_TRACE(RP_TRACE_LVL_INFO, "cmd 0x%" PRIx32 " len: 0x%" PRIx32 " id: = 0x%" \ + PRIx32 " flags: 0x%" PRIx32 " dev: 0x%" PRIx32 "\r\n", + be32toh(s->rsp.pkt->hdr.cmd), + be32toh(s->rsp.pkt->hdr.len), + be32toh(s->rsp.pkt->hdr.id), + be32toh(s->rsp.pkt->hdr.flags), + be32toh(s->rsp.pkt->hdr.dev)); + RP_TRACE(RP_TRACE_LVL_INFO, "timestamp 0x%" PRIx64 " attributes: 0x%" \ + PRIx64 " addr: 0x%" PRIx64 " len: 0x%" PRIx64 " result: 0x%" PRIx32 "\= r\n", + be64toh(s->rsp.pkt->ats.timestamp), + be64toh(s->rsp.pkt->ats.attributes), + be64toh(s->rsp.pkt->ats.addr), + be64toh(s->rsp.pkt->ats.len), + be32toh(s->rsp.pkt->ats.result)); + rp_write(s->rp, (void *)s->rsp.pkt, enclen); } =20 +static AddressSpace *bus_iommu_address_space(BusState *iommu_bus, + uint32_t iommu_id, uint16_t d= evid) +{ + if (iommu_bus && iommu_bus->iommu[iommu_id].iommu_ops) { + return iommu_bus->iommu[iommu_id].iommu_ops->get_address_space( + iommu_bus, iommu_bus->iommu[iommu_id].iommu_opaque, devid); + } + return &address_space_memory; +} + +static void rp_ats_init_done(Notifier *notifier, void *data) +{ + RemotePortATS *s =3D container_of(notifier, RemotePortATS, machine_don= e); + AddressSpace *as; + + if (s->rp_stream_id) { + as =3D bus_iommu_address_space(sysbus_get_default(), + s->iommu_id, s->rp_stream_id); + address_space_init(&s->as, as->root, "dma"); + } else { + address_space_init(&s->as, s->mr ? s->mr : get_system_memory(), "d= ma"); + } +} + static void rp_ats_realize(DeviceState *dev, Error **errp) { RemotePortATS *s =3D REMOTE_PORT_ATS(dev); =20 s->peer =3D rp_get_peer(s->rp); - address_space_init(&s->as, s->mr ? s->mr : get_system_memory(), "ats-a= s"); =20 s->iommu_notifiers =3D g_array_new(false, true, sizeof(ATSIOMMUNotifie= r *)); s->cache =3D g_array_new(false, true, sizeof(IOMMUTLBEntry *)); + + s->machine_done.notify =3D rp_ats_init_done; + qemu_add_machine_init_done_notifier(&s->machine_done); } =20 static void rp_prop_allow_set_link(const Object *obj, const char *name, @@ -363,7 +456,9 @@ static void rp_ats_unrealize(DeviceState *dev) } =20 static Property rp_properties[] =3D { + DEFINE_PROP_UINT32("iommu-id", RemotePortATS, iommu_id, 0), DEFINE_PROP_UINT32("rp-chan0", RemotePortATS, rp_dev, 0), + DEFINE_PROP_UINT32("rp-stream-id", RemotePortATS, rp_stream_id, 0), }; =20 static void rp_ats_class_init(ObjectClass *oc, const void *data) diff --git a/hw/core/remote-port-memory-slave.c b/hw/core/remote-port-memor= y-slave.c index 0419e75bfa..2694f3edae 100644 --- a/hw/core/remote-port-memory-slave.c +++ b/hw/core/remote-port-memory-slave.c @@ -192,13 +192,38 @@ static AddressSpace *bus_iommu_address_space(BusState= *iommu_bus, return &address_space_memory; } =20 +static void rp_memory_slave_create_ats(RemotePortMemorySlave *s) +{ + Object *tmp_obj; + + /* Create RP ATS dev. */ + tmp_obj =3D object_new(TYPE_REMOTE_PORT_ATS); + s->rp_ats =3D REMOTE_PORT_ATS(tmp_obj); + object_property_add_child(OBJECT(s), "rp-ats", tmp_obj); + object_unref(tmp_obj); + + /* Setup the RP ATS dev. */ + rp_device_attach(OBJECT(s->rp), OBJECT(s->rp_ats), 0, + s->rp_ats_id, &error_abort); + object_property_set_int(OBJECT(s->rp_ats), "iommu-id", + s->iommu_id, &error_abort); + object_property_set_int(OBJECT(s->rp_ats), "rp-stream-id", + s->rp_stream_id, &error_abort); + object_property_set_bool(OBJECT(s->rp_ats), "realized", + true, &error_abort); + + /* Setup the RP Slave dev. */ + object_property_set_link(OBJECT(s), "rp-ats-cache", + OBJECT(s->rp_ats), &error_abort); +} + static void rp_memory_slave_init_done(Notifier *notifier, void *data) { RemotePortMemorySlave *s =3D container_of(notifier, RemotePortMemorySl= ave, machine_done); AddressSpace *as; =20 - if (s->channel_id) { + if (s->rp_stream_id) { as =3D bus_iommu_address_space(sysbus_get_default(), s->iommu_id, s->rp_stream_id); address_space_init(&s->as, as->root, "dma"); @@ -212,6 +237,11 @@ static void rp_memory_slave_realize(DeviceState *dev, = Error **errp) RemotePortMemorySlave *s =3D REMOTE_PORT_MEMORY_SLAVE(dev); =20 s->peer =3D rp_get_peer(s->rp); + + if (s->rp_ats_id > 0) { + rp_memory_slave_create_ats(s); + } + s->machine_done.notify =3D rp_memory_slave_init_done; qemu_add_machine_init_done_notifier(&s->machine_done); } @@ -260,8 +290,8 @@ static void rp_memory_slave_unrealize(DeviceState *dev) =20 static Property rp_properties[] =3D { DEFINE_PROP_UINT32("iommu-id", RemotePortMemorySlave, iommu_id, 0), - DEFINE_PROP_UINT32("rp-chan0", RemotePortMemorySlave, channel_id, 0), - DEFINE_PROP_END_OF_LIST() + DEFINE_PROP_UINT32("rp-chan0", RemotePortMemorySlave, rp_stream_id, 0), + DEFINE_PROP_UINT32("rp-ats-id", RemotePortMemorySlave, rp_ats_id, 0), }; =20 static void rp_memory_slave_class_init(ObjectClass *oc, const void *data) diff --git a/include/hw/core/remote-port-ats.h b/include/hw/core/remote-por= t-ats.h index 8bdae1bce9..9e1a2cf419 100644 --- a/include/hw/core/remote-port-ats.h +++ b/include/hw/core/remote-port-ats.h @@ -45,6 +45,9 @@ typedef struct { GArray *iommu_notifiers; uint32_t rp_dev; GArray *cache; /* Translation cache */ + Notifier machine_done; + uint32_t rp_stream_id; + uint32_t iommu_id; } RemotePortATS; =20 #define TYPE_REMOTE_PORT_ATS_CACHE "remote-port-ats-cache" diff --git a/include/hw/core/remote-port-memory-slave.h b/include/hw/core/r= emote-port-memory-slave.h index 3161073a3f..56959ee124 100644 --- a/include/hw/core/remote-port-memory-slave.h +++ b/include/hw/core/remote-port-memory-slave.h @@ -23,7 +23,6 @@ typedef struct RemotePortMemorySlave { /* private */ SysBusDevice parent; /* public */ - uint32_t channel_id; struct RemotePort *rp; struct rp_peer_state *peer; MemoryRegion *mr; @@ -32,6 +31,9 @@ typedef struct RemotePortMemorySlave { RemotePortDynPkt rsp; RemotePortATSCache *ats_cache; Notifier machine_done; + uint32_t rp_stream_id; + RemotePortATS *rp_ats; + uint32_t rp_ats_id; uint32_t iommu_id; } RemotePortMemorySlave; #endif --=20 2.43.0