Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * hvconsole.c |
| 3 | * Copyright (C) 2004 Hollis Blanchard, IBM Corporation |
| 4 | * Copyright (C) 2004 IBM Corporation |
| 5 | * |
| 6 | * Additional Author(s): |
| 7 | * Ryan S. Arnold <rsa@us.ibm.com> |
| 8 | * |
| 9 | * LPAR console support. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
Paul Gortmaker | e9848d6 | 2011-07-22 18:15:07 -0400 | [diff] [blame] | 27 | #include <linux/export.h> |
| 28 | #include <linux/errno.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include <asm/hvcall.h> |
| 30 | #include <asm/hvconsole.h> |
Deepthi Dharwar | 212bebb | 2013-08-22 15:23:52 +0530 | [diff] [blame] | 31 | #include <asm/plpar_wrappers.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | /** |
| 34 | * hvc_get_chars - retrieve characters from firmware for denoted vterm adatper |
| 35 | * @vtermno: The vtermno or unit_address of the adapter from which to fetch the |
| 36 | * data. |
| 37 | * @buf: The character buffer into which to put the character data fetched from |
| 38 | * firmware. |
| 39 | * @count: not used? |
| 40 | */ |
| 41 | int hvc_get_chars(uint32_t vtermno, char *buf, int count) |
| 42 | { |
Anton Blanchard | a0a96ee | 2013-08-07 02:01:23 +1000 | [diff] [blame] | 43 | long ret; |
| 44 | unsigned long retbuf[PLPAR_HCALL_BUFSIZE]; |
| 45 | unsigned long *lbuf = (unsigned long *)buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | |
Anton Blanchard | a0a96ee | 2013-08-07 02:01:23 +1000 | [diff] [blame] | 47 | ret = plpar_hcall(H_GET_TERM_CHAR, retbuf, vtermno); |
Anton Blanchard | a02f6df | 2013-08-07 02:01:49 +1000 | [diff] [blame] | 48 | lbuf[0] = be64_to_cpu(retbuf[1]); |
| 49 | lbuf[1] = be64_to_cpu(retbuf[2]); |
Anton Blanchard | a0a96ee | 2013-08-07 02:01:23 +1000 | [diff] [blame] | 50 | |
| 51 | if (ret == H_SUCCESS) |
| 52 | return retbuf[0]; |
Anton Blanchard | b9377ff | 2006-07-19 08:01:28 +1000 | [diff] [blame] | 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | EXPORT_SYMBOL(hvc_get_chars); |
| 58 | |
Milton Miller | 70b234a | 2005-07-07 17:56:26 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /** |
| 61 | * hvc_put_chars: send characters to firmware for denoted vterm adapter |
| 62 | * @vtermno: The vtermno or unit_address of the adapter from which the data |
| 63 | * originated. |
| 64 | * @buf: The character buffer that contains the character data to send to |
| 65 | * firmware. |
| 66 | * @count: Send this number of characters. |
| 67 | */ |
| 68 | int hvc_put_chars(uint32_t vtermno, const char *buf, int count) |
| 69 | { |
| 70 | unsigned long *lbuf = (unsigned long *) buf; |
| 71 | long ret; |
| 72 | |
Ryan S. Arnold | 45d607e | 2006-03-27 21:25:16 +0200 | [diff] [blame] | 73 | |
| 74 | /* hcall will ret H_PARAMETER if 'count' exceeds firmware max.*/ |
| 75 | if (count > MAX_VIO_PUT_CHARS) |
| 76 | count = MAX_VIO_PUT_CHARS; |
| 77 | |
Anton Blanchard | a02f6df | 2013-08-07 02:01:49 +1000 | [diff] [blame] | 78 | ret = plpar_hcall_norets(H_PUT_TERM_CHAR, vtermno, count, |
| 79 | cpu_to_be64(lbuf[0]), |
| 80 | cpu_to_be64(lbuf[1])); |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 81 | if (ret == H_SUCCESS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | return count; |
Segher Boessenkool | 706c8c9 | 2006-03-30 14:49:40 +0200 | [diff] [blame] | 83 | if (ret == H_BUSY) |
Anton Blanchard | 51d3302 | 2011-07-05 21:51:36 +0000 | [diff] [blame] | 84 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return -EIO; |
| 86 | } |
| 87 | |
| 88 | EXPORT_SYMBOL(hvc_put_chars); |