Linux-2.6.12-rc2
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / ppc64 / kernel / hvconsole.c
1 /*
2 * hvconsole.c
3 * Copyright (C) 2004 Hollis Blanchard, IBM Corporation
4 * Copyright (C) 2004 IBM Corporation
5 *
6 * Additional Author(s):
7 * Ryan S. Arnold <rsa@us.ibm.com>
8 *
9 * LPAR console support.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <asm/hvcall.h>
29 #include <asm/hvconsole.h>
30 #include <asm/prom.h>
31
32 /**
33 * hvc_get_chars - retrieve characters from firmware for denoted vterm adatper
34 * @vtermno: The vtermno or unit_address of the adapter from which to fetch the
35 * data.
36 * @buf: The character buffer into which to put the character data fetched from
37 * firmware.
38 * @count: not used?
39 */
40 int hvc_get_chars(uint32_t vtermno, char *buf, int count)
41 {
42 unsigned long got;
43
44 if (plpar_hcall(H_GET_TERM_CHAR, vtermno, 0, 0, 0, &got,
45 (unsigned long *)buf, (unsigned long *)buf+1) == H_Success) {
46 /*
47 * Work around a HV bug where it gives us a null
48 * after every \r. -- paulus
49 */
50 if (got > 0) {
51 int i;
52 for (i = 1; i < got; ++i) {
53 if (buf[i] == 0 && buf[i-1] == '\r') {
54 --got;
55 if (i < got)
56 memmove(&buf[i], &buf[i+1],
57 got - i);
58 }
59 }
60 }
61 return got;
62 }
63 return 0;
64 }
65
66 EXPORT_SYMBOL(hvc_get_chars);
67
68 /**
69 * hvc_put_chars: send characters to firmware for denoted vterm adapter
70 * @vtermno: The vtermno or unit_address of the adapter from which the data
71 * originated.
72 * @buf: The character buffer that contains the character data to send to
73 * firmware.
74 * @count: Send this number of characters.
75 */
76 int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
77 {
78 unsigned long *lbuf = (unsigned long *) buf;
79 long ret;
80
81 ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, lbuf[0],
82 lbuf[1]);
83 if (ret == H_Success)
84 return count;
85 if (ret == H_Busy)
86 return 0;
87 return -EIO;
88 }
89
90 EXPORT_SYMBOL(hvc_put_chars);
91
92 /*
93 * We hope/assume that the first vty found corresponds to the first console
94 * device.
95 */
96 int hvc_find_vtys(void)
97 {
98 struct device_node *vty;
99 int num_found = 0;
100
101 for (vty = of_find_node_by_name(NULL, "vty"); vty != NULL;
102 vty = of_find_node_by_name(vty, "vty")) {
103 uint32_t *vtermno;
104
105 /* We have statically defined space for only a certain number of
106 * console adapters. */
107 if (num_found >= MAX_NR_HVC_CONSOLES)
108 break;
109
110 vtermno = (uint32_t *)get_property(vty, "reg", NULL);
111 if (!vtermno)
112 continue;
113
114 if (device_is_compatible(vty, "hvterm1")) {
115 hvc_instantiate(*vtermno, num_found);
116 ++num_found;
117 }
118 }
119
120 return num_found;
121 }