Closing in... what does this button do?

Index: dsdt.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/dsdt.c,v
retrieving revision 1.205
diff -u -p -r1.205 dsdt.c
--- dsdt.c      12 Dec 2013 20:56:01 -0000      1.205
+++ dsdt.c      18 Apr 2014 09:33:15 -0000
@@ -114,6 +114,8 @@ int                 aml_intlen = 64;
 struct aml_node                aml_root;
 struct aml_value       *aml_global_lock;
 
+int noisy;
+
 /* Perfect Hash key */
 #define HASH_OFF               6904
 #define HASH_SIZE              179
@@ -736,72 +738,68 @@ static long global_lock_count = 0;
 void
 acpi_glk_enter(void)
 {
-       acpi_acquire_glk(&acpi_softc->sc_facs->global_lock);
-}
-
-void
-acpi_glk_leave(void)
-{
-       int x;
-
-       if (acpi_release_glk(&acpi_softc->sc_facs->global_lock)) {
-               /*
-                * If pending, notify the BIOS that the lock was released
-                * by the OSPM. No locking is needed because nobody outside
-                * the ACPI thread is touching this register.
-                */
-               x = acpi_read_pmreg(acpi_softc, ACPIREG_PM1_CNT, 0);
-               x |= ACPI_PM1_GBL_RLS;
-               acpi_write_pmreg(acpi_softc, ACPIREG_PM1_CNT, 0, x);
-       }
-}
-
-void
-aml_lockfield(struct aml_scope *scope, struct aml_value *field)
-{
        int st = 0;
 
-       if (AML_FIELD_LOCK(field->v_field.flags) != AML_FIELD_LOCK_ON)
-               return;
-
-       /* If lock is already ours, just continue */
+       /* If lock is already ours, just continue. */
        if (global_lock_count++)
                return;
 
-       /* Spin to acquire lock */
+       /* Spin to acquire the lock. */
        while (!st) {
                st = acpi_acquire_glk(&acpi_softc->sc_facs->global_lock);
                /* XXX - yield/delay? */
        }
-
-       return;
 }
 
 void
-aml_unlockfield(struct aml_scope *scope, struct aml_value *field)
+acpi_glk_leave(void)
 {
-       int st, x, s;
-
-       if (AML_FIELD_LOCK(field->v_field.flags) != AML_FIELD_LOCK_ON)
-               return;
+       int st, x;
 
-       /* If we are the last ones, turn out the lights */
+       /* If we are the last one, turn out the lights. */
        if (--global_lock_count)
                return;
 
-       /* Release lock */
        st = acpi_release_glk(&acpi_softc->sc_facs->global_lock);
        if (!st)
                return;
 
-       /* Signal others if someone waiting */
-       s = spltty();
+       /*
+        * If pending, notify the BIOS that the lock was released by
+        * OSPM.  No locking is needed because nobody outside the ACPI
+        * thread is supposed to touch this register.
+        */
        x = acpi_read_pmreg(acpi_softc, ACPIREG_PM1_CNT, 0);
        x |= ACPI_PM1_GBL_RLS;
        acpi_write_pmreg(acpi_softc, ACPIREG_PM1_CNT, 0, x);
-       splx(s);
+}
 
-       return;
+void
+aml_lockfield(struct aml_scope *scope, struct aml_value *field)
+{
+       if (AML_FIELD_LOCK(field->v_field.flags) != AML_FIELD_LOCK_ON) {
+               if (noisy)
+                       printf("lock not needed\n");
+               return;
+       }
+
+       if (noisy)
+               printf("locking\n");
+       acpi_glk_enter();
+}
+
+void
+aml_unlockfield(struct aml_scope *scope, struct aml_value *field)
+{
+       if (AML_FIELD_LOCK(field->v_field.flags) != AML_FIELD_LOCK_ON) {
+               if (noisy)
+                       printf("unlock not needed\n");
+               return;
+       }
+
+       if (noisy)
+               printf("unlocking\n");
+       acpi_glk_leave();
 }
 
 /*
@@ -2259,11 +2257,13 @@ aml_rwgas(struct aml_value *rgn, int bpo
        void *tbit, *vbit;
        int slen, type, sz;
 
-       dnprintf(10," %5s %.2x %.8llx %.4x [%s]\n",
-               mode == ACPI_IOREAD ? "read" : "write",
-               rgn->v_opregion.iospace,
-               rgn->v_opregion.iobase + (bpos >> 3),
-               blen, aml_nodename(rgn->node));
+       if (noisy) {
+               printf(" %5s %.2x %.8llx %.4x [%s]\n",
+                       mode == ACPI_IOREAD ? "read" : "write",
+                       rgn->v_opregion.iospace,
+                       rgn->v_opregion.iobase + (bpos >> 3),
+                       blen, aml_nodename(rgn->node));
+       }
        memset(&tmp, 0, sizeof(tmp));
        pi.addr = rgn->v_opregion.iobase + (bpos >> 3);
        if (rgn->v_opregion.iospace == GAS_PCI_CFG_SPACE)
@@ -2315,9 +2315,16 @@ aml_rwgas(struct aml_value *rgn, int bpo
 
        if (mode == ACPI_IOREAD) {
                /* Read bits from opregion */
+               if (noisy) {
+                       printf("gasio rd: %d %#llx %d %d %d\n",
+                           type, pi.addr, sz, slen, tbit);
+               }
                acpi_gasio(acpi_softc, ACPI_IOREAD, type, pi.addr,
                    sz, slen, tbit);
                aml_bufcpy(vbit, 0, tbit, bpos & 7, blen);
+               if (noisy) {
+                       printf("aml_bufcpy: %#x\n", val->v_integer);
+               }
        } else {
                /* Write bits to opregion */
                if (val->length < slen) {
@@ -2335,6 +2342,10 @@ aml_rwgas(struct aml_value *rgn, int bpo
                }
                /* Copy target bits, then write to region */
                aml_bufcpy(tbit, bpos & 7, vbit, 0, blen);
+               if (noisy) {
+                       printf("gasio: %d %#llx %d %d %d\n", type, pi.addr, sz,
+                           slen, tbit);
+               }
                acpi_gasio(acpi_softc, ACPI_IOWRITE, type, pi.addr,
                    sz, slen, tbit);
 
@@ -2440,6 +2451,11 @@ aml_rwfield(struct aml_value *fld, int b
                aml_rwgas(ref1, fld->v_field.bitpos, fld->v_field.bitlen,
                    val, mode, fld->v_field.flags);
        } else if (fld->v_field.type == AMLOP_FIELD) {
+               if (noisy) {
+                       printf("field: aml_rwgas bitpos %d bpos %d blen %d,"
+                           "flags %#x\n", fld->v_field.bitpos, bpos, blen,
+                           fld->v_field.flags);
+               }
                aml_rwgas(ref1, fld->v_field.bitpos + bpos, blen, val, mode,
                    fld->v_field.flags);
        } else if (mode == ACPI_IOREAD) {
@@ -2450,6 +2466,9 @@ aml_rwfield(struct aml_value *fld, int b
        } else {
                /* bufferfield:write */
                val = aml_convert(val, AML_OBJTYPE_INTEGER, -1);
+               if (noisy) {
+                       printf("write: %#llx\n", val->v_integer);
+               }
                aml_bufcpy(ref1->v_buffer, fld->v_field.bitpos, &val->v_integer,
                    0, fld->v_field.bitlen);
                aml_delref(&val, "wrbuffld");
@@ -2657,6 +2676,8 @@ aml_store(struct aml_scope *scope, struc
                break;
        case AML_OBJTYPE_BUFFERFIELD:
        case AML_OBJTYPE_FIELDUNIT:
+               if (noisy)
+                       printf("field: aml_rwfield(%d)\n", lhs->v_field.bitlen);
                aml_rwfield(lhs, 0, lhs->v_field.bitlen, rhs, ACPI_IOWRITE);
                break;
        case AML_OBJTYPE_DEBUGOBJ:
@@ -3423,7 +3444,8 @@ aml_parse(struct aml_scope *scope, int r
                /* No opcode handler */
                aml_die("Unknown opcode: %.4x @ %.4x", opcode, pc);
        }
-       dnprintf(18,"%.4x %s\n", pc, aml_mnem(opcode, scope->pos));
+       if (noisy)
+               printf("%.4x %s\n", pc, aml_mnem(opcode, scope->pos));
 
        /* --== Stage 1: Process opcode arguments ==-- */
        memset(opargs, 0, sizeof(opargs));
Index: acpiec.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpiec.c,v
retrieving revision 1.48
diff -u -p -r1.48 acpiec.c
--- acpiec.c    2 Jul 2013 18:37:47 -0000       1.48
+++ acpiec.c    18 Apr 2014 09:33:15 -0000
@@ -34,6 +34,7 @@
 
 int            acpiec_match(struct device *, void *, void *);
 void           acpiec_attach(struct device *, struct device *, void *);
+int            acpiec_activate(struct device *, int);
 
 u_int8_t       acpiec_status(struct acpiec_softc *);
 u_int8_t       acpiec_read_data(struct acpiec_softc *);
@@ -54,6 +55,7 @@ int           acpiec_getregister(const u_int8_t *
 
 void           acpiec_wait(struct acpiec_softc *, u_int8_t, u_int8_t);
 void           acpiec_sci_event(struct acpiec_softc *);
+void           acpiec_clear_events(struct acpiec_softc *);
 
 void           acpiec_get_events(struct acpiec_softc *);
 
@@ -82,7 +84,8 @@ void          acpiec_unlock(struct acpiec_softc 
 int    acpiec_reg(struct acpiec_softc *);
 
 struct cfattach acpiec_ca = {
-       sizeof(struct acpiec_softc), acpiec_match, acpiec_attach
+       sizeof(struct acpiec_softc), acpiec_match, acpiec_attach,
+       NULL, acpiec_activate
 };
 
 struct cfdriver acpiec_cd = {
@@ -296,6 +299,8 @@ acpiec_attach(struct device *parent, str
        acpi_set_gpehandler(sc->sc_acpi, sc->sc_gpe, acpiec_gpehandler,
            sc, 1);
 #endif
+
+       acpiec_clear_events(sc);
        
        if (aml_evalname(sc->sc_acpi, sc->sc_devnode, "_GLK", 0, NULL, &res))
                sc->sc_glk = 0;
@@ -307,6 +312,20 @@ acpiec_attach(struct device *parent, str
        printf("\n");
 }
 
+int
+acpiec_activate(struct device *self, int act)
+{
+       struct acpiec_softc *sc = (struct acpiec_softc *)self;
+
+
+       switch (act) {
+       case DVACT_RESUME:
+               acpiec_clear_events(sc);
+               break;
+       }
+       return (0);
+}
+
 void
 acpiec_get_events(struct acpiec_softc *sc)
 {
@@ -552,4 +571,18 @@ acpiec_unlock(struct acpiec_softc *sc)
        }
 
        sc->sc_ecbusy = 0;
+}
+
+void
+acpiec_clear_events(struct acpiec_softc *sc)
+{
+       int i;
+
+       for (i = 0; i < 100; i++) {
+               acpiec_write_cmd(sc, EC_CMD_QR);
+               sc->sc_gotsci = 0;
+               if ((acpiec_status(sc) & EC_STAT_SCI_EVT) != EC_STAT_SCI_EVT) {
+                       break;
+               }
+       }
 }
Index: acpitz.c
===================================================================
RCS file: /cvs/src/sys/dev/acpi/acpitz.c,v
retrieving revision 1.44
diff -u -p -r1.44 acpitz.c
--- acpitz.c    31 Oct 2012 16:35:36 -0000      1.44
+++ acpitz.c    18 Apr 2014 09:33:15 -0000
@@ -96,6 +96,8 @@ extern int    perflevel;
 
 extern struct aml_node aml_root;
 
+extern int noisy;
+
 void
 acpitz_init_perf(void *arg)
 {
@@ -319,11 +321,13 @@ acpitz_refresh(void *arg)
            sc->sc_devnode->name);
 
        /* get _TMP and debounce the value */
+       noisy = 1;
        if (-1 == (sc->sc_tmp = acpitz_gettempreading(sc, "_TMP"))) {
                printf("%s: %s: failed to read temp\n", DEVNAME(sc),
                    sc->sc_devnode->name);
                return;
        }
+       noisy = 0;
        /* critical trip points */
        if (sc->sc_crt != -1 && sc->sc_crt <= sc->sc_tmp) {
                /* do critical shutdown */

Reply via email to