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