Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/acpi acpiec(4): New ACPIEC_DEBUG option.
details: https://anonhg.NetBSD.org/src/rev/068b2957e613
branches: trunk
changeset: 377580:068b2957e613
user: riastradh <riastradh%NetBSD.org@localhost>
date: Tue Jul 18 10:02:25 2023 +0000
description:
acpiec(4): New ACPIEC_DEBUG option.
Value is bit mask of debug messages to enable.
Enable in x86/ALL kernels.
No functional change intended when the option is off.
diffstat:
sys/arch/amd64/conf/ALL | 5 +-
sys/arch/i386/conf/ALL | 5 +-
sys/dev/acpi/acpi_ec.c | 165 +++++++++++++++++++++++++++++++++++++++++++----
sys/dev/acpi/files.acpi | 3 +-
4 files changed, 158 insertions(+), 20 deletions(-)
diffs (truncated from 379 to 300 lines):
diff -r 19e496b8c09c -r 068b2957e613 sys/arch/amd64/conf/ALL
--- a/sys/arch/amd64/conf/ALL Tue Jul 18 10:02:09 2023 +0000
+++ b/sys/arch/amd64/conf/ALL Tue Jul 18 10:02:25 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.178 2023/07/07 12:46:50 riastradh Exp $
+# $NetBSD: ALL,v 1.179 2023/07/18 10:02:25 riastradh Exp $
# From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
#
# ALL machine description file
@@ -17,7 +17,7 @@ include "arch/amd64/conf/std.amd64"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "ALL-$Revision: 1.178 $"
+#ident "ALL-$Revision: 1.179 $"
maxusers 64 # estimated number of users
@@ -370,6 +370,7 @@ acpibut* at acpi? # ACPI Button
acpidalb* at acpi? # ACPI Direct Application Launch Button
acpiec* at acpi? # ACPI Embedded Controller (late)
acpiecdt* at acpi? # ACPI Embedded Controller (early)
+options ACPIEC_DEBUG=-1
acpifan* at acpi? # ACPI Fan
acpilid* at acpi? # ACPI Lid Switch
acpipmtr* at acpi? # ACPI Power Meter (experimental)
diff -r 19e496b8c09c -r 068b2957e613 sys/arch/i386/conf/ALL
--- a/sys/arch/i386/conf/ALL Tue Jul 18 10:02:09 2023 +0000
+++ b/sys/arch/i386/conf/ALL Tue Jul 18 10:02:25 2023 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: ALL,v 1.510 2023/07/16 10:20:07 riastradh Exp $
+# $NetBSD: ALL,v 1.511 2023/07/18 10:02:25 riastradh Exp $
# From NetBSD: GENERIC,v 1.787 2006/10/01 18:37:54 bouyer Exp
#
# ALL machine description file
@@ -17,7 +17,7 @@ include "arch/i386/conf/std.i386"
options INCLUDE_CONFIG_FILE # embed config file in kernel binary
-#ident "ALL-$Revision: 1.510 $"
+#ident "ALL-$Revision: 1.511 $"
maxusers 64 # estimated number of users
@@ -357,6 +357,7 @@ acpibut* at acpi? # ACPI Button
acpidalb* at acpi? # ACPI Direct Application Launch Button
acpiec* at acpi? # ACPI Embedded Controller (late)
acpiecdt* at acpi? # ACPI Embedded Controller (early)
+options ACPIEC_DEBUG=-1
acpifan* at acpi? # ACPI Fan
acpilid* at acpi? # ACPI Lid Switch
acpipmtr* at acpi? # ACPI Power Meter (experimental)
diff -r 19e496b8c09c -r 068b2957e613 sys/dev/acpi/acpi_ec.c
--- a/sys/dev/acpi/acpi_ec.c Tue Jul 18 10:02:09 2023 +0000
+++ b/sys/dev/acpi/acpi_ec.c Tue Jul 18 10:02:25 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_ec.c,v 1.87 2023/07/18 10:02:09 riastradh Exp $ */
+/* $NetBSD: acpi_ec.c,v 1.88 2023/07/18 10:02:25 riastradh Exp $ */
/*-
* Copyright (c) 2007 Joerg Sonnenberger <joerg%NetBSD.org@localhost>.
@@ -59,7 +59,11 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.87 2023/07/18 10:02:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.88 2023/07/18 10:02:25 riastradh Exp $");
+
+#ifdef _KERNEL_OPT
+#include "opt_acpi_ec.h"
+#endif
#include <sys/param.h>
#include <sys/callout.h>
@@ -101,23 +105,39 @@ ACPI_MODULE_NAME ("acpi_ec")
#define EC_STATUS_SCI 0x20
#define EC_STATUS_SMI 0x40
+#define EC_STATUS_FMT \
+ "\x10\10IGN7\7SMI\6SCI\5BURST\4CMD\3IGN2\2IBF\1OBF"
+
static const struct device_compatible_entry compat_data[] = {
{ .compat = "PNP0C09" },
DEVICE_COMPAT_EOL
};
+#define EC_STATE_ENUM(F) \
+ F(EC_STATE_QUERY, "QUERY") \
+ F(EC_STATE_QUERY_VAL, "QUERY_VAL") \
+ F(EC_STATE_READ, "READ") \
+ F(EC_STATE_READ_ADDR, "READ_ADDR") \
+ F(EC_STATE_READ_VAL, "READ_VAL") \
+ F(EC_STATE_WRITE, "WRITE") \
+ F(EC_STATE_WRITE_ADDR, "WRITE_ADDR") \
+ F(EC_STATE_WRITE_VAL, "WRITE_VAL") \
+ F(EC_STATE_FREE, "FREE") \
+
enum ec_state_t {
- EC_STATE_QUERY,
- EC_STATE_QUERY_VAL,
- EC_STATE_READ,
- EC_STATE_READ_ADDR,
- EC_STATE_READ_VAL,
- EC_STATE_WRITE,
- EC_STATE_WRITE_ADDR,
- EC_STATE_WRITE_VAL,
- EC_STATE_FREE
+#define F(N, S) N,
+ EC_STATE_ENUM(F)
+#undef F
};
+#ifdef ACPIEC_DEBUG
+static const char *const acpiec_state_names[] = {
+#define F(N, S) [N] = S,
+ EC_STATE_ENUM(F)
+#undef F
+};
+#endif
+
struct acpiec_softc {
device_t sc_dev;
@@ -144,6 +164,55 @@ struct acpiec_softc {
uint8_t sc_cur_addr, sc_cur_val;
};
+#ifdef ACPIEC_DEBUG
+
+#define ACPIEC_DEBUG_ENUM(F) \
+ F(ACPIEC_DEBUG_REG, "REG") \
+ F(ACPIEC_DEBUG_RW, "RW") \
+ F(ACPIEC_DEBUG_QUERY, "QUERY") \
+ F(ACPIEC_DEBUG_TRANSITION, "TRANSITION") \
+ F(ACPIEC_DEBUG_INTR, "INTR") \
+
+enum {
+#define F(N, S) N,
+ ACPIEC_DEBUG_ENUM(F)
+#undef F
+};
+
+static const char *const acpiec_debug_names[] = {
+#define F(N, S) [N] = S,
+ ACPIEC_DEBUG_ENUM(F)
+#undef F
+};
+
+int acpiec_debug = ACPIEC_DEBUG;
+
+#define DPRINTF(n, sc, fmt, ...) do \
+{ \
+ if (acpiec_debug & __BIT(n)) { \
+ char dprintbuf[16]; \
+ const char *state; \
+ \
+ /* paranoia */ \
+ if ((sc)->sc_state < __arraycount(acpiec_state_names)) { \
+ state = acpiec_state_names[(sc)->sc_state]; \
+ } else { \
+ snprintf(dprintbuf, sizeof(dprintbuf), "0x%x", \
+ (sc)->sc_state); \
+ state = dprintbuf; \
+ } \
+ \
+ device_printf((sc)->sc_dev, "(%s) [%s] "fmt, \
+ acpiec_debug_names[n], state, ##__VA_ARGS__); \
+ } \
+} while (0)
+
+#else
+
+#define DPRINTF(n, sc, fmt, ...) __nothing
+
+#endif
+
static int acpiecdt_match(device_t, cfdata_t, void *);
static void acpiecdt_attach(device_t, device_t, void *);
@@ -495,24 +564,38 @@ acpiec_parse_gpe_package(device_t self,
static uint8_t
acpiec_read_data(struct acpiec_softc *sc)
{
- return bus_space_read_1(sc->sc_data_st, sc->sc_data_sh, 0);
+ uint8_t x;
+
+ x = bus_space_read_1(sc->sc_data_st, sc->sc_data_sh, 0);
+ DPRINTF(ACPIEC_DEBUG_REG, sc, "read data=0x%"PRIx8"\n", x);
+
+ return x;
}
static void
acpiec_write_data(struct acpiec_softc *sc, uint8_t val)
{
+
+ DPRINTF(ACPIEC_DEBUG_REG, sc, "write data=0x%"PRIx8"\n", val);
bus_space_write_1(sc->sc_data_st, sc->sc_data_sh, 0, val);
}
static uint8_t
acpiec_read_status(struct acpiec_softc *sc)
{
- return bus_space_read_1(sc->sc_csr_st, sc->sc_csr_sh, 0);
+ uint8_t x;
+
+ x = bus_space_read_1(sc->sc_csr_st, sc->sc_csr_sh, 0);
+ DPRINTF(ACPIEC_DEBUG_REG, sc, "read status=0x%"PRIx8"\n", x);
+
+ return x;
}
static void
acpiec_write_command(struct acpiec_softc *sc, uint8_t cmd)
{
+
+ DPRINTF(ACPIEC_DEBUG_REG, sc, "write command=0x%"PRIx8"\n", cmd);
bus_space_write_1(sc->sc_csr_st, sc->sc_csr_sh, 0, cmd);
}
@@ -575,6 +658,13 @@ acpiec_read(device_t dv, uint8_t addr, u
acpiec_lock(dv);
mutex_enter(&sc->sc_mtx);
+ DPRINTF(ACPIEC_DEBUG_RW, sc,
+ "pid %ld %s, lid %ld%s%s: read addr 0x%"PRIx8"\n",
+ (long)curproc->p_pid, curproc->p_comm,
+ (long)curlwp->l_lid, curlwp->l_name ? " " : "",
+ curlwp->l_name ? curlwp->l_name : "",
+ addr);
+
sc->sc_cur_addr = addr;
sc->sc_state = EC_STATE_READ;
@@ -606,6 +696,13 @@ acpiec_read(device_t dv, uint8_t addr, u
}
done:
+ DPRINTF(ACPIEC_DEBUG_RW, sc,
+ "pid %ld %s, lid %ld%s%s: read addr 0x%"PRIx8": 0x%"PRIx8"\n",
+ (long)curproc->p_pid, curproc->p_comm,
+ (long)curlwp->l_lid, curlwp->l_name ? " " : "",
+ curlwp->l_name ? curlwp->l_name : "",
+ addr, sc->sc_cur_val);
+
*val = sc->sc_cur_val;
mutex_exit(&sc->sc_mtx);
@@ -622,6 +719,13 @@ acpiec_write(device_t dv, uint8_t addr,
acpiec_lock(dv);
mutex_enter(&sc->sc_mtx);
+ DPRINTF(ACPIEC_DEBUG_RW, sc,
+ "pid %ld %s, lid %ld%s%s write addr 0x%"PRIx8": 0x%"PRIx8"\n",
+ (long)curproc->p_pid, curproc->p_comm,
+ (long)curlwp->l_lid, curlwp->l_name ? " " : "",
+ curlwp->l_name ? curlwp->l_name : "",
+ addr, val);
+
sc->sc_cur_addr = addr;
sc->sc_cur_val = val;
sc->sc_state = EC_STATE_WRITE;
@@ -654,6 +758,14 @@ acpiec_write(device_t dv, uint8_t addr,
}
done:
+ DPRINTF(ACPIEC_DEBUG_RW, sc,
+ "pid %ld %s, lid %ld%s%s: write addr 0x%"PRIx8": 0x%"PRIx8
+ " done\n",
+ (long)curproc->p_pid, curproc->p_comm,
+ (long)curlwp->l_lid, curlwp->l_name ? " " : "",
+ curlwp->l_name ? curlwp->l_name : "",
+ addr, val);
+
mutex_exit(&sc->sc_mtx);
acpiec_unlock(dv);
return AE_OK;
@@ -755,11 +867,14 @@ loop:
if (sc->sc_got_sci == false)
cv_wait(&sc->sc_cv_sci, &sc->sc_mtx);
+ DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI query requested\n");
mutex_exit(&sc->sc_mtx);
acpiec_lock(dv);
mutex_enter(&sc->sc_mtx);
+ DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI query\n");
+
/* The Query command can always be issued, so be defensive here. */
sc->sc_got_sci = false;
sc->sc_state = EC_STATE_QUERY;
@@ -771,10 +886,12 @@ loop:
delay(1);
}
+ DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI polling timeout\n");
cv_wait(&sc->sc_cv, &sc->sc_mtx);
done:
Home |
Main Index |
Thread Index |
Old Index