vector.c 19 KB

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