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 |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or |
| 19 | * (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 29 | */ |
| 30 | |
| 31 | #include <linux/console.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/err.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/moduleparam.h> |
| 36 | #include <linux/types.h> |
| 37 | |
| 38 | #include <asm/irq.h> |
| 39 | #include <asm/rtas.h> |
| 40 | #include "hvc_console.h" |
| 41 | |
| 42 | #define hvc_rtas_cookie 0x67781e15 |
| 43 | struct hvc_struct *hvc_rtas_dev; |
| 44 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 45 | static int rtascons_put_char_token = RTAS_UNKNOWN_SERVICE; |
| 46 | static int rtascons_get_char_token = RTAS_UNKNOWN_SERVICE; |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 47 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 48 | static inline int hvc_rtas_write_console(uint32_t vtermno, const char *buf, |
| 49 | int count) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 50 | { |
| 51 | int i; |
| 52 | |
| 53 | for (i = 0; i < count; i++) { |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 54 | if (rtas_call(rtascons_put_char_token, 1, 1, NULL, buf[i])) |
| 55 | break; |
| 56 | } |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 57 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 58 | return i; |
| 59 | } |
| 60 | |
| 61 | static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count) |
| 62 | { |
| 63 | int i, c; |
| 64 | |
| 65 | for (i = 0; i < count; i++) { |
| 66 | if (rtas_call(rtascons_get_char_token, 0, 2, &c)) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 67 | break; |
| 68 | |
| 69 | buf[i] = c; |
| 70 | } |
| 71 | |
| 72 | return i; |
| 73 | } |
| 74 | |
Rusty Russell | 1dff399 | 2009-11-28 12:20:26 +0530 | [diff] [blame] | 75 | static const struct hv_ops hvc_rtas_get_put_ops = { |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 76 | .get_chars = hvc_rtas_read_console, |
| 77 | .put_chars = hvc_rtas_write_console, |
| 78 | }; |
| 79 | |
Adrian Bunk | 1407b3d | 2008-02-14 08:30:57 +1100 | [diff] [blame] | 80 | static int __init hvc_rtas_init(void) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 81 | { |
| 82 | struct hvc_struct *hp; |
| 83 | |
| 84 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 85 | rtascons_put_char_token = rtas_token("put-term-char"); |
| 86 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 87 | return -EIO; |
| 88 | |
| 89 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 90 | rtascons_get_char_token = rtas_token("get-term-char"); |
| 91 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 92 | return -EIO; |
| 93 | |
| 94 | BUG_ON(hvc_rtas_dev); |
| 95 | |
| 96 | /* Allocate an hvc_struct for the console device we instantiated |
| 97 | * earlier. Save off hp so that we can return it on exit */ |
Alan Cox | d4e33fa | 2012-01-26 17:44:09 +0000 | [diff] [blame] | 98 | 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] | 99 | if (IS_ERR(hp)) |
| 100 | return PTR_ERR(hp); |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 101 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 102 | hvc_rtas_dev = hp; |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 103 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 104 | return 0; |
| 105 | } |
Paul Gortmaker | 4fedd0b | 2014-01-15 16:35:43 -0500 | [diff] [blame] | 106 | device_initcall(hvc_rtas_init); |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 107 | |
| 108 | /* 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] | 109 | static int __init hvc_rtas_console_init(void) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 110 | { |
| 111 | rtascons_put_char_token = rtas_token("put-term-char"); |
| 112 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 113 | return -EIO; |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 114 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 115 | rtascons_get_char_token = rtas_token("get-term-char"); |
| 116 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 117 | return -EIO; |
| 118 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 119 | hvc_instantiate(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops); |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 120 | add_preferred_console("hvc", 0, NULL); |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 121 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | console_initcall(hvc_rtas_console_init); |