vector.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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;
  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, err;
  108. if (d->move_in_progress)
  109. return -EBUSY;
  110. /* Only try and allocate irqs on cpus that are present */
  111. err = -ENOSPC;
  112. cpumask_clear(d->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, vector_cpumask, mask);
  117. if (cpumask_subset(vector_cpumask, d->domain)) {
  118. err = 0;
  119. if (cpumask_equal(vector_cpumask, d->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(d->old_domain, d->domain,
  127. vector_cpumask);
  128. d->move_in_progress =
  129. cpumask_intersects(d->old_domain, cpu_online_mask);
  130. cpumask_and(d->domain, d->domain, vector_cpumask);
  131. break;
  132. }
  133. vector = current_vector;
  134. offset = current_offset;
  135. next:
  136. vector += 16;
  137. if (vector >= first_system_vector) {
  138. offset = (offset + 1) % 16;
  139. vector = FIRST_EXTERNAL_VECTOR + offset;
  140. }
  141. if (unlikely(current_vector == vector)) {
  142. cpumask_or(d->old_domain, d->old_domain,
  143. vector_cpumask);
  144. cpumask_andnot(vector_cpumask, mask, d->old_domain);
  145. cpu = cpumask_first_and(vector_cpumask,
  146. cpu_online_mask);
  147. continue;
  148. }
  149. if (test_bit(vector, used_vectors))
  150. goto next;
  151. for_each_cpu_and(new_cpu, vector_cpumask, cpu_online_mask) {
  152. if (!IS_ERR_OR_NULL(per_cpu(vector_irq, new_cpu)[vector]))
  153. goto next;
  154. }
  155. /* Found one! */
  156. current_vector = vector;
  157. current_offset = offset;
  158. if (d->cfg.vector) {
  159. cpumask_copy(d->old_domain, d->domain);
  160. d->move_in_progress =
  161. cpumask_intersects(d->old_domain, cpu_online_mask);
  162. }
  163. for_each_cpu_and(new_cpu, vector_cpumask, cpu_online_mask)
  164. per_cpu(vector_irq, new_cpu)[vector] = irq_to_desc(irq);
  165. d->cfg.vector = vector;
  166. cpumask_copy(d->domain, vector_cpumask);
  167. err = 0;
  168. break;
  169. }
  170. if (!err) {
  171. /* cache destination APIC IDs into cfg->dest_apicid */
  172. err = apic->cpu_mask_to_apicid_and(mask, d->domain,
  173. &d->cfg.dest_apicid);
  174. }
  175. return err;
  176. }
  177. static int assign_irq_vector(int irq, struct apic_chip_data *data,
  178. const struct cpumask *mask)
  179. {
  180. int err;
  181. unsigned long flags;
  182. raw_spin_lock_irqsave(&vector_lock, flags);
  183. err = __assign_irq_vector(irq, data, mask);
  184. raw_spin_unlock_irqrestore(&vector_lock, flags);
  185. return err;
  186. }
  187. static int assign_irq_vector_policy(int irq, int node,
  188. struct apic_chip_data *data,
  189. struct irq_alloc_info *info)
  190. {
  191. if (info && info->mask)
  192. return assign_irq_vector(irq, data, info->mask);
  193. if (node != NUMA_NO_NODE &&
  194. assign_irq_vector(irq, data, cpumask_of_node(node)) == 0)
  195. return 0;
  196. return assign_irq_vector(irq, data, apic->target_cpus());
  197. }
  198. static void clear_irq_vector(int irq, struct apic_chip_data *data)
  199. {
  200. struct irq_desc *desc;
  201. unsigned long flags;
  202. int cpu, vector;
  203. raw_spin_lock_irqsave(&vector_lock, flags);
  204. BUG_ON(!data->cfg.vector);
  205. vector = data->cfg.vector;
  206. for_each_cpu_and(cpu, data->domain, cpu_online_mask)
  207. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED;
  208. data->cfg.vector = 0;
  209. cpumask_clear(data->domain);
  210. if (likely(!data->move_in_progress)) {
  211. raw_spin_unlock_irqrestore(&vector_lock, flags);
  212. return;
  213. }
  214. desc = irq_to_desc(irq);
  215. for_each_cpu_and(cpu, data->old_domain, cpu_online_mask) {
  216. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS;
  217. vector++) {
  218. if (per_cpu(vector_irq, cpu)[vector] != desc)
  219. continue;
  220. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED;
  221. break;
  222. }
  223. }
  224. data->move_in_progress = 0;
  225. raw_spin_unlock_irqrestore(&vector_lock, flags);
  226. }
  227. void init_irq_alloc_info(struct irq_alloc_info *info,
  228. const struct cpumask *mask)
  229. {
  230. memset(info, 0, sizeof(*info));
  231. info->mask = mask;
  232. }
  233. void copy_irq_alloc_info(struct irq_alloc_info *dst, struct irq_alloc_info *src)
  234. {
  235. if (src)
  236. *dst = *src;
  237. else
  238. memset(dst, 0, sizeof(*dst));
  239. }
  240. static void x86_vector_free_irqs(struct irq_domain *domain,
  241. unsigned int virq, unsigned int nr_irqs)
  242. {
  243. struct irq_data *irq_data;
  244. int i;
  245. for (i = 0; i < nr_irqs; i++) {
  246. irq_data = irq_domain_get_irq_data(x86_vector_domain, virq + i);
  247. if (irq_data && irq_data->chip_data) {
  248. clear_irq_vector(virq + i, irq_data->chip_data);
  249. free_apic_chip_data(irq_data->chip_data);
  250. #ifdef CONFIG_X86_IO_APIC
  251. if (virq + i < nr_legacy_irqs())
  252. legacy_irq_data[virq + i] = NULL;
  253. #endif
  254. irq_domain_reset_irq_data(irq_data);
  255. }
  256. }
  257. }
  258. static int x86_vector_alloc_irqs(struct irq_domain *domain, unsigned int virq,
  259. unsigned int nr_irqs, void *arg)
  260. {
  261. struct irq_alloc_info *info = arg;
  262. struct apic_chip_data *data;
  263. struct irq_data *irq_data;
  264. int i, err, node;
  265. if (disable_apic)
  266. return -ENXIO;
  267. /* Currently vector allocator can't guarantee contiguous allocations */
  268. if ((info->flags & X86_IRQ_ALLOC_CONTIGUOUS_VECTORS) && nr_irqs > 1)
  269. return -ENOSYS;
  270. for (i = 0; i < nr_irqs; i++) {
  271. irq_data = irq_domain_get_irq_data(domain, virq + i);
  272. BUG_ON(!irq_data);
  273. node = irq_data_get_node(irq_data);
  274. #ifdef CONFIG_X86_IO_APIC
  275. if (virq + i < nr_legacy_irqs() && legacy_irq_data[virq + i])
  276. data = legacy_irq_data[virq + i];
  277. else
  278. #endif
  279. data = alloc_apic_chip_data(node);
  280. if (!data) {
  281. err = -ENOMEM;
  282. goto error;
  283. }
  284. irq_data->chip = &lapic_controller;
  285. irq_data->chip_data = data;
  286. irq_data->hwirq = virq + i;
  287. err = assign_irq_vector_policy(virq + i, node, data, info);
  288. if (err)
  289. goto error;
  290. }
  291. return 0;
  292. error:
  293. x86_vector_free_irqs(domain, virq, i + 1);
  294. return err;
  295. }
  296. static const struct irq_domain_ops x86_vector_domain_ops = {
  297. .alloc = x86_vector_alloc_irqs,
  298. .free = x86_vector_free_irqs,
  299. };
  300. int __init arch_probe_nr_irqs(void)
  301. {
  302. int nr;
  303. if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
  304. nr_irqs = NR_VECTORS * nr_cpu_ids;
  305. nr = (gsi_top + nr_legacy_irqs()) + 8 * nr_cpu_ids;
  306. #if defined(CONFIG_PCI_MSI) || defined(CONFIG_HT_IRQ)
  307. /*
  308. * for MSI and HT dyn irq
  309. */
  310. if (gsi_top <= NR_IRQS_LEGACY)
  311. nr += 8 * nr_cpu_ids;
  312. else
  313. nr += gsi_top * 16;
  314. #endif
  315. if (nr < nr_irqs)
  316. nr_irqs = nr;
  317. /*
  318. * We don't know if PIC is present at this point so we need to do
  319. * probe() to get the right number of legacy IRQs.
  320. */
  321. return legacy_pic->probe();
  322. }
  323. #ifdef CONFIG_X86_IO_APIC
  324. static void init_legacy_irqs(void)
  325. {
  326. int i, node = cpu_to_node(0);
  327. struct apic_chip_data *data;
  328. /*
  329. * For legacy IRQ's, start with assigning irq0 to irq15 to
  330. * ISA_IRQ_VECTOR(i) for all cpu's.
  331. */
  332. for (i = 0; i < nr_legacy_irqs(); i++) {
  333. data = legacy_irq_data[i] = alloc_apic_chip_data(node);
  334. BUG_ON(!data);
  335. data->cfg.vector = ISA_IRQ_VECTOR(i);
  336. cpumask_setall(data->domain);
  337. irq_set_chip_data(i, data);
  338. }
  339. }
  340. #else
  341. static void init_legacy_irqs(void) { }
  342. #endif
  343. int __init arch_early_irq_init(void)
  344. {
  345. init_legacy_irqs();
  346. x86_vector_domain = irq_domain_add_tree(NULL, &x86_vector_domain_ops,
  347. NULL);
  348. BUG_ON(x86_vector_domain == NULL);
  349. irq_set_default_host(x86_vector_domain);
  350. arch_init_msi_domain(x86_vector_domain);
  351. arch_init_htirq_domain(x86_vector_domain);
  352. BUG_ON(!alloc_cpumask_var(&vector_cpumask, GFP_KERNEL));
  353. return arch_early_ioapic_init();
  354. }
  355. /* Initialize vector_irq on a new cpu */
  356. static void __setup_vector_irq(int cpu)
  357. {
  358. struct apic_chip_data *data;
  359. struct irq_desc *desc;
  360. int irq, vector;
  361. /* Mark the inuse vectors */
  362. for_each_irq_desc(irq, desc) {
  363. struct irq_data *idata = irq_desc_get_irq_data(desc);
  364. data = apic_chip_data(idata);
  365. if (!data || !cpumask_test_cpu(cpu, data->domain))
  366. continue;
  367. vector = data->cfg.vector;
  368. per_cpu(vector_irq, cpu)[vector] = desc;
  369. }
  370. /* Mark the free vectors */
  371. for (vector = 0; vector < NR_VECTORS; ++vector) {
  372. desc = per_cpu(vector_irq, cpu)[vector];
  373. if (IS_ERR_OR_NULL(desc))
  374. continue;
  375. data = apic_chip_data(irq_desc_get_irq_data(desc));
  376. if (!cpumask_test_cpu(cpu, data->domain))
  377. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED;
  378. }
  379. }
  380. /*
  381. * Setup the vector to irq mappings. Must be called with vector_lock held.
  382. */
  383. void setup_vector_irq(int cpu)
  384. {
  385. int irq;
  386. lockdep_assert_held(&vector_lock);
  387. /*
  388. * On most of the platforms, legacy PIC delivers the interrupts on the
  389. * boot cpu. But there are certain platforms where PIC interrupts are
  390. * delivered to multiple cpu's. If the legacy IRQ is handled by the
  391. * legacy PIC, for the new cpu that is coming online, setup the static
  392. * legacy vector to irq mapping:
  393. */
  394. for (irq = 0; irq < nr_legacy_irqs(); irq++)
  395. per_cpu(vector_irq, cpu)[ISA_IRQ_VECTOR(irq)] = irq_to_desc(irq);
  396. __setup_vector_irq(cpu);
  397. }
  398. static int apic_retrigger_irq(struct irq_data *irq_data)
  399. {
  400. struct apic_chip_data *data = apic_chip_data(irq_data);
  401. unsigned long flags;
  402. int cpu;
  403. raw_spin_lock_irqsave(&vector_lock, flags);
  404. cpu = cpumask_first_and(data->domain, cpu_online_mask);
  405. apic->send_IPI_mask(cpumask_of(cpu), data->cfg.vector);
  406. raw_spin_unlock_irqrestore(&vector_lock, flags);
  407. return 1;
  408. }
  409. void apic_ack_edge(struct irq_data *data)
  410. {
  411. irq_complete_move(irqd_cfg(data));
  412. irq_move_irq(data);
  413. ack_APIC_irq();
  414. }
  415. static int apic_set_affinity(struct irq_data *irq_data,
  416. const struct cpumask *dest, bool force)
  417. {
  418. struct apic_chip_data *data = irq_data->chip_data;
  419. int err, irq = irq_data->irq;
  420. if (!config_enabled(CONFIG_SMP))
  421. return -EPERM;
  422. if (!cpumask_intersects(dest, cpu_online_mask))
  423. return -EINVAL;
  424. err = assign_irq_vector(irq, data, dest);
  425. if (err) {
  426. if (assign_irq_vector(irq, data,
  427. irq_data_get_affinity_mask(irq_data)))
  428. pr_err("Failed to recover vector for irq %d\n", irq);
  429. return err;
  430. }
  431. return IRQ_SET_MASK_OK;
  432. }
  433. static struct irq_chip lapic_controller = {
  434. .irq_ack = apic_ack_edge,
  435. .irq_set_affinity = apic_set_affinity,
  436. .irq_retrigger = apic_retrigger_irq,
  437. };
  438. #ifdef CONFIG_SMP
  439. static void __send_cleanup_vector(struct apic_chip_data *data)
  440. {
  441. cpumask_var_t cleanup_mask;
  442. if (unlikely(!alloc_cpumask_var(&cleanup_mask, GFP_ATOMIC))) {
  443. unsigned int i;
  444. for_each_cpu_and(i, data->old_domain, cpu_online_mask)
  445. apic->send_IPI_mask(cpumask_of(i),
  446. IRQ_MOVE_CLEANUP_VECTOR);
  447. } else {
  448. cpumask_and(cleanup_mask, data->old_domain, cpu_online_mask);
  449. apic->send_IPI_mask(cleanup_mask, IRQ_MOVE_CLEANUP_VECTOR);
  450. free_cpumask_var(cleanup_mask);
  451. }
  452. data->move_in_progress = 0;
  453. }
  454. void send_cleanup_vector(struct irq_cfg *cfg)
  455. {
  456. struct apic_chip_data *data;
  457. data = container_of(cfg, struct apic_chip_data, cfg);
  458. if (data->move_in_progress)
  459. __send_cleanup_vector(data);
  460. }
  461. asmlinkage __visible void smp_irq_move_cleanup_interrupt(void)
  462. {
  463. unsigned vector, me;
  464. entering_ack_irq();
  465. /* Prevent vectors vanishing under us */
  466. raw_spin_lock(&vector_lock);
  467. me = smp_processor_id();
  468. for (vector = FIRST_EXTERNAL_VECTOR; vector < NR_VECTORS; vector++) {
  469. struct apic_chip_data *data;
  470. struct irq_desc *desc;
  471. unsigned int irr;
  472. retry:
  473. desc = __this_cpu_read(vector_irq[vector]);
  474. if (IS_ERR_OR_NULL(desc))
  475. continue;
  476. if (!raw_spin_trylock(&desc->lock)) {
  477. raw_spin_unlock(&vector_lock);
  478. cpu_relax();
  479. raw_spin_lock(&vector_lock);
  480. goto retry;
  481. }
  482. data = apic_chip_data(irq_desc_get_irq_data(desc));
  483. if (!data)
  484. goto unlock;
  485. /*
  486. * Check if the irq migration is in progress. If so, we
  487. * haven't received the cleanup request yet for this irq.
  488. */
  489. if (data->move_in_progress)
  490. goto unlock;
  491. if (vector == data->cfg.vector &&
  492. cpumask_test_cpu(me, data->domain))
  493. goto unlock;
  494. irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
  495. /*
  496. * Check if the vector that needs to be cleanedup is
  497. * registered at the cpu's IRR. If so, then this is not
  498. * the best time to clean it up. Lets clean it up in the
  499. * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
  500. * to myself.
  501. */
  502. if (irr & (1 << (vector % 32))) {
  503. apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
  504. goto unlock;
  505. }
  506. __this_cpu_write(vector_irq[vector], VECTOR_UNUSED);
  507. unlock:
  508. raw_spin_unlock(&desc->lock);
  509. }
  510. raw_spin_unlock(&vector_lock);
  511. exiting_irq();
  512. }
  513. static void __irq_complete_move(struct irq_cfg *cfg, unsigned vector)
  514. {
  515. unsigned me;
  516. struct apic_chip_data *data;
  517. data = container_of(cfg, struct apic_chip_data, cfg);
  518. if (likely(!data->move_in_progress))
  519. return;
  520. me = smp_processor_id();
  521. if (vector == data->cfg.vector && cpumask_test_cpu(me, data->domain))
  522. __send_cleanup_vector(data);
  523. }
  524. void irq_complete_move(struct irq_cfg *cfg)
  525. {
  526. __irq_complete_move(cfg, ~get_irq_regs()->orig_ax);
  527. }
  528. void irq_force_complete_move(int irq)
  529. {
  530. struct irq_cfg *cfg = irq_cfg(irq);
  531. if (cfg)
  532. __irq_complete_move(cfg, cfg->vector);
  533. }
  534. #endif
  535. static void __init print_APIC_field(int base)
  536. {
  537. int i;
  538. printk(KERN_DEBUG);
  539. for (i = 0; i < 8; i++)
  540. pr_cont("%08x", apic_read(base + i*0x10));
  541. pr_cont("\n");
  542. }
  543. static void __init print_local_APIC(void *dummy)
  544. {
  545. unsigned int i, v, ver, maxlvt;
  546. u64 icr;
  547. pr_debug("printing local APIC contents on CPU#%d/%d:\n",
  548. smp_processor_id(), hard_smp_processor_id());
  549. v = apic_read(APIC_ID);
  550. pr_info("... APIC ID: %08x (%01x)\n", v, read_apic_id());
  551. v = apic_read(APIC_LVR);
  552. pr_info("... APIC VERSION: %08x\n", v);
  553. ver = GET_APIC_VERSION(v);
  554. maxlvt = lapic_get_maxlvt();
  555. v = apic_read(APIC_TASKPRI);
  556. pr_debug("... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
  557. /* !82489DX */
  558. if (APIC_INTEGRATED(ver)) {
  559. if (!APIC_XAPIC(ver)) {
  560. v = apic_read(APIC_ARBPRI);
  561. pr_debug("... APIC ARBPRI: %08x (%02x)\n",
  562. v, v & APIC_ARBPRI_MASK);
  563. }
  564. v = apic_read(APIC_PROCPRI);
  565. pr_debug("... APIC PROCPRI: %08x\n", v);
  566. }
  567. /*
  568. * Remote read supported only in the 82489DX and local APIC for
  569. * Pentium processors.
  570. */
  571. if (!APIC_INTEGRATED(ver) || maxlvt == 3) {
  572. v = apic_read(APIC_RRR);
  573. pr_debug("... APIC RRR: %08x\n", v);
  574. }
  575. v = apic_read(APIC_LDR);
  576. pr_debug("... APIC LDR: %08x\n", v);
  577. if (!x2apic_enabled()) {
  578. v = apic_read(APIC_DFR);
  579. pr_debug("... APIC DFR: %08x\n", v);
  580. }
  581. v = apic_read(APIC_SPIV);
  582. pr_debug("... APIC SPIV: %08x\n", v);
  583. pr_debug("... APIC ISR field:\n");
  584. print_APIC_field(APIC_ISR);
  585. pr_debug("... APIC TMR field:\n");
  586. print_APIC_field(APIC_TMR);
  587. pr_debug("... APIC IRR field:\n");
  588. print_APIC_field(APIC_IRR);
  589. /* !82489DX */
  590. if (APIC_INTEGRATED(ver)) {
  591. /* Due to the Pentium erratum 3AP. */
  592. if (maxlvt > 3)
  593. apic_write(APIC_ESR, 0);
  594. v = apic_read(APIC_ESR);
  595. pr_debug("... APIC ESR: %08x\n", v);
  596. }
  597. icr = apic_icr_read();
  598. pr_debug("... APIC ICR: %08x\n", (u32)icr);
  599. pr_debug("... APIC ICR2: %08x\n", (u32)(icr >> 32));
  600. v = apic_read(APIC_LVTT);
  601. pr_debug("... APIC LVTT: %08x\n", v);
  602. if (maxlvt > 3) {
  603. /* PC is LVT#4. */
  604. v = apic_read(APIC_LVTPC);
  605. pr_debug("... APIC LVTPC: %08x\n", v);
  606. }
  607. v = apic_read(APIC_LVT0);
  608. pr_debug("... APIC LVT0: %08x\n", v);
  609. v = apic_read(APIC_LVT1);
  610. pr_debug("... APIC LVT1: %08x\n", v);
  611. if (maxlvt > 2) {
  612. /* ERR is LVT#3. */
  613. v = apic_read(APIC_LVTERR);
  614. pr_debug("... APIC LVTERR: %08x\n", v);
  615. }
  616. v = apic_read(APIC_TMICT);
  617. pr_debug("... APIC TMICT: %08x\n", v);
  618. v = apic_read(APIC_TMCCT);
  619. pr_debug("... APIC TMCCT: %08x\n", v);
  620. v = apic_read(APIC_TDCR);
  621. pr_debug("... APIC TDCR: %08x\n", v);
  622. if (boot_cpu_has(X86_FEATURE_EXTAPIC)) {
  623. v = apic_read(APIC_EFEAT);
  624. maxlvt = (v >> 16) & 0xff;
  625. pr_debug("... APIC EFEAT: %08x\n", v);
  626. v = apic_read(APIC_ECTRL);
  627. pr_debug("... APIC ECTRL: %08x\n", v);
  628. for (i = 0; i < maxlvt; i++) {
  629. v = apic_read(APIC_EILVTn(i));
  630. pr_debug("... APIC EILVT%d: %08x\n", i, v);
  631. }
  632. }
  633. pr_cont("\n");
  634. }
  635. static void __init print_local_APICs(int maxcpu)
  636. {
  637. int cpu;
  638. if (!maxcpu)
  639. return;
  640. preempt_disable();
  641. for_each_online_cpu(cpu) {
  642. if (cpu >= maxcpu)
  643. break;
  644. smp_call_function_single(cpu, print_local_APIC, NULL, 1);
  645. }
  646. preempt_enable();
  647. }
  648. static void __init print_PIC(void)
  649. {
  650. unsigned int v;
  651. unsigned long flags;
  652. if (!nr_legacy_irqs())
  653. return;
  654. pr_debug("\nprinting PIC contents\n");
  655. raw_spin_lock_irqsave(&i8259A_lock, flags);
  656. v = inb(0xa1) << 8 | inb(0x21);
  657. pr_debug("... PIC IMR: %04x\n", v);
  658. v = inb(0xa0) << 8 | inb(0x20);
  659. pr_debug("... PIC IRR: %04x\n", v);
  660. outb(0x0b, 0xa0);
  661. outb(0x0b, 0x20);
  662. v = inb(0xa0) << 8 | inb(0x20);
  663. outb(0x0a, 0xa0);
  664. outb(0x0a, 0x20);
  665. raw_spin_unlock_irqrestore(&i8259A_lock, flags);
  666. pr_debug("... PIC ISR: %04x\n", v);
  667. v = inb(0x4d1) << 8 | inb(0x4d0);
  668. pr_debug("... PIC ELCR: %04x\n", v);
  669. }
  670. static int show_lapic __initdata = 1;
  671. static __init int setup_show_lapic(char *arg)
  672. {
  673. int num = -1;
  674. if (strcmp(arg, "all") == 0) {
  675. show_lapic = CONFIG_NR_CPUS;
  676. } else {
  677. get_option(&arg, &num);
  678. if (num >= 0)
  679. show_lapic = num;
  680. }
  681. return 1;
  682. }
  683. __setup("show_lapic=", setup_show_lapic);
  684. static int __init print_ICs(void)
  685. {
  686. if (apic_verbosity == APIC_QUIET)
  687. return 0;
  688. print_PIC();
  689. /* don't print out if apic is not there */
  690. if (!cpu_has_apic && !apic_from_smp_config())
  691. return 0;
  692. print_local_APICs(show_lapic);
  693. print_IO_APICs();
  694. return 0;
  695. }
  696. late_initcall(print_ICs);