acpi.c 26 KB

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