acpi.c 26 KB

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