console.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /* $Id: console.c,v 1.9 1997/10/29 07:41:43 ecd Exp $
  2. * console.c: Routines that deal with sending and receiving IO
  3. * to/from the current console device using the PROM.
  4. *
  5. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6. * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  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. extern int prom_stdin, prom_stdout;
  16. /* Non blocking get character from console input device, returns -1
  17. * if no input was taken. This can be used for polling.
  18. */
  19. __inline__ int
  20. prom_nbgetchar(void)
  21. {
  22. char inc;
  23. if (p1275_cmd("read", P1275_ARG(1,P1275_ARG_OUT_BUF)|
  24. P1275_INOUT(3,1),
  25. prom_stdin, &inc, P1275_SIZE(1)) == 1)
  26. return inc;
  27. else
  28. return -1;
  29. }
  30. /* Non blocking put character to console device, returns -1 if
  31. * unsuccessful.
  32. */
  33. __inline__ int
  34. prom_nbputchar(char c)
  35. {
  36. char outc;
  37. outc = c;
  38. if (p1275_cmd("write", P1275_ARG(1,P1275_ARG_IN_BUF)|
  39. P1275_INOUT(3,1),
  40. prom_stdout, &outc, P1275_SIZE(1)) == 1)
  41. return 0;
  42. else
  43. return -1;
  44. }
  45. /* Blocking version of get character routine above. */
  46. char
  47. prom_getchar(void)
  48. {
  49. int character;
  50. while((character = prom_nbgetchar()) == -1) ;
  51. return (char) character;
  52. }
  53. /* Blocking version of put character routine above. */
  54. void
  55. prom_putchar(char c)
  56. {
  57. prom_nbputchar(c);
  58. return;
  59. }
  60. void
  61. prom_puts(const char *s, int len)
  62. {
  63. p1275_cmd("write", P1275_ARG(1,P1275_ARG_IN_BUF)|
  64. P1275_INOUT(3,1),
  65. prom_stdout, s, P1275_SIZE(len));
  66. }