vector.c 33 KB

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