vector.c 20 KB

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