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