From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40731) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRKgt-0000Yl-Cp for qemu-devel@nongnu.org; Wed, 02 Oct 2013 07:34:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VRKgj-00026K-UB for qemu-devel@nongnu.org; Wed, 02 Oct 2013 07:34:03 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:48565) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VRKgj-00025r-M8 for qemu-devel@nongnu.org; Wed, 02 Oct 2013 07:33:53 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 2 Oct 2013 12:33:52 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 05052219005C for ; Wed, 2 Oct 2013 12:33:50 +0100 (BST) Received: from d06av04.portsmouth.uk.ibm.com (d06av04.portsmouth.uk.ibm.com [9.149.37.216]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r92BXbcM53608472 for ; Wed, 2 Oct 2013 11:33:37 GMT Received: from d06av04.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av04.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id r92BXnFA022905 for ; Wed, 2 Oct 2013 05:33:49 -0600 From: Michael Mueller Date: Wed, 2 Oct 2013 13:33:36 +0200 Message-Id: <1380713622-22325-6-git-send-email-mimu@linux.vnet.ibm.com> In-Reply-To: <1380713622-22325-1-git-send-email-mimu@linux.vnet.ibm.com> References: <1380713622-22325-1-git-send-email-mimu@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH RFC 05/11] s390/qemu: cpu model alias support List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Michael Mueller This patch implements the infrastructure to dynamically add cpu model aliases. Signed-off-by: Michael Mueller --- target-s390x/cpu-models.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++ target-s390x/cpu-models.h | 11 ++++++++ 2 files changed, 77 insertions(+) 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 -- 1.8.3.1