Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 1 | /* |
| 2 | * IBM RTAS driver interface to hvc_console.c |
| 3 | * |
| 4 | * (C) Copyright IBM Corporation 2001-2005 |
| 5 | * (C) Copyright Red Hat, Inc. 2005 |
| 6 | * |
| 7 | * Author(s): Maximino Augilar <IBM STI Design Center> |
| 8 | * : Ryan S. Arnold <rsa@us.ibm.com> |
| 9 | * : Utz Bacher <utz.bacher@de.ibm.com> |
| 10 | * : David Woodhouse <dwmw2@infradead.org> |
| 11 | * |
| 12 | * inspired by drivers/char/hvc_console.c |
| 13 | * written by Anton Blanchard and Paul Mackerras |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or modify |
| 16 | * it under the terms of the GNU General Public License as published by |
| 17 | * the Free Software Foundation; either version 2 of the License, or |
| 18 | * (at your option) any later version. |
| 19 | * |
| 20 | * This program is distributed in the hope that it will be useful, |
| 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 23 | * GNU General Public License for more details. |
| 24 | * |
| 25 | * You should have received a copy of the GNU General Public License |
| 26 | * along with this program; if not, write to the Free Software |
| 27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 28 | */ |
| 29 | |
| 30 | #include <linux/console.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/err.h> |
| 33 | #include <linux/init.h> |
| 34 | #include <linux/moduleparam.h> |
| 35 | #include <linux/types.h> |
| 36 | |
| 37 | #include <asm/irq.h> |
| 38 | #include <asm/rtas.h> |
| 39 | #include "hvc_console.h" |
| 40 | |
| 41 | #define hvc_rtas_cookie 0x67781e15 |
| 42 | struct hvc_struct *hvc_rtas_dev; |
| 43 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 44 | static int rtascons_put_char_token = RTAS_UNKNOWN_SERVICE; |
| 45 | static int rtascons_get_char_token = RTAS_UNKNOWN_SERVICE; |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 46 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 47 | static inline int hvc_rtas_write_console(uint32_t vtermno, const char *buf, |
| 48 | int count) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 49 | { |
| 50 | int i; |
| 51 | |
| 52 | for (i = 0; i < count; i++) { |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 53 | if (rtas_call(rtascons_put_char_token, 1, 1, NULL, buf[i])) |
| 54 | break; |
| 55 | } |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 56 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 57 | return i; |
| 58 | } |
| 59 | |
| 60 | static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count) |
| 61 | { |
| 62 | int i, c; |
| 63 | |
| 64 | for (i = 0; i < count; i++) { |
| 65 | if (rtas_call(rtascons_get_char_token, 0, 2, &c)) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 66 | break; |
| 67 | |
| 68 | buf[i] = c; |
| 69 | } |
| 70 | |
| 71 | return i; |
| 72 | } |
| 73 | |
| 74 | static struct hv_ops hvc_rtas_get_put_ops = { |
| 75 | .get_chars = hvc_rtas_read_console, |
| 76 | .put_chars = hvc_rtas_write_console, |
| 77 | }; |
| 78 | |
| 79 | static int hvc_rtas_init(void) |
| 80 | { |
| 81 | struct hvc_struct *hp; |
| 82 | |
| 83 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 84 | rtascons_put_char_token = rtas_token("put-term-char"); |
| 85 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 86 | return -EIO; |
| 87 | |
| 88 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 89 | rtascons_get_char_token = rtas_token("get-term-char"); |
| 90 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 91 | return -EIO; |
| 92 | |
| 93 | BUG_ON(hvc_rtas_dev); |
| 94 | |
| 95 | /* Allocate an hvc_struct for the console device we instantiated |
| 96 | * earlier. Save off hp so that we can return it on exit */ |
Stephen Rothwell | 4e9e95a | 2006-07-13 18:53:32 +1000 | [diff] [blame] | 97 | hp = hvc_alloc(hvc_rtas_cookie, NO_IRQ, &hvc_rtas_get_put_ops, 16); |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 98 | if (IS_ERR(hp)) |
| 99 | return PTR_ERR(hp); |
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 | hvc_rtas_dev = hp; |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 102 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 103 | return 0; |
| 104 | } |
| 105 | module_init(hvc_rtas_init); |
| 106 | |
| 107 | /* This will tear down the tty portion of the driver */ |
| 108 | static void __exit hvc_rtas_exit(void) |
| 109 | { |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 110 | /* Really the fun isn't over until the worker thread breaks down and |
| 111 | * the tty cleans up */ |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 112 | if (hvc_rtas_dev) |
| 113 | hvc_remove(hvc_rtas_dev); |
| 114 | } |
| 115 | module_exit(hvc_rtas_exit); |
| 116 | |
| 117 | /* 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] | 118 | static int __init hvc_rtas_console_init(void) |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 119 | { |
| 120 | rtascons_put_char_token = rtas_token("put-term-char"); |
| 121 | if (rtascons_put_char_token == RTAS_UNKNOWN_SERVICE) |
| 122 | return -EIO; |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 123 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 124 | rtascons_get_char_token = rtas_token("get-term-char"); |
| 125 | if (rtascons_get_char_token == RTAS_UNKNOWN_SERVICE) |
| 126 | return -EIO; |
| 127 | |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 128 | hvc_instantiate(hvc_rtas_cookie, 0, &hvc_rtas_get_put_ops); |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 129 | add_preferred_console("hvc", 0, NULL); |
Michael Ellerman | 6b81e80 | 2006-06-07 17:10:09 +1000 | [diff] [blame] | 130 | |
Arnd Bergmann | f4d1749 | 2006-03-27 21:26:03 +0200 | [diff] [blame] | 131 | return 0; |
| 132 | } |
| 133 | console_initcall(hvc_rtas_console_init); |