ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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 <asm/hvcall.h>
24 #include <asm/prom.h>
25 #include <asm/hvconsole.h>
26
27 int hvc_get_chars(int index, char *buf, int count)
28 {
29         unsigned long got;
30
31         if (plpar_hcall(H_GET_TERM_CHAR, index, 0, 0, 0, &got,
32                 (unsigned long *)buf, (unsigned long *)buf+1) == H_Success) {
33                 /*
34                  * Work around a HV bug where it gives us a null
35                  * after every \r.  -- paulus
36                  */
37                 if (got > 0) {
38                         int i;
39                         for (i = 1; i < got; ++i) {
40                                 if (buf[i] == 0 && buf[i-1] == '\r') {
41                                         --got;
42                                         if (i < got)
43                                                 memmove(&buf[i], &buf[i+1],
44                                                         got - i);
45                                 }
46                         }
47                 }
48                 return got;
49         }
50         return 0;
51 }
52
53 int hvc_put_chars(int index, const char *buf, int count)
54 {
55         unsigned long *lbuf = (unsigned long *) buf;
56         long ret;
57
58         ret = plpar_hcall_norets(H_PUT_TERM_CHAR, index, count, lbuf[0],
59                                  lbuf[1]);
60         if (ret == H_Success)
61                 return count;
62         if (ret == H_Busy)
63                 return 0;
64         return -1;
65 }
66
67 /* return the number of client vterms present */
68 /* XXX this requires an interface change to handle multiple discontiguous
69  * vterms */
70 int hvc_count(int *start_termno)
71 {
72         struct device_node *vty;
73         int num_found = 0;
74
75         /* consider only the first vty node.
76          * we should _always_ be able to find one. */
77         vty = of_find_node_by_name(NULL, "vty");
78         if (vty && device_is_compatible(vty, "hvterm1")) {
79                 u32 *termno = (u32 *)get_property(vty, "reg", 0);
80
81                 if (termno && start_termno)
82                         *start_termno = *termno;
83                 num_found = 1;
84                 of_node_put(vty);
85         }
86
87         return num_found;
88 }