WIP FPC-III support
[linux/fpc-iii.git] / arch / powerpc / platforms / pseries / hvconsole.c
blob1ac52963e08b47365415a93c09702354cb896d4c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * hvconsole.c
4 * Copyright (C) 2004 Hollis Blanchard, IBM Corporation
5 * Copyright (C) 2004 IBM Corporation
7 * Additional Author(s):
8 * Ryan S. Arnold <rsa@us.ibm.com>
10 * LPAR console support.
13 #include <linux/kernel.h>
14 #include <linux/export.h>
15 #include <linux/errno.h>
16 #include <asm/hvcall.h>
17 #include <asm/hvconsole.h>
18 #include <asm/plpar_wrappers.h>
20 /**
21 * hvc_get_chars - retrieve characters from firmware for denoted vterm adapter
22 * @vtermno: The vtermno or unit_address of the adapter from which to fetch the
23 * data.
24 * @buf: The character buffer into which to put the character data fetched from
25 * firmware.
26 * @count: not used?
28 int hvc_get_chars(uint32_t vtermno, char *buf, int count)
30 long ret;
31 unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
32 unsigned long *lbuf = (unsigned long *)buf;
34 ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno);
35 lbuf[0] = be64_to_cpu(retbuf[1]);
36 lbuf[1] = be64_to_cpu(retbuf[2]);
38 if (ret == H_SUCCESS)
39 return retbuf[0];
41 return 0;
44 EXPORT_SYMBOL(hvc_get_chars);
47 /**
48 * hvc_put_chars: send characters to firmware for denoted vterm adapter
49 * @vtermno: The vtermno or unit_address of the adapter from which the data
50 * originated.
51 * @buf: The character buffer that contains the character data to send to
52 * firmware. Must be at least 16 bytes, even if count is less than 16.
53 * @count: Send this number of characters.
55 int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
57 unsigned long *lbuf = (unsigned long *) buf;
58 long ret;
61 /* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
62 if (count > MAX_VIO_PUT_CHARS)
63 count = MAX_VIO_PUT_CHARS;
65 ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count,
66 cpu_to_be64(lbuf[0]),
67 cpu_to_be64(lbuf[1]));
68 if (ret == H_SUCCESS)
69 return count;
70 if (ret == H_BUSY)
71 return -EAGAIN;
72 return -EIO;
75 EXPORT_SYMBOL(hvc_put_chars);