console_64.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #include <linux/types.h>
  8. #include <linux/kernel.h>
  9. #include <linux/sched.h>
  10. #include <asm/openprom.h>
  11. #include <asm/oplib.h>
  12. #include <asm/system.h>
  13. #include <linux/string.h>
  14. extern int prom_stdin, prom_stdout;
  15. /* Non blocking get character from console input device, returns -1
  16. * if no input was taken. This can be used for polling.
  17. */
  18. inline int
  19. prom_nbgetchar(void)
  20. {
  21. char inc;
  22. if (p1275_cmd("read", P1275_ARG(1,P1275_ARG_OUT_BUF)|
  23. P1275_INOUT(3,1),
  24. prom_stdin, &inc, P1275_SIZE(1)) == 1)
  25. return inc;
  26. else
  27. return -1;
  28. }
  29. /* Non blocking put character to console device, returns -1 if
  30. * unsuccessful.
  31. */
  32. inline int
  33. prom_nbputchar(char c)
  34. {
  35. char outc;
  36. outc = c;
  37. if (p1275_cmd("write", P1275_ARG(1,P1275_ARG_IN_BUF)|
  38. P1275_INOUT(3,1),
  39. prom_stdout, &outc, P1275_SIZE(1)) == 1)
  40. return 0;
  41. else
  42. return -1;
  43. }
  44. /* Blocking version of get character routine above. */
  45. char
  46. prom_getchar(void)
  47. {
  48. int character;
  49. while((character = prom_nbgetchar()) == -1) ;
  50. return (char) character;
  51. }
  52. /* Blocking version of put character routine above. */
  53. void
  54. prom_putchar(char c)
  55. {
  56. prom_nbputchar(c);
  57. return;
  58. }
  59. void
  60. prom_puts(const char *s, int len)
  61. {
  62. p1275_cmd("write", P1275_ARG(1,P1275_ARG_IN_BUF)|
  63. P1275_INOUT(3,1),
  64. prom_stdout, s, P1275_SIZE(len));
  65. }