The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/i386/acpica/madt.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 2003 John Baldwin <jhb@FreeBSD.org>
    3  * All rights reserved.
    4  *
    5  * Redistribution and use in source and binary forms, with or without
    6  * modification, are permitted provided that the following conditions
    7  * are met:
    8  * 1. Redistributions of source code must retain the above copyright
    9  *    notice, this list of conditions and the following disclaimer.
   10  * 2. Redistributions in binary form must reproduce the above copyright
   11  *    notice, this list of conditions and the following disclaimer in the
   12  *    documentation and/or other materials provided with the distribution.
   13  * 3. Neither the name of the author nor the names of any co-contributors
   14  *    may be used to endorse or promote products derived from this software
   15  *    without specific prior written permission.
   16  *
   17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   27  * SUCH DAMAGE.
   28  */
   29 
   30 #include <sys/cdefs.h>
   31 __FBSDID("$FreeBSD: src/sys/i386/acpica/madt.c,v 1.17.2.1 2005/02/27 21:28:18 obrien Exp $");
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/bus.h>
   36 #include <sys/kernel.h>
   37 #include <sys/malloc.h>
   38 #include <sys/smp.h>
   39 
   40 #include <vm/vm.h>
   41 #include <vm/vm_param.h>
   42 #include <vm/pmap.h>
   43 
   44 #include <machine/apicreg.h>
   45 #include <machine/frame.h>
   46 #include <machine/intr_machdep.h>
   47 #include <machine/apicvar.h>
   48 #include <machine/md_var.h>
   49 #include <machine/specialreg.h>
   50 
   51 #include "acpi.h"
   52 #include <contrib/dev/acpica/actables.h>
   53 #include <dev/acpica/acpivar.h>
   54 #include <dev/pci/pcivar.h>
   55 
   56 #define NIOAPICS                32      /* Max number of I/O APICs */
   57 #define NLAPICS                 32      /* Max number of local APICs */
   58 
   59 typedef void madt_entry_handler(APIC_HEADER *entry, void *arg);
   60 
   61 /* These two arrays are indexed by APIC IDs. */
   62 struct ioapic_info {
   63         void *io_apic;
   64         UINT32 io_vector;
   65 } ioapics[NIOAPICS];
   66 
   67 struct lapic_info {
   68         u_int la_enabled:1;
   69         u_int la_acpi_id:8;
   70 } lapics[NLAPICS];
   71 
   72 static int madt_found_sci_override;
   73 static MULTIPLE_APIC_TABLE *madt;
   74 static vm_paddr_t madt_physaddr;
   75 static vm_offset_t madt_length;
   76 
   77 MALLOC_DEFINE(M_MADT, "MADT Table", "ACPI MADT Table Items");
   78 
   79 static enum intr_polarity interrupt_polarity(UINT16 Polarity, UINT8 Source);
   80 static enum intr_trigger interrupt_trigger(UINT16 TriggerMode, UINT8 Source);
   81 static int      madt_find_cpu(u_int acpi_id, u_int *apic_id);
   82 static int      madt_find_interrupt(int intr, void **apic, u_int *pin);
   83 static void     *madt_map(vm_paddr_t pa, int offset, vm_offset_t length);
   84 static void     *madt_map_table(vm_paddr_t pa, int offset, const char *sig);
   85 static void     madt_parse_apics(APIC_HEADER *entry, void *arg);
   86 static void     madt_parse_interrupt_override(MADT_INTERRUPT_OVERRIDE *intr);
   87 static void     madt_parse_ints(APIC_HEADER *entry, void *arg __unused);
   88 static void     madt_parse_local_nmi(MADT_LOCAL_APIC_NMI *nmi);
   89 static void     madt_parse_nmi(MADT_NMI_SOURCE *nmi);
   90 static int      madt_probe(void);
   91 static int      madt_probe_cpus(void);
   92 static void     madt_probe_cpus_handler(APIC_HEADER *entry, void *arg __unused);
   93 static int      madt_probe_table(vm_paddr_t address);
   94 static void     madt_register(void *dummy);
   95 static int      madt_setup_local(void);
   96 static int      madt_setup_io(void);
   97 static void     madt_unmap(void *data, vm_offset_t length);
   98 static void     madt_unmap_table(void *table);
   99 static void     madt_walk_table(madt_entry_handler *handler, void *arg);
  100 
  101 static struct apic_enumerator madt_enumerator = {
  102         "MADT",
  103         madt_probe,
  104         madt_probe_cpus,
  105         madt_setup_local,
  106         madt_setup_io
  107 };
  108 
  109 /*
  110  * Code to abuse the crashdump map to map in the tables for the early
  111  * probe.  We cheat and make the following assumptions about how we
  112  * use this KVA: page 0 is used to map in the first page of each table
  113  * found via the RSDT or XSDT and pages 1 to n are used to map in the
  114  * RSDT or XSDT.  The offset is in pages; the length is in bytes.
  115  */
  116 static void *
  117 madt_map(vm_paddr_t pa, int offset, vm_offset_t length)
  118 {
  119         vm_offset_t va, off;
  120         void *data;
  121 
  122         off = pa & PAGE_MASK;
  123         length = roundup(length + off, PAGE_SIZE);
  124         pa = pa & PG_FRAME;
  125         va = (vm_offset_t)pmap_kenter_temporary(pa, offset) +
  126             (offset * PAGE_SIZE);
  127         data = (void *)(va + off);
  128         length -= PAGE_SIZE;
  129         while (length > 0) {
  130                 va += PAGE_SIZE;
  131                 pa += PAGE_SIZE;
  132                 length -= PAGE_SIZE;
  133                 pmap_kenter(va, pa);
  134                 invlpg(va);
  135         }
  136         return (data);
  137 }
  138 
  139 static void
  140 madt_unmap(void *data, vm_offset_t length)
  141 {
  142         vm_offset_t va, off;
  143 
  144         va = (vm_offset_t)data;
  145         off = va & PAGE_MASK;
  146         length = roundup(length + off, PAGE_SIZE);
  147         va &= ~PAGE_MASK;
  148         while (length > 0) {
  149                 pmap_kremove(va);
  150                 invlpg(va);
  151                 va += PAGE_SIZE;
  152                 length -= PAGE_SIZE;
  153         }
  154 }
  155 
  156 static void *
  157 madt_map_table(vm_paddr_t pa, int offset, const char *sig)
  158 {
  159         ACPI_TABLE_HEADER *header;
  160         vm_offset_t length;
  161         void *table;
  162 
  163         header = madt_map(pa, offset, sizeof(ACPI_TABLE_HEADER));
  164         if (strncmp(header->Signature, sig, 4) != 0) {
  165                 madt_unmap(header, sizeof(ACPI_TABLE_HEADER));
  166                 return (NULL);
  167         }
  168         length = header->Length;
  169         madt_unmap(header, sizeof(ACPI_TABLE_HEADER));
  170         table = madt_map(pa, offset, length);
  171         if (ACPI_FAILURE(AcpiTbVerifyTableChecksum(table))) {
  172                 if (bootverbose)
  173                         printf("MADT: Failed checksum for table %s\n", sig);
  174                 madt_unmap(table, length);
  175                 return (NULL);
  176         }
  177         return (table);
  178 }
  179 
  180 static void
  181 madt_unmap_table(void *table)
  182 {
  183         ACPI_TABLE_HEADER *header;
  184 
  185         header = (ACPI_TABLE_HEADER *)table;
  186         madt_unmap(table, header->Length);
  187 }
  188 
  189 /*
  190  * Look for an ACPI Multiple APIC Description Table ("APIC")
  191  */
  192 static int
  193 madt_probe(void)
  194 {
  195         ACPI_POINTER rsdp_ptr;
  196         RSDP_DESCRIPTOR *rsdp;
  197         RSDT_DESCRIPTOR *rsdt;
  198         XSDT_DESCRIPTOR *xsdt;
  199         int i, count;
  200 
  201         if (resource_disabled("acpi", 0))
  202                 return (ENXIO);
  203 
  204         /*
  205          * Map in the RSDP.  Since ACPI uses AcpiOsMapMemory() which in turn
  206          * calls pmap_mapdev() to find the RSDP, we assume that we can use
  207          * pmap_mapdev() to map the RSDP.
  208          */
  209         if (AcpiOsGetRootPointer(ACPI_LOGICAL_ADDRESSING, &rsdp_ptr) != AE_OK)
  210                 return (ENXIO);
  211 #ifdef __i386__
  212         KASSERT(rsdp_ptr.Pointer.Physical < KERNLOAD, ("RSDP too high"));
  213 #endif
  214         rsdp = pmap_mapdev(rsdp_ptr.Pointer.Physical, sizeof(RSDP_DESCRIPTOR));
  215         if (rsdp == NULL) {
  216                 if (bootverbose)
  217                         printf("MADT: Failed to map RSDP\n");
  218                 return (ENXIO);
  219         }
  220 
  221         /*
  222          * For ACPI < 2.0, use the RSDT.  For ACPI >= 2.0, use the XSDT.
  223          * We map the XSDT and RSDT at page 1 in the crashdump area.
  224          * Page 0 is used to map in the headers of candidate ACPI tables.
  225          */
  226         if (rsdp->Revision >= 2) {
  227                 /*
  228                  * AcpiOsGetRootPointer only verifies the checksum for
  229                  * the version 1.0 portion of the RSDP.  Version 2.0 has
  230                  * an additional checksum that we verify first.
  231                  */
  232                 if (AcpiTbChecksum(rsdp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0) {
  233                         if (bootverbose)
  234                                 printf("MADT: RSDP failed extended checksum\n");
  235                         return (ENXIO);
  236                 }
  237                 xsdt = madt_map_table(rsdp->XsdtPhysicalAddress, 1, XSDT_SIG);
  238                 if (xsdt == NULL) {
  239                         if (bootverbose)
  240                                 printf("MADT: Failed to map XSDT\n");
  241                         return (ENXIO);
  242                 }
  243                 count = (xsdt->Length - sizeof(ACPI_TABLE_HEADER)) /
  244                     sizeof(UINT64);
  245                 for (i = 0; i < count; i++)
  246                         if (madt_probe_table(xsdt->TableOffsetEntry[i]))
  247                                 break;
  248                 madt_unmap_table(xsdt);
  249         } else {
  250                 rsdt = madt_map_table(rsdp->RsdtPhysicalAddress, 1, RSDT_SIG);
  251                 if (rsdt == NULL) {
  252                         if (bootverbose)
  253                                 printf("MADT: Failed to map RSDT\n");
  254                         return (ENXIO);
  255                 }
  256                 count = (rsdt->Length - sizeof(ACPI_TABLE_HEADER)) /
  257                     sizeof(UINT32);
  258                 for (i = 0; i < count; i++)
  259                         if (madt_probe_table(rsdt->TableOffsetEntry[i]))
  260                                 break;
  261                 madt_unmap_table(rsdt);
  262         }
  263         pmap_unmapdev((vm_offset_t)rsdp, sizeof(RSDP_DESCRIPTOR));
  264         if (madt_physaddr == 0) {
  265                 if (bootverbose)
  266                         printf("MADT: No MADT table found\n");
  267                 return (ENXIO);
  268         }
  269         if (bootverbose)
  270                 printf("MADT: Found table at 0x%jx\n",
  271                     (uintmax_t)madt_physaddr);
  272 
  273         /*
  274          * Verify that we can map the full table and that its checksum is
  275          * correct, etc.
  276          */
  277         madt = madt_map_table(madt_physaddr, 0, APIC_SIG);
  278         if (madt == NULL)
  279                 return (ENXIO);
  280         madt_unmap_table(madt);
  281         madt = NULL;
  282 
  283         return (0);
  284 }
  285 
  286 /*
  287  * See if a given ACPI table is the MADT.
  288  */
  289 static int
  290 madt_probe_table(vm_paddr_t address)
  291 {
  292         ACPI_TABLE_HEADER *table;
  293 
  294         table = madt_map(address, 0, sizeof(ACPI_TABLE_HEADER));
  295         if (table == NULL) {
  296                 if (bootverbose)
  297                         printf("MADT: Failed to map table at 0x%jx\n",
  298                             (uintmax_t)address);
  299                 return (0);
  300         }
  301         if (bootverbose)
  302                 printf("Table '%.4s' at 0x%jx\n", table->Signature,
  303                     (uintmax_t)address);
  304 
  305         if (strncmp(table->Signature, APIC_SIG, 4) != 0) {
  306                 madt_unmap(table, sizeof(ACPI_TABLE_HEADER));
  307                 return (0);
  308         }
  309         madt_physaddr = address;
  310         madt_length = table->Length;
  311         madt_unmap(table, sizeof(ACPI_TABLE_HEADER));
  312         return (1);
  313 }
  314 
  315 /*
  316  * Run through the MP table enumerating CPUs.
  317  */
  318 static int
  319 madt_probe_cpus(void)
  320 {
  321 
  322         madt = madt_map_table(madt_physaddr, 0, APIC_SIG);
  323         KASSERT(madt != NULL, ("Unable to re-map MADT"));
  324         madt_walk_table(madt_probe_cpus_handler, NULL);
  325         madt_unmap_table(madt);
  326         madt = NULL;
  327         return (0);
  328 }
  329 
  330 /*
  331  * Initialize the local APIC on the BSP.
  332  */
  333 static int
  334 madt_setup_local(void)
  335 {
  336 
  337         madt = pmap_mapdev(madt_physaddr, madt_length);
  338         lapic_init((uintptr_t)madt->LocalApicAddress);
  339         printf("ACPI APIC Table: <%.*s %.*s>\n",
  340             (int)sizeof(madt->OemId), madt->OemId,
  341             (int)sizeof(madt->OemTableId), madt->OemTableId);
  342 
  343         /*
  344          * We ignore 64-bit local APIC override entries.  Should we
  345          * perhaps emit a warning here if we find one?
  346          */
  347         return (0);
  348 }
  349 
  350 /*
  351  * Enumerate I/O APICs and setup interrupt sources.
  352  */
  353 static int
  354 madt_setup_io(void)
  355 {
  356         void *ioapic;
  357         u_int pin;
  358         int i;
  359 
  360         /* Try to initialize ACPI so that we can access the FADT. */
  361         i = acpi_Startup();
  362         if (ACPI_FAILURE(i)) {
  363                 printf("MADT: ACPI Startup failed with %s\n",
  364                     AcpiFormatException(i));
  365                 printf("Try disabling either ACPI or apic support.\n");
  366                 panic("Using MADT but ACPI doesn't work");
  367         }
  368                     
  369         /* First, we run through adding I/O APIC's. */
  370         if (madt->PCATCompat && !(acpi_quirks & ACPI_Q_MADT_IRQ0))
  371                 ioapic_enable_mixed_mode();
  372         madt_walk_table(madt_parse_apics, NULL);
  373 
  374         /* Second, we run through the table tweaking interrupt sources. */
  375         madt_walk_table(madt_parse_ints, NULL);
  376 
  377         /*
  378          * If there was not an explicit override entry for the SCI,
  379          * force it to use level trigger and active-low polarity.
  380          */
  381         if (!madt_found_sci_override) {
  382                 if (madt_find_interrupt(AcpiGbl_FADT->SciInt, &ioapic, &pin)
  383                     != 0)
  384                         printf("MADT: Could not find APIC for SCI IRQ %d\n",
  385                             AcpiGbl_FADT->SciInt);
  386                 else {
  387                         printf(
  388         "MADT: Forcing active-low polarity and level trigger for SCI\n");
  389                         ioapic_set_polarity(ioapic, pin, INTR_POLARITY_LOW);
  390                         ioapic_set_triggermode(ioapic, pin, INTR_TRIGGER_LEVEL);
  391                 }
  392         }
  393 
  394         /* Third, we register all the I/O APIC's. */
  395         for (i = 0; i < NIOAPICS; i++)
  396                 if (ioapics[i].io_apic != NULL)
  397                         ioapic_register(ioapics[i].io_apic);
  398 
  399         /* Finally, we throw the switch to enable the I/O APIC's. */
  400         acpi_SetDefaultIntrModel(ACPI_INTR_APIC);
  401 
  402         return (0);
  403 }
  404 
  405 static void
  406 madt_register(void *dummy __unused)
  407 {
  408 
  409         apic_register_enumerator(&madt_enumerator);
  410 }
  411 SYSINIT(madt_register, SI_SUB_CPU - 1, SI_ORDER_FIRST, madt_register, NULL)
  412 
  413 /*
  414  * Call the handler routine for each entry in the MADT table.
  415  */
  416 static void
  417 madt_walk_table(madt_entry_handler *handler, void *arg)
  418 {
  419         APIC_HEADER *entry;
  420         u_char *p, *end;
  421 
  422         end = (u_char *)(madt) + madt->Length;
  423         for (p = (u_char *)(madt + 1); p < end; ) {
  424                 entry = (APIC_HEADER *)p;
  425                 handler(entry, arg);
  426                 p += entry->Length;
  427         }
  428 }
  429 
  430 static void
  431 madt_probe_cpus_handler(APIC_HEADER *entry, void *arg)
  432 {
  433         MADT_PROCESSOR_APIC *proc;
  434         struct lapic_info *la;
  435 
  436         switch (entry->Type) {
  437         case APIC_PROCESSOR:
  438                 /*
  439                  * The MADT does not include a BSP flag, so we have to
  440                  * let the MP code figure out which CPU is the BSP on
  441                  * its own.
  442                  */
  443                 proc = (MADT_PROCESSOR_APIC *)entry;
  444                 if (bootverbose)
  445                         printf("MADT: Found CPU APIC ID %d ACPI ID %d: %s\n",
  446                             proc->LocalApicId, proc->ProcessorId,
  447                             proc->ProcessorEnabled ? "enabled" : "disabled");
  448                 if (!proc->ProcessorEnabled)
  449                         break;
  450                 if (proc->LocalApicId >= NLAPICS)
  451                         panic("%s: CPU ID %d too high", __func__,
  452                             proc->LocalApicId);
  453                 la = &lapics[proc->LocalApicId];
  454                 KASSERT(la->la_enabled == 0,
  455                     ("Duplicate local APIC ID %d", proc->LocalApicId));
  456                 la->la_enabled = 1;
  457                 la->la_acpi_id = proc->ProcessorId;
  458                 lapic_create(proc->LocalApicId, 0);
  459                 break;
  460         }
  461 }
  462 
  463 
  464 /*
  465  * Add an I/O APIC from an entry in the table.
  466  */
  467 static void
  468 madt_parse_apics(APIC_HEADER *entry, void *arg __unused)
  469 {
  470         MADT_IO_APIC *apic;
  471 
  472         switch (entry->Type) {
  473         case APIC_IO:
  474                 apic = (MADT_IO_APIC *)entry;
  475                 if (bootverbose)
  476                         printf("MADT: Found IO APIC ID %d, Interrupt %d at %p\n",
  477                             apic->IoApicId, apic->Interrupt,
  478                             (void *)(uintptr_t)apic->Address);
  479                 if (apic->IoApicId >= NIOAPICS)
  480                         panic("%s: I/O APIC ID %d too high", __func__,
  481                             apic->IoApicId);
  482                 if (ioapics[apic->IoApicId].io_apic != NULL)
  483                         panic("%s: Double APIC ID %d", __func__,
  484                             apic->IoApicId);
  485                 ioapics[apic->IoApicId].io_apic = ioapic_create(
  486                         (uintptr_t)apic->Address, apic->IoApicId,
  487                             apic->Interrupt);
  488                 ioapics[apic->IoApicId].io_vector = apic->Interrupt;
  489                 break;
  490         default:
  491                 break;
  492         }
  493 }
  494 
  495 /*
  496  * Determine properties of an interrupt source.  Note that for ACPI these
  497  * functions are only used for ISA interrupts, so we assume ISA bus values
  498  * (Active Hi, Edge Triggered) for conforming values except for the ACPI
  499  * SCI for which we use Active Lo, Level Triggered.
  500  */
  501 static enum intr_polarity
  502 interrupt_polarity(UINT16 Polarity, UINT8 Source)
  503 {
  504 
  505         switch (Polarity) {
  506         case POLARITY_CONFORMS:
  507                 if (Source == AcpiGbl_FADT->SciInt)
  508                         return (INTR_POLARITY_LOW);
  509                 else
  510                         return (INTR_POLARITY_HIGH);
  511         case POLARITY_ACTIVE_HIGH:
  512                 return (INTR_POLARITY_HIGH);
  513         case POLARITY_ACTIVE_LOW:
  514                 return (INTR_POLARITY_LOW);
  515         default:
  516                 panic("Bogus Interrupt Polarity");
  517         }
  518 }
  519 
  520 static enum intr_trigger
  521 interrupt_trigger(UINT16 TriggerMode, UINT8 Source)
  522 {
  523 
  524         switch (TriggerMode) {
  525         case TRIGGER_CONFORMS:
  526                 if (Source == AcpiGbl_FADT->SciInt)
  527                         return (INTR_TRIGGER_LEVEL);
  528                 else
  529                         return (INTR_TRIGGER_EDGE);
  530         case TRIGGER_EDGE:
  531                 return (INTR_TRIGGER_EDGE);
  532         case TRIGGER_LEVEL:
  533                 return (INTR_TRIGGER_LEVEL);
  534         default:
  535                 panic("Bogus Interrupt Trigger Mode");
  536         }
  537 }
  538 
  539 /*
  540  * Find the local APIC ID associated with a given ACPI Processor ID.
  541  */
  542 static int
  543 madt_find_cpu(u_int acpi_id, u_int *apic_id)
  544 {
  545         int i;
  546 
  547         for (i = 0; i < NLAPICS; i++) {
  548                 if (!lapics[i].la_enabled)
  549                         continue;
  550                 if (lapics[i].la_acpi_id != acpi_id)
  551                         continue;
  552                 *apic_id = i;
  553                 return (0);
  554         }
  555         return (ENOENT);
  556 }
  557 
  558 /*
  559  * Find the IO APIC and pin on that APIC associated with a given global
  560  * interrupt.
  561  */
  562 static int
  563 madt_find_interrupt(int intr, void **apic, u_int *pin)
  564 {
  565         int i, best;
  566 
  567         best = -1;
  568         for (i = 0; i < NIOAPICS; i++) {
  569                 if (ioapics[i].io_apic == NULL ||
  570                     ioapics[i].io_vector > intr)
  571                         continue;
  572                 if (best == -1 ||
  573                     ioapics[best].io_vector < ioapics[i].io_vector)
  574                         best = i;
  575         }
  576         if (best == -1)
  577                 return (ENOENT);
  578         *apic = ioapics[best].io_apic;
  579         *pin = intr - ioapics[best].io_vector;
  580         if (*pin > 32)
  581                 printf("WARNING: Found intpin of %u for vector %d\n", *pin,
  582                     intr);
  583         return (0);
  584 }
  585 
  586 /*
  587  * Parse an interrupt source override for an ISA interrupt.
  588  */
  589 static void
  590 madt_parse_interrupt_override(MADT_INTERRUPT_OVERRIDE *intr)
  591 {
  592         void *new_ioapic, *old_ioapic;
  593         u_int new_pin, old_pin;
  594         enum intr_trigger trig;
  595         enum intr_polarity pol;
  596         char buf[64];
  597 
  598         if (acpi_quirks & ACPI_Q_MADT_IRQ0 && intr->Source == 0 &&
  599             intr->Interrupt == 2) {
  600                 if (bootverbose)
  601                         printf("MADT: Skipping timer override\n");
  602                 return;
  603         }
  604         if (bootverbose)
  605                 printf("MADT: Interrupt override: source %u, irq %u\n",
  606                     intr->Source, intr->Interrupt);
  607         KASSERT(intr->Bus == 0, ("bus for interrupt overrides must be zero"));
  608         if (madt_find_interrupt(intr->Interrupt, &new_ioapic,
  609             &new_pin) != 0) {
  610                 printf("MADT: Could not find APIC for vector %d (IRQ %d)\n",
  611                     intr->Interrupt, intr->Source);
  612                 return;
  613         }
  614 
  615         /*
  616          * Lookup the appropriate trigger and polarity modes for this
  617          * entry.
  618          */
  619         trig = interrupt_trigger(intr->TriggerMode, intr->Source);
  620         pol = interrupt_polarity(intr->Polarity, intr->Source);
  621         
  622         /*
  623          * If the SCI is identity mapped but has edge trigger and
  624          * active-hi polarity or the force_sci_lo tunable is set,
  625          * force it to use level/lo.
  626          */
  627         if (intr->Source == AcpiGbl_FADT->SciInt) {
  628                 madt_found_sci_override = 1;
  629                 if (getenv_string("hw.acpi.sci.trigger", buf, sizeof(buf))) {
  630                         if (tolower(buf[0]) == 'e')
  631                                 trig = INTR_TRIGGER_EDGE;
  632                         else if (tolower(buf[0]) == 'l')
  633                                 trig = INTR_TRIGGER_LEVEL;
  634                         else
  635                                 panic(
  636                                 "Invalid trigger %s: must be 'edge' or 'level'",
  637                                     buf);
  638                         printf("MADT: Forcing SCI to %s trigger\n",
  639                             trig == INTR_TRIGGER_EDGE ? "edge" : "level");
  640                 }
  641                 if (getenv_string("hw.acpi.sci.polarity", buf, sizeof(buf))) {
  642                         if (tolower(buf[0]) == 'h')
  643                                 pol = INTR_POLARITY_HIGH;
  644                         else if (tolower(buf[0]) == 'l')
  645                                 pol = INTR_POLARITY_LOW;
  646                         else
  647                                 panic(
  648                                 "Invalid polarity %s: must be 'high' or 'low'",
  649                                     buf);
  650                         printf("MADT: Forcing SCI to active %s polarity\n",
  651                             pol == INTR_POLARITY_HIGH ? "high" : "low");
  652                 }
  653         }
  654 
  655         /* Remap the IRQ if it is mapped to a different interrupt vector. */
  656         if (intr->Source != intr->Interrupt) {
  657                 /*
  658                  * If the SCI is remapped to a non-ISA global interrupt,
  659                  * then override the vector we use to setup and allocate
  660                  * the interrupt.
  661                  */
  662                 if (intr->Interrupt > 15 &&
  663                     intr->Source == AcpiGbl_FADT->SciInt)
  664                         acpi_OverrideInterruptLevel(intr->Interrupt);
  665                 else
  666                         ioapic_remap_vector(new_ioapic, new_pin, intr->Source);
  667                 if (madt_find_interrupt(intr->Source, &old_ioapic,
  668                     &old_pin) != 0)
  669                         printf("MADT: Could not find APIC for source IRQ %d\n",
  670                             intr->Source);
  671                 else if (ioapic_get_vector(old_ioapic, old_pin) ==
  672                     intr->Source)
  673                         ioapic_disable_pin(old_ioapic, old_pin);
  674         }
  675 
  676         /* Program the polarity and trigger mode. */
  677         ioapic_set_triggermode(new_ioapic, new_pin, trig);
  678         ioapic_set_polarity(new_ioapic, new_pin, pol);
  679 }
  680 
  681 /*
  682  * Parse an entry for an NMI routed to an IO APIC.
  683  */
  684 static void
  685 madt_parse_nmi(MADT_NMI_SOURCE *nmi)
  686 {
  687         void *ioapic;
  688         u_int pin;
  689 
  690         if (madt_find_interrupt(nmi->Interrupt, &ioapic, &pin) != 0) {
  691                 printf("MADT: Could not find APIC for vector %d\n",
  692                     nmi->Interrupt);
  693                 return;
  694         }
  695 
  696         ioapic_set_nmi(ioapic, pin);
  697         if (nmi->TriggerMode != TRIGGER_CONFORMS)
  698                 ioapic_set_triggermode(ioapic, pin,
  699                     interrupt_trigger(nmi->TriggerMode, 0));
  700         if (nmi->Polarity != TRIGGER_CONFORMS)
  701                 ioapic_set_polarity(ioapic, pin,
  702                     interrupt_polarity(nmi->Polarity, 0));
  703 }
  704 
  705 /*
  706  * Parse an entry for an NMI routed to a local APIC LVT pin.
  707  */
  708 static void
  709 madt_parse_local_nmi(MADT_LOCAL_APIC_NMI *nmi)
  710 {
  711         u_int apic_id, pin;
  712 
  713         if (nmi->ProcessorId == 0xff)
  714                 apic_id = APIC_ID_ALL;
  715         else if (madt_find_cpu(nmi->ProcessorId, &apic_id) != 0) {
  716                 if (bootverbose)
  717                         printf("MADT: Ignoring local NMI routed to ACPI CPU %u\n",
  718                             nmi->ProcessorId);
  719                 return;
  720         }
  721         if (nmi->Lint == 0)
  722                 pin = LVT_LINT0;
  723         else
  724                 pin = LVT_LINT1;
  725         lapic_set_lvt_mode(apic_id, pin, APIC_LVT_DM_NMI);
  726         if (nmi->TriggerMode != TRIGGER_CONFORMS)
  727                 lapic_set_lvt_triggermode(apic_id, pin,
  728                     interrupt_trigger(nmi->TriggerMode, 0));
  729         if (nmi->Polarity != POLARITY_CONFORMS)
  730                 lapic_set_lvt_polarity(apic_id, pin,
  731                     interrupt_polarity(nmi->Polarity, 0));
  732 }
  733 
  734 /*
  735  * Parse interrupt entries.
  736  */
  737 static void
  738 madt_parse_ints(APIC_HEADER *entry, void *arg __unused)
  739 {
  740 
  741         switch (entry->Type) {
  742         case APIC_XRUPT_OVERRIDE:
  743                 madt_parse_interrupt_override(
  744                         (MADT_INTERRUPT_OVERRIDE *)entry);
  745                 break;
  746         case APIC_NMI:
  747                 madt_parse_nmi((MADT_NMI_SOURCE *)entry);
  748                 break;
  749         case APIC_LOCAL_NMI:
  750                 madt_parse_local_nmi((MADT_LOCAL_APIC_NMI *)entry);
  751                 break;
  752         }
  753 }
  754 
  755 /*
  756  * Setup per-CPU ACPI IDs.
  757  */
  758 static void
  759 madt_set_ids(void *dummy)
  760 {
  761         struct lapic_info *la;
  762         struct pcpu *pc;
  763         u_int i;
  764 
  765         if (madt == NULL)
  766                 return;
  767         for (i = 0; i <= mp_maxid; i++) {
  768                 if (CPU_ABSENT(i))
  769                         continue;
  770                 pc = pcpu_find(i);
  771                 KASSERT(pc != NULL, ("no pcpu data for CPU %d", i));
  772                 la = &lapics[pc->pc_apic_id];
  773                 if (!la->la_enabled)
  774                         panic("APIC: CPU with APIC ID %u is not enabled",
  775                             pc->pc_apic_id);
  776                 pc->pc_acpi_id = la->la_acpi_id;
  777                 if (bootverbose)
  778                         printf("APIC: CPU %u has ACPI ID %u\n", i,
  779                             la->la_acpi_id);
  780         }
  781 }
  782 SYSINIT(madt_set_ids, SI_SUB_CPU, SI_ORDER_ANY, madt_set_ids, NULL)

Cache object: 9d4249ae2dde94726d0e45b1d3f0cdd4


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.