PageRenderTime 48ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/x86_64/kernel/io_apic.c

https://bitbucket.org/evzijst/gittest
C | 1982 lines | 1339 code | 309 blank | 334 comment | 240 complexity | ef48098e06b4faed412965fdda672c2e MD5 | raw file
Possible License(s): CC-BY-SA-3.0, GPL-2.0, LGPL-2.0
  1. /*
  2. * Intel IO-APIC support for multi-Pentium hosts.
  3. *
  4. * Copyright (C) 1997, 1998, 1999, 2000 Ingo Molnar, Hajnalka Szabo
  5. *
  6. * Many thanks to Stig Venaas for trying out countless experimental
  7. * patches and reporting/debugging problems patiently!
  8. *
  9. * (c) 1999, Multiple IO-APIC support, developed by
  10. * Ken-ichi Yaku <yaku@css1.kbnes.nec.co.jp> and
  11. * Hidemi Kishimoto <kisimoto@css1.kbnes.nec.co.jp>,
  12. * further tested and cleaned up by Zach Brown <zab@redhat.com>
  13. * and Ingo Molnar <mingo@redhat.com>
  14. *
  15. * Fixes
  16. * Maciej W. Rozycki : Bits for genuine 82489DX APICs;
  17. * thanks to Eric Gilmore
  18. * and Rolf G. Tews
  19. * for testing these extensively
  20. * Paul Diefenbaugh : Added full ACPI support
  21. */
  22. #include <linux/mm.h>
  23. #include <linux/irq.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/init.h>
  26. #include <linux/delay.h>
  27. #include <linux/sched.h>
  28. #include <linux/config.h>
  29. #include <linux/smp_lock.h>
  30. #include <linux/mc146818rtc.h>
  31. #include <linux/acpi.h>
  32. #include <linux/sysdev.h>
  33. #include <asm/io.h>
  34. #include <asm/smp.h>
  35. #include <asm/desc.h>
  36. #include <asm/proto.h>
  37. #include <asm/mach_apic.h>
  38. #define __apicdebuginit __init
  39. int sis_apic_bug; /* not actually supported, dummy for compile */
  40. static DEFINE_SPINLOCK(ioapic_lock);
  41. /*
  42. * # of IRQ routing registers
  43. */
  44. int nr_ioapic_registers[MAX_IO_APICS];
  45. /*
  46. * Rough estimation of how many shared IRQs there are, can
  47. * be changed anytime.
  48. */
  49. #define MAX_PLUS_SHARED_IRQS NR_IRQS
  50. #define PIN_MAP_SIZE (MAX_PLUS_SHARED_IRQS + NR_IRQS)
  51. /*
  52. * This is performance-critical, we want to do it O(1)
  53. *
  54. * the indexing order of this array favors 1:1 mappings
  55. * between pins and IRQs.
  56. */
  57. static struct irq_pin_list {
  58. short apic, pin, next;
  59. } irq_2_pin[PIN_MAP_SIZE];
  60. int vector_irq[NR_VECTORS] = { [0 ... NR_VECTORS - 1] = -1};
  61. #ifdef CONFIG_PCI_MSI
  62. #define vector_to_irq(vector) \
  63. (platform_legacy_irq(vector) ? vector : vector_irq[vector])
  64. #else
  65. #define vector_to_irq(vector) (vector)
  66. #endif
  67. /*
  68. * The common case is 1:1 IRQ<->pin mappings. Sometimes there are
  69. * shared ISA-space IRQs, so we have to support them. We are super
  70. * fast in the common case, and fast for shared ISA-space IRQs.
  71. */
  72. static void add_pin_to_irq(unsigned int irq, int apic, int pin)
  73. {
  74. static int first_free_entry = NR_IRQS;
  75. struct irq_pin_list *entry = irq_2_pin + irq;
  76. while (entry->next)
  77. entry = irq_2_pin + entry->next;
  78. if (entry->pin != -1) {
  79. entry->next = first_free_entry;
  80. entry = irq_2_pin + entry->next;
  81. if (++first_free_entry >= PIN_MAP_SIZE)
  82. panic("io_apic.c: whoops");
  83. }
  84. entry->apic = apic;
  85. entry->pin = pin;
  86. }
  87. #define __DO_ACTION(R, ACTION, FINAL) \
  88. \
  89. { \
  90. int pin; \
  91. struct irq_pin_list *entry = irq_2_pin + irq; \
  92. \
  93. for (;;) { \
  94. unsigned int reg; \
  95. pin = entry->pin; \
  96. if (pin == -1) \
  97. break; \
  98. reg = io_apic_read(entry->apic, 0x10 + R + pin*2); \
  99. reg ACTION; \
  100. io_apic_modify(entry->apic, reg); \
  101. if (!entry->next) \
  102. break; \
  103. entry = irq_2_pin + entry->next; \
  104. } \
  105. FINAL; \
  106. }
  107. #define DO_ACTION(name,R,ACTION, FINAL) \
  108. \
  109. static void name##_IO_APIC_irq (unsigned int irq) \
  110. __DO_ACTION(R, ACTION, FINAL)
  111. DO_ACTION( __mask, 0, |= 0x00010000, io_apic_sync(entry->apic) )
  112. /* mask = 1 */
  113. DO_ACTION( __unmask, 0, &= 0xfffeffff, )
  114. /* mask = 0 */
  115. static void mask_IO_APIC_irq (unsigned int irq)
  116. {
  117. unsigned long flags;
  118. spin_lock_irqsave(&ioapic_lock, flags);
  119. __mask_IO_APIC_irq(irq);
  120. spin_unlock_irqrestore(&ioapic_lock, flags);
  121. }
  122. static void unmask_IO_APIC_irq (unsigned int irq)
  123. {
  124. unsigned long flags;
  125. spin_lock_irqsave(&ioapic_lock, flags);
  126. __unmask_IO_APIC_irq(irq);
  127. spin_unlock_irqrestore(&ioapic_lock, flags);
  128. }
  129. static void clear_IO_APIC_pin(unsigned int apic, unsigned int pin)
  130. {
  131. struct IO_APIC_route_entry entry;
  132. unsigned long flags;
  133. /* Check delivery_mode to be sure we're not clearing an SMI pin */
  134. spin_lock_irqsave(&ioapic_lock, flags);
  135. *(((int*)&entry) + 0) = io_apic_read(apic, 0x10 + 2 * pin);
  136. *(((int*)&entry) + 1) = io_apic_read(apic, 0x11 + 2 * pin);
  137. spin_unlock_irqrestore(&ioapic_lock, flags);
  138. if (entry.delivery_mode == dest_SMI)
  139. return;
  140. /*
  141. * Disable it in the IO-APIC irq-routing table:
  142. */
  143. memset(&entry, 0, sizeof(entry));
  144. entry.mask = 1;
  145. spin_lock_irqsave(&ioapic_lock, flags);
  146. io_apic_write(apic, 0x10 + 2 * pin, *(((int *)&entry) + 0));
  147. io_apic_write(apic, 0x11 + 2 * pin, *(((int *)&entry) + 1));
  148. spin_unlock_irqrestore(&ioapic_lock, flags);
  149. }
  150. static void clear_IO_APIC (void)
  151. {
  152. int apic, pin;
  153. for (apic = 0; apic < nr_ioapics; apic++)
  154. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
  155. clear_IO_APIC_pin(apic, pin);
  156. }
  157. /*
  158. * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
  159. * specific CPU-side IRQs.
  160. */
  161. #define MAX_PIRQS 8
  162. static int pirq_entries [MAX_PIRQS];
  163. static int pirqs_enabled;
  164. int skip_ioapic_setup;
  165. int ioapic_force;
  166. /* dummy parsing: see setup.c */
  167. static int __init disable_ioapic_setup(char *str)
  168. {
  169. skip_ioapic_setup = 1;
  170. return 1;
  171. }
  172. static int __init enable_ioapic_setup(char *str)
  173. {
  174. ioapic_force = 1;
  175. skip_ioapic_setup = 0;
  176. return 1;
  177. }
  178. __setup("noapic", disable_ioapic_setup);
  179. __setup("apic", enable_ioapic_setup);
  180. #include <asm/pci-direct.h>
  181. #include <linux/pci_ids.h>
  182. #include <linux/pci.h>
  183. /* Temporary Hack. Nvidia and VIA boards currently only work with IO-APIC
  184. off. Check for an Nvidia or VIA PCI bridge and turn it off.
  185. Use pci direct infrastructure because this runs before the PCI subsystem.
  186. Can be overwritten with "apic"
  187. And another hack to disable the IOMMU on VIA chipsets.
  188. Kludge-O-Rama. */
  189. void __init check_ioapic(void)
  190. {
  191. int num,slot,func;
  192. if (ioapic_force)
  193. return;
  194. /* Poor man's PCI discovery */
  195. for (num = 0; num < 32; num++) {
  196. for (slot = 0; slot < 32; slot++) {
  197. for (func = 0; func < 8; func++) {
  198. u32 class;
  199. u32 vendor;
  200. u8 type;
  201. class = read_pci_config(num,slot,func,
  202. PCI_CLASS_REVISION);
  203. if (class == 0xffffffff)
  204. break;
  205. if ((class >> 16) != PCI_CLASS_BRIDGE_PCI)
  206. continue;
  207. vendor = read_pci_config(num, slot, func,
  208. PCI_VENDOR_ID);
  209. vendor &= 0xffff;
  210. switch (vendor) {
  211. case PCI_VENDOR_ID_VIA:
  212. #ifdef CONFIG_GART_IOMMU
  213. if ((end_pfn >= (0xffffffff>>PAGE_SHIFT) ||
  214. force_iommu) &&
  215. !iommu_aperture_allowed) {
  216. printk(KERN_INFO
  217. "Looks like a VIA chipset. Disabling IOMMU. Overwrite with \"iommu=allowed\"\n");
  218. iommu_aperture_disabled = 1;
  219. }
  220. #endif
  221. return;
  222. case PCI_VENDOR_ID_NVIDIA:
  223. #ifdef CONFIG_ACPI
  224. /* All timer overrides on Nvidia
  225. seem to be wrong. Skip them. */
  226. acpi_skip_timer_override = 1;
  227. printk(KERN_INFO
  228. "Nvidia board detected. Ignoring ACPI timer override.\n");
  229. #endif
  230. /* RED-PEN skip them on mptables too? */
  231. return;
  232. }
  233. /* No multi-function device? */
  234. type = read_pci_config_byte(num,slot,func,
  235. PCI_HEADER_TYPE);
  236. if (!(type & 0x80))
  237. break;
  238. }
  239. }
  240. }
  241. }
  242. static int __init ioapic_pirq_setup(char *str)
  243. {
  244. int i, max;
  245. int ints[MAX_PIRQS+1];
  246. get_options(str, ARRAY_SIZE(ints), ints);
  247. for (i = 0; i < MAX_PIRQS; i++)
  248. pirq_entries[i] = -1;
  249. pirqs_enabled = 1;
  250. apic_printk(APIC_VERBOSE, "PIRQ redirection, working around broken MP-BIOS.\n");
  251. max = MAX_PIRQS;
  252. if (ints[0] < MAX_PIRQS)
  253. max = ints[0];
  254. for (i = 0; i < max; i++) {
  255. apic_printk(APIC_VERBOSE, "... PIRQ%d -> IRQ %d\n", i, ints[i+1]);
  256. /*
  257. * PIRQs are mapped upside down, usually.
  258. */
  259. pirq_entries[MAX_PIRQS-i-1] = ints[i+1];
  260. }
  261. return 1;
  262. }
  263. __setup("pirq=", ioapic_pirq_setup);
  264. /*
  265. * Find the IRQ entry number of a certain pin.
  266. */
  267. static int find_irq_entry(int apic, int pin, int type)
  268. {
  269. int i;
  270. for (i = 0; i < mp_irq_entries; i++)
  271. if (mp_irqs[i].mpc_irqtype == type &&
  272. (mp_irqs[i].mpc_dstapic == mp_ioapics[apic].mpc_apicid ||
  273. mp_irqs[i].mpc_dstapic == MP_APIC_ALL) &&
  274. mp_irqs[i].mpc_dstirq == pin)
  275. return i;
  276. return -1;
  277. }
  278. /*
  279. * Find the pin to which IRQ[irq] (ISA) is connected
  280. */
  281. static int __init find_isa_irq_pin(int irq, int type)
  282. {
  283. int i;
  284. for (i = 0; i < mp_irq_entries; i++) {
  285. int lbus = mp_irqs[i].mpc_srcbus;
  286. if ((mp_bus_id_to_type[lbus] == MP_BUS_ISA ||
  287. mp_bus_id_to_type[lbus] == MP_BUS_EISA ||
  288. mp_bus_id_to_type[lbus] == MP_BUS_MCA) &&
  289. (mp_irqs[i].mpc_irqtype == type) &&
  290. (mp_irqs[i].mpc_srcbusirq == irq))
  291. return mp_irqs[i].mpc_dstirq;
  292. }
  293. return -1;
  294. }
  295. /*
  296. * Find a specific PCI IRQ entry.
  297. * Not an __init, possibly needed by modules
  298. */
  299. static int pin_2_irq(int idx, int apic, int pin);
  300. int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin)
  301. {
  302. int apic, i, best_guess = -1;
  303. apic_printk(APIC_DEBUG, "querying PCI -> IRQ mapping bus:%d, slot:%d, pin:%d.\n",
  304. bus, slot, pin);
  305. if (mp_bus_id_to_pci_bus[bus] == -1) {
  306. apic_printk(APIC_VERBOSE, "PCI BIOS passed nonexistent PCI bus %d!\n", bus);
  307. return -1;
  308. }
  309. for (i = 0; i < mp_irq_entries; i++) {
  310. int lbus = mp_irqs[i].mpc_srcbus;
  311. for (apic = 0; apic < nr_ioapics; apic++)
  312. if (mp_ioapics[apic].mpc_apicid == mp_irqs[i].mpc_dstapic ||
  313. mp_irqs[i].mpc_dstapic == MP_APIC_ALL)
  314. break;
  315. if ((mp_bus_id_to_type[lbus] == MP_BUS_PCI) &&
  316. !mp_irqs[i].mpc_irqtype &&
  317. (bus == lbus) &&
  318. (slot == ((mp_irqs[i].mpc_srcbusirq >> 2) & 0x1f))) {
  319. int irq = pin_2_irq(i,apic,mp_irqs[i].mpc_dstirq);
  320. if (!(apic || IO_APIC_IRQ(irq)))
  321. continue;
  322. if (pin == (mp_irqs[i].mpc_srcbusirq & 3))
  323. return irq;
  324. /*
  325. * Use the first all-but-pin matching entry as a
  326. * best-guess fuzzy result for broken mptables.
  327. */
  328. if (best_guess < 0)
  329. best_guess = irq;
  330. }
  331. }
  332. return best_guess;
  333. }
  334. /*
  335. * EISA Edge/Level control register, ELCR
  336. */
  337. static int EISA_ELCR(unsigned int irq)
  338. {
  339. if (irq < 16) {
  340. unsigned int port = 0x4d0 + (irq >> 3);
  341. return (inb(port) >> (irq & 7)) & 1;
  342. }
  343. apic_printk(APIC_VERBOSE, "Broken MPtable reports ISA irq %d\n", irq);
  344. return 0;
  345. }
  346. /* EISA interrupts are always polarity zero and can be edge or level
  347. * trigger depending on the ELCR value. If an interrupt is listed as
  348. * EISA conforming in the MP table, that means its trigger type must
  349. * be read in from the ELCR */
  350. #define default_EISA_trigger(idx) (EISA_ELCR(mp_irqs[idx].mpc_srcbusirq))
  351. #define default_EISA_polarity(idx) (0)
  352. /* ISA interrupts are always polarity zero edge triggered,
  353. * when listed as conforming in the MP table. */
  354. #define default_ISA_trigger(idx) (0)
  355. #define default_ISA_polarity(idx) (0)
  356. /* PCI interrupts are always polarity one level triggered,
  357. * when listed as conforming in the MP table. */
  358. #define default_PCI_trigger(idx) (1)
  359. #define default_PCI_polarity(idx) (1)
  360. /* MCA interrupts are always polarity zero level triggered,
  361. * when listed as conforming in the MP table. */
  362. #define default_MCA_trigger(idx) (1)
  363. #define default_MCA_polarity(idx) (0)
  364. static int __init MPBIOS_polarity(int idx)
  365. {
  366. int bus = mp_irqs[idx].mpc_srcbus;
  367. int polarity;
  368. /*
  369. * Determine IRQ line polarity (high active or low active):
  370. */
  371. switch (mp_irqs[idx].mpc_irqflag & 3)
  372. {
  373. case 0: /* conforms, ie. bus-type dependent polarity */
  374. {
  375. switch (mp_bus_id_to_type[bus])
  376. {
  377. case MP_BUS_ISA: /* ISA pin */
  378. {
  379. polarity = default_ISA_polarity(idx);
  380. break;
  381. }
  382. case MP_BUS_EISA: /* EISA pin */
  383. {
  384. polarity = default_EISA_polarity(idx);
  385. break;
  386. }
  387. case MP_BUS_PCI: /* PCI pin */
  388. {
  389. polarity = default_PCI_polarity(idx);
  390. break;
  391. }
  392. case MP_BUS_MCA: /* MCA pin */
  393. {
  394. polarity = default_MCA_polarity(idx);
  395. break;
  396. }
  397. default:
  398. {
  399. printk(KERN_WARNING "broken BIOS!!\n");
  400. polarity = 1;
  401. break;
  402. }
  403. }
  404. break;
  405. }
  406. case 1: /* high active */
  407. {
  408. polarity = 0;
  409. break;
  410. }
  411. case 2: /* reserved */
  412. {
  413. printk(KERN_WARNING "broken BIOS!!\n");
  414. polarity = 1;
  415. break;
  416. }
  417. case 3: /* low active */
  418. {
  419. polarity = 1;
  420. break;
  421. }
  422. default: /* invalid */
  423. {
  424. printk(KERN_WARNING "broken BIOS!!\n");
  425. polarity = 1;
  426. break;
  427. }
  428. }
  429. return polarity;
  430. }
  431. static int MPBIOS_trigger(int idx)
  432. {
  433. int bus = mp_irqs[idx].mpc_srcbus;
  434. int trigger;
  435. /*
  436. * Determine IRQ trigger mode (edge or level sensitive):
  437. */
  438. switch ((mp_irqs[idx].mpc_irqflag>>2) & 3)
  439. {
  440. case 0: /* conforms, ie. bus-type dependent */
  441. {
  442. switch (mp_bus_id_to_type[bus])
  443. {
  444. case MP_BUS_ISA: /* ISA pin */
  445. {
  446. trigger = default_ISA_trigger(idx);
  447. break;
  448. }
  449. case MP_BUS_EISA: /* EISA pin */
  450. {
  451. trigger = default_EISA_trigger(idx);
  452. break;
  453. }
  454. case MP_BUS_PCI: /* PCI pin */
  455. {
  456. trigger = default_PCI_trigger(idx);
  457. break;
  458. }
  459. case MP_BUS_MCA: /* MCA pin */
  460. {
  461. trigger = default_MCA_trigger(idx);
  462. break;
  463. }
  464. default:
  465. {
  466. printk(KERN_WARNING "broken BIOS!!\n");
  467. trigger = 1;
  468. break;
  469. }
  470. }
  471. break;
  472. }
  473. case 1: /* edge */
  474. {
  475. trigger = 0;
  476. break;
  477. }
  478. case 2: /* reserved */
  479. {
  480. printk(KERN_WARNING "broken BIOS!!\n");
  481. trigger = 1;
  482. break;
  483. }
  484. case 3: /* level */
  485. {
  486. trigger = 1;
  487. break;
  488. }
  489. default: /* invalid */
  490. {
  491. printk(KERN_WARNING "broken BIOS!!\n");
  492. trigger = 0;
  493. break;
  494. }
  495. }
  496. return trigger;
  497. }
  498. static inline int irq_polarity(int idx)
  499. {
  500. return MPBIOS_polarity(idx);
  501. }
  502. static inline int irq_trigger(int idx)
  503. {
  504. return MPBIOS_trigger(idx);
  505. }
  506. static int pin_2_irq(int idx, int apic, int pin)
  507. {
  508. int irq, i;
  509. int bus = mp_irqs[idx].mpc_srcbus;
  510. /*
  511. * Debugging check, we are in big trouble if this message pops up!
  512. */
  513. if (mp_irqs[idx].mpc_dstirq != pin)
  514. printk(KERN_ERR "broken BIOS or MPTABLE parser, ayiee!!\n");
  515. switch (mp_bus_id_to_type[bus])
  516. {
  517. case MP_BUS_ISA: /* ISA pin */
  518. case MP_BUS_EISA:
  519. case MP_BUS_MCA:
  520. {
  521. irq = mp_irqs[idx].mpc_srcbusirq;
  522. break;
  523. }
  524. case MP_BUS_PCI: /* PCI pin */
  525. {
  526. /*
  527. * PCI IRQs are mapped in order
  528. */
  529. i = irq = 0;
  530. while (i < apic)
  531. irq += nr_ioapic_registers[i++];
  532. irq += pin;
  533. break;
  534. }
  535. default:
  536. {
  537. printk(KERN_ERR "unknown bus type %d.\n",bus);
  538. irq = 0;
  539. break;
  540. }
  541. }
  542. /*
  543. * PCI IRQ command line redirection. Yes, limits are hardcoded.
  544. */
  545. if ((pin >= 16) && (pin <= 23)) {
  546. if (pirq_entries[pin-16] != -1) {
  547. if (!pirq_entries[pin-16]) {
  548. apic_printk(APIC_VERBOSE, "disabling PIRQ%d\n", pin-16);
  549. } else {
  550. irq = pirq_entries[pin-16];
  551. apic_printk(APIC_VERBOSE, "using PIRQ%d -> IRQ %d\n",
  552. pin-16, irq);
  553. }
  554. }
  555. }
  556. return irq;
  557. }
  558. static inline int IO_APIC_irq_trigger(int irq)
  559. {
  560. int apic, idx, pin;
  561. for (apic = 0; apic < nr_ioapics; apic++) {
  562. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  563. idx = find_irq_entry(apic,pin,mp_INT);
  564. if ((idx != -1) && (irq == pin_2_irq(idx,apic,pin)))
  565. return irq_trigger(idx);
  566. }
  567. }
  568. /*
  569. * nonexistent IRQs are edge default
  570. */
  571. return 0;
  572. }
  573. /* irq_vectors is indexed by the sum of all RTEs in all I/O APICs. */
  574. u8 irq_vector[NR_IRQ_VECTORS] = { FIRST_DEVICE_VECTOR , 0 };
  575. int assign_irq_vector(int irq)
  576. {
  577. static int current_vector = FIRST_DEVICE_VECTOR, offset = 0;
  578. BUG_ON(irq >= NR_IRQ_VECTORS);
  579. if (IO_APIC_VECTOR(irq) > 0)
  580. return IO_APIC_VECTOR(irq);
  581. next:
  582. current_vector += 8;
  583. if (current_vector == IA32_SYSCALL_VECTOR)
  584. goto next;
  585. if (current_vector >= FIRST_SYSTEM_VECTOR) {
  586. offset++;
  587. if (!(offset%8))
  588. return -ENOSPC;
  589. current_vector = FIRST_DEVICE_VECTOR + offset;
  590. }
  591. vector_irq[current_vector] = irq;
  592. if (irq != AUTO_ASSIGN)
  593. IO_APIC_VECTOR(irq) = current_vector;
  594. return current_vector;
  595. }
  596. extern void (*interrupt[NR_IRQS])(void);
  597. static struct hw_interrupt_type ioapic_level_type;
  598. static struct hw_interrupt_type ioapic_edge_type;
  599. #define IOAPIC_AUTO -1
  600. #define IOAPIC_EDGE 0
  601. #define IOAPIC_LEVEL 1
  602. static inline void ioapic_register_intr(int irq, int vector, unsigned long trigger)
  603. {
  604. if (use_pci_vector() && !platform_legacy_irq(irq)) {
  605. if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
  606. trigger == IOAPIC_LEVEL)
  607. irq_desc[vector].handler = &ioapic_level_type;
  608. else
  609. irq_desc[vector].handler = &ioapic_edge_type;
  610. set_intr_gate(vector, interrupt[vector]);
  611. } else {
  612. if ((trigger == IOAPIC_AUTO && IO_APIC_irq_trigger(irq)) ||
  613. trigger == IOAPIC_LEVEL)
  614. irq_desc[irq].handler = &ioapic_level_type;
  615. else
  616. irq_desc[irq].handler = &ioapic_edge_type;
  617. set_intr_gate(vector, interrupt[irq]);
  618. }
  619. }
  620. static void __init setup_IO_APIC_irqs(void)
  621. {
  622. struct IO_APIC_route_entry entry;
  623. int apic, pin, idx, irq, first_notcon = 1, vector;
  624. unsigned long flags;
  625. apic_printk(APIC_VERBOSE, KERN_DEBUG "init IO_APIC IRQs\n");
  626. for (apic = 0; apic < nr_ioapics; apic++) {
  627. for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) {
  628. /*
  629. * add it to the IO-APIC irq-routing table:
  630. */
  631. memset(&entry,0,sizeof(entry));
  632. entry.delivery_mode = INT_DELIVERY_MODE;
  633. entry.dest_mode = INT_DEST_MODE;
  634. entry.mask = 0; /* enable IRQ */
  635. entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
  636. idx = find_irq_entry(apic,pin,mp_INT);
  637. if (idx == -1) {
  638. if (first_notcon) {
  639. apic_printk(APIC_VERBOSE, KERN_DEBUG " IO-APIC (apicid-pin) %d-%d", mp_ioapics[apic].mpc_apicid, pin);
  640. first_notcon = 0;
  641. } else
  642. apic_printk(APIC_VERBOSE, ", %d-%d", mp_ioapics[apic].mpc_apicid, pin);
  643. continue;
  644. }
  645. entry.trigger = irq_trigger(idx);
  646. entry.polarity = irq_polarity(idx);
  647. if (irq_trigger(idx)) {
  648. entry.trigger = 1;
  649. entry.mask = 1;
  650. entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
  651. }
  652. irq = pin_2_irq(idx, apic, pin);
  653. add_pin_to_irq(irq, apic, pin);
  654. if (!apic && !IO_APIC_IRQ(irq))
  655. continue;
  656. if (IO_APIC_IRQ(irq)) {
  657. vector = assign_irq_vector(irq);
  658. entry.vector = vector;
  659. ioapic_register_intr(irq, vector, IOAPIC_AUTO);
  660. if (!apic && (irq < 16))
  661. disable_8259A_irq(irq);
  662. }
  663. spin_lock_irqsave(&ioapic_lock, flags);
  664. io_apic_write(apic, 0x11+2*pin, *(((int *)&entry)+1));
  665. io_apic_write(apic, 0x10+2*pin, *(((int *)&entry)+0));
  666. spin_unlock_irqrestore(&ioapic_lock, flags);
  667. }
  668. }
  669. if (!first_notcon)
  670. apic_printk(APIC_VERBOSE," not connected.\n");
  671. }
  672. /*
  673. * Set up the 8259A-master output pin as broadcast to all
  674. * CPUs.
  675. */
  676. static void __init setup_ExtINT_IRQ0_pin(unsigned int pin, int vector)
  677. {
  678. struct IO_APIC_route_entry entry;
  679. unsigned long flags;
  680. memset(&entry,0,sizeof(entry));
  681. disable_8259A_irq(0);
  682. /* mask LVT0 */
  683. apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
  684. /*
  685. * We use logical delivery to get the timer IRQ
  686. * to the first CPU.
  687. */
  688. entry.dest_mode = INT_DEST_MODE;
  689. entry.mask = 0; /* unmask IRQ now */
  690. entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
  691. entry.delivery_mode = INT_DELIVERY_MODE;
  692. entry.polarity = 0;
  693. entry.trigger = 0;
  694. entry.vector = vector;
  695. /*
  696. * The timer IRQ doesn't have to know that behind the
  697. * scene we have a 8259A-master in AEOI mode ...
  698. */
  699. irq_desc[0].handler = &ioapic_edge_type;
  700. /*
  701. * Add it to the IO-APIC irq-routing table:
  702. */
  703. spin_lock_irqsave(&ioapic_lock, flags);
  704. io_apic_write(0, 0x11+2*pin, *(((int *)&entry)+1));
  705. io_apic_write(0, 0x10+2*pin, *(((int *)&entry)+0));
  706. spin_unlock_irqrestore(&ioapic_lock, flags);
  707. enable_8259A_irq(0);
  708. }
  709. void __init UNEXPECTED_IO_APIC(void)
  710. {
  711. }
  712. void __apicdebuginit print_IO_APIC(void)
  713. {
  714. int apic, i;
  715. union IO_APIC_reg_00 reg_00;
  716. union IO_APIC_reg_01 reg_01;
  717. union IO_APIC_reg_02 reg_02;
  718. unsigned long flags;
  719. if (apic_verbosity == APIC_QUIET)
  720. return;
  721. printk(KERN_DEBUG "number of MP IRQ sources: %d.\n", mp_irq_entries);
  722. for (i = 0; i < nr_ioapics; i++)
  723. printk(KERN_DEBUG "number of IO-APIC #%d registers: %d.\n",
  724. mp_ioapics[i].mpc_apicid, nr_ioapic_registers[i]);
  725. /*
  726. * We are a bit conservative about what we expect. We have to
  727. * know about every hardware change ASAP.
  728. */
  729. printk(KERN_INFO "testing the IO APIC.......................\n");
  730. for (apic = 0; apic < nr_ioapics; apic++) {
  731. spin_lock_irqsave(&ioapic_lock, flags);
  732. reg_00.raw = io_apic_read(apic, 0);
  733. reg_01.raw = io_apic_read(apic, 1);
  734. if (reg_01.bits.version >= 0x10)
  735. reg_02.raw = io_apic_read(apic, 2);
  736. spin_unlock_irqrestore(&ioapic_lock, flags);
  737. printk("\n");
  738. printk(KERN_DEBUG "IO APIC #%d......\n", mp_ioapics[apic].mpc_apicid);
  739. printk(KERN_DEBUG ".... register #00: %08X\n", reg_00.raw);
  740. printk(KERN_DEBUG "....... : physical APIC id: %02X\n", reg_00.bits.ID);
  741. if (reg_00.bits.__reserved_1 || reg_00.bits.__reserved_2)
  742. UNEXPECTED_IO_APIC();
  743. printk(KERN_DEBUG ".... register #01: %08X\n", *(int *)&reg_01);
  744. printk(KERN_DEBUG "....... : max redirection entries: %04X\n", reg_01.bits.entries);
  745. if ( (reg_01.bits.entries != 0x0f) && /* older (Neptune) boards */
  746. (reg_01.bits.entries != 0x17) && /* typical ISA+PCI boards */
  747. (reg_01.bits.entries != 0x1b) && /* Compaq Proliant boards */
  748. (reg_01.bits.entries != 0x1f) && /* dual Xeon boards */
  749. (reg_01.bits.entries != 0x22) && /* bigger Xeon boards */
  750. (reg_01.bits.entries != 0x2E) &&
  751. (reg_01.bits.entries != 0x3F) &&
  752. (reg_01.bits.entries != 0x03)
  753. )
  754. UNEXPECTED_IO_APIC();
  755. printk(KERN_DEBUG "....... : PRQ implemented: %X\n", reg_01.bits.PRQ);
  756. printk(KERN_DEBUG "....... : IO APIC version: %04X\n", reg_01.bits.version);
  757. if ( (reg_01.bits.version != 0x01) && /* 82489DX IO-APICs */
  758. (reg_01.bits.version != 0x02) && /* 82801BA IO-APICs (ICH2) */
  759. (reg_01.bits.version != 0x10) && /* oldest IO-APICs */
  760. (reg_01.bits.version != 0x11) && /* Pentium/Pro IO-APICs */
  761. (reg_01.bits.version != 0x13) && /* Xeon IO-APICs */
  762. (reg_01.bits.version != 0x20) /* Intel P64H (82806 AA) */
  763. )
  764. UNEXPECTED_IO_APIC();
  765. if (reg_01.bits.__reserved_1 || reg_01.bits.__reserved_2)
  766. UNEXPECTED_IO_APIC();
  767. if (reg_01.bits.version >= 0x10) {
  768. printk(KERN_DEBUG ".... register #02: %08X\n", reg_02.raw);
  769. printk(KERN_DEBUG "....... : arbitration: %02X\n", reg_02.bits.arbitration);
  770. if (reg_02.bits.__reserved_1 || reg_02.bits.__reserved_2)
  771. UNEXPECTED_IO_APIC();
  772. }
  773. printk(KERN_DEBUG ".... IRQ redirection table:\n");
  774. printk(KERN_DEBUG " NR Log Phy Mask Trig IRR Pol"
  775. " Stat Dest Deli Vect: \n");
  776. for (i = 0; i <= reg_01.bits.entries; i++) {
  777. struct IO_APIC_route_entry entry;
  778. spin_lock_irqsave(&ioapic_lock, flags);
  779. *(((int *)&entry)+0) = io_apic_read(apic, 0x10+i*2);
  780. *(((int *)&entry)+1) = io_apic_read(apic, 0x11+i*2);
  781. spin_unlock_irqrestore(&ioapic_lock, flags);
  782. printk(KERN_DEBUG " %02x %03X %02X ",
  783. i,
  784. entry.dest.logical.logical_dest,
  785. entry.dest.physical.physical_dest
  786. );
  787. printk("%1d %1d %1d %1d %1d %1d %1d %02X\n",
  788. entry.mask,
  789. entry.trigger,
  790. entry.irr,
  791. entry.polarity,
  792. entry.delivery_status,
  793. entry.dest_mode,
  794. entry.delivery_mode,
  795. entry.vector
  796. );
  797. }
  798. }
  799. if (use_pci_vector())
  800. printk(KERN_INFO "Using vector-based indexing\n");
  801. printk(KERN_DEBUG "IRQ to pin mappings:\n");
  802. for (i = 0; i < NR_IRQS; i++) {
  803. struct irq_pin_list *entry = irq_2_pin + i;
  804. if (entry->pin < 0)
  805. continue;
  806. if (use_pci_vector() && !platform_legacy_irq(i))
  807. printk(KERN_DEBUG "IRQ%d ", IO_APIC_VECTOR(i));
  808. else
  809. printk(KERN_DEBUG "IRQ%d ", i);
  810. for (;;) {
  811. printk("-> %d:%d", entry->apic, entry->pin);
  812. if (!entry->next)
  813. break;
  814. entry = irq_2_pin + entry->next;
  815. }
  816. printk("\n");
  817. }
  818. printk(KERN_INFO ".................................... done.\n");
  819. return;
  820. }
  821. #if 0
  822. static __apicdebuginit void print_APIC_bitfield (int base)
  823. {
  824. unsigned int v;
  825. int i, j;
  826. if (apic_verbosity == APIC_QUIET)
  827. return;
  828. printk(KERN_DEBUG "0123456789abcdef0123456789abcdef\n" KERN_DEBUG);
  829. for (i = 0; i < 8; i++) {
  830. v = apic_read(base + i*0x10);
  831. for (j = 0; j < 32; j++) {
  832. if (v & (1<<j))
  833. printk("1");
  834. else
  835. printk("0");
  836. }
  837. printk("\n");
  838. }
  839. }
  840. void __apicdebuginit print_local_APIC(void * dummy)
  841. {
  842. unsigned int v, ver, maxlvt;
  843. if (apic_verbosity == APIC_QUIET)
  844. return;
  845. printk("\n" KERN_DEBUG "printing local APIC contents on CPU#%d/%d:\n",
  846. smp_processor_id(), hard_smp_processor_id());
  847. v = apic_read(APIC_ID);
  848. printk(KERN_INFO "... APIC ID: %08x (%01x)\n", v, GET_APIC_ID(v));
  849. v = apic_read(APIC_LVR);
  850. printk(KERN_INFO "... APIC VERSION: %08x\n", v);
  851. ver = GET_APIC_VERSION(v);
  852. maxlvt = get_maxlvt();
  853. v = apic_read(APIC_TASKPRI);
  854. printk(KERN_DEBUG "... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
  855. if (APIC_INTEGRATED(ver)) { /* !82489DX */
  856. v = apic_read(APIC_ARBPRI);
  857. printk(KERN_DEBUG "... APIC ARBPRI: %08x (%02x)\n", v,
  858. v & APIC_ARBPRI_MASK);
  859. v = apic_read(APIC_PROCPRI);
  860. printk(KERN_DEBUG "... APIC PROCPRI: %08x\n", v);
  861. }
  862. v = apic_read(APIC_EOI);
  863. printk(KERN_DEBUG "... APIC EOI: %08x\n", v);
  864. v = apic_read(APIC_RRR);
  865. printk(KERN_DEBUG "... APIC RRR: %08x\n", v);
  866. v = apic_read(APIC_LDR);
  867. printk(KERN_DEBUG "... APIC LDR: %08x\n", v);
  868. v = apic_read(APIC_DFR);
  869. printk(KERN_DEBUG "... APIC DFR: %08x\n", v);
  870. v = apic_read(APIC_SPIV);
  871. printk(KERN_DEBUG "... APIC SPIV: %08x\n", v);
  872. printk(KERN_DEBUG "... APIC ISR field:\n");
  873. print_APIC_bitfield(APIC_ISR);
  874. printk(KERN_DEBUG "... APIC TMR field:\n");
  875. print_APIC_bitfield(APIC_TMR);
  876. printk(KERN_DEBUG "... APIC IRR field:\n");
  877. print_APIC_bitfield(APIC_IRR);
  878. if (APIC_INTEGRATED(ver)) { /* !82489DX */
  879. if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */
  880. apic_write(APIC_ESR, 0);
  881. v = apic_read(APIC_ESR);
  882. printk(KERN_DEBUG "... APIC ESR: %08x\n", v);
  883. }
  884. v = apic_read(APIC_ICR);
  885. printk(KERN_DEBUG "... APIC ICR: %08x\n", v);
  886. v = apic_read(APIC_ICR2);
  887. printk(KERN_DEBUG "... APIC ICR2: %08x\n", v);
  888. v = apic_read(APIC_LVTT);
  889. printk(KERN_DEBUG "... APIC LVTT: %08x\n", v);
  890. if (maxlvt > 3) { /* PC is LVT#4. */
  891. v = apic_read(APIC_LVTPC);
  892. printk(KERN_DEBUG "... APIC LVTPC: %08x\n", v);
  893. }
  894. v = apic_read(APIC_LVT0);
  895. printk(KERN_DEBUG "... APIC LVT0: %08x\n", v);
  896. v = apic_read(APIC_LVT1);
  897. printk(KERN_DEBUG "... APIC LVT1: %08x\n", v);
  898. if (maxlvt > 2) { /* ERR is LVT#3. */
  899. v = apic_read(APIC_LVTERR);
  900. printk(KERN_DEBUG "... APIC LVTERR: %08x\n", v);
  901. }
  902. v = apic_read(APIC_TMICT);
  903. printk(KERN_DEBUG "... APIC TMICT: %08x\n", v);
  904. v = apic_read(APIC_TMCCT);
  905. printk(KERN_DEBUG "... APIC TMCCT: %08x\n", v);
  906. v = apic_read(APIC_TDCR);
  907. printk(KERN_DEBUG "... APIC TDCR: %08x\n", v);
  908. printk("\n");
  909. }
  910. void print_all_local_APICs (void)
  911. {
  912. on_each_cpu(print_local_APIC, NULL, 1, 1);
  913. }
  914. void __apicdebuginit print_PIC(void)
  915. {
  916. extern spinlock_t i8259A_lock;
  917. unsigned int v;
  918. unsigned long flags;
  919. if (apic_verbosity == APIC_QUIET)
  920. return;
  921. printk(KERN_DEBUG "\nprinting PIC contents\n");
  922. spin_lock_irqsave(&i8259A_lock, flags);
  923. v = inb(0xa1) << 8 | inb(0x21);
  924. printk(KERN_DEBUG "... PIC IMR: %04x\n", v);
  925. v = inb(0xa0) << 8 | inb(0x20);
  926. printk(KERN_DEBUG "... PIC IRR: %04x\n", v);
  927. outb(0x0b,0xa0);
  928. outb(0x0b,0x20);
  929. v = inb(0xa0) << 8 | inb(0x20);
  930. outb(0x0a,0xa0);
  931. outb(0x0a,0x20);
  932. spin_unlock_irqrestore(&i8259A_lock, flags);
  933. printk(KERN_DEBUG "... PIC ISR: %04x\n", v);
  934. v = inb(0x4d1) << 8 | inb(0x4d0);
  935. printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
  936. }
  937. #endif /* 0 */
  938. static void __init enable_IO_APIC(void)
  939. {
  940. union IO_APIC_reg_01 reg_01;
  941. int i;
  942. unsigned long flags;
  943. for (i = 0; i < PIN_MAP_SIZE; i++) {
  944. irq_2_pin[i].pin = -1;
  945. irq_2_pin[i].next = 0;
  946. }
  947. if (!pirqs_enabled)
  948. for (i = 0; i < MAX_PIRQS; i++)
  949. pirq_entries[i] = -1;
  950. /*
  951. * The number of IO-APIC IRQ registers (== #pins):
  952. */
  953. for (i = 0; i < nr_ioapics; i++) {
  954. spin_lock_irqsave(&ioapic_lock, flags);
  955. reg_01.raw = io_apic_read(i, 1);
  956. spin_unlock_irqrestore(&ioapic_lock, flags);
  957. nr_ioapic_registers[i] = reg_01.bits.entries+1;
  958. }
  959. /*
  960. * Do not trust the IO-APIC being empty at bootup
  961. */
  962. clear_IO_APIC();
  963. }
  964. /*
  965. * Not an __init, needed by the reboot code
  966. */
  967. void disable_IO_APIC(void)
  968. {
  969. /*
  970. * Clear the IO-APIC before rebooting:
  971. */
  972. clear_IO_APIC();
  973. disconnect_bsp_APIC();
  974. }
  975. /*
  976. * function to set the IO-APIC physical IDs based on the
  977. * values stored in the MPC table.
  978. *
  979. * by Matt Domsch <Matt_Domsch@dell.com> Tue Dec 21 12:25:05 CST 1999
  980. */
  981. static void __init setup_ioapic_ids_from_mpc (void)
  982. {
  983. union IO_APIC_reg_00 reg_00;
  984. int apic;
  985. int i;
  986. unsigned char old_id;
  987. unsigned long flags;
  988. /*
  989. * Set the IOAPIC ID to the value stored in the MPC table.
  990. */
  991. for (apic = 0; apic < nr_ioapics; apic++) {
  992. /* Read the register 0 value */
  993. spin_lock_irqsave(&ioapic_lock, flags);
  994. reg_00.raw = io_apic_read(apic, 0);
  995. spin_unlock_irqrestore(&ioapic_lock, flags);
  996. old_id = mp_ioapics[apic].mpc_apicid;
  997. printk(KERN_INFO "Using IO-APIC %d\n", mp_ioapics[apic].mpc_apicid);
  998. /*
  999. * We need to adjust the IRQ routing table
  1000. * if the ID changed.
  1001. */
  1002. if (old_id != mp_ioapics[apic].mpc_apicid)
  1003. for (i = 0; i < mp_irq_entries; i++)
  1004. if (mp_irqs[i].mpc_dstapic == old_id)
  1005. mp_irqs[i].mpc_dstapic
  1006. = mp_ioapics[apic].mpc_apicid;
  1007. /*
  1008. * Read the right value from the MPC table and
  1009. * write it into the ID register.
  1010. */
  1011. apic_printk(APIC_VERBOSE,KERN_INFO "...changing IO-APIC physical APIC ID to %d ...",
  1012. mp_ioapics[apic].mpc_apicid);
  1013. reg_00.bits.ID = mp_ioapics[apic].mpc_apicid;
  1014. spin_lock_irqsave(&ioapic_lock, flags);
  1015. io_apic_write(apic, 0, reg_00.raw);
  1016. spin_unlock_irqrestore(&ioapic_lock, flags);
  1017. /*
  1018. * Sanity check
  1019. */
  1020. spin_lock_irqsave(&ioapic_lock, flags);
  1021. reg_00.raw = io_apic_read(apic, 0);
  1022. spin_unlock_irqrestore(&ioapic_lock, flags);
  1023. if (reg_00.bits.ID != mp_ioapics[apic].mpc_apicid)
  1024. printk("could not set ID!\n");
  1025. else
  1026. apic_printk(APIC_VERBOSE," ok.\n");
  1027. }
  1028. }
  1029. /*
  1030. * There is a nasty bug in some older SMP boards, their mptable lies
  1031. * about the timer IRQ. We do the following to work around the situation:
  1032. *
  1033. * - timer IRQ defaults to IO-APIC IRQ
  1034. * - if this function detects that timer IRQs are defunct, then we fall
  1035. * back to ISA timer IRQs
  1036. */
  1037. static int __init timer_irq_works(void)
  1038. {
  1039. unsigned long t1 = jiffies;
  1040. local_irq_enable();
  1041. /* Let ten ticks pass... */
  1042. mdelay((10 * 1000) / HZ);
  1043. /*
  1044. * Expect a few ticks at least, to be sure some possible
  1045. * glue logic does not lock up after one or two first
  1046. * ticks in a non-ExtINT mode. Also the local APIC
  1047. * might have cached one ExtINT interrupt. Finally, at
  1048. * least one tick may be lost due to delays.
  1049. */
  1050. /* jiffies wrap? */
  1051. if (jiffies - t1 > 4)
  1052. return 1;
  1053. return 0;
  1054. }
  1055. /*
  1056. * In the SMP+IOAPIC case it might happen that there are an unspecified
  1057. * number of pending IRQ events unhandled. These cases are very rare,
  1058. * so we 'resend' these IRQs via IPIs, to the same CPU. It's much
  1059. * better to do it this way as thus we do not have to be aware of
  1060. * 'pending' interrupts in the IRQ path, except at this point.
  1061. */
  1062. /*
  1063. * Edge triggered needs to resend any interrupt
  1064. * that was delayed but this is now handled in the device
  1065. * independent code.
  1066. */
  1067. /*
  1068. * Starting up a edge-triggered IO-APIC interrupt is
  1069. * nasty - we need to make sure that we get the edge.
  1070. * If it is already asserted for some reason, we need
  1071. * return 1 to indicate that is was pending.
  1072. *
  1073. * This is not complete - we should be able to fake
  1074. * an edge even if it isn't on the 8259A...
  1075. */
  1076. static unsigned int startup_edge_ioapic_irq(unsigned int irq)
  1077. {
  1078. int was_pending = 0;
  1079. unsigned long flags;
  1080. spin_lock_irqsave(&ioapic_lock, flags);
  1081. if (irq < 16) {
  1082. disable_8259A_irq(irq);
  1083. if (i8259A_irq_pending(irq))
  1084. was_pending = 1;
  1085. }
  1086. __unmask_IO_APIC_irq(irq);
  1087. spin_unlock_irqrestore(&ioapic_lock, flags);
  1088. return was_pending;
  1089. }
  1090. /*
  1091. * Once we have recorded IRQ_PENDING already, we can mask the
  1092. * interrupt for real. This prevents IRQ storms from unhandled
  1093. * devices.
  1094. */
  1095. static void ack_edge_ioapic_irq(unsigned int irq)
  1096. {
  1097. if ((irq_desc[irq].status & (IRQ_PENDING | IRQ_DISABLED))
  1098. == (IRQ_PENDING | IRQ_DISABLED))
  1099. mask_IO_APIC_irq(irq);
  1100. ack_APIC_irq();
  1101. }
  1102. /*
  1103. * Level triggered interrupts can just be masked,
  1104. * and shutting down and starting up the interrupt
  1105. * is the same as enabling and disabling them -- except
  1106. * with a startup need to return a "was pending" value.
  1107. *
  1108. * Level triggered interrupts are special because we
  1109. * do not touch any IO-APIC register while handling
  1110. * them. We ack the APIC in the end-IRQ handler, not
  1111. * in the start-IRQ-handler. Protection against reentrance
  1112. * from the same interrupt is still provided, both by the
  1113. * generic IRQ layer and by the fact that an unacked local
  1114. * APIC does not accept IRQs.
  1115. */
  1116. static unsigned int startup_level_ioapic_irq (unsigned int irq)
  1117. {
  1118. unmask_IO_APIC_irq(irq);
  1119. return 0; /* don't check for pending */
  1120. }
  1121. static void end_level_ioapic_irq (unsigned int irq)
  1122. {
  1123. ack_APIC_irq();
  1124. }
  1125. static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t mask)
  1126. {
  1127. unsigned long flags;
  1128. unsigned int dest;
  1129. dest = cpu_mask_to_apicid(mask);
  1130. /*
  1131. * Only the high 8 bits are valid.
  1132. */
  1133. dest = SET_APIC_LOGICAL_ID(dest);
  1134. spin_lock_irqsave(&ioapic_lock, flags);
  1135. __DO_ACTION(1, = dest, )
  1136. spin_unlock_irqrestore(&ioapic_lock, flags);
  1137. }
  1138. #ifdef CONFIG_PCI_MSI
  1139. static unsigned int startup_edge_ioapic_vector(unsigned int vector)
  1140. {
  1141. int irq = vector_to_irq(vector);
  1142. return startup_edge_ioapic_irq(irq);
  1143. }
  1144. static void ack_edge_ioapic_vector(unsigned int vector)
  1145. {
  1146. int irq = vector_to_irq(vector);
  1147. ack_edge_ioapic_irq(irq);
  1148. }
  1149. static unsigned int startup_level_ioapic_vector (unsigned int vector)
  1150. {
  1151. int irq = vector_to_irq(vector);
  1152. return startup_level_ioapic_irq (irq);
  1153. }
  1154. static void end_level_ioapic_vector (unsigned int vector)
  1155. {
  1156. int irq = vector_to_irq(vector);
  1157. end_level_ioapic_irq(irq);
  1158. }
  1159. static void mask_IO_APIC_vector (unsigned int vector)
  1160. {
  1161. int irq = vector_to_irq(vector);
  1162. mask_IO_APIC_irq(irq);
  1163. }
  1164. static void unmask_IO_APIC_vector (unsigned int vector)
  1165. {
  1166. int irq = vector_to_irq(vector);
  1167. unmask_IO_APIC_irq(irq);
  1168. }
  1169. static void set_ioapic_affinity_vector (unsigned int vector,
  1170. cpumask_t cpu_mask)
  1171. {
  1172. int irq = vector_to_irq(vector);
  1173. set_ioapic_affinity_irq(irq, cpu_mask);
  1174. }
  1175. #endif
  1176. /*
  1177. * Level and edge triggered IO-APIC interrupts need different handling,
  1178. * so we use two separate IRQ descriptors. Edge triggered IRQs can be
  1179. * handled with the level-triggered descriptor, but that one has slightly
  1180. * more overhead. Level-triggered interrupts cannot be handled with the
  1181. * edge-triggered handler, without risking IRQ storms and other ugly
  1182. * races.
  1183. */
  1184. static struct hw_interrupt_type ioapic_edge_type = {
  1185. .typename = "IO-APIC-edge",
  1186. .startup = startup_edge_ioapic,
  1187. .shutdown = shutdown_edge_ioapic,
  1188. .enable = enable_edge_ioapic,
  1189. .disable = disable_edge_ioapic,
  1190. .ack = ack_edge_ioapic,
  1191. .end = end_edge_ioapic,
  1192. .set_affinity = set_ioapic_affinity,
  1193. };
  1194. static struct hw_interrupt_type ioapic_level_type = {
  1195. .typename = "IO-APIC-level",
  1196. .startup = startup_level_ioapic,
  1197. .shutdown = shutdown_level_ioapic,
  1198. .enable = enable_level_ioapic,
  1199. .disable = disable_level_ioapic,
  1200. .ack = mask_and_ack_level_ioapic,
  1201. .end = end_level_ioapic,
  1202. .set_affinity = set_ioapic_affinity,
  1203. };
  1204. static inline void init_IO_APIC_traps(void)
  1205. {
  1206. int irq;
  1207. /*
  1208. * NOTE! The local APIC isn't very good at handling
  1209. * multiple interrupts at the same interrupt level.
  1210. * As the interrupt level is determined by taking the
  1211. * vector number and shifting that right by 4, we
  1212. * want to spread these out a bit so that they don't
  1213. * all fall in the same interrupt level.
  1214. *
  1215. * Also, we've got to be careful not to trash gate
  1216. * 0x80, because int 0x80 is hm, kind of importantish. ;)
  1217. */
  1218. for (irq = 0; irq < NR_IRQS ; irq++) {
  1219. int tmp = irq;
  1220. if (use_pci_vector()) {
  1221. if (!platform_legacy_irq(tmp))
  1222. if ((tmp = vector_to_irq(tmp)) == -1)
  1223. continue;
  1224. }
  1225. if (IO_APIC_IRQ(tmp) && !IO_APIC_VECTOR(tmp)) {
  1226. /*
  1227. * Hmm.. We don't have an entry for this,
  1228. * so default to an old-fashioned 8259
  1229. * interrupt if we can..
  1230. */
  1231. if (irq < 16)
  1232. make_8259A_irq(irq);
  1233. else
  1234. /* Strange. Oh, well.. */
  1235. irq_desc[irq].handler = &no_irq_type;
  1236. }
  1237. }
  1238. }
  1239. static void enable_lapic_irq (unsigned int irq)
  1240. {
  1241. unsigned long v;
  1242. v = apic_read(APIC_LVT0);
  1243. apic_write_around(APIC_LVT0, v & ~APIC_LVT_MASKED);
  1244. }
  1245. static void disable_lapic_irq (unsigned int irq)
  1246. {
  1247. unsigned long v;
  1248. v = apic_read(APIC_LVT0);
  1249. apic_write_around(APIC_LVT0, v | APIC_LVT_MASKED);
  1250. }
  1251. static void ack_lapic_irq (unsigned int irq)
  1252. {
  1253. ack_APIC_irq();
  1254. }
  1255. static void end_lapic_irq (unsigned int i) { /* nothing */ }
  1256. static struct hw_interrupt_type lapic_irq_type = {
  1257. .typename = "local-APIC-edge",
  1258. .startup = NULL, /* startup_irq() not used for IRQ0 */
  1259. .shutdown = NULL, /* shutdown_irq() not used for IRQ0 */
  1260. .enable = enable_lapic_irq,
  1261. .disable = disable_lapic_irq,
  1262. .ack = ack_lapic_irq,
  1263. .end = end_lapic_irq,
  1264. };
  1265. static void setup_nmi (void)
  1266. {
  1267. /*
  1268. * Dirty trick to enable the NMI watchdog ...
  1269. * We put the 8259A master into AEOI mode and
  1270. * unmask on all local APICs LVT0 as NMI.
  1271. *
  1272. * The idea to use the 8259A in AEOI mode ('8259A Virtual Wire')
  1273. * is from Maciej W. Rozycki - so we do not have to EOI from
  1274. * the NMI handler or the timer interrupt.
  1275. */
  1276. printk(KERN_INFO "activating NMI Watchdog ...");
  1277. enable_NMI_through_LVT0(NULL);
  1278. printk(" done.\n");
  1279. }
  1280. /*
  1281. * This looks a bit hackish but it's about the only one way of sending
  1282. * a few INTA cycles to 8259As and any associated glue logic. ICR does
  1283. * not support the ExtINT mode, unfortunately. We need to send these
  1284. * cycles as some i82489DX-based boards have glue logic that keeps the
  1285. * 8259A interrupt line asserted until INTA. --macro
  1286. */
  1287. static inline void unlock_ExtINT_logic(void)
  1288. {
  1289. int pin, i;
  1290. struct IO_APIC_route_entry entry0, entry1;
  1291. unsigned char save_control, save_freq_select;
  1292. unsigned long flags;
  1293. pin = find_isa_irq_pin(8, mp_INT);
  1294. if (pin == -1)
  1295. return;
  1296. spin_lock_irqsave(&ioapic_lock, flags);
  1297. *(((int *)&entry0) + 1) = io_apic_read(0, 0x11 + 2 * pin);
  1298. *(((int *)&entry0) + 0) = io_apic_read(0, 0x10 + 2 * pin);
  1299. spin_unlock_irqrestore(&ioapic_lock, flags);
  1300. clear_IO_APIC_pin(0, pin);
  1301. memset(&entry1, 0, sizeof(entry1));
  1302. entry1.dest_mode = 0; /* physical delivery */
  1303. entry1.mask = 0; /* unmask IRQ now */
  1304. entry1.dest.physical.physical_dest = hard_smp_processor_id();
  1305. entry1.delivery_mode = dest_ExtINT;
  1306. entry1.polarity = entry0.polarity;
  1307. entry1.trigger = 0;
  1308. entry1.vector = 0;
  1309. spin_lock_irqsave(&ioapic_lock, flags);
  1310. io_apic_write(0, 0x11 + 2 * pin, *(((int *)&entry1) + 1));
  1311. io_apic_write(0, 0x10 + 2 * pin, *(((int *)&entry1) + 0));
  1312. spin_unlock_irqrestore(&ioapic_lock, flags);
  1313. save_control = CMOS_READ(RTC_CONTROL);
  1314. save_freq_select = CMOS_READ(RTC_FREQ_SELECT);
  1315. CMOS_WRITE((save_freq_select & ~RTC_RATE_SELECT) | 0x6,
  1316. RTC_FREQ_SELECT);
  1317. CMOS_WRITE(save_control | RTC_PIE, RTC_CONTROL);
  1318. i = 100;
  1319. while (i-- > 0) {
  1320. mdelay(10);
  1321. if ((CMOS_READ(RTC_INTR_FLAGS) & RTC_PF) == RTC_PF)
  1322. i -= 10;
  1323. }
  1324. CMOS_WRITE(save_control, RTC_CONTROL);
  1325. CMOS_WRITE(save_freq_select, RTC_FREQ_SELECT);
  1326. clear_IO_APIC_pin(0, pin);
  1327. spin_lock_irqsave(&ioapic_lock, flags);
  1328. io_apic_write(0, 0x11 + 2 * pin, *(((int *)&entry0) + 1));
  1329. io_apic_write(0, 0x10 + 2 * pin, *(((int *)&entry0) + 0));
  1330. spin_unlock_irqrestore(&ioapic_lock, flags);
  1331. }
  1332. /*
  1333. * This code may look a bit paranoid, but it's supposed to cooperate with
  1334. * a wide range of boards and BIOS bugs. Fortunately only the timer IRQ
  1335. * is so screwy. Thanks to Brian Perkins for testing/hacking this beast
  1336. * fanatically on his truly buggy board.
  1337. */
  1338. static inline void check_timer(void)
  1339. {
  1340. int pin1, pin2;
  1341. int vector;
  1342. /*
  1343. * get/set the timer IRQ vector:
  1344. */
  1345. disable_8259A_irq(0);
  1346. vector = assign_irq_vector(0);
  1347. set_intr_gate(vector, interrupt[0]);
  1348. /*
  1349. * Subtle, code in do_timer_interrupt() expects an AEOI
  1350. * mode for the 8259A whenever interrupts are routed
  1351. * through I/O APICs. Also IRQ0 has to be enabled in
  1352. * the 8259A which implies the virtual wire has to be
  1353. * disabled in the local APIC.
  1354. */
  1355. apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_EXTINT);
  1356. init_8259A(1);
  1357. enable_8259A_irq(0);
  1358. pin1 = find_isa_irq_pin(0, mp_INT);
  1359. pin2 = find_isa_irq_pin(0, mp_ExtINT);
  1360. apic_printk(APIC_VERBOSE,KERN_INFO "..TIMER: vector=0x%02X pin1=%d pin2=%d\n", vector, pin1, pin2);
  1361. if (pin1 != -1) {
  1362. /*
  1363. * Ok, does IRQ0 through the IOAPIC work?
  1364. */
  1365. unmask_IO_APIC_irq(0);
  1366. if (timer_irq_works()) {
  1367. nmi_watchdog_default();
  1368. if (nmi_watchdog == NMI_IO_APIC) {
  1369. disable_8259A_irq(0);
  1370. setup_nmi();
  1371. enable_8259A_irq(0);
  1372. check_nmi_watchdog();
  1373. }
  1374. return;
  1375. }
  1376. clear_IO_APIC_pin(0, pin1);
  1377. apic_printk(APIC_QUIET,KERN_ERR "..MP-BIOS bug: 8254 timer not connected to IO-APIC\n");
  1378. }
  1379. apic_printk(APIC_VERBOSE,KERN_INFO "...trying to set up timer (IRQ0) through the 8259A ... ");
  1380. if (pin2 != -1) {
  1381. apic_printk(APIC_VERBOSE,"\n..... (found pin %d) ...", pin2);
  1382. /*
  1383. * legacy devices should be connected to IO APIC #0
  1384. */
  1385. setup_ExtINT_IRQ0_pin(pin2, vector);
  1386. if (timer_irq_works()) {
  1387. printk("works.\n");
  1388. nmi_watchdog_default();
  1389. if (nmi_watchdog == NMI_IO_APIC) {
  1390. setup_nmi();
  1391. check_nmi_watchdog();
  1392. }
  1393. return;
  1394. }
  1395. /*
  1396. * Cleanup, just in case ...
  1397. */
  1398. clear_IO_APIC_pin(0, pin2);
  1399. }
  1400. printk(" failed.\n");
  1401. if (nmi_watchdog) {
  1402. printk(KERN_WARNING "timer doesn't work through the IO-APIC - disabling NMI Watchdog!\n");
  1403. nmi_watchdog = 0;
  1404. }
  1405. apic_printk(APIC_VERBOSE, KERN_INFO "...trying to set up timer as Virtual Wire IRQ...");
  1406. disable_8259A_irq(0);
  1407. irq_desc[0].handler = &lapic_irq_type;
  1408. apic_write_around(APIC_LVT0, APIC_DM_FIXED | vector); /* Fixed mode */
  1409. enable_8259A_irq(0);
  1410. if (timer_irq_works()) {
  1411. apic_printk(APIC_QUIET, " works.\n");
  1412. return;
  1413. }
  1414. apic_write_around(APIC_LVT0, APIC_LVT_MASKED | APIC_DM_FIXED | vector);
  1415. apic_printk(APIC_VERBOSE," failed.\n");
  1416. apic_printk(APIC_VERBOSE, KERN_INFO "...trying to set up timer as ExtINT IRQ...");
  1417. init_8259A(0);
  1418. make_8259A_irq(0);
  1419. apic_write_around(APIC_LVT0, APIC_DM_EXTINT);
  1420. unlock_ExtINT_logic();
  1421. if (timer_irq_works()) {
  1422. apic_printk(APIC_VERBOSE," works.\n");
  1423. return;
  1424. }
  1425. apic_printk(APIC_VERBOSE," failed :(.\n");
  1426. panic("IO-APIC + timer doesn't work! Try using the 'noapic' kernel parameter\n");
  1427. }
  1428. /*
  1429. *
  1430. * IRQ's that are handled by the PIC in the MPS IOAPIC case.
  1431. * - IRQ2 is the cascade IRQ, and cannot be a io-apic IRQ.
  1432. * Linux doesn't really care, as it's not actually used
  1433. * for any interrupt handling anyway.
  1434. */
  1435. #define PIC_IRQS (1<<2)
  1436. void __init setup_IO_APIC(void)
  1437. {
  1438. enable_IO_APIC();
  1439. if (acpi_ioapic)
  1440. io_apic_irqs = ~0; /* all IRQs go through IOAPIC */
  1441. else
  1442. io_apic_irqs = ~PIC_IRQS;
  1443. apic_printk(APIC_VERBOSE, "ENABLING IO-APIC IRQs\n");
  1444. /*
  1445. * Set up the IO-APIC IRQ routing table.
  1446. */
  1447. if (!acpi_ioapic)
  1448. setup_ioapic_ids_from_mpc();
  1449. sync_Arb_IDs();
  1450. setup_IO_APIC_irqs();
  1451. init_IO_APIC_traps();
  1452. check_timer();
  1453. if (!acpi_ioapic)
  1454. print_IO_APIC();
  1455. }
  1456. struct sysfs_ioapic_data {
  1457. struct sys_device dev;
  1458. struct IO_APIC_route_entry entry[0];
  1459. };
  1460. static struct sysfs_ioapic_data * mp_ioapic_data[MAX_IO_APICS];
  1461. static int ioapic_suspend(struct sys_device *dev, u32 state)
  1462. {
  1463. struct IO_APIC_route_entry *entry;
  1464. struct sysfs_ioapic_data *data;
  1465. unsigned long flags;
  1466. int i;
  1467. data = container_of(dev, struct sysfs_ioapic_data, dev);
  1468. entry = data->entry;
  1469. spin_lock_irqsave(&ioapic_lock, flags);
  1470. for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ ) {
  1471. *(((int *)entry) + 1) = io_apic_read(dev->id, 0x11 + 2 * i);
  1472. *(((int *)entry) + 0) = io_apic_read(dev->id, 0x10 + 2 * i);
  1473. }
  1474. spin_unlock_irqrestore(&ioapic_lock, flags);
  1475. return 0;
  1476. }
  1477. static int ioapic_resume(struct sys_device *dev)
  1478. {
  1479. struct IO_APIC_route_entry *entry;
  1480. struct sysfs_ioapic_data *data;
  1481. unsigned long flags;
  1482. union IO_APIC_reg_00 reg_00;
  1483. int i;
  1484. data = container_of(dev, struct sysfs_ioapic_data, dev);
  1485. entry = data->entry;
  1486. spin_lock_irqsave(&ioapic_lock, flags);
  1487. reg_00.raw = io_apic_read(dev->id, 0);
  1488. if (reg_00.bits.ID != mp_ioapics[dev->id].mpc_apicid) {
  1489. reg_00.bits.ID = mp_ioapics[dev->id].mpc_apicid;
  1490. io_apic_write(dev->id, 0, reg_00.raw);
  1491. }
  1492. for (i = 0; i < nr_ioapic_registers[dev->id]; i ++, entry ++ ) {
  1493. io_apic_write(dev->id, 0x11+2*i, *(((int *)entry)+1));
  1494. io_apic_write(dev->id, 0x10+2*i, *(((int *)entry)+0));
  1495. }
  1496. spin_unlock_irqrestore(&ioapic_lock, flags);
  1497. return 0;
  1498. }
  1499. static struct sysdev_class ioapic_sysdev_class = {
  1500. set_kset_name("ioapic"),
  1501. .suspend = ioapic_suspend,
  1502. .resume = ioapic_resume,
  1503. };
  1504. static int __init ioapic_init_sysfs(void)
  1505. {
  1506. struct sys_device * dev;
  1507. int i, size, error = 0;
  1508. error = sysdev_class_register(&ioapic_sysdev_class);
  1509. if (error)
  1510. return error;
  1511. for (i = 0; i < nr_ioapics; i++ ) {
  1512. size = sizeof(struct sys_device) + nr_ioapic_registers[i]
  1513. * sizeof(struct IO_APIC_route_entry);
  1514. mp_ioapic_data[i] = kmalloc(size, GFP_KERNEL);
  1515. if (!mp_ioapic_data[i]) {
  1516. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  1517. continue;
  1518. }
  1519. memset(mp_ioapic_data[i], 0, size);
  1520. dev = &mp_ioapic_data[i]->dev;
  1521. dev->id = i;
  1522. dev->cls = &ioapic_sysdev_class;
  1523. error = sysdev_register(dev);
  1524. if (error) {
  1525. kfree(mp_ioapic_data[i]);
  1526. mp_ioapic_data[i] = NULL;
  1527. printk(KERN_ERR "Can't suspend/resume IOAPIC %d\n", i);
  1528. continue;
  1529. }
  1530. }
  1531. return 0;
  1532. }
  1533. device_initcall(ioapic_init_sysfs);
  1534. /* --------------------------------------------------------------------------
  1535. ACPI-based IOAPIC Configuration
  1536. -------------------------------------------------------------------------- */
  1537. #ifdef CONFIG_ACPI_BOOT
  1538. #define IO_APIC_MAX_ID 0xFE
  1539. int __init io_apic_get_unique_id (int ioapic, int apic_id)
  1540. {
  1541. union IO_APIC_reg_00 reg_00;
  1542. static physid_mask_t apic_id_map;
  1543. unsigned long flags;
  1544. int i = 0;
  1545. /*
  1546. * The P4 platform supports up to 256 APIC IDs on two separate APIC
  1547. * buses (one for LAPICs, one for IOAPICs), where predecessors only
  1548. * supports up to 16 on one shared APIC bus.
  1549. *
  1550. * TBD: Expand LAPIC/IOAPIC support on P4-class systems to take full
  1551. * advantage of new APIC bus architecture.
  1552. */
  1553. if (physids_empty(apic_id_map))
  1554. apic_id_map = phys_cpu_present_map;
  1555. spin_lock_irqsave(&ioapic_lock, flags);
  1556. reg_00.raw = io_apic_read(ioapic, 0);
  1557. spin_unlock_irqrestore(&ioapic_lock, flags);
  1558. if (apic_id >= IO_APIC_MAX_ID) {
  1559. apic_printk(APIC_QUIET, KERN_WARNING "IOAPIC[%d]: Invalid apic_id %d, trying "
  1560. "%d\n", ioapic, apic_id, reg_00.bits.ID);
  1561. apic_id = reg_00.bits.ID;
  1562. }
  1563. /*
  1564. * Every APIC in a system must have a unique ID or we get lots of nice
  1565. * 'stuck on smp_invalidate_needed IPI wait' messages.
  1566. */
  1567. if (physid_isset(apic_id, apic_id_map)) {
  1568. for (i = 0; i < IO_APIC_MAX_ID; i++) {
  1569. if (!physid_isset(i, apic_id_map))
  1570. break;
  1571. }
  1572. if (i == IO_APIC_MAX_ID)
  1573. panic("Max apic_id exceeded!\n");
  1574. apic_printk(APIC_VERBOSE, KERN_WARNING "IOAPIC[%d]: apic_id %d already used, "
  1575. "trying %d\n", ioapic, apic_id, i);
  1576. apic_id = i;
  1577. }
  1578. physid_set(apic_id, apic_id_map);
  1579. if (reg_00.bits.ID != apic_id) {
  1580. reg_00.bits.ID = apic_id;
  1581. spin_lock_irqsave(&ioapic_lock, flags);
  1582. io_apic_write(ioapic, 0, reg_00.raw);
  1583. reg_00.raw = io_apic_read(ioapic, 0);
  1584. spin_unlock_irqrestore(&ioapic_lock, flags);
  1585. /* Sanity check */
  1586. if (reg_00.bits.ID != apic_id)
  1587. panic("IOAPIC[%d]: Unable change apic_id!\n", ioapic);
  1588. }
  1589. apic_printk(APIC_VERBOSE,KERN_INFO "IOAPIC[%d]: Assigned apic_id %d\n", ioapic, apic_id);
  1590. return apic_id;
  1591. }
  1592. int __init io_apic_get_version (int ioapic)
  1593. {
  1594. union IO_APIC_reg_01 reg_01;
  1595. unsigned long flags;
  1596. spin_lock_irqsave(&ioapic_lock, flags);
  1597. reg_01.raw = io_apic_read(ioapic, 1);
  1598. spin_unlock_irqrestore(&ioapic_lock, flags);
  1599. return reg_01.bits.version;
  1600. }
  1601. int __init io_apic_get_redir_entries (int ioapic)
  1602. {
  1603. union IO_APIC_reg_01 reg_01;
  1604. unsigned long flags;
  1605. spin_lock_irqsave(&ioapic_lock, flags);
  1606. reg_01.raw = io_apic_read(ioapic, 1);
  1607. spin_unlock_irqrestore(&ioapic_lock, flags);
  1608. return reg_01.bits.entries;
  1609. }
  1610. int io_apic_set_pci_routing (int ioapic, int pin, int irq, int edge_level, int active_high_low)
  1611. {
  1612. struct IO_APIC_route_entry entry;
  1613. unsigned long flags;
  1614. if (!IO_APIC_IRQ(irq)) {
  1615. apic_printk(APIC_QUIET,KERN_ERR "IOAPIC[%d]: Invalid reference to IRQ 0\n",
  1616. ioapic);
  1617. return -EINVAL;
  1618. }
  1619. /*
  1620. * Generate a PCI IRQ routing entry and program the IOAPIC accordingly.
  1621. * Note that we mask (disable) IRQs now -- these get enabled when the
  1622. * corresponding device driver registers for this IRQ.
  1623. */
  1624. memset(&entry,0,sizeof(entry));
  1625. entry.delivery_mode = INT_DELIVERY_MODE;
  1626. entry.dest_mode = INT_DEST_MODE;
  1627. entry.dest.logical.logical_dest = cpu_mask_to_apicid(TARGET_CPUS);
  1628. entry.trigger = edge_level;
  1629. entry.polarity = active_high_low;
  1630. entry.mask = 1; /* Disabled (masked) */
  1631. /*
  1632. * IRQs < 16 are already in the irq_2_pin[] map
  1633. */
  1634. if (irq >= 16)
  1635. add_pin_to_irq(irq, ioapic, pin);
  1636. entry.vector = assign_irq_vector(irq);
  1637. apic_printk(APIC_VERBOSE,KERN_DEBUG "IOAPIC[%d]: Set PCI routing entry (%d-%d -> 0x%x -> "
  1638. "IRQ %d Mode:%i Active:%i)\n", ioapic,
  1639. mp_ioapics[ioapic].mpc_apicid, pin, entry.vector, irq,
  1640. edge_level, active_high_low);
  1641. ioapic_register_intr(irq, entry.vector, edge_level);
  1642. if (!ioapic && (irq < 16))
  1643. disable_8259A_irq(irq);
  1644. spin_lock_irqsave(&ioapic_lock, flags);
  1645. io_apic_write(ioapic, 0x11+2*pin, *(((int *)&entry)+1));
  1646. io_apic_write(ioapic, 0x10+2*pin, *(((int *)&entry)+0));
  1647. spin_unlock_irqrestore(&ioapic_lock, flags);
  1648. return 0;
  1649. }
  1650. #endif /*CONFIG_ACPI_BOOT*/
  1651. /*
  1652. * This function currently is only a helper for the i386 smp boot process where
  1653. * we need to reprogram the ioredtbls to cater for the cpus which have come online
  1654. * so mask in all cases should simply be TARGET_CPUS
  1655. */
  1656. void __init setup_ioapic_dest(void)
  1657. {
  1658. int pin, ioapic, irq, irq_entry;
  1659. if (skip_ioapic_setup == 1)
  1660. return;
  1661. for (ioapic = 0; ioapic < nr_ioapics; ioapic++) {
  1662. for (pin = 0; pin < nr_ioapic_registers[ioapic]; pin++) {
  1663. irq_entry = find_irq_entry(ioapic, pin, mp_INT);
  1664. if (irq_entry == -1)
  1665. continue;
  1666. irq = pin_2_irq(irq_entry, ioapic, pin);
  1667. set_ioapic_affinity_irq(irq, TARGET_CPUS);
  1668. }
  1669. }
  1670. }