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/amd64/acpica/acpi_machdep.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) 2001 Mitsuru IWASAKI
    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  *
   14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   24  * SUCH DAMAGE.
   25  */
   26 
   27 #include <sys/cdefs.h>
   28 __FBSDID("$FreeBSD: releng/8.4/sys/amd64/acpica/acpi_machdep.c 237823 2012-06-29 21:25:24Z jhb $");
   29 
   30 #include <sys/param.h>
   31 #include <sys/bus.h>
   32 #include <sys/kernel.h>
   33 #include <sys/module.h>
   34 #include <sys/sysctl.h>
   35 
   36 #include <vm/vm.h>
   37 #include <vm/pmap.h>
   38 
   39 #include <contrib/dev/acpica/include/acpi.h>
   40 #include <contrib/dev/acpica/include/accommon.h>
   41 #include <contrib/dev/acpica/include/actables.h>
   42 
   43 #include <dev/acpica/acpivar.h>
   44 
   45 #include <machine/nexusvar.h>
   46 
   47 int acpi_resume_beep;
   48 TUNABLE_INT("debug.acpi.resume_beep", &acpi_resume_beep);
   49 SYSCTL_INT(_debug_acpi, OID_AUTO, resume_beep, CTLFLAG_RW, &acpi_resume_beep,
   50     0, "Beep the PC speaker when resuming");
   51 
   52 int acpi_reset_video;
   53 TUNABLE_INT("hw.acpi.reset_video", &acpi_reset_video);
   54 
   55 static int intr_model = ACPI_INTR_PIC;
   56 static struct apm_clone_data acpi_clone;
   57 
   58 int
   59 acpi_machdep_init(device_t dev)
   60 {
   61         struct acpi_softc       *sc;
   62 
   63         sc = devclass_get_softc(devclass_find("acpi"), 0);
   64 
   65         /* Create a fake clone for /dev/acpi. */
   66         STAILQ_INIT(&sc->apm_cdevs);
   67         acpi_clone.cdev = sc->acpi_dev_t;
   68         acpi_clone.acpi_sc = sc;
   69         ACPI_LOCK(acpi);
   70         STAILQ_INSERT_TAIL(&sc->apm_cdevs, &acpi_clone, entries);
   71         ACPI_UNLOCK(acpi);
   72         sc->acpi_clone = &acpi_clone;
   73 
   74         if (intr_model != ACPI_INTR_PIC)
   75                 acpi_SetIntrModel(intr_model);
   76 
   77         SYSCTL_ADD_UINT(&sc->acpi_sysctl_ctx,
   78             SYSCTL_CHILDREN(sc->acpi_sysctl_tree), OID_AUTO,
   79             "reset_video", CTLFLAG_RW, &acpi_reset_video, 0,
   80             "Call the VESA reset BIOS vector on the resume path");
   81 
   82         return (0);
   83 }
   84 
   85 void
   86 acpi_SetDefaultIntrModel(int model)
   87 {
   88 
   89         intr_model = model;
   90 }
   91 
   92 int
   93 acpi_machdep_quirks(int *quirks)
   94 {
   95         return (0);
   96 }
   97 
   98 void
   99 acpi_cpu_c1()
  100 {
  101         __asm __volatile("sti; hlt");
  102 }
  103 
  104 /*
  105  * Support for mapping ACPI tables during early boot.  Currently this
  106  * uses the crashdump map to map each table.  However, the crashdump
  107  * map is created in pmap_bootstrap() right after the direct map, so
  108  * we should be able to just use pmap_mapbios() here instead.
  109  *
  110  * This makes the following assumptions about how we use this KVA:
  111  * pages 0 and 1 are used to map in the header of each table found via
  112  * the RSDT or XSDT and pages 2 to n are used to map in the RSDT or
  113  * XSDT.  This has to use 2 pages for the table headers in case a
  114  * header spans a page boundary.
  115  *
  116  * XXX: We don't ensure the table fits in the available address space
  117  * in the crashdump map.
  118  */
  119 
  120 /*
  121  * Map some memory using the crashdump map.  'offset' is an offset in
  122  * pages into the crashdump map to use for the start of the mapping.
  123  */
  124 static void *
  125 table_map(vm_paddr_t pa, int offset, vm_offset_t length)
  126 {
  127         vm_offset_t va, off;
  128         void *data;
  129 
  130         off = pa & PAGE_MASK;
  131         length = roundup(length + off, PAGE_SIZE);
  132         pa = pa & PG_FRAME;
  133         va = (vm_offset_t)pmap_kenter_temporary(pa, offset) +
  134             (offset * PAGE_SIZE);
  135         data = (void *)(va + off);
  136         length -= PAGE_SIZE;
  137         while (length > 0) {
  138                 va += PAGE_SIZE;
  139                 pa += PAGE_SIZE;
  140                 length -= PAGE_SIZE;
  141                 pmap_kenter(va, pa);
  142                 invlpg(va);
  143         }
  144         return (data);
  145 }
  146 
  147 /* Unmap memory previously mapped with table_map(). */
  148 static void
  149 table_unmap(void *data, vm_offset_t length)
  150 {
  151         vm_offset_t va, off;
  152 
  153         va = (vm_offset_t)data;
  154         off = va & PAGE_MASK;
  155         length = roundup(length + off, PAGE_SIZE);
  156         va &= ~PAGE_MASK;
  157         while (length > 0) {
  158                 pmap_kremove(va);
  159                 invlpg(va);
  160                 va += PAGE_SIZE;
  161                 length -= PAGE_SIZE;
  162         }
  163 }
  164 
  165 /*
  166  * Map a table at a given offset into the crashdump map.  It first
  167  * maps the header to determine the table length and then maps the
  168  * entire table.
  169  */
  170 static void *
  171 map_table(vm_paddr_t pa, int offset, const char *sig)
  172 {
  173         ACPI_TABLE_HEADER *header;
  174         vm_offset_t length;
  175         void *table;
  176 
  177         header = table_map(pa, offset, sizeof(ACPI_TABLE_HEADER));
  178         if (strncmp(header->Signature, sig, ACPI_NAME_SIZE) != 0) {
  179                 table_unmap(header, sizeof(ACPI_TABLE_HEADER));
  180                 return (NULL);
  181         }
  182         length = header->Length;
  183         table_unmap(header, sizeof(ACPI_TABLE_HEADER));
  184         table = table_map(pa, offset, length);
  185         if (ACPI_FAILURE(AcpiTbChecksum(table, length))) {
  186                 if (bootverbose)
  187                         printf("ACPI: Failed checksum for table %s\n", sig);
  188 #if (ACPI_CHECKSUM_ABORT)
  189                 table_unmap(table, length);
  190                 return (NULL);
  191 #endif
  192         }
  193         return (table);
  194 }
  195 
  196 /*
  197  * See if a given ACPI table is the requested table.  Returns the
  198  * length of the able if it matches or zero on failure.
  199  */
  200 static int
  201 probe_table(vm_paddr_t address, const char *sig)
  202 {
  203         ACPI_TABLE_HEADER *table;
  204 
  205         table = table_map(address, 0, sizeof(ACPI_TABLE_HEADER));
  206         if (table == NULL) {
  207                 if (bootverbose)
  208                         printf("ACPI: Failed to map table at 0x%jx\n",
  209                             (uintmax_t)address);
  210                 return (0);
  211         }
  212         if (bootverbose)
  213                 printf("Table '%.4s' at 0x%jx\n", table->Signature,
  214                     (uintmax_t)address);
  215 
  216         if (strncmp(table->Signature, sig, ACPI_NAME_SIZE) != 0) {
  217                 table_unmap(table, sizeof(ACPI_TABLE_HEADER));
  218                 return (0);
  219         }
  220         table_unmap(table, sizeof(ACPI_TABLE_HEADER));
  221         return (1);
  222 }
  223 
  224 /*
  225  * Try to map a table at a given physical address previously returned
  226  * by acpi_find_table().
  227  */
  228 void *
  229 acpi_map_table(vm_paddr_t pa, const char *sig)
  230 {
  231 
  232         return (map_table(pa, 0, sig));
  233 }
  234 
  235 /* Unmap a table previously mapped via acpi_map_table(). */
  236 void
  237 acpi_unmap_table(void *table)
  238 {
  239         ACPI_TABLE_HEADER *header;
  240 
  241         header = (ACPI_TABLE_HEADER *)table;
  242         table_unmap(table, header->Length);
  243 }
  244 
  245 /*
  246  * Return the physical address of the requested table or zero if one
  247  * is not found.
  248  */
  249 vm_paddr_t
  250 acpi_find_table(const char *sig)
  251 {
  252         ACPI_PHYSICAL_ADDRESS rsdp_ptr;
  253         ACPI_TABLE_RSDP *rsdp;
  254         ACPI_TABLE_RSDT *rsdt;
  255         ACPI_TABLE_XSDT *xsdt;
  256         ACPI_TABLE_HEADER *table;
  257         vm_paddr_t addr;
  258         int i, count;
  259 
  260         if (resource_disabled("acpi", 0))
  261                 return (0);
  262 
  263         /*
  264          * Map in the RSDP.  Since ACPI uses AcpiOsMapMemory() which in turn
  265          * calls pmap_mapbios() to find the RSDP, we assume that we can use
  266          * pmap_mapbios() to map the RSDP.
  267          */
  268         if ((rsdp_ptr = AcpiOsGetRootPointer()) == 0)
  269                 return (0);
  270         rsdp = pmap_mapbios(rsdp_ptr, sizeof(ACPI_TABLE_RSDP));
  271         if (rsdp == NULL) {
  272                 if (bootverbose)
  273                         printf("ACPI: Failed to map RSDP\n");
  274                 return (0);
  275         }
  276 
  277         /*
  278          * For ACPI >= 2.0, use the XSDT if it is available.
  279          * Otherwise, use the RSDT.  We map the XSDT or RSDT at page 2
  280          * in the crashdump area.  Pages 0 and 1 are used to map in the
  281          * headers of candidate ACPI tables.
  282          */
  283         addr = 0;
  284         if (rsdp->Revision >= 2 && rsdp->XsdtPhysicalAddress != 0) {
  285                 /*
  286                  * AcpiOsGetRootPointer only verifies the checksum for
  287                  * the version 1.0 portion of the RSDP.  Version 2.0 has
  288                  * an additional checksum that we verify first.
  289                  */
  290                 if (AcpiTbChecksum((UINT8 *)rsdp, ACPI_RSDP_XCHECKSUM_LENGTH)) {
  291                         if (bootverbose)
  292                                 printf("ACPI: RSDP failed extended checksum\n");
  293                         return (0);
  294                 }
  295                 xsdt = map_table(rsdp->XsdtPhysicalAddress, 2, ACPI_SIG_XSDT);
  296                 if (xsdt == NULL) {
  297                         if (bootverbose)
  298                                 printf("ACPI: Failed to map XSDT\n");
  299                         return (0);
  300                 }
  301                 count = (xsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) /
  302                     sizeof(UINT64);
  303                 for (i = 0; i < count; i++)
  304                         if (probe_table(xsdt->TableOffsetEntry[i], sig)) {
  305                                 addr = xsdt->TableOffsetEntry[i];
  306                                 break;
  307                         }
  308                 acpi_unmap_table(xsdt);
  309         } else {
  310                 rsdt = map_table(rsdp->RsdtPhysicalAddress, 2, ACPI_SIG_RSDT);
  311                 if (rsdt == NULL) {
  312                         if (bootverbose)
  313                                 printf("ACPI: Failed to map RSDT\n");
  314                         return (0);
  315                 }
  316                 count = (rsdt->Header.Length - sizeof(ACPI_TABLE_HEADER)) /
  317                     sizeof(UINT32);
  318                 for (i = 0; i < count; i++)
  319                         if (probe_table(rsdt->TableOffsetEntry[i], sig)) {
  320                                 addr = rsdt->TableOffsetEntry[i];
  321                                 break;
  322                         }
  323                 acpi_unmap_table(rsdt);
  324         }
  325         pmap_unmapbios((vm_offset_t)rsdp, sizeof(ACPI_TABLE_RSDP));
  326         if (addr == 0) {
  327                 if (bootverbose)
  328                         printf("ACPI: No %s table found\n", sig);
  329                 return (0);
  330         }
  331         if (bootverbose)
  332                 printf("%s: Found table at 0x%jx\n", sig, (uintmax_t)addr);
  333 
  334         /*
  335          * Verify that we can map the full table and that its checksum is
  336          * correct, etc.
  337          */
  338         table = map_table(addr, 0, sig);
  339         if (table == NULL)
  340                 return (0);
  341         acpi_unmap_table(table);
  342 
  343         return (addr);
  344 }
  345 
  346 /*
  347  * ACPI nexus(4) driver.
  348  */
  349 static int
  350 nexus_acpi_probe(device_t dev)
  351 {
  352         int error;
  353 
  354         error = acpi_identify();
  355         if (error)
  356                 return (error);
  357 
  358         return (BUS_PROBE_DEFAULT);
  359 }
  360 
  361 static int
  362 nexus_acpi_attach(device_t dev)
  363 {
  364         device_t acpi_dev;
  365         int error;
  366 
  367         nexus_init_resources();
  368         bus_generic_probe(dev);
  369         acpi_dev = BUS_ADD_CHILD(dev, 10, "acpi", 0);
  370         if (acpi_dev == NULL)
  371                 panic("failed to add acpi0 device");
  372 
  373         error = bus_generic_attach(dev);
  374         if (error == 0)
  375                 acpi_install_wakeup_handler(device_get_softc(acpi_dev));
  376 
  377         return (error);
  378 }
  379 
  380 static device_method_t nexus_acpi_methods[] = {
  381         /* Device interface */
  382         DEVMETHOD(device_probe,         nexus_acpi_probe),
  383         DEVMETHOD(device_attach,        nexus_acpi_attach),
  384 
  385         { 0, 0 }
  386 };
  387 
  388 DEFINE_CLASS_1(nexus, nexus_acpi_driver, nexus_acpi_methods, 1, nexus_driver);
  389 static devclass_t nexus_devclass;
  390 
  391 DRIVER_MODULE(nexus_acpi, root, nexus_acpi_driver, nexus_devclass, 0, 0);

Cache object: 0748c5404fc7aacc0bccc8a570054e6b


[ 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.