acpi.c 23 KB

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