acpi.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  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. iosapic_init(iosapic->address, iosapic->global_irq_base);
  198. return 0;
  199. }
  200. static int __init
  201. acpi_parse_plat_int_src (
  202. acpi_table_entry_header *header, const unsigned long end)
  203. {
  204. struct acpi_table_plat_int_src *plintsrc;
  205. int vector;
  206. plintsrc = (struct acpi_table_plat_int_src *) header;
  207. if (BAD_MADT_ENTRY(plintsrc, end))
  208. return -EINVAL;
  209. /*
  210. * Get vector assignment for this interrupt, set attributes,
  211. * and program the IOSAPIC routing table.
  212. */
  213. vector = iosapic_register_platform_intr(plintsrc->type,
  214. plintsrc->global_irq,
  215. plintsrc->iosapic_vector,
  216. plintsrc->eid,
  217. plintsrc->id,
  218. (plintsrc->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
  219. (plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
  220. platform_intr_list[plintsrc->type] = vector;
  221. return 0;
  222. }
  223. static int __init
  224. acpi_parse_int_src_ovr (
  225. acpi_table_entry_header *header, const unsigned long end)
  226. {
  227. struct acpi_table_int_src_ovr *p;
  228. p = (struct acpi_table_int_src_ovr *) header;
  229. if (BAD_MADT_ENTRY(p, end))
  230. return -EINVAL;
  231. iosapic_override_isa_irq(p->bus_irq, p->global_irq,
  232. (p->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
  233. (p->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
  234. return 0;
  235. }
  236. static int __init
  237. acpi_parse_nmi_src (acpi_table_entry_header *header, const unsigned long end)
  238. {
  239. struct acpi_table_nmi_src *nmi_src;
  240. nmi_src = (struct acpi_table_nmi_src*) header;
  241. if (BAD_MADT_ENTRY(nmi_src, end))
  242. return -EINVAL;
  243. /* TBD: Support nimsrc entries */
  244. return 0;
  245. }
  246. static void __init
  247. acpi_madt_oem_check (char *oem_id, char *oem_table_id)
  248. {
  249. if (!strncmp(oem_id, "IBM", 3) &&
  250. (!strncmp(oem_table_id, "SERMOW", 6))) {
  251. /*
  252. * Unfortunately ITC_DRIFT is not yet part of the
  253. * official SAL spec, so the ITC_DRIFT bit is not
  254. * set by the BIOS on this hardware.
  255. */
  256. sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
  257. cyclone_setup();
  258. }
  259. }
  260. static int __init
  261. acpi_parse_madt (unsigned long phys_addr, unsigned long size)
  262. {
  263. if (!phys_addr || !size)
  264. return -EINVAL;
  265. acpi_madt = (struct acpi_table_madt *) __va(phys_addr);
  266. /* remember the value for reference after free_initmem() */
  267. #ifdef CONFIG_ITANIUM
  268. has_8259 = 1; /* Firmware on old Itanium systems is broken */
  269. #else
  270. has_8259 = acpi_madt->flags.pcat_compat;
  271. #endif
  272. iosapic_system_init(has_8259);
  273. /* Get base address of IPI Message Block */
  274. if (acpi_madt->lapic_address)
  275. ipi_base_addr = ioremap(acpi_madt->lapic_address, 0);
  276. printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
  277. acpi_madt_oem_check(acpi_madt->header.oem_id,
  278. acpi_madt->header.oem_table_id);
  279. return 0;
  280. }
  281. #ifdef CONFIG_ACPI_NUMA
  282. #undef SLIT_DEBUG
  283. #define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
  284. static int __initdata srat_num_cpus; /* number of cpus */
  285. static u32 __devinitdata pxm_flag[PXM_FLAG_LEN];
  286. #define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag))
  287. #define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag))
  288. /* maps to convert between proximity domain and logical node ID */
  289. int __devinitdata pxm_to_nid_map[MAX_PXM_DOMAINS];
  290. int __initdata nid_to_pxm_map[MAX_NUMNODES];
  291. static struct acpi_table_slit __initdata *slit_table;
  292. /*
  293. * ACPI 2.0 SLIT (System Locality Information Table)
  294. * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
  295. */
  296. void __init
  297. acpi_numa_slit_init (struct acpi_table_slit *slit)
  298. {
  299. u32 len;
  300. len = sizeof(struct acpi_table_header) + 8
  301. + slit->localities * slit->localities;
  302. if (slit->header.length != len) {
  303. printk(KERN_ERR "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
  304. len, slit->header.length);
  305. memset(numa_slit, 10, sizeof(numa_slit));
  306. return;
  307. }
  308. slit_table = slit;
  309. }
  310. void __init
  311. acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa)
  312. {
  313. /* record this node in proximity bitmap */
  314. pxm_bit_set(pa->proximity_domain);
  315. node_cpuid[srat_num_cpus].phys_id = (pa->apic_id << 8) | (pa->lsapic_eid);
  316. /* nid should be overridden as logical node id later */
  317. node_cpuid[srat_num_cpus].nid = pa->proximity_domain;
  318. srat_num_cpus++;
  319. }
  320. void __init
  321. acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma)
  322. {
  323. unsigned long paddr, size;
  324. u8 pxm;
  325. struct node_memblk_s *p, *q, *pend;
  326. pxm = ma->proximity_domain;
  327. /* fill node memory chunk structure */
  328. paddr = ma->base_addr_hi;
  329. paddr = (paddr << 32) | ma->base_addr_lo;
  330. size = ma->length_hi;
  331. size = (size << 32) | ma->length_lo;
  332. /* Ignore disabled entries */
  333. if (!ma->flags.enabled)
  334. return;
  335. /* record this node in proximity bitmap */
  336. pxm_bit_set(pxm);
  337. /* Insertion sort based on base address */
  338. pend = &node_memblk[num_node_memblks];
  339. for (p = &node_memblk[0]; p < pend; p++) {
  340. if (paddr < p->start_paddr)
  341. break;
  342. }
  343. if (p < pend) {
  344. for (q = pend - 1; q >= p; q--)
  345. *(q + 1) = *q;
  346. }
  347. p->start_paddr = paddr;
  348. p->size = size;
  349. p->nid = pxm;
  350. num_node_memblks++;
  351. }
  352. void __init
  353. acpi_numa_arch_fixup (void)
  354. {
  355. int i, j, node_from, node_to;
  356. /* If there's no SRAT, fix the phys_id and mark node 0 online */
  357. if (srat_num_cpus == 0) {
  358. node_set_online(0);
  359. node_cpuid[0].phys_id = hard_smp_processor_id();
  360. return;
  361. }
  362. /*
  363. * MCD - This can probably be dropped now. No need for pxm ID to node ID
  364. * mapping with sparse node numbering iff MAX_PXM_DOMAINS <= MAX_NUMNODES.
  365. */
  366. /* calculate total number of nodes in system from PXM bitmap */
  367. memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
  368. memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
  369. nodes_clear(node_online_map);
  370. for (i = 0; i < MAX_PXM_DOMAINS; i++) {
  371. if (pxm_bit_test(i)) {
  372. int nid = num_online_nodes();
  373. pxm_to_nid_map[i] = nid;
  374. nid_to_pxm_map[nid] = i;
  375. node_set_online(nid);
  376. }
  377. }
  378. /* set logical node id in memory chunk structure */
  379. for (i = 0; i < num_node_memblks; i++)
  380. node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid];
  381. /* assign memory bank numbers for each chunk on each node */
  382. for_each_online_node(i) {
  383. int bank;
  384. bank = 0;
  385. for (j = 0; j < num_node_memblks; j++)
  386. if (node_memblk[j].nid == i)
  387. node_memblk[j].bank = bank++;
  388. }
  389. /* set logical node id in cpu structure */
  390. for (i = 0; i < srat_num_cpus; i++)
  391. node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
  392. printk(KERN_INFO "Number of logical nodes in system = %d\n", num_online_nodes());
  393. printk(KERN_INFO "Number of memory chunks in system = %d\n", num_node_memblks);
  394. if (!slit_table) return;
  395. memset(numa_slit, -1, sizeof(numa_slit));
  396. for (i=0; i<slit_table->localities; i++) {
  397. if (!pxm_bit_test(i))
  398. continue;
  399. node_from = pxm_to_nid_map[i];
  400. for (j=0; j<slit_table->localities; j++) {
  401. if (!pxm_bit_test(j))
  402. continue;
  403. node_to = pxm_to_nid_map[j];
  404. node_distance(node_from, node_to) =
  405. slit_table->entry[i*slit_table->localities + j];
  406. }
  407. }
  408. #ifdef SLIT_DEBUG
  409. printk("ACPI 2.0 SLIT locality table:\n");
  410. for_each_online_node(i) {
  411. for_each_online_node(j)
  412. printk("%03d ", node_distance(i,j));
  413. printk("\n");
  414. }
  415. #endif
  416. }
  417. #endif /* CONFIG_ACPI_NUMA */
  418. unsigned int
  419. acpi_register_gsi (u32 gsi, int edge_level, int active_high_low)
  420. {
  421. if (has_8259 && gsi < 16)
  422. return isa_irq_to_vector(gsi);
  423. return iosapic_register_intr(gsi,
  424. (active_high_low == ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
  425. (edge_level == ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
  426. }
  427. EXPORT_SYMBOL(acpi_register_gsi);
  428. #ifdef CONFIG_ACPI_DEALLOCATE_IRQ
  429. void
  430. acpi_unregister_gsi (u32 gsi)
  431. {
  432. iosapic_unregister_intr(gsi);
  433. }
  434. EXPORT_SYMBOL(acpi_unregister_gsi);
  435. #endif /* CONFIG_ACPI_DEALLOCATE_IRQ */
  436. static int __init
  437. acpi_parse_fadt (unsigned long phys_addr, unsigned long size)
  438. {
  439. struct acpi_table_header *fadt_header;
  440. struct fadt_descriptor_rev2 *fadt;
  441. if (!phys_addr || !size)
  442. return -EINVAL;
  443. fadt_header = (struct acpi_table_header *) __va(phys_addr);
  444. if (fadt_header->revision != 3)
  445. return -ENODEV; /* Only deal with ACPI 2.0 FADT */
  446. fadt = (struct fadt_descriptor_rev2 *) fadt_header;
  447. if (!(fadt->iapc_boot_arch & BAF_8042_KEYBOARD_CONTROLLER))
  448. acpi_kbd_controller_present = 0;
  449. if (fadt->iapc_boot_arch & BAF_LEGACY_DEVICES)
  450. acpi_legacy_devices = 1;
  451. acpi_register_gsi(fadt->sci_int, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
  452. return 0;
  453. }
  454. unsigned long __init
  455. acpi_find_rsdp (void)
  456. {
  457. unsigned long rsdp_phys = 0;
  458. if (efi.acpi20)
  459. rsdp_phys = __pa(efi.acpi20);
  460. else if (efi.acpi)
  461. printk(KERN_WARNING PREFIX "v1.0/r0.71 tables no longer supported\n");
  462. return rsdp_phys;
  463. }
  464. int __init
  465. acpi_boot_init (void)
  466. {
  467. /*
  468. * MADT
  469. * ----
  470. * Parse the Multiple APIC Description Table (MADT), if exists.
  471. * Note that this table provides platform SMP configuration
  472. * information -- the successor to MPS tables.
  473. */
  474. if (acpi_table_parse(ACPI_APIC, acpi_parse_madt) < 1) {
  475. printk(KERN_ERR PREFIX "Can't find MADT\n");
  476. goto skip_madt;
  477. }
  478. /* Local APIC */
  479. if (acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0) < 0)
  480. printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
  481. if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_parse_lsapic, NR_CPUS) < 1)
  482. printk(KERN_ERR PREFIX "Error parsing MADT - no LAPIC entries\n");
  483. if (acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0) < 0)
  484. printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
  485. /* I/O APIC */
  486. if (acpi_table_parse_madt(ACPI_MADT_IOSAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1)
  487. printk(KERN_ERR PREFIX "Error parsing MADT - no IOSAPIC entries\n");
  488. /* System-Level Interrupt Routing */
  489. if (acpi_table_parse_madt(ACPI_MADT_PLAT_INT_SRC, acpi_parse_plat_int_src, ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
  490. printk(KERN_ERR PREFIX "Error parsing platform interrupt source entry\n");
  491. if (acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, 0) < 0)
  492. printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
  493. if (acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, 0) < 0)
  494. printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
  495. skip_madt:
  496. /*
  497. * FADT says whether a legacy keyboard controller is present.
  498. * The FADT also contains an SCI_INT line, by which the system
  499. * gets interrupts such as power and sleep buttons. If it's not
  500. * on a Legacy interrupt, it needs to be setup.
  501. */
  502. if (acpi_table_parse(ACPI_FADT, acpi_parse_fadt) < 1)
  503. printk(KERN_ERR PREFIX "Can't find FADT\n");
  504. #ifdef CONFIG_SMP
  505. if (available_cpus == 0) {
  506. printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
  507. printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
  508. smp_boot_data.cpu_phys_id[available_cpus] = hard_smp_processor_id();
  509. available_cpus = 1; /* We've got at least one of these, no? */
  510. }
  511. smp_boot_data.cpu_count = available_cpus;
  512. smp_build_cpu_map();
  513. # ifdef CONFIG_ACPI_NUMA
  514. if (srat_num_cpus == 0) {
  515. int cpu, i = 1;
  516. for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
  517. if (smp_boot_data.cpu_phys_id[cpu] != hard_smp_processor_id())
  518. node_cpuid[i++].phys_id = smp_boot_data.cpu_phys_id[cpu];
  519. }
  520. build_cpu_to_node_map();
  521. # endif
  522. #endif
  523. /* Make boot-up look pretty */
  524. printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus, total_cpus);
  525. return 0;
  526. }
  527. int
  528. acpi_gsi_to_irq (u32 gsi, unsigned int *irq)
  529. {
  530. int vector;
  531. if (has_8259 && gsi < 16)
  532. *irq = isa_irq_to_vector(gsi);
  533. else {
  534. vector = gsi_to_vector(gsi);
  535. if (vector == -1)
  536. return -1;
  537. *irq = vector;
  538. }
  539. return 0;
  540. }
  541. /*
  542. * ACPI based hotplug CPU support
  543. */
  544. #ifdef CONFIG_ACPI_HOTPLUG_CPU
  545. static
  546. int
  547. acpi_map_cpu2node(acpi_handle handle, int cpu, long physid)
  548. {
  549. #ifdef CONFIG_ACPI_NUMA
  550. int pxm_id;
  551. pxm_id = acpi_get_pxm(handle);
  552. /*
  553. * Assuming that the container driver would have set the proximity
  554. * domain and would have initialized pxm_to_nid_map[pxm_id] && pxm_flag
  555. */
  556. node_cpuid[cpu].nid = (pxm_id < 0) ? 0:
  557. pxm_to_nid_map[pxm_id];
  558. node_cpuid[cpu].phys_id = physid;
  559. #endif
  560. return(0);
  561. }
  562. int
  563. acpi_map_lsapic(acpi_handle handle, int *pcpu)
  564. {
  565. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  566. union acpi_object *obj;
  567. struct acpi_table_lsapic *lsapic;
  568. cpumask_t tmp_map;
  569. long physid;
  570. int cpu;
  571. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  572. return -EINVAL;
  573. if (!buffer.length || !buffer.pointer)
  574. return -EINVAL;
  575. obj = buffer.pointer;
  576. if (obj->type != ACPI_TYPE_BUFFER ||
  577. obj->buffer.length < sizeof(*lsapic)) {
  578. acpi_os_free(buffer.pointer);
  579. return -EINVAL;
  580. }
  581. lsapic = (struct acpi_table_lsapic *)obj->buffer.pointer;
  582. if ((lsapic->header.type != ACPI_MADT_LSAPIC) ||
  583. (!lsapic->flags.enabled)) {
  584. acpi_os_free(buffer.pointer);
  585. return -EINVAL;
  586. }
  587. physid = ((lsapic->id <<8) | (lsapic->eid));
  588. acpi_os_free(buffer.pointer);
  589. buffer.length = ACPI_ALLOCATE_BUFFER;
  590. buffer.pointer = NULL;
  591. cpus_complement(tmp_map, cpu_present_map);
  592. cpu = first_cpu(tmp_map);
  593. if(cpu >= NR_CPUS)
  594. return -EINVAL;
  595. acpi_map_cpu2node(handle, cpu, physid);
  596. cpu_set(cpu, cpu_present_map);
  597. ia64_cpu_to_sapicid[cpu] = physid;
  598. ia64_acpiid_to_sapicid[lsapic->acpi_id] = ia64_cpu_to_sapicid[cpu];
  599. *pcpu = cpu;
  600. return(0);
  601. }
  602. EXPORT_SYMBOL(acpi_map_lsapic);
  603. int
  604. acpi_unmap_lsapic(int cpu)
  605. {
  606. int i;
  607. for (i=0; i<MAX_SAPICS; i++) {
  608. if (ia64_acpiid_to_sapicid[i] == ia64_cpu_to_sapicid[cpu]) {
  609. ia64_acpiid_to_sapicid[i] = -1;
  610. break;
  611. }
  612. }
  613. ia64_cpu_to_sapicid[cpu] = -1;
  614. cpu_clear(cpu,cpu_present_map);
  615. #ifdef CONFIG_ACPI_NUMA
  616. /* NUMA specific cleanup's */
  617. #endif
  618. return(0);
  619. }
  620. EXPORT_SYMBOL(acpi_unmap_lsapic);
  621. #endif /* CONFIG_ACPI_HOTPLUG_CPU */
  622. #ifdef CONFIG_ACPI_NUMA
  623. acpi_status __init
  624. acpi_map_iosapic (acpi_handle handle, u32 depth, void *context, void **ret)
  625. {
  626. struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
  627. union acpi_object *obj;
  628. struct acpi_table_iosapic *iosapic;
  629. unsigned int gsi_base;
  630. int node;
  631. /* Only care about objects w/ a method that returns the MADT */
  632. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
  633. return AE_OK;
  634. if (!buffer.length || !buffer.pointer)
  635. return AE_OK;
  636. obj = buffer.pointer;
  637. if (obj->type != ACPI_TYPE_BUFFER ||
  638. obj->buffer.length < sizeof(*iosapic)) {
  639. acpi_os_free(buffer.pointer);
  640. return AE_OK;
  641. }
  642. iosapic = (struct acpi_table_iosapic *)obj->buffer.pointer;
  643. if (iosapic->header.type != ACPI_MADT_IOSAPIC) {
  644. acpi_os_free(buffer.pointer);
  645. return AE_OK;
  646. }
  647. gsi_base = iosapic->global_irq_base;
  648. acpi_os_free(buffer.pointer);
  649. buffer.length = ACPI_ALLOCATE_BUFFER;
  650. buffer.pointer = NULL;
  651. /*
  652. * OK, it's an IOSAPIC MADT entry, look for a _PXM method to tell
  653. * us which node to associate this with.
  654. */
  655. if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PXM", NULL, &buffer)))
  656. return AE_OK;
  657. if (!buffer.length || !buffer.pointer)
  658. return AE_OK;
  659. obj = buffer.pointer;
  660. if (obj->type != ACPI_TYPE_INTEGER ||
  661. obj->integer.value >= MAX_PXM_DOMAINS) {
  662. acpi_os_free(buffer.pointer);
  663. return AE_OK;
  664. }
  665. node = pxm_to_nid_map[obj->integer.value];
  666. acpi_os_free(buffer.pointer);
  667. if (node >= MAX_NUMNODES || !node_online(node) ||
  668. cpus_empty(node_to_cpumask(node)))
  669. return AE_OK;
  670. /* We know a gsi to node mapping! */
  671. map_iosapic_to_node(gsi_base, node);
  672. return AE_OK;
  673. }
  674. #endif /* CONFIG_NUMA */
  675. #endif /* CONFIG_ACPI_BOOT */