acpi.c 24 KB

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