Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi - reduce the frequency of updating informations...



details:   https://anonhg.NetBSD.org/src/rev/643bac8f1419
branches:  trunk
changeset: 543081:643bac8f1419
user:      tshiozak <tshiozak%NetBSD.org@localhost>
date:      Sun Feb 16 16:50:09 2003 +0000

description:
- reduce the frequency of updating informations on the power sources;
  it is very slow to access to EC on some machines (i.e. CASIO FIVA 2xx).
- clean the flags up.
- add locks while updating informations.
- some cosmetic changes.

diffstat:

 sys/dev/acpi/acpi_acad.c |   99 +++++++++--
 sys/dev/acpi/acpi_bat.c  |  412 ++++++++++++++++++++++++++++++++++++----------
 2 files changed, 397 insertions(+), 114 deletions(-)

diffs (truncated from 853 to 300 lines):

diff -r e612fc52ba21 -r 643bac8f1419 sys/dev/acpi/acpi_acad.c
--- a/sys/dev/acpi/acpi_acad.c  Sun Feb 16 16:21:59 2003 +0000
+++ b/sys/dev/acpi/acpi_acad.c  Sun Feb 16 16:50:09 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_acad.c,v 1.6 2002/12/31 05:26:56 explorer Exp $   */
+/*     $NetBSD: acpi_acad.c,v 1.7 2003/02/16 16:50:09 tshiozak Exp $   */
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -35,12 +35,16 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#if 0
+#define ACPI_ACAD_DEBUG
+#endif
+
 /*
  * ACPI AC Adapter driver.
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_acad.c,v 1.6 2002/12/31 05:26:56 explorer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_acad.c,v 1.7 2003/02/16 16:50:09 tshiozak Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -62,10 +66,12 @@
        struct device sc_dev;           /* base device glue */
        struct acpi_devnode *sc_node;   /* our ACPI devnode */
        int sc_flags;                   /* see below */
-       int sc_status;                  /* power status */
+
        struct sysmon_envsys sc_sysmon;
        struct envsys_basic_info sc_info[ACPIACAD_NSENSORS];
        struct envsys_tre_data sc_data[ACPIACAD_NSENSORS];
+
+       struct simplelock sc_lock;
 };
 
 const struct envsys_range acpiacad_range[] = {
@@ -74,16 +80,48 @@
 };
 
 #define        AACAD_F_VERBOSE         0x01    /* verbose events */
+#define AACAD_F_AVAILABLE      0x02    /* information is available */
+#define AACAD_F_LOCKED         0x04    /* is locked? */
 
-int    acpiacad_match(struct device *, struct cfdata *, void *);
-void   acpiacad_attach(struct device *, struct device *, void *);
+#define AACAD_SET(sc, f)       (void)((sc)->sc_flags |= (f))
+#define AACAD_CLEAR(sc, f)     (void)((sc)->sc_flags &= ~(f))
+#define AACAD_ISSET(sc, f)     ((sc)->sc_flags & (f))
+
+#define AACAD_ASSERT_LOCKED(sc)                                        \
+do {                                                           \
+       if (!((sc)->sc_flags & AACAD_F_LOCKED))                 \
+               panic("acpi_bat (expected to be locked)");      \
+} while(/*CONSTCOND*/0)
+#define AACAD_ASSERT_UNLOCKED(sc)                              \
+do {                                                           \
+       if (((sc)->sc_flags & AACAD_F_LOCKED))                  \
+               panic("acpi_bat (expected to be unlocked)");    \
+} while(/*CONSTCOND*/0)
+#define AACAD_LOCK(sc, s)                      \
+do {                                           \
+       AACAD_ASSERT_UNLOCKED(sc);              \
+       (s) = splhigh();                        \
+       simple_lock(&(sc)->sc_lock);            \
+       AACAD_SET((sc), AACAD_F_LOCKED);        \
+} while(/*CONSTCOND*/0)
+#define AACAD_UNLOCK(sc, s)                    \
+do {                                           \
+       AACAD_ASSERT_LOCKED(sc);                \
+       AACAD_CLEAR((sc), AACAD_F_LOCKED);      \
+       simple_unlock(&(sc)->sc_lock);          \
+       splx((s));                              \
+} while(/*CONSTCOND*/0)
+
+static int acpiacad_match(struct device *, struct cfdata *, void *);
+static void acpiacad_attach(struct device *, struct device *, void *);
 
 CFATTACH_DECL(acpiacad, sizeof(struct acpiacad_softc),
     acpiacad_match, acpiacad_attach, NULL, NULL);
 
-void   acpiacad_get_status(void *);
-void   acpiacad_notify_handler(ACPI_HANDLE, UINT32, void *context);
-static void acpiacad_init_envsys(struct acpiacad_softc *sc);
+static void acpiacad_get_status(void *);
+static void acpiacad_clear_status(struct acpiacad_softc *);
+static void acpiacad_notify_handler(ACPI_HANDLE, UINT32, void *);
+static void acpiacad_init_envsys(struct acpiacad_softc *);
 static int acpiacad_gtredata(struct sysmon_envsys *, struct envsys_tre_data *);
 static int acpiacad_streinfo(struct sysmon_envsys *, struct envsys_basic_info *);
 
@@ -139,9 +177,11 @@
                return;
        }
 
+#ifdef ACPI_ACAD_DEBUG
        /* Display the current state. */
        sc->sc_flags = AACAD_F_VERBOSE;
-       acpiacad_get_status(sc);
+#endif
+
        acpiacad_init_envsys(sc);
 }
 
@@ -154,17 +194,35 @@
 acpiacad_get_status(void *arg)
 {
        struct acpiacad_softc *sc = arg;
+       int status, s;
 
        if (acpi_eval_integer(sc->sc_node->ad_handle, "_PSR",
-           &sc->sc_status) != AE_OK)
+           &status) != AE_OK)
                return;
 
-       sc->sc_data[ACPIACAD_CONNECTED].cur.data_s = !!(sc->sc_status);
-       sc->sc_data[ACPIACAD_DISCONNECTED].cur.data_s = !(sc->sc_status);
+       AACAD_LOCK(sc, s);
+       sc->sc_data[ACPIACAD_CONNECTED].cur.data_s = !!(status);
+       sc->sc_data[ACPIACAD_DISCONNECTED].cur.data_s = !(status);
+       AACAD_SET(sc, AACAD_F_AVAILABLE);
+       AACAD_UNLOCK(sc, s);
+
+       if (AACAD_ISSET(sc, AACAD_F_VERBOSE))
+               printf("%s: AC adapter %sconnected\n",
+                   sc->sc_dev.dv_xname, status == 0 ? "not " : "");
+}
 
-       if (sc->sc_flags & AACAD_F_VERBOSE)
-               printf("%s: AC adapter %sconnected\n",
-                   sc->sc_dev.dv_xname, sc->sc_status == 0 ? "not " : "");
+/*
+ * Clear status
+ */
+void
+acpiacad_clear_status(struct acpiacad_softc *sc)
+{
+
+       AACAD_ASSERT_LOCKED(sc);
+
+       sc->sc_data[ACPIACAD_CONNECTED].cur.data_s = 0;
+       sc->sc_data[ACPIACAD_DISCONNECTED].cur.data_s = 0;
+       AACAD_CLEAR(sc, AACAD_F_AVAILABLE);
 }
 
 /*
@@ -176,7 +234,7 @@
 acpiacad_notify_handler(ACPI_HANDLE handle, UINT32 notify, void *context)
 {
        struct acpiacad_softc *sc = context;
-       int rv;
+       int rv, s;
 
        switch (notify) {
        /*
@@ -190,6 +248,9 @@
                printf("%s: received notify message: 0x%x\n",
                    sc->sc_dev.dv_xname, notify);
 #endif
+               AACAD_LOCK(sc, s);
+               acpiacad_clear_status(sc);
+               AACAD_UNLOCK(sc, s);
                rv = AcpiOsQueueForExecution(OSD_PRIORITY_LO,
                    acpiacad_get_status, sc);
                if (rv != AE_OK)
@@ -203,7 +264,7 @@
        }
 }
 
-static void
+void
 acpiacad_init_envsys(struct acpiacad_softc *sc)
 {
        int i;
@@ -239,12 +300,14 @@
                    sc->sc_dev.dv_xname);
 }
 
-
 int
 acpiacad_gtredata(struct sysmon_envsys *sme, struct envsys_tre_data *tred)
 {
        struct acpiacad_softc *sc = sme->sme_cookie;
 
+       if (!AACAD_ISSET(sc, AACAD_F_AVAILABLE))
+               acpiacad_get_status(sc);
+
        /* XXX locking */
        *tred = sc->sc_data[tred->sensor];
        /* XXX locking */
diff -r e612fc52ba21 -r 643bac8f1419 sys/dev/acpi/acpi_bat.c
--- a/sys/dev/acpi/acpi_bat.c   Sun Feb 16 16:21:59 2003 +0000
+++ b/sys/dev/acpi/acpi_bat.c   Sun Feb 16 16:50:09 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: acpi_bat.c,v 1.14 2002/12/31 05:26:56 explorer Exp $   */
+/*     $NetBSD: acpi_bat.c,v 1.15 2003/02/16 16:50:09 tshiozak Exp $   */
 
 /*
  * Copyright 2001 Bill Sommerfeld.
@@ -50,7 +50,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.14 2002/12/31 05:26:56 explorer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.15 2003/02/16 16:50:09 tshiozak Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -64,18 +64,19 @@
 #include <dev/acpi/acpivar.h>
 
 /* sensor indexes */
-#define ACPIBAT_DCAPACITY      0
-#define ACPIBAT_LFCCAPACITY    1
-#define ACPIBAT_TECHNOLOGY     2
-#define ACPIBAT_DVOLTAGE       3
-#define ACPIBAT_WCAPACITY      4
-#define ACPIBAT_LCAPACITY      5
-#define ACPIBAT_VOLTAGE                6
-#define ACPIBAT_LOAD           7
-#define ACPIBAT_CAPACITY       8
-#define ACPIBAT_CHARGING       9
-#define ACPIBAT_DISCHARGING    10
-#define ACPIBAT_NSENSORS       11  /* number of sensors */
+#define ACPIBAT_PRESENT                0
+#define ACPIBAT_DCAPACITY      1
+#define ACPIBAT_LFCCAPACITY    2
+#define ACPIBAT_TECHNOLOGY     3
+#define ACPIBAT_DVOLTAGE       4
+#define ACPIBAT_WCAPACITY      5
+#define ACPIBAT_LCAPACITY      6
+#define ACPIBAT_VOLTAGE                7
+#define ACPIBAT_LOAD           8
+#define ACPIBAT_CAPACITY       9
+#define ACPIBAT_CHARGING       10
+#define ACPIBAT_DISCHARGING    11
+#define ACPIBAT_NSENSORS       12  /* number of sensors */
 
 const struct envsys_range acpibat_range_amp[] = {
        { 0, 1,         ENVSYS_SVOLTS_DC },
@@ -97,15 +98,15 @@
        struct device sc_dev;           /* base device glue */
        struct acpi_devnode *sc_node;   /* our ACPI devnode */
        int sc_flags;                   /* see below */
-       struct callout sc_callout;      /* XXX temporary polling */
-       int sc_present;                 /* is battery present? */
-       int sc_status;                  /* power status */
+       int sc_available;               /* available information level */
 
        struct sysmon_envsys sc_sysmon;
        struct envsys_basic_info sc_info[ACPIBAT_NSENSORS];
        struct envsys_tre_data sc_data[ACPIBAT_NSENSORS];
 
        ACPI_OBJECT sc_Ret[BAT_WORDS];  /* Return Buffer */
+
+       struct simplelock sc_lock;
 };
 
 /*
@@ -125,17 +126,56 @@
 /*
  * Flags for battery status from _STA return
  */
-#define ACPIBAT_STA_PRESENT     0x00000010  /* battery present */
+#define ACPIBAT_STA_PRESENT    0x00000010  /* battery present */
 
 /*
  * These flags are used to set internal state in our softc.
  */
 #define        ABAT_F_VERBOSE          0x01    /* verbose events */
 #define ABAT_F_PWRUNIT_MA      0x02    /* mA instead of mW */
+#define ABAT_F_PRESENT         0x04    /* is the battery present? */
+#define ABAT_F_LOCKED          0x08    /* is locked? */
+#define ABAT_F_DISCHARGING     0x10    /* discharging */
+#define ABAT_F_CHARGING                0x20    /* charging */
+#define ABAT_F_CRITICAL                0x40    /* charging */
 
-#define ACM_RATEUNIT(sc) (((sc)->sc_flags & ABAT_F_PWRUNIT_MA)?"A":"W")
-#define ACM_CAPUNIT(sc) (((sc)->sc_flags & ABAT_F_PWRUNIT_MA)?"Ah":"Wh")
-#define ACM_SCALE(x)   ((x) / 1000), ((x) % 1000)
+#define ABAT_SET(sc, f)                (void)((sc)->sc_flags |= (f))
+#define ABAT_CLEAR(sc, f)      (void)((sc)->sc_flags &= ~(f))
+#define ABAT_ISSET(sc, f)      ((sc)->sc_flags & (f))
+
+/*
+ * Available info level
+ */
+
+#define ABAT_ALV_NONE          0       /* none is available */
+#define ABAT_ALV_PRESENCE      1       /* presence info is available */
+#define ABAT_ALV_INFO          2       /* battery info is available */
+#define ABAT_ALV_STAT          3       /* battery status is available */
+
+#define ABAT_ASSERT_LOCKED(sc)                                 \
+do {                                                           \
+       if (!((sc)->sc_flags & ABAT_F_LOCKED))                  \



Home | Main Index | Thread Index | Old Index