qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH-for-10.0] system/qtest: Access memory using cpu_physical_memory_rw() API
@ 2024-11-27 19:19 Philippe Mathieu-Daudé
  2024-11-27 22:35 ` Richard Henderson
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Philippe Mathieu-Daudé @ 2024-11-27 19:19 UTC (permalink / raw)
  To: qemu-devel
  Cc: Thomas Huth, Anton Johansson, Richard Henderson, Laurent Vivier,
	Paolo Bonzini, Fabiano Rosas, Philippe Mathieu-Daudé

There is no vCPU within the QTest accelerator (well, they
are stubs doing nothing, see dummy_cpu_thread_fn).
Directly use the cpu_physical_memory_rw() API -- which
amusingly prefixed 'cpu_' does not use vCPU -- to access
memory. This reduces accesses to the global 'first_cpu'.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 system/qtest.c | 42 ++++++++++++++----------------------------
 1 file changed, 14 insertions(+), 28 deletions(-)

diff --git a/system/qtest.c b/system/qtest.c
index 12703a20455..a2de9a7d5a4 100644
--- a/system/qtest.c
+++ b/system/qtest.c
@@ -18,6 +18,7 @@
 #include "chardev/char-fe.h"
 #include "exec/ioport.h"
 #include "exec/memory.h"
+#include "exec/cpu-common.h"
 #include "exec/tswap.h"
 #include "hw/qdev-core.h"
 #include "hw/irq.h"
@@ -514,23 +515,19 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
 
         if (words[0][5] == 'b') {
             uint8_t data = value;
-            address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                                &data, 1);
+            cpu_physical_memory_write(addr, &data, 1);
         } else if (words[0][5] == 'w') {
             uint16_t data = value;
             tswap16s(&data);
-            address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                                &data, 2);
+            cpu_physical_memory_write(addr, &data, 2);
         } else if (words[0][5] == 'l') {
             uint32_t data = value;
             tswap32s(&data);
-            address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                                &data, 4);
+            cpu_physical_memory_write(addr, &data, 4);
         } else if (words[0][5] == 'q') {
             uint64_t data = value;
             tswap64s(&data);
-            address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                                &data, 8);
+            cpu_physical_memory_write(addr, &data, 8);
         }
         qtest_send_prefix(chr);
         qtest_send(chr, "OK\n");
@@ -548,22 +545,18 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
 
         if (words[0][4] == 'b') {
             uint8_t data;
-            address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                               &data, 1);
+            cpu_physical_memory_read(addr, &data, 1);
             value = data;
         } else if (words[0][4] == 'w') {
             uint16_t data;
-            address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                               &data, 2);
+            cpu_physical_memory_read(addr, &data, 2);
             value = tswap16(data);
         } else if (words[0][4] == 'l') {
             uint32_t data;
-            address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                               &data, 4);
+            cpu_physical_memory_read(addr, &data, 4);
             value = tswap32(data);
         } else if (words[0][4] == 'q') {
-            address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                               &value, 8);
+            cpu_physical_memory_read(addr, &value, 8);
             tswap64s(&value);
         }
         qtest_send_prefix(chr);
@@ -583,9 +576,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         g_assert(len);
 
         data = g_malloc(len);
-        address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
-                           len);
-
+        cpu_physical_memory_read(addr, data, len);
         enc = qemu_hexdump_line(NULL, data, len, 0, 0);
 
         qtest_send_prefix(chr);
@@ -605,8 +596,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         g_assert(ret == 0);
 
         data = g_malloc(len);
-        address_space_read(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
-                           len);
+        cpu_physical_memory_read(addr, data, len);
         b64_data = g_base64_encode(data, len);
         qtest_send_prefix(chr);
         qtest_sendf(chr, "OK %s\n", b64_data);
@@ -640,8 +630,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
                 data[i] = 0;
             }
         }
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
-                            len);
+        cpu_physical_memory_write(addr, data, len);
         g_free(data);
 
         qtest_send_prefix(chr);
@@ -663,8 +652,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         if (len) {
             data = g_malloc(len);
             memset(data, pattern, len);
-            address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
-                                data, len);
+            cpu_physical_memory_write(addr, data, len);
             g_free(data);
         }
 
@@ -696,9 +684,7 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
                            len, out_len);
             out_len = MIN(out_len, len);
         }
-
-        address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED, data,
-                            len);
+        cpu_physical_memory_write(addr, data, len);
 
         qtest_send_prefix(chr);
         qtest_send(chr, "OK\n");
-- 
2.45.2



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2024-12-10 10:32 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-27 19:19 [PATCH-for-10.0] system/qtest: Access memory using cpu_physical_memory_rw() API Philippe Mathieu-Daudé
2024-11-27 22:35 ` Richard Henderson
2024-11-28  5:56   ` Philippe Mathieu-Daudé
2024-12-09 17:08 ` Fabiano Rosas
2024-12-09 20:34   ` Fabiano Rosas
2024-12-09 20:42     ` Philippe Mathieu-Daudé
2024-12-10 10:03 ` Peter Maydell
2024-12-10 10:20   ` Philippe Mathieu-Daudé
2024-12-10 10:31     ` Philippe Mathieu-Daudé
2024-12-10 10:31     ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).