acpi.c 25 KB

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