sio.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. /* $OpenBSD: sio.c,v 1.3 2013/10/29 21:49:07 miod Exp $ */
  2. /* $NetBSD: sio.c,v 1.3 2013/01/21 11:58:12 tsutsui Exp $ */
  3. /*
  4. * Copyright (c) 1992 OMRON Corporation.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * OMRON Corporation.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. All advertising materials mentioning features or use of this software
  18. * must display the following acknowledgement:
  19. * This product includes software developed by the University of
  20. * California, Berkeley and its contributors.
  21. * 4. Neither the name of the University nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  26. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  28. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  29. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  34. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. *
  37. * @(#)sio.c 8.1 (Berkeley) 6/10/93
  38. */
  39. /*
  40. * Copyright (c) 1992, 1993
  41. * The Regents of the University of California. All rights reserved.
  42. *
  43. * This code is derived from software contributed to Berkeley by
  44. * OMRON Corporation.
  45. *
  46. * Redistribution and use in source and binary forms, with or without
  47. * modification, are permitted provided that the following conditions
  48. * are met:
  49. * 1. Redistributions of source code must retain the above copyright
  50. * notice, this list of conditions and the following disclaimer.
  51. * 2. Redistributions in binary form must reproduce the above copyright
  52. * notice, this list of conditions and the following disclaimer in the
  53. * documentation and/or other materials provided with the distribution.
  54. * 3. Neither the name of the University nor the names of its contributors
  55. * may be used to endorse or promote products derived from this software
  56. * without specific prior written permission.
  57. *
  58. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  59. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  60. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  61. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  62. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  63. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  64. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  65. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  66. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  67. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  68. * SUCH DAMAGE.
  69. *
  70. * @(#)sio.c 8.1 (Berkeley) 6/10/93
  71. */
  72. /* sio.c NOV-25-1991 */
  73. #define NSIO 2
  74. #include <sys/param.h>
  75. #include <machine/board.h>
  76. #include <luna88k/stand/boot/samachdep.h>
  77. #include <luna88k/stand/boot/sioreg.h>
  78. #include <luna88k/stand/boot/rcvbuf.h>
  79. #include <luna88k/stand/boot/kbdreg.h>
  80. static int siointr(int);
  81. static int sioreg(int, int);
  82. struct rcvbuf rcvbuf[NSIO];
  83. int sioconsole = -1;
  84. struct siodevice *sio_addr[2];
  85. void
  86. _siointr(void)
  87. {
  88. int unit;
  89. for (unit = 0; unit < NSIO; unit++)
  90. while (siointr(unit) != 0)
  91. continue;
  92. }
  93. int
  94. siointr(int unit)
  95. {
  96. /* struct siodevice *sio = sio_addr[unit]; */
  97. int rr0 = sioreg(REG(unit, RR0), 0);
  98. int rr1 = sioreg(REG(unit, RR1), 0);
  99. if (rr0 & RR0_RXAVAIL) {
  100. if (rr1 & RR1_FRAMING)
  101. return 1;
  102. if (rr1 & (RR1_PARITY | RR1_OVERRUN))
  103. sioreg(REG(unit, WR0), WR0_ERRRST); /* Channel-A Error Reset */
  104. if (unit == 1) {
  105. int c = kbd_decode(sio_addr[unit]->sio_data);
  106. if ((c & KC_TYPE) == KC_CODE)
  107. PUSH_RBUF(unit, c);
  108. } else {
  109. PUSH_RBUF(unit, sio_addr[unit]->sio_data);
  110. }
  111. return 1;
  112. }
  113. return 0;
  114. }
  115. /*
  116. * Following are all routines needed for SIO to act as console
  117. */
  118. #include <dev/cons.h>
  119. void
  120. siocnprobe(struct consdev *cp)
  121. {
  122. sio_addr[0] = (struct siodevice *)OBIO_SIO;
  123. sio_addr[1] = (struct siodevice *)OBIO_SIO + 1;
  124. /* make sure hardware exists */
  125. if (badaddr(sio_addr[0], 4) != 0) {
  126. cp->cn_pri = CN_DEAD;
  127. return;
  128. }
  129. /* locate the major number */
  130. /* initialize required fields */
  131. cp->cn_dev = 0;
  132. cp->cn_pri = CN_LOWPRI;
  133. }
  134. void
  135. siocninit(struct consdev *cp)
  136. {
  137. int unit = cp->cn_dev;
  138. sioinit();
  139. sioconsole = unit;
  140. }
  141. int
  142. siocngetc(dev_t dev)
  143. {
  144. int c, unit = dev;
  145. _siointr();
  146. if (RBUF_EMPTY(unit))
  147. return 0;
  148. POP_RBUF(unit, c);
  149. return(c);
  150. }
  151. void
  152. siocnputc(dev_t dev, int c)
  153. {
  154. int unit = dev;
  155. if (sioconsole == -1) {
  156. (void) sioinit();
  157. sioconsole = unit;
  158. }
  159. /* wait for any pending transmission to finish */
  160. while ((sioreg(REG(unit, RR0), 0) & RR0_TXEMPTY) == 0);
  161. sio_addr[unit]->sio_data = (c & 0xFF);
  162. /* wait for any pending transmission to finish */
  163. while ((sioreg(REG(unit, RR0), 0) & RR0_TXEMPTY) == 0);
  164. }
  165. /* SIO misc routines */
  166. void
  167. sioinit(void)
  168. {
  169. RBUF_INIT(0);
  170. RBUF_INIT(1);
  171. sioreg(REG(0, WR0), WR0_CHANRST); /* Channel-A Reset */
  172. sioreg(WR2A, WR2_VEC86 | WR2_INTR_1); /* Set CPU BUS Interface Mode */
  173. sioreg(WR2B, 0); /* Set Interrupt Vector */
  174. sioreg(REG(0, WR0), WR0_RSTINT); /* Reset E/S Interrupt */
  175. sioreg(REG(0, WR4), WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY); /* Tx/Rx */
  176. sioreg(REG(0, WR3), WR3_RX8BIT | WR3_RXENBL); /* Rx */
  177. sioreg(REG(0, WR5), WR5_TX8BIT | WR5_TXENBL | WR5_DTR | WR5_RTS); /* Tx */
  178. sioreg(REG(0, WR0), WR0_RSTINT); /* Reset E/S Interrupt */
  179. sioreg(REG(0, WR1), WR1_RXALLS); /* Interrupted All Char. */
  180. sioreg(REG(1, WR0), WR0_CHANRST); /* Channel-A Reset */
  181. sioreg(REG(1, WR0), WR0_RSTINT); /* Reset E/S Interrupt */
  182. sioreg(REG(1, WR4), WR4_BAUD96 | WR4_STOP1 | WR4_NPARITY); /* Tx/Rx */
  183. sioreg(REG(1, WR3), WR3_RX8BIT | WR3_RXENBL); /* Rx */
  184. sioreg(REG(1, WR5), WR5_TX8BIT | WR5_TXENBL); /* Tx */
  185. sioreg(REG(1, WR0), WR0_RSTINT); /* Reset E/S Interrupt */
  186. sioreg(REG(1, WR1), WR1_RXALLS); /* Interrupted All Char. */
  187. }
  188. int
  189. sioreg(int reg, int val)
  190. {
  191. int chan;
  192. chan = CHANNEL(reg);
  193. if (isStatusReg(reg)) {
  194. if (REGNO(reg) != 0)
  195. sio_addr[chan]->sio_cmd = REGNO(reg);
  196. return(sio_addr[chan]->sio_stat);
  197. } else {
  198. if (REGNO(reg) != 0)
  199. sio_addr[chan]->sio_cmd = REGNO(reg);
  200. sio_addr[chan]->sio_cmd = val;
  201. return(val);
  202. }
  203. }