x86, irq: Count legacy IRQs by legacy_pic->nr_legacy_irqs instead of NR_IRQS_LEGACY
[deliverable/linux.git] / arch / x86 / kernel / apic / io_apic.c
index 81e08eff05eedbd2e839a14229464cbea456e84c..4208ea9edc108870d72fe8e1256094b4fb614a20 100644 (file)
 
 #define __apicdebuginit(type) static type __init
 
+#define        for_each_ioapic(idx)            \
+       for ((idx) = 0; (idx) < nr_ioapics; (idx)++)
+#define        for_each_ioapic_reverse(idx)    \
+       for ((idx) = nr_ioapics - 1; (idx) >= 0; (idx)--)
+#define        for_each_pin(idx, pin)          \
+       for ((pin) = 0; (pin) < ioapics[(idx)].nr_registers; (pin)++)
+#define        for_each_ioapic_pin(idx, pin)   \
+       for_each_ioapic((idx))          \
+               for_each_pin((idx), (pin))
+
 #define for_each_irq_pin(entry, head) \
        for (entry = head; entry; entry = entry->next)
 
@@ -107,6 +117,31 @@ struct mp_ioapic_gsi *mp_ioapic_gsi_routing(int ioapic_idx)
        return &ioapics[ioapic_idx].gsi_config;
 }
 
+static inline int mp_ioapic_pin_count(int ioapic)
+{
+       struct mp_ioapic_gsi *gsi_cfg = mp_ioapic_gsi_routing(ioapic);
+
+       return gsi_cfg->gsi_end - gsi_cfg->gsi_base + 1;
+}
+
+u32 mp_pin_to_gsi(int ioapic, int pin)
+{
+       return mp_ioapic_gsi_routing(ioapic)->gsi_base + pin;
+}
+
+/*
+ * Initialize all legacy IRQs and all pins on the first IOAPIC
+ * if we have legacy interrupt controller. Kernel boot option "pirq="
+ * may rely on non-legacy pins on the first IOAPIC.
+ */
+static inline int mp_init_irq_at_boot(int ioapic, int irq)
+{
+       if (!nr_legacy_irqs())
+               return 0;
+
+       return ioapic == 0 || (irq >= 0 && irq < nr_legacy_irqs());
+}
+
 int nr_ioapics;
 
 /* The one past the highest gsi number used */
@@ -118,9 +153,6 @@ struct mpc_intsrc mp_irqs[MAX_IRQ_SOURCES];
 /* # of MP IRQ source entries */
 int mp_irq_entries;
 
-/* GSI interrupts */
-static int nr_irqs_gsi = NR_IRQS_LEGACY;
-
 #ifdef CONFIG_EISA
 int mp_bus_id_to_type[MAX_MP_BUSSES];
 #endif
@@ -191,10 +223,10 @@ int __init arch_early_irq_init(void)
        struct irq_cfg *cfg;
        int count, node, i;
 
-       if (!legacy_pic->nr_legacy_irqs)
+       if (!nr_legacy_irqs())
                io_apic_irqs = ~0UL;
 
-       for (i = 0; i < nr_ioapics; i++) {
+       for_each_ioapic(i) {
                ioapics[i].saved_registers =
                        kzalloc(sizeof(struct IO_APIC_route_entry) *
                                ioapics[i].nr_registers, GFP_KERNEL);
@@ -214,7 +246,7 @@ int __init arch_early_irq_init(void)
                 * For legacy IRQ's, start with assigning irq0 to irq15 to
                 * IRQ0_VECTOR to IRQ15_VECTOR for all cpu's.
                 */
-               if (i < legacy_pic->nr_legacy_irqs) {
+               if (i < nr_legacy_irqs()) {
                        cfg[i].vector = IRQ0_VECTOR + i;
                        cpumask_setall(cfg[i].domain);
                }
@@ -223,7 +255,7 @@ int __init arch_early_irq_init(void)
        return 0;
 }
 
-static struct irq_cfg *irq_cfg(unsigned int irq)
+static inline struct irq_cfg *irq_cfg(unsigned int irq)
 {
        return irq_get_chip_data(irq);
 }
@@ -265,7 +297,7 @@ static struct irq_cfg *alloc_irq_and_cfg_at(unsigned int at, int node)
        if (res < 0) {
                if (res != -EEXIST)
                        return NULL;
-               cfg = irq_get_chip_data(at);
+               cfg = irq_cfg(at);
                if (cfg)
                        return cfg;
        }
@@ -627,9 +659,8 @@ static void clear_IO_APIC (void)
 {
        int apic, pin;
 
-       for (apic = 0; apic < nr_ioapics; apic++)
-               for (pin = 0; pin < ioapics[apic].nr_registers; pin++)
-                       clear_IO_APIC_pin(apic, pin);
+       for_each_ioapic_pin(apic, pin)
+               clear_IO_APIC_pin(apic, pin);
 }
 
 #ifdef CONFIG_X86_32
@@ -678,13 +709,13 @@ int save_ioapic_entries(void)
        int apic, pin;
        int err = 0;
 
-       for (apic = 0; apic < nr_ioapics; apic++) {
+       for_each_ioapic(apic) {
                if (!ioapics[apic].saved_registers) {
                        err = -ENOMEM;
                        continue;
                }
 
-               for (pin = 0; pin < ioapics[apic].nr_registers; pin++)
+               for_each_pin(apic, pin)
                        ioapics[apic].saved_registers[pin] =
                                ioapic_read_entry(apic, pin);
        }
@@ -699,11 +730,11 @@ void mask_ioapic_entries(void)
 {
        int apic, pin;
 
-       for (apic = 0; apic < nr_ioapics; apic++) {
+       for_each_ioapic(apic) {
                if (!ioapics[apic].saved_registers)
                        continue;
 
-               for (pin = 0; pin < ioapics[apic].nr_registers; pin++) {
+               for_each_pin(apic, pin) {
                        struct IO_APIC_route_entry entry;
 
                        entry = ioapics[apic].saved_registers[pin];
@@ -722,11 +753,11 @@ int restore_ioapic_entries(void)
 {
        int apic, pin;
 
-       for (apic = 0; apic < nr_ioapics; apic++) {
+       for_each_ioapic(apic) {
                if (!ioapics[apic].saved_registers)
                        continue;
 
-               for (pin = 0; pin < ioapics[apic].nr_registers; pin++)
+               for_each_pin(apic, pin)
                        ioapic_write_entry(apic, pin,
                                           ioapics[apic].saved_registers[pin]);
        }
@@ -785,7 +816,7 @@ static int __init find_isa_irq_apic(int irq, int type)
        if (i < mp_irq_entries) {
                int ioapic_idx;
 
-               for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+               for_each_ioapic(ioapic_idx)
                        if (mpc_ioapic_id(ioapic_idx) == mp_irqs[i].dstapic)
                                return ioapic_idx;
        }
@@ -799,7 +830,7 @@ static int __init find_isa_irq_apic(int irq, int type)
  */
 static int EISA_ELCR(unsigned int irq)
 {
-       if (irq < legacy_pic->nr_legacy_irqs) {
+       if (irq < nr_legacy_irqs()) {
                unsigned int port = 0x4d0 + (irq >> 3);
                return (inb(port) >> (irq & 7)) & 1;
        }
@@ -956,7 +987,7 @@ static int pin_2_irq(int idx, int apic, int pin)
        } else {
                u32 gsi = gsi_cfg->gsi_base + pin;
 
-               if (gsi >= NR_IRQS_LEGACY)
+               if (gsi >= nr_legacy_irqs())
                        irq = gsi;
                else
                        irq = gsi_top + gsi;
@@ -991,7 +1022,7 @@ static int pin_2_irq(int idx, int apic, int pin)
 int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
                                struct io_apic_irq_attr *irq_attr)
 {
-       int ioapic_idx, i, best_guess = -1;
+       int irq, i, best_guess = -1;
 
        apic_printk(APIC_DEBUG,
                    "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
@@ -1001,41 +1032,46 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
                            "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
                return -1;
        }
+
        for (i = 0; i < mp_irq_entries; i++) {
                int lbus = mp_irqs[i].srcbus;
+               int ioapic_idx, found = 0;
+
+               if (bus != lbus || mp_irqs[i].irqtype != mp_INT ||
+                   slot != ((mp_irqs[i].srcbusirq >> 2) & 0x1f))
+                       continue;
 
-               for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+               for_each_ioapic(ioapic_idx)
                        if (mpc_ioapic_id(ioapic_idx) == mp_irqs[i].dstapic ||
-                           mp_irqs[i].dstapic == MP_APIC_ALL)
+                           mp_irqs[i].dstapic == MP_APIC_ALL) {
+                               found = 1;
                                break;
+                       }
+               if (!found)
+                       continue;
 
-               if (!test_bit(lbus, mp_bus_not_pci) &&
-                   !mp_irqs[i].irqtype &&
-                   (bus == lbus) &&
-                   (slot == ((mp_irqs[i].srcbusirq >> 2) & 0x1f))) {
-                       int irq = pin_2_irq(i, ioapic_idx, mp_irqs[i].dstirq);
-
-                       if (!(ioapic_idx || IO_APIC_IRQ(irq)))
-                               continue;
+               /* Skip ISA IRQs */
+               irq = pin_2_irq(i, ioapic_idx, mp_irqs[i].dstirq);
+               if (ioapic_idx == 0 && !IO_APIC_IRQ(irq))
+                       continue;
 
-                       if (pin == (mp_irqs[i].srcbusirq & 3)) {
-                               set_io_apic_irq_attr(irq_attr, ioapic_idx,
-                                                    mp_irqs[i].dstirq,
-                                                    irq_trigger(i),
-                                                    irq_polarity(i));
-                               return irq;
-                       }
-                       /*
-                        * Use the first all-but-pin matching entry as a
-                        * best-guess fuzzy result for broken mptables.
-                        */
-                       if (best_guess < 0) {
-                               set_io_apic_irq_attr(irq_attr, ioapic_idx,
-                                                    mp_irqs[i].dstirq,
-                                                    irq_trigger(i),
-                                                    irq_polarity(i));
-                               best_guess = irq;
-                       }
+               if (pin == (mp_irqs[i].srcbusirq & 3)) {
+                       set_io_apic_irq_attr(irq_attr, ioapic_idx,
+                                            mp_irqs[i].dstirq,
+                                            irq_trigger(i),
+                                            irq_polarity(i));
+                       return irq;
+               }
+               /*
+                * Use the first all-but-pin matching entry as a
+                * best-guess fuzzy result for broken mptables.
+                */
+               if (best_guess < 0) {
+                       set_io_apic_irq_attr(irq_attr, ioapic_idx,
+                                            mp_irqs[i].dstirq,
+                                            irq_trigger(i),
+                                            irq_polarity(i));
+                       best_guess = irq;
                }
        }
        return best_guess;
@@ -1198,7 +1234,7 @@ void __setup_vector_irq(int cpu)
        raw_spin_lock(&vector_lock);
        /* Mark the inuse vectors */
        for_each_active_irq(irq) {
-               cfg = irq_get_chip_data(irq);
+               cfg = irq_cfg(irq);
                if (!cfg)
                        continue;
 
@@ -1227,12 +1263,10 @@ static inline int IO_APIC_irq_trigger(int irq)
 {
        int apic, idx, pin;
 
-       for (apic = 0; apic < nr_ioapics; apic++) {
-               for (pin = 0; pin < ioapics[apic].nr_registers; pin++) {
-                       idx = find_irq_entry(apic, pin, mp_INT);
-                       if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
-                               return irq_trigger(idx);
-               }
+       for_each_ioapic_pin(apic, pin) {
+               idx = find_irq_entry(apic, pin, mp_INT);
+               if ((idx != -1) && (irq == pin_2_irq(idx, apic, pin)))
+                       return irq_trigger(idx);
        }
        /*
          * nonexistent IRQs are edge default
@@ -1330,7 +1364,7 @@ static void setup_ioapic_irq(unsigned int irq, struct irq_cfg *cfg,
        }
 
        ioapic_register_intr(irq, cfg, attr->trigger);
-       if (irq < legacy_pic->nr_legacy_irqs)
+       if (irq < nr_legacy_irqs())
                legacy_pic->mask(irq);
 
        ioapic_write_entry(attr->ioapic, attr->ioapic_pin, entry);
@@ -1352,14 +1386,13 @@ static void __init __io_apic_setup_irqs(unsigned int ioapic_idx)
        struct io_apic_irq_attr attr;
        unsigned int pin, irq;
 
-       for (pin = 0; pin < ioapics[ioapic_idx].nr_registers; pin++) {
+       for_each_pin(ioapic_idx, pin) {
                idx = find_irq_entry(ioapic_idx, pin, mp_INT);
                if (io_apic_pin_not_connected(idx, ioapic_idx, pin))
                        continue;
 
                irq = pin_2_irq(idx, ioapic_idx, pin);
-
-               if ((ioapic_idx > 0) && (irq > 16))
+               if (!mp_init_irq_at_boot(ioapic_idx, irq))
                        continue;
 
                /*
@@ -1383,12 +1416,12 @@ static void __init setup_IO_APIC_irqs(void)
 
        apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
 
-       for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+       for_each_ioapic(ioapic_idx)
                __io_apic_setup_irqs(ioapic_idx);
 }
 
 /*
- * for the gsit that is not in first ioapic
+ * for the gsi that is not in first ioapic
  * but could not use acpi_register_gsi()
  * like some special sci in IBM x3330
  */
@@ -1410,9 +1443,7 @@ void setup_IO_APIC_irq_extra(u32 gsi)
                return;
 
        irq = pin_2_irq(idx, ioapic_idx, pin);
-
-       /* Only handle the non legacy irqs on secondary ioapics */
-       if (ioapic_idx == 0 || irq < NR_IRQS_LEGACY)
+       if (mp_init_irq_at_boot(ioapic_idx, irq))
                return;
 
        set_io_apic_irq_attr(&attr, ioapic_idx, pin, irq_trigger(idx),
@@ -1586,7 +1617,7 @@ __apicdebuginit(void) print_IO_APICs(void)
        struct irq_chip *chip;
 
        printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
-       for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+       for_each_ioapic(ioapic_idx)
                printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
                       mpc_ioapic_id(ioapic_idx),
                       ioapics[ioapic_idx].nr_registers);
@@ -1597,7 +1628,7 @@ __apicdebuginit(void) print_IO_APICs(void)
         */
        printk(KERN_INFO "testing the IO APIC.......................\n");
 
-       for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++)
+       for_each_ioapic(ioapic_idx)
                print_IO_APIC(ioapic_idx);
 
        printk(KERN_DEBUG "IRQ to pin mappings:\n");
@@ -1608,7 +1639,7 @@ __apicdebuginit(void) print_IO_APICs(void)
                if (chip != &ioapic_chip)
                        continue;
 
-               cfg = irq_get_chip_data(irq);
+               cfg = irq_cfg(irq);
                if (!cfg)
                        continue;
                entry = cfg->irq_2_pin;
@@ -1758,7 +1789,7 @@ __apicdebuginit(void) print_PIC(void)
        unsigned int v;
        unsigned long flags;
 
-       if (!legacy_pic->nr_legacy_irqs)
+       if (!nr_legacy_irqs())
                return;
 
        printk(KERN_DEBUG "\nprinting PIC contents\n");
@@ -1828,26 +1859,22 @@ static struct { int pin, apic; } ioapic_i8259 = { -1, -1 };
 void __init enable_IO_APIC(void)
 {
        int i8259_apic, i8259_pin;
-       int apic;
+       int apic, pin;
 
-       if (!legacy_pic->nr_legacy_irqs)
+       if (!nr_legacy_irqs())
                return;
 
-       for(apic = 0; apic < nr_ioapics; apic++) {
-               int pin;
+       for_each_ioapic_pin(apic, pin) {
                /* See if any of the pins is in ExtINT mode */
-               for (pin = 0; pin < ioapics[apic].nr_registers; pin++) {
-                       struct IO_APIC_route_entry entry;
-                       entry = ioapic_read_entry(apic, pin);
+               struct IO_APIC_route_entry entry = ioapic_read_entry(apic, pin);
 
-                       /* If the interrupt line is enabled and in ExtInt mode
-                        * I have found the pin where the i8259 is connected.
-                        */
-                       if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
-                               ioapic_i8259.apic = apic;
-                               ioapic_i8259.pin  = pin;
-                               goto found_i8259;
-                       }
+               /* If the interrupt line is enabled and in ExtInt mode
+                * I have found the pin where the i8259 is connected.
+                */
+               if ((entry.mask == 0) && (entry.delivery_mode == dest_ExtINT)) {
+                       ioapic_i8259.apic = apic;
+                       ioapic_i8259.pin  = pin;
+                       goto found_i8259;
                }
        }
  found_i8259:
@@ -1919,7 +1946,7 @@ void disable_IO_APIC(void)
         */
        clear_IO_APIC();
 
-       if (!legacy_pic->nr_legacy_irqs)
+       if (!nr_legacy_irqs())
                return;
 
        x86_io_apic_ops.disable();
@@ -1950,7 +1977,7 @@ void __init setup_ioapic_ids_from_mpc_nocheck(void)
        /*
         * Set the IOAPIC ID to the value stored in the MPC table.
         */
-       for (ioapic_idx = 0; ioapic_idx < nr_ioapics; ioapic_idx++) {
+       for_each_ioapic(ioapic_idx) {
                /* Read the register 0 value */
                raw_spin_lock_irqsave(&ioapic_lock, flags);
                reg_00.raw = io_apic_read(ioapic_idx, 0);
@@ -2123,7 +2150,7 @@ static unsigned int startup_ioapic_irq(struct irq_data *data)
        unsigned long flags;
 
        raw_spin_lock_irqsave(&ioapic_lock, flags);
-       if (irq < legacy_pic->nr_legacy_irqs) {
+       if (irq < nr_legacy_irqs()) {
                legacy_pic->mask(irq);
                if (legacy_pic->irq_pending(irq))
                        was_pending = 1;
@@ -2225,7 +2252,7 @@ asmlinkage __visible void smp_irq_move_cleanup_interrupt(void)
                        apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
                        goto unlock;
                }
-               __this_cpu_write(vector_irq[vector], -1);
+               __this_cpu_write(vector_irq[vector], VECTOR_UNDEFINED);
 unlock:
                raw_spin_unlock(&desc->lock);
        }
@@ -2253,7 +2280,7 @@ static void irq_complete_move(struct irq_cfg *cfg)
 
 void irq_force_complete_move(int irq)
 {
-       struct irq_cfg *cfg = irq_get_chip_data(irq);
+       struct irq_cfg *cfg = irq_cfg(irq);
 
        if (!cfg)
                return;
@@ -2514,26 +2541,15 @@ static inline void init_IO_APIC_traps(void)
        struct irq_cfg *cfg;
        unsigned int irq;
 
-       /*
-        * NOTE! The local APIC isn't very good at handling
-        * multiple interrupts at the same interrupt level.
-        * As the interrupt level is determined by taking the
-        * vector number and shifting that right by 4, we
-        * want to spread these out a bit so that they don't
-        * all fall in the same interrupt level.
-        *
-        * Also, we've got to be careful not to trash gate
-        * 0x80, because int 0x80 is hm, kind of importantish. ;)
-        */
        for_each_active_irq(irq) {
-               cfg = irq_get_chip_data(irq);
+               cfg = irq_cfg(irq);
                if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) {
                        /*
                         * Hmm.. We don't have an entry for this,
                         * so default to an old-fashioned 8259
                         * interrupt if we can..
                         */
-                       if (irq < legacy_pic->nr_legacy_irqs)
+                       if (irq < nr_legacy_irqs())
                                legacy_pic->make_irq(irq);
                        else
                                /* Strange. Oh, well.. */
@@ -2649,8 +2665,6 @@ static int __init disable_timer_pin_setup(char *arg)
 }
 early_param("disable_timer_pin_1", disable_timer_pin_setup);
 
-int timer_through_8259 __initdata;
-
 /*
  * This code may look a bit paranoid, but it's supposed to cooperate with
  * a wide range of boards and BIOS bugs.  Fortunately only the timer IRQ
@@ -2661,7 +2675,7 @@ int timer_through_8259 __initdata;
  */
 static inline void __init check_timer(void)
 {
-       struct irq_cfg *cfg = irq_get_chip_data(0);
+       struct irq_cfg *cfg = irq_cfg(0);
        int node = cpu_to_node(0);
        int apic1, pin1, apic2, pin2;
        unsigned long flags;
@@ -2755,7 +2769,6 @@ static inline void __init check_timer(void)
                legacy_pic->unmask(0);
                if (timer_irq_works()) {
                        apic_printk(APIC_QUIET, KERN_INFO "....... works.\n");
-                       timer_through_8259 = 1;
                        goto out;
                }
                /*
@@ -2833,7 +2846,7 @@ void __init setup_IO_APIC(void)
        /*
         * calling enable_IO_APIC() is moved to setup_local_APIC for BP
         */
-       io_apic_irqs = legacy_pic->nr_legacy_irqs ? ~PIC_IRQS : ~0UL;
+       io_apic_irqs = nr_legacy_irqs() ? ~PIC_IRQS : ~0UL;
 
        apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n");
        /*
@@ -2844,7 +2857,7 @@ void __init setup_IO_APIC(void)
        sync_Arb_IDs();
        setup_IO_APIC_irqs();
        init_IO_APIC_traps();
-       if (legacy_pic->nr_legacy_irqs)
+       if (nr_legacy_irqs())
                check_timer();
 }
 
@@ -2880,7 +2893,7 @@ static void ioapic_resume(void)
 {
        int ioapic_idx;
 
-       for (ioapic_idx = nr_ioapics - 1; ioapic_idx >= 0; ioapic_idx--)
+       for_each_ioapic_reverse(ioapic_idx)
                resume_ioapic_id(ioapic_idx);
 
        restore_ioapic_entries();
@@ -2926,7 +2939,7 @@ int arch_setup_hwirq(unsigned int irq, int node)
 
 void arch_teardown_hwirq(unsigned int irq)
 {
-       struct irq_cfg *cfg = irq_get_chip_data(irq);
+       struct irq_cfg *cfg = irq_cfg(irq);
        unsigned long flags;
 
        free_remapped_irq(irq);
@@ -3053,7 +3066,7 @@ int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc,
        if (!irq_offset)
                write_msi_msg(irq, &msg);
 
-       setup_remapped_irq(irq, irq_get_chip_data(irq), chip);
+       setup_remapped_irq(irq, irq_cfg(irq), chip);
 
        irq_set_chip_and_handler_name(irq, chip, handle_edge_irq, "edge");
 
@@ -3192,7 +3205,7 @@ int default_setup_hpet_msi(unsigned int irq, unsigned int id)
 
        hpet_msi_write(irq_get_handler_data(irq), &msg);
        irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
-       setup_remapped_irq(irq, irq_get_chip_data(irq), chip);
+       setup_remapped_irq(irq, irq_cfg(irq), chip);
 
        irq_set_chip_and_handler_name(irq, chip, handle_edge_irq, "edge");
        return 0;
@@ -3340,20 +3353,11 @@ static int __init io_apic_get_redir_entries(int ioapic)
        return reg_01.bits.entries + 1;
 }
 
-static void __init probe_nr_irqs_gsi(void)
-{
-       int nr;
-
-       nr = gsi_top + NR_IRQS_LEGACY;
-       if (nr > nr_irqs_gsi)
-               nr_irqs_gsi = nr;
-
-       printk(KERN_DEBUG "nr_irqs_gsi: %d\n", nr_irqs_gsi);
-}
-
 unsigned int arch_dynirq_lower_bound(unsigned int from)
 {
-       return from < nr_irqs_gsi ? nr_irqs_gsi : from;
+       unsigned int min = gsi_top + nr_legacy_irqs();
+
+       return from < min ? min : from;
 }
 
 int __init arch_probe_nr_irqs(void)
@@ -3363,17 +3367,17 @@ int __init arch_probe_nr_irqs(void)
        if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
                nr_irqs = NR_VECTORS * nr_cpu_ids;
 
-       nr = nr_irqs_gsi + 8 * nr_cpu_ids;
+       nr = (gsi_top + nr_legacy_irqs()) + 8 * nr_cpu_ids;
 #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
        /*
         * for MSI and HT dyn irq
         */
-       nr += nr_irqs_gsi * 16;
+       nr += gsi_top * 16;
 #endif
        if (nr < nr_irqs)
                nr_irqs = nr;
 
-       return NR_IRQS_LEGACY;
+       return nr_legacy_irqs();
 }
 
 int io_apic_set_pci_routing(struct device *dev, int irq,
@@ -3483,9 +3487,8 @@ static u8 __init io_apic_unique_id(u8 id)
        DECLARE_BITMAP(used, 256);
 
        bitmap_zero(used, 256);
-       for (i = 0; i < nr_ioapics; i++) {
+       for_each_ioapic(i)
                __set_bit(mpc_ioapic_id(i), used);
-       }
        if (!test_bit(id, used))
                return id;
        return find_first_zero_bit(used, 256);
@@ -3543,14 +3546,13 @@ void __init setup_ioapic_dest(void)
        if (skip_ioapic_setup == 1)
                return;
 
-       for (ioapic = 0; ioapic < nr_ioapics; ioapic++)
-       for (pin = 0; pin < ioapics[ioapic].nr_registers; pin++) {
+       for_each_ioapic_pin(ioapic, pin) {
                irq_entry = find_irq_entry(ioapic, pin, mp_INT);
                if (irq_entry == -1)
                        continue;
-               irq = pin_2_irq(irq_entry, ioapic, pin);
 
-               if ((ioapic > 0) && (irq > 16))
+               irq = pin_2_irq(irq_entry, ioapic, pin);
+               if (!mp_init_irq_at_boot(ioapic, irq))
                        continue;
 
                idata = irq_get_irq_data(irq);
@@ -3573,29 +3575,33 @@ void __init setup_ioapic_dest(void)
 
 static struct resource *ioapic_resources;
 
-static struct resource * __init ioapic_setup_resources(int nr_ioapics)
+static struct resource * __init ioapic_setup_resources(void)
 {
        unsigned long n;
        struct resource *res;
        char *mem;
-       int i;
+       int i, num = 0;
 
-       if (nr_ioapics <= 0)
+       for_each_ioapic(i)
+               num++;
+       if (num == 0)
                return NULL;
 
        n = IOAPIC_RESOURCE_NAME_SIZE + sizeof(struct resource);
-       n *= nr_ioapics;
+       n *= num;
 
        mem = alloc_bootmem(n);
        res = (void *)mem;
 
-       mem += sizeof(struct resource) * nr_ioapics;
+       mem += sizeof(struct resource) * num;
 
-       for (i = 0; i < nr_ioapics; i++) {
-               res[i].name = mem;
-               res[i].flags = IORESOURCE_MEM | IORESOURCE_BUSY;
+       num = 0;
+       for_each_ioapic(i) {
+               res[num].name = mem;
+               res[num].flags = IORESOURCE_MEM | IORESOURCE_BUSY;
                snprintf(mem, IOAPIC_RESOURCE_NAME_SIZE, "IOAPIC %u", i);
                mem += IOAPIC_RESOURCE_NAME_SIZE;
+               num++;
        }
 
        ioapic_resources = res;
@@ -3609,8 +3615,8 @@ void __init native_io_apic_init_mappings(void)
        struct resource *ioapic_res;
        int i;
 
-       ioapic_res = ioapic_setup_resources(nr_ioapics);
-       for (i = 0; i < nr_ioapics; i++) {
+       ioapic_res = ioapic_setup_resources();
+       for_each_ioapic(i) {
                if (smp_found_config) {
                        ioapic_phys = mpc_ioapic_addr(i);
 #ifdef CONFIG_X86_32
@@ -3641,8 +3647,6 @@ fake_ioapic_page:
                ioapic_res->end = ioapic_phys + IO_APIC_SLOT_SIZE - 1;
                ioapic_res++;
        }
-
-       probe_nr_irqs_gsi();
 }
 
 void __init ioapic_insert_resources(void)
@@ -3657,7 +3661,7 @@ void __init ioapic_insert_resources(void)
                return;
        }
 
-       for (i = 0; i < nr_ioapics; i++) {
+       for_each_ioapic(i) {
                insert_resource(&iomem_resource, r);
                r++;
        }
@@ -3665,16 +3669,15 @@ void __init ioapic_insert_resources(void)
 
 int mp_find_ioapic(u32 gsi)
 {
-       int i = 0;
+       int i;
 
        if (nr_ioapics == 0)
                return -1;
 
        /* Find the IOAPIC that manages this GSI. */
-       for (i = 0; i < nr_ioapics; i++) {
+       for_each_ioapic(i) {
                struct mp_ioapic_gsi *gsi_cfg = mp_ioapic_gsi_routing(i);
-               if ((gsi >= gsi_cfg->gsi_base)
-                   && (gsi <= gsi_cfg->gsi_end))
+               if (gsi >= gsi_cfg->gsi_base && gsi <= gsi_cfg->gsi_end)
                        return i;
        }
 
@@ -3686,7 +3689,7 @@ int mp_find_ioapic_pin(int ioapic, u32 gsi)
 {
        struct mp_ioapic_gsi *gsi_cfg;
 
-       if (WARN_ON(ioapic == -1))
+       if (WARN_ON(ioapic < 0))
                return -1;
 
        gsi_cfg = mp_ioapic_gsi_routing(ioapic);
This page took 0.03756 seconds and 5 git commands to generate.