qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Cédric Le Goater" <clg@kaod.org>
Subject: [PULL 12/23] softmmu/qtest: Move the target-specific pseries RTAS code out of qtest.c
Date: Thu, 20 Apr 2023 12:12:05 +0200	[thread overview]
Message-ID: <20230420101216.786304-13-thuth@redhat.com> (raw)
In-Reply-To: <20230420101216.786304-1-thuth@redhat.com>

Ideally, qtest.c should be independent from target specific code, so
we only have to compile it once for all targets. Thus start improving
the situation by moving the pseries related code to hw/ppc/spapr_rtas.c
instead and allow target code to register a callback handler for such
target specific commands.

Message-Id: <20230411183418.1640500-2-thuth@redhat.com>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 include/sysemu/qtest.h |  4 ++++
 hw/ppc/spapr_rtas.c    | 29 +++++++++++++++++++++++++++++
 softmmu/qtest.c        | 39 +++++++++++++--------------------------
 3 files changed, 46 insertions(+), 26 deletions(-)

diff --git a/include/sysemu/qtest.h b/include/sysemu/qtest.h
index 4c53537ef3..85f05b0e46 100644
--- a/include/sysemu/qtest.h
+++ b/include/sysemu/qtest.h
@@ -14,6 +14,7 @@
 #ifndef QTEST_H
 #define QTEST_H
 
+#include "chardev/char.h"
 
 extern bool qtest_allowed;
 
@@ -22,6 +23,9 @@ static inline bool qtest_enabled(void)
     return qtest_allowed;
 }
 
+void qtest_send_prefix(CharBackend *chr);
+void G_GNUC_PRINTF(2, 3) qtest_sendf(CharBackend *chr, const char *fmt, ...);
+void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words));
 bool qtest_driver(void);
 
 void qtest_server_init(const char *qtest_chrdev, const char *qtest_log, Error **errp);
diff --git a/hw/ppc/spapr_rtas.c b/hw/ppc/spapr_rtas.c
index 3f664ea02c..7df21581c2 100644
--- a/hw/ppc/spapr_rtas.c
+++ b/hw/ppc/spapr_rtas.c
@@ -33,6 +33,7 @@
 #include "sysemu/cpus.h"
 #include "sysemu/hw_accel.h"
 #include "sysemu/runstate.h"
+#include "sysemu/qtest.h"
 #include "kvm_ppc.h"
 
 #include "hw/ppc/spapr.h"
@@ -548,6 +549,32 @@ uint64_t qtest_rtas_call(char *cmd, uint32_t nargs, uint64_t args,
     return H_PARAMETER;
 }
 
+static bool spapr_qtest_callback(CharBackend *chr, gchar **words)
+{
+    if (strcmp(words[0], "rtas") == 0) {
+        uint64_t res, args, ret;
+        unsigned long nargs, nret;
+        int rc;
+
+        rc = qemu_strtoul(words[2], NULL, 0, &nargs);
+        g_assert(rc == 0);
+        rc = qemu_strtou64(words[3], NULL, 0, &args);
+        g_assert(rc == 0);
+        rc = qemu_strtoul(words[4], NULL, 0, &nret);
+        g_assert(rc == 0);
+        rc = qemu_strtou64(words[5], NULL, 0, &ret);
+        g_assert(rc == 0);
+        res = qtest_rtas_call(words[1], nargs, args, nret, ret);
+
+        qtest_send_prefix(chr);
+        qtest_sendf(chr, "OK %"PRIu64"\n", res);
+
+        return true;
+    }
+
+    return false;
+}
+
 void spapr_rtas_register(int token, const char *name, spapr_rtas_fn fn)
 {
     assert((token >= RTAS_TOKEN_BASE) && (token < RTAS_TOKEN_MAX));
@@ -630,6 +657,8 @@ static void core_rtas_register_types(void)
                         rtas_ibm_nmi_register);
     spapr_rtas_register(RTAS_IBM_NMI_INTERLOCK, "ibm,nmi-interlock",
                         rtas_ibm_nmi_interlock);
+
+    qtest_set_command_cb(spapr_qtest_callback);
 }
 
 type_init(core_rtas_register_types)
diff --git a/softmmu/qtest.c b/softmmu/qtest.c
index 26852996b5..09126df38a 100644
--- a/softmmu/qtest.c
+++ b/softmmu/qtest.c
@@ -29,10 +29,6 @@
 #include "qemu/module.h"
 #include "qemu/cutils.h"
 #include "qom/object_interfaces.h"
-#include CONFIG_DEVICES
-#ifdef CONFIG_PSERIES
-#include "hw/ppc/spapr_rtas.h"
-#endif
 
 #define MAX_IRQ 256
 
@@ -263,7 +259,7 @@ static int hex2nib(char ch)
     }
 }
 
-static void qtest_send_prefix(CharBackend *chr)
+void qtest_send_prefix(CharBackend *chr)
 {
     if (!qtest_log_fp || !qtest_opened) {
         return;
@@ -302,8 +298,7 @@ static void qtest_send(CharBackend *chr, const char *str)
     qtest_server_send(qtest_server_send_opaque, str);
 }
 
-static void G_GNUC_PRINTF(2, 3) qtest_sendf(CharBackend *chr,
-                                           const char *fmt, ...)
+void qtest_sendf(CharBackend *chr, const char *fmt, ...)
 {
     va_list ap;
     gchar *buffer;
@@ -361,6 +356,15 @@ static void qtest_clock_warp(int64_t dest)
     qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
 }
 
+static bool (*process_command_cb)(CharBackend *chr, gchar **words);
+
+void qtest_set_command_cb(bool (*pc_cb)(CharBackend *chr, gchar **words))
+{
+    assert(!process_command_cb);  /* Switch to a list if we need more than one */
+
+    process_command_cb = pc_cb;
+}
+
 static void qtest_process_command(CharBackend *chr, gchar **words)
 {
     const gchar *command;
@@ -717,25 +721,6 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         qtest_sendf(chr, "OK big\n");
 #else
         qtest_sendf(chr, "OK little\n");
-#endif
-#ifdef CONFIG_PSERIES
-    } else if (strcmp(words[0], "rtas") == 0) {
-        uint64_t res, args, ret;
-        unsigned long nargs, nret;
-        int rc;
-
-        rc = qemu_strtoul(words[2], NULL, 0, &nargs);
-        g_assert(rc == 0);
-        rc = qemu_strtou64(words[3], NULL, 0, &args);
-        g_assert(rc == 0);
-        rc = qemu_strtoul(words[4], NULL, 0, &nret);
-        g_assert(rc == 0);
-        rc = qemu_strtou64(words[5], NULL, 0, &ret);
-        g_assert(rc == 0);
-        res = qtest_rtas_call(words[1], nargs, args, nret, ret);
-
-        qtest_send_prefix(chr);
-        qtest_sendf(chr, "OK %"PRIu64"\n", res);
 #endif
     } else if (qtest_enabled() && strcmp(words[0], "clock_step") == 0) {
         int64_t ns;
@@ -777,6 +762,8 @@ static void qtest_process_command(CharBackend *chr, gchar **words)
         qtest_send_prefix(chr);
         qtest_sendf(chr, "OK %"PRIi64"\n",
                     (int64_t)qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL));
+    } else if (process_command_cb && process_command_cb(chr, words)) {
+        /* Command got consumed by the callback handler */
     } else {
         qtest_send_prefix(chr);
         qtest_sendf(chr, "FAIL Unknown command '%s'\n", words[0]);
-- 
2.31.1



  parent reply	other threads:[~2023-04-20 10:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-20 10:11 [PULL 00/23] First batch of testing and misc patches for 8.1 Thomas Huth
2023-04-20 10:11 ` [PULL 01/23] hw: Add compat machines " Thomas Huth
2023-04-20 10:11 ` [PULL 02/23] docs: Fix typo (wphx => whpx) Thomas Huth
2023-04-20 10:11 ` [PULL 03/23] docs/cxl: Fix sentence Thomas Huth
2023-04-20 10:11 ` [PULL 04/23] test: Fix test-crypto-secret when compiling without keyring support Thomas Huth
2023-04-20 10:11 ` [PULL 05/23] qtest: Don't assert on "-qtest chardev:myid" Thomas Huth
2023-04-20 10:11 ` [PULL 06/23] chardev: Allow setting file chardev input file on the command line Thomas Huth
2023-04-20 10:12 ` [PULL 07/23] travis.yml: Add missing clang-10 package to the 'Clang (disable-tcg)' job Thomas Huth
2023-04-20 10:12 ` [PULL 08/23] travis.yml: Add missing 'flex', 'bison' packages to 'GCC (user)' job Thomas Huth
2023-04-20 10:12 ` [PULL 09/23] tests/migration: Only run auto_converge in slow mode Thomas Huth
2023-04-20 10:12 ` [PULL 10/23] target/i386: Set family/model/stepping of the "max" CPU according to LM bit Thomas Huth
2023-04-20 10:12 ` [PULL 11/23] hw/char: Move two more files from specific_ss to softmmu_ss Thomas Huth
2023-04-20 10:12 ` Thomas Huth [this message]
2023-04-20 10:12 ` [PULL 13/23] include/exec: Provide the tswap() functions for target independent code, too Thomas Huth
2023-04-20 10:12 ` [PULL 14/23] softmmu: Make qtest.c target independent Thomas Huth
2023-04-20 10:12 ` [PULL 15/23] hw/display: Compile vga.c as target-independent code Thomas Huth
2023-04-20 10:12 ` [PULL 16/23] softmmu: Move dirtylimit.c into the target independent source set Thomas Huth
2023-04-20 10:12 ` [PULL 17/23] hw/core: Move numa.c " Thomas Huth
2023-04-20 10:12 ` [PULL 18/23] cpu: Remove parameter of list_cpus() Thomas Huth
2023-04-20 10:12 ` [PULL 19/23] MAINTAINERS: Add Juan Quintela to developer guides review Thomas Huth
2023-04-20 10:12 ` [PULL 20/23] qtest: Add functions for accessing devices on Aspeed I2C controller Thomas Huth
2023-04-20 10:12 ` [PULL 21/23] qtest: Move tpm_util_tis_transmit() into tpm-tis-utils.c and rename it Thomas Huth
2023-04-20 10:12 ` [PULL 22/23] qtest: Add a test case for TPM TIS I2C connected to Aspeed I2C controller Thomas Huth
2023-04-20 10:12 ` [PULL 23/23] tests/vm/freebsd: Update to FreeBSD 13.2 Thomas Huth
2023-04-21 17:28 ` [PULL 00/23] First batch of testing and misc patches for 8.1 Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230420101216.786304-13-thuth@redhat.com \
    --to=thuth@redhat.com \
    --cc=clg@kaod.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).