All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Andreas Färber" <afaerber@suse.de>
To: qemu-devel@nongnu.org
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Andreas Färber" <afaerber@suse.de>,
	"Paul Brook" <paul@codesourcery.com>
Subject: [Qemu-devel] [PATCH RFC v3 04/21] target-arm: Introduce QOM CPU and use it for CPUID lookup
Date: Fri,  3 Feb 2012 03:59:35 +0100	[thread overview]
Message-ID: <1328237992-14953-5-git-send-email-afaerber@suse.de> (raw)
In-Reply-To: <1328237992-14953-1-git-send-email-afaerber@suse.de>

Create a CPU subclass, and register classes matching all CPU models
except for "pxa270", which is an alias for "pxa270-a0".

Make arm_cpu_list() enumerate CPU subclasses.

Replace cpu_arm_find_by_name()'s string -> CPUID lookup by storing the
CPUID in the class.
NB: CPUIDs were first introduced by Paul Brook in r1765 (2006).

Signed-off-by: Andreas Färber <afaerber@suse.de>
Cc: Anthony Liguori <anthony@codemonkey.ws>
Cc: Paul Brook <paul@codesourcery.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
---
 Makefile.target       |    1 +
 target-arm/cpu-core.h |   59 +++++++++++++++
 target-arm/cpu.c      |  190 +++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/cpu.h      |    1 -
 target-arm/helper.c   |   85 +++++++---------------
 5 files changed, 277 insertions(+), 59 deletions(-)
 create mode 100644 target-arm/cpu-core.h
 create mode 100644 target-arm/cpu.c

diff --git a/Makefile.target b/Makefile.target
index 68481a3..5c139be 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -80,6 +80,7 @@ endif
 libobj-$(TARGET_SPARC64) += vis_helper.o
 libobj-$(CONFIG_NEED_MMU) += mmu.o
 libobj-$(TARGET_ARM) += neon_helper.o iwmmxt_helper.o
+libobj-$(TARGET_ARM) += cpu.o
 ifeq ($(TARGET_BASE_ARCH), sparc)
 libobj-y += fop_helper.o cc_helper.o win_helper.o mmu_helper.o ldst_helper.o
 libobj-y += cpu_init.o
diff --git a/target-arm/cpu-core.h b/target-arm/cpu-core.h
new file mode 100644
index 0000000..3e8f046
--- /dev/null
+++ b/target-arm/cpu-core.h
@@ -0,0 +1,59 @@
+/*
+ * QEMU ARM CPU
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/old-licenses/gpl-2.0>
+ */
+#ifndef QEMU_ARM_CPU_CORE_H
+#define QEMU_ARM_CPU_CORE_H
+
+#include "qemu/cpu.h"
+
+#define TYPE_ARM_CPU "arm-cpu"
+
+#define ARM_CPU_CLASS(klass) \
+    OBJECT_CLASS_CHECK(ARMCPUClass, (klass), TYPE_ARM_CPU)
+#define ARM_CPU(obj) \
+    OBJECT_CHECK(ARMCPU, (obj), TYPE_ARM_CPU)
+#define ARM_CPU_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(ARMCPUClass, (obj), TYPE_ARM_CPU)
+
+/**
+ * ARMCPUClass:
+ *
+ * An ARM CPU model.
+ */
+typedef struct ARMCPUClass {
+    /*< private >*/
+    CPUClass parent_class;
+
+    struct {
+        uint32_t c0_cpuid;
+    } cp15;
+} ARMCPUClass;
+
+/**
+ * ARMCPU:
+ *
+ * An ARM CPU core.
+ */
+typedef struct ARMCPU {
+    /*< private >*/
+    CPU parent_obj;
+} ARMCPU;
+
+
+#endif
diff --git a/target-arm/cpu.c b/target-arm/cpu.c
new file mode 100644
index 0000000..9255a19
--- /dev/null
+++ b/target-arm/cpu.c
@@ -0,0 +1,190 @@
+/*
+ * QEMU ARM CPU
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/old-licenses/gpl-2.0>
+ */
+
+#include "cpu-core.h"
+#include "qemu-common.h"
+
+static void arm_cpu_reset(CPU *c)
+{
+    cpu_common_reset(c);
+}
+
+/* CPU models */
+
+typedef struct ARMCPUInfo {
+    const char *name;
+    uint32_t id;
+} ARMCPUInfo;
+
+static const ARMCPUInfo arm_cpus[] = {
+    {
+        .name = "arm926",
+        .id = 0x41069265,
+    },
+    {
+        .name = "arm946",
+        .id = 0x41059461,
+    },
+    {
+        .name = "arm1026",
+        .id = 0x4106a262,
+    },
+    /* What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an
+     * older core than plain "arm1136". In particular this does not
+     * have the v6K features.
+     */
+    {
+        .name = "arm1136-r2",
+        .id = 0x4107b362,
+    },
+    {
+        .name = "arm1136",
+        .id = 0x4117b363,
+    },
+    {
+        .name = "arm1176",
+        .id = 0x410fb767,
+    },
+    {
+        .name = "arm11mpcore",
+        .id = 0x410fb022,
+    },
+    {
+        .name = "cortex-m3",
+        .id = 0x410fc231,
+    },
+    {
+        .name = "cortex-a8",
+        .id = 0x410fc080,
+    },
+    {
+        .name = "cortex-a9",
+        .id = 0x410fc090,
+    },
+    {
+        .name = "cortex-a15",
+        .id = 0x412fc0f1,
+    },
+    {
+        .name = "ti925t",
+        .id = 0x54029252,
+    },
+    {
+        .name = "sa1100",
+        .id = 0x4401A11B,
+    },
+    {
+        .name = "sa1110",
+        .id = 0x6901B119,
+    },
+    {
+        .name = "pxa250",
+        .id = 0x69052100,
+    },
+    {
+        .name = "pxa255",
+        .id = 0x69052d00,
+    },
+    {
+        .name = "pxa260",
+        .id = 0x69052903,
+    },
+    {
+        .name = "pxa261",
+        .id = 0x69052d05,
+    },
+    {
+        .name = "pxa262",
+        .id = 0x69052d06,
+    },
+    {
+        .name = "pxa270-a0",
+        .id = 0x69054110,
+    },
+    {
+        .name = "pxa270-a1",
+        .id = 0x69054111,
+    },
+    {
+        .name = "pxa270-b0",
+        .id = 0x69054112,
+    },
+    {
+        .name = "pxa270-b1",
+        .id = 0x69054113,
+    },
+    {
+        .name = "pxa270-c0",
+        .id = 0x69054114,
+    },
+    {
+        .name = "pxa270-c5",
+        .id = 0x69054117,
+    },
+    {
+        .name = "any",
+        .id = 0xffffffff,
+    },
+};
+
+static void arm_cpu_class_init(ObjectClass *klass, void *data)
+{
+    ARMCPUClass *k = ARM_CPU_CLASS(klass);
+    CPUClass *cpu_class = CPU_CLASS(klass);
+    const ARMCPUInfo *info = data;
+
+    cpu_class->reset = arm_cpu_reset;
+
+    k->cp15.c0_cpuid = info->id;
+}
+
+static void cpu_register(const ARMCPUInfo *info)
+{
+    TypeInfo type = {
+        .name = info->name,
+        .parent = TYPE_ARM_CPU,
+        .instance_size = sizeof(ARMCPU),
+        .class_size = sizeof(ARMCPUClass),
+        .class_init = arm_cpu_class_init,
+        .class_data = (void *)info,
+    };
+
+    type_register_static(&type);
+}
+
+static TypeInfo arm_cpu_type_info = {
+    .name = TYPE_ARM_CPU,
+    .parent = TYPE_CPU,
+    .instance_size = sizeof(ARMCPU),
+    .abstract = true,
+    .class_size = sizeof(ARMCPUClass),
+};
+
+static void arm_cpu_types_init(void)
+{
+    int i;
+
+    type_register_static(&arm_cpu_type_info);
+    for (i = 0; i < ARRAY_SIZE(arm_cpus); i++) {
+        cpu_register(&arm_cpus[i]);
+    }
+}
+
+type_init(arm_cpu_types_init)
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 0d9b39c..5905ef2 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -420,7 +420,6 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum,
 #define ARM_CPUID_PXA260      0x69052903
 #define ARM_CPUID_PXA261      0x69052d05
 #define ARM_CPUID_PXA262      0x69052d06
-#define ARM_CPUID_PXA270      0x69054110
 #define ARM_CPUID_PXA270_A0   0x69054110
 #define ARM_CPUID_PXA270_A1   0x69054111
 #define ARM_CPUID_PXA270_B0   0x69054112
diff --git a/target-arm/helper.c b/target-arm/helper.c
index ea4f35f..d8425db 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -11,6 +11,7 @@
 #include "hw/loader.h"
 #endif
 #include "sysemu.h"
+#include "cpu-core.h"
 
 static uint32_t cortexa15_cp15_c0_c1[8] = {
     0x00001131, 0x00011011, 0x02010555, 0x00000000,
@@ -51,8 +52,6 @@ static uint32_t arm1176_cp15_c0_c1[8] =
 static uint32_t arm1176_cp15_c0_c2[8] =
 { 0x0140011, 0x12002111, 0x11231121, 0x01102131, 0x01141, 0, 0, 0 };
 
-static uint32_t cpu_arm_find_by_name(const char *name);
-
 static inline void set_feature(CPUARMState *env, int feature)
 {
     env->features |= 1u << feature;
@@ -400,13 +399,21 @@ static int vfp_gdb_set_reg(CPUState *env, uint8_t *buf, int reg)
 
 CPUARMState *cpu_arm_init(const char *cpu_model)
 {
+    ObjectClass *klass;
+    ARMCPUClass *cpu_class;
     CPUARMState *env;
-    uint32_t id;
     static int inited = 0;
 
-    id = cpu_arm_find_by_name(cpu_model);
-    if (id == 0)
+    /* One legacy alias to check */
+    if (strcmp(cpu_model, "pxa270") == 0) {
+        cpu_model = "pxa270-a0";
+    }
+
+    klass = object_class_by_name(cpu_model);
+    if (klass == NULL) {
         return NULL;
+    }
+    cpu_class = ARM_CPU_CLASS(klass);
     env = g_malloc0(sizeof(CPUARMState));
     cpu_exec_init(env);
     if (tcg_enabled() && !inited) {
@@ -415,7 +422,7 @@ CPUARMState *cpu_arm_init(const char *cpu_model)
     }
 
     env->cpu_model_str = cpu_model;
-    env->cp15.c0_cpuid = id;
+    env->cp15.c0_cpuid = cpu_class->cp15.c0_cpuid;
     cpu_reset(env);
     if (arm_feature(env, ARM_FEATURE_NEON)) {
         gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
@@ -431,66 +438,28 @@ CPUARMState *cpu_arm_init(const char *cpu_model)
     return env;
 }
 
-struct arm_cpu_t {
-    uint32_t id;
-    const char *name;
+struct ARMCPUListState {
+    fprintf_function cpu_fprintf;
+    FILE *file;
 };
 
-static const struct arm_cpu_t arm_cpu_names[] = {
-    { ARM_CPUID_ARM926, "arm926"},
-    { ARM_CPUID_ARM946, "arm946"},
-    { ARM_CPUID_ARM1026, "arm1026"},
-    { ARM_CPUID_ARM1136, "arm1136"},
-    { ARM_CPUID_ARM1136_R2, "arm1136-r2"},
-    { ARM_CPUID_ARM1176, "arm1176"},
-    { ARM_CPUID_ARM11MPCORE, "arm11mpcore"},
-    { ARM_CPUID_CORTEXM3, "cortex-m3"},
-    { ARM_CPUID_CORTEXA8, "cortex-a8"},
-    { ARM_CPUID_CORTEXA9, "cortex-a9"},
-    { ARM_CPUID_CORTEXA15, "cortex-a15" },
-    { ARM_CPUID_TI925T, "ti925t" },
-    { ARM_CPUID_PXA250, "pxa250" },
-    { ARM_CPUID_SA1100,    "sa1100" },
-    { ARM_CPUID_SA1110,    "sa1110" },
-    { ARM_CPUID_PXA255, "pxa255" },
-    { ARM_CPUID_PXA260, "pxa260" },
-    { ARM_CPUID_PXA261, "pxa261" },
-    { ARM_CPUID_PXA262, "pxa262" },
-    { ARM_CPUID_PXA270, "pxa270" },
-    { ARM_CPUID_PXA270_A0, "pxa270-a0" },
-    { ARM_CPUID_PXA270_A1, "pxa270-a1" },
-    { ARM_CPUID_PXA270_B0, "pxa270-b0" },
-    { ARM_CPUID_PXA270_B1, "pxa270-b1" },
-    { ARM_CPUID_PXA270_C0, "pxa270-c0" },
-    { ARM_CPUID_PXA270_C5, "pxa270-c5" },
-    { ARM_CPUID_ANY, "any"},
-    { 0, NULL}
-};
-
-void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf)
+static void arm_cpu_list_entry(ObjectClass *klass, void *opaque)
 {
-    int i;
+    struct ARMCPUListState *s = opaque;
 
-    (*cpu_fprintf)(f, "Available CPUs:\n");
-    for (i = 0; arm_cpu_names[i].name; i++) {
-        (*cpu_fprintf)(f, "  %s\n", arm_cpu_names[i].name);
-    }
+    (*s->cpu_fprintf)(s->file, "  %s\n",
+                      object_class_get_name(klass));
 }
 
-/* return 0 if not found */
-static uint32_t cpu_arm_find_by_name(const char *name)
+void arm_cpu_list(FILE *f, fprintf_function cpu_fprintf)
 {
-    int i;
-    uint32_t id;
+    struct ARMCPUListState s = {
+        .cpu_fprintf = cpu_fprintf,
+        .file = f,
+    };
 
-    id = 0;
-    for (i = 0; arm_cpu_names[i].name; i++) {
-        if (strcmp(name, arm_cpu_names[i].name) == 0) {
-            id = arm_cpu_names[i].id;
-            break;
-        }
-    }
-    return id;
+    (*cpu_fprintf)(f, "Available CPUs:\n");
+    object_class_foreach(arm_cpu_list_entry, TYPE_CPU, false, &s);
 }
 
 void cpu_arm_close(CPUARMState *env)
-- 
1.7.7

  parent reply	other threads:[~2012-02-03  3:02 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-03  2:59 [Qemu-devel] [PATCH RFC v3 00/21] Introduce QOM CPU and use it for ARM Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH v3 01/21] qom: Register QOM infrastructure early Andreas Färber
2012-02-06 19:14   ` Anthony Liguori
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 02/21] qom: Add QOM support to user emulators Andreas Färber
2012-02-06 19:16   ` Anthony Liguori
2012-02-06 23:23     ` Andreas Färber
2012-02-07 17:25     ` Peter Maydell
2012-02-07 17:51       ` Anthony Liguori
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 03/21] qom: Introduce CPU class Andreas Färber
2012-02-06 19:24   ` Anthony Liguori
2012-02-06 20:01     ` Peter Maydell
2012-02-06 20:14     ` Andreas Färber
2012-02-06 21:22       ` Anthony Liguori
2012-02-03  2:59 ` Andreas Färber [this message]
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 05/21] target-arm: Embed CPUARMState in QOM ARMCPU Andreas Färber
2012-02-06 23:00   ` Anthony Liguori
2012-02-06 23:05     ` Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 06/21] target-arm: Prepare model-specific class_init function Andreas Färber
2012-02-06 23:03   ` Anthony Liguori
2012-02-06 23:08     ` Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 07/21] target-arm: Overwrite reset handler for ti925t Andreas Färber
2012-02-07 17:30   ` Peter Maydell
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 08/21] target-arm: Move CPU feature flags out of CPUState Andreas Färber
2012-02-07 17:28   ` Peter Maydell
2012-02-07 17:43     ` Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 09/21] target-arm: No longer abort on unhandled CPUIDs on reset Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 10/21] target-arm: Store cp15 c0_c1 and c0_c2 in ARMCPUClass Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 11/21] target-arm: Store cp15 c0_cachetype register " Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 12/21] target-arm: Move cp15 c1_sys register to ARMCPUClass Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 13/21] target-arm: Store JTAG_ID in ARMCPUClass Andreas Färber
2012-02-07 17:47   ` Peter Maydell
2012-02-07 18:41     ` Andreas Färber
2012-02-07 19:06       ` Peter Maydell
2012-02-07 22:07         ` Andreas Färber
2012-02-07 23:30           ` Peter Maydell
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 14/21] target-arm: Move the PXA270's iwMMXt reset to pxa270_reset() Andreas Färber
2012-02-17  9:59   ` andrzej zaborowski
2012-02-17 12:03     ` Andreas Färber
2012-02-17 12:44       ` andrzej zaborowski
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 15/21] target-arm: Store VFP FPSID register in ARMCPUClass Andreas Färber
2012-02-07 17:44   ` Peter Maydell
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 16/21] target-arm: Store VFP MVFR0 and MVFR1 " Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 17/21] target-arm: Store CLIDR " Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 18/21] target-arm: Store CCSIDRs " Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 19/21] target-arm: Kill off cpu_reset_model_id() Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [PATCH RFC v3 20/21] target-arm: Prepare halted property for CPU Andreas Färber
2012-02-03  2:59 ` [Qemu-devel] [FYI v3 21/21] target-arm: Just for testing! Andreas Färber

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=1328237992-14953-5-git-send-email-afaerber@suse.de \
    --to=afaerber@suse.de \
    --cc=paul@codesourcery.com \
    --cc=peter.maydell@linaro.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.