vector.c 32 KB

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