qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Kardashevskiy <aik@ozlabs.ru>
To: qemu-devel@nongnu.org
Cc: "Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"Igor Mammedov" <imammedo@redhat.com>,
	qemu-ppc@nongnu.org, "Andreas Färber" <afaerber@suse.de>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH v2 1/2] cpu: add suboptions support
Date: Fri,  8 Nov 2013 19:22:42 +1100	[thread overview]
Message-ID: <1383898963-4772-2-git-send-email-aik@ozlabs.ru> (raw)
In-Reply-To: <1383898963-4772-1-git-send-email-aik@ozlabs.ru>

This adds suboptions support for -cpu.

Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Andreas Färber <afaerber@suse.de>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
---
 include/qom/cpu.h       | 29 +++++++++++++++++++++++++++++
 include/sysemu/sysemu.h |  1 +
 qom/cpu.c               | 27 +++++++++++++++++++++++++++
 vl.c                    | 42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 99 insertions(+)

diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index 7739e00..7d3b043 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -124,6 +124,7 @@ typedef struct CPUClass {
                             int cpuid, void *opaque);
     int (*write_elf32_qemunote)(WriteCoreDumpFunction f, CPUState *cpu,
                                 void *opaque);
+    void (*parse_options)(CPUState *cpu, Error **errp);
 
     const struct VMStateDescription *vmsd;
     int gdb_num_core_regs;
@@ -327,6 +328,34 @@ static inline hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
 #endif
 
 /**
+ * cpu_parse_options:
+ * @cpu: The CPU to set options for.
+ */
+static inline int cpu_parse_options(CPUState *cpu)
+{
+    CPUClass *cc = CPU_GET_CLASS(cpu);
+    Error *err = NULL;
+
+    if (cc->parse_options) {
+        cc->parse_options(cpu, &err);
+        if (err) {
+            return -1;
+        }
+    }
+
+    /* No callback, let arch do it the old way */
+    return 0;
+}
+
+/**
+ * cpu_default_parse_options_func:
+ * The default handler for CPUClass::parse_options
+ * @cpu: the CPU to set option for.
+ * @errp: the handling error descriptor.
+ */
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp);
+
+/**
  * cpu_reset:
  * @cpu: The CPU whose state is to be reset.
  */
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index cd5791e..c6e3ea0 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -190,6 +190,7 @@ char *get_boot_devices_list(size_t *size);
 DeviceState *get_boot_device(uint32_t position);
 
 QemuOpts *qemu_get_machine_opts(void);
+QemuOpts *qemu_get_cpu_opts(void);
 
 bool usb_enabled(bool default_usb);
 
diff --git a/qom/cpu.c b/qom/cpu.c
index 818fb26..231dec5 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -24,6 +24,8 @@
 #include "qemu/notify.h"
 #include "qemu/log.h"
 #include "sysemu/sysemu.h"
+#include "qapi/qmp/qerror.h"
+#include "qemu/config-file.h"
 
 bool cpu_exists(int64_t id)
 {
@@ -186,6 +188,31 @@ void cpu_reset(CPUState *cpu)
     }
 }
 
+static int cpu_set_property(const char *name, const char *value, void *opaque)
+{
+    Error *err = NULL;
+
+    if (strcmp(name, "type") == 0) {
+        return 0;
+    }
+
+    object_property_parse(opaque, value, name, &err);
+    if (err != NULL) {
+        qerror_report_err(err);
+        error_free(err);
+        return -1;
+    }
+
+    return 0;
+}
+
+void cpu_default_parse_options_func(CPUState *cpu, Error **errp)
+{
+    if (qemu_opt_foreach(qemu_get_cpu_opts(), cpu_set_property, cpu, 1)) {
+        error_setg(errp, "Bad option");
+    }
+}
+
 static void cpu_common_reset(CPUState *cpu)
 {
     CPUClass *cc = CPU_GET_CLASS(cpu);
diff --git a/vl.c b/vl.c
index 4ad15b8..09f8e8b 100644
--- a/vl.c
+++ b/vl.c
@@ -433,6 +433,16 @@ static QemuOptsList qemu_machine_opts = {
     },
 };
 
+static QemuOptsList qemu_cpu_opts = {
+    .name = "cpu",
+    .implied_opt_name = "type",
+    .merge_lists = true,
+    .head = QTAILQ_HEAD_INITIALIZER(qemu_cpu_opts.head),
+    .desc = {
+        { /* End of list */ }
+    },
+};
+
 static QemuOptsList qemu_boot_opts = {
     .name = "boot-opts",
     .implied_opt_name = "order",
@@ -548,6 +558,25 @@ QemuOpts *qemu_get_machine_opts(void)
     return opts;
 }
 
+/**
+ * Get CPU options
+ *
+ * Returns: CPU options (never null).
+ */
+QemuOpts *qemu_get_cpu_opts(void)
+{
+    QemuOptsList *list;
+    QemuOpts *opts;
+
+    list = qemu_find_opts("cpu");
+    assert(list);
+    opts = qemu_opts_find(list, NULL);
+    if (!opts) {
+        opts = qemu_opts_create_nofail(list);
+    }
+    return opts;
+}
+
 const char *qemu_get_vm_name(void)
 {
     return qemu_name;
@@ -2877,6 +2906,7 @@ int main(int argc, char **argv, char **envp)
     qemu_add_opts(&qemu_trace_opts);
     qemu_add_opts(&qemu_option_rom_opts);
     qemu_add_opts(&qemu_machine_opts);
+    qemu_add_opts(&qemu_cpu_opts);
     qemu_add_opts(&qemu_smp_opts);
     qemu_add_opts(&qemu_boot_opts);
     qemu_add_opts(&qemu_sandbox_opts);
@@ -2972,7 +3002,19 @@ int main(int argc, char **argv, char **envp)
             }
             case QEMU_OPTION_cpu:
                 /* hw initialization will check this */
+
+                /* Store cpu_model for old style parser */
                 cpu_model = optarg;
+
+                /*
+                 * Parse and save options in the cpu options list
+                 * for a new parser
+                 */
+                olist = qemu_find_opts("cpu");
+                opts = qemu_opts_parse(olist, optarg, 1);
+                if (!opts) {
+                    exit(1);
+                }
                 break;
             case QEMU_OPTION_hda:
                 {
-- 
1.8.4.rc4

  reply	other threads:[~2013-11-08  8:23 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-27  8:06 [Qemu-devel] [PATCH] spapr: add "compat" machine option Alexey Kardashevskiy
2013-09-30 11:25 ` Alexander Graf
2013-09-30 11:52   ` Paolo Bonzini
2013-09-30 12:57     ` Alexey Kardashevskiy
2013-11-05  9:06       ` Paolo Bonzini
2013-11-05  9:16         ` Alexander Graf
2013-11-05  9:52           ` Paolo Bonzini
2013-11-05 10:27             ` Alexander Graf
2013-11-05 10:33               ` Paolo Bonzini
2013-11-05 10:45             ` Alexey Kardashevskiy
2013-11-05 10:46               ` Paolo Bonzini
2013-11-05 13:53             ` Andreas Färber
2013-11-06 11:36               ` Igor Mammedov
2013-11-07  9:11               ` Alexey Kardashevskiy
2013-11-07 13:36                 ` Igor Mammedov
2013-11-08  8:22                   ` Alexey Kardashevskiy
2013-11-08 13:20                     ` Andreas Färber
2013-11-08 14:57                       ` Alexey Kardashevskiy
2013-11-08 15:07                         ` Andreas Färber
2013-11-07 14:01                 ` Andreas Färber
2013-11-08  8:22                   ` [Qemu-devel] [PATCH v2 0/2] " Alexey Kardashevskiy
2013-11-08  8:22                     ` Alexey Kardashevskiy [this message]
2013-11-08  8:22                     ` [Qemu-devel] [PATCH v2 2/2] target-ppc: add "compat" CPU option Alexey Kardashevskiy
2013-11-08 13:24                     ` [Qemu-devel] [PATCH v2 0/2] spapr: add "compat" machine option Andreas Färber
2013-11-06  3:27         ` [Qemu-devel] [PATCH] " Paul Mackerras
2013-09-30 13:22   ` Alexey Kardashevskiy
2013-09-30 14:49     ` Alexander Graf
2013-11-05  2:19       ` Alexey Kardashevskiy
2013-11-05  9:23         ` Alexander Graf
2013-11-06  5:48   ` Paul Mackerras
2013-11-06 12:07     ` Alexander Graf

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=1383898963-4772-2-git-send-email-aik@ozlabs.ru \
    --to=aik@ozlabs.ru \
    --cc=afaerber@suse.de \
    --cc=imammedo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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).