vector.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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. * Jiang Liu <jiang.liu@linux.intel.com>
  7. * Enable support of hierarchical irqdomains
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/interrupt.h>
  14. #include <linux/init.h>
  15. #include <linux/compiler.h>
  16. #include <linux/slab.h>
  17. #include <asm/irqdomain.h>
  18. #include <asm/hw_irq.h>
  19. #include <asm/apic.h>
  20. #include <asm/i8259.h>
  21. #include <asm/desc.h>
  22. #include <asm/irq_remapping.h>
  23. struct apic_chip_data {
  24. struct irq_cfg cfg;
  25. cpumask_var_t domain;
  26. cpumask_var_t old_domain;
  27. u8 move_in_progress : 1;
  28. };
  29. struct irq_domain *x86_vector_domain;
  30. EXPORT_SYMBOL_GPL(x86_vector_domain);
  31. static DEFINE_RAW_SPINLOCK(vector_lock);
  32. static cpumask_var_t vector_cpumask, vector_searchmask, searched_cpumask;
  33. static struct irq_chip lapic_controller;
  34. #ifdef CONFIG_X86_IO_APIC
  35. static struct apic_chip_data *legacy_irq_data[NR_IRQS_LEGACY];
  36. #endif
  37. void lock_vector_lock(void)
  38. {
  39. /* Used to the online set of cpus does not change
  40. * during assign_irq_vector.
  41. */
  42. raw_spin_lock(&vector_lock);
  43. }
  44. void unlock_vector_lock(void)
  45. {
  46. raw_spin_unlock(&vector_lock);
  47. }
  48. static struct apic_chip_data *apic_chip_data(struct irq_data *irq_data)
  49. {
  50. if (!irq_data)
  51. return NULL;
  52. while (irq_data->parent_data)
  53. irq_data = irq_data->parent_data;
  54. return irq_data->chip_data;
  55. }
  56. struct irq_cfg *irqd_cfg(struct irq_data *irq_data)
  57. {
  58. struct apic_chip_data *data = apic_chip_data(irq_data);
  59. return data ? &data->cfg : NULL;
  60. }
  61. EXPORT_SYMBOL_GPL(irqd_cfg);
  62. struct irq_cfg *irq_cfg(unsigned int irq)
  63. {
  64. return irqd_cfg(irq_get_irq_data(irq));
  65. }
  66. static struct apic_chip_data *alloc_apic_chip_data(int node)
  67. {
  68. struct apic_chip_data *data;
  69. data = kzalloc_node(sizeof(*data), GFP_KERNEL, node);
  70. if (!data)
  71. return NULL;
  72. if (!zalloc_cpumask_var_node(&data->domain, GFP_KERNEL, node))
  73. goto out_data;
  74. if (!zalloc_cpumask_var_node(&data->old_domain, GFP_KERNEL, node))
  75. goto out_domain;
  76. return data;
  77. out_domain:
  78. free_cpumask_var(data->domain);
  79. out_data:
  80. kfree(data);
  81. return NULL;
  82. }
  83. static void free_apic_chip_data(struct apic_chip_data *data)
  84. {
  85. if (data) {
  86. free_cpumask_var(data->domain);
  87. free_cpumask_var(data->old_domain);
  88. kfree(data);
  89. }
  90. }
  91. static int __assign_irq_vector(int irq, struct apic_chip_data *d,
  92. const struct cpumask *mask)
  93. {
  94. /*
  95. * NOTE! The local APIC isn't very good at handling
  96. * multiple interrupts at the same interrupt level.
  97. * As the interrupt level is determined by taking the
  98. * vector number and shifting that right by 4, we
  99. * want to spread these out a bit so that they don't
  100. * all fall in the same interrupt level.
  101. *
  102. * Also, we've got to be careful not to trash gate
  103. * 0x80, because int 0x80 is hm, kind of importantish. ;)
  104. */
  105. static int current_vector = FIRST_EXTERNAL_VECTOR + VECTOR_OFFSET_START;
  106. static int current_offset = VECTOR_OFFSET_START % 16;
  107. int cpu, vector;
  108. if (d->move_in_progress)
  109. return -EBUSY;
  110. /* Only try and allocate irqs on cpus that are present */
  111. cpumask_clear(d->old_domain);
  112. cpumask_clear(searched_cpumask);
  113. cpu = cpumask_first_and(mask, cpu_online_mask);
  114. while (cpu < nr_cpu_ids) {
  115. int new_cpu, offset;
  116. /* Get the possible target cpus for @mask/@cpu from the apic */
  117. apic->vector_allocation_domain(cpu, vector_cpumask, mask);
  118. /*
  119. * Clear the offline cpus from @vector_cpumask for searching
  120. * and verify whether the result overlaps with @mask. If true,
  121. * then the call to apic->cpu_mask_to_apicid_and() will
  122. * succeed as well. If not, no point in trying to find a
  123. * vector in this mask.
  124. */
  125. cpumask_and(vector_searchmask, vector_cpumask, cpu_online_mask);
  126. if (!cpumask_intersects(vector_searchmask, mask))
  127. goto next_cpu;
  128. if (cpumask_subset(vector_cpumask, d->domain)) {
  129. if (cpumask_equal(vector_cpumask, d->domain))
  130. goto success;
  131. /*
  132. * Mark the cpus which are not longer in the mask for
  133. * cleanup.
  134. */
  135. cpumask_andnot(d->old_domain, d->domain, vector_cpumask);
  136. vector = d->cfg.vector;
  137. goto update;
  138. }
  139. vector = current_vector;
  140. offset = current_offset;
  141. next:
  142. vector += 16;
  143. if (vector >= first_system_vector) {
  144. offset = (offset + 1) % 16;
  145. vector = FIRST_EXTERNAL_VECTOR + offset;
  146. }
  147. /* If the search wrapped around, try the next cpu */
  148. if (unlikely(current_vector == vector))
  149. goto next_cpu;
  150. if (test_bit(vector, used_vectors))
  151. goto next;
  152. for_each_cpu(new_cpu, vector_searchmask) {
  153. if (!IS_ERR_OR_NULL(per_cpu(vector_irq, new_cpu)[vector]))
  154. goto next;
  155. }
  156. /* Found one! */
  157. current_vector = vector;
  158. current_offset = offset;
  159. /* Schedule the old vector for cleanup on all cpus */
  160. if (d->cfg.vector)
  161. cpumask_copy(d->old_domain, d->domain);
  162. for_each_cpu(new_cpu, vector_searchmask)
  163. per_cpu(vector_irq, new_cpu)[vector] = irq_to_desc(irq);
  164. goto update;
  165. next_cpu:
  166. /*
  167. * We exclude the current @vector_cpumask from the requested
  168. * @mask and try again with the next online cpu in the
  169. * result. We cannot modify @mask, so we use @vector_cpumask
  170. * as a temporary buffer here as it will be reassigned when
  171. * calling apic->vector_allocation_domain() above.
  172. */
  173. cpumask_or(searched_cpumask, searched_cpumask, vector_cpumask);
  174. cpumask_andnot(vector_cpumask, mask, searched_cpumask);
  175. cpu = cpumask_first_and(vector_cpumask, cpu_online_mask);
  176. continue;
  177. }
  178. return -ENOSPC;
  179. update:
  180. /* Cleanup required ? */
  181. d->move_in_progress = cpumask_intersects(d->old_domain, cpu_online_mask);
  182. d->cfg.vector = vector;
  183. cpumask_copy(d->domain, vector_cpumask);
  184. success:
  185. /*
  186. * Cache destination APIC IDs into cfg->dest_apicid. This cannot fail
  187. * as we already established, that mask & d->domain & cpu_online_mask
  188. * is not empty.
  189. */
  190. BUG_ON(apic->cpu_mask_to_apicid_and(mask, d->domain,
  191. &d->cfg.dest_apicid));
  192. return 0;
  193. }
  194. static int assign_irq_vector(int irq, struct apic_chip_data *data,
  195. const struct cpumask *mask)
  196. {
  197. int err;
  198. unsigned long flags;
  199. raw_spin_lock_irqsave(&vector_lock, flags);
  200. err = __assign_irq_vector(irq, data, mask);
  201. raw_spin_unlock_irqrestore(&vector_lock, flags);
  202. return err;
  203. }
  204. static int assign_irq_vector_policy(int irq, int node,
  205. struct apic_chip_data *data,
  206. struct irq_alloc_info *info)
  207. {
  208. if (info && info->mask)
  209. return assign_irq_vector(irq, data, info->mask);
  210. if (node != NUMA_NO_NODE &&
  211. assign_irq_vector(irq, data, cpumask_of_node(node)) == 0)
  212. return 0;
  213. return assign_irq_vector(irq, data, apic->target_cpus());
  214. }
  215. static void clear_irq_vector(int irq, struct apic_chip_data *data)
  216. {
  217. struct irq_desc *desc;
  218. int cpu, vector;
  219. BUG_ON(!data->cfg.vector);
  220. vector = data->cfg.vector;
  221. for_each_cpu_and(cpu, data->domain, cpu_online_mask)
  222. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED;
  223. data->cfg.vector = 0;
  224. cpumask_clear(data->domain);
  225. if (likely(!data->move_in_progress))
  226. return;
  227. desc = irq_to_desc(irq);
  228. for_each_cpu_and(cpu, data->old_domain, cpu_online_mask) {
  229. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS;
  230. vector++) {
  231. if (per_cpu(vector_irq, cpu)[vector] != desc)
  232. continue;
  233. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED;
  234. break;
  235. }
  236. }
  237. data->move_in_progress = 0;
  238. }
  239. void init_irq_alloc_info(struct irq_alloc_info *info,
  240. const struct cpumask *mask)
  241. {
  242. memset(info, 0, sizeof(*info));
  243. info->mask = mask;
  244. }
  245. void copy_irq_alloc_info(struct irq_alloc_info *dst, struct irq_alloc_info *src)
  246. {
  247. if (src)
  248. *dst = *src;
  249. else
  250. memset(dst, 0, sizeof(*dst));
  251. }
  252. static void x86_vector_free_irqs(struct irq_domain *domain,
  253. unsigned int virq, unsigned int nr_irqs)
  254. {
  255. struct apic_chip_data *apic_data;
  256. struct irq_data *irq_data;
  257. unsigned long flags;
  258. int i;
  259. for (i = 0; i < nr_irqs; i++) {
  260. irq_data = irq_domain_get_irq_data(x86_vector_domain, virq + i);
  261. if (irq_data && irq_data->chip_data) {
  262. raw_spin_lock_irqsave(&vector_lock, flags);
  263. clear_irq_vector(virq + i, irq_data->chip_data);
  264. apic_data = irq_data->chip_data;
  265. irq_domain_reset_irq_data(irq_data);
  266. raw_spin_unlock_irqrestore(&vector_lock, flags);
  267. free_apic_chip_data(apic_data);
  268. #ifdef CONFIG_X86_IO_APIC
  269. if (virq + i < nr_legacy_irqs())
  270. legacy_irq_data[virq + i] = NULL;
  271. #endif
  272. }
  273. }
  274. }
  275. static int x86_vector_alloc_irqs(struct irq_domain *domain, unsigned int virq,
  276. unsigned int nr_irqs, void *arg)
  277. {
  278. struct irq_alloc_info *info = arg;
  279. struct apic_chip_data *data;
  280. struct irq_data *irq_data;
  281. int i, err, node;
  282. if (disable_apic)
  283. return -ENXIO;
  284. /* Currently vector allocator can't guarantee contiguous allocations */
  285. if ((info->flags & X86_IRQ_ALLOC_CONTIGUOUS_VECTORS) && nr_irqs > 1)
  286. return -ENOSYS;
  287. for (i = 0; i < nr_irqs; i++) {
  288. irq_data = irq_domain_get_irq_data(domain, virq + i);
  289. BUG_ON(!irq_data);
  290. node = irq_data_get_node(irq_data);
  291. #ifdef CONFIG_X86_IO_APIC
  292. if (virq + i < nr_legacy_irqs() && legacy_irq_data[virq + i])
  293. data = legacy_irq_data[virq + i];
  294. else
  295. #endif
  296. data = alloc_apic_chip_data(node);
  297. if (!data) {
  298. err = -ENOMEM;
  299. goto error;
  300. }
  301. irq_data->chip = &lapic_controller;
  302. irq_data->chip_data = data;
  303. irq_data->hwirq = virq + i;
  304. err = assign_irq_vector_policy(virq + i, node, data, info);
  305. if (err)
  306. goto error;
  307. }
  308. return 0;
  309. error:
  310. x86_vector_free_irqs(domain, virq, i + 1);
  311. return err;
  312. }
  313. static const struct irq_domain_ops x86_vector_domain_ops = {
  314. .alloc = x86_vector_alloc_irqs,
  315. .free = x86_vector_free_irqs,
  316. };
  317. int __init arch_probe_nr_irqs(void)
  318. {
  319. int nr;
  320. if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
  321. nr_irqs = NR_VECTORS * nr_cpu_ids;
  322. nr = (gsi_top + nr_legacy_irqs()) + 8 * nr_cpu_ids;
  323. #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
  324. /*
  325. * for MSI and HT dyn irq
  326. */
  327. if (gsi_top <= NR_IRQS_LEGACY)
  328. nr += 8 * nr_cpu_ids;
  329. else
  330. nr += gsi_top * 16;
  331. #endif
  332. if (nr < nr_irqs)
  333. nr_irqs = nr;
  334. /*
  335. * We don't know if PIC is present at this point so we need to do
  336. * probe() to get the right number of legacy IRQs.
  337. */
  338. return legacy_pic->probe();
  339. }
  340. #ifdef CONFIG_X86_IO_APIC
  341. static void init_legacy_irqs(void)
  342. {
  343. int i, node = cpu_to_node(0);
  344. struct apic_chip_data *data;
  345. /*
  346. * For legacy IRQ's, start with assigning irq0 to irq15 to
  347. * ISA_IRQ_VECTOR(i) for all cpu's.
  348. */
  349. for (i = 0; i < nr_legacy_irqs(); i++) {
  350. data = legacy_irq_data[i] = alloc_apic_chip_data(node);
  351. BUG_ON(!data);
  352. data->cfg.vector = ISA_IRQ_VECTOR(i);
  353. cpumask_setall(data->domain);
  354. irq_set_chip_data(i, data);
  355. }
  356. }
  357. #else
  358. static void init_legacy_irqs(void) { }
  359. #endif
  360. int __init arch_early_irq_init(void)
  361. {
  362. init_legacy_irqs();
  363. x86_vector_domain = irq_domain_add_tree(NULL, &x86_vector_domain_ops,
  364. NULL);
  365. BUG_ON(x86_vector_domain == NULL);
  366. irq_set_default_host(x86_vector_domain);
  367. arch_init_msi_domain(x86_vector_domain);
  368. arch_init_htirq_domain(x86_vector_domain);
  369. BUG_ON(!alloc_cpumask_var(&vector_cpumask, GFP_KERNEL));
  370. BUG_ON(!alloc_cpumask_var(&vector_searchmask, GFP_KERNEL));
  371. BUG_ON(!alloc_cpumask_var(&searched_cpumask, GFP_KERNEL));
  372. return arch_early_ioapic_init();
  373. }
  374. /* Initialize vector_irq on a new cpu */
  375. static void __setup_vector_irq(int cpu)
  376. {
  377. struct apic_chip_data *data;
  378. struct irq_desc *desc;
  379. int irq, vector;
  380. /* Mark the inuse vectors */
  381. for_each_irq_desc(irq, desc) {
  382. struct irq_data *idata = irq_desc_get_irq_data(desc);
  383. data = apic_chip_data(idata);
  384. if (!data || !cpumask_test_cpu(cpu, data->domain))
  385. continue;
  386. vector = data->cfg.vector;
  387. per_cpu(vector_irq, cpu)[vector] = desc;
  388. }
  389. /* Mark the free vectors */
  390. for (vector = 0; vector < NR_VECTORS; ++vector) {
  391. desc = per_cpu(vector_irq, cpu)[vector];
  392. if (IS_ERR_OR_NULL(desc))
  393. continue;
  394. data = apic_chip_data(irq_desc_get_irq_data(desc));
  395. if (!cpumask_test_cpu(cpu, data->domain))
  396. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED;
  397. }
  398. }
  399. /*
  400. * Setup the vector to irq mappings. Must be called with vector_lock held.
  401. */
  402. void setup_vector_irq(int cpu)
  403. {
  404. int irq;
  405. lockdep_assert_held(&vector_lock);
  406. /*
  407. * On most of the platforms, legacy PIC delivers the interrupts on the
  408. * boot cpu. But there are certain platforms where PIC interrupts are
  409. * delivered to multiple cpu's. If the legacy IRQ is handled by the
  410. * legacy PIC, for the new cpu that is coming online, setup the static
  411. * legacy vector to irq mapping:
  412. */
  413. for (irq = 0; irq < nr_legacy_irqs(); irq++)
  414. per_cpu(vector_irq, cpu)[ISA_IRQ_VECTOR(irq)] = irq_to_desc(irq);
  415. __setup_vector_irq(cpu);
  416. }
  417. static int apic_retrigger_irq(struct irq_data *irq_data)
  418. {
  419. struct apic_chip_data *data = apic_chip_data(irq_data);
  420. unsigned long flags;
  421. int cpu;
  422. raw_spin_lock_irqsave(&vector_lock, flags);
  423. cpu = cpumask_first_and(data->domain, cpu_online_mask);
  424. apic->send_IPI_mask(cpumask_of(cpu), data->cfg.vector);
  425. raw_spin_unlock_irqrestore(&vector_lock, flags);
  426. return 1;
  427. }
  428. void apic_ack_edge(struct irq_data *data)
  429. {
  430. irq_complete_move(irqd_cfg(data));
  431. irq_move_irq(data);
  432. ack_APIC_irq();
  433. }
  434. static int apic_set_affinity(struct irq_data *irq_data,
  435. const struct cpumask *dest, bool force)
  436. {
  437. struct apic_chip_data *data = irq_data->chip_data;
  438. int err, irq = irq_data->irq;
  439. if (!config_enabled(CONFIG_SMP))
  440. return -EPERM;
  441. if (!cpumask_intersects(dest, cpu_online_mask))
  442. return -EINVAL;
  443. err = assign_irq_vector(irq, data, dest);
  444. return err ? err : IRQ_SET_MASK_OK;
  445. }
  446. static struct irq_chip lapic_controller = {
  447. .irq_ack = apic_ack_edge,
  448. .irq_set_affinity = apic_set_affinity,
  449. .irq_retrigger = apic_retrigger_irq,
  450. };
  451. #ifdef CONFIG_SMP
  452. static void __send_cleanup_vector(struct apic_chip_data *data)
  453. {
  454. cpumask_var_t cleanup_mask;
  455. if (unlikely(!alloc_cpumask_var(&cleanup_mask, GFP_ATOMIC))) {
  456. unsigned int i;
  457. for_each_cpu_and(i, data->old_domain, cpu_online_mask)
  458. apic->send_IPI_mask(cpumask_of(i),
  459. IRQ_MOVE_CLEANUP_VECTOR);
  460. } else {
  461. cpumask_and(cleanup_mask, data->old_domain, cpu_online_mask);
  462. apic->send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
  463. free_cpumask_var(cleanup_mask);
  464. }
  465. data->move_in_progress = 0;
  466. }
  467. void send_cleanup_vector(struct irq_cfg *cfg)
  468. {
  469. struct apic_chip_data *data;
  470. data = container_of(cfg, struct apic_chip_data, cfg);
  471. if (data->move_in_progress)
  472. __send_cleanup_vector(data);
  473. }
  474. asmlinkage __visible void smp_irq_move_cleanup_interrupt(void)
  475. {
  476. unsigned vector, me;
  477. entering_ack_irq();
  478. /* Prevent vectors vanishing under us */
  479. raw_spin_lock(&vector_lock);
  480. me = smp_processor_id();
  481. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
  482. struct apic_chip_data *data;
  483. struct irq_desc *desc;
  484. unsigned int irr;
  485. retry:
  486. desc = __this_cpu_read(vector_irq[vector]);
  487. if (IS_ERR_OR_NULL(desc))
  488. continue;
  489. if (!raw_spin_trylock(&desc->lock)) {
  490. raw_spin_unlock(&vector_lock);
  491. cpu_relax();
  492. raw_spin_lock(&vector_lock);
  493. goto retry;
  494. }
  495. data = apic_chip_data(irq_desc_get_irq_data(desc));
  496. if (!data)
  497. goto unlock;
  498. /*
  499. * Check if the irq migration is in progress. If so, we
  500. * haven't received the cleanup request yet for this irq.
  501. */
  502. if (data->move_in_progress)
  503. goto unlock;
  504. if (vector == data->cfg.vector &&
  505. cpumask_test_cpu(me, data->domain))
  506. goto unlock;
  507. irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
  508. /*
  509. * Check if the vector that needs to be cleanedup is
  510. * registered at the cpu's IRR. If so, then this is not
  511. * the best time to clean it up. Lets clean it up in the
  512. * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
  513. * to myself.
  514. */
  515. if (irr & (1 << (vector % 32))) {
  516. apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
  517. goto unlock;
  518. }
  519. __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
  520. unlock:
  521. raw_spin_unlock(&desc->lock);
  522. }
  523. raw_spin_unlock(&vector_lock);
  524. exiting_irq();
  525. }
  526. static void __irq_complete_move(struct irq_cfg *cfg, unsigned vector)
  527. {
  528. unsigned me;
  529. struct apic_chip_data *data;
  530. data = container_of(cfg, struct apic_chip_data, cfg);
  531. if (likely(!data->move_in_progress))
  532. return;
  533. me = smp_processor_id();
  534. if (vector == data->cfg.vector && cpumask_test_cpu(me, data->domain))
  535. __send_cleanup_vector(data);
  536. }
  537. void irq_complete_move(struct irq_cfg *cfg)
  538. {
  539. __irq_complete_move(cfg, ~get_irq_regs()->orig_ax);
  540. }
  541. void irq_force_complete_move(int irq)
  542. {
  543. struct irq_cfg *cfg = irq_cfg(irq);
  544. if (cfg)
  545. __irq_complete_move(cfg, cfg->vector);
  546. }
  547. #endif
  548. static void __init print_APIC_field(int base)
  549. {
  550. int i;
  551. printk(KERN_DEBUG);
  552. for (i = 0; i < 8; i++)
  553. pr_cont("%08x", apic_read(base + i*0x10));
  554. pr_cont("\n");
  555. }
  556. static void __init print_local_APIC(void *dummy)
  557. {
  558. unsigned int i, v, ver, maxlvt;
  559. u64 icr;
  560. pr_debug("printing local APIC contents on CPU#%d/%d:\n",
  561. smp_processor_id(), hard_smp_processor_id());
  562. v = apic_read(APIC_ID);
  563. pr_info("... APIC ID: %08x (%01x)\n", v, read_apic_id());
  564. v = apic_read(APIC_LVR);
  565. pr_info("... APIC VERSION: %08x\n", v);
  566. ver = GET_APIC_VERSION(v);
  567. maxlvt = lapic_get_maxlvt();
  568. v = apic_read(APIC_TASKPRI);
  569. pr_debug("... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
  570. /* !82489DX */
  571. if (APIC_INTEGRATED(ver)) {
  572. if (!APIC_XAPIC(ver)) {
  573. v = apic_read(APIC_ARBPRI);
  574. pr_debug("... APIC ARBPRI: %08x (%02x)\n",
  575. v, v & APIC_ARBPRI_MASK);
  576. }
  577. v = apic_read(APIC_PROCPRI);
  578. pr_debug("... APIC PROCPRI: %08x\n", v);
  579. }
  580. /*
  581. * Remote read supported only in the 82489DX and local APIC for
  582. * Pentium processors.
  583. */
  584. if (!APIC_INTEGRATED(ver) || maxlvt == 3) {
  585. v = apic_read(APIC_RRR);
  586. pr_debug("... APIC RRR: %08x\n", v);
  587. }
  588. v = apic_read(APIC_LDR);
  589. pr_debug("... APIC LDR: %08x\n", v);
  590. if (!x2apic_enabled()) {
  591. v = apic_read(APIC_DFR);
  592. pr_debug("... APIC DFR: %08x\n", v);
  593. }
  594. v = apic_read(APIC_SPIV);
  595. pr_debug("... APIC SPIV: %08x\n", v);
  596. pr_debug("... APIC ISR field:\n");
  597. print_APIC_field(APIC_ISR);
  598. pr_debug("... APIC TMR field:\n");
  599. print_APIC_field(APIC_TMR);
  600. pr_debug("... APIC IRR field:\n");
  601. print_APIC_field(APIC_IRR);
  602. /* !82489DX */
  603. if (APIC_INTEGRATED(ver)) {
  604. /* Due to the Pentium erratum 3AP. */
  605. if (maxlvt > 3)
  606. apic_write(APIC_ESR, 0);
  607. v = apic_read(APIC_ESR);
  608. pr_debug("... APIC ESR: %08x\n", v);
  609. }
  610. icr = apic_icr_read();
  611. pr_debug("... APIC ICR: %08x\n", (u32)icr);
  612. pr_debug("... APIC ICR2: %08x\n", (u32)(icr >> 32));
  613. v = apic_read(APIC_LVTT);
  614. pr_debug("... APIC LVTT: %08x\n", v);
  615. if (maxlvt > 3) {
  616. /* PC is LVT#4. */
  617. v = apic_read(APIC_LVTPC);
  618. pr_debug("... APIC LVTPC: %08x\n", v);
  619. }
  620. v = apic_read(APIC_LVT0);
  621. pr_debug("... APIC LVT0: %08x\n", v);
  622. v = apic_read(APIC_LVT1);
  623. pr_debug("... APIC LVT1: %08x\n", v);
  624. if (maxlvt > 2) {
  625. /* ERR is LVT#3. */
  626. v = apic_read(APIC_LVTERR);
  627. pr_debug("... APIC LVTERR: %08x\n", v);
  628. }
  629. v = apic_read(APIC_TMICT);
  630. pr_debug("... APIC TMICT: %08x\n", v);
  631. v = apic_read(APIC_TMCCT);
  632. pr_debug("... APIC TMCCT: %08x\n", v);
  633. v = apic_read(APIC_TDCR);
  634. pr_debug("... APIC TDCR: %08x\n", v);
  635. if (boot_cpu_has(X86_FEATURE_EXTAPIC)) {
  636. v = apic_read(APIC_EFEAT);
  637. maxlvt = (v >> 16) & 0xff;
  638. pr_debug("... APIC EFEAT: %08x\n", v);
  639. v = apic_read(APIC_ECTRL);
  640. pr_debug("... APIC ECTRL: %08x\n", v);
  641. for (i = 0; i < maxlvt; i++) {
  642. v = apic_read(APIC_EILVTn(i));
  643. pr_debug("... APIC EILVT%d: %08x\n", i, v);
  644. }
  645. }
  646. pr_cont("\n");
  647. }
  648. static void __init print_local_APICs(int maxcpu)
  649. {
  650. int cpu;
  651. if (!maxcpu)
  652. return;
  653. preempt_disable();
  654. for_each_online_cpu(cpu) {
  655. if (cpu >= maxcpu)
  656. break;
  657. smp_call_function_single(cpu, print_local_APIC, NULL, 1);
  658. }
  659. preempt_enable();
  660. }
  661. static void __init print_PIC(void)
  662. {
  663. unsigned int v;
  664. unsigned long flags;
  665. if (!nr_legacy_irqs())
  666. return;
  667. pr_debug("\nprinting PIC contents\n");
  668. raw_spin_lock_irqsave(&i8259A_lock, flags);
  669. v = inb(0xa1) << 8 | inb(0x21);
  670. pr_debug("... PIC IMR: %04x\n", v);
  671. v = inb(0xa0) << 8 | inb(0x20);
  672. pr_debug("... PIC IRR: %04x\n", v);
  673. outb(0x0b, 0xa0);
  674. outb(0x0b, 0x20);
  675. v = inb(0xa0) << 8 | inb(0x20);
  676. outb(0x0a, 0xa0);
  677. outb(0x0a, 0x20);
  678. raw_spin_unlock_irqrestore(&i8259A_lock, flags);
  679. pr_debug("... PIC ISR: %04x\n", v);
  680. v = inb(0x4d1) << 8 | inb(0x4d0);
  681. pr_debug("... PIC ELCR: %04x\n", v);
  682. }
  683. static int show_lapic __initdata = 1;
  684. static __init int setup_show_lapic(char *arg)
  685. {
  686. int num = -1;
  687. if (strcmp(arg, "all") == 0) {
  688. show_lapic = CONFIG_NR_CPUS;
  689. } else {
  690. get_option(&arg, &num);
  691. if (num >= 0)
  692. show_lapic = num;
  693. }
  694. return 1;
  695. }
  696. __setup("show_lapic=", setup_show_lapic);
  697. static int __init print_ICs(void)
  698. {
  699. if (apic_verbosity == APIC_QUIET)
  700. return 0;
  701. print_PIC();
  702. /* don't print out if apic is not there */
  703. if (!cpu_has_apic && !apic_from_smp_config())
  704. return 0;
  705. print_local_APICs(show_lapic);
  706. print_IO_APICs();
  707. return 0;
  708. }
  709. late_initcall(print_ICs);