console.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* $Id: console.c,v 1.25 2001/10/30 04:54:22 davem 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) 1998 Pete Zaitcev <zaitcev@yahoo.com>
  7. */
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <asm/openprom.h>
  12. #include <asm/sun4prom.h>
  13. #include <asm/oplib.h>
  14. #include <asm/system.h>
  15. #include <linux/string.h>
  16. extern void restore_current(void);
  17. /* Non blocking get character from console input device, returns -1
  18. * if no input was taken. This can be used for polling.
  19. */
  20. int
  21. prom_nbgetchar(void)
  22. {
  23. static char inc;
  24. int i = -1;
  25. unsigned long flags;
  26. spin_lock_irqsave(&prom_lock, flags);
  27. switch(prom_vers) {
  28. case PROM_V0:
  29. case PROM_SUN4:
  30. i = (*(romvec->pv_nbgetchar))();
  31. break;
  32. case PROM_V2:
  33. case PROM_V3:
  34. if( (*(romvec->pv_v2devops).v2_dev_read)(*romvec->pv_v2bootargs.fd_stdin , &inc, 0x1) == 1) {
  35. i = inc;
  36. } else {
  37. i = -1;
  38. }
  39. break;
  40. default:
  41. i = -1;
  42. break;
  43. };
  44. restore_current();
  45. spin_unlock_irqrestore(&prom_lock, flags);
  46. return i; /* Ugh, we could spin forever on unsupported proms ;( */
  47. }
  48. /* Non blocking put character to console device, returns -1 if
  49. * unsuccessful.
  50. */
  51. int
  52. prom_nbputchar(char c)
  53. {
  54. static char outc;
  55. unsigned long flags;
  56. int i = -1;
  57. spin_lock_irqsave(&prom_lock, flags);
  58. switch(prom_vers) {
  59. case PROM_V0:
  60. case PROM_SUN4:
  61. i = (*(romvec->pv_nbputchar))(c);
  62. break;
  63. case PROM_V2:
  64. case PROM_V3:
  65. outc = c;
  66. if( (*(romvec->pv_v2devops).v2_dev_write)(*romvec->pv_v2bootargs.fd_stdout, &outc, 0x1) == 1)
  67. i = 0;
  68. else
  69. i = -1;
  70. break;
  71. default:
  72. i = -1;
  73. break;
  74. };
  75. restore_current();
  76. spin_unlock_irqrestore(&prom_lock, flags);
  77. return i; /* Ugh, we could spin forever on unsupported proms ;( */
  78. }
  79. /* Blocking version of get character routine above. */
  80. char
  81. prom_getchar(void)
  82. {
  83. int character;
  84. while((character = prom_nbgetchar()) == -1) ;
  85. return (char) character;
  86. }
  87. /* Blocking version of put character routine above. */
  88. void
  89. prom_putchar(char c)
  90. {
  91. while(prom_nbputchar(c) == -1) ;
  92. return;
  93. }