linux-s390.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Mueller <mimu@linux.vnet.ibm.com>
To: qemu-devel@nongnu.org, kvm@vger.kernel.org,
	linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: mimu@linux.vnet.ibm.com, Gleb Natapov <gleb@kernel.org>,
	Alexander Graf <agraf@suse.de>,
	Christian Borntraeger <borntraeger@de.ibm.com>,
	"Jason J. Herne" <jjherne@linux.vnet.ibm.com>,
	Cornelia Huck <cornelia.huck@de.ibm.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Andreas Faerber <afaerber@suse.de>,
	Richard Henderson <rth@twiddle.net>
Subject: [PATCH v1 RFC 04/10] QEMU: s390: cpu model alias support
Date: Tue, 13 May 2014 17:00:16 +0200	[thread overview]
Message-ID: <1399993222-16339-5-git-send-email-mimu@linux.vnet.ibm.com> (raw)
In-Reply-To: <1399993222-16339-1-git-send-email-mimu@linux.vnet.ibm.com>

This patch implements the infrastructure to dynamically add cpu model aliases.

Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 target-s390x/cpu-models.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/cpu-models.h | 12 +++++++++
 2 files changed, 76 insertions(+)

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index e437bd0..25147a4 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -86,6 +86,9 @@ S390_PROC_DEF("2827-ga1", CPU_S390_2827_GA1, "IBM zEnterprise EC12 GA1")
 S390_PROC_DEF("2827-ga2", CPU_S390_2827_GA2, "IBM zEnterprise EC12 GA2")
 S390_PROC_DEF("2828-ga1", CPU_S390_2828_GA1, "IBM zEnterprise BC12 GA1")
 
+/* S390 CPU aliases can be added dynamically to this list */
+GSList *s390_cpu_aliases;
+
 static inline unsigned long bit_in_word(unsigned int nr)
 {
     return 1ul << (__WORDSIZE - 1 - (nr % __WORDSIZE));
@@ -103,3 +106,64 @@ static inline int test_facility(unsigned long nr, unsigned long *fac_list)
 
     return (*ptr & bit_in_word(nr)) != 0;
 }
+
+static gint s390_cpu_compare_class_name(gconstpointer a, gconstpointer b)
+{
+    ObjectClass *oc = (ObjectClass *)a;
+    const char *name = b;
+
+    if (strncasecmp(name, object_class_get_name(oc), strlen(name)) == 0 &&
+        strcmp(object_class_get_name(oc) + strlen(name),
+               "-" TYPE_S390_CPU) == 0) {
+        return 0;
+    }
+
+    return -1;
+}
+
+ObjectClass *s390_cpu_class_by_name(const char *name)
+{
+    GSList *list, *item;
+    ObjectClass *ret = NULL;
+    S390CPUAlias *alias;
+
+    for (item = s390_cpu_aliases; item != NULL; item = item->next) {
+        alias = (S390CPUAlias *) item->data;
+        if (strcmp(alias->name, name) == 0) {
+            return s390_cpu_class_by_name(alias->model);
+        }
+    }
+    list = object_class_get_list(TYPE_S390_CPU, false);
+    item = g_slist_find_custom(list, name, s390_cpu_compare_class_name);
+    if (item) {
+        ret = OBJECT_CLASS(item->data);
+    }
+    g_slist_free(list);
+
+    return ret;
+}
+
+/* define a new s390 cpu alias */
+int set_s390_cpu_alias(const char *name, const char *model)
+{
+    S390CPUAlias *alias;
+
+    if (!name || !model) {
+        return -EINVAL;
+    }
+    if (!g_strcmp0(name, model)) {
+        return -EINVAL;
+    }
+    if (!s390_cpu_class_by_name(model)) {
+        return -EINVAL;
+    }
+    alias = g_try_malloc0(sizeof(S390CPUAlias));
+    if (!alias) {
+        return -ENOMEM;
+    }
+    alias->name = g_strdup(name);
+    alias->model = g_strdup(model);
+    s390_cpu_aliases = g_slist_append(s390_cpu_aliases, alias);
+
+    return 0;
+}
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 6f9a1a1..f5c8112 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -43,6 +43,18 @@
 #define cpu_class(x)      (((x) >> 20) & 0x3)
 #define cpu_generation(x) (((x) >> 24) & 0xff)
 
+ObjectClass *s390_cpu_class_by_name(const char *name);
+int set_s390_cpu_alias(const char *name, const char *model);
+
+/*
+ * S390 cpu aliases will be added dynamically
+ */
+typedef struct S390CPUAlias {
+    char *name;
+    char *model;
+} S390CPUAlias;
+extern GSList *s390_cpu_aliases;
+
 /*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
-- 
1.8.3.1

  parent reply	other threads:[~2014-05-13 15:00 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-13 15:00 [PATCH v1 RFC 00/10] QEMU: s390: cpu model implementation Michael Mueller
2014-05-13 15:00 ` [PATCH v1 RFC 01/10] QEMU: introduce function cpudesc_avail Michael Mueller
2014-05-13 15:00 ` [PATCH v1 RFC 02/10] QEMU: s390: cpu model cpu class definition Michael Mueller
2014-05-13 15:00 ` [PATCH v1 RFC 03/10] QEMU: s390: cpu model facilities support Michael Mueller
2014-05-13 15:00 ` Michael Mueller [this message]
2014-05-13 15:00 ` [PATCH v1 RFC 05/10] s390: update linux-headers for kvm VM device attributes Michael Mueller
2014-05-13 15:00 ` [PATCH v1 RFC 06/10] QEMU: s390: cpu model kvm VM attr interface routines Michael Mueller
2014-05-13 15:00 ` [PATCH v1 RFC 07/10] QEMU: s390: cpu model class initialization Michael Mueller
2014-05-13 15:00 ` [PATCH v1 RFC 08/10] QEMU: s390: cpu model QMP query-cpu-definitions Michael Mueller
2014-05-13 15:00 ` [PATCH v1 RFC 09/10] QEMU: s390: cpu model QMP query-cpu-model Michael Mueller
2014-05-13 15:29   ` Eric Blake
2014-05-14  9:07     ` [Qemu-devel] " Michael Mueller
2014-05-13 15:00 ` [PATCH v1 RFC 10/10] QEMU: s390: cpu model enablement Michael Mueller

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=1399993222-16339-5-git-send-email-mimu@linux.vnet.ibm.com \
    --to=mimu@linux.vnet.ibm.com \
    --cc=afaerber@suse.de \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=gleb@kernel.org \
    --cc=jjherne@linux.vnet.ibm.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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).