PERFORCE change 208334 for review
Robert Watson
rwatson at FreeBSD.org
Wed Mar 21 21:30:12 UTC 2012
http://p4web.freebsd.org/@@208334?ac=10
Change 208334 by rwatson at rwatson_svr_ctsrd_mipsbuild on 2012/03/21 21:29:41
Adapt the Deimos gxemul console driver to FreeBSD, using it to
implement a low-level console. This appears to work with local
gxemul, but a tty driver is not yet implemented.
Affected files ...
.. //depot/projects/ctsrd/beribsd/src/sys/mips/beri/gxemul_uart.c#2 edit
Differences ...
==== //depot/projects/ctsrd/beribsd/src/sys/mips/beri/gxemul_uart.c#2 (text+ko) ====
@@ -1,5 +1,5 @@
/*-
- * Copyright (c) 2011 Robert N. M. Watson
+ * Copyright (c) 2011-2012 Robert N. M. Watson
* All rights reserved.
*
* This software was developed by SRI International and the University of
@@ -28,10 +28,67 @@
* SUCH DAMAGE.
*/
-#include "include/gxemul.h"
-#include "include/mips.h"
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/cons.h>
+#include <sys/endian.h>
+#include <sys/kdb.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/tty.h>
+
+#include <ddb/ddb.h>
+
+/*
+ * Low-level console driver functions.
+ */
+static cn_probe_t gxemul_uart_cnprobe;
+static cn_init_t gxemul_uart_cninit;
+static cn_term_t gxemul_uart_cnterm;
+static cn_getc_t gxemul_uart_cngetc;
+static cn_putc_t gxemul_uart_cnputc;
+static cn_grab_t gxemul_uart_cngrab;
+static cn_ungrab_t gxemul_uart_cnungrab;
+
+/*
+ * I/O routines lifted from Deimos.
+ *
+ * XXXRW: Should be using FreeBSD's bus routines here.
+ */
+#define MIPS_XKPHYS_UNCACHED_BASE 0x9000000000000000
+
+typedef uint64_t paddr_t;
+typedef uint64_t vaddr_t;
+
+static inline vaddr_t
+mips_phys_to_uncached(paddr_t phys)
+{
+
+ return (phys | MIPS_XKPHYS_UNCACHED_BASE);
+}
+
+static inline uint8_t
+mips_ioread_uint8(vaddr_t vaddr)
+{
+ uint8_t v;
+
+ __asm__ __volatile__ ("lbu %0, 0(%1)" : "=r" (v) : "r" (vaddr));
+ return (v);
+}
+
+static inline void
+mips_iowrite_uint8(vaddr_t vaddr, uint8_t v)
+{
+
+ __asm__ __volatile__ ("sb %0, 0(%1)" : : "r" (v), "r" (vaddr));
+}
-#include "dev/uart/uart.h"
+/*
+ * gxemul-specific constants.
+ */
+#define GXEMUL_CONS_BASE 0x10000000 /* gxemul console device. */
/*
* Routines for interacting with the gxemul test console. Programming details
@@ -54,7 +111,7 @@
* Low-level read and write routines.
*/
static inline uint8_t
-cons_data_read(void)
+gxemul_uart_data_read(void)
{
return (mips_ioread_uint8(mips_phys_to_uncached(GXEMUL_CONS_BASE +
@@ -62,54 +119,102 @@
}
static inline void
-cons_data_write(uint8_t v)
+gxemul_uart_data_write(uint8_t v)
{
mips_iowrite_uint8(mips_phys_to_uncached(GXEMUL_CONS_BASE +
GXEMUL_PUTGETCHAR_OFF), v);
}
-int
-uart_writable(void)
+static int
+gxemul_uart_writable(void)
{
return (1);
}
-int
-uart_readable(void)
+static int
+gxemul_uart_readable(void)
{
uint32_t v;
if (buffer_valid)
return (1);
- v = cons_data_read();
+ v = gxemul_uart_data_read();
if (v != 0) {
buffer_valid = 1;
buffer_data = v;
+ return (1);
}
return (0);
}
-char
-uart_read(void)
+static void
+gxemul_uart_write(char ch)
+{
+
+ while (!gxemul_uart_writable());
+ gxemul_uart_data_write(ch);
+}
+
+static char
+gxemul_uart_read(void)
{
- while (!uart_readable());
+ while (!gxemul_uart_readable());
buffer_valid = 0;
return (buffer_data);
}
-void
-uart_write(char ch)
+/*
+ * Implementation of a FreeBSD low-level, polled console driver.
+ */
+static void
+gxemul_uart_cnprobe(struct consdev *cp)
+{
+
+ sprintf(cp->cn_name, "gxemul_uart");
+ cp->cn_pri = CN_NORMAL;
+}
+
+static void
+gxemul_uart_cninit(struct consdev *cp)
+{
+
+}
+
+static void
+gxemul_uart_cnterm(struct consdev *cp)
+{
+
+}
+
+static int
+gxemul_uart_cngetc(struct consdev *cp)
+{
+ int ret;
+
+ ret = gxemul_uart_read();
+ return (ret);
+}
+
+static void
+gxemul_uart_cnputc(struct consdev *cp, int c)
+{
+
+ gxemul_uart_write(c);
+}
+
+static void
+gxemul_uart_cngrab(struct consdev *cp)
{
- cons_data_write(ch);
}
-void
-uart_init(void)
+static void
+gxemul_uart_cnungrab(struct consdev *cp)
{
- /* Nothing required. */
}
+
+CONSOLE_DRIVER(gxemul_uart);
More information about the p4-projects
mailing list