acpi.c 24 KB

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