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>
277568cb4eSPaul Mackerras #include <linux/module.h>
287568cb4eSPaul Mackerras #include <asm/hvcall.h>
297568cb4eSPaul Mackerras #include <asm/hvconsole.h>
307568cb4eSPaul Mackerras 
317568cb4eSPaul Mackerras /**
327568cb4eSPaul Mackerras  * hvc_get_chars - retrieve characters from firmware for denoted vterm adatper
337568cb4eSPaul Mackerras  * @vtermno: The vtermno or unit_address of the adapter from which to fetch the
347568cb4eSPaul Mackerras  *	data.
357568cb4eSPaul Mackerras  * @buf: The character buffer into which to put the character data fetched from
367568cb4eSPaul Mackerras  *	firmware.
377568cb4eSPaul Mackerras  * @count: not used?
387568cb4eSPaul Mackerras  */
397568cb4eSPaul Mackerras int hvc_get_chars(uint32_t vtermno, char *buf, int count)
407568cb4eSPaul Mackerras {
417568cb4eSPaul Mackerras 	unsigned long got;
427568cb4eSPaul Mackerras 
437568cb4eSPaul Mackerras 	if (plpar_hcall(H_GET_TERM_CHAR, vtermno, 0, 0, 0, &got,
44706c8c93SSegher Boessenkool 		(unsigned long *)buf, (unsigned long *)buf+1) == H_SUCCESS)
457568cb4eSPaul Mackerras 		return got;
467568cb4eSPaul Mackerras 	return 0;
477568cb4eSPaul Mackerras }
487568cb4eSPaul Mackerras 
497568cb4eSPaul Mackerras EXPORT_SYMBOL(hvc_get_chars);
507568cb4eSPaul Mackerras 
517568cb4eSPaul Mackerras 
527568cb4eSPaul Mackerras /**
537568cb4eSPaul Mackerras  * hvc_put_chars: send characters to firmware for denoted vterm adapter
547568cb4eSPaul Mackerras  * @vtermno: The vtermno or unit_address of the adapter from which the data
557568cb4eSPaul Mackerras  *	originated.
567568cb4eSPaul Mackerras  * @buf: The character buffer that contains the character data to send to
577568cb4eSPaul Mackerras  *	firmware.
587568cb4eSPaul Mackerras  * @count: Send this number of characters.
597568cb4eSPaul Mackerras  */
607568cb4eSPaul Mackerras int hvc_put_chars(uint32_t vtermno, const char *buf, int count)
617568cb4eSPaul Mackerras {
627568cb4eSPaul Mackerras 	unsigned long *lbuf = (unsigned long *) buf;
637568cb4eSPaul Mackerras 	long ret;
647568cb4eSPaul Mackerras 
6545d607edSRyan S. Arnold 
6645d607edSRyan S. Arnold 	/* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/
6745d607edSRyan S. Arnold 	if (count > MAX_VIO_PUT_CHARS)
6845d607edSRyan S. Arnold 		count = MAX_VIO_PUT_CHARS;
6945d607edSRyan S. Arnold 
707568cb4eSPaul Mackerras 	ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, lbuf[0],
717568cb4eSPaul Mackerras 				 lbuf[1]);
72706c8c93SSegher Boessenkool 	if (ret == H_SUCCESS)
737568cb4eSPaul Mackerras 		return count;
74706c8c93SSegher Boessenkool 	if (ret == H_BUSY)
757568cb4eSPaul Mackerras 		return 0;
767568cb4eSPaul Mackerras 	return -EIO;
777568cb4eSPaul Mackerras }
787568cb4eSPaul Mackerras 
797568cb4eSPaul Mackerras EXPORT_SYMBOL(hvc_put_chars);
80