[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/5] Platform: Add serial device
From: |
Alexander Graf |
Subject: |
[Qemu-devel] [PATCH 2/5] Platform: Add serial device |
Date: |
Wed, 4 Jun 2014 14:28:53 +0200 |
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 <address@hidden>
---
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
- [Qemu-devel] [PATCH 4/5] PPC: e500: Support platform devices, (continued)
- [Qemu-devel] [PATCH 4/5] PPC: e500: Support platform devices, Alexander Graf, 2014/06/04
- [Qemu-devel] [PATCH 5/5] PPC: e500: Add support for platform serial devices, Alexander Graf, 2014/06/04
- [Qemu-devel] [PATCH 1/5] Platform: Add platform device class, Alexander Graf, 2014/06/04
- [Qemu-devel] [PATCH 2/5] Platform: Add serial device,
Alexander Graf <=
- [Qemu-devel] [PATCH 3/5] PPC: e500: Only create dt entries for existing serial ports, Alexander Graf, 2014/06/04
- Re: [Qemu-devel] [PATCH 0/5] Platform device support, Paolo Bonzini, 2014/06/19
- Re: [Qemu-devel] [PATCH 0/5] Platform device support, Peter Crosthwaite, 2014/06/20