acpi.c 25 KB

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