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