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