acpi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * acpi.c - Architecture-Specific Low-Level ACPI Support
  4. *
  5. * Copyright (C) 1999 VA Linux Systems
  6. * Copyright (C) 1999,2000 Walt Drummond <[email protected]>
  7. * Copyright (C) 2000, 2002-2003 Hewlett-Packard Co.
  8. * David Mosberger-Tang <[email protected]>
  9. * Copyright (C) 2000 Intel Corp.
  10. * Copyright (C) 2000,2001 J.I. Lee <[email protected]>
  11. * Copyright (C) 2001 Paul Diefenbaugh <[email protected]>
  12. * Copyright (C) 2001 Jenna Hall <[email protected]>
  13. * Copyright (C) 2001 Takayoshi Kochi <[email protected]>
  14. * Copyright (C) 2002 Erich Focht <[email protected]>
  15. * Copyright (C) 2004 Ashok Raj <[email protected]>
  16. */
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/kernel.h>
  20. #include <linux/sched.h>
  21. #include <linux/smp.h>
  22. #include <linux/string.h>
  23. #include <linux/types.h>
  24. #include <linux/irq.h>
  25. #include <linux/acpi.h>
  26. #include <linux/efi.h>
  27. #include <linux/mmzone.h>
  28. #include <linux/nodemask.h>
  29. #include <linux/slab.h>
  30. #include <acpi/processor.h>
  31. #include <asm/io.h>
  32. #include <asm/iosapic.h>
  33. #include <asm/page.h>
  34. #include <asm/numa.h>
  35. #include <asm/sal.h>
  36. #include <asm/cyclone.h>
  37. #define PREFIX "ACPI: "
  38. int acpi_lapic;
  39. unsigned int acpi_cpei_override;
  40. unsigned int acpi_cpei_phys_cpuid;
  41. #define ACPI_MAX_PLATFORM_INTERRUPTS 256
  42. /* Array to record platform interrupt vectors for generic interrupt routing. */
  43. int platform_intr_list[ACPI_MAX_PLATFORM_INTERRUPTS] = {
  44. [0 ... ACPI_MAX_PLATFORM_INTERRUPTS - 1] = -1
  45. };
  46. enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_IOSAPIC;
  47. /*
  48. * Interrupt routing API for device drivers. Provides interrupt vector for
  49. * a generic platform event. Currently only CPEI is implemented.
  50. */
  51. int acpi_request_vector(u32 int_type)
  52. {
  53. int vector = -1;
  54. if (int_type < ACPI_MAX_PLATFORM_INTERRUPTS) {
  55. /* corrected platform error interrupt */
  56. vector = platform_intr_list[int_type];
  57. } else
  58. printk(KERN_ERR
  59. "acpi_request_vector(): invalid interrupt type\n");
  60. return vector;
  61. }
  62. void __init __iomem *__acpi_map_table(unsigned long phys, unsigned long size)
  63. {
  64. return __va(phys);
  65. }
  66. void __init __acpi_unmap_table(void __iomem *map, unsigned long size)
  67. {
  68. }
  69. /* --------------------------------------------------------------------------
  70. Boot-time Table Parsing
  71. -------------------------------------------------------------------------- */
  72. static int available_cpus __initdata;
  73. struct acpi_table_madt *acpi_madt __initdata;
  74. static u8 has_8259;
  75. static int __init
  76. acpi_parse_lapic_addr_ovr(union acpi_subtable_headers * header,
  77. const unsigned long end)
  78. {
  79. struct acpi_madt_local_apic_override *lapic;
  80. lapic = (struct acpi_madt_local_apic_override *)header;
  81. if (BAD_MADT_ENTRY(lapic, end))
  82. return -EINVAL;
  83. if (lapic->address) {
  84. iounmap(ipi_base_addr);
  85. ipi_base_addr = ioremap(lapic->address, 0);
  86. }
  87. return 0;
  88. }
  89. static int __init
  90. acpi_parse_lsapic(union acpi_subtable_headers *header, const unsigned long end)
  91. {
  92. struct acpi_madt_local_sapic *lsapic;
  93. lsapic = (struct acpi_madt_local_sapic *)header;
  94. /*Skip BAD_MADT_ENTRY check, as lsapic size could vary */
  95. if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
  96. #ifdef CONFIG_SMP
  97. smp_boot_data.cpu_phys_id[available_cpus] =
  98. (lsapic->id << 8) | lsapic->eid;
  99. #endif
  100. ++available_cpus;
  101. }
  102. total_cpus++;
  103. return 0;
  104. }
  105. static int __init
  106. acpi_parse_lapic_nmi(union acpi_subtable_headers * header, const unsigned long end)
  107. {
  108. struct acpi_madt_local_apic_nmi *lacpi_nmi;
  109. lacpi_nmi = (struct acpi_madt_local_apic_nmi *)header;
  110. if (BAD_MADT_ENTRY(lacpi_nmi, end))
  111. return -EINVAL;
  112. /* TBD: Support lapic_nmi entries */
  113. return 0;
  114. }
  115. static int __init
  116. acpi_parse_iosapic(union acpi_subtable_headers * header, const unsigned long end)
  117. {
  118. struct acpi_madt_io_sapic *iosapic;
  119. iosapic = (struct acpi_madt_io_sapic *)header;
  120. if (BAD_MADT_ENTRY(iosapic, end))
  121. return -EINVAL;
  122. return iosapic_init(iosapic->address, iosapic->global_irq_base);
  123. }
  124. static unsigned int __initdata acpi_madt_rev;
  125. static int __init
  126. acpi_parse_plat_int_src(union acpi_subtable_headers * header,
  127. const unsigned long end)
  128. {
  129. struct acpi_madt_interrupt_source *plintsrc;
  130. int vector;
  131. plintsrc = (struct acpi_madt_interrupt_source *)header;
  132. if (BAD_MADT_ENTRY(plintsrc, end))
  133. return -EINVAL;
  134. /*
  135. * Get vector assignment for this interrupt, set attributes,
  136. * and program the IOSAPIC routing table.
  137. */
  138. vector = iosapic_register_platform_intr(plintsrc->type,
  139. plintsrc->global_irq,
  140. plintsrc->io_sapic_vector,
  141. plintsrc->eid,
  142. plintsrc->id,
  143. ((plintsrc->inti_flags & ACPI_MADT_POLARITY_MASK) ==
  144. ACPI_MADT_POLARITY_ACTIVE_HIGH) ?
  145. IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
  146. ((plintsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) ==
  147. ACPI_MADT_TRIGGER_EDGE) ?
  148. IOSAPIC_EDGE : IOSAPIC_LEVEL);
  149. platform_intr_list[plintsrc->type] = vector;
  150. if (acpi_madt_rev > 1) {
  151. acpi_cpei_override = plintsrc->flags & ACPI_MADT_CPEI_OVERRIDE;
  152. }
  153. /*
  154. * Save the physical id, so we can check when its being removed
  155. */
  156. acpi_cpei_phys_cpuid = ((plintsrc->id << 8) | (plintsrc->eid)) & 0xffff;
  157. return 0;
  158. }
  159. #ifdef CONFIG_HOTPLUG_CPU
  160. unsigned int can_cpei_retarget(void)
  161. {
  162. extern int cpe_vector;
  163. extern unsigned int force_cpei_retarget;
  164. /*
  165. * Only if CPEI is supported and the override flag
  166. * is present, otherwise return that its re-targettable
  167. * if we are in polling mode.
  168. */
  169. if (cpe_vector > 0) {
  170. if (acpi_cpei_override || force_cpei_retarget)
  171. return 1;
  172. else
  173. return 0;
  174. }
  175. return 1;
  176. }
  177. unsigned int is_cpu_cpei_target(unsigned int cpu)
  178. {
  179. unsigned int logical_id;
  180. logical_id = cpu_logical_id(acpi_cpei_phys_cpuid);
  181. if (logical_id == cpu)
  182. return 1;
  183. else
  184. return 0;
  185. }
  186. void set_cpei_target_cpu(unsigned int cpu)
  187. {
  188. acpi_cpei_phys_cpuid = cpu_physical_id(cpu);
  189. }
  190. #endif
  191. unsigned int get_cpei_target_cpu(void)
  192. {
  193. return acpi_cpei_phys_cpuid;
  194. }
  195. static int __init
  196. acpi_parse_int_src_ovr(union acpi_subtable_headers * header,
  197. const unsigned long end)
  198. {
  199. struct acpi_madt_interrupt_override *p;
  200. p = (struct acpi_madt_interrupt_override *)header;
  201. if (BAD_MADT_ENTRY(p, end))
  202. return -EINVAL;
  203. iosapic_override_isa_irq(p->source_irq, p->global_irq,
  204. ((p->inti_flags & ACPI_MADT_POLARITY_MASK) ==
  205. ACPI_MADT_POLARITY_ACTIVE_LOW) ?
  206. IOSAPIC_POL_LOW : IOSAPIC_POL_HIGH,
  207. ((p->inti_flags & ACPI_MADT_TRIGGER_MASK) ==
  208. ACPI_MADT_TRIGGER_LEVEL) ?
  209. IOSAPIC_LEVEL : IOSAPIC_EDGE);
  210. return 0;
  211. }
  212. static int __init
  213. acpi_parse_nmi_src(union acpi_subtable_headers * header, const unsigned long end)
  214. {
  215. struct acpi_madt_nmi_source *nmi_src;
  216. nmi_src = (struct acpi_madt_nmi_source *)header;
  217. if (BAD_MADT_ENTRY(nmi_src, end))
  218. return -EINVAL;
  219. /* TBD: Support nimsrc entries */
  220. return 0;
  221. }
  222. static void __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
  223. {
  224. if (!strncmp(oem_id, "IBM", 3) && (!strncmp(oem_table_id, "SERMOW", 6))) {
  225. /*
  226. * Unfortunately ITC_DRIFT is not yet part of the
  227. * official SAL spec, so the ITC_DRIFT bit is not
  228. * set by the BIOS on this hardware.
  229. */
  230. sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
  231. cyclone_setup();
  232. }
  233. }
  234. static int __init acpi_parse_madt(struct acpi_table_header *table)
  235. {
  236. acpi_madt = (struct acpi_table_madt *)table;
  237. acpi_madt_rev = acpi_madt->header.revision;
  238. /* remember the value for reference after free_initmem() */
  239. #ifdef CONFIG_ITANIUM
  240. has_8259 = 1; /* Firmware on old Itanium systems is broken */
  241. #else
  242. has_8259 = acpi_madt->flags & ACPI_MADT_PCAT_COMPAT;
  243. #endif
  244. iosapic_system_init(has_8259);
  245. /* Get base address of IPI Message Block */
  246. if (acpi_madt->address)
  247. ipi_base_addr = ioremap(acpi_madt->address, 0);
  248. printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
  249. acpi_madt_oem_check(acpi_madt->header.oem_id,
  250. acpi_madt->header.oem_table_id);
  251. return 0;
  252. }
  253. #ifdef CONFIG_ACPI_NUMA
  254. #undef SLIT_DEBUG
  255. #define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
  256. static int __initdata srat_num_cpus; /* number of cpus */
  257. static u32 pxm_flag[PXM_FLAG_LEN];
  258. #define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag))
  259. #define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag))
  260. static struct acpi_table_slit __initdata *slit_table;
  261. cpumask_t early_cpu_possible_map = CPU_MASK_NONE;
  262. static int __init
  263. get_processor_proximity_domain(struct acpi_srat_cpu_affinity *pa)
  264. {
  265. int pxm;
  266. pxm = pa->proximity_domain_lo;
  267. if (acpi_srat_revision >= 2)
  268. pxm += pa->proximity_domain_hi[0] << 8;
  269. return pxm;
  270. }
  271. static int __init
  272. get_memory_proximity_domain(struct acpi_srat_mem_affinity *ma)
  273. {
  274. int pxm;
  275. pxm = ma->proximity_domain;
  276. if (acpi_srat_revision <= 1)
  277. pxm &= 0xff;
  278. return pxm;
  279. }
  280. /*
  281. * ACPI 2.0 SLIT (System Locality Information Table)
  282. * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
  283. */
  284. void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
  285. {
  286. u32 len;
  287. len = sizeof(struct acpi_table_header) + 8
  288. + slit->locality_count * slit->locality_count;
  289. if (slit->header.length != len) {
  290. printk(KERN_ERR
  291. "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
  292. len, slit->header.length);
  293. return;
  294. }
  295. slit_table = slit;
  296. }
  297. void __init
  298. acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
  299. {
  300. int pxm;
  301. if (!(pa->flags & ACPI_SRAT_CPU_ENABLED))
  302. return;
  303. if (srat_num_cpus >= ARRAY_SIZE(node_cpuid)) {
  304. printk_once(KERN_WARNING
  305. "node_cpuid[%ld] is too small, may not be able to use all cpus\n",
  306. ARRAY_SIZE(node_cpuid));
  307. return;
  308. }
  309. pxm = get_processor_proximity_domain(pa);
  310. /* record this node in proximity bitmap */
  311. pxm_bit_set(pxm);
  312. node_cpuid[srat_num_cpus].phys_id =
  313. (pa->apic_id << 8) | (pa->local_sapic_eid);
  314. /* nid should be overridden as logical node id later */
  315. node_cpuid[srat_num_cpus].nid = pxm;
  316. cpumask_set_cpu(srat_num_cpus, &early_cpu_possible_map);
  317. srat_num_cpus++;
  318. }
  319. int __init
  320. acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
  321. {
  322. unsigned long paddr, size;
  323. int pxm;
  324. struct node_memblk_s *p, *q, *pend;
  325. pxm = get_memory_proximity_domain(ma);
  326. /* fill node memory chunk structure */
  327. paddr = ma->base_address;
  328. size = ma->length;
  329. /* Ignore disabled entries */
  330. if (!(ma->flags & ACPI_SRAT_MEM_ENABLED))
  331. return -1;
  332. if (num_node_memblks >= NR_NODE_MEMBLKS) {
  333. pr_err("NUMA: too many memblk ranges\n");
  334. return -EINVAL;
  335. }
  336. /* record this node in proximity bitmap */
  337. pxm_bit_set(pxm);
  338. /* Insertion sort based on base address */
  339. pend = &node_memblk[num_node_memblks];
  340. for (p = &node_memblk[0]; p < pend; p++) {
  341. if (paddr < p->start_paddr)
  342. break;
  343. }
  344. if (p < pend) {
  345. for (q = pend - 1; q >= p; q--)
  346. *(q + 1) = *q;
  347. }
  348. p->start_paddr = paddr;
  349. p->size = size;
  350. p->nid = pxm;
  351. num_node_memblks++;
  352. return 0;
  353. }
  354. void __init acpi_numa_fixup(void)
  355. {
  356. int i, j, node_from, node_to;
  357. /* If there's no SRAT, fix the phys_id and mark node 0 online */
  358. if (srat_num_cpus == 0) {
  359. node_set_online(0);
  360. node_cpuid[0].phys_id = hard_smp_processor_id();
  361. slit_distance(0, 0) = LOCAL_DISTANCE;
  362. goto out;
  363. }
  364. /*
  365. * MCD - This can probably be dropped now. No need for pxm ID to node ID
  366. * mapping with sparse node numbering iff MAX_PXM_DOMAINS <= MAX_NUMNODES.
  367. */
  368. nodes_clear(node_online_map);
  369. for (i = 0; i < MAX_PXM_DOMAINS; i++) {
  370. if (pxm_bit_test(i)) {
  371. int nid = acpi_map_pxm_to_node(i);
  372. node_set_online(nid);
  373. }
  374. }
  375. /* set logical node id in memory chunk structure */
  376. for (i = 0; i < num_node_memblks; i++)
  377. node_memblk[i].nid = pxm_to_node(node_memblk[i].nid);
  378. /* assign memory bank numbers for each chunk on each node */
  379. for_each_online_node(i) {
  380. int bank;
  381. bank = 0;
  382. for (j = 0; j < num_node_memblks; j++)
  383. if (node_memblk[j].nid == i)
  384. node_memblk[j].bank = bank++;
  385. }
  386. /* set logical node id in cpu structure */
  387. for_each_possible_early_cpu(i)
  388. node_cpuid[i].nid = pxm_to_node(node_cpuid[i].nid);
  389. printk(KERN_INFO "Number of logical nodes in system = %d\n",
  390. num_online_nodes());
  391. printk(KERN_INFO "Number of memory chunks in system = %d\n",
  392. num_node_memblks);
  393. if (!slit_table) {
  394. for (i = 0; i < MAX_NUMNODES; i++)
  395. for (j = 0; j < MAX_NUMNODES; j++)
  396. slit_distance(i, j) = i == j ?
  397. LOCAL_DISTANCE : REMOTE_DISTANCE;
  398. goto out;
  399. }
  400. memset(numa_slit, -1, sizeof(numa_slit));
  401. for (i = 0; i < slit_table->locality_count; i++) {
  402. if (!pxm_bit_test(i))
  403. continue;
  404. node_from = pxm_to_node(i);
  405. for (j = 0; j < slit_table->locality_count; j++) {
  406. if (!pxm_bit_test(j))
  407. continue;
  408. node_to = pxm_to_node(j);
  409. slit_distance(node_from, node_to) =
  410. slit_table->entry[i * slit_table->locality_count + j];
  411. }
  412. }
  413. #ifdef SLIT_DEBUG
  414. printk("ACPI 2.0 SLIT locality table:\n");
  415. for_each_online_node(i) {
  416. for_each_online_node(j)
  417. printk("%03d ", node_distance(i, j));
  418. printk("\n");
  419. }
  420. #endif
  421. out:
  422. node_possible_map = node_online_map;
  423. }
  424. #endif /* CONFIG_ACPI_NUMA */
  425. /*
  426. * success: return IRQ number (>=0)
  427. * failure: return < 0
  428. */
  429. int acpi_register_gsi(struct device *dev, u32 gsi, int triggering, int polarity)
  430. {
  431. if (acpi_irq_model == ACPI_IRQ_MODEL_PLATFORM)
  432. return gsi;
  433. if (has_8259 && gsi < 16)
  434. return isa_irq_to_vector(gsi);
  435. return iosapic_register_intr(gsi,
  436. (polarity ==
  437. ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH :
  438. IOSAPIC_POL_LOW,
  439. (triggering ==
  440. ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE :
  441. IOSAPIC_LEVEL);
  442. }
  443. EXPORT_SYMBOL_GPL(acpi_register_gsi);
  444. void acpi_unregister_gsi(u32 gsi)
  445. {
  446. if (acpi_irq_model == ACPI_IRQ_MODEL_PLATFORM)
  447. return;
  448. if (has_8259 && gsi < 16)
  449. return;
  450. iosapic_unregister_intr(gsi);
  451. }
  452. EXPORT_SYMBOL_GPL(acpi_unregister_gsi);
  453. static int __init acpi_parse_fadt(struct acpi_table_header *table)
  454. {
  455. struct acpi_table_header *fadt_header;
  456. struct acpi_table_fadt *fadt;
  457. fadt_header = (struct acpi_table_header *)table;
  458. if (fadt_header->revision != 3)
  459. return -ENODEV; /* Only deal with ACPI 2.0 FADT */
  460. fadt = (struct acpi_table_fadt *)fadt_header;
  461. acpi_register_gsi(NULL, fadt->sci_interrupt, ACPI_LEVEL_SENSITIVE,
  462. ACPI_ACTIVE_LOW);
  463. return 0;
  464. }
  465. int __init early_acpi_boot_init(void)
  466. {
  467. int ret;
  468. /*
  469. * do a partial walk of MADT to determine how many CPUs
  470. * we have including offline CPUs
  471. */
  472. if (acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  473. printk(KERN_ERR PREFIX "Can't find MADT\n");
  474. return 0;
  475. }
  476. ret = acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC,
  477. acpi_parse_lsapic, NR_CPUS);
  478. if (ret < 1)
  479. printk(KERN_ERR PREFIX
  480. "Error parsing MADT - no LAPIC entries\n");
  481. else
  482. acpi_lapic = 1;
  483. #ifdef CONFIG_SMP
  484. if (available_cpus == 0) {
  485. printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
  486. printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
  487. smp_boot_data.cpu_phys_id[available_cpus] =
  488. hard_smp_processor_id();
  489. available_cpus = 1; /* We've got at least one of these, no? */
  490. }
  491. smp_boot_data.cpu_count = available_cpus;
  492. #endif
  493. /* Make boot-up look pretty */
  494. printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus,
  495. total_cpus);
  496. return 0;
  497. }
  498. int __init acpi_boot_init(void)
  499. {
  500. /*
  501. * MADT
  502. * ----
  503. * Parse the Multiple APIC Description Table (MADT), if exists.
  504. * Note that this table provides platform SMP configuration
  505. * information -- the successor to MPS tables.
  506. */
  507. if (acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
  508. printk(KERN_ERR PREFIX "Can't find MADT\n");
  509. goto skip_madt;
  510. }
  511. /* Local APIC */
  512. if (acpi_table_parse_madt
  513. (ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE, acpi_parse_lapic_addr_ovr, 0) < 0)
  514. printk(KERN_ERR PREFIX
  515. "Error parsing LAPIC address override entry\n");
  516. if (acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0)
  517. < 0)
  518. printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
  519. /* I/O APIC */
  520. if (acpi_table_parse_madt
  521. (ACPI_MADT_TYPE_IO_SAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1) {
  522. printk(KERN_ERR PREFIX
  523. "Error parsing MADT - no IOSAPIC entries\n");
  524. }
  525. /* System-Level Interrupt Routing */
  526. if (acpi_table_parse_madt
  527. (ACPI_MADT_TYPE_INTERRUPT_SOURCE, acpi_parse_plat_int_src,
  528. ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
  529. printk(KERN_ERR PREFIX
  530. "Error parsing platform interrupt source entry\n");
  531. if (acpi_table_parse_madt
  532. (ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr, 0) < 0)
  533. printk(KERN_ERR PREFIX
  534. "Error parsing interrupt source overrides entry\n");
  535. if (acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src, 0) < 0)
  536. printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
  537. skip_madt:
  538. /*
  539. * FADT says whether a legacy keyboard controller is present.
  540. * The FADT also contains an SCI_INT line, by which the system
  541. * gets interrupts such as power and sleep buttons. If it's not
  542. * on a Legacy interrupt, it needs to be setup.
  543. */
  544. if (acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt))
  545. printk(KERN_ERR PREFIX "Can't find FADT\n");
  546. #ifdef CONFIG_ACPI_NUMA
  547. #ifdef CONFIG_SMP
  548. if (srat_num_cpus == 0) {
  549. int cpu, i = 1;
  550. for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
  551. if (smp_boot_data.cpu_phys_id[cpu] !=
  552. hard_smp_processor_id())
  553. node_cpuid[i++].phys_id =
  554. smp_boot_data.cpu_phys_id[cpu];
  555. }
  556. #endif
  557. build_cpu_to_node_map();
  558. #endif
  559. return 0;
  560. }
  561. int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
  562. {
  563. int tmp;
  564. if (has_8259 && gsi < 16)
  565. *irq = isa_irq_to_vector(gsi);
  566. else {
  567. tmp = gsi_to_irq(gsi);
  568. if (tmp == -1)
  569. return -1;
  570. *irq = tmp;
  571. }
  572. return 0;
  573. }
  574. int acpi_isa_irq_to_gsi(unsigned isa_irq, u32 *gsi)
  575. {
  576. if (isa_irq >= 16)
  577. return -1;
  578. *gsi = isa_irq;
  579. return 0;
  580. }
  581. /*
  582. * ACPI based hotplug CPU support
  583. */
  584. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  585. int acpi_map_cpu2node(acpi_handle handle, int cpu, int physid)
  586. {
  587. #ifdef CONFIG_ACPI_NUMA
  588. /*
  589. * We don't have cpu-only-node hotadd. But if the system equips
  590. * SRAT table, pxm is already found and node is ready.
  591. * So, just pxm_to_nid(pxm) is OK.
  592. * This code here is for the system which doesn't have full SRAT
  593. * table for possible cpus.
  594. */
  595. node_cpuid[cpu].phys_id = physid;
  596. node_cpuid[cpu].nid = acpi_get_node(handle);
  597. #endif
  598. return 0;
  599. }
  600. int additional_cpus __initdata = -1;
  601. static __init int setup_additional_cpus(char *s)
  602. {
  603. if (s)
  604. additional_cpus = simple_strtol(s, NULL, 0);
  605. return 0;
  606. }
  607. early_param("additional_cpus", setup_additional_cpus);
  608. /*
  609. * cpu_possible_mask should be static, it cannot change as CPUs
  610. * are onlined, or offlined. The reason is per-cpu data-structures
  611. * are allocated by some modules at init time, and dont expect to
  612. * do this dynamically on cpu arrival/departure.
  613. * cpu_present_mask on the other hand can change dynamically.
  614. * In case when cpu_hotplug is not compiled, then we resort to current
  615. * behaviour, which is cpu_possible == cpu_present.
  616. * - Ashok Raj
  617. *
  618. * Three ways to find out the number of additional hotplug CPUs:
  619. * - If the BIOS specified disabled CPUs in ACPI/mptables use that.
  620. * - The user can overwrite it with additional_cpus=NUM
  621. * - Otherwise don't reserve additional CPUs.
  622. */
  623. __init void prefill_possible_map(void)
  624. {
  625. int i;
  626. int possible, disabled_cpus;
  627. disabled_cpus = total_cpus - available_cpus;
  628. if (additional_cpus == -1) {
  629. if (disabled_cpus > 0)
  630. additional_cpus = disabled_cpus;
  631. else
  632. additional_cpus = 0;
  633. }
  634. possible = available_cpus + additional_cpus;
  635. if (possible > nr_cpu_ids)
  636. possible = nr_cpu_ids;
  637. printk(KERN_INFO "SMP: Allowing %d CPUs, %d hotplug CPUs\n",
  638. possible, max((possible - available_cpus), 0));
  639. for (i = 0; i < possible; i++)
  640. set_cpu_possible(i, true);
  641. }
  642. static int _acpi_map_lsapic(acpi_handle handle, int physid, int *pcpu)
  643. {
  644. cpumask_t tmp_map;
  645. int cpu;
  646. cpumask_complement(&tmp_map, cpu_present_mask);
  647. cpu = cpumask_first(&tmp_map);
  648. if (cpu >= nr_cpu_ids)
  649. return -EINVAL;
  650. acpi_map_cpu2node(handle, cpu, physid);
  651. set_cpu_present(cpu, true);
  652. ia64_cpu_to_sapicid[cpu] = physid;
  653. acpi_processor_set_pdc(handle);
  654. *pcpu = cpu;
  655. return (0);
  656. }
  657. /* wrapper to silence section mismatch warning */
  658. int __ref acpi_map_cpu(acpi_handle handle, phys_cpuid_t physid, u32 acpi_id,
  659. int *pcpu)
  660. {
  661. return _acpi_map_lsapic(handle, physid, pcpu);
  662. }
  663. EXPORT_SYMBOL(acpi_map_cpu);
  664. int acpi_unmap_cpu(int cpu)
  665. {
  666. ia64_cpu_to_sapicid[cpu] = -1;
  667. set_cpu_present(cpu, false);
  668. #ifdef CONFIG_ACPI_NUMA
  669. /* NUMA specific cleanup's */
  670. #endif
  671. return (0);
  672. }
  673. EXPORT_SYMBOL(acpi_unmap_cpu);
  674. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  675. #ifdef CONFIG_ACPI_NUMA
  676. static acpi_status acpi_map_iosapic(acpi_handle handle, u32 depth,
  677. void *context, void **ret)
  678. {
  679. struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
  680. union acpi_object *obj;
  681. struct acpi_madt_io_sapic *iosapic;
  682. unsigned int gsi_base;
  683. int node;
  684. /* Only care about objects w/ a method that returns the MADT */
  685. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  686. return AE_OK;
  687. if (!buffer.length || !buffer.pointer)
  688. return AE_OK;
  689. obj = buffer.pointer;
  690. if (obj->type != ACPI_TYPE_BUFFER ||
  691. obj->buffer.length < sizeof(*iosapic)) {
  692. kfree(buffer.pointer);
  693. return AE_OK;
  694. }
  695. iosapic = (struct acpi_madt_io_sapic *)obj->buffer.pointer;
  696. if (iosapic->header.type != ACPI_MADT_TYPE_IO_SAPIC) {
  697. kfree(buffer.pointer);
  698. return AE_OK;
  699. }
  700. gsi_base = iosapic->global_irq_base;
  701. kfree(buffer.pointer);
  702. /* OK, it's an IOSAPIC MADT entry; associate it with a node */
  703. node = acpi_get_node(handle);
  704. if (node == NUMA_NO_NODE || !node_online(node) ||
  705. cpumask_empty(cpumask_of_node(node)))
  706. return AE_OK;
  707. /* We know a gsi to node mapping! */
  708. map_iosapic_to_node(gsi_base, node);
  709. return AE_OK;
  710. }
  711. static int __init
  712. acpi_map_iosapics (void)
  713. {
  714. acpi_get_devices(NULL, acpi_map_iosapic, NULL, NULL);
  715. return 0;
  716. }
  717. fs_initcall(acpi_map_iosapics);
  718. #endif /* CONFIG_ACPI_NUMA */
  719. int __ref acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
  720. {
  721. int err;
  722. if ((err = iosapic_init(phys_addr, gsi_base)))
  723. return err;
  724. #ifdef CONFIG_ACPI_NUMA
  725. acpi_map_iosapic(handle, 0, NULL, NULL);
  726. #endif /* CONFIG_ACPI_NUMA */
  727. return 0;
  728. }
  729. EXPORT_SYMBOL(acpi_register_ioapic);
  730. int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
  731. {
  732. return iosapic_remove(gsi_base);
  733. }
  734. EXPORT_SYMBOL(acpi_unregister_ioapic);
  735. /*
  736. * acpi_suspend_lowlevel() - save kernel state and suspend.
  737. *
  738. * TBD when IA64 starts to support suspend...
  739. */
  740. int acpi_suspend_lowlevel(void) { return 0; }