Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86, ioapic: Use proper defines for the entry fields

While looking at the printout issue, I stumbled more than once over
the various 0/1 assignments which are either commented in strange ways
or force to lookup the meaning.

Use proper constants and fix the misleading comments. While at it
remove pointless 0 assignments in native_disable_io_apic() which have
no value for understanding the code.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: David Cohen <david.a.cohen@linux.intel.com>
Cc: Sander Eikelenboom <linux@eikelenboom.it>
Cc: David Vrabel <david.vrabel@citrix.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: Joerg Roedel <joro@8bytes.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Rafael J. Wysocki <rjw@rjwysocki.net>
Cc: Randy Dunlap <rdunlap@infradead.org>
Cc: Yinghai Lu <yinghai@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dimitri Sivanich <sivanich@sgi.com>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: x86@kernel.org
Link: http://lkml.kernel.org/r/1428978610-28986-30-git-send-email-jiang.liu@linux.intel.com
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

+63 -53
+13 -3
arch/x86/include/asm/io_apic.h
··· 98 98 struct irq_alloc_info; 99 99 struct irq_data; 100 100 101 - #define IOAPIC_AUTO -1 102 - #define IOAPIC_EDGE 0 103 - #define IOAPIC_LEVEL 1 101 + #define IOAPIC_AUTO -1 102 + #define IOAPIC_EDGE 0 103 + #define IOAPIC_LEVEL 1 104 + 105 + #define IOAPIC_MASKED 1 106 + #define IOAPIC_UNMASKED 0 107 + 108 + #define IOAPIC_POL_HIGH 0 109 + #define IOAPIC_POL_LOW 1 110 + 111 + #define IOAPIC_DEST_MODE_PHYSICAL 0 112 + #define IOAPIC_DEST_MODE_LOGICAL 1 113 + 104 114 #define IOAPIC_MAP_ALLOC 0x1 105 115 #define IOAPIC_MAP_CHECK 0x2 106 116
+50 -50
arch/x86/kernel/apic/io_apic.c
··· 356 356 static void ioapic_mask_entry(int apic, int pin) 357 357 { 358 358 unsigned long flags; 359 - union entry_union eu = { .entry.mask = 1 }; 359 + union entry_union eu = { .entry.mask = IOAPIC_MASKED }; 360 360 361 361 raw_spin_lock_irqsave(&ioapic_lock, flags); 362 362 io_apic_write(apic, 0x10 + 2*pin, eu.w1); ··· 517 517 /* 518 518 * Mask the entry and change the trigger mode to edge. 519 519 */ 520 - entry1.mask = 1; 520 + entry1.mask = IOAPIC_MASKED; 521 521 entry1.trigger = IOAPIC_EDGE; 522 522 523 523 __ioapic_write_entry(apic, pin, entry1); ··· 553 553 * Make sure the entry is masked and re-read the contents to check 554 554 * if it is a level triggered pin and if the remote-IRR is set. 555 555 */ 556 - if (!entry.mask) { 557 - entry.mask = 1; 556 + if (entry.mask == IOAPIC_UNMASKED) { 557 + entry.mask = IOAPIC_MASKED; 558 558 ioapic_write_entry(apic, pin, entry); 559 559 entry = ioapic_read_entry(apic, pin); 560 560 } ··· 567 567 * doesn't clear the remote-IRR if the trigger mode is not 568 568 * set to level. 569 569 */ 570 - if (!entry.trigger) { 570 + if (entry.trigger == IOAPIC_EDGE) { 571 571 entry.trigger = IOAPIC_LEVEL; 572 572 ioapic_write_entry(apic, pin, entry); 573 573 } ··· 670 670 struct IO_APIC_route_entry entry; 671 671 672 672 entry = ioapics[apic].saved_registers[pin]; 673 - if (!entry.mask) { 674 - entry.mask = 1; 673 + if (entry.mask == IOAPIC_UNMASKED) { 674 + entry.mask = IOAPIC_MASKED; 675 675 ioapic_write_entry(apic, pin, entry); 676 676 } 677 677 } ··· 773 773 774 774 #endif 775 775 776 - /* ISA interrupts are always polarity zero edge triggered, 776 + /* ISA interrupts are always active high edge triggered, 777 777 * when listed as conforming in the MP table. */ 778 778 779 - #define default_ISA_trigger(idx) (0) 780 - #define default_ISA_polarity(idx) (0) 779 + #define default_ISA_trigger(idx) (IOAPIC_EDGE) 780 + #define default_ISA_polarity(idx) (IOAPIC_POL_HIGH) 781 781 782 782 /* EISA interrupts are always polarity zero and can be edge or level 783 783 * trigger depending on the ELCR value. If an interrupt is listed as ··· 787 787 #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].srcbusirq)) 788 788 #define default_EISA_polarity(idx) default_ISA_polarity(idx) 789 789 790 - /* PCI interrupts are always polarity one level triggered, 790 + /* PCI interrupts are always active low level triggered, 791 791 * when listed as conforming in the MP table. */ 792 792 793 - #define default_PCI_trigger(idx) (1) 794 - #define default_PCI_polarity(idx) (1) 793 + #define default_PCI_trigger(idx) (IOAPIC_LEVEL) 794 + #define default_PCI_polarity(idx) (IOAPIC_POL_LOW) 795 795 796 796 static int irq_polarity(int idx) 797 797 { ··· 811 811 break; 812 812 case 1: /* high active */ 813 813 { 814 - polarity = 0; 814 + polarity = IOAPIC_POL_HIGH; 815 815 break; 816 816 } 817 817 case 2: /* reserved */ 818 818 { 819 819 pr_warn("broken BIOS!!\n"); 820 - polarity = 1; 820 + polarity = IOAPIC_POL_LOW; 821 821 break; 822 822 } 823 823 case 3: /* low active */ 824 824 { 825 - polarity = 1; 825 + polarity = IOAPIC_POL_LOW; 826 826 break; 827 827 } 828 828 default: /* invalid */ 829 829 { 830 830 pr_warn("broken BIOS!!\n"); 831 - polarity = 1; 831 + polarity = IOAPIC_POL_LOW; 832 832 break; 833 833 } 834 834 } ··· 870 870 default: 871 871 { 872 872 pr_warn("broken BIOS!!\n"); 873 - trigger = 1; 873 + trigger = IOAPIC_LEVEL; 874 874 break; 875 875 } 876 876 } ··· 878 878 break; 879 879 case 1: /* edge */ 880 880 { 881 - trigger = 0; 881 + trigger = IOAPIC_EDGE; 882 882 break; 883 883 } 884 884 case 2: /* reserved */ 885 885 { 886 886 pr_warn("broken BIOS!!\n"); 887 - trigger = 1; 887 + trigger = IOAPIC_LEVEL; 888 888 break; 889 889 } 890 890 case 3: /* level */ 891 891 { 892 - trigger = 1; 892 + trigger = IOAPIC_LEVEL; 893 893 break; 894 894 } 895 895 default: /* invalid */ 896 896 { 897 897 pr_warn("broken BIOS!!\n"); 898 - trigger = 0; 898 + trigger = IOAPIC_EDGE; 899 899 break; 900 900 } 901 901 } ··· 939 939 dst->ioapic_polarity = polarity; 940 940 } else { 941 941 /* 942 - * PCI interrupts are always polarity one level 942 + * PCI interrupts are always active low level 943 943 * triggered. 944 944 */ 945 - dst->ioapic_trigger = 1; 946 - dst->ioapic_polarity = 1; 945 + dst->ioapic_trigger = IOAPIC_LEVEL; 946 + dst->ioapic_polarity = IOAPIC_POL_LOW; 947 947 } 948 948 } 949 949 } ··· 1296 1296 entry = ioapic_read_entry(apic, i); 1297 1297 snprintf(buf, sizeof(buf), 1298 1298 " pin%02x, %s, %s, %s, V(%02X), IRR(%1d), S(%1d)", 1299 - i, entry.mask ? "disabled" : "enabled ", 1300 - entry.trigger ? "level" : "edge ", 1301 - entry.polarity ? "low " : "high", 1299 + i, 1300 + entry.mask == IOAPIC_MASKED ? "disabled" : "enabled ", 1301 + entry.trigger == IOAPIC_LEVEL ? "level" : "edge ", 1302 + entry.polarity == IOAPIC_POL_LOW ? "low " : "high", 1302 1303 entry.vector, entry.irr, entry.delivery_status); 1303 1304 if (ir_entry->format) 1304 1305 printk(KERN_DEBUG "%s, remapped, I(%04X), Z(%X)\n", ··· 1307 1306 ir_entry->zero); 1308 1307 else 1309 1308 printk(KERN_DEBUG "%s, %s, D(%02X), M(%1d)\n", 1310 - buf, entry.dest_mode ? "logical " : "physical", 1309 + buf, 1310 + entry.dest_mode == IOAPIC_DEST_MODE_LOGICAL ? 1311 + "logical " : "physical", 1311 1312 entry.dest, entry.delivery_mode); 1312 1313 } 1313 1314 } ··· 1479 1476 struct IO_APIC_route_entry entry; 1480 1477 1481 1478 memset(&entry, 0, sizeof(entry)); 1482 - entry.mask = 0; /* Enabled */ 1483 - entry.trigger = 0; /* Edge */ 1484 - entry.irr = 0; 1485 - entry.polarity = 0; /* High */ 1486 - entry.delivery_status = 0; 1487 - entry.dest_mode = 0; /* Physical */ 1488 - entry.delivery_mode = dest_ExtINT; /* ExtInt */ 1489 - entry.vector = 0; 1490 - entry.dest = read_apic_id(); 1479 + entry.mask = IOAPIC_UNMASKED; 1480 + entry.trigger = IOAPIC_EDGE; 1481 + entry.polarity = IOAPIC_POL_HIGH; 1482 + entry.dest_mode = IOAPIC_DEST_MODE_PHYSICAL; 1483 + entry.delivery_mode = dest_ExtINT; 1484 + entry.dest = read_apic_id(); 1491 1485 1492 1486 /* 1493 1487 * Add it to the IO-APIC irq-routing table: ··· 1494 1494 1495 1495 if (cpu_has_apic || apic_from_smp_config()) 1496 1496 disconnect_bsp_APIC(ioapic_i8259.pin != -1); 1497 - 1498 1497 } 1499 1498 1500 1499 /* ··· 2017 2018 2018 2019 memset(&entry1, 0, sizeof(entry1)); 2019 2020 2020 - entry1.dest_mode = 0; /* physical delivery */ 2021 - entry1.mask = 0; /* unmask IRQ now */ 2021 + entry1.dest_mode = IOAPIC_DEST_MODE_PHYSICAL; 2022 + entry1.mask = IOAPIC_UNMASKED; 2022 2023 entry1.dest = hard_smp_processor_id(); 2023 2024 entry1.delivery_mode = dest_ExtINT; 2024 2025 entry1.polarity = entry0.polarity; 2025 - entry1.trigger = 0; 2026 + entry1.trigger = IOAPIC_EDGE; 2026 2027 entry1.vector = 0; 2027 2028 2028 2029 ioapic_write_entry(apic, pin, entry1); ··· 2910 2911 data->polarity = info->ioapic_polarity; 2911 2912 } else if (acpi_get_override_irq(gsi, &data->trigger, 2912 2913 &data->polarity) < 0) { 2913 - /* PCI interrupts are always polarity one level triggered. */ 2914 - data->trigger = 1; 2915 - data->polarity = 1; 2914 + /* PCI interrupts are always active low level triggered. */ 2915 + data->trigger = IOAPIC_LEVEL; 2916 + data->polarity = IOAPIC_POL_LOW; 2916 2917 } 2917 2918 } 2918 2919 ··· 2924 2925 entry->dest_mode = apic->irq_dest_mode; 2925 2926 entry->dest = cfg->dest_apicid; 2926 2927 entry->vector = cfg->vector; 2927 - entry->mask = 0; /* enable IRQ */ 2928 2928 entry->trigger = data->trigger; 2929 2929 entry->polarity = data->polarity; 2930 2930 /* 2931 - * Mask level triggered irqs. 2932 - * Use IRQ_DELAYED_DISABLE for edge triggered irqs. 2931 + * Mask level triggered irqs. Edge triggered irqs are masked 2932 + * by the irq core code in case they fire. 2933 2933 */ 2934 - if (data->trigger) 2935 - entry->mask = 1; 2934 + if (data->trigger == IOAPIC_LEVEL) 2935 + entry->mask = IOAPIC_MASKED; 2936 + else 2937 + entry->mask = IOAPIC_UNMASKED; 2936 2938 } 2937 2939 2938 2940 int mp_irqdomain_alloc(struct irq_domain *domain, unsigned int virq,