PageRenderTime 57ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/kern/arm32/shark/pic.c

https://bitbucket.org/mischief/oskit
C | 234 lines | 85 code | 24 blank | 125 comment | 11 complexity | a008ecbd149d8f20b290d21e61d3b965 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Copyright (c) 1994-1999 University of Utah and the Flux Group.
  3. * All rights reserved.
  4. *
  5. * This file is part of the Flux OSKit. The OSKit is free software, also known
  6. * as "open source;" you can redistribute it and/or modify it under the terms
  7. * of the GNU General Public License (GPL), version 2, as published by the Free
  8. * Software Foundation (FSF). To explore alternate licensing terms, contact
  9. * the University of Utah at csl-dist@cs.utah.edu or +1-801-585-3271.
  10. *
  11. * The OSKit is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  13. * FOR A PARTICULAR PURPOSE. See the GPL for more details. You should have
  14. * received a copy of the GPL along with the OSKit; see the file COPYING. If
  15. * not, write to the FSF, 59 Temple Place #330, Boston, MA 02111-1307, USA.
  16. */
  17. /*
  18. * Copyright 1997
  19. * Digital Equipment Corporation. All rights reserved.
  20. *
  21. * This software is furnished under license and may be used and
  22. * copied only in accordance with the following terms and conditions.
  23. * Subject to these conditions, you may download, copy, install,
  24. * use, modify and distribute this software in source and/or binary
  25. * form. No title or ownership is transferred hereby.
  26. *
  27. * 1) Any source code used, modified or distributed must reproduce
  28. * and retain this copyright notice and list of conditions as
  29. * they appear in the source file.
  30. *
  31. * 2) No right is granted to use any trade name, trademark, or logo of
  32. * Digital Equipment Corporation. Neither the "Digital Equipment
  33. * Corporation" name nor any trademark or logo of Digital Equipment
  34. * Corporation may be used to endorse or promote products derived
  35. * from this software without the prior written permission of
  36. * Digital Equipment Corporation.
  37. *
  38. * 3) This software is provided "AS-IS" and any express or implied
  39. * warranties, including but not limited to, any implied warranties
  40. * of merchantability, fitness for a particular purpose, or
  41. * non-infringement are disclaimed. In no event shall DIGITAL be
  42. * liable for any damages whatsoever, and in particular, DIGITAL
  43. * shall not be liable for special, indirect, consequential, or
  44. * incidental damages or damages for lost profits, loss of
  45. * revenue or loss of use, whether such damages arise in contract,
  46. * negligence, tort, under statute, in equity, at law or otherwise,
  47. * even if advised of the possibility of such damage.
  48. */
  49. /*
  50. * Mach Operating System
  51. * Copyright (c) 1991,1990,1989 Carnegie Mellon University
  52. * All Rights Reserved.
  53. *
  54. * Permission to use, copy, modify and distribute this software and its
  55. * documentation is hereby granted, provided that both the copyright
  56. * notice and this permission notice appear in all copies of the
  57. * software, derivative works or modified versions, and any portions
  58. * thereof, and that both notices appear in supporting documentation.
  59. *
  60. * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  61. * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  62. * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  63. *
  64. * Carnegie Mellon requests users of this software to return to
  65. *
  66. * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
  67. * School of Computer Science
  68. * Carnegie Mellon University
  69. * Pittsburgh PA 15213-3890
  70. *
  71. * any improvements or extensions that they make and grant Carnegie Mellon
  72. * the rights to redistribute these changes.
  73. */
  74. /*
  75. Copyright (c) 1988,1989 Prime Computer, Inc. Natick, MA 01760
  76. All Rights Reserved.
  77. Permission to use, copy, modify, and distribute this
  78. software and its documentation for any purpose and
  79. without fee is hereby granted, provided that the above
  80. copyright notice appears in all copies and that both the
  81. copyright notice and this permission notice appear in
  82. supporting documentation, and that the name of Prime
  83. Computer, Inc. not be used in advertising or publicity
  84. pertaining to distribution of the software without
  85. specific, written prior permission.
  86. THIS SOFTWARE IS PROVIDED "AS IS", AND PRIME COMPUTER,
  87. INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
  88. SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  89. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN
  90. NO EVENT SHALL PRIME COMPUTER, INC. BE LIABLE FOR ANY
  91. SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
  92. DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
  93. PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR
  94. OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION
  95. WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  96. */
  97. /*
  98. * Routines for manipulating the 8259A Programmable Interrupt
  99. * Controller (PIC)
  100. */
  101. #include <sys/types.h>
  102. #include <oskit/arm32/pio.h>
  103. #include <oskit/arm32/proc_reg.h>
  104. #include <oskit/arm32/shark/pic.h>
  105. #include <assert.h>
  106. /*
  107. * Initialize the PIC,
  108. * Note that we don't disable all intrs here, you can call pic_disable_all.
  109. *
  110. * XXX the original Mach version put delays after the outb's in this
  111. * function, so we do the same thing (FreeBSD doesn't.) Don't know if
  112. * this is still required, the enable/disable functions below work
  113. * like champs without it.
  114. */
  115. void
  116. pic_init(unsigned char master_base, unsigned char slave_base)
  117. {
  118. /* Initialize the master. */
  119. outb_p(MASTER_ICW, PICM_ICW1|LEVL_TRIGGER);
  120. outb_p(MASTER_OCW, master_base);
  121. outb_p(MASTER_OCW, PICM_ICW3);
  122. outb_p(MASTER_OCW, PICM_ICW4|AUTO_EOI_MOD);
  123. outb_p(MASTER_ICW, 0x68); /* special mask mode (if available) */
  124. outb_p(MASTER_ICW, 0x0a); /* Read IRR, not ISR */
  125. /* Initialize the slave. */
  126. outb_p(SLAVES_ICW, PICS_ICW1|LEVL_TRIGGER);
  127. outb_p(SLAVES_OCW, slave_base);
  128. outb_p(SLAVES_OCW, PICS_ICW3);
  129. outb_p(SLAVES_OCW, PICS_ICW4|AUTO_EOI_MOD);
  130. outb_p(SLAVES_ICW, 0x68); /* special mask mode (if available) */
  131. outb_p(SLAVES_ICW, 0x0a); /* Read IRR, not ISR */
  132. /* Ack any bogus intrs by setting the End Of Interrupt bit. */
  133. outb_p(MASTER_ICW, NON_SPEC_EOI);
  134. outb_p(SLAVES_ICW, NON_SPEC_EOI);
  135. }
  136. /*
  137. * Enable the irq by clearing the appropriate bit in the PIC.
  138. */
  139. void
  140. pic_enable_irq(unsigned char irq)
  141. {
  142. unsigned int enabled = interrupts_enabled();
  143. assert(irq < 16);
  144. disable_interrupts();
  145. if (irq < 8)
  146. outb(MASTER_OCW, inb(MASTER_OCW) & ~(1 << irq));
  147. else {
  148. /* Enable the cascade line on the master. */
  149. outb(MASTER_OCW, inb(MASTER_OCW) & ~(1 << 2));
  150. irq -= 8;
  151. outb(SLAVES_OCW, inb(SLAVES_OCW) & ~(1 << irq));
  152. }
  153. if (enabled)
  154. enable_interrupts();
  155. }
  156. /*
  157. * Disable the irq by setting the appropriate bit in the PIC.
  158. */
  159. void
  160. pic_disable_irq(unsigned char irq)
  161. {
  162. unsigned int enabled = interrupts_enabled();
  163. assert(irq < 16);
  164. disable_interrupts();
  165. if (irq < 8)
  166. outb(MASTER_OCW, inb(MASTER_OCW) | (1 << irq));
  167. else {
  168. irq -= 8;
  169. outb(SLAVES_OCW, inb(SLAVES_OCW) | (1 << irq));
  170. }
  171. if (enabled)
  172. enable_interrupts();
  173. }
  174. /*
  175. * Check to see if the specified irq is currently pending.
  176. */
  177. int
  178. pic_test_irq(unsigned char irq)
  179. {
  180. assert(irq < 16);
  181. if (irq < 8)
  182. return inb(MASTER_ICW) & (1 << irq);
  183. else {
  184. irq -= 8;
  185. return inb(SLAVES_ICW) & (1 << irq);
  186. }
  187. }
  188. int
  189. pic_get_irqmask(void)
  190. {
  191. return (inb(SLAVES_OCW) << 8) | inb(MASTER_OCW);
  192. }
  193. void
  194. pic_set_irqmask(int mask)
  195. {
  196. unsigned int enabled, m, s;
  197. m = mask & 0xff;
  198. s = (mask >> 8) & 0xff;
  199. /* ensure that slave PIC is enabled if necessary */
  200. if (s != PICS_MASK)
  201. m &= ~(1 << 2);
  202. enabled = interrupts_enabled();
  203. disable_interrupts();
  204. outb(MASTER_OCW, m);
  205. outb(SLAVES_OCW, s);
  206. if (enabled)
  207. enable_interrupts();
  208. }