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>
46 #include <linux/nodemask.h>
48 #include <asm/iosapic.h>
49 #include <asm/machvec.h>
51 #include <asm/system.h>
54 #include <asm/cyclone.h>
56 #define BAD_MADT_ENTRY(entry, end) ( \
57 (!entry) || (unsigned long)entry + sizeof(*entry) > end || \
58 ((acpi_table_entry_header *)entry)->length != sizeof(*entry))
60 #define PREFIX "ACPI: "
62 void (*pm_idle) (void);
63 EXPORT_SYMBOL(pm_idle);
64 void (*pm_power_off) (void);
65 EXPORT_SYMBOL(pm_power_off);
67 unsigned char acpi_kbd_controller_present = 1;
68 unsigned char acpi_legacy_devices;
70 #define MAX_SAPICS 256
71 u16 ia64_acpiid_to_sapicid[MAX_SAPICS] =
72 { [0 ... MAX_SAPICS - 1] = -1 };
73 EXPORT_SYMBOL(ia64_acpiid_to_sapicid);
76 acpi_get_sysname (void)
78 #ifdef CONFIG_IA64_GENERIC
79 unsigned long rsdp_phys;
80 struct acpi20_table_rsdp *rsdp;
81 struct acpi_table_xsdt *xsdt;
82 struct acpi_table_header *hdr;
84 rsdp_phys = acpi_find_rsdp();
86 printk(KERN_ERR "ACPI 2.0 RSDP not found, default to \"dig\"\n");
90 rsdp = (struct acpi20_table_rsdp *) __va(rsdp_phys);
91 if (strncmp(rsdp->signature, RSDP_SIG, sizeof(RSDP_SIG) - 1)) {
92 printk(KERN_ERR "ACPI 2.0 RSDP signature incorrect, default to \"dig\"\n");
96 xsdt = (struct acpi_table_xsdt *) __va(rsdp->xsdt_address);
98 if (strncmp(hdr->signature, XSDT_SIG, sizeof(XSDT_SIG) - 1)) {
99 printk(KERN_ERR "ACPI 2.0 XSDT signature incorrect, default to \"dig\"\n");
103 if (!strcmp(hdr->oem_id, "HP")) {
106 else if (!strcmp(hdr->oem_id, "SGI")) {
112 # if defined (CONFIG_IA64_HP_SIM)
114 # elif defined (CONFIG_IA64_HP_ZX1)
116 # elif defined (CONFIG_IA64_SGI_SN2)
118 # elif defined (CONFIG_IA64_DIG)
121 # error Unknown platform. Fix acpi.c.
126 #ifdef CONFIG_ACPI_BOOT
128 #define ACPI_MAX_PLATFORM_INTERRUPTS 256
130 /* Array to record platform interrupt vectors for generic interrupt routing. */
131 int platform_intr_list[ACPI_MAX_PLATFORM_INTERRUPTS] = {
132 [0 ... ACPI_MAX_PLATFORM_INTERRUPTS - 1] = -1
135 enum acpi_irq_model_id acpi_irq_model = ACPI_IRQ_MODEL_IOSAPIC;
138 * Interrupt routing API for device drivers. Provides interrupt vector for
139 * a generic platform event. Currently only CPEI is implemented.
142 acpi_request_vector (u32 int_type)
146 if (int_type < ACPI_MAX_PLATFORM_INTERRUPTS) {
147 /* corrected platform error interrupt */
148 vector = platform_intr_list[int_type];
150 printk(KERN_ERR "acpi_request_vector(): invalid interrupt type\n");
155 __acpi_map_table (unsigned long phys_addr, unsigned long size)
157 return __va(phys_addr);
160 /* --------------------------------------------------------------------------
161 Boot-time Table Parsing
162 -------------------------------------------------------------------------- */
164 static int total_cpus __initdata;
165 static int available_cpus __initdata;
166 struct acpi_table_madt * acpi_madt __initdata;
171 acpi_parse_lapic_addr_ovr (
172 acpi_table_entry_header *header, const unsigned long end)
174 struct acpi_table_lapic_addr_ovr *lapic;
176 lapic = (struct acpi_table_lapic_addr_ovr *) header;
178 if (BAD_MADT_ENTRY(lapic, end))
181 if (lapic->address) {
182 iounmap(ipi_base_addr);
183 ipi_base_addr = ioremap(lapic->address, 0);
190 acpi_parse_lsapic (acpi_table_entry_header *header, const unsigned long end)
192 struct acpi_table_lsapic *lsapic;
194 lsapic = (struct acpi_table_lsapic *) header;
196 if (BAD_MADT_ENTRY(lsapic, end))
199 if (lsapic->flags.enabled) {
201 smp_boot_data.cpu_phys_id[available_cpus] = (lsapic->id << 8) | lsapic->eid;
203 ia64_acpiid_to_sapicid[lsapic->acpi_id] = (lsapic->id << 8) | lsapic->eid;
213 acpi_parse_lapic_nmi (acpi_table_entry_header *header, const unsigned long end)
215 struct acpi_table_lapic_nmi *lacpi_nmi;
217 lacpi_nmi = (struct acpi_table_lapic_nmi*) header;
219 if (BAD_MADT_ENTRY(lacpi_nmi, end))
222 /* TBD: Support lapic_nmi entries */
228 acpi_parse_iosapic (acpi_table_entry_header *header, const unsigned long end)
230 struct acpi_table_iosapic *iosapic;
232 iosapic = (struct acpi_table_iosapic *) header;
234 if (BAD_MADT_ENTRY(iosapic, end))
237 iosapic_init(iosapic->address, iosapic->global_irq_base);
244 acpi_parse_plat_int_src (
245 acpi_table_entry_header *header, const unsigned long end)
247 struct acpi_table_plat_int_src *plintsrc;
250 plintsrc = (struct acpi_table_plat_int_src *) header;
252 if (BAD_MADT_ENTRY(plintsrc, end))
256 * Get vector assignment for this interrupt, set attributes,
257 * and program the IOSAPIC routing table.
259 vector = iosapic_register_platform_intr(plintsrc->type,
260 plintsrc->global_irq,
261 plintsrc->iosapic_vector,
264 (plintsrc->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
265 (plintsrc->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
267 platform_intr_list[plintsrc->type] = vector;
273 acpi_parse_int_src_ovr (
274 acpi_table_entry_header *header, const unsigned long end)
276 struct acpi_table_int_src_ovr *p;
278 p = (struct acpi_table_int_src_ovr *) header;
280 if (BAD_MADT_ENTRY(p, end))
283 iosapic_override_isa_irq(p->bus_irq, p->global_irq,
284 (p->flags.polarity == 1) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
285 (p->flags.trigger == 1) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
291 acpi_parse_nmi_src (acpi_table_entry_header *header, const unsigned long end)
293 struct acpi_table_nmi_src *nmi_src;
295 nmi_src = (struct acpi_table_nmi_src*) header;
297 if (BAD_MADT_ENTRY(nmi_src, end))
300 /* TBD: Support nimsrc entries */
305 acpi_madt_oem_check (char *oem_id, char *oem_table_id)
307 if (!strncmp(oem_id, "IBM", 3) &&
308 (!strncmp(oem_table_id, "SERMOW", 6))) {
311 * Unfortunately ITC_DRIFT is not yet part of the
312 * official SAL spec, so the ITC_DRIFT bit is not
313 * set by the BIOS on this hardware.
315 sal_platform_features |= IA64_SAL_PLATFORM_FEATURE_ITC_DRIFT;
322 acpi_parse_madt (unsigned long phys_addr, unsigned long size)
324 if (!phys_addr || !size)
327 acpi_madt = (struct acpi_table_madt *) __va(phys_addr);
329 /* remember the value for reference after free_initmem() */
330 #ifdef CONFIG_ITANIUM
331 has_8259 = 1; /* Firmware on old Itanium systems is broken */
333 has_8259 = acpi_madt->flags.pcat_compat;
335 iosapic_system_init(has_8259);
337 /* Get base address of IPI Message Block */
339 if (acpi_madt->lapic_address)
340 ipi_base_addr = ioremap(acpi_madt->lapic_address, 0);
342 printk(KERN_INFO PREFIX "Local APIC address %p\n", ipi_base_addr);
344 acpi_madt_oem_check(acpi_madt->header.oem_id,
345 acpi_madt->header.oem_table_id);
351 #ifdef CONFIG_ACPI_NUMA
355 #define PXM_FLAG_LEN ((MAX_PXM_DOMAINS + 1)/32)
357 static int __initdata srat_num_cpus; /* number of cpus */
358 static u32 __initdata pxm_flag[PXM_FLAG_LEN];
359 #define pxm_bit_set(bit) (set_bit(bit,(void *)pxm_flag))
360 #define pxm_bit_test(bit) (test_bit(bit,(void *)pxm_flag))
361 /* maps to convert between proximity domain and logical node ID */
362 int __initdata pxm_to_nid_map[MAX_PXM_DOMAINS];
363 int __initdata nid_to_pxm_map[MAX_NUMNODES];
364 static struct acpi_table_slit __initdata *slit_table;
367 * ACPI 2.0 SLIT (System Locality Information Table)
368 * http://devresource.hp.com/devresource/Docs/TechPapers/IA64/slit.pdf
371 acpi_numa_slit_init (struct acpi_table_slit *slit)
375 len = sizeof(struct acpi_table_header) + 8
376 + slit->localities * slit->localities;
377 if (slit->header.length != len) {
378 printk(KERN_ERR "ACPI 2.0 SLIT: size mismatch: %d expected, %d actual\n",
379 len, slit->header.length);
380 memset(numa_slit, 10, sizeof(numa_slit));
387 acpi_numa_processor_affinity_init (struct acpi_table_processor_affinity *pa)
389 /* record this node in proximity bitmap */
390 pxm_bit_set(pa->proximity_domain);
392 node_cpuid[srat_num_cpus].phys_id = (pa->apic_id << 8) | (pa->lsapic_eid);
393 /* nid should be overridden as logical node id later */
394 node_cpuid[srat_num_cpus].nid = pa->proximity_domain;
399 acpi_numa_memory_affinity_init (struct acpi_table_memory_affinity *ma)
401 unsigned long paddr, size;
403 struct node_memblk_s *p, *q, *pend;
405 pxm = ma->proximity_domain;
407 /* fill node memory chunk structure */
408 paddr = ma->base_addr_hi;
409 paddr = (paddr << 32) | ma->base_addr_lo;
410 size = ma->length_hi;
411 size = (size << 32) | ma->length_lo;
413 /* Ignore disabled entries */
414 if (!ma->flags.enabled)
417 /* record this node in proximity bitmap */
420 /* Insertion sort based on base address */
421 pend = &node_memblk[num_node_memblks];
422 for (p = &node_memblk[0]; p < pend; p++) {
423 if (paddr < p->start_paddr)
427 for (q = pend - 1; q >= p; q--)
430 p->start_paddr = paddr;
437 acpi_numa_arch_fixup (void)
439 int i, j, node_from, node_to;
441 /* If there's no SRAT, fix the phys_id and mark node 0 online */
442 if (srat_num_cpus == 0) {
444 node_cpuid[0].phys_id = hard_smp_processor_id();
448 /* calculate total number of nodes in system from PXM bitmap */
449 numnodes = 0; /* init total nodes in system */
451 memset(pxm_to_nid_map, -1, sizeof(pxm_to_nid_map));
452 memset(nid_to_pxm_map, -1, sizeof(nid_to_pxm_map));
453 for (i = 0; i < MAX_PXM_DOMAINS; i++) {
454 if (pxm_bit_test(i)) {
455 pxm_to_nid_map[i] = numnodes;
456 node_set_online(numnodes);
457 nid_to_pxm_map[numnodes++] = i;
461 /* set logical node id in memory chunk structure */
462 for (i = 0; i < num_node_memblks; i++)
463 node_memblk[i].nid = pxm_to_nid_map[node_memblk[i].nid];
465 /* assign memory bank numbers for each chunk on each node */
466 for (i = 0; i < numnodes; i++) {
470 for (j = 0; j < num_node_memblks; j++)
471 if (node_memblk[j].nid == i)
472 node_memblk[j].bank = bank++;
475 /* set logical node id in cpu structure */
476 for (i = 0; i < srat_num_cpus; i++)
477 node_cpuid[i].nid = pxm_to_nid_map[node_cpuid[i].nid];
479 printk(KERN_INFO "Number of logical nodes in system = %d\n", numnodes);
480 printk(KERN_INFO "Number of memory chunks in system = %d\n", num_node_memblks);
482 if (!slit_table) return;
483 memset(numa_slit, -1, sizeof(numa_slit));
484 for (i=0; i<slit_table->localities; i++) {
485 if (!pxm_bit_test(i))
487 node_from = pxm_to_nid_map[i];
488 for (j=0; j<slit_table->localities; j++) {
489 if (!pxm_bit_test(j))
491 node_to = pxm_to_nid_map[j];
492 node_distance(node_from, node_to) =
493 slit_table->entry[i*slit_table->localities + j];
498 printk("ACPI 2.0 SLIT locality table:\n");
499 for (i = 0; i < numnodes; i++) {
500 for (j = 0; j < numnodes; j++)
501 printk("%03d ", node_distance(i,j));
506 #endif /* CONFIG_ACPI_NUMA */
509 acpi_register_gsi (u32 gsi, int edge_level, int active_high_low)
511 if (has_8259 && gsi < 16)
512 return isa_irq_to_vector(gsi);
514 return iosapic_register_intr(gsi,
515 (active_high_low == ACPI_ACTIVE_HIGH) ? IOSAPIC_POL_HIGH : IOSAPIC_POL_LOW,
516 (edge_level == ACPI_EDGE_SENSITIVE) ? IOSAPIC_EDGE : IOSAPIC_LEVEL);
518 EXPORT_SYMBOL(acpi_register_gsi);
521 acpi_parse_fadt (unsigned long phys_addr, unsigned long size)
523 struct acpi_table_header *fadt_header;
524 struct fadt_descriptor_rev2 *fadt;
526 if (!phys_addr || !size)
529 fadt_header = (struct acpi_table_header *) __va(phys_addr);
530 if (fadt_header->revision != 3)
531 return -ENODEV; /* Only deal with ACPI 2.0 FADT */
533 fadt = (struct fadt_descriptor_rev2 *) fadt_header;
535 if (!(fadt->iapc_boot_arch & BAF_8042_KEYBOARD_CONTROLLER))
536 acpi_kbd_controller_present = 0;
538 if (fadt->iapc_boot_arch & BAF_LEGACY_DEVICES)
539 acpi_legacy_devices = 1;
541 acpi_register_gsi(fadt->sci_int, ACPI_LEVEL_SENSITIVE, ACPI_ACTIVE_LOW);
547 acpi_find_rsdp (void)
549 unsigned long rsdp_phys = 0;
552 rsdp_phys = __pa(efi.acpi20);
554 printk(KERN_WARNING PREFIX "v1.0/r0.71 tables no longer supported\n");
560 acpi_boot_init (void)
566 * Parse the Multiple APIC Description Table (MADT), if exists.
567 * Note that this table provides platform SMP configuration
568 * information -- the successor to MPS tables.
571 if (acpi_table_parse(ACPI_APIC, acpi_parse_madt) < 1) {
572 printk(KERN_ERR PREFIX "Can't find MADT\n");
578 if (acpi_table_parse_madt(ACPI_MADT_LAPIC_ADDR_OVR, acpi_parse_lapic_addr_ovr, 0) < 0)
579 printk(KERN_ERR PREFIX "Error parsing LAPIC address override entry\n");
581 if (acpi_table_parse_madt(ACPI_MADT_LSAPIC, acpi_parse_lsapic, NR_CPUS) < 1)
582 printk(KERN_ERR PREFIX "Error parsing MADT - no LAPIC entries\n");
584 if (acpi_table_parse_madt(ACPI_MADT_LAPIC_NMI, acpi_parse_lapic_nmi, 0) < 0)
585 printk(KERN_ERR PREFIX "Error parsing LAPIC NMI entry\n");
589 if (acpi_table_parse_madt(ACPI_MADT_IOSAPIC, acpi_parse_iosapic, NR_IOSAPICS) < 1)
590 printk(KERN_ERR PREFIX "Error parsing MADT - no IOSAPIC entries\n");
592 /* System-Level Interrupt Routing */
594 if (acpi_table_parse_madt(ACPI_MADT_PLAT_INT_SRC, acpi_parse_plat_int_src, ACPI_MAX_PLATFORM_INTERRUPTS) < 0)
595 printk(KERN_ERR PREFIX "Error parsing platform interrupt source entry\n");
597 if (acpi_table_parse_madt(ACPI_MADT_INT_SRC_OVR, acpi_parse_int_src_ovr, 0) < 0)
598 printk(KERN_ERR PREFIX "Error parsing interrupt source overrides entry\n");
600 if (acpi_table_parse_madt(ACPI_MADT_NMI_SRC, acpi_parse_nmi_src, 0) < 0)
601 printk(KERN_ERR PREFIX "Error parsing NMI SRC entry\n");
605 * FADT says whether a legacy keyboard controller is present.
606 * The FADT also contains an SCI_INT line, by which the system
607 * gets interrupts such as power and sleep buttons. If it's not
608 * on a Legacy interrupt, it needs to be setup.
610 if (acpi_table_parse(ACPI_FADT, acpi_parse_fadt) < 1)
611 printk(KERN_ERR PREFIX "Can't find FADT\n");
614 if (available_cpus == 0) {
615 printk(KERN_INFO "ACPI: Found 0 CPUS; assuming 1\n");
616 printk(KERN_INFO "CPU 0 (0x%04x)", hard_smp_processor_id());
617 smp_boot_data.cpu_phys_id[available_cpus] = hard_smp_processor_id();
618 available_cpus = 1; /* We've got at least one of these, no? */
620 smp_boot_data.cpu_count = available_cpus;
623 # ifdef CONFIG_ACPI_NUMA
624 if (srat_num_cpus == 0) {
626 for (cpu = 0; cpu < smp_boot_data.cpu_count; cpu++)
627 if (smp_boot_data.cpu_phys_id[cpu] != hard_smp_processor_id())
628 node_cpuid[i++].phys_id = smp_boot_data.cpu_phys_id[cpu];
630 build_cpu_to_node_map();
633 /* Make boot-up look pretty */
634 printk(KERN_INFO "%d CPUs available, %d CPUs total\n", available_cpus, total_cpus);
639 acpi_gsi_to_irq (u32 gsi, unsigned int *irq)
643 if (has_8259 && gsi < 16)
644 *irq = isa_irq_to_vector(gsi);
646 vector = gsi_to_vector(gsi);
657 acpi_map_iosapic (acpi_handle handle, u32 depth, void *context, void **ret)
659 struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
660 union acpi_object *obj;
661 struct acpi_table_iosapic *iosapic;
662 unsigned int gsi_base;
665 /* Only care about objects w/ a method that returns the MADT */
666 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_MAT", NULL, &buffer)))
669 if (!buffer.length || !buffer.pointer)
672 obj = buffer.pointer;
673 if (obj->type != ACPI_TYPE_BUFFER ||
674 obj->buffer.length < sizeof(*iosapic)) {
675 acpi_os_free(buffer.pointer);
679 iosapic = (struct acpi_table_iosapic *)obj->buffer.pointer;
681 if (iosapic->header.type != ACPI_MADT_IOSAPIC) {
682 acpi_os_free(buffer.pointer);
686 gsi_base = iosapic->global_irq_base;
688 acpi_os_free(buffer.pointer);
689 buffer.length = ACPI_ALLOCATE_BUFFER;
690 buffer.pointer = NULL;
693 * OK, it's an IOSAPIC MADT entry, look for a _PXM method to tell
694 * us which node to associate this with.
696 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_PXM", NULL, &buffer)))
699 if (!buffer.length || !buffer.pointer)
702 obj = buffer.pointer;
704 if (obj->type != ACPI_TYPE_INTEGER ||
705 obj->integer.value >= MAX_PXM_DOMAINS) {
706 acpi_os_free(buffer.pointer);
710 node = pxm_to_nid_map[obj->integer.value];
711 acpi_os_free(buffer.pointer);
713 if (node >= MAX_NUMNODES || !node_online(node) ||
714 cpus_empty(node_to_cpumask(node)))
717 /* We know a gsi to node mapping! */
718 map_iosapic_to_node(gsi_base, node);
721 #endif /* CONFIG_NUMA */
722 #endif /* CONFIG_ACPI_BOOT */