CVS commit: src/sys/dev/acpi

2024-05-10 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri May 10 19:29:46 UTC 2024

Modified Files:
src/sys/dev/acpi: acpi_display.c

Log Message:
Add quirk for machines were the getting the brightness value always
returns the same result by keeping a local copy of the last set value.

This makes the brightness buttons work on my Thinkpad T450s, and will
probably fix PR kern/57825 as well.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/acpi/acpi_display.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_display.c
diff -u src/sys/dev/acpi/acpi_display.c:1.23 src/sys/dev/acpi/acpi_display.c:1.24
--- src/sys/dev/acpi/acpi_display.c:1.23	Fri Mar 17 17:16:06 2023
+++ src/sys/dev/acpi/acpi_display.c	Fri May 10 19:29:46 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_display.c,v 1.23 2023/03/17 17:16:06 andvar Exp $	*/
+/*	$NetBSD: acpi_display.c,v 1.24 2024/05/10 19:29:46 maya Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.23 2023/03/17 17:16:06 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.24 2024/05/10 19:29:46 maya Exp $");
 
 #include 
 #include 
@@ -270,6 +270,12 @@ struct acpidisp_brctl {
 	uint8_t		*bc_level;		/* Array of levels */
 	uint16_t	 bc_level_count;	/* Number of levels */
 	uint8_t		 bc_current;		/* Current level */
+
+	/* 
+	 * Quirk if firmware returns wrong values for _BQC
+	 * (acpidisp_get_brightness) 
+	 */
+	bool		bc_bqc_broken;
 };
 
 /*
@@ -376,6 +382,7 @@ static int	acpidisp_get_brightness(const
 		uint8_t *);
 static int	acpidisp_set_brightness(const struct acpidisp_out_softc *,
 		uint8_t);
+static int	acpidisp_quirk_get_brightness(const struct acpidisp_out_softc *);
 
 static void	acpidisp_print_odinfo(device_t, const struct acpidisp_odinfo *);
 static void	acpidisp_print_brctl(device_t, const struct acpidisp_brctl *);
@@ -717,6 +724,10 @@ acpidisp_out_attach(device_t parent, dev
 			kmem_free(bc, sizeof(*bc));
 			osc->sc_brctl = NULL;
 		} else {
+			if (acpidisp_quirk_get_brightness(osc)) {
+aprint_error_dev(self,
+"failed to test _BQC quirk\n");
+			}
 			acpidisp_print_brctl(self, osc->sc_brctl);
 		}
 	}
@@ -1860,6 +1871,11 @@ acpidisp_get_brightness(const struct acp
 	if (!(osc->sc_caps & ACPI_DISP_OUT_CAP__BQC))
 		return ENODEV;
 
+	if (osc->sc_brctl->bc_bqc_broken) {
+		*valuep = osc->sc_brctl->bc_current;
+		return 0;
+	}
+
 	rv = acpi_eval_integer(hdl, "_BQC", );
 	if (ACPI_FAILURE(rv)) {
 		aprint_error_dev(osc->sc_dev, "failed to evaluate %s.%s: %s\n",
@@ -1878,6 +1894,60 @@ acpidisp_get_brightness(const struct acp
 	return 0;
 }
 
+/*
+ * Quirk for when getting the brightness value always returns the same
+ * result, which breaks brightness controls which try to lower the
+ * brightness by a specific value and then check if it worked.
+ */
+static int
+acpidisp_quirk_get_brightness(const struct acpidisp_out_softc *osc)
+{
+	struct acpidisp_brctl *bc;
+	uint8_t original_brightness, test_brightness;
+	int error;
+
+	bc = osc->sc_brctl;
+
+	/* Avoid false results if quirk already enabled */
+	bc->bc_bqc_broken = false;
+
+	error = acpidisp_get_brightness(osc, >bc_current);
+	if (error)
+		return error;
+	original_brightness = bc->bc_current;
+
+	/* Find a different brightness value */
+	test_brightness = bc->bc_level[bc->bc_level_count - 1];
+	if (test_brightness == original_brightness)
+		test_brightness = bc->bc_level[0];
+
+	if (test_brightness == original_brightness) {
+		aprint_error_dev(osc->sc_dev,
+		"couldn't find different brightness levels"
+		" for _BQC quirk test\n");
+		return 0;
+	}
+
+	bc->bc_current = test_brightness;
+	error = acpidisp_set_brightness(osc, bc->bc_current);
+	if (error)
+		return error;
+
+	error = acpidisp_get_brightness(osc, >bc_current);
+	if (error)
+		return error;
+
+	/* We set a different value, but got the original value back */
+	if (bc->bc_current == original_brightness) {
+		aprint_normal_dev(osc->sc_dev, "_BQC broken, enabling quirk\n");
+		bc->bc_bqc_broken = true;
+	}
+
+	/* Restore original value */
+	bc->bc_current = original_brightness;
+	return acpidisp_set_brightness(osc, bc->bc_current);
+}
+
 static int
 acpidisp_set_brightness(const struct acpidisp_out_softc *osc, uint8_t value)
 {



CVS commit: src/sys/dev/acpi

2024-05-10 Thread Maya Rashish
Module Name:src
Committed By:   maya
Date:   Fri May 10 19:29:46 UTC 2024

Modified Files:
src/sys/dev/acpi: acpi_display.c

Log Message:
Add quirk for machines were the getting the brightness value always
returns the same result by keeping a local copy of the last set value.

This makes the brightness buttons work on my Thinkpad T450s, and will
probably fix PR kern/57825 as well.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/acpi/acpi_display.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/dev/acpi

2024-04-28 Thread Taylor R Campbell
> Module Name:src
> Committed By:   christos
> Date:   Fri Apr 26 18:19:18 UTC 2024
> 
> Modified Files:
> src/sys/dev/acpi: acpi_bat.c
> 
> Log Message:
> PR/58201: Malte Dehling: re-order sysmon initialization before acpi
> registration, to avoid needing to call to acpi_deregister_notify on sysmon
> failure.

This isn't really a bug: the detach function calls
acpi_deregister_notify.  Now, with this change, it will call
acpi_deregister_notify even if acpi_register_notify was never called.

Fortunately, that's mostly harmless in the current implementation --
just as it was harmless to leave the notifier there; it doesn't use
any memory that would be leaked.

(Really, if there's any bug here, it's that sysmon_envsys_register can
fail at all.  This creates vast swaths of never-tested error branches
that waste maintainer and auditor time.)


CVS commit: src/sys/dev/acpi

2024-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 27 14:50:18 UTC 2024

Modified Files:
src/sys/dev/acpi: thinkpad_acpi.c

Log Message:
Expose a sysctl interface hw.acpi.thinkpad.bat[]. to control
some aspects of battery charging behavior on supported systems:

charge_start
threshold below which to start charging (in %, 0-99)

charge_stop
threshold above which to stop charging (in %, 1-100)

force_discharge
discharge while on AC power, e.g., for calibration

charge_inhibit
inhibit charging while on AC power

>From Malte Dehling


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/acpi/thinkpad_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/thinkpad_acpi.c
diff -u src/sys/dev/acpi/thinkpad_acpi.c:1.56 src/sys/dev/acpi/thinkpad_acpi.c:1.57
--- src/sys/dev/acpi/thinkpad_acpi.c:1.56	Sat Apr 27 10:45:11 2024
+++ src/sys/dev/acpi/thinkpad_acpi.c	Sat Apr 27 10:50:18 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: thinkpad_acpi.c,v 1.56 2024/04/27 14:45:11 christos Exp $ */
+/* $NetBSD: thinkpad_acpi.c,v 1.57 2024/04/27 14:50:18 christos Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,13 +27,14 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.56 2024/04/27 14:45:11 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.57 2024/04/27 14:50:18 christos Exp $");
 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -49,10 +50,27 @@ ACPI_MODULE_NAME		("thinkpad_acpi")
 #define	THINKPAD_NFANSENSORS	1
 #define	THINKPAD_NSENSORS	(THINKPAD_NTEMPSENSORS + THINKPAD_NFANSENSORS)
 
+typedef struct tp_sysctl_param {
+	device_t		sp_dev;
+	int			sp_bat;
+} tp_sysctl_param_t;
+
+typedef union tp_batctl {
+	int			have_any;
+	struct {
+	int			charge_start:1;
+	int			charge_stop:1;
+	int			charge_inhibit:1;
+	int			force_discharge:1;
+	int			individual_control:1;
+	}			have;
+} tp_batctl_t;
+
 typedef struct thinkpad_softc {
 	device_t		sc_dev;
 	device_t		sc_ecdev;
 	struct acpi_devnode	*sc_node;
+	struct sysctllog	*sc_log;
 	ACPI_HANDLE		sc_powhdl;
 	ACPI_HANDLE		sc_cmoshdl;
 	ACPI_INTEGER		sc_ver;
@@ -90,6 +108,14 @@ typedef struct thinkpad_softc {
 	envsys_data_t		sc_sensor[THINKPAD_NSENSORS];
 
 	int			sc_display_state;
+
+#define THINKPAD_BAT_ANY	0
+#define THINKPAD_BAT_PRIMARY	1
+#define THINKPAD_BAT_SECONDARY	2
+#define THINKPAD_BAT_LAST	3
+
+	tp_batctl_t		sc_batctl;
+	tp_sysctl_param_t	sc_scparam[THINKPAD_BAT_LAST];
 } thinkpad_softc_t;
 
 /* Hotkey events */
@@ -130,6 +156,17 @@ typedef struct thinkpad_softc {
 #define	THINKPAD_DISPLAY_ALL \
 	(THINKPAD_DISPLAY_LCD | THINKPAD_DISPLAY_CRT | THINKPAD_DISPLAY_DVI)
 
+#define THINKPAD_GET_CHARGE_START	"BCTG"
+#define THINKPAD_SET_CHARGE_START	"BCCS"
+#define THINKPAD_GET_CHARGE_STOP	"BCSG"
+#define THINKPAD_SET_CHARGE_STOP	"BCSS"
+#define THINKPAD_GET_FORCE_DISCHARGE	"BDSG"
+#define THINKPAD_SET_FORCE_DISCHARGE	"BDSS"
+#define THINKPAD_GET_CHARGE_INHIBIT	"BICG"
+#define THINKPAD_SET_CHARGE_INHIBIT	"BICS"
+
+#define THINKPAD_CALL_ERROR		0x8000
+
 #define THINKPAD_BLUETOOTH_HWPRESENT	0x01
 #define THINKPAD_BLUETOOTH_RADIOSSW	0x02
 #define THINKPAD_BLUETOOTH_RESUMECTRL	0x04
@@ -168,6 +205,9 @@ static void	thinkpad_brightness_down(dev
 static uint8_t	thinkpad_brightness_read(thinkpad_softc_t *);
 static void	thinkpad_cmos(thinkpad_softc_t *, uint8_t);
 
+static void	thinkpad_battery_probe_support(device_t);
+static void	thinkpad_battery_sysctl_setup(device_t);
+
 CFATTACH_DECL3_NEW(thinkpad, sizeof(thinkpad_softc_t),
 thinkpad_match, thinkpad_attach, thinkpad_detach, NULL, NULL, NULL,
 0);
@@ -220,6 +260,7 @@ thinkpad_attach(device_t parent, device_
 	int i;
 
 	sc->sc_dev = self;
+	sc->sc_log = NULL;
 	sc->sc_powhdl = NULL;
 	sc->sc_cmoshdl = NULL;
 	sc->sc_node = aa->aa_node;
@@ -371,6 +412,17 @@ thinkpad_attach(device_t parent, device_
 	/* Register temperature and fan sensors with envsys */
 	thinkpad_sensors_init(sc);
 
+	/* Probe supported battery charge/control operations */
+	thinkpad_battery_probe_support(self);
+
+	if (sc->sc_batctl.have_any) {
+		for (i = 0; i < THINKPAD_BAT_LAST; i++) {
+			sc->sc_scparam[i].sp_dev = self;
+			sc->sc_scparam[i].sp_bat = i;
+		}
+		thinkpad_battery_sysctl_setup(self);
+	}
+
 fail:
 	if (!pmf_device_register(self, NULL, thinkpad_resume))
 		aprint_error_dev(self, "couldn't establish power handler\n");
@@ -396,6 +448,9 @@ thinkpad_detach(device_t self, int flags
 	if (sc->sc_sme != NULL)
 		sysmon_envsys_unregister(sc->sc_sme);
 
+	if (sc->sc_log != NULL)
+		sysctl_teardown(>sc_log);
+
 	pmf_device_deregister(self);
 
 	pmf_event_deregister(self, PMFE_DISPLAY_BRIGHTNESS_UP,
@@ -948,6 +1003,290 @@ thinkpad_cmos(thinkpad_softc_t *sc, uint
 		AcpiFormatException(rv));
 }
 
+static uint32_t
+thinkpad_call_method(device_t 

CVS commit: src/sys/dev/acpi

2024-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 27 14:50:18 UTC 2024

Modified Files:
src/sys/dev/acpi: thinkpad_acpi.c

Log Message:
Expose a sysctl interface hw.acpi.thinkpad.bat[]. to control
some aspects of battery charging behavior on supported systems:

charge_start
threshold below which to start charging (in %, 0-99)

charge_stop
threshold above which to stop charging (in %, 1-100)

force_discharge
discharge while on AC power, e.g., for calibration

charge_inhibit
inhibit charging while on AC power

>From Malte Dehling


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/dev/acpi/thinkpad_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 27 14:45:11 UTC 2024

Modified Files:
src/sys/dev/acpi: thinkpad_acpi.c

Log Message:
thinkpad cosmetic patches (Malte Dehling)


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/acpi/thinkpad_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-04-27 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 27 14:45:11 UTC 2024

Modified Files:
src/sys/dev/acpi: thinkpad_acpi.c

Log Message:
thinkpad cosmetic patches (Malte Dehling)


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/dev/acpi/thinkpad_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/thinkpad_acpi.c
diff -u src/sys/dev/acpi/thinkpad_acpi.c:1.55 src/sys/dev/acpi/thinkpad_acpi.c:1.56
--- src/sys/dev/acpi/thinkpad_acpi.c:1.55	Fri Aug 12 12:21:41 2022
+++ src/sys/dev/acpi/thinkpad_acpi.c	Sat Apr 27 10:45:11 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: thinkpad_acpi.c,v 1.55 2022/08/12 16:21:41 riastradh Exp $ */
+/* $NetBSD: thinkpad_acpi.c,v 1.56 2024/04/27 14:45:11 christos Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.55 2022/08/12 16:21:41 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.56 2024/04/27 14:45:11 christos Exp $");
 
 #include 
 #include 
@@ -138,8 +138,8 @@ typedef struct thinkpad_softc {
 #define THINKPAD_WWAN_RADIOSSW		0x02
 #define THINKPAD_WWAN_RESUMECTRL	0x04
 
-#define THINKPAD_UWB_HWPRESENT	0x01
-#define THINKPAD_UWB_RADIOSSW	0x02
+#define THINKPAD_UWB_HWPRESENT		0x01
+#define THINKPAD_UWB_RADIOSSW		0x02
 
 #define THINKPAD_RFK_BLUETOOTH		0
 #define THINKPAD_RFK_WWAN		1
@@ -165,7 +165,7 @@ static void	thinkpad_bluetooth_toggle(th
 static bool	thinkpad_resume(device_t, const pmf_qual_t *);
 static void	thinkpad_brightness_up(device_t);
 static void	thinkpad_brightness_down(device_t);
-static uint8_t	thinkpad_brightness_read(thinkpad_softc_t *sc);
+static uint8_t	thinkpad_brightness_read(thinkpad_softc_t *);
 static void	thinkpad_cmos(thinkpad_softc_t *, uint8_t);
 
 CFATTACH_DECL3_NEW(thinkpad, sizeof(thinkpad_softc_t),
@@ -230,7 +230,7 @@ thinkpad_attach(device_t parent, device_
 
 	sc->sc_ecdev = NULL;
 	for (curdev = deviter_first(, DEVITER_F_ROOT_FIRST);
-	 curdev != NULL; curdev = deviter_next())
+	curdev != NULL; curdev = deviter_next())
 		if (device_is_a(curdev, "acpiecdt") ||
 		device_is_a(curdev, "acpiec")) {
 			sc->sc_ecdev = curdev;
@@ -330,29 +330,30 @@ thinkpad_attach(device_t parent, device_
 #endif
 	for (i = TP_PSW_DISPLAY_CYCLE; i < TP_PSW_LAST; i++)
 		sc->sc_smpsw[i].smpsw_type = PSWITCH_TYPE_HOTKEY;
-	psw[TP_PSW_DISPLAY_CYCLE].smpsw_name = PSWITCH_HK_DISPLAY_CYCLE;
-	psw[TP_PSW_LOCK_SCREEN].smpsw_name = PSWITCH_HK_LOCK_SCREEN;
-	psw[TP_PSW_BATTERY_INFO].smpsw_name = PSWITCH_HK_BATTERY_INFO;
-	psw[TP_PSW_EJECT_BUTTON].smpsw_name = PSWITCH_HK_EJECT_BUTTON;
-	psw[TP_PSW_ZOOM_BUTTON].smpsw_name = PSWITCH_HK_ZOOM_BUTTON;
-	psw[TP_PSW_VENDOR_BUTTON].smpsw_name = PSWITCH_HK_VENDOR_BUTTON;
+
+	psw[TP_PSW_DISPLAY_CYCLE].smpsw_name	= PSWITCH_HK_DISPLAY_CYCLE;
+	psw[TP_PSW_LOCK_SCREEN].smpsw_name	= PSWITCH_HK_LOCK_SCREEN;
+	psw[TP_PSW_BATTERY_INFO].smpsw_name	= PSWITCH_HK_BATTERY_INFO;
+	psw[TP_PSW_EJECT_BUTTON].smpsw_name	= PSWITCH_HK_EJECT_BUTTON;
+	psw[TP_PSW_ZOOM_BUTTON].smpsw_name	= PSWITCH_HK_ZOOM_BUTTON;
+	psw[TP_PSW_VENDOR_BUTTON].smpsw_name	= PSWITCH_HK_VENDOR_BUTTON;
 #ifndef THINKPAD_NORMAL_HOTKEYS
-	psw[TP_PSW_FNF1_BUTTON].smpsw_name = PSWITCH_HK_FNF1_BUTTON;
-	psw[TP_PSW_WIRELESS_BUTTON].smpsw_name = PSWITCH_HK_WIRELESS_BUTTON;
-	psw[TP_PSW_WWAN_BUTTON].smpsw_name = PSWITCH_HK_WWAN_BUTTON;
-	psw[TP_PSW_POINTER_BUTTON].smpsw_name  = PSWITCH_HK_POINTER_BUTTON;
-	psw[TP_PSW_FNF10_BUTTON].smpsw_name= PSWITCH_HK_FNF10_BUTTON;
-	psw[TP_PSW_FNF11_BUTTON].smpsw_name= PSWITCH_HK_FNF11_BUTTON;
-	psw[TP_PSW_BRIGHTNESS_UP].smpsw_name   = PSWITCH_HK_BRIGHTNESS_UP;
-	psw[TP_PSW_BRIGHTNESS_DOWN].smpsw_name = PSWITCH_HK_BRIGHTNESS_DOWN;
-	psw[TP_PSW_THINKLIGHT].smpsw_name  = PSWITCH_HK_THINKLIGHT;
-	psw[TP_PSW_VOLUME_UP].smpsw_name   = PSWITCH_HK_VOLUME_UP;
-	psw[TP_PSW_VOLUME_DOWN].smpsw_name = PSWITCH_HK_VOLUME_DOWN;
-	psw[TP_PSW_VOLUME_MUTE].smpsw_name = PSWITCH_HK_VOLUME_MUTE;
-	psw[TP_PSW_STAR_BUTTON].smpsw_name = PSWITCH_HK_STAR_BUTTON;
-	psw[TP_PSW_SCISSORS_BUTTON].smpsw_name = PSWITCH_HK_SCISSORS_BUTTON;
-	psw[TP_PSW_BLUETOOTH_BUTTON].smpsw_name = PSWITCH_HK_BLUETOOTH_BUTTON;
-	psw[TP_PSW_KEYBOARD_BUTTON].smpsw_name = PSWITCH_HK_KEYBOARD_BUTTON;
+	psw[TP_PSW_FNF1_BUTTON].smpsw_name	= PSWITCH_HK_FNF1_BUTTON;
+	psw[TP_PSW_WIRELESS_BUTTON].smpsw_name	= PSWITCH_HK_WIRELESS_BUTTON;
+	psw[TP_PSW_WWAN_BUTTON].smpsw_name	= PSWITCH_HK_WWAN_BUTTON;
+	psw[TP_PSW_POINTER_BUTTON].smpsw_name	= PSWITCH_HK_POINTER_BUTTON;
+	psw[TP_PSW_FNF10_BUTTON].smpsw_name	= PSWITCH_HK_FNF10_BUTTON;
+	psw[TP_PSW_FNF11_BUTTON].smpsw_name	= PSWITCH_HK_FNF11_BUTTON;
+	psw[TP_PSW_BRIGHTNESS_UP].smpsw_name	= PSWITCH_HK_BRIGHTNESS_UP;
+	psw[TP_PSW_BRIGHTNESS_DOWN].smpsw_name	= PSWITCH_HK_BRIGHTNESS_DOWN;
+	psw[TP_PSW_THINKLIGHT].smpsw_name	= PSWITCH_HK_THINKLIGHT;
+	

CVS commit: src/sys/dev/acpi

2024-04-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 27 00:40:07 UTC 2024

Modified Files:
src/sys/dev/acpi: acpi_bat.c

Log Message:
Remove 0 initializations (since the softc is zalloc'ed) and the initial
refresh which will have no data.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/dev/acpi/acpi_bat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_bat.c
diff -u src/sys/dev/acpi/acpi_bat.c:1.122 src/sys/dev/acpi/acpi_bat.c:1.123
--- src/sys/dev/acpi/acpi_bat.c:1.122	Fri Apr 26 14:19:18 2024
+++ src/sys/dev/acpi/acpi_bat.c	Fri Apr 26 20:40:06 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_bat.c,v 1.122 2024/04/26 18:19:18 christos Exp $	*/
+/*	$NetBSD: acpi_bat.c,v 1.123 2024/04/27 00:40:06 christos Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.122 2024/04/26 18:19:18 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.123 2024/04/27 00:40:06 christos Exp $");
 
 #include 
 #include 
@@ -229,14 +229,6 @@ acpibat_attach(device_t parent, device_t
 
 	sc->sc_node = aa->aa_node;
 
-	sc->sc_present = 0;
-	sc->sc_dvoltage = 0;
-	sc->sc_dcapacity = 0;
-	sc->sc_lcapacity = 0;
-	sc->sc_wcapacity = 0;
-
-	sc->sc_sme = NULL;
-
 	mutex_init(>sc_mutex, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(>sc_condvar, device_xname(self));
 
@@ -759,7 +751,7 @@ acpibat_init_envsys(device_t dv)
 	sc->sc_sme->sme_cookie = dv;
 	sc->sc_sme->sme_refresh = acpibat_refresh;
 	sc->sc_sme->sme_class = SME_CLASS_BATTERY;
-	sc->sc_sme->sme_flags = SME_POLL_ONLY | SME_INIT_REFRESH;
+	sc->sc_sme->sme_flags = SME_POLL_ONLY;
 	sc->sc_sme->sme_get_limits = acpibat_get_limits;
 
 	if (sysmon_envsys_register(sc->sc_sme))



CVS commit: src/sys/dev/acpi

2024-04-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Apr 27 00:40:07 UTC 2024

Modified Files:
src/sys/dev/acpi: acpi_bat.c

Log Message:
Remove 0 initializations (since the softc is zalloc'ed) and the initial
refresh which will have no data.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/sys/dev/acpi/acpi_bat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-04-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr 26 18:19:18 UTC 2024

Modified Files:
src/sys/dev/acpi: acpi_bat.c

Log Message:
PR/58201: Malte Dehling: re-order sysmon initialization before acpi
registration, to avoid needing to call to acpi_deregister_notify on sysmon
failure.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/dev/acpi/acpi_bat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_bat.c
diff -u src/sys/dev/acpi/acpi_bat.c:1.121 src/sys/dev/acpi/acpi_bat.c:1.122
--- src/sys/dev/acpi/acpi_bat.c:1.121	Thu Jan  6 20:10:57 2022
+++ src/sys/dev/acpi/acpi_bat.c	Fri Apr 26 14:19:18 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_bat.c,v 1.121 2022/01/07 01:10:57 riastradh Exp $	*/
+/*	$NetBSD: acpi_bat.c,v 1.122 2024/04/26 18:19:18 christos Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.121 2022/01/07 01:10:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.122 2024/04/26 18:19:18 christos Exp $");
 
 #include 
 #include 
@@ -762,17 +762,16 @@ acpibat_init_envsys(device_t dv)
 	sc->sc_sme->sme_flags = SME_POLL_ONLY | SME_INIT_REFRESH;
 	sc->sc_sme->sme_get_limits = acpibat_get_limits;
 
+	if (sysmon_envsys_register(sc->sc_sme))
+		goto fail;
+
 	(void)acpi_register_notify(sc->sc_node, acpibat_notify_handler);
 	acpibat_update_info(dv);
 	acpibat_update_status(dv);
 
-	if (sysmon_envsys_register(sc->sc_sme))
-		goto fail;
-
 	(void)pmf_device_register(dv, NULL, acpibat_resume);
 
 	return;
-
 fail:
 	aprint_error_dev(dv, "failed to initialize sysmon\n");
 



CVS commit: src/sys/dev/acpi

2024-04-26 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr 26 18:19:18 UTC 2024

Modified Files:
src/sys/dev/acpi: acpi_bat.c

Log Message:
PR/58201: Malte Dehling: re-order sysmon initialization before acpi
registration, to avoid needing to call to acpi_deregister_notify on sysmon
failure.


To generate a diff of this commit:
cvs rdiff -u -r1.121 -r1.122 src/sys/dev/acpi/acpi_bat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Mar 28 13:40:08 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c

Log Message:
apei(4): Fix uninitialized stack access in error branch.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/apei_einj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-28 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Mar 28 13:40:08 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c

Log Message:
apei(4): Fix uninitialized stack access in error branch.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/apei_einj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_einj.c
diff -u src/sys/dev/acpi/apei_einj.c:1.6 src/sys/dev/acpi/apei_einj.c:1.7
--- src/sys/dev/acpi/apei_einj.c:1.6	Tue Mar 26 22:01:03 2024
+++ src/sys/dev/acpi/apei_einj.c	Thu Mar 28 13:40:08 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_einj.c,v 1.6 2024/03/26 22:01:03 rillig Exp $	*/
+/*	$NetBSD: apei_einj.c,v 1.7 2024/03/28 13:40:08 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.6 2024/03/26 22:01:03 rillig Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.7 2024/03/28 13:40:08 riastradh Exp $");
 
 #include 
 
@@ -516,6 +516,16 @@ apei_einj_trigger(struct apei_softc *sc,
 	uint32_t i, nentries;
 
 	/*
+	 * Initialize the machine to execute the TRIGGER_ERROR action's
+	 * instructions.  Do this early to keep the error branches
+	 * simpler.
+	 */
+	memset(M, 0, sizeof(*M));
+	M->sc = sc;
+	M->x = x;		/* input */
+	M->y = 0;		/* output */
+
+	/*
 	 * Get the TRIGGER_ERROR action table's physical address.
 	 */
 	teatab_pa = apei_einj_act(sc, ACPI_EINJ_GET_TRIGGER_TABLE, 0);
@@ -588,15 +598,6 @@ apei_einj_trigger(struct apei_softc *sc,
 	teatab = AcpiOsMapMemory(teatab_pa, mapsize);
 
 	/*
-	 * Initialize the machine to execute the TRIGGER_ERROR action's
-	 * instructions.
-	 */
-	memset(M, 0, sizeof(*M));
-	M->sc = sc;
-	M->x = x;		/* input */
-	M->y = 0;		/* output */
-
-	/*
 	 * Now iterate over the EINJ-type entries and execute the
 	 * trigger error action instructions -- but skip if they're not
 	 * for the TRIGGER_ERROR action, and stop if they're truncated.



CVS commit: src/sys/dev/acpi

2024-03-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 26 22:16:12 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_cper.h

Log Message:
apei: fix typos in comments and snprintb bitfmt


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_cper.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_cper.h
diff -u src/sys/dev/acpi/apei_cper.h:1.1 src/sys/dev/acpi/apei_cper.h:1.2
--- src/sys/dev/acpi/apei_cper.h:1.1	Wed Mar 20 17:11:43 2024
+++ src/sys/dev/acpi/apei_cper.h	Tue Mar 26 22:16:12 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_cper.h,v 1.1 2024/03/20 17:11:43 riastradh Exp $	*/
+/*	$NetBSD: apei_cper.h,v 1.2 2024/03/26 22:16:12 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -43,9 +43,9 @@
  * https://uefi.org/specs/UEFI/2.10/Apx_N_Common_Platform_Error_Record.html#record-header
  */
 struct cper_header {
-	char		SignatureStart[4];	/* `CPER" */
+	char		SignatureStart[4];	/* `CPER' */
 	uint16_t	Revision;
-	uint32_t	SignatureEnd;		/* 0xfff */
+	uint32_t	SignatureEnd;		/* 0x */
 	uint16_t	SectionCount;
 	uint32_t	ErrorSeverity;
 	uint32_t	ValidationBits;
@@ -179,7 +179,7 @@ enum {/* struct cper_memory_error::v
 	"b\006"	"BANK\0"		  \
 	"b\007"	"DEVICE\0"		  \
 	"b\010"	"ROW\0"			  \
-	"b\011"	"COLUJMN\0"		  \
+	"b\011"	"COLUMN\0"		  \
 	"b\012"	"BIT_POSITION\0"	  \
 	"b\013"	"REQUESTOR_ID\0"	  \
 	"b\014"	"RESPONDER_ID\0"	  \



CVS commit: src/sys/dev/acpi

2024-03-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 26 22:16:12 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_cper.h

Log Message:
apei: fix typos in comments and snprintb bitfmt


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_cper.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 26 22:01:03 UTC 2024

Modified Files:
src/sys/dev/acpi: apei.c apei_einj.c

Log Message:
apei: fix typos in comments


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/apei_einj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Tue Mar 26 22:01:03 UTC 2024

Modified Files:
src/sys/dev/acpi: apei.c apei_einj.c

Log Message:
apei: fix typos in comments


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/apei_einj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei.c
diff -u src/sys/dev/acpi/apei.c:1.2 src/sys/dev/acpi/apei.c:1.3
--- src/sys/dev/acpi/apei.c:1.2	Sat Mar 23 03:41:35 2024
+++ src/sys/dev/acpi/apei.c	Tue Mar 26 22:01:03 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei.c,v 1.2 2024/03/23 03:41:35 riastradh Exp $	*/
+/*	$NetBSD: apei.c,v 1.3 2024/03/26 22:01:03 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei.c,v 1.2 2024/03/23 03:41:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei.c,v 1.3 2024/03/26 22:01:03 rillig Exp $");
 
 #include 
 #include 
@@ -305,7 +305,7 @@ apei_cper_guid_dec(const uint8_t buf[sta
  * apei_format_guid(uuid, s)
  *
  *	Format a UUID as a string.  This uses C initializer notation,
- *	not UUID notation, in order to match what the text in the UEFI
+ *	not UUID notation, in order to match the text in the UEFI
  *	specification.
  */
 static void

Index: src/sys/dev/acpi/apei_einj.c
diff -u src/sys/dev/acpi/apei_einj.c:1.5 src/sys/dev/acpi/apei_einj.c:1.6
--- src/sys/dev/acpi/apei_einj.c:1.5	Fri Mar 22 20:48:14 2024
+++ src/sys/dev/acpi/apei_einj.c	Tue Mar 26 22:01:03 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_einj.c,v 1.5 2024/03/22 20:48:14 riastradh Exp $	*/
+/*	$NetBSD: apei_einj.c,v 1.6 2024/03/26 22:01:03 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.5 2024/03/22 20:48:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.6 2024/03/26 22:01:03 rillig Exp $");
 
 #include 
 
@@ -114,7 +114,7 @@ static const char *const apei_einj_instr
 /*
  * apei_einj_instreg
  *
- *	Table of which isntructions use a register operand.
+ *	Table of which instructions use a register operand.
  *
  *	Must match apei_einj_instfunc.
  */



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 23 03:41:35 UTC 2024

Modified Files:
src/sys/dev/acpi: apei.c

Log Message:
apei(4): Make sure to initialize *fatalp in apei_gesb_report.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei.c
diff -u src/sys/dev/acpi/apei.c:1.1 src/sys/dev/acpi/apei.c:1.2
--- src/sys/dev/acpi/apei.c:1.1	Wed Mar 20 17:11:43 2024
+++ src/sys/dev/acpi/apei.c	Sat Mar 23 03:41:35 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei.c,v 1.1 2024/03/20 17:11:43 riastradh Exp $	*/
+/*	$NetBSD: apei.c,v 1.2 2024/03/23 03:41:35 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei.c,v 1.1 2024/03/20 17:11:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei.c,v 1.2 2024/03/23 03:41:35 riastradh Exp $");
 
 #include 
 #include 
@@ -673,7 +673,8 @@ apei_gesb_report(struct apei_softc *sc, 
 	if (size < sizeof(*gesb)) {
 		device_printf(sc->sc_dev, "%s: truncated GESB, %zu < %zu\n",
 		ctx, size, sizeof(*gesb));
-		return 0;
+		status = 0;
+		goto out;
 	}
 	size -= sizeof(*gesb);
 



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat Mar 23 03:41:35 UTC 2024

Modified Files:
src/sys/dev/acpi: apei.c

Log Message:
apei(4): Make sure to initialize *fatalp in apei_gesb_report.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 20:48:14 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c apei_erst.c apei_reg.c apei_reg.h

Log Message:
apei(4): Simplify EINJ/ERST register access now that it's pre-mapped.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/apei_einj.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei_erst.c \
src/sys/dev/acpi/apei_reg.c src/sys/dev/acpi/apei_reg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_einj.c
diff -u src/sys/dev/acpi/apei_einj.c:1.4 src/sys/dev/acpi/apei_einj.c:1.5
--- src/sys/dev/acpi/apei_einj.c:1.4	Fri Mar 22 20:48:05 2024
+++ src/sys/dev/acpi/apei_einj.c	Fri Mar 22 20:48:14 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_einj.c,v 1.4 2024/03/22 20:48:05 riastradh Exp $	*/
+/*	$NetBSD: apei_einj.c,v 1.5 2024/03/22 20:48:14 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.4 2024/03/22 20:48:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.5 2024/03/22 20:48:14 riastradh Exp $");
 
 #include 
 
@@ -399,7 +399,6 @@ apei_einj_instfunc(ACPI_WHEA_HEADER *hea
 void *cookie, uint32_t *ipp, uint32_t maxip)
 {
 	struct apei_einj_machine *M = cookie;
-	ACPI_STATUS rv = AE_OK;
 
 	/*
 	 * Abbreviate some of the intermediate quantities to make the
@@ -434,43 +433,26 @@ apei_einj_instfunc(ACPI_WHEA_HEADER *hea
 	 */
 	switch (header->Instruction) {
 	case ACPI_EINJ_READ_REGISTER:
-		rv = apei_read_register(reg, map, Mask, >y);
-		if (ACPI_FAILURE(rv))
-			break;
+		M->y = apei_read_register(reg, map, Mask);
 		break;
 	case ACPI_EINJ_READ_REGISTER_VALUE: {
 		uint64_t v;
 
-		rv = apei_read_register(reg, map, Mask, );
-		if (ACPI_FAILURE(rv))
-			break;
+		v = apei_read_register(reg, map, Mask);
 		M->y = (v == Value ? 1 : 0);
 		break;
 	}
 	case ACPI_EINJ_WRITE_REGISTER:
-		rv = apei_write_register(reg, map, Mask, preserve_register,
-		M->x);
+		apei_write_register(reg, map, Mask, preserve_register, M->x);
 		break;
 	case ACPI_EINJ_WRITE_REGISTER_VALUE:
-		rv = apei_write_register(reg, map, Mask, preserve_register,
-		Value);
+		apei_write_register(reg, map, Mask, preserve_register, Value);
 		break;
 	case ACPI_EINJ_NOOP:
 		break;
-	default:
-		rv = AE_ERROR;
+	default:		/* XXX unreachable */
 		break;
 	}
-
-	/*
-	 * If any register I/O failed, print the failure message.  This
-	 * could be more specific about exactly what failed, but that
-	 * takes a little more effort to write.
-	 */
-	if (ACPI_FAILURE(rv)) {
-		aprint_debug_dev(M->sc->sc_dev, "%s: failed: %s\n", __func__,
-		AcpiFormatException(rv));
-	}
 }
 
 /*

Index: src/sys/dev/acpi/apei_erst.c
diff -u src/sys/dev/acpi/apei_erst.c:1.2 src/sys/dev/acpi/apei_erst.c:1.3
--- src/sys/dev/acpi/apei_erst.c:1.2	Fri Mar 22 20:48:05 2024
+++ src/sys/dev/acpi/apei_erst.c	Fri Mar 22 20:48:14 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_erst.c,v 1.2 2024/03/22 20:48:05 riastradh Exp $	*/
+/*	$NetBSD: apei_erst.c,v 1.3 2024/03/22 20:48:14 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_erst.c,v 1.2 2024/03/22 20:48:05 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_erst.c,v 1.3 2024/03/22 20:48:14 riastradh Exp $");
 
 #include 
 #include 
@@ -376,7 +376,6 @@ apei_erst_instfunc(ACPI_WHEA_HEADER *hea
 void *cookie, uint32_t *ipp, uint32_t maxip)
 {
 	struct apei_erst_machine *const M = cookie;
-	ACPI_STATUS rv = AE_OK;
 
 	/*
 	 * Abbreviate some of the intermediate quantities to make the
@@ -411,35 +410,31 @@ apei_erst_instfunc(ACPI_WHEA_HEADER *hea
 	 */
 	switch (header->Instruction) {
 	case ACPI_ERST_READ_REGISTER:
-		rv = apei_read_register(reg, map, Mask, >y);
+		M->y = apei_read_register(reg, map, Mask);
 		break;
 	case ACPI_ERST_READ_REGISTER_VALUE: {
 		uint64_t v;
 
-		rv = apei_read_register(reg, map, Mask, );
-		if (ACPI_FAILURE(rv))
-			break;
+		v = apei_read_register(reg, map, Mask);
 		M->y = (v == Value ? 1 : 0);
 		break;
 	}
 	case ACPI_ERST_WRITE_REGISTER:
-		rv = apei_write_register(reg, map, Mask, preserve_register,
-		M->x);
+		apei_write_register(reg, map, Mask, preserve_register, M->x);
 		break;
 	case ACPI_ERST_WRITE_REGISTER_VALUE:
-		rv = apei_write_register(reg, map, Mask, preserve_register,
-		Value);
+		apei_write_register(reg, map, Mask, preserve_register, Value);
 		break;
 	case ACPI_ERST_NOOP:
 		break;
 	case ACPI_ERST_LOAD_VAR1:
-		rv = apei_read_register(reg, map, Mask, >var1);
+		M->var1 = apei_read_register(reg, map, Mask);
 		break;
 	case ACPI_ERST_LOAD_VAR2:
-		rv = apei_read_register(reg, map, Mask, >var2);
+		M->var2 = apei_read_register(reg, map, Mask);
 		break;
 	case ACPI_ERST_STORE_VAR1:
-		rv = apei_write_register(reg, 

CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 20:48:14 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c apei_erst.c apei_reg.c apei_reg.h

Log Message:
apei(4): Simplify EINJ/ERST register access now that it's pre-mapped.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/apei_einj.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei_erst.c \
src/sys/dev/acpi/apei_reg.c src/sys/dev/acpi/apei_reg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 20:48:05 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c apei_erst.c apei_interp.c apei_interp.h
apei_reg.c apei_reg.h

Log Message:
apei(4): Pre-map registers when compiling interpreter.

This way we don't have to worry about mapping them in nasty contexts
where access to uvm_km_alloc may not be allowed.  Paves the way to
use ERST for saving dmesg on crash.

Exception: ACPI_ERST_MOVE_DATA still needs to do AcpiOsMapMemory.
We'll need to reserve a couple pages to avoid that.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/apei_einj.c \
src/sys/dev/acpi/apei_interp.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_erst.c \
src/sys/dev/acpi/apei_interp.h src/sys/dev/acpi/apei_reg.c \
src/sys/dev/acpi/apei_reg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_einj.c
diff -u src/sys/dev/acpi/apei_einj.c:1.3 src/sys/dev/acpi/apei_einj.c:1.4
--- src/sys/dev/acpi/apei_einj.c:1.3	Thu Mar 21 02:35:09 2024
+++ src/sys/dev/acpi/apei_einj.c	Fri Mar 22 20:48:05 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_einj.c,v 1.3 2024/03/21 02:35:09 riastradh Exp $	*/
+/*	$NetBSD: apei_einj.c,v 1.4 2024/03/22 20:48:05 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.3 2024/03/21 02:35:09 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.4 2024/03/22 20:48:05 riastradh Exp $");
 
 #include 
 
@@ -55,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: apei_einj.c,
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -63,8 +64,8 @@ __KERNEL_RCSID(0, "$NetBSD: apei_einj.c,
 #define	_COMPONENT	ACPI_RESOURCE_COMPONENT
 ACPI_MODULE_NAME	("apei")
 
-static void apei_einj_instfunc(ACPI_WHEA_HEADER *, void *, uint32_t *,
-uint32_t);
+static void apei_einj_instfunc(ACPI_WHEA_HEADER *, struct apei_mapreg *,
+void *, uint32_t *, uint32_t);
 static uint64_t apei_einj_act(struct apei_softc *, enum AcpiEinjActions,
 uint64_t);
 static uint64_t apei_einj_trigger(struct apei_softc *, uint64_t);
@@ -111,6 +112,21 @@ static const char *const apei_einj_instr
 };
 
 /*
+ * apei_einj_instreg
+ *
+ *	Table of which isntructions use a register operand.
+ *
+ *	Must match apei_einj_instfunc.
+ */
+static const bool apei_einj_instreg[] = {
+	[ACPI_EINJ_READ_REGISTER] = true,
+	[ACPI_EINJ_READ_REGISTER_VALUE] = true,
+	[ACPI_EINJ_WRITE_REGISTER] = true,
+	[ACPI_EINJ_WRITE_REGISTER_VALUE] = true,
+	[ACPI_EINJ_NOOP] = false,
+};
+
+/*
  * apei_einj_attach(sc)
  *
  *	Scan the Error Injection table to ascertain what error
@@ -184,7 +200,7 @@ apei_einj_attach(struct apei_softc *sc)
 	jsc->jsc_interp = apei_interp_create("EINJ",
 	apei_einj_action, __arraycount(apei_einj_action),
 	apei_einj_instruction, __arraycount(apei_einj_instruction),
-	/*instvalid*/NULL, apei_einj_instfunc);
+	apei_einj_instreg, /*instvalid*/NULL, apei_einj_instfunc);
 
 	/*
 	 * Compile the interpreter from the EINJ action instruction
@@ -379,8 +395,8 @@ struct apei_einj_machine {
  *	too.
  */
 static void
-apei_einj_instfunc(ACPI_WHEA_HEADER *header, void *cookie, uint32_t *ipp,
-uint32_t maxip)
+apei_einj_instfunc(ACPI_WHEA_HEADER *header, struct apei_mapreg *map,
+void *cookie, uint32_t *ipp, uint32_t maxip)
 {
 	struct apei_einj_machine *M = cookie;
 	ACPI_STATUS rv = AE_OK;
@@ -418,24 +434,26 @@ apei_einj_instfunc(ACPI_WHEA_HEADER *hea
 	 */
 	switch (header->Instruction) {
 	case ACPI_EINJ_READ_REGISTER:
-		rv = apei_read_register(reg, Mask, >y);
+		rv = apei_read_register(reg, map, Mask, >y);
 		if (ACPI_FAILURE(rv))
 			break;
 		break;
 	case ACPI_EINJ_READ_REGISTER_VALUE: {
 		uint64_t v;
 
-		rv = apei_read_register(reg, Mask, );
+		rv = apei_read_register(reg, map, Mask, );
 		if (ACPI_FAILURE(rv))
 			break;
 		M->y = (v == Value ? 1 : 0);
 		break;
 	}
 	case ACPI_EINJ_WRITE_REGISTER:
-		rv = apei_write_register(reg, Mask, preserve_register, M->x);
+		rv = apei_write_register(reg, map, Mask, preserve_register,
+		M->x);
 		break;
 	case ACPI_EINJ_WRITE_REGISTER_VALUE:
-		rv = apei_write_register(reg, Mask, preserve_register, Value);
+		rv = apei_write_register(reg, map, Mask, preserve_register,
+		Value);
 		break;
 	case ACPI_EINJ_NOOP:
 		break;
@@ -621,14 +639,43 @@ apei_einj_trigger(struct apei_softc *sc,
 		}
 
 		/*
+		 * Verify the instruction.
+		 */
+		if (header->Instruction >= __arraycount(apei_einj_instreg)) {
+			device_printf(sc->sc_dev, "TRIGGER_ERROR action table:"
+			" unknown instruction: %"PRIu32"\n",
+			header->Instruction);
+			continue;
+		}
+
+		/*
+		 * Map the register if needed.
+		 */
+		struct apei_mapreg *map = NULL;
+		if (apei_einj_instreg[header->Instruction]) {
+			map = apei_mapreg_map(>RegisterRegion);

CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 20:48:05 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c apei_erst.c apei_interp.c apei_interp.h
apei_reg.c apei_reg.h

Log Message:
apei(4): Pre-map registers when compiling interpreter.

This way we don't have to worry about mapping them in nasty contexts
where access to uvm_km_alloc may not be allowed.  Paves the way to
use ERST for saving dmesg on crash.

Exception: ACPI_ERST_MOVE_DATA still needs to do AcpiOsMapMemory.
We'll need to reserve a couple pages to avoid that.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/apei_einj.c \
src/sys/dev/acpi/apei_interp.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_erst.c \
src/sys/dev/acpi/apei_interp.h src/sys/dev/acpi/apei_reg.c \
src/sys/dev/acpi/apei_reg.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 20:47:52 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_mapreg.c

Log Message:
apei(4): Allow pre-mapping I/O registers too.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/apei_mapreg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_mapreg.c
diff -u src/sys/dev/acpi/apei_mapreg.c:1.3 src/sys/dev/acpi/apei_mapreg.c:1.4
--- src/sys/dev/acpi/apei_mapreg.c:1.3	Fri Mar 22 20:47:31 2024
+++ src/sys/dev/acpi/apei_mapreg.c	Fri Mar 22 20:47:52 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_mapreg.c,v 1.3 2024/03/22 20:47:31 riastradh Exp $	*/
+/*	$NetBSD: apei_mapreg.c,v 1.4 2024/03/22 20:47:52 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_mapreg.c,v 1.3 2024/03/22 20:47:31 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_mapreg.c,v 1.4 2024/03/22 20:47:52 riastradh Exp $");
 
 #include 
 
@@ -73,7 +73,10 @@ apei_mapreg_map(const ACPI_GENERIC_ADDRE
 	case 1:			/* 8-bit */
 	case 2:			/* 16-bit */
 	case 3:			/* 32-bit */
+		break;
 	case 4:			/* 64-bit */
+		if (reg->SpaceId == ACPI_ADR_SPACE_SYSTEM_IO)
+			return NULL;
 		break;
 	default:
 		return NULL;
@@ -100,11 +103,14 @@ apei_mapreg_map(const ACPI_GENERIC_ADDRE
 
 	/*
 	 * Dispatch on the space id.
-	 *
-	 * Currently this only handles memory space because I/O space
-	 * is too painful to contemplate reimplementing here.
 	 */
 	switch (reg->SpaceId) {
+	case ACPI_ADR_SPACE_SYSTEM_IO:
+		/*
+		 * Just need to return something non-null -- no state
+		 * to record for a mapping.
+		 */
+		return (struct apei_mapreg *)__UNCONST(reg);
 	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
 		return AcpiOsMapMemory(reg->Address,
 		1 << (reg->AccessWidth - 1));
@@ -123,7 +129,16 @@ apei_mapreg_unmap(const ACPI_GENERIC_ADD
 struct apei_mapreg *map)
 {
 
-	AcpiOsUnmapMemory(map, 1 << (reg->AccessWidth - 1));
+	switch (reg->SpaceId) {
+	case ACPI_ADR_SPACE_SYSTEM_IO:
+		KASSERT(map == __UNCONST(reg));
+		break;
+	case ACPI_ADR_SPACE_SYSTEM_MEMORY:
+		AcpiOsUnmapMemory(map, 1 << (reg->AccessWidth - 1));
+		break;
+	default:
+		panic("invalid register mapping");
+	}
 }
 
 /*
@@ -142,18 +157,50 @@ apei_mapreg_read(const ACPI_GENERIC_ADDR
 	for (i = 0; i < n; i++) {
 		uint64_t chunk;
 
-		switch (reg->AccessWidth) {
-		case 1:
-			chunk = *((volatile const uint8_t *)map + i);
+		switch (reg->SpaceId) {
+		case ACPI_ADR_SPACE_SYSTEM_IO: {
+			ACPI_IO_ADDRESS addr;
+			uint32_t chunk32 = 0;
+			ACPI_STATUS rv;
+
+			switch (reg->AccessWidth) {
+			case 1:
+addr = reg->Address + i;
+break;
+			case 2:
+addr = reg->Address + 2*i;
+break;
+			case 3:
+addr = reg->Address + 4*i;
+break;
+			case 4:	/* no 64-bit I/O ports */
+			default:
+__unreachable();
+			}
+			rv = AcpiOsReadPort(addr, ,
+			NBBY*(1 << (reg->AccessWidth - 1)));
+			KASSERTMSG(!ACPI_FAILURE(rv), "%s",
+			AcpiFormatException(rv));
+			chunk = chunk32;
 			break;
-		case 2:
-			chunk = *((volatile const uint16_t *)map + i);
-			break;
-		case 3:
-			chunk = *((volatile const uint32_t *)map + i);
-			break;
-		case 4:
-			chunk = *((volatile const uint64_t *)map + i);
+		}
+		case ACPI_ADR_SPACE_SYSTEM_MEMORY:
+			switch (reg->AccessWidth) {
+			case 1:
+chunk = *((volatile const uint8_t *)map + i);
+break;
+			case 2:
+chunk = *((volatile const uint16_t *)map + i);
+break;
+			case 3:
+chunk = *((volatile const uint32_t *)map + i);
+break;
+			case 4:
+chunk = *((volatile const uint64_t *)map + i);
+break;
+			default:
+__unreachable();
+			}
 			break;
 		default:
 			__unreachable();
@@ -181,18 +228,48 @@ apei_mapreg_write(const ACPI_GENERIC_ADD
 	for (i = 0; i < n; i++) {
 		uint64_t chunk = v >> (i*chunkbits);
 
-		switch (reg->AccessWidth) {
-		case 1:
-			*((volatile uint8_t *)map + i) = chunk;
+		switch (reg->SpaceId) {
+		case ACPI_ADR_SPACE_SYSTEM_IO: {
+			ACPI_IO_ADDRESS addr;
+			ACPI_STATUS rv;
+
+			switch (reg->AccessWidth) {
+			case 1:
+addr = reg->Address + i;
+break;
+			case 2:
+addr = reg->Address + 2*i;
+break;
+			case 3:
+addr = reg->Address + 4*i;
+break;
+			case 4:	/* no 64-bit I/O ports */
+			default:
+__unreachable();
+			}
+			rv = AcpiOsWritePort(addr, chunk,
+			NBBY*(1 << (reg->AccessWidth - 1)));
+			KASSERTMSG(!ACPI_FAILURE(rv), "%s",
+			AcpiFormatException(rv));
 			break;
-		case 2:
-			*((volatile uint16_t *)map + i) = chunk;
-			break;
-		case 3:
-			*((volatile uint32_t *)map + i) = chunk;
-			break;
-		case 4:
-			*((volatile uint64_t *)map + i) = chunk;
+		}
+		case ACPI_ADR_SPACE_SYSTEM_MEMORY:
+			switch (reg->AccessWidth) {
+			case 1:
+*((volatile uint8_t *)map + i) = chunk;
+break;
+			case 2:
+*((volatile uint16_t 

CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 20:47:52 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_mapreg.c

Log Message:
apei(4): Allow pre-mapping I/O registers too.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/apei_mapreg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 20:47:31 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_mapreg.c

Log Message:
apei(4): Fix register chunk counting.

Now it will actually read and write the registers!

Have been updating and reloading the wrong module to test this, oops.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei_mapreg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 20:47:31 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_mapreg.c

Log Message:
apei(4): Fix register chunk counting.

Now it will actually read and write the registers!

Have been updating and reloading the wrong module to test this, oops.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei_mapreg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_mapreg.c
diff -u src/sys/dev/acpi/apei_mapreg.c:1.2 src/sys/dev/acpi/apei_mapreg.c:1.3
--- src/sys/dev/acpi/apei_mapreg.c:1.2	Fri Mar 22 18:19:14 2024
+++ src/sys/dev/acpi/apei_mapreg.c	Fri Mar 22 20:47:31 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_mapreg.c,v 1.2 2024/03/22 18:19:14 riastradh Exp $	*/
+/*	$NetBSD: apei_mapreg.c,v 1.3 2024/03/22 20:47:31 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_mapreg.c,v 1.2 2024/03/22 18:19:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_mapreg.c,v 1.3 2024/03/22 20:47:31 riastradh Exp $");
 
 #include 
 
@@ -136,7 +136,7 @@ apei_mapreg_read(const ACPI_GENERIC_ADDR
 const struct apei_mapreg *map)
 {
 	unsigned chunkbits = NBBY*(1 << (reg->AccessWidth - 1));
-	unsigned i, n = reg->BitWidth % chunkbits;
+	unsigned i, n = reg->BitWidth / chunkbits;
 	uint64_t v = 0;
 
 	for (i = 0; i < n; i++) {
@@ -175,7 +175,7 @@ apei_mapreg_write(const ACPI_GENERIC_ADD
 uint64_t v)
 {
 	unsigned chunkbits = NBBY*(1 << (reg->AccessWidth - 1));
-	unsigned i, n = reg->BitWidth % chunkbits;
+	unsigned i, n = reg->BitWidth / chunkbits;
 
 	membar_release();	/* XXX probably not right for MMIO */
 	for (i = 0; i < n; i++) {



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 18:19:14 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_mapreg.c

Log Message:
apei(4): Fix indexing of multi-unit register access.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_mapreg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 18:19:14 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_mapreg.c

Log Message:
apei(4): Fix indexing of multi-unit register access.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_mapreg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_mapreg.c
diff -u src/sys/dev/acpi/apei_mapreg.c:1.1 src/sys/dev/acpi/apei_mapreg.c:1.2
--- src/sys/dev/acpi/apei_mapreg.c:1.1	Wed Mar 20 17:11:44 2024
+++ src/sys/dev/acpi/apei_mapreg.c	Fri Mar 22 18:19:14 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_mapreg.c,v 1.1 2024/03/20 17:11:44 riastradh Exp $	*/
+/*	$NetBSD: apei_mapreg.c,v 1.2 2024/03/22 18:19:14 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_mapreg.c,v 1.1 2024/03/20 17:11:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_mapreg.c,v 1.2 2024/03/22 18:19:14 riastradh Exp $");
 
 #include 
 
@@ -144,16 +144,16 @@ apei_mapreg_read(const ACPI_GENERIC_ADDR
 
 		switch (reg->AccessWidth) {
 		case 1:
-			chunk = *(volatile const uint8_t *)map;
+			chunk = *((volatile const uint8_t *)map + i);
 			break;
 		case 2:
-			chunk = *(volatile const uint16_t *)map;
+			chunk = *((volatile const uint16_t *)map + i);
 			break;
 		case 3:
-			chunk = *(volatile const uint32_t *)map;
+			chunk = *((volatile const uint32_t *)map + i);
 			break;
 		case 4:
-			chunk = *(volatile const uint64_t *)map;
+			chunk = *((volatile const uint64_t *)map + i);
 			break;
 		default:
 			__unreachable();
@@ -183,16 +183,16 @@ apei_mapreg_write(const ACPI_GENERIC_ADD
 
 		switch (reg->AccessWidth) {
 		case 1:
-			*(volatile uint8_t *)map = chunk;
+			*((volatile uint8_t *)map + i) = chunk;
 			break;
 		case 2:
-			*(volatile uint16_t *)map = chunk;
+			*((volatile uint16_t *)map + i) = chunk;
 			break;
 		case 3:
-			*(volatile uint32_t *)map = chunk;
+			*((volatile uint32_t *)map + i) = chunk;
 			break;
 		case 4:
-			*(volatile uint64_t *)map = chunk;
+			*((volatile uint64_t *)map + i) = chunk;
 			break;
 		default:
 			__unreachable();



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 18:19:03 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_interp.c

Log Message:
apei(4): Plug memory leak on teardown of instruction interpreter.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei_interp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_interp.c
diff -u src/sys/dev/acpi/apei_interp.c:1.2 src/sys/dev/acpi/apei_interp.c:1.3
--- src/sys/dev/acpi/apei_interp.c:1.2	Wed Mar 20 19:21:04 2024
+++ src/sys/dev/acpi/apei_interp.c	Fri Mar 22 18:19:03 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_interp.c,v 1.2 2024/03/20 19:21:04 riastradh Exp $	*/
+/*	$NetBSD: apei_interp.c,v 1.3 2024/03/22 18:19:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -107,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_interp.c,v 1.2 2024/03/20 19:21:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_interp.c,v 1.3 2024/03/22 18:19:03 riastradh Exp $");
 
 #include 
 
@@ -170,7 +170,16 @@ apei_interp_create(const char *name,
 void
 apei_interp_destroy(struct apei_interp *I)
 {
-	unsigned nact = I->nact;
+	unsigned action, nact = I->nact;
+
+	for (action = 0; action < nact; action++) {
+		struct apei_actinst *const A = >actinst[action];
+
+		if (A->ninst == 0 || A->ninst == UINT32_MAX || A->inst == NULL)
+			continue;
+		kmem_free(A->inst, A->ninst * sizeof(A->inst[0]));
+		A->inst = NULL;
+	}
 
 	kmem_free(I, offsetof(struct apei_interp, actinst[nact]));
 }



CVS commit: src/sys/dev/acpi

2024-03-22 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Mar 22 18:19:03 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_interp.c

Log Message:
apei(4): Plug memory leak on teardown of instruction interpreter.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei_interp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Mar 21 02:35:09 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c apei_hest.c

Log Message:
apei(4): Note some TODOs for EINJ and HEST.

No functional change intended, comments only.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei_einj.c \
src/sys/dev/acpi/apei_hest.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Mar 21 02:35:09 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c apei_hest.c

Log Message:
apei(4): Note some TODOs for EINJ and HEST.

No functional change intended, comments only.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/apei_einj.c \
src/sys/dev/acpi/apei_hest.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_einj.c
diff -u src/sys/dev/acpi/apei_einj.c:1.2 src/sys/dev/acpi/apei_einj.c:1.3
--- src/sys/dev/acpi/apei_einj.c:1.2	Thu Mar 21 02:34:59 2024
+++ src/sys/dev/acpi/apei_einj.c	Thu Mar 21 02:35:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_einj.c,v 1.2 2024/03/21 02:34:59 riastradh Exp $	*/
+/*	$NetBSD: apei_einj.c,v 1.3 2024/03/21 02:35:09 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -38,10 +38,13 @@
  * some nontrivial userland support; maybe relying on the user to tread
  * carefully with error injection is fine -- after all, many types of
  * error injection will cause a system halt/panic.
+ *
+ * XXX Properly expose SET_ERROR_TYPE_WITH_ADDRESS, which has a more
+ * complicated relationship with its RegisterRegion field.
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.2 2024/03/21 02:34:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.3 2024/03/21 02:35:09 riastradh Exp $");
 
 #include 
 
Index: src/sys/dev/acpi/apei_hest.c
diff -u src/sys/dev/acpi/apei_hest.c:1.2 src/sys/dev/acpi/apei_hest.c:1.3
--- src/sys/dev/acpi/apei_hest.c:1.2	Wed Mar 20 18:47:59 2024
+++ src/sys/dev/acpi/apei_hest.c	Thu Mar 21 02:35:09 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_hest.c,v 1.2 2024/03/20 18:47:59 riastradh Exp $	*/
+/*	$NetBSD: apei_hest.c,v 1.3 2024/03/21 02:35:09 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -43,10 +43,16 @@
  *
  * XXX sort out interrupt notification types, e.g. do we ever need to
  * do acpi_intr_establish?
+ *
+ * XXX sysctl knob to force polling each particular error source that
+ * supports it
+ *
+ * XXX consider a lighter-weight polling schedule for machines with
+ * thousands of polled GHESes
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_hest.c,v 1.2 2024/03/20 18:47:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_hest.c,v 1.3 2024/03/21 02:35:09 riastradh Exp $");
 
 #include 
 



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Mar 21 02:35:00 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c

Log Message:
apei(4): Fix parsing checks for TRIGGER_ERROR action table.

The TableSize is size of the header plus the body, not just the body.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_einj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_einj.c
diff -u src/sys/dev/acpi/apei_einj.c:1.1 src/sys/dev/acpi/apei_einj.c:1.2
--- src/sys/dev/acpi/apei_einj.c:1.1	Wed Mar 20 17:11:43 2024
+++ src/sys/dev/acpi/apei_einj.c	Thu Mar 21 02:34:59 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_einj.c,v 1.1 2024/03/20 17:11:43 riastradh Exp $	*/
+/*	$NetBSD: apei_einj.c,v 1.2 2024/03/21 02:34:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.1 2024/03/20 17:11:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_einj.c,v 1.2 2024/03/21 02:34:59 riastradh Exp $");
 
 #include 
 
@@ -507,7 +507,7 @@ apei_einj_trigger(struct apei_softc *sc,
 {
 	uint64_t teatab_pa;
 	ACPI_EINJ_TRIGGER *teatab = NULL;
-	size_t mapsize = 0, tabsize;
+	size_t mapsize = 0, tabsize, bodysize;
 	ACPI_EINJ_ENTRY *entry;
 	struct apei_einj_machine einj_machine, *const M = _machine;
 	uint32_t i, nentries;
@@ -561,16 +561,20 @@ apei_einj_trigger(struct apei_softc *sc,
 	 * table is short.
 	 */
 	tabsize = teatab->TableSize;
-	if (nentries < howmany(tabsize, sizeof(ACPI_EINJ_ENTRY))) {
+	bodysize = tabsize - teatab->HeaderSize;
+	if (nentries < howmany(bodysize, sizeof(ACPI_EINJ_ENTRY))) {
 		device_printf(sc->sc_dev, "TRIGGER_ERROR action table:"
 		" %zu bytes of trailing garbage\n",
 		tabsize - nentries*sizeof(ACPI_EINJ_ENTRY));
-		tabsize = nentries*sizeof(ACPI_EINJ_ENTRY);
-	} else if (nentries > howmany(tabsize, sizeof(ACPI_EINJ_ENTRY))) {
+		bodysize = nentries*sizeof(ACPI_EINJ_ENTRY);
+		tabsize = teatab->HeaderSize + bodysize;
+	} else if (nentries > howmany(bodysize, sizeof(ACPI_EINJ_ENTRY))) {
 		device_printf(sc->sc_dev, "TRIGGER_ERROR action table:"
 		" truncated to %zu entries\n",
 		nentries*sizeof(ACPI_EINJ_ENTRY));
-		nentries = howmany(tabsize, sizeof(ACPI_EINJ_ENTRY));
+		nentries = howmany(bodysize, sizeof(ACPI_EINJ_ENTRY));
+		bodysize = nentries*sizeof(ACPI_EINJ_ENTRY);
+		tabsize = teatab->HeaderSize + bodysize;
 	}
 
 	/*
@@ -596,7 +600,7 @@ apei_einj_trigger(struct apei_softc *sc,
 	 *
 	 * Entries are fixed-size, so we can just index them.
 	 */
-	entry = (ACPI_EINJ_ENTRY *)(teatab + 1);
+	entry = (ACPI_EINJ_ENTRY *)((char *)teatab + teatab->HeaderSize);
 	for (i = 0; i < nentries; i++) {
 		ACPI_WHEA_HEADER *const header = [i].WheaHeader;
 



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Mar 21 02:35:00 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_einj.c

Log Message:
apei(4): Fix parsing checks for TRIGGER_ERROR action table.

The TableSize is size of the header plus the body, not just the body.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_einj.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 20 19:21:05 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_interp.c

Log Message:
apei(4): Tweak some comments about the APEI interpreter language.

No functional change intended.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_interp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_interp.c
diff -u src/sys/dev/acpi/apei_interp.c:1.1 src/sys/dev/acpi/apei_interp.c:1.2
--- src/sys/dev/acpi/apei_interp.c:1.1	Wed Mar 20 17:11:43 2024
+++ src/sys/dev/acpi/apei_interp.c	Wed Mar 20 19:21:04 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_interp.c,v 1.1 2024/03/20 17:11:43 riastradh Exp $	*/
+/*	$NetBSD: apei_interp.c,v 1.2 2024/03/20 19:21:04 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -49,11 +49,13 @@
  *	+---+
  *	| Action=SET_ERROR_TYPE|
  *	| Instruction=SKIP_NEXT_INSTRUCTION_IF_TRUE	|
+ *	| Register=0x7fabcd10 [memory]			|
  *	| Value=0xdeadbeef|
  *	+---+
  *	| Action=SET_ERROR_TYPE|
  *	| Instruction=WRITE_REGISTER_VALUE		|
  *	| Register=0x7fabcd14 [memory]			|
+ *	| Value=1	|
  *	+---+
  *	| Action=SET_ERROR_TYPE|
  *	| Instruction=READ_REGISTER			|
@@ -90,9 +92,9 @@
  *
  * This APEI interpreter first compiles the table into a contiguous
  * sequence of instructions for each action, to make execution easier,
- * since there's no requirement that the actions be in order, and the
- * GOTO instruction relies on contiguous indexing of the instructions
- * for an action.
+ * since there's no requirement that the instructions for an action be
+ * contiguous in the table, and the GOTO instruction relies on
+ * contiguous indexing of the instructions for an action.
  *
  * This interpreter also does a little validation so the firmware
  * doesn't, e.g., GOTO somewhere in oblivion.  The validation is mainly
@@ -105,7 +107,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_interp.c,v 1.1 2024/03/20 17:11:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_interp.c,v 1.2 2024/03/20 19:21:04 riastradh Exp $");
 
 #include 
 



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 20 19:21:05 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_interp.c

Log Message:
apei(4): Tweak some comments about the APEI interpreter language.

No functional change intended.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_interp.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 20 18:47:59 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_hest.c

Log Message:
apei(4): Pacify -Wsign-compare.

Assert that the parsing made forward progress too while here.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_hest.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 20 18:47:59 UTC 2024

Modified Files:
src/sys/dev/acpi: apei_hest.c

Log Message:
apei(4): Pacify -Wsign-compare.

Assert that the parsing made forward progress too while here.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/apei_hest.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/apei_hest.c
diff -u src/sys/dev/acpi/apei_hest.c:1.1 src/sys/dev/acpi/apei_hest.c:1.2
--- src/sys/dev/acpi/apei_hest.c:1.1	Wed Mar 20 17:11:43 2024
+++ src/sys/dev/acpi/apei_hest.c	Wed Mar 20 18:47:59 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: apei_hest.c,v 1.1 2024/03/20 17:11:43 riastradh Exp $	*/
+/*	$NetBSD: apei_hest.c,v 1.2 2024/03/20 18:47:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2024 The NetBSD Foundation, Inc.
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: apei_hest.c,v 1.1 2024/03/20 17:11:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: apei_hest.c,v 1.2 2024/03/20 18:47:59 riastradh Exp $");
 
 #include 
 
@@ -917,7 +917,9 @@ apei_hest_attach(struct apei_softc *sc)
 			" %"PRIu32"\n", i);
 			break;
 		}
-		KASSERT((const char *)next - (const char *)header <= resid);
+		KASSERT(header < next);
+		KASSERT((size_t)((const char *)next - (const char *)header) <=
+		resid);
 		resid -= (const char *)next - (const char *)header;
 	}
 	if (resid) {



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 20 12:43:13 UTC 2024

Modified Files:
src/sys/dev/acpi: files.acpi

Log Message:
acpi(4): Make apeibus actually work as an iattr.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/dev/acpi/files.acpi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/files.acpi
diff -u src/sys/dev/acpi/files.acpi:1.129 src/sys/dev/acpi/files.acpi:1.130
--- src/sys/dev/acpi/files.acpi:1.129	Wed Mar 20 03:14:45 2024
+++ src/sys/dev/acpi/files.acpi	Wed Mar 20 12:43:13 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.129 2024/03/20 03:14:45 riastradh Exp $
+#	$NetBSD: files.acpi,v 1.130 2024/03/20 12:43:13 riastradh Exp $
 
 defflag	opt_acpi.h	ACPIVERBOSE ACPI_DEBUG ACPI_ACTIVATE_DEV
 			ACPI_DSDT_OVERRIDE ACPI_SCANPCI ACPI_BREAKPOINT
@@ -16,7 +16,7 @@ define	acpigtdtbus { }
 define	acpimadtbus { }
 define	apeibus { }
 
-device	acpi: acpica, acpiapmbus, acpinodebus, acpiecdtbus, acpisdtbus, acpigtdtbus, acpimadtbus, acpihpetbus, acpiwdrtbus, sysmon_power, sysmon_taskq
+device	acpi: acpica, acpiapmbus, acpinodebus, acpiecdtbus, acpisdtbus, acpigtdtbus, acpimadtbus, acpihpetbus, acpiwdrtbus, apeibus, sysmon_power, sysmon_taskq
 attach	acpi at acpibus
 file	dev/acpi/acpi.c			acpi
 file	dev/acpi/acpi_debug.c		acpi



CVS commit: src/sys/dev/acpi

2024-03-20 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 20 12:43:13 UTC 2024

Modified Files:
src/sys/dev/acpi: files.acpi

Log Message:
acpi(4): Make apeibus actually work as an iattr.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.129 -r1.130 src/sys/dev/acpi/files.acpi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 20 03:14:45 UTC 2024

Modified Files:
src/sys/dev/acpi: acpi.c acpivar.h files.acpi

Log Message:
acpi(4): New iattr `apeibus' for attaching an APEI driver.

APEI is the ACPI Platform Error Interface, a standard (if very
complicated) interface for reporting hardware errors to the OS.

Firmware support for APEI is presented through the ACPI tables BERT
(Boot Error Record Table), ERST (Error Record Serialization Table),
EINJ (Error Injection Table), and HEST (Hardware Error Source Table),
rather than through nodes in the ACPI device tree, so it can't just
attach through the existing acpinodebus iattr and instead requires a
special pseudo-bus like acpiwdrt(4).

No driver yet -- this is just the hook to attach one in a module.

The new member sc_apei of struct acpi_softc is placed at the end of
the structure so that this change can be safely pulled up to release
branches without risk to ABI compatibility in existing modules such
as acpiverbose.kmod which may rely on the layout (but not size) of
struct acpi_softc.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.298 -r1.299 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/acpi/acpivar.h
cvs rdiff -u -r1.128 -r1.129 src/sys/dev/acpi/files.acpi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-03-19 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed Mar 20 03:14:45 UTC 2024

Modified Files:
src/sys/dev/acpi: acpi.c acpivar.h files.acpi

Log Message:
acpi(4): New iattr `apeibus' for attaching an APEI driver.

APEI is the ACPI Platform Error Interface, a standard (if very
complicated) interface for reporting hardware errors to the OS.

Firmware support for APEI is presented through the ACPI tables BERT
(Boot Error Record Table), ERST (Error Record Serialization Table),
EINJ (Error Injection Table), and HEST (Hardware Error Source Table),
rather than through nodes in the ACPI device tree, so it can't just
attach through the existing acpinodebus iattr and instead requires a
special pseudo-bus like acpiwdrt(4).

No driver yet -- this is just the hook to attach one in a module.

The new member sc_apei of struct acpi_softc is placed at the end of
the structure so that this change can be safely pulled up to release
branches without risk to ABI compatibility in existing modules such
as acpiverbose.kmod which may rely on the layout (but not size) of
struct acpi_softc.

PR kern/58046


To generate a diff of this commit:
cvs rdiff -u -r1.298 -r1.299 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/acpi/acpivar.h
cvs rdiff -u -r1.128 -r1.129 src/sys/dev/acpi/files.acpi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.298 src/sys/dev/acpi/acpi.c:1.299
--- src/sys/dev/acpi/acpi.c:1.298	Tue May 31 20:28:57 2022
+++ src/sys/dev/acpi/acpi.c	Wed Mar 20 03:14:45 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.298 2022/05/31 20:28:57 mrg Exp $	*/
+/*	$NetBSD: acpi.c,v 1.299 2024/03/20 03:14:45 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.298 2022/05/31 20:28:57 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.299 2024/03/20 03:14:45 riastradh Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -636,6 +636,9 @@ acpi_childdet(device_t self, device_t ch
 	if (sc->sc_wdrt == child)
 		sc->sc_wdrt = NULL;
 
+	if (sc->sc_apei == child)
+		sc->sc_apei = NULL;
+
 	SIMPLEQ_FOREACH(ad, >sc_head, ad_list) {
 
 		if (ad->ad_device == child)
@@ -923,6 +926,11 @@ acpi_rescan(device_t self, const char *i
 	   CFARGS(.iattr = "acpiwdrtbus"));
 	}
 
+	if (ifattr_match(ifattr, "apeibus") && sc->sc_apei == NULL) {
+		sc->sc_apei = config_found(sc->sc_dev, NULL, NULL,
+	   CFARGS(.iattr = "apeibus"));
+	}
+
 	return 0;
 }
 

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.89 src/sys/dev/acpi/acpivar.h:1.90
--- src/sys/dev/acpi/acpivar.h:1.89	Sun Dec 26 14:34:39 2021
+++ src/sys/dev/acpi/acpivar.h	Wed Mar 20 03:14:45 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.89 2021/12/26 14:34:39 jmcneill Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.90 2024/03/20 03:14:45 riastradh Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -177,6 +177,13 @@ struct acpi_softc {
 	struct sysmon_pswitch	 sc_smpsw_sleep;
 
 	SIMPLEQ_HEAD(, acpi_devnode)	sc_head;
+
+	/*
+	 * Move this section to the other pseudo-bus child pointers
+	 * after pullup -- putting it here avoids potential ABI
+	 * compatibility issues with kernel modules.
+	 */
+	device_t		 sc_apei;	/* apei(4) pseudo-bus */
 };
 
 /*

Index: src/sys/dev/acpi/files.acpi
diff -u src/sys/dev/acpi/files.acpi:1.128 src/sys/dev/acpi/files.acpi:1.129
--- src/sys/dev/acpi/files.acpi:1.128	Tue Jul 18 10:02:25 2023
+++ src/sys/dev/acpi/files.acpi	Wed Mar 20 03:14:45 2024
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.128 2023/07/18 10:02:25 riastradh Exp $
+#	$NetBSD: files.acpi,v 1.129 2024/03/20 03:14:45 riastradh Exp $
 
 defflag	opt_acpi.h	ACPIVERBOSE ACPI_DEBUG ACPI_ACTIVATE_DEV
 			ACPI_DSDT_OVERRIDE ACPI_SCANPCI ACPI_BREAKPOINT
@@ -14,6 +14,7 @@ define	acpiwdrtbus { }
 define	acpisdtbus { }
 define	acpigtdtbus { }
 define	acpimadtbus { }
+define	apeibus { }
 
 device	acpi: acpica, acpiapmbus, acpinodebus, acpiecdtbus, acpisdtbus, acpigtdtbus, acpimadtbus, acpihpetbus, acpiwdrtbus, sysmon_power, sysmon_taskq
 attach	acpi at acpibus



CVS commit: src/sys/dev/acpi

2024-02-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb  9 16:53:15 UTC 2024

Modified Files:
src/sys/dev/acpi: dwcmmc_acpi.c

Log Message:
Trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/dwcmmc_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/dwcmmc_acpi.c
diff -u src/sys/dev/acpi/dwcmmc_acpi.c:1.2 src/sys/dev/acpi/dwcmmc_acpi.c:1.3
--- src/sys/dev/acpi/dwcmmc_acpi.c:1.2	Sun Feb  6 15:48:12 2022
+++ src/sys/dev/acpi/dwcmmc_acpi.c	Fri Feb  9 16:53:15 2024
@@ -1,4 +1,4 @@
-/* $NetBSD: dwcmmc_acpi.c,v 1.2 2022/02/06 15:48:12 jmcneill Exp $ */
+/* $NetBSD: dwcmmc_acpi.c,v 1.3 2024/02/09 16:53:15 skrll Exp $ */
 
 /*-
  * Copyright (c) 2022 Jared McNeill 
@@ -27,16 +27,16 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwcmmc_acpi.c,v 1.2 2022/02/06 15:48:12 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwcmmc_acpi.c,v 1.3 2024/02/09 16:53:15 skrll Exp $");
 
 #include 
 #include 
 #include 
 #include 
 
-#include  
-#include  
-#include 
+#include 
+#include 
+#include 
 
 #include 
 #include 



CVS commit: src/sys/dev/acpi

2024-02-09 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Fri Feb  9 16:53:15 UTC 2024

Modified Files:
src/sys/dev/acpi: dwcmmc_acpi.c

Log Message:
Trailing whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/dwcmmc_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2024-02-08 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Feb  8 10:05:01 UTC 2024

Modified Files:
src/sys/dev/acpi: acpidevs_data.h

Log Message:
Regen with typo fixed.

Regeneration script doesn't seem to react to description changes only, thus
regenerated it twice by changing device name locally and putting it back
to original value.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/acpi/acpidevs_data.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpidevs_data.h
diff -u src/sys/dev/acpi/acpidevs_data.h:1.26 src/sys/dev/acpi/acpidevs_data.h:1.27
--- src/sys/dev/acpi/acpidevs_data.h:1.26	Wed Jun 22 19:26:36 2011
+++ src/sys/dev/acpi/acpidevs_data.h	Thu Feb  8 10:05:01 2024
@@ -1,10 +1,10 @@
-/*	$NetBSD: acpidevs_data.h,v 1.26 2011/06/22 19:26:36 jruoho Exp $	*/
+/*	$NetBSD: acpidevs_data.h,v 1.27 2024/02/08 10:05:01 andvar Exp $	*/
 
 /*
  * THIS FILE AUTOMATICALLY GENERATED.  DO NOT EDIT.
  *
  * generated from:
- *	# NetBSD: acpidevs,v 1.35 2011/06/22 19:26:22 jruoho Exp
+ *	# NetBSD: acpidevs,v 1.36 2019/05/28 08:59:34 msaitoh Exp
  */
 
 const struct { const char *pnp, *str; } acpi_knowndevs[] = {
@@ -1434,7 +1434,7 @@ const struct { const char *pnp, *str; } 
 	},
 	{
 	"ENE0100",
-	"KB3924-based CIR Port Reciever",
+	"KB3924-based CIR Port Receiver",
 	},
 	{
 	"HPQ0004",



CVS commit: src/sys/dev/acpi

2024-02-08 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Thu Feb  8 10:05:01 UTC 2024

Modified Files:
src/sys/dev/acpi: acpidevs_data.h

Log Message:
Regen with typo fixed.

Regeneration script doesn't seem to react to description changes only, thus
regenerated it twice by changing device name locally and putting it back
to original value.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/acpi/acpidevs_data.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi/wmi

2023-08-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 11 08:36:59 UTC 2023

Modified Files:
src/sys/dev/acpi/wmi: wmi_acpi.c

Log Message:
acpiwmi(4): Fix abuse of char buffer for struct guid_t content.

Nothing guarantees alignment, so this is all undefined behaviour,
even if we don't touch the uninitialized members.

XXX pullup-10
XXX pullup-9
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/acpi/wmi/wmi_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/wmi/wmi_acpi.c
diff -u src/sys/dev/acpi/wmi/wmi_acpi.c:1.22 src/sys/dev/acpi/wmi/wmi_acpi.c:1.23
--- src/sys/dev/acpi/wmi/wmi_acpi.c:1.22	Thu Aug 10 20:49:19 2023
+++ src/sys/dev/acpi/wmi/wmi_acpi.c	Fri Aug 11 08:36:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: wmi_acpi.c,v 1.22 2023/08/10 20:49:19 mrg Exp $	*/
+/*	$NetBSD: wmi_acpi.c,v 1.23 2023/08/11 08:36:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Jukka Ruohonen 
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.22 2023/08/10 20:49:19 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.23 2023/08/11 08:36:59 riastradh Exp $");
 
 #include 
 #include 
@@ -320,8 +320,8 @@ acpi_wmi_guid_get(struct acpi_wmi_softc 
 const char *src, struct wmi_t **out)
 {
 	struct wmi_t *wmi;
-	struct guid_t *guid;
-	char bin[MAX(16, sizeof(*guid))];
+	struct guid_t guid;
+	char bin[16];
 	char hex[3];
 	const char *ptr;
 	uint8_t i;
@@ -346,14 +346,14 @@ acpi_wmi_guid_get(struct acpi_wmi_softc 
 		ptr++;
 	}
 
-	guid = (struct guid_t *)bin;
-	guid->data1 = be32toh(guid->data1);
-	guid->data2 = be16toh(guid->data2);
-	guid->data3 = be16toh(guid->data3);
+	guid.data1 = be32dec([0]);
+	guid.data2 = be16dec([4]);
+	guid.data3 = be16dec([6]);
+	memcpy(guid.data4, [8], 8);
 
 	SIMPLEQ_FOREACH(wmi, >wmi_head, wmi_link) {
 
-		if (GUIDCMP(guid, >guid) != 0) {
+		if (GUIDCMP(, >guid) != 0) {
 
 			if (out != NULL)
 *out = wmi;



CVS commit: src/sys/dev/acpi/wmi

2023-08-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 11 08:36:59 UTC 2023

Modified Files:
src/sys/dev/acpi/wmi: wmi_acpi.c

Log Message:
acpiwmi(4): Fix abuse of char buffer for struct guid_t content.

Nothing guarantees alignment, so this is all undefined behaviour,
even if we don't touch the uninitialized members.

XXX pullup-10
XXX pullup-9
XXX pullup-8


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/acpi/wmi/wmi_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:17:12 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): One more debug message about read/write polling timeout.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.107 src/sys/dev/acpi/acpi_ec.c:1.108
--- src/sys/dev/acpi/acpi_ec.c:1.107	Tue Jul 18 10:17:02 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:17:12 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.107 2023/07/18 10:17:02 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.108 2023/07/18 10:17:12 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.107 2023/07/18 10:17:02 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.108 2023/07/18 10:17:12 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -688,6 +688,7 @@ acpiec_wait_timeout(struct acpiec_softc 
 		delay(1);
 	}
 
+	DPRINTF(ACPIEC_DEBUG_RW, sc, "SCI polling timeout\n");
 	if (cold || acpiec_cold) {
 		int timeo = 1000 * EC_CMD_TIMEOUT;
 



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:17:12 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): One more debug message about read/write polling timeout.


To generate a diff of this commit:
cvs rdiff -u -r1.107 -r1.108 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:17:02 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Take a lock around acpiec_cold updates.

Otherwise we race with readers -- probably harmlessly, but let's
avoid the appearance of problems.

XXX Maybe acpiec_suspend and acpiec_shutdown should interrupt
transactions and force them to fail promptly?

XXX This looks bad because acpiec_cold is global and sc->sc_mtx
doesn't look like it's global, but we expect to have only one
acpiec(4) device anyway from what I understand.  Maybe we should move
acpiec_cold into the softc?


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:17:02 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Take a lock around acpiec_cold updates.

Otherwise we race with readers -- probably harmlessly, but let's
avoid the appearance of problems.

XXX Maybe acpiec_suspend and acpiec_shutdown should interrupt
transactions and force them to fail promptly?

XXX This looks bad because acpiec_cold is global and sc->sc_mtx
doesn't look like it's global, but we expect to have only one
acpiec(4) device anyway from what I understand.  Maybe we should move
acpiec_cold into the softc?


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.107 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.106 src/sys/dev/acpi/acpi_ec.c:1.107
--- src/sys/dev/acpi/acpi_ec.c:1.106	Tue Jul 18 10:10:49 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:17:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.106 2023/07/18 10:10:49 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.107 2023/07/18 10:17:02 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.106 2023/07/18 10:10:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.107 2023/07/18 10:17:02 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -477,8 +477,23 @@ post_data_map:
 static bool
 acpiec_suspend(device_t dv, const pmf_qual_t *qual)
 {
+	struct acpiec_softc *sc = device_private(dv);
 
+	/*
+	 * XXX This looks bad because acpiec_cold is global and
+	 * sc->sc_mtx doesn't look like it's global, but we can have
+	 * only one acpiec(4) device anyway.  Maybe acpiec_cold should
+	 * live in the softc to make this look less bad?
+	 *
+	 * XXX Should this block read/write/query transactions until
+	 * resume?
+	 *
+	 * XXX Should this interrupt existing transactions to make them
+	 * fail promptly or restart on resume?
+	 */
+	mutex_enter(>sc_mtx);
 	acpiec_cold = true;
+	mutex_exit(>sc_mtx);
 
 	return true;
 }
@@ -486,8 +501,11 @@ acpiec_suspend(device_t dv, const pmf_qu
 static bool
 acpiec_resume(device_t dv, const pmf_qual_t *qual)
 {
+	struct acpiec_softc *sc = device_private(dv);
 
+	mutex_enter(>sc_mtx);
 	acpiec_cold = false;
+	mutex_exit(>sc_mtx);
 
 	return true;
 }
@@ -495,8 +513,12 @@ acpiec_resume(device_t dv, const pmf_qua
 static bool
 acpiec_shutdown(device_t dv, int how)
 {
+	struct acpiec_softc *sc = device_private(dv);
 
+	mutex_enter(>sc_mtx);
 	acpiec_cold = true;
+	mutex_exit(>sc_mtx);
+
 	return true;
 }
 



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:10:49 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Factor out if (state == FREE) cv_signal(sc_cv).

In principle this could have a functional change, but at worst, it is
to signal more wakeups than needed, which should always be safe.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.105 src/sys/dev/acpi/acpi_ec.c:1.106
--- src/sys/dev/acpi/acpi_ec.c:1.105	Tue Jul 18 10:06:55 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:10:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.105 2023/07/18 10:06:55 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.106 2023/07/18 10:10:49 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.105 2023/07/18 10:06:55 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.106 2023/07/18 10:10:49 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -967,7 +967,6 @@ acpiec_gpe_state_machine(struct acpiec_s
 			break; /* Nothing of interest here. */
 		sc->sc_cur_val = acpiec_read_data(sc);
 		sc->sc_state = EC_STATE_FREE;
-		cv_signal(>sc_cv);
 		break;
 
 	case EC_STATE_READ:
@@ -989,7 +988,6 @@ acpiec_gpe_state_machine(struct acpiec_s
 			break; /* Nothing of interest here. */
 		sc->sc_cur_val = acpiec_read_data(sc);
 		sc->sc_state = EC_STATE_FREE;
-		cv_signal(>sc_cv);
 		break;
 
 	case EC_STATE_WRITE:
@@ -1009,9 +1007,8 @@ acpiec_gpe_state_machine(struct acpiec_s
 	case EC_STATE_WRITE_VAL:
 		if ((reg & EC_STATUS_IBF) != 0)
 			break; /* Nothing of interest here. */
-		sc->sc_state = EC_STATE_FREE;
-		cv_signal(>sc_cv);
 		acpiec_write_data(sc, sc->sc_cur_val);
+		sc->sc_state = EC_STATE_FREE;
 		break;
 
 	case EC_STATE_FREE:
@@ -1022,10 +1019,12 @@ acpiec_gpe_state_machine(struct acpiec_s
 	}
 
 	/*
-	 * If we just ended a transaction, and an SCI was requested,
-	 * notify the SCI thread.
+	 * If we are not in a transaction, wake anyone waiting to start
+	 * one.  If an SCI was requested, notify the SCI thread that it
+	 * needs to handle the SCI.
 	 */
 	if (sc->sc_state == EC_STATE_FREE) {
+		cv_signal(>sc_cv);
 		if (reg & EC_STATUS_SCI) {
 			DPRINTF(ACPIEC_DEBUG_TRANSITION, sc,
 			"wake SCI thread\n");



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:10:49 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Factor out if (state == FREE) cv_signal(sc_cv).

In principle this could have a functional change, but at worst, it is
to signal more wakeups than needed, which should always be safe.


To generate a diff of this commit:
cvs rdiff -u -r1.105 -r1.106 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:55 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_space_handler.

Better to keep the device_t isolated to public interfaces.  Simpler
internally this way.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.104 src/sys/dev/acpi/acpi_ec.c:1.105
--- src/sys/dev/acpi/acpi_ec.c:1.104	Tue Jul 18 10:06:44 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:06:55 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.104 2023/07/18 10:06:44 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.105 2023/07/18 10:06:55 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.104 2023/07/18 10:06:44 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.105 2023/07/18 10:06:55 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -425,7 +425,7 @@ acpiec_common_attach(device_t parent, de
 	callout_setfunc(>sc_pseudo_intr, acpiec_callout, sc);
 
 	rv = AcpiInstallAddressSpaceHandler(sc->sc_ech, ACPI_ADR_SPACE_EC,
-	acpiec_space_handler, acpiec_space_setup, self);
+	acpiec_space_handler, acpiec_space_setup, sc);
 	if (rv != AE_OK) {
 		aprint_error_dev(self,
 		"unable to install address space handler: %s\n",
@@ -777,8 +777,8 @@ out:	mutex_exit(>sc_mtx);
  *
  *	Transfer bitwidth/8 bytes of data between paddr and *value:
  *	from paddr to *value when func is ACPI_READ, and the other way
- *	when func is ACPI_WRITE.  arg is the acpiec(4) or acpiecdt(4)
- *	device.  region_arg is ignored (XXX why? determined by
+ *	when func is ACPI_WRITE.  arg is the acpiec_softc pointer.
+ *	region_arg is ignored (XXX why? determined by
  *	acpiec_space_setup but never used by anything that I can see).
  *
  *	The caller always provides storage at *value large enough for
@@ -808,8 +808,7 @@ static ACPI_STATUS
 acpiec_space_handler(uint32_t func, ACPI_PHYSICAL_ADDRESS paddr,
 uint32_t width, ACPI_INTEGER *value, void *arg, void *region_arg)
 {
-	device_t dv = arg;
-	struct acpiec_softc *sc = device_private(dv);
+	struct acpiec_softc *sc = arg;
 	ACPI_STATUS rv;
 	uint8_t addr, *buf;
 	unsigned int i;
@@ -1074,13 +1073,17 @@ acpiec_gpe_handler(ACPI_HANDLE hdl, uint
 ACPI_STATUS
 acpiec_bus_read(device_t dv, u_int addr, ACPI_INTEGER *val, int width)
 {
-	return acpiec_space_handler(ACPI_READ, addr, width * 8, val, dv, NULL);
+	struct acpiec_softc *sc = device_private(dv);
+
+	return acpiec_space_handler(ACPI_READ, addr, width * 8, val, sc, NULL);
 }
 
 ACPI_STATUS
 acpiec_bus_write(device_t dv, u_int addr, ACPI_INTEGER val, int width)
 {
-	return acpiec_space_handler(ACPI_WRITE, addr, width * 8, , dv,
+	struct acpiec_softc *sc = device_private(dv);
+
+	return acpiec_space_handler(ACPI_WRITE, addr, width * 8, , sc,
 	NULL);
 }
 



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:55 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_space_handler.

Better to keep the device_t isolated to public interfaces.  Simpler
internally this way.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.104 -r1.105 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:44 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_gpe_query thread.

Simpler.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.103 src/sys/dev/acpi/acpi_ec.c:1.104
--- src/sys/dev/acpi/acpi_ec.c:1.103	Tue Jul 18 10:06:33 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:06:44 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.103 2023/07/18 10:06:33 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.104 2023/07/18 10:06:44 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.103 2023/07/18 10:06:33 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.104 2023/07/18 10:06:44 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -449,7 +449,7 @@ acpiec_common_attach(device_t parent, de
 	}
 
 	if (kthread_create(PRI_NONE, KTHREAD_MPSAFE, NULL, acpiec_gpe_query,
-		   self, NULL, "acpiec sci thread")) {
+		sc, NULL, "acpiec sci thread")) {
 		aprint_error_dev(self, "unable to create query kthread\n");
 		goto post_csr_map;
 	}
@@ -882,8 +882,7 @@ acpiec_wait(struct acpiec_softc *sc)
 static void
 acpiec_gpe_query(void *arg)
 {
-	device_t dv = arg;
-	struct acpiec_softc *sc = device_private(dv);
+	struct acpiec_softc *sc = arg;
 	uint8_t reg;
 	char qxx[5];
 	ACPI_STATUS rv;
@@ -931,7 +930,7 @@ loop:
 	snprintf(qxx, sizeof(qxx), "_Q%02X", (unsigned int)reg);
 	rv = AcpiEvaluateObject(sc->sc_ech, qxx, NULL, NULL);
 	if (rv != AE_OK && rv != AE_NOT_FOUND) {
-		aprint_error_dev(dv, "GPE query method %s failed: %s",
+		aprint_error_dev(sc->sc_dev, "GPE query method %s failed: %s",
 		qxx, AcpiFormatException(rv));
 	}
 



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:44 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_gpe_query thread.

Simpler.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:33 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_read/write.

Simpler, type-safer.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.102 src/sys/dev/acpi/acpi_ec.c:1.103
--- src/sys/dev/acpi/acpi_ec.c:1.102	Tue Jul 18 10:06:22 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:06:33 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.102 2023/07/18 10:06:22 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.103 2023/07/18 10:06:33 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.102 2023/07/18 10:06:22 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.103 2023/07/18 10:06:33 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -697,9 +697,8 @@ acpiec_wait_timeout(struct acpiec_softc 
 }
 
 static ACPI_STATUS
-acpiec_read(device_t dv, uint8_t addr, uint8_t *val)
+acpiec_read(struct acpiec_softc *sc, uint8_t addr, uint8_t *val)
 {
-	struct acpiec_softc *sc = device_private(dv);
 	ACPI_STATUS rv;
 
 	acpiec_lock(sc);
@@ -736,9 +735,8 @@ out:	mutex_exit(>sc_mtx);
 }
 
 static ACPI_STATUS
-acpiec_write(device_t dv, uint8_t addr, uint8_t val)
+acpiec_write(struct acpiec_softc *sc, uint8_t addr, uint8_t val)
 {
-	struct acpiec_softc *sc = device_private(dv);
 	ACPI_STATUS rv;
 
 	acpiec_lock(sc);
@@ -810,7 +808,8 @@ static ACPI_STATUS
 acpiec_space_handler(uint32_t func, ACPI_PHYSICAL_ADDRESS paddr,
 uint32_t width, ACPI_INTEGER *value, void *arg, void *region_arg)
 {
-	device_t dv;
+	device_t dv = arg;
+	struct acpiec_softc *sc = device_private(dv);
 	ACPI_STATUS rv;
 	uint8_t addr, *buf;
 	unsigned int i;
@@ -820,7 +819,6 @@ acpiec_space_handler(uint32_t func, ACPI
 		return AE_BAD_PARAMETER;
 
 	addr = paddr;
-	dv = arg;
 	buf = (uint8_t *)value;
 
 	rv = AE_OK;
@@ -828,7 +826,7 @@ acpiec_space_handler(uint32_t func, ACPI
 	switch (func) {
 	case ACPI_READ:
 		for (i = 0; i < width; i += 8, ++addr, ++buf) {
-			rv = acpiec_read(dv, addr, buf);
+			rv = acpiec_read(sc, addr, buf);
 			if (rv != AE_OK)
 break;
 		}
@@ -841,14 +839,15 @@ acpiec_space_handler(uint32_t func, ACPI
 		break;
 	case ACPI_WRITE:
 		for (i = 0; i < width; i += 8, ++addr, ++buf) {
-			rv = acpiec_write(dv, addr, *buf);
+			rv = acpiec_write(sc, addr, *buf);
 			if (rv != AE_OK)
 break;
 		}
 		break;
 	default:
-		aprint_error("%s: invalid Address Space function called: %x\n",
-		device_xname(dv), (unsigned int)func);
+		aprint_error_dev(sc->sc_dev,
+		"invalid Address Space function called: %x\n",
+		(unsigned int)func);
 		return AE_BAD_PARAMETER;
 	}
 



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:33 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_read/write.

Simpler, type-safer.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.102 -r1.103 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:22 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_lock/unlock.

Simpler, type-safer.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.101 src/sys/dev/acpi/acpi_ec.c:1.102
--- src/sys/dev/acpi/acpi_ec.c:1.101	Tue Jul 18 10:06:11 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:06:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.101 2023/07/18 10:06:11 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.102 2023/07/18 10:06:22 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.101 2023/07/18 10:06:11 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.102 2023/07/18 10:06:22 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -619,9 +619,8 @@ acpiec_space_setup(ACPI_HANDLE region, u
 }
 
 static void
-acpiec_lock(device_t dv)
+acpiec_lock(struct acpiec_softc *sc)
 {
-	struct acpiec_softc *sc = device_private(dv);
 	ACPI_STATUS rv;
 
 	mutex_enter(>sc_access_mtx);
@@ -630,7 +629,7 @@ acpiec_lock(device_t dv)
 		rv = AcpiAcquireGlobalLock(EC_LOCK_TIMEOUT,
 		>sc_global_lock);
 		if (rv != AE_OK) {
-			aprint_error_dev(dv,
+			aprint_error_dev(sc->sc_dev,
 			"failed to acquire global lock: %s\n",
 			AcpiFormatException(rv));
 			return;
@@ -639,15 +638,14 @@ acpiec_lock(device_t dv)
 }
 
 static void
-acpiec_unlock(device_t dv)
+acpiec_unlock(struct acpiec_softc *sc)
 {
-	struct acpiec_softc *sc = device_private(dv);
 	ACPI_STATUS rv;
 
 	if (sc->sc_need_global_lock) {
 		rv = AcpiReleaseGlobalLock(sc->sc_global_lock);
 		if (rv != AE_OK) {
-			aprint_error_dev(dv,
+			aprint_error_dev(sc->sc_dev,
 			"failed to release global lock: %s\n",
 			AcpiFormatException(rv));
 		}
@@ -704,7 +702,7 @@ acpiec_read(device_t dv, uint8_t addr, u
 	struct acpiec_softc *sc = device_private(dv);
 	ACPI_STATUS rv;
 
-	acpiec_lock(dv);
+	acpiec_lock(sc);
 	mutex_enter(>sc_mtx);
 
 	DPRINTF(ACPIEC_DEBUG_RW, sc,
@@ -733,7 +731,7 @@ acpiec_read(device_t dv, uint8_t addr, u
 	*val = sc->sc_cur_val;
 
 out:	mutex_exit(>sc_mtx);
-	acpiec_unlock(dv);
+	acpiec_unlock(sc);
 	return rv;
 }
 
@@ -743,7 +741,7 @@ acpiec_write(device_t dv, uint8_t addr, 
 	struct acpiec_softc *sc = device_private(dv);
 	ACPI_STATUS rv;
 
-	acpiec_lock(dv);
+	acpiec_lock(sc);
 	mutex_enter(>sc_mtx);
 
 	DPRINTF(ACPIEC_DEBUG_RW, sc,
@@ -772,7 +770,7 @@ acpiec_write(device_t dv, uint8_t addr, 
 	addr, val);
 
 out:	mutex_exit(>sc_mtx);
-	acpiec_unlock(dv);
+	acpiec_unlock(sc);
 	return rv;
 }
 
@@ -905,7 +903,7 @@ loop:
 	 * EC wants to submit a query to us.  Exclude concurrent reads
 	 * and writes while we handle it.
 	 */
-	acpiec_lock(dv);
+	acpiec_lock(sc);
 	mutex_enter(>sc_mtx);
 
 	DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI query\n");
@@ -923,7 +921,7 @@ loop:
 	DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI query: 0x%"PRIx8"\n", reg);
 
 	mutex_exit(>sc_mtx);
-	acpiec_unlock(dv);
+	acpiec_unlock(sc);
 
 	if (reg == 0)
 		goto loop; /* Spurious query result */



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:22 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_lock/unlock.

Simpler, type-safer.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.101 -r1.102 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:12 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_gpe_handler.

Simpler.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.100 src/sys/dev/acpi/acpi_ec.c:1.101
--- src/sys/dev/acpi/acpi_ec.c:1.100	Tue Jul 18 10:06:00 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:06:11 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.100 2023/07/18 10:06:00 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.101 2023/07/18 10:06:11 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.100 2023/07/18 10:06:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.101 2023/07/18 10:06:11 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -434,7 +434,7 @@ acpiec_common_attach(device_t parent, de
 	}
 
 	rv = AcpiInstallGpeHandler(sc->sc_gpeh, sc->sc_gpebit,
-	ACPI_GPE_EDGE_TRIGGERED, acpiec_gpe_handler, self);
+	ACPI_GPE_EDGE_TRIGGERED, acpiec_gpe_handler, sc);
 	if (rv != AE_OK) {
 		aprint_error_dev(self, "unable to install GPE handler: %s\n",
 		AcpiFormatException(rv));
@@ -1065,8 +1065,7 @@ acpiec_callout(void *arg)
 static uint32_t
 acpiec_gpe_handler(ACPI_HANDLE hdl, uint32_t gpebit, void *arg)
 {
-	device_t dv = arg;
-	struct acpiec_softc *sc = device_private(dv);
+	struct acpiec_softc *sc = arg;
 
 	mutex_enter(>sc_mtx);
 	DPRINTF(ACPIEC_DEBUG_INTR, sc, "GPE\n");



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:12 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_gpe_handler.

Simpler.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:00 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_callout.

Simpler.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:06:00 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_callout.

Simpler.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.99 -r1.100 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.99 src/sys/dev/acpi/acpi_ec.c:1.100
--- src/sys/dev/acpi/acpi_ec.c:1.99	Tue Jul 18 10:05:49 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:06:00 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.99 2023/07/18 10:05:49 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.100 2023/07/18 10:06:00 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.99 2023/07/18 10:05:49 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.100 2023/07/18 10:06:00 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -422,7 +422,7 @@ acpiec_common_attach(device_t parent, de
 		aprint_normal_dev(self, "using global ACPI lock\n");
 
 	callout_init(>sc_pseudo_intr, CALLOUT_MPSAFE);
-	callout_setfunc(>sc_pseudo_intr, acpiec_callout, self);
+	callout_setfunc(>sc_pseudo_intr, acpiec_callout, sc);
 
 	rv = AcpiInstallAddressSpaceHandler(sc->sc_ech, ACPI_ADR_SPACE_EC,
 	acpiec_space_handler, acpiec_space_setup, self);
@@ -1054,8 +1054,7 @@ acpiec_gpe_state_machine(struct acpiec_s
 static void
 acpiec_callout(void *arg)
 {
-	device_t dv = arg;
-	struct acpiec_softc *sc = device_private(dv);
+	struct acpiec_softc *sc = arg;
 
 	mutex_enter(>sc_mtx);
 	DPRINTF(ACPIEC_DEBUG_INTR, sc, "callout\n");



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:05:49 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_gpe_state_machine.

Simpler, type-safer.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.98 src/sys/dev/acpi/acpi_ec.c:1.99
--- src/sys/dev/acpi/acpi_ec.c:1.98	Tue Jul 18 10:05:24 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:05:49 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.98 2023/07/18 10:05:24 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.99 2023/07/18 10:05:49 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.98 2023/07/18 10:05:24 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.99 2023/07/18 10:05:49 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -235,7 +235,7 @@ static ACPI_STATUS acpiec_space_setup(AC
 static ACPI_STATUS acpiec_space_handler(uint32_t, ACPI_PHYSICAL_ADDRESS,
 uint32_t, ACPI_INTEGER *, void *, void *);
 
-static void acpiec_gpe_state_machine(device_t);
+static void acpiec_gpe_state_machine(struct acpiec_softc *);
 
 CFATTACH_DECL_NEW(acpiec, sizeof(struct acpiec_softc),
 acpiec_match, acpiec_attach, NULL, NULL);
@@ -662,7 +662,7 @@ acpiec_wait_timeout(struct acpiec_softc 
 	int i;
 
 	for (i = 0; i < EC_POLL_TIMEOUT; ++i) {
-		acpiec_gpe_state_machine(dv);
+		acpiec_gpe_state_machine(sc);
 		if (sc->sc_state == EC_STATE_FREE)
 			return AE_OK;
 		delay(1);
@@ -673,7 +673,7 @@ acpiec_wait_timeout(struct acpiec_softc 
 
 		while (sc->sc_state != EC_STATE_FREE && timeo-- > 0) {
 			delay(1000);
-			acpiec_gpe_state_machine(dv);
+			acpiec_gpe_state_machine(sc);
 		}
 		if (sc->sc_state != EC_STATE_FREE) {
 			aprint_error_dev(dv, "command timed out, state %d\n",
@@ -860,14 +860,13 @@ acpiec_space_handler(uint32_t func, ACPI
 static void
 acpiec_wait(struct acpiec_softc *sc)
 {
-	device_t dv = sc->sc_dev;
 	int i;
 
 	/*
 	 * First, attempt to get the query by polling.
 	 */
 	for (i = 0; i < EC_POLL_TIMEOUT; ++i) {
-		acpiec_gpe_state_machine(dv);
+		acpiec_gpe_state_machine(sc);
 		if (sc->sc_state == EC_STATE_FREE)
 			return;
 		delay(1);
@@ -943,9 +942,8 @@ loop:
 }
 
 static void
-acpiec_gpe_state_machine(device_t dv)
+acpiec_gpe_state_machine(struct acpiec_softc *sc)
 {
-	struct acpiec_softc *sc = device_private(dv);
 	uint8_t reg;
 
 	KASSERT(mutex_owned(>sc_mtx));
@@ -1061,7 +1059,7 @@ acpiec_callout(void *arg)
 
 	mutex_enter(>sc_mtx);
 	DPRINTF(ACPIEC_DEBUG_INTR, sc, "callout\n");
-	acpiec_gpe_state_machine(dv);
+	acpiec_gpe_state_machine(sc);
 	mutex_exit(>sc_mtx);
 }
 
@@ -1073,7 +1071,7 @@ acpiec_gpe_handler(ACPI_HANDLE hdl, uint
 
 	mutex_enter(>sc_mtx);
 	DPRINTF(ACPIEC_DEBUG_INTR, sc, "GPE\n");
-	acpiec_gpe_state_machine(dv);
+	acpiec_gpe_state_machine(sc);
 	mutex_exit(>sc_mtx);
 
 	return ACPI_INTERRUPT_HANDLED | ACPI_REENABLE_GPE;



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:05:49 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Pass softc, not device_t, to acpiec_gpe_state_machine.

Simpler, type-safer.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.98 -r1.99 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:05:25 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Factor wait logic out.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.97 src/sys/dev/acpi/acpi_ec.c:1.98
--- src/sys/dev/acpi/acpi_ec.c:1.97	Tue Jul 18 10:05:13 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:05:24 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.97 2023/07/18 10:05:13 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.98 2023/07/18 10:05:24 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.97 2023/07/18 10:05:13 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.98 2023/07/18 10:05:24 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -656,35 +656,21 @@ acpiec_unlock(device_t dv)
 }
 
 static ACPI_STATUS
-acpiec_read(device_t dv, uint8_t addr, uint8_t *val)
+acpiec_wait_timeout(struct acpiec_softc *sc)
 {
-	struct acpiec_softc *sc = device_private(dv);
-	int i, timeo = 1000 * EC_CMD_TIMEOUT;
-	ACPI_STATUS rv;
-
-	acpiec_lock(dv);
-	mutex_enter(>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);
-
-	KASSERT(sc->sc_state == EC_STATE_FREE);
-
-	sc->sc_cur_addr = addr;
-	sc->sc_state = EC_STATE_READ;
+	device_t dv = sc->sc_dev;
+	int i;
 
 	for (i = 0; i < EC_POLL_TIMEOUT; ++i) {
 		acpiec_gpe_state_machine(dv);
 		if (sc->sc_state == EC_STATE_FREE)
-			goto done;
+			return AE_OK;
 		delay(1);
 	}
 
 	if (cold || acpiec_cold) {
+		int timeo = 1000 * EC_CMD_TIMEOUT;
+
 		while (sc->sc_state != EC_STATE_FREE && timeo-- > 0) {
 			delay(1000);
 			acpiec_gpe_state_machine(dv);
@@ -692,8 +678,7 @@ acpiec_read(device_t dv, uint8_t addr, u
 		if (sc->sc_state != EC_STATE_FREE) {
 			aprint_error_dev(dv, "command timed out, state %d\n",
 			sc->sc_state);
-			rv = AE_ERROR;
-			goto out;
+			return AE_ERROR;
 		}
 	} else {
 		const unsigned deadline = getticks() + EC_CMD_TIMEOUT*hz;
@@ -706,12 +691,38 @@ acpiec_read(device_t dv, uint8_t addr, u
 			aprint_error_dev(dv,
 			"command takes over %d sec...\n",
 			EC_CMD_TIMEOUT);
-			rv = AE_ERROR;
-			goto out;
+			return AE_ERROR;
 		}
 	}
 
-done:
+	return AE_OK;
+}
+
+static ACPI_STATUS
+acpiec_read(device_t dv, uint8_t addr, uint8_t *val)
+{
+	struct acpiec_softc *sc = device_private(dv);
+	ACPI_STATUS rv;
+
+	acpiec_lock(dv);
+	mutex_enter(>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);
+
+	KASSERT(sc->sc_state == EC_STATE_FREE);
+
+	sc->sc_cur_addr = addr;
+	sc->sc_state = EC_STATE_READ;
+
+	rv = acpiec_wait_timeout(sc);
+	if (ACPI_FAILURE(rv))
+		goto out;
+
 	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,
@@ -720,9 +731,8 @@ done:
 	addr, sc->sc_cur_val);
 
 	*val = sc->sc_cur_val;
-	rv = AE_OK;
-out:
-	mutex_exit(>sc_mtx);
+
+out:	mutex_exit(>sc_mtx);
 	acpiec_unlock(dv);
 	return rv;
 }
@@ -731,7 +741,6 @@ static ACPI_STATUS
 acpiec_write(device_t dv, uint8_t addr, uint8_t val)
 {
 	struct acpiec_softc *sc = device_private(dv);
-	int i, timeo = 1000 * EC_CMD_TIMEOUT;
 	ACPI_STATUS rv;
 
 	acpiec_lock(dv);
@@ -750,41 +759,10 @@ acpiec_write(device_t dv, uint8_t addr, 
 	sc->sc_cur_val = val;
 	sc->sc_state = EC_STATE_WRITE;
 
-	for (i = 0; i < EC_POLL_TIMEOUT; ++i) {
-		acpiec_gpe_state_machine(dv);
-		if (sc->sc_state == EC_STATE_FREE)
-			goto done;
-		delay(1);
-	}
-
-	if (cold || acpiec_cold) {
-		while (sc->sc_state != EC_STATE_FREE && timeo-- > 0) {
-			delay(1000);
-			acpiec_gpe_state_machine(dv);
-		}
-		if (sc->sc_state != EC_STATE_FREE) {
-			aprint_error_dev(dv, "command timed out, state %d\n",
-			sc->sc_state);
-			rv = AE_ERROR;
-			goto out;
-		}
-	} else {
-		const unsigned deadline = getticks() + EC_CMD_TIMEOUT*hz;
-		unsigned delta;
-
-		while (sc->sc_state != EC_STATE_FREE &&
-		(delta = deadline - getticks()) < INT_MAX)
-			(void)cv_timedwait(>sc_cv, >sc_mtx, delta);
-		if (sc->sc_state != EC_STATE_FREE) {
-			aprint_error_dev(dv,
-			"command takes over %d sec...\n",
-			EC_CMD_TIMEOUT);
-			rv = AE_ERROR;
-			goto out;
-		}
-	}
+	rv = acpiec_wait_timeout(sc);
+	if (ACPI_FAILURE(rv))
+		goto out;
 
-done:
 	

CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:05:25 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Factor wait logic out.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.97 -r1.98 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:05:13 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Merge returns in acpiec_read/write.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:05:13 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Merge returns in acpiec_read/write.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.96 -r1.97 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.96 src/sys/dev/acpi/acpi_ec.c:1.97
--- src/sys/dev/acpi/acpi_ec.c:1.96	Tue Jul 18 10:05:01 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:05:13 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.96 2023/07/18 10:05:01 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.97 2023/07/18 10:05:13 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.96 2023/07/18 10:05:01 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.97 2023/07/18 10:05:13 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -660,6 +660,7 @@ acpiec_read(device_t dv, uint8_t addr, u
 {
 	struct acpiec_softc *sc = device_private(dv);
 	int i, timeo = 1000 * EC_CMD_TIMEOUT;
+	ACPI_STATUS rv;
 
 	acpiec_lock(dv);
 	mutex_enter(>sc_mtx);
@@ -691,9 +692,8 @@ acpiec_read(device_t dv, uint8_t addr, u
 		if (sc->sc_state != EC_STATE_FREE) {
 			aprint_error_dev(dv, "command timed out, state %d\n",
 			sc->sc_state);
-			mutex_exit(>sc_mtx);
-			acpiec_unlock(dv);
-			return AE_ERROR;
+			rv = AE_ERROR;
+			goto out;
 		}
 	} else {
 		const unsigned deadline = getticks() + EC_CMD_TIMEOUT*hz;
@@ -703,12 +703,11 @@ acpiec_read(device_t dv, uint8_t addr, u
 		(delta = deadline - getticks()) < INT_MAX)
 			(void)cv_timedwait(>sc_cv, >sc_mtx, delta);
 		if (sc->sc_state != EC_STATE_FREE) {
-			mutex_exit(>sc_mtx);
-			acpiec_unlock(dv);
 			aprint_error_dev(dv,
 			"command takes over %d sec...\n",
 			EC_CMD_TIMEOUT);
-			return AE_ERROR;
+			rv = AE_ERROR;
+			goto out;
 		}
 	}
 
@@ -721,10 +720,11 @@ done:
 	addr, sc->sc_cur_val);
 
 	*val = sc->sc_cur_val;
-
+	rv = AE_OK;
+out:
 	mutex_exit(>sc_mtx);
 	acpiec_unlock(dv);
-	return AE_OK;
+	return rv;
 }
 
 static ACPI_STATUS
@@ -732,6 +732,7 @@ acpiec_write(device_t dv, uint8_t addr, 
 {
 	struct acpiec_softc *sc = device_private(dv);
 	int i, timeo = 1000 * EC_CMD_TIMEOUT;
+	ACPI_STATUS rv;
 
 	acpiec_lock(dv);
 	mutex_enter(>sc_mtx);
@@ -764,9 +765,8 @@ acpiec_write(device_t dv, uint8_t addr, 
 		if (sc->sc_state != EC_STATE_FREE) {
 			aprint_error_dev(dv, "command timed out, state %d\n",
 			sc->sc_state);
-			mutex_exit(>sc_mtx);
-			acpiec_unlock(dv);
-			return AE_ERROR;
+			rv = AE_ERROR;
+			goto out;
 		}
 	} else {
 		const unsigned deadline = getticks() + EC_CMD_TIMEOUT*hz;
@@ -776,12 +776,11 @@ acpiec_write(device_t dv, uint8_t addr, 
 		(delta = deadline - getticks()) < INT_MAX)
 			(void)cv_timedwait(>sc_cv, >sc_mtx, delta);
 		if (sc->sc_state != EC_STATE_FREE) {
-			mutex_exit(>sc_mtx);
-			acpiec_unlock(dv);
 			aprint_error_dev(dv,
 			"command takes over %d sec...\n",
 			EC_CMD_TIMEOUT);
-			return AE_ERROR;
+			rv = AE_ERROR;
+			goto out;
 		}
 	}
 
@@ -793,10 +792,11 @@ done:
 	(long)curlwp->l_lid, curlwp->l_name ? " " : "",
 	curlwp->l_name ? curlwp->l_name : "",
 	addr, val);
-
+	rv = AE_OK;
+out:
 	mutex_exit(>sc_mtx);
 	acpiec_unlock(dv);
-	return AE_OK;
+	return rv;
 }
 
 /*



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:05:01 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Don't touch sc->sc_state outside sc->sc_mtx.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.95 src/sys/dev/acpi/acpi_ec.c:1.96
--- src/sys/dev/acpi/acpi_ec.c:1.95	Tue Jul 18 10:04:50 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:05:01 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.95 2023/07/18 10:04:50 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.96 2023/07/18 10:05:01 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.95 2023/07/18 10:04:50 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.96 2023/07/18 10:05:01 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -689,10 +689,10 @@ acpiec_read(device_t dv, uint8_t addr, u
 			acpiec_gpe_state_machine(dv);
 		}
 		if (sc->sc_state != EC_STATE_FREE) {
-			mutex_exit(>sc_mtx);
-			acpiec_unlock(dv);
 			aprint_error_dev(dv, "command timed out, state %d\n",
 			sc->sc_state);
+			mutex_exit(>sc_mtx);
+			acpiec_unlock(dv);
 			return AE_ERROR;
 		}
 	} else {
@@ -762,10 +762,10 @@ acpiec_write(device_t dv, uint8_t addr, 
 			acpiec_gpe_state_machine(dv);
 		}
 		if (sc->sc_state != EC_STATE_FREE) {
-			mutex_exit(>sc_mtx);
-			acpiec_unlock(dv);
 			aprint_error_dev(dv, "command timed out, state %d\n",
 			sc->sc_state);
+			mutex_exit(>sc_mtx);
+			acpiec_unlock(dv);
 			return AE_ERROR;
 		}
 	} else {



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:05:01 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Don't touch sc->sc_state outside sc->sc_mtx.


To generate a diff of this commit:
cvs rdiff -u -r1.95 -r1.96 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:04:50 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Fix cv_timedwait abuse in acpiec_read/write.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:04:50 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Fix cv_timedwait abuse in acpiec_read/write.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.94 src/sys/dev/acpi/acpi_ec.c:1.95
--- src/sys/dev/acpi/acpi_ec.c:1.94	Tue Jul 18 10:04:40 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:04:50 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.94 2023/07/18 10:04:40 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.95 2023/07/18 10:04:50 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.94 2023/07/18 10:04:40 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.95 2023/07/18 10:04:50 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -695,17 +695,21 @@ acpiec_read(device_t dv, uint8_t addr, u
 			sc->sc_state);
 			return AE_ERROR;
 		}
-	} else if (cv_timedwait(>sc_cv, >sc_mtx, EC_CMD_TIMEOUT * hz)) {
-		/*
-		 * XXX while (sc->sc_state != EC_STATE_FREE)
-		 *	cv_timedwait(...),
-		 * plus deadline
-		 */
-		mutex_exit(>sc_mtx);
-		acpiec_unlock(dv);
-		aprint_error_dev(dv,
-		"command takes over %d sec...\n", EC_CMD_TIMEOUT);
-		return AE_ERROR;
+	} else {
+		const unsigned deadline = getticks() + EC_CMD_TIMEOUT*hz;
+		unsigned delta;
+
+		while (sc->sc_state != EC_STATE_FREE &&
+		(delta = deadline - getticks()) < INT_MAX)
+			(void)cv_timedwait(>sc_cv, >sc_mtx, delta);
+		if (sc->sc_state != EC_STATE_FREE) {
+			mutex_exit(>sc_mtx);
+			acpiec_unlock(dv);
+			aprint_error_dev(dv,
+			"command takes over %d sec...\n",
+			EC_CMD_TIMEOUT);
+			return AE_ERROR;
+		}
 	}
 
 done:
@@ -764,17 +768,21 @@ acpiec_write(device_t dv, uint8_t addr, 
 			sc->sc_state);
 			return AE_ERROR;
 		}
-	} else if (cv_timedwait(>sc_cv, >sc_mtx, EC_CMD_TIMEOUT * hz)) {
-		/*
-		 * XXX while (sc->sc_state != EC_STATE_FREE)
-		 *	cv_timedwait(...),
-		 * plus deadline
-		 */
-		mutex_exit(>sc_mtx);
-		acpiec_unlock(dv);
-		aprint_error_dev(dv,
-		"command takes over %d sec...\n", EC_CMD_TIMEOUT);
-		return AE_ERROR;
+	} else {
+		const unsigned deadline = getticks() + EC_CMD_TIMEOUT*hz;
+		unsigned delta;
+
+		while (sc->sc_state != EC_STATE_FREE &&
+		(delta = deadline - getticks()) < INT_MAX)
+			(void)cv_timedwait(>sc_cv, >sc_mtx, delta);
+		if (sc->sc_state != EC_STATE_FREE) {
+			mutex_exit(>sc_mtx);
+			acpiec_unlock(dv);
+			aprint_error_dev(dv,
+			"command takes over %d sec...\n",
+			EC_CMD_TIMEOUT);
+			return AE_ERROR;
+		}
 	}
 
 done:



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:04:40 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Fix interrupt wait loop in acpiec_gpe_query thread.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.93 src/sys/dev/acpi/acpi_ec.c:1.94
--- src/sys/dev/acpi/acpi_ec.c:1.93	Tue Jul 18 10:04:28 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:04:40 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.93 2023/07/18 10:04:28 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.94 2023/07/18 10:04:40 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.93 2023/07/18 10:04:28 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.94 2023/07/18 10:04:40 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -908,6 +908,9 @@ loop:
 	sc->sc_got_sci = false;
 	sc->sc_state = EC_STATE_QUERY;
 
+	/*
+	 * First, attempt to get the query by polling.
+	 */
 	for (i = 0; i < EC_POLL_TIMEOUT; ++i) {
 		acpiec_gpe_state_machine(dv);
 		if (sc->sc_state == EC_STATE_FREE)
@@ -915,9 +918,14 @@ loop:
 		delay(1);
 	}
 
+	/*
+	 * Polling timed out.  Try waiting for interrupts -- either GPE
+	 * interrupts, or periodic callouts in case GPE interrupts are
+	 * broken.
+	 */
 	DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI polling timeout\n");
-	/* XXX while (sc->sc_state != EC_STATE_FREE) cv_wait(...) */
-	cv_wait(>sc_cv, >sc_mtx);
+	while (sc->sc_state != EC_STATE_FREE)
+		cv_wait(>sc_cv, >sc_mtx);
 
 done:
 	reg = sc->sc_cur_val;



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:04:40 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Fix interrupt wait loop in acpiec_gpe_query thread.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:04:28 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Fix cv_wait loop around sc->sc_got_sci.

That is, make it actually loop as required, so it gracefully handles
spurious wakeups instead of barging into invalid states.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.92 src/sys/dev/acpi/acpi_ec.c:1.93
--- src/sys/dev/acpi/acpi_ec.c:1.92	Tue Jul 18 10:04:14 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:04:28 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.92 2023/07/18 10:04:14 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.93 2023/07/18 10:04:28 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.92 2023/07/18 10:04:14 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.93 2023/07/18 10:04:28 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -885,11 +885,9 @@ acpiec_gpe_query(void *arg)
 loop:
 	/*
 	 * Wait until the EC sends an SCI requesting a query.
-	 *
-	 * XXX This needs to be `while', not `if'.
 	 */
 	mutex_enter(>sc_mtx);
-	if (sc->sc_got_sci == false)
+	while (!sc->sc_got_sci)
 		cv_wait(>sc_cv_sci, >sc_mtx);
 	DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI query requested\n");
 	mutex_exit(>sc_mtx);
@@ -906,6 +904,7 @@ loop:
 	KASSERT(sc->sc_state == EC_STATE_FREE);
 
 	/* The Query command can always be issued, so be defensive here. */
+	KASSERT(sc->sc_got_sci);
 	sc->sc_got_sci = false;
 	sc->sc_state = EC_STATE_QUERY;
 



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:04:28 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Fix cv_wait loop around sc->sc_got_sci.

That is, make it actually loop as required, so it gracefully handles
spurious wakeups instead of barging into invalid states.


To generate a diff of this commit:
cvs rdiff -u -r1.92 -r1.93 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:04:14 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Set sc_got_sci only when a transaction is over.

Before, when the acpiec thread noticed an SCI had been requested and
entered acpiec_gpe_state_machine to send the query command, it would
see the SCI is still requested -- because it had yet to acknowledge
it by setting the query command! -- and think the EC was asking for a
_second_ SCI.

So once the first SCI transaction was over, it would start a second
one, even though the EC hadn't asked for another -- and this would
wedge on some ECs.

Now, acpiec_gpe_state_machine waits to see what state we transition
to before taking the SCI bit to mean we need to notify the acpiec
thread to handle another query.

That way, when the acpiec thread enters acpiec_gpe_state_machine with
EC_STATE_QUERY, it can send the query command first, with the side
effect of clearing the SCI bit in subsequent reads of the status
register, and it won't think another SCI has been requested until it
returns to EC_STATE_FREE and sees the SCI bit set again in the status
register.

Possibly relevant PRs:

PR kern/53135
PR kern/52763
PR kern/57162


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:04:14 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Set sc_got_sci only when a transaction is over.

Before, when the acpiec thread noticed an SCI had been requested and
entered acpiec_gpe_state_machine to send the query command, it would
see the SCI is still requested -- because it had yet to acknowledge
it by setting the query command! -- and think the EC was asking for a
_second_ SCI.

So once the first SCI transaction was over, it would start a second
one, even though the EC hadn't asked for another -- and this would
wedge on some ECs.

Now, acpiec_gpe_state_machine waits to see what state we transition
to before taking the SCI bit to mean we need to notify the acpiec
thread to handle another query.

That way, when the acpiec thread enters acpiec_gpe_state_machine with
EC_STATE_QUERY, it can send the query command first, with the side
effect of clearing the SCI bit in subsequent reads of the status
register, and it won't think another SCI has been requested until it
returns to EC_STATE_FREE and sees the SCI bit set again in the status
register.

Possibly relevant PRs:

PR kern/53135
PR kern/52763
PR kern/57162


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.91 src/sys/dev/acpi/acpi_ec.c:1.92
--- src/sys/dev/acpi/acpi_ec.c:1.91	Tue Jul 18 10:03:59 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:04:14 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.91 2023/07/18 10:03:59 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.92 2023/07/18 10:04:14 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.91 2023/07/18 10:03:59 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.92 2023/07/18 10:04:14 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -962,9 +962,6 @@ acpiec_gpe_state_machine(device_t dv)
 	}
 #endif
 
-	if (reg & EC_STATUS_SCI)
-		sc->sc_got_sci = true;
-
 	switch (sc->sc_state) {
 	case EC_STATE_QUERY:
 		if ((reg & EC_STATUS_IBF) != 0)
@@ -1026,11 +1023,6 @@ acpiec_gpe_state_machine(device_t dv)
 		break;
 
 	case EC_STATE_FREE:
-		if (sc->sc_got_sci) {
-			DPRINTF(ACPIEC_DEBUG_TRANSITION, sc,
-			"wake SCI thread\n");
-			cv_signal(>sc_cv_sci);
-		}
 		break;
 
 	default:
@@ -1038,6 +1030,19 @@ acpiec_gpe_state_machine(device_t dv)
 	}
 
 	/*
+	 * If we just ended a transaction, and an SCI was requested,
+	 * notify the SCI thread.
+	 */
+	if (sc->sc_state == EC_STATE_FREE) {
+		if (reg & EC_STATUS_SCI) {
+			DPRINTF(ACPIEC_DEBUG_TRANSITION, sc,
+			"wake SCI thread\n");
+			sc->sc_got_sci = true;
+			cv_signal(>sc_cv_sci);
+		}
+	}
+
+	/*
 	 * In case GPE interrupts are broken, poll once per tick for EC
 	 * status updates while a transaction is still pending.
 	 */



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:03:59 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Assert state is free when we start a transaction.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:03:59 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Assert state is free when we start a transaction.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.90 src/sys/dev/acpi/acpi_ec.c:1.91
--- src/sys/dev/acpi/acpi_ec.c:1.90	Tue Jul 18 10:03:46 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:03:59 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.90 2023/07/18 10:03:46 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.91 2023/07/18 10:03:59 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.90 2023/07/18 10:03:46 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.91 2023/07/18 10:03:59 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -671,6 +671,8 @@ acpiec_read(device_t dv, uint8_t addr, u
 	curlwp->l_name ? curlwp->l_name : "",
 	addr);
 
+	KASSERT(sc->sc_state == EC_STATE_FREE);
+
 	sc->sc_cur_addr = addr;
 	sc->sc_state = EC_STATE_READ;
 
@@ -737,6 +739,8 @@ acpiec_write(device_t dv, uint8_t addr, 
 	curlwp->l_name ? curlwp->l_name : "",
 	addr, val);
 
+	KASSERT(sc->sc_state == EC_STATE_FREE);
+
 	sc->sc_cur_addr = addr;
 	sc->sc_cur_val = val;
 	sc->sc_state = EC_STATE_WRITE;
@@ -899,6 +903,8 @@ loop:
 
 	DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI query\n");
 
+	KASSERT(sc->sc_state == EC_STATE_FREE);
+
 	/* The Query command can always be issued, so be defensive here. */
 	sc->sc_got_sci = false;
 	sc->sc_state = EC_STATE_QUERY;



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:03:47 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Sprinkle comments.

Note where this code is abusing cv_wait and needs a loop to handle
spurious wakeups.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.89 src/sys/dev/acpi/acpi_ec.c:1.90
--- src/sys/dev/acpi/acpi_ec.c:1.89	Tue Jul 18 10:03:35 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:03:46 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.89 2023/07/18 10:03:35 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.90 2023/07/18 10:03:46 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -57,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.89 2023/07/18 10:03:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.90 2023/07/18 10:03:46 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -694,6 +694,11 @@ acpiec_read(device_t dv, uint8_t addr, u
 			return AE_ERROR;
 		}
 	} else if (cv_timedwait(>sc_cv, >sc_mtx, EC_CMD_TIMEOUT * hz)) {
+		/*
+		 * XXX while (sc->sc_state != EC_STATE_FREE)
+		 *	cv_timedwait(...),
+		 * plus deadline
+		 */
 		mutex_exit(>sc_mtx);
 		acpiec_unlock(dv);
 		aprint_error_dev(dv,
@@ -756,6 +761,11 @@ acpiec_write(device_t dv, uint8_t addr, 
 			return AE_ERROR;
 		}
 	} else if (cv_timedwait(>sc_cv, >sc_mtx, EC_CMD_TIMEOUT * hz)) {
+		/*
+		 * XXX while (sc->sc_state != EC_STATE_FREE)
+		 *	cv_timedwait(...),
+		 * plus deadline
+		 */
 		mutex_exit(>sc_mtx);
 		acpiec_unlock(dv);
 		aprint_error_dev(dv,
@@ -869,13 +879,21 @@ acpiec_gpe_query(void *arg)
 	int i;
 
 loop:
+	/*
+	 * Wait until the EC sends an SCI requesting a query.
+	 *
+	 * XXX This needs to be `while', not `if'.
+	 */
 	mutex_enter(>sc_mtx);
-
 	if (sc->sc_got_sci == false)
 		cv_wait(>sc_cv_sci, >sc_mtx);
 	DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI query requested\n");
 	mutex_exit(>sc_mtx);
 
+	/*
+	 * EC wants to submit a query to us.  Exclude concurrent reads
+	 * and writes while we handle it.
+	 */
 	acpiec_lock(dv);
 	mutex_enter(>sc_mtx);
 
@@ -893,6 +911,7 @@ loop:
 	}
 
 	DPRINTF(ACPIEC_DEBUG_QUERY, sc, "SCI polling timeout\n");
+	/* XXX while (sc->sc_state != EC_STATE_FREE) cv_wait(...) */
 	cv_wait(>sc_cv, >sc_mtx);
 
 done:
@@ -951,17 +970,14 @@ acpiec_gpe_state_machine(device_t dv)
 	case EC_STATE_QUERY_VAL:
 		if ((reg & EC_STATUS_OBF) == 0)
 			break; /* Nothing of interest here. */
-
 		sc->sc_cur_val = acpiec_read_data(sc);
 		sc->sc_state = EC_STATE_FREE;
-
 		cv_signal(>sc_cv);
 		break;
 
 	case EC_STATE_READ:
 		if ((reg & EC_STATUS_IBF) != 0)
 			break; /* Nothing of interest here. */
-
 		acpiec_write_command(sc, EC_COMMAND_READ);
 		sc->sc_state = EC_STATE_READ_ADDR;
 		break;
@@ -969,7 +985,6 @@ acpiec_gpe_state_machine(device_t dv)
 	case EC_STATE_READ_ADDR:
 		if ((reg & EC_STATUS_IBF) != 0)
 			break; /* Nothing of interest here. */
-
 		acpiec_write_data(sc, sc->sc_cur_addr);
 		sc->sc_state = EC_STATE_READ_VAL;
 		break;
@@ -979,14 +994,12 @@ acpiec_gpe_state_machine(device_t dv)
 			break; /* Nothing of interest here. */
 		sc->sc_cur_val = acpiec_read_data(sc);
 		sc->sc_state = EC_STATE_FREE;
-
 		cv_signal(>sc_cv);
 		break;
 
 	case EC_STATE_WRITE:
 		if ((reg & EC_STATUS_IBF) != 0)
 			break; /* Nothing of interest here. */
-
 		acpiec_write_command(sc, EC_COMMAND_WRITE);
 		sc->sc_state = EC_STATE_WRITE_ADDR;
 		break;
@@ -1003,7 +1016,6 @@ acpiec_gpe_state_machine(device_t dv)
 			break; /* Nothing of interest here. */
 		sc->sc_state = EC_STATE_FREE;
 		cv_signal(>sc_cv);
-
 		acpiec_write_data(sc, sc->sc_cur_val);
 		break;
 
@@ -1014,10 +1026,15 @@ acpiec_gpe_state_machine(device_t dv)
 			cv_signal(>sc_cv_sci);
 		}
 		break;
+
 	default:
 		panic("invalid state");
 	}
 
+	/*
+	 * In case GPE interrupts are broken, poll once per tick for EC
+	 * status updates while a transaction is still pending.
+	 */
 	if (sc->sc_state != EC_STATE_FREE) {
 		DPRINTF(ACPIEC_DEBUG_INTR, sc, "schedule callout\n");
 		callout_schedule(>sc_pseudo_intr, 1);



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:03:47 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Sprinkle comments.

Note where this code is abusing cv_wait and needs a loop to handle
spurious wakeups.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:03:35 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Clarify lock order and sprinkle lock assertions.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.88 src/sys/dev/acpi/acpi_ec.c:1.89
--- src/sys/dev/acpi/acpi_ec.c:1.88	Tue Jul 18 10:02:25 2023
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:03:35 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.88 2023/07/18 10:02:25 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.89 2023/07/18 10:03:35 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -34,14 +34,12 @@
  * - read and write access from ASL, e.g. to read battery state
  * - notification of ASL of System Control Interrupts.
  *
- * Access to the EC is serialised by sc_access_mtx and optionally the
- * ACPI global mutex.  Both locks are held until the request is fulfilled.
- * All access to the softc has to hold sc_mtx to serialise against the GPE
- * handler and the callout.  sc_mtx is also used for wakeup conditions.
+ * Lock order:
+ *	sc_access_mtx (serializes EC transactions -- read, write, or SCI)
+ *	-> ACPI global lock (excludes other ACPI access during EC transaction)
+ *	-> sc_mtx (serializes state machine transitions and waits)
  *
- * SCIs are processed in a kernel thread. Handling gets a bit complicated
- * by the lock order (sc_mtx must be acquired after sc_access_mtx and the
- * ACPI global mutex).
+ * SCIs are processed in a kernel thread.
  *
  * Read and write requests spin around for a short time as many requests
  * can be handled instantly by the EC.  During normal processing interrupt
@@ -59,7 +57,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.88 2023/07/18 10:02:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.89 2023/07/18 10:03:35 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_acpi_ec.h"
@@ -566,6 +564,8 @@ acpiec_read_data(struct acpiec_softc *sc
 {
 	uint8_t x;
 
+	KASSERT(mutex_owned(>sc_mtx));
+
 	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);
 
@@ -576,6 +576,8 @@ static void
 acpiec_write_data(struct acpiec_softc *sc, uint8_t val)
 {
 
+	KASSERT(mutex_owned(>sc_mtx));
+
 	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);
 }
@@ -585,6 +587,8 @@ acpiec_read_status(struct acpiec_softc *
 {
 	uint8_t x;
 
+	KASSERT(mutex_owned(>sc_mtx));
+
 	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);
 
@@ -595,6 +599,8 @@ static void
 acpiec_write_command(struct acpiec_softc *sc, uint8_t cmd)
 {
 
+	KASSERT(mutex_owned(>sc_mtx));
+
 	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);
 }
@@ -918,6 +924,8 @@ acpiec_gpe_state_machine(device_t dv)
 	struct acpiec_softc *sc = device_private(dv);
 	uint8_t reg;
 
+	KASSERT(mutex_owned(>sc_mtx));
+
 	reg = acpiec_read_status(sc);
 
 #ifdef ACPIEC_DEBUG



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:03:35 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Clarify lock order and sprinkle lock assertions.

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:02:09 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Record device_t self.

Not used yet, to be used soon for device_printf and to allow making
some of the internal functions a little more type-safe later.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.86 src/sys/dev/acpi/acpi_ec.c:1.87
--- src/sys/dev/acpi/acpi_ec.c:1.86	Fri Dec 31 17:22:25 2021
+++ src/sys/dev/acpi/acpi_ec.c	Tue Jul 18 10:02:09 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.86 2021/12/31 17:22:25 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.87 2023/07/18 10:02:09 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.86 2021/12/31 17:22:25 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.87 2023/07/18 10:02:09 riastradh Exp $");
 
 #include 
 #include 
@@ -119,6 +119,8 @@ enum ec_state_t {
 };
 
 struct acpiec_softc {
+	device_t sc_dev;
+
 	ACPI_HANDLE sc_ech;
 
 	ACPI_HANDLE sc_gpeh;
@@ -313,6 +315,8 @@ acpiec_common_attach(device_t parent, de
 	ACPI_STATUS rv;
 	ACPI_INTEGER val;
 
+	sc->sc_dev = self;
+
 	sc->sc_csr_st = cmdt;
 	sc->sc_data_st = datat;
 



CVS commit: src/sys/dev/acpi

2023-07-18 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Tue Jul 18 10:02:09 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_ec.c

Log Message:
acpiec(4): Record device_t self.

Not used yet, to be used soon for device_printf and to allow making
some of the internal functions a little more type-safe later.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/acpi/acpi_ec.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi/acpica

2023-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 10 01:23:28 UTC 2023

Modified Files:
src/sys/dev/acpi/acpica: acpi_func.h

Log Message:
acpi(4): Fix membars in ACPI_ACQUIRE/RELEASE_GLOBAL_LOCK.

XXX pullup-8 (by patch with membar_enter/exit)
XXX pullup-9 (by patch with membar_enter/exit)
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/acpica/acpi_func.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpica/acpi_func.h
diff -u src/sys/dev/acpi/acpica/acpi_func.h:1.6 src/sys/dev/acpi/acpica/acpi_func.h:1.7
--- src/sys/dev/acpi/acpica/acpi_func.h:1.6	Fri Oct 12 21:36:24 2018
+++ src/sys/dev/acpi/acpica/acpi_func.h	Wed May 10 01:23:27 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_func.h,v 1.6 2018/10/12 21:36:24 jmcneill Exp $	*/
+/*	$NetBSD: acpi_func.h,v 1.7 2023/05/10 01:23:27 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2000 Michael Smith
@@ -62,6 +62,7 @@ acpi_acquire_global_lock(uint32_t *lock)
 		((old >> 1) & GL_BIT_PENDING);
 		val = atomic_cas_32(lock, old, new);
 	} while (__predict_false(val != old));
+	membar_acquire();
 
 	return ((new < GL_BIT_MASK) ? GL_ACQUIRED : GL_BUSY);
 }
@@ -71,6 +72,7 @@ acpi_release_global_lock(uint32_t *lock)
 {
 	uint32_t new, old, val;
 
+	membar_release();
 	do {
 		old = *lock;
 		new = old & ~GL_BIT_MASK;



CVS commit: src/sys/dev/acpi/acpica

2023-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 10 01:23:28 UTC 2023

Modified Files:
src/sys/dev/acpi/acpica: acpi_func.h

Log Message:
acpi(4): Fix membars in ACPI_ACQUIRE/RELEASE_GLOBAL_LOCK.

XXX pullup-8 (by patch with membar_enter/exit)
XXX pullup-9 (by patch with membar_enter/exit)
XXX pullup-10


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/acpica/acpi_func.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi/wmi

2023-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 10 00:08:23 UTC 2023

Modified Files:
src/sys/dev/acpi/wmi: wmi_acpi.c

Log Message:
acpiwmi(4): Use config_detach_children.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/acpi/wmi/wmi_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi/wmi

2023-05-09 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Wed May 10 00:08:23 UTC 2023

Modified Files:
src/sys/dev/acpi/wmi: wmi_acpi.c

Log Message:
acpiwmi(4): Use config_detach_children.


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/acpi/wmi/wmi_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/wmi/wmi_acpi.c
diff -u src/sys/dev/acpi/wmi/wmi_acpi.c:1.20 src/sys/dev/acpi/wmi/wmi_acpi.c:1.21
--- src/sys/dev/acpi/wmi/wmi_acpi.c:1.20	Sun Dec 12 22:20:52 2021
+++ src/sys/dev/acpi/wmi/wmi_acpi.c	Wed May 10 00:08:22 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: wmi_acpi.c,v 1.20 2021/12/12 22:20:52 andvar Exp $	*/
+/*	$NetBSD: wmi_acpi.c,v 1.21 2023/05/10 00:08:22 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Jukka Ruohonen 
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.20 2021/12/12 22:20:52 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wmi_acpi.c,v 1.21 2023/05/10 00:08:22 riastradh Exp $");
 
 #include 
 #include 
@@ -126,18 +126,19 @@ static int
 acpi_wmi_detach(device_t self, int flags)
 {
 	struct acpi_wmi_softc *sc = device_private(self);
+	int error;
+
+	error = config_detach_children(self, flags);
+	if (error)
+		return error;
 
 	acpi_wmi_event_del(sc);
 
 	if (sc->sc_ecdev != NULL) {
-
 		(void)AcpiRemoveAddressSpaceHandler(sc->sc_node->ad_handle,
 		ACPI_ADR_SPACE_EC, acpi_wmi_ec_handler);
 	}
 
-	if (sc->sc_child != NULL)
-		(void)config_detach(sc->sc_child, flags);
-
 	acpi_wmi_del(sc);
 	pmf_device_deregister(self);
 



CVS commit: src/sys/dev/acpi

2023-03-17 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Mar 17 17:16:06 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_display.c

Log Message:
s/Brigthness/Brightness/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/acpi/acpi_display.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_display.c
diff -u src/sys/dev/acpi/acpi_display.c:1.22 src/sys/dev/acpi/acpi_display.c:1.23
--- src/sys/dev/acpi/acpi_display.c:1.22	Sun Feb 27 21:21:51 2022
+++ src/sys/dev/acpi/acpi_display.c	Fri Mar 17 17:16:06 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_display.c,v 1.22 2022/02/27 21:21:51 riastradh Exp $	*/
+/*	$NetBSD: acpi_display.c,v 1.23 2023/03/17 17:16:06 andvar Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.22 2022/02/27 21:21:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.23 2023/03/17 17:16:06 andvar Exp $");
 
 #include 
 #include 
@@ -848,7 +848,7 @@ acpidisp_out_capabilities(const struct a
 
 	cap = 0;
 
-	/* List of Brigthness levels */
+	/* List of Brightness levels */
 	if (acpidisp_has_method(ad->ad_handle, "_BCL", ACPI_TYPE_PACKAGE))
 		cap |= ACPI_DISP_OUT_CAP__BCL;
 



CVS commit: src/sys/dev/acpi

2023-03-17 Thread Andrius Varanavicius
Module Name:src
Committed By:   andvar
Date:   Fri Mar 17 17:16:06 UTC 2023

Modified Files:
src/sys/dev/acpi: acpi_display.c

Log Message:
s/Brigthness/Brightness/ in comment.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/acpi/acpi_display.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2022-08-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 12 16:21:41 UTC 2022

Modified Files:
src/sys/dev/acpi: thinkpad_acpi.c

Log Message:
thinkpad(4): Don't detach on shutdown.

There's no important state that needs to be recorded, or resources
that need to be relinquished, so detach-on-shutdown isn't necessary.

At the moment, detach-on-shutdown is actually harmful here: if
shutdown is triggered by a sysmon power switch event, then
config_detach will be called from the sysmon taskqueue, but
thinkpad_detach has to wait for ACPI notifiers to finish running
which means waiting for the sysmon taskqueue -> deadlock or crash.

We should maybe arrange to do config_detach from a thread other than
the sysmon taskqueue thread to avoid this class of problems -- but
for now, thinkpad(4) has no reason to detach on shutdown anyway, so
let's take the easy path.

Note: There are many drivers that set DVF_DETACH_SHUTDOWN which
probably shouldn't; the flag means the kernel _will_ detach on
shutdown, not that it _may_.  Even those that do need to record state
or relinquish resources might be better served by pmf shutdown hooks
which can skip freeing software resources for faster shutdown.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/acpi/thinkpad_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/acpi

2022-08-12 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Fri Aug 12 16:21:41 UTC 2022

Modified Files:
src/sys/dev/acpi: thinkpad_acpi.c

Log Message:
thinkpad(4): Don't detach on shutdown.

There's no important state that needs to be recorded, or resources
that need to be relinquished, so detach-on-shutdown isn't necessary.

At the moment, detach-on-shutdown is actually harmful here: if
shutdown is triggered by a sysmon power switch event, then
config_detach will be called from the sysmon taskqueue, but
thinkpad_detach has to wait for ACPI notifiers to finish running
which means waiting for the sysmon taskqueue -> deadlock or crash.

We should maybe arrange to do config_detach from a thread other than
the sysmon taskqueue thread to avoid this class of problems -- but
for now, thinkpad(4) has no reason to detach on shutdown anyway, so
let's take the easy path.

Note: There are many drivers that set DVF_DETACH_SHUTDOWN which
probably shouldn't; the flag means the kernel _will_ detach on
shutdown, not that it _may_.  Even those that do need to record state
or relinquish resources might be better served by pmf shutdown hooks
which can skip freeing software resources for faster shutdown.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/dev/acpi/thinkpad_acpi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/thinkpad_acpi.c
diff -u src/sys/dev/acpi/thinkpad_acpi.c:1.54 src/sys/dev/acpi/thinkpad_acpi.c:1.55
--- src/sys/dev/acpi/thinkpad_acpi.c:1.54	Fri Dec 31 17:22:35 2021
+++ src/sys/dev/acpi/thinkpad_acpi.c	Fri Aug 12 16:21:41 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: thinkpad_acpi.c,v 1.54 2021/12/31 17:22:35 riastradh Exp $ */
+/* $NetBSD: thinkpad_acpi.c,v 1.55 2022/08/12 16:21:41 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.54 2021/12/31 17:22:35 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.55 2022/08/12 16:21:41 riastradh Exp $");
 
 #include 
 #include 
@@ -170,7 +170,7 @@ static void	thinkpad_cmos(thinkpad_softc
 
 CFATTACH_DECL3_NEW(thinkpad, sizeof(thinkpad_softc_t),
 thinkpad_match, thinkpad_attach, thinkpad_detach, NULL, NULL, NULL,
-DVF_DETACH_SHUTDOWN);
+0);
 
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "IBM0068" },



CVS commit: src/sys/dev/acpi

2022-07-22 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jul 23 03:08:17 UTC 2022

Modified Files:
src/sys/dev/acpi: acpi_i2c.c acpi_util.c acpi_util.h

Log Message:
- Handle dtlink in acpi_pack_compat_list().
- Don't pass the _HID value as the device name; always use the ACPI
  node name.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/acpi/acpi_i2c.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/acpi/acpi_util.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



  1   2   3   4   >