Skip to content

Commit d253166

Browse files
maciej-w-rozyckiKAGA-KOKO
authored andcommitted
x86: Avoid magic number with ELCR register accesses
Define PIC_ELCR1 and PIC_ELCR2 macros for accesses to the ELCR registers implemented by many chipsets in their embedded 8259A PIC cores, avoiding magic numbers that are difficult to handle, and complementing the macros we already have for registers originally defined with discrete 8259A PIC implementations. No functional change. Signed-off-by: Maciej W. Rozycki <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 0e8c6f5 commit d253166

File tree

7 files changed

+15
-11
lines changed

7 files changed

+15
-11
lines changed

arch/x86/include/asm/i8259.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ extern unsigned int cached_irq_mask;
1919
#define PIC_MASTER_OCW3 PIC_MASTER_ISR
2020
#define PIC_SLAVE_CMD 0xa0
2121
#define PIC_SLAVE_IMR 0xa1
22+
#define PIC_ELCR1 0x4d0
23+
#define PIC_ELCR2 0x4d1
2224

2325
/* i8259A PIC related value */
2426
#define PIC_CASCADE_IR 2

arch/x86/kernel/acpi/boot.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,7 @@ void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
570570
unsigned int old, new;
571571

572572
/* Real old ELCR mask */
573-
old = inb(0x4d0) | (inb(0x4d1) << 8);
573+
old = inb(PIC_ELCR1) | (inb(PIC_ELCR2) << 8);
574574

575575
/*
576576
* If we use ACPI to set PCI IRQs, then we should clear ELCR
@@ -596,8 +596,8 @@ void __init acpi_pic_sci_set_trigger(unsigned int irq, u16 trigger)
596596
return;
597597

598598
pr_warn("setting ELCR to %04x (from %04x)\n", new, old);
599-
outb(new, 0x4d0);
600-
outb(new >> 8, 0x4d1);
599+
outb(new, PIC_ELCR1);
600+
outb(new >> 8, PIC_ELCR2);
601601
}
602602

603603
int acpi_gsi_to_irq(u32 gsi, unsigned int *irqp)

arch/x86/kernel/apic/io_apic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ static bool irq_active_low(int idx)
764764
static bool EISA_ELCR(unsigned int irq)
765765
{
766766
if (irq < nr_legacy_irqs()) {
767-
unsigned int port = 0x4d0 + (irq >> 3);
767+
unsigned int port = PIC_ELCR1 + (irq >> 3);
768768
return (inb(port) >> (irq & 7)) & 1;
769769
}
770770
apic_printk(APIC_VERBOSE, KERN_INFO

arch/x86/kernel/apic/vector.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,7 @@ static void __init print_PIC(void)
12991299

13001300
pr_debug("... PIC ISR: %04x\n", v);
13011301

1302-
v = inb(0x4d1) << 8 | inb(0x4d0);
1302+
v = inb(PIC_ELCR2) << 8 | inb(PIC_ELCR1);
13031303
pr_debug("... PIC ELCR: %04x\n", v);
13041304
}
13051305

arch/x86/kernel/i8259.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,15 @@ static char irq_trigger[2];
235235
*/
236236
static void restore_ELCR(char *trigger)
237237
{
238-
outb(trigger[0], 0x4d0);
239-
outb(trigger[1], 0x4d1);
238+
outb(trigger[0], PIC_ELCR1);
239+
outb(trigger[1], PIC_ELCR2);
240240
}
241241

242242
static void save_ELCR(char *trigger)
243243
{
244244
/* IRQ 0,1,2,8,13 are marked as reserved */
245-
trigger[0] = inb(0x4d0) & 0xF8;
246-
trigger[1] = inb(0x4d1) & 0xDE;
245+
trigger[0] = inb(PIC_ELCR1) & 0xF8;
246+
trigger[1] = inb(PIC_ELCR2) & 0xDE;
247247
}
248248

249249
static void i8259A_resume(void)

arch/x86/kernel/mpparse.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/smp.h>
2020
#include <linux/pci.h>
2121

22+
#include <asm/i8259.h>
2223
#include <asm/io_apic.h>
2324
#include <asm/acpi.h>
2425
#include <asm/irqdomain.h>
@@ -251,7 +252,7 @@ static int __init ELCR_trigger(unsigned int irq)
251252
{
252253
unsigned int port;
253254

254-
port = 0x4d0 + (irq >> 3);
255+
port = PIC_ELCR1 + (irq >> 3);
255256
return (inb(port) >> (irq & 7)) & 1;
256257
}
257258

arch/x86/pci/irq.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/irq.h>
1919
#include <linux/acpi.h>
2020

21+
#include <asm/i8259.h>
2122
#include <asm/pc-conf-reg.h>
2223
#include <asm/pci_x86.h>
2324

@@ -158,7 +159,7 @@ static void __init pirq_peer_trick(void)
158159
void elcr_set_level_irq(unsigned int irq)
159160
{
160161
unsigned char mask = 1 << (irq & 7);
161-
unsigned int port = 0x4d0 + (irq >> 3);
162+
unsigned int port = PIC_ELCR1 + (irq >> 3);
162163
unsigned char val;
163164
static u16 elcr_irq_mask;
164165

0 commit comments

Comments
 (0)