acpi.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850
  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. *
  15. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License as published by
  19. * the Free Software Foundation; either version 2 of the License, or
  20. * (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. *
  31. * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  32. */
  33. #include <linux/config.h>
  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. ((acpi_table_entry_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 char acpi_kbd_controller_present = 1;
  63. unsigned char acpi_legacy_devices;
  64. #define MAX_SAPICS 256
  65. u16 ia64_acpiid_to_sapicid[MAX_SAPICS] =
  66. { [0 ... MAX_SAPICS - 1] = -1 };
  67. EXPORT_SYMBOL(ia64_acpiid_to_sapicid);
  68. const char *
  69. acpi_get_sysname (void)
  70. {
  71. #ifdef CONFIG_IA64_GENERIC
  72. unsigned long rsdp_phys;
  73. struct acpi20_table_rsdp *rsdp;
  74. struct acpi_table_xsdt *xsdt;
  75. struct acpi_table_header *hdr;
  76. rsdp_phys = acpi_find_rsdp();
  77. if (!rsdp_phys) {
  78. printk(KERN_ERR "ACPI 2.0 RSDP not found, default to \"dig\"\n");
  79. return "dig";
  80. }
  81. rsdp = (struct acpi20_table_rsdp *) __va(rsdp_phys);
  82. if (strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1)) {
  83. printk(KERN_ERR "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
  84. return "dig";
  85. }
  86. xsdt = (struct acpi_table_xsdt *) __va(rsdp->xsdt_address);
  87. hdr = &xsdt->header;
  88. if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1)) {
  89. printk(KERN_ERR "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. }
  95. else if (!strcmp(hdr->oem_id, "SGI")) {
  96. return "sn2";
  97. }
  98. return "dig";
  99. #else
  100. # if defined (CONFIG_IA64_HP_SIM)
  101. return "hpsim";
  102. # elif defined (CONFIG_IA64_HP_ZX1)
  103. return "hpzx1";
  104. # elif defined (CONFIG_IA64_HP_ZX1_SWIOTLB)
  105. return "hpzx1_swiotlb";
  106. # elif defined (CONFIG_IA64_SGI_SN2)
  107. return "sn2";
  108. # elif defined (CONFIG_IA64_DIG)
  109. return "dig";
  110. # else
  111. # error Unknown platform. Fix acpi.c.
  112. # endif
  113. #endif
  114. }
  115. #ifdef CONFIG_ACPI_BOOT
  116. #define ACPI_MAX_PLATFORM_INTERRUPTS 256
  117. /* Array to record platform interrupt vectors for generic interrupt routing. */
  118. int platform_intr_list[ACPI_MAX_PLATFORM_INTERRUPTS] = {
  119. [0 ... ACPI_MAX_PLATFORM_INTERRUPTS - 1] = -1
  120. };
  121. enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_IOSAPIC;
  122. /*
  123. * Interrupt routing API for device drivers. Provides interrupt vector for
  124. * a generic platform event. Currently only CPEI is implemented.
  125. */
  126. int
  127. acpi_request_vector (u32 int_type)
  128. {
  129. int vector = -1;
  130. if (int_type < ACPI_MAX_PLATFORM_INTERRUPTS) {
  131. /* corrected platform error interrupt */
  132. vector = platform_intr_list[int_type];
  133. } else
  134. printk(KERN_ERR "acpi_request_vector(): invalid interrupt type\n");
  135. return vector;
  136. }
  137. char *
  138. __acpi_map_table (unsigned long phys_addr, unsigned long size)
  139. {
  140. return __va(phys_addr);
  141. }
  142. /* --------------------------------------------------------------------------
  143. Boot-time Table Parsing
  144. -------------------------------------------------------------------------- */
  145. static int total_cpus __initdata;
  146. static int available_cpus __initdata;
  147. struct acpi_table_madt * acpi_madt __initdata;
  148. static u8 has_8259;
  149. static int __init
  150. acpi_parse_lapic_addr_ovr (
  151. acpi_table_entry_header *header, const unsigned long end)
  152. {
  153. struct acpi_table_lapic_addr_ovr *lapic;
  154. lapic = (struct acpi_table_lapic_addr_ovr *) header;
  155. if (BAD_MADT_ENTRY(lapic, end))
  156. return -EINVAL;
  157. if (lapic->address) {
  158. iounmap(ipi_base_addr);
  159. ipi_base_addr = ioremap(lapic->address, 0);
  160. }
  161. return 0;
  162. }
  163. static int __init
  164. acpi_parse_lsapic (acpi_table_entry_header *header, const unsigned long end)
  165. {
  166. struct acpi_table_lsapic *lsapic;
  167. lsapic = (struct acpi_table_lsapic *) header;
  168. if (BAD_MADT_ENTRY(lsapic, end))
  169. return -EINVAL;
  170. if (lsapic->flags.enabled) {
  171. #ifdef CONFIG_SMP
  172. smp_boot_data.cpu_phys_id[available_cpus] = (lsapic->id << 8) | lsapic->eid;
  173. #endif
  174. ia64_acpiid_to_sapicid[lsapic->acpi_id] = (lsapic->id << 8) | lsapic->eid;
  175. ++available_cpus;
  176. }
  177. total_cpus++;
  178. return 0;
  179. }
  180. static int __init
  181. acpi_parse_lapic_nmi (acpi_table_entry_header *header, const unsigned long end)
  182. {
  183. struct acpi_table_lapic_nmi *lacpi_nmi;
  184. lacpi_nmi = (struct acpi_table_lapic_nmi*) header;
  185. if (BAD_MADT_ENTRY(lacpi_nmi, end))
  186. return -EINVAL;
  187. /* TBD: Support lapic_nmi entries */
  188. return 0;
  189. }
  190. static int __init
  191. acpi_parse_iosapic (acpi_table_entry_header *header, const unsigned long end)
  192. {
  193. struct acpi_table_iosapic *iosapic;
  194. iosapic = (struct acpi_table_iosapic *) header;
  195. if (BAD_MADT_ENTRY(iosapic, end))
  196. return -EINVAL;
  197. return iosapic_init(iosapic->address, iosapic->global_irq_base);
  198. }
  199. static int __init
  200. acpi_parse_plat_int_src (
  201. acpi_table_entry_header *header, const unsigned long end)
  202. {
  203. struct acpi_table_plat_int_src *plintsrc;
  204. int vector;
  205. plintsrc = (struct acpi_table_plat_int_src *) header;
  206. if (BAD_MADT_ENTRY(plintsrc, end))
  207. return -EINVAL;
  208. /*
  209. * Get vector assignment for this interrupt, set attributes,
  210. * and program the IOSAPIC routing table.
  211. */
  212. vector = iosapic_register_platform_intr(plintsrc->type,
  213. plintsrc->global_irq,
  214. plintsrc->iosapic_vector,
  215. plintsrc->eid,
  216. plintsrc->id,
  217. (plintsrc->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
  218. (plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
  219. platform_intr_list[plintsrc->type] = vector;
  220. return 0;
  221. }
  222. static int __init
  223. acpi_parse_int_src_ovr (
  224. acpi_table_entry_header *header, const unsigned long end)
  225. {
  226. struct acpi_table_int_src_ovr *p;
  227. p = (struct acpi_table_int_src_ovr *) header;
  228. if (BAD_MADT_ENTRY(p, end))
  229. return -EINVAL;
  230. iosapic_override_isa_irq(p->bus_irq, p->global_irq,
  231. (p->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
  232. (p->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
  233. return 0;
  234. }
  235. static int __init
  236. acpi_parse_nmi_src (acpi_table_entry_header *header, const unsigned long end)
  237. {
  238. struct acpi_table_nmi_src *nmi_src;
  239. nmi_src = (struct acpi_table_nmi_src*) header;
  240. if (BAD_MADT_ENTRY(nmi_src, end))
  241. return -EINVAL;
  242. /* TBD: Support nimsrc entries */
  243. return 0;
  244. }
  245. static void __init
  246. acpi_madt_oem_check (char *oem_id, char *oem_table_id)
  247. {
  248. if (!strncmp(oem_id, "IBM", 3) &&
  249. (!strncmp(oem_table_id, "SERMOW", 6))) {
  250. /*
  251. * Unfortunately ITC_DRIFT is not yet part of the
  252. * official SAL spec, so the ITC_DRIFT bit is not
  253. * set by the BIOS on this hardware.
  254. */
  255. sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
  256. cyclone_setup();
  257. }
  258. }
  259. static int __init
  260. acpi_parse_madt (unsigned long phys_addr, unsigned long size)
  261. {
  262. if (!phys_addr || !size)
  263. return -EINVAL;
  264. acpi_madt = (struct acpi_table_madt *) __va(phys_addr);
  265. /* remember the value for reference after free_initmem() */
  266. #ifdef CONFIG_ITANIUM
  267. has_8259 = 1; /* Firmware on old Itanium systems is broken */
  268. #else
  269. has_8259 = acpi_madt->flags.pcat_compat;
  270. #endif
  271. iosapic_system_init(has_8259);
  272. /* Get base address of IPI Message Block */
  273. if (acpi_madt->lapic_address)
  274. ipi_base_addr = ioremap(acpi_madt->lapic_address, 0);
  275. printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
  276. acpi_madt_oem_check(acpi_madt->header.oem_id,
  277. acpi_madt->header.oem_table_id);
  278. return 0;
  279. }
  280. #ifdef CONFIG_ACPI_NUMA
  281. #undef SLIT_DEBUG
  282. #define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
  283. static int __initdata srat_num_cpus; /* number of cpus */
  284. static u32 __devinitdata pxm_flag[PXM_FLAG_LEN];
  285. #define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag))
  286. #define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag))
  287. /* maps to convert between proximity domain and logical node ID */
  288. int __devinitdata pxm_to_nid_map[MAX_PXM_DOMAINS];
  289. int __initdata nid_to_pxm_map[MAX_NUMNODES];
  290. static struct acpi_table_slit __initdata *slit_table;
  291. /*
  292. * ACPI 2.0 SLIT (System Locality Information Table)
  293. * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
  294. */
  295. void __init
  296. acpi_numa_slit_init (struct acpi_table_slit *slit)
  297. {
  298. u32 len;
  299. len = sizeof(struct acpi_table_header) + 8
  300. + slit->localities * slit->localities;
  301. if (slit->header.length != len) {
  302. printk(KERN_ERR "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
  303. len, slit->header.length);
  304. memset(numa_slit, 10, sizeof(numa_slit));
  305. return;
  306. }
  307. slit_table = slit;
  308. }
  309. void __init
  310. acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa)
  311. {
  312. /* record this node in proximity bitmap */
  313. pxm_bit_set(pa->proximity_domain);
  314. node_cpuid[srat_num_cpus].phys_id = (pa->apic_id << 8) | (pa->lsapic_eid);
  315. /* nid should be overridden as logical node id later */
  316. node_cpuid[srat_num_cpus].nid = pa->proximity_domain;
  317. srat_num_cpus++;
  318. }
  319. void __init
  320. acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma)
  321. {
  322. unsigned long paddr, size;
  323. u8 pxm;
  324. struct node_memblk_s *p, *q, *pend;
  325. pxm = ma->proximity_domain;
  326. /* fill node memory chunk structure */
  327. paddr = ma->base_addr_hi;
  328. paddr = (paddr << 32) | ma->base_addr_lo;
  329. size = ma->length_hi;
  330. size = (size << 32) | ma->length_lo;
  331. /* Ignore disabled entries */
  332. if (!ma->flags.enabled)
  333. return;
  334. /* record this node in proximity bitmap */
  335. pxm_bit_set(pxm);
  336. /* Insertion sort based on base address */
  337. pend = &node_memblk[num_node_memblks];
  338. for (p = &node_memblk[0]; p < pend; p++) {
  339. if (paddr < p->start_paddr)
  340. break;
  341. }
  342. if (p < pend) {
  343. for (q = pend - 1; q >= p; q--)
  344. *(q + 1) = *q;
  345. }
  346. p->start_paddr = paddr;
  347. p->size = size;
  348. p->nid = pxm;
  349. num_node_memblks++;
  350. }
  351. void __init
  352. acpi_numa_arch_fixup (void)
  353. {
  354. int i, j, node_from, node_to;
  355. /* If there's no SRAT, fix the phys_id and mark node 0 online */
  356. if (srat_num_cpus == 0) {
  357. node_set_online(0);
  358. node_cpuid[0].phys_id = hard_smp_processor_id();
  359. return;
  360. }
  361. /*
  362. * MCD - This can probably be dropped now. No need for pxm ID to node ID
  363. * mapping with sparse node numbering iff MAX_PXM_DOMAINS <= MAX_NUMNODES.
  364. */
  365. /* calculate total number of nodes in system from PXM bitmap */
  366. memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
  367. memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
  368. nodes_clear(node_online_map);
  369. for (i = 0; i < MAX_PXM_DOMAINS; i++) {
  370. if (pxm_bit_test(i)) {
  371. int nid = num_online_nodes();
  372. pxm_to_nid_map[i] = nid;
  373. nid_to_pxm_map[nid] = i;
  374. node_set_online(nid);
  375. }
  376. }
  377. /* set logical node id in memory chunk structure */
  378. for (i = 0; i < num_node_memblks; i++)
  379. node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid];
  380. /* assign memory bank numbers for each chunk on each node */
  381. for_each_online_node(i) {
  382. int bank;
  383. bank = 0;
  384. for (j = 0; j < num_node_memblks; j++)
  385. if (node_memblk[j].nid == i)
  386. node_memblk[j].bank = bank++;
  387. }
  388. /* set logical node id in cpu structure */
  389. for (i = 0; i < srat_num_cpus; i++)
  390. node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
  391. printk(KERN_INFO "Number of logical nodes in system = %d\n", num_online_nodes());
  392. printk(KERN_INFO "Number of memory chunks in system = %d\n", num_node_memblks);
  393. if (!slit_table) return;
  394. memset(numa_slit, -1, sizeof(numa_slit));
  395. for (i=0; i<slit_table->localities; i++) {
  396. if (!pxm_bit_test(i))
  397. continue;
  398. node_from = pxm_to_nid_map[i];
  399. for (j=0; j<slit_table->localities; j++) {
  400. if (!pxm_bit_test(j))
  401. continue;
  402. node_to = pxm_to_nid_map[j];
  403. node_distance(node_from, node_to) =
  404. slit_table->entry[i*slit_table->localities + j];
  405. }
  406. }
  407. #ifdef SLIT_DEBUG
  408. printk("ACPI 2.0 SLIT locality table:\n");
  409. for_each_online_node(i) {
  410. for_each_online_node(j)
  411. printk("%03d ", node_distance(i,j));
  412. printk("\n");
  413. }
  414. #endif
  415. }
  416. #endif /* CONFIG_ACPI_NUMA */
  417. unsigned int
  418. acpi_register_gsi (u32 gsi, int edge_level, int active_high_low)
  419. {
  420. if (has_8259 && gsi < 16)
  421. return isa_irq_to_vector(gsi);
  422. return iosapic_register_intr(gsi,
  423. (active_high_low == ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
  424. (edge_level == ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
  425. }
  426. EXPORT_SYMBOL(acpi_register_gsi);
  427. #ifdef CONFIG_ACPI_DEALLOCATE_IRQ
  428. void
  429. acpi_unregister_gsi (u32 gsi)
  430. {
  431. iosapic_unregister_intr(gsi);
  432. }
  433. EXPORT_SYMBOL(acpi_unregister_gsi);
  434. #endif /* CONFIG_ACPI_DEALLOCATE_IRQ */
  435. static int __init
  436. acpi_parse_fadt (unsigned long phys_addr, unsigned long size)
  437. {
  438. struct acpi_table_header *fadt_header;
  439. struct fadt_descriptor_rev2 *fadt;
  440. if (!phys_addr || !size)
  441. return -EINVAL;
  442. fadt_header = (struct acpi_table_header *) __va(phys_addr);
  443. if (fadt_header->revision != 3)
  444. return -ENODEV; /* Only deal with ACPI 2.0 FADT */
  445. fadt = (struct fadt_descriptor_rev2 *) fadt_header;
  446. if (!(fadt->iapc_boot_arch & BAF_8042_KEYBOARD_CONTROLLER))
  447. acpi_kbd_controller_present = 0;
  448. if (fadt->iapc_boot_arch & BAF_LEGACY_DEVICES)
  449. acpi_legacy_devices = 1;
  450. acpi_register_gsi(fadt->sci_int, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
  451. return 0;
  452. }
  453. unsigned long __init
  454. acpi_find_rsdp (void)
  455. {
  456. unsigned long rsdp_phys = 0;
  457. if (efi.acpi20)
  458. rsdp_phys = __pa(efi.acpi20);
  459. else if (efi.acpi)
  460. printk(KERN_WARNING PREFIX "v1.0/r0.71 tables no longer supported\n");
  461. return rsdp_phys;
  462. }
  463. int __init
  464. acpi_boot_init (void)
  465. {
  466. /*
  467. * MADT
  468. * ----
  469. * Parse the Multiple APIC Description Table (MADT), if exists.
  470. * Note that this table provides platform SMP configuration
  471. * information -- the successor to MPS tables.
  472. */
  473. if (acpi_table_parse(ACPI_APIC, acpi_parse_madt) < 1) {
  474. printk(KERN_ERR PREFIX "Can't find MADT\n");
  475. goto skip_madt;
  476. }
  477. /* Local APIC */
  478. if (acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0) < 0)
  479. printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
  480. if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_parse_lsapic, NR_CPUS) < 1)
  481. printk(KERN_ERR PREFIX "Error parsing MADT - no LAPIC entries\n");
  482. if (acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0) < 0)
  483. printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
  484. /* I/O APIC */
  485. if (acpi_table_parse_madt(ACPI_MADT_IOSAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1)
  486. printk(KERN_ERR PREFIX "Error parsing MADT - no IOSAPIC entries\n");
  487. /* System-Level Interrupt Routing */
  488. if (acpi_table_parse_madt(ACPI_MADT_PLAT_INT_SRC, acpi_parse_plat_int_src, ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
  489. printk(KERN_ERR PREFIX "Error parsing platform interrupt source entry\n");
  490. if (acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, 0) < 0)
  491. printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
  492. if (acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, 0) < 0)
  493. printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
  494. skip_madt:
  495. /*
  496. * FADT says whether a legacy keyboard controller is present.
  497. * The FADT also contains an SCI_INT line, by which the system
  498. * gets interrupts such as power and sleep buttons. If it's not
  499. * on a Legacy interrupt, it needs to be setup.
  500. */
  501. if (acpi_table_parse(ACPI_FADT, acpi_parse_fadt) < 1)
  502. printk(KERN_ERR PREFIX "Can't find FADT\n");
  503. #ifdef CONFIG_SMP
  504. if (available_cpus == 0) {
  505. printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
  506. printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
  507. smp_boot_data.cpu_phys_id[available_cpus] = hard_smp_processor_id();
  508. available_cpus = 1; /* We've got at least one of these, no? */
  509. }
  510. smp_boot_data.cpu_count = available_cpus;
  511. smp_build_cpu_map();
  512. # ifdef CONFIG_ACPI_NUMA
  513. if (srat_num_cpus == 0) {
  514. int cpu, i = 1;
  515. for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
  516. if (smp_boot_data.cpu_phys_id[cpu] != hard_smp_processor_id())
  517. node_cpuid[i++].phys_id = smp_boot_data.cpu_phys_id[cpu];
  518. }
  519. build_cpu_to_node_map();
  520. # endif
  521. #endif
  522. /* Make boot-up look pretty */
  523. printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus, total_cpus);
  524. return 0;
  525. }
  526. int
  527. acpi_gsi_to_irq (u32 gsi, unsigned int *irq)
  528. {
  529. int vector;
  530. if (has_8259 && gsi < 16)
  531. *irq = isa_irq_to_vector(gsi);
  532. else {
  533. vector = gsi_to_vector(gsi);
  534. if (vector == -1)
  535. return -1;
  536. *irq = vector;
  537. }
  538. return 0;
  539. }
  540. /*
  541. * ACPI based hotplug CPU support
  542. */
  543. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  544. static
  545. int
  546. acpi_map_cpu2node(acpi_handle handle, int cpu, long physid)
  547. {
  548. #ifdef CONFIG_ACPI_NUMA
  549. int pxm_id;
  550. pxm_id = acpi_get_pxm(handle);
  551. /*
  552. * Assuming that the container driver would have set the proximity
  553. * domain and would have initialized pxm_to_nid_map[pxm_id] && pxm_flag
  554. */
  555. node_cpuid[cpu].nid = (pxm_id < 0) ? 0:
  556. pxm_to_nid_map[pxm_id];
  557. node_cpuid[cpu].phys_id = physid;
  558. #endif
  559. return(0);
  560. }
  561. int
  562. acpi_map_lsapic(acpi_handle handle, int *pcpu)
  563. {
  564. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  565. union acpi_object *obj;
  566. struct acpi_table_lsapic *lsapic;
  567. cpumask_t tmp_map;
  568. long physid;
  569. int cpu;
  570. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  571. return -EINVAL;
  572. if (!buffer.length || !buffer.pointer)
  573. return -EINVAL;
  574. obj = buffer.pointer;
  575. if (obj->type != ACPI_TYPE_BUFFER ||
  576. obj->buffer.length < sizeof(*lsapic)) {
  577. acpi_os_free(buffer.pointer);
  578. return -EINVAL;
  579. }
  580. lsapic = (struct acpi_table_lsapic *)obj->buffer.pointer;
  581. if ((lsapic->header.type != ACPI_MADT_LSAPIC) ||
  582. (!lsapic->flags.enabled)) {
  583. acpi_os_free(buffer.pointer);
  584. return -EINVAL;
  585. }
  586. physid = ((lsapic->id <<8) | (lsapic->eid));
  587. acpi_os_free(buffer.pointer);
  588. buffer.length = ACPI_ALLOCATE_BUFFER;
  589. buffer.pointer = NULL;
  590. cpus_complement(tmp_map, cpu_present_map);
  591. cpu = first_cpu(tmp_map);
  592. if(cpu >= NR_CPUS)
  593. return -EINVAL;
  594. acpi_map_cpu2node(handle, cpu, physid);
  595. cpu_set(cpu, cpu_present_map);
  596. ia64_cpu_to_sapicid[cpu] = physid;
  597. ia64_acpiid_to_sapicid[lsapic->acpi_id] = ia64_cpu_to_sapicid[cpu];
  598. *pcpu = cpu;
  599. return(0);
  600. }
  601. EXPORT_SYMBOL(acpi_map_lsapic);
  602. int
  603. acpi_unmap_lsapic(int cpu)
  604. {
  605. int i;
  606. for (i=0; i<MAX_SAPICS; i++) {
  607. if (ia64_acpiid_to_sapicid[i] == ia64_cpu_to_sapicid[cpu]) {
  608. ia64_acpiid_to_sapicid[i] = -1;
  609. break;
  610. }
  611. }
  612. ia64_cpu_to_sapicid[cpu] = -1;
  613. cpu_clear(cpu,cpu_present_map);
  614. #ifdef CONFIG_ACPI_NUMA
  615. /* NUMA specific cleanup's */
  616. #endif
  617. return(0);
  618. }
  619. EXPORT_SYMBOL(acpi_unmap_lsapic);
  620. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  621. #ifdef CONFIG_ACPI_NUMA
  622. acpi_status __devinit
  623. acpi_map_iosapic (acpi_handle handle, u32 depth, void *context, void **ret)
  624. {
  625. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  626. union acpi_object *obj;
  627. struct acpi_table_iosapic *iosapic;
  628. unsigned int gsi_base;
  629. int pxm, node;
  630. /* Only care about objects w/ a method that returns the MADT */
  631. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  632. return AE_OK;
  633. if (!buffer.length || !buffer.pointer)
  634. return AE_OK;
  635. obj = buffer.pointer;
  636. if (obj->type != ACPI_TYPE_BUFFER ||
  637. obj->buffer.length < sizeof(*iosapic)) {
  638. acpi_os_free(buffer.pointer);
  639. return AE_OK;
  640. }
  641. iosapic = (struct acpi_table_iosapic *)obj->buffer.pointer;
  642. if (iosapic->header.type != ACPI_MADT_IOSAPIC) {
  643. acpi_os_free(buffer.pointer);
  644. return AE_OK;
  645. }
  646. gsi_base = iosapic->global_irq_base;
  647. acpi_os_free(buffer.pointer);
  648. /*
  649. * OK, it's an IOSAPIC MADT entry, look for a _PXM value to tell
  650. * us which node to associate this with.
  651. */
  652. pxm = acpi_get_pxm(handle);
  653. if (pxm < 0)
  654. return AE_OK;
  655. node = pxm_to_nid_map[pxm];
  656. if (node >= MAX_NUMNODES || !node_online(node) ||
  657. cpus_empty(node_to_cpumask(node)))
  658. return AE_OK;
  659. /* We know a gsi to node mapping! */
  660. map_iosapic_to_node(gsi_base, node);
  661. return AE_OK;
  662. }
  663. #endif /* CONFIG_NUMA */
  664. int
  665. acpi_register_ioapic (acpi_handle handle, u64 phys_addr, u32 gsi_base)
  666. {
  667. int err;
  668. if ((err = iosapic_init(phys_addr, gsi_base)))
  669. return err;
  670. #if CONFIG_ACPI_NUMA
  671. acpi_map_iosapic(handle, 0, NULL, NULL);
  672. #endif /* CONFIG_ACPI_NUMA */
  673. return 0;
  674. }
  675. EXPORT_SYMBOL(acpi_register_ioapic);
  676. int
  677. acpi_unregister_ioapic (acpi_handle handle, u32 gsi_base)
  678. {
  679. return iosapic_remove(gsi_base);
  680. }
  681. EXPORT_SYMBOL(acpi_unregister_ioapic);
  682. #endif /* CONFIG_ACPI_BOOT */