Greg Kroah-Hartman | e3b3d0f | 2017-11-06 18:11:51 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 2 | /* |
| 3 | * IBM RTAS driver interface to hvc_console.c |
| 4 | * |
| 5 | * (C) Copyright IBM Corporation 2001-2005 |
| 6 | * (C) Copyright Red Hat, Inc. 2005 |
| 7 | * |
| 8 | * Author(s): Maximino Augilar <IBM STI Design Center> |
| 9 | * : Ryan S. Arnold <rsa@us.ibm.com> |
| 10 | * : Utz Bacher <utz.bacher@de.ibm.com> |
| 11 | * : David Woodhouse <dwmw2@infradead.org> |
| 12 | * |
| 13 | * inspired by drivers/char/hvc_console.c |
| 14 | * written by Anton Blanchard and Paul Mackerras |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <linux/console.h> |
| 18 | #include <linux/delay.h> |
| 19 | #include <linux/err.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/moduleparam.h> |
| 22 | #include <linux/types.h> |
| 23 | |
| 24 | #include <asm/irq.h> |
| 25 | #include <asm/rtas.h> |
| 26 | #include "hvc_console.h" |
| 27 | |
| 28 | #define hvc_rtas_cookie 0x67781e15 |
| 29 | struct hvc_struct *hvc_rtas_dev; |
| 30 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 31 | static int rtascons_put_char_token = RTAS_UNKNOWN_SERVICE; |
| 32 | static int rtascons_get_char_token = RTAS_UNKNOWN_SERVICE; |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 33 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 34 | static inline int hvc_rtas_write_console(uint32_t vtermno, const char *buf, |
| 35 | int count) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 36 | { |
| 37 | int i; |
| 38 | |
| 39 | for (i = 0; i < count; i++) { |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 40 | if (rtas_call(rtascons_put_char_token, 1, 1, NULL, buf[i])) |
| 41 | break; |
| 42 | } |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 43 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 44 | return i; |
| 45 | } |
| 46 | |
| 47 | static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count) |
| 48 | { |
| 49 | int i, c; |
| 50 | |
| 51 | for (i = 0; i < count; i++) { |
| 52 | if (rtas_call(rtascons_get_char_token, 0, 2, &c)) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 53 | break; |
| 54 | |
| 55 | buf[i] = c; |
| 56 | } |
| 57 | |
| 58 | return i; |
| 59 | } |
| 60 | |
Rusty Russell | 1dff399 | 2009-11-28 12:20:26 +0530 | [diff] [blame] | 61 | static const struct hv_ops hvc_rtas_get_put_ops = { |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 62 | .get_chars = hvc_rtas_read_console, |
| 63 | .put_chars = hvc_rtas_write_console, |
| 64 | }; |
| 65 | |
Adrian Bunk | 1407b3d | 2008-02-14 08:30:57 +1100 | [diff] [blame] | 66 | static int __init hvc_rtas_init(void) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 67 | { |
| 68 | struct hvc_struct *hp; |
| 69 | |
| 70 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 71 | rtascons_put_char_token = rtas_token("put-term-char"); |
| 72 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 73 | return -EIO; |
| 74 | |
| 75 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 76 | rtascons_get_char_token = rtas_token("get-term-char"); |
| 77 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 78 | return -EIO; |
| 79 | |
| 80 | BUG_ON(hvc_rtas_dev); |
| 81 | |
| 82 | /* Allocate an hvc_struct for the console device we instantiated |
| 83 | * earlier. Save off hp so that we can return it on exit */ |
Alan Cox | d4e33fa | 2012-01-26 17:44:09 +0000 | [diff] [blame] | 84 | hp = hvc_alloc(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops, 16); |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 85 | if (IS_ERR(hp)) |
| 86 | return PTR_ERR(hp); |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 87 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 88 | hvc_rtas_dev = hp; |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 89 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 90 | return 0; |
| 91 | } |
Paul Gortmaker | 4fedd0b | 2014-01-15 16:35:43 -0500 | [diff] [blame] | 92 | device_initcall(hvc_rtas_init); |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 93 | |
| 94 | /* This will happen prior to module init. There is no tty at this time? */ |
Stephen Rothwell | a6dfe1d | 2007-07-22 00:31:28 +1000 | [diff] [blame] | 95 | static int __init hvc_rtas_console_init(void) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 96 | { |
| 97 | rtascons_put_char_token = rtas_token("put-term-char"); |
| 98 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 99 | return -EIO; |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 100 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 101 | rtascons_get_char_token = rtas_token("get-term-char"); |
| 102 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 103 | return -EIO; |
| 104 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 105 | hvc_instantiate(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops); |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 106 | add_preferred_console("hvc", 0, NULL); |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 107 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 108 | return 0; |
| 109 | } |
| 110 | console_initcall(hvc_rtas_console_init); |