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 2/5] Platform: Add serial device
Date: Wed,  4 Jun 2014 14:28:53 +0200	[thread overview]
Message-ID: <1401884936-12907-3-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1401884936-12907-1-git-send-email-agraf@suse.de>

The serial port is a simple device that users (read: libvirt) are happy to
create using -device. Unfortunately that only works for ISA and PCI devices,
since sysbus devices can not get spawned using -device without intimate
knowledge of the address layout and interrupt mapping topoligy of the board.

This patch introduces a new platform serial port device that exposes its
interrupt line and memory region via platform device properties. That allows
us to spawn such a device to default locations by simply saying -device.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/char/Makefile.objs             |   1 +
 hw/char/serial-platform.c         | 103 ++++++++++++++++++++++++++++++++++++++
 include/hw/char/serial-platform.h |  56 +++++++++++++++++++++
 3 files changed, 160 insertions(+)
 create mode 100644 hw/char/serial-platform.c
 create mode 100644 include/hw/char/serial-platform.h

diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs
index 317385d..ffb49e5 100644
--- a/hw/char/Makefile.objs
+++ b/hw/char/Makefile.objs
@@ -3,6 +3,7 @@ common-obj-$(CONFIG_ESCC) += escc.o
 common-obj-$(CONFIG_PARALLEL) += parallel.o
 common-obj-$(CONFIG_PL011) += pl011.o
 common-obj-$(CONFIG_SERIAL) += serial.o serial-isa.o
+common-obj-$(CONFIG_SERIAL_PLATFORM) += serial-platform.o
 common-obj-$(CONFIG_SERIAL_PCI) += serial-pci.o
 common-obj-$(CONFIG_VIRTIO) += virtio-console.o
 common-obj-$(CONFIG_XILINX) += xilinx_uartlite.o
diff --git a/hw/char/serial-platform.c b/hw/char/serial-platform.c
new file mode 100644
index 0000000..9edee93
--- /dev/null
+++ b/hw/char/serial-platform.c
@@ -0,0 +1,103 @@
+/*
+ * QEMU 16550A UART emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "hw/char/serial.h"
+#include "hw/char/serial-platform.h"
+#include "hw/platform/device.h"
+
+static void serial_platform_realizefn(DeviceState *dev, Error **errp)
+{
+    PlatformSerialClass *psc = PLATFORM_SERIAL_GET_CLASS(dev);
+    PlatformSerialState *p = PLATFORM_SERIAL(dev);
+    SerialState *s = &p->state;
+
+    /* super() */
+    psc->parent_realize(dev, errp);
+
+    /* Initialize serial port */
+    s->baudbase = 115200;
+    serial_realize_core(s, errp);
+}
+
+static void serial_platform_init(Object *obj)
+{
+    PlatformSerialState *p = PLATFORM_SERIAL(obj);
+    SerialState *s = &p->state;
+    PlatformDeviceState *pdev = &p->parent_obj;
+
+    /* Initialize static data */
+    memory_region_init_io(&s->io, OBJECT(p), &serial_io_ops, s, "serial", 8);
+
+    /* Populate parent fields */
+    pdev->num_regions = 1;
+    pdev->regions = g_new(MemoryRegion *, 1);
+    pdev->regions[0] = &s->io;
+    pdev->num_irqs = 1;
+    pdev->irqs = g_new(qemu_irq *, 1);
+    pdev->irqs[0] = &s->irq;
+}
+
+static const VMStateDescription vmstate_platform_serial = {
+    .name = "serial",
+    .version_id = 3,
+    .minimum_version_id = 2,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT(state, PlatformSerialState, 0, vmstate_serial, SerialState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static Property serial_platform_properties[] = {
+    DEFINE_PROP_CHR("chardev",   PlatformSerialState, state.chr),
+    DEFINE_PROP_UINT32("wakeup", PlatformSerialState, state.wakeup, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void serial_platform_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    PlatformSerialClass *psc = PLATFORM_SERIAL_CLASS(oc);
+
+    psc->parent_realize = dc->realize;
+    dc->realize = serial_platform_realizefn;
+    dc->vmsd = &vmstate_platform_serial;
+    dc->props = serial_platform_properties;
+}
+
+static const TypeInfo serial_platform_info = {
+    .name          = TYPE_PLATFORM_SERIAL,
+    .parent        = TYPE_PLATFORM_DEVICE,
+    .instance_size = sizeof(PlatformSerialState),
+    .instance_init = serial_platform_init,
+    .class_init    = serial_platform_class_init,
+    .class_size    = sizeof(PlatformSerialClass),
+};
+
+static void serial_register_types(void)
+{
+    type_register_static(&serial_platform_info);
+}
+
+type_init(serial_register_types)
diff --git a/include/hw/char/serial-platform.h b/include/hw/char/serial-platform.h
new file mode 100644
index 0000000..b3650e7
--- /dev/null
+++ b/include/hw/char/serial-platform.h
@@ -0,0 +1,56 @@
+/*
+ * QEMU 16550A UART emulation
+ *
+ * Copyright (c) 2003-2004 Fabrice Bellard
+ * Copyright (c) 2008 Citrix Systems, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+#ifndef HW_CHAR_SERIAL_PLATFORM_H
+#define HW_CHAR_SERIAL_PLATFORM_H
+
+#include "hw/char/serial.h"
+#include "hw/platform/device.h"
+
+#define TYPE_PLATFORM_SERIAL "platform-serial"
+#define PLATFORM_SERIAL(obj) OBJECT_CHECK(PlatformSerialState, (obj), \
+                                         TYPE_PLATFORM_SERIAL)
+
+typedef struct PlatformSerialState {
+    /*< private >*/
+    PlatformDeviceState parent_obj;
+    /*< public >*/
+
+    SerialState state;
+} PlatformSerialState;
+
+#define PLATFORM_SERIAL_CLASS(class) \
+    OBJECT_CLASS_CHECK(PlatformSerialClass, (class), TYPE_PLATFORM_SERIAL)
+#define PLATFORM_SERIAL_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(PlatformSerialClass, (obj), TYPE_PLATFORM_SERIAL)
+
+typedef struct PlatformSerialClass {
+    /*< private >*/
+    DeviceClass parent_class;
+    /*< public >*/
+
+    DeviceRealize parent_realize;
+} PlatformSerialClass;
+
+#endif /* !HW_CHAR_SERIAL_PLATFORM_H */
-- 
1.8.1.4

  parent 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 ` [Qemu-devel] [PATCH 1/5] Platform: Add platform device class Alexander Graf
2014-06-19 14:51   ` Eric Auger
2014-06-04 12:28 ` Alexander Graf [this message]
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-3-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.