]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm: Add support for early serial printk
authorPekka Enberg <penberg@cs.helsinki.fi>
Sun, 11 Apr 2010 17:42:10 +0000 (20:42 +0300)
committerPekka Enberg <penberg@cs.helsinki.fi>
Sun, 11 Apr 2010 17:51:57 +0000 (20:51 +0300)
Signed-off-by: Pekka Enberg <penberg@cs.helsinki.fi>
tools/kvm/Makefile
tools/kvm/early_printk.c [new file with mode: 0644]
tools/kvm/include/kvm/early_printk.h [new file with mode: 0644]
tools/kvm/include/kvm/ioport.h [new file with mode: 0644]
tools/kvm/ioport.c
tools/kvm/main.c

index 1846f3c4f7e7d8f5daa58d4278cae5c0dd1675d7..8db8548cf0310236a43917a39114d7eab5c166cb 100644 (file)
@@ -10,6 +10,7 @@ export E Q
 PROGRAM        = kvm
 
 OBJS   += cpuid.o
+OBJS   += early_printk.o
 OBJS   += interrupt.o
 OBJS   += ioport.o
 OBJS   += kvm.o
diff --git a/tools/kvm/early_printk.c b/tools/kvm/early_printk.c
new file mode 100644 (file)
index 0000000..026ab78
--- /dev/null
@@ -0,0 +1,37 @@
+#include "kvm/early_printk.h"
+
+#include "kvm/ioport.h"
+
+#include <stdio.h>
+
+static bool early_serial_txr_out(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
+{
+       char *p = data;
+
+       printf("%c", *p);
+
+       return true;
+}
+
+static struct ioport_operations early_serial_txr_ops = {
+       .io_out         = early_serial_txr_out,
+};
+
+static bool early_serial_lsr_in(struct kvm *self, uint16_t port, void *data, int size, uint32_t count)
+{
+       uint8_t *p = data;
+
+       *p      = 0x20; /* xmtrdy */
+
+       return true;
+}
+
+static struct ioport_operations early_serial_lsr_ops = {
+       .io_in          = early_serial_lsr_in,
+};
+
+void early_printk__init(void)
+{
+       ioport__register(0x03F8, &early_serial_txr_ops);
+       ioport__register(0x03FD, &early_serial_lsr_ops);
+}
diff --git a/tools/kvm/include/kvm/early_printk.h b/tools/kvm/include/kvm/early_printk.h
new file mode 100644 (file)
index 0000000..3ff49c0
--- /dev/null
@@ -0,0 +1,6 @@
+#ifndef KVM__EARLY_PRINTK_H
+#define KVM__EARLY_PRINTK_H
+
+void early_printk__init(void);
+
+#endif /* KVM__EARLY_PRINTK_H */
diff --git a/tools/kvm/include/kvm/ioport.h b/tools/kvm/include/kvm/ioport.h
new file mode 100644 (file)
index 0000000..3721910
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef KVM__IOPORT_H
+#define KVM__IOPORT_H
+
+#include <stdbool.h>
+#include <stdint.h>
+
+struct kvm;
+
+struct ioport_operations {
+       bool (*io_in)(struct kvm *self, uint16_t port, void *data, int size, uint32_t count);
+       bool (*io_out)(struct kvm *self, uint16_t port, void *data, int size, uint32_t count);
+};
+
+void ioport__register(uint16_t port, struct ioport_operations *ops);
+
+#endif /* KVM__IOPORT_H */
index 31324b3fe4772bb4bc57c0b675e09f7176db0353..8930ccb0f61addb31bc2d26135129d66270a05d1 100644 (file)
@@ -1,13 +1,11 @@
+#include "kvm/ioport.h"
+
 #include "kvm/kvm.h"
 
+#include <assert.h>
 #include <limits.h>
 #include <stdio.h>
 
-struct ioport_operations {
-       bool (*io_in)(struct kvm *self, uint16_t port, void *data, int size, uint32_t count);
-       bool (*io_out)(struct kvm *self, uint16_t port, void *data, int size, uint32_t count);
-};
-
 static uint8_t ioport_to_uint8(void *data)
 {
        uint8_t *p = data;
@@ -81,12 +79,23 @@ static struct ioport_operations *ioport_ops[USHRT_MAX] = {
        [0x3D4]         = &dummy_read_write_ioport_ops,
        [0x3D5]         = &dummy_write_only_ioport_ops,
 
+       /* PORT 03F8-03FF - Serial port (8250,8250A,8251,16450,16550,16550A,etc.) COM1 */
+       [0x03F9]        = &dummy_read_write_ioport_ops,
+       [0x03FA]        = &dummy_read_write_ioport_ops,
+       [0x03FB]        = &dummy_read_write_ioport_ops,
+       [0x03FC]        = &dummy_read_write_ioport_ops,
+
        /* PORT 0CF8-0CFF - PCI Configuration Mechanism 1 - Configuration Registers */
        [0x0CF8]        = &dummy_write_only_ioport_ops,
        [0x0CFC]        = &dummy_read_write_ioport_ops,
        [0x0CFE]        = &dummy_read_write_ioport_ops,
 };
 
+void ioport__register(uint16_t port, struct ioport_operations *ops)
+{
+       ioport_ops[port]        = ops;
+}
+
 static const char *to_direction(int direction)
 {
        if (direction == KVM_EXIT_IO_IN)
index b6414e77f474ddf0409902624664206ce7252f46..61253fdecd041798cde811f5fdf95ca4a7109172 100644 (file)
@@ -1,5 +1,6 @@
 #include "kvm/kvm.h"
 
+#include "kvm/early_printk.h"
 #include "kvm/util.h"
 
 #include <inttypes.h>
@@ -58,6 +59,8 @@ int main(int argc, char *argv[])
        if (single_step)
                kvm__enable_singlestep(kvm);
 
+       early_printk__init();
+
        for (;;) {
                kvm__run(kvm);