2017-11-07 00:11:51 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2008-11-05 21:20:17 +07:00
|
|
|
/*
|
|
|
|
* udbg interface to hvc_console.c
|
|
|
|
*
|
|
|
|
* (C) Copyright David Gibson, IBM Corporation 2008.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
|
|
|
|
#include <asm/udbg.h>
|
|
|
|
|
|
|
|
#include "hvc_console.h"
|
|
|
|
|
|
|
|
struct hvc_struct *hvc_udbg_dev;
|
|
|
|
|
|
|
|
static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-03-14 14:37:04 +07:00
|
|
|
for (i = 0; i < count && udbg_putc; i++)
|
2008-11-05 21:20:17 +07:00
|
|
|
udbg_putc(buf[i]);
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hvc_udbg_get(uint32_t vtermno, char *buf, int count)
|
|
|
|
{
|
|
|
|
int i, c;
|
|
|
|
|
|
|
|
if (!udbg_getc_poll)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if ((c = udbg_getc_poll()) == -1)
|
|
|
|
break;
|
|
|
|
buf[i] = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2009-11-28 13:50:26 +07:00
|
|
|
static const struct hv_ops hvc_udbg_ops = {
|
2008-11-05 21:20:17 +07:00
|
|
|
.get_chars = hvc_udbg_get,
|
|
|
|
.put_chars = hvc_udbg_put,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init hvc_udbg_init(void)
|
|
|
|
{
|
|
|
|
struct hvc_struct *hp;
|
|
|
|
|
2012-03-14 14:37:04 +07:00
|
|
|
if (!udbg_putc)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2008-11-05 21:20:17 +07:00
|
|
|
BUG_ON(hvc_udbg_dev);
|
|
|
|
|
2012-01-27 00:44:09 +07:00
|
|
|
hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16);
|
2008-11-05 21:20:17 +07:00
|
|
|
if (IS_ERR(hp))
|
|
|
|
return PTR_ERR(hp);
|
|
|
|
|
|
|
|
hvc_udbg_dev = hp;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2014-01-16 04:35:43 +07:00
|
|
|
device_initcall(hvc_udbg_init);
|
2008-11-05 21:20:17 +07:00
|
|
|
|
|
|
|
static int __init hvc_udbg_console_init(void)
|
|
|
|
{
|
2012-03-14 14:37:04 +07:00
|
|
|
if (!udbg_putc)
|
|
|
|
return -ENODEV;
|
|
|
|
|
2008-11-05 21:20:17 +07:00
|
|
|
hvc_instantiate(0, 0, &hvc_udbg_ops);
|
|
|
|
add_preferred_console("hvc", 0, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
console_initcall(hvc_udbg_console_init);
|