From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:33510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsZnK-0004Gn-L2 for qemu-devel@nongnu.org; Wed, 01 Feb 2012 08:00:22 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RsZnB-0005OC-QJ for qemu-devel@nongnu.org; Wed, 01 Feb 2012 08:00:14 -0500 Received: from cantor2.suse.de ([195.135.220.15]:37168 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RsZnB-0005LE-6k for qemu-devel@nongnu.org; Wed, 01 Feb 2012 08:00:05 -0500 From: =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Wed, 1 Feb 2012 13:57:21 +0100 Message-Id: <1328101045-10717-5-git-send-email-afaerber@suse.de> In-Reply-To: <1328101045-10717-1-git-send-email-afaerber@suse.de> References: <1328101045-10717-1-git-send-email-afaerber@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH RFC v2 4/8] qom: Introduce CPU class List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= It's abstract and derived directly from TYPE_OBJECT. Prepare a virtual reset method. 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. Signed-off-by: Andreas F=C3=A4rber Cc: Anthony Liguori --- Makefile.objs | 1 + Makefile.target | 9 +++++-- hw/cpu.c | 39 ++++++++++++++++++++++++++++++++ include/qemu/cpu.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++= ++++++ 4 files changed, 108 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 +=3D $(trace-obj-y) =20 hw-obj-y =3D hw-obj-y +=3D vl.o loader.o +hw-obj-y +=3D cpu.o hw-obj-$(CONFIG_VIRTIO) +=3D virtio-console.o hw-obj-y +=3D usb-libhw.o hw-obj-$(CONFIG_VIRTIO_PCI) +=3D 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 +=3D $(HELPER_CFLAGS) =20 ifdef CONFIG_LINUX_USER =20 -$(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) =20 QEMU_CFLAGS+=3D-I$(SRC_PATH)/linux-user/$(TARGET_ABI_DIR) -I$(SRC_PATH)/= linux-user obj-y =3D main.o syscall.o strace.o mmap.o signal.o thunk.o \ @@ -130,6 +130,7 @@ obj-m68k-y +=3D m68k-sim.o m68k-semi.o $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS) =20 obj-y +=3D module.o +obj-y +=3D cpu.o obj-y +=3D $(addprefix ../qom/, $(qom-y)) obj-y +=3D $(addprefix ../libuser/, $(user-obj-y)) obj-y +=3D $(addprefix ../libdis-user/, $(libdis-y)) @@ -142,7 +143,7 @@ endif #CONFIG_LINUX_USER =20 ifdef CONFIG_DARWIN_USER =20 -$(call set-vpath, $(SRC_PATH)/darwin-user) +$(call set-vpath, $(SRC_PATH)/darwin-user:$(SRC_PATH)/hw) =20 QEMU_CFLAGS+=3D-I$(SRC_PATH)/darwin-user -I$(SRC_PATH)/darwin-user/$(TAR= GET_ARCH) =20 @@ -159,6 +160,7 @@ obj-i386-y +=3D ioport-user.o $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS) =20 obj-y +=3D module.o +obj-y +=3D cpu.o obj-y +=3D $(addprefix ../qom/, $(qom-y)) obj-y +=3D $(addprefix ../libuser/, $(user-obj-y)) obj-y +=3D $(addprefix ../libdis-user/, $(libdis-y)) @@ -171,7 +173,7 @@ endif #CONFIG_DARWIN_USER =20 ifdef CONFIG_BSD_USER =20 -$(call set-vpath, $(SRC_PATH)/bsd-user) +$(call set-vpath, $(SRC_PATH)/bsd-user:$(SRC_PATH)/hw) =20 QEMU_CFLAGS+=3D-I$(SRC_PATH)/bsd-user -I$(SRC_PATH)/bsd-user/$(TARGET_AR= CH) =20 @@ -183,6 +185,7 @@ obj-i386-y +=3D ioport-user.o $(obj-y) $(obj-$(TARGET_BASE_ARCH)-y): $(GENERATED_HEADERS) =20 obj-y +=3D module.o +obj-y +=3D cpu.o obj-y +=3D $(addprefix ../qom/, $(qom-y)) obj-y +=3D $(addprefix ../libuser/, $(user-obj-y)) obj-y +=3D $(addprefix ../libdis-user/, $(libdis-y)) diff --git a/hw/cpu.c b/hw/cpu.c new file mode 100644 index 0000000..1502fee --- /dev/null +++ b/hw/cpu.c @@ -0,0 +1,39 @@ +/* + * 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/cpu.h" +#include "qemu-common.h" + +void cpu_do_reset(CPU *cpu) +{ + CPUClass *klass =3D CPU_GET_CLASS(cpu); + + if (klass->reset !=3D NULL) { + (*klass->reset)(cpu); + } +} + +void cpu_common_reset(CPU *cpu) +{ +} + +static TypeInfo cpu_type_info =3D { + .name =3D TYPE_CPU, + .parent =3D TYPE_OBJECT, + .instance_size =3D sizeof(CPU), + .abstract =3D true, + .class_size =3D sizeof(CPUClass), +}; + +static void cpu_register_types(void) +{ + type_register_static(&cpu_type_info); +} + +type_init(cpu_register_types) diff --git a/include/qemu/cpu.h b/include/qemu/cpu.h new file mode 100644 index 0000000..cccf4a5 --- /dev/null +++ b/include/qemu/cpu.h @@ -0,0 +1,62 @@ +/* + * 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" + +#define CPU(obj) OBJECT_CHECK(CPU, (obj), TYPE_CPU) +#define CPU_CLASS(class) OBJECT_CLASS_CHECK(CPUClass, (class), TYPE_CPU) +#define CPU_GET_CLASS(obj) OBJECT_GET_CLASS(CPUClass, (obj), TYPE_CPU) + +typedef struct CPU CPU; + +/** + * CPUClass: + * @reset: Callback to reset the #CPU to its initial state. + * + * Represents a CPU family or model. + */ +typedef struct CPUClass { + ObjectClass parent_class; + + void (*reset)(CPU *cpu); +} CPUClass; + +/** + * CPU: + * + * State of one CPU core or thread. + */ +struct CPU { + Object parent_obj; + + /* TODO Move common fields from CPUState here. */ +}; + + +/* TODO Rename to cpu_reset once all CPUState is converted to QOM. */ +/** + * cpu_do_reset: + * @cpu: The CPU whose state is to be reset. + */ +void cpu_do_reset(CPU *cpu); + +/** + * cpu_common_reset: + * @cpu: The CPU whose common state is to be reset. + * + * To be used by derived classes. + */ +void cpu_common_reset(CPU *cpu); + + +#endif --=20 1.7.7