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/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  *      $FreeBSD: releng/5.1/sys/i386/acpica/acpi_machdep.c 114977 2003-05-13 16:59:46Z jhb $
   27  */
   28 
   29 #include <sys/param.h>
   30 #include <sys/bus.h>
   31 #include <sys/conf.h>
   32 #include <sys/fcntl.h>
   33 #include <sys/uio.h>
   34 
   35 #include "acpi.h"
   36 
   37 #include <dev/acpica/acpivar.h>
   38 #include <dev/acpica/acpiio.h>
   39 
   40 static device_t acpi_dev;
   41 
   42 /*
   43  * APM driver emulation 
   44  */
   45 
   46 #if __FreeBSD_version < 500000
   47 #include <sys/select.h>
   48 #else
   49 #include <sys/selinfo.h>
   50 #endif
   51 
   52 #include <machine/apm_bios.h>
   53 #include <machine/pc/bios.h>
   54 
   55 #if __FreeBSD_version < 500000
   56 #include <i386/apm/apm.h>
   57 #else
   58 #include <i386/bios/apm.h>
   59 #endif
   60 
   61 static struct apm_softc apm_softc;
   62 
   63 static d_open_t apmopen;
   64 static d_close_t apmclose;
   65 static d_write_t apmwrite;
   66 static d_ioctl_t apmioctl;
   67 static d_poll_t apmpoll;
   68 
   69 #define CDEV_MAJOR 39
   70 static struct cdevsw apm_cdevsw = {
   71         .d_open =       apmopen,
   72         .d_close =      apmclose,
   73         .d_write =      apmwrite,
   74         .d_ioctl =      apmioctl,
   75         .d_poll =       apmpoll,
   76         .d_name =       "apm",
   77         .d_maj =        CDEV_MAJOR,
   78 };
   79 
   80 static int
   81 acpi_capm_convert_battstate(struct  acpi_battinfo *battp)
   82 {
   83         int     state;
   84 
   85         state = 0xff;   /* XXX unknown */
   86 
   87         if (battp->state & ACPI_BATT_STAT_DISCHARG) {
   88                 if (battp->cap >= 50) {
   89                         state = 0;      /* high */
   90                 } else {
   91                         state = 1;      /* low */
   92                 }
   93         }
   94         if (battp->state & ACPI_BATT_STAT_CRITICAL) {
   95                 state = 2;              /* critical */
   96         }
   97         if (battp->state & ACPI_BATT_STAT_CHARGING) {
   98                 state = 3;              /* charging */
   99         }
  100         return (state);
  101 }
  102 
  103 static int
  104 acpi_capm_convert_battflags(struct  acpi_battinfo *battp)
  105 {
  106         int     flags;
  107 
  108         flags = 0;
  109 
  110         if (battp->cap >= 50) {
  111                 flags |= APM_BATT_HIGH;
  112         } else {
  113                 if (battp->state & ACPI_BATT_STAT_CRITICAL) {
  114                         flags |= APM_BATT_CRITICAL;
  115                 } else {
  116                         flags |= APM_BATT_LOW;
  117                 }
  118         }
  119         if (battp->state & ACPI_BATT_STAT_CHARGING) {
  120                 flags |= APM_BATT_CHARGING;
  121         }
  122         if (battp->state == ACPI_BATT_STAT_NOT_PRESENT) {
  123                 flags = APM_BATT_NOT_PRESENT;
  124         }
  125 
  126         return (flags);
  127 }
  128 
  129 static int
  130 acpi_capm_get_info(apm_info_t aip)
  131 {
  132         int     acline;
  133         struct  acpi_battinfo batt;
  134 
  135         aip->ai_infoversion = 1;
  136         aip->ai_major       = 1;
  137         aip->ai_minor       = 2;
  138         aip->ai_status      = apm_softc.active;
  139         aip->ai_capabilities= 0xff00;   /* XXX unknown */
  140 
  141         if (acpi_acad_get_acline(&acline)) {
  142                 aip->ai_acline = 0xff;          /* unknown */
  143         } else {
  144                 aip->ai_acline = acline;        /* on/off */
  145         }
  146 
  147         if (acpi_battery_get_battinfo(-1, &batt)) {
  148                 aip->ai_batt_stat = 0xff;       /* unknown */
  149                 aip->ai_batt_life = 0xff;       /* unknown */
  150                 aip->ai_batt_time = -1;         /* unknown */
  151                 aip->ai_batteries = 0;
  152         } else {
  153                 aip->ai_batt_stat = acpi_capm_convert_battstate(&batt);
  154                 aip->ai_batt_life = batt.cap;
  155                 aip->ai_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
  156                 aip->ai_batteries = acpi_battery_get_units();
  157         }
  158 
  159         return (0);
  160 }
  161 
  162 static int
  163 acpi_capm_get_pwstatus(apm_pwstatus_t app)
  164 {
  165         int     batt_unit;
  166         int     acline;
  167         struct  acpi_battinfo batt;
  168 
  169         if (app->ap_device != PMDV_ALLDEV &&
  170             (app->ap_device < PMDV_BATT0 || app->ap_device > PMDV_BATT_ALL)) {
  171                 return (1);
  172         }
  173 
  174         if (app->ap_device == PMDV_ALLDEV) {
  175                 batt_unit = -1;                 /* all units */
  176         } else {
  177                 batt_unit = app->ap_device - PMDV_BATT0;
  178         }
  179 
  180         if (acpi_battery_get_battinfo(batt_unit, &batt)) {
  181                 return (1);
  182         }
  183 
  184         app->ap_batt_stat = acpi_capm_convert_battstate(&batt);
  185         app->ap_batt_flag = acpi_capm_convert_battflags(&batt);
  186         app->ap_batt_life = batt.cap;
  187         app->ap_batt_time = (batt.min == -1) ? -1 : batt.min * 60;
  188 
  189         if (acpi_acad_get_acline(&acline)) {
  190                 app->ap_acline = 0xff;          /* unknown */
  191         } else {
  192                 app->ap_acline = acline;        /* on/off */
  193         }
  194 
  195         return (0);
  196 }
  197 
  198 static int
  199 apmopen(dev_t dev, int flag, int fmt, d_thread_t *td)
  200 {
  201         return (0);
  202 }
  203 
  204 static int
  205 apmclose(dev_t dev, int flag, int fmt, d_thread_t *td)
  206 {
  207         return (0);
  208 }
  209 
  210 static int
  211 apmioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, d_thread_t *td)
  212 {
  213         int     error = 0;
  214         struct  acpi_softc *acpi_sc;
  215         struct apm_info info;
  216         apm_info_old_t aiop;
  217 
  218         if ((acpi_sc = device_get_softc(acpi_dev)) == NULL) {
  219                 return (ENXIO);
  220         }
  221 
  222         switch (cmd) {
  223         case APMIO_SUSPEND:
  224                 if (!(flag & FWRITE))
  225                         return (EPERM);
  226                 if (apm_softc.active)
  227                         acpi_SetSleepState(acpi_sc, acpi_sc->acpi_suspend_sx);
  228                 else
  229                         error = EINVAL;
  230                 break;
  231 
  232         case APMIO_STANDBY:
  233                 if (!(flag & FWRITE))
  234                         return (EPERM);
  235                 if (apm_softc.active)
  236                         acpi_SetSleepState(acpi_sc, acpi_sc->acpi_standby_sx);
  237                 else
  238                         error = EINVAL;
  239                 break;
  240 
  241         case APMIO_GETINFO_OLD:
  242                 if (acpi_capm_get_info(&info))
  243                         error = ENXIO;
  244                 aiop = (apm_info_old_t)addr;
  245                 aiop->ai_major = info.ai_major;
  246                 aiop->ai_minor = info.ai_minor;
  247                 aiop->ai_acline = info.ai_acline;
  248                 aiop->ai_batt_stat = info.ai_batt_stat;
  249                 aiop->ai_batt_life = info.ai_batt_life;
  250                 aiop->ai_status = info.ai_status;
  251                 break;
  252 
  253         case APMIO_GETINFO:
  254                 if (acpi_capm_get_info((apm_info_t)addr))
  255                         error = ENXIO;
  256 
  257                 break;
  258 
  259         case APMIO_GETPWSTATUS:
  260                 if (acpi_capm_get_pwstatus((apm_pwstatus_t)addr))
  261                         error = ENXIO;
  262                 break;
  263 
  264         case APMIO_ENABLE:
  265                 if (!(flag & FWRITE))
  266                         return (EPERM);
  267                 apm_softc.active = 1;
  268                 break;
  269 
  270         case APMIO_DISABLE:
  271                 if (!(flag & FWRITE))
  272                         return (EPERM);
  273                 apm_softc.active = 0;
  274                 break;
  275 
  276         case APMIO_HALTCPU:
  277                 break;
  278 
  279         case APMIO_NOTHALTCPU:
  280                 break;
  281 
  282         case APMIO_DISPLAY:
  283                 if (!(flag & FWRITE))
  284                         return (EPERM);
  285                 break;
  286 
  287         case APMIO_BIOS:
  288                 if (!(flag & FWRITE))
  289                         return (EPERM);
  290                 bzero(addr, sizeof(struct apm_bios_arg));
  291                 break;
  292 
  293         default:
  294                 error = EINVAL;
  295                 break;
  296         }
  297 
  298         return (error);
  299 }
  300 
  301 static int
  302 apmwrite(dev_t dev, struct uio *uio, int ioflag)
  303 {
  304 
  305         return (uio->uio_resid);
  306 }
  307 
  308 static int
  309 apmpoll(dev_t dev, int events, d_thread_t *td)
  310 {
  311         return (0);
  312 }
  313 
  314 static void
  315 acpi_capm_init(struct acpi_softc *sc)
  316 {
  317 
  318         make_dev(&apm_cdevsw, 0, 0, 5, 0664, "apm");
  319 }
  320 
  321 int
  322 acpi_machdep_init(device_t dev)
  323 {
  324         struct  acpi_softc *sc;
  325 
  326         acpi_dev = dev;
  327         if ((sc = device_get_softc(acpi_dev)) == NULL) {
  328                 return (ENXIO);
  329         }
  330 
  331         /*
  332          * XXX: Prevent the PnP BIOS code from interfering with
  333          * our own scan of ISA devices.
  334          */
  335         PnPBIOStable = NULL;
  336 
  337         acpi_capm_init(sc);
  338 
  339         acpi_install_wakeup_handler(sc);
  340 
  341 #ifdef SMP
  342         acpi_SetIntrModel(ACPI_INTR_APIC);
  343 #endif
  344         return (0);
  345 }
  346 

Cache object: b57c95b518d0c4ced1e672e0a295b649


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