~ubuntu-branches/debian/wheezy/linux-2.6/wheezy

« back to all changes in this revision

Viewing changes to arch/x86/kernel/apic/io_apic.c

  • Committer: Bazaar Package Importer
  • Author(s): Ben Hutchings, Ben Hutchings, Aurelien Jarno
  • Date: 2011-06-07 12:14:05 UTC
  • mfrom: (43.1.9 sid)
  • Revision ID: james.westby@ubuntu.com-20110607121405-i3h1rd7nrnd2b73h
Tags: 2.6.39-2
[ Ben Hutchings ]
* [x86] Enable BACKLIGHT_APPLE, replacing BACKLIGHT_MBP_NVIDIA
  (Closes: #627492)
* cgroups: Disable memory resource controller by default. Allow it
  to be enabled using kernel parameter 'cgroup_enable=memory'.
* rt2800usb: Enable support for more USB devices including
  Linksys WUSB600N (Closes: #596626) (this change was accidentally
  omitted from 2.6.39-1)
* [x86] Remove Celeron from list of processors supporting PAE. Most
  'Celeron M' models do not.
* Update debconf template translations:
  - Swedish (Martin Bagge) (Closes: #628932)
  - French (David Prévot) (Closes: #628191)
* aufs: Update for 2.6.39 (Closes: #627837)
* Add stable 2.6.39.1, including:
  - ext4: dont set PageUptodate in ext4_end_bio()
  - pata_cmd64x: fix boot crash on parisc (Closes: #622997, #622745)
  - ext3: Fix fs corruption when make_indexed_dir() fails
  - netfilter: nf_ct_sip: validate Content-Length in TCP SIP messages
  - sctp: fix race between sctp_bind_addr_free() and
    sctp_bind_addr_conflict()
  - sctp: fix memory leak of the ASCONF queue when free asoc
  - md/bitmap: fix saving of events_cleared and other state
  - cdc_acm: Fix oops when Droids MuIn LCD is connected
  - cx88: Fix conversion from BKL to fine-grained locks (Closes: #619827)
  - keys: Set cred->user_ns in key_replace_session_keyring (CVE-2011-2184)
  - tmpfs: fix race between truncate and writepage
  - nfs41: Correct offset for LAYOUTCOMMIT
  - xen/mmu: fix a race window causing leave_mm BUG()
  - ext4: fix possible use-after-free in ext4_remove_li_request()
  For the complete list of changes, see:
   http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.39.1
* Bump ABI to 2
* netfilter: Enable IP_SET, IP_SET_BITMAP_IP, IP_SET_BITMAP_IPMAC,
  IP_SET_BITMAP_PORT, IP_SET_HASH_IP, IP_SET_HASH_IPPORT,
  IP_SET_HASH_IPPORTIP, IP_SET_HASH_IPPORTNET, IP_SET_HASH_NET,
  IP_SET_HASH_NETPORT, IP_SET_LIST_SET, NETFILTER_XT_SET as modules
  (Closes: #629401)

[ Aurelien Jarno ]
* [mipsel/loongson-2f] Disable_SCSI_LPFC to workaround GCC ICE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <linux/compiler.h>
31
31
#include <linux/acpi.h>
32
32
#include <linux/module.h>
33
 
#include <linux/sysdev.h>
 
33
#include <linux/syscore_ops.h>
34
34
#include <linux/msi.h>
35
35
#include <linux/htirq.h>
36
36
#include <linux/freezer.h>
108
108
 
109
109
int skip_ioapic_setup;
110
110
 
111
 
void arch_disable_smp_support(void)
 
111
/**
 
112
 * disable_ioapic_support() - disables ioapic support at runtime
 
113
 */
 
114
void disable_ioapic_support(void)
112
115
{
113
116
#ifdef CONFIG_PCI
114
117
        noioapicquirk = 1;
120
123
static int __init parse_noapic(char *str)
121
124
{
122
125
        /* disable IO-APIC */
123
 
        arch_disable_smp_support();
 
126
        disable_ioapic_support();
124
127
        return 0;
125
128
}
126
129
early_param("noapic", parse_noapic);
127
130
 
 
131
static int io_apic_setup_irq_pin(unsigned int irq, int node,
 
132
                                 struct io_apic_irq_attr *attr);
 
133
 
128
134
/* Will be called in mpparse/acpi/sfi codes for saving IRQ info */
129
135
void mp_save_irq(struct mpc_intsrc *m)
130
136
{
181
187
        irq_reserve_irqs(0, legacy_pic->nr_legacy_irqs);
182
188
 
183
189
        for (i = 0; i < count; i++) {
184
 
                set_irq_chip_data(i, &cfg[i]);
 
190
                irq_set_chip_data(i, &cfg[i]);
185
191
                zalloc_cpumask_var_node(&cfg[i].domain, GFP_KERNEL, node);
186
192
                zalloc_cpumask_var_node(&cfg[i].old_domain, GFP_KERNEL, node);
187
193
                /*
200
206
#ifdef CONFIG_SPARSE_IRQ
201
207
static struct irq_cfg *irq_cfg(unsigned int irq)
202
208
{
203
 
        return get_irq_chip_data(irq);
 
209
        return irq_get_chip_data(irq);
204
210
}
205
211
 
206
212
static struct irq_cfg *alloc_irq_cfg(unsigned int irq, int node)
226
232
{
227
233
        if (!cfg)
228
234
                return;
229
 
        set_irq_chip_data(at, NULL);
 
235
        irq_set_chip_data(at, NULL);
230
236
        free_cpumask_var(cfg->domain);
231
237
        free_cpumask_var(cfg->old_domain);
232
238
        kfree(cfg);
256
262
        if (res < 0) {
257
263
                if (res != -EEXIST)
258
264
                        return NULL;
259
 
                cfg = get_irq_chip_data(at);
 
265
                cfg = irq_get_chip_data(at);
260
266
                if (cfg)
261
267
                        return cfg;
262
268
        }
263
269
 
264
270
        cfg = alloc_irq_cfg(at, node);
265
271
        if (cfg)
266
 
                set_irq_chip_data(at, cfg);
 
272
                irq_set_chip_data(at, cfg);
267
273
        else
268
274
                irq_free_desc(at);
269
275
        return cfg;
818
824
#define default_MCA_trigger(idx)        (1)
819
825
#define default_MCA_polarity(idx)       default_ISA_polarity(idx)
820
826
 
821
 
static int MPBIOS_polarity(int idx)
 
827
static int irq_polarity(int idx)
822
828
{
823
829
        int bus = mp_irqs[idx].srcbus;
824
830
        int polarity;
860
866
        return polarity;
861
867
}
862
868
 
863
 
static int MPBIOS_trigger(int idx)
 
869
static int irq_trigger(int idx)
864
870
{
865
871
        int bus = mp_irqs[idx].srcbus;
866
872
        int trigger;
932
938
        return trigger;
933
939
}
934
940
 
935
 
static inline int irq_polarity(int idx)
936
 
{
937
 
        return MPBIOS_polarity(idx);
938
 
}
939
 
 
940
 
static inline int irq_trigger(int idx)
941
 
{
942
 
        return MPBIOS_trigger(idx);
943
 
}
944
 
 
945
941
static int pin_2_irq(int idx, int apic, int pin)
946
942
{
947
943
        int irq;
1189
1185
        raw_spin_lock(&vector_lock);
1190
1186
        /* Mark the inuse vectors */
1191
1187
        for_each_active_irq(irq) {
1192
 
                cfg = get_irq_chip_data(irq);
 
1188
                cfg = irq_get_chip_data(irq);
1193
1189
                if (!cfg)
1194
1190
                        continue;
1195
1191
                /*
1220
1216
static struct irq_chip ioapic_chip;
1221
1217
static struct irq_chip ir_ioapic_chip;
1222
1218
 
1223
 
#define IOAPIC_AUTO     -1
1224
 
#define IOAPIC_EDGE     0
1225
 
#define IOAPIC_LEVEL    1
1226
 
 
1227
1219
#ifdef CONFIG_X86_32
1228
1220
static inline int IO_APIC_irq_trigger(int irq)
1229
1221
{
1248
1240
}
1249
1241
#endif
1250
1242
 
1251
 
static void ioapic_register_intr(unsigned int irq, unsigned long trigger)
 
1243
static void ioapic_register_intr(unsigned int irq, struct irq_cfg *cfg,
 
1244
                                 unsigned long trigger)
1252
1245
{
 
1246
        struct irq_chip *chip = &ioapic_chip;
 
1247
        irq_flow_handler_t hdl;
 
1248
        bool fasteoi;
1253
1249
 
1254
1250
        if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
1255
 
            trigger == IOAPIC_LEVEL)
 
1251
            trigger == IOAPIC_LEVEL) {
1256
1252
                irq_set_status_flags(irq, IRQ_LEVEL);
1257
 
        else
 
1253
                fasteoi = true;
 
1254
        } else {
1258
1255
                irq_clear_status_flags(irq, IRQ_LEVEL);
 
1256
                fasteoi = false;
 
1257
        }
1259
1258
 
1260
 
        if (irq_remapped(get_irq_chip_data(irq))) {
 
1259
        if (irq_remapped(cfg)) {
1261
1260
                irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
1262
 
                if (trigger)
1263
 
                        set_irq_chip_and_handler_name(irq, &ir_ioapic_chip,
1264
 
                                                      handle_fasteoi_irq,
1265
 
                                                     "fasteoi");
1266
 
                else
1267
 
                        set_irq_chip_and_handler_name(irq, &ir_ioapic_chip,
1268
 
                                                      handle_edge_irq, "edge");
1269
 
                return;
 
1261
                chip = &ir_ioapic_chip;
 
1262
                fasteoi = trigger != 0;
1270
1263
        }
1271
1264
 
1272
 
        if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
1273
 
            trigger == IOAPIC_LEVEL)
1274
 
                set_irq_chip_and_handler_name(irq, &ioapic_chip,
1275
 
                                              handle_fasteoi_irq,
1276
 
                                              "fasteoi");
1277
 
        else
1278
 
                set_irq_chip_and_handler_name(irq, &ioapic_chip,
1279
 
                                              handle_edge_irq, "edge");
 
1265
        hdl = fasteoi ? handle_fasteoi_irq : handle_edge_irq;
 
1266
        irq_set_chip_and_handler_name(irq, chip, hdl,
 
1267
                                      fasteoi ? "fasteoi" : "edge");
1280
1268
}
1281
1269
 
1282
1270
static int setup_ioapic_entry(int apic_id, int irq,
1374
1362
                return;
1375
1363
        }
1376
1364
 
1377
 
        ioapic_register_intr(irq, trigger);
 
1365
        ioapic_register_intr(irq, cfg, trigger);
1378
1366
        if (irq < legacy_pic->nr_legacy_irqs)
1379
1367
                legacy_pic->mask(irq);
1380
1368
 
1385
1373
        DECLARE_BITMAP(pin_programmed, MP_MAX_IOAPIC_PIN + 1);
1386
1374
} mp_ioapic_routing[MAX_IO_APICS];
1387
1375
 
1388
 
static void __init setup_IO_APIC_irqs(void)
1389
 
{
1390
 
        int apic_id, pin, idx, irq, notcon = 0;
1391
 
        int node = cpu_to_node(0);
1392
 
        struct irq_cfg *cfg;
1393
 
 
1394
 
        apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
1395
 
 
1396
 
        for (apic_id = 0; apic_id < nr_ioapics; apic_id++)
 
1376
static bool __init io_apic_pin_not_connected(int idx, int apic_id, int pin)
 
1377
{
 
1378
        if (idx != -1)
 
1379
                return false;
 
1380
 
 
1381
        apic_printk(APIC_VERBOSE, KERN_DEBUG " apic %d pin %d not connected\n",
 
1382
                    mp_ioapics[apic_id].apicid, pin);
 
1383
        return true;
 
1384
}
 
1385
 
 
1386
static void __init __io_apic_setup_irqs(unsigned int apic_id)
 
1387
{
 
1388
        int idx, node = cpu_to_node(0);
 
1389
        struct io_apic_irq_attr attr;
 
1390
        unsigned int pin, irq;
 
1391
 
1397
1392
        for (pin = 0; pin < nr_ioapic_registers[apic_id]; pin++) {
1398
1393
                idx = find_irq_entry(apic_id, pin, mp_INT);
1399
 
                if (idx == -1) {
1400
 
                        if (!notcon) {
1401
 
                                notcon = 1;
1402
 
                                apic_printk(APIC_VERBOSE,
1403
 
                                        KERN_DEBUG " %d-%d",
1404
 
                                        mp_ioapics[apic_id].apicid, pin);
1405
 
                        } else
1406
 
                                apic_printk(APIC_VERBOSE, " %d-%d",
1407
 
                                        mp_ioapics[apic_id].apicid, pin);
 
1394
                if (io_apic_pin_not_connected(idx, apic_id, pin))
1408
1395
                        continue;
1409
 
                }
1410
 
                if (notcon) {
1411
 
                        apic_printk(APIC_VERBOSE,
1412
 
                                " (apicid-pin) not connected\n");
1413
 
                        notcon = 0;
1414
 
                }
1415
1396
 
1416
1397
                irq = pin_2_irq(idx, apic_id, pin);
1417
1398
 
1423
1404
                 * installed and if it returns 1:
1424
1405
                 */
1425
1406
                if (apic->multi_timer_check &&
1426
 
                                apic->multi_timer_check(apic_id, irq))
1427
 
                        continue;
1428
 
 
1429
 
                cfg = alloc_irq_and_cfg_at(irq, node);
1430
 
                if (!cfg)
1431
 
                        continue;
1432
 
 
1433
 
                add_pin_to_irq_node(cfg, node, apic_id, pin);
1434
 
                /*
1435
 
                 * don't mark it in pin_programmed, so later acpi could
1436
 
                 * set it correctly when irq < 16
1437
 
                 */
1438
 
                setup_ioapic_irq(apic_id, pin, irq, cfg, irq_trigger(idx),
1439
 
                                  irq_polarity(idx));
 
1407
                    apic->multi_timer_check(apic_id, irq))
 
1408
                        continue;
 
1409
 
 
1410
                set_io_apic_irq_attr(&attr, apic_id, pin, irq_trigger(idx),
 
1411
                                     irq_polarity(idx));
 
1412
 
 
1413
                io_apic_setup_irq_pin(irq, node, &attr);
1440
1414
        }
1441
 
 
1442
 
        if (notcon)
1443
 
                apic_printk(APIC_VERBOSE,
1444
 
                        " (apicid-pin) not connected\n");
 
1415
}
 
1416
 
 
1417
static void __init setup_IO_APIC_irqs(void)
 
1418
{
 
1419
        unsigned int apic_id;
 
1420
 
 
1421
        apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
 
1422
 
 
1423
        for (apic_id = 0; apic_id < nr_ioapics; apic_id++)
 
1424
                __io_apic_setup_irqs(apic_id);
1445
1425
}
1446
1426
 
1447
1427
/*
1452
1432
void setup_IO_APIC_irq_extra(u32 gsi)
1453
1433
{
1454
1434
        int apic_id = 0, pin, idx, irq, node = cpu_to_node(0);
1455
 
        struct irq_cfg *cfg;
 
1435
        struct io_apic_irq_attr attr;
1456
1436
 
1457
1437
        /*
1458
1438
         * Convert 'gsi' to 'ioapic.pin'.
1472
1452
        if (apic_id == 0 || irq < NR_IRQS_LEGACY)
1473
1453
                return;
1474
1454
 
1475
 
        cfg = alloc_irq_and_cfg_at(irq, node);
1476
 
        if (!cfg)
1477
 
                return;
1478
 
 
1479
 
        add_pin_to_irq_node(cfg, node, apic_id, pin);
1480
 
 
1481
 
        if (test_bit(pin, mp_ioapic_routing[apic_id].pin_programmed)) {
1482
 
                pr_debug("Pin %d-%d already programmed\n",
1483
 
                         mp_ioapics[apic_id].apicid, pin);
1484
 
                return;
1485
 
        }
1486
 
        set_bit(pin, mp_ioapic_routing[apic_id].pin_programmed);
1487
 
 
1488
 
        setup_ioapic_irq(apic_id, pin, irq, cfg,
1489
 
                        irq_trigger(idx), irq_polarity(idx));
 
1455
        set_io_apic_irq_attr(&attr, apic_id, pin, irq_trigger(idx),
 
1456
                             irq_polarity(idx));
 
1457
 
 
1458
        io_apic_setup_irq_pin_once(irq, node, &attr);
1490
1459
}
1491
1460
 
1492
1461
/*
1518
1487
         * The timer IRQ doesn't have to know that behind the
1519
1488
         * scene we may have a 8259A-master in AEOI mode ...
1520
1489
         */
1521
 
        set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge");
 
1490
        irq_set_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq,
 
1491
                                      "edge");
1522
1492
 
1523
1493
        /*
1524
1494
         * Add it to the IO-APIC irq-routing table:
1625
1595
        for_each_active_irq(irq) {
1626
1596
                struct irq_pin_list *entry;
1627
1597
 
1628
 
                cfg = get_irq_chip_data(irq);
 
1598
                cfg = irq_get_chip_data(irq);
1629
1599
                if (!cfg)
1630
1600
                        continue;
1631
1601
                entry = cfg->irq_2_pin;
1916
1886
         *
1917
1887
         * With interrupt-remapping, for now we will use virtual wire A mode,
1918
1888
         * as virtual wire B is little complex (need to configure both
1919
 
         * IOAPIC RTE aswell as interrupt-remapping table entry).
 
1889
         * IOAPIC RTE as well as interrupt-remapping table entry).
1920
1890
         * As this gets called during crash dump, keep this simple for now.
1921
1891
         */
1922
1892
        if (ioapic_i8259.pin != -1 && !intr_remapping_enabled) {
2391
2361
 
2392
2362
void irq_force_complete_move(int irq)
2393
2363
{
2394
 
        struct irq_cfg *cfg = get_irq_chip_data(irq);
 
2364
        struct irq_cfg *cfg = irq_get_chip_data(irq);
2395
2365
 
2396
2366
        if (!cfg)
2397
2367
                return;
2405
2375
static void ack_apic_edge(struct irq_data *data)
2406
2376
{
2407
2377
        irq_complete_move(data->chip_data);
2408
 
        move_native_irq(data->irq);
 
2378
        irq_move_irq(data);
2409
2379
        ack_APIC_irq();
2410
2380
}
2411
2381
 
2462
2432
        irq_complete_move(cfg);
2463
2433
#ifdef CONFIG_GENERIC_PENDING_IRQ
2464
2434
        /* If we are moving the irq we need to mask it */
2465
 
        if (unlikely(irq_to_desc(irq)->status & IRQ_MOVE_PENDING)) {
 
2435
        if (unlikely(irqd_is_setaffinity_pending(data))) {
2466
2436
                do_unmask_irq = 1;
2467
2437
                mask_ioapic(cfg);
2468
2438
        }
2551
2521
                 * and you can go talk to the chipset vendor about it.
2552
2522
                 */
2553
2523
                if (!io_apic_level_ack_pending(cfg))
2554
 
                        move_masked_irq(irq);
 
2524
                        irq_move_masked_irq(data);
2555
2525
                unmask_ioapic(cfg);
2556
2526
        }
2557
2527
}
2614
2584
         * 0x80, because int 0x80 is hm, kind of importantish. ;)
2615
2585
         */
2616
2586
        for_each_active_irq(irq) {
2617
 
                cfg = get_irq_chip_data(irq);
 
2587
                cfg = irq_get_chip_data(irq);
2618
2588
                if (IO_APIC_IRQ(irq) && cfg && !cfg->vector) {
2619
2589
                        /*
2620
2590
                         * Hmm.. We don't have an entry for this,
2625
2595
                                legacy_pic->make_irq(irq);
2626
2596
                        else
2627
2597
                                /* Strange. Oh, well.. */
2628
 
                                set_irq_chip(irq, &no_irq_chip);
 
2598
                                irq_set_chip(irq, &no_irq_chip);
2629
2599
                }
2630
2600
        }
2631
2601
}
2665
2635
static void lapic_register_intr(int irq)
2666
2636
{
2667
2637
        irq_clear_status_flags(irq, IRQ_LEVEL);
2668
 
        set_irq_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
 
2638
        irq_set_chip_and_handler_name(irq, &lapic_chip, handle_edge_irq,
2669
2639
                                      "edge");
2670
2640
}
2671
2641
 
2749
2719
 */
2750
2720
static inline void __init check_timer(void)
2751
2721
{
2752
 
        struct irq_cfg *cfg = get_irq_chip_data(0);
 
2722
        struct irq_cfg *cfg = irq_get_chip_data(0);
2753
2723
        int node = cpu_to_node(0);
2754
2724
        int apic1, pin1, apic2, pin2;
2755
2725
        unsigned long flags;
2935
2905
}
2936
2906
 
2937
2907
/*
2938
 
 *      Called after all the initialization is done. If we didnt find any
 
2908
 *      Called after all the initialization is done. If we didn't find any
2939
2909
 *      APIC bugs then we can allow the modify fast path
2940
2910
 */
2941
2911
 
2948
2918
 
2949
2919
late_initcall(io_apic_bug_finalize);
2950
2920
 
2951
 
struct sysfs_ioapic_data {
2952
 
        struct sys_device dev;
2953
 
        struct IO_APIC_route_entry entry[0];
2954
 
};
2955
 
static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];
 
2921
static struct IO_APIC_route_entry *ioapic_saved_data[MAX_IO_APICS];
2956
2922
 
2957
 
static int ioapic_suspend(struct sys_device *dev, pm_message_t state)
 
2923
static void suspend_ioapic(int ioapic_id)
2958
2924
{
2959
 
        struct IO_APIC_route_entry *entry;
2960
 
        struct sysfs_ioapic_data *data;
 
2925
        struct IO_APIC_route_entry *saved_data = ioapic_saved_data[ioapic_id];
2961
2926
        int i;
2962
2927
 
2963
 
        data = container_of(dev, struct sysfs_ioapic_data, dev);
2964
 
        entry = data->entry;
2965
 
        for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ )
2966
 
                *entry = ioapic_read_entry(dev->id, i);
 
2928
        if (!saved_data)
 
2929
                return;
 
2930
 
 
2931
        for (i = 0; i < nr_ioapic_registers[ioapic_id]; i++)
 
2932
                saved_data[i] = ioapic_read_entry(ioapic_id, i);
 
2933
}
 
2934
 
 
2935
static int ioapic_suspend(void)
 
2936
{
 
2937
        int ioapic_id;
 
2938
 
 
2939
        for (ioapic_id = 0; ioapic_id < nr_ioapics; ioapic_id++)
 
2940
                suspend_ioapic(ioapic_id);
2967
2941
 
2968
2942
        return 0;
2969
2943
}
2970
2944
 
2971
 
static int ioapic_resume(struct sys_device *dev)
 
2945
static void resume_ioapic(int ioapic_id)
2972
2946
{
2973
 
        struct IO_APIC_route_entry *entry;
2974
 
        struct sysfs_ioapic_data *data;
 
2947
        struct IO_APIC_route_entry *saved_data = ioapic_saved_data[ioapic_id];
2975
2948
        unsigned long flags;
2976
2949
        union IO_APIC_reg_00 reg_00;
2977
2950
        int i;
2978
2951
 
2979
 
        data = container_of(dev, struct sysfs_ioapic_data, dev);
2980
 
        entry = data->entry;
 
2952
        if (!saved_data)
 
2953
                return;
2981
2954
 
2982
2955
        raw_spin_lock_irqsave(&ioapic_lock, flags);
2983
 
        reg_00.raw = io_apic_read(dev->id, 0);
2984
 
        if (reg_00.bits.ID != mp_ioapics[dev->id].apicid) {
2985
 
                reg_00.bits.ID = mp_ioapics[dev->id].apicid;
2986
 
                io_apic_write(dev->id, 0, reg_00.raw);
 
2956
        reg_00.raw = io_apic_read(ioapic_id, 0);
 
2957
        if (reg_00.bits.ID != mp_ioapics[ioapic_id].apicid) {
 
2958
                reg_00.bits.ID = mp_ioapics[ioapic_id].apicid;
 
2959
                io_apic_write(ioapic_id, 0, reg_00.raw);
2987
2960
        }
2988
2961
        raw_spin_unlock_irqrestore(&ioapic_lock, flags);
2989
 
        for (i = 0; i < nr_ioapic_registers[dev->id]; i++)
2990
 
                ioapic_write_entry(dev->id, i, entry[i]);
2991
 
 
2992
 
        return 0;
2993
 
}
2994
 
 
2995
 
static struct sysdev_class ioapic_sysdev_class = {
2996
 
        .name = "ioapic",
 
2962
        for (i = 0; i < nr_ioapic_registers[ioapic_id]; i++)
 
2963
                ioapic_write_entry(ioapic_id, i, saved_data[i]);
 
2964
}
 
2965
 
 
2966
static void ioapic_resume(void)
 
2967
{
 
2968
        int ioapic_id;
 
2969
 
 
2970
        for (ioapic_id = nr_ioapics - 1; ioapic_id >= 0; ioapic_id--)
 
2971
                resume_ioapic(ioapic_id);
 
2972
}
 
2973
 
 
2974
static struct syscore_ops ioapic_syscore_ops = {
2997
2975
        .suspend = ioapic_suspend,
2998
2976
        .resume = ioapic_resume,
2999
2977
};
3000
2978
 
3001
 
static int __init ioapic_init_sysfs(void)
 
2979
static int __init ioapic_init_ops(void)
3002
2980
{
3003
 
        struct sys_device * dev;
3004
 
        int i, size, error;
3005
 
 
3006
 
        error = sysdev_class_register(&ioapic_sysdev_class);
3007
 
        if (error)
3008
 
                return error;
3009
 
 
3010
 
        for (i = 0; i < nr_ioapics; i++ ) {
3011
 
                size = sizeof(struct sys_device) + nr_ioapic_registers[i]
 
2981
        int i;
 
2982
 
 
2983
        for (i = 0; i < nr_ioapics; i++) {
 
2984
                unsigned int size;
 
2985
 
 
2986
                size = nr_ioapic_registers[i]
3012
2987
                        * sizeof(struct IO_APIC_route_entry);
3013
 
                mp_ioapic_data[i] = kzalloc(size, GFP_KERNEL);
3014
 
                if (!mp_ioapic_data[i]) {
3015
 
                        printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
3016
 
                        continue;
3017
 
                }
3018
 
                dev = &mp_ioapic_data[i]->dev;
3019
 
                dev->id = i;
3020
 
                dev->cls = &ioapic_sysdev_class;
3021
 
                error = sysdev_register(dev);
3022
 
                if (error) {
3023
 
                        kfree(mp_ioapic_data[i]);
3024
 
                        mp_ioapic_data[i] = NULL;
3025
 
                        printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
3026
 
                        continue;
3027
 
                }
 
2988
                ioapic_saved_data[i] = kzalloc(size, GFP_KERNEL);
 
2989
                if (!ioapic_saved_data[i])
 
2990
                        pr_err("IOAPIC %d: suspend/resume impossible!\n", i);
3028
2991
        }
3029
2992
 
 
2993
        register_syscore_ops(&ioapic_syscore_ops);
 
2994
 
3030
2995
        return 0;
3031
2996
}
3032
2997
 
3033
 
device_initcall(ioapic_init_sysfs);
 
2998
device_initcall(ioapic_init_ops);
3034
2999
 
3035
3000
/*
3036
3001
 * Dynamic irq allocate and deallocation
3060
3025
        raw_spin_unlock_irqrestore(&vector_lock, flags);
3061
3026
 
3062
3027
        if (ret) {
3063
 
                set_irq_chip_data(irq, cfg);
 
3028
                irq_set_chip_data(irq, cfg);
3064
3029
                irq_clear_status_flags(irq, IRQ_NOREQUEST);
3065
3030
        } else {
3066
3031
                free_irq_at(irq, cfg);
3085
3050
 
3086
3051
void destroy_irq(unsigned int irq)
3087
3052
{
3088
 
        struct irq_cfg *cfg = get_irq_chip_data(irq);
 
3053
        struct irq_cfg *cfg = irq_get_chip_data(irq);
3089
3054
        unsigned long flags;
3090
3055
 
3091
3056
        irq_set_status_flags(irq, IRQ_NOREQUEST|IRQ_NOPROBE);
3119
3084
 
3120
3085
        dest = apic->cpu_mask_to_apicid_and(cfg->domain, apic->target_cpus());
3121
3086
 
3122
 
        if (irq_remapped(get_irq_chip_data(irq))) {
 
3087
        if (irq_remapped(cfg)) {
3123
3088
                struct irte irte;
3124
3089
                int ir_index;
3125
3090
                u16 sub_handle;
3291
3256
 
3292
3257
static int setup_msi_irq(struct pci_dev *dev, struct msi_desc *msidesc, int irq)
3293
3258
{
 
3259
        struct irq_chip *chip = &msi_chip;
3294
3260
        struct msi_msg msg;
3295
3261
        int ret;
3296
3262
 
3298
3264
        if (ret < 0)
3299
3265
                return ret;
3300
3266
 
3301
 
        set_irq_msi(irq, msidesc);
 
3267
        irq_set_msi_desc(irq, msidesc);
3302
3268
        write_msi_msg(irq, &msg);
3303
3269
 
3304
 
        if (irq_remapped(get_irq_chip_data(irq))) {
 
3270
        if (irq_remapped(irq_get_chip_data(irq))) {
3305
3271
                irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
3306
 
                set_irq_chip_and_handler_name(irq, &msi_ir_chip, handle_edge_irq, "edge");
3307
 
        } else
3308
 
                set_irq_chip_and_handler_name(irq, &msi_chip, handle_edge_irq, "edge");
 
3272
                chip = &msi_ir_chip;
 
3273
        }
 
3274
 
 
3275
        irq_set_chip_and_handler_name(irq, chip, handle_edge_irq, "edge");
3309
3276
 
3310
3277
        dev_printk(KERN_DEBUG, &dev->dev, "irq %d for MSI/MSI-X\n", irq);
3311
3278
 
3423
3390
        if (ret < 0)
3424
3391
                return ret;
3425
3392
        dmar_msi_write(irq, &msg);
3426
 
        set_irq_chip_and_handler_name(irq, &dmar_msi_type, handle_edge_irq,
3427
 
                "edge");
 
3393
        irq_set_chip_and_handler_name(irq, &dmar_msi_type, handle_edge_irq,
 
3394
                                      "edge");
3428
3395
        return 0;
3429
3396
}
3430
3397
#endif
3482
3449
 
3483
3450
int arch_setup_hpet_msi(unsigned int irq, unsigned int id)
3484
3451
{
 
3452
        struct irq_chip *chip = &hpet_msi_type;
3485
3453
        struct msi_msg msg;
3486
3454
        int ret;
3487
3455
 
3501
3469
        if (ret < 0)
3502
3470
                return ret;
3503
3471
 
3504
 
        hpet_msi_write(get_irq_data(irq), &msg);
 
3472
        hpet_msi_write(irq_get_handler_data(irq), &msg);
3505
3473
        irq_set_status_flags(irq, IRQ_MOVE_PCNTXT);
3506
 
        if (irq_remapped(get_irq_chip_data(irq)))
3507
 
                set_irq_chip_and_handler_name(irq, &ir_hpet_msi_type,
3508
 
                                              handle_edge_irq, "edge");
3509
 
        else
3510
 
                set_irq_chip_and_handler_name(irq, &hpet_msi_type,
3511
 
                                              handle_edge_irq, "edge");
 
3474
        if (irq_remapped(irq_get_chip_data(irq)))
 
3475
                chip = &ir_hpet_msi_type;
3512
3476
 
 
3477
        irq_set_chip_and_handler_name(irq, chip, handle_edge_irq, "edge");
3513
3478
        return 0;
3514
3479
}
3515
3480
#endif
3596
3561
 
3597
3562
                write_ht_irq_msg(irq, &msg);
3598
3563
 
3599
 
                set_irq_chip_and_handler_name(irq, &ht_irq_chip,
 
3564
                irq_set_chip_and_handler_name(irq, &ht_irq_chip,
3600
3565
                                              handle_edge_irq, "edge");
3601
3566
 
3602
3567
                dev_printk(KERN_DEBUG, &dev->dev, "irq %d for HT\n", irq);
3605
3570
}
3606
3571
#endif /* CONFIG_HT_IRQ */
3607
3572
 
3608
 
int __init io_apic_get_redir_entries (int ioapic)
 
3573
static int
 
3574
io_apic_setup_irq_pin(unsigned int irq, int node, struct io_apic_irq_attr *attr)
 
3575
{
 
3576
        struct irq_cfg *cfg = alloc_irq_and_cfg_at(irq, node);
 
3577
        int ret;
 
3578
 
 
3579
        if (!cfg)
 
3580
                return -EINVAL;
 
3581
        ret = __add_pin_to_irq_node(cfg, node, attr->ioapic, attr->ioapic_pin);
 
3582
        if (!ret)
 
3583
                setup_ioapic_irq(attr->ioapic, attr->ioapic_pin, irq, cfg,
 
3584
                                 attr->trigger, attr->polarity);
 
3585
        return ret;
 
3586
}
 
3587
 
 
3588
int io_apic_setup_irq_pin_once(unsigned int irq, int node,
 
3589
                               struct io_apic_irq_attr *attr)
 
3590
{
 
3591
        unsigned int id = attr->ioapic, pin = attr->ioapic_pin;
 
3592
        int ret;
 
3593
 
 
3594
        /* Avoid redundant programming */
 
3595
        if (test_bit(pin, mp_ioapic_routing[id].pin_programmed)) {
 
3596
                pr_debug("Pin %d-%d already programmed\n",
 
3597
                         mp_ioapics[id].apicid, pin);
 
3598
                return 0;
 
3599
        }
 
3600
        ret = io_apic_setup_irq_pin(irq, node, attr);
 
3601
        if (!ret)
 
3602
                set_bit(pin, mp_ioapic_routing[id].pin_programmed);
 
3603
        return ret;
 
3604
}
 
3605
 
 
3606
static int __init io_apic_get_redir_entries(int ioapic)
3609
3607
{
3610
3608
        union IO_APIC_reg_01    reg_01;
3611
3609
        unsigned long flags;
3659
3657
}
3660
3658
#endif
3661
3659
 
3662
 
static int __io_apic_set_pci_routing(struct device *dev, int irq,
3663
 
                                struct io_apic_irq_attr *irq_attr)
 
3660
int io_apic_set_pci_routing(struct device *dev, int irq,
 
3661
                            struct io_apic_irq_attr *irq_attr)
3664
3662
{
3665
 
        struct irq_cfg *cfg;
3666
3663
        int node;
3667
 
        int ioapic, pin;
3668
 
        int trigger, polarity;
3669
3664
 
3670
 
        ioapic = irq_attr->ioapic;
3671
3665
        if (!IO_APIC_IRQ(irq)) {
3672
3666
                apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
3673
 
                        ioapic);
 
3667
                            irq_attr->ioapic);
3674
3668
                return -EINVAL;
3675
3669
        }
3676
3670
 
3677
 
        if (dev)
3678
 
                node = dev_to_node(dev);
3679
 
        else
3680
 
                node = cpu_to_node(0);
3681
 
 
3682
 
        cfg = alloc_irq_and_cfg_at(irq, node);
3683
 
        if (!cfg)
3684
 
                return 0;
3685
 
 
3686
 
        pin = irq_attr->ioapic_pin;
3687
 
        trigger = irq_attr->trigger;
3688
 
        polarity = irq_attr->polarity;
3689
 
 
3690
 
        /*
3691
 
         * IRQs < 16 are already in the irq_2_pin[] map
3692
 
         */
3693
 
        if (irq >= legacy_pic->nr_legacy_irqs) {
3694
 
                if (__add_pin_to_irq_node(cfg, node, ioapic, pin)) {
3695
 
                        printk(KERN_INFO "can not add pin %d for irq %d\n",
3696
 
                                pin, irq);
3697
 
                        return 0;
3698
 
                }
3699
 
        }
3700
 
 
3701
 
        setup_ioapic_irq(ioapic, pin, irq, cfg, trigger, polarity);
3702
 
 
3703
 
        return 0;
3704
 
}
3705
 
 
3706
 
int io_apic_set_pci_routing(struct device *dev, int irq,
3707
 
                                struct io_apic_irq_attr *irq_attr)
3708
 
{
3709
 
        int ioapic, pin;
3710
 
        /*
3711
 
         * Avoid pin reprogramming.  PRTs typically include entries
3712
 
         * with redundant pin->gsi mappings (but unique PCI devices);
3713
 
         * we only program the IOAPIC on the first.
3714
 
         */
3715
 
        ioapic = irq_attr->ioapic;
3716
 
        pin = irq_attr->ioapic_pin;
3717
 
        if (test_bit(pin, mp_ioapic_routing[ioapic].pin_programmed)) {
3718
 
                pr_debug("Pin %d-%d already programmed\n",
3719
 
                         mp_ioapics[ioapic].apicid, pin);
3720
 
                return 0;
3721
 
        }
3722
 
        set_bit(pin, mp_ioapic_routing[ioapic].pin_programmed);
3723
 
 
3724
 
        return __io_apic_set_pci_routing(dev, irq, irq_attr);
3725
 
}
3726
 
 
3727
 
u8 __init io_apic_unique_id(u8 id)
3728
 
{
3729
 
#ifdef CONFIG_X86_32
3730
 
        if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
3731
 
            !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
3732
 
                return io_apic_get_unique_id(nr_ioapics, id);
3733
 
        else
3734
 
                return id;
3735
 
#else
3736
 
        int i;
3737
 
        DECLARE_BITMAP(used, 256);
3738
 
 
3739
 
        bitmap_zero(used, 256);
3740
 
        for (i = 0; i < nr_ioapics; i++) {
3741
 
                struct mpc_ioapic *ia = &mp_ioapics[i];
3742
 
                __set_bit(ia->apicid, used);
3743
 
        }
3744
 
        if (!test_bit(id, used))
3745
 
                return id;
3746
 
        return find_first_zero_bit(used, 256);
3747
 
#endif
3748
 
}
3749
 
 
3750
 
#ifdef CONFIG_X86_32
3751
 
int __init io_apic_get_unique_id(int ioapic, int apic_id)
 
3671
        node = dev ? dev_to_node(dev) : cpu_to_node(0);
 
3672
 
 
3673
        return io_apic_setup_irq_pin_once(irq, node, irq_attr);
 
3674
}
 
3675
 
 
3676
#ifdef CONFIG_X86_32
 
3677
static int __init io_apic_get_unique_id(int ioapic, int apic_id)
3752
3678
{
3753
3679
        union IO_APIC_reg_00 reg_00;
3754
3680
        static physid_mask_t apic_id_map = PHYSID_MASK_NONE;
3821
3747
 
3822
3748
        return apic_id;
3823
3749
}
 
3750
 
 
3751
static u8 __init io_apic_unique_id(u8 id)
 
3752
{
 
3753
        if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
 
3754
            !APIC_XAPIC(apic_version[boot_cpu_physical_apicid]))
 
3755
                return io_apic_get_unique_id(nr_ioapics, id);
 
3756
        else
 
3757
                return id;
 
3758
}
 
3759
#else
 
3760
static u8 __init io_apic_unique_id(u8 id)
 
3761
{
 
3762
        int i;
 
3763
        DECLARE_BITMAP(used, 256);
 
3764
 
 
3765
        bitmap_zero(used, 256);
 
3766
        for (i = 0; i < nr_ioapics; i++) {
 
3767
                struct mpc_ioapic *ia = &mp_ioapics[i];
 
3768
                __set_bit(ia->apicid, used);
 
3769
        }
 
3770
        if (!test_bit(id, used))
 
3771
                return id;
 
3772
        return find_first_zero_bit(used, 256);
 
3773
}
3824
3774
#endif
3825
3775
 
3826
 
int __init io_apic_get_version(int ioapic)
 
3776
static int __init io_apic_get_version(int ioapic)
3827
3777
{
3828
3778
        union IO_APIC_reg_01    reg_01;
3829
3779
        unsigned long flags;
3868
3818
void __init setup_ioapic_dest(void)
3869
3819
{
3870
3820
        int pin, ioapic, irq, irq_entry;
3871
 
        struct irq_desc *desc;
3872
3821
        const struct cpumask *mask;
 
3822
        struct irq_data *idata;
3873
3823
 
3874
3824
        if (skip_ioapic_setup == 1)
3875
3825
                return;
3884
3834
                if ((ioapic > 0) && (irq > 16))
3885
3835
                        continue;
3886
3836
 
3887
 
                desc = irq_to_desc(irq);
 
3837
                idata = irq_get_irq_data(irq);
3888
3838
 
3889
3839
                /*
3890
3840
                 * Honour affinities which have been set in early boot
3891
3841
                 */
3892
 
                if (desc->status &
3893
 
                    (IRQ_NO_BALANCING | IRQ_AFFINITY_SET))
3894
 
                        mask = desc->irq_data.affinity;
 
3842
                if (!irqd_can_balance(idata) || irqd_affinity_was_set(idata))
 
3843
                        mask = idata->affinity;
3895
3844
                else
3896
3845
                        mask = apic->target_cpus();
3897
3846
 
3898
3847
                if (intr_remapping_enabled)
3899
 
                        ir_ioapic_set_affinity(&desc->irq_data, mask, false);
 
3848
                        ir_ioapic_set_affinity(idata, mask, false);
3900
3849
                else
3901
 
                        ioapic_set_affinity(&desc->irq_data, mask, false);
 
3850
                        ioapic_set_affinity(idata, mask, false);
3902
3851
        }
3903
3852
 
3904
3853
}
4026
3975
        return gsi - mp_gsi_routing[ioapic].gsi_base;
4027
3976
}
4028
3977
 
4029
 
static int bad_ioapic(unsigned long address)
 
3978
static __init int bad_ioapic(unsigned long address)
4030
3979
{
4031
3980
        if (nr_ioapics >= MAX_IO_APICS) {
4032
 
                printk(KERN_WARNING "WARING: Max # of I/O APICs (%d) exceeded "
 
3981
                printk(KERN_WARNING "WARNING: Max # of I/O APICs (%d) exceeded "
4033
3982
                       "(found %d), skipping\n", MAX_IO_APICS, nr_ioapics);
4034
3983
                return 1;
4035
3984
        }
4086
4035
/* Enable IOAPIC early just for system timer */
4087
4036
void __init pre_init_apic_IRQ0(void)
4088
4037
{
4089
 
        struct irq_cfg *cfg;
 
4038
        struct io_apic_irq_attr attr = { 0, 0, 0, 0 };
4090
4039
 
4091
4040
        printk(KERN_INFO "Early APIC setup for system timer0\n");
4092
4041
#ifndef CONFIG_SMP
4093
4042
        physid_set_mask_of_physid(boot_cpu_physical_apicid,
4094
4043
                                         &phys_cpu_present_map);
4095
4044
#endif
4096
 
        /* Make sure the irq descriptor is set up */
4097
 
        cfg = alloc_irq_and_cfg_at(0, 0);
4098
 
 
4099
4045
        setup_local_APIC();
4100
4046
 
4101
 
        add_pin_to_irq_node(cfg, 0, 0, 0);
4102
 
        set_irq_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq, "edge");
4103
 
 
4104
 
        setup_ioapic_irq(0, 0, 0, cfg, 0, 0);
 
4047
        io_apic_setup_irq_pin(0, 0, &attr);
 
4048
        irq_set_chip_and_handler_name(0, &ioapic_chip, handle_edge_irq,
 
4049
                                      "edge");
4105
4050
}