Greg Kroah-Hartman | e3b3d0f | 2017-11-06 18:11:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
David Gibson | d5e5491 | 2008-11-05 14:20:17 +0000 | [diff] [blame] | 2 | /* |
| 3 | * udbg interface to hvc_console.c |
| 4 | * |
| 5 | * (C) Copyright David Gibson, IBM Corporation 2008. |
David Gibson | d5e5491 | 2008-11-05 14:20:17 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <linux/console.h> |
| 9 | #include <linux/delay.h> |
| 10 | #include <linux/err.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/types.h> |
| 14 | #include <linux/irq.h> |
| 15 | |
| 16 | #include <asm/udbg.h> |
| 17 | |
| 18 | #include "hvc_console.h" |
| 19 | |
| 20 | struct hvc_struct *hvc_udbg_dev; |
| 21 | |
| 22 | static int hvc_udbg_put(uint32_t vtermno, const char *buf, int count) |
| 23 | { |
| 24 | int i; |
| 25 | |
Benjamin Herrenschmidt | 7d3d897 | 2012-03-14 18:37:04 +1100 | [diff] [blame] | 26 | for (i = 0; i < count && udbg_putc; i++) |
David Gibson | d5e5491 | 2008-11-05 14:20:17 +0000 | [diff] [blame] | 27 | udbg_putc(buf[i]); |
| 28 | |
| 29 | return i; |
| 30 | } |
| 31 | |
| 32 | static int hvc_udbg_get(uint32_t vtermno, char *buf, int count) |
| 33 | { |
| 34 | int i, c; |
| 35 | |
| 36 | if (!udbg_getc_poll) |
| 37 | return 0; |
| 38 | |
| 39 | for (i = 0; i < count; i++) { |
| 40 | if ((c = udbg_getc_poll()) == -1) |
| 41 | break; |
| 42 | buf[i] = c; |
| 43 | } |
| 44 | |
| 45 | return i; |
| 46 | } |
| 47 | |
Rusty Russell | 1dff399 | 2009-11-28 12:20:26 +0530 | [diff] [blame] | 48 | static const struct hv_ops hvc_udbg_ops = { |
David Gibson | d5e5491 | 2008-11-05 14:20:17 +0000 | [diff] [blame] | 49 | .get_chars = hvc_udbg_get, |
| 50 | .put_chars = hvc_udbg_put, |
| 51 | }; |
| 52 | |
| 53 | static int __init hvc_udbg_init(void) |
| 54 | { |
| 55 | struct hvc_struct *hp; |
| 56 | |
Benjamin Herrenschmidt | 7d3d897 | 2012-03-14 18:37:04 +1100 | [diff] [blame] | 57 | if (!udbg_putc) |
| 58 | return -ENODEV; |
| 59 | |
David Gibson | d5e5491 | 2008-11-05 14:20:17 +0000 | [diff] [blame] | 60 | BUG_ON(hvc_udbg_dev); |
| 61 | |
Alan Cox | d4e33fa | 2012-01-26 17:44:09 +0000 | [diff] [blame] | 62 | hp = hvc_alloc(0, 0, &hvc_udbg_ops, 16); |
David Gibson | d5e5491 | 2008-11-05 14:20:17 +0000 | [diff] [blame] | 63 | if (IS_ERR(hp)) |
| 64 | return PTR_ERR(hp); |
| 65 | |
| 66 | hvc_udbg_dev = hp; |
| 67 | |
| 68 | return 0; |
| 69 | } |
Paul Gortmaker | 4fedd0b | 2014-01-15 16:35:43 -0500 | [diff] [blame] | 70 | device_initcall(hvc_udbg_init); |
David Gibson | d5e5491 | 2008-11-05 14:20:17 +0000 | [diff] [blame] | 71 | |
| 72 | static int __init hvc_udbg_console_init(void) |
| 73 | { |
Benjamin Herrenschmidt | 7d3d897 | 2012-03-14 18:37:04 +1100 | [diff] [blame] | 74 | if (!udbg_putc) |
| 75 | return -ENODEV; |
| 76 | |
David Gibson | d5e5491 | 2008-11-05 14:20:17 +0000 | [diff] [blame] | 77 | hvc_instantiate(0, 0, &hvc_udbg_ops); |
| 78 | add_preferred_console("hvc", 0, NULL); |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | console_initcall(hvc_udbg_console_init); |