acpi.c 25 KB

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