2019-05-27 13:55:05 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* hvconsole.c
|
|
|
|
* Copyright (C) 2004 Hollis Blanchard, IBM Corporation
|
|
|
|
* Copyright (C) 2004 IBM Corporation
|
|
|
|
*
|
|
|
|
* Additional Author(s):
|
|
|
|
* Ryan S. Arnold <rsa@us.ibm.com>
|
|
|
|
*
|
|
|
|
* LPAR console support.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
2011-07-23 05:15:07 +07:00
|
|
|
#include <linux/export.h>
|
|
|
|
#include <linux/errno.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
#include <asm/hvcall.h>
|
|
|
|
#include <asm/hvconsole.h>
|
2013-08-22 16:53:52 +07:00
|
|
|
#include <asm/plpar_wrappers.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/**
|
2016-02-25 01:51:11 +07:00
|
|
|
* hvc_get_chars - retrieve characters from firmware for denoted vterm adapter
|
2005-04-17 05:20:36 +07:00
|
|
|
* @vtermno: The vtermno or unit_address of the adapter from which to fetch the
|
|
|
|
* data.
|
|
|
|
* @buf: The character buffer into which to put the character data fetched from
|
|
|
|
* firmware.
|
|
|
|
* @count: not used?
|
|
|
|
*/
|
|
|
|
int hvc_get_chars(uint32_t vtermno, char *buf, int count)
|
|
|
|
{
|
2013-08-06 23:01:23 +07:00
|
|
|
long ret;
|
|
|
|
unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
|
|
|
|
unsigned long *lbuf = (unsigned long *)buf;
|
|
|
|
|
|
|
|
ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno);
|
2013-08-06 23:01:49 +07:00
|
|
|
lbuf[0] = be64_to_cpu(retbuf[1]);
|
|
|
|
lbuf[1] = be64_to_cpu(retbuf[2]);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2013-08-06 23:01:23 +07:00
|
|
|
if (ret == H_SUCCESS)
|
|
|
|
return retbuf[0];
|
2006-07-19 05:01:28 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(hvc_get_chars);
|
|
|
|
|
2005-07-08 07:56:26 +07:00
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/**
|
|
|
|
* hvc_put_chars: send characters to firmware for denoted vterm adapter
|
|
|
|
* @vtermno: The vtermno or unit_address of the adapter from which the data
|
|
|
|
* originated.
|
|
|
|
* @buf: The character buffer that contains the character data to send to
|
2019-06-03 13:56:57 +07:00
|
|
|
* firmware. Must be at least 16 bytes, even if count is less than 16.
|
2005-04-17 05:20:36 +07:00
|
|
|
* @count: Send this number of characters.
|
|
|
|
*/
|
|
|
|
int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
|
|
|
|
{
|
|
|
|
unsigned long *lbuf = (unsigned long *) buf;
|
|
|
|
long ret;
|
|
|
|
|
2006-03-28 02:25:16 +07:00
|
|
|
|
|
|
|
/* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
|
|
|
|
if (count > MAX_VIO_PUT_CHARS)
|
|
|
|
count = MAX_VIO_PUT_CHARS;
|
|
|
|
|
2013-08-06 23:01:49 +07:00
|
|
|
ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count,
|
|
|
|
cpu_to_be64(lbuf[0]),
|
|
|
|
cpu_to_be64(lbuf[1]));
|
2006-03-30 19:49:40 +07:00
|
|
|
if (ret == H_SUCCESS)
|
2005-04-17 05:20:36 +07:00
|
|
|
return count;
|
2006-03-30 19:49:40 +07:00
|
|
|
if (ret == H_BUSY)
|
2011-07-06 04:51:36 +07:00
|
|
|
return -EAGAIN;
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXPORT_SYMBOL(hvc_put_chars);
|