acpi.c 26 KB

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