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