vector.c 33 KB

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