qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH RFC 4/7] qom: Introduce CPU class


From: Anthony Liguori
Subject: Re: [Qemu-devel] [PATCH RFC 4/7] qom: Introduce CPU class
Date: Sun, 29 Jan 2012 20:14:11 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.23) Gecko/20110922 Lightning/1.0b2 Thunderbird/3.1.15

On 01/29/2012 07:25 AM, Andreas Färber wrote:
It's abstract, derived directly from TYPE_OBJECT (to avoid dependency
on MODULE_INIT_DEVICE) and for now is empty.

Place it in hw/. Have user emulators pick it up via VPATH, building it
per target since they didn't use any qdev/QOM devices so far.

Introduce processor_init() for registering, and call module init as
needed.

Signed-off-by: Andreas Färber<address@hidden>
Cc: Anthony Liguori<address@hidden>
---
  Makefile.objs      |    1 +
  Makefile.target    |    9 ++++++---
  arch_init.c        |    1 +
  bsd-user/main.c    |    1 +
  darwin-user/main.c |    1 +
  hw/cpu.c           |   27 +++++++++++++++++++++++++++
  include/qemu/cpu.h |   27 +++++++++++++++++++++++++++
  linux-user/main.c  |    1 +
  module.h           |    2 ++
  9 files changed, 67 insertions(+), 3 deletions(-)
  create mode 100644 hw/cpu.c
  create mode 100644 include/qemu/cpu.h

diff --git a/Makefile.objs b/Makefile.objs
index b942625..a4b20fa 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -189,6 +189,7 @@ user-obj-y += $(trace-obj-y)

  hw-obj-y =
  hw-obj-y += vl.o loader.o
+hw-obj-y += cpu.o
  hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
  hw-obj-y += usb-libhw.o
  hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
diff --git a/Makefile.target b/Makefile.target
index d1b7867..5d3470e 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -107,7 +107,7 @@ signal.o: QEMU_CFLAGS += $(HELPER_CFLAGS)

  ifdef CONFIG_LINUX_USER

-$(call set-vpath, 
$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR))
+$(call set-vpath, 
$(SRC_PATH)/linux-user:$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR):$(SRC_PATH)/hw)

  QEMU_CFLAGS+=-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) 
-I$(SRC_PATH)/linux-user
  obj-y = main.o syscall.o strace.o mmap.o signal.o thunk.o \
@@ -130,6 +130,7 @@ obj-m68k-y += m68k-sim.o m68k-semi.o
  $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)

  obj-y += module.o
+obj-y += cpu.o
  obj-y += $(addprefix ../qom/, $(qom-y))
  obj-y += $(addprefix ../libuser/, $(user-obj-y))
  obj-y += $(addprefix ../libdis-user/, $(libdis-y))
@@ -142,7 +143,7 @@ endif #CONFIG_LINUX_USER

  ifdef CONFIG_DARWIN_USER

-$(call set-vpath, $(SRC_PATH)/darwin-user)
+$(call set-vpath, $(SRC_PATH)/darwin-user:$(SRC_PATH)/hw)

  QEMU_CFLAGS+=-I$(SRC_PATH)/darwin-user 
-I$(SRC_PATH)/darwin-user/$(TARGET_ARCH)

@@ -159,6 +160,7 @@ obj-i386-y += ioport-user.o
  $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)

  obj-y += module.o
+obj-y += cpu.o
  obj-y += $(addprefix ../qom/, $(qom-y))
  obj-y += $(addprefix ../libuser/, $(user-obj-y))
  obj-y += $(addprefix ../libdis-user/, $(libdis-y))
@@ -171,7 +173,7 @@ endif #CONFIG_DARWIN_USER

  ifdef CONFIG_BSD_USER

-$(call set-vpath, $(SRC_PATH)/bsd-user)
+$(call set-vpath, $(SRC_PATH)/bsd-user:$(SRC_PATH)/hw)

  QEMU_CFLAGS+=-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_ARCH)

@@ -183,6 +185,7 @@ obj-i386-y += ioport-user.o
  $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS)

  obj-y += module.o
+obj-y += cpu.o
  obj-y += $(addprefix ../qom/, $(qom-y))
  obj-y += $(addprefix ../libuser/, $(user-obj-y))
  obj-y += $(addprefix ../libdis-user/, $(libdis-y))
diff --git a/arch_init.c b/arch_init.c
index 2366511..c0d5f4f 100644
--- a/arch_init.c
+++ b/arch_init.c
@@ -692,6 +692,7 @@ void do_smbios_option(const char *optarg)

  void cpudef_init(void)
  {
+    module_call_init(MODULE_INIT_CPU);
  #if defined(cpudef_setup)
      cpudef_setup(); /* parse cpu definitions in target config file */
  #endif
diff --git a/bsd-user/main.c b/bsd-user/main.c
index 2ff0361..70e1146 100644
--- a/bsd-user/main.c
+++ b/bsd-user/main.c
@@ -761,6 +761,7 @@ int main(int argc, char **argv)
      }

      cpu_model = NULL;
+    module_call_init(MODULE_INIT_CPU);
  #if defined(cpudef_setup)
      cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
  #endif
diff --git a/darwin-user/main.c b/darwin-user/main.c
index a4c630d..d065f00 100644
--- a/darwin-user/main.c
+++ b/darwin-user/main.c
@@ -751,6 +751,7 @@ int main(int argc, char **argv)
          usage();

      module_call_init(MODULE_INIT_EARLY);
+    module_call_init(MODULE_INIT_CPU);

      optind = 1;
      for(;;) {
diff --git a/hw/cpu.c b/hw/cpu.c
new file mode 100644
index 0000000..c0e9cfa
--- /dev/null
+++ b/hw/cpu.c
@@ -0,0 +1,27 @@
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * Licensed under the terms of the GNU GPL version 2
+ * or (at your option) any later version.
+ */
+
+#include "qemu/object.h"
+#include "qemu/cpu.h"
+#include "qemu-common.h"
+
+static TypeInfo cpu_type_info = {
+    .name = TYPE_CPU,
+    .parent = TYPE_OBJECT,
+    .instance_size = sizeof(CPU),


Probably want to do CPUState or something of that nature so that you can use CPU() as a dynamic_cast macro.

BTW, if the class_size == parent.class_size you don't need to define or specific the class.

Regards,

Anthony Liguori

+    .abstract = true,
+    .class_size = sizeof(CPUClass),
+};
+
+static void cpu_register_types(void)
+{
+    type_register_static(&cpu_type_info);
+}
+
+processor_init(cpu_register_types)
diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h
new file mode 100644
index 0000000..4b81f3b
--- /dev/null
+++ b/include/qemu/cpu.h
@@ -0,0 +1,27 @@
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * Licensed under the terms of the GNU GPL version 2
+ * or (at your option) any later version.
+ */
+#ifndef QEMU_CPU_H
+#define QEMU_CPU_H
+
+#include "qemu/object.h"
+
+#define TYPE_CPU "cpu"
+
+typedef struct CPUClass {
+    ObjectClass parent_class;
+} CPUClass;
+
+typedef struct CPU {
+    Object parent_obj;
+
+    /* TODO Move common CPUState here */
+} CPU;
+
+
+#endif
diff --git a/linux-user/main.c b/linux-user/main.c
index d4368b6..e727e8d 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -3304,6 +3304,7 @@ int main(int argc, char **argv, char **envp)
      }

      cpu_model = NULL;
+    module_call_init(MODULE_INIT_CPU);
  #if defined(cpudef_setup)
      cpudef_setup(); /* parse cpu definitions in target config file (TBD) */
  #endif
diff --git a/module.h b/module.h
index 567ff3a..512ba6c 100644
--- a/module.h
+++ b/module.h
@@ -26,6 +26,7 @@ typedef enum {
      MODULE_INIT_DEVICE,
      MODULE_INIT_MACHINE,
      MODULE_INIT_QAPI,
+    MODULE_INIT_CPU,
      MODULE_INIT_MAX
  } module_init_type;

@@ -34,6 +35,7 @@ typedef enum {
  #define device_init(function) module_init(function, MODULE_INIT_DEVICE)
  #define machine_init(function) module_init(function, MODULE_INIT_MACHINE)
  #define qapi_init(function) module_init(function, MODULE_INIT_QAPI)
+#define processor_init(function) module_init(function, MODULE_INIT_CPU)

  void register_module_init(void (*fn)(void), module_init_type type);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]