All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: qemu-ppc@nongnu.org
Cc: qemu-devel@nongnu.org, eric.auger@linaro.org
Subject: [Qemu-devel] [PATCH 1/5] Platform: Add platform device class
Date: Wed,  4 Jun 2014 14:28:52 +0200	[thread overview]
Message-ID: <1401884936-12907-2-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1401884936-12907-1-git-send-email-agraf@suse.de>

This patch adds a new device class called "platform device". This is an
abstract class for consumption of actual classes that implement devices.

The new thing about platform devices is that they have awareness of all
memory regions and IRQs that the device exposes. That gives us the ability
to manually specify thing using properties from the command line.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/Makefile.objs             |   1 +
 hw/platform/Makefile.objs    |   1 +
 hw/platform/device.c         | 108 +++++++++++++++++++++++++++++++++++++++++++
 include/hw/platform/device.h |  45 ++++++++++++++++++
 4 files changed, 155 insertions(+)
 create mode 100644 hw/platform/Makefile.objs
 create mode 100644 hw/platform/device.c
 create mode 100644 include/hw/platform/device.h

diff --git a/hw/Makefile.objs b/hw/Makefile.objs
index d178b65..f300f68 100644
--- a/hw/Makefile.objs
+++ b/hw/Makefile.objs
@@ -20,6 +20,7 @@ devices-dirs-$(CONFIG_SOFTMMU) += nvram/
 devices-dirs-$(CONFIG_SOFTMMU) += pci/
 devices-dirs-$(CONFIG_PCI) += pci-bridge/ pci-host/
 devices-dirs-$(CONFIG_SOFTMMU) += pcmcia/
+devices-dirs-$(CONFIG_PLATFORM) += platform/
 devices-dirs-$(CONFIG_SOFTMMU) += scsi/
 devices-dirs-$(CONFIG_SOFTMMU) += sd/
 devices-dirs-$(CONFIG_SOFTMMU) += ssi/
diff --git a/hw/platform/Makefile.objs b/hw/platform/Makefile.objs
new file mode 100644
index 0000000..824356b
--- /dev/null
+++ b/hw/platform/Makefile.objs
@@ -0,0 +1 @@
+common-obj-$(CONFIG_PLATFORM) += device.o
diff --git a/hw/platform/device.c b/hw/platform/device.c
new file mode 100644
index 0000000..9e23370
--- /dev/null
+++ b/hw/platform/device.c
@@ -0,0 +1,108 @@
+/*
+ * Platform Device that can expose its memory regions and IRQ lines
+ *
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ *
+ * Authors: Alexander Graf,   <agraf@suse.de>
+ *
+ * This 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 is an abstract platform device, so you really only want to use it
+ * as parent class for platform devices.
+ *
+ * It ensures that all boilerplate is properly abstracted away from children
+ * and consistent across devices.
+ *
+ * When instantiating a platform device you can optionally always specify 2
+ * properties which otherwise get populated automatically:
+ *
+ *  regions: Offsets in the platform hole the device's memory regions get mapped
+ *           to.
+ *  irqs: IRQ pins in the linear platform IRQ range the device's IRQs get mapped
+ *           to.
+ */
+
+#include "qemu-common.h"
+#include "hw/platform/device.h"
+
+static void fixup_regions(PlatformDeviceState *s)
+{
+    uint64_t *addrs = g_new(uint64_t, s->num_regions);
+    int i;
+
+    /* Treat memory offsets that the user did not specify as dynamic */
+    for (i = 0; i < s->num_regions; i++) {
+        if (s->num_plat_region_addrs > i) {
+            addrs[i] = s->plat_region_addrs[i];
+        } else {
+            addrs[i] = PLATFORM_DYNAMIC;
+        }
+    }
+
+    s->plat_region_addrs = addrs;
+    s->num_plat_region_addrs = s->num_regions;
+}
+
+static void fixup_irqs(PlatformDeviceState *s)
+{
+    uint32_t *irqs = g_new(uint32_t, s->num_irqs);
+    int i;
+
+    /* Treat IRQs that the user did not specify as dynamic */
+    for (i = 0; i < s->num_irqs; i++) {
+        if (s->num_plat_irqs > i) {
+            irqs[i] = s->plat_irqs[i];
+        } else {
+            irqs[i] = PLATFORM_DYNAMIC;
+        }
+    }
+
+    s->plat_irqs = irqs;
+    s->num_plat_irqs = s->num_irqs;
+}
+
+static void platform_device_realize(DeviceState *dev, Error **errp)
+{
+    PlatformDeviceState *s = PLATFORM_DEVICE(dev);
+
+    fixup_regions(s);
+    fixup_irqs(s);
+}
+
+static Property platform_device_properties[] = {
+    /* memory regions for a device */
+    DEFINE_PROP_ARRAY("regions", PlatformDeviceState, num_plat_region_addrs,
+                      plat_region_addrs, qdev_prop_uint64, uint64_t),
+    /* interrupts for a device */
+    DEFINE_PROP_ARRAY("irqs", PlatformDeviceState, num_plat_irqs,
+                      plat_irqs, qdev_prop_uint32, uint32_t),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void platform_device_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+
+    dc->realize = platform_device_realize;
+    dc->props = platform_device_properties;
+}
+
+static const TypeInfo platform_device_type_info = {
+    .name = TYPE_PLATFORM_DEVICE,
+    .parent = TYPE_DEVICE,
+    .instance_size = sizeof(PlatformDeviceState),
+    .abstract = true,
+    .class_init = platform_device_class_init,
+};
+
+
+static void device_register_types(void)
+{
+    type_register_static(&platform_device_type_info);
+}
+
+type_init(device_register_types)
diff --git a/include/hw/platform/device.h b/include/hw/platform/device.h
new file mode 100644
index 0000000..a17f79e
--- /dev/null
+++ b/include/hw/platform/device.h
@@ -0,0 +1,45 @@
+/*
+ * Generic platform device with IRQ and IO placement hints
+ *
+ * Copyright 2014 Freescale Semiconductor, Inc.
+ *
+ * Authors: Alexander Graf,   <agraf@suse.de>
+ *
+ * This 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.
+ */
+
+#ifndef QEMU_HW_PLATFORM_DEVICE_H
+#define QEMU_HW_PLATFORM_DEVICE_H
+
+#include "qemu-common.h"
+#include "hw/qdev.h"
+
+#define TYPE_PLATFORM_DEVICE "platform-device"
+#define PLATFORM_DEVICE(obj) OBJECT_CHECK(PlatformDeviceState, (obj), TYPE_PLATFORM_DEVICE)
+#define PLATFORM_DYNAMIC -1LL
+
+typedef struct PlatformDeviceState {
+    /*< private >*/
+
+    DeviceState parent_obj;
+    QTAILQ_ENTRY(PlatformDeviceState) next;
+
+    /* these get set by children to indicate their resources */
+    uint32_t num_regions;
+    MemoryRegion **regions;
+    uint32_t num_irqs;
+    qemu_irq **irqs;
+
+    /*< public >*/
+
+    /* these get set by the user though qdev parameters */
+    uint32_t num_plat_region_addrs;
+    uint64_t *plat_region_addrs;
+    uint32_t num_plat_irqs;
+    uint32_t *plat_irqs;
+} PlatformDeviceState;
+
+#endif /* !QEMU_HW_PLATFORM_DEVICE_H */
-- 
1.8.1.4

  reply	other threads:[~2014-06-04 12:29 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-04 12:28 [Qemu-devel] [PATCH 0/5] Platform device support Alexander Graf
2014-06-04 12:28 ` Alexander Graf [this message]
2014-06-19 14:51   ` [Qemu-devel] [PATCH 1/5] Platform: Add platform device class Eric Auger
2014-06-04 12:28 ` [Qemu-devel] [PATCH 2/5] Platform: Add serial device Alexander Graf
2014-06-04 12:28 ` [Qemu-devel] [PATCH 3/5] PPC: e500: Only create dt entries for existing serial ports Alexander Graf
2014-06-04 12:28 ` [Qemu-devel] [PATCH 4/5] PPC: e500: Support platform devices Alexander Graf
2014-06-13  8:58   ` Bharat.Bhushan
2014-06-13  9:46     ` Alexander Graf
2014-06-19 14:56   ` Eric Auger
2014-06-19 21:40     ` Alexander Graf
2014-06-27  9:29   ` Eric Auger
2014-06-27 11:30     ` Alexander Graf
2014-06-27 16:50       ` Eric Auger
2014-06-04 12:28 ` [Qemu-devel] [PATCH 5/5] PPC: e500: Add support for platform serial devices Alexander Graf
2014-06-19 20:54 ` [Qemu-devel] [PATCH 0/5] Platform device support Paolo Bonzini
2014-06-19 21:38   ` Alexander Graf
2014-06-20  6:43 ` Peter Crosthwaite
2014-06-20  7:39   ` Paolo Bonzini
2014-06-26 12:01   ` Alexander Graf
2014-06-27 10:30     ` Andreas Färber
2014-06-27 10:54       ` Peter Crosthwaite
2014-06-27 11:17         ` Andreas Färber
2014-06-27 11:24           ` Alexander Graf
2014-06-27 11:48             ` Paolo Bonzini
2014-06-27 11:52               ` Peter Maydell
2014-06-27 12:00                 ` Paolo Bonzini
2014-06-27 11:41         ` Alexander Graf
2014-06-27 11:40       ` Alexander Graf

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=1401884936-12907-2-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=eric.auger@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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.