Patchwork [RFC,05/11] s390/qemu: cpu model alias support

login
register
mail settings
Submitter Michael Mueller
Date Oct. 2, 2013, 11:33 a.m.
Message ID <1380713622-22325-6-git-send-email-mimu@linux.vnet.ibm.com>
Download mbox | patch
Permalink /patch/279701/
State New
Headers show

Comments

Michael Mueller - Oct. 2, 2013, 11:33 a.m.
This patch implements the infrastructure to dynamically add cpu model aliases.

Signed-off-by: Michael Mueller <mimu@linux.vnet.ibm.com>
---
 target-s390x/cpu-models.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 target-s390x/cpu-models.h | 11 ++++++++
 2 files changed, 77 insertions(+)

Patch

diff --git a/target-s390x/cpu-models.c b/target-s390x/cpu-models.c
index b813f89..4a4720a 100644
--- a/target-s390x/cpu-models.c
+++ b/target-s390x/cpu-models.c
@@ -171,6 +171,69 @@  static unsigned long *facilities(unsigned int cpu_id)
     return fac;
 }
 
+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 */
+static int set_s390_cpu_alias(const char *name, const char *model)
+{
+    S390CPUAlias *alias;
+    GSList *item;
+
+        if (!name || !model) {
+            return -1;
+        }
+    if (!s390_cpu_class_by_name(model)) {
+            return -1;
+        }
+
+        alias = g_malloc0(sizeof(S390CPUAlias));
+        if (!alias) {
+            return -1;
+        }
+    item = g_slist_alloc();
+    if (!item) {
+            g_free(alias);
+            return -1;
+        }
+    alias->name = g_strdup(name);
+    alias->model = g_strdup(model);
+    s390_cpu_aliases = g_slist_append(s390_cpu_aliases, alias);
+
+        return 0;
+}
+
 /* define S390 CPU model classes */
 S390_PROC_DEF("2064-ga1", CPU_S390_2064_GA1, "IBM zSeries 900 GA1")
 S390_PROC_DEF("2064-ga2", CPU_S390_2064_GA2, "IBM zSeries 900 GA2")
@@ -200,3 +263,6 @@  S390_PROC_DEF("2818-ga1", CPU_S390_2818_GA1, "IBM zEnterprise 114 GA1")
 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 will be added dynamically to this list */
+GSList *s390_cpu_aliases;
diff --git a/target-s390x/cpu-models.h b/target-s390x/cpu-models.h
index 8a3b947..e188eca 100644
--- a/target-s390x/cpu-models.h
+++ b/target-s390x/cpu-models.h
@@ -26,6 +26,17 @@ 
 #define cpu_generation(x) (((x) >> 24) & 0xff)
 
 /*
+ * S390 cpu aliases will be added dynamically
+ */
+typedef struct S390CPUAlias {
+    char *name;
+    char *model;
+} S390CPUAlias;
+extern GSList *s390_cpu_aliases;
+
+ObjectClass *s390_cpu_class_by_name(const char *name);
+
+/*
  * bits 0-7   : CMOS generation
  * bits 8-9   : reserved
  * bits 10-11 : machine class 0/unknown 1/EC 2/BC