From nobody Wed Nov 27 02:41:22 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1701983172520895.1192366667859; Thu, 7 Dec 2023 13:06:12 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rBLY2-0002kE-7D; Thu, 07 Dec 2023 16:04:42 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rBLXs-0002dC-0S for qemu-devel@nongnu.org; Thu, 07 Dec 2023 16:04:32 -0500 Received: from smtp1.lauterbach.com ([62.154.241.196]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rBLXn-0005nf-Uk for qemu-devel@nongnu.org; Thu, 07 Dec 2023 16:04:31 -0500 Received: (qmail 10305 invoked by uid 484); 7 Dec 2023 21:04:08 -0000 Received: from nedpc1.intern.lauterbach.com (Authenticated_SSL:neder@[10.2.11.92]) (envelope-sender ) by smtp1.lauterbach.com (qmail-ldap-1.03) with TLS_AES_256_GCM_SHA384 encrypted SMTP for ; 7 Dec 2023 21:04:07 -0000 X-Qmail-Scanner-Diagnostics: from nedpc1.intern.lauterbach.com by smtp1.lauterbach.com (envelope-from , uid 484) with qmail-scanner-2.11 (mhr: 1.0. clamdscan: 0.99/21437. spamassassin: 3.4.0. Clear:RC:1(10.2.11.92):. Processed in 0.073117 secs); 07 Dec 2023 21:04:08 -0000 From: Nicolas Eder To: qemu-devel@nongnu.org Cc: "Nicolas Eder" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , "Christian Boenig" , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v4 05/17] mcdstub: memory helper functions added Date: Thu, 7 Dec 2023 22:03:46 +0100 Message-Id: <20231207210358.7409-6-nicolas.eder@lauterbach.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231207210358.7409-1-nicolas.eder@lauterbach.com> References: <20231207210358.7409-1-nicolas.eder@lauterbach.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Qmail-Scanner-2.11: added fake Content-Type header 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=62.154.241.196; envelope-from=nicolas.eder@lauterbach.com; helo=smtp1.lauterbach.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1701983173376100005 Content-Type: text/plain; charset="utf-8" --- include/exec/cpu-common.h | 3 +++ include/exec/memory.h | 9 +++++++++ system/memory.c | 11 +++++++++++ system/physmem.c | 26 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index 41115d8919..dd989b5ab2 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -182,6 +182,9 @@ int ram_block_discard_range(RAMBlock *rb, uint64_t star= t, size_t length); int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, void *ptr, size_t len, bool is_write); =20 +int cpu_memory_get_physical_address(CPUState *cpu, vaddr *addr, size_t *le= n); + + /* vl.c */ void list_cpus(void); =20 diff --git a/include/exec/memory.h b/include/exec/memory.h index 831f7c996d..174de807d5 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -3142,6 +3142,15 @@ bool ram_block_discard_is_disabled(void); */ bool ram_block_discard_is_required(void); =20 +/* + * mcd_find_address_space() - Find the address spaces with the correspondi= ng + * name. + * + * Currently only used by the mcd debugger. + * @as_name: Name to look for. + */ +AddressSpace *mcd_find_address_space(const char *as_name); + #endif =20 #endif diff --git a/system/memory.c b/system/memory.c index 798b6c0a17..9a8fa79e0c 100644 --- a/system/memory.c +++ b/system/memory.c @@ -3562,6 +3562,17 @@ void mtree_info(bool flatview, bool dispatch_tree, b= ool owner, bool disabled) } } =20 +AddressSpace *mcd_find_address_space(const char *as_name) +{ + AddressSpace *as; + QTAILQ_FOREACH(as, &address_spaces, address_spaces_link) { + if (strcmp(as->name, as_name) =3D=3D 0) { + return as; + } + } + return NULL; +} + void memory_region_init_ram(MemoryRegion *mr, Object *owner, const char *name, diff --git a/system/physmem.c b/system/physmem.c index a63853a7bc..70733c67c7 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -3422,6 +3422,32 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr, return 0; } =20 +int cpu_memory_get_physical_address(CPUState *cpu, vaddr *addr, size_t *le= n) +{ + hwaddr phys_addr; + vaddr l, page; + + cpu_synchronize_state(cpu); + MemTxAttrs attrs; + + page =3D *addr & TARGET_PAGE_MASK; + phys_addr =3D cpu_get_phys_page_attrs_debug(cpu, page, &attrs); + /* if no physical page mapped, return an error */ + if (phys_addr =3D=3D -1) { + return -1; + } + l =3D (page + TARGET_PAGE_SIZE) - *addr; + if (l > *len) { + l =3D *len; + } + phys_addr +=3D (*addr & ~TARGET_PAGE_MASK); + + /* set output values */ + *addr =3D phys_addr; + *len =3D l; + return 0; +} + /* * Allows code that needs to deal with migration bitmaps etc to still be b= uilt * target independent. --=20 2.34.1