vector.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255
  1. /*
  2. * Local APIC related interfaces to support IOAPIC, MSI, 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/seq_file.h>
  15. #include <linux/init.h>
  16. #include <linux/compiler.h>
  17. #include <linux/slab.h>
  18. #include <asm/irqdomain.h>
  19. #include <asm/hw_irq.h>
  20. #include <asm/apic.h>
  21. #include <asm/i8259.h>
  22. #include <asm/desc.h>
  23. #include <asm/irq_remapping.h>
  24. #include <asm/trace/irq_vectors.h>
  25. struct apic_chip_data {
  26. struct irq_cfg hw_irq_cfg;
  27. unsigned int vector;
  28. unsigned int prev_vector;
  29. unsigned int cpu;
  30. unsigned int prev_cpu;
  31. unsigned int irq;
  32. struct hlist_node clist;
  33. unsigned int move_in_progress : 1,
  34. is_managed : 1,
  35. can_reserve : 1,
  36. has_reserved : 1;
  37. };
  38. struct irq_domain *x86_vector_domain;
  39. EXPORT_SYMBOL_GPL(x86_vector_domain);
  40. static DEFINE_RAW_SPINLOCK(vector_lock);
  41. static cpumask_var_t vector_searchmask;
  42. static struct irq_chip lapic_controller;
  43. static struct irq_matrix *vector_matrix;
  44. #ifdef CONFIG_SMP
  45. static DEFINE_PER_CPU(struct hlist_head, cleanup_list);
  46. #endif
  47. void lock_vector_lock(void)
  48. {
  49. /* Used to the online set of cpus does not change
  50. * during assign_irq_vector.
  51. */
  52. raw_spin_lock(&vector_lock);
  53. }
  54. void unlock_vector_lock(void)
  55. {
  56. raw_spin_unlock(&vector_lock);
  57. }
  58. void init_irq_alloc_info(struct irq_alloc_info *info,
  59. const struct cpumask *mask)
  60. {
  61. memset(info, 0, sizeof(*info));
  62. info->mask = mask;
  63. }
  64. void copy_irq_alloc_info(struct irq_alloc_info *dst, struct irq_alloc_info *src)
  65. {
  66. if (src)
  67. *dst = *src;
  68. else
  69. memset(dst, 0, sizeof(*dst));
  70. }
  71. static struct apic_chip_data *apic_chip_data(struct irq_data *irqd)
  72. {
  73. if (!irqd)
  74. return NULL;
  75. while (irqd->parent_data)
  76. irqd = irqd->parent_data;
  77. return irqd->chip_data;
  78. }
  79. struct irq_cfg *irqd_cfg(struct irq_data *irqd)
  80. {
  81. struct apic_chip_data *apicd = apic_chip_data(irqd);
  82. return apicd ? &apicd->hw_irq_cfg : NULL;
  83. }
  84. EXPORT_SYMBOL_GPL(irqd_cfg);
  85. struct irq_cfg *irq_cfg(unsigned int irq)
  86. {
  87. return irqd_cfg(irq_get_irq_data(irq));
  88. }
  89. static struct apic_chip_data *alloc_apic_chip_data(int node)
  90. {
  91. struct apic_chip_data *apicd;
  92. apicd = kzalloc_node(sizeof(*apicd), GFP_KERNEL, node);
  93. if (apicd)
  94. INIT_HLIST_NODE(&apicd->clist);
  95. return apicd;
  96. }
  97. static void free_apic_chip_data(struct apic_chip_data *apicd)
  98. {
  99. kfree(apicd);
  100. }
  101. static void apic_update_irq_cfg(struct irq_data *irqd, unsigned int vector,
  102. unsigned int cpu)
  103. {
  104. struct apic_chip_data *apicd = apic_chip_data(irqd);
  105. lockdep_assert_held(&vector_lock);
  106. apicd->hw_irq_cfg.vector = vector;
  107. apicd->hw_irq_cfg.dest_apicid = apic->calc_dest_apicid(cpu);
  108. irq_data_update_effective_affinity(irqd, cpumask_of(cpu));
  109. trace_vector_config(irqd->irq, vector, cpu,
  110. apicd->hw_irq_cfg.dest_apicid);
  111. }
  112. static void apic_update_vector(struct irq_data *irqd, unsigned int newvec,
  113. unsigned int newcpu)
  114. {
  115. struct apic_chip_data *apicd = apic_chip_data(irqd);
  116. struct irq_desc *desc = irq_data_to_desc(irqd);
  117. bool managed = irqd_affinity_is_managed(irqd);
  118. lockdep_assert_held(&vector_lock);
  119. trace_vector_update(irqd->irq, newvec, newcpu, apicd->vector,
  120. apicd->cpu);
  121. /*
  122. * If there is no vector associated or if the associated vector is
  123. * the shutdown vector, which is associated to make PCI/MSI
  124. * shutdown mode work, then there is nothing to release. Clear out
  125. * prev_vector for this and the offlined target case.
  126. */
  127. apicd->prev_vector = 0;
  128. if (!apicd->vector || apicd->vector == MANAGED_IRQ_SHUTDOWN_VECTOR)
  129. goto setnew;
  130. /*
  131. * If the target CPU of the previous vector is online, then mark
  132. * the vector as move in progress and store it for cleanup when the
  133. * first interrupt on the new vector arrives. If the target CPU is
  134. * offline then the regular release mechanism via the cleanup
  135. * vector is not possible and the vector can be immediately freed
  136. * in the underlying matrix allocator.
  137. */
  138. if (cpu_online(apicd->cpu)) {
  139. apicd->move_in_progress = true;
  140. apicd->prev_vector = apicd->vector;
  141. apicd->prev_cpu = apicd->cpu;
  142. } else {
  143. irq_matrix_free(vector_matrix, apicd->cpu, apicd->vector,
  144. managed);
  145. }
  146. setnew:
  147. apicd->vector = newvec;
  148. apicd->cpu = newcpu;
  149. BUG_ON(!IS_ERR_OR_NULL(per_cpu(vector_irq, newcpu)[newvec]));
  150. per_cpu(vector_irq, newcpu)[newvec] = desc;
  151. }
  152. static void vector_assign_managed_shutdown(struct irq_data *irqd)
  153. {
  154. unsigned int cpu = cpumask_first(cpu_online_mask);
  155. apic_update_irq_cfg(irqd, MANAGED_IRQ_SHUTDOWN_VECTOR, cpu);
  156. }
  157. static int reserve_managed_vector(struct irq_data *irqd)
  158. {
  159. const struct cpumask *affmsk = irq_data_get_affinity_mask(irqd);
  160. struct apic_chip_data *apicd = apic_chip_data(irqd);
  161. unsigned long flags;
  162. int ret;
  163. raw_spin_lock_irqsave(&vector_lock, flags);
  164. apicd->is_managed = true;
  165. ret = irq_matrix_reserve_managed(vector_matrix, affmsk);
  166. raw_spin_unlock_irqrestore(&vector_lock, flags);
  167. trace_vector_reserve_managed(irqd->irq, ret);
  168. return ret;
  169. }
  170. static void reserve_irq_vector_locked(struct irq_data *irqd)
  171. {
  172. struct apic_chip_data *apicd = apic_chip_data(irqd);
  173. irq_matrix_reserve(vector_matrix);
  174. apicd->can_reserve = true;
  175. apicd->has_reserved = true;
  176. irqd_set_can_reserve(irqd);
  177. trace_vector_reserve(irqd->irq, 0);
  178. vector_assign_managed_shutdown(irqd);
  179. }
  180. static int reserve_irq_vector(struct irq_data *irqd)
  181. {
  182. unsigned long flags;
  183. raw_spin_lock_irqsave(&vector_lock, flags);
  184. reserve_irq_vector_locked(irqd);
  185. raw_spin_unlock_irqrestore(&vector_lock, flags);
  186. return 0;
  187. }
  188. static int allocate_vector(struct irq_data *irqd, const struct cpumask *dest)
  189. {
  190. struct apic_chip_data *apicd = apic_chip_data(irqd);
  191. bool resvd = apicd->has_reserved;
  192. unsigned int cpu = apicd->cpu;
  193. int vector = apicd->vector;
  194. lockdep_assert_held(&vector_lock);
  195. /*
  196. * If the current target CPU is online and in the new requested
  197. * affinity mask, there is no point in moving the interrupt from
  198. * one CPU to another.
  199. */
  200. if (vector && cpu_online(cpu) && cpumask_test_cpu(cpu, dest))
  201. return 0;
  202. /*
  203. * Careful here. @apicd might either have move_in_progress set or
  204. * be enqueued for cleanup. Assigning a new vector would either
  205. * leave a stale vector on some CPU around or in case of a pending
  206. * cleanup corrupt the hlist.
  207. */
  208. if (apicd->move_in_progress || !hlist_unhashed(&apicd->clist))
  209. return -EBUSY;
  210. vector = irq_matrix_alloc(vector_matrix, dest, resvd, &cpu);
  211. if (vector > 0)
  212. apic_update_vector(irqd, vector, cpu);
  213. trace_vector_alloc(irqd->irq, vector, resvd, vector);
  214. return vector;
  215. }
  216. static int assign_vector_locked(struct irq_data *irqd,
  217. const struct cpumask *dest)
  218. {
  219. struct apic_chip_data *apicd = apic_chip_data(irqd);
  220. int vector = allocate_vector(irqd, dest);
  221. if (vector < 0)
  222. return vector;
  223. apic_update_irq_cfg(irqd, apicd->vector, apicd->cpu);
  224. return 0;
  225. }
  226. static int assign_irq_vector(struct irq_data *irqd, const struct cpumask *dest)
  227. {
  228. unsigned long flags;
  229. int ret;
  230. raw_spin_lock_irqsave(&vector_lock, flags);
  231. cpumask_and(vector_searchmask, dest, cpu_online_mask);
  232. ret = assign_vector_locked(irqd, vector_searchmask);
  233. raw_spin_unlock_irqrestore(&vector_lock, flags);
  234. return ret;
  235. }
  236. static int assign_irq_vector_any_locked(struct irq_data *irqd)
  237. {
  238. /* Get the affinity mask - either irq_default_affinity or (user) set */
  239. const struct cpumask *affmsk = irq_data_get_affinity_mask(irqd);
  240. int node = irq_data_get_node(irqd);
  241. if (node == NUMA_NO_NODE)
  242. goto all;
  243. /* Try the intersection of @affmsk and node mask */
  244. cpumask_and(vector_searchmask, cpumask_of_node(node), affmsk);
  245. if (!assign_vector_locked(irqd, vector_searchmask))
  246. return 0;
  247. /* Try the node mask */
  248. if (!assign_vector_locked(irqd, cpumask_of_node(node)))
  249. return 0;
  250. all:
  251. /* Try the full affinity mask */
  252. cpumask_and(vector_searchmask, affmsk, cpu_online_mask);
  253. if (!assign_vector_locked(irqd, vector_searchmask))
  254. return 0;
  255. /* Try the full online mask */
  256. return assign_vector_locked(irqd, cpu_online_mask);
  257. }
  258. static int
  259. assign_irq_vector_policy(struct irq_data *irqd, struct irq_alloc_info *info)
  260. {
  261. if (irqd_affinity_is_managed(irqd))
  262. return reserve_managed_vector(irqd);
  263. if (info->mask)
  264. return assign_irq_vector(irqd, info->mask);
  265. /*
  266. * Make only a global reservation with no guarantee. A real vector
  267. * is associated at activation time.
  268. */
  269. return reserve_irq_vector(irqd);
  270. }
  271. static int
  272. assign_managed_vector(struct irq_data *irqd, const struct cpumask *dest)
  273. {
  274. const struct cpumask *affmsk = irq_data_get_affinity_mask(irqd);
  275. struct apic_chip_data *apicd = apic_chip_data(irqd);
  276. int vector, cpu;
  277. cpumask_and(vector_searchmask, vector_searchmask, affmsk);
  278. cpu = cpumask_first(vector_searchmask);
  279. if (cpu >= nr_cpu_ids)
  280. return -EINVAL;
  281. /* set_affinity might call here for nothing */
  282. if (apicd->vector && cpumask_test_cpu(apicd->cpu, vector_searchmask))
  283. return 0;
  284. vector = irq_matrix_alloc_managed(vector_matrix, cpu);
  285. trace_vector_alloc_managed(irqd->irq, vector, vector);
  286. if (vector < 0)
  287. return vector;
  288. apic_update_vector(irqd, vector, cpu);
  289. apic_update_irq_cfg(irqd, vector, cpu);
  290. return 0;
  291. }
  292. static void clear_irq_vector(struct irq_data *irqd)
  293. {
  294. struct apic_chip_data *apicd = apic_chip_data(irqd);
  295. bool managed = irqd_affinity_is_managed(irqd);
  296. unsigned int vector = apicd->vector;
  297. lockdep_assert_held(&vector_lock);
  298. if (!vector)
  299. return;
  300. trace_vector_clear(irqd->irq, vector, apicd->cpu, apicd->prev_vector,
  301. apicd->prev_cpu);
  302. per_cpu(vector_irq, apicd->cpu)[vector] = VECTOR_UNUSED;
  303. irq_matrix_free(vector_matrix, apicd->cpu, vector, managed);
  304. apicd->vector = 0;
  305. /* Clean up move in progress */
  306. vector = apicd->prev_vector;
  307. if (!vector)
  308. return;
  309. per_cpu(vector_irq, apicd->prev_cpu)[vector] = VECTOR_UNUSED;
  310. irq_matrix_free(vector_matrix, apicd->prev_cpu, vector, managed);
  311. apicd->prev_vector = 0;
  312. apicd->move_in_progress = 0;
  313. hlist_del_init(&apicd->clist);
  314. }
  315. static void x86_vector_deactivate(struct irq_domain *dom, struct irq_data *irqd)
  316. {
  317. struct apic_chip_data *apicd = apic_chip_data(irqd);
  318. unsigned long flags;
  319. trace_vector_deactivate(irqd->irq, apicd->is_managed,
  320. apicd->can_reserve, false);
  321. /* Regular fixed assigned interrupt */
  322. if (!apicd->is_managed && !apicd->can_reserve)
  323. return;
  324. /* If the interrupt has a global reservation, nothing to do */
  325. if (apicd->has_reserved)
  326. return;
  327. raw_spin_lock_irqsave(&vector_lock, flags);
  328. clear_irq_vector(irqd);
  329. if (apicd->can_reserve)
  330. reserve_irq_vector_locked(irqd);
  331. else
  332. vector_assign_managed_shutdown(irqd);
  333. raw_spin_unlock_irqrestore(&vector_lock, flags);
  334. }
  335. static int activate_reserved(struct irq_data *irqd)
  336. {
  337. struct apic_chip_data *apicd = apic_chip_data(irqd);
  338. int ret;
  339. ret = assign_irq_vector_any_locked(irqd);
  340. if (!ret) {
  341. apicd->has_reserved = false;
  342. /*
  343. * Core might have disabled reservation mode after
  344. * allocating the irq descriptor. Ideally this should
  345. * happen before allocation time, but that would require
  346. * completely convoluted ways of transporting that
  347. * information.
  348. */
  349. if (!irqd_can_reserve(irqd))
  350. apicd->can_reserve = false;
  351. }
  352. return ret;
  353. }
  354. static int activate_managed(struct irq_data *irqd)
  355. {
  356. const struct cpumask *dest = irq_data_get_affinity_mask(irqd);
  357. int ret;
  358. cpumask_and(vector_searchmask, dest, cpu_online_mask);
  359. if (WARN_ON_ONCE(cpumask_empty(vector_searchmask))) {
  360. /* Something in the core code broke! Survive gracefully */
  361. pr_err("Managed startup for irq %u, but no CPU\n", irqd->irq);
  362. return EINVAL;
  363. }
  364. ret = assign_managed_vector(irqd, vector_searchmask);
  365. /*
  366. * This should not happen. The vector reservation got buggered. Handle
  367. * it gracefully.
  368. */
  369. if (WARN_ON_ONCE(ret < 0)) {
  370. pr_err("Managed startup irq %u, no vector available\n",
  371. irqd->irq);
  372. }
  373. return ret;
  374. }
  375. static int x86_vector_activate(struct irq_domain *dom, struct irq_data *irqd,
  376. bool reserve)
  377. {
  378. struct apic_chip_data *apicd = apic_chip_data(irqd);
  379. unsigned long flags;
  380. int ret = 0;
  381. trace_vector_activate(irqd->irq, apicd->is_managed,
  382. apicd->can_reserve, reserve);
  383. /* Nothing to do for fixed assigned vectors */
  384. if (!apicd->can_reserve && !apicd->is_managed)
  385. return 0;
  386. raw_spin_lock_irqsave(&vector_lock, flags);
  387. if (reserve || irqd_is_managed_and_shutdown(irqd))
  388. vector_assign_managed_shutdown(irqd);
  389. else if (apicd->is_managed)
  390. ret = activate_managed(irqd);
  391. else if (apicd->has_reserved)
  392. ret = activate_reserved(irqd);
  393. raw_spin_unlock_irqrestore(&vector_lock, flags);
  394. return ret;
  395. }
  396. static void vector_free_reserved_and_managed(struct irq_data *irqd)
  397. {
  398. const struct cpumask *dest = irq_data_get_affinity_mask(irqd);
  399. struct apic_chip_data *apicd = apic_chip_data(irqd);
  400. trace_vector_teardown(irqd->irq, apicd->is_managed,
  401. apicd->has_reserved);
  402. if (apicd->has_reserved)
  403. irq_matrix_remove_reserved(vector_matrix);
  404. if (apicd->is_managed)
  405. irq_matrix_remove_managed(vector_matrix, dest);
  406. }
  407. static void x86_vector_free_irqs(struct irq_domain *domain,
  408. unsigned int virq, unsigned int nr_irqs)
  409. {
  410. struct apic_chip_data *apicd;
  411. struct irq_data *irqd;
  412. unsigned long flags;
  413. int i;
  414. for (i = 0; i < nr_irqs; i++) {
  415. irqd = irq_domain_get_irq_data(x86_vector_domain, virq + i);
  416. if (irqd && irqd->chip_data) {
  417. raw_spin_lock_irqsave(&vector_lock, flags);
  418. clear_irq_vector(irqd);
  419. vector_free_reserved_and_managed(irqd);
  420. apicd = irqd->chip_data;
  421. irq_domain_reset_irq_data(irqd);
  422. raw_spin_unlock_irqrestore(&vector_lock, flags);
  423. free_apic_chip_data(apicd);
  424. }
  425. }
  426. }
  427. static bool vector_configure_legacy(unsigned int virq, struct irq_data *irqd,
  428. struct apic_chip_data *apicd)
  429. {
  430. unsigned long flags;
  431. bool realloc = false;
  432. apicd->vector = ISA_IRQ_VECTOR(virq);
  433. apicd->cpu = 0;
  434. raw_spin_lock_irqsave(&vector_lock, flags);
  435. /*
  436. * If the interrupt is activated, then it must stay at this vector
  437. * position. That's usually the timer interrupt (0).
  438. */
  439. if (irqd_is_activated(irqd)) {
  440. trace_vector_setup(virq, true, 0);
  441. apic_update_irq_cfg(irqd, apicd->vector, apicd->cpu);
  442. } else {
  443. /* Release the vector */
  444. apicd->can_reserve = true;
  445. irqd_set_can_reserve(irqd);
  446. clear_irq_vector(irqd);
  447. realloc = true;
  448. }
  449. raw_spin_unlock_irqrestore(&vector_lock, flags);
  450. return realloc;
  451. }
  452. static int x86_vector_alloc_irqs(struct irq_domain *domain, unsigned int virq,
  453. unsigned int nr_irqs, void *arg)
  454. {
  455. struct irq_alloc_info *info = arg;
  456. struct apic_chip_data *apicd;
  457. struct irq_data *irqd;
  458. int i, err, node;
  459. if (disable_apic)
  460. return -ENXIO;
  461. /* Currently vector allocator can't guarantee contiguous allocations */
  462. if ((info->flags & X86_IRQ_ALLOC_CONTIGUOUS_VECTORS) && nr_irqs > 1)
  463. return -ENOSYS;
  464. for (i = 0; i < nr_irqs; i++) {
  465. irqd = irq_domain_get_irq_data(domain, virq + i);
  466. BUG_ON(!irqd);
  467. node = irq_data_get_node(irqd);
  468. WARN_ON_ONCE(irqd->chip_data);
  469. apicd = alloc_apic_chip_data(node);
  470. if (!apicd) {
  471. err = -ENOMEM;
  472. goto error;
  473. }
  474. apicd->irq = virq + i;
  475. irqd->chip = &lapic_controller;
  476. irqd->chip_data = apicd;
  477. irqd->hwirq = virq + i;
  478. irqd_set_single_target(irqd);
  479. /*
  480. * Legacy vectors are already assigned when the IOAPIC
  481. * takes them over. They stay on the same vector. This is
  482. * required for check_timer() to work correctly as it might
  483. * switch back to legacy mode. Only update the hardware
  484. * config.
  485. */
  486. if (info->flags & X86_IRQ_ALLOC_LEGACY) {
  487. if (!vector_configure_legacy(virq + i, irqd, apicd))
  488. continue;
  489. }
  490. err = assign_irq_vector_policy(irqd, info);
  491. trace_vector_setup(virq + i, false, err);
  492. if (err) {
  493. irqd->chip_data = NULL;
  494. free_apic_chip_data(apicd);
  495. goto error;
  496. }
  497. }
  498. return 0;
  499. error:
  500. x86_vector_free_irqs(domain, virq, i);
  501. return err;
  502. }
  503. #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
  504. static void x86_vector_debug_show(struct seq_file *m, struct irq_domain *d,
  505. struct irq_data *irqd, int ind)
  506. {
  507. struct apic_chip_data apicd;
  508. unsigned long flags;
  509. int irq;
  510. if (!irqd) {
  511. irq_matrix_debug_show(m, vector_matrix, ind);
  512. return;
  513. }
  514. irq = irqd->irq;
  515. if (irq < nr_legacy_irqs() && !test_bit(irq, &io_apic_irqs)) {
  516. seq_printf(m, "%*sVector: %5d\n", ind, "", ISA_IRQ_VECTOR(irq));
  517. seq_printf(m, "%*sTarget: Legacy PIC all CPUs\n", ind, "");
  518. return;
  519. }
  520. if (!irqd->chip_data) {
  521. seq_printf(m, "%*sVector: Not assigned\n", ind, "");
  522. return;
  523. }
  524. raw_spin_lock_irqsave(&vector_lock, flags);
  525. memcpy(&apicd, irqd->chip_data, sizeof(apicd));
  526. raw_spin_unlock_irqrestore(&vector_lock, flags);
  527. seq_printf(m, "%*sVector: %5u\n", ind, "", apicd.vector);
  528. seq_printf(m, "%*sTarget: %5u\n", ind, "", apicd.cpu);
  529. if (apicd.prev_vector) {
  530. seq_printf(m, "%*sPrevious vector: %5u\n", ind, "", apicd.prev_vector);
  531. seq_printf(m, "%*sPrevious target: %5u\n", ind, "", apicd.prev_cpu);
  532. }
  533. seq_printf(m, "%*smove_in_progress: %u\n", ind, "", apicd.move_in_progress ? 1 : 0);
  534. seq_printf(m, "%*sis_managed: %u\n", ind, "", apicd.is_managed ? 1 : 0);
  535. seq_printf(m, "%*scan_reserve: %u\n", ind, "", apicd.can_reserve ? 1 : 0);
  536. seq_printf(m, "%*shas_reserved: %u\n", ind, "", apicd.has_reserved ? 1 : 0);
  537. seq_printf(m, "%*scleanup_pending: %u\n", ind, "", !hlist_unhashed(&apicd.clist));
  538. }
  539. #endif
  540. static const struct irq_domain_ops x86_vector_domain_ops = {
  541. .alloc = x86_vector_alloc_irqs,
  542. .free = x86_vector_free_irqs,
  543. .activate = x86_vector_activate,
  544. .deactivate = x86_vector_deactivate,
  545. #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
  546. .debug_show = x86_vector_debug_show,
  547. #endif
  548. };
  549. int __init arch_probe_nr_irqs(void)
  550. {
  551. int nr;
  552. if (nr_irqs > (NR_VECTORS * nr_cpu_ids))
  553. nr_irqs = NR_VECTORS * nr_cpu_ids;
  554. nr = (gsi_top + nr_legacy_irqs()) + 8 * nr_cpu_ids;
  555. #if defined(CONFIG_PCI_MSI)
  556. /*
  557. * for MSI and HT dyn irq
  558. */
  559. if (gsi_top <= NR_IRQS_LEGACY)
  560. nr += 8 * nr_cpu_ids;
  561. else
  562. nr += gsi_top * 16;
  563. #endif
  564. if (nr < nr_irqs)
  565. nr_irqs = nr;
  566. /*
  567. * We don't know if PIC is present at this point so we need to do
  568. * probe() to get the right number of legacy IRQs.
  569. */
  570. return legacy_pic->probe();
  571. }
  572. void lapic_assign_legacy_vector(unsigned int irq, bool replace)
  573. {
  574. /*
  575. * Use assign system here so it wont get accounted as allocated
  576. * and moveable in the cpu hotplug check and it prevents managed
  577. * irq reservation from touching it.
  578. */
  579. irq_matrix_assign_system(vector_matrix, ISA_IRQ_VECTOR(irq), replace);
  580. }
  581. void __init lapic_assign_system_vectors(void)
  582. {
  583. unsigned int i, vector = 0;
  584. for_each_set_bit_from(vector, system_vectors, NR_VECTORS)
  585. irq_matrix_assign_system(vector_matrix, vector, false);
  586. if (nr_legacy_irqs() > 1)
  587. lapic_assign_legacy_vector(PIC_CASCADE_IR, false);
  588. /* System vectors are reserved, online it */
  589. irq_matrix_online(vector_matrix);
  590. /* Mark the preallocated legacy interrupts */
  591. for (i = 0; i < nr_legacy_irqs(); i++) {
  592. if (i != PIC_CASCADE_IR)
  593. irq_matrix_assign(vector_matrix, ISA_IRQ_VECTOR(i));
  594. }
  595. }
  596. int __init arch_early_irq_init(void)
  597. {
  598. struct fwnode_handle *fn;
  599. fn = irq_domain_alloc_named_fwnode("VECTOR");
  600. BUG_ON(!fn);
  601. x86_vector_domain = irq_domain_create_tree(fn, &x86_vector_domain_ops,
  602. NULL);
  603. BUG_ON(x86_vector_domain == NULL);
  604. irq_domain_free_fwnode(fn);
  605. irq_set_default_host(x86_vector_domain);
  606. arch_init_msi_domain(x86_vector_domain);
  607. BUG_ON(!alloc_cpumask_var(&vector_searchmask, GFP_KERNEL));
  608. /*
  609. * Allocate the vector matrix allocator data structure and limit the
  610. * search area.
  611. */
  612. vector_matrix = irq_alloc_matrix(NR_VECTORS, FIRST_EXTERNAL_VECTOR,
  613. FIRST_SYSTEM_VECTOR);
  614. BUG_ON(!vector_matrix);
  615. return arch_early_ioapic_init();
  616. }
  617. #ifdef CONFIG_SMP
  618. static struct irq_desc *__setup_vector_irq(int vector)
  619. {
  620. int isairq = vector - ISA_IRQ_VECTOR(0);
  621. /* Check whether the irq is in the legacy space */
  622. if (isairq < 0 || isairq >= nr_legacy_irqs())
  623. return VECTOR_UNUSED;
  624. /* Check whether the irq is handled by the IOAPIC */
  625. if (test_bit(isairq, &io_apic_irqs))
  626. return VECTOR_UNUSED;
  627. return irq_to_desc(isairq);
  628. }
  629. /* Online the local APIC infrastructure and initialize the vectors */
  630. void lapic_online(void)
  631. {
  632. unsigned int vector;
  633. lockdep_assert_held(&vector_lock);
  634. /* Online the vector matrix array for this CPU */
  635. irq_matrix_online(vector_matrix);
  636. /*
  637. * The interrupt affinity logic never targets interrupts to offline
  638. * CPUs. The exception are the legacy PIC interrupts. In general
  639. * they are only targeted to CPU0, but depending on the platform
  640. * they can be distributed to any online CPU in hardware. The
  641. * kernel has no influence on that. So all active legacy vectors
  642. * must be installed on all CPUs. All non legacy interrupts can be
  643. * cleared.
  644. */
  645. for (vector = 0; vector < NR_VECTORS; vector++)
  646. this_cpu_write(vector_irq[vector], __setup_vector_irq(vector));
  647. }
  648. void lapic_offline(void)
  649. {
  650. lock_vector_lock();
  651. irq_matrix_offline(vector_matrix);
  652. unlock_vector_lock();
  653. }
  654. static int apic_set_affinity(struct irq_data *irqd,
  655. const struct cpumask *dest, bool force)
  656. {
  657. struct apic_chip_data *apicd = apic_chip_data(irqd);
  658. int err;
  659. /*
  660. * Core code can call here for inactive interrupts. For inactive
  661. * interrupts which use managed or reservation mode there is no
  662. * point in going through the vector assignment right now as the
  663. * activation will assign a vector which fits the destination
  664. * cpumask. Let the core code store the destination mask and be
  665. * done with it.
  666. */
  667. if (!irqd_is_activated(irqd) &&
  668. (apicd->is_managed || apicd->can_reserve))
  669. return IRQ_SET_MASK_OK;
  670. raw_spin_lock(&vector_lock);
  671. cpumask_and(vector_searchmask, dest, cpu_online_mask);
  672. if (irqd_affinity_is_managed(irqd))
  673. err = assign_managed_vector(irqd, vector_searchmask);
  674. else
  675. err = assign_vector_locked(irqd, vector_searchmask);
  676. raw_spin_unlock(&vector_lock);
  677. return err ? err : IRQ_SET_MASK_OK;
  678. }
  679. #else
  680. # define apic_set_affinity NULL
  681. #endif
  682. static int apic_retrigger_irq(struct irq_data *irqd)
  683. {
  684. struct apic_chip_data *apicd = apic_chip_data(irqd);
  685. unsigned long flags;
  686. raw_spin_lock_irqsave(&vector_lock, flags);
  687. apic->send_IPI(apicd->cpu, apicd->vector);
  688. raw_spin_unlock_irqrestore(&vector_lock, flags);
  689. return 1;
  690. }
  691. void apic_ack_irq(struct irq_data *irqd)
  692. {
  693. irq_move_irq(irqd);
  694. ack_APIC_irq();
  695. }
  696. void apic_ack_edge(struct irq_data *irqd)
  697. {
  698. irq_complete_move(irqd_cfg(irqd));
  699. apic_ack_irq(irqd);
  700. }
  701. static struct irq_chip lapic_controller = {
  702. .name = "APIC",
  703. .irq_ack = apic_ack_edge,
  704. .irq_set_affinity = apic_set_affinity,
  705. .irq_retrigger = apic_retrigger_irq,
  706. };
  707. #ifdef CONFIG_SMP
  708. static void free_moved_vector(struct apic_chip_data *apicd)
  709. {
  710. unsigned int vector = apicd->prev_vector;
  711. unsigned int cpu = apicd->prev_cpu;
  712. bool managed = apicd->is_managed;
  713. /*
  714. * This should never happen. Managed interrupts are not
  715. * migrated except on CPU down, which does not involve the
  716. * cleanup vector. But try to keep the accounting correct
  717. * nevertheless.
  718. */
  719. WARN_ON_ONCE(managed);
  720. trace_vector_free_moved(apicd->irq, cpu, vector, managed);
  721. irq_matrix_free(vector_matrix, cpu, vector, managed);
  722. per_cpu(vector_irq, cpu)[vector] = VECTOR_UNUSED;
  723. hlist_del_init(&apicd->clist);
  724. apicd->prev_vector = 0;
  725. apicd->move_in_progress = 0;
  726. }
  727. asmlinkage __visible void __irq_entry smp_irq_move_cleanup_interrupt(void)
  728. {
  729. struct hlist_head *clhead = this_cpu_ptr(&cleanup_list);
  730. struct apic_chip_data *apicd;
  731. struct hlist_node *tmp;
  732. entering_ack_irq();
  733. /* Prevent vectors vanishing under us */
  734. raw_spin_lock(&vector_lock);
  735. hlist_for_each_entry_safe(apicd, tmp, clhead, clist) {
  736. unsigned int irr, vector = apicd->prev_vector;
  737. /*
  738. * Paranoia: Check if the vector that needs to be cleaned
  739. * up is registered at the APICs IRR. If so, then this is
  740. * not the best time to clean it up. Clean it up in the
  741. * next attempt by sending another IRQ_MOVE_CLEANUP_VECTOR
  742. * to this CPU. IRQ_MOVE_CLEANUP_VECTOR is the lowest
  743. * priority external vector, so on return from this
  744. * interrupt the device interrupt will happen first.
  745. */
  746. irr = apic_read(APIC_IRR + (vector / 32 * 0x10));
  747. if (irr & (1U << (vector % 32))) {
  748. apic->send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
  749. continue;
  750. }
  751. free_moved_vector(apicd);
  752. }
  753. raw_spin_unlock(&vector_lock);
  754. exiting_irq();
  755. }
  756. static void __send_cleanup_vector(struct apic_chip_data *apicd)
  757. {
  758. unsigned int cpu;
  759. raw_spin_lock(&vector_lock);
  760. apicd->move_in_progress = 0;
  761. cpu = apicd->prev_cpu;
  762. if (cpu_online(cpu)) {
  763. hlist_add_head(&apicd->clist, per_cpu_ptr(&cleanup_list, cpu));
  764. apic->send_IPI(cpu, IRQ_MOVE_CLEANUP_VECTOR);
  765. } else {
  766. apicd->prev_vector = 0;
  767. }
  768. raw_spin_unlock(&vector_lock);
  769. }
  770. void send_cleanup_vector(struct irq_cfg *cfg)
  771. {
  772. struct apic_chip_data *apicd;
  773. apicd = container_of(cfg, struct apic_chip_data, hw_irq_cfg);
  774. if (apicd->move_in_progress)
  775. __send_cleanup_vector(apicd);
  776. }
  777. static void __irq_complete_move(struct irq_cfg *cfg, unsigned vector)
  778. {
  779. struct apic_chip_data *apicd;
  780. apicd = container_of(cfg, struct apic_chip_data, hw_irq_cfg);
  781. if (likely(!apicd->move_in_progress))
  782. return;
  783. if (vector == apicd->vector && apicd->cpu == smp_processor_id())
  784. __send_cleanup_vector(apicd);
  785. }
  786. void irq_complete_move(struct irq_cfg *cfg)
  787. {
  788. __irq_complete_move(cfg, ~get_irq_regs()->orig_ax);
  789. }
  790. /*
  791. * Called from fixup_irqs() with @desc->lock held and interrupts disabled.
  792. */
  793. void irq_force_complete_move(struct irq_desc *desc)
  794. {
  795. struct apic_chip_data *apicd;
  796. struct irq_data *irqd;
  797. unsigned int vector;
  798. /*
  799. * The function is called for all descriptors regardless of which
  800. * irqdomain they belong to. For example if an IRQ is provided by
  801. * an irq_chip as part of a GPIO driver, the chip data for that
  802. * descriptor is specific to the irq_chip in question.
  803. *
  804. * Check first that the chip_data is what we expect
  805. * (apic_chip_data) before touching it any further.
  806. */
  807. irqd = irq_domain_get_irq_data(x86_vector_domain,
  808. irq_desc_get_irq(desc));
  809. if (!irqd)
  810. return;
  811. raw_spin_lock(&vector_lock);
  812. apicd = apic_chip_data(irqd);
  813. if (!apicd)
  814. goto unlock;
  815. /*
  816. * If prev_vector is empty, no action required.
  817. */
  818. vector = apicd->prev_vector;
  819. if (!vector)
  820. goto unlock;
  821. /*
  822. * This is tricky. If the cleanup of the old vector has not been
  823. * done yet, then the following setaffinity call will fail with
  824. * -EBUSY. This can leave the interrupt in a stale state.
  825. *
  826. * All CPUs are stuck in stop machine with interrupts disabled so
  827. * calling __irq_complete_move() would be completely pointless.
  828. *
  829. * 1) The interrupt is in move_in_progress state. That means that we
  830. * have not seen an interrupt since the io_apic was reprogrammed to
  831. * the new vector.
  832. *
  833. * 2) The interrupt has fired on the new vector, but the cleanup IPIs
  834. * have not been processed yet.
  835. */
  836. if (apicd->move_in_progress) {
  837. /*
  838. * In theory there is a race:
  839. *
  840. * set_ioapic(new_vector) <-- Interrupt is raised before update
  841. * is effective, i.e. it's raised on
  842. * the old vector.
  843. *
  844. * So if the target cpu cannot handle that interrupt before
  845. * the old vector is cleaned up, we get a spurious interrupt
  846. * and in the worst case the ioapic irq line becomes stale.
  847. *
  848. * But in case of cpu hotplug this should be a non issue
  849. * because if the affinity update happens right before all
  850. * cpus rendevouz in stop machine, there is no way that the
  851. * interrupt can be blocked on the target cpu because all cpus
  852. * loops first with interrupts enabled in stop machine, so the
  853. * old vector is not yet cleaned up when the interrupt fires.
  854. *
  855. * So the only way to run into this issue is if the delivery
  856. * of the interrupt on the apic/system bus would be delayed
  857. * beyond the point where the target cpu disables interrupts
  858. * in stop machine. I doubt that it can happen, but at least
  859. * there is a theroretical chance. Virtualization might be
  860. * able to expose this, but AFAICT the IOAPIC emulation is not
  861. * as stupid as the real hardware.
  862. *
  863. * Anyway, there is nothing we can do about that at this point
  864. * w/o refactoring the whole fixup_irq() business completely.
  865. * We print at least the irq number and the old vector number,
  866. * so we have the necessary information when a problem in that
  867. * area arises.
  868. */
  869. pr_warn("IRQ fixup: irq %d move in progress, old vector %d\n",
  870. irqd->irq, vector);
  871. }
  872. free_moved_vector(apicd);
  873. unlock:
  874. raw_spin_unlock(&vector_lock);
  875. }
  876. #ifdef CONFIG_HOTPLUG_CPU
  877. /*
  878. * Note, this is not accurate accounting, but at least good enough to
  879. * prevent that the actual interrupt move will run out of vectors.
  880. */
  881. int lapic_can_unplug_cpu(void)
  882. {
  883. unsigned int rsvd, avl, tomove, cpu = smp_processor_id();
  884. int ret = 0;
  885. raw_spin_lock(&vector_lock);
  886. tomove = irq_matrix_allocated(vector_matrix);
  887. avl = irq_matrix_available(vector_matrix, true);
  888. if (avl < tomove) {
  889. pr_warn("CPU %u has %u vectors, %u available. Cannot disable CPU\n",
  890. cpu, tomove, avl);
  891. ret = -ENOSPC;
  892. goto out;
  893. }
  894. rsvd = irq_matrix_reserved(vector_matrix);
  895. if (avl < rsvd) {
  896. pr_warn("Reserved vectors %u > available %u. IRQ request may fail\n",
  897. rsvd, avl);
  898. }
  899. out:
  900. raw_spin_unlock(&vector_lock);
  901. return ret;
  902. }
  903. #endif /* HOTPLUG_CPU */
  904. #endif /* SMP */
  905. static void __init print_APIC_field(int base)
  906. {
  907. int i;
  908. printk(KERN_DEBUG);
  909. for (i = 0; i < 8; i++)
  910. pr_cont("%08x", apic_read(base + i*0x10));
  911. pr_cont("\n");
  912. }
  913. static void __init print_local_APIC(void *dummy)
  914. {
  915. unsigned int i, v, ver, maxlvt;
  916. u64 icr;
  917. pr_debug("printing local APIC contents on CPU#%d/%d:\n",
  918. smp_processor_id(), hard_smp_processor_id());
  919. v = apic_read(APIC_ID);
  920. pr_info("... APIC ID: %08x (%01x)\n", v, read_apic_id());
  921. v = apic_read(APIC_LVR);
  922. pr_info("... APIC VERSION: %08x\n", v);
  923. ver = GET_APIC_VERSION(v);
  924. maxlvt = lapic_get_maxlvt();
  925. v = apic_read(APIC_TASKPRI);
  926. pr_debug("... APIC TASKPRI: %08x (%02x)\n", v, v & APIC_TPRI_MASK);
  927. /* !82489DX */
  928. if (APIC_INTEGRATED(ver)) {
  929. if (!APIC_XAPIC(ver)) {
  930. v = apic_read(APIC_ARBPRI);
  931. pr_debug("... APIC ARBPRI: %08x (%02x)\n",
  932. v, v & APIC_ARBPRI_MASK);
  933. }
  934. v = apic_read(APIC_PROCPRI);
  935. pr_debug("... APIC PROCPRI: %08x\n", v);
  936. }
  937. /*
  938. * Remote read supported only in the 82489DX and local APIC for
  939. * Pentium processors.
  940. */
  941. if (!APIC_INTEGRATED(ver) || maxlvt == 3) {
  942. v = apic_read(APIC_RRR);
  943. pr_debug("... APIC RRR: %08x\n", v);
  944. }
  945. v = apic_read(APIC_LDR);
  946. pr_debug("... APIC LDR: %08x\n", v);
  947. if (!x2apic_enabled()) {
  948. v = apic_read(APIC_DFR);
  949. pr_debug("... APIC DFR: %08x\n", v);
  950. }
  951. v = apic_read(APIC_SPIV);
  952. pr_debug("... APIC SPIV: %08x\n", v);
  953. pr_debug("... APIC ISR field:\n");
  954. print_APIC_field(APIC_ISR);
  955. pr_debug("... APIC TMR field:\n");
  956. print_APIC_field(APIC_TMR);
  957. pr_debug("... APIC IRR field:\n");
  958. print_APIC_field(APIC_IRR);
  959. /* !82489DX */
  960. if (APIC_INTEGRATED(ver)) {
  961. /* Due to the Pentium erratum 3AP. */
  962. if (maxlvt > 3)
  963. apic_write(APIC_ESR, 0);
  964. v = apic_read(APIC_ESR);
  965. pr_debug("... APIC ESR: %08x\n", v);
  966. }
  967. icr = apic_icr_read();
  968. pr_debug("... APIC ICR: %08x\n", (u32)icr);
  969. pr_debug("... APIC ICR2: %08x\n", (u32)(icr >> 32));
  970. v = apic_read(APIC_LVTT);
  971. pr_debug("... APIC LVTT: %08x\n", v);
  972. if (maxlvt > 3) {
  973. /* PC is LVT#4. */
  974. v = apic_read(APIC_LVTPC);
  975. pr_debug("... APIC LVTPC: %08x\n", v);
  976. }
  977. v = apic_read(APIC_LVT0);
  978. pr_debug("... APIC LVT0: %08x\n", v);
  979. v = apic_read(APIC_LVT1);
  980. pr_debug("... APIC LVT1: %08x\n", v);
  981. if (maxlvt > 2) {
  982. /* ERR is LVT#3. */
  983. v = apic_read(APIC_LVTERR);
  984. pr_debug("... APIC LVTERR: %08x\n", v);
  985. }
  986. v = apic_read(APIC_TMICT);
  987. pr_debug("... APIC TMICT: %08x\n", v);
  988. v = apic_read(APIC_TMCCT);
  989. pr_debug("... APIC TMCCT: %08x\n", v);
  990. v = apic_read(APIC_TDCR);
  991. pr_debug("... APIC TDCR: %08x\n", v);
  992. if (boot_cpu_has(X86_FEATURE_EXTAPIC)) {
  993. v = apic_read(APIC_EFEAT);
  994. maxlvt = (v >> 16) & 0xff;
  995. pr_debug("... APIC EFEAT: %08x\n", v);
  996. v = apic_read(APIC_ECTRL);
  997. pr_debug("... APIC ECTRL: %08x\n", v);
  998. for (i = 0; i < maxlvt; i++) {
  999. v = apic_read(APIC_EILVTn(i));
  1000. pr_debug("... APIC EILVT%d: %08x\n", i, v);
  1001. }
  1002. }
  1003. pr_cont("\n");
  1004. }
  1005. static void __init print_local_APICs(int maxcpu)
  1006. {
  1007. int cpu;
  1008. if (!maxcpu)
  1009. return;
  1010. preempt_disable();
  1011. for_each_online_cpu(cpu) {
  1012. if (cpu >= maxcpu)
  1013. break;
  1014. smp_call_function_single(cpu, print_local_APIC, NULL, 1);
  1015. }
  1016. preempt_enable();
  1017. }
  1018. static void __init print_PIC(void)
  1019. {
  1020. unsigned int v;
  1021. unsigned long flags;
  1022. if (!nr_legacy_irqs())
  1023. return;
  1024. pr_debug("\nprinting PIC contents\n");
  1025. raw_spin_lock_irqsave(&i8259A_lock, flags);
  1026. v = inb(0xa1) << 8 | inb(0x21);
  1027. pr_debug("... PIC IMR: %04x\n", v);
  1028. v = inb(0xa0) << 8 | inb(0x20);
  1029. pr_debug("... PIC IRR: %04x\n", v);
  1030. outb(0x0b, 0xa0);
  1031. outb(0x0b, 0x20);
  1032. v = inb(0xa0) << 8 | inb(0x20);
  1033. outb(0x0a, 0xa0);
  1034. outb(0x0a, 0x20);
  1035. raw_spin_unlock_irqrestore(&i8259A_lock, flags);
  1036. pr_debug("... PIC ISR: %04x\n", v);
  1037. v = inb(0x4d1) << 8 | inb(0x4d0);
  1038. pr_debug("... PIC ELCR: %04x\n", v);
  1039. }
  1040. static int show_lapic __initdata = 1;
  1041. static __init int setup_show_lapic(char *arg)
  1042. {
  1043. int num = -1;
  1044. if (strcmp(arg, "all") == 0) {
  1045. show_lapic = CONFIG_NR_CPUS;
  1046. } else {
  1047. get_option(&arg, &num);
  1048. if (num >= 0)
  1049. show_lapic = num;
  1050. }
  1051. return 1;
  1052. }
  1053. __setup("show_lapic=", setup_show_lapic);
  1054. static int __init print_ICs(void)
  1055. {
  1056. if (apic_verbosity == APIC_QUIET)
  1057. return 0;
  1058. print_PIC();
  1059. /* don't print out if apic is not there */
  1060. if (!boot_cpu_has(X86_FEATURE_APIC) && !apic_from_smp_config())
  1061. return 0;
  1062. print_local_APICs(show_lapic);
  1063. print_IO_APICs();
  1064. return 0;
  1065. }
  1066. late_initcall(print_ICs);