Skip to contentSkip to conversation

cpu: make a child of DeviceState

PATCH In review Anthony Liguori 3 participants 9 messages Aug 10, 2012 – Aug 15, 2012

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover cpu: make a child of DeviceState

This is just a rebase of this series that I posted back in June.

Andreas had a different approach involving a #define but I think doing a full split ends up being nicer. For instance, the recently added thread information is only relevant to cpu-softmmu so we can limit that entirely to cpu-softmmu.

#1 lore raw

PATCH 1/2 qdev: split up header so it can be used in cpu.h

Header file dependency is a frickin' nightmare right now. cpu.h tends to get included in our 'include everything' header files but qdev also needs to include those headers mainly for qdev-properties since it knows about CharDriverState and friends.

We can solve this for now by splitting out qdev.h along the same lines that we previously split the C file. Then cpu.h just needs to include qdev-core.h

---
 hw/irq.h             |    2 +
 hw/mc146818rtc.c     |    1 +
 hw/qdev-addr.c       |    1 +
 hw/qdev-core.h       |  240 ++++++++++++++++++++++++++++++++
 hw/qdev-monitor.h    |   16 ++
 hw/qdev-properties.c |    1 +
 hw/qdev-properties.h |  128 +++++++++++++++++
 hw/qdev.c            |    1 +
 hw/qdev.h            |  371 +-------------------------------------------------
 9 files changed, 394 insertions(+), 367 deletions(-)
 create mode 100644 hw/qdev-core.h
 create mode 100644 hw/qdev-monitor.h
 create mode 100644 hw/qdev-properties.h
hw/irq.h +2 -0
index 56c55f0..1339a3a 100644
@@ -3,6 +3,8 @@
 
 /* Generic IRQ/GPIO pin infrastructure.  */
 
+typedef struct IRQState *qemu_irq;
+
 typedef void (*qemu_irq_handler)(void *opaque, int n, int level);
 
 void qemu_set_irq(qemu_irq irq, int level);
hw/mc146818rtc.c +1 -0
index 3777f85..3780617 100644
@@ -25,6 +25,7 @@
 #include "qemu-timer.h"
 #include "sysemu.h"
 #include "mc146818rtc.h"
+#include "qapi/qapi-visit-core.h"
 
 #ifdef TARGET_I386
 #include "apic.h"
hw/qdev-addr.c +1 -0
index b711b6b..5b5d38f 100644
@@ -1,6 +1,7 @@
 #include "qdev.h"
 #include "qdev-addr.h"
 #include "targphys.h"
+#include "qapi/qapi-visit-core.h"
 
 /* --- target physical address --- */
 
hw/qdev-core.h new file +240 -0

240 lines not on this page · raw message

hw/qdev-monitor.h new file +16 -0
new file mode 100644
index 0000000..220ceba
@@ -0,0 +1,16 @@
+#ifndef QEMU_QDEV_MONITOR_H
+#define QEMU_QDEV_MONITOR_H
+
+#include "qdev-core.h"
+#include "monitor.h"
+
+/*** monitor commands ***/
+
+void do_info_qtree(Monitor *mon);
+void do_info_qdm(Monitor *mon);
+int do_device_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int do_device_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int qdev_device_help(QemuOpts *opts);
+DeviceState *qdev_device_add(QemuOpts *opts);
+
+#endif
hw/qdev-properties.c +1 -0
index 8aca0d4..81d901c 100644
@@ -4,6 +4,7 @@
 #include "blockdev.h"
 #include "hw/block-common.h"
 #include "net/hub.h"
+#include "qapi/qapi-visit-core.h"
 
 void *qdev_get_prop_ptr(DeviceState *dev, Property *prop)
 {
hw/qdev-properties.h new file +128 -0

128 lines not on this page · raw message

hw/qdev.c +1 -0
index b5b74b9..36c3e4b 100644
@@ -29,6 +29,7 @@
 #include "qdev.h"
 #include "sysemu.h"
 #include "error.h"
+#include "qapi/qapi-visit-core.h"
 
 int qdev_hotplug = 0;
 static bool qdev_hot_added = false;
hw/qdev.h +4 -367

376 lines not on this page · raw message

Signature · 1 line
1.7.5.4
Reviewed-by on v1 1/2
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] qdev: split up header so it can be used in cpu.h

Am 10.08.2012 19:00, schrieb Anthony Liguori:

Quoted 10 lines

Header file dependency is a frickin' nightmare right now. cpu.h tends to get included in our 'include everything' header files but qdev also needs to include those headers mainly for qdev-properties since it knows about CharDriverState and friends.

We can solve this for now by splitting out qdev.h along the same lines that we previously split the C file. Then cpu.h just needs to include qdev-core.h

Quickly looked through and qdev.h split looks fine.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#3 lore raw

PATCH 2/2 cpu: for cpu-user and cpu-softmmu and make cpu-softmmu a child of DeviceState

In reply to Anthony Liguori

The line between linux-user and softmmu is not very well defined right now. linux-user really don't want to include devices and making CpuState a child of DeviceState would require pulling lots of stuff into linux-user.

To solve this, we simply fork cpu-user and cpu-softmmu letting them evolve independently.

We also need to push a qdev_init_nofail() into all callers of cpu_init(). This is needed eventually anyway so might as well do this now.

---
 Makefile.objs                 |    6 ---
 hw/armv7m.c                   |    1 +
 hw/axis_dev88.c               |    1 +
 hw/exynos4210.c               |    1 +
 hw/highbank.c                 |    1 +
 hw/integratorcp.c             |    1 +
 hw/leon3.c                    |    1 +
 hw/lm32_boards.c              |    2 +
 hw/milkymist.c                |    1 +
 hw/mips_fulong2e.c            |    1 +
 hw/mips_jazz.c                |    1 +
 hw/mips_malta.c               |    1 +
 hw/mips_mipssim.c             |    1 +
 hw/mips_r4k.c                 |    1 +
 hw/musicpal.c                 |    1 +
 hw/omap1.c                    |    1 +
 hw/omap2.c                    |    1 +
 hw/pc.c                       |    1 +
 hw/petalogix_ml605_mmu.c      |    1 +
 hw/petalogix_s3adsp1800_mmu.c |    1 +
 hw/ppc440_bamboo.c            |    1 +
 hw/ppc4xx_devs.c              |    1 +
 hw/ppc_newworld.c             |    1 +
 hw/ppc_oldworld.c             |    1 +
 hw/ppc_prep.c                 |    1 +
 hw/ppce500_mpc8544ds.c        |    1 +
 hw/pxa2xx.c                   |    1 +
 hw/r2d.c                      |    1 +
 hw/realview.c                 |    1 +
 hw/s390-virtio.c              |    1 +
 hw/spapr.c                    |    1 +
 hw/strongarm.c                |    1 +
 hw/sun4m.c                    |    1 +
 hw/sun4u.c                    |    1 +
 hw/versatilepb.c              |    1 +
 hw/vexpress.c                 |    2 +
 hw/virtex_ml507.c             |    1 +
 hw/xen_machine_pv.c           |    1 +
 hw/xilinx_zynq.c              |    1 +
 hw/xtensa_lx60.c              |    1 +
 hw/xtensa_sim.c               |    1 +
 include/qemu/cpu-softmmu.h    |   82 +++++++++++++++++++++++++++++++++++++++
 include/qemu/cpu-user.h       |   75 ++++++++++++++++++++++++++++++++++++
 include/qemu/cpu.h            |   85 ++---------------------------------------
 qemu-common.h                 |    3 +-
 qom/Makefile.objs             |    5 +-
 qom/cpu-softmmu.c             |   66 +++++++++++++++++++++++++++++++
 qom/cpu-user.c                |   70 +++++++++++++++++++++++++++++++++
 48 files changed, 343 insertions(+), 91 deletions(-)
 create mode 100644 include/qemu/cpu-softmmu.h
 create mode 100644 include/qemu/cpu-user.h
 create mode 100644 qom/cpu-softmmu.c
 create mode 100644 qom/cpu-user.c
Makefile.objs +0 -6
index 5ebbcfa..f285926 100644
@@ -12,12 +12,6 @@ qobject-obj-y += qerror.o error.o qemu-error.o
 universal-obj-y += $(qobject-obj-y)
 
 #######################################################################
-# QOM
-qom-obj-y = qom/
-
-universal-obj-y += $(qom-obj-y)
-
-#######################################################################
 # oslib-obj-y is code depending on the OS (win32 vs posix)
 oslib-obj-y = osdep.o
 oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o
hw/armv7m.c +1 -0
index 8cec78d..2e8fa06 100644
@@ -188,6 +188,7 @@ qemu_irq *armv7m_init(MemoryRegion *address_space_mem,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
 #if 0
hw/axis_dev88.c +1 -0
index eab6327..f34fe8a 100644
@@ -265,6 +265,7 @@ void axisdev88_init (ram_addr_t ram_size,
         cpu_model = "crisv32";
     }
     cpu = cpu_cris_init(cpu_model);
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     /* allocate RAM */
hw/exynos4210.c +1 -0
index 00d4db8..aca8738 100644
@@ -122,6 +122,7 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
             fprintf(stderr, "Unable to find CPU %d definition\n", n);
             exit(1);
         }
+        qdev_init_nofail(DEVICE(s->cpu[n]));
 
         /* Create PIC controller for each processor instance */
         irqp = arm_pic_init_cpu(s->cpu[n]);
hw/highbank.c +1 -0
index 11aa131..8f66f70 100644
@@ -214,6 +214,7 @@ static void highbank_init(ram_addr_t ram_size,
             fprintf(stderr, "Unable to find CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
 
         /* This will become a QOM property eventually */
         cpu->reset_cbar = GIC_BASE_ADDR;
hw/integratorcp.c +1 -0
index d0e2e90..e19d745 100644
@@ -460,6 +460,7 @@ static void integratorcp_init(ram_addr_t ram_size,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
 
     memory_region_init_ram(ram, "integrator.ram", ram_size);
     vmstate_register_ram_global(ram);
hw/leon3.c +1 -0
index 878d3aa..6d79631 100644
@@ -123,6 +123,7 @@ static void leon3_generic_hw_init(ram_addr_t  ram_size,
         fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     cpu_sparc_set_id(env, 0);
hw/lm32_boards.c +2 -0
index b76d800..319580b 100644
@@ -103,6 +103,7 @@ static void lm32_evr_init(ram_addr_t ram_size_not_used,
         cpu_model = "lm32-full";
     }
     cpu = cpu_lm32_init(cpu_model);
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
     reset_info->cpu = cpu;
 
@@ -200,6 +201,7 @@ static void lm32_uclinux_init(ram_addr_t ram_size_not_used,
         cpu_model = "lm32-full";
     }
     cpu = cpu_lm32_init(cpu_model);
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
     reset_info->cpu = cpu;
 
hw/milkymist.c +1 -0
index 2e7235b..959495c 100644
@@ -107,6 +107,7 @@ milkymist_init(ram_addr_t ram_size_not_used,
         cpu_model = "lm32-full";
     }
     cpu = cpu_lm32_init(cpu_model);
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
     reset_info->cpu = cpu;
 
hw/mips_fulong2e.c +1 -0
index 38e4b86..a8a28a0 100644
@@ -285,6 +285,7 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     qemu_register_reset(main_cpu_reset, cpu);
hw/mips_jazz.c +1 -0
index db927f1..c0eee7c 100644
@@ -147,6 +147,7 @@ static void mips_jazz_init(MemoryRegion *address_space,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
     qemu_register_reset(main_cpu_reset, cpu);
 
hw/mips_malta.c +1 -0
index 351c88e..8c98265 100644
@@ -833,6 +833,7 @@ void mips_malta_init (ram_addr_t ram_size,
             fprintf(stderr, "Unable to find CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         env = &cpu->env;
 
         /* Init internal devices */
hw/mips_mipssim.c +1 -0
index 830f635..d164203 100644
@@ -158,6 +158,7 @@ mips_mipssim_init (ram_addr_t ram_size,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     reset_info = g_malloc0(sizeof(ResetData));
hw/mips_r4k.c +1 -0
index 967a76e..6ae690a 100644
@@ -185,6 +185,7 @@ void mips_r4k_init (ram_addr_t ram_size,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     reset_info = g_malloc0(sizeof(ResetData));
hw/musicpal.c +1 -0
index ad725b5..c2f42f2 100644
@@ -1538,6 +1538,7 @@ static void musicpal_init(ram_addr_t ram_size,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     cpu_pic = arm_pic_init_cpu(cpu);
 
     /* For now we use a fixed - the original - RAM size */
hw/omap1.c +1 -0
index ad60cc4..c20cfda 100644
@@ -3836,6 +3836,7 @@ struct omap_mpu_state_s *omap310_mpu_init(MemoryRegion *system_memory,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(s->cpu));
     s->sdram_size = sdram_size;
     s->sram_size = OMAP15XX_SRAM_SIZE;
 
hw/omap2.c +1 -0
index 4278dd1..aee94a3 100644
@@ -2258,6 +2258,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(MemoryRegion *sysmem,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(s->cpu));
     s->sdram_size = sdram_size;
     s->sram_size = OMAP242X_SRAM_SIZE;
 
hw/pc.c +1 -0
index 81c391c..b1f163e 100644
@@ -915,6 +915,7 @@ static X86CPU *pc_new_cpu(const char *cpu_model)
         fprintf(stderr, "Unable to find x86 CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
     if ((env->cpuid_features & CPUID_APIC) || smp_cpus > 1) {
         env->apic_state = apic_init(env, env->cpuid_apic_id);
hw/petalogix_ml605_mmu.c +1 -0
index 6a7d0c0..173fb54 100644
@@ -91,6 +91,7 @@ petalogix_ml605_init(ram_addr_t ram_size,
         cpu_model = "microblaze";
     }
     cpu = cpu_mb_init(cpu_model);
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     /* Attach emulated BRAM through the LMB.  */
hw/petalogix_s3adsp1800_mmu.c +1 -0
index 2cf6882..1984187 100644
@@ -79,6 +79,7 @@ petalogix_s3adsp1800_init(ram_addr_t ram_size,
         cpu_model = "microblaze";
     }
     cpu = cpu_mb_init(cpu_model);
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     /* Attach emulated BRAM through the LMB.  */
hw/ppc440_bamboo.c +1 -0
index 0dd4dab..cf67b06 100644
@@ -192,6 +192,7 @@ static void bamboo_init(ram_addr_t ram_size,
         fprintf(stderr, "Unable to initialize CPU!\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     qemu_register_reset(main_cpu_reset, cpu);
hw/ppc4xx_devs.c +1 -0
index 41163e6..34f4172 100644
@@ -61,6 +61,7 @@ CPUPPCState *ppc4xx_init (const char *cpu_model,
                 cpu_model);
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     cpu_clk->cb = NULL; /* We don't care about CPU clock frequency changes */
hw/ppc_newworld.c +1 -0
index 4e2a6e6..b1d05fd 100644
@@ -172,6 +172,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
             fprintf(stderr, "Unable to find PowerPC CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         env = &cpu->env;
 
         /* Set time-base frequency to 100 Mhz */
hw/ppc_oldworld.c +1 -0
index f2c6908..955e961 100644
@@ -110,6 +110,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
             fprintf(stderr, "Unable to find PowerPC CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         env = &cpu->env;
 
         /* Set time-base frequency to 16.6 Mhz */
hw/ppc_prep.c +1 -0
index be2b268..649df80 100644
@@ -493,6 +493,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
             fprintf(stderr, "Unable to find PowerPC CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         env = &cpu->env;
 
         if (env->flags & POWERPC_FLAG_RTC_CLK) {
hw/ppce500_mpc8544ds.c +1 -0
index 8b9fd83..130764f 100644
@@ -458,6 +458,7 @@ static void mpc8544ds_init(ram_addr_t ram_size,
             fprintf(stderr, "Unable to initialize CPU!\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         env = &cpu->env;
 
         if (!firstenv) {
hw/pxa2xx.c +1 -0
index d5f1420..3a5e79a 100644
@@ -2021,6 +2021,7 @@ PXA2xxState *pxa270_init(MemoryRegion *address_space,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(s->cpu));
     s->reset = qemu_allocate_irqs(pxa2xx_reset, s, 1)[0];
 
     /* SDRAM & Internal Memory Storage */
hw/r2d.c +1 -0
index 0f16e81..d820241 100644
@@ -245,6 +245,7 @@ static void r2d_init(ram_addr_t ram_size,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     reset_info = g_malloc0(sizeof(ResetData));
hw/realview.c +1 -0
index 19db4d0..469db99 100644
@@ -94,6 +94,7 @@ static void realview_init(ram_addr_t ram_size,
             fprintf(stderr, "Unable to find CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         irqp = arm_pic_init_cpu(cpu);
         cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
     }
hw/s390-virtio.c +1 -0
index 47eed35..9566aab 100644
@@ -213,6 +213,7 @@ static void s390_init(ram_addr_t my_ram_size,
         CPUS390XState *tmp_env;
 
         cpu = cpu_s390x_init(cpu_model);
+        qdev_init_nofail(DEVICE(cpu));
         tmp_env = &cpu->env;
         if (!env) {
             env = tmp_env;
hw/spapr.c +1 -0
index 81c9343..660246e 100644
@@ -612,6 +612,7 @@ static void ppc_spapr_init(ram_addr_t ram_size,
             fprintf(stderr, "Unable to find PowerPC CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         env = &cpu->env;
 
         /* Set time-base frequency to 512 MHz */
hw/strongarm.c +1 -0
index 7150eeb..ccc3ec6 100644
@@ -1569,6 +1569,7 @@ StrongARMState *sa1110_init(MemoryRegion *sysmem,
         error_report("Unable to find CPU definition");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(s->cpu));
 
     memory_region_init_ram(&s->sdram, "strongarm.sdram", sdram_size);
     vmstate_register_ram_global(&s->sdram);
hw/sun4m.c +1 -0
index 0f909b5..ea2405d 100644
@@ -819,6 +819,7 @@ static void cpu_devinit(const char *cpu_model, unsigned int id,
         fprintf(stderr, "qemu: Unable to find Sparc CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     cpu_sparc_set_id(env, id);
hw/sun4u.c +1 -0
index 137a7c6..48ef0a3 100644
@@ -770,6 +770,7 @@ static SPARCCPU *cpu_devinit(const char *cpu_model, const struct hwdef *hwdef)
         fprintf(stderr, "Unable to find Sparc CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     env->tick = cpu_timer_create("tick", env, tick_irq,
hw/versatilepb.c +1 -0
index 4fd5d9b..7c113a2 100644
@@ -197,6 +197,7 @@ static void versatile_init(ram_addr_t ram_size,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     memory_region_init_ram(ram, "versatile.ram", ram_size);
     vmstate_register_ram_global(ram);
     /* ??? RAM should repeat to fill physical memory space.  */
hw/vexpress.c +2 -0
index b615844..8a30696 100644
@@ -181,6 +181,7 @@ static void a9_daughterboard_init(const VEDBoardInfo *daughterboard,
             fprintf(stderr, "Unable to find CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         irqp = arm_pic_init_cpu(cpu);
         cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
     }
@@ -280,6 +281,7 @@ static void a15_daughterboard_init(const VEDBoardInfo *daughterboard,
             fprintf(stderr, "Unable to find CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         irqp = arm_pic_init_cpu(cpu);
         cpu_irq[n] = irqp[ARM_PIC_CPU_IRQ];
     }
hw/virtex_ml507.c +1 -0
index 79bc0d1..c356400 100644
@@ -92,6 +92,7 @@ static PowerPCCPU *ppc440_init_xilinx(ram_addr_t *ram_size,
         fprintf(stderr, "Unable to initialize CPU!\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
 
     ppc_booke_timers_init(env, sysclk, 0/* no flags */);
hw/xen_machine_pv.c +1 -0
index 4b72aa7..4017f43 100644
@@ -50,6 +50,7 @@ static void xen_init_pv(ram_addr_t ram_size,
 #endif
     }
     cpu = cpu_x86_init(cpu_model);
+    qdev_init_nofail(DEVICE(cpu));
     env = &cpu->env;
     env->halted = 1;
 
hw/xilinx_zynq.c +1 -0
index 7e6c273..537351c 100644
@@ -71,6 +71,7 @@ static void zynq_init(ram_addr_t ram_size, const char *boot_device,
         fprintf(stderr, "Unable to find CPU definition\n");
         exit(1);
     }
+    qdev_init_nofail(DEVICE(cpu));
     irqp = arm_pic_init_cpu(cpu);
     cpu_irq = irqp[ARM_PIC_CPU_IRQ];
 
hw/xtensa_lx60.c +1 -0
index 3653f65..9bde624 100644
@@ -182,6 +182,7 @@ static void lx_init(const LxBoardDesc *board,
             fprintf(stderr, "Unable to find CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         env = &cpu->env;
 
         env->sregs[PRID] = n;
hw/xtensa_sim.c +1 -0
index 831460b..6eb8ea1 100644
@@ -60,6 +60,7 @@ static void sim_init(ram_addr_t ram_size,
             fprintf(stderr, "Unable to find CPU definition\n");
             exit(1);
         }
+        qdev_init_nofail(DEVICE(cpu));
         env = &cpu->env;
 
         env->sregs[PRID] = n;
include/qemu/cpu-softmmu.h new file +82 -0

82 lines not on this page · raw message

include/qemu/cpu-user.h new file +75 -0

75 lines not on this page · raw message

include/qemu/cpu.h +4 -81

86 lines not on this page · raw message

qemu-common.h +2 -1
index f9deca6..47a3aab 100644
@@ -270,7 +270,6 @@ typedef struct PCIEPort PCIEPort;
 typedef struct PCIESlot PCIESlot;
 typedef struct MSIMessage MSIMessage;
 typedef struct SerialState SerialState;
-typedef struct IRQState *qemu_irq;
 typedef struct PCMCIACardState PCMCIACardState;
 typedef struct MouseTransformInfo MouseTransformInfo;
 typedef struct uWireSlave uWireSlave;
@@ -281,6 +280,8 @@ typedef struct VirtIODevice VirtIODevice;
 typedef struct QEMUSGList QEMUSGList;
 typedef struct SHPCDevice SHPCDevice;
 
+#include "hw/irq.h"
+
 typedef uint64_t pcibus_t;
 
 typedef enum LostTickPolicy {
qom/Makefile.objs +2 -3
index 5ef060a..a24fadf 100644
@@ -1,4 +1,3 @@
 qom-obj-y = object.o container.o qom-qobject.o
-qom-obj-twice-y = cpu.o
-common-obj-y = $(qom-obj-twice-y)
-user-obj-y = $(qom-obj-twice-y)
+common-obj-y += $(qom-obj-y) cpu-softmmu.o
+user-obj-y += $(qom-obj-y) cpu-user.o
qom/cpu-softmmu.c new file +66 -0

66 lines not on this page · raw message

qom/cpu-user.c new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
1.7.5.4
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] cpu: for cpu-user and cpu-softmmu and make cpu-softmmu a child of DeviceState

Quoted 12 lines · Anthony Liguori

The line between linux-user and softmmu is not very well defined right now. linux-user really don't want to include devices and making CpuState a child of DeviceState would require pulling lots of stuff into linux-user.

To solve this, we simply fork cpu-user and cpu-softmmu letting them evolve independently.

We also need to push a qdev_init_nofail() into all callers of cpu_init(). This is needed eventually anyway so might as well do this now.

---

[...]

Quoted 2 lines
qom/cpu-user.c new file +0 -0

[...]

qom/cpu-user.c line 58

Quoted 7 lines
qom/cpu-user.c new file +7 -0
+static TypeInfo cpu_type_info = {
+    .name = TYPE_CPU,
+#ifdef CONFIG_USER_ONLY
+    .parent = TYPE_OBJECT,
+#else
+    .parent = TYPE_DEVICE,
+#endif

Is this #ifdef supposed to be here?

Quoted 15 lines
qom/cpu-user.c new file +12 -0
+    .instance_size = sizeof(CPUState),
+    .abstract = true,
+    .class_size = sizeof(CPUClass),
+    .class_init = cpu_class_init,
+};
+
+static void cpu_register_types(void)
+{
+    type_register_static(&cpu_type_info);
+}
+
+type_init(cpu_register_types)
Signature · 1 line
1.7.5.4
Signature · 1 line
Eduardo
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] cpu: for cpu-user and cpu-softmmu and make cpu-softmmu a child of DeviceState

Quoted 17 lines · Eduardo Habkost
Quoted 12 lines · Anthony Liguori

The line between linux-user and softmmu is not very well defined right now. linux-user really don't want to include devices and making CpuState a child of DeviceState would require pulling lots of stuff into linux-user.

To solve this, we simply fork cpu-user and cpu-softmmu letting them evolve independently.

We also need to push a qdev_init_nofail() into all callers of cpu_init(). This is needed eventually anyway so might as well do this now.

---

[...]

Quoted 2 lines
qom/cpu-user.c new file +0 -0

[...]

Quoted 9 lines

qom/cpu-user.c line 58

Quoted 7 lines
qom/cpu-user.c new file +7 -0
+static TypeInfo cpu_type_info = {
+    .name = TYPE_CPU,
+#ifdef CONFIG_USER_ONLY
+    .parent = TYPE_OBJECT,
+#else
+    .parent = TYPE_DEVICE,
+#endif

Is this #ifdef supposed to be here?

Nope. Thanks.

Regards,

Anthony Liguori

Quoted 19 lines
Quoted 16 lines
qom/cpu-user.c new file +12 -0
+    .instance_size = sizeof(CPUState),
+    .abstract = true,
+    .class_size = sizeof(CPUClass),
+    .class_init = cpu_class_init,
+};
+
+static void cpu_register_types(void)
+{
+    type_register_static(&cpu_type_info);
+}
+
+type_init(cpu_register_types)
Signature · 1 line
1.7.5.4
Signature · 1 line
Eduardo
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] cpu: for cpu-user and cpu-softmmu and make cpu-softmmu a child of DeviceState

In reply to Anthony Liguori

Am 10.08.2012 19:00, schrieb Anthony Liguori:

Quoted 6 lines

The line between linux-user and softmmu is not very well defined right now. linux-user really don't want to include devices and making CpuState a child of DeviceState would require pulling lots of stuff into linux-user.

To solve this, we simply fork cpu-user and cpu-softmmu letting them evolve independently.

In the KVM call discussion there was no consensus that such independent evolution is actually desirable.

For example, moving forward with eliminating the CPU_COMMON mess this will mean duplicating the implementation of cpu_common_reset() - currently empty but in need of at least some zero'ing in the future. My fear is that such duplication will lead to fixes getting applied to the softmmu version only and contributors forgetting / being unaware that there is a second place to apply the same change.

Putting different TypeInfos into seperate source files is fine with me, but I would rather have shared implementations with an #ifdef than duplicating things.
By comparison, forgetting to add a new field in either struct would lead to a compilation failure, getting noticed, so that seems doable.

Quoted 2 lines

We also need to push a qdev_init_nofail() into all callers of cpu_init(). This is needed eventually anyway so might as well do this now.

Patch would be better readable doing that as a follow-up...

Quoted 73 lines
---
 Makefile.objs                 |    6 ---
 hw/armv7m.c                   |    1 +
 hw/axis_dev88.c               |    1 +
 hw/exynos4210.c               |    1 +
 hw/highbank.c                 |    1 +
 hw/integratorcp.c             |    1 +
 hw/leon3.c                    |    1 +
 hw/lm32_boards.c              |    2 +
 hw/milkymist.c                |    1 +
 hw/mips_fulong2e.c            |    1 +
 hw/mips_jazz.c                |    1 +
 hw/mips_malta.c               |    1 +
 hw/mips_mipssim.c             |    1 +
 hw/mips_r4k.c                 |    1 +
 hw/musicpal.c                 |    1 +
 hw/omap1.c                    |    1 +
 hw/omap2.c                    |    1 +
 hw/pc.c                       |    1 +
 hw/petalogix_ml605_mmu.c      |    1 +
 hw/petalogix_s3adsp1800_mmu.c |    1 +
 hw/ppc440_bamboo.c            |    1 +
 hw/ppc4xx_devs.c              |    1 +
 hw/ppc_newworld.c             |    1 +
 hw/ppc_oldworld.c             |    1 +
 hw/ppc_prep.c                 |    1 +
 hw/ppce500_mpc8544ds.c        |    1 +
 hw/pxa2xx.c                   |    1 +
 hw/r2d.c                      |    1 +
 hw/realview.c                 |    1 +
 hw/s390-virtio.c              |    1 +
 hw/spapr.c                    |    1 +
 hw/strongarm.c                |    1 +
 hw/sun4m.c                    |    1 +
 hw/sun4u.c                    |    1 +
 hw/versatilepb.c              |    1 +
 hw/vexpress.c                 |    2 +
 hw/virtex_ml507.c             |    1 +
 hw/xen_machine_pv.c           |    1 +
 hw/xilinx_zynq.c              |    1 +
 hw/xtensa_lx60.c              |    1 +
 hw/xtensa_sim.c               |    1 +
 include/qemu/cpu-softmmu.h    |   82 +++++++++++++++++++++++++++++++++++++++
 include/qemu/cpu-user.h       |   75 ++++++++++++++++++++++++++++++++++++
 include/qemu/cpu.h            |   85 ++---------------------------------------
 qemu-common.h                 |    3 +-
 qom/Makefile.objs             |    5 +-
 qom/cpu-softmmu.c             |   66 +++++++++++++++++++++++++++++++
 qom/cpu-user.c                |   70 +++++++++++++++++++++++++++++++++
 48 files changed, 343 insertions(+), 91 deletions(-)
 create mode 100644 include/qemu/cpu-softmmu.h
 create mode 100644 include/qemu/cpu-user.h
 create mode 100644 qom/cpu-softmmu.c
 create mode 100644 qom/cpu-user.c
Makefile.objs +0 -6
index 5ebbcfa..f285926 100644
@@ -12,12 +12,6 @@ qobject-obj-y += qerror.o error.o qemu-error.o
 universal-obj-y += $(qobject-obj-y)
 
 #######################################################################
-# QOM
-qom-obj-y = qom/
-
-universal-obj-y += $(qom-obj-y)
-
-#######################################################################
 # oslib-obj-y is code depending on the OS (win32 vs posix)
 oslib-obj-y = osdep.o
 oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o

[...]

Quoted 183 lines
include/qemu/cpu-softmmu.h new file +82 -0
new file mode 100644
index 0000000..4f7b602
@@ -0,0 +1,82 @@
+/*
+ * QEMU CPU model
+ *
+ * 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/gpl-2.0.html>
+ */
+#ifndef QEMU_CPU_H
+#define QEMU_CPU_H
+
+#include "hw/qdev-core.h"
+#include "qemu-thread.h"
+
+/**
+ * SECTION:cpu
+ * @section_id: QEMU-cpu
+ * @title: CPU Class
+ * @short_description: Base class for all CPUs
+ */
+
+#define TYPE_CPU "cpu"
+
+#define CPU(obj) OBJECT_CHECK(CPUState, (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 CPUState CPUState;
+
+/**
+ * CPUClass:
+ * @reset: Callback to reset the #CPUState to its initial state.
+ *
+ * Represents a CPU family or model.
+ */
+typedef struct CPUClass {
+    /*< private >*/
+    DeviceClass parent_class;
+    /*< public >*/
+
+    void (*reset)(CPUState *cpu);
+} CPUClass;
+
+/**
+ * CPUState:
+ *
+ * State of one CPU core or thread.
+ */
+struct CPUState {
+    /*< private >*/
+    DeviceState parent_obj;
+    /*< public >*/
+
+    struct QemuThread *thread;
+#ifdef _WIN32
+   HANDLE hThread;
+#endif
+    bool thread_kicked;
+
+    /* TODO Move common fields from CPUArchState here. */
+};
+
+
+/**
+ * cpu_reset:
+ * @cpu: The CPU whose state is to be reset.
+ */
+void cpu_reset(CPUState *cpu);
+
+
+#endif
include/qemu/cpu-user.h new file +75 -0
new file mode 100644
index 0000000..78b65b3
@@ -0,0 +1,75 @@
+/*
+ * QEMU CPU model
+ *
+ * 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/gpl-2.0.html>
+ */
+#ifndef QEMU_CPU_H
+#define QEMU_CPU_H
+
+#include "qemu/object.h"
+
+/**
+ * SECTION:cpu
+ * @section_id: QEMU-cpu
+ * @title: CPU Class
+ * @short_description: Base class for all CPUs
+ */
+
+#define TYPE_CPU "cpu"
+
+#define CPU(obj) OBJECT_CHECK(CPUState, (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 CPUState CPUState;
+
+/**
+ * CPUClass:
+ * @reset: Callback to reset the #CPUState to its initial state.
+ *
+ * Represents a CPU family or model.
+ */
+typedef struct CPUClass {
+    /*< private >*/
+    ObjectClass parent_class;
+    /*< public >*/
+
+    void (*reset)(CPUState *cpu);
+} CPUClass;
+
+/**
+ * CPUState:
+ *
+ * State of one CPU core or thread.
+ */
+struct CPUState {
+    /*< private >*/
+    Object parent_obj;
+    /*< public >*/
+
+    /* TODO Move common fields from CPUArchState here. */
+};
+
+
+/**
+ * cpu_reset:
+ * @cpu: The CPU whose state is to be reset.
+ */
+void cpu_reset(CPUState *cpu);
+
+
+#endif
include/qemu/cpu.h +0 -9
index ad706a6..862988a 100644
@@ -1,82 +1,5 @@
-/*
- * QEMU CPU model
- *
- * 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.

include/qemu/cpu.h line 19

Quoted 10 lines
include/qemu/cpu.h +0 -10
- *
- * 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/gpl-2.0.html>
- */

If we empty this file, suggest to use either a GPLv2+ or MIT header to clarify licensing.

Quoted 50 lines
include/qemu/cpu.h +0 -50
-#ifndef QEMU_CPU_H
-#define QEMU_CPU_H
-
-#include "qemu/object.h"
-#include "qemu-thread.h"
-
-/**
- * SECTION:cpu
- * @section_id: QEMU-cpu
- * @title: CPU Class
- * @short_description: Base class for all CPUs
- */
-
-#define TYPE_CPU "cpu"
-
-#define CPU(obj) OBJECT_CHECK(CPUState, (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 CPUState CPUState;
-
-/**
- * CPUClass:
- * @reset: Callback to reset the #CPUState to its initial state.
- *
- * Represents a CPU family or model.
- */
-typedef struct CPUClass {
-    /*< private >*/
-    ObjectClass parent_class;
-    /*< public >*/
-
-    void (*reset)(CPUState *cpu);
-} CPUClass;
-
-/**
- * CPUState:
- *
- * State of one CPU core or thread.
- */
-struct CPUState {
-    /*< private >*/
-    Object parent_obj;
-    /*< public >*/
-
-    struct QemuThread *thread;
-#ifdef _WIN32
-    HANDLE hThread;
-#endif
-    bool thread_kicked;

include/qemu/cpu.h line 79

Quoted 10 lines
include/qemu/cpu.h +0 -10
-
-    /* TODO Move common fields from CPUArchState here. */
-};
-
-
-/**
- * cpu_reset:
- * @cpu: The CPU whose state is to be reset.
- */
-void cpu_reset(CPUState *cpu);

As commented on IRC, I would prefer this to stay in a shared cpu.h since it is used identically for softmmu and *-user. Simplifies rewriting documentation or adding Error** or whatever.

Same for TYPE_CPU and cast macros, they do not differ.

Quoted 20 lines
include/qemu/cpu.h +4 -2
-
-
+#ifdef CONFIG_USER_ONLY
+#include "qemu/cpu-user.h"
+#else
+#include "qemu/cpu-softmmu.h"
 #endif
qemu-common.h +0 -1
index f9deca6..47a3aab 100644
@@ -270,7 +270,6 @@ typedef struct PCIEPort PCIEPort;
 typedef struct PCIESlot PCIESlot;
 typedef struct MSIMessage MSIMessage;
 typedef struct SerialState SerialState;
-typedef struct IRQState *qemu_irq;
 typedef struct PCMCIACardState PCMCIACardState;
 typedef struct MouseTransformInfo MouseTransformInfo;
 typedef struct uWireSlave uWireSlave;

qemu-common.h typedef struct VirtIODevice VirtIODevice; · line 283

Quoted 4 lines
qemu-common.h +1 -0
@@ -281,6 +280,8 @@ typedef struct VirtIODevice VirtIODevice;
 typedef struct QEMUSGList QEMUSGList;
 typedef struct SHPCDevice SHPCDevice;
 
+#include "hw/irq.h"

Independent of cpu split?

Quoted 9 lines
qemu-common.h +1 -0
+
 typedef uint64_t pcibus_t;
 
 typedef enum LostTickPolicy {
qom/Makefile.objs +0 -0
index 5ef060a..a24fadf 100644

qom/Makefile.objs line 3

Quoted 6 lines
qom/Makefile.objs +2 -3
@@ -1,4 +1,3 @@
 qom-obj-y = object.o container.o qom-qobject.o
-qom-obj-twice-y = cpu.o
-common-obj-y = $(qom-obj-twice-y)
-user-obj-y = $(qom-obj-twice-y)
+common-obj-y += $(qom-obj-y) cpu-softmmu.o
+user-obj-y += $(qom-obj-y) cpu-user.o

This is silently making cpu.c unused without deleting it, no?

Quoted 48 lines
qom/cpu-softmmu.c new file +42 -0
new file mode 100644
index 0000000..5790944
@@ -0,0 +1,66 @@
+/*
+ * QEMU CPU model
+ *
+ * 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/gpl-2.0.html>
+ */
+
+#include "qemu/cpu.h"
+#include "qemu-common.h"
+#include "hw/qdev.h"
+
+void cpu_reset(CPUState *cpu)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->reset != NULL) {
+        (*klass->reset)(cpu);
+    }
+}
+
+static void cpu_common_reset(CPUState *cpu)
+{
+}
+
+static int cpu_realize(DeviceState *dev)
+{
+    return 0;
+}
+

qom/cpu-softmmu.c line 52

Quoted 10 lines
qom/cpu-softmmu.c new file +10 -0
+static void cpu_class_init(ObjectClass *klass, void *data)
+{
+    CPUClass *k = CPU_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    k->reset = cpu_common_reset;
+    dc->init = cpu_realize;
+}
+
+static TypeInfo cpu_type_info = {

const was/is missing... o;-)

Since this has been getting late - sorry - and there being no follow-ups for v1.2, what about applying patch 1/2 and deferring 2/2 to v1.3 / cpu-next?

Regards,
Andreas

Quoted 90 lines
qom/cpu-softmmu.c new file +14 -0
+    .name = TYPE_CPU,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(CPUState),
+    .abstract = true,
+    .class_size = sizeof(CPUClass),
+    .class_init = cpu_class_init,
+};
+
+static void cpu_register_types(void)
+{
+    type_register_static(&cpu_type_info);
+}
+
+type_init(cpu_register_types)
qom/cpu-user.c new file +70 -0
new file mode 100644
index 0000000..17b796f
@@ -0,0 +1,70 @@
+/*
+ * QEMU CPU model
+ *
+ * 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/gpl-2.0.html>
+ */
+
+#include "qemu/cpu.h"
+#include "qemu-common.h"
+
+void cpu_reset(CPUState *cpu)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->reset != NULL) {
+        (*klass->reset)(cpu);
+    }
+}
+
+static void cpu_common_reset(CPUState *cpu)
+{
+}
+
+static void cpu_class_init(ObjectClass *klass, void *data)
+{
+#ifndef CONFIG_USER_ONLY
+    DeviceClass *dc = DEVICE_CLASS(klass);
+#endif
+    CPUClass *k = CPU_CLASS(klass);
+
+#ifndef CONFIG_USER_ONLY
+    /* Overwrite this in subclasses for which hotplug is supported. */
+    dc->no_user = 1;
+#endif
+
+    k->reset = cpu_common_reset;
+}
+
+static TypeInfo cpu_type_info = {
+    .name = TYPE_CPU,
+#ifdef CONFIG_USER_ONLY
+    .parent = TYPE_OBJECT,
+#else
+    .parent = TYPE_DEVICE,
+#endif
+    .instance_size = sizeof(CPUState),
+    .abstract = true,
+    .class_size = sizeof(CPUClass),
+    .class_init = cpu_class_init,
+};
+
+static void cpu_register_types(void)
+{
+    type_register_static(&cpu_type_info);
+}
+
+type_init(cpu_register_types)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] cpu: for cpu-user and cpu-softmmu and make cpu-softmmu a child of DeviceState

Quoted 11 lines · Andreas Färber

Am 10.08.2012 19:00, schrieb Anthony Liguori:

Quoted 6 lines

The line between linux-user and softmmu is not very well defined right now. linux-user really don't want to include devices and making CpuState a child of DeviceState would require pulling lots of stuff into linux-user.

To solve this, we simply fork cpu-user and cpu-softmmu letting them evolve independently.

In the KVM call discussion there was no consensus that such independent evolution is actually desirable.

Quoted 6 lines

For example, moving forward with eliminating the CPU_COMMON mess this will mean duplicating the implementation of cpu_common_reset() - currently empty but in need of at least some zero'ing in the future. My fear is that such duplication will lead to fixes getting applied to the softmmu version only and contributors forgetting / being unaware that there is a second place to apply the same change.

Well the alternative is to build qdev for linux-user.

I tried very hard to make that work but I gave up. That is without a doubt the Right Solution.

Quoted 4 lines

Putting different TypeInfos into seperate source files is fine with me, but I would rather have shared implementations with an #ifdef than duplicating things.

I fear a tremendous amount of #ifdef's becoming necessary to make this work long term. That's why I prefer divergence. linux-user can stay simple and softmmu will be unaffected.

Quoted 7 lines

By comparison, forgetting to add a new field in either struct would lead to a compilation failure, getting noticed, so that seems doable.

Quoted 2 lines

We also need to push a qdev_init_nofail() into all callers of cpu_init(). This is needed eventually anyway so might as well do this now.

Patch would be better readable doing that as a follow-up...

Pretty sure that causes a breakage although I don't remember why so I don't think splitting up the patch is possible.

Quoted 436 lines
Quoted 74 lines
---
 Makefile.objs                 |    6 ---
 hw/armv7m.c                   |    1 +
 hw/axis_dev88.c               |    1 +
 hw/exynos4210.c               |    1 +
 hw/highbank.c                 |    1 +
 hw/integratorcp.c             |    1 +
 hw/leon3.c                    |    1 +
 hw/lm32_boards.c              |    2 +
 hw/milkymist.c                |    1 +
 hw/mips_fulong2e.c            |    1 +
 hw/mips_jazz.c                |    1 +
 hw/mips_malta.c               |    1 +
 hw/mips_mipssim.c             |    1 +
 hw/mips_r4k.c                 |    1 +
 hw/musicpal.c                 |    1 +
 hw/omap1.c                    |    1 +
 hw/omap2.c                    |    1 +
 hw/pc.c                       |    1 +
 hw/petalogix_ml605_mmu.c      |    1 +
 hw/petalogix_s3adsp1800_mmu.c |    1 +
 hw/ppc440_bamboo.c            |    1 +
 hw/ppc4xx_devs.c              |    1 +
 hw/ppc_newworld.c             |    1 +
 hw/ppc_oldworld.c             |    1 +
 hw/ppc_prep.c                 |    1 +
 hw/ppce500_mpc8544ds.c        |    1 +
 hw/pxa2xx.c                   |    1 +
 hw/r2d.c                      |    1 +
 hw/realview.c                 |    1 +
 hw/s390-virtio.c              |    1 +
 hw/spapr.c                    |    1 +
 hw/strongarm.c                |    1 +
 hw/sun4m.c                    |    1 +
 hw/sun4u.c                    |    1 +
 hw/versatilepb.c              |    1 +
 hw/vexpress.c                 |    2 +
 hw/virtex_ml507.c             |    1 +
 hw/xen_machine_pv.c           |    1 +
 hw/xilinx_zynq.c              |    1 +
 hw/xtensa_lx60.c              |    1 +
 hw/xtensa_sim.c               |    1 +
 include/qemu/cpu-softmmu.h    |   82 +++++++++++++++++++++++++++++++++++++++
 include/qemu/cpu-user.h       |   75 ++++++++++++++++++++++++++++++++++++
 include/qemu/cpu.h            |   85 ++---------------------------------------
 qemu-common.h                 |    3 +-
 qom/Makefile.objs             |    5 +-
 qom/cpu-softmmu.c             |   66 +++++++++++++++++++++++++++++++
 qom/cpu-user.c                |   70 +++++++++++++++++++++++++++++++++
 48 files changed, 343 insertions(+), 91 deletions(-)
 create mode 100644 include/qemu/cpu-softmmu.h
 create mode 100644 include/qemu/cpu-user.h
 create mode 100644 qom/cpu-softmmu.c
 create mode 100644 qom/cpu-user.c
Makefile.objs +0 -6
index 5ebbcfa..f285926 100644
@@ -12,12 +12,6 @@ qobject-obj-y += qerror.o error.o qemu-error.o
 universal-obj-y += $(qobject-obj-y)
 
 #######################################################################
-# QOM
-qom-obj-y = qom/
-
-universal-obj-y += $(qom-obj-y)
-
-#######################################################################
 # oslib-obj-y is code depending on the OS (win32 vs posix)
 oslib-obj-y = osdep.o
 oslib-obj-$(CONFIG_WIN32) += oslib-win32.o qemu-thread-win32.o

[...]

Quoted 183 lines
include/qemu/cpu-softmmu.h new file +82 -0
new file mode 100644
index 0000000..4f7b602
@@ -0,0 +1,82 @@
+/*
+ * QEMU CPU model
+ *
+ * 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/gpl-2.0.html>
+ */
+#ifndef QEMU_CPU_H
+#define QEMU_CPU_H
+
+#include "hw/qdev-core.h"
+#include "qemu-thread.h"
+
+/**
+ * SECTION:cpu
+ * @section_id: QEMU-cpu
+ * @title: CPU Class
+ * @short_description: Base class for all CPUs
+ */
+
+#define TYPE_CPU "cpu"
+
+#define CPU(obj) OBJECT_CHECK(CPUState, (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 CPUState CPUState;
+
+/**
+ * CPUClass:
+ * @reset: Callback to reset the #CPUState to its initial state.
+ *
+ * Represents a CPU family or model.
+ */
+typedef struct CPUClass {
+    /*< private >*/
+    DeviceClass parent_class;
+    /*< public >*/
+
+    void (*reset)(CPUState *cpu);
+} CPUClass;
+
+/**
+ * CPUState:
+ *
+ * State of one CPU core or thread.
+ */
+struct CPUState {
+    /*< private >*/
+    DeviceState parent_obj;
+    /*< public >*/
+
+    struct QemuThread *thread;
+#ifdef _WIN32
+   HANDLE hThread;
+#endif
+    bool thread_kicked;
+
+    /* TODO Move common fields from CPUArchState here. */
+};
+
+
+/**
+ * cpu_reset:
+ * @cpu: The CPU whose state is to be reset.
+ */
+void cpu_reset(CPUState *cpu);
+
+
+#endif
include/qemu/cpu-user.h new file +75 -0
new file mode 100644
index 0000000..78b65b3
@@ -0,0 +1,75 @@
+/*
+ * QEMU CPU model
+ *
+ * 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/gpl-2.0.html>
+ */
+#ifndef QEMU_CPU_H
+#define QEMU_CPU_H
+
+#include "qemu/object.h"
+
+/**
+ * SECTION:cpu
+ * @section_id: QEMU-cpu
+ * @title: CPU Class
+ * @short_description: Base class for all CPUs
+ */
+
+#define TYPE_CPU "cpu"
+
+#define CPU(obj) OBJECT_CHECK(CPUState, (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 CPUState CPUState;
+
+/**
+ * CPUClass:
+ * @reset: Callback to reset the #CPUState to its initial state.
+ *
+ * Represents a CPU family or model.
+ */
+typedef struct CPUClass {
+    /*< private >*/
+    ObjectClass parent_class;
+    /*< public >*/
+
+    void (*reset)(CPUState *cpu);
+} CPUClass;
+
+/**
+ * CPUState:
+ *
+ * State of one CPU core or thread.
+ */
+struct CPUState {
+    /*< private >*/
+    Object parent_obj;
+    /*< public >*/
+
+    /* TODO Move common fields from CPUArchState here. */
+};
+
+
+/**
+ * cpu_reset:
+ * @cpu: The CPU whose state is to be reset.
+ */
+void cpu_reset(CPUState *cpu);
+
+
+#endif
include/qemu/cpu.h +0 -9
index ad706a6..862988a 100644
@@ -1,82 +1,5 @@
-/*
- * QEMU CPU model
- *
- * 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.

include/qemu/cpu.h line 19

Quoted 10 lines
include/qemu/cpu.h +0 -10
- *
- * 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/gpl-2.0.html>
- */

If we empty this file, suggest to use either a GPLv2+ or MIT header to clarify licensing.

Quoted 50 lines
include/qemu/cpu.h +0 -50
-#ifndef QEMU_CPU_H
-#define QEMU_CPU_H
-
-#include "qemu/object.h"
-#include "qemu-thread.h"
-
-/**
- * SECTION:cpu
- * @section_id: QEMU-cpu
- * @title: CPU Class
- * @short_description: Base class for all CPUs
- */
-
-#define TYPE_CPU "cpu"
-
-#define CPU(obj) OBJECT_CHECK(CPUState, (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 CPUState CPUState;
-
-/**
- * CPUClass:
- * @reset: Callback to reset the #CPUState to its initial state.
- *
- * Represents a CPU family or model.
- */
-typedef struct CPUClass {
-    /*< private >*/
-    ObjectClass parent_class;
-    /*< public >*/
-
-    void (*reset)(CPUState *cpu);
-} CPUClass;
-
-/**
- * CPUState:
- *
- * State of one CPU core or thread.
- */
-struct CPUState {
-    /*< private >*/
-    Object parent_obj;
-    /*< public >*/
-
-    struct QemuThread *thread;
-#ifdef _WIN32
-    HANDLE hThread;
-#endif
-    bool thread_kicked;

include/qemu/cpu.h line 79

Quoted 10 lines
include/qemu/cpu.h +0 -10
-
-    /* TODO Move common fields from CPUArchState here. */
-};
-
-
-/**
- * cpu_reset:
- * @cpu: The CPU whose state is to be reset.
- */
-void cpu_reset(CPUState *cpu);

As commented on IRC, I would prefer this to stay in a shared cpu.h since it is used identically for softmmu and *-user. Simplifies rewriting documentation or adding Error** or whatever.

Same for TYPE_CPU and cast macros, they do not differ.

Quoted 20 lines
include/qemu/cpu.h +4 -2
-
-
+#ifdef CONFIG_USER_ONLY
+#include "qemu/cpu-user.h"
+#else
+#include "qemu/cpu-softmmu.h"
 #endif
qemu-common.h +0 -1
index f9deca6..47a3aab 100644
@@ -270,7 +270,6 @@ typedef struct PCIEPort PCIEPort;
 typedef struct PCIESlot PCIESlot;
 typedef struct MSIMessage MSIMessage;
 typedef struct SerialState SerialState;
-typedef struct IRQState *qemu_irq;
 typedef struct PCMCIACardState PCMCIACardState;
 typedef struct MouseTransformInfo MouseTransformInfo;
 typedef struct uWireSlave uWireSlave;

qemu-common.h typedef struct VirtIODevice VirtIODevice; · line 283

Quoted 4 lines
qemu-common.h +1 -0
@@ -281,6 +280,8 @@ typedef struct VirtIODevice VirtIODevice;
 typedef struct QEMUSGList QEMUSGList;
 typedef struct SHPCDevice SHPCDevice;
 
+#include "hw/irq.h"

Independent of cpu split?

Quoted 9 lines
qemu-common.h +1 -0
+
 typedef uint64_t pcibus_t;
 
 typedef enum LostTickPolicy {
qom/Makefile.objs +0 -0
index 5ef060a..a24fadf 100644

qom/Makefile.objs line 3

Quoted 6 lines
qom/Makefile.objs +2 -3
@@ -1,4 +1,3 @@
 qom-obj-y = object.o container.o qom-qobject.o
-qom-obj-twice-y = cpu.o
-common-obj-y = $(qom-obj-twice-y)
-user-obj-y = $(qom-obj-twice-y)
+common-obj-y += $(qom-obj-y) cpu-softmmu.o
+user-obj-y += $(qom-obj-y) cpu-user.o

This is silently making cpu.c unused without deleting it, no?

Quoted 52 lines
qom/cpu-softmmu.c new file +46 -0
new file mode 100644
index 0000000..5790944
@@ -0,0 +1,66 @@
+/*
+ * QEMU CPU model
+ *
+ * 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/gpl-2.0.html>
+ */
+
+#include "qemu/cpu.h"
+#include "qemu-common.h"
+#include "hw/qdev.h"
+
+void cpu_reset(CPUState *cpu)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->reset != NULL) {
+        (*klass->reset)(cpu);
+    }
+}
+
+static void cpu_common_reset(CPUState *cpu)
+{
+}
+
+static int cpu_realize(DeviceState *dev)
+{
+    return 0;
+}
+
+static void cpu_class_init(ObjectClass *klass, void *data)
+{
+    CPUClass *k = CPU_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
Quoted 8 lines

qom/cpu-softmmu.c line 52

Quoted 6 lines
qom/cpu-softmmu.c new file +6 -0
+
+    k->reset = cpu_common_reset;
+    dc->init = cpu_realize;
+}
+
+static TypeInfo cpu_type_info = {

const was/is missing... o;-)

Ack.

Quoted 4 lines

Since this has been getting late - sorry - and there being no follow-ups for v1.2, what about applying patch 1/2 and deferring 2/2 to v1.3 / cpu-next?

I think we should apply 1/2 for 1.2. For 1.3, we need a better solution and I think the better solution is to do this split and insist on people that care about linux-user doing the work to make qdev buildable.

I was concerned about this from the beginning (introducing qom into linux-user). I think we need to draw a line here and say that linux-user needs to keep up with the rate of change here. We can't burden softmmu to do all the work on linux-user.

If anyone has a better idea about how to isolate linux-user here I'm all for it but if it's going to need to interact with QOM, it needs to be able to handle qdev and everything else that comes with it.

Regards,

Anthony Liguori

Quoted 99 lines

Regards,
Andreas

Quoted 90 lines
qom/cpu-softmmu.c new file +14 -0
+    .name = TYPE_CPU,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(CPUState),
+    .abstract = true,
+    .class_size = sizeof(CPUClass),
+    .class_init = cpu_class_init,
+};
+
+static void cpu_register_types(void)
+{
+    type_register_static(&cpu_type_info);
+}
+
+type_init(cpu_register_types)
qom/cpu-user.c new file +70 -0
new file mode 100644
index 0000000..17b796f
@@ -0,0 +1,70 @@
+/*
+ * QEMU CPU model
+ *
+ * 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/gpl-2.0.html>
+ */
+
+#include "qemu/cpu.h"
+#include "qemu-common.h"
+
+void cpu_reset(CPUState *cpu)
+{
+    CPUClass *klass = CPU_GET_CLASS(cpu);
+
+    if (klass->reset != NULL) {
+        (*klass->reset)(cpu);
+    }
+}
+
+static void cpu_common_reset(CPUState *cpu)
+{
+}
+
+static void cpu_class_init(ObjectClass *klass, void *data)
+{
+#ifndef CONFIG_USER_ONLY
+    DeviceClass *dc = DEVICE_CLASS(klass);
+#endif
+    CPUClass *k = CPU_CLASS(klass);
+
+#ifndef CONFIG_USER_ONLY
+    /* Overwrite this in subclasses for which hotplug is supported. */
+    dc->no_user = 1;
+#endif
+
+    k->reset = cpu_common_reset;
+}
+
+static TypeInfo cpu_type_info = {
+    .name = TYPE_CPU,
+#ifdef CONFIG_USER_ONLY
+    .parent = TYPE_OBJECT,
+#else
+    .parent = TYPE_DEVICE,
+#endif
+    .instance_size = sizeof(CPUState),
+    .abstract = true,
+    .class_size = sizeof(CPUClass),
+    .class_init = cpu_class_init,
+};
+
+static void cpu_register_types(void)
+{
+    type_register_static(&cpu_type_info);
+}
+
+type_init(cpu_register_types)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#8 lore raw
In reply to Anthony Liguori

Am 10.08.2012 19:00, schrieb Anthony Liguori:

Quoted 5 lines

This is just a rebase of this series that I posted back in June.

Andreas had a different approach involving a #define but I think doing a full split ends up being nicer. For instance, the recently added thread information is only relevant to cpu-softmmu so we can limit that entirely to cpu-softmmu.

For the record, the thread information was not really added, it was merely moved from CPU_COMMON, which being a large macro didn't easily allow #ifdef'ing within itself (cf., former CPU_COMMON_THREAD). If this were the only issue, we could add an #ifndef CONFIG_USER_ONLY to drop unneeded CPU_COMMON fields - most CPU_COMMON fields are to eventually end up in CPUState, so this discussion is not just about the two(?) fields we see today.

Andreas

Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg