2 * acpi.c - Architecture-Specific Low-Level ACPI Support
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>
15 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34 #include <linux/config.h>
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>
47 #include <asm/iosapic.h>
48 #include <asm/machvec.h>
50 #include <asm/system.h>
53 #include <asm/cyclone.h>
55 #define BAD_MADT_ENTRY(entry, end) ( \
56 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
57 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
59 #define PREFIX "ACPI: "
61 void (*pm_idle) (void);
62 EXPORT_SYMBOL(pm_idle);
63 void (*pm_power_off) (void);
65 unsigned char acpi_kbd_controller_present = 1;
66 unsigned char acpi_legacy_devices;
69 acpi_get_sysname (void)
71 #ifdef CONFIG_IA64_GENERIC
72 unsigned long rsdp_phys;
73 struct acpi20_table_rsdp *rsdp;
74 struct acpi_table_xsdt *xsdt;
75 struct acpi_table_header *hdr;
77 rsdp_phys = acpi_find_rsdp();
79 printk(KERN_ERR "ACPI 2.0 RSDP not found, default to \"dig\"\n");
83 rsdp = (struct acpi20_table_rsdp *) __va(rsdp_phys);
84 if (strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1)) {
85 printk(KERN_ERR "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
89 xsdt = (struct acpi_table_xsdt *) __va(rsdp->xsdt_address);
91 if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1)) {
92 printk(KERN_ERR "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
96 if (!strcmp(hdr->oem_id, "HP")) {
99 else if (!strcmp(hdr->oem_id, "SGI")) {
105 # if defined (CONFIG_IA64_HP_SIM)
107 # elif defined (CONFIG_IA64_HP_ZX1)
109 # elif defined (CONFIG_IA64_SGI_SN2)
111 # elif defined (CONFIG_IA64_DIG)
114 # error Unknown platform. Fix acpi.c.
119 #ifdef CONFIG_ACPI_BOOT
121 #define ACPI_MAX_PLATFORM_INTERRUPTS 256
123 /* Array to record platform interrupt vectors for generic interrupt routing. */
124 int platform_intr_list[ACPI_MAX_PLATFORM_INTERRUPTS] = {
125 [0 ... ACPI_MAX_PLATFORM_INTERRUPTS - 1] = -1
128 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_IOSAPIC;
131 * Interrupt routing API for device drivers. Provides interrupt vector for
132 * a generic platform event. Currently only CPEI is implemented.
135 acpi_request_vector (u32 int_type)
139 if (int_type < ACPI_MAX_PLATFORM_INTERRUPTS) {
140 /* corrected platform error interrupt */
141 vector = platform_intr_list[int_type];
143 printk(KERN_ERR "acpi_request_vector(): invalid interrupt type\n");
148 __acpi_map_table (unsigned long phys_addr, unsigned long size)
150 return __va(phys_addr);
153 /* --------------------------------------------------------------------------
154 Boot-time Table Parsing
155 -------------------------------------------------------------------------- */
157 static int total_cpus __initdata;
158 static int available_cpus __initdata;
159 struct acpi_table_madt * acpi_madt __initdata;
164 acpi_parse_lapic_addr_ovr (
165 acpi_table_entry_header *header, const unsigned long end)
167 struct acpi_table_lapic_addr_ovr *lapic;
169 lapic = (struct acpi_table_lapic_addr_ovr *) header;
171 if (BAD_MADT_ENTRY(lapic, end))
174 if (lapic->address) {
175 iounmap((void *) ipi_base_addr);
176 ipi_base_addr = (unsigned long) ioremap(lapic->address, 0);
183 acpi_parse_lsapic (acpi_table_entry_header *header, const unsigned long end)
185 struct acpi_table_lsapic *lsapic;
187 lsapic = (struct acpi_table_lsapic *) header;
189 if (BAD_MADT_ENTRY(lsapic, end))
192 if (lsapic->flags.enabled) {
194 smp_boot_data.cpu_phys_id[available_cpus] = (lsapic->id << 8) | lsapic->eid;
205 acpi_parse_lapic_nmi (acpi_table_entry_header *header, const unsigned long end)
207 struct acpi_table_lapic_nmi *lacpi_nmi;
209 lacpi_nmi = (struct acpi_table_lapic_nmi*) header;
211 if (BAD_MADT_ENTRY(lacpi_nmi, end))
214 /* TBD: Support lapic_nmi entries */
220 acpi_parse_iosapic (acpi_table_entry_header *header, const unsigned long end)
222 struct acpi_table_iosapic *iosapic;
224 iosapic = (struct acpi_table_iosapic *) header;
226 if (BAD_MADT_ENTRY(iosapic, end))
229 iosapic_init(iosapic->address, iosapic->global_irq_base);
236 acpi_parse_plat_int_src (
237 acpi_table_entry_header *header, const unsigned long end)
239 struct acpi_table_plat_int_src *plintsrc;
242 plintsrc = (struct acpi_table_plat_int_src *) header;
244 if (BAD_MADT_ENTRY(plintsrc, end))
248 * Get vector assignment for this interrupt, set attributes,
249 * and program the IOSAPIC routing table.
251 vector = iosapic_register_platform_intr(plintsrc->type,
252 plintsrc->global_irq,
253 plintsrc->iosapic_vector,
256 (plintsrc->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
257 (plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
259 platform_intr_list[plintsrc->type] = vector;
265 acpi_parse_int_src_ovr (
266 acpi_table_entry_header *header, const unsigned long end)
268 struct acpi_table_int_src_ovr *p;
270 p = (struct acpi_table_int_src_ovr *) header;
272 if (BAD_MADT_ENTRY(p, end))
275 iosapic_override_isa_irq(p->bus_irq, p->global_irq,
276 (p->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
277 (p->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
283 acpi_parse_nmi_src (acpi_table_entry_header *header, const unsigned long end)
285 struct acpi_table_nmi_src *nmi_src;
287 nmi_src = (struct acpi_table_nmi_src*) header;
289 if (BAD_MADT_ENTRY(nmi_src, end))
292 /* TBD: Support nimsrc entries */
297 acpi_madt_oem_check (char *oem_id, char *oem_table_id)
299 if (!strncmp(oem_id, "IBM", 3) &&
300 (!strncmp(oem_table_id, "SERMOW", 6))) {
303 * Unfortunately ITC_DRIFT is not yet part of the
304 * official SAL spec, so the ITC_DRIFT bit is not
305 * set by the BIOS on this hardware.
307 sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
314 acpi_parse_madt (unsigned long phys_addr, unsigned long size)
316 if (!phys_addr || !size)
319 acpi_madt = (struct acpi_table_madt *) __va(phys_addr);
321 /* remember the value for reference after free_initmem() */
322 #ifdef CONFIG_ITANIUM
323 has_8259 = 1; /* Firmware on old Itanium systems is broken */
325 has_8259 = acpi_madt->flags.pcat_compat;
327 iosapic_system_init(has_8259);
329 /* Get base address of IPI Message Block */
331 if (acpi_madt->lapic_address)
332 ipi_base_addr = (unsigned long) ioremap(acpi_madt->lapic_address, 0);
334 printk(KERN_INFO PREFIX "Local APIC address 0x%lx\n", ipi_base_addr);
336 acpi_madt_oem_check(acpi_madt->header.oem_id,
337 acpi_madt->header.oem_table_id);
343 #ifdef CONFIG_ACPI_NUMA
347 #define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
349 static int __initdata srat_num_cpus; /* number of cpus */
350 static u32 __initdata pxm_flag[PXM_FLAG_LEN];
351 #define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag))
352 #define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag))
353 /* maps to convert between proximity domain and logical node ID */
354 int __initdata pxm_to_nid_map[MAX_PXM_DOMAINS];
355 int __initdata nid_to_pxm_map[MAX_NUMNODES];
356 static struct acpi_table_slit __initdata *slit_table;
359 * ACPI 2.0 SLIT (System Locality Information Table)
360 * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
363 acpi_numa_slit_init (struct acpi_table_slit *slit)
367 len = sizeof(struct acpi_table_header) + 8
368 + slit->localities * slit->localities;
369 if (slit->header.length != len) {
370 printk(KERN_ERR "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
371 len, slit->header.length);
372 memset(numa_slit, 10, sizeof(numa_slit));
379 acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa)
381 /* record this node in proximity bitmap */
382 pxm_bit_set(pa->proximity_domain);
384 node_cpuid[srat_num_cpus].phys_id = (pa->apic_id << 8) | (pa->lsapic_eid);
385 /* nid should be overridden as logical node id later */
386 node_cpuid[srat_num_cpus].nid = pa->proximity_domain;
391 acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma)
393 unsigned long paddr, size;
395 struct node_memblk_s *p, *q, *pend;
397 pxm = ma->proximity_domain;
399 /* fill node memory chunk structure */
400 paddr = ma->base_addr_hi;
401 paddr = (paddr << 32) | ma->base_addr_lo;
402 size = ma->length_hi;
403 size = (size << 32) | ma->length_lo;
405 /* Ignore disabled entries */
406 if (!ma->flags.enabled)
409 /* record this node in proximity bitmap */
412 /* Insertion sort based on base address */
413 pend = &node_memblk[num_node_memblks];
414 for (p = &node_memblk[0]; p < pend; p++) {
415 if (paddr < p->start_paddr)
419 for (q = pend - 1; q >= p; q--)
422 p->start_paddr = paddr;
429 acpi_numa_arch_fixup (void)
431 int i, j, node_from, node_to;
433 /* If there's no SRAT, fix the phys_id */
434 if (srat_num_cpus == 0) {
435 node_cpuid[0].phys_id = hard_smp_processor_id();
439 /* calculate total number of nodes in system from PXM bitmap */
440 numnodes = 0; /* init total nodes in system */
442 memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
443 memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
444 for (i = 0; i < MAX_PXM_DOMAINS; i++) {
445 if (pxm_bit_test(i)) {
446 pxm_to_nid_map[i] = numnodes;
447 node_set_online(numnodes);
448 nid_to_pxm_map[numnodes++] = i;
452 /* set logical node id in memory chunk structure */
453 for (i = 0; i < num_node_memblks; i++)
454 node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid];
456 /* assign memory bank numbers for each chunk on each node */
457 for (i = 0; i < numnodes; i++) {
461 for (j = 0; j < num_node_memblks; j++)
462 if (node_memblk[j].nid == i)
463 node_memblk[j].bank = bank++;
466 /* set logical node id in cpu structure */
467 for (i = 0; i < srat_num_cpus; i++)
468 node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
470 printk(KERN_INFO "Number of logical nodes in system = %d\n", numnodes);
471 printk(KERN_INFO "Number of memory chunks in system = %d\n", num_node_memblks);
473 if (!slit_table) return;
474 memset(numa_slit, -1, sizeof(numa_slit));
475 for (i=0; i<slit_table->localities; i++) {
476 if (!pxm_bit_test(i))
478 node_from = pxm_to_nid_map[i];
479 for (j=0; j<slit_table->localities; j++) {
480 if (!pxm_bit_test(j))
482 node_to = pxm_to_nid_map[j];
483 node_distance(node_from, node_to) =
484 slit_table->entry[i*slit_table->localities + j];
489 printk("ACPI 2.0 SLIT locality table:\n");
490 for (i = 0; i < numnodes; i++) {
491 for (j = 0; j < numnodes; j++)
492 printk("%03d ", node_distance(i,j));
497 #endif /* CONFIG_ACPI_NUMA */
500 acpi_register_gsi (u32 gsi, int edge_level, int active_high_low)
502 if (has_8259 && gsi < 16)
503 return isa_irq_to_vector(gsi);
505 return iosapic_register_intr(gsi,
506 (active_high_low == ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
507 (edge_level == ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
509 EXPORT_SYMBOL(acpi_register_gsi);
512 acpi_parse_fadt (unsigned long phys_addr, unsigned long size)
514 struct acpi_table_header *fadt_header;
515 struct fadt_descriptor_rev2 *fadt;
517 if (!phys_addr || !size)
520 fadt_header = (struct acpi_table_header *) __va(phys_addr);
521 if (fadt_header->revision != 3)
522 return -ENODEV; /* Only deal with ACPI 2.0 FADT */
524 fadt = (struct fadt_descriptor_rev2 *) fadt_header;
526 if (!(fadt->iapc_boot_arch & BAF_8042_KEYBOARD_CONTROLLER))
527 acpi_kbd_controller_present = 0;
529 if (fadt->iapc_boot_arch & BAF_LEGACY_DEVICES)
530 acpi_legacy_devices = 1;
532 acpi_register_gsi(fadt->sci_int, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
538 acpi_find_rsdp (void)
540 unsigned long rsdp_phys = 0;
543 rsdp_phys = __pa(efi.acpi20);
545 printk(KERN_WARNING PREFIX "v1.0/r0.71 tables no longer supported\n");
551 acpi_boot_init (void)
557 * Parse the Multiple APIC Description Table (MADT), if exists.
558 * Note that this table provides platform SMP configuration
559 * information -- the successor to MPS tables.
562 if (acpi_table_parse(ACPI_APIC, acpi_parse_madt) < 1) {
563 printk(KERN_ERR PREFIX "Can't find MADT\n");
569 if (acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0) < 0)
570 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
572 if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_parse_lsapic, NR_CPUS) < 1)
573 printk(KERN_ERR PREFIX "Error parsing MADT - no LAPIC entries\n");
575 if (acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0) < 0)
576 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
580 if (acpi_table_parse_madt(ACPI_MADT_IOSAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1)
581 printk(KERN_ERR PREFIX "Error parsing MADT - no IOSAPIC entries\n");
583 /* System-Level Interrupt Routing */
585 if (acpi_table_parse_madt(ACPI_MADT_PLAT_INT_SRC, acpi_parse_plat_int_src, ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
586 printk(KERN_ERR PREFIX "Error parsing platform interrupt source entry\n");
588 if (acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, 0) < 0)
589 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
591 if (acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, 0) < 0)
592 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
596 * FADT says whether a legacy keyboard controller is present.
597 * The FADT also contains an SCI_INT line, by which the system
598 * gets interrupts such as power and sleep buttons. If it's not
599 * on a Legacy interrupt, it needs to be setup.
601 if (acpi_table_parse(ACPI_FADT, acpi_parse_fadt) < 1)
602 printk(KERN_ERR PREFIX "Can't find FADT\n");
605 if (available_cpus == 0) {
606 printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
607 printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
608 smp_boot_data.cpu_phys_id[available_cpus] = hard_smp_processor_id();
609 available_cpus = 1; /* We've got at least one of these, no? */
611 smp_boot_data.cpu_count = available_cpus;
614 # ifdef CONFIG_ACPI_NUMA
615 if (srat_num_cpus == 0) {
617 for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
618 if (smp_boot_data.cpu_phys_id[cpu] != hard_smp_processor_id())
619 node_cpuid[i++].phys_id = smp_boot_data.cpu_phys_id[cpu];
621 build_cpu_to_node_map();
624 /* Make boot-up look pretty */
625 printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus, total_cpus);
630 acpi_gsi_to_irq (u32 gsi, unsigned int *irq)
634 if (has_8259 && gsi < 16)
635 *irq = isa_irq_to_vector(gsi);
637 vector = gsi_to_vector(gsi);
646 #endif /* CONFIG_ACPI_BOOT */