Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1da177e4 LT |
30 | |
31 | /** | |
32 | * hvc_get_chars - retrieve characters from firmware for denoted vterm adatper | |
33 | * @vtermno: The vtermno or unit_address of the adapter from which to fetch the | |
34 | * data. | |
35 | * @buf: The character buffer into which to put the character data fetched from | |
36 | * firmware. | |
37 | * @count: not used? | |
38 | */ | |
39 | int hvc_get_chars(uint32_t vtermno, char *buf, int count) | |
40 | { | |
41 | unsigned long got; | |
42 | ||
43 | if (plpar_hcall(H_GET_TERM_CHAR, vtermno, 0, 0, 0, &got, | |
44 | (unsigned long *)buf, (unsigned long *)buf+1) == H_Success) { | |
45 | /* | |
46 | * Work around a HV bug where it gives us a null | |
47 | * after every \r. -- paulus | |
48 | */ | |
49 | if (got > 0) { | |
50 | int i; | |
51 | for (i = 1; i < got; ++i) { | |
52 | if (buf[i] == 0 && buf[i-1] == '\r') { | |
53 | --got; | |
54 | if (i < got) | |
55 | memmove(&buf[i], &buf[i+1], | |
56 | got - i); | |
57 | } | |
58 | } | |
59 | } | |
60 | return got; | |
61 | } | |
62 | return 0; | |
63 | } | |
64 | ||
65 | EXPORT_SYMBOL(hvc_get_chars); | |
66 | ||
67 | /** | |
68 | * hvc_put_chars: send characters to firmware for denoted vterm adapter | |
69 | * @vtermno: The vtermno or unit_address of the adapter from which the data | |
70 | * originated. | |
71 | * @buf: The character buffer that contains the character data to send to | |
72 | * firmware. | |
73 | * @count: Send this number of characters. | |
74 | */ | |
75 | int hvc_put_chars(uint32_t vtermno, const char *buf, int count) | |
76 | { | |
77 | unsigned long *lbuf = (unsigned long *) buf; | |
78 | long ret; | |
79 | ||
80 | ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, lbuf[0], | |
81 | lbuf[1]); | |
82 | if (ret == H_Success) | |
83 | return count; | |
84 | if (ret == H_Busy) | |
85 | return 0; | |
86 | return -EIO; | |
87 | } | |
88 | ||
89 | EXPORT_SYMBOL(hvc_put_chars); |