David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 1 | /* console.c: Routines that deal with sending and receiving IO |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * to/from the current console device using the PROM. |
| 3 | * |
David S. Miller | d979f17 | 2007-10-27 00:13:04 -0700 | [diff] [blame] | 4 | * Copyright (C) 1995 David S. Miller (davem@davemloft.net) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 6 | */ |
| 7 | |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <asm/openprom.h> |
| 12 | #include <asm/oplib.h> |
| 13 | #include <asm/system.h> |
| 14 | #include <linux/string.h> |
| 15 | |
| 16 | extern int prom_stdin, prom_stdout; |
| 17 | |
| 18 | /* Non blocking get character from console input device, returns -1 |
| 19 | * if no input was taken. This can be used for polling. |
| 20 | */ |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 21 | static int prom_nbgetchar(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 23 | unsigned long args[7]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 25 | args[0] = (unsigned long) "read"; |
| 26 | args[1] = 3; |
| 27 | args[2] = 1; |
| 28 | args[3] = (unsigned int) prom_stdin; |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 29 | args[4] = (unsigned long) buf; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 30 | args[5] = 1; |
| 31 | args[6] = (unsigned long) -1; |
| 32 | |
| 33 | p1275_cmd_direct(args); |
| 34 | |
| 35 | if (args[6] == 1) |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 36 | return 0; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 37 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | /* Non blocking put character to console device, returns -1 if |
| 41 | * unsuccessful. |
| 42 | */ |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 43 | static int prom_nbputchar(const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 45 | unsigned long args[7]; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 46 | |
| 47 | args[0] = (unsigned long) "write"; |
| 48 | args[1] = 3; |
| 49 | args[2] = 1; |
| 50 | args[3] = (unsigned int) prom_stdout; |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 51 | args[4] = (unsigned long) buf; |
David S. Miller | 25edd69 | 2010-08-23 23:10:57 -0700 | [diff] [blame] | 52 | args[5] = 1; |
| 53 | args[6] = (unsigned long) -1; |
| 54 | |
| 55 | p1275_cmd_direct(args); |
| 56 | |
| 57 | if (args[6] == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | return 0; |
| 59 | else |
| 60 | return -1; |
| 61 | } |
| 62 | |
| 63 | /* Blocking version of get character routine above. */ |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 64 | void prom_getchar(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | { |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 66 | while (1) { |
| 67 | int err = prom_nbgetchar(buf); |
| 68 | if (!err) |
| 69 | break; |
| 70 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | /* Blocking version of put character routine above. */ |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 74 | void prom_putchar(const char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
David S. Miller | e62cac1 | 2010-11-30 14:33:29 -0800 | [diff] [blame^] | 76 | while (1) { |
| 77 | int err = prom_nbputchar(buf); |
| 78 | if (!err) |
| 79 | break; |
| 80 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |