acpi.c 26 KB

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