All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Hervé Poussineau" <hpoussin@reactos.org>
To: qemu-devel@nongnu.org
Cc: "Hervé Poussineau" <hpoussin@reactos.org>
Subject: [Qemu-devel] [PATCH 02/20] [MIPS] cpu: convert to qdev
Date: Sun,  1 Aug 2010 19:37:04 +0200	[thread overview]
Message-ID: <1280684242-19611-2-git-send-email-hpoussin@reactos.org> (raw)
In-Reply-To: <4C5579DA.8050508@reactos.org>

Add a qdev device representing a whole MIPS CPU, ie the core, the interrupt controller, and the timer.
Export a qdev bus, so other devices can use MIPS CPU interrupts

Signed-off-by: Hervé Poussineau <hpoussin@reactos.org>
---
 hw/mips_cpudevs.h |    4 ++
 hw/mips_int.c     |   81 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+), 0 deletions(-)

diff --git a/hw/mips_cpudevs.h b/hw/mips_cpudevs.h
index db82b41..495b3fd 100644
--- a/hw/mips_cpudevs.h
+++ b/hw/mips_cpudevs.h
@@ -1,5 +1,7 @@
 #ifndef HW_MIPS_CPUDEVS_H
 #define HW_MIPS_CPUDEVS_H
+#include "qdev.h"
+
 /* Definitions for MIPS CPU internal devices.  */
 
 /* mips_addr.c */
@@ -8,6 +10,8 @@ uint64_t cpu_mips_phys_to_kseg0(void *opaque, uint64_t addr);
 
 /* mips_int.c */
 void cpu_mips_irq_init_cpu(CPUState *env);
+BusState *cpu_mips_init_cpu(const char *model);
+void cpu_mips_register(DeviceInfo *info);
 
 /* mips_timer.c */
 void cpu_mips_clock_init(CPUState *);
diff --git a/hw/mips_int.c b/hw/mips_int.c
index 477f6ab..8e868be 100644
--- a/hw/mips_int.c
+++ b/hw/mips_int.c
@@ -22,6 +22,7 @@
 
 #include "hw.h"
 #include "mips_cpudevs.h"
+#include "sysbus.h"
 #include "cpu.h"
 
 static void cpu_mips_irq_request(void *opaque, int irq, int level)
@@ -63,3 +64,83 @@ void cpu_mips_soft_irq(CPUState *env, int irq, int level)
 
     qemu_set_irq(env->irq[irq], level);
 }
+
+typedef struct CPUMIPS
+{
+    SysBusDevice busdev;
+    BusState qbus;
+    char *model;
+    CPUState state;
+} CPUMIPS;
+
+static void cpu_mips_irq_request1(void *opaque, int irq, int level)
+{
+    CPUMIPS *s = FROM_SYSBUS(CPUMIPS, sysbus_from_qdev(opaque));
+    CPUState *env = &s->state;
+    cpu_mips_irq_request(env, irq, level);
+}
+
+static void cpu_device_reset(DeviceState *d)
+{
+    CPUMIPS *s = FROM_SYSBUS(CPUMIPS, sysbus_from_qdev(d));
+    cpu_reset(&s->state);
+}
+
+static struct BusInfo cpu_bus_info = {
+    .name      = "cpu",
+    .size      = 0,
+};
+
+void cpu_mips_register(DeviceInfo *info)
+{
+    info->bus_info = &cpu_bus_info;
+    qdev_register(info);
+}
+
+static int cpu_device_init(SysBusDevice *dev)
+{
+    CPUMIPS* cpu = FROM_SYSBUS(CPUMIPS, dev);
+
+    if (cpu_mips_init_inplace(&cpu->state, cpu->model) < 0)
+        return -1;
+
+    cpu_mips_clock_init(&cpu->state);
+
+    qbus_create_inplace(&cpu->qbus, &cpu_bus_info, &dev->qdev, NULL);
+    qdev_init_gpio_in(cpu->qbus.parent, cpu_mips_irq_request1, 8);
+    return 0;
+}
+
+static SysBusDeviceInfo cpu_device_info = {
+    .qdev.name  = "cpu-mips",
+    .qdev.size  = sizeof(CPUMIPS),
+    .qdev.reset = cpu_device_reset,
+    .init       = cpu_device_init,
+    .qdev.props = (Property[]) {
+        DEFINE_PROP_STRING("model", CPUMIPS, model),
+        DEFINE_PROP_END_OF_LIST(),
+    },
+};
+
+static void mips_register_devices(void)
+{
+    sysbus_register_withprop(&cpu_device_info);
+}
+
+device_init(mips_register_devices)
+
+BusState *cpu_mips_init_cpu(const char *cpu_model)
+{
+    DeviceState *dev;
+
+    dev = qdev_create(NULL, "cpu-mips");
+    if (!dev) {
+        return NULL;
+    }
+    qdev_prop_set_string(dev, "model", qemu_strdup(cpu_model));
+    if (qdev_init(dev) < 0) {
+        return NULL;
+    }
+    return &container_of(dev, CPUMIPS, busdev.qdev)->qbus;
+}
+
-- 
1.7.1.GIT

  parent reply	other threads:[~2010-08-01 18:10 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-01 13:42 [Qemu-devel] [PATCH 00/20] MIPS Magnum conversion to qdev Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 01/20] [MIPS] cpu: add a init inplace method Hervé Poussineau
2010-08-01 17:37 ` Hervé Poussineau [this message]
2010-08-01 17:37 ` [Qemu-devel] [PATCH 03/20] [MIPS] Jazz emulation: create a qdev cpu Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 04/20] [MIPS] rc4030: convert to qdev Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 05/20] Add a stub for some rc4030 functions, if rc4030 support is not compiled in Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 06/20] [MIPS] qdev: convert i8042 to rc4030 device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 07/20] [MIPS] qdev: convert parallel port " Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 08/20] [MIPS] qdev: convert serial " Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 09/20] [MIPS] qdev: convert jazz-led to sysbus device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 10/20] [MIPS] Jazz emulation: make video card optional Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 11/20] [MIPS] qdev: convert vga-isa-mm to ISA device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 12/20] [MIPS] qdev: convert g364fb to rc4030 device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 13/20] [MIPS] qdev: add a rtc forwarder device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 14/20] [MIPS] qdev: add an isa bus device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 15/20] [MIPS] qdev: convert dp83932 network card to rc4030 device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 16/20] [MIPS] qdev: convert floppy disk controller " Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 17/20] [MIPS] qdev: convert esp scsi adapter " Hervé Poussineau
2010-08-02 14:51   ` Artyom Tarasenko
2010-08-01 17:37 ` [Qemu-devel] [PATCH 18/20] [MIPS] qdev: convert ds1225y nvram to sysbus device Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 19/20] [MIPS] qdev: add a mips board device, which initializes the ram and the rom Hervé Poussineau
2010-08-01 17:37 ` [Qemu-devel] [PATCH 20/20] [MIPS] qdev: Complete rc4030 conversion, by removing legacy stuff Hervé Poussineau
2010-08-02 16:06 ` [Qemu-devel] [PATCH 00/20] MIPS Magnum conversion to qdev Blue Swirl

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=1280684242-19611-2-git-send-email-hpoussin@reactos.org \
    --to=hpoussin@reactos.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.