[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / ppc64 / kernel / hvconsole.c
blobc72fb8ffe974a3d42bd6865eeba8fcfacfda6f19
1 /*
2 * hvconsole.c
3 * Copyright (C) 2004 Hollis Blanchard, IBM Corporation
4 * Copyright (C) 2004 IBM Corporation
6 * Additional Author(s):
7 * Ryan S. Arnold <rsa@us.ibm.com>
9 * LPAR console support.
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.
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.
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
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>
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?
40 int hvc_get_chars(uint32_t vtermno, char *buf, int count)
42 unsigned long got;
44 if (plpar_hcall(H_GET_TERM_CHAR, vtermno, 0, 0, 0, &got,
45 (unsigned long *)buf, (unsigned long *)buf+1) == H_Success) {
47 * Work around a HV bug where it gives us a null
48 * after every \r. -- paulus
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);
61 return got;
63 return 0;
66 EXPORT_SYMBOL(hvc_get_chars);
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.
76 int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
78 unsigned long *lbuf = (unsigned long *) buf;
79 long ret;
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;
90 EXPORT_SYMBOL(hvc_put_chars);
93 * We hope/assume that the first vty found corresponds to the first console
94 * device.
96 int hvc_find_vtys(void)
98 struct device_node *vty;
99 int num_found = 0;
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;
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;
110 vtermno = (uint32_t *)get_property(vty, "reg", NULL);
111 if (!vtermno)
112 continue;
114 if (device_is_compatible(vty, "hvterm1")) {
115 hvc_instantiate(*vtermno, num_found);
116 ++num_found;
120 return num_found;