acpi.c 25 KB

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