1 /* console.c: Routines that deal with sending and receiving IO 2 * to/from the current console device using the PROM. 3 * 4 * Copyright (C) 1995 David S. Miller (davem@davemloft.net) 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 */ 21 static int prom_nbgetchar(char *buf) 22 { 23 unsigned long args[7]; 24 25 args[0] = (unsigned long) "read"; 26 args[1] = 3; 27 args[2] = 1; 28 args[3] = (unsigned int) prom_stdin; 29 args[4] = (unsigned long) buf; 30 args[5] = 1; 31 args[6] = (unsigned long) -1; 32 33 p1275_cmd_direct(args); 34 35 if (args[6] == 1) 36 return 0; 37 return -1; 38 } 39 40 /* Non blocking put character to console device, returns -1 if 41 * unsuccessful. 42 */ 43 static int prom_nbputchar(const char *buf) 44 { 45 unsigned long args[7]; 46 47 args[0] = (unsigned long) "write"; 48 args[1] = 3; 49 args[2] = 1; 50 args[3] = (unsigned int) prom_stdout; 51 args[4] = (unsigned long) buf; 52 args[5] = 1; 53 args[6] = (unsigned long) -1; 54 55 p1275_cmd_direct(args); 56 57 if (args[6] == 1) 58 return 0; 59 else 60 return -1; 61 } 62 63 /* Blocking version of get character routine above. */ 64 void prom_getchar(char *buf) 65 { 66 while (1) { 67 int err = prom_nbgetchar(buf); 68 if (!err) 69 break; 70 } 71 } 72 73 /* Blocking version of put character routine above. */ 74 void prom_putchar(const char *buf) 75 { 76 while (1) { 77 int err = prom_nbputchar(buf); 78 if (!err) 79 break; 80 } 81 } 82