visws_apic.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:9k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /*
  2.  * linux/arch/i386/kernel/visws_apic.c
  3.  *
  4.  * Copyright (C) 1999 Bent Hagemark, Ingo Molnar
  5.  *
  6.  *  SGI Visual Workstation interrupt controller
  7.  *
  8.  *  The Cobalt system ASIC in the Visual Workstation contains a "Cobalt" APIC
  9.  *  which serves as the main interrupt controller in the system.  Non-legacy
  10.  *  hardware in the system uses this controller directly.  Legacy devices
  11.  *  are connected to the PIIX4 which in turn has its 8259(s) connected to
  12.  *  a of the Cobalt APIC entry.
  13.  */
  14. #include <linux/ptrace.h>
  15. #include <linux/errno.h>
  16. #include <linux/kernel_stat.h>
  17. #include <linux/signal.h>
  18. #include <linux/sched.h>
  19. #include <linux/ioport.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/timex.h>
  22. #include <linux/slab.h>
  23. #include <linux/random.h>
  24. #include <linux/smp.h>
  25. #include <linux/smp_lock.h>
  26. #include <linux/init.h>
  27. #include <asm/system.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #include <asm/bitops.h>
  31. #include <asm/smp.h>
  32. #include <asm/pgtable.h>
  33. #include <asm/delay.h>
  34. #include <asm/desc.h>
  35. #include <asm/cobalt.h>
  36. #include <linux/irq.h>
  37. /*
  38.  * This is the PIIX4-based 8259 that is wired up indirectly to Cobalt
  39.  * -- not the manner expected by the normal 8259 code in irq.c.
  40.  *
  41.  * there is a 'master' physical interrupt source that gets sent to
  42.  * the CPU. But in the chipset there are various 'virtual' interrupts
  43.  * waiting to be handled. We represent this to Linux through a 'master'
  44.  * interrupt controller type, and through a special virtual interrupt-
  45.  * controller. Device drivers only see the virtual interrupt sources.
  46.  */
  47. #define CO_IRQ_BASE 0x20 /* This is the 0x20 in init_IRQ()! */
  48. static void startup_piix4_master_irq(unsigned int irq);
  49. static void shutdown_piix4_master_irq(unsigned int irq);
  50. static void do_piix4_master_IRQ(unsigned int irq, struct pt_regs * regs);
  51. #define enable_piix4_master_irq startup_piix4_master_irq
  52. #define disable_piix4_master_irq shutdown_piix4_master_irq
  53. static struct hw_interrupt_type piix4_master_irq_type = {
  54. "PIIX4-master",
  55. startup_piix4_master_irq,
  56. shutdown_piix4_master_irq,
  57. do_piix4_master_IRQ,
  58. enable_piix4_master_irq,
  59. disable_piix4_master_irq
  60. };
  61. static void enable_piix4_virtual_irq(unsigned int irq);
  62. static void disable_piix4_virtual_irq(unsigned int irq);
  63. #define startup_piix4_virtual_irq enable_piix4_virtual_irq
  64. #define shutdown_piix4_virtual_irq disable_piix4_virtual_irq
  65. static struct hw_interrupt_type piix4_virtual_irq_type = {
  66. "PIIX4-virtual",
  67. startup_piix4_virtual_irq,
  68. shutdown_piix4_virtual_irq,
  69. 0, /* no handler, it's never called physically */
  70. enable_piix4_virtual_irq,
  71. disable_piix4_virtual_irq
  72. };
  73. /*
  74.  * This is the SGI Cobalt (IO-)APIC:
  75.  */
  76. static void do_cobalt_IRQ(unsigned int irq, struct pt_regs * regs);
  77. static void enable_cobalt_irq(unsigned int irq);
  78. static void disable_cobalt_irq(unsigned int irq);
  79. static void startup_cobalt_irq(unsigned int irq);
  80. #define shutdown_cobalt_irq disable_cobalt_irq
  81. static spinlock_t irq_controller_lock = SPIN_LOCK_UNLOCKED;
  82. static struct hw_interrupt_type cobalt_irq_type = {
  83. "Cobalt-APIC",
  84. startup_cobalt_irq,
  85. shutdown_cobalt_irq,
  86. do_cobalt_IRQ,
  87. enable_cobalt_irq,
  88. disable_cobalt_irq
  89. };
  90. /*
  91.  * Not an __init, needed by the reboot code
  92.  */
  93. void disable_IO_APIC(void)
  94. {
  95. /* Nop on Cobalt */
  96. /*
  97.  * Cobalt (IO)-APIC functions to handle PCI devices.
  98.  */
  99. static void disable_cobalt_irq(unsigned int irq)
  100. {
  101. /* XXX undo the APIC entry here? */
  102. /*
  103.  * definitely, we do not want to have IRQ storms from
  104.  * unused devices --mingo
  105.  */
  106. }
  107. static void enable_cobalt_irq(unsigned int irq)
  108. {
  109. }
  110. /*
  111.  * Set the given Cobalt APIC Redirection Table entry to point
  112.  * to the given IDT vector/index.
  113.  */
  114. static void co_apic_set(int entry, int idtvec)
  115. {
  116. co_apic_write(CO_APIC_LO(entry), CO_APIC_LEVEL | (CO_IRQ_BASE+idtvec));
  117. co_apic_write(CO_APIC_HI(entry), 0);
  118. printk("Cobalt APIC Entry %d IDT Vector %dn", entry, idtvec);
  119. }
  120. /*
  121.  * "irq" really just serves to identify the device.  Here is where we
  122.  * map this to the Cobalt APIC entry where it's physically wired.
  123.  * This is called via request_irq -> setup_x86_irq -> irq_desc->startup()
  124.  */
  125. static void startup_cobalt_irq(unsigned int irq)
  126. {
  127. /*
  128.  * These "irq"'s are wired to the same Cobalt APIC entries
  129.  * for all (known) motherboard types/revs
  130.  */
  131. switch (irq) {
  132. case CO_IRQ_TIMER: co_apic_set(CO_APIC_CPU, CO_IRQ_TIMER);
  133. return;
  134. case CO_IRQ_ENET: co_apic_set(CO_APIC_ENET, CO_IRQ_ENET);
  135. return;
  136. case CO_IRQ_SERIAL: return; /* XXX move to piix4-8259 "virtual" */
  137. case CO_IRQ_8259: co_apic_set(CO_APIC_8259, CO_IRQ_8259);
  138. return;
  139. case CO_IRQ_IDE:
  140. switch (visws_board_type) {
  141. case VISWS_320:
  142. switch (visws_board_rev) {
  143. case 5:
  144. co_apic_set(CO_APIC_0_5_IDE0, CO_IRQ_IDE);
  145. co_apic_set(CO_APIC_0_5_IDE1, CO_IRQ_IDE);
  146. return;
  147. case 6:
  148. co_apic_set(CO_APIC_0_6_IDE0, CO_IRQ_IDE);
  149. co_apic_set(CO_APIC_0_6_IDE1, CO_IRQ_IDE);
  150. return;
  151. }
  152. case VISWS_540:
  153. switch (visws_board_rev) {
  154. case 2:
  155. co_apic_set(CO_APIC_1_2_IDE0, CO_IRQ_IDE);
  156. return;
  157. }
  158. }
  159. break;
  160. default:
  161. panic("huh?");
  162. }
  163. }
  164. /*
  165.  * This is the handle() op in do_IRQ()
  166.  */
  167. static void do_cobalt_IRQ(unsigned int irq, struct pt_regs * regs)
  168. {
  169. struct irqaction * action;
  170. irq_desc_t *desc = irq_desc + irq;
  171. spin_lock(&irq_controller_lock);
  172. {
  173. unsigned int status;
  174. /* XXX APIC EOI? */
  175. status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
  176. action = NULL;
  177. if (!(status & (IRQ_DISABLED | IRQ_INPROGRESS))) {
  178. action = desc->action;
  179. status |= IRQ_INPROGRESS;
  180. }
  181. desc->status = status;
  182. }
  183. spin_unlock(&irq_controller_lock);
  184. /* Exit early if we had no action or it was disabled */
  185. if (!action)
  186. return;
  187. handle_IRQ_event(irq, regs, action);
  188. (void)co_cpu_read(CO_CPU_REV); /* Sync driver ack to its h/w */
  189. apic_write(APIC_EOI, APIC_EIO_ACK); /* Send EOI to Cobalt APIC */
  190. spin_lock(&irq_controller_lock);
  191. {
  192. unsigned int status = desc->status & ~IRQ_INPROGRESS;
  193. desc->status = status;
  194. if (!(status & IRQ_DISABLED))
  195. enable_cobalt_irq(irq);
  196. }
  197. spin_unlock(&irq_controller_lock);
  198. }
  199. /*
  200.  * PIIX4-8259 master/virtual functions to handle:
  201.  *
  202.  * floppy
  203.  * parallel
  204.  * serial
  205.  * audio (?)
  206.  *
  207.  * None of these get Cobalt APIC entries, neither do they have IDT
  208.  * entries. These interrupts are purely virtual and distributed from
  209.  * the 'master' interrupt source: CO_IRQ_8259.
  210.  *
  211.  * When the 8259 interrupts its handler figures out which of these
  212.  * devices is interrupting and dispatches to it's handler.
  213.  *
  214.  * CAREFUL: devices see the 'virtual' interrupt only. Thus disable/
  215.  * enable_irq gets the right irq. This 'master' irq is never directly
  216.  * manipulated by any driver.
  217.  */
  218. static void startup_piix4_master_irq(unsigned int irq)
  219. {
  220. /* ICW1 */
  221. outb(0x11, 0x20);
  222. outb(0x11, 0xa0);
  223. /* ICW2 */
  224. outb(0x08, 0x21);
  225. outb(0x70, 0xa1);
  226. /* ICW3 */
  227. outb(0x04, 0x21);
  228. outb(0x02, 0xa1);
  229. /* ICW4 */
  230. outb(0x01, 0x21);
  231. outb(0x01, 0xa1);
  232. /* OCW1 - disable all interrupts in both 8259's */
  233. outb(0xff, 0x21);
  234. outb(0xff, 0xa1);
  235. startup_cobalt_irq(irq);
  236. }
  237. static void shutdown_piix4_master_irq(unsigned int irq)
  238. {
  239. /*
  240.  * [we skip the 8259 magic here, not strictly necessary]
  241.  */
  242. shutdown_cobalt_irq(irq);
  243. }
  244. static void do_piix4_master_IRQ(unsigned int irq, struct pt_regs * regs)
  245. {
  246. int realirq, mask;
  247. /* Find out what's interrupting in the PIIX4 8259 */
  248. spin_lock(&irq_controller_lock);
  249. outb(0x0c, 0x20); /* OCW3 Poll command */
  250. realirq = inb(0x20);
  251. if (!(realirq & 0x80)) {
  252. /*
  253.  * Bit 7 == 0 means invalid/spurious
  254.  */
  255. goto out_unlock;
  256. }
  257. realirq &= 0x7f;
  258. /*
  259.  * mask and ack the 8259
  260.  */
  261. mask = inb(0x21);
  262. if ((mask >> realirq) & 0x01)
  263. /*
  264.  * This IRQ is masked... ignore
  265.  */
  266. goto out_unlock;
  267. outb(mask | (1<<realirq), 0x21);
  268. /*
  269.  * OCW2 - non-specific EOI
  270.  */
  271. outb(0x20, 0x20);
  272. spin_unlock(&irq_controller_lock);
  273. /*
  274.  * handle this 'virtual interrupt' as a Cobalt one now.
  275.  */
  276. kstat.irqs[smp_processor_id()][irq]++;
  277. do_cobalt_IRQ(realirq, regs);
  278. spin_lock(&irq_controller_lock);
  279. {
  280. irq_desc_t *desc = irq_desc + realirq;
  281. if (!(desc->status & IRQ_DISABLED))
  282. enable_piix4_virtual_irq(realirq);
  283. }
  284. spin_unlock(&irq_controller_lock);
  285. return;
  286. out_unlock:
  287. spin_unlock(&irq_controller_lock);
  288. return;
  289. }
  290. static void enable_piix4_virtual_irq(unsigned int irq)
  291. {
  292. /*
  293.  * assumes this irq is one of the legacy devices
  294.  */
  295. unsigned int mask = inb(0x21);
  296.   mask &= ~(1 << irq);
  297. outb(mask, 0x21);
  298. enable_cobalt_irq(irq);
  299. }
  300. /*
  301.  * assumes this irq is one of the legacy devices
  302.  */
  303. static void disable_piix4_virtual_irq(unsigned int irq)
  304. {
  305. unsigned int mask;
  306. disable_cobalt_irq(irq);
  307. mask = inb(0x21);
  308.   mask &= ~(1 << irq);
  309. outb(mask, 0x21);
  310. }
  311. static struct irqaction master_action =
  312. { no_action, 0, 0, "PIIX4-8259", NULL, NULL };
  313. void init_VISWS_APIC_irqs(void)
  314. {
  315. int i;
  316. for (i = 0; i < 16; i++) {
  317. irq_desc[i].status = IRQ_DISABLED;
  318. irq_desc[i].action = 0;
  319. irq_desc[i].depth = 1;
  320. /*
  321.  * Cobalt IRQs are mapped to standard ISA
  322.  * interrupt vectors:
  323.  */
  324. switch (i) {
  325. /*
  326.  * Only CO_IRQ_8259 will be raised
  327.  * externally.
  328.  */
  329. case CO_IRQ_8259:
  330. irq_desc[i].handler = &piix4_master_irq_type;
  331. break;
  332. case CO_IRQ_FLOPPY:
  333. case CO_IRQ_PARLL:
  334. irq_desc[i].handler = &piix4_virtual_irq_type;
  335. break;
  336. default:
  337. irq_desc[i].handler = &cobalt_irq_type;
  338. break;
  339. }
  340. }
  341. /*
  342.  * The master interrupt is always present:
  343.  */
  344. setup_x86_irq(CO_IRQ_8259, &master_action);
  345. }