acpi.c 26 KB

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