17568cb4eSPaul Mackerras /*
27568cb4eSPaul Mackerras  * hvconsole.c
37568cb4eSPaul Mackerras  * Copyright (C) 2004 Hollis Blanchard, IBM Corporation
47568cb4eSPaul Mackerras  * Copyright (C) 2004 IBM Corporation
57568cb4eSPaul Mackerras  *
67568cb4eSPaul Mackerras  * Additional Author(s):
77568cb4eSPaul Mackerras  *  Ryan S. Arnold <rsa@us.ibm.com>
87568cb4eSPaul Mackerras  *
97568cb4eSPaul Mackerras  * LPAR console support.
107568cb4eSPaul Mackerras  *
117568cb4eSPaul Mackerras  * This program is free software; you can redistribute it and/or modify
127568cb4eSPaul Mackerras  * it under the terms of the GNU General Public License as published by
137568cb4eSPaul Mackerras  * the Free Software Foundation; either version 2 of the License, or
147568cb4eSPaul Mackerras  * (at your option) any later version.
157568cb4eSPaul Mackerras  *
167568cb4eSPaul Mackerras  * This program is distributed in the hope that it will be useful,
177568cb4eSPaul Mackerras  * but WITHOUT ANY WARRANTY; without even the implied warranty of
187568cb4eSPaul Mackerras  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
197568cb4eSPaul Mackerras  * GNU General Public License for more details.
207568cb4eSPaul Mackerras  *
217568cb4eSPaul Mackerras  * You should have received a copy of the GNU General Public License
227568cb4eSPaul Mackerras  * along with this program; if not, write to the Free Software
237568cb4eSPaul Mackerras  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
247568cb4eSPaul Mackerras  */
257568cb4eSPaul Mackerras 
267568cb4eSPaul Mackerras #include <linux/kernel.h>
27e9848d62SPaul Gortmaker #include <linux/export.h>
28e9848d62SPaul Gortmaker #include <linux/errno.h>
297568cb4eSPaul Mackerras #include <asm/hvcall.h>
307568cb4eSPaul Mackerras #include <asm/hvconsole.h>
31b9377ffcSAnton Blanchard #include "plpar_wrappers.h"
327568cb4eSPaul Mackerras 
337568cb4eSPaul Mackerras /**
347568cb4eSPaul Mackerras  * hvc_get_chars - retrieve characters from firmware for denoted vterm adatper
357568cb4eSPaul Mackerras  * @vtermno: The vtermno or unit_address of the adapter from which to fetch the
367568cb4eSPaul Mackerras  *	data.
377568cb4eSPaul Mackerras  * @buf: The character buffer into which to put the character data fetched from
387568cb4eSPaul Mackerras  *	firmware.
397568cb4eSPaul Mackerras  * @count: not used?
407568cb4eSPaul Mackerras  */
417568cb4eSPaul Mackerras int hvc_get_chars(uint32_t vtermno, char *buf, int count)
427568cb4eSPaul Mackerras {
43a0a96ee9SAnton Blanchard 	long ret;
44a0a96ee9SAnton Blanchard 	unsigned long retbuf[PLPAR_HCALL_BUFSIZE];
45a0a96ee9SAnton Blanchard 	unsigned long *lbuf = (unsigned long *)buf;
467568cb4eSPaul Mackerras 
47a0a96ee9SAnton Blanchard 	ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno);
48a02f6dfcSAnton Blanchard 	lbuf[0] = be64_to_cpu(retbuf[1]);
49a02f6dfcSAnton Blanchard 	lbuf[1] = be64_to_cpu(retbuf[2]);
50a0a96ee9SAnton Blanchard 
51a0a96ee9SAnton Blanchard 	if (ret == H_SUCCESS)
52a0a96ee9SAnton Blanchard 		return retbuf[0];
53b9377ffcSAnton Blanchard 
547568cb4eSPaul Mackerras 	return 0;
557568cb4eSPaul Mackerras }
567568cb4eSPaul Mackerras 
577568cb4eSPaul Mackerras EXPORT_SYMBOL(hvc_get_chars);
587568cb4eSPaul Mackerras 
597568cb4eSPaul Mackerras 
607568cb4eSPaul Mackerras /**
617568cb4eSPaul Mackerras  * hvc_put_chars: send characters to firmware for denoted vterm adapter
627568cb4eSPaul Mackerras  * @vtermno: The vtermno or unit_address of the adapter from which the data
637568cb4eSPaul Mackerras  *	originated.
647568cb4eSPaul Mackerras  * @buf: The character buffer that contains the character data to send to
657568cb4eSPaul Mackerras  *	firmware.
667568cb4eSPaul Mackerras  * @count: Send this number of characters.
677568cb4eSPaul Mackerras  */
687568cb4eSPaul Mackerras int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
697568cb4eSPaul Mackerras {
707568cb4eSPaul Mackerras 	unsigned long *lbuf = (unsigned long *) buf;
717568cb4eSPaul Mackerras 	long ret;
727568cb4eSPaul Mackerras 
7345d607edSRyan S. Arnold 
7445d607edSRyan S. Arnold 	/* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
7545d607edSRyan S. Arnold 	if (count > MAX_VIO_PUT_CHARS)
7645d607edSRyan S. Arnold 		count = MAX_VIO_PUT_CHARS;
7745d607edSRyan S. Arnold 
78a02f6dfcSAnton Blanchard 	ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count,
79a02f6dfcSAnton Blanchard 				 cpu_to_be64(lbuf[0]),
80a02f6dfcSAnton Blanchard 				 cpu_to_be64(lbuf[1]));
81706c8c93SSegher Boessenkool 	if (ret == H_SUCCESS)
827568cb4eSPaul Mackerras 		return count;
83706c8c93SSegher Boessenkool 	if (ret == H_BUSY)
8451d33021SAnton Blanchard 		return -EAGAIN;
857568cb4eSPaul Mackerras 	return -EIO;
867568cb4eSPaul Mackerras }
877568cb4eSPaul Mackerras 
887568cb4eSPaul Mackerras EXPORT_SYMBOL(hvc_put_chars);
89