blob: 3f6a89b09816ee667b323214e3f8efbb949efad7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Anton Blanchardb9377ff2006-07-19 08:01:28 +100030#include "plpar_wrappers.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
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 */
40int hvc_get_chars(uint32_t vtermno, char *buf, int count)
41{
42 unsigned long got;
43
Anton Blanchardb9377ff2006-07-19 08:01:28 +100044 if (plpar_get_term_char(vtermno, &got, buf) == H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 return got;
Anton Blanchardb9377ff2006-07-19 08:01:28 +100046
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 return 0;
48}
49
50EXPORT_SYMBOL(hvc_get_chars);
51
Milton Miller70b234a2005-07-07 17:56:26 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053/**
54 * hvc_put_chars: send characters to firmware for denoted vterm adapter
55 * @vtermno: The vtermno or unit_address of the adapter from which the data
56 * originated.
57 * @buf: The character buffer that contains the character data to send to
58 * firmware.
59 * @count: Send this number of characters.
60 */
61int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
62{
63 unsigned long *lbuf = (unsigned long *) buf;
64 long ret;
65
Ryan S. Arnold45d607e2006-03-27 21:25:16 +020066
67 /* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
68 if (count > MAX_VIO_PUT_CHARS)
69 count = MAX_VIO_PUT_CHARS;
70
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, lbuf[0],
72 lbuf[1]);
Segher Boessenkool706c8c92006-03-30 14:49:40 +020073 if (ret == H_SUCCESS)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 return count;
Segher Boessenkool706c8c92006-03-30 14:49:40 +020075 if (ret == H_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 return 0;
77 return -EIO;
78}
79
80EXPORT_SYMBOL(hvc_put_chars);