vector.c 19 KB

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