debuggers.hg

view xen/arch/ia64/linux-xen/acpi.c @ 17977:11318234588e

[IA64] remove some #ifndef XEN using empty headerfiles.

move mm_numa.c from linux-xen to linux because now mm_numa.c is
identical to linux files.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Thu Jun 19 12:48:04 2008 +0900 (2008-06-19)
parents 220f3d62e272
children 903a901ab372
line source
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 */
35 #include <linux/module.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/sched.h>
39 #include <linux/smp.h>
40 #include <linux/string.h>
41 #include <linux/types.h>
42 #include <linux/irq.h>
43 #include <linux/acpi.h>
44 #include <linux/efi.h>
45 #include <linux/mmzone.h>
46 #include <linux/nodemask.h>
47 #include <asm/io.h>
48 #include <asm/iosapic.h>
49 #include <asm/machvec.h>
50 #include <asm/page.h>
51 #include <asm/system.h>
52 #include <asm/numa.h>
53 #include <asm/sal.h>
54 #include <asm/cyclone.h>
55 #include <asm/xen/hypervisor.h>
56 #ifdef XEN
57 #include <asm/hw_irq.h>
58 extern u8 numa_slit[MAX_NUMNODES * MAX_NUMNODES];
59 #endif
62 #define BAD_MADT_ENTRY(entry, end) ( \
63 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
64 ((struct acpi_subtable_header *)entry)->length < sizeof(*entry))
66 #define PREFIX "ACPI: "
68 void (*pm_idle) (void);
69 EXPORT_SYMBOL(pm_idle);
70 void (*pm_power_off) (void);
71 EXPORT_SYMBOL(pm_power_off);
73 unsigned int acpi_cpei_override;
74 unsigned int acpi_cpei_phys_cpuid;
76 unsigned long acpi_wakeup_address = 0;
78 #ifdef CONFIG_IA64_GENERIC
79 #ifndef XEN
80 static unsigned long __init acpi_find_rsdp(void)
81 #else
82 unsigned long __init acpi_find_rsdp(void)
83 #endif
84 {
85 unsigned long rsdp_phys = 0;
87 if (efi.acpi20 != EFI_INVALID_TABLE_ADDR)
88 rsdp_phys = efi.acpi20;
89 else if (efi.acpi != EFI_INVALID_TABLE_ADDR)
90 printk(KERN_WARNING PREFIX
91 "v1.0/r0.71 tables no longer supported\n");
92 return rsdp_phys;
93 }
94 #endif
96 const char __init *
97 acpi_get_sysname(void)
98 {
99 #ifdef CONFIG_IA64_GENERIC
100 unsigned long rsdp_phys;
101 struct acpi_table_rsdp *rsdp;
102 struct acpi_table_xsdt *xsdt;
103 struct acpi_table_header *hdr;
105 rsdp_phys = acpi_find_rsdp();
106 if (!rsdp_phys) {
107 printk(KERN_ERR
108 "ACPI 2.0 RSDP not found, default to \"dig\"\n");
109 return "dig";
110 }
112 rsdp = (struct acpi_table_rsdp *)__va(rsdp_phys);
113 if (strncmp(rsdp->signature, ACPI_SIG_RSDP, sizeof(ACPI_SIG_RSDP) - 1)) {
114 printk(KERN_ERR
115 "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
116 return "dig";
117 }
119 xsdt = (struct acpi_table_xsdt *)__va(rsdp->xsdt_physical_address);
120 hdr = &xsdt->header;
121 if (strncmp(hdr->signature, ACPI_SIG_XSDT, sizeof(ACPI_SIG_XSDT) - 1)) {
122 printk(KERN_ERR
123 "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
124 return "dig";
125 }
127 if (!strcmp(hdr->oem_id, "HP")) {
128 return "hpzx1";
129 } else if (!strcmp(hdr->oem_id, "SGI")) {
130 if (!strcmp(hdr->oem_table_id + 4, "UV"))
131 return "uv";
132 else
133 return "sn2";
134 #ifndef XEN
135 } else if (is_running_on_xen() && !strcmp(hdr->oem_id, "XEN")) {
136 return "xen";
137 #endif
138 }
140 return "dig";
141 #else
142 # if defined (CONFIG_IA64_HP_SIM)
143 return "hpsim";
144 # elif defined (CONFIG_IA64_HP_ZX1)
145 return "hpzx1";
146 # elif defined (CONFIG_IA64_HP_ZX1_SWIOTLB)
147 return "hpzx1_swiotlb";
148 # elif defined (CONFIG_IA64_SGI_SN2)
149 return "sn2";
150 # elif defined (CONFIG_IA64_SGI_UV)
151 return "uv";
152 # elif defined (CONFIG_IA64_DIG)
153 return "dig";
154 # elif defined (CONFIG_IA64_XEN)
155 return "xen";
156 # else
157 # error Unknown platform. Fix acpi.c.
158 # endif
159 #endif
160 }
162 #ifdef CONFIG_ACPI
164 #define ACPI_MAX_PLATFORM_INTERRUPTS 256
166 /* Array to record platform interrupt vectors for generic interrupt routing. */
167 int platform_intr_list[ACPI_MAX_PLATFORM_INTERRUPTS] = {
168 [0 ... ACPI_MAX_PLATFORM_INTERRUPTS - 1] = -1
169 };
171 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_IOSAPIC;
173 /*
174 * Interrupt routing API for device drivers. Provides interrupt vector for
175 * a generic platform event. Currently only CPEI is implemented.
176 */
177 int acpi_request_vector(u32 int_type)
178 {
179 int vector = -1;
181 if (int_type < ACPI_MAX_PLATFORM_INTERRUPTS) {
182 /* corrected platform error interrupt */
183 vector = platform_intr_list[int_type];
184 } else
185 printk(KERN_ERR
186 "acpi_request_vector(): invalid interrupt type\n");
187 return vector;
188 }
190 char *__init __acpi_map_table(unsigned long phys_addr, unsigned long size)
191 {
192 return __va(phys_addr);
193 }
195 /* --------------------------------------------------------------------------
196 Boot-time Table Parsing
197 -------------------------------------------------------------------------- */
199 static int total_cpus __initdata;
200 static int available_cpus __initdata;
201 struct acpi_table_madt *acpi_madt __initdata;
202 static u8 has_8259;
204 static int __init
205 acpi_parse_lapic_addr_ovr(struct acpi_subtable_header * header,
206 const unsigned long end)
207 {
208 struct acpi_madt_local_apic_override *lapic;
210 lapic = (struct acpi_madt_local_apic_override *)header;
212 if (BAD_MADT_ENTRY(lapic, end))
213 return -EINVAL;
215 if (lapic->address) {
216 iounmap(ipi_base_addr);
217 ipi_base_addr = ioremap(lapic->address, 0);
218 }
219 return 0;
220 }
222 static int __init
223 acpi_parse_lsapic(struct acpi_subtable_header * header, const unsigned long end)
224 {
225 struct acpi_madt_local_sapic *lsapic;
227 lsapic = (struct acpi_madt_local_sapic *)header;
229 /*Skip BAD_MADT_ENTRY check, as lsapic size could vary */
231 if (lsapic->lapic_flags & ACPI_MADT_ENABLED) {
232 #ifdef CONFIG_SMP
233 smp_boot_data.cpu_phys_id[available_cpus] =
234 (lsapic->id << 8) | lsapic->eid;
235 #endif
236 ++available_cpus;
237 }
239 total_cpus++;
240 return 0;
241 }
243 static int __init
244 acpi_parse_lapic_nmi(struct acpi_subtable_header * header, const unsigned long end)
245 {
246 struct acpi_madt_local_apic_nmi *lacpi_nmi;
248 lacpi_nmi = (struct acpi_madt_local_apic_nmi *)header;
250 if (BAD_MADT_ENTRY(lacpi_nmi, end))
251 return -EINVAL;
253 /* TBD: Support lapic_nmi entries */
254 return 0;
255 }
257 static int __init
258 acpi_parse_iosapic(struct acpi_subtable_header * header, const unsigned long end)
259 {
260 struct acpi_madt_io_sapic *iosapic;
262 iosapic = (struct acpi_madt_io_sapic *)header;
264 if (BAD_MADT_ENTRY(iosapic, end))
265 return -EINVAL;
267 return iosapic_init(iosapic->address, iosapic->global_irq_base);
268 }
270 static unsigned int __initdata acpi_madt_rev;
272 static int __init
273 acpi_parse_plat_int_src(struct acpi_subtable_header * header,
274 const unsigned long end)
275 {
276 struct acpi_madt_interrupt_source *plintsrc;
277 int vector;
279 plintsrc = (struct acpi_madt_interrupt_source *)header;
281 if (BAD_MADT_ENTRY(plintsrc, end))
282 return -EINVAL;
284 /*
285 * Get vector assignment for this interrupt, set attributes,
286 * and program the IOSAPIC routing table.
287 */
288 vector = iosapic_register_platform_intr(plintsrc->type,
289 plintsrc->global_irq,
290 plintsrc->io_sapic_vector,
291 plintsrc->eid,
292 plintsrc->id,
293 ((plintsrc->inti_flags & ACPI_MADT_POLARITY_MASK) ==
294 ACPI_MADT_POLARITY_ACTIVE_HIGH) ?
295 IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
296 ((plintsrc->inti_flags & ACPI_MADT_TRIGGER_MASK) ==
297 ACPI_MADT_TRIGGER_EDGE) ?
298 IOSAPIC_EDGE : IOSAPIC_LEVEL);
300 platform_intr_list[plintsrc->type] = vector;
301 if (acpi_madt_rev > 1) {
302 acpi_cpei_override = plintsrc->flags & ACPI_MADT_CPEI_OVERRIDE;
303 }
305 /*
306 * Save the physical id, so we can check when its being removed
307 */
308 acpi_cpei_phys_cpuid = ((plintsrc->id << 8) | (plintsrc->eid)) & 0xffff;
310 return 0;
311 }
313 #ifdef CONFIG_HOTPLUG_CPU
315 #ifdef XEN
316 unsigned int force_cpei_retarget = 0;
317 #endif
319 unsigned int can_cpei_retarget(void)
320 {
321 extern int cpe_vector;
322 extern unsigned int force_cpei_retarget;
324 /*
325 * Only if CPEI is supported and the override flag
326 * is present, otherwise return that its re-targettable
327 * if we are in polling mode.
328 */
329 if (cpe_vector > 0) {
330 if (acpi_cpei_override || force_cpei_retarget)
331 return 1;
332 else
333 return 0;
334 }
335 return 1;
336 }
338 unsigned int is_cpu_cpei_target(unsigned int cpu)
339 {
340 unsigned int logical_id;
342 logical_id = cpu_logical_id(acpi_cpei_phys_cpuid);
344 if (logical_id == cpu)
345 return 1;
346 else
347 return 0;
348 }
350 void set_cpei_target_cpu(unsigned int cpu)
351 {
352 acpi_cpei_phys_cpuid = cpu_physical_id(cpu);
353 }
354 #endif
356 unsigned int get_cpei_target_cpu(void)
357 {
358 return acpi_cpei_phys_cpuid;
359 }
361 static int __init
362 acpi_parse_int_src_ovr(struct acpi_subtable_header * header,
363 const unsigned long end)
364 {
365 struct acpi_madt_interrupt_override *p;
367 p = (struct acpi_madt_interrupt_override *)header;
369 if (BAD_MADT_ENTRY(p, end))
370 return -EINVAL;
372 iosapic_override_isa_irq(p->source_irq, p->global_irq,
373 ((p->inti_flags & ACPI_MADT_POLARITY_MASK) ==
374 ACPI_MADT_POLARITY_ACTIVE_HIGH) ?
375 IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
376 ((p->inti_flags & ACPI_MADT_TRIGGER_MASK) ==
377 ACPI_MADT_TRIGGER_EDGE) ?
378 IOSAPIC_EDGE : IOSAPIC_LEVEL);
379 return 0;
380 }
382 static int __init
383 acpi_parse_nmi_src(struct acpi_subtable_header * header, const unsigned long end)
384 {
385 struct acpi_madt_nmi_source *nmi_src;
387 nmi_src = (struct acpi_madt_nmi_source *)header;
389 if (BAD_MADT_ENTRY(nmi_src, end))
390 return -EINVAL;
392 /* TBD: Support nimsrc entries */
393 return 0;
394 }
396 static void __init acpi_madt_oem_check(char *oem_id, char *oem_table_id)
397 {
398 if (!strncmp(oem_id, "IBM", 3) && (!strncmp(oem_table_id, "SERMOW", 6))) {
400 /*
401 * Unfortunately ITC_DRIFT is not yet part of the
402 * official SAL spec, so the ITC_DRIFT bit is not
403 * set by the BIOS on this hardware.
404 */
405 sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
407 #ifndef XEN
408 cyclone_setup();
409 #endif
410 }
411 }
413 static int __init acpi_parse_madt(struct acpi_table_header *table)
414 {
415 if (!table)
416 return -EINVAL;
418 acpi_madt = (struct acpi_table_madt *)table;
420 acpi_madt_rev = acpi_madt->header.revision;
422 /* remember the value for reference after free_initmem() */
423 #ifdef CONFIG_ITANIUM
424 has_8259 = 1; /* Firmware on old Itanium systems is broken */
425 #else
426 has_8259 = acpi_madt->flags & ACPI_MADT_PCAT_COMPAT;
427 #endif
428 iosapic_system_init(has_8259);
430 /* Get base address of IPI Message Block */
432 if (acpi_madt->address)
433 ipi_base_addr = ioremap(acpi_madt->address, 0);
435 printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
437 acpi_madt_oem_check(acpi_madt->header.oem_id,
438 acpi_madt->header.oem_table_id);
440 return 0;
441 }
443 #ifdef CONFIG_ACPI_NUMA
445 #undef SLIT_DEBUG
447 #define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
449 static int __initdata srat_num_cpus; /* number of cpus */
450 static u32 __devinitdata pxm_flag[PXM_FLAG_LEN];
451 #define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag))
452 #define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag))
453 static struct acpi_table_slit __initdata *slit_table;
454 cpumask_t early_cpu_possible_map = CPU_MASK_NONE;
456 static int get_processor_proximity_domain(struct acpi_srat_cpu_affinity *pa)
457 {
458 int pxm;
460 pxm = pa->proximity_domain_lo;
461 if (ia64_platform_is("sn2"))
462 pxm += pa->proximity_domain_hi[0] << 8;
463 return pxm;
464 }
466 static int get_memory_proximity_domain(struct acpi_srat_mem_affinity *ma)
467 {
468 int pxm;
470 pxm = ma->proximity_domain;
471 if (!ia64_platform_is("sn2"))
472 pxm &= 0xff;
474 return pxm;
475 }
477 /*
478 * ACPI 2.0 SLIT (System Locality Information Table)
479 * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
480 */
481 void __init acpi_numa_slit_init(struct acpi_table_slit *slit)
482 {
483 u32 len;
485 len = sizeof(struct acpi_table_header) + 8
486 + slit->locality_count * slit->locality_count;
487 if (slit->header.length != len) {
488 printk(KERN_ERR
489 "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
490 len, slit->header.length);
491 memset(numa_slit, 10, sizeof(numa_slit));
492 return;
493 }
494 slit_table = slit;
495 }
497 #ifndef XEN
498 void __init
499 acpi_numa_processor_affinity_init(struct acpi_srat_cpu_affinity *pa)
500 #else
501 void __init
502 acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa__)
503 #endif
504 {
505 #ifdef XEN
506 struct acpi_srat_cpu_affinity *pa = (struct acpi_srat_cpu_affinity *)pa__;
507 #endif
508 int pxm;
510 if (!(pa->flags & ACPI_SRAT_CPU_ENABLED))
511 return;
513 pxm = get_processor_proximity_domain(pa);
515 /* record this node in proximity bitmap */
516 pxm_bit_set(pxm);
518 node_cpuid[srat_num_cpus].phys_id =
519 (pa->apic_id << 8) | (pa->local_sapic_eid);
520 /* nid should be overridden as logical node id later */
521 node_cpuid[srat_num_cpus].nid = pxm;
522 cpu_set(srat_num_cpus, early_cpu_possible_map);
523 srat_num_cpus++;
524 }
526 #ifndef XEN
527 void __init
528 acpi_numa_memory_affinity_init(struct acpi_srat_mem_affinity *ma)
529 #else
530 void __init
531 acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma__)
532 #endif
533 {
534 #ifdef XEN
535 struct acpi_srat_mem_affinity *ma =
536 (struct acpi_srat_mem_affinity *)ma__;
537 #endif
538 unsigned long paddr, size;
539 int pxm;
540 struct node_memblk_s *p, *q, *pend;
542 pxm = get_memory_proximity_domain(ma);
544 /* fill node memory chunk structure */
545 paddr = ma->base_address;
546 size = ma->length;
548 /* Ignore disabled entries */
549 if (!(ma->flags & ACPI_SRAT_MEM_ENABLED))
550 return;
552 /* record this node in proximity bitmap */
553 pxm_bit_set(pxm);
555 /* Insertion sort based on base address */
556 pend = &node_memblk[num_node_memblks];
557 for (p = &node_memblk[0]; p < pend; p++) {
558 if (paddr < p->start_paddr)
559 break;
560 }
561 if (p < pend) {
562 for (q = pend - 1; q >= p; q--)
563 *(q + 1) = *q;
564 }
565 p->start_paddr = paddr;
566 p->size = size;
567 p->nid = pxm;
568 num_node_memblks++;
569 }
571 void __init acpi_numa_arch_fixup(void)
572 {
573 int i, j, node_from, node_to;
575 /* If there's no SRAT, fix the phys_id and mark node 0 online */
576 if (srat_num_cpus == 0) {
577 node_set_online(0);
578 node_cpuid[0].phys_id = hard_smp_processor_id();
579 return;
580 }
582 /*
583 * MCD - This can probably be dropped now. No need for pxm ID to node ID
584 * mapping with sparse node numbering iff MAX_PXM_DOMAINS <= MAX_NUMNODES.
585 */
586 nodes_clear(node_online_map);
587 for (i = 0; i < MAX_PXM_DOMAINS; i++) {
588 if (pxm_bit_test(i)) {
589 int nid = acpi_map_pxm_to_node(i);
590 node_set_online(nid);
591 }
592 }
594 /* set logical node id in memory chunk structure */
595 for (i = 0; i < num_node_memblks; i++)
596 node_memblk[i].nid = pxm_to_node(node_memblk[i].nid);
598 /* assign memory bank numbers for each chunk on each node */
599 for_each_online_node(i) {
600 int bank;
602 bank = 0;
603 for (j = 0; j < num_node_memblks; j++)
604 if (node_memblk[j].nid == i)
605 node_memblk[j].bank = bank++;
606 }
608 /* set logical node id in cpu structure */
609 for_each_possible_early_cpu(i)
610 node_cpuid[i].nid = pxm_to_node(node_cpuid[i].nid);
612 printk(KERN_INFO "Number of logical nodes in system = %d\n",
613 num_online_nodes());
614 printk(KERN_INFO "Number of memory chunks in system = %d\n",
615 num_node_memblks);
617 if (!slit_table)
618 return;
619 memset(numa_slit, -1, sizeof(numa_slit));
620 for (i = 0; i < slit_table->locality_count; i++) {
621 if (!pxm_bit_test(i))
622 continue;
623 node_from = pxm_to_node(i);
624 for (j = 0; j < slit_table->locality_count; j++) {
625 if (!pxm_bit_test(j))
626 continue;
627 node_to = pxm_to_node(j);
628 node_distance(node_from, node_to) =
629 slit_table->entry[i * slit_table->locality_count + j];
630 }
631 }
633 #ifdef SLIT_DEBUG
634 printk("ACPI 2.0 SLIT locality table:\n");
635 for_each_online_node(i) {
636 for_each_online_node(j)
637 printk("%03d ", node_distance(i, j));
638 printk("\n");
639 }
640 #endif
641 }
642 #endif /* CONFIG_ACPI_NUMA */
644 #ifndef XEN
645 /*
646 * success: return IRQ number (>=0)
647 * failure: return < 0
648 */
649 int acpi_register_gsi(u32 gsi, int triggering, int polarity)
650 {
651 if (acpi_irq_model == ACPI_IRQ_MODEL_PLATFORM)
652 return gsi;
654 if (has_8259 && gsi < 16)
655 return isa_irq_to_vector(gsi);
657 return iosapic_register_intr(gsi,
658 (polarity ==
659 ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH :
660 IOSAPIC_POL_LOW,
661 (triggering ==
662 ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE :
663 IOSAPIC_LEVEL);
664 }
666 void acpi_unregister_gsi(u32 gsi)
667 {
668 if (acpi_irq_model == ACPI_IRQ_MODEL_PLATFORM)
669 return;
671 if (has_8259 && gsi < 16)
672 return;
674 iosapic_unregister_intr(gsi);
675 }
676 #endif
678 static int __init acpi_parse_fadt(struct acpi_table_header *table)
679 {
680 struct acpi_table_header *fadt_header;
681 struct acpi_table_fadt *fadt;
683 if (!table)
684 return -EINVAL;
686 fadt_header = (struct acpi_table_header *)table;
687 if (fadt_header->revision != 3)
688 return -ENODEV; /* Only deal with ACPI 2.0 FADT */
690 fadt = (struct acpi_table_fadt *)fadt_header;
692 #ifndef XEN
693 acpi_register_gsi(fadt->sci_interrupt, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
694 #endif
695 return 0;
696 }
698 int __init acpi_boot_init(void)
699 {
701 /*
702 * MADT
703 * ----
704 * Parse the Multiple APIC Description Table (MADT), if exists.
705 * Note that this table provides platform SMP configuration
706 * information -- the successor to MPS tables.
707 */
709 if (acpi_table_parse(ACPI_SIG_MADT, acpi_parse_madt)) {
710 printk(KERN_ERR PREFIX "Can't find MADT\n");
711 goto skip_madt;
712 }
714 /* Local APIC */
716 if (acpi_table_parse_madt
717 (ACPI_MADT_TYPE_LOCAL_APIC_OVERRIDE, acpi_parse_lapic_addr_ovr, 0) < 0)
718 printk(KERN_ERR PREFIX
719 "Error parsing LAPIC address override entry\n");
721 if (acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_SAPIC, acpi_parse_lsapic, NR_CPUS)
722 < 1)
723 printk(KERN_ERR PREFIX
724 "Error parsing MADT - no LAPIC entries\n");
726 if (acpi_table_parse_madt(ACPI_MADT_TYPE_LOCAL_APIC_NMI, acpi_parse_lapic_nmi, 0)
727 < 0)
728 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
730 /* I/O APIC */
732 if (acpi_table_parse_madt
733 (ACPI_MADT_TYPE_IO_SAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1) {
734 if (!ia64_platform_is("sn2"))
735 printk(KERN_ERR PREFIX
736 "Error parsing MADT - no IOSAPIC entries\n");
737 }
739 /* System-Level Interrupt Routing */
741 if (acpi_table_parse_madt
742 (ACPI_MADT_TYPE_INTERRUPT_SOURCE, acpi_parse_plat_int_src,
743 ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
744 printk(KERN_ERR PREFIX
745 "Error parsing platform interrupt source entry\n");
747 if (acpi_table_parse_madt
748 (ACPI_MADT_TYPE_INTERRUPT_OVERRIDE, acpi_parse_int_src_ovr, 0) < 0)
749 printk(KERN_ERR PREFIX
750 "Error parsing interrupt source overrides entry\n");
752 if (acpi_table_parse_madt(ACPI_MADT_TYPE_NMI_SOURCE, acpi_parse_nmi_src, 0) < 0)
753 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
754 skip_madt:
756 /*
757 * FADT says whether a legacy keyboard controller is present.
758 * The FADT also contains an SCI_INT line, by which the system
759 * gets interrupts such as power and sleep buttons. If it's not
760 * on a Legacy interrupt, it needs to be setup.
761 */
762 if (acpi_table_parse(ACPI_SIG_FADT, acpi_parse_fadt))
763 printk(KERN_ERR PREFIX "Can't find FADT\n");
765 #ifdef CONFIG_SMP
766 if (available_cpus == 0) {
767 printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
768 printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
769 smp_boot_data.cpu_phys_id[available_cpus] =
770 hard_smp_processor_id();
771 available_cpus = 1; /* We've got at least one of these, no? */
772 }
773 smp_boot_data.cpu_count = available_cpus;
775 smp_build_cpu_map();
776 # ifdef CONFIG_ACPI_NUMA
777 if (srat_num_cpus == 0) {
778 int cpu, i = 1;
779 for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
780 if (smp_boot_data.cpu_phys_id[cpu] !=
781 hard_smp_processor_id())
782 node_cpuid[i++].phys_id =
783 smp_boot_data.cpu_phys_id[cpu];
784 }
785 # endif
786 #endif
787 #ifdef CONFIG_ACPI_NUMA
788 build_cpu_to_node_map();
789 #endif
790 /* Make boot-up look pretty */
791 printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus,
792 total_cpus);
793 return 0;
794 }
796 int acpi_gsi_to_irq(u32 gsi, unsigned int *irq)
797 {
798 int tmp;
800 if (has_8259 && gsi < 16)
801 *irq = isa_irq_to_vector(gsi);
802 else {
803 tmp = gsi_to_irq(gsi);
804 if (tmp == -1)
805 return -1;
806 *irq = tmp;
807 }
808 return 0;
809 }
811 /*
812 * ACPI based hotplug CPU support
813 */
814 #ifdef CONFIG_ACPI_HOTPLUG_CPU
815 static
816 int acpi_map_cpu2node(acpi_handle handle, int cpu, long physid)
817 {
818 #ifdef CONFIG_ACPI_NUMA
819 int pxm_id;
820 int nid;
822 pxm_id = acpi_get_pxm(handle);
823 /*
824 * We don't have cpu-only-node hotadd. But if the system equips
825 * SRAT table, pxm is already found and node is ready.
826 * So, just pxm_to_nid(pxm) is OK.
827 * This code here is for the system which doesn't have full SRAT
828 * table for possible cpus.
829 */
830 nid = acpi_map_pxm_to_node(pxm_id);
831 node_cpuid[cpu].phys_id = physid;
832 node_cpuid[cpu].nid = nid;
833 #endif
834 return (0);
835 }
837 int additional_cpus __initdata = -1;
839 static __init int setup_additional_cpus(char *s)
840 {
841 if (s)
842 additional_cpus = simple_strtol(s, NULL, 0);
844 return 0;
845 }
847 early_param("additional_cpus", setup_additional_cpus);
849 /*
850 * cpu_possible_map should be static, it cannot change as CPUs
851 * are onlined, or offlined. The reason is per-cpu data-structures
852 * are allocated by some modules at init time, and dont expect to
853 * do this dynamically on cpu arrival/departure.
854 * cpu_present_map on the other hand can change dynamically.
855 * In case when cpu_hotplug is not compiled, then we resort to current
856 * behaviour, which is cpu_possible == cpu_present.
857 * - Ashok Raj
858 *
859 * Three ways to find out the number of additional hotplug CPUs:
860 * - If the BIOS specified disabled CPUs in ACPI/mptables use that.
861 * - The user can overwrite it with additional_cpus=NUM
862 * - Otherwise don't reserve additional CPUs.
863 */
864 __init void prefill_possible_map(void)
865 {
866 int i;
867 int possible, disabled_cpus;
869 disabled_cpus = total_cpus - available_cpus;
871 if (additional_cpus == -1) {
872 if (disabled_cpus > 0)
873 additional_cpus = disabled_cpus;
874 else
875 additional_cpus = 0;
876 }
878 possible = available_cpus + additional_cpus;
880 if (possible > NR_CPUS)
881 possible = NR_CPUS;
883 printk(KERN_INFO "SMP: Allowing %d CPUs, %d hotplug CPUs\n",
884 possible, max((possible - available_cpus), 0));
886 for (i = 0; i < possible; i++)
887 cpu_set(i, cpu_possible_map);
888 }
890 #ifndef XEN
891 int acpi_map_lsapic(acpi_handle handle, int *pcpu)
892 {
893 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
894 union acpi_object *obj;
895 struct acpi_madt_local_sapic *lsapic;
896 cpumask_t tmp_map;
897 long physid;
898 int cpu;
900 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
901 return -EINVAL;
903 if (!buffer.length || !buffer.pointer)
904 return -EINVAL;
906 obj = buffer.pointer;
907 if (obj->type != ACPI_TYPE_BUFFER)
908 {
909 kfree(buffer.pointer);
910 return -EINVAL;
911 }
913 lsapic = (struct acpi_madt_local_sapic *)obj->buffer.pointer;
915 if ((lsapic->header.type != ACPI_MADT_TYPE_LOCAL_SAPIC) ||
916 (!(lsapic->lapic_flags & ACPI_MADT_ENABLED))) {
917 kfree(buffer.pointer);
918 return -EINVAL;
919 }
921 physid = ((lsapic->id << 8) | (lsapic->eid));
923 kfree(buffer.pointer);
924 buffer.length = ACPI_ALLOCATE_BUFFER;
925 buffer.pointer = NULL;
927 cpus_complement(tmp_map, cpu_present_map);
928 cpu = first_cpu(tmp_map);
929 if (cpu >= NR_CPUS)
930 return -EINVAL;
932 acpi_map_cpu2node(handle, cpu, physid);
934 cpu_set(cpu, cpu_present_map);
935 ia64_cpu_to_sapicid[cpu] = physid;
937 *pcpu = cpu;
938 return (0);
939 }
941 EXPORT_SYMBOL(acpi_map_lsapic);
943 int acpi_unmap_lsapic(int cpu)
944 {
945 ia64_cpu_to_sapicid[cpu] = -1;
946 cpu_clear(cpu, cpu_present_map);
948 #ifdef CONFIG_ACPI_NUMA
949 /* NUMA specific cleanup's */
950 #endif
952 return (0);
953 }
955 EXPORT_SYMBOL(acpi_unmap_lsapic);
956 #endif /* XEN */
957 #endif /* CONFIG_ACPI_HOTPLUG_CPU */
959 #ifndef XEN
960 #ifdef CONFIG_ACPI_NUMA
961 static acpi_status __devinit
962 acpi_map_iosapic(acpi_handle handle, u32 depth, void *context, void **ret)
963 {
964 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
965 union acpi_object *obj;
966 struct acpi_madt_io_sapic *iosapic;
967 unsigned int gsi_base;
968 int pxm, node;
970 /* Only care about objects w/ a method that returns the MADT */
971 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
972 return AE_OK;
974 if (!buffer.length || !buffer.pointer)
975 return AE_OK;
977 obj = buffer.pointer;
978 if (obj->type != ACPI_TYPE_BUFFER ||
979 obj->buffer.length < sizeof(*iosapic)) {
980 kfree(buffer.pointer);
981 return AE_OK;
982 }
984 iosapic = (struct acpi_madt_io_sapic *)obj->buffer.pointer;
986 if (iosapic->header.type != ACPI_MADT_TYPE_IO_SAPIC) {
987 kfree(buffer.pointer);
988 return AE_OK;
989 }
991 gsi_base = iosapic->global_irq_base;
993 kfree(buffer.pointer);
995 /*
996 * OK, it's an IOSAPIC MADT entry, look for a _PXM value to tell
997 * us which node to associate this with.
998 */
999 pxm = acpi_get_pxm(handle);
1000 if (pxm < 0)
1001 return AE_OK;
1003 node = pxm_to_node(pxm);
1005 if (node >= MAX_NUMNODES || !node_online(node) ||
1006 cpus_empty(node_to_cpumask(node)))
1007 return AE_OK;
1009 /* We know a gsi to node mapping! */
1010 map_iosapic_to_node(gsi_base, node);
1011 return AE_OK;
1014 static int __init
1015 acpi_map_iosapics (void)
1017 acpi_get_devices(NULL, acpi_map_iosapic, NULL, NULL);
1018 return 0;
1021 fs_initcall(acpi_map_iosapics);
1022 #endif /* CONFIG_ACPI_NUMA */
1024 int __ref acpi_register_ioapic(acpi_handle handle, u64 phys_addr, u32 gsi_base)
1026 int err;
1028 if ((err = iosapic_init(phys_addr, gsi_base)))
1029 return err;
1031 #ifdef CONFIG_ACPI_NUMA
1032 acpi_map_iosapic(handle, 0, NULL, NULL);
1033 #endif /* CONFIG_ACPI_NUMA */
1035 return 0;
1038 EXPORT_SYMBOL(acpi_register_ioapic);
1040 int acpi_unregister_ioapic(acpi_handle handle, u32 gsi_base)
1042 return iosapic_remove(gsi_base);
1045 EXPORT_SYMBOL(acpi_unregister_ioapic);
1046 #endif /* XEN */
1048 /*
1049 * acpi_save_state_mem() - save kernel state
1051 * TBD when when IA64 starts to support suspend...
1052 */
1053 int acpi_save_state_mem(void) { return 0; }
1055 /*
1056 * acpi_restore_state()
1057 */
1058 void acpi_restore_state_mem(void) {}
1060 /*
1061 * do_suspend_lowlevel()
1062 */
1063 void do_suspend_lowlevel(void) {}
1065 #endif /* CONFIG_ACPI */