Index: boot/arch/sparc64/Makefile.inc
===================================================================
--- boot/arch/sparc64/Makefile.inc	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ boot/arch/sparc64/Makefile.inc	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -39,4 +39,9 @@
 EXTRA_CFLAGS = -mcpu=ultrasparc -m64 -mno-fpu -mcmodel=medlow
 
+ifeq ($(PROCESSOR), sun4v)
+RD_DRVS_ESSENTIAL += \
+	platform/sun4v \
+	char/sun4v-con
+else
 RD_DRVS_ESSENTIAL += \
 	platform/sun4u \
@@ -48,4 +53,5 @@
 RD_DRV_CFG += \
 	bus/isa
+endif
 
 SOURCES = \
Index: uspace/Makefile
===================================================================
--- uspace/Makefile	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ uspace/Makefile	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -161,4 +161,5 @@
 	drv/char/ps2mouse \
 	drv/char/ski-con \
+	drv/char/sun4v-con \
 	drv/char/xtkbd \
 	drv/test/test1 \
@@ -183,4 +184,5 @@
 	drv/platform/pc \
 	drv/platform/ski \
+	drv/platform/sun4v \
 	drv/time/cmos-rtc
 
Index: uspace/drv/char/msim-con/msim-con.c
===================================================================
--- uspace/drv/char/msim-con/msim-con.c	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ uspace/drv/char/msim-con/msim-con.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -68,5 +68,5 @@
 	msim_cmds
 };
-#include <stdio.h>
+
 static void msim_irq_handler(ipc_callid_t iid, ipc_call_t *call, void *arg)
 {
@@ -75,5 +75,5 @@
 
 	c = IPC_GET_ARG2(*call);
-	printf("key=%d\n", c);
+
 	if (con->client_sess != NULL) {
 		async_exch_t *exch = async_exchange_begin(con->client_sess);
@@ -90,5 +90,4 @@
 	int rc;
 
-	printf("msim_con_add\n");
 	fun = ddf_fun_create(con->dev, fun_exposed, "a");
 	if (fun == NULL) {
@@ -112,6 +111,4 @@
 	}
 
-	printf("msim_con_add: irq subscribe\n");
-
 	msim_ranges[0].base = paddr;
 	msim_cmds[0].addr = (void *) paddr;
@@ -119,5 +116,4 @@
 	subscribed = true;
 
-	printf("msim_con_add: bind\n");
 	rc = ddf_fun_bind(fun);
 	if (rc != EOK) {
@@ -126,5 +122,4 @@
 	}
 
-	printf("msim_con_add: DONE\n");
 	return EOK;
 error:
@@ -162,6 +157,4 @@
 	async_answer_0(iid, EOK);
 
-	printf("msim_con_connection\n");
-
 	con = (msim_con_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg));
 
@@ -185,5 +178,4 @@
 			} else
 				async_answer_0(callid, ELIMIT);
-			printf("msim_con_connection: set client_sess\n");
 		} else {
 			switch (method) {
Index: uspace/drv/char/sun4v-con/Makefile
===================================================================
--- uspace/drv/char/sun4v-con/Makefile	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
+++ uspace/drv/char/sun4v-con/Makefile	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -0,0 +1,37 @@
+#
+# Copyright (c) 2017 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../../..
+LIBS = drv
+BINARY = sun4v-con
+
+SOURCES = \
+	main.c \
+	sun4v-con.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/char/sun4v-con/main.c
===================================================================
--- uspace/drv/char/sun4v-con/main.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
+++ uspace/drv/char/sun4v-con/main.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file Sun4v console driver
+ */
+
+#include <ddf/driver.h>
+#include <ddf/log.h>
+#include <errno.h>
+#include <stdio.h>
+
+#include "sun4v-con.h"
+
+#define NAME  "sun4v-con"
+
+static int sun4v_con_dev_add(ddf_dev_t *dev);
+static int sun4v_con_dev_remove(ddf_dev_t *dev);
+static int sun4v_con_dev_gone(ddf_dev_t *dev);
+static int sun4v_con_fun_online(ddf_fun_t *fun);
+static int sun4v_con_fun_offline(ddf_fun_t *fun);
+
+static driver_ops_t driver_ops = {
+	.dev_add = sun4v_con_dev_add,
+	.dev_remove = sun4v_con_dev_remove,
+	.dev_gone = sun4v_con_dev_gone,
+	.fun_online = sun4v_con_fun_online,
+	.fun_offline = sun4v_con_fun_offline
+};
+
+static driver_t sun4v_con_driver = {
+	.name = NAME,
+	.driver_ops = &driver_ops
+};
+
+static int sun4v_con_dev_add(ddf_dev_t *dev)
+{
+	sun4v_con_t *sun4v_con;
+
+        ddf_msg(LVL_DEBUG, "sun4v_con_dev_add(%p)", dev);
+	sun4v_con = ddf_dev_data_alloc(dev, sizeof(sun4v_con_t));
+	if (sun4v_con == NULL) {
+		ddf_msg(LVL_ERROR, "Failed allocating soft state.");
+		return ENOMEM;
+	}
+
+	sun4v_con->dev = dev;
+
+	return sun4v_con_add(sun4v_con);
+}
+
+static int sun4v_con_dev_remove(ddf_dev_t *dev)
+{
+        sun4v_con_t *sun4v_con = (sun4v_con_t *)ddf_dev_data_get(dev);
+
+        ddf_msg(LVL_DEBUG, "sun4v_con_dev_remove(%p)", dev);
+
+        return sun4v_con_remove(sun4v_con);
+}
+
+static int sun4v_con_dev_gone(ddf_dev_t *dev)
+{
+        sun4v_con_t *sun4v_con = (sun4v_con_t *)ddf_dev_data_get(dev);
+
+        ddf_msg(LVL_DEBUG, "sun4v_con_dev_gone(%p)", dev);
+
+        return sun4v_con_gone(sun4v_con);
+}
+
+static int sun4v_con_fun_online(ddf_fun_t *fun)
+{
+        ddf_msg(LVL_DEBUG, "sun4v_con_fun_online()");
+        return ddf_fun_online(fun);
+}
+
+static int sun4v_con_fun_offline(ddf_fun_t *fun)
+{
+        ddf_msg(LVL_DEBUG, "sun4v_con_fun_offline()");
+        return ddf_fun_offline(fun);
+}
+
+int main(int argc, char *argv[])
+{
+	printf(NAME ": Sun4v console driver\n");
+	ddf_log_init(NAME);
+	return ddf_driver_main(&sun4v_con_driver);
+}
+
+/** @}
+ */
Index: uspace/drv/char/sun4v-con/sun4v-con.c
===================================================================
--- uspace/drv/char/sun4v-con/sun4v-con.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
+++ uspace/drv/char/sun4v-con/sun4v-con.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -0,0 +1,220 @@
+/*
+ * Copyright (c) 2008 Pavel Rimsky
+ * Copyright (c) 2011 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file Sun4v console driver
+ */
+
+#include <as.h>
+#include <async.h>
+#include <ddf/log.h>
+#include <ddi.h>
+#include <errno.h>
+#include <ipc/char.h>
+#include <stdbool.h>
+#include <sysinfo.h>
+#include <thread.h>
+
+#include "sun4v-con.h"
+
+static void sun4v_con_connection(ipc_callid_t, ipc_call_t *, void *);
+
+#define POLL_INTERVAL  10000
+
+/*
+ * Kernel counterpart of the driver pushes characters (it has read) here.
+ * Keep in sync with the definition from
+ * kernel/arch/sparc64/src/drivers/niagara.c.
+ */
+#define INPUT_BUFFER_SIZE  ((PAGE_SIZE) - 2 * 8)
+
+typedef volatile struct {
+	uint64_t write_ptr;
+	uint64_t read_ptr;
+	char data[INPUT_BUFFER_SIZE];
+} __attribute__((packed)) __attribute__((aligned(PAGE_SIZE))) *input_buffer_t;
+
+/* virtual address of the shared buffer */
+static input_buffer_t input_buffer;
+
+static void sun4v_thread_impl(void *arg);
+
+static void sun4v_con_putchar(sun4v_con_t *con, uint8_t data)
+{
+	(void) con;
+	(void) data;
+}
+
+/** Add sun4v console device. */
+int sun4v_con_add(sun4v_con_t *con)
+{
+	ddf_fun_t *fun = NULL;
+	int rc;
+
+	input_buffer = (input_buffer_t) AS_AREA_ANY;
+
+	fun = ddf_fun_create(con->dev, fun_exposed, "a");
+	if (fun == NULL) {
+		ddf_msg(LVL_ERROR, "Error creating function 'a'.");
+		rc = ENOMEM;
+		goto error;
+	}
+
+	ddf_fun_set_conn_handler(fun, sun4v_con_connection);
+
+	sysarg_t paddr;
+	rc = sysinfo_get_value("niagara.inbuf.address", &paddr);
+	if (rc != EOK) {
+		ddf_msg(LVL_ERROR, "niagara.inbuf.address not set (%d)", rc);
+		goto error;
+	}
+
+	rc = physmem_map(paddr, 1, AS_AREA_READ | AS_AREA_WRITE,
+	    (void *) &input_buffer);
+	if (rc != EOK) {
+		ddf_msg(LVL_ERROR, "Error mapping memory: %d", rc);
+		goto error;
+	}
+
+	thread_id_t tid;
+	rc = thread_create(sun4v_thread_impl, con, "kbd_poll", &tid);
+	if (rc != EOK)
+		goto error;
+
+	rc = ddf_fun_bind(fun);
+	if (rc != EOK) {
+		ddf_msg(LVL_ERROR, "Error binding function 'a'.");
+		goto error;
+	}
+
+	return EOK;
+error:
+	/* XXX Clean up thread */
+
+	if (input_buffer != (input_buffer_t) AS_AREA_ANY)
+		physmem_unmap((void *) input_buffer);
+
+	if (fun != NULL)
+		ddf_fun_destroy(fun);
+
+	return rc;
+}
+
+/** Remove sun4v console device */
+int sun4v_con_remove(sun4v_con_t *con)
+{
+	return ENOTSUP;
+}
+
+/** Msim console device gone */
+int sun4v_con_gone(sun4v_con_t *con)
+{
+	return ENOTSUP;
+}
+
+/**
+ * Called regularly by the polling thread. Reads codes of all the
+ * pressed keys from the buffer.
+ */
+static void sun4v_key_pressed(sun4v_con_t *con)
+{
+	char c;
+
+	while (input_buffer->read_ptr != input_buffer->write_ptr) {
+		c = input_buffer->data[input_buffer->read_ptr];
+		input_buffer->read_ptr =
+		    ((input_buffer->read_ptr) + 1) % INPUT_BUFFER_SIZE;
+		if (con->client_sess != NULL) {
+			async_exch_t *exch = async_exchange_begin(con->client_sess);
+			async_msg_1(exch, CHAR_NOTIF_BYTE, c);
+			async_exchange_end(exch);
+		}
+		(void) c;
+	}
+}
+
+/**
+ * Thread to poll Sun4v console for keypresses.
+ */
+static void sun4v_thread_impl(void *arg)
+{
+	sun4v_con_t *con = (sun4v_con_t *) arg;
+
+	while (true) {
+		sun4v_key_pressed(con);
+		thread_usleep(POLL_INTERVAL);
+	}
+}
+
+/** Character device connection handler. */
+static void sun4v_con_connection(ipc_callid_t iid, ipc_call_t *icall,
+    void *arg)
+{
+	sun4v_con_t *con;
+
+	/* Answer the IPC_M_CONNECT_ME_TO call. */
+	async_answer_0(iid, EOK);
+
+	con = (sun4v_con_t *)ddf_dev_data_get(ddf_fun_get_dev((ddf_fun_t *)arg));
+
+	while (true) {
+		ipc_call_t call;
+		ipc_callid_t callid = async_get_call(&call);
+		sysarg_t method = IPC_GET_IMETHOD(call);
+
+		if (!method) {
+			/* The other side has hung up. */
+			async_answer_0(callid, EOK);
+			return;
+		}
+
+		async_sess_t *sess =
+		    async_callback_receive_start(EXCHANGE_SERIALIZE, &call);
+		if (sess != NULL) {
+			if (con->client_sess == NULL) {
+				con->client_sess = sess;
+				async_answer_0(callid, EOK);
+			} else
+				async_answer_0(callid, ELIMIT);
+		} else {
+			switch (method) {
+			case CHAR_WRITE_BYTE:
+				ddf_msg(LVL_DEBUG, "Write %" PRIun " to device\n",
+				    IPC_GET_ARG1(call));
+				sun4v_con_putchar(con, (uint8_t) IPC_GET_ARG1(call));
+				async_answer_0(callid, EOK);
+				break;
+			default:
+				async_answer_0(callid, EINVAL);
+			}
+		}
+	}
+}
+
+/** @}
+ */
Index: uspace/drv/char/sun4v-con/sun4v-con.h
===================================================================
--- uspace/drv/char/sun4v-con/sun4v-con.h	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
+++ uspace/drv/char/sun4v-con/sun4v-con.h	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup genarch
+ * @{
+ */
+/** @file
+ */
+
+#ifndef SUN4V_CON_H
+#define SUN4V_CON_H
+
+#include <async.h>
+#include <ddf/driver.h>
+#include <loc.h>
+#include <stdint.h>
+
+/** Sun4v console */
+typedef struct {
+	async_sess_t *client_sess;
+	ddf_dev_t *dev;
+} sun4v_con_t;
+
+extern int sun4v_con_init(sun4v_con_t *);
+extern void sun4v_con_write(uint8_t data);
+
+
+extern int sun4v_con_add(sun4v_con_t *);
+extern int sun4v_con_remove(sun4v_con_t *);
+extern int sun4v_con_gone(sun4v_con_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/drv/char/sun4v-con/sun4v-con.ma
===================================================================
--- uspace/drv/char/sun4v-con/sun4v-con.ma	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
+++ uspace/drv/char/sun4v-con/sun4v-con.ma	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -0,0 +1,1 @@
+10 sun4v/console
Index: uspace/drv/platform/sun4u/sun4u.ma
===================================================================
--- uspace/drv/platform/sun4u/sun4u.ma	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ uspace/drv/platform/sun4u/sun4u.ma	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -1,1 +1,2 @@
 10 platform/sun4u
+10 platform/sun4v
Index: uspace/drv/platform/sun4v/Makefile
===================================================================
--- uspace/drv/platform/sun4v/Makefile	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
+++ uspace/drv/platform/sun4v/Makefile	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -0,0 +1,36 @@
+#
+# Copyright (c) 2017 Jiri Svoboda
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+USPACE_PREFIX = ../../..
+LIBS = drv
+BINARY = sun4v
+
+SOURCES = \
+	sun4v.c
+
+include $(USPACE_PREFIX)/Makefile.common
Index: uspace/drv/platform/sun4v/sun4v.c
===================================================================
--- uspace/drv/platform/sun4v/sun4v.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
+++ uspace/drv/platform/sun4v/sun4v.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/**
+ * @defgroup sun4v platform driver.
+ * @brief Sun4v platform driver.
+ * @{
+ */
+
+/** @file
+ */
+
+#include <assert.h>
+#include <stdio.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <ddf/driver.h>
+#include <ddf/log.h>
+
+#define NAME "sun4v"
+
+static int sun4v_dev_add(ddf_dev_t *dev);
+
+static driver_ops_t sun4v_ops = {
+	.dev_add = &sun4v_dev_add
+};
+
+static driver_t sun4v_driver = {
+	.name = NAME,
+	.driver_ops = &sun4v_ops
+};
+
+static int sun4v_add_fun(ddf_dev_t *dev, const char *name, const char *str_match_id)
+{
+	ddf_msg(LVL_NOTE, "Adding function '%s'.", name);
+
+	ddf_fun_t *fnode = NULL;
+	int rc;
+
+	/* Create new device. */
+	fnode = ddf_fun_create(dev, fun_inner, name);
+	if (fnode == NULL) {
+		ddf_msg(LVL_ERROR, "Error creating function '%s'", name);
+		rc = ENOMEM;
+		goto error;
+	}
+
+	/* Add match ID */
+	rc = ddf_fun_add_match_id(fnode, str_match_id, 100);
+	if (rc != EOK) {
+		ddf_msg(LVL_ERROR, "Error adding match ID");
+		goto error;
+	}
+
+	/* Register function. */
+	if (ddf_fun_bind(fnode) != EOK) {
+		ddf_msg(LVL_ERROR, "Failed binding function %s.", name);
+		goto error;
+	}
+
+	return EOK;
+
+error:
+	if (fnode != NULL)
+		ddf_fun_destroy(fnode);
+
+	return rc;
+}
+
+static int sun4v_add_functions(ddf_dev_t *dev)
+{
+	int rc;
+
+	rc = sun4v_add_fun(dev, "console", "sun4v/console");
+	if (rc != EOK)
+		return rc;
+
+	return EOK;
+}
+
+/** Add device. */
+static int sun4v_dev_add(ddf_dev_t *dev)
+{
+	ddf_msg(LVL_NOTE, "sun4v_dev_add, device handle = %d",
+	    (int)ddf_dev_get_handle(dev));
+
+	/* Register functions. */
+	if (sun4v_add_functions(dev)) {
+		ddf_msg(LVL_ERROR, "Failed to add functions for sun4v platform.");
+	}
+
+	return EOK;
+}
+
+int main(int argc, char *argv[])
+{
+	int rc;
+
+	printf(NAME ": Sun4v platform driver\n");
+
+	rc = ddf_log_init(NAME);
+	if (rc != EOK) {
+		printf(NAME ": Failed initializing logging service");
+		return 1;
+	}
+
+	return ddf_driver_main(&sun4v_driver);
+}
+
+/**
+ * @}
+ */
Index: uspace/drv/platform/sun4v/sun4v.ma
===================================================================
--- uspace/drv/platform/sun4v/sun4v.ma	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
+++ uspace/drv/platform/sun4v/sun4v.ma	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -0,0 +1,1 @@
+10 platform/sun4v
Index: uspace/srv/hid/input/Makefile
===================================================================
--- uspace/srv/hid/input/Makefile	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ uspace/srv/hid/input/Makefile	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -40,5 +40,4 @@
 	port/adb_mouse.c \
 	port/chardev.c \
-	port/niagara.c \
 	proto/adb.c \
 	proto/mousedev.c \
Index: uspace/srv/hid/input/input.c
===================================================================
--- uspace/srv/hid/input/input.c	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ uspace/srv/hid/input/input.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -647,5 +647,5 @@
 #endif
 #if defined(UARCH_sparc64) && defined(PROCESSOR_sun4v)
-	kbd_add_dev(&niagara_port, &stty_ctl);
+	kbd_add_dev(&chardev_port, &stty_ctl);
 #endif
 	/* Silence warning on abs32le about kbd_add_dev() being unused */
Index: uspace/srv/hid/input/kbd_port.h
===================================================================
--- uspace/srv/hid/input/kbd_port.h	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ uspace/srv/hid/input/kbd_port.h	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -49,5 +49,4 @@
 extern kbd_port_ops_t adb_port;
 extern kbd_port_ops_t chardev_port;
-extern kbd_port_ops_t niagara_port;
 extern kbd_port_ops_t ns16550_port;
 
Index: uspace/srv/hid/input/port/chardev.c
===================================================================
--- uspace/srv/hid/input/port/chardev.c	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ uspace/srv/hid/input/port/chardev.c	(revision 7aa9430447f0291e544450fa9f31d4ba06a73c7f)
@@ -61,5 +61,5 @@
 	/** S3C24xx UART - Openmoko debug console */
 	"char/s3c24xx_uart",
-	/** Ski console, MSIM console */
+	/** Ski console, MSIM console, Sun4v console */
 	"devices/\\hw\\console\\a"
 };
Index: pace/srv/hid/input/port/niagara.c
===================================================================
--- uspace/srv/hid/input/port/niagara.c	(revision 3a377519d27f1af98ffea0cbb0a8e3ab362b32f6)
+++ 	(revision )
@@ -1,141 +1,0 @@
-/*
- * Copyright (c) 2008 Pavel Rimsky
- * Copyright (c) 2011 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup kbd_port
- * @ingroup  kbd
- * @{
- */
-/** @file
- * @brief Niagara console keyboard port driver.
- */
-
-#include <as.h>
-#include <ddi.h>
-#include <async.h>
-#include <sysinfo.h>
-#include <stdio.h>
-#include <thread.h>
-#include <stdbool.h>
-#include <errno.h>
-#include "../kbd_port.h"
-#include "../kbd.h"
-
-static int niagara_port_init(kbd_dev_t *);
-static void niagara_port_write(uint8_t data);
-
-kbd_port_ops_t niagara_port = {
-	.init = niagara_port_init,
-	.write = niagara_port_write
-};
-
-static kbd_dev_t *kbd_dev;
-
-#define POLL_INTERVAL  10000
-
-/*
- * Kernel counterpart of the driver pushes characters (it has read) here.
- * Keep in sync with the definition from
- * kernel/arch/sparc64/src/drivers/niagara.c.
- */
-#define INPUT_BUFFER_SIZE  ((PAGE_SIZE) - 2 * 8)
-
-typedef volatile struct {
-	uint64_t write_ptr;
-	uint64_t read_ptr;
-	char data[INPUT_BUFFER_SIZE];
-} __attribute__((packed)) __attribute__((aligned(PAGE_SIZE))) *input_buffer_t;
-
-/* virtual address of the shared buffer */
-static input_buffer_t input_buffer = (input_buffer_t) AS_AREA_ANY;
-
-static void niagara_thread_impl(void *arg);
-
-/**
- * Initializes the Niagara driver.
- * Maps the shared buffer and creates the polling thread.
- */
-static int niagara_port_init(kbd_dev_t *kdev)
-{
-	kbd_dev = kdev;
-	
-	sysarg_t paddr;
-	if (sysinfo_get_value("niagara.inbuf.address", &paddr) != EOK)
-		return -1;
-	
-	int rc = physmem_map(paddr, 1, AS_AREA_READ | AS_AREA_WRITE,
-	    (void *) &input_buffer);
-	if (rc != 0) {
-		printf("Niagara: uspace driver couldn't map physical memory: %d\n",
-		    rc);
-		return rc;
-	}
-	
-	thread_id_t tid;
-	rc = thread_create(niagara_thread_impl, NULL, "kbd_poll", &tid);
-	if (rc != 0)
-		return rc;
-	
-	return 0;
-}
-
-static void niagara_port_write(uint8_t data)
-{
-	(void) data;
-}
-
-/**
- * Called regularly by the polling thread. Reads codes of all the
- * pressed keys from the buffer.
- */
-static void niagara_key_pressed(void)
-{
-	char c;
-	
-	while (input_buffer->read_ptr != input_buffer->write_ptr) {
-		c = input_buffer->data[input_buffer->read_ptr];
-		input_buffer->read_ptr =
-		    ((input_buffer->read_ptr) + 1) % INPUT_BUFFER_SIZE;
-		kbd_push_data(kbd_dev, c);
-	}
-}
-
-/**
- * Thread to poll Niagara console for keypresses.
- */
-static void niagara_thread_impl(void *arg)
-{
-	(void) arg;
-
-	while (1) {
-		niagara_key_pressed();
-		thread_usleep(POLL_INTERVAL);
-	}
-}
-/** @}
- */
