blob: a9a575433ce9de43046d19d2d4d182425bbcb2bd [file] [log] [blame]
David S. Millerd979f172007-10-27 00:13:04 -07001/* console.c: Routines that deal with sending and receiving IO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * to/from the current console device using the PROM.
3 *
David S. Millerd979f172007-10-27 00:13:04 -07004 * Copyright (C) 1995 David S. Miller (davem@davemloft.net)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * 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
16extern 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. Millere62cac12010-11-30 14:33:29 -080021static int prom_nbgetchar(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070022{
David S. Miller25edd692010-08-23 23:10:57 -070023 unsigned long args[7];
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
David S. Miller25edd692010-08-23 23:10:57 -070025 args[0] = (unsigned long) "read";
26 args[1] = 3;
27 args[2] = 1;
28 args[3] = (unsigned int) prom_stdin;
David S. Millere62cac12010-11-30 14:33:29 -080029 args[4] = (unsigned long) buf;
David S. Miller25edd692010-08-23 23:10:57 -070030 args[5] = 1;
31 args[6] = (unsigned long) -1;
32
33 p1275_cmd_direct(args);
34
35 if (args[6] == 1)
David S. Millere62cac12010-11-30 14:33:29 -080036 return 0;
David S. Miller25edd692010-08-23 23:10:57 -070037 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038}
39
40/* Non blocking put character to console device, returns -1 if
41 * unsuccessful.
42 */
David S. Millere62cac12010-11-30 14:33:29 -080043static int prom_nbputchar(const char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
David S. Miller25edd692010-08-23 23:10:57 -070045 unsigned long args[7];
David S. Miller25edd692010-08-23 23:10:57 -070046
47 args[0] = (unsigned long) "write";
48 args[1] = 3;
49 args[2] = 1;
50 args[3] = (unsigned int) prom_stdout;
David S. Millere62cac12010-11-30 14:33:29 -080051 args[4] = (unsigned long) buf;
David S. Miller25edd692010-08-23 23:10:57 -070052 args[5] = 1;
53 args[6] = (unsigned long) -1;
54
55 p1275_cmd_direct(args);
56
57 if (args[6] == 1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 return 0;
59 else
60 return -1;
61}
62
63/* Blocking version of get character routine above. */
David S. Millere62cac12010-11-30 14:33:29 -080064void prom_getchar(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
David S. Millere62cac12010-11-30 14:33:29 -080066 while (1) {
67 int err = prom_nbgetchar(buf);
68 if (!err)
69 break;
70 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070071}
72
73/* Blocking version of put character routine above. */
David S. Millere62cac12010-11-30 14:33:29 -080074void prom_putchar(const char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075{
David S. Millere62cac12010-11-30 14:33:29 -080076 while (1) {
77 int err = prom_nbputchar(buf);
78 if (!err)
79 break;
80 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}