acpi.c 25 KB

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