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