xref: /linux/arch/powerpc/platforms/pseries/hvconsole.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
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
6  *
7  * Additional Author(s):
8  *  Ryan S. Arnold <rsa@us.ibm.com>
9  *
10  * LPAR console support.
11  */
12 
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>
19 
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?
27  */
28 ssize_t hvc_get_chars(uint32_t vtermno, u8 *buf, size_t count)
29 {
30 	long ret;
31 	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
32 	unsigned long *lbuf = (unsigned long *)buf;
33 
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]);
37 
38 	if (ret == H_SUCCESS)
39 		return retbuf[0];
40 
41 	return 0;
42 }
43 
44 EXPORT_SYMBOL(hvc_get_chars);
45 
46 
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.
54  */
55 ssize_t hvc_put_chars(uint32_t vtermno, const u8 *buf, size_t count)
56 {
57 	unsigned long *lbuf = (unsigned long *) buf;
58 	long ret;
59 
60 
61 	/* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
62 	if (count > MAX_VIO_PUT_CHARS)
63 		count = MAX_VIO_PUT_CHARS;
64 
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;
73 }
74 
75 EXPORT_SYMBOL(hvc_put_chars);
76