acpi.c 26 KB

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