Patchwork [6/9] PlatBus: Add serial-platbus device

login
register
mail settings
Submitter Alexander Graf
Date July 22, 2013, 5:50 p.m.
Message ID <1374515411-43818-7-git-send-email-agraf@suse.de>
Download mbox | patch
Permalink /patch/260778/
State New
Headers show

Comments

Alexander Graf - July 22, 2013, 5:50 p.m.
We want to be able to spawn a serial console on the platform bus. Create
a small platbus wrapper device very similar to the ISA one.

Signed-off-by: Alexander Graf <agraf@suse.de>
---
 hw/char/Makefile.objs            |   1 +
 hw/char/serial-platbus.c         | 100 +++++++++++++++++++++++++++++++++++++++
 include/hw/char/serial-platbus.h |  56 ++++++++++++++++++++++
 3 files changed, 157 insertions(+)
 create mode 100644 hw/char/serial-platbus.c
 create mode 100644 include/hw/char/serial-platbus.h
Peter Maydell - July 22, 2013, 6:26 p.m.
On 22 July 2013 18:50, Alexander Graf <agraf@suse.de> wrote:
> We want to be able to spawn a serial console on the platform bus. Create
> a small platbus wrapper device very similar to the ISA one.

Why not use virtio-console?

-- PMM
Alexander Graf - July 22, 2013, 6:56 p.m.
On 22.07.2013, at 20:26, Peter Maydell wrote:

> On 22 July 2013 18:50, Alexander Graf <agraf@suse.de> wrote:
>> We want to be able to spawn a serial console on the platform bus. Create
>> a small platbus wrapper device very similar to the ISA one.
> 
> Why not use virtio-console?

Because eventually we want -nodefaults not generate any UARTs and only create them through -device. Guests expect /dev/ttySx device nodes for their serial ports.


Alex
Scott Wood - July 24, 2013, 8:16 p.m.
On 07/22/2013 01:56:32 PM, Alexander Graf wrote:
> 
> On 22.07.2013, at 20:26, Peter Maydell wrote:
> 
> > On 22 July 2013 18:50, Alexander Graf <agraf@suse.de> wrote:
> >> We want to be able to spawn a serial console on the platform bus.  
> Create
> >> a small platbus wrapper device very similar to the ISA one.
> >
> > Why not use virtio-console?
> 
> Because eventually we want -nodefaults not generate any UARTs and  
> only create them through -device. Guests expect /dev/ttySx device  
> nodes for their serial ports.

Plus, it's nice to have debug output from early on, rather than having  
to wait until PCI is up and running.

-Scott
Peter Maydell - July 24, 2013, 8:25 p.m.
On 24 July 2013 21:16, Scott Wood <scottwood@freescale.com> wrote:
> Plus, it's nice to have debug output from early on, rather than having to
> wait until PCI is up and running.

It would be nice if the device tree had bindings for
"you can find your emergency serial port here"...

-- PMM

Patch

diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs
index f8f3dbc..777796c 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_PLATBUS) += serial-platbus.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-platbus.c b/hw/char/serial-platbus.c
new file mode 100644
index 0000000..ee3019c
--- /dev/null
+++ b/hw/char/serial-platbus.c
@@ -0,0 +1,100 @@ 
+/*
+ * 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-platbus.h"
+#include "hw/platbus/platbus.h"
+#include "hw/platbus/device.h"
+
+static void serial_platbus_realizefn(DeviceState *dev, Error **errp)
+{
+    PlatBusSerialClass *psc = PLATBUS_SERIAL_GET_CLASS(dev);
+    PlatBusSerialState *p = PLATBUS_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_platbus_init(Object *obj)
+{
+    PlatBusSerialState *p = PLATBUS_SERIAL(obj);
+    SerialState *s = &p->state;
+    PlatBusDeviceState *pdev = &p->parent_obj;
+
+    /* Initialize static data */
+    memory_region_init_io(&s->io, OBJECT(p), &serial_io_ops, s, "serial", 8);
+
+    /* Populate parent fields */
+    platbus_device_set_irqs(pdev, &s->irq);
+    platbus_device_set_regions(pdev, &s->io);
+}
+
+static const VMStateDescription vmstate_platbus_serial = {
+    .name = "serial",
+    .version_id = 3,
+    .minimum_version_id = 2,
+    .fields = (VMStateField[]) {
+        VMSTATE_STRUCT(state, PlatBusSerialState, 0, vmstate_serial, SerialState),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static Property serial_platbus_properties[] = {
+    DEFINE_PROP_CHR("chardev",   PlatBusSerialState, state.chr),
+    DEFINE_PROP_UINT32("wakeup", PlatBusSerialState, state.wakeup, 0),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void serial_platbus_class_init(ObjectClass *oc, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(oc);
+    PlatBusSerialClass *psc = PLATBUS_SERIAL_CLASS(oc);
+
+    psc->parent_realize = dc->realize;
+    dc->realize = serial_platbus_realizefn;
+    dc->vmsd = &vmstate_platbus_serial;
+    dc->props = serial_platbus_properties;
+}
+
+static const TypeInfo serial_platbus_info = {
+    .name          = TYPE_PLATBUS_SERIAL,
+    .parent        = TYPE_PLATBUS_DEVICE,
+    .instance_size = sizeof(PlatBusSerialState),
+    .instance_init = serial_platbus_init,
+    .class_init    = serial_platbus_class_init,
+    .class_size    = sizeof(PlatBusSerialClass),
+};
+
+static void serial_register_types(void)
+{
+    type_register_static(&serial_platbus_info);
+}
+
+type_init(serial_register_types)
diff --git a/include/hw/char/serial-platbus.h b/include/hw/char/serial-platbus.h
new file mode 100644
index 0000000..182ab77
--- /dev/null
+++ b/include/hw/char/serial-platbus.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_PLATBUS_H
+#define HW_CHAR_SERIAL_PLATBUS_H
+
+#include "hw/char/serial.h"
+#include "hw/platbus/device.h"
+
+#define TYPE_PLATBUS_SERIAL "platbus-serial"
+#define PLATBUS_SERIAL(obj) OBJECT_CHECK(PlatBusSerialState, (obj), \
+                                         TYPE_PLATBUS_SERIAL)
+
+typedef struct PlatBusSerialState {
+    /*< private >*/
+    PlatBusDeviceState parent_obj;
+    /*< public >*/
+
+    SerialState state;
+} PlatBusSerialState;
+
+#define PLATBUS_SERIAL_CLASS(class) \
+    OBJECT_CLASS_CHECK(PlatBusSerialClass, (class), TYPE_PLATBUS_SERIAL)
+#define PLATBUS_SERIAL_GET_CLASS(obj) \
+    OBJECT_GET_CLASS(PlatBusSerialClass, (obj), TYPE_PLATBUS_SERIAL)
+
+typedef struct PlatBusSerialClass {
+    /*< private >*/
+    DeviceClass parent_class;
+    /*< public >*/
+
+    DeviceRealize parent_realize;
+} PlatBusSerialClass;
+
+#endif /* !HW_CHAR_SERIAL_PLATBUS_H */