acpi.c 25 KB

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