From nobody Sat Feb 7 09:04:13 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