Message ID | 1327843531-32403-5-git-send-email-afaerber@suse.de |
---|---|
State | New |
Headers | show |
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<afaerber@suse.de> > Cc: Anthony Liguori<aliguori@us.ibm.com> > --- > 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); >
Am 30.01.2012 03:14, schrieb Anthony Liguori: > On 01/29/2012 07:25 AM, Andreas Färber wrote: >> +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. Yeah, I stumbled upon that but didn't need it so far. CPUState is already taken by the old concept. In an earlier version I had used CPUCore (CPU_CORE()) but then I thought that doesn't sound right for HyperThreading (CPU -> cores -> threads). Since QEMU so far uses the term "CPU" for all of those I went with that. Any better suggestions? > BTW, if the class_size == parent.class_size you don't need to define or > specific the class. I'm sorry? You mean we don't need CPUClass yet because it doesn't add anything to ObjectClass yet? I was planning on having a reset function defined there, to be called in place of current aliased cpu_reset(). For that to work I am emptying cpu_arm_reset() step by step (cf. 9/7) until it can defer to: (*CPU_GET_CLASS(ENV_GET_OBJECT(env))->reset)(ENV_GET_OBJECT(env)); I've been thinking along the lines of: if something doesn't change at runtime then it goes into a class. Or did you mean something else? Andreas
Am 30.01.2012 03:14, schrieb Anthony Liguori: > On 01/29/2012 07:25 AM, Andreas Färber wrote: >> +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. My testing seems to indicate CPU and CPU(obj) can co-exist (GCC 4.6.2). Considered name alternatives: CPUState - already taken as #define for legacy CPU${arch}State CPUCore - fits ARM but there's socket vs. core vs. thread on x86 CPUCommon - puts the emphasis on common, which is not a noun CommonCPU - no other base class uses such a naming scheme CPUModel - it's not just a model but the state of one instance CPUFamily - same as for CPUModel CPUState would be nicest IMO, but refactoring CPUState into something else just to refactor it back to QOM CPUState feels like churn. Andreas
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), + .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);
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 <afaerber@suse.de> Cc: Anthony Liguori <aliguori@us.ibm.com> --- 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