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