vector.c 19 KB

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