qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Balamuruhan S <bala24@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: maddy@linux.vnet.ibm.com, Balamuruhan S <bala24@linux.ibm.com>,
	anju@linux.vnet.ibm.com, clg@kaod.org, hari@linux.vnet.ibm.com,
	pbonzini@redhat.com, david@gibson.dropbear.id.au
Subject: [Qemu-devel] [RFC PATCH 2/6] hw/ppc/pnv_xscom: extend xscom to use python interface
Date: Wed,  7 Aug 2019 12:44:41 +0530	[thread overview]
Message-ID: <20190807071445.4109-3-bala24@linux.ibm.com> (raw)
In-Reply-To: <20190807071445.4109-1-bala24@linux.ibm.com>

Existing xscom access emulation for read/write can be
extended with the python interface to support feeding
data externally.

Signed-off-by: Balamuruhan S <bala24@linux.ibm.com>
---
 hw/ppc/pnv_xscom.c      | 31 ++++++++++++++++++++++++++++---
 include/sysemu/sysemu.h |  4 ++++
 qemu-options.hx         | 14 ++++++++++++++
 vl.c                    | 42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 88 insertions(+), 3 deletions(-)

diff --git a/hw/ppc/pnv_xscom.c b/hw/ppc/pnv_xscom.c
index 2b81c75f56..5d5b5e9884 100644
--- a/hw/ppc/pnv_xscom.c
+++ b/hw/ppc/pnv_xscom.c
@@ -17,11 +17,13 @@
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include "sysemu/python_api.h"
 #include "qemu/osdep.h"
 #include "hw/hw.h"
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "sysemu/hw_accel.h"
+#include "sysemu/sysemu.h"
 #include "target/ppc/cpu.h"
 #include "hw/sysbus.h"
 
@@ -157,8 +159,20 @@ static uint64_t xscom_read(void *opaque, hwaddr addr, unsigned width)
     uint64_t val = 0;
     MemTxResult result;
 
-    /* Handle some SCOMs here before dispatch */
-    val = xscom_read_default(chip, pcba);
+    if (xscom_module && xscom_readp) {
+        char **args = g_malloc(2 * sizeof(uint64_t));
+        PnvChipClass *pcc = PNV_CHIP_GET_CLASS(chip);
+        python_args_init_cast_long(args, pcba, 0);
+        python_args_init_cast_int(args, pcc->chip_type, 1);
+        val = python_callback_int(module_path, xscom_module, xscom_readp,
+                                  args, 2);
+        python_args_clean(args, 2);
+        g_free(args);
+    }
+    else {
+        /* Handle some SCOMs here before dispatch */
+        val = xscom_read_default(chip, pcba);
+    }
     if (val != -1) {
         goto complete;
     }
@@ -184,8 +198,19 @@ static void xscom_write(void *opaque, hwaddr addr, uint64_t val,
     uint32_t pcba = pnv_xscom_pcba(chip, addr);
     MemTxResult result;
 
+    if (xscom_module && xscom_writep) {
+        char **args = g_malloc(sizeof(uint64_t));
+        bool xscom_success;
+        python_args_init_cast_long(args, pcba, 0);
+        xscom_success = python_callback_bool(module_path, xscom_module,
+                                             xscom_writep, args, 1);
+        python_args_clean(args, 1);
+        g_free(args);
+        if (xscom_success)
+            goto complete;
+    }
     /* Handle some SCOMs here before dispatch */
-    if (xscom_write_default(chip, pcba, val)) {
+    else if (xscom_write_default(chip, pcba, val)) {
         goto complete;
     }
 
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 984c439ac9..9b8dc346d6 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -117,6 +117,10 @@ extern bool enable_mlock;
 extern bool enable_cpu_pm;
 extern QEMUClockType rtc_clock;
 extern const char *mem_path;
+extern const char *module_path;
+extern const char *xscom_module;
+extern const char *xscom_readp;
+extern const char *xscom_writep;
 extern int mem_prealloc;
 
 #define MAX_NODES 128
diff --git a/qemu-options.hx b/qemu-options.hx
index 9621e934c0..06c9f34d99 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -385,6 +385,20 @@ STEXI
 Allocate guest RAM from a temporarily created file in @var{path}.
 ETEXI
 
+DEF("module-path", HAS_ARG, QEMU_OPTION_modulepath,
+    "-module-path FILE  provide absolute path where python modules"
+    "resides\n", QEMU_ARCH_ALL)
+STEXI
+@item -module-path [path=]@var{absolute path}[,homer_module=homer,homer_func=func1]
+@findex -module-path
+Provides information about where the python modules exist and the callback
+functions defined.
+
+@example
+qemu-system-ppc64 -module-path /home/modules/,homer_module=homer,homer_func=homer_read
+@end example
+ETEXI
+
 DEF("mem-prealloc", 0, QEMU_OPTION_mem_prealloc,
     "-mem-prealloc   preallocate guest memory (use with -mem-path)\n",
     QEMU_ARCH_ALL)
diff --git a/vl.c b/vl.c
index b426b32134..28f0dc1c1b 100644
--- a/vl.c
+++ b/vl.c
@@ -140,6 +140,10 @@ int display_opengl;
 const char* keyboard_layout = NULL;
 ram_addr_t ram_size;
 const char *mem_path = NULL;
+const char *module_path = NULL;
+const char *xscom_module = NULL;
+const char *xscom_readp = NULL;
+const char *xscom_writep = NULL;
 int mem_prealloc = 0; /* force preallocation of physical target memory */
 bool enable_mlock = false;
 bool enable_cpu_pm = false;
@@ -469,6 +473,32 @@ static QemuOptsList qemu_mem_opts = {
     },
 };
 
+static QemuOptsList qemu_module_opts = {
+    .name = "module_path",
+    .implied_opt_name = "module_path",
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_module_opts.head),
+    .merge_lists = true,
+    .desc = {
+        {
+            .name = "module_path",
+            .type = QEMU_OPT_STRING,
+        },
+        {
+            .name = "xscom_module",
+            .type = QEMU_OPT_STRING,
+        },
+        {
+            .name = "xscom_read",
+            .type = QEMU_OPT_STRING,
+        },
+        {
+            .name = "xscom_write",
+            .type = QEMU_OPT_STRING,
+        },
+        { /* end of list */ }
+    },
+};
+
 static QemuOptsList qemu_icount_opts = {
     .name = "icount",
     .implied_opt_name = "shift",
@@ -2923,6 +2953,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_machine_opts);
     qemu_add_opts(&qemu_accel_opts);
     qemu_add_opts(&qemu_mem_opts);
+    qemu_add_opts(&qemu_module_opts);
     qemu_add_opts(&qemu_smp_opts);
     qemu_add_opts(&qemu_boot_opts);
     qemu_add_opts(&qemu_add_fd_opts);
@@ -3190,6 +3221,17 @@ int main(int argc, char **argv, char **envp)
             case QEMU_OPTION_mempath:
                 mem_path = optarg;
                 break;
+            case QEMU_OPTION_modulepath:
+                opts = qemu_opts_parse_noisily(qemu_find_opts("module_path"),
+                                               optarg, true);
+                if (!opts) {
+                    exit(EXIT_FAILURE);
+                }
+                module_path = qemu_opt_get(opts, "module_path");
+                xscom_module = qemu_opt_get(opts, "xscom_module");
+                xscom_readp = qemu_opt_get(opts, "xscom_read");
+                xscom_writep = qemu_opt_get(opts, "xscom_write");
+                break;
             case QEMU_OPTION_mem_prealloc:
                 mem_prealloc = 1;
                 break;
-- 
2.14.5



  parent reply	other threads:[~2019-08-07  7:17 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-07  7:14 [Qemu-devel] [RFC PATCH 0/6] Enhancing Qemu MMIO emulation with scripting interface Balamuruhan S
2019-08-07  7:14 ` [Qemu-devel] [RFC PATCH 1/6] utils/python_api: add scripting interface for Qemu with python lib Balamuruhan S
2019-08-07 10:20   ` Philippe Mathieu-Daudé
2019-08-08 10:10     ` Stefan Hajnoczi
2019-08-08 10:33       ` Philippe Mathieu-Daudé
2019-08-08 10:53       ` Daniel P. Berrangé
2019-08-09  8:46         ` Stefan Hajnoczi
2019-08-12  4:53           ` Balamuruhan S
2019-08-08 10:09   ` Stefan Hajnoczi
2019-08-11  6:39     ` Balamuruhan S
2019-08-08 10:49   ` Daniel P. Berrangé
2019-08-08 12:45     ` Philippe Mathieu-Daudé
2019-08-09  4:39       ` David Gibson
2019-08-12  4:45       ` Balamuruhan S
2019-08-07  7:14 ` Balamuruhan S [this message]
2019-08-08  9:04   ` [Qemu-devel] [RFC PATCH 2/6] hw/ppc/pnv_xscom: extend xscom to use python interface Cédric Le Goater
2019-08-07  7:14 ` [Qemu-devel] [RFC PATCH 3/6] hw/ppc/pnv_homer: add homer/occ common area emulation for PowerNV Balamuruhan S
2019-08-07  7:54   ` Cédric Le Goater
2019-08-07 10:07     ` Balamuruhan S
2019-08-08  8:32       ` Cédric Le Goater
2019-08-09  4:44     ` David Gibson
2019-08-11  6:34       ` Balamuruhan S
2019-08-07  7:14 ` [Qemu-devel] [RFC PATCH 4/6] hw/ppc/pnv: initialize and realize homer/occ common area Balamuruhan S
2019-08-07  7:59   ` Cédric Le Goater
2019-08-07 10:12     ` Balamuruhan S
2019-08-08  8:46       ` Cédric Le Goater
2019-08-09  4:45   ` David Gibson
2019-08-07  7:14 ` [Qemu-devel] [RFC PATCH 5/6] hw/ppc/pnv_xscom: retrieve homer/occ base address from PBA BARs Balamuruhan S
2019-08-07  8:01   ` Cédric Le Goater
2019-08-07 10:22     ` Balamuruhan S
2019-08-09  4:45   ` David Gibson
2019-08-07  7:14 ` [Qemu-devel] [RFC PATCH 6/6] hw/ppc/pnv_homer: add python interface support for homer/occ common area Balamuruhan S
2019-08-07 10:27   ` Philippe Mathieu-Daudé
2019-08-11  6:05     ` Balamuruhan S
2019-08-09  4:46   ` David Gibson
2019-08-11  6:19     ` Balamuruhan S
2019-08-07  7:33 ` [Qemu-devel] [RFC PATCH 0/6] Enhancing Qemu MMIO emulation with scripting interface no-reply
2019-08-07  8:15 ` Cédric Le Goater
2019-08-07 10:16   ` Balamuruhan S
2019-08-09  4:49   ` David Gibson
2019-08-12  5:07     ` Balamuruhan S
2019-08-07  8:51 ` no-reply
2019-08-07  9:18 ` no-reply
2019-08-08 10:25 ` Stefan Hajnoczi
2019-08-12  6:03   ` Balamuruhan S

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=20190807071445.4109-3-bala24@linux.ibm.com \
    --to=bala24@linux.ibm.com \
    --cc=anju@linux.vnet.ibm.com \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=hari@linux.vnet.ibm.com \
    --cc=maddy@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.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).