Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * hvconsole.c
0004  * Copyright (C) 2004 Hollis Blanchard, IBM Corporation
0005  * Copyright (C) 2004 IBM Corporation
0006  *
0007  * Additional Author(s):
0008  *  Ryan S. Arnold <rsa@us.ibm.com>
0009  *
0010  * LPAR console support.
0011  */
0012 
0013 #include <linux/kernel.h>
0014 #include <linux/export.h>
0015 #include <linux/errno.h>
0016 #include <asm/hvcall.h>
0017 #include <asm/hvconsole.h>
0018 #include <asm/plpar_wrappers.h>
0019 
0020 /**
0021  * hvc_get_chars - retrieve characters from firmware for denoted vterm adapter
0022  * @vtermno: The vtermno or unit_address of the adapter from which to fetch the
0023  *  data.
0024  * @buf: The character buffer into which to put the character data fetched from
0025  *  firmware.
0026  * @count: not used?
0027  */
0028 int hvc_get_chars(uint32_t vtermno, char *buf, int count)
0029 {
0030     long ret;
0031     unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
0032     unsigned long *lbuf = (unsigned long *)buf;
0033 
0034     ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno);
0035     lbuf[0] = be64_to_cpu(retbuf[1]);
0036     lbuf[1] = be64_to_cpu(retbuf[2]);
0037 
0038     if (ret == H_SUCCESS)
0039         return retbuf[0];
0040 
0041     return 0;
0042 }
0043 
0044 EXPORT_SYMBOL(hvc_get_chars);
0045 
0046 
0047 /**
0048  * hvc_put_chars: send characters to firmware for denoted vterm adapter
0049  * @vtermno: The vtermno or unit_address of the adapter from which the data
0050  *  originated.
0051  * @buf: The character buffer that contains the character data to send to
0052  *  firmware. Must be at least 16 bytes, even if count is less than 16.
0053  * @count: Send this number of characters.
0054  */
0055 int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
0056 {
0057     unsigned long *lbuf = (unsigned long *) buf;
0058     long ret;
0059 
0060 
0061     /* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
0062     if (count > MAX_VIO_PUT_CHARS)
0063         count = MAX_VIO_PUT_CHARS;
0064 
0065     ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count,
0066                  cpu_to_be64(lbuf[0]),
0067                  cpu_to_be64(lbuf[1]));
0068     if (ret == H_SUCCESS)
0069         return count;
0070     if (ret == H_BUSY)
0071         return -EAGAIN;
0072     return -EIO;
0073 }
0074 
0075 EXPORT_SYMBOL(hvc_put_chars);