1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * linux/arch/alpha/kernel/irq_i8259.c 4 * 5 * This is the 'legacy' 8259A Programmable Interrupt Controller, 6 * present in the majority of PC/AT boxes. 7 * 8 * Started hacking from linux-2.3.30pre6/arch/i386/kernel/i8259.c. 9 */ 10 11 #include <linux/init.h> 12 #include <linux/cache.h> 13 #include <linux/sched.h> 14 #include <linux/irq.h> 15 #include <linux/interrupt.h> 16 17 #include <asm/io.h> 18 19 #include "proto.h" 20 #include "irq_impl.h" 21 22 23 /* Note mask bit is true for DISABLED irqs. */ 24 static unsigned int cached_irq_mask = 0xffff; 25 static DEFINE_RAW_SPINLOCK(i8259_irq_lock); 26 27 static inline void 28 i8259_update_irq_hw(unsigned int irq, unsigned long mask) 29 { 30 int port = 0x21; 31 if (irq & 8) mask >>= 8; 32 if (irq & 8) port = 0xA1; 33 outb(mask, port); 34 } 35 36 inline void 37 i8259a_enable_irq(struct irq_data *d) 38 { 39 unsigned long flags; 40 41 raw_spin_lock_irqsave(&i8259_irq_lock, flags); 42 i8259_update_irq_hw(d->irq, cached_irq_mask &= ~(1 << d->irq)); 43 raw_spin_unlock_irqrestore(&i8259_irq_lock, flags); 44 } 45 46 static inline void 47 __i8259a_disable_irq(unsigned int irq) 48 { 49 i8259_update_irq_hw(irq, cached_irq_mask |= 1 << irq); 50 } 51 52 void 53 i8259a_disable_irq(struct irq_data *d) 54 { 55 unsigned long flags; 56 57 raw_spin_lock_irqsave(&i8259_irq_lock, flags); 58 __i8259a_disable_irq(d->irq); 59 raw_spin_unlock_irqrestore(&i8259_irq_lock, flags); 60 } 61 62 void 63 i8259a_mask_and_ack_irq(struct irq_data *d) 64 { 65 unsigned int irq = d->irq; 66 unsigned long flags; 67 68 raw_spin_lock_irqsave(&i8259_irq_lock, flags); 69 __i8259a_disable_irq(irq); 70 71 /* Ack the interrupt making it the lowest priority. */ 72 if (irq >= 8) { 73 outb(0xE0 | (irq - 8), 0xa0); /* ack the slave */ 74 irq = 2; 75 } 76 outb(0xE0 | irq, 0x20); /* ack the master */ 77 raw_spin_unlock_irqrestore(&i8259_irq_lock, flags); 78 } 79 80 struct irq_chip i8259a_irq_type = { 81 .name = "XT-PIC", 82 .irq_unmask = i8259a_enable_irq, 83 .irq_mask = i8259a_disable_irq, 84 .irq_mask_ack = i8259a_mask_and_ack_irq, 85 }; 86 87 void __init 88 init_i8259a_irqs(void) 89 { 90 long i; 91 92 outb(0xff, 0x21); /* mask all of 8259A-1 */ 93 outb(0xff, 0xA1); /* mask all of 8259A-2 */ 94 95 for (i = 0; i < 16; i++) { 96 irq_set_chip_and_handler(i, &i8259a_irq_type, handle_level_irq); 97 } 98 99 if (request_irq(2, no_action, 0, "cascade", NULL)) 100 pr_err("Failed to request irq 2 (cascade)\n"); 101 } 102 103 104 #if defined(CONFIG_ALPHA_GENERIC) 105 # define IACK_SC alpha_mv.iack_sc 106 #elif defined(CONFIG_ALPHA_CIA) 107 # define IACK_SC CIA_IACK_SC 108 #elif defined(CONFIG_ALPHA_PYXIS) 109 # define IACK_SC PYXIS_IACK_SC 110 #elif defined(CONFIG_ALPHA_TITAN) 111 # define IACK_SC TITAN_IACK_SC 112 #elif defined(CONFIG_ALPHA_TSUNAMI) 113 # define IACK_SC TSUNAMI_IACK_SC 114 #elif defined(CONFIG_ALPHA_IRONGATE) 115 # define IACK_SC IRONGATE_IACK_SC 116 #endif 117 /* Note that CONFIG_ALPHA_POLARIS is intentionally left out here, since 118 sys_rx164 wants to use isa_no_iack_sc_device_interrupt for some reason. */ 119 120 #if defined(IACK_SC) 121 void 122 isa_device_interrupt(unsigned long vector) 123 { 124 /* 125 * Generate a PCI interrupt acknowledge cycle. The PIC will 126 * respond with the interrupt vector of the highest priority 127 * interrupt that is pending. The PALcode sets up the 128 * interrupts vectors such that irq level L generates vector L. 129 */ 130 int j = *(vuip) IACK_SC; 131 j &= 0xff; 132 handle_irq(j); 133 } 134 #endif 135 136 #if defined(CONFIG_ALPHA_GENERIC) || !defined(IACK_SC) 137 void 138 isa_no_iack_sc_device_interrupt(unsigned long vector) 139 { 140 unsigned long pic; 141 142 /* 143 * It seems to me that the probability of two or more *device* 144 * interrupts occurring at almost exactly the same time is 145 * pretty low. So why pay the price of checking for 146 * additional interrupts here if the common case can be 147 * handled so much easier? 148 */ 149 /* 150 * The first read of gives you *all* interrupting lines. 151 * Therefore, read the mask register and and out those lines 152 * not enabled. Note that some documentation has 21 and a1 153 * write only. This is not true. 154 */ 155 pic = inb(0x20) | (inb(0xA0) << 8); /* read isr */ 156 pic &= 0xFFFB; /* mask out cascade & hibits */ 157 158 while (pic) { 159 int j = ffz(~pic); 160 pic &= pic - 1; 161 handle_irq(j); 162 } 163 } 164 #endif 165