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