VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / arch / ppc64 / kernel / hvconsole.c
1 /*
2  * hvconsole.c
3  * Copyright (C) 2004 Hollis Blanchard, IBM Corporation
4  *
5  * LPAR console support.
6  * 
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  * 
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20  */
21
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <asm/hvcall.h>
25 #include <asm/prom.h>
26 #include <asm/hvconsole.h>
27
28 int hvc_get_chars(int index, char *buf, int count)
29 {
30         unsigned long got;
31
32         if (plpar_hcall(H_GET_TERM_CHAR, index, 0, 0, 0, &got,
33                 (unsigned long *)buf, (unsigned long *)buf+1) == H_Success) {
34                 /*
35                  * Work around a HV bug where it gives us a null
36                  * after every \r.  -- paulus
37                  */
38                 if (got > 0) {
39                         int i;
40                         for (i = 1; i < got; ++i) {
41                                 if (buf[i] == 0 && buf[i-1] == '\r') {
42                                         --got;
43                                         if (i < got)
44                                                 memmove(&buf[i], &buf[i+1],
45                                                         got - i);
46                                 }
47                         }
48                 }
49                 return got;
50         }
51         return 0;
52 }
53
54 EXPORT_SYMBOL(hvc_get_chars);
55
56 int hvc_put_chars(int index, const char *buf, int count)
57 {
58         unsigned long *lbuf = (unsigned long *) buf;
59         long ret;
60
61         ret = plpar_hcall_norets(H_PUT_TERM_CHAR, index, count, lbuf[0],
62                                  lbuf[1]);
63         if (ret == H_Success)
64                 return count;
65         if (ret == H_Busy)
66                 return 0;
67         return -1;
68 }
69
70 EXPORT_SYMBOL(hvc_put_chars);
71
72 /* return the number of client vterms present */
73 /* XXX this requires an interface change to handle multiple discontiguous
74  * vterms */
75 int hvc_count(int *start_termno)
76 {
77         struct device_node *vty;
78         int num_found = 0;
79
80         /* consider only the first vty node.
81          * we should _always_ be able to find one. */
82         vty = of_find_node_by_name(NULL, "vty");
83         if (vty && device_is_compatible(vty, "hvterm1")) {
84                 u32 *termno = (u32 *)get_property(vty, "reg", NULL);
85
86                 if (termno && start_termno)
87                         *start_termno = *termno;
88                 num_found = 1;
89                 of_node_put(vty);
90         }
91
92         return num_found;
93 }