acpi.c 25 KB

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