vector.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. /*
  2. * Local APIC related interfaces to support IOAPIC, MSI, HT_IRQ etc.
  3. *
  4. * Copyright (C) 1997, 1998, 1999, 2000, 2009 Ingo Molnar, Hajnalka Szabo
  5. * Moved from arch/x86/kernel/apic/io_apic.c.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/interrupt.h>
  12. #include <linux/init.h>
  13. #include <linux/compiler.h>
  14. #include <linux/irqdomain.h>
  15. #include <linux/slab.h>
  16. #include <asm/hw_irq.h>
  17. #include <asm/apic.h>
  18. #include <asm/i8259.h>
  19. #include <asm/desc.h>
  20. #include <asm/irq_remapping.h>
  21. static DEFINE_RAW_SPINLOCK(vector_lock);
  22. void lock_vector_lock(void)
  23. {
  24. /* Used to the online set of cpus does not change
  25. * during assign_irq_vector.
  26. */
  27. raw_spin_lock(&vector_lock);
  28. }
  29. void unlock_vector_lock(void)
  30. {
  31. raw_spin_unlock(&vector_lock);
  32. }
  33. struct irq_cfg *irq_cfg(unsigned int irq)
  34. {
  35. return irq_get_chip_data(irq);
  36. }
  37. struct irq_cfg *irqd_cfg(struct irq_data *irq_data)
  38. {
  39. return irq_data->chip_data;
  40. }
  41. static struct irq_cfg *alloc_irq_cfg(unsigned int irq, int node)
  42. {
  43. struct irq_cfg *cfg;
  44. cfg = kzalloc_node(sizeof(*cfg), GFP_KERNEL, node);
  45. if (!cfg)
  46. return NULL;
  47. if (!zalloc_cpumask_var_node(&cfg->domain, GFP_KERNEL, node))
  48. goto out_cfg;
  49. if (!zalloc_cpumask_var_node(&cfg->old_domain, GFP_KERNEL, node))
  50. goto out_domain;
  51. #ifdef CONFIG_X86_IO_APIC
  52. INIT_LIST_HEAD(&cfg->irq_2_pin);
  53. #endif
  54. return cfg;
  55. out_domain:
  56. free_cpumask_var(cfg->domain);
  57. out_cfg:
  58. kfree(cfg);
  59. return NULL;
  60. }
  61. struct irq_cfg *alloc_irq_and_cfg_at(unsigned int at, int node)
  62. {
  63. int res = irq_alloc_desc_at(at, node);
  64. struct irq_cfg *cfg;
  65. if (res < 0) {
  66. if (res != -EEXIST)
  67. return NULL;
  68. cfg = irq_cfg(at);
  69. if (cfg)
  70. return cfg;
  71. }
  72. cfg = alloc_irq_cfg(at, node);
  73. if (cfg)
  74. irq_set_chip_data(at, cfg);
  75. else
  76. irq_free_desc(at);
  77. return cfg;
  78. }
  79. static void free_irq_cfg(unsigned int at, struct irq_cfg *cfg)
  80. {
  81. if (!cfg)
  82. return;
  83. irq_set_chip_data(at, NULL);
  84. free_cpumask_var(cfg->domain);
  85. free_cpumask_var(cfg->old_domain);
  86. kfree(cfg);
  87. }
  88. static int
  89. __assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
  90. {
  91. /*
  92. * NOTE! The local APIC isn't very good at handling
  93. * multiple interrupts at the same interrupt level.
  94. * As the interrupt level is determined by taking the
  95. * vector number and shifting that right by 4, we
  96. * want to spread these out a bit so that they don't
  97. * all fall in the same interrupt level.
  98. *
  99. * Also, we've got to be careful not to trash gate
  100. * 0x80, because int 0x80 is hm, kind of importantish. ;)
  101. */
  102. static int current_vector = FIRST_EXTERNAL_VECTOR + VECTOR_OFFSET_START;
  103. static int current_offset = VECTOR_OFFSET_START % 16;
  104. int cpu, err;
  105. cpumask_var_t tmp_mask;
  106. if (cfg->move_in_progress)
  107. return -EBUSY;
  108. if (!alloc_cpumask_var(&tmp_mask, GFP_ATOMIC))
  109. return -ENOMEM;
  110. /* Only try and allocate irqs on cpus that are present */
  111. err = -ENOSPC;
  112. cpumask_clear(cfg->old_domain);
  113. cpu = cpumask_first_and(mask, cpu_online_mask);
  114. while (cpu < nr_cpu_ids) {
  115. int new_cpu, vector, offset;
  116. apic->vector_allocation_domain(cpu, tmp_mask, mask);
  117. if (cpumask_subset(tmp_mask, cfg->domain)) {
  118. err = 0;
  119. if (cpumask_equal(tmp_mask, cfg->domain))
  120. break;
  121. /*
  122. * New cpumask using the vector is a proper subset of
  123. * the current in use mask. So cleanup the vector
  124. * allocation for the members that are not used anymore.
  125. */
  126. cpumask_andnot(cfg->old_domain, cfg->domain, tmp_mask);
  127. cfg->move_in_progress =
  128. cpumask_intersects(cfg->old_domain, cpu_online_mask);
  129. cpumask_and(cfg->domain, cfg->domain, tmp_mask);
  130. break;
  131. }
  132. vector = current_vector;
  133. offset = current_offset;
  134. next:
  135. vector += 16;
  136. if (vector >= first_system_vector) {
  137. offset = (offset + 1) % 16;
  138. vector = FIRST_EXTERNAL_VECTOR + offset;
  139. }
  140. if (unlikely(current_vector == vector)) {
  141. cpumask_or(cfg->old_domain, cfg->old_domain, tmp_mask);
  142. cpumask_andnot(tmp_mask, mask, cfg->old_domain);
  143. cpu = cpumask_first_and(tmp_mask, cpu_online_mask);
  144. continue;
  145. }
  146. if (test_bit(vector, used_vectors))
  147. goto next;
  148. for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask) {
  149. if (per_cpu(vector_irq, new_cpu)[vector] >
  150. VECTOR_UNDEFINED)
  151. goto next;
  152. }
  153. /* Found one! */
  154. current_vector = vector;
  155. current_offset = offset;
  156. if (cfg->vector) {
  157. cpumask_copy(cfg->old_domain, cfg->domain);
  158. cfg->move_in_progress =
  159. cpumask_intersects(cfg->old_domain, cpu_online_mask);
  160. }
  161. for_each_cpu_and(new_cpu, tmp_mask, cpu_online_mask)
  162. per_cpu(vector_irq, new_cpu)[vector] = irq;
  163. cfg->vector = vector;
  164. cpumask_copy(cfg->domain, tmp_mask);
  165. err = 0;
  166. break;
  167. }
  168. free_cpumask_var(tmp_mask);
  169. return err;
  170. }
  171. int assign_irq_vector(int irq, struct irq_cfg *cfg, const struct cpumask *mask)
  172. {
  173. int err;
  174. unsigned long flags;
  175. raw_spin_lock_irqsave(&vector_lock, flags);
  176. err = __assign_irq_vector(irq, cfg, mask);
  177. raw_spin_unlock_irqrestore(&vector_lock, flags);
  178. return err;
  179. }
  180. void clear_irq_vector(int irq, struct irq_cfg *cfg)
  181. {
  182. int cpu, vector;
  183. unsigned long flags;
  184. raw_spin_lock_irqsave(&vector_lock, flags);
  185. BUG_ON(!cfg->vector);
  186. vector = cfg->vector;
  187. for_each_cpu_and(cpu, cfg->domain, cpu_online_mask)
  188. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNDEFINED;
  189. cfg->vector = 0;
  190. cpumask_clear(cfg->domain);
  191. if (likely(!cfg->move_in_progress)) {
  192. raw_spin_unlock_irqrestore(&vector_lock, flags);
  193. return;
  194. }
  195. for_each_cpu_and(cpu, cfg->old_domain, cpu_online_mask) {
  196. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS;
  197. vector++) {
  198. if (per_cpu(vector_irq, cpu)[vector] != irq)
  199. continue;
  200. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNDEFINED;
  201. break;
  202. }
  203. }
  204. cfg->move_in_progress = 0;
  205. raw_spin_unlock_irqrestore(&vector_lock, flags);
  206. }
  207. int __init arch_probe_nr_irqs(void)
  208. {
  209. int nr;
  210. if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
  211. nr_irqs = NR_VECTORS * nr_cpu_ids;
  212. nr = (gsi_top + nr_legacy_irqs()) + 8 * nr_cpu_ids;
  213. #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
  214. /*
  215. * for MSI and HT dyn irq
  216. */
  217. if (gsi_top <= NR_IRQS_LEGACY)
  218. nr += 8 * nr_cpu_ids;
  219. else
  220. nr += gsi_top * 16;
  221. #endif
  222. if (nr < nr_irqs)
  223. nr_irqs = nr;
  224. return nr_legacy_irqs();
  225. }
  226. int __init arch_early_irq_init(void)
  227. {
  228. return arch_early_ioapic_init();
  229. }
  230. static void __setup_vector_irq(int cpu)
  231. {
  232. /* Initialize vector_irq on a new cpu */
  233. int irq, vector;
  234. struct irq_cfg *cfg;
  235. /*
  236. * vector_lock will make sure that we don't run into irq vector
  237. * assignments that might be happening on another cpu in parallel,
  238. * while we setup our initial vector to irq mappings.
  239. */
  240. raw_spin_lock(&vector_lock);
  241. /* Mark the inuse vectors */
  242. for_each_active_irq(irq) {
  243. cfg = irq_cfg(irq);
  244. if (!cfg)
  245. continue;
  246. if (!cpumask_test_cpu(cpu, cfg->domain))
  247. continue;
  248. vector = cfg->vector;
  249. per_cpu(vector_irq, cpu)[vector] = irq;
  250. }
  251. /* Mark the free vectors */
  252. for (vector = 0; vector < NR_VECTORS; ++vector) {
  253. irq = per_cpu(vector_irq, cpu)[vector];
  254. if (irq <= VECTOR_UNDEFINED)
  255. continue;
  256. cfg = irq_cfg(irq);
  257. if (!cpumask_test_cpu(cpu, cfg->domain))
  258. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNDEFINED;
  259. }
  260. raw_spin_unlock(&vector_lock);
  261. }
  262. /*
  263. * Setup the vector to irq mappings.
  264. */
  265. void setup_vector_irq(int cpu)
  266. {
  267. int irq;
  268. /*
  269. * On most of the platforms, legacy PIC delivers the interrupts on the
  270. * boot cpu. But there are certain platforms where PIC interrupts are
  271. * delivered to multiple cpu's. If the legacy IRQ is handled by the
  272. * legacy PIC, for the new cpu that is coming online, setup the static
  273. * legacy vector to irq mapping:
  274. */
  275. for (irq = 0; irq < nr_legacy_irqs(); irq++)
  276. per_cpu(vector_irq, cpu)[IRQ0_VECTOR + irq] = irq;
  277. __setup_vector_irq(cpu);
  278. }
  279. int apic_retrigger_irq(struct irq_data *data)
  280. {
  281. struct irq_cfg *cfg = irqd_cfg(data);
  282. unsigned long flags;
  283. int cpu;
  284. raw_spin_lock_irqsave(&vector_lock, flags);
  285. cpu = cpumask_first_and(cfg->domain, cpu_online_mask);
  286. apic->send_IPI_mask(cpumask_of(cpu), cfg->vector);
  287. raw_spin_unlock_irqrestore(&vector_lock, flags);
  288. return 1;
  289. }
  290. void apic_ack_edge(struct irq_data *data)
  291. {
  292. irq_complete_move(irqd_cfg(data));
  293. irq_move_irq(data);
  294. ack_APIC_irq();
  295. }
  296. /*
  297. * Either sets data->affinity to a valid value, and returns
  298. * ->cpu_mask_to_apicid of that in dest_id, or returns -1 and
  299. * leaves data->affinity untouched.
  300. */
  301. int apic_set_affinity(struct irq_data *data, const struct cpumask *mask,
  302. unsigned int *dest_id)
  303. {
  304. struct irq_cfg *cfg = irqd_cfg(data);
  305. unsigned int irq = data->irq;
  306. int err;
  307. if (!config_enabled(CONFIG_SMP))
  308. return -EPERM;
  309. if (!cpumask_intersects(mask, cpu_online_mask))
  310. return -EINVAL;
  311. err = assign_irq_vector(irq, cfg, mask);
  312. if (err)
  313. return err;
  314. err = apic->cpu_mask_to_apicid_and(mask, cfg->domain, dest_id);
  315. if (err) {
  316. if (assign_irq_vector(irq, cfg, data->affinity))
  317. pr_err("Failed to recover vector for irq %d\n", irq);
  318. return err;
  319. }
  320. cpumask_copy(data->affinity, mask);
  321. return 0;
  322. }
  323. #ifdef CONFIG_SMP
  324. void send_cleanup_vector(struct irq_cfg *cfg)
  325. {
  326. cpumask_var_t cleanup_mask;
  327. if (unlikely(!alloc_cpumask_var(&cleanup_mask, GFP_ATOMIC))) {
  328. unsigned int i;
  329. for_each_cpu_and(i, cfg->old_domain, cpu_online_mask)
  330. apic->send_IPI_mask(cpumask_of(i),
  331. IRQ_MOVE_CLEANUP_VECTOR);
  332. } else {
  333. cpumask_and(cleanup_mask, cfg->old_domain, cpu_online_mask);
  334. apic->send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
  335. free_cpumask_var(cleanup_mask);
  336. }
  337. cfg->move_in_progress = 0;
  338. }
  339. asmlinkage __visible void smp_irq_move_cleanup_interrupt(void)
  340. {
  341. unsigned vector, me;
  342. ack_APIC_irq();
  343. irq_enter();
  344. exit_idle();
  345. me = smp_processor_id();
  346. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
  347. int irq;
  348. unsigned int irr;
  349. struct irq_desc *desc;
  350. struct irq_cfg *cfg;
  351. irq = __this_cpu_read(vector_irq[vector]);
  352. if (irq <= VECTOR_UNDEFINED)
  353. continue;
  354. desc = irq_to_desc(irq);
  355. if (!desc)
  356. continue;
  357. cfg = irq_cfg(irq);
  358. if (!cfg)
  359. continue;
  360. raw_spin_lock(&desc->lock);
  361. /*
  362. * Check if the irq migration is in progress. If so, we
  363. * haven't received the cleanup request yet for this irq.
  364. */
  365. if (cfg->move_in_progress)
  366. goto unlock;
  367. if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
  368. goto unlock;
  369. irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
  370. /*
  371. * Check if the vector that needs to be cleanedup is
  372. * registered at the cpu's IRR. If so, then this is not
  373. * the best time to clean it up. Lets clean it up in the
  374. * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
  375. * to myself.
  376. */
  377. if (irr & (1 << (vector % 32))) {
  378. apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
  379. goto unlock;
  380. }
  381. __this_cpu_write(vector_irq[vector], VECTOR_UNDEFINED);
  382. unlock:
  383. raw_spin_unlock(&desc->lock);
  384. }
  385. irq_exit();
  386. }
  387. static void __irq_complete_move(struct irq_cfg *cfg, unsigned vector)
  388. {
  389. unsigned me;
  390. if (likely(!cfg->move_in_progress))
  391. return;
  392. me = smp_processor_id();
  393. if (vector == cfg->vector && cpumask_test_cpu(me, cfg->domain))
  394. send_cleanup_vector(cfg);
  395. }
  396. void irq_complete_move(struct irq_cfg *cfg)
  397. {
  398. __irq_complete_move(cfg, ~get_irq_regs()->orig_ax);
  399. }
  400. void irq_force_complete_move(int irq)
  401. {
  402. struct irq_cfg *cfg = irq_cfg(irq);
  403. if (!cfg)
  404. return;
  405. __irq_complete_move(cfg, cfg->vector);
  406. }
  407. #endif
  408. /*
  409. * Dynamic irq allocate and deallocation. Should be replaced by irq domains!
  410. */
  411. int arch_setup_hwirq(unsigned int irq, int node)
  412. {
  413. struct irq_cfg *cfg;
  414. unsigned long flags;
  415. int ret;
  416. cfg = alloc_irq_cfg(irq, node);
  417. if (!cfg)
  418. return -ENOMEM;
  419. raw_spin_lock_irqsave(&vector_lock, flags);
  420. ret = __assign_irq_vector(irq, cfg, apic->target_cpus());
  421. raw_spin_unlock_irqrestore(&vector_lock, flags);
  422. if (!ret)
  423. irq_set_chip_data(irq, cfg);
  424. else
  425. free_irq_cfg(irq, cfg);
  426. return ret;
  427. }
  428. void arch_teardown_hwirq(unsigned int irq)
  429. {
  430. struct irq_cfg *cfg = irq_cfg(irq);
  431. free_remapped_irq(irq);
  432. clear_irq_vector(irq, cfg);
  433. free_irq_cfg(irq, cfg);
  434. }
  435. static void __init print_APIC_field(int base)
  436. {
  437. int i;
  438. printk(KERN_DEBUG);
  439. for (i = 0; i < 8; i++)
  440. pr_cont("%08x", apic_read(base + i*0x10));
  441. pr_cont("\n");
  442. }
  443. static void __init print_local_APIC(void *dummy)
  444. {
  445. unsigned int i, v, ver, maxlvt;
  446. u64 icr;
  447. pr_debug("printing local APIC contents on CPU#%d/%d:\n",
  448. smp_processor_id(), hard_smp_processor_id());
  449. v = apic_read(APIC_ID);
  450. pr_info("... APIC ID: %08x (%01x)\n", v, read_apic_id());
  451. v = apic_read(APIC_LVR);
  452. pr_info("... APIC VERSION: %08x\n", v);
  453. ver = GET_APIC_VERSION(v);
  454. maxlvt = lapic_get_maxlvt();
  455. v = apic_read(APIC_TASKPRI);
  456. pr_debug("... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
  457. /* !82489DX */
  458. if (APIC_INTEGRATED(ver)) {
  459. if (!APIC_XAPIC(ver)) {
  460. v = apic_read(APIC_ARBPRI);
  461. pr_debug("... APIC ARBPRI: %08x (%02x)\n",
  462. v, v & APIC_ARBPRI_MASK);
  463. }
  464. v = apic_read(APIC_PROCPRI);
  465. pr_debug("... APIC PROCPRI: %08x\n", v);
  466. }
  467. /*
  468. * Remote read supported only in the 82489DX and local APIC for
  469. * Pentium processors.
  470. */
  471. if (!APIC_INTEGRATED(ver) || maxlvt == 3) {
  472. v = apic_read(APIC_RRR);
  473. pr_debug("... APIC RRR: %08x\n", v);
  474. }
  475. v = apic_read(APIC_LDR);
  476. pr_debug("... APIC LDR: %08x\n", v);
  477. if (!x2apic_enabled()) {
  478. v = apic_read(APIC_DFR);
  479. pr_debug("... APIC DFR: %08x\n", v);
  480. }
  481. v = apic_read(APIC_SPIV);
  482. pr_debug("... APIC SPIV: %08x\n", v);
  483. pr_debug("... APIC ISR field:\n");
  484. print_APIC_field(APIC_ISR);
  485. pr_debug("... APIC TMR field:\n");
  486. print_APIC_field(APIC_TMR);
  487. pr_debug("... APIC IRR field:\n");
  488. print_APIC_field(APIC_IRR);
  489. /* !82489DX */
  490. if (APIC_INTEGRATED(ver)) {
  491. /* Due to the Pentium erratum 3AP. */
  492. if (maxlvt > 3)
  493. apic_write(APIC_ESR, 0);
  494. v = apic_read(APIC_ESR);
  495. pr_debug("... APIC ESR: %08x\n", v);
  496. }
  497. icr = apic_icr_read();
  498. pr_debug("... APIC ICR: %08x\n", (u32)icr);
  499. pr_debug("... APIC ICR2: %08x\n", (u32)(icr >> 32));
  500. v = apic_read(APIC_LVTT);
  501. pr_debug("... APIC LVTT: %08x\n", v);
  502. if (maxlvt > 3) {
  503. /* PC is LVT#4. */
  504. v = apic_read(APIC_LVTPC);
  505. pr_debug("... APIC LVTPC: %08x\n", v);
  506. }
  507. v = apic_read(APIC_LVT0);
  508. pr_debug("... APIC LVT0: %08x\n", v);
  509. v = apic_read(APIC_LVT1);
  510. pr_debug("... APIC LVT1: %08x\n", v);
  511. if (maxlvt > 2) {
  512. /* ERR is LVT#3. */
  513. v = apic_read(APIC_LVTERR);
  514. pr_debug("... APIC LVTERR: %08x\n", v);
  515. }
  516. v = apic_read(APIC_TMICT);
  517. pr_debug("... APIC TMICT: %08x\n", v);
  518. v = apic_read(APIC_TMCCT);
  519. pr_debug("... APIC TMCCT: %08x\n", v);
  520. v = apic_read(APIC_TDCR);
  521. pr_debug("... APIC TDCR: %08x\n", v);
  522. if (boot_cpu_has(X86_FEATURE_EXTAPIC)) {
  523. v = apic_read(APIC_EFEAT);
  524. maxlvt = (v >> 16) & 0xff;
  525. pr_debug("... APIC EFEAT: %08x\n", v);
  526. v = apic_read(APIC_ECTRL);
  527. pr_debug("... APIC ECTRL: %08x\n", v);
  528. for (i = 0; i < maxlvt; i++) {
  529. v = apic_read(APIC_EILVTn(i));
  530. pr_debug("... APIC EILVT%d: %08x\n", i, v);
  531. }
  532. }
  533. pr_cont("\n");
  534. }
  535. static void __init print_local_APICs(int maxcpu)
  536. {
  537. int cpu;
  538. if (!maxcpu)
  539. return;
  540. preempt_disable();
  541. for_each_online_cpu(cpu) {
  542. if (cpu >= maxcpu)
  543. break;
  544. smp_call_function_single(cpu, print_local_APIC, NULL, 1);
  545. }
  546. preempt_enable();
  547. }
  548. static void __init print_PIC(void)
  549. {
  550. unsigned int v;
  551. unsigned long flags;
  552. if (!nr_legacy_irqs())
  553. return;
  554. pr_debug("\nprinting PIC contents\n");
  555. raw_spin_lock_irqsave(&i8259A_lock, flags);
  556. v = inb(0xa1) << 8 | inb(0x21);
  557. pr_debug("... PIC IMR: %04x\n", v);
  558. v = inb(0xa0) << 8 | inb(0x20);
  559. pr_debug("... PIC IRR: %04x\n", v);
  560. outb(0x0b, 0xa0);
  561. outb(0x0b, 0x20);
  562. v = inb(0xa0) << 8 | inb(0x20);
  563. outb(0x0a, 0xa0);
  564. outb(0x0a, 0x20);
  565. raw_spin_unlock_irqrestore(&i8259A_lock, flags);
  566. pr_debug("... PIC ISR: %04x\n", v);
  567. v = inb(0x4d1) << 8 | inb(0x4d0);
  568. pr_debug("... PIC ELCR: %04x\n", v);
  569. }
  570. static int show_lapic __initdata = 1;
  571. static __init int setup_show_lapic(char *arg)
  572. {
  573. int num = -1;
  574. if (strcmp(arg, "all") == 0) {
  575. show_lapic = CONFIG_NR_CPUS;
  576. } else {
  577. get_option(&arg, &num);
  578. if (num >= 0)
  579. show_lapic = num;
  580. }
  581. return 1;
  582. }
  583. __setup("show_lapic=", setup_show_lapic);
  584. static int __init print_ICs(void)
  585. {
  586. if (apic_verbosity == APIC_QUIET)
  587. return 0;
  588. print_PIC();
  589. /* don't print out if apic is not there */
  590. if (!cpu_has_apic && !apic_from_smp_config())
  591. return 0;
  592. print_local_APICs(show_lapic);
  593. print_IO_APICs();
  594. return 0;
  595. }
  596. late_initcall(print_ICs);