acpi.c 24 KB

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