CVS commit: src/sys/dev/acpi

2021-08-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Aug  9 04:06:21 UTC 2021

Added Files:
src/sys/dev/acpi: acpi_i2c.h

Log Message:
Fix CVS eff-up.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.4 src/sys/dev/acpi/acpi_i2c.h

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

Added files:

Index: src/sys/dev/acpi/acpi_i2c.h
diff -u /dev/null src/sys/dev/acpi/acpi_i2c.h:1.4
--- /dev/null	Mon Aug  9 04:06:21 2021
+++ src/sys/dev/acpi/acpi_i2c.h	Mon Aug  9 04:06:21 2021
@@ -0,0 +1,38 @@
+/* $NetBSD: acpi_i2c.h,v 1.4 2021/08/09 04:06:21 thorpej Exp $ */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Manuel Bouyer.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+
+#ifndef _SYS_DEV_ACPI_ACPI_I2C_H
+#define _SYS_DEV_ACPI_ACPI_I2C_H
+#include 
+
+prop_array_t acpi_enter_i2c_devs(device_t, struct acpi_devnode *);
+#endif /*  _SYS_DEV_ACPI_ACPI_I2C_H */



CVS commit: src/sys/dev/acpi

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 21:19:16 UTC 2021

Modified Files:
src/sys/dev/acpi: acpi_mcfg.c acpi_mcfg.h

Log Message:
acpi: expose acpimcfg_configure_bus_cb


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/acpi/acpi_mcfg.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/acpi_mcfg.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/acpi_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.23 src/sys/dev/acpi/acpi_mcfg.c:1.24
--- src/sys/dev/acpi/acpi_mcfg.c:1.23	Tue Jan 26 15:30:05 2021
+++ src/sys/dev/acpi/acpi_mcfg.c	Sat Aug  7 21:19:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.23 2021/01/26 15:30:05 skrll Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.24 2021/08/07 21:19:15 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.23 2021/01/26 15:30:05 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.24 2021/08/07 21:19:15 jmcneill Exp $");
 
 #include 
 #include 
@@ -693,7 +693,7 @@ out:
 }
 
 #ifdef PCI_NETBSD_CONFIGURE
-static ACPI_STATUS
+ACPI_STATUS
 acpimcfg_configure_bus_cb(ACPI_RESOURCE *res, void *ctx)
 {
 	struct pciconf_resources *pcires = ctx;

Index: src/sys/dev/acpi/acpi_mcfg.h
diff -u src/sys/dev/acpi/acpi_mcfg.h:1.3 src/sys/dev/acpi/acpi_mcfg.h:1.4
--- src/sys/dev/acpi/acpi_mcfg.h:1.3	Sun Feb  2 16:31:25 2020
+++ src/sys/dev/acpi/acpi_mcfg.h	Sat Aug  7 21:19:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.h,v 1.3 2020/02/02 16:31:25 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.h,v 1.4 2021/08/07 21:19:15 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -33,6 +33,7 @@ void	acpimcfg_probe(struct acpi_softc *)
 int	acpimcfg_init(bus_space_tag_t, const struct acpimcfg_ops *);
 int	acpimcfg_map_bus(device_t, pci_chipset_tag_t, int);
 int	acpimcfg_configure_bus(device_t, pci_chipset_tag_t, ACPI_HANDLE, int, int);
+ACPI_STATUS acpimcfg_configure_bus_cb(ACPI_RESOURCE *, void *);
 
 int	acpimcfg_conf_read(pci_chipset_tag_t, pcitag_t, int, pcireg_t *);
 int	acpimcfg_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);



CVS commit: src/sys/dev/acpi

2021-08-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Aug  7 18:39:40 UTC 2021

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

Log Message:
acpi: Add acpi_resource_parse_any().

Like acpi_resource_parse(), but doesn't exclude "produced" resources.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/dev/acpi/acpi_resource.c
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/acpi/acpivar.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/acpi_resource.c
diff -u src/sys/dev/acpi/acpi_resource.c:1.41 src/sys/dev/acpi/acpi_resource.c:1.42
--- src/sys/dev/acpi/acpi_resource.c:1.41	Tue Dec 31 17:26:04 2019
+++ src/sys/dev/acpi/acpi_resource.c	Sat Aug  7 18:39:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_resource.c,v 1.41 2019/12/31 17:26:04 jmcneill Exp $	*/
+/*	$NetBSD: acpi_resource.c,v 1.42 2021/08/07 18:39:40 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.41 2019/12/31 17:26:04 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.42 2021/08/07 18:39:40 jmcneill Exp $");
 
 #include 
 #include 
@@ -83,6 +83,7 @@ static ACPI_STATUS acpi_resource_parse_c
 
 struct resource_parse_callback_arg {
 	const struct acpi_resource_parse_ops *ops;
+	bool include_producer;
 	device_t dev;
 	void *context;
 };
@@ -247,7 +248,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 	case ACPI_RESOURCE_TYPE_ADDRESS32:
 		/* XXX Only fixed size supported for now */
 		if (res->Data.Address32.Address.AddressLength == 0 ||
-		res->Data.Address32.ProducerConsumer != ACPI_CONSUMER)
+		(!arg->include_producer &&
+		 res->Data.Address32.ProducerConsumer != ACPI_CONSUMER))
 			break;
 #define ADDRESS32_FIXED2(r)		\
 	((r)->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&	\
@@ -302,7 +304,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 #ifdef _LP64
 		/* XXX Only fixed size supported for now */
 		if (res->Data.Address64.Address.AddressLength == 0 ||
-		res->Data.Address64.ProducerConsumer != ACPI_CONSUMER)
+		(!arg->include_producer &&
+		 res->Data.Address64.ProducerConsumer != ACPI_CONSUMER))
 			break;
 #define ADDRESS64_FIXED2(r)		\
 	((r)->Data.Address64.MinAddressFixed == ACPI_ADDRESS_FIXED &&	\
@@ -357,7 +360,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 		break;
 
 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
-		if (res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
+		if (!arg->include_producer &&
+		res->Data.ExtendedIrq.ProducerConsumer != ACPI_CONSUMER) {
 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
 			"ignored ExtIRQ producer\n"));
 			break;
@@ -420,6 +424,7 @@ acpi_resource_parse(device_t dev, ACPI_H
 		cbarg.context = arg;
 	cbarg.ops = ops;
 	cbarg.dev = dev;
+	cbarg.include_producer = false;
 
 	rv = AcpiWalkResources(handle, path, acpi_resource_parse_callback,
 	);
@@ -436,6 +441,45 @@ acpi_resource_parse(device_t dev, ACPI_H
 }
 
 /*
+ * acpi_resource_parse_any:
+ *
+ *	Parse a device node's resources and fill them in for the
+ *	client. Like acpi_resource_parse, but doesn't skip ResourceProducer
+ *	type resources.
+ */
+ACPI_STATUS
+acpi_resource_parse_any(device_t dev, ACPI_HANDLE handle, const char *path,
+void *arg, const struct acpi_resource_parse_ops *ops)
+{
+	struct resource_parse_callback_arg cbarg;
+	ACPI_STATUS rv;
+
+	ACPI_FUNCTION_TRACE(__func__);
+
+	if (ops->init)
+		(*ops->init)(dev, arg, );
+	else
+		cbarg.context = arg;
+	cbarg.ops = ops;
+	cbarg.dev = dev;
+	cbarg.include_producer = true;
+
+	rv = AcpiWalkResources(handle, path, acpi_resource_parse_callback,
+	);
+	if (ACPI_FAILURE(rv)) {
+		aprint_error_dev(dev, "ACPI: unable to get %s resources: %s\n",
+		path, AcpiFormatException(rv));
+		return_ACPI_STATUS(rv);
+	}
+
+	if (ops->fini)
+		(*ops->fini)(dev, cbarg.context);
+
+	return_ACPI_STATUS(AE_OK);
+}
+
+
+/*
  * acpi_resource_print:
  *
  *	Print the resources assigned to a device.

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.86 src/sys/dev/acpi/acpivar.h:1.87
--- src/sys/dev/acpi/acpivar.h:1.86	Wed May 12 23:22:33 2021
+++ src/sys/dev/acpi/acpivar.h	Sat Aug  7 18:39:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.86 2021/05/12 23:22:33 thorpej Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.87 2021/08/07 18:39:40 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -330,6 +330,8 @@ void		acpi_deregister_notify(struct acpi
 
 ACPI_STATUS	acpi_resource_parse(device_t, ACPI_HANDLE, const char *,
 		void *, const struct acpi_resource_parse_ops *);
+ACPI_STATUS	acpi_resource_parse_any(device_t, ACPI_HANDLE, const char *,
+		void *, const struct acpi_resource_parse_ops *);
 void		acpi_resource_print(device_t, struct acpi_resources *);
 void		acpi_resource_cleanup(struct acpi_resources *);
 



CVS commit: src/sys/dev/acpi

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Jul 25 01:43:08 UTC 2021

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

Log Message:
acpi_timer: use ACPI-Fast if WAET timer one read flag is set

The Windows ACPI Emulated Devices Table (WAET) has a hint to inform the OS
that a single read of the PM timer is reliable. Honour this flag.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/acpi/acpi_timer.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_timer.c
diff -u src/sys/dev/acpi/acpi_timer.c:1.26 src/sys/dev/acpi/acpi_timer.c:1.27
--- src/sys/dev/acpi/acpi_timer.c:1.26	Fri May 29 12:30:41 2020
+++ src/sys/dev/acpi/acpi_timer.c	Sun Jul 25 01:43:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_timer.c,v 1.26 2020/05/29 12:30:41 rin Exp $ */
+/* $NetBSD: acpi_timer.c,v 1.27 2021/07/25 01:43:08 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2006 Matthias Drochner 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_timer.c,v 1.26 2020/05/29 12:30:41 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_timer.c,v 1.27 2021/07/25 01:43:08 jmcneill Exp $");
 
 #include 
 #include 
@@ -61,6 +61,7 @@ int
 acpitimer_init(struct acpi_softc *sc)
 {
 #if (!ACPI_REDUCED_HARDWARE)
+	ACPI_TABLE_WAET *waet;
 	ACPI_STATUS rv;
 	uint32_t bits;
 	int i, j;
@@ -79,6 +80,18 @@ acpitimer_init(struct acpi_softc *sc)
 	for (i = j = 0; i < 10; i++)
 		j += acpitimer_test();
 
+	rv = AcpiGetTable(ACPI_SIG_WAET, 0, (ACPI_TABLE_HEADER **));
+	if (ACPI_SUCCESS(rv)) {
+		/*
+		 * Windows ACPI Emulated Devices Table (WAET) has a hint
+		 * to let the OS know that a single read of the PM timer
+		 * provides a reliable value.
+		 */
+		if ((waet->Flags & ACPI_WAET_TIMER_ONE_READ) != 0) {
+			j += 10;
+		}
+	}
+
 	if (j >= 10) {
 		acpi_timecounter.tc_name = "ACPI-Fast";
 		acpi_timecounter.tc_get_timecount = acpitimer_read_fast;



CVS commit: src/sys/dev/acpi

2021-07-24 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jul 24 11:36:41 UTC 2021

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

Log Message:
acpi: /dev/acpi: fix bounds check when reading tables


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/acpi_dev.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_dev.c
diff -u src/sys/dev/acpi/acpi_dev.c:1.1 src/sys/dev/acpi/acpi_dev.c:1.2
--- src/sys/dev/acpi/acpi_dev.c:1.1	Sun Dec  6 02:57:30 2020
+++ src/sys/dev/acpi/acpi_dev.c	Sat Jul 24 11:36:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_dev.c,v 1.1 2020/12/06 02:57:30 jmcneill Exp $ */
+/* $NetBSD: acpi_dev.c,v 1.2 2021/07/24 11:36:41 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_dev.c,v 1.1 2020/12/06 02:57:30 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_dev.c,v 1.2 2021/07/24 11:36:41 jmcneill Exp $");
 
 #include 
 #include 
@@ -208,7 +208,7 @@ acpi_read(dev_t dev, struct uio *uio, in
 
 	/* Copy the contents of the table to user-space */
 	pa = uio->uio_offset;
-	len = uimin(pa - table_pa + table_len, uio->uio_resid);
+	len = uimin(table_len - (pa - table_pa), uio->uio_resid);
 	data = AcpiOsMapMemory(pa, len);
 	if (data == NULL) {
 		return ENOMEM;



CVS commit: src/sys/dev/acpi

2021-05-30 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun May 30 11:24:11 UTC 2021

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

Log Message:
thinkpad(4): Fix evaluation of MHKA on version 2 devices.

Need to pass an argument.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 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.52 src/sys/dev/acpi/thinkpad_acpi.c:1.53
--- src/sys/dev/acpi/thinkpad_acpi.c:1.52	Sat May 29 16:49:57 2021
+++ src/sys/dev/acpi/thinkpad_acpi.c	Sun May 30 11:24:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: thinkpad_acpi.c,v 1.52 2021/05/29 16:49:57 riastradh Exp $ */
+/* $NetBSD: thinkpad_acpi.c,v 1.53 2021/05/30 11:24:10 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.52 2021/05/29 16:49:57 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.53 2021/05/30 11:24:10 riastradh Exp $");
 
 #include 
 #include 
@@ -55,6 +55,7 @@ typedef struct thinkpad_softc {
 	struct acpi_devnode	*sc_node;
 	ACPI_HANDLE		sc_powhdl;
 	ACPI_HANDLE		sc_cmoshdl;
+	ACPI_INTEGER		sc_ver;
 
 #define	TP_PSW_SLEEP		0	/* FnF4 */
 #define	TP_PSW_HIBERNATE	1	/* FnF12 */
@@ -241,13 +242,58 @@ thinkpad_attach(device_t parent, device_
 		aprint_debug_dev(self, "using EC at %s\n",
 		device_xname(sc->sc_ecdev));
 
-	/* Get the supported event mask */
-	rv = acpi_eval_integer(sc->sc_node->ad_handle, "MHKA", );
+	/* Query the version number */
+	rv = acpi_eval_integer(aa->aa_node->ad_handle, "MHKV", >sc_ver);
 	if (ACPI_FAILURE(rv)) {
-		aprint_error_dev(self, "couldn't evaluate MHKA: %s\n",
+		aprint_error_dev(self, "couldn't evaluate MHKV: %s\n",
 		AcpiFormatException(rv));
 		goto fail;
 	}
+	aprint_normal_dev(self, "version %04x\n", (unsigned)sc->sc_ver);
+
+	/* Get the supported event mask */
+	switch (sc->sc_ver) {
+	case THINKPAD_HKEY_VERSION_1:
+		rv = acpi_eval_integer(sc->sc_node->ad_handle, "MHKA", );
+		if (ACPI_FAILURE(rv)) {
+			aprint_error_dev(self, "couldn't evaluate MHKA: %s\n",
+			AcpiFormatException(rv));
+			goto fail;
+		}
+		break;
+	case THINKPAD_HKEY_VERSION_2: {
+		ACPI_OBJECT args[1] = {
+			[0] = { .Integer = {
+.Type = ACPI_TYPE_INTEGER,
+.Value = 1, /* hotkey events */
+			} },
+		};
+		ACPI_OBJECT_LIST arglist = {
+			.Count = __arraycount(args),
+			.Pointer = args,
+		};
+		ACPI_OBJECT ret;
+		ACPI_BUFFER buf = { .Pointer = , .Length = sizeof(ret) };
+
+		rv = AcpiEvaluateObject(sc->sc_node->ad_handle, "MHKA",
+		, );
+		if (ACPI_FAILURE(rv)) {
+			aprint_error_dev(self, "couldn't evaluate MHKA(1):"
+			" %s\n",
+			AcpiFormatException(rv));
+			goto fail;
+		}
+		if (buf.Length == 0 || ret.Type != ACPI_TYPE_INTEGER) {
+			aprint_error_dev(self, "failed to evaluate MHKA(1)\n");
+			goto fail;
+		}
+		val = ret.Integer.Value;
+		break;
+	}
+	default:
+		panic("%s: invalid version %jd", device_xname(self),
+		(intmax_t)sc->sc_ver);
+	}
 
 	/* Enable all supported events */
 	rv = thinkpad_mask_init(sc, val);



CVS commit: src/sys/dev/acpi

2021-05-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May 29 16:49:49 UTC 2021

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

Log Message:
thinkpad(4): Add dtrace probe for hotkey events.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 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.50 src/sys/dev/acpi/thinkpad_acpi.c:1.51
--- src/sys/dev/acpi/thinkpad_acpi.c:1.50	Sat May 29 16:49:39 2021
+++ src/sys/dev/acpi/thinkpad_acpi.c	Sat May 29 16:49:49 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: thinkpad_acpi.c,v 1.50 2021/05/29 16:49:39 riastradh Exp $ */
+/* $NetBSD: thinkpad_acpi.c,v 1.51 2021/05/29 16:49:49 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,11 +27,12 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.50 2021/05/29 16:49:39 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.51 2021/05/29 16:49:49 riastradh Exp $");
 
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -363,6 +364,10 @@ thinkpad_notify_handler(ACPI_HANDLE hdl,
 	(void)AcpiOsExecute(OSL_NOTIFY_HANDLER, thinkpad_get_hotkeys, sc);
 }
 
+SDT_PROBE_DEFINE2(sdt, thinkpad, hotkey, MHKP,
+"struct thinkpad_softc *"/*sc*/,
+"ACPI_INTEGER"/*val*/);
+
 static void
 thinkpad_get_hotkeys(void *opaque)
 {
@@ -379,6 +384,7 @@ thinkpad_get_hotkeys(void *opaque)
 			AcpiFormatException(rv));
 			return;
 		}
+		SDT_PROBE2(sdt, thinkpad, hotkey, MHKP,  sc, val);
 
 		if (val == 0)
 			return;



CVS commit: src/sys/dev/acpi

2021-05-29 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sat May 29 16:49:39 UTC 2021

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

Log Message:
thinkpad(4): Attach at LEN0268 with v2 Thinkpad hotkeys too.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 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.49 src/sys/dev/acpi/thinkpad_acpi.c:1.50
--- src/sys/dev/acpi/thinkpad_acpi.c:1.49	Fri Jan 29 15:49:55 2021
+++ src/sys/dev/acpi/thinkpad_acpi.c	Sat May 29 16:49:39 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: thinkpad_acpi.c,v 1.49 2021/01/29 15:49:55 thorpej Exp $ */
+/* $NetBSD: thinkpad_acpi.c,v 1.50 2021/05/29 16:49:39 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.49 2021/01/29 15:49:55 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.50 2021/05/29 16:49:39 riastradh Exp $");
 
 #include 
 #include 
@@ -111,7 +111,8 @@ typedef struct thinkpad_softc {
 #define	THINKPAD_CMOS_BRIGHTNESS_UP	0x04
 #define	THINKPAD_CMOS_BRIGHTNESS_DOWN	0x05
 
-#define	THINKPAD_HKEY_VERSION		0x0100
+#define	THINKPAD_HKEY_VERSION_1		0x0100
+#define	THINKPAD_HKEY_VERSION_2		0x0200
 
 #define	THINKPAD_DISPLAY_LCD		0x01
 #define	THINKPAD_DISPLAY_CRT		0x02
@@ -164,6 +165,7 @@ CFATTACH_DECL3_NEW(thinkpad, sizeof(thin
 static const struct device_compatible_entry compat_data[] = {
 	{ .compat = "IBM0068" },
 	{ .compat = "LEN0068" },
+	{ .compat = "LEN0268" },
 	DEVICE_COMPAT_EOL
 };
 
@@ -178,13 +180,18 @@ thinkpad_match(device_t parent, cfdata_t
 	if (ret == 0)
 		return 0;
 
-	/* We only support hotkey version 0x0100 */
+	/* We only support hotkey versions 0x0100 and 0x0200 */
 	if (ACPI_FAILURE(acpi_eval_integer(aa->aa_node->ad_handle, "MHKV",
 	)))
 		return 0;
 
-	if (ver != THINKPAD_HKEY_VERSION)
+	switch (ver) {
+	case THINKPAD_HKEY_VERSION_1:
+	case THINKPAD_HKEY_VERSION_2:
+		break;
+	default:
 		return 0;
+	}
 
 	/* Cool, looks like we're good to go */
 	return ret;



CVS commit: src/sys/dev/acpi

2021-02-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb  5 17:13:40 UTC 2021

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

Log Message:
Assign device handles to "at acpi" and "at pci" devices in
acpi_device_register().


To generate a diff of this commit:
cvs rdiff -u -r1.289 -r1.290 src/sys/dev/acpi/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/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.289 src/sys/dev/acpi/acpi.c:1.290
--- src/sys/dev/acpi/acpi.c:1.289	Thu Feb  4 21:39:00 2021
+++ src/sys/dev/acpi/acpi.c	Fri Feb  5 17:13:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.289 2021/02/04 21:39:00 thorpej Exp $	*/
+/*	$NetBSD: acpi.c,v 1.290 2021/02/05 17:13:40 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.289 2021/02/04 21:39:00 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.290 2021/02/05 17:13:40 thorpej Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -1130,9 +1130,42 @@ acpi_print(void *aux, const char *pnp)
  *	attaching devices.
  */
 void
-acpi_device_register(device_t dev __unused, void *v __unused)
+acpi_device_register(device_t dev, void *v)
 {
-	/* Placeholder. */
+	/* All we do here is set the devhandle in the device_t. */
+	device_t parent = device_parent(dev);
+	ACPI_HANDLE hdl = NULL;
+
+	/*
+	 * aa_node is only valid if we attached to the "acpinodebus"
+	 * interface attribute.
+	 */
+	if (device_attached_to_iattr(dev, "acpinodebus")) {
+		const struct acpi_attach_args *aa = v;
+		hdl = aa->aa_node->ad_handle;
+	} else if (device_is_a(parent, "pci")) {
+		const struct pci_attach_args *pa = v;
+		struct acpi_devnode *ad;
+		u_int segment;
+
+#ifdef __HAVE_PCI_GET_SEGMENT
+		segment = pci_get_segment(pa->pa_pc);
+#else
+		segment = 0;
+#endif /* __HAVE_PCI_GET_SEGMENT */
+
+		ad = acpi_pcidev_find(segment,
+		pa->pa_bus, pa->pa_device, pa->pa_function);
+		if (ad == NULL || (hdl = ad->ad_handle) == NULL) {
+			aprint_debug_dev(dev, "no matching ACPI node\n");
+			return;
+		}
+	} else {
+		return;
+	}
+	KASSERT(hdl != NULL);
+
+	device_set_handle(dev, devhandle_from_acpi(hdl));
 }
 
 /*



CVS commit: src/sys/dev/acpi

2021-02-05 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Feb  5 17:12:43 UTC 2021

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

Log Message:
ACPI device handle implementation.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.10 -r1.11 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.

Modified files:

Index: src/sys/dev/acpi/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.23 src/sys/dev/acpi/acpi_util.c:1.24
--- src/sys/dev/acpi/acpi_util.c:1.23	Wed Jan 27 05:11:54 2021
+++ src/sys/dev/acpi/acpi_util.c	Fri Feb  5 17:12:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.23 2021/01/27 05:11:54 thorpej Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.24 2021/02/05 17:12:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007, 2021 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.23 2021/01/27 05:11:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.24 2021/02/05 17:12:43 thorpej Exp $");
 
 #include 
 #include 
@@ -88,6 +88,75 @@ static const char * const acpicpu_ids[] 
 };
 
 /*
+ * ACPI device handle support.
+ */
+
+static device_call_t
+acpi_devhandle_lookup_device_call(devhandle_t handle, const char *name,
+devhandle_t *call_handlep)
+{
+	__link_set_decl(acpi_device_calls, struct device_call_descriptor);
+	struct device_call_descriptor * const *desc;
+
+	__link_set_foreach(desc, acpi_device_calls) {
+		if (strcmp((*desc)->name, name) == 0) {
+			return (*desc)->call;
+		}
+	}
+	return NULL;
+}
+
+static const struct devhandle_impl acpi_devhandle_impl = {
+	.type = DEVHANDLE_TYPE_ACPI,
+	.lookup_device_call = acpi_devhandle_lookup_device_call,
+};
+
+devhandle_t
+devhandle_from_acpi(ACPI_HANDLE const hdl)
+{
+	devhandle_t handle = {
+		.impl = _devhandle_impl,
+		.pointer = hdl,
+	};
+
+	return handle;
+}
+
+ACPI_HANDLE
+devhandle_to_acpi(devhandle_t const handle)
+{
+	KASSERT(devhandle_type(handle) == DEVHANDLE_TYPE_ACPI);
+
+	return handle.pointer;
+}
+
+static int
+acpi_device_enumerate_children(device_t dev, devhandle_t call_handle, void *v)
+{
+	struct device_enumerate_children_args *args = v;
+	ACPI_HANDLE hdl = devhandle_to_acpi(call_handle);
+	struct acpi_devnode *devnode, *ad;
+
+	devnode = acpi_match_node(hdl);
+	KASSERT(devnode != NULL);
+
+	SIMPLEQ_FOREACH(ad, >ad_child_head, ad_child_list) {
+		if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE ||
+		!acpi_device_present(ad->ad_handle)) {
+			continue;
+		}
+		if (!args->callback(dev, devhandle_from_acpi(ad->ad_handle),
+args->callback_arg)) {
+			break;
+		}
+	}
+
+	return 0;
+}
+ACPI_DEVICE_CALL_REGISTER("device-enumerate-children",
+			  acpi_device_enumerate_children)
+
+/*
  * Evaluate an integer object.
  */
 ACPI_STATUS

Index: src/sys/dev/acpi/acpi_util.h
diff -u src/sys/dev/acpi/acpi_util.h:1.10 src/sys/dev/acpi/acpi_util.h:1.11
--- src/sys/dev/acpi/acpi_util.h:1.10	Tue Jan 26 00:19:53 2021
+++ src/sys/dev/acpi/acpi_util.h	Fri Feb  5 17:12:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.h,v 1.10 2021/01/26 00:19:53 jmcneill Exp $ */
+/*	$NetBSD: acpi_util.h,v 1.11 2021/02/05 17:12:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -67,6 +67,12 @@
 #ifndef _SYS_DEV_ACPI_ACPI_UTIL_H
 #define _SYS_DEV_ACPI_ACPI_UTIL_H
 
+devhandle_t	devhandle_from_acpi(ACPI_HANDLE);
+ACPI_HANDLE	devhandle_to_acpi(devhandle_t);
+
+#define	ACPI_DEVICE_CALL_REGISTER(_n_, _c_)\
+	DEVICE_CALL_REGISTER(acpi_device_calls, _n_, _c_)
+
 ACPI_STATUS	acpi_eval_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
 ACPI_STATUS	acpi_eval_set_integer(ACPI_HANDLE handle, const char *path,
 		ACPI_INTEGER arg);



CVS commit: src/sys/dev/acpi

2021-02-04 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Feb  4 23:59:46 UTC 2021

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

Log Message:
Use acpi_compatible_match().


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/dwiic_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/dwiic_acpi.c
diff -u src/sys/dev/acpi/dwiic_acpi.c:1.6 src/sys/dev/acpi/dwiic_acpi.c:1.7
--- src/sys/dev/acpi/dwiic_acpi.c:1.6	Tue Jan 26 00:19:53 2021
+++ src/sys/dev/acpi/dwiic_acpi.c	Thu Feb  4 23:59:46 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwiic_acpi.c,v 1.6 2021/01/26 00:19:53 jmcneill Exp $ */
+/* $NetBSD: dwiic_acpi.c,v 1.7 2021/02/04 23:59:46 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.6 2021/01/26 00:19:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.7 2021/02/04 23:59:46 thorpej Exp $");
 
 #include 
 #include 
@@ -59,12 +59,12 @@ static void	dwiic_acpi_configure(struct 
 
 CFATTACH_DECL_NEW(dwiic_acpi, sizeof(struct dwiic_softc), dwiic_acpi_match, dwiic_acpi_attach, NULL, NULL);
 
-static const char * const compatible[] = {
-	"AMD0010",	/* AMD FCH */
-	"AMDI0010",	/* AMD FCH */
-	"AMDI0510",	/* AMD Seattle */
-	"APMC0D0F",	/* Ampere eMAG */
-	NULL
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "AMD0010" },	/* AMD FCH */
+	{ .compat = "AMDI0010" },	/* AMD FCH */
+	{ .compat = "AMDI0510" },	/* AMD Seattle */
+	{ .compat = "APMC0D0F" },	/* Ampere eMAG */
+	DEVICE_COMPAT_EOL
 };
 
 static int
@@ -72,10 +72,7 @@ dwiic_acpi_match(device_t parent, cfdata
 {
 	struct acpi_attach_args *aa = aux;
 
-	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-		return 0;
-
-	return acpi_match_hid(aa->aa_node->ad_devinfo, compatible);
+	return acpi_compatible_match(aa, compat_data);
 }
 
 static void



CVS commit: src/sys/dev/acpi

2021-02-04 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Feb  4 21:39:00 UTC 2021

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

Log Message:
Add acpi_device_register().  Just a placeholder for now.


To generate a diff of this commit:
cvs rdiff -u -r1.288 -r1.289 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.84 -r1.85 src/sys/dev/acpi/acpivar.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/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.288 src/sys/dev/acpi/acpi.c:1.289
--- src/sys/dev/acpi/acpi.c:1.288	Sun Dec 13 20:24:26 2020
+++ src/sys/dev/acpi/acpi.c	Thu Feb  4 21:39:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.288 2020/12/13 20:24:26 jmcneill Exp $	*/
+/*	$NetBSD: acpi.c,v 1.289 2021/02/04 21:39:00 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.288 2020/12/13 20:24:26 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.289 2021/02/04 21:39:00 thorpej Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -1125,6 +1125,17 @@ acpi_print(void *aux, const char *pnp)
 }
 
 /*
+ * acpi_device_register --
+ *	Called by the platform device_register() routine when
+ *	attaching devices.
+ */
+void
+acpi_device_register(device_t dev __unused, void *v __unused)
+{
+	/* Placeholder. */
+}
+
+/*
  * Notify.
  */
 static void

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.84 src/sys/dev/acpi/acpivar.h:1.85
--- src/sys/dev/acpi/acpivar.h:1.84	Wed Jan 27 05:11:54 2021
+++ src/sys/dev/acpi/acpivar.h	Thu Feb  4 21:39:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.84 2021/01/27 05:11:54 thorpej Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.85 2021/02/04 21:39:00 thorpej Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -319,6 +319,7 @@ const struct device_compatible_entry *
 		const struct device_compatible_entry *);
 
 bool	acpi_device_present(ACPI_HANDLE);
+void		acpi_device_register(device_t, void *);
 
 int		acpi_reset(void);
 



CVS commit: src/sys/dev/acpi

2021-01-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jan 29 15:49:55 UTC 2021

Modified Files:
src/sys/dev/acpi: acpi_cppc.c acpi_ec.c acpi_fan.c acpi_ged.c
acpi_lid.c acpi_pcd.c acpi_pmtr.c aibs_acpi.c amdccp_acpi.c
apple_smc_acpi.c asus_acpi.c atppc_acpi.c attimer_acpi.c
dalb_acpi.c ehci_acpi.c fdc_acpi.c fujbp_acpi.c fujhk_acpi.c
genet_acpi.c hpacel_acpi.c hpet_acpi.c hpqlb_acpi.c ipmi_acpi.c
joy_acpi.c lpt_acpi.c mpu_acpi.c pcppi_acpi.c plgpio_acpi.c
qemufwcfg_acpi.c smbus_acpi.c sony_acpi.c spic_acpi.c
thinkpad_acpi.c ug_acpi.c vald_acpi.c valz_acpi.c virtio_acpi.c
vmbus_acpi.c xhci_acpi.c
src/sys/dev/acpi/wmi: wmi_acpi.c

Log Message:
Use acpi_compatible_match().


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/acpi_cppc.c \
src/sys/dev/acpi/acpi_pcd.c src/sys/dev/acpi/qemufwcfg_acpi.c
cvs rdiff -u -r1.84 -r1.85 src/sys/dev/acpi/acpi_ec.c
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/acpi/acpi_fan.c \
src/sys/dev/acpi/acpi_pmtr.c src/sys/dev/acpi/spic_acpi.c \
src/sys/dev/acpi/valz_acpi.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/acpi_ged.c
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/acpi/acpi_lid.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/aibs_acpi.c \
src/sys/dev/acpi/plgpio_acpi.c src/sys/dev/acpi/ug_acpi.c \
src/sys/dev/acpi/virtio_acpi.c
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/amdccp_acpi.c \
src/sys/dev/acpi/apple_smc_acpi.c src/sys/dev/acpi/ehci_acpi.c \
src/sys/dev/acpi/fujbp_acpi.c src/sys/dev/acpi/fujhk_acpi.c
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/acpi/asus_acpi.c
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/acpi/atppc_acpi.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/acpi/attimer_acpi.c \
src/sys/dev/acpi/smbus_acpi.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/acpi/dalb_acpi.c
cvs rdiff -u -r1.45 -r1.46 src/sys/dev/acpi/fdc_acpi.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/genet_acpi.c \
src/sys/dev/acpi/ipmi_acpi.c src/sys/dev/acpi/vmbus_acpi.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/hpacel_acpi.c \
src/sys/dev/acpi/vald_acpi.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/acpi/hpet_acpi.c \
src/sys/dev/acpi/joy_acpi.c
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/acpi/hpqlb_acpi.c \
src/sys/dev/acpi/xhci_acpi.c
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/acpi/lpt_acpi.c
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/acpi/mpu_acpi.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/acpi/pcppi_acpi.c
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/acpi/sony_acpi.c
cvs rdiff -u -r1.48 -r1.49 src/sys/dev/acpi/thinkpad_acpi.c
cvs rdiff -u -r1.16 -r1.17 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/acpi_cppc.c
diff -u src/sys/dev/acpi/acpi_cppc.c:1.1 src/sys/dev/acpi/acpi_cppc.c:1.2
--- src/sys/dev/acpi/acpi_cppc.c:1.1	Sun Dec 13 20:39:20 2020
+++ src/sys/dev/acpi/acpi_cppc.c	Fri Jan 29 15:49:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cppc.c,v 1.1 2020/12/13 20:39:20 jmcneill Exp $ */
+/* $NetBSD: acpi_cppc.c,v 1.2 2021/01/29 15:49:55 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_cppc.c,v 1.1 2020/12/13 20:39:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cppc.c,v 1.2 2021/01/29 15:49:55 thorpej Exp $");
 
 #include 
 #include 
@@ -104,9 +104,9 @@ static ACPI_STATUS	cppc_write(struct cpp
 CFATTACH_DECL_NEW(acpicppc, sizeof(struct cppc_softc),
 cppc_match, cppc_attach, NULL, NULL);
 
-static const char * const compatible[] = {
-	"ACPI0007",	/* ACPI Processor Device */
-	NULL
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "ACPI0007" },	/* ACPI Processor Device */
+	DEVICE_COMPAT_EOL
 };
 
 static int
@@ -116,13 +116,8 @@ cppc_match(device_t parent, cfdata_t cf,
 	ACPI_HANDLE handle;
 	ACPI_STATUS rv;
 
-	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) {
+	if (acpi_compatible_match(aa, compat_data) == 0)
 		return 0;
-	}
-
-	if (acpi_match_hid(aa->aa_node->ad_devinfo, compatible) == 0) {
-		return 0;
-	}
 
 	rv = AcpiGetHandle(aa->aa_node->ad_handle, "_CPC", );
 	if (ACPI_FAILURE(rv)) {
@@ -134,7 +129,7 @@ cppc_match(device_t parent, cfdata_t cf,
 	}
 
 	/* When CPPC and P-states/T-states are both available, prefer CPPC */
-	return 20;
+	return ACPI_MATCHSCORE_CID_MAX + 1;
 }
 
 static void
Index: src/sys/dev/acpi/acpi_pcd.c
diff -u src/sys/dev/acpi/acpi_pcd.c:1.1 src/sys/dev/acpi/acpi_pcd.c:1.2
--- src/sys/dev/acpi/acpi_pcd.c:1.1	Mon Dec  7 10:57:41 2020
+++ src/sys/dev/acpi/acpi_pcd.c	Fri Jan 29 15:49:55 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pcd.c,v 1.1 2020/12/07 10:57:41 jmcneill Exp $ */
+/* $NetBSD: acpi_pcd.c,v 1.2 2021/01/29 15:49:55 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pcd.c,v 1.1 2020/12/07 10:57:41 

CVS commit: src/sys/dev/acpi

2021-01-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jan 29 15:24:00 UTC 2021

Modified Files:
src/sys/dev/acpi: acpi_button.c com_acpi.c pckbc_acpi.c tpm_acpi.c

Log Message:
Use acpi_compatible_match() / acpi_compatible_lookup().


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/sys/dev/acpi/acpi_button.c
cvs rdiff -u -r1.40 -r1.41 src/sys/dev/acpi/com_acpi.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/acpi/pckbc_acpi.c
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/acpi/tpm_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/acpi_button.c
diff -u src/sys/dev/acpi/acpi_button.c:1.42 src/sys/dev/acpi/acpi_button.c:1.43
--- src/sys/dev/acpi/acpi_button.c:1.42	Thu Apr 23 23:23:00 2015
+++ src/sys/dev/acpi/acpi_button.c	Fri Jan 29 15:24:00 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_button.c,v 1.42 2015/04/23 23:23:00 pgoyette Exp $	*/
+/*	$NetBSD: acpi_button.c,v 1.43 2021/01/29 15:24:00 thorpej Exp $	*/
 
 /*
  * Copyright 2001, 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.42 2015/04/23 23:23:00 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_button.c,v 1.43 2021/01/29 15:24:00 thorpej Exp $");
 
 #include 
 #include 
@@ -61,14 +61,25 @@ struct acpibut_softc {
 	struct sysmon_pswitch	 sc_smpsw;
 };
 
-static const char * const power_button_hid[] = {
-	"PNP0C0C",
-	NULL
+struct button_type {
+	const char *desc;
+	int type;
+};
+
+static const struct button_type power_button_type = {
+	.desc = "Power",
+	.type = PSWITCH_TYPE_POWER
 };
 
-static const char * const sleep_button_hid[] = {
-	"PNP0C0E",
-	NULL
+static const struct button_type sleep_button_type = {
+	.desc = "Sleep",
+	.type = PSWITCH_TYPE_SLEEP
+};
+
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "PNP0C0C",	.data = _button_type },
+	{ .compat = "PNP0C0E",	.data = _button_type },
+	DEVICE_COMPAT_EOL
 };
 
 static int	acpibut_match(device_t, cfdata_t, void *);
@@ -90,16 +101,7 @@ acpibut_match(device_t parent, cfdata_t 
 {
 	struct acpi_attach_args *aa = aux;
 
-	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-		return 0;
-
-	if (acpi_match_hid(aa->aa_node->ad_devinfo, power_button_hid))
-		return 1;
-
-	if (acpi_match_hid(aa->aa_node->ad_devinfo, sleep_button_hid))
-		return 1;
-
-	return 0;
+	return acpi_compatible_match(aa, compat_data);
 }
 
 /*
@@ -112,22 +114,20 @@ acpibut_attach(device_t parent, device_t
 {
 	struct acpibut_softc *sc = device_private(self);
 	struct acpi_attach_args *aa = aux;
+	const struct device_compatible_entry *dce;
+	const struct button_type *type;
 	struct acpi_wakedev *aw;
-	const char *desc;
 
 	sc->sc_smpsw.smpsw_name = device_xname(self);
 
-	if (acpi_match_hid(aa->aa_node->ad_devinfo, power_button_hid)) {
-		sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_POWER;
-		desc = "Power";
-	} else if (acpi_match_hid(aa->aa_node->ad_devinfo, sleep_button_hid)) {
-		sc->sc_smpsw.smpsw_type = PSWITCH_TYPE_SLEEP;
-		desc = "Sleep";
-	} else
-		panic("%s: impossible", __func__);
+	dce = acpi_compatible_lookup(aa, compat_data);
+	KASSERT(dce != NULL);
+	type = dce->data;
+
+	sc->sc_smpsw.smpsw_type = type->type;
 
-	aprint_naive(": ACPI %s Button\n", desc);
-	aprint_normal(": ACPI %s Button\n", desc);
+	aprint_naive(": ACPI %s Button\n", type->desc);
+	aprint_normal(": ACPI %s Button\n", type->desc);
 
 	sc->sc_node = aa->aa_node;
 	aw = sc->sc_node->ad_wakedev;

Index: src/sys/dev/acpi/com_acpi.c
diff -u src/sys/dev/acpi/com_acpi.c:1.40 src/sys/dev/acpi/com_acpi.c:1.41
--- src/sys/dev/acpi/com_acpi.c:1.40	Fri Mar  1 09:21:06 2019
+++ src/sys/dev/acpi/com_acpi.c	Fri Jan 29 15:24:00 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: com_acpi.c,v 1.40 2019/03/01 09:21:06 mlelstv Exp $ */
+/* $NetBSD: com_acpi.c,v 1.41 2021/01/29 15:24:00 thorpej Exp $ */
 
 /*
  * Copyright (c) 2002 Jared D. McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.40 2019/03/01 09:21:06 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.41 2021/01/29 15:24:00 thorpej Exp $");
 
 #include 
 #include 
@@ -53,27 +53,38 @@ CFATTACH_DECL_NEW(com_acpi, sizeof(struc
  * Supported device IDs
  */
 
-static const char * const com_acpi_ids[] = {
-	"PNP0500",	/* Standard PC COM port */
-	"PNP0501",	/* 16550A-compatible COM port */
-	"PNP0510",	/* Generic IRDA-compatible device */
-	"PNP0511",	/* Generic IRDA-compatible device */
-	"IBM0071",	/* IBM ThinkPad IRDA device */
-	"SMCF010",	/* SMC SuperIO IRDA device */
-	"NSC6001",	/* NSC IRDA device */
-	"FUJ02E6",	/* Fujitsu Serial Pen Tablet */
-	"HISI0031",	/* Hisilicon UART */
-	"8250dw",	/* Designware APB UART */
-	NULL
-};
+static const struct device_compatible_entry compat_data[] = {
+	/* Standard PC COM port */
+	{ .compat = "PNP0500",		.value = COM_TYPE_NORMAL },
 
-/*
- * Subset of supported device IDs of type COM_TYPE_DW_APB
- */
-static const char * const 

CVS commit: src/sys/dev/acpi

2021-01-29 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jan 29 15:20:13 UTC 2021

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

Log Message:
Use acpi_compatible_match().


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/sys/dev/acpi/acpi_acad.c
cvs rdiff -u -r1.116 -r1.117 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_acad.c
diff -u src/sys/dev/acpi/acpi_acad.c:1.51 src/sys/dev/acpi/acpi_acad.c:1.52
--- src/sys/dev/acpi/acpi_acad.c:1.51	Thu Apr 23 23:23:00 2015
+++ src/sys/dev/acpi/acpi_acad.c	Fri Jan 29 15:20:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_acad.c,v 1.51 2015/04/23 23:23:00 pgoyette Exp $	*/
+/*	$NetBSD: acpi_acad.c,v 1.52 2021/01/29 15:20:13 thorpej Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_acad.c,v 1.51 2015/04/23 23:23:00 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_acad.c,v 1.52 2021/01/29 15:20:13 thorpej Exp $");
 
 #include 
 #include 
@@ -64,9 +64,9 @@ struct acpiacad_softc {
 	int			 sc_status;
 };
 
-static const char * const acad_hid[] = {
-	"ACPI0003",
-	NULL
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "ACPI0003" },
+	DEVICE_COMPAT_EOL
 };
 
 static int	acpiacad_match(device_t, cfdata_t, void *);
@@ -90,10 +90,7 @@ acpiacad_match(device_t parent, cfdata_t
 {
 	struct acpi_attach_args *aa = aux;
 
-	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-		return 0;
-
-	return acpi_match_hid(aa->aa_node->ad_devinfo, acad_hid);
+	return acpi_compatible_match(aa, compat_data);
 }
 
 /*

Index: src/sys/dev/acpi/acpi_bat.c
diff -u src/sys/dev/acpi/acpi_bat.c:1.116 src/sys/dev/acpi/acpi_bat.c:1.117
--- src/sys/dev/acpi/acpi_bat.c:1.116	Fri Aug 10 17:11:56 2018
+++ src/sys/dev/acpi/acpi_bat.c	Fri Jan 29 15:20:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_bat.c,v 1.116 2018/08/10 17:11:56 riastradh Exp $	*/
+/*	$NetBSD: acpi_bat.c,v 1.117 2021/01/29 15:20:13 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -75,7 +75,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.116 2018/08/10 17:11:56 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_bat.c,v 1.117 2021/01/29 15:20:13 thorpej Exp $");
 
 #include 
 #include 
@@ -159,9 +159,9 @@ struct acpibat_softc {
 	int  sc_present;
 };
 
-static const char * const bat_hid[] = {
-	"PNP0C0A",
-	NULL
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "PNP0C0A" },
+	DEVICE_COMPAT_EOL
 };
 
 #define ACPIBAT_PWRUNIT_MA	0x0001  /* mA not mW */
@@ -207,10 +207,7 @@ acpibat_match(device_t parent, cfdata_t 
 {
 	struct acpi_attach_args *aa = aux;
 
-	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-		return 0;
-
-	return acpi_match_hid(aa->aa_node->ad_devinfo, bat_hid);
+	return acpi_compatible_match(aa, compat_data);
 }
 
 /*



CVS commit: src/sys/dev/acpi

2021-01-28 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri Jan 29 02:26:58 UTC 2021

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

Log Message:
Use acpi_compatible_match().


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/nxpiic_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/nxpiic_acpi.c
diff -u src/sys/dev/acpi/nxpiic_acpi.c:1.3 src/sys/dev/acpi/nxpiic_acpi.c:1.4
--- src/sys/dev/acpi/nxpiic_acpi.c:1.3	Tue Jan 26 00:19:53 2021
+++ src/sys/dev/acpi/nxpiic_acpi.c	Fri Jan 29 02:26:58 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: nxpiic_acpi.c,v 1.3 2021/01/26 00:19:53 jmcneill Exp $ */
+/* $NetBSD: nxpiic_acpi.c,v 1.4 2021/01/29 02:26:58 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi.c,v 1.3 2021/01/26 00:19:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi.c,v 1.4 2021/01/29 02:26:58 thorpej Exp $");
 
 #include 
 #include 
@@ -82,9 +82,9 @@ static void	nxpiic_acpi_iowr(struct moto
 CFATTACH_DECL_NEW(nxpiic_acpi, sizeof(struct nxpiic_softc),
 nxpiic_acpi_match, nxpiic_acpi_attach, NULL, NULL);
 
-static const char * const compatible[] = {
-	"NXP0001",
-	NULL
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "NXP0001" },
+	DEVICE_COMPAT_EOL
 };
 
 static int
@@ -92,10 +92,7 @@ nxpiic_acpi_match(device_t parent, cfdat
 {
 	struct acpi_attach_args *aa = aux;
 
-	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
-		return 0;
-
-	return acpi_match_hid(aa->aa_node->ad_devinfo, compatible);
+	return acpi_compatible_match(aa, compat_data);
 }
 
 static void



CVS commit: src/sys/dev/acpi

2021-01-26 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jan 27 05:11:54 UTC 2021

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

Log Message:
Introduce weighted matching for ACPI autoconfiguration, and provide
acpi_compatible_match() based around device_compatible_entry.  Matches
against _HID score big, matches against _CID are weighted in the
standard most-to-least-specific ordering, less than _HID.

Also provide a maching value for _CLS, that's always less than _HID
and _CID matches, and use that in acpi_match_class().

Also provide acpi_compatible_lookup(), that returing the matching
entry based on the same criteria.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.83 -r1.84 src/sys/dev/acpi/acpivar.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/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.22 src/sys/dev/acpi/acpi_util.c:1.23
--- src/sys/dev/acpi/acpi_util.c:1.22	Tue Jan 26 00:23:16 2021
+++ src/sys/dev/acpi/acpi_util.c	Wed Jan 27 05:11:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.22 2021/01/26 00:23:16 jmcneill Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.23 2021/01/27 05:11:54 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007, 2021 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.22 2021/01/26 00:23:16 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.23 2021/01/27 05:11:54 thorpej Exp $");
 
 #include 
 #include 
@@ -306,7 +306,7 @@ acpi_name(ACPI_HANDLE handle)
 }
 
 /*
- * Pack _HID and _CID ID strings into an OpenFirmware-like
+ * Pack _HID and _CID ID strings into an OpenFirmware-style
  * string list.
  */
 char *
@@ -314,49 +314,143 @@ acpi_pack_compat_list(ACPI_DEVICE_INFO *
 {
 	KASSERT(sizep != NULL);
 
-	char *strlist, *cp;
-	size_t len = 0;
+	char *sl = NULL;
+	size_t slsize = 0;
 	uint32_t i;
 
-	/*
-	 * First calculate the total size required.
-	 * N.B. PNP Device ID length includes terminating NUL.
-	 */
 	if ((ad->Valid & ACPI_VALID_HID) != 0) {
-		len += ad->HardwareId.Length;
+		strlist_append(, , ad->HardwareId.String);
 	}
 
 	if ((ad->Valid & ACPI_VALID_CID) != 0) {
 		for (i = 0; i < ad->CompatibleIdList.Count; i++) {
-			len += ad->CompatibleIdList.Ids[i].Length;
+			strlist_append(, ,
+			ad->CompatibleIdList.Ids[i].String);
 		}
 	}
 
-	*sizep = len;
-	if (len == 0) {
-		return NULL;
+	*sizep = slsize;
+	return sl;
+}
+
+/*
+ * The ACPI_PNP_DEVICE_ID type is somewhat inconvenient for us to
+ * use.  We'll need some temporary space to pack it into an array
+ * of C strings.  Room for 8 should be plenty, but we can allocate
+ * more if necessary.
+ */
+#define	ACPI_COMPATSTR_MAX	8
+
+static const char **
+acpi_compatible_alloc_strarray(ACPI_PNP_DEVICE_ID *ids,
+unsigned int count, const char **buf)
+{
+	unsigned int i;
+
+	buf = kmem_tmpbuf_alloc(count * sizeof(const char *),
+	buf, ACPI_COMPATSTR_MAX * sizeof(const char *), KM_SLEEP);
+	for (i = 0; i < count; i++) {
+		buf[i] = ids[i].String;
+	}
+	return buf;
+}
+
+static void
+acpi_compatible_free_strarray(const char **cpp, unsigned int count,
+const char **buf)
+{
+	kmem_tmpbuf_free(cpp, count * sizeof(const char *), buf);
+}
+
+/*
+ * acpi_compatible_match --
+ *
+ *	Returns a weighted match value, comparing the _HID and _CID
+ *	IDs against a driver's compatbility data.
+ */
+int
+acpi_compatible_match(const struct acpi_attach_args * const aa,
+const struct device_compatible_entry * const dce)
+{
+	const char *strings[ACPI_COMPATSTR_MAX * sizeof(const char *)];
+	const char **cpp;
+
+	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE) {
+		return 0;
 	}
 
-	cp = strlist = kmem_alloc(len, KM_SLEEP);
+	ACPI_DEVICE_INFO *ad = aa->aa_node->ad_devinfo;
 
 	if ((ad->Valid & ACPI_VALID_HID) != 0) {
-		memcpy(cp, ad->HardwareId.String, ad->HardwareId.Length);
-		cp += ad->HardwareId.Length;
+		strings[0] = ad->HardwareId.String;
+
+		/* Matching _HID wins big. */
+		if (device_compatible_pmatch(strings, 1, dce) != 0) {
+			return ACPI_MATCHSCORE_HID;
+		}
 	}
 
 	if ((ad->Valid & ACPI_VALID_CID) != 0) {
-		for (i = 0; i < ad->CompatibleIdList.Count; i++) {
-			memcpy(cp, ad->CompatibleIdList.Ids[i].String,
-			ad->CompatibleIdList.Ids[i].Length);
-			cp += ad->CompatibleIdList.Ids[i].Length;
+		cpp = acpi_compatible_alloc_strarray(ad->CompatibleIdList.Ids,
+		ad->CompatibleIdList.Count, strings);
+		int rv;
+
+		rv = device_compatible_pmatch(cpp,
+		ad->CompatibleIdList.Count, dce);
+		acpi_compatible_free_strarray(cpp, ad->CompatibleIdList.Count,
+		strings);
+		if (rv) {
+			rv = (rv - 1) + ACPI_MATCHSCORE_CID;
+			if (rv > ACPI_MATCHSCORE_CID_MAX) {
+rv = ACPI_MATCHSCORE_CID_MAX;
+			}
+			return rv;
 		}
 	}
 
-	KASSERT((size_t)(cp - strlist) == len);
-
-	return strlist;
+	return 0;
 }
 
+/*
+ * acpi_compatible_lookup 

CVS commit: src/sys/dev/acpi

2021-01-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jan 26 15:30:05 UTC 2021

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

Log Message:
Trailing whitespace


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/dev/acpi/acpi_mcfg.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_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.22 src/sys/dev/acpi/acpi_mcfg.c:1.23
--- src/sys/dev/acpi/acpi_mcfg.c:1.22	Tue Jan 26 15:29:41 2021
+++ src/sys/dev/acpi/acpi_mcfg.c	Tue Jan 26 15:30:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.22 2021/01/26 15:29:41 skrll Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.23 2021/01/26 15:30:05 skrll Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.22 2021/01/26 15:29:41 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.23 2021/01/26 15:30:05 skrll Exp $");
 
 #include 
 #include 
@@ -507,7 +507,7 @@ acpimcfg_device_probe(const struct pci_a
 		force_hasextcnf = true;
 	if (qd != NULL && (qd->quirks & PCI_QUIRK_NOEXTCNF) != 0)
 		force_noextcnf = true;
-	
+
 	/* Probe extended configuration space. */
 	if ((!force_hasextcnf) && ((force_noextcnf) ||
 		((reg = pci_conf_read(pc, tag, PCI_CONF_SIZE)) == (pcireg_t)-1)



CVS commit: src/sys/dev/acpi

2021-01-26 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Tue Jan 26 15:29:42 UTC 2021

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

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/acpi/acpi_mcfg.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_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.21 src/sys/dev/acpi/acpi_mcfg.c:1.22
--- src/sys/dev/acpi/acpi_mcfg.c:1.21	Sun Dec  6 12:47:12 2020
+++ src/sys/dev/acpi/acpi_mcfg.c	Tue Jan 26 15:29:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.21 2020/12/06 12:47:12 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.22 2021/01/26 15:29:41 skrll Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.21 2020/12/06 12:47:12 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.22 2021/01/26 15:29:41 skrll Exp $");
 
 #include 
 #include 
@@ -364,7 +364,7 @@ acpimcfg_init(bus_space_tag_t memt, cons
 		if (mcfg_ops->ao_validate != NULL &&
 		!mcfg_ops->ao_validate(ama->Address, ama->StartBusNumber,
 		  _end)) {
-			if (!acpimcfg_find_system_resource( ama->Address,
+			if (!acpimcfg_find_system_resource(ama->Address,
 			ama->StartBusNumber, _end)) {
 aprint_debug_dev(acpi_sc->sc_dev,
 "MCFG: segment %d, bus %d-%d, "



CVS commit: src/sys/dev/acpi

2021-01-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jan 26 00:23:16 UTC 2021

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

Log Message:
build fix


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/acpi/acpi_util.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_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.21 src/sys/dev/acpi/acpi_util.c:1.22
--- src/sys/dev/acpi/acpi_util.c:1.21	Tue Jan 26 00:19:53 2021
+++ src/sys/dev/acpi/acpi_util.c	Tue Jan 26 00:23:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.21 2021/01/26 00:19:53 jmcneill Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.22 2021/01/26 00:23:16 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007, 2021 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.21 2021/01/26 00:19:53 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.22 2021/01/26 00:23:16 jmcneill Exp $");
 
 #include 
 #include 
@@ -873,7 +873,8 @@ acpi_claim_childdevs(device_t dev, struc
 	SIMPLEQ_FOREACH(ad, >ad_child_head, ad_child_list) {
 		if (ad->ad_device != NULL)
 			continue;
-		aprint_debug(dev, "claiming %s\n", acpi_name(ad->ad_handle));
+		aprint_debug_dev(dev, "claiming %s\n",
+		acpi_name(ad->ad_handle));
 		ad->ad_device = dev;
 		acpi_claim_childdevs(dev, ad);
 	}



CVS commit: src/sys/dev/acpi

2021-01-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Jan 25 12:09:59 UTC 2021

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

Log Message:
Configure clocks and enable NXP Layerscape quirks in motoi2c


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/nxpiic_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/nxpiic_acpi.c
diff -u src/sys/dev/acpi/nxpiic_acpi.c:1.1 src/sys/dev/acpi/nxpiic_acpi.c:1.2
--- src/sys/dev/acpi/nxpiic_acpi.c:1.1	Sun Jan 24 18:02:51 2021
+++ src/sys/dev/acpi/nxpiic_acpi.c	Mon Jan 25 12:09:58 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: nxpiic_acpi.c,v 1.1 2021/01/24 18:02:51 jmcneill Exp $ */
+/* $NetBSD: nxpiic_acpi.c,v 1.2 2021/01/25 12:09:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi.c,v 1.1 2021/01/24 18:02:51 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi.c,v 1.2 2021/01/25 12:09:58 jmcneill Exp $");
 
 #include 
 #include 
@@ -45,6 +45,29 @@ __KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi.
 #include 
 #include 
 
+#define	NXPIIC_SPEED_STD	10
+
+static const struct clk_div {
+	int scl_div;
+	uint8_t ibc;
+} nxpiic_clk_div[] = {
+	{ 20, 0x00 },	{ 22, 0x01 },	{ 24, 0x02 },	{ 26, 0x03 },
+	{ 28, 0x04 },	{ 30, 0x05 },	{ 32, 0x09 },	{ 34, 0x06 },
+	{ 36, 0x0a },	{ 40, 0x07 },	{ 44, 0x0c },	{ 48, 0x0d },
+	{ 52, 0x43 },	{ 56, 0x0e },	{ 60, 0x45 },	{ 64, 0x12 },
+	{ 68, 0x0f },	{ 72, 0x13 },	{ 80, 0x14 },	{ 88, 0x15 },
+	{ 96, 0x19 },	{ 104, 0x16 },	{ 112, 0x1a },	{ 128, 0x17 },
+	{ 136, 0x4f },	{ 144, 0x1c },	{ 160, 0x1d },	{ 176, 0x55 },
+	{ 192, 0x1e },	{ 208, 0x56 },	{ 224, 0x22 },	{ 228, 0x24 },
+	{ 240, 0x1f },	{ 256, 0x23 },	{ 288, 0x5c },	{ 320, 0x25 },
+	{ 384, 0x26 },	{ 448, 0x2a },	{ 480, 0x27 },	{ 512, 0x2b },
+	{ 576, 0x2c },	{ 640, 0x2d },	{ 768, 0x31 },	{ 896, 0x32 },
+	{ 960, 0x2f },	{ 1024, 0x33 },	{ 1152, 0x34 },	{ 1280, 0x35 },
+	{ 1536, 0x36 },	{ 1792, 0x3a },	{ 1920, 0x37 },	{ 2048, 0x3b },
+	{ 2304, 0x3c },	{ 2560, 0x3d },	{ 3072, 0x3e },	{ 3584, 0x7a },
+	{ 3840, 0x3f },	{ 4096, 0x7B },	{ 5120, 0x7d },	{ 6144, 0x7e },
+};
+
 struct nxpiic_softc {
 	device_t		sc_dev;
 	struct motoi2c_softc	sc_motoi2c;
@@ -80,12 +103,13 @@ nxpiic_acpi_attach(device_t parent, devi
 {
 	struct nxpiic_softc * const sc = device_private(self);
 	struct motoi2c_softc * const msc = >sc_motoi2c;
+	struct motoi2c_settings settings;
 	struct acpi_attach_args *aa = aux;
 	struct acpi_resources res;
 	struct acpi_mem *mem;
 	ACPI_INTEGER clock_freq;
 	ACPI_STATUS rv;
-	int error;
+	int error, n;
 
 	sc->sc_dev = self;
 	msc->sc_iot = aa->aa_memt;
@@ -107,6 +131,7 @@ nxpiic_acpi_attach(device_t parent, devi
 		aprint_error_dev(self, "couldn't get clock frequency\n");
 		goto done;
 	}
+	aprint_debug_dev(self, "bus clock %u Hz\n", (u_int)clock_freq);
 
 	error = bus_space_map(msc->sc_iot, mem->ar_base, mem->ar_length, 0,
 	>sc_ioh);
@@ -115,11 +140,20 @@ nxpiic_acpi_attach(device_t parent, devi
 		return;
 	}
 
+	settings.i2c_adr = MOTOI2C_ADR_DEFAULT;
+	settings.i2c_dfsrr = MOTOI2C_DFSRR_DEFAULT;
+	for (n = 0; n < __arraycount(nxpiic_clk_div) - 1; n++) {
+		if (clock_freq / nxpiic_clk_div[n].scl_div < NXPIIC_SPEED_STD)
+			break;
+	}
+	settings.i2c_fdr = nxpiic_clk_div[n].ibc;
+
+	msc->sc_flags |= MOTOI2C_F_ENABLE_INV | MOTOI2C_F_STATUS_W1C;
 	msc->sc_iord = nxpiic_acpi_iord;
 	msc->sc_iowr = nxpiic_acpi_iowr;
 	msc->sc_child_devices = acpi_enter_i2c_devs(aa->aa_node);
 
-	motoi2c_attach_common(self, msc, NULL);
+	motoi2c_attach_common(self, msc, );
 
 done:
 	acpi_resource_cleanup();



CVS commit: src/sys/dev/acpi

2021-01-15 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Jan 16 01:23:04 UTC 2021

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

Log Message:
Match PNP0C31 as a TPM 1.2 device.  Works on my ThinkPad X260, and
eliminates the last of the devices that attach to "isa".


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/acpi/tpm_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/tpm_acpi.c
diff -u src/sys/dev/acpi/tpm_acpi.c:1.11 src/sys/dev/acpi/tpm_acpi.c:1.12
--- src/sys/dev/acpi/tpm_acpi.c:1.11	Wed Oct  9 14:03:57 2019
+++ src/sys/dev/acpi/tpm_acpi.c	Sat Jan 16 01:23:04 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tpm_acpi.c,v 1.11 2019/10/09 14:03:57 maxv Exp $ */
+/* $NetBSD: tpm_acpi.c,v 1.12 2021/01/16 01:23:04 thorpej Exp $ */
 
 /*
  * Copyright (c) 2012, 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.11 2019/10/09 14:03:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.12 2021/01/16 01:23:04 thorpej Exp $");
 
 #include 
 #include 
@@ -56,6 +56,14 @@ CFATTACH_DECL_NEW(tpm_acpi, sizeof(struc
 tpm_acpi_attach, NULL, NULL);
 
 /*
+ * Supported TPM 1.2 devices.
+ */
+static const char * const tpm_1_2_acpi_ids[] = {
+	"PNP0C31",
+	NULL
+};
+
+/*
  * Supported TPM 2.0 devices.
  */
 static const char * const tpm2_acpi_ids[] = {
@@ -77,6 +85,11 @@ tpm_acpi_match(device_t parent, cfdata_t
 	if (tpm_cd.cd_devs && tpm_cd.cd_devs[0])
 		return 0;
 
+	if (acpi_match_hid(aa->aa_node->ad_devinfo, tpm_1_2_acpi_ids)) {
+		/* XXX assume TPM 1.2 devices are memory-mapped. */
+		return 1;
+	}
+
 	if (!acpi_match_hid(aa->aa_node->ad_devinfo, tpm2_acpi_ids))
 		return 0;
 
@@ -122,7 +135,11 @@ tpm_acpi_attach(device_t parent, device_
 	size = mem->ar_length;
 
 	sc->sc_dev = self;
-	sc->sc_ver = TPM_2_0;
+	if (acpi_match_hid(aa->aa_node->ad_devinfo, tpm_1_2_acpi_ids)) {
+		sc->sc_ver = TPM_1_2;
+	} else {
+		sc->sc_ver = TPM_2_0;
+	}
 	mutex_init(>sc_lock, MUTEX_DEFAULT, IPL_NONE);
 	sc->sc_busy = false;
 	sc->sc_intf = _intf_tis12;



CVS commit: src/sys/dev/acpi

2021-01-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jan 14 14:38:22 UTC 2021

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

Log Message:
Use acpi_dsm() in acpi_usb_post_reset().


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/acpi_usb.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_usb.c
diff -u src/sys/dev/acpi/acpi_usb.c:1.1 src/sys/dev/acpi/acpi_usb.c:1.2
--- src/sys/dev/acpi/acpi_usb.c:1.1	Fri Oct 26 23:33:38 2018
+++ src/sys/dev/acpi/acpi_usb.c	Thu Jan 14 14:38:22 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_usb.c,v 1.1 2018/10/26 23:33:38 jmcneill Exp $ */
+/* $NetBSD: acpi_usb.c,v 1.2 2021/01/14 14:38:22 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_usb.c,v 1.1 2018/10/26 23:33:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_usb.c,v 1.2 2021/01/14 14:38:22 thorpej Exp $");
 
 #include 
 
@@ -53,9 +53,6 @@ static UINT8 ehci_acpi_dsm_uuid[ACPI_UUI
 void
 acpi_usb_post_reset(ACPI_HANDLE handle)
 {
-	ACPI_OBJECT_LIST objs;
-	ACPI_OBJECT obj[4];
-	ACPI_HANDLE method;
 
 	/*
 	 * Invoke the _DSM control method for post-reset processing function
@@ -64,21 +61,5 @@ acpi_usb_post_reset(ACPI_HANDLE handle)
 	 * device into host mode.
 	 */
 
-	objs.Count = 4;
-	objs.Pointer = obj;
-	obj[0].Type = ACPI_TYPE_BUFFER;
-	obj[0].Buffer.Length = ACPI_UUID_LENGTH;
-	obj[0].Buffer.Pointer = ehci_acpi_dsm_uuid;
-	obj[1].Type = ACPI_TYPE_INTEGER;
-	obj[1].Integer.Value = 0;	/* Revision ID = 0 */
-	obj[2].Type = ACPI_TYPE_INTEGER;
-	obj[2].Integer.Value = 1;	/* Function index = 1 */
-	obj[3].Type = ACPI_TYPE_PACKAGE;
-	obj[3].Package.Count = 0;	/* Empty package (not used) */
-	obj[3].Package.Elements = NULL;
-
-	if (ACPI_FAILURE(AcpiGetHandle(handle, "_DSM", )))
-		return;
-
-	(void)AcpiEvaluateObject(method, NULL, , NULL);
+	(void)acpi_dsm(handle, ehci_acpi_dsm_uuid, 0, 1, NULL, NULL);
 }



CVS commit: src/sys/dev/acpi

2021-01-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jan 14 14:37:17 UTC 2021

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

Log Message:
In acpi_pci_ignore_boot_config(), use acpi_dsm() and add some comments
describing the (somewhat confusing) semantics of the _DSM method used
here.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/acpi/acpi_pci.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_pci.c
diff -u src/sys/dev/acpi/acpi_pci.c:1.29 src/sys/dev/acpi/acpi_pci.c:1.30
--- src/sys/dev/acpi/acpi_pci.c:1.29	Fri May  8 14:42:38 2020
+++ src/sys/dev/acpi/acpi_pci.c	Thu Jan 14 14:37:17 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci.c,v 1.29 2020/05/08 14:42:38 jmcneill Exp $ */
+/* $NetBSD: acpi_pci.c,v 1.30 2021/01/14 14:37:17 thorpej Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.29 2020/05/08 14:42:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.30 2021/01/14 14:37:17 thorpej Exp $");
 
 #include 
 #include 
@@ -495,44 +495,50 @@ acpi_pcidev_find_dev(struct acpi_devnode
 ACPI_INTEGER
 acpi_pci_ignore_boot_config(ACPI_HANDLE handle)
 {
-	ACPI_OBJECT_LIST objs;
-	ACPI_OBJECT obj[4], *pobj;
-	ACPI_BUFFER buf;
+	ACPI_OBJECT *pobj = NULL;
 	ACPI_INTEGER ret;
 
-	objs.Count = 4;
-	objs.Pointer = obj;
-	obj[0].Type = ACPI_TYPE_BUFFER;
-	obj[0].Buffer.Length = ACPI_UUID_LENGTH;
-	obj[0].Buffer.Pointer = acpi_pci_dsm_uuid;
-	obj[1].Type = ACPI_TYPE_INTEGER;
-	obj[1].Integer.Value = 1;
-	obj[2].Type = ACPI_TYPE_INTEGER;
-	obj[2].Integer.Value = 5;
-	obj[3].Type = ACPI_TYPE_PACKAGE;
-	obj[3].Package.Count = 0;
-	obj[3].Package.Elements = NULL;
-
-	buf.Pointer = NULL;
-	buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
+	/*
+	 * This one is a little confusing, but the result of
+	 * evaluating _DSM #5 is:
+	 *
+	 * 0: The operating system may not ignore the boot configuration
+	 *of PCI resources.
+	 *
+	 * 1: The operating system may ignore the boot configuration of
+	 *PCI resources, and reconfigure or rebalance these resources
+	 *in the hierarchy as required.
+	 */
 
-	if (ACPI_FAILURE(AcpiEvaluateObject(handle, "_DSM", , )) || buf.Pointer == NULL)
+	if (ACPI_FAILURE(acpi_dsm(handle, acpi_pci_dsm_uuid,
+  1, 5, NULL, ))) {
+		/*
+		 * In the absence of _DSM #5, we may assume that the
+		 * boot config can be ignored.
+		 */
 		return 1;
+	}
 
+	/*
+	 * ...and we default to "may ignore" in the event that the
+	 * method returns nonsense.
+	 */
 	ret = 1;
 
-	pobj = buf.Pointer;
-	switch (pobj->Type) {
-	case ACPI_TYPE_INTEGER:
-		ret = pobj->Integer.Value;
-		break;
-	case ACPI_TYPE_PACKAGE:
-		if (pobj->Package.Count == 1 && pobj->Package.Elements[0].Type == ACPI_TYPE_INTEGER)
-			ret = pobj->Package.Elements[0].Integer.Value;
-		break;
-	}
+	if (pobj != NULL) {
+		switch (pobj->Type) {
+		case ACPI_TYPE_INTEGER:
+			ret = pobj->Integer.Value;
+			break;
 
-	ACPI_FREE(buf.Pointer);
+		case ACPI_TYPE_PACKAGE:
+			if (pobj->Package.Count == 1 &&
+			pobj->Package.Elements[0].Type == ACPI_TYPE_INTEGER)
+ret = pobj->Package.Elements[0].Integer.Value;
+			break;
+		}
+		ACPI_FREE(pobj);
+	}
 
 	return ret;
 }



CVS commit: src/sys/dev/acpi

2021-01-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jan 14 14:35:53 UTC 2021

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

Log Message:
- Add a new routine, acpi_pack_compat_list(), that packs the _HID
  and _CID device ID strings into an OpenFirmware-like string list,
  analogous to how the "compatible" property is represented in
  OpenFirmware and the Device Tree specifications.
- Add generic routines for evaluating Device Specific Methods (_DSM).


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.8 -r1.9 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.

Modified files:

Index: src/sys/dev/acpi/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.19 src/sys/dev/acpi/acpi_util.c:1.20
--- src/sys/dev/acpi/acpi_util.c:1.19	Fri Oct 23 10:59:37 2020
+++ src/sys/dev/acpi/acpi_util.c	Thu Jan 14 14:35:53 2021
@@ -1,7 +1,7 @@
-/*	$NetBSD: acpi_util.c,v 1.19 2020/10/23 10:59:37 jmcneill Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.20 2021/01/14 14:35:53 thorpej Exp $ */
 
 /*-
- * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
+ * Copyright (c) 2003, 2007, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.19 2020/10/23 10:59:37 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.20 2021/01/14 14:35:53 thorpej Exp $");
 
 #include 
 #include 
@@ -306,6 +306,59 @@ acpi_name(ACPI_HANDLE handle)
 }
 
 /*
+ * Pack _HID and _CID ID strings into an OpenFirmware-like
+ * string list.
+ */
+char *
+acpi_pack_compat_list(ACPI_DEVICE_INFO *ad, size_t *sizep)
+{
+	KASSERT(sizep != NULL);
+
+	char *strlist, *cp;
+	size_t len = 0;
+	uint32_t i;
+
+	/*
+	 * First calculate the total size required.
+	 * N.B. PNP Device ID length includes terminating NUL.
+	 */
+	if ((ad->Valid & ACPI_VALID_HID) != 0) {
+		len += ad->HardwareId.Length;
+	}
+
+	if ((ad->Valid & ACPI_VALID_CID) != 0) {
+		for (i = 0; i < ad->CompatibleIdList.Count; i++) {
+			len += ad->CompatibleIdList.Ids[i].Length;
+		}
+	}
+
+	*sizep = len;
+	if (len == 0) {
+		return NULL;
+	}
+
+	cp = strlist = kmem_alloc(len, KM_SLEEP);
+
+	if ((ad->Valid & ACPI_VALID_HID) != 0) {
+		memcpy(cp, ad->HardwareId.String, ad->HardwareId.Length);
+		cp += ad->HardwareId.Length;
+	}
+
+	if ((ad->Valid & ACPI_VALID_CID) != 0) {
+		for (i = 0; i < ad->CompatibleIdList.Count; i++) {
+			memcpy(cp, ad->CompatibleIdList.Ids[i].String,
+			ad->CompatibleIdList.Ids[i].Length);
+			cp += ad->CompatibleIdList.Ids[i].Length;
+		}
+	}
+
+	KASSERT((size_t)(cp - strlist) == len);
+
+	return strlist;
+}
+
+
+/*
  * Match given IDs against _HID and _CIDs.
  */
 int
@@ -636,7 +689,7 @@ acpi_intr_string(void *c, char *buf, siz
 }
 
 /*
- * USB Device-Specific Data (_DSD) support
+ * Device-Specific Data (_DSD) support
  */
 
 static UINT8 acpi_dsd_uuid[ACPI_UUID_LENGTH] = {
@@ -728,3 +781,86 @@ acpi_dsd_string(ACPI_HANDLE handle, cons
 		ACPI_FREE(buf.Pointer);
 	return rv;
 }
+
+/*
+ * Device Specific Method (_DSM) support
+ */
+
+ACPI_STATUS
+acpi_dsm_typed(ACPI_HANDLE handle, uint8_t *uuid, ACPI_INTEGER rev,
+ACPI_INTEGER func, const ACPI_OBJECT *arg3, ACPI_OBJECT_TYPE return_type,
+ACPI_OBJECT **return_obj)
+{
+	ACPI_OBJECT_LIST arg;
+	ACPI_OBJECT obj[4];
+	ACPI_BUFFER buf;
+	ACPI_STATUS status;
+
+	arg.Count = 4;
+	arg.Pointer = obj;
+
+	obj[0].Type = ACPI_TYPE_BUFFER;
+	obj[0].Buffer.Length = ACPI_UUID_LENGTH;
+	obj[0].Buffer.Pointer = uuid;
+
+	obj[1].Type = ACPI_TYPE_INTEGER;
+	obj[1].Integer.Value = rev;
+
+	obj[2].Type = ACPI_TYPE_INTEGER;
+	obj[2].Integer.Value = func;
+
+	if (arg3 != NULL) {
+		obj[3] = *arg3;
+	} else {
+		obj[3].Type = ACPI_TYPE_PACKAGE;
+		obj[3].Package.Count = 0;
+		obj[3].Package.Elements = NULL;
+	}
+
+	buf.Pointer = NULL;
+	buf.Length = ACPI_ALLOCATE_BUFFER;
+
+	if (return_obj == NULL && return_type == ACPI_TYPE_ANY) {
+		status = AcpiEvaluateObject(handle, "_DSM", , NULL);
+	} else {
+		*return_obj = NULL;
+		status = AcpiEvaluateObjectTyped(handle, "_DSM", , ,
+		return_type);
+	}
+	if (ACPI_FAILURE(status)) {
+		return status;
+	}
+	if (return_obj != NULL) {
+		*return_obj = buf.Pointer;
+	} else if (buf.Pointer != NULL) {
+		ACPI_FREE(buf.Pointer);
+	}
+	return AE_OK;
+}
+
+ACPI_STATUS
+acpi_dsm_integer(ACPI_HANDLE handle, uint8_t *uuid, ACPI_INTEGER rev,
+ACPI_INTEGER func, const ACPI_OBJECT *arg3, ACPI_INTEGER *ret)
+{
+	ACPI_OBJECT *obj;
+	ACPI_STATUS status;
+
+	status = acpi_dsm_typed(handle, uuid, rev, func, arg3,
+	ACPI_TYPE_INTEGER, );
+	if (ACPI_FAILURE(status)) {
+		return status;
+	}
+
+	*ret = obj->Integer.Value;
+	ACPI_FREE(obj);
+
+	return AE_OK;
+}
+
+ACPI_STATUS
+acpi_dsm(ACPI_HANDLE handle, uint8_t *uuid, ACPI_INTEGER rev,
+ACPI_INTEGER func, const 

CVS commit: src/sys/dev/acpi

2020-12-13 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 13 20:39:20 UTC 2020

Modified Files:
src/sys/dev/acpi: files.acpi
Added Files:
src/sys/dev/acpi: acpi_cppc.c

Log Message:
acpi: Add support for Collaborative Processor Performance Control (CPPC).

CPPC is the modern replacement for processor performance controls (P-states
and T-states). The _CPC method on a processor device contains information
about supported performance levels of the device.

This driver reports the supported performance levels and allows for
setting the desired level using the machdep.cpufreq.cpuN.* sysctls. Note
that a "performance level" value is not guaranteed to represent a CPU
frequency, so treat the numbers reported as such.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/acpi/acpi_cppc.c
cvs rdiff -u -r1.118 -r1.119 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.118 src/sys/dev/acpi/files.acpi:1.119
--- src/sys/dev/acpi/files.acpi:1.118	Sun Dec 13 20:27:53 2020
+++ src/sys/dev/acpi/files.acpi	Sun Dec 13 20:39:20 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.118 2020/12/13 20:27:53 jmcneill Exp $
+#	$NetBSD: files.acpi,v 1.119 2020/12/13 20:39:20 jmcneill Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -111,6 +111,11 @@ device	acpipcc
 attach	acpipcc at acpisdtbus
 file	dev/acpi/acpi_pcc.c		acpipcc
 
+# ACPI Collaborative Processor Performance Control
+device	acpicppc: acpipcc
+attach	acpicppc at acpinodebus
+file	dev/acpi/acpi_cppc.c		acpicppc
+
 # Serial interface
 attach	com at acpinodebus with com_acpi
 file	dev/acpi/com_acpi.c		com_acpi

Added files:

Index: src/sys/dev/acpi/acpi_cppc.c
diff -u /dev/null src/sys/dev/acpi/acpi_cppc.c:1.1
--- /dev/null	Sun Dec 13 20:39:20 2020
+++ src/sys/dev/acpi/acpi_cppc.c	Sun Dec 13 20:39:20 2020
@@ -0,0 +1,440 @@
+/* $NetBSD: acpi_cppc.c,v 1.1 2020/12/13 20:39:20 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2020 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * ACPI Collaborative Processor Performance Control support.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: acpi_cppc.c,v 1.1 2020/12/13 20:39:20 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#include 
+
+/* _CPC package elements */
+typedef enum CPCPackageElement {
+	CPCNumEntries,
+	CPCRevision,
+	CPCHighestPerformance,
+	CPCNominalPerformance,
+	CPCLowestNonlinearPerformance,
+	CPCLowestPerformance,
+	CPCGuaranteedPerformanceReg,
+	CPCDesiredPerformanceReg,
+	CPCMinimumPerformanceReg,
+	CPCMaximumPerformanceReg,
+	CPCPerformanceReductionToleranceReg,
+	CPCTimeWindowReg,
+	CPCCounterWraparoundTime,
+	CPCReferencePerformanceCounterReg,
+	CPCDeliveredPerformanceCounterReg,
+	CPCPerformanceLimitedReg,
+	CPCCPPCEnableReg,
+	CPCAutonomousSelectionEnable,
+	CPCAutonomousActivityWindowReg,
+	CPCEnergyPerformancePreferenceReg,
+	CPCReferencePerformance,
+	CPCLowestFrequency,
+	CPCNominalFrequency,
+} CPCPackageElement;
+
+/* PCC command numbers */
+#define	CPPC_PCC_READ	0x00
+#define	CPPC_PCC_WRITE	0x01
+
+struct cppc_softc {
+	device_t		sc_dev;
+	struct cpu_info	*	sc_cpuinfo;
+	ACPI_HANDLE		sc_handle;
+	ACPI_OBJECT *		sc_cpc;
+	u_int			sc_ncpc;
+
+	char *			sc_available;
+	int			sc_node_target;
+	int			sc_node_current;
+	ACPI_INTEGER		sc_max_target;
+	ACPI_INTEGER		sc_min_target;
+};
+
+static int		cppc_match(device_t, cfdata_t, void *);
+static void		cppc_attach(device_t, device_t, void *);
+
+static 

CVS commit: src/sys/dev/acpi

2020-12-13 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 13 20:27:53 UTC 2020

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

Log Message:
acpi: Add support for ACPI Platform Communications Channel (PCC).


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/acpi/acpi_pcc.c \
src/sys/dev/acpi/acpi_pcc.h
cvs rdiff -u -r1.117 -r1.118 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.117 src/sys/dev/acpi/files.acpi:1.118
--- src/sys/dev/acpi/files.acpi:1.117	Mon Dec  7 10:57:41 2020
+++ src/sys/dev/acpi/files.acpi	Sun Dec 13 20:27:53 2020
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.117 2020/12/07 10:57:41 jmcneill Exp $
+#	$NetBSD: files.acpi,v 1.118 2020/12/13 20:27:53 jmcneill Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -106,6 +106,11 @@ device	acpipcd
 attach	acpipcd at acpinodebus
 file	dev/acpi/acpi_pcd.c		acpipcd
 
+# Platform Communications Channel
+device	acpipcc
+attach	acpipcc at acpisdtbus
+file	dev/acpi/acpi_pcc.c		acpipcc
+
 # Serial interface
 attach	com at acpinodebus with com_acpi
 file	dev/acpi/com_acpi.c		com_acpi

Added files:

Index: src/sys/dev/acpi/acpi_pcc.c
diff -u /dev/null src/sys/dev/acpi/acpi_pcc.c:1.1
--- /dev/null	Sun Dec 13 20:27:53 2020
+++ src/sys/dev/acpi/acpi_pcc.c	Sun Dec 13 20:27:53 2020
@@ -0,0 +1,389 @@
+/* $NetBSD: acpi_pcc.c,v 1.1 2020/12/13 20:27:53 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2020 Jared McNeill 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Platform Communications Channel (PCC) device driver.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: acpi_pcc.c,v 1.1 2020/12/13 20:27:53 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+
+#define	PCC_MEMORY_BARRIER()	membar_sync()
+#if defined(__aarch64__)
+#define	PCC_DMA_BARRIER()	__asm __volatile("dsb sy" ::: "memory")
+#else
+#error PCC_BARRIER not implemented on this platform
+#endif
+
+#define	PCC_SIGNATURE(space_id)		(0x50434300 | (space_id))
+#define	PCC_STATUS_COMMAND_COMPLETE	__BIT(0)
+#define	PCC_STATUS_COMMAND_ERROR	__BIT(2)
+
+struct pcc_register {
+	ACPI_GENERIC_ADDRESS	reg_addr;
+	uint64_t		reg_preserve;
+	uint64_t		reg_set;
+};
+
+struct pcc_subspace {
+	uint8_t			ss_id;
+	uint8_t			ss_type;
+	void *			ss_data;
+	size_t			ss_len;
+	struct pcc_register	ss_doorbell_reg;
+	uint32_t		ss_latency;
+	uint32_t		ss_turnaround;
+	kmutex_t		ss_lock;
+};
+
+struct pcc_softc {
+	device_t		sc_dev;
+	struct pcc_subspace *	sc_ss;
+	u_int			sc_nss;
+};
+
+typedef void (*pcc_subspace_callback)(ACPI_SUBTABLE_HEADER *, uint8_t, void *);
+
+static int	pcc_match(device_t, cfdata_t, void *);
+static void	pcc_attach(device_t, device_t, void *);
+
+static uint8_t	pcc_subspace_foreach(ACPI_TABLE_PCCT *,
+ pcc_subspace_callback, void *);
+static void	pcc_subspace_attach(ACPI_SUBTABLE_HEADER *, uint8_t, void *);
+
+static struct pcc_softc *pcc_softc = NULL;
+
+CFATTACH_DECL_NEW(acpipcc, sizeof(struct pcc_softc),
+pcc_match, pcc_attach, NULL, NULL);
+
+static int
+pcc_match(device_t parent, cfdata_t cf, void *aux)
+{
+	ACPI_TABLE_HEADER *hdrp = aux;
+
+	return memcmp(hdrp->Signature, ACPI_SIG_PCCT, ACPI_NAMESEG_SIZE) == 0;
+}
+
+static void
+pcc_attach(device_t parent, device_t self, void *aux)
+{
+	struct pcc_softc * const sc = device_private(self);
+	ACPI_TABLE_PCCT *pcct = aux;
+	u_int count;
+
+	if (pcc_softc != NULL) {
+		aprint_error(": Already attached!\n");
+		

CVS commit: src/sys/dev/acpi

2020-12-13 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Sun Dec 13 08:20:56 UTC 2020

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

Log Message:
Add missing include


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/acpi/atppc_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/atppc_acpi.c
diff -u src/sys/dev/acpi/atppc_acpi.c:1.20 src/sys/dev/acpi/atppc_acpi.c:1.21
--- src/sys/dev/acpi/atppc_acpi.c:1.20	Fri Dec 11 07:01:27 2020
+++ src/sys/dev/acpi/atppc_acpi.c	Sun Dec 13 08:20:56 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: atppc_acpi.c,v 1.20 2020/12/11 07:01:27 martin Exp $ */
+/* $NetBSD: atppc_acpi.c,v 1.21 2020/12/13 08:20:56 martin Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.20 2020/12/11 07:01:27 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.21 2020/12/13 08:20:56 martin Exp $");
 
 #include "opt_atppc.h"
 
@@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c
 #include 
 
 #include 
+#include 
 
 #include 
 



CVS commit: src/sys/dev/acpi

2020-12-10 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Dec 11 07:01:27 UTC 2020

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

Log Message:
Fix editor mishap in r1.18


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/sys/dev/acpi/atppc_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/atppc_acpi.c
diff -u src/sys/dev/acpi/atppc_acpi.c:1.19 src/sys/dev/acpi/atppc_acpi.c:1.20
--- src/sys/dev/acpi/atppc_acpi.c:1.19	Mon Dec  7 10:02:51 2020
+++ src/sys/dev/acpi/atppc_acpi.c	Fri Dec 11 07:01:27 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: atppc_acpi.c,v 1.19 2020/12/07 10:02:51 jmcneill Exp $ */
+/* $NetBSD: atppc_acpi.c,v 1.20 2020/12/11 07:01:27 martin Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.19 2020/12/07 10:02:51 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.20 2020/12/11 07:01:27 martin Exp $");
 
 #include "opt_atppc.h"
 
@@ -142,7 +142,7 @@ atppc_acpi_attach(device_t parent, devic
 
 	sc->sc_ieh = acpi_intr_establish(self,
 	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
-	IPL_TTY, false, atppcintr, self device_xname(self));
+	IPL_TTY, false, atppcintr, self, device_xname(self));
 	if (sc->sc_ieh == NULL) {
 		aprint_error_dev(self, "unable to establish interrupt\n");
 		goto out;



CVS commit: src/sys/dev/acpi

2020-12-07 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Dec  7 10:02:51 UTC 2020

Modified Files:
src/sys/dev/acpi: ahcisata_acpi.c amdccp_acpi.c atppc_acpi.c
dwiic_acpi.c ehci_acpi.c fdc_acpi.c genet_acpi.c lpt_acpi.c
mpu_acpi.c plgpio_acpi.c spic_acpi.c virtio_acpi.c wb_acpi.c
xhci_acpi.c

Log Message:
Fix 32-bit build.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/ahcisata_acpi.c \
src/sys/dev/acpi/plgpio_acpi.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/amdccp_acpi.c \
src/sys/dev/acpi/dwiic_acpi.c src/sys/dev/acpi/ehci_acpi.c \
src/sys/dev/acpi/virtio_acpi.c
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/acpi/atppc_acpi.c
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/acpi/fdc_acpi.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/genet_acpi.c
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/acpi/lpt_acpi.c
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/acpi/mpu_acpi.c
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/acpi/spic_acpi.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/wb_acpi.c
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/acpi/xhci_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/ahcisata_acpi.c
diff -u src/sys/dev/acpi/ahcisata_acpi.c:1.5 src/sys/dev/acpi/ahcisata_acpi.c:1.6
--- src/sys/dev/acpi/ahcisata_acpi.c:1.5	Wed Apr 15 19:26:51 2020
+++ src/sys/dev/acpi/ahcisata_acpi.c	Mon Dec  7 10:02:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ahcisata_acpi.c,v 1.5 2020/04/15 19:26:51 jmcneill Exp $ */
+/* $NetBSD: ahcisata_acpi.c,v 1.6 2020/12/07 10:02:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_acpi.c,v 1.5 2020/04/15 19:26:51 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_acpi.c,v 1.6 2020/12/07 10:02:51 jmcneill Exp $");
 
 #include 
 #include 
@@ -112,7 +112,8 @@ ahcisata_acpi_attach(device_t parent, de
 		sc->sc_dmat = aa->aa_dmat;
 	}
 
-	ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+	ih = acpi_intr_establish(self,
+	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
 	IPL_BIO, false, ahci_intr, sc, device_xname(self));
 	if (ih == NULL) {
 		aprint_error_dev(self, "couldn't install interrupt handler\n");
Index: src/sys/dev/acpi/plgpio_acpi.c
diff -u src/sys/dev/acpi/plgpio_acpi.c:1.5 src/sys/dev/acpi/plgpio_acpi.c:1.6
--- src/sys/dev/acpi/plgpio_acpi.c:1.5	Fri Nov 23 14:08:40 2018
+++ src/sys/dev/acpi/plgpio_acpi.c	Mon Dec  7 10:02:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: plgpio_acpi.c,v 1.5 2018/11/23 14:08:40 jmcneill Exp $ */
+/* $NetBSD: plgpio_acpi.c,v 1.6 2020/12/07 10:02:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: plgpio_acpi.c,v 1.5 2018/11/23 14:08:40 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: plgpio_acpi.c,v 1.6 2020/12/07 10:02:51 jmcneill Exp $");
 
 #include 
 #include 
@@ -131,7 +131,8 @@ plgpio_acpi_attach(device_t parent, devi
 		goto done;
 	}
 
-	ih = acpi_intr_establish(self, (uint64_t)asc->sc_handle,
+	ih = acpi_intr_establish(self,
+	(uint64_t)(uintptr_t)asc->sc_handle,
 	IPL_VM, false, plgpio_acpi_intr, asc, device_xname(self));
 	if (ih == NULL)
 		aprint_error_dev(self, "couldn't establish interrupt\n");

Index: src/sys/dev/acpi/amdccp_acpi.c
diff -u src/sys/dev/acpi/amdccp_acpi.c:1.3 src/sys/dev/acpi/amdccp_acpi.c:1.4
--- src/sys/dev/acpi/amdccp_acpi.c:1.3	Sun Dec  6 12:23:13 2020
+++ src/sys/dev/acpi/amdccp_acpi.c	Mon Dec  7 10:02:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: amdccp_acpi.c,v 1.3 2020/12/06 12:23:13 jmcneill Exp $ */
+/* $NetBSD: amdccp_acpi.c,v 1.4 2020/12/07 10:02:51 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2018 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdccp_acpi.c,v 1.3 2020/12/06 12:23:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdccp_acpi.c,v 1.4 2020/12/07 10:02:51 jmcneill Exp $");
 
 #include 
 #include 
@@ -95,7 +95,8 @@ amdccp_acpi_attach(device_t parent, devi
 	}
 
 #if notyet
-	ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+	ih = acpi_intr_establish(self,
+	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
 	IPL_VM, true, amdccp_intr, sc, device_xname(self));
 	if (ih == NULL) {
 		aprint_error_dev(self, "couldn't install interrupt handler\n");
Index: src/sys/dev/acpi/dwiic_acpi.c
diff -u src/sys/dev/acpi/dwiic_acpi.c:1.3 src/sys/dev/acpi/dwiic_acpi.c:1.4
--- src/sys/dev/acpi/dwiic_acpi.c:1.3	Mon Sep 23 08:50:52 2019
+++ src/sys/dev/acpi/dwiic_acpi.c	Mon Dec  7 10:02:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: dwiic_acpi.c,v 1.3 2019/09/23 08:50:52 jmcneill Exp $ */
+/* $NetBSD: dwiic_acpi.c,v 1.4 2020/12/07 10:02:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.3 2019/09/23 08:50:52 

CVS commit: src/sys/dev/acpi

2020-12-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec  6 12:47:12 UTC 2020

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

Log Message:
Fix typo in comment


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/acpi/acpi_mcfg.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_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.20 src/sys/dev/acpi/acpi_mcfg.c:1.21
--- src/sys/dev/acpi/acpi_mcfg.c:1.20	Tue Jul  7 03:38:48 2020
+++ src/sys/dev/acpi/acpi_mcfg.c	Sun Dec  6 12:47:12 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.20 2020/07/07 03:38:48 thorpej Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.21 2020/12/06 12:47:12 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.20 2020/07/07 03:38:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.21 2020/12/06 12:47:12 jmcneill Exp $");
 
 #include 
 #include 
@@ -576,7 +576,7 @@ acpimcfg_map_bus(device_t self, pci_chip
 	mb = >ms_bus[boff];
 	baddr = seg->ms_address + (bus * ACPIMCFG_SIZE_PER_BUS);
 
-	/* Map extended configration space of all dev/func. */
+	/* Map extended configuration space of all dev/func. */
 	error = bus_space_map(seg->ms_bst, baddr, ACPIMCFG_SIZE_PER_BUS, 0,
 	);
 	if (error != 0)
@@ -797,7 +797,7 @@ acpimcfg_configure_bus(device_t self, pc
 		mb = >ms_bus[boff];
 		baddr = seg->ms_address + (b * ACPIMCFG_SIZE_PER_BUS);
 
-		/* Map extended configration space of all dev/func. */
+		/* Map extended configuration space of all dev/func. */
 		error = bus_space_map(seg->ms_bst, baddr, ACPIMCFG_SIZE_PER_BUS, 0,
 		[b]);
 		if (error != 0)



CVS commit: src/sys/dev/acpi

2020-12-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec  6 12:23:13 UTC 2020

Modified Files:
src/sys/dev/acpi: amdccp_acpi.c atppc_acpi.c fdc_acpi.c lpt_acpi.c
mpu_acpi.c pckbc_acpi.c spic_acpi.c wb_acpi.c

Log Message:
acpi: Use acpi_intr_establish to install interrupt handlers

Get rid of bus-specific (isa_intr_establish) and MD (intr_establish) calls
from MI ACPI code, and use acpi_intr_establish everywhere.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/amdccp_acpi.c
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/acpi/atppc_acpi.c
cvs rdiff -u -r1.43 -r1.44 src/sys/dev/acpi/fdc_acpi.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/acpi/lpt_acpi.c
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/acpi/mpu_acpi.c
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/acpi/pckbc_acpi.c
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/spic_acpi.c
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/wb_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/amdccp_acpi.c
diff -u src/sys/dev/acpi/amdccp_acpi.c:1.2 src/sys/dev/acpi/amdccp_acpi.c:1.3
--- src/sys/dev/acpi/amdccp_acpi.c:1.2	Sun Oct 21 11:09:20 2018
+++ src/sys/dev/acpi/amdccp_acpi.c	Sun Dec  6 12:23:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: amdccp_acpi.c,v 1.2 2018/10/21 11:09:20 jmcneill Exp $ */
+/* $NetBSD: amdccp_acpi.c,v 1.3 2020/12/06 12:23:13 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2018 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: amdccp_acpi.c,v 1.2 2018/10/21 11:09:20 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: amdccp_acpi.c,v 1.3 2020/12/06 12:23:13 jmcneill Exp $");
 
 #include 
 #include 
@@ -36,6 +36,7 @@ __KERNEL_RCSID(0, "$NetBSD: amdccp_acpi.
 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -68,9 +69,6 @@ amdccp_acpi_attach(device_t parent, devi
 	struct acpi_attach_args *aa = aux;
 	struct acpi_resources res;
 	struct acpi_mem *mem;
-#if notyet
-	struct acpi_irq *irq;
-#endif
 	ACPI_STATUS rv;
 #if notyet
 	void *ih;
@@ -89,23 +87,16 @@ amdccp_acpi_attach(device_t parent, devi
 		goto done;
 	}
 
-#if notyet
-	irq = acpi_res_irq(, 0);
-	if (irq == NULL) {
-		aprint_error_dev(self, "couldn't find irq resource\n");
-		goto done;
-	}
-
-#endif
 	sc->sc_bst = aa->aa_memt;
-	if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0, >sc_bsh) != 0) {
+	if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0,
+	>sc_bsh) != 0) {
 		aprint_error_dev(self, "couldn't map registers\n");
 		goto done;
 	}
 
 #if notyet
-	const int type = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL;
-	ih = intr_establish(irq->ar_irq, IPL_VM, type | IST_MPSAFE, amdccp_intr, sc);
+	ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+	IPL_VM, true, amdccp_intr, sc, device_xname(self));
 	if (ih == NULL) {
 		aprint_error_dev(self, "couldn't install interrupt handler\n");
 		return;

Index: src/sys/dev/acpi/atppc_acpi.c
diff -u src/sys/dev/acpi/atppc_acpi.c:1.17 src/sys/dev/acpi/atppc_acpi.c:1.18
--- src/sys/dev/acpi/atppc_acpi.c:1.17	Fri Mar  5 14:00:17 2010
+++ src/sys/dev/acpi/atppc_acpi.c	Sun Dec  6 12:23:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: atppc_acpi.c,v 1.17 2010/03/05 14:00:17 jruoho Exp $ */
+/* $NetBSD: atppc_acpi.c,v 1.18 2020/12/06 12:23:13 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2004 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.17 2010/03/05 14:00:17 jruoho Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atppc_acpi.c,v 1.18 2020/12/06 12:23:13 jmcneill Exp $");
 
 #include "opt_atppc.h"
 
@@ -98,10 +98,8 @@ atppc_acpi_attach(device_t parent, devic
 	struct acpi_attach_args *aa = aux;
 	struct acpi_resources res;
 	struct acpi_io *io;
-	struct acpi_irq *irq;
 	struct acpi_drq *drq;
 	ACPI_STATUS rv;
-	int nirq;
 
 	sc->sc_dev_ok = ATPPC_NOATTACH;
 
@@ -120,14 +118,6 @@ atppc_acpi_attach(device_t parent, devic
 		goto out;
 	}
 
-	/* find our IRQ */
-	irq = acpi_res_irq(, 0);
-	if (irq == NULL) {
-		aprint_error_dev(sc->sc_dev, "unable to find irq resource\n");
-		goto out;
-	}
-	nirq = irq->ar_irq;
-
 	/* find our DRQ */
 	drq = acpi_res_drq(, 0);
 	if (drq == NULL) {
@@ -150,9 +140,12 @@ atppc_acpi_attach(device_t parent, devic
 		goto out;
 	}
 
-	sc->sc_ieh = isa_intr_establish(aa->aa_ic, nirq,
-	(irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL,
-	IPL_TTY, atppcintr, sc->sc_dev);
+	sc->sc_ieh = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+	IPL_TTY, false, atppcintr, self device_xname(self));
+	if (sc->sc_ieh == NULL) {
+		aprint_error_dev(self, "unable to establish interrupt\n");
+		goto out;
+	}
 
 	/* setup DMA hooks */
 	if (atppc_isadma_setup(sc, asc->sc_ic, asc->sc_drq) == 0) {

Index: src/sys/dev/acpi/fdc_acpi.c
diff -u src/sys/dev/acpi/fdc_acpi.c:1.43 src/sys/dev/acpi/fdc_acpi.c:1.44
--- src/sys/dev/acpi/fdc_acpi.c:1.43	Mon Apr 13 16:33:23 

CVS commit: src/sys/dev/acpi

2020-12-06 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec  6 11:38:28 UTC 2020

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

Log Message:
acpi: remove unused acpi_quirks_osi_* functions


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/acpi/acpi_quirks.c
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/acpi/acpivar.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/acpi_quirks.c
diff -u src/sys/dev/acpi/acpi_quirks.c:1.21 src/sys/dev/acpi/acpi_quirks.c:1.22
--- src/sys/dev/acpi/acpi_quirks.c:1.21	Mon May  4 20:06:38 2020
+++ src/sys/dev/acpi/acpi_quirks.c	Sun Dec  6 11:38:28 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_quirks.c,v 1.21 2020/05/04 20:06:38 jdolecek Exp $ */
+/* $NetBSD: acpi_quirks.c,v 1.22 2020/12/06 11:38:28 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.21 2020/05/04 20:06:38 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.22 2020/12/06 11:38:28 jmcneill Exp $");
 
 #include "opt_acpi.h"
 
@@ -211,61 +211,3 @@ acpi_find_quirks(void)
 
 	return 0;
 }
-
-/*
- * Add or delete a string to the list that should return
- * true when _OSI is being queried. The defaults are:
- *
- *	"Windows 2000"		# Windows 2000
- *	"Windows 2001"		# Windows XP
- *	"Windows 2001 SP1"	# Windows XP SP1
- *	"Windows 2001.1"	# Windows Server 2003
- *	"Windows 2001 SP2"	# Windows XP SP2
- *	"Windows 2001.1 SP1"	# Windows Server 2003 SP1
- *	"Windows 2006"		# Windows Vista
- *	"Windows 2006.1"	# Windows Server 2008
- *	"Windows 2006 SP1"	# Windows Vista SP1
- *	"Windows 2006 SP2"	# Windows Vista SP2
- *	"Windows 2009"		# Windows 7 and Server 2008
- */
-int
-acpi_quirks_osi_add(const char *str)
-{
-	ACPI_STATUS rv;
-
-	if (str == NULL || *str == '\0')
-		return EINVAL;
-
-	rv = AcpiInstallInterface(__UNCONST(str));
-
-	return (rv != AE_OK) ? EIO : 0;
-}
-
-int
-acpi_quirks_osi_del(const char *str)
-{
-	ACPI_STATUS rv;
-
-	if (str == NULL || *str == '\0')
-		return EINVAL;
-
-	rv = AcpiRemoveInterface(__UNCONST(str));
-
-	return (rv != AE_OK) ? EIO : 0;
-}
-
-#if 0
-static void
-acpi_quirks_osi_linux(void)
-{
-	(void)acpi_quirks_osi_add("Linux");
-}
-
-static void
-acpi_quirks_osi_vista(void)
-{
-	(void)acpi_quirks_osi_del("Windows 2006");
-	(void)acpi_quirks_osi_del("Windows 2006 SP1");
-	(void)acpi_quirks_osi_del("Windows 2006 SP2");
-}
-#endif

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.82 src/sys/dev/acpi/acpivar.h:1.83
--- src/sys/dev/acpi/acpivar.h:1.82	Fri Jan 17 17:06:32 2020
+++ src/sys/dev/acpi/acpivar.h	Sun Dec  6 11:38:28 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.82 2020/01/17 17:06:32 jmcneill Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.83 2020/12/06 11:38:28 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -382,8 +382,6 @@ struct acpi_quirk {
 #define ACPI_QUIRK_OLDBIOS	0x0010	/* BIOS date blacklisted */
 
 int	acpi_find_quirks(void);
-int	acpi_quirks_osi_add(const char *);
-int	acpi_quirks_osi_del(const char *);
 
 #ifdef ACPI_DEBUG
 void	acpi_debug_init(void);



CVS commit: src/sys/dev/acpi

2020-11-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Nov  8 14:16:59 UTC 2020

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

Log Message:
Ignore PNP0001 (EISA interrupt controller) and PNP0C02 (motherboard
resources) when enumerating devices.


To generate a diff of this commit:
cvs rdiff -u -r1.285 -r1.286 src/sys/dev/acpi/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/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.285 src/sys/dev/acpi/acpi.c:1.286
--- src/sys/dev/acpi/acpi.c:1.285	Mon Jun 22 16:14:18 2020
+++ src/sys/dev/acpi/acpi.c	Sun Nov  8 14:16:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.285 2020/06/22 16:14:18 maxv Exp $	*/
+/*	$NetBSD: acpi.c,v 1.286 2020/11/08 14:16:59 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.285 2020/06/22 16:14:18 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.286 2020/11/08 14:16:59 jmcneill Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -166,9 +166,11 @@ static const char * const acpi_ignored_i
 #if defined(i386) || defined(x86_64)
 	"ACPI0007",	/* ACPI CPUs do not attach to acpi(4) */
 	"PNP",	/* AT interrupt controller is handled internally */
+	"PNP0001",	/* EISA interrupt controller is handled internally */
 	"PNP0200",	/* AT DMA controller is handled internally */
 	"PNP0A??",	/* PCI Busses are handled internally */
 	"PNP0B00",	/* AT RTC is handled internally */
+	"PNP0C02",	/* PnP motherboard resources */
 	"PNP0C0F",	/* ACPI PCI link devices are handled internally */
 #endif
 #if defined(x86_64)



CVS commit: src/sys/dev/acpi

2020-10-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 24 08:57:06 UTC 2020

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

Log Message:
Test the 64bit dma tag with BUS_DMA_TAG_VALID before using it.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/vmbus_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/vmbus_acpi.c
diff -u src/sys/dev/acpi/vmbus_acpi.c:1.2 src/sys/dev/acpi/vmbus_acpi.c:1.3
--- src/sys/dev/acpi/vmbus_acpi.c:1.2	Fri May 24 14:28:48 2019
+++ src/sys/dev/acpi/vmbus_acpi.c	Sat Oct 24 08:57:06 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: vmbus_acpi.c,v 1.2 2019/05/24 14:28:48 nonaka Exp $	*/
+/*	$NetBSD: vmbus_acpi.c,v 1.3 2020/10/24 08:57:06 skrll Exp $	*/
 
 /*
  * Copyright (c) 2018 Kimihiro Nonaka 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: vmbus_acpi.c,v 1.2 2019/05/24 14:28:48 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vmbus_acpi.c,v 1.3 2020/10/24 08:57:06 skrll Exp $");
 
 #include 
 #include 
@@ -84,7 +84,8 @@ vmbus_acpi_attach(device_t parent, devic
 	sc->sc.sc_dev = self;
 	sc->sc.sc_iot = aa->aa_iot;
 	sc->sc.sc_memt = aa->aa_memt;
-	sc->sc.sc_dmat = aa->aa_dmat64 ? aa->aa_dmat64 : aa->aa_dmat;
+	sc->sc.sc_dmat = BUS_DMA_TAG_VALID(aa->aa_dmat64) ?
+	aa->aa_dmat64 : aa->aa_dmat;
 
 	if (vmbus_attach(>sc))
 		return;



CVS commit: src/sys/dev/acpi

2020-10-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 24 08:55:23 UTC 2020

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

Log Message:
Fix DMA size reporting.  Previously it could report 64bit DMA when the tag
wasn't available (and it fell back to 32bit tag)


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/acpi/xhci_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/xhci_acpi.c
diff -u src/sys/dev/acpi/xhci_acpi.c:1.7 src/sys/dev/acpi/xhci_acpi.c:1.8
--- src/sys/dev/acpi/xhci_acpi.c:1.7	Fri Jan 31 23:12:13 2020
+++ src/sys/dev/acpi/xhci_acpi.c	Sat Oct 24 08:55:23 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci_acpi.c,v 1.7 2020/01/31 23:12:13 jmcneill Exp $ */
+/* $NetBSD: xhci_acpi.c,v 1.8 2020/10/24 08:55:23 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.7 2020/01/31 23:12:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.8 2020/10/24 08:55:23 skrll Exp $");
 
 #include 
 #include 
@@ -129,10 +129,9 @@ xhci_acpi_attach(device_t parent, device
 	}
 
 	hccparams = bus_space_read_4(sc->sc_iot, sc->sc_ioh, XHCI_HCCPARAMS);
-	if (XHCI_HCC_AC64(hccparams)) {
+	if (XHCI_HCC_AC64(hccparams) && BUS_DMA_TAG_VALID(aa->aa_dmat64)) {
 		aprint_verbose_dev(self, "using 64-bit DMA\n");
-		sc->sc_bus.ub_dmatag = BUS_DMA_TAG_VALID(aa->aa_dmat64) ?
-		aa->aa_dmat64 : aa->aa_dmat;
+		sc->sc_bus.ub_dmatag = aa->aa_dmat64;
 	} else {
 		aprint_verbose_dev(self, "using 32-bit DMA\n");
 		sc->sc_bus.ub_dmatag = aa->aa_dmat;



CVS commit: src/sys/dev/acpi

2020-10-24 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Sat Oct 24 07:21:01 UTC 2020

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

Log Message:
Use the 64bit DMA tag if its valid.

There appears to be a bug in virtio / ld_virtio and bounce buffers that
was triggered when the bus_dmatag_subregion code on arm64 was fixed to
correctly create a new tag for the 32bit tag vs the system (64bit) tag.
This change avoids the bug.

PR/55737: Apparent bug in evbarm64 DMA code causes filesystem corruption


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/virtio_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/virtio_acpi.c
diff -u src/sys/dev/acpi/virtio_acpi.c:1.2 src/sys/dev/acpi/virtio_acpi.c:1.3
--- src/sys/dev/acpi/virtio_acpi.c:1.2	Fri Nov 16 23:18:17 2018
+++ src/sys/dev/acpi/virtio_acpi.c	Sat Oct 24 07:21:01 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_acpi.c,v 1.2 2018/11/16 23:18:17 jmcneill Exp $ */
+/* $NetBSD: virtio_acpi.c,v 1.3 2020/10/24 07:21:01 skrll Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_acpi.c,v 1.2 2018/11/16 23:18:17 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_acpi.c,v 1.3 2020/10/24 07:21:01 skrll Exp $");
 
 #include 
 #include 
@@ -95,7 +95,14 @@ virtio_acpi_attach(device_t parent, devi
 	sc->sc_handle = aa->aa_node->ad_handle;
 	msc->sc_iot = aa->aa_memt;
 	vsc->sc_dev = self;
-	vsc->sc_dmat = aa->aa_dmat;
+
+	if (BUS_DMA_TAG_VALID(aa->aa_dmat64)) {
+		aprint_verbose(": using 64-bit DMA");
+		vsc->sc_dmat = aa->aa_dmat64;
+	} else {
+		aprint_verbose(": using 32-bit DMA");
+		vsc->sc_dmat = aa->aa_dmat;
+	}
 
 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
 	, _resource_parse_ops_default);



CVS commit: src/sys/dev/acpi

2020-10-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 23 11:00:09 UTC 2020

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

Log Message:
Use MI acpi_intr_establish_irq instead of MD intr_establish


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/acpi_ged.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_ged.c
diff -u src/sys/dev/acpi/acpi_ged.c:1.1 src/sys/dev/acpi/acpi_ged.c:1.2
--- src/sys/dev/acpi/acpi_ged.c:1.1	Mon Oct 22 22:36:19 2018
+++ src/sys/dev/acpi/acpi_ged.c	Fri Oct 23 11:00:09 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_ged.c,v 1.1 2018/10/22 22:36:19 jmcneill Exp $ */
+/* $NetBSD: acpi_ged.c,v 1.2 2020/10/23 11:00:09 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ged.c,v 1.1 2018/10/22 22:36:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ged.c,v 1.2 2020/10/23 11:00:09 jmcneill Exp $");
 
 #include 
 #include 
@@ -42,6 +42,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_ged.c,v
 #include 
 #include 
 #include 
+#include 
 
 static int	acpi_ged_match(device_t, cfdata_t, void *);
 static void	acpi_ged_attach(device_t, device_t, void *);
@@ -83,8 +84,8 @@ acpi_ged_register_event(void *priv, stru
 	device_t dev = priv;
 	void *ih;
 
-	const int type = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL;
-	ih = intr_establish(irq->ar_irq, IPL_VM, type, acpi_ged_intr, ev);
+	ih = acpi_intr_establish_irq(dev, irq, IPL_VM, true,
+	acpi_ged_intr, ev, device_xname(dev));
 	if (ih == NULL) {
 		aprint_error_dev(dev, "couldn't establish interrupt (irq %d)\n", irq->ar_irq);
 		return;



CVS commit: src/sys/dev/acpi

2020-10-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 23 10:59:37 UTC 2020

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

Log Message:
Add acpi_intr_establish_irq, which is like acpi_intr_establish except
it takes a struct acpi_irq * instead of ACPI_HANDLE. Useful if a device
has more than one IRQ resource (acpi_intr_establish always picks the
first).


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/acpi_intr.h
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/acpi/acpi_util.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_intr.h
diff -u src/sys/dev/acpi/acpi_intr.h:1.4 src/sys/dev/acpi/acpi_intr.h:1.5
--- src/sys/dev/acpi/acpi_intr.h:1.4	Sun Dec 22 15:57:07 2019
+++ src/sys/dev/acpi/acpi_intr.h	Fri Oct 23 10:59:37 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_intr.h,v 1.4 2019/12/22 15:57:07 thorpej Exp $ */
+/* $NetBSD: acpi_intr.h,v 1.5 2020/10/23 10:59:37 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -34,6 +34,8 @@
 
 void *		acpi_intr_establish(device_t, uint64_t, int, bool,
 		int (*intr)(void *), void *, const char *);
+void *		acpi_intr_establish_irq(device_t, struct acpi_irq *, int,
+		bool, int (*intr)(void *), void *, const char *);
 void		acpi_intr_mask(void *);
 void		acpi_intr_unmask(void *);
 void 		acpi_intr_disestablish(void *);

Index: src/sys/dev/acpi/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.18 src/sys/dev/acpi/acpi_util.c:1.19
--- src/sys/dev/acpi/acpi_util.c:1.18	Tue Dec 31 09:10:15 2019
+++ src/sys/dev/acpi/acpi_util.c	Fri Oct 23 10:59:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.18 2019/12/31 09:10:15 mlelstv Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.19 2020/10/23 10:59:37 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.18 2019/12/31 09:10:15 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.19 2020/10/23 10:59:37 jmcneill Exp $");
 
 #include 
 #include 
@@ -550,7 +550,6 @@ out:
 }
 
 struct acpi_irq_handler {
-	ACPI_HANDLE aih_hdl;
 	uint32_t aih_irq;
 	void *aih_ih;
 };
@@ -563,8 +562,7 @@ acpi_intr_establish(device_t dev, uint64
 	ACPI_HANDLE hdl = (void *)(uintptr_t)c;
 	struct acpi_resources res;
 	struct acpi_irq *irq;
-	struct acpi_irq_handler *aih = NULL;
-	void *ih;
+	void *aih = NULL;
 
 	rv = acpi_resource_parse(dev, hdl, "_CRS", ,
 	_resource_parse_ops_quiet);
@@ -575,18 +573,31 @@ acpi_intr_establish(device_t dev, uint64
 	if (irq == NULL)
 		goto end;
 
+	aih = acpi_intr_establish_irq(dev, irq, ipl, mpsafe,
+	intr, iarg, xname);
+
+end:
+	acpi_resource_cleanup();
+
+	return aih;
+}
+
+void *
+acpi_intr_establish_irq(device_t dev, struct acpi_irq *irq, int ipl,
+bool mpsafe, int (*intr)(void *), void *iarg, const char *xname)
+{
+	struct acpi_irq_handler *aih;
+	void *ih;
+
 	const int type = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL;
 	ih = acpi_md_intr_establish(irq->ar_irq, ipl, type, intr, iarg, mpsafe, xname);
 	if (ih == NULL)
-		goto end;
+		return NULL;
 
 	aih = kmem_alloc(sizeof(struct acpi_irq_handler), KM_SLEEP);
-	aih->aih_hdl = hdl;
 	aih->aih_irq = irq->ar_irq;
 	aih->aih_ih = ih;
 
-end:
-	acpi_resource_cleanup();
 	return aih;
 }
 



CVS commit: src/sys/dev/acpi

2020-07-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed Jul  8 13:41:53 UTC 2020

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

Log Message:
Update for proplib API changes.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/dev/acpi/acpi_debug.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_debug.c
diff -u src/sys/dev/acpi/acpi_debug.c:1.7 src/sys/dev/acpi/acpi_debug.c:1.8
--- src/sys/dev/acpi/acpi_debug.c:1.7	Mon Mar 23 00:37:19 2020
+++ src/sys/dev/acpi/acpi_debug.c	Wed Jul  8 13:41:53 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_debug.c,v 1.7 2020/03/23 00:37:19 chs Exp $ */
+/* $NetBSD: acpi_debug.c,v 1.8 2020/07/08 13:41:53 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen 
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_debug.c,v 1.7 2020/03/23 00:37:19 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_debug.c,v 1.8 2020/07/08 13:41:53 thorpej Exp $");
 
 #include 
 #include 
@@ -250,9 +250,9 @@ acpi_debug_getkey(prop_dictionary_t dict
 
 	while ((obj = prop_object_iterator_next(i)) != NULL) {
 
-		key = prop_dictionary_keysym_cstring_nocopy(obj);
+		key = prop_dictionary_keysym_value(obj);
 		val = prop_dictionary_get(dict, key);
-		num = prop_number_unsigned_integer_value(val);
+		num = prop_number_unsigned_value(val);
 
 		if (arg == num)
 			return key;
@@ -284,7 +284,7 @@ acpi_debug_sysctl_layer(SYSCTLFN_ARGS)
 	if (obj == NULL)
 		return EINVAL;
 
-	AcpiDbgLayer = prop_number_unsigned_integer_value(obj);
+	AcpiDbgLayer = prop_number_unsigned_value(obj);
 
 	(void)memcpy(rnode->sysctl_data, node.sysctl_data, ACPI_DEBUG_MAX);
 
@@ -314,7 +314,7 @@ acpi_debug_sysctl_level(SYSCTLFN_ARGS)
 	if (obj == NULL)
 		return EINVAL;
 
-	AcpiDbgLevel = prop_number_unsigned_integer_value(obj);
+	AcpiDbgLevel = prop_number_unsigned_value(obj);
 
 	(void)memcpy(rnode->sysctl_data, node.sysctl_data, ACPI_DEBUG_MAX);
 



CVS commit: src/sys/dev/acpi

2020-06-30 Thread Stephen Borrill
Module Name:src
Committed By:   sborrill
Date:   Tue Jun 30 13:14:21 UTC 2020

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

Log Message:
Only need to set brightness if reading the initial state fails
to sync firmware and the driver. Avoids black screen at boot time.
Thanks to jmcneill@


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 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.17 src/sys/dev/acpi/acpi_display.c:1.18
--- src/sys/dev/acpi/acpi_display.c:1.17	Tue Apr 28 11:02:37 2020
+++ src/sys/dev/acpi/acpi_display.c	Tue Jun 30 13:14:21 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_display.c,v 1.17 2020/04/28 11:02:37 jmcneill Exp $	*/
+/*	$NetBSD: acpi_display.c,v 1.18 2020/06/30 13:14:21 sborrill Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.17 2020/04/28 11:02:37 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.18 2020/06/30 13:14:21 sborrill Exp $");
 
 #include 
 #include 
@@ -647,8 +647,8 @@ acpidisp_out_attach(device_t parent, dev
 		 * Synchronize ACPI and driver brightness levels, and
 		 * check that brightness control is working.
 		 */
-		(void)acpidisp_get_brightness(osc, >bc_current);
-		if (acpidisp_set_brightness(osc, bc->bc_current)) {
+		if (acpidisp_get_brightness(osc, >bc_current) &&
+		acpidisp_set_brightness(osc, bc->bc_current)) {
 			kmem_free(bc->bc_level,
 			bc->bc_level_count * sizeof(*bc->bc_level));
 			kmem_free(bc, sizeof(*bc));



CVS commit: src/sys/dev/acpi

2020-06-22 Thread Maxime Villard
Module Name:src
Committed By:   maxv
Date:   Mon Jun 22 16:14:18 UTC 2020

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

Log Message:
Fix memory leak. Found by kLSan.


To generate a diff of this commit:
cvs rdiff -u -r1.284 -r1.285 src/sys/dev/acpi/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/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.284 src/sys/dev/acpi/acpi.c:1.285
--- src/sys/dev/acpi/acpi.c:1.284	Thu Apr  9 10:46:19 2020
+++ src/sys/dev/acpi/acpi.c	Mon Jun 22 16:14:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.284 2020/04/09 10:46:19 jmcneill Exp $	*/
+/*	$NetBSD: acpi.c,v 1.285 2020/06/22 16:14:18 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.284 2020/04/09 10:46:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.285 2020/06/22 16:14:18 maxv Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -792,6 +792,11 @@ acpi_make_devnode(ACPI_HANDLE handle, ui
 		}
 
 		awc->aw_parent = ad;
+		break;
+
+	default:
+		ACPI_FREE(devinfo);
+		break;
 	}
 
 	return AE_OK;



CVS commit: src/sys/dev/acpi

2020-06-15 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon Jun 15 15:29:46 UTC 2020

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

Log Message:
only install space handler and enable interrupt for EC if ACPI
claims the device is actually present, it's not enough when there
is entry for it in the ACPI tables

fixes interrupt storm triggered on Dell PowerEdge R220 by enabling
GPE interrupt on a non-enabled EC (for which _REG call later
fails), reported and fix tested by Dima Veselov:
http://mail-index.netbsd.org/netbsd-users/2020/03/02/msg024166.html

XXX pullup netbsd-9


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 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.83 src/sys/dev/acpi/acpi_ec.c:1.84
--- src/sys/dev/acpi/acpi_ec.c:1.83	Mon May  4 20:06:38 2020
+++ src/sys/dev/acpi/acpi_ec.c	Mon Jun 15 15:29:46 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.83 2020/05/04 20:06:38 jdolecek Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.84 2020/06/15 15:29:46 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.83 2020/05/04 20:06:38 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.84 2020/06/15 15:29:46 jdolecek Exp $");
 
 #include 
 #include 
@@ -268,6 +268,11 @@ acpiec_attach(device_t parent, device_t 
 		goto fail0;
 	}
 
+	if (!acpi_device_present(aa->aa_node->ad_handle)) {
+		aprint_normal(": not present\n");
+		goto fail0;
+	}
+
 	if (!acpiec_parse_gpe_package(self, aa->aa_node->ad_handle,
   _handle, ))
 		goto fail0;



CVS commit: src/sys/dev/acpi

2020-06-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon Jun  8 20:21:56 UTC 2020

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

Log Message:
Update for proplib(3) API changes.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/acpi_i2c.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_i2c.c
diff -u src/sys/dev/acpi/acpi_i2c.c:1.5 src/sys/dev/acpi/acpi_i2c.c:1.6
--- src/sys/dev/acpi/acpi_i2c.c:1.5	Sat Sep 28 11:24:10 2019
+++ src/sys/dev/acpi/acpi_i2c.c	Mon Jun  8 20:21:56 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_i2c.c,v 1.5 2019/09/28 11:24:10 bouyer Exp $ */
+/* $NetBSD: acpi_i2c.c,v 1.6 2020/06/08 20:21:56 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.5 2019/09/28 11:24:10 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.6 2020/06/08 20:21:56 thorpej Exp $");
 
 #include 
 #include 
@@ -189,7 +189,7 @@ acpi_enter_i2c_device(struct acpi_devnod
 		name = ad->ad_name;
 	else
 		name = ad->ad_devinfo->HardwareId.String;
-	prop_dictionary_set_cstring(dev, "name", name);
+	prop_dictionary_set_string(dev, "name", name);
 	prop_dictionary_set_uint32(dev, "addr", i2cc.i2c_addr);
 	prop_dictionary_set_uint64(dev, "cookie", (uintptr_t)ad->ad_handle);
 	/* first search by name, then by CID */



CVS commit: src/sys/dev/acpi

2020-06-03 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Thu Jun  4 03:14:36 UTC 2020

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

Log Message:
Nix trailing whitespace.  NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/dev/acpi/acpi_cpu_cstate.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_cpu_cstate.c
diff -u src/sys/dev/acpi/acpi_cpu_cstate.c:1.61 src/sys/dev/acpi/acpi_cpu_cstate.c:1.62
--- src/sys/dev/acpi/acpi_cpu_cstate.c:1.61	Sun May 31 01:39:33 2020
+++ src/sys/dev/acpi/acpi_cpu_cstate.c	Thu Jun  4 03:14:36 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_cstate.c,v 1.61 2020/05/31 01:39:33 ad Exp $ */
+/* $NetBSD: acpi_cpu_cstate.c,v 1.62 2020/06/04 03:14:36 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen 
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.61 2020/05/31 01:39:33 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.62 2020/06/04 03:14:36 riastradh Exp $");
 
 #include 
 #include 
@@ -744,8 +744,8 @@ acpicpu_cstate_idle_enter(struct acpicpu
 #ifdef notyet
 	/*
 	 * XXX This has a significant performance impact because the ACPI
-	 * timer seems very slow and with many CPUs becomes a chokepoint. 
-	 * Better to use the TSC (if invariant) or APIC timer instead. 
+	 * timer seems very slow and with many CPUs becomes a chokepoint.
+	 * Better to use the TSC (if invariant) or APIC timer instead.
 	 * Proably even getbintime().  Disabled for now as no functional
 	 * change - only C1 sleep is enabled.
 	 */



CVS commit: src/sys/dev/acpi

2020-05-30 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun May 31 01:39:33 UTC 2020

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

Log Message:
Disable read of the ACPI timer during idle, fixing performance degradation
observed with acpicpu.  C1 (MWAIT) is the deepest sleep currently enabled so
there should be no functional change.  Also, the computed nap time is run
through hztoms() which seems incorrect as the ACPI timer is running in the
MHz range.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/sys/dev/acpi/acpi_cpu_cstate.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_cpu_cstate.c
diff -u src/sys/dev/acpi/acpi_cpu_cstate.c:1.60 src/sys/dev/acpi/acpi_cpu_cstate.c:1.61
--- src/sys/dev/acpi/acpi_cpu_cstate.c:1.60	Sun Feb  3 03:19:27 2019
+++ src/sys/dev/acpi/acpi_cpu_cstate.c	Sun May 31 01:39:33 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_cpu_cstate.c,v 1.60 2019/02/03 03:19:27 mrg Exp $ */
+/* $NetBSD: acpi_cpu_cstate.c,v 1.61 2020/05/31 01:39:33 ad Exp $ */
 
 /*-
  * Copyright (c) 2010, 2011 Jukka Ruohonen 
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.60 2019/02/03 03:19:27 mrg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_cpu_cstate.c,v 1.61 2020/05/31 01:39:33 ad Exp $");
 
 #include 
 #include 
@@ -739,9 +739,18 @@ static void
 acpicpu_cstate_idle_enter(struct acpicpu_softc *sc, int state)
 {
 	struct acpicpu_cstate *cs = >sc_cstate[state];
-	uint32_t end, start, val;
+	uint32_t val;
 
+#ifdef notyet
+	/*
+	 * XXX This has a significant performance impact because the ACPI
+	 * timer seems very slow and with many CPUs becomes a chokepoint. 
+	 * Better to use the TSC (if invariant) or APIC timer instead. 
+	 * Proably even getbintime().  Disabled for now as no functional
+	 * change - only C1 sleep is enabled.
+	 */
 	start = acpitimer_read_fast(NULL);
+#endif
 
 	switch (cs->cs_method) {
 
@@ -756,8 +765,15 @@ acpicpu_cstate_idle_enter(struct acpicpu
 	}
 
 	cs->cs_evcnt.ev_count++;
+
+#ifdef notyet
+	/*
+	 * XXX As above.  Also, hztoms() seems incorrect as the ACPI timer
+	 * is running the MHz region.
+	 */
 	end = acpitimer_read_fast(NULL);
 	sc->sc_cstate_sleep = hztoms(acpitimer_delta(end, start)) * 1000;
+#endif
 }
 
 static bool



CVS commit: src/sys/dev/acpi

2020-05-17 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Sun May 17 11:32:51 UTC 2020

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

Log Message:
With the recent change of the EC address space handler, we no longer get
an ACPI_INTEGER in host byte order but a byte sized buffer with little
endian data.

Extract only the low 8 bits from buffer to get the fan speed again.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 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.47 src/sys/dev/acpi/thinkpad_acpi.c:1.48
--- src/sys/dev/acpi/thinkpad_acpi.c:1.47	Mon Aug  5 10:09:35 2019
+++ src/sys/dev/acpi/thinkpad_acpi.c	Sun May 17 11:32:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: thinkpad_acpi.c,v 1.47 2019/08/05 10:09:35 msaitoh Exp $ */
+/* $NetBSD: thinkpad_acpi.c,v 1.48 2020/05/17 11:32:51 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2007 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.47 2019/08/05 10:09:35 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: thinkpad_acpi.c,v 1.48 2020/05/17 11:32:51 mlelstv Exp $");
 
 #include 
 #include 
@@ -702,6 +702,13 @@ thinkpad_fan_refresh(struct sysmon_envsy
 		edata->state = ENVSYS_SINVALID;
 		return;
 	}
+
+	/*
+	 * Extract the low bytes from buffers
+	 */
+	lo = ((uint8_t *))[0];
+	hi = ((uint8_t *))[0];
+
 	rpm = int)hi) << 8) | ((int)lo));
 	if (rpm < 0) {
 		edata->state = ENVSYS_SINVALID;



CVS commit: src/sys/dev/acpi

2020-05-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May  8 14:42:38 UTC 2020

Modified Files:
src/sys/dev/acpi: acpi_pci.c acpi_pci.h

Log Message:
expose acpi_pcidev_pciroot_bus


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/acpi/acpi_pci.c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/acpi/acpi_pci.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/acpi_pci.c
diff -u src/sys/dev/acpi/acpi_pci.c:1.28 src/sys/dev/acpi/acpi_pci.c:1.29
--- src/sys/dev/acpi/acpi_pci.c:1.28	Sat Jan 18 12:32:57 2020
+++ src/sys/dev/acpi/acpi_pci.c	Fri May  8 14:42:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci.c,v 1.28 2020/01/18 12:32:57 jmcneill Exp $ */
+/* $NetBSD: acpi_pci.c,v 1.29 2020/05/08 14:42:38 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.28 2020/01/18 12:32:57 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.29 2020/05/08 14:42:38 jmcneill Exp $");
 
 #include 
 #include 
@@ -53,7 +53,6 @@ ACPI_MODULE_NAME	  ("acpi_pci")
 #define ACPI_HILODWORD(x) ACPI_HIWORD(ACPI_LODWORD((x)))
 #define ACPI_LOLODWORD(x) ACPI_LOWORD(ACPI_LODWORD((x)))
 
-static ACPI_STATUS	  acpi_pcidev_pciroot_bus(ACPI_HANDLE, uint16_t *);
 static ACPI_STATUS	  acpi_pcidev_pciroot_bus_callback(ACPI_RESOURCE *,
 			   void *);
 
@@ -106,7 +105,7 @@ static UINT8 acpi_pci_dsm_uuid[ACPI_UUID
  *	If successful, return AE_OK and fill *busp.  Otherwise, return an
  *	exception code and leave *busp unchanged.
  */
-static ACPI_STATUS
+ACPI_STATUS
 acpi_pcidev_pciroot_bus(ACPI_HANDLE handle, uint16_t *busp)
 {
 	ACPI_STATUS rv;

Index: src/sys/dev/acpi/acpi_pci.h
diff -u src/sys/dev/acpi/acpi_pci.h:1.11 src/sys/dev/acpi/acpi_pci.h:1.12
--- src/sys/dev/acpi/acpi_pci.h:1.11	Fri Jan 17 17:06:32 2020
+++ src/sys/dev/acpi/acpi_pci.h	Fri May  8 14:42:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci.h,v 1.11 2020/01/17 17:06:32 jmcneill Exp $ */
+/* $NetBSD: acpi_pci.h,v 1.12 2020/05/08 14:42:38 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -32,6 +32,7 @@
 #define _SYS_DEV_ACPI_ACPI_PCI_H
 
 ACPI_STATUS		 acpi_pcidev_scan(struct acpi_devnode *);
+ACPI_STATUS		 acpi_pcidev_pciroot_bus(ACPI_HANDLE, uint16_t *);
 ACPI_STATUS		 acpi_pcidev_ppb_downbus(pci_chipset_tag_t,
 		 uint16_t, uint16_t, uint16_t,
 		 uint16_t, uint16_t *);



CVS commit: src/sys/dev/acpi

2020-05-04 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Mon May  4 20:06:38 UTC 2020

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

Log Message:
constify


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/dev/acpi/acpi_ec.c
cvs rdiff -u -r1.20 -r1.21 src/sys/dev/acpi/acpi_quirks.c
cvs rdiff -u -r1.32 -r1.33 src/sys/dev/acpi/wss_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/acpi_ec.c
diff -u src/sys/dev/acpi/acpi_ec.c:1.82 src/sys/dev/acpi/acpi_ec.c:1.83
--- src/sys/dev/acpi/acpi_ec.c:1.82	Tue Apr 28 10:04:32 2020
+++ src/sys/dev/acpi/acpi_ec.c	Mon May  4 20:06:38 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.82 2020/04/28 10:04:32 jmcneill Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.83 2020/05/04 20:06:38 jdolecek Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.82 2020/04/28 10:04:32 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.83 2020/05/04 20:06:38 jdolecek Exp $");
 
 #include 
 #include 
@@ -101,7 +101,7 @@ ACPI_MODULE_NAME("acpi_ec")
 #define	EC_STATUS_SCI		0x20
 #define	EC_STATUS_SMI		0x40
 
-static const char *ec_hid[] = {
+static const char * const ec_hid[] = {
 	"PNP0C09",
 	NULL,
 };

Index: src/sys/dev/acpi/acpi_quirks.c
diff -u src/sys/dev/acpi/acpi_quirks.c:1.20 src/sys/dev/acpi/acpi_quirks.c:1.21
--- src/sys/dev/acpi/acpi_quirks.c:1.20	Mon Nov 14 02:44:59 2011
+++ src/sys/dev/acpi/acpi_quirks.c	Mon May  4 20:06:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_quirks.c,v 1.20 2011/11/14 02:44:59 jmcneill Exp $ */
+/* $NetBSD: acpi_quirks.c,v 1.21 2020/05/04 20:06:38 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -64,7 +64,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.20 2011/11/14 02:44:59 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_quirks.c,v 1.21 2020/05/04 20:06:38 jdolecek Exp $");
 
 #include "opt_acpi.h"
 
@@ -84,7 +84,7 @@ ACPI_MODULE_NAME	("acpi_quirks")
 
 static int acpi_quirks_revcmp(uint32_t, uint32_t, int);
 
-static struct acpi_quirk acpi_quirks[] = {
+static const struct acpi_quirk acpi_quirks[] = {
 
 	{ ACPI_SIG_FADT, "ASUS  ", 0x30303031, AQ_LTE, "CUV4X-D ",
 	  ACPI_QUIRK_BROKEN },
@@ -152,7 +152,7 @@ int
 acpi_find_quirks(void)
 {
 	ACPI_TABLE_HEADER fadt, dsdt, xsdt, *hdr;
-	struct acpi_quirk *aq;
+	const struct acpi_quirk *aq;
 	ACPI_STATUS rv;
 	size_t i, len;
 

Index: src/sys/dev/acpi/wss_acpi.c
diff -u src/sys/dev/acpi/wss_acpi.c:1.32 src/sys/dev/acpi/wss_acpi.c:1.33
--- src/sys/dev/acpi/wss_acpi.c:1.32	Wed May  8 13:40:17 2019
+++ src/sys/dev/acpi/wss_acpi.c	Mon May  4 20:06:38 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: wss_acpi.c,v 1.32 2019/05/08 13:40:17 isaki Exp $ */
+/* $NetBSD: wss_acpi.c,v 1.33 2020/05/04 20:06:38 jdolecek Exp $ */
 
 /*
  * Copyright (c) 2002 Jared D. McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wss_acpi.c,v 1.32 2019/05/08 13:40:17 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wss_acpi.c,v 1.33 2020/05/04 20:06:38 jdolecek Exp $");
 
 #include 
 #include 
@@ -59,7 +59,7 @@ struct wss_acpi_hint {
 	int offset_ad1848;		/* offset from start of DAC region */
 };
 
-static struct wss_acpi_hint wss_acpi_hints[] = {
+static const struct wss_acpi_hint wss_acpi_hints[] = {
 	{ "NMX2210", 1, 2, WSS_CODEC },
 	{ "CSC", 0, 1, 0 },		/* Dell Latitude CPi */
 	{ "CSC0100", 0, 1, 0 },		/* CS4610 with CS4236 codec */
@@ -114,7 +114,7 @@ wss_acpi_attach(device_t parent, device_
 	struct acpi_drq *playdrq, *recdrq;
 	struct audio_attach_args arg;
 	ACPI_STATUS rv;
-	struct wss_acpi_hint *wah;
+	const struct wss_acpi_hint *wah;
 
 	sc->sc_ad1848.sc_ad1848.sc_dev = self;
 	wah = _acpi_hints[



CVS commit: src/sys/dev/acpi

2020-04-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Apr 28 11:02:37 UTC 2020

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

Log Message:
Demote "unknown output device" message from error to debug, and change
the wording to reflect what is really happening -- the display output is
not connected.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 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.16 src/sys/dev/acpi/acpi_display.c:1.17
--- src/sys/dev/acpi/acpi_display.c:1.16	Thu Jun  1 02:45:09 2017
+++ src/sys/dev/acpi/acpi_display.c	Tue Apr 28 11:02:37 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_display.c,v 1.16 2017/06/01 02:45:09 chs Exp $	*/
+/*	$NetBSD: acpi_display.c,v 1.17 2020/04/28 11:02:37 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2010 The NetBSD Foundation, Inc.
@@ -66,7 +66,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.16 2017/06/01 02:45:09 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_display.c,v 1.17 2020/04/28 11:02:37 jmcneill Exp $");
 
 #include 
 #include 
@@ -1549,8 +1549,8 @@ acpidisp_vga_bind_outdevs(struct acpidis
 			}
 		}
 		if (i == oi->oi_dev_count)
-			aprint_error_dev(asc->sc_dev,
-			"unknown output device %s\n",
+			aprint_debug_dev(asc->sc_dev,
+			"output device %s not connected\n",
 			device_xname(osc->sc_dev));
 	}
 }



CVS commit: src/sys/dev/acpi

2020-04-28 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Apr 28 10:04:32 UTC 2020

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

Log Message:
kern/55206: acpibat reporting broken by acpi_ec.c r1.81

Assume byte instead of qword alignment of the buffer passed to the EC
space handler.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.81 src/sys/dev/acpi/acpi_ec.c:1.82
--- src/sys/dev/acpi/acpi_ec.c:1.81	Sun Apr 12 01:12:03 2020
+++ src/sys/dev/acpi/acpi_ec.c	Tue Apr 28 10:04:32 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.81 2020/04/12 01:12:03 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.82 2020/04/28 10:04:32 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.81 2020/04/12 01:12:03 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.82 2020/04/28 10:04:32 jmcneill Exp $");
 
 #include 
 #include 
@@ -659,32 +659,30 @@ acpiec_space_handler(uint32_t func, ACPI
 {
 	device_t dv;
 	ACPI_STATUS rv;
-	uint8_t addr, reg;
+	uint8_t addr, *buf;
 	unsigned int i;
 
-	if (paddr > 0xff || width % 8 != 0 || width > sizeof(ACPI_INTEGER)*8 ||
+	if (paddr > 0xff || width % 8 != 0 ||
 	value == NULL || arg == NULL || paddr + width / 8 > 0x100)
 		return AE_BAD_PARAMETER;
 
 	addr = paddr;
 	dv = arg;
+	buf = (uint8_t *)value;
 
 	rv = AE_OK;
 
 	switch (func) {
 	case ACPI_READ:
-		*value = 0;
-		for (i = 0; i < width; i += 8, ++addr) {
-			rv = acpiec_read(dv, addr, );
+		for (i = 0; i < width; i += 8, ++addr, ++buf) {
+			rv = acpiec_read(dv, addr, buf);
 			if (rv != AE_OK)
 break;
-			*value |= (ACPI_INTEGER)reg << i;
 		}
 		break;
 	case ACPI_WRITE:
-		for (i = 0; i < width; i += 8, ++addr) {
-			reg = (*value >> i) & 0xff;
-			rv = acpiec_write(dv, addr, reg);
+		for (i = 0; i < width; i += 8, ++addr, ++buf) {
+			rv = acpiec_write(dv, addr, *buf);
 			if (rv != AE_OK)
 break;
 		}



CVS commit: src/sys/dev/acpi

2020-04-15 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Wed Apr 15 19:26:51 UTC 2020

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

Log Message:
Use 64-bit DMA if available


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/ahcisata_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/ahcisata_acpi.c
diff -u src/sys/dev/acpi/ahcisata_acpi.c:1.4 src/sys/dev/acpi/ahcisata_acpi.c:1.5
--- src/sys/dev/acpi/ahcisata_acpi.c:1.4	Fri Nov 16 23:18:17 2018
+++ src/sys/dev/acpi/ahcisata_acpi.c	Wed Apr 15 19:26:51 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: ahcisata_acpi.c,v 1.4 2018/11/16 23:18:17 jmcneill Exp $ */
+/* $NetBSD: ahcisata_acpi.c,v 1.5 2020/04/15 19:26:51 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_acpi.c,v 1.4 2018/11/16 23:18:17 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_acpi.c,v 1.5 2020/04/15 19:26:51 jmcneill Exp $");
 
 #include 
 #include 
@@ -75,6 +75,7 @@ ahcisata_acpi_attach(device_t parent, de
 	struct acpi_mem *mem;
 	struct acpi_irq *irq;
 	ACPI_STATUS rv;
+	uint32_t cap;
 	void *ih;
 
 	rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS",
@@ -95,7 +96,6 @@ ahcisata_acpi_attach(device_t parent, de
 	}
 
 	sc->sc_atac.atac_dev = self;
-	sc->sc_dmat = aa->aa_dmat;
 	sc->sc_ahcit = aa->aa_memt;
 	sc->sc_ahcis = mem->ar_length;
 	if (bus_space_map(aa->aa_memt, mem->ar_base, mem->ar_length, 0, >sc_ahcih) != 0) {
@@ -103,6 +103,15 @@ ahcisata_acpi_attach(device_t parent, de
 		goto done;
 	}
 
+	cap = AHCI_READ(sc, AHCI_CAP);
+	if ((cap & AHCI_CAP_64BIT) != 0 && BUS_DMA_TAG_VALID(aa->aa_dmat64)) {
+		aprint_verbose_dev(self, "using 64-bit DMA\n");
+		sc->sc_dmat = aa->aa_dmat64;
+	} else {
+		aprint_verbose_dev(self, "using 32-bit DMA\n");
+		sc->sc_dmat = aa->aa_dmat;
+	}
+
 	ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
 	IPL_BIO, false, ahci_intr, sc, device_xname(self));
 	if (ih == NULL) {



CVS commit: src/sys/dev/acpi

2020-04-13 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Apr 13 12:08:06 UTC 2020

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

Log Message:
Work around a compiler issue when building on aarch64 with KUBSAN.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/sys/dev/acpi/acpi_mcfg.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_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.18 src/sys/dev/acpi/acpi_mcfg.c:1.19
--- src/sys/dev/acpi/acpi_mcfg.c:1.18	Sun Feb  2 16:31:25 2020
+++ src/sys/dev/acpi/acpi_mcfg.c	Mon Apr 13 12:08:05 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.18 2020/02/02 16:31:25 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.19 2020/04/13 12:08:05 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.18 2020/02/02 16:31:25 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.19 2020/04/13 12:08:05 jmcneill Exp $");
 
 #include 
 #include 
@@ -750,7 +750,8 @@ acpimcfg_configure_bus_cb(ACPI_RESOURCE 
 		}
 		ex = pcires->memext;
 		s = "non-prefetchable";
-	} else if (res->Data.Address.ResourceType == ACPI_IO_RANGE) {
+	} else {
+		KASSERT(res->Data.Address.ResourceType == ACPI_IO_RANGE);
 		if (pcires->ioext == NULL) {
 			pcires->ioext = extent_create("pciio", 0, ULONG_MAX,
 			NULL, 0, EX_WAITOK);
@@ -764,7 +765,6 @@ acpimcfg_configure_bus_cb(ACPI_RESOURCE 
 		}
 		ex = pcires->ioext;
 		s = "i/o";
-		
 	}
 
 	switch (res->Type) {



CVS commit: src/sys/dev/acpi

2020-04-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 12 01:11:23 UTC 2020

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

Log Message:
Revert acpi_ec.c 1.77.

We will do this another way.

ok msaitoh


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 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.77 src/sys/dev/acpi/acpi_ec.c:1.78
--- src/sys/dev/acpi/acpi_ec.c:1.77	Tue Aug  6 01:53:47 2019
+++ src/sys/dev/acpi/acpi_ec.c	Sun Apr 12 01:11:23 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.77 2019/08/06 01:53:47 msaitoh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.78 2020/04/12 01:11:23 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.77 2019/08/06 01:53:47 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.78 2020/04/12 01:11:23 riastradh Exp $");
 
 #include 
 #include 
@@ -679,15 +679,20 @@ acpiec_space_handler(uint32_t func, ACPI
 	if (func == ACPI_READ)
 		*value = 0;
 
-	for (addr = paddr; addr < (paddr + width / 8); addr++, reg++) {
-		if (func == ACPI_READ)
+	do {
+		switch (func) {
+		case ACPI_READ:
 			rv = acpiec_read(dv, addr, reg);
-		else
+			break;
+		case ACPI_WRITE:
 			rv = acpiec_write(dv, addr, *reg);
-
+			break;
+		}
 		if (rv != AE_OK)
 			break;
-	}
+		addr++;
+		reg++;
+	} while (addr < (paddr + width / 8));
 
 	return rv;
 }



CVS commit: src/sys/dev/acpi

2020-04-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 12 01:12:03 UTC 2020

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

Log Message:
Reject overly large widths, from mlelstv.

We are returning an ACPI_INTEGER (= uint64_t), so it doesn't make
sense to handle more than 64 bits.

Apparently there are some ACPIs out there that ask for unreasonably
large widths here.  Just reject those requests, rather than writing
past the caller's stack buffer.

Previously we attempted to fix this by copying byte by byte as large
as the caller asked, in order to avoid the undefined behaviour of
shifting past the size of ACPI_INTEGER, but that just turned a shift
(which might have been harmless on real machines) into a stack buffer
overflow (!).

ok msaitoh


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 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.80 src/sys/dev/acpi/acpi_ec.c:1.81
--- src/sys/dev/acpi/acpi_ec.c:1.80	Sun Apr 12 01:11:52 2020
+++ src/sys/dev/acpi/acpi_ec.c	Sun Apr 12 01:12:03 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.80 2020/04/12 01:11:52 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.81 2020/04/12 01:12:03 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.80 2020/04/12 01:11:52 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.81 2020/04/12 01:12:03 riastradh Exp $");
 
 #include 
 #include 
@@ -662,8 +662,8 @@ acpiec_space_handler(uint32_t func, ACPI
 	uint8_t addr, reg;
 	unsigned int i;
 
-	if (paddr > 0xff || width % 8 != 0 || value == NULL || arg == NULL ||
-	paddr + width / 8 > 0x100)
+	if (paddr > 0xff || width % 8 != 0 || width > sizeof(ACPI_INTEGER)*8 ||
+	value == NULL || arg == NULL || paddr + width / 8 > 0x100)
 		return AE_BAD_PARAMETER;
 
 	addr = paddr;



CVS commit: src/sys/dev/acpi

2020-04-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 12 01:11:52 UTC 2020

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

Log Message:
KNF


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 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.79 src/sys/dev/acpi/acpi_ec.c:1.80
--- src/sys/dev/acpi/acpi_ec.c:1.79	Sun Apr 12 01:11:43 2020
+++ src/sys/dev/acpi/acpi_ec.c	Sun Apr 12 01:11:52 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.79 2020/04/12 01:11:43 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.80 2020/04/12 01:11:52 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.79 2020/04/12 01:11:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.80 2020/04/12 01:11:52 riastradh Exp $");
 
 #include 
 #include 
@@ -404,6 +404,7 @@ post_data_map:
 static bool
 acpiec_suspend(device_t dv, const pmf_qual_t *qual)
 {
+
 	acpiec_cold = true;
 
 	return true;
@@ -412,6 +413,7 @@ acpiec_suspend(device_t dv, const pmf_qu
 static bool
 acpiec_resume(device_t dv, const pmf_qual_t *qual)
 {
+
 	acpiec_cold = false;
 
 	return true;
@@ -454,9 +456,10 @@ acpiec_parse_gpe_package(device_t self, 
 		ACPI_FREE(p);
 		return false;
 	}
-	
+
 	if (p->Package.Count != 2) {
-		aprint_error_dev(self, "_GPE package does not contain 2 elements\n");
+		aprint_error_dev(self,
+		"_GPE package does not contain 2 elements\n");
 		ACPI_FREE(p);
 		return false;
 	}
@@ -511,6 +514,7 @@ static ACPI_STATUS
 acpiec_space_setup(ACPI_HANDLE region, uint32_t func, void *arg,
 void **region_arg)
 {
+
 	if (func == ACPI_REGION_DEACTIVATE)
 		*region_arg = NULL;
 	else
@@ -528,9 +532,11 @@ acpiec_lock(device_t dv)
 	mutex_enter(>sc_access_mtx);
 
 	if (sc->sc_need_global_lock) {
-		rv = AcpiAcquireGlobalLock(EC_LOCK_TIMEOUT, >sc_global_lock);
+		rv = AcpiAcquireGlobalLock(EC_LOCK_TIMEOUT,
+		>sc_global_lock);
 		if (rv != AE_OK) {
-			aprint_error_dev(dv, "failed to acquire global lock: %s\n",
+			aprint_error_dev(dv,
+			"failed to acquire global lock: %s\n",
 			AcpiFormatException(rv));
 			return;
 		}
@@ -546,7 +552,8 @@ acpiec_unlock(device_t dv)
 	if (sc->sc_need_global_lock) {
 		rv = AcpiReleaseGlobalLock(sc->sc_global_lock);
 		if (rv != AE_OK) {
-			aprint_error_dev(dv, "failed to release global lock: %s\n",
+			aprint_error_dev(dv,
+			"failed to release global lock: %s\n",
 			AcpiFormatException(rv));
 		}
 	}
@@ -587,7 +594,8 @@ acpiec_read(device_t dv, uint8_t addr, u
 	} else if (cv_timedwait(>sc_cv, >sc_mtx, EC_CMD_TIMEOUT * hz)) {
 		mutex_exit(>sc_mtx);
 		acpiec_unlock(dv);
-		aprint_error_dev(dv, "command takes over %d sec...\n", EC_CMD_TIMEOUT);
+		aprint_error_dev(dv,
+		"command takes over %d sec...\n", EC_CMD_TIMEOUT);
 		return AE_ERROR;
 	}
 
@@ -634,7 +642,8 @@ acpiec_write(device_t dv, uint8_t addr, 
 	} else if (cv_timedwait(>sc_cv, >sc_mtx, EC_CMD_TIMEOUT * hz)) {
 		mutex_exit(>sc_mtx);
 		acpiec_unlock(dv);
-		aprint_error_dev(dv, "command takes over %d sec...\n", EC_CMD_TIMEOUT);
+		aprint_error_dev(dv,
+		"command takes over %d sec...\n", EC_CMD_TIMEOUT);
 		return AE_ERROR;
 	}
 
@@ -674,7 +683,7 @@ acpiec_space_handler(uint32_t func, ACPI
 		break;
 	case ACPI_WRITE:
 		for (i = 0; i < width; i += 8, ++addr) {
-			reg = (*value >>i) & 0xff;
+			reg = (*value >> i) & 0xff;
 			rv = acpiec_write(dv, addr, reg);
 			if (rv != AE_OK)
 break;
@@ -867,7 +876,8 @@ acpiec_bus_read(device_t dv, u_int addr,
 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, NULL);
+	return acpiec_space_handler(ACPI_WRITE, addr, width * 8, , dv,
+	NULL);
 }
 
 ACPI_HANDLE



CVS commit: src/sys/dev/acpi

2020-04-11 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Apr 12 01:11:43 UTC 2020

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

Log Message:
Revert acpi_ec.c 1.76.

We will do this another way, and separate KNF fixes from the critical
functional change.

ok msaitoh


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 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.78 src/sys/dev/acpi/acpi_ec.c:1.79
--- src/sys/dev/acpi/acpi_ec.c:1.78	Sun Apr 12 01:11:23 2020
+++ src/sys/dev/acpi/acpi_ec.c	Sun Apr 12 01:11:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_ec.c,v 1.78 2020/04/12 01:11:23 riastradh Exp $	*/
+/*	$NetBSD: acpi_ec.c,v 1.79 2020/04/12 01:11:43 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2007 Joerg Sonnenberger .
@@ -59,7 +59,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.78 2020/04/12 01:11:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_ec.c,v 1.79 2020/04/12 01:11:43 riastradh Exp $");
 
 #include 
 #include 
@@ -404,7 +404,6 @@ post_data_map:
 static bool
 acpiec_suspend(device_t dv, const pmf_qual_t *qual)
 {
-
 	acpiec_cold = true;
 
 	return true;
@@ -413,7 +412,6 @@ acpiec_suspend(device_t dv, const pmf_qu
 static bool
 acpiec_resume(device_t dv, const pmf_qual_t *qual)
 {
-
 	acpiec_cold = false;
 
 	return true;
@@ -456,10 +454,9 @@ acpiec_parse_gpe_package(device_t self, 
 		ACPI_FREE(p);
 		return false;
 	}
-
+	
 	if (p->Package.Count != 2) {
-		aprint_error_dev(self,
-		"_GPE package does not contain 2 elements\n");
+		aprint_error_dev(self, "_GPE package does not contain 2 elements\n");
 		ACPI_FREE(p);
 		return false;
 	}
@@ -514,7 +511,6 @@ static ACPI_STATUS
 acpiec_space_setup(ACPI_HANDLE region, uint32_t func, void *arg,
 void **region_arg)
 {
-
 	if (func == ACPI_REGION_DEACTIVATE)
 		*region_arg = NULL;
 	else
@@ -532,11 +528,9 @@ acpiec_lock(device_t dv)
 	mutex_enter(>sc_access_mtx);
 
 	if (sc->sc_need_global_lock) {
-		rv = AcpiAcquireGlobalLock(EC_LOCK_TIMEOUT,
-		>sc_global_lock);
+		rv = AcpiAcquireGlobalLock(EC_LOCK_TIMEOUT, >sc_global_lock);
 		if (rv != AE_OK) {
-			aprint_error_dev(dv,
-			"failed to acquire global lock: %s\n",
+			aprint_error_dev(dv, "failed to acquire global lock: %s\n",
 			AcpiFormatException(rv));
 			return;
 		}
@@ -552,8 +546,7 @@ acpiec_unlock(device_t dv)
 	if (sc->sc_need_global_lock) {
 		rv = AcpiReleaseGlobalLock(sc->sc_global_lock);
 		if (rv != AE_OK) {
-			aprint_error_dev(dv,
-			"failed to release global lock: %s\n",
+			aprint_error_dev(dv, "failed to release global lock: %s\n",
 			AcpiFormatException(rv));
 		}
 	}
@@ -594,8 +587,7 @@ acpiec_read(device_t dv, uint8_t addr, u
 	} else if (cv_timedwait(>sc_cv, >sc_mtx, EC_CMD_TIMEOUT * hz)) {
 		mutex_exit(>sc_mtx);
 		acpiec_unlock(dv);
-		aprint_error_dev(dv,
-		"command takes over %d sec...\n", EC_CMD_TIMEOUT);
+		aprint_error_dev(dv, "command takes over %d sec...\n", EC_CMD_TIMEOUT);
 		return AE_ERROR;
 	}
 
@@ -642,8 +634,7 @@ acpiec_write(device_t dv, uint8_t addr, 
 	} else if (cv_timedwait(>sc_cv, >sc_mtx, EC_CMD_TIMEOUT * hz)) {
 		mutex_exit(>sc_mtx);
 		acpiec_unlock(dv);
-		aprint_error_dev(dv,
-		"command takes over %d sec...\n", EC_CMD_TIMEOUT);
+		aprint_error_dev(dv, "command takes over %d sec...\n", EC_CMD_TIMEOUT);
 		return AE_ERROR;
 	}
 
@@ -657,42 +648,43 @@ 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;
+	device_t dv;
 	ACPI_STATUS rv;
-	uint8_t addr;
-	uint8_t *reg;
+	uint8_t addr, reg;
+	unsigned int i;
 
-	if ((func != ACPI_READ) && (func != ACPI_WRITE)) {
-		aprint_error("%s: invalid Address Space function called: %x\n",
-		device_xname(dv), (unsigned int)func);
-		return AE_BAD_PARAMETER;
-	}
 	if (paddr > 0xff || width % 8 != 0 || value == NULL || arg == NULL ||
 	paddr + width / 8 > 0x100)
 		return AE_BAD_PARAMETER;
 
 	addr = paddr;
-	reg = (uint8_t *)value;
+	dv = arg;
 
 	rv = AE_OK;
 
-	if (func == ACPI_READ)
+	switch (func) {
+	case ACPI_READ:
 		*value = 0;
-
-	do {
-		switch (func) {
-		case ACPI_READ:
-			rv = acpiec_read(dv, addr, reg);
-			break;
-		case ACPI_WRITE:
-			rv = acpiec_write(dv, addr, *reg);
-			break;
+		for (i = 0; i < width; i += 8, ++addr) {
+			rv = acpiec_read(dv, addr, );
+			if (rv != AE_OK)
+break;
+			*value |= (ACPI_INTEGER)reg << i;
+		}
+		break;
+	case ACPI_WRITE:
+		for (i = 0; i < width; i += 8, ++addr) {
+			reg = (*value >>i) & 0xff;
+			rv = acpiec_write(dv, addr, reg);
+			if (rv != AE_OK)
+break;
 		}
-		if (rv != AE_OK)
-			break;
-		addr++;
-		reg++;
-	} while (addr < (paddr + width / 8));
+		break;
+	default:
+		aprint_error("%s: invalid Address Space function called: %x\n",
+		

CVS commit: src/sys/dev/acpi

2020-04-09 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Apr  9 10:46:19 UTC 2020

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

Log Message:
Stop walking MADT / GTDT subtables if we hit a header with length 0


To generate a diff of this commit:
cvs rdiff -u -r1.283 -r1.284 src/sys/dev/acpi/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/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.283 src/sys/dev/acpi/acpi.c:1.284
--- src/sys/dev/acpi/acpi.c:1.283	Fri Jan 17 17:06:32 2020
+++ src/sys/dev/acpi/acpi.c	Thu Apr  9 10:46:19 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.283 2020/01/17 17:06:32 jmcneill Exp $	*/
+/*	$NetBSD: acpi.c,v 1.284 2020/04/09 10:46:19 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.283 2020/01/17 17:06:32 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.284 2020/04/09 10:46:19 jmcneill Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -1809,7 +1809,7 @@ acpi_madt_walk(ACPI_STATUS (*func)(ACPI_
 
 		hdrp = (ACPI_SUBTABLE_HEADER *)where;
 
-		if (ACPI_FAILURE(func(hdrp, aux)))
+		if (hdrp->Length == 0 || ACPI_FAILURE(func(hdrp, aux)))
 			break;
 
 		where += hdrp->Length;
@@ -1829,7 +1829,7 @@ acpi_gtdt_walk(ACPI_STATUS (*func)(ACPI_
 
 		hdrp = (ACPI_GTDT_HEADER *)where;
 
-		if (ACPI_FAILURE(func(hdrp, aux)))
+		if (hdrp->Length == 0 || ACPI_FAILURE(func(hdrp, aux)))
 			break;
 
 		where += hdrp->Length;



CVS commit: src/sys/dev/acpi

2020-03-22 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Mon Mar 23 00:37:19 UTC 2020

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

Log Message:
in acpi_debug_init(), the string we extract from the dictionary is
a normal C string, so use strlcpy() rather than memcpy() to copy it.
found by KASAN.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/acpi_debug.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_debug.c
diff -u src/sys/dev/acpi/acpi_debug.c:1.6 src/sys/dev/acpi/acpi_debug.c:1.7
--- src/sys/dev/acpi/acpi_debug.c:1.6	Sat Jan  5 20:40:26 2019
+++ src/sys/dev/acpi/acpi_debug.c	Mon Mar 23 00:37:19 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_debug.c,v 1.6 2019/01/05 20:40:26 christos Exp $ */
+/* $NetBSD: acpi_debug.c,v 1.7 2020/03/23 00:37:19 chs Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen 
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_debug.c,v 1.6 2019/01/05 20:40:26 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_debug.c,v 1.7 2020/03/23 00:37:19 chs Exp $");
 
 #include 
 #include 
@@ -124,8 +124,8 @@ acpi_debug_init(void)
 	layer = acpi_debug_getkey(acpi_debug_layer_d, AcpiDbgLayer);
 	level = acpi_debug_getkey(acpi_debug_level_d, AcpiDbgLevel);
 
-	(void)memcpy(acpi_debug_layer_s, layer, ACPI_DEBUG_MAX);
-	(void)memcpy(acpi_debug_level_s, level, ACPI_DEBUG_MAX);
+	strlcpy(acpi_debug_layer_s, layer, ACPI_DEBUG_MAX);
+	strlcpy(acpi_debug_level_s, level, ACPI_DEBUG_MAX);
 
 	return;
 



CVS commit: src/sys/dev/acpi

2020-02-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Feb  2 16:31:25 UTC 2020

Modified Files:
src/sys/dev/acpi: acpi_mcfg.c acpi_mcfg.h

Log Message:
Add acpimcfg_conf_valid helper for pcie controllers with nonstandard
config space layouts.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/acpi/acpi_mcfg.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/acpi_mcfg.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/acpi_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.17 src/sys/dev/acpi/acpi_mcfg.c:1.18
--- src/sys/dev/acpi/acpi_mcfg.c:1.17	Mon Oct 14 00:15:13 2019
+++ src/sys/dev/acpi/acpi_mcfg.c	Sun Feb  2 16:31:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.17 2019/10/14 00:15:13 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.18 2020/02/02 16:31:25 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.17 2019/10/14 00:15:13 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.18 2020/02/02 16:31:25 jmcneill Exp $");
 
 #include 
 #include 
@@ -962,3 +962,28 @@ acpimcfg_conf_write(pci_chipset_tag_t pc
 	mcfg_ops->ao_write(seg->ms_bst, mb->bsh[dev][func], reg, data);
 	return 0;
 }
+
+bool
+acpimcfg_conf_valid(pci_chipset_tag_t pc, pcitag_t tag, int reg)
+{
+	struct mcfg_segment *seg = NULL;
+	struct mcfg_bus *mb;
+	int bus, dev, func;
+
+	if (!mcfg_inited)
+		return false;
+
+	pci_decompose_tag(pc, tag, , , );
+
+	seg = acpimcfg_get_segment(pc, bus);
+	if (seg == NULL)
+		return false;
+
+	mb = >ms_bus[bus - seg->ms_bus_start];
+	if (!PCIDEV_IS_VALID(mb, dev, func))
+		return false;
+	if (!EXTCONF_IS_VALID(mb, dev, func) && reg >= PCI_CONF_SIZE)
+		return false;
+
+	return true;
+}

Index: src/sys/dev/acpi/acpi_mcfg.h
diff -u src/sys/dev/acpi/acpi_mcfg.h:1.2 src/sys/dev/acpi/acpi_mcfg.h:1.3
--- src/sys/dev/acpi/acpi_mcfg.h:1.2	Mon Oct 15 10:01:32 2018
+++ src/sys/dev/acpi/acpi_mcfg.h	Sun Feb  2 16:31:25 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.h,v 1.2 2018/10/15 10:01:32 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.h,v 1.3 2020/02/02 16:31:25 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -36,6 +36,7 @@ int	acpimcfg_configure_bus(device_t, pci
 
 int	acpimcfg_conf_read(pci_chipset_tag_t, pcitag_t, int, pcireg_t *);
 int	acpimcfg_conf_write(pci_chipset_tag_t, pcitag_t, int, pcireg_t);
+bool	acpimcfg_conf_valid(pci_chipset_tag_t, pcitag_t, int);
 
 struct acpimcfg_ops {
 	/* validate MCFG memory region */



CVS commit: src/sys/dev/acpi

2020-02-01 Thread Tobias Nygren
Module Name:src
Committed By:   tnn
Date:   Sat Feb  1 20:11:24 UTC 2020

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

Log Message:
fix build


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/acpi/sdhc_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/sdhc_acpi.c
diff -u src/sys/dev/acpi/sdhc_acpi.c:1.13 src/sys/dev/acpi/sdhc_acpi.c:1.14
--- src/sys/dev/acpi/sdhc_acpi.c:1.13	Sat Feb  1 19:11:59 2020
+++ src/sys/dev/acpi/sdhc_acpi.c	Sat Feb  1 20:11:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc_acpi.c,v 1.13 2020/02/01 19:11:59 christos Exp $	*/
+/*	$NetBSD: sdhc_acpi.c,v 1.14 2020/02/01 20:11:24 tnn Exp $	*/
 
 /*
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.13 2020/02/01 19:11:59 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.14 2020/02/01 20:11:24 tnn Exp $");
 
 #include 
 #include 
@@ -91,7 +91,7 @@ static const struct sdhc_acpi_slot {
 	{ .hid = "INT344D",		 .type = SLOT_TYPE_SD },
 	{ .hid = "NXP0003",  .uid = "0", .type = SLOT_TYPE_SD,
 	 .flags = SDHC_ESDHC_FLAGS },
-	{ .hid = "NXP0003",  .uid = "1", .type SLOT_TYPE_EMMC,
+	{ .hid = "NXP0003",  .uid = "1", .type = SLOT_TYPE_EMMC,
 	 .flags = SDHC_ESDHC_FLAGS },
 
 	/* Generic IDs last */



CVS commit: src/sys/dev/acpi

2020-02-01 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Feb  1 19:11:59 UTC 2020

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

Log Message:
use designated initializers


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/acpi/sdhc_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/sdhc_acpi.c
diff -u src/sys/dev/acpi/sdhc_acpi.c:1.12 src/sys/dev/acpi/sdhc_acpi.c:1.13
--- src/sys/dev/acpi/sdhc_acpi.c:1.12	Sat Feb  1 13:24:24 2020
+++ src/sys/dev/acpi/sdhc_acpi.c	Sat Feb  1 14:11:59 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc_acpi.c,v 1.12 2020/02/01 18:24:24 jmcneill Exp $	*/
+/*	$NetBSD: sdhc_acpi.c,v 1.13 2020/02/01 19:11:59 christos Exp $	*/
 
 /*
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.12 2020/02/01 18:24:24 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.13 2020/02/01 19:11:59 christos Exp $");
 
 #include 
 #include 
@@ -78,22 +78,25 @@ static const struct sdhc_acpi_slot {
 #define	SLOT_TYPE_EMMC	1	/* eMMC */
 	uint32_t flags;
 } sdhc_acpi_slot_map[] = {
-	{ "80865ACA",	NULL,	SLOT_TYPE_SD,	0 },
-	{ "80865ACC",	NULL,	SLOT_TYPE_EMMC,	0 },
-	{ "80865AD0",	NULL,	SLOT_TYPE_SD,	0 },
-	{ "80860F14",   "1",	SLOT_TYPE_EMMC,	0 },
-	{ "80860F14",   "3",	SLOT_TYPE_SD,	0 },
-	{ "80860F16",   NULL,	SLOT_TYPE_SD,	0 },
-	{ "INT33BB",	"2",	SLOT_TYPE_SD,	0 },
-	{ "INT33BB",	"3",	SLOT_TYPE_SD,	0 },
-	{ "INT33C6",	NULL,	SLOT_TYPE_SD,	0 },
-	{ "INT3436",	NULL,	SLOT_TYPE_SD,	0 },
-	{ "INT344D",	NULL,	SLOT_TYPE_SD,	0 },
-	{ "NXP0003",	"0",	SLOT_TYPE_SD,	SDHC_ESDHC_FLAGS },
-	{ "NXP0003",	"1",	SLOT_TYPE_EMMC,	SDHC_ESDHC_FLAGS },
+	{ .hid = "80865ACA",		 .type = SLOT_TYPE_SD },
+	{ .hid = "80865ACC",		 .type = SLOT_TYPE_EMMC },
+	{ .hid = "80865AD0",		 .type = SLOT_TYPE_SD },
+	{ .hid = "80860F14", .uid = "1", .type = SLOT_TYPE_EMMC },
+	{ .hid = "80860F14", .uid = "3", .type = SLOT_TYPE_SD },
+	{ .hid = "80860F16",   		 .type = SLOT_TYPE_SD },
+	{ .hid = "INT33BB",  .uid = "2", .type = SLOT_TYPE_SD },
+	{ .hid = "INT33BB",  .uid = "3", .type = SLOT_TYPE_SD },
+	{ .hid = "INT33C6",		 .type = SLOT_TYPE_SD },
+	{ .hid = "INT3436",		 .type = SLOT_TYPE_SD },
+	{ .hid = "INT344D",		 .type = SLOT_TYPE_SD },
+	{ .hid = "NXP0003",  .uid = "0", .type = SLOT_TYPE_SD,
+	 .flags = SDHC_ESDHC_FLAGS },
+	{ .hid = "NXP0003",  .uid = "1", .type SLOT_TYPE_EMMC,
+	 .flags = SDHC_ESDHC_FLAGS },
+
 	/* Generic IDs last */
-	{ "PNP0D40",	NULL,	SLOT_TYPE_SD,	0 },
-	{ "PNP0FFF",	"3",	SLOT_TYPE_SD,	0 },
+	{ .hid = "PNP0D40",		 .type = SLOT_TYPE_SD },
+	{ .hid = "PNP0FFF",  .uid = "3", .type = SLOT_TYPE_SD },
 };
 
 static const struct sdhc_acpi_slot *



CVS commit: src/sys/dev/acpi

2020-02-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb  1 18:24:24 UTC 2020

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

Log Message:
appease -Werror=missing-field-initializers


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/acpi/sdhc_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/sdhc_acpi.c
diff -u src/sys/dev/acpi/sdhc_acpi.c:1.11 src/sys/dev/acpi/sdhc_acpi.c:1.12
--- src/sys/dev/acpi/sdhc_acpi.c:1.11	Sat Feb  1 13:40:55 2020
+++ src/sys/dev/acpi/sdhc_acpi.c	Sat Feb  1 18:24:24 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc_acpi.c,v 1.11 2020/02/01 13:40:55 jmcneill Exp $	*/
+/*	$NetBSD: sdhc_acpi.c,v 1.12 2020/02/01 18:24:24 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.11 2020/02/01 13:40:55 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.12 2020/02/01 18:24:24 jmcneill Exp $");
 
 #include 
 #include 
@@ -78,22 +78,22 @@ static const struct sdhc_acpi_slot {
 #define	SLOT_TYPE_EMMC	1	/* eMMC */
 	uint32_t flags;
 } sdhc_acpi_slot_map[] = {
-	{ "80865ACA",	NULL,	SLOT_TYPE_SD },
-	{ "80865ACC",	NULL,	SLOT_TYPE_EMMC },
-	{ "80865AD0",	NULL,	SLOT_TYPE_SD },
-	{ "80860F14",   "1",	SLOT_TYPE_EMMC },
-	{ "80860F14",   "3",	SLOT_TYPE_SD },
-	{ "80860F16",   NULL,	SLOT_TYPE_SD },
-	{ "INT33BB",	"2",	SLOT_TYPE_SD },
-	{ "INT33BB",	"3",	SLOT_TYPE_SD },
-	{ "INT33C6",	NULL,	SLOT_TYPE_SD },
-	{ "INT3436",	NULL,	SLOT_TYPE_SD },
-	{ "INT344D",	NULL,	SLOT_TYPE_SD },
+	{ "80865ACA",	NULL,	SLOT_TYPE_SD,	0 },
+	{ "80865ACC",	NULL,	SLOT_TYPE_EMMC,	0 },
+	{ "80865AD0",	NULL,	SLOT_TYPE_SD,	0 },
+	{ "80860F14",   "1",	SLOT_TYPE_EMMC,	0 },
+	{ "80860F14",   "3",	SLOT_TYPE_SD,	0 },
+	{ "80860F16",   NULL,	SLOT_TYPE_SD,	0 },
+	{ "INT33BB",	"2",	SLOT_TYPE_SD,	0 },
+	{ "INT33BB",	"3",	SLOT_TYPE_SD,	0 },
+	{ "INT33C6",	NULL,	SLOT_TYPE_SD,	0 },
+	{ "INT3436",	NULL,	SLOT_TYPE_SD,	0 },
+	{ "INT344D",	NULL,	SLOT_TYPE_SD,	0 },
 	{ "NXP0003",	"0",	SLOT_TYPE_SD,	SDHC_ESDHC_FLAGS },
 	{ "NXP0003",	"1",	SLOT_TYPE_EMMC,	SDHC_ESDHC_FLAGS },
 	/* Generic IDs last */
-	{ "PNP0D40",	NULL,	SLOT_TYPE_SD },
-	{ "PNP0FFF",	"3",	SLOT_TYPE_SD },
+	{ "PNP0D40",	NULL,	SLOT_TYPE_SD,	0 },
+	{ "PNP0FFF",	"3",	SLOT_TYPE_SD,	0 },
 };
 
 static const struct sdhc_acpi_slot *



CVS commit: src/sys/dev/acpi

2020-02-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb  1 13:40:55 UTC 2020

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

Log Message:
Add NXP/Freescale ESDHC specific support


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/acpi/sdhc_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/sdhc_acpi.c
diff -u src/sys/dev/acpi/sdhc_acpi.c:1.10 src/sys/dev/acpi/sdhc_acpi.c:1.11
--- src/sys/dev/acpi/sdhc_acpi.c:1.10	Sat Feb  1 13:09:08 2020
+++ src/sys/dev/acpi/sdhc_acpi.c	Sat Feb  1 13:40:55 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc_acpi.c,v 1.10 2020/02/01 13:09:08 jmcneill Exp $	*/
+/*	$NetBSD: sdhc_acpi.c,v 1.11 2020/02/01 13:40:55 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.10 2020/02/01 13:09:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.11 2020/02/01 13:40:55 jmcneill Exp $");
 
 #include 
 #include 
@@ -41,6 +41,10 @@ __KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,
 #include 
 #include 
 
+/* Freescale ESDHC */
+#define	SDHC_ESDHC_FLAGS	\
+(SDHC_FLAG_HAVE_DVS|SDHC_FLAG_NO_PWR0|SDHC_FLAG_32BIT_ACCESS|SDHC_FLAG_ENHANCED)
+
 #define _COMPONENT	ACPI_RESOURCE_COMPONENT
 ACPI_MODULE_NAME	("sdhc_acpi")
 
@@ -72,6 +76,7 @@ static const struct sdhc_acpi_slot {
 	int type;
 #define	SLOT_TYPE_SD	0	/* SD or SDIO */
 #define	SLOT_TYPE_EMMC	1	/* eMMC */
+	uint32_t flags;
 } sdhc_acpi_slot_map[] = {
 	{ "80865ACA",	NULL,	SLOT_TYPE_SD },
 	{ "80865ACC",	NULL,	SLOT_TYPE_EMMC },
@@ -84,6 +89,9 @@ static const struct sdhc_acpi_slot {
 	{ "INT33C6",	NULL,	SLOT_TYPE_SD },
 	{ "INT3436",	NULL,	SLOT_TYPE_SD },
 	{ "INT344D",	NULL,	SLOT_TYPE_SD },
+	{ "NXP0003",	"0",	SLOT_TYPE_SD,	SDHC_ESDHC_FLAGS },
+	{ "NXP0003",	"1",	SLOT_TYPE_EMMC,	SDHC_ESDHC_FLAGS },
+	/* Generic IDs last */
 	{ "PNP0D40",	NULL,	SLOT_TYPE_SD },
 	{ "PNP0FFF",	"3",	SLOT_TYPE_SD },
 };
@@ -192,6 +200,8 @@ sdhc_acpi_attach(device_t parent, device
 
 	sc->sc.sc_host = kmem_zalloc(sizeof(struct sdhc_host *), KM_SLEEP);
 
+	sc->sc.sc_flags |= slot->flags;
+
 	/* Enable DMA transfer */
 	sc->sc.sc_flags |= SDHC_FLAG_USE_DMA;
 



CVS commit: src/sys/dev/acpi

2020-02-01 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Feb  1 13:09:09 UTC 2020

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

Log Message:
Use acpi_match_hid to match both _HID and _CID


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/acpi/sdhc_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/sdhc_acpi.c
diff -u src/sys/dev/acpi/sdhc_acpi.c:1.9 src/sys/dev/acpi/sdhc_acpi.c:1.10
--- src/sys/dev/acpi/sdhc_acpi.c:1.9	Sun Dec 29 12:46:43 2019
+++ src/sys/dev/acpi/sdhc_acpi.c	Sat Feb  1 13:09:08 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc_acpi.c,v 1.9 2019/12/29 12:46:43 jmcneill Exp $	*/
+/*	$NetBSD: sdhc_acpi.c,v 1.10 2020/02/01 13:09:08 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.9 2019/12/29 12:46:43 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.10 2020/02/01 13:09:08 jmcneill Exp $");
 
 #include 
 #include 
@@ -103,7 +103,8 @@ sdhc_acpi_find_slot(ACPI_DEVICE_INFO *ad
 
 	for (i = 0; i < __arraycount(sdhc_acpi_slot_map); i++) {
 		slot = _acpi_slot_map[i];
-		if (strcmp(hid, slot->hid) == 0) {
+		const char * const slot_id[] = { slot->hid, NULL };
+		if (acpi_match_hid(ad, slot_id)) {
 			if (slot->uid == NULL ||
 			((ad->Valid & ACPI_VALID_UID) != 0 &&
 			 uid != NULL &&



CVS commit: src/sys/dev/acpi

2020-01-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Jan 31 23:12:13 UTC 2020

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

Log Message:
Match HID 808622B7 (DesignWare USB3)


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/xhci_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/xhci_acpi.c
diff -u src/sys/dev/acpi/xhci_acpi.c:1.6 src/sys/dev/acpi/xhci_acpi.c:1.7
--- src/sys/dev/acpi/xhci_acpi.c:1.6	Tue Jan 21 11:29:17 2020
+++ src/sys/dev/acpi/xhci_acpi.c	Fri Jan 31 23:12:13 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci_acpi.c,v 1.6 2020/01/21 11:29:17 jmcneill Exp $ */
+/* $NetBSD: xhci_acpi.c,v 1.7 2020/01/31 23:12:13 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.6 2020/01/21 11:29:17 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.7 2020/01/31 23:12:13 jmcneill Exp $");
 
 #include 
 #include 
@@ -52,6 +52,7 @@ __KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,
 static const char * const compatible[] = {
 	"PNP0D10",	/* XHCI-compliant USB controller without standard debug */
 	"PNP0D15",	/* XHCI-compliant USB controller with standard debug */
+	"808622B7",	/* DesignWare Dual Role SuperSpeed USB controller */
 	NULL
 };
 



CVS commit: src/sys/dev/acpi

2020-01-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Jan 21 11:29:17 UTC 2020

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

Log Message:
Choose between dmat and dmat64, instead of relying on subregion of the 32-bit 
tag


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/xhci_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/xhci_acpi.c
diff -u src/sys/dev/acpi/xhci_acpi.c:1.5 src/sys/dev/acpi/xhci_acpi.c:1.6
--- src/sys/dev/acpi/xhci_acpi.c:1.5	Sat Jun 22 19:35:40 2019
+++ src/sys/dev/acpi/xhci_acpi.c	Tue Jan 21 11:29:17 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci_acpi.c,v 1.5 2019/06/22 19:35:40 jmcneill Exp $ */
+/* $NetBSD: xhci_acpi.c,v 1.6 2020/01/21 11:29:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.5 2019/06/22 19:35:40 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.6 2020/01/21 11:29:17 jmcneill Exp $");
 
 #include 
 #include 
@@ -130,16 +130,11 @@ xhci_acpi_attach(device_t parent, device
 	hccparams = bus_space_read_4(sc->sc_iot, sc->sc_ioh, XHCI_HCCPARAMS);
 	if (XHCI_HCC_AC64(hccparams)) {
 		aprint_verbose_dev(self, "using 64-bit DMA\n");
-		sc->sc_bus.ub_dmatag = aa->aa_dmat;
+		sc->sc_bus.ub_dmatag = BUS_DMA_TAG_VALID(aa->aa_dmat64) ?
+		aa->aa_dmat64 : aa->aa_dmat;
 	} else {
 		aprint_verbose_dev(self, "using 32-bit DMA\n");
-		error = bus_dmatag_subregion(aa->aa_dmat, 0, 0x,
-		>sc_bus.ub_dmatag, BUS_DMA_WAITOK);
-		if (error != 0) {
-			aprint_error_dev(self, "couldn't create DMA tag: %d\n",
-			error);
-			return;
-		}
+		sc->sc_bus.ub_dmatag = aa->aa_dmat;
 	}
 
 ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,



CVS commit: src/sys/dev/acpi

2020-01-18 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 18 12:32:57 UTC 2020

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

Log Message:
Ignore PCI boot config unless the _DSM for ignoring PCI boot config is
explicitly set to 0.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/acpi/acpi_pci.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_pci.c
diff -u src/sys/dev/acpi/acpi_pci.c:1.27 src/sys/dev/acpi/acpi_pci.c:1.28
--- src/sys/dev/acpi/acpi_pci.c:1.27	Fri Jan 17 17:06:32 2020
+++ src/sys/dev/acpi/acpi_pci.c	Sat Jan 18 12:32:57 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci.c,v 1.27 2020/01/17 17:06:32 jmcneill Exp $ */
+/* $NetBSD: acpi_pci.c,v 1.28 2020/01/18 12:32:57 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.27 2020/01/17 17:06:32 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.28 2020/01/18 12:32:57 jmcneill Exp $");
 
 #include 
 #include 
@@ -518,9 +518,9 @@ acpi_pci_ignore_boot_config(ACPI_HANDLE 
 	buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
 
 	if (ACPI_FAILURE(AcpiEvaluateObject(handle, "_DSM", , )) || buf.Pointer == NULL)
-		return 0;
+		return 1;
 
-	ret = 0;
+	ret = 1;
 
 	pobj = buf.Pointer;
 	switch (pobj->Type) {



CVS commit: src/sys/dev/acpi

2020-01-12 Thread Chuck Silvers
Module Name:src
Committed By:   chs
Date:   Mon Jan 13 00:19:43 UTC 2020

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

Log Message:
apply FreeBSD revs r214848 and r214849:

r214849 | jkim | 2010-11-05 13:24:26 -0700 (Fri, 05 Nov 2010) | 2 lines

Add a forgotten change from the previous commit.

r214848 | jkim | 2010-11-05 12:50:09 -0700 (Fri, 05 Nov 2010) | 13 lines

Fix a use-after-free bug for extended IRQ resource[1].  When _PRS buffer is
copied as a template for _SRS, a string pointer for descriptor name is also
copied and it becomes stale as soon as it gets de-allocated[2].  Now _CRS is
used as a template for _SRS as ACPI specification suggests if it is usable.
The template from _PRS is still utilized but only when _CRS is not available
or broken.  To avoid use-after-free the problem in this case, however, only
mandatory fields are copied, optional data is removed, and structure length
is adjusted accordingly.

Reported by:hps[1]
Analyzed by:avg[2]
Tested by:  hps

This also fixes reading past the end of a structure as detected by KASAN.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/dev/acpi/acpi_pci_link.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_pci_link.c
diff -u src/sys/dev/acpi/acpi_pci_link.c:1.24 src/sys/dev/acpi/acpi_pci_link.c:1.25
--- src/sys/dev/acpi/acpi_pci_link.c:1.24	Fri Dec  6 07:27:06 2019
+++ src/sys/dev/acpi/acpi_pci_link.c	Mon Jan 13 00:19:43 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_pci_link.c,v 1.24 2019/12/06 07:27:06 maxv Exp $	*/
+/*	$NetBSD: acpi_pci_link.c,v 1.25 2020/01/13 00:19:43 chs Exp $	*/
 
 /*-
  * Copyright (c) 2002 Mitsuru IWASAKI 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci_link.c,v 1.24 2019/12/06 07:27:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci_link.c,v 1.25 2020/01/13 00:19:43 chs Exp $");
 
 #include 
 #include 
@@ -255,6 +255,7 @@ link_add_crs(ACPI_RESOURCE *res, void *c
 static ACPI_STATUS
 link_add_prs(ACPI_RESOURCE *res, void *context)
 {
+	ACPI_RESOURCE *tmp;
 	struct link_res_request *req;
 	struct link *link;
 	uint8_t *irqs = NULL;
@@ -301,32 +302,28 @@ link_add_prs(ACPI_RESOURCE *res, void *c
 		req->res_index++;
 
 		/*
-		 * Stash a copy of the resource for later use when
-		 * doing _SRS.
-		 *
-		 * Note that in theory res->Length may exceed the size
-		 * of ACPI_RESOURCE, due to variable length lists in
-		 * subtypes.  However, all uses of l_prs_template only
-		 * rely on lists lengths of zero or one, for which
-		 * sizeof(ACPI_RESOURCE) is sufficient space anyway.
-		 * We cannot read longer than Length bytes, in case we
-		 * read off the end of mapped memory.  So we read
-		 * whichever length is shortest, Length or
-		 * sizeof(ACPI_RESOURCE).
+		 * Stash a copy of the resource for later use when doing
+		 * _SRS.
 		 */
-		KASSERT(res->Length >= ACPI_RS_SIZE_MIN);
+		tmp = >l_prs_template;
+		if (is_ext_irq) {
+			memcpy(tmp, res, ACPI_RS_SIZE(tmp->Data.ExtendedIrq));
 
-		memset(>l_prs_template, 0, sizeof(link->l_prs_template));
-		memcpy(>l_prs_template, res,
-		   MIN(res->Length, sizeof(link->l_prs_template)));
+			/*
+			 * XXX acpi_AppendBufferResource() cannot handle
+			 * optional data.
+			 */
+			memset(>Data.ExtendedIrq.ResourceSource, 0,
+			sizeof(tmp->Data.ExtendedIrq.ResourceSource));
+			tmp->Length = ACPI_RS_SIZE(tmp->Data.ExtendedIrq);
 
-		if (is_ext_irq) {
 			link->l_num_irqs =
 			res->Data.ExtendedIrq.InterruptCount;
 			link->l_trig = res->Data.ExtendedIrq.Triggering;
 			link->l_pol = res->Data.ExtendedIrq.Polarity;
 			ext_irqs = res->Data.ExtendedIrq.Interrupts;
 		} else {
+			memcpy(tmp, res, ACPI_RS_SIZE(tmp->Data.Irq));
 			link->l_num_irqs = res->Data.Irq.InterruptCount;
 			link->l_trig = res->Data.Irq.Triggering;
 			link->l_pol = res->Data.Irq.Polarity;
@@ -737,17 +734,16 @@ acpi_pci_link_add_reference(void *v, int
 static ACPI_STATUS
 acpi_pci_link_srs_from_crs(struct acpi_pci_link_softc *sc, ACPI_BUFFER *srsbuf)
 {
-	ACPI_RESOURCE *resource, *end, newres, *resptr;
-	ACPI_BUFFER crsbuf;
+	ACPI_RESOURCE *end, *res;
 	ACPI_STATUS status;
 	struct link *link;
 	int i, in_dpf;
 
 	/* Fetch the _CRS. */
-	crsbuf.Pointer = NULL;
-	crsbuf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
-	status = AcpiGetCurrentResources(sc->pl_handle, );
-	if (ACPI_SUCCESS(status) && crsbuf.Pointer == NULL)
+	srsbuf->Pointer = NULL;
+	srsbuf->Length = ACPI_ALLOCATE_BUFFER;
+	status = AcpiGetCurrentResources(sc->pl_handle, srsbuf);
+	if (ACPI_SUCCESS(status) && srsbuf->Pointer == NULL)
 		status = AE_NO_MEMORY;
 	if (ACPI_FAILURE(status)) {
 		aprint_verbose("%s: Unable to fetch current resources: %s\n",
@@ -756,14 +752,13 @@ acpi_pci_link_srs_from_crs(struct acpi_p
 	}
 
 	/* Fill in IRQ resources via link structures. */
-	srsbuf->Pointer = NULL;
 	

CVS commit: src/sys/dev/acpi

2019-12-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Dec 31 13:39:15 UTC 2019

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

Log Message:
Include device decoding type in acpi_mem resources


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/acpi/acpi_resource.c
cvs rdiff -u -r1.79 -r1.80 src/sys/dev/acpi/acpivar.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/acpi_resource.c
diff -u src/sys/dev/acpi/acpi_resource.c:1.39 src/sys/dev/acpi/acpi_resource.c:1.40
--- src/sys/dev/acpi/acpi_resource.c:1.39	Tue Dec 31 12:27:50 2019
+++ src/sys/dev/acpi/acpi_resource.c	Tue Dec 31 13:39:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_resource.c,v 1.39 2019/12/31 12:27:50 jmcneill Exp $	*/
+/*	$NetBSD: acpi_resource.c,v 1.40 2019/12/31 13:39:15 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.39 2019/12/31 12:27:50 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.40 2019/12/31 13:39:15 jmcneill Exp $");
 
 #include 
 #include 
@@ -148,7 +148,7 @@ acpi_resource_parse_callback(ACPI_RESOUR
 			(*ops->memory)(arg->dev, arg->context,
 			res->Data.FixedMemory32.Address,
 			res->Data.FixedMemory32.AddressLength,
-			0);
+			0, 0);
 		break;
 
 	case ACPI_RESOURCE_TYPE_MEMORY32:
@@ -162,7 +162,7 @@ acpi_resource_parse_callback(ACPI_RESOUR
 (*ops->memory)(arg->dev, arg->context,
 res->Data.Memory32.Minimum,
 res->Data.Memory32.AddressLength,
-0);
+0, 0);
 		} else {
 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
 	 "Memory32 0x%x-0x%x/%u\n",
@@ -189,7 +189,7 @@ acpi_resource_parse_callback(ACPI_RESOUR
 (*ops->memory)(arg->dev, arg->context,
 res->Data.Memory24.Minimum,
 res->Data.Memory24.AddressLength,
-0);
+0, 0);
 		} else {
 			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
 	 "Memory24 0x%x-0x%x/%u\n",
@@ -259,7 +259,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 	(*ops->memory)(arg->dev, arg->context,
 	res->Data.Address32.Address.Minimum,
 	res->Data.Address32.Address.AddressLength,
-	res->Data.Address32.Address.TranslationOffset);
+	res->Data.Address32.Address.TranslationOffset,
+	res->Data.Address32.Decode);
 			} else {
 if (ops->memrange)
 	(*ops->memrange)(arg->dev, arg->context,
@@ -313,7 +314,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 	(*ops->memory)(arg->dev, arg->context,
 	res->Data.Address64.Address.Minimum,
 	res->Data.Address64.Address.AddressLength,
-	res->Data.Address64.Address.TranslationOffset);
+	res->Data.Address64.Address.TranslationOffset,
+	res->Data.Address64.Decode);
 			} else {
 if (ops->memrange)
 	(*ops->memrange)(arg->dev, arg->context,
@@ -652,7 +654,7 @@ static void	acpi_res_parse_iorange(devic
 		uint32_t, uint32_t, uint32_t);
 
 static void	acpi_res_parse_memory(device_t, void *, uint64_t,
-		uint64_t, uint64_t);
+		uint64_t, uint64_t, uint8_t);
 static void	acpi_res_parse_memrange(device_t, void *, uint64_t,
 		uint64_t, uint64_t, uint64_t);
 
@@ -802,7 +804,7 @@ acpi_res_parse_iorange(device_t dev, voi
 
 static void
 acpi_res_parse_memory(device_t dev, void *context, uint64_t base,
-uint64_t length, uint64_t offset)
+uint64_t length, uint64_t offset, uint8_t decode)
 {
 	struct acpi_resources *res = context;
 	struct acpi_mem *ar;
@@ -819,6 +821,7 @@ acpi_res_parse_memory(device_t dev, void
 	ar->ar_base = base;
 	ar->ar_length = length;
 	ar->ar_offset = offset;
+	ar->ar_decode = decode;
 
 	SIMPLEQ_INSERT_TAIL(>ar_mem, ar, ar_list);
 }

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.79 src/sys/dev/acpi/acpivar.h:1.80
--- src/sys/dev/acpi/acpivar.h:1.79	Tue Dec 31 12:27:50 2019
+++ src/sys/dev/acpi/acpivar.h	Tue Dec 31 13:39:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.79 2019/12/31 12:27:50 jmcneill Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.80 2019/12/31 13:39:15 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -227,6 +227,7 @@ struct acpi_mem {
 	bus_addr_t	ar_base;
 	bus_size_t	ar_length;
 	bus_addr_t	ar_offset;
+	uint8_t		ar_decode;
 };
 
 struct acpi_memrange {
@@ -285,7 +286,8 @@ struct acpi_resource_parse_ops {
 	void	(*iorange)(device_t, void *, uint32_t, uint32_t,
 		uint32_t, uint32_t);
 
-	void	(*memory)(device_t, void *, uint64_t, uint64_t, uint64_t);
+	void	(*memory)(device_t, void *, uint64_t, uint64_t,
+		uint64_t, uint8_t);
 	void	(*memrange)(device_t, void *, uint64_t, uint64_t,
 		uint64_t, uint64_t);
 



CVS commit: src/sys/dev/acpi

2019-12-31 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Dec 31 12:27:50 UTC 2019

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

Log Message:
Fetch bus_dma tags when acpi devnodes are created. They do not change
and this allows MD code to create more complex tags without being
concerned with the tag being destroyed later. While here, capture
translations offsets for address32/address64 resources.


To generate a diff of this commit:
cvs rdiff -u -r1.281 -r1.282 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/acpi/acpi_resource.c
cvs rdiff -u -r1.78 -r1.79 src/sys/dev/acpi/acpivar.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/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.281 src/sys/dev/acpi/acpi.c:1.282
--- src/sys/dev/acpi/acpi.c:1.281	Mon Dec 30 19:52:11 2019
+++ src/sys/dev/acpi/acpi.c	Tue Dec 31 12:27:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.281 2019/12/30 19:52:11 jmcneill Exp $	*/
+/*	$NetBSD: acpi.c,v 1.282 2019/12/31 12:27:50 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.281 2019/12/30 19:52:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.282 2019/12/31 12:27:50 jmcneill Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -200,6 +200,7 @@ static bool		acpi_resume(device_t, const
 
 static void		acpi_build_tree(struct acpi_softc *);
 static void		acpi_config_tree(struct acpi_softc *);
+static void		acpi_config_dma(struct acpi_softc *);
 static ACPI_STATUS	acpi_make_devnode(ACPI_HANDLE, uint32_t,
 	  void *, void **);
 static ACPI_STATUS	acpi_make_devnode_post(ACPI_HANDLE, uint32_t,
@@ -687,6 +688,10 @@ acpi_build_tree(struct acpi_softc *sc)
 static void
 acpi_config_tree(struct acpi_softc *sc)
 {
+	/*
+	 * Assign bus_dma resources
+	 */
+	acpi_config_dma(sc);
 
 	/*
 	 * Configure all everything found "at acpi?".
@@ -707,6 +712,24 @@ acpi_config_tree(struct acpi_softc *sc)
 	(void)config_defer(sc->sc_dev, acpi_rescan_capabilities);
 }
 
+static void
+acpi_config_dma(struct acpi_softc *sc)
+{
+	struct acpi_devnode *ad;
+
+	SIMPLEQ_FOREACH(ad, >ad_head, ad_list) {
+
+		if (ad->ad_device != NULL)
+			continue;
+
+		if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE)
+			continue;
+
+		ad->ad_dmat = acpi_get_dma_tag(sc, ad);
+		ad->ad_dmat64 = acpi_get_dma64_tag(sc, ad);
+	}
+}
+
 static ACPI_STATUS
 acpi_make_devnode(ACPI_HANDLE handle, uint32_t level,
 void *context, void **status)
@@ -895,18 +918,11 @@ acpi_rescan_early(struct acpi_softc *sc)
 		aa.aa_pc = sc->sc_pc;
 		aa.aa_pciflags = sc->sc_pciflags;
 		aa.aa_ic = sc->sc_ic;
-		aa.aa_dmat = acpi_get_dma_tag(sc, ad);
-		aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad);
+		aa.aa_dmat = ad->ad_dmat;
+		aa.aa_dmat64 = ad->ad_dmat64;
 
 		ad->ad_device = config_found_ia(sc->sc_dev,
 		"acpinodebus", , acpi_print);
-
-		if (ad->ad_device == NULL) {
-			if (aa.aa_dmat != NULL)
-bus_dmatag_destroy(aa.aa_dmat);
-			if (aa.aa_dmat64 != NULL)
-bus_dmatag_destroy(aa.aa_dmat64);
-		}
 	}
 }
 
@@ -964,18 +980,11 @@ acpi_rescan_nodes(struct acpi_softc *sc)
 		aa.aa_pc = sc->sc_pc;
 		aa.aa_pciflags = sc->sc_pciflags;
 		aa.aa_ic = sc->sc_ic;
-		aa.aa_dmat = acpi_get_dma_tag(sc, ad);
-		aa.aa_dmat64 = acpi_get_dma64_tag(sc, ad);
+		aa.aa_dmat = ad->ad_dmat;
+		aa.aa_dmat64 = ad->ad_dmat64;
 
 		ad->ad_device = config_found_ia(sc->sc_dev,
 		"acpinodebus", , acpi_print);
-
-		if (ad->ad_device == NULL) {
-			if (aa.aa_dmat != NULL)
-bus_dmatag_destroy(aa.aa_dmat);
-			if (aa.aa_dmat64 != NULL)
-bus_dmatag_destroy(aa.aa_dmat64);
-		}
 	}
 }
 

Index: src/sys/dev/acpi/acpi_resource.c
diff -u src/sys/dev/acpi/acpi_resource.c:1.38 src/sys/dev/acpi/acpi_resource.c:1.39
--- src/sys/dev/acpi/acpi_resource.c:1.38	Thu Oct 25 10:38:57 2018
+++ src/sys/dev/acpi/acpi_resource.c	Tue Dec 31 12:27:50 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_resource.c,v 1.38 2018/10/25 10:38:57 jmcneill Exp $	*/
+/*	$NetBSD: acpi_resource.c,v 1.39 2019/12/31 12:27:50 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.38 2018/10/25 10:38:57 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.39 2019/12/31 12:27:50 jmcneill Exp $");
 
 #include 
 #include 
@@ -147,7 +147,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 		if (ops->memory)
 			(*ops->memory)(arg->dev, arg->context,
 			res->Data.FixedMemory32.Address,
-			res->Data.FixedMemory32.AddressLength);
+			res->Data.FixedMemory32.AddressLength,
+			0);
 		break;
 
 	case ACPI_RESOURCE_TYPE_MEMORY32:
@@ -160,7 +161,8 @@ acpi_resource_parse_callback(ACPI_RESOUR
 			if (ops->memory)
 (*ops->memory)(arg->dev, arg->context,
 res->Data.Memory32.Minimum,
-res->Data.Memory32.AddressLength);
+  

CVS commit: src/sys/dev/acpi

2019-12-31 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Dec 31 09:10:15 UTC 2019

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

Log Message:
Free buffers only when allocated.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/dev/acpi/acpi_util.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_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.17 src/sys/dev/acpi/acpi_util.c:1.18
--- src/sys/dev/acpi/acpi_util.c:1.17	Sun Dec 29 13:45:11 2019
+++ src/sys/dev/acpi/acpi_util.c	Tue Dec 31 09:10:15 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.17 2019/12/29 13:45:11 jmcneill Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.18 2019/12/31 09:10:15 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.17 2019/12/29 13:45:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.18 2019/12/31 09:10:15 mlelstv Exp $");
 
 #include 
 #include 
@@ -694,7 +694,8 @@ acpi_dsd_integer(ACPI_HANDLE handle, con
 	if (ACPI_SUCCESS(rv))
 		*val = propval->Integer.Value;
 
-	ACPI_FREE(buf.Pointer);
+	if (buf.Pointer != NULL)
+		ACPI_FREE(buf.Pointer);
 	return rv;
 }
 
@@ -712,6 +713,7 @@ acpi_dsd_string(ACPI_HANDLE handle, cons
 	if (ACPI_SUCCESS(rv))
 		*val = kmem_strdup(propval->String.Pointer, KM_SLEEP);
 
-	ACPI_FREE(buf.Pointer);
+	if (buf.Pointer != NULL)
+		ACPI_FREE(buf.Pointer);
 	return rv;
 }



CVS commit: src/sys/dev/acpi

2019-12-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Dec 30 19:52:11 UTC 2019

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

Log Message:
Hide ACPI0004 devices on aarch64


To generate a diff of this commit:
cvs rdiff -u -r1.280 -r1.281 src/sys/dev/acpi/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/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.280 src/sys/dev/acpi/acpi.c:1.281
--- src/sys/dev/acpi/acpi.c:1.280	Mon Dec 30 19:49:38 2019
+++ src/sys/dev/acpi/acpi.c	Mon Dec 30 19:52:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.280 2019/12/30 19:49:38 jmcneill Exp $	*/
+/*	$NetBSD: acpi.c,v 1.281 2019/12/30 19:52:11 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.280 2019/12/30 19:49:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.281 2019/12/30 19:52:11 jmcneill Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -175,6 +175,7 @@ static const char * const acpi_ignored_i
 	"PNP0C04",	/* FPU is handled internally */
 #endif
 #if defined(__aarch64__)
+	"ACPI0004",	/* ACPI module devices are handled internally */
 	"ACPI0007",	/* ACPI CPUs are attached via MADT GICC subtables */
 	"PNP0C0F",	/* ACPI PCI link devices are handled internally */
 #endif



CVS commit: src/sys/dev/acpi

2019-12-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Mon Dec 30 19:49:38 UTC 2019

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

Log Message:
MD code may allocate a new dma tag for attach args, so destroy it if the device 
node is not claimed


To generate a diff of this commit:
cvs rdiff -u -r1.279 -r1.280 src/sys/dev/acpi/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/acpi.c
diff -u src/sys/dev/acpi/acpi.c:1.279 src/sys/dev/acpi/acpi.c:1.280
--- src/sys/dev/acpi/acpi.c:1.279	Sun Dec 29 23:47:56 2019
+++ src/sys/dev/acpi/acpi.c	Mon Dec 30 19:49:38 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.279 2019/12/29 23:47:56 jmcneill Exp $	*/
+/*	$NetBSD: acpi.c,v 1.280 2019/12/30 19:49:38 jmcneill Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.279 2019/12/29 23:47:56 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.280 2019/12/30 19:49:38 jmcneill Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -899,6 +899,13 @@ acpi_rescan_early(struct acpi_softc *sc)
 
 		ad->ad_device = config_found_ia(sc->sc_dev,
 		"acpinodebus", , acpi_print);
+
+		if (ad->ad_device == NULL) {
+			if (aa.aa_dmat != NULL)
+bus_dmatag_destroy(aa.aa_dmat);
+			if (aa.aa_dmat64 != NULL)
+bus_dmatag_destroy(aa.aa_dmat64);
+		}
 	}
 }
 
@@ -961,6 +968,13 @@ acpi_rescan_nodes(struct acpi_softc *sc)
 
 		ad->ad_device = config_found_ia(sc->sc_dev,
 		"acpinodebus", , acpi_print);
+
+		if (ad->ad_device == NULL) {
+			if (aa.aa_dmat != NULL)
+bus_dmatag_destroy(aa.aa_dmat);
+			if (aa.aa_dmat64 != NULL)
+bus_dmatag_destroy(aa.aa_dmat64);
+		}
 	}
 }
 



CVS commit: src/sys/dev/acpi

2019-12-29 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 29 13:45:11 UTC 2019

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

Log Message:
Add support for reading _DSD string property values.


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.7 -r1.8 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.

Modified files:

Index: src/sys/dev/acpi/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.16 src/sys/dev/acpi/acpi_util.c:1.17
--- src/sys/dev/acpi/acpi_util.c:1.16	Sun Dec 22 15:57:07 2019
+++ src/sys/dev/acpi/acpi_util.c	Sun Dec 29 13:45:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.16 2019/12/22 15:57:07 thorpej Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.17 2019/12/29 13:45:11 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.16 2019/12/22 15:57:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.17 2019/12/29 13:45:11 jmcneill Exp $");
 
 #include 
 #include 
@@ -633,23 +633,19 @@ static UINT8 acpi_dsd_uuid[ACPI_UUID_LEN
 	0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01
 };
 
-ACPI_STATUS
-acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val)
+static ACPI_STATUS
+acpi_dsd_property(ACPI_HANDLE handle, const char *prop, ACPI_BUFFER *pbuf, ACPI_OBJECT_TYPE type, ACPI_OBJECT **ret)
 {
 	ACPI_OBJECT *obj, *uuid, *props, *pobj, *propkey, *propval;
 	ACPI_STATUS rv;
-	ACPI_BUFFER buf;
 	int n;
 
-	buf.Pointer = NULL;
-	buf.Length = ACPI_ALLOCATE_BUFFER;
-
-	rv = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, , ACPI_TYPE_PACKAGE);
+	rv = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, pbuf, ACPI_TYPE_PACKAGE);
 	if (ACPI_FAILURE(rv))
 		return rv;
 
 	props = NULL;
-	obj = (ACPI_OBJECT *)buf.Pointer;
+	obj = (ACPI_OBJECT *)pbuf->Pointer;
 	for (n = 0; (n + 1) < obj->Package.Count; n += 2) {
 		uuid = >Package.Elements[n];
 		if (uuid->Buffer.Length == ACPI_UUID_LENGTH &&
@@ -658,10 +654,8 @@ acpi_dsd_integer(ACPI_HANDLE handle, con
 			break;
 		}
 	}
-	if (props == NULL) {
-		rv = AE_NOT_FOUND;
-		goto done;
-	}
+	if (props == NULL)
+		return AE_NOT_FOUND;
 
 	for (n = 0; n < props->Package.Count; n++) {
 		pobj = >Package.Elements[n];
@@ -674,16 +668,50 @@ acpi_dsd_integer(ACPI_HANDLE handle, con
 		if (strcmp(propkey->String.Pointer, prop) != 0)
 			continue;
 
-		if (propval->Type != ACPI_TYPE_INTEGER) {
-			rv = AE_TYPE;
+		if (propval->Type != type) {
+			return AE_TYPE;
 		} else {
-			*val = propval->Integer.Value;
-			rv = AE_OK;
+			*ret = propval;
+			return AE_OK;
 		}
 		break;
 	}
 
-done:
+	return AE_NOT_FOUND;
+}
+
+ACPI_STATUS
+acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val)
+{
+	ACPI_OBJECT *propval;
+	ACPI_STATUS rv;
+	ACPI_BUFFER buf;
+
+	buf.Pointer = NULL;
+	buf.Length = ACPI_ALLOCATE_BUFFER;
+
+	rv = acpi_dsd_property(handle, prop, , ACPI_TYPE_INTEGER, );
+	if (ACPI_SUCCESS(rv))
+		*val = propval->Integer.Value;
+
+	ACPI_FREE(buf.Pointer);
+	return rv;
+}
+
+ACPI_STATUS
+acpi_dsd_string(ACPI_HANDLE handle, const char *prop, char **val)
+{
+	ACPI_OBJECT *propval;
+	ACPI_STATUS rv;
+	ACPI_BUFFER buf;
+
+	buf.Pointer = NULL;
+	buf.Length = ACPI_ALLOCATE_BUFFER;
+
+	rv = acpi_dsd_property(handle, prop, , ACPI_TYPE_STRING, );
+	if (ACPI_SUCCESS(rv))
+		*val = kmem_strdup(propval->String.Pointer, KM_SLEEP);
+
 	ACPI_FREE(buf.Pointer);
 	return rv;
 }

Index: src/sys/dev/acpi/acpi_util.h
diff -u src/sys/dev/acpi/acpi_util.h:1.7 src/sys/dev/acpi/acpi_util.h:1.8
--- src/sys/dev/acpi/acpi_util.h:1.7	Fri Dec 21 14:51:12 2018
+++ src/sys/dev/acpi/acpi_util.h	Sun Dec 29 13:45:11 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.h,v 1.7 2018/12/21 14:51:12 jmcneill Exp $ */
+/*	$NetBSD: acpi_util.h,v 1.8 2019/12/29 13:45:11 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -89,5 +89,6 @@ ACPI_HANDLE	 acpi_match_cpu_info(struct 
 struct cpu_info *acpi_match_cpu_handle(ACPI_HANDLE);
 
 ACPI_STATUS	 acpi_dsd_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
+ACPI_STATUS	 acpi_dsd_string(ACPI_HANDLE, const char *, char **);
 
 #endif	/* !_SYS_DEV_ACPI_ACPI_UTIL_H */



CVS commit: src/sys/dev/acpi

2019-12-29 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sun Dec 29 12:46:43 UTC 2019

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

Log Message:
Read clock frequency from device properties


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/dev/acpi/sdhc_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/sdhc_acpi.c
diff -u src/sys/dev/acpi/sdhc_acpi.c:1.8 src/sys/dev/acpi/sdhc_acpi.c:1.9
--- src/sys/dev/acpi/sdhc_acpi.c:1.8	Tue Oct 15 00:13:52 2019
+++ src/sys/dev/acpi/sdhc_acpi.c	Sun Dec 29 12:46:43 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc_acpi.c,v 1.8 2019/10/15 00:13:52 chs Exp $	*/
+/*	$NetBSD: sdhc_acpi.c,v 1.9 2019/12/29 12:46:43 jmcneill Exp $	*/
 
 /*
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.8 2019/10/15 00:13:52 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.9 2019/12/29 12:46:43 jmcneill Exp $");
 
 #include 
 #include 
@@ -135,6 +135,7 @@ sdhc_acpi_attach(device_t parent, device
 	struct acpi_mem *mem;
 	struct acpi_irq *irq;
 	ACPI_STATUS rv;
+	ACPI_INTEGER clock_freq;
 
 	sc->sc.sc_dev = self;
 	sc->sc.sc_dmat = aa->aa_dmat;
@@ -193,6 +194,12 @@ sdhc_acpi_attach(device_t parent, device
 	/* Enable DMA transfer */
 	sc->sc.sc_flags |= SDHC_FLAG_USE_DMA;
 
+	/* Read clock frequency from device properties */
+	rv = acpi_dsd_integer(aa->aa_node->ad_handle, "clock-frequency",
+	_freq);
+	if (ACPI_SUCCESS(rv))
+		sc->sc.sc_clkbase = clock_freq / 1000;
+
 	if (sdhc_host_found(>sc, sc->sc_memt, sc->sc_memh,
 	sc->sc_memsize) != 0) {
 		aprint_error_dev(self, "couldn't initialize host\n");



CVS commit: src/sys/dev/acpi

2019-12-22 Thread Andrew Doran
Module Name:src
Committed By:   ad
Date:   Sun Dec 22 22:18:04 UTC 2019

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

Log Message:
Avoid doing zero sized allocations if we get bad data.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/acpi_srat.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_srat.c
diff -u src/sys/dev/acpi/acpi_srat.c:1.6 src/sys/dev/acpi/acpi_srat.c:1.7
--- src/sys/dev/acpi/acpi_srat.c:1.6	Tue Oct  1 18:00:08 2019
+++ src/sys/dev/acpi/acpi_srat.c	Sun Dec 22 22:18:04 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_srat.c,v 1.6 2019/10/01 18:00:08 chs Exp $ */
+/* $NetBSD: acpi_srat.c,v 1.7 2019/12/22 22:18:04 ad Exp $ */
 
 /*
  * Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_srat.c,v 1.6 2019/10/01 18:00:08 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_srat.c,v 1.7 2019/12/22 22:18:04 ad Exp $");
 
 #include 
 #include 
@@ -334,6 +334,11 @@ acpisrat_refresh(void)
 
 	nnodes = MAX(cnodes, mnodes) + 1;
 
+	if (nnodes == 0 || nmems == 0 || ncpus == 0) {
+		rc = ENOENT;
+		goto fail;
+	}
+
 	node_array = kmem_zalloc(nnodes * sizeof(struct acpisrat_node),
 	KM_SLEEP);
 	cpu_array = kmem_zalloc(ncpus * sizeof(struct acpisrat_cpu),
@@ -358,15 +363,20 @@ acpisrat_refresh(void)
 	for (i = 0; i < nnodes; i++) {
 		node_array[i].nodeid = i;
 
-		node_array[i].cpu = kmem_zalloc(node_array[i].ncpus *
-		sizeof(struct acpisrat_cpu *), KM_SLEEP);
-		node_array[i].mem = kmem_zalloc(node_array[i].nmems *
-		sizeof(struct acpisrat_mem *), KM_SLEEP);
+		if (node_array[i].ncpus != 0) {
+			node_array[i].cpu = kmem_zalloc(node_array[i].ncpus *
+			sizeof(struct acpisrat_cpu *), KM_SLEEP);
+		}
+		if (node_array[i].nmems != 0) {
+			node_array[i].mem = kmem_zalloc(node_array[i].nmems *
+			sizeof(struct acpisrat_mem *), KM_SLEEP);
+		}
 
 		k = 0;
 		for (j = 0; j < ncpus; j++) {
 			if (cpu_array[j].nodeid != i)
 continue;
+			KASSERT(node_array[i].cpu != NULL);
 			node_array[i].cpu[k] = _array[j];
 			k++;
 		}
@@ -375,11 +385,13 @@ acpisrat_refresh(void)
 		for (j = 0; j < nmems; j++) {
 			if (mem_array[j].nodeid != i)
 continue;
+			KASSERT(node_array[i].mem != NULL);
 			node_array[i].mem[k] = _array[j];
 			k++;
 		}
 	}
 
+ fail:
 	while ((citer = CPU_FIRST()) != NULL) {
 		CPU_REM(citer);
 		cpu_free(citer);
@@ -390,7 +402,7 @@ acpisrat_refresh(void)
 		mem_free(miter);
 	}
 
-	return 0;
+	return rc;
 }
 
 /*



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

2019-12-04 Thread Manuel Bouyer
Module Name:src
Committed By:   bouyer
Date:   Wed Dec  4 19:51:32 UTC 2019

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

Log Message:
Finally fix problem discussed in this old thread:
http://mail-index.netbsd.org/tech-kern/2017/12/03/msg022661.html

Dell's radio hotkey sends a PMFE_RADIO_TOGGLE event, but nothing actually
listen to it.
Turn it into a PSWITCH_HK_WIRELESS_BUTTON hotkey, similar to
what thinkpad_acpi.c does.
Add type/subtypes seen on a Dell lattitude 5480 laptop.
XXX we need a PMFE_AUDIO_MICRO_TOGGLE, and something to handle it.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/acpi/wmi/wmi_dell.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_dell.c
diff -u src/sys/dev/acpi/wmi/wmi_dell.c:1.11 src/sys/dev/acpi/wmi/wmi_dell.c:1.12
--- src/sys/dev/acpi/wmi/wmi_dell.c:1.11	Sun Dec  3 23:43:00 2017
+++ src/sys/dev/acpi/wmi/wmi_dell.c	Wed Dec  4 19:51:32 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: wmi_dell.c,v 1.11 2017/12/03 23:43:00 christos Exp $ */
+/*	$NetBSD: wmi_dell.c,v 1.12 2019/12/04 19:51:32 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: wmi_dell.c,v 1.11 2017/12/03 23:43:00 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wmi_dell.c,v 1.12 2019/12/04 19:51:32 bouyer Exp $");
 
 #include 
 #include 
@@ -53,7 +53,8 @@ __KERNEL_RCSID(0, "$NetBSD: wmi_dell.c,v
 ACPI_MODULE_NAME			("wmi_dell")
 
 #define WMI_DELL_PSW_DISPLAY_CYCLE	0
-#define WMI_DELL_PSW_COUNT		1
+#define WMI_DELL_PSW_RADIO_TOGGLE	1
+#define WMI_DELL_PSW_COUNT		2
 
 #define WMI_DELL_GUID_EVENT		"9DBB5994-A997-11DA-B012-B622A1EF5492"
 #define WMI_DELL_GUID_DESC		"8D9DDCBC-A997-11DA-B012-B622A1EF5492"
@@ -82,7 +83,7 @@ const struct wmi_dell_actions {
 	{WMI_DELLA_PMF, 0x, 0xe006, PMFE_DISPLAY_BRIGHTNESS_UP},
 	{WMI_DELLA_PSW, 0x, 0xe00b, WMI_DELL_PSW_DISPLAY_CYCLE},
 
-	{WMI_DELLA_PMF, 0x, 0xe008, PMFE_RADIO_TOGGLE},
+	{WMI_DELLA_PSW, 0x, 0xe008, WMI_DELL_PSW_RADIO_TOGGLE},
 	{WMI_DELLA_IGN, 0x, 0xe00c, 0}, /* keyboard illumination */
 
 	/* volume control */
@@ -96,14 +97,16 @@ const struct wmi_dell_actions {
 	/* type 0x10 */
 	{WMI_DELLA_PMF, 0x0010, 0x0057, PMFE_DISPLAY_BRIGHTNESS_DOWN},
 	{WMI_DELLA_PMF, 0x0010, 0x0058, PMFE_DISPLAY_BRIGHTNESS_UP},
+	{WMI_DELLA_IGN, 0x0010, 0x0150, 0}, /* XXX microphone toggle */
 	{WMI_DELLA_IGN, 0x0010, 0x0151, 0}, /* Fn-lock */
 	{WMI_DELLA_IGN, 0x0010, 0x0152, 0}, /* keyboard illumination */
-	{WMI_DELLA_PMF, 0x0010, 0x0153, PMFE_RADIO_TOGGLE},
+	{WMI_DELLA_PSW, 0x0010, 0x0153, WMI_DELL_PSW_RADIO_TOGGLE},
 	{WMI_DELLA_IGN, 0x0010, 0x0155, 0}, /* Stealth mode toggle */
+	{WMI_DELLA_PSW, 0x0010, 0xE008, WMI_DELL_PSW_RADIO_TOGGLE},
 	{WMI_DELLA_IGN, 0x0010, 0xE035, 0}, /* Fn-lock */
 
 	/* type 0x11 */
-	{WMI_DELLA_IGN, 0x0011, 0x02eb5, 0}, /* keyboard illumination */
+	{WMI_DELLA_IGN, 0x0011, 0x02eb, 0}, /* keyboard illumination */
 };
 
 static int	wmi_dell_match(device_t, cfdata_t, void *);
@@ -182,9 +185,23 @@ wmi_dell_attach(device_t parent, device_
 
 	e = sysmon_pswitch_register(>sc_smpsw[WMI_DELL_PSW_DISPLAY_CYCLE]);
 
+	if (e != 0) {
+		sc->sc_smpsw_valid = false;
+		goto end;
+	}
+
+	sc->sc_smpsw[WMI_DELL_PSW_RADIO_TOGGLE].smpsw_name =
+	PSWITCH_HK_WIRELESS_BUTTON;
+
+	sc->sc_smpsw[WMI_DELL_PSW_RADIO_TOGGLE].smpsw_type =
+	PSWITCH_TYPE_HOTKEY;
+
+	e = sysmon_pswitch_register(>sc_smpsw[WMI_DELL_PSW_RADIO_TOGGLE]);
+
 	if (e != 0)
 		sc->sc_smpsw_valid = false;
 
+end:
 	(void)pmf_device_register(self, wmi_dell_suspend, wmi_dell_resume);
 }
 



CVS commit: src/sys/dev/acpi

2019-04-21 Thread matthew green
Module Name:src
Committed By:   mrg
Date:   Sun Apr 21 21:52:10 UTC 2019

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

Log Message:
use cpu_name() on a struct cpu_info *.  don't assume it has a ci_dev
member that is valid input to device_xname().

fixes build on arm64.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/acpi/acpi_tz.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_tz.c
diff -u src/sys/dev/acpi/acpi_tz.c:1.89 src/sys/dev/acpi/acpi_tz.c:1.90
--- src/sys/dev/acpi/acpi_tz.c:1.89	Thu Jun  1 02:45:09 2017
+++ src/sys/dev/acpi/acpi_tz.c	Sun Apr 21 21:52:09 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_tz.c,v 1.89 2017/06/01 02:45:09 chs Exp $ */
+/* $NetBSD: acpi_tz.c,v 1.90 2019/04/21 21:52:09 mrg Exp $ */
 
 /*
  * Copyright (c) 2003 Jared D. McNeill 
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.89 2017/06/01 02:45:09 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 1.90 2019/04/21 21:52:09 mrg Exp $");
 
 #include 
 #include 
@@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: acpi_tz.c,v 
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -748,7 +749,7 @@ acpitz_print_processor_list(device_t dv)
 		if (cnt == 0)
 			aprint_normal(":");
 
-		aprint_normal(" %s", device_xname(ci->ci_dev));
+		aprint_normal(" %s", cpu_name(ci));
 
 		sc->sc_psl[cnt] = ci;
 		++cnt;



CVS commit: src/sys/dev/acpi

2019-03-01 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Fri Mar  1 09:21:06 UTC 2019

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

Log Message:
Fix build for i386.

The acpi_intr_establish function should really take an AD_HANDLE parameter.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/acpi/com_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/com_acpi.c
diff -u src/sys/dev/acpi/com_acpi.c:1.39 src/sys/dev/acpi/com_acpi.c:1.40
--- src/sys/dev/acpi/com_acpi.c:1.39	Tue Feb 26 06:15:55 2019
+++ src/sys/dev/acpi/com_acpi.c	Fri Mar  1 09:21:06 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: com_acpi.c,v 1.39 2019/02/26 06:15:55 mlelstv Exp $ */
+/* $NetBSD: com_acpi.c,v 1.40 2019/03/01 09:21:06 mlelstv Exp $ */
 
 /*
  * Copyright (c) 2002 Jared D. McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.39 2019/02/26 06:15:55 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.40 2019/03/01 09:21:06 mlelstv Exp $");
 
 #include 
 #include 
@@ -174,7 +174,7 @@ com_acpi_attach(device_t parent, device_
 
 	if (!ISSET(sc->sc_hwflags, COM_HW_POLL))
 		asc->sc_ih = acpi_intr_establish(self,
-		(uint64_t)aa->aa_node->ad_handle,
+		(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
 		IPL_SERIAL, true, comintr, sc, device_xname(self));
 
 	if (!pmf_device_register(self, NULL, com_resume))



CVS commit: src/sys/dev/acpi

2019-02-25 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Tue Feb 26 06:15:55 UTC 2019

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

Log Message:
Cast to same type as parameter. NFCI.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/acpi/com_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/com_acpi.c
diff -u src/sys/dev/acpi/com_acpi.c:1.38 src/sys/dev/acpi/com_acpi.c:1.39
--- src/sys/dev/acpi/com_acpi.c:1.38	Mon Dec 24 17:44:40 2018
+++ src/sys/dev/acpi/com_acpi.c	Tue Feb 26 06:15:55 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: com_acpi.c,v 1.38 2018/12/24 17:44:40 christos Exp $ */
+/* $NetBSD: com_acpi.c,v 1.39 2019/02/26 06:15:55 mlelstv Exp $ */
 
 /*
  * Copyright (c) 2002 Jared D. McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.38 2018/12/24 17:44:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.39 2019/02/26 06:15:55 mlelstv Exp $");
 
 #include 
 #include 
@@ -174,7 +174,7 @@ com_acpi_attach(device_t parent, device_
 
 	if (!ISSET(sc->sc_hwflags, COM_HW_POLL))
 		asc->sc_ih = acpi_intr_establish(self,
-		(intptr_t)aa->aa_node->ad_handle,
+		(uint64_t)aa->aa_node->ad_handle,
 		IPL_SERIAL, true, comintr, sc, device_xname(self));
 
 	if (!pmf_device_register(self, NULL, com_resume))



CVS commit: src/sys/dev/acpi

2019-02-16 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Sat Feb 16 23:28:57 UTC 2019

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

Log Message:
Fix cut & paste error in comment


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/xhci_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/xhci_acpi.c
diff -u src/sys/dev/acpi/xhci_acpi.c:1.2 src/sys/dev/acpi/xhci_acpi.c:1.3
--- src/sys/dev/acpi/xhci_acpi.c:1.2	Fri Nov 16 23:18:17 2018
+++ src/sys/dev/acpi/xhci_acpi.c	Sat Feb 16 23:28:56 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: xhci_acpi.c,v 1.2 2018/11/16 23:18:17 jmcneill Exp $ */
+/* $NetBSD: xhci_acpi.c,v 1.3 2019/02/16 23:28:56 tron Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.2 2018/11/16 23:18:17 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,v 1.3 2019/02/16 23:28:56 tron Exp $");
 
 #include 
 #include 
@@ -50,8 +50,8 @@ __KERNEL_RCSID(0, "$NetBSD: xhci_acpi.c,
 #include 
 
 static const char * const compatible[] = {
-	"PNP0D10",	/* EHCI-compliant USB controller without standard debug */
-	"PNP0D15",	/* EHCI-compliant USB controller with standard debug */
+	"PNP0D10",	/* XHCI-compliant USB controller without standard debug */
+	"PNP0D15",	/* XHCI-compliant USB controller with standard debug */
 	NULL
 };
 



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

2019-02-15 Thread Kamil Rytarowski
Module Name:src
Committed By:   kamil
Date:   Fri Feb 15 20:48:57 UTC 2019

Modified Files:
src/sys/dev/acpi/acpica: OsdHardware.c

Log Message:
Avoid UB in OsdHardware.c

UBSan: Undefined Behavior in src/sys/dev/acpi/acpica/OsdHardware.c:265:17,
left shift of 255 by 24 places cannot be represented in type 'int'

This file isn't part of upstream acpica so just fix it locally.

Reported and initial patch by 


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/dev/acpi/acpica/OsdHardware.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/acpica/OsdHardware.c
diff -u src/sys/dev/acpi/acpica/OsdHardware.c:1.10 src/sys/dev/acpi/acpica/OsdHardware.c:1.11
--- src/sys/dev/acpi/acpica/OsdHardware.c:1.10	Tue Jan 26 22:52:14 2016
+++ src/sys/dev/acpi/acpica/OsdHardware.c	Fri Feb 15 20:48:57 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: OsdHardware.c,v 1.10 2016/01/26 22:52:14 christos Exp $	*/
+/*	$NetBSD: OsdHardware.c,v 1.11 2019/02/15 20:48:57 kamil Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -44,7 +44,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: OsdHardware.c,v 1.10 2016/01/26 22:52:14 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: OsdHardware.c,v 1.11 2019/02/15 20:48:57 kamil Exp $");
 
 #include 
 #include 
@@ -262,13 +262,13 @@ AcpiOsWritePciConfiguration(ACPI_PCI_ID 
 	switch (Width) {
 	case 8:
 		tmp = pci_conf_read(pc, tag, Register & ~3);
-		tmp &= ~(0xff << ((Register & 3) * 8));
+		tmp &= ~(0xffu << ((Register & 3) * 8));
 		tmp |= (Value << ((Register & 3) * 8));
 		break;
 
 	case 16:
 		tmp = pci_conf_read(pc, tag, Register & ~3);
-		tmp &= ~(0x << ((Register & 3) * 8));
+		tmp &= ~(0xu << ((Register & 3) * 8));
 		tmp |= (Value << ((Register & 3) * 8));
 		break;
 



CVS commit: src/sys/dev/acpi

2019-01-30 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 30 20:20:37 UTC 2019

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

Log Message:
don't print resources twice. It is automagically done in acpi_res_parse_fini.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/ipmi_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/ipmi_acpi.c
diff -u src/sys/dev/acpi/ipmi_acpi.c:1.2 src/sys/dev/acpi/ipmi_acpi.c:1.3
--- src/sys/dev/acpi/ipmi_acpi.c:1.2	Wed Dec 26 01:45:58 2018
+++ src/sys/dev/acpi/ipmi_acpi.c	Wed Jan 30 15:20:36 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: ipmi_acpi.c,v 1.2 2018/12/26 06:45:58 mlelstv Exp $ */
+/* $NetBSD: ipmi_acpi.c,v 1.3 2019/01/30 20:20:36 christos Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ipmi_acpi.c,v 1.2 2018/12/26 06:45:58 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ipmi_acpi.c,v 1.3 2019/01/30 20:20:36 christos Exp $");
 
 #include 
 #include 
@@ -122,8 +122,6 @@ ipmi_acpi_attach(device_t parent, device
 			return;
 		}
 
-		acpi_resource_print(self, );
-
 		io = acpi_res_io(, 0);
 		mem = acpi_res_mem(, 0);
 		if (io == NULL && mem == NULL) {



CVS commit: src/sys/dev/acpi

2019-01-05 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Jan  5 20:40:26 UTC 2019

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

Log Message:
add normal debug level


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/acpi/acpi_debug.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_debug.c
diff -u src/sys/dev/acpi/acpi_debug.c:1.5 src/sys/dev/acpi/acpi_debug.c:1.6
--- src/sys/dev/acpi/acpi_debug.c:1.5	Tue Feb 25 13:30:09 2014
+++ src/sys/dev/acpi/acpi_debug.c	Sat Jan  5 15:40:26 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_debug.c,v 1.5 2014/02/25 18:30:09 pooka Exp $ */
+/* $NetBSD: acpi_debug.c,v 1.6 2019/01/05 20:40:26 christos Exp $ */
 
 /*-
  * Copyright (c) 2010 Jukka Ruohonen 
@@ -27,7 +27,7 @@
  * SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_debug.c,v 1.5 2014/02/25 18:30:09 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_debug.c,v 1.6 2019/01/05 20:40:26 christos Exp $");
 
 #include 
 #include 
@@ -219,6 +219,8 @@ acpi_debug_create(void)
 	ACPI_DEBUG_ADD(acpi_debug_level_d, ACPI_LV_EVENTS);
 	ACPI_DEBUG_ADD(acpi_debug_level_d, ACPI_LV_VERBOSE);
 
+	ACPI_DEBUG_ADD(acpi_debug_level_d, ACPI_NORMAL_DEFAULT);
+
 	/*
 	 * The default debug level.
 	 */



CVS commit: src/sys/dev/acpi

2018-12-24 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Mon Dec 24 17:44:40 UTC 2018

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

Log Message:
- fix compilation on 32 bit systems.
- wrap long lines


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/acpi/com_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/com_acpi.c
diff -u src/sys/dev/acpi/com_acpi.c:1.37 src/sys/dev/acpi/com_acpi.c:1.38
--- src/sys/dev/acpi/com_acpi.c:1.37	Fri Dec 21 09:51:47 2018
+++ src/sys/dev/acpi/com_acpi.c	Mon Dec 24 12:44:40 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: com_acpi.c,v 1.37 2018/12/21 14:51:47 jmcneill Exp $ */
+/* $NetBSD: com_acpi.c,v 1.38 2018/12/24 17:44:40 christos Exp $ */
 
 /*
  * Copyright (c) 2002 Jared D. McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.37 2018/12/21 14:51:47 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.38 2018/12/24 17:44:40 christos Exp $");
 
 #include 
 #include 
@@ -163,7 +163,8 @@ com_acpi_attach(device_t parent, device_
 		}
 	}
 
-	rv = acpi_dsd_integer(aa->aa_node->ad_handle, "clock-frequency", _freq);
+	rv = acpi_dsd_integer(aa->aa_node->ad_handle, "clock-frequency",
+	_freq);
 	if (ACPI_SUCCESS(rv))
 		sc->sc_frequency = clock_freq;
 	else
@@ -172,7 +173,8 @@ com_acpi_attach(device_t parent, device_
 	com_attach_subr(sc);
 
 	if (!ISSET(sc->sc_hwflags, COM_HW_POLL))
-		asc->sc_ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+		asc->sc_ih = acpi_intr_establish(self,
+		(intptr_t)aa->aa_node->ad_handle,
 		IPL_SERIAL, true, comintr, sc, device_xname(self));
 
 	if (!pmf_device_register(self, NULL, com_resume))



CVS commit: src/sys/dev/acpi

2018-12-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Dec 21 14:51:47 UTC 2018

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

Log Message:
Support Designware APB UART


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/dev/acpi/com_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/com_acpi.c
diff -u src/sys/dev/acpi/com_acpi.c:1.36 src/sys/dev/acpi/com_acpi.c:1.37
--- src/sys/dev/acpi/com_acpi.c:1.36	Sat Dec  8 17:46:13 2018
+++ src/sys/dev/acpi/com_acpi.c	Fri Dec 21 14:51:47 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: com_acpi.c,v 1.36 2018/12/08 17:46:13 thorpej Exp $ */
+/* $NetBSD: com_acpi.c,v 1.37 2018/12/21 14:51:47 jmcneill Exp $ */
 
 /*
  * Copyright (c) 2002 Jared D. McNeill 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.36 2018/12/08 17:46:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v 1.37 2018/12/21 14:51:47 jmcneill Exp $");
 
 #include 
 #include 
@@ -34,11 +34,10 @@ __KERNEL_RCSID(0, "$NetBSD: com_acpi.c,v
 #include 
 
 #include 
+#include 
 
 #include 
 
-#include 
-
 static int	com_acpi_match(device_t, cfdata_t , void *);
 static void	com_acpi_attach(device_t, device_t, void *);
 
@@ -63,6 +62,17 @@ static const char * const com_acpi_ids[]
 	"SMCF010",	/* SMC SuperIO IRDA device */
 	"NSC6001",	/* NSC IRDA device */
 	"FUJ02E6",	/* Fujitsu Serial Pen Tablet */
+	"HISI0031",	/* Hisilicon UART */
+	"8250dw",	/* Designware APB UART */
+	NULL
+};
+
+/*
+ * Subset of supported device IDs of type COM_TYPE_DW_APB
+ */
+static const char * const com_acpi_dw_ids[] = {
+	"HISI0031",	/* Hisilicon UART */
+	"8250dw",	/* Designware APB UART */
 	NULL
 };
 
@@ -98,6 +108,7 @@ com_acpi_attach(device_t parent, device_
 	bus_addr_t base;
 	bus_size_t size;
 	ACPI_STATUS rv;
+	ACPI_INTEGER clock_freq;
 
 	sc->sc_dev = self;
 
@@ -142,18 +153,27 @@ com_acpi_attach(device_t parent, device_
 
 	aprint_normal("%s", device_xname(self));
 
-	if (com_probe_subr(>sc_regs) == 0) {
-		aprint_error(": com probe failed\n");
-		goto out;
+	if (acpi_match_hid(aa->aa_node->ad_devinfo, com_acpi_dw_ids) != 0) {
+		sc->sc_type = COM_TYPE_DW_APB;
+		SET(sc->sc_hwflags, COM_HW_POLL);	/* XXX */
+	} else {
+		if (com_probe_subr(>sc_regs) == 0) {
+			aprint_error(": com probe failed\n");
+			goto out;
+		}
 	}
 
-	sc->sc_frequency = 115200 * 16;
+	rv = acpi_dsd_integer(aa->aa_node->ad_handle, "clock-frequency", _freq);
+	if (ACPI_SUCCESS(rv))
+		sc->sc_frequency = clock_freq;
+	else
+		sc->sc_frequency = 115200 * 16;
 
 	com_attach_subr(sc);
 
-	asc->sc_ih = isa_intr_establish_xname(aa->aa_ic, irq->ar_irq,
-	(irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL,
-	IPL_SERIAL, comintr, sc, device_xname(sc->sc_dev));
+	if (!ISSET(sc->sc_hwflags, COM_HW_POLL))
+		asc->sc_ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+		IPL_SERIAL, true, comintr, sc, device_xname(self));
 
 	if (!pmf_device_register(self, NULL, com_resume))
 		aprint_error_dev(self, "couldn't establish a power handler\n");



CVS commit: src/sys/dev/acpi

2018-12-21 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Dec 21 14:51:12 UTC 2018

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

Log Message:
Add acpi_dsd_integer, which reads an integer value from an ACPI 5.0 _DSD
key/value package list.


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.6 -r1.7 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.

Modified files:

Index: src/sys/dev/acpi/acpi_util.c
diff -u src/sys/dev/acpi/acpi_util.c:1.14 src/sys/dev/acpi/acpi_util.c:1.15
--- src/sys/dev/acpi/acpi_util.c:1.14	Fri Nov 16 23:05:50 2018
+++ src/sys/dev/acpi/acpi_util.c	Fri Dec 21 14:51:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.c,v 1.14 2018/11/16 23:05:50 jmcneill Exp $ */
+/*	$NetBSD: acpi_util.c,v 1.15 2018/12/21 14:51:12 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.14 2018/11/16 23:05:50 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.15 2018/12/21 14:51:12 jmcneill Exp $");
 
 #include 
 #include 
@@ -607,3 +607,67 @@ acpi_intr_string(void *c, char *buf, siz
 
 	return intr_string(ih, buf, size);
 }
+
+/*
+ * USB Device-Specific Data (_DSD) support
+ */
+
+static UINT8 acpi_dsd_uuid[ACPI_UUID_LENGTH] = {
+	0x14, 0xd8, 0xff, 0xda, 0xba, 0x6e, 0x8c, 0x4d,
+	0x8a, 0x91, 0xbc, 0x9b, 0xbf, 0x4a, 0xa3, 0x01
+};
+
+ACPI_STATUS
+acpi_dsd_integer(ACPI_HANDLE handle, const char *prop, ACPI_INTEGER *val)
+{
+	ACPI_OBJECT *obj, *uuid, *props, *pobj, *propkey, *propval;
+	ACPI_STATUS rv;
+	ACPI_BUFFER buf;
+	int n;
+
+	buf.Pointer = NULL;
+	buf.Length = ACPI_ALLOCATE_BUFFER;
+
+	rv = AcpiEvaluateObjectTyped(handle, "_DSD", NULL, , ACPI_TYPE_PACKAGE);
+	if (ACPI_FAILURE(rv))
+		return rv;
+
+	props = NULL;
+	obj = (ACPI_OBJECT *)buf.Pointer;
+	for (n = 0; (n + 1) < obj->Package.Count; n += 2) {
+		uuid = >Package.Elements[n];
+		if (uuid->Buffer.Length == ACPI_UUID_LENGTH &&
+		memcmp(uuid->Buffer.Pointer, acpi_dsd_uuid, ACPI_UUID_LENGTH) == 0) {
+			props = >Package.Elements[n + 1];
+			break;
+		}
+	}
+	if (props == NULL) {
+		rv = AE_NOT_FOUND;
+		goto done;
+	}
+
+	for (n = 0; n < props->Package.Count; n++) {
+		pobj = >Package.Elements[n];
+		if (pobj->Type != ACPI_TYPE_PACKAGE || pobj->Package.Count != 2)
+			continue;
+		propkey = (ACPI_OBJECT *)>Package.Elements[0];
+		propval = (ACPI_OBJECT *)>Package.Elements[1];
+		if (propkey->Type != ACPI_TYPE_STRING)
+			continue;
+		if (strcmp(propkey->String.Pointer, prop) != 0)
+			continue;
+
+		if (propval->Type != ACPI_TYPE_INTEGER) {
+			rv = AE_TYPE;
+		} else {
+			*val = propval->Integer.Value;
+			rv = AE_OK;
+		}
+		break;
+	}
+
+done:
+	ACPI_FREE(buf.Pointer);
+	return rv;
+}

Index: src/sys/dev/acpi/acpi_util.h
diff -u src/sys/dev/acpi/acpi_util.h:1.6 src/sys/dev/acpi/acpi_util.h:1.7
--- src/sys/dev/acpi/acpi_util.h:1.6	Fri Oct 12 23:25:29 2018
+++ src/sys/dev/acpi/acpi_util.h	Fri Dec 21 14:51:12 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_util.h,v 1.6 2018/10/12 23:25:29 jmcneill Exp $ */
+/*	$NetBSD: acpi_util.h,v 1.7 2018/12/21 14:51:12 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -88,4 +88,6 @@ int		 acpi_match_class(ACPI_HANDLE, uint
 ACPI_HANDLE	 acpi_match_cpu_info(struct cpu_info *);
 struct cpu_info *acpi_match_cpu_handle(ACPI_HANDLE);
 
+ACPI_STATUS	 acpi_dsd_integer(ACPI_HANDLE, const char *, ACPI_INTEGER *);
+
 #endif	/* !_SYS_DEV_ACPI_ACPI_UTIL_H */



CVS commit: src/sys/dev/acpi

2018-12-20 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Dec 20 19:16:17 UTC 2018

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

Log Message:
An ACPI MCFG allocation with start bus number = end bus number is valid,
so do not skip it. An entry like this defines MCFG space for a single bus.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/dev/acpi/acpi_mcfg.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_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.15 src/sys/dev/acpi/acpi_mcfg.c:1.16
--- src/sys/dev/acpi/acpi_mcfg.c:1.15	Sat Dec  8 15:02:06 2018
+++ src/sys/dev/acpi/acpi_mcfg.c	Thu Dec 20 19:16:17 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.15 2018/12/08 15:02:06 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.16 2018/12/20 19:16:17 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.15 2018/12/08 15:02:06 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.16 2018/12/20 19:16:17 jmcneill Exp $");
 
 #include 
 #include 
@@ -350,15 +350,6 @@ acpimcfg_init(bus_space_tag_t memt, cons
 		 * Some (broken?) BIOSen have an MCFG table for an empty
 		 * bus range.  Ignore those tables.
 		 */
-		if (ama->StartBusNumber == ama->EndBusNumber) {
-			aprint_debug_dev(acpi_sc->sc_dev,
-			"MCFG: segment %d, bus %d-%d, address 0x%016" PRIx64
-			": ignore (bus %d == %d)\n", ama->PciSegment,
-			ama->StartBusNumber, ama->EndBusNumber,
-			ama->Address, ama->StartBusNumber,
-			ama->EndBusNumber);
-			goto next;
-		}
 		if (ama->StartBusNumber > ama->EndBusNumber) {
 			aprint_debug_dev(acpi_sc->sc_dev,
 			"MCFG: segment %d, bus %d-%d, address 0x%016" PRIx64



CVS commit: src/sys/dev/acpi

2018-12-09 Thread Jaromir Dolecek
Module Name:src
Committed By:   jdolecek
Date:   Sun Dec  9 11:12:58 UTC 2018

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

Log Message:
make compile on 64-bit archs after acpi_mem ar_length was changed
from uint32_t to bus_size_t in rev. 1.77 of acpivar.h


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/tpm_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/tpm_acpi.c
diff -u src/sys/dev/acpi/tpm_acpi.c:1.6 src/sys/dev/acpi/tpm_acpi.c:1.7
--- src/sys/dev/acpi/tpm_acpi.c:1.6	Thu Feb 22 01:50:26 2018
+++ src/sys/dev/acpi/tpm_acpi.c	Sun Dec  9 11:12:58 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: tpm_acpi.c,v 1.6 2018/02/22 01:50:26 christos Exp $ */
+/* $NetBSD: tpm_acpi.c,v 1.7 2018/12/09 11:12:58 jdolecek Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -52,7 +52,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.6 2018/02/22 01:50:26 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tpm_acpi.c,v 1.7 2018/12/09 11:12:58 jdolecek Exp $");
 
 #include 
 #include 
@@ -156,8 +156,8 @@ tpm_acpi_attach(device_t parent, device_
 
 		if (mem->ar_length != TPM_SIZE) {
 			aprint_error_dev(sc->sc_dev,
-			"wrong size mem %u != %u\n",
-			mem->ar_length, TPM_SIZE);
+			"wrong size mem %"PRIu64" != %u\n",
+			(uint64_t)mem->ar_length, TPM_SIZE);
 			goto out;
 		}
 



CVS commit: src/sys/dev/acpi

2018-12-08 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Dec  8 15:02:06 UTC 2018

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

Log Message:
acpimcfg_configure_bus_cb can support 16-bit addresses now


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/dev/acpi/acpi_mcfg.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_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.14 src/sys/dev/acpi/acpi_mcfg.c:1.15
--- src/sys/dev/acpi/acpi_mcfg.c:1.14	Mon Dec  3 05:22:03 2018
+++ src/sys/dev/acpi/acpi_mcfg.c	Sat Dec  8 15:02:06 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.14 2018/12/03 05:22:03 cherry Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.15 2018/12/08 15:02:06 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.14 2018/12/03 05:22:03 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.15 2018/12/08 15:02:06 jmcneill Exp $");
 
 #include 
 #include 
@@ -717,7 +717,8 @@ acpimcfg_configure_bus_cb(ACPI_RESOURCE 
 	const char *s;
 	int error;
 
-	if (res->Type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
+	if (res->Type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
+	res->Type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
 	res->Type != ACPI_RESOURCE_TYPE_ADDRESS64)
 		return AE_OK;
 



CVS commit: src/sys/dev/acpi

2018-12-02 Thread Cherry G. Mathew
Module Name:src
Committed By:   cherry
Date:   Mon Dec  3 05:22:03 UTC 2018

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

Log Message:
Define macro before using it. This macro is used as a compile time
"plugin" mechanism to use various platform specific enumeration
functions. It is currently separately defined for 'native' and XEN,
but the mechanism is not exported globally as it should be.

XXX: fix this.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/dev/acpi/acpi_mcfg.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_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.13 src/sys/dev/acpi/acpi_mcfg.c:1.14
--- src/sys/dev/acpi/acpi_mcfg.c:1.13	Fri Nov  2 19:51:08 2018
+++ src/sys/dev/acpi/acpi_mcfg.c	Mon Dec  3 05:22:03 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.13 2018/11/02 19:51:08 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.14 2018/12/03 05:22:03 cherry Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.13 2018/11/02 19:51:08 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.14 2018/12/03 05:22:03 cherry Exp $");
 
 #include 
 #include 
@@ -539,6 +539,10 @@ acpimcfg_device_probe(const struct pci_a
 	return 0;
 }
 
+#ifdef PCI_MACHDEP_ENUMERATE_BUS
+#define pci_enumerate_bus PCI_MACHDEP_ENUMERATE_BUS
+#endif
+
 static void
 acpimcfg_scan_bus(struct pci_softc *sc, pci_chipset_tag_t pc, int bus)
 {



CVS commit: src/sys/dev/acpi

2018-11-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Nov 23 14:08:40 UTC 2018

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

Log Message:
Use acpi_intr_establish


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/dev/acpi/plgpio_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/plgpio_acpi.c
diff -u src/sys/dev/acpi/plgpio_acpi.c:1.4 src/sys/dev/acpi/plgpio_acpi.c:1.5
--- src/sys/dev/acpi/plgpio_acpi.c:1.4	Tue Oct 23 09:19:02 2018
+++ src/sys/dev/acpi/plgpio_acpi.c	Fri Nov 23 14:08:40 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: plgpio_acpi.c,v 1.4 2018/10/23 09:19:02 jmcneill Exp $ */
+/* $NetBSD: plgpio_acpi.c,v 1.5 2018/11/23 14:08:40 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: plgpio_acpi.c,v 1.4 2018/10/23 09:19:02 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: plgpio_acpi.c,v 1.5 2018/11/23 14:08:40 jmcneill Exp $");
 
 #include 
 #include 
@@ -40,6 +40,7 @@ __KERNEL_RCSID(0, "$NetBSD: plgpio_acpi.
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -108,7 +109,7 @@ plgpio_acpi_attach(device_t parent, devi
 	}
 
 	irq = acpi_res_irq(, 0);
-	if (mem == NULL) {
+	if (irq == NULL) {
 		aprint_error_dev(self, "couldn't find irq resource\n");
 		goto done;
 	}
@@ -130,8 +131,8 @@ plgpio_acpi_attach(device_t parent, devi
 		goto done;
 	}
 
-	const int type = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL;
-	ih = intr_establish(irq->ar_irq, IPL_VM, type, plgpio_acpi_intr, asc);
+	ih = acpi_intr_establish(self, (uint64_t)asc->sc_handle,
+	IPL_VM, false, plgpio_acpi_intr, asc, device_xname(self));
 	if (ih == NULL)
 		aprint_error_dev(self, "couldn't establish interrupt\n");
 



CVS commit: src/sys/dev/acpi

2018-11-16 Thread Robert Elz
Module Name:src
Committed By:   kre
Date:   Sat Nov 17 07:06:26 UTC 2018

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

Log Message:
Attempt to appease gcc and unbreak i386 build.   Should be NFC.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/dev/acpi/sdhc_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/sdhc_acpi.c
diff -u src/sys/dev/acpi/sdhc_acpi.c:1.6 src/sys/dev/acpi/sdhc_acpi.c:1.7
--- src/sys/dev/acpi/sdhc_acpi.c:1.6	Fri Nov 16 23:05:50 2018
+++ src/sys/dev/acpi/sdhc_acpi.c	Sat Nov 17 07:06:25 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sdhc_acpi.c,v 1.6 2018/11/16 23:05:50 jmcneill Exp $	*/
+/*	$NetBSD: sdhc_acpi.c,v 1.7 2018/11/17 07:06:25 kre Exp $	*/
 
 /*
  * Copyright (c) 2016 Kimihiro Nonaka 
@@ -26,7 +26,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.6 2018/11/16 23:05:50 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sdhc_acpi.c,v 1.7 2018/11/17 07:06:25 kre Exp $");
 
 #include 
 #include 
@@ -179,7 +179,8 @@ sdhc_acpi_attach(device_t parent, device
 		goto cleanup;
 	}
 
-	sc->sc_ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+	sc->sc_ih = acpi_intr_establish(self,
+	(uint64_t)(uintptr_t)aa->aa_node->ad_handle,
 	IPL_BIO, false, sdhc_intr, >sc, device_xname(self));
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(self,



CVS commit: src/sys/dev/acpi

2018-11-16 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Nov 16 23:18:17 UTC 2018

Modified Files:
src/sys/dev/acpi: ahcisata_acpi.c dwiic_acpi.c ehci_acpi.c
virtio_acpi.c xhci_acpi.c

Log Message:
Use acpi_intr_establish


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/ahcisata_acpi.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/dwiic_acpi.c \
src/sys/dev/acpi/virtio_acpi.c src/sys/dev/acpi/xhci_acpi.c
cvs rdiff -u -r1.2 -r1.3 src/sys/dev/acpi/ehci_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/ahcisata_acpi.c
diff -u src/sys/dev/acpi/ahcisata_acpi.c:1.3 src/sys/dev/acpi/ahcisata_acpi.c:1.4
--- src/sys/dev/acpi/ahcisata_acpi.c:1.3	Mon Oct 15 18:58:35 2018
+++ src/sys/dev/acpi/ahcisata_acpi.c	Fri Nov 16 23:18:17 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ahcisata_acpi.c,v 1.3 2018/10/15 18:58:35 jdolecek Exp $ */
+/* $NetBSD: ahcisata_acpi.c,v 1.4 2018/11/16 23:18:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ahcisata_acpi.c,v 1.3 2018/10/15 18:58:35 jdolecek Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahcisata_acpi.c,v 1.4 2018/11/16 23:18:17 jmcneill Exp $");
 
 #include 
 #include 
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: ahcisata_acp
 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -102,8 +103,8 @@ ahcisata_acpi_attach(device_t parent, de
 		goto done;
 	}
 
-	const int type = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL;
-	ih = intr_establish(irq->ar_irq, IPL_BIO, type, ahci_intr, sc);
+	ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+	IPL_BIO, false, ahci_intr, sc, device_xname(self));
 	if (ih == NULL) {
 		aprint_error_dev(self, "couldn't install interrupt handler\n");
 		return;

Index: src/sys/dev/acpi/dwiic_acpi.c
diff -u src/sys/dev/acpi/dwiic_acpi.c:1.1 src/sys/dev/acpi/dwiic_acpi.c:1.2
--- src/sys/dev/acpi/dwiic_acpi.c:1.1	Wed Oct 17 00:03:47 2018
+++ src/sys/dev/acpi/dwiic_acpi.c	Fri Nov 16 23:18:17 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: dwiic_acpi.c,v 1.1 2018/10/17 00:03:47 jmcneill Exp $ */
+/* $NetBSD: dwiic_acpi.c,v 1.2 2018/11/16 23:18:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.1 2018/10/17 00:03:47 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.2 2018/11/16 23:18:17 jmcneill Exp $");
 
 #include 
 #include 
@@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c
 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -113,8 +114,8 @@ dwiic_acpi_attach(device_t parent, devic
 		return;
 	}
 
-	const int type = (irq->ar_type == ACPI_EDGE_SENSITIVE) ? IST_EDGE : IST_LEVEL;
-	ih = intr_establish(irq->ar_irq, IPL_VM, type, dwiic_intr, sc);
+	ih = acpi_intr_establish(self, (uint64_t)aa->aa_node->ad_handle,
+	IPL_VM, true, dwiic_intr, sc, device_xname(self));
 	if (ih == NULL) {
 		aprint_error_dev(self, "couldn't install interrupt handler\n");
 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, mem->ar_length);
Index: src/sys/dev/acpi/virtio_acpi.c
diff -u src/sys/dev/acpi/virtio_acpi.c:1.1 src/sys/dev/acpi/virtio_acpi.c:1.2
--- src/sys/dev/acpi/virtio_acpi.c:1.1	Sun Oct 21 12:26:38 2018
+++ src/sys/dev/acpi/virtio_acpi.c	Fri Nov 16 23:18:17 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: virtio_acpi.c,v 1.1 2018/10/21 12:26:38 jmcneill Exp $ */
+/* $NetBSD: virtio_acpi.c,v 1.2 2018/11/16 23:18:17 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: virtio_acpi.c,v 1.1 2018/10/21 12:26:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: virtio_acpi.c,v 1.2 2018/11/16 23:18:17 jmcneill Exp $");
 
 #include 
 #include 
@@ -39,12 +39,14 @@ __KERNEL_RCSID(0, "$NetBSD: virtio_acpi.
 
 #include 
 #include 
+#include 
 
 #define	VIRTIO_PRIVATE
 #include 
 
 struct virtio_acpi_softc {
 	struct virtio_mmio_softc	sc_msc;
+	ACPI_HANDLE			sc_handle;
 	intsc_irq;
 	intsc_irqtype;
 };
@@ -90,6 +92,7 @@ virtio_acpi_attach(device_t parent, devi
 	ACPI_STATUS rv;
 	int error;
 
+	sc->sc_handle = aa->aa_node->ad_handle;
 	msc->sc_iot = aa->aa_memt;
 	vsc->sc_dev = self;
 	vsc->sc_dmat = aa->aa_dmat;
@@ -164,7 +167,8 @@ virtio_acpi_setup_interrupts(struct virt
 	struct virtio_acpi_softc * const sc = (struct virtio_acpi_softc *)msc;
 	struct virtio_softc * const vsc = >sc_sc;
 
-	msc->sc_ih = intr_establish(sc->sc_irq, IPL_VM, sc->sc_irqtype, virtio_mmio_intr, msc);
+	msc->sc_ih = acpi_intr_establish(vsc->sc_dev, (uint64_t)sc->sc_handle,
+IPL_VM, false, virtio_mmio_intr, msc, device_xname(vsc->sc_dev));
 	if (msc->sc_ih == NULL) {
 		aprint_error_dev(vsc->sc_dev, "couldn't install interrupt handler\n");
 		return -1;
@@ -179,7 +183,7 @@ static void
 virtio_acpi_free_interrupts(struct 

CVS commit: src/sys/dev/acpi

2018-11-02 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Nov  2 19:51:08 UTC 2018

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

Log Message:
Do not ignore non-zero segment numbers in MCFG if __HAVE_PCI_GET_SEGMENT
is defined.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/acpi/acpi_mcfg.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_mcfg.c
diff -u src/sys/dev/acpi/acpi_mcfg.c:1.12 src/sys/dev/acpi/acpi_mcfg.c:1.13
--- src/sys/dev/acpi/acpi_mcfg.c:1.12	Fri Nov  2 15:01:18 2018
+++ src/sys/dev/acpi/acpi_mcfg.c	Fri Nov  2 19:51:08 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_mcfg.c,v 1.12 2018/11/02 15:01:18 jmcneill Exp $	*/
+/*	$NetBSD: acpi_mcfg.c,v 1.13 2018/11/02 19:51:08 jmcneill Exp $	*/
 
 /*-
  * Copyright (C) 2015 NONAKA Kimihiro 
@@ -28,7 +28,7 @@
 #include "opt_pci.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.12 2018/11/02 15:01:18 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_mcfg.c,v 1.13 2018/11/02 19:51:08 jmcneill Exp $");
 
 #include 
 #include 
@@ -394,6 +394,7 @@ acpimcfg_init(bus_space_tag_t memt, cons
 			ama->Address, ama->StartBusNumber, bus_end);
 		}
 
+#ifndef __HAVE_PCI_GET_SEGMENT
 		if (ama->PciSegment != 0) {
 			aprint_debug_dev(acpi_sc->sc_dev,
 			"MCFG: segment %d, bus %d-%d, address 0x%016" PRIx64
@@ -401,6 +402,7 @@ acpimcfg_init(bus_space_tag_t memt, cons
 			ama->StartBusNumber, bus_end, ama->Address);
 			goto next;
 		}
+#endif
 
 		seg = _segs[nsegs++];
 		seg->ms_address = ama->Address;



CVS commit: src/sys/dev/acpi

2018-10-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 26 23:33:38 UTC 2018

Modified Files:
src/sys/dev/acpi: ehci_acpi.c files.acpi
Added Files:
src/sys/dev/acpi: acpi_usb.c acpi_usb.h xhci_acpi.c

Log Message:
Add xhci at acpi glue


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/acpi/acpi_usb.c \
src/sys/dev/acpi/acpi_usb.h src/sys/dev/acpi/xhci_acpi.c
cvs rdiff -u -r1.1 -r1.2 src/sys/dev/acpi/ehci_acpi.c
cvs rdiff -u -r1.112 -r1.113 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/ehci_acpi.c
diff -u src/sys/dev/acpi/ehci_acpi.c:1.1 src/sys/dev/acpi/ehci_acpi.c:1.2
--- src/sys/dev/acpi/ehci_acpi.c:1.1	Fri Oct 26 10:46:21 2018
+++ src/sys/dev/acpi/ehci_acpi.c	Fri Oct 26 23:33:38 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: ehci_acpi.c,v 1.1 2018/10/26 10:46:21 jmcneill Exp $ */
+/* $NetBSD: ehci_acpi.c,v 1.2 2018/10/26 23:33:38 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ehci_acpi.c,v 1.1 2018/10/26 10:46:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci_acpi.c,v 1.2 2018/10/26 23:33:38 jmcneill Exp $");
 
 #include 
 #include 
@@ -46,12 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: ehci_acpi.c,
 
 #include 
 #include 
-
-/* Windows-defined USB subsystem device-specific method (_DSM) */
-static UINT8 ehci_acpi_dsm_uuid[ACPI_UUID_LENGTH] = {
-	0x85, 0xe3, 0x2e, 0xce, 0xe6, 0x00, 0xcb, 0x48,
-	0x9f, 0x05, 0x2e, 0xdb, 0x92, 0x7c, 0x48, 0x99
-};
+#include 
 
 static const char * const compatible[] = {
 	"PNP0D20",	/* EHCI-compliant USB controller without standard debug */
@@ -158,32 +153,6 @@ static void
 ehci_acpi_init(struct ehci_softc *sc)
 {
 	struct ehci_acpi_softc * const asc = (struct ehci_acpi_softc *)sc;
-	ACPI_OBJECT_LIST objs;
-	ACPI_OBJECT obj[4];
-	ACPI_HANDLE method;
-
-	/*
-	 * Invoke the _DSM control method for post-reset processing function
-	 * for dual-role USB controllers. If supported, this will perform any
-	 * controller-specific initialization required to put the dual-role
-	 * device into host mode.
-	 */
-
-	objs.Count = 4;
-	objs.Pointer = obj;
-	obj[0].Type = ACPI_TYPE_BUFFER;
-	obj[0].Buffer.Length = ACPI_UUID_LENGTH;
-	obj[0].Buffer.Pointer = ehci_acpi_dsm_uuid;
-	obj[1].Type = ACPI_TYPE_INTEGER;
-	obj[1].Integer.Value = 0;	/* Revision ID = 0 */
-	obj[2].Type = ACPI_TYPE_INTEGER;
-	obj[2].Integer.Value = 1;	/* Function index = 1 */
-	obj[3].Type = ACPI_TYPE_PACKAGE;
-	obj[3].Package.Count = 0;	/* Empty package (not used) */
-	obj[3].Package.Elements = NULL;
-
-	if (ACPI_FAILURE(AcpiGetHandle(asc->sc_handle, "_DSM", )))
-		return;
 
-	(void)AcpiEvaluateObject(method, NULL, , NULL);
+	acpi_usb_post_reset(asc->sc_handle);
 }

Index: src/sys/dev/acpi/files.acpi
diff -u src/sys/dev/acpi/files.acpi:1.112 src/sys/dev/acpi/files.acpi:1.113
--- src/sys/dev/acpi/files.acpi:1.112	Fri Oct 26 10:46:21 2018
+++ src/sys/dev/acpi/files.acpi	Fri Oct 26 23:33:38 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.112 2018/10/26 10:46:21 jmcneill Exp $
+#	$NetBSD: files.acpi,v 1.113 2018/10/26 23:33:38 jmcneill Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -32,6 +32,7 @@ file	dev/acpi/acpi_resource.c	acpi
 file	dev/acpi/acpi_srat.c		acpi
 file	dev/acpi/acpi_slit.c		acpi
 file	dev/acpi/acpi_timer.c		acpi
+file	dev/acpi/acpi_usb.c		acpi
 file	dev/acpi/acpi_util.c		acpi
 file	dev/acpi/acpi_wakedev.c		acpi
 file	dev/acpi/acpi_verbose.c		acpi & acpiverbose
@@ -259,4 +260,8 @@ file	dev/acpi/virtio_acpi.c		virtio_acpi
 attach	ehci at acpinodebus with ehci_acpi
 file	dev/acpi/ehci_acpi.c		ehci_acpi
 
+# XHCI-compliant USB controller
+attach	xhci at acpinodebus with xhci_acpi
+file	dev/acpi/xhci_acpi.c		xhci_acpi
+
 include	"dev/acpi/wmi/files.wmi"

Added files:

Index: src/sys/dev/acpi/acpi_usb.c
diff -u /dev/null src/sys/dev/acpi/acpi_usb.c:1.1
--- /dev/null	Fri Oct 26 23:33:38 2018
+++ src/sys/dev/acpi/acpi_usb.c	Fri Oct 26 23:33:38 2018
@@ -0,0 +1,84 @@
+/* $NetBSD: acpi_usb.c,v 1.1 2018/10/26 23:33:38 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill .
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR 

CVS commit: src/sys/dev/acpi

2018-10-26 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri Oct 26 10:46:21 UTC 2018

Modified Files:
src/sys/dev/acpi: files.acpi
Added Files:
src/sys/dev/acpi: ehci_acpi.c

Log Message:
Add ehci at acpi glue


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/dev/acpi/ehci_acpi.c
cvs rdiff -u -r1.111 -r1.112 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.111 src/sys/dev/acpi/files.acpi:1.112
--- src/sys/dev/acpi/files.acpi:1.111	Mon Oct 22 22:36:19 2018
+++ src/sys/dev/acpi/files.acpi	Fri Oct 26 10:46:21 2018
@@ -1,4 +1,4 @@
-#	$NetBSD: files.acpi,v 1.111 2018/10/22 22:36:19 jmcneill Exp $
+#	$NetBSD: files.acpi,v 1.112 2018/10/26 10:46:21 jmcneill Exp $
 
 include "dev/acpi/acpica/files.acpica"
 
@@ -255,4 +255,8 @@ file	dev/acpi/amdccp_acpi.c		amdccp_acpi
 attach	virtio at acpinodebus with virtio_acpi
 file	dev/acpi/virtio_acpi.c		virtio_acpi
 
+# EHCI-compliant USB controller
+attach	ehci at acpinodebus with ehci_acpi
+file	dev/acpi/ehci_acpi.c		ehci_acpi
+
 include	"dev/acpi/wmi/files.wmi"

Added files:

Index: src/sys/dev/acpi/ehci_acpi.c
diff -u /dev/null src/sys/dev/acpi/ehci_acpi.c:1.1
--- /dev/null	Fri Oct 26 10:46:21 2018
+++ src/sys/dev/acpi/ehci_acpi.c	Fri Oct 26 10:46:21 2018
@@ -0,0 +1,189 @@
+/* $NetBSD: ehci_acpi.c,v 1.1 2018/10/26 10:46:21 jmcneill Exp $ */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jared McNeill .
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include 
+__KERNEL_RCSID(0, "$NetBSD: ehci_acpi.c,v 1.1 2018/10/26 10:46:21 jmcneill Exp $");
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+/* Windows-defined USB subsystem device-specific method (_DSM) */
+static UINT8 ehci_acpi_dsm_uuid[ACPI_UUID_LENGTH] = {
+	0x85, 0xe3, 0x2e, 0xce, 0xe6, 0x00, 0xcb, 0x48,
+	0x9f, 0x05, 0x2e, 0xdb, 0x92, 0x7c, 0x48, 0x99
+};
+
+static const char * const compatible[] = {
+	"PNP0D20",	/* EHCI-compliant USB controller without standard debug */
+	"PNP0D25",	/* EHCI-compliant USB controller with standard debug */
+	NULL
+};
+
+struct ehci_acpi_softc {
+	struct ehci_softc	sc_ehci;
+	ACPI_HANDLE		sc_handle;
+};
+
+static int	ehci_acpi_match(device_t, cfdata_t, void *);
+static void	ehci_acpi_attach(device_t, device_t, void *);
+
+static void	ehci_acpi_init(struct ehci_softc *);
+
+CFATTACH_DECL2_NEW(ehci_acpi, sizeof(struct ehci_acpi_softc),
+	ehci_acpi_match, ehci_acpi_attach, NULL,
+	ehci_activate, NULL, ehci_childdet);
+
+static int
+ehci_acpi_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct acpi_attach_args *aa = aux;
+
+	if (aa->aa_node->ad_type != ACPI_TYPE_DEVICE)
+		return 0;
+
+	return acpi_match_hid(aa->aa_node->ad_devinfo, compatible);
+}
+
+static void
+ehci_acpi_attach(device_t parent, device_t self, void *aux)
+{
+	struct ehci_acpi_softc * const asc = device_private(self);
+	struct ehci_softc * const sc = >sc_ehci;
+	struct acpi_attach_args *aa = aux;
+	struct acpi_resources res;
+	struct acpi_mem *mem;
+	struct acpi_irq *irq;
+	ACPI_STATUS rv;
+	int error;
+	void *ih;
+
+	asc->sc_handle = aa->aa_node->ad_handle;
+
+	sc->sc_dev = self;
+	sc->sc_bus.ub_hcpriv = sc;
+	sc->sc_bus.ub_dmatag = aa->aa_dmat;
+	sc->sc_bus.ub_revision = USBREV_2_0;
+	sc->sc_flags = EHCIF_ETTF;
+	sc->sc_vendor_init = ehci_acpi_init;
+
+	rv = acpi_resource_parse(sc->sc_dev, asc->sc_handle, "_CRS",
+	

CVS commit: src/sys/dev/acpi

2018-10-25 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Thu Oct 25 10:38:57 UTC 2018

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

Log Message:
Add support for 64-bit memory resources.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/dev/acpi/acpi_resource.c
cvs rdiff -u -r1.76 -r1.77 src/sys/dev/acpi/acpivar.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/acpi_resource.c
diff -u src/sys/dev/acpi/acpi_resource.c:1.37 src/sys/dev/acpi/acpi_resource.c:1.38
--- src/sys/dev/acpi/acpi_resource.c:1.37	Mon Jul 27 04:50:50 2015
+++ src/sys/dev/acpi/acpi_resource.c	Thu Oct 25 10:38:57 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi_resource.c,v 1.37 2015/07/27 04:50:50 msaitoh Exp $	*/
+/*	$NetBSD: acpi_resource.c,v 1.38 2018/10/25 10:38:57 jmcneill Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.37 2015/07/27 04:50:50 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_resource.c,v 1.38 2018/10/25 10:38:57 jmcneill Exp $");
 
 #include 
 #include 
@@ -246,12 +246,12 @@ acpi_resource_parse_callback(ACPI_RESOUR
 		if (res->Data.Address32.Address.AddressLength == 0 ||
 		res->Data.Address32.ProducerConsumer != ACPI_CONSUMER)
 			break;
-#define ADRRESS32_FIXED2(r)		\
+#define ADDRESS32_FIXED2(r)		\
 	((r)->Data.Address32.MinAddressFixed == ACPI_ADDRESS_FIXED &&	\
 	 (r)->Data.Address32.MaxAddressFixed == ACPI_ADDRESS_FIXED)
 		switch (res->Data.Address32.ResourceType) {
 		case ACPI_MEMORY_RANGE:
-			if (ADRRESS32_FIXED2(res)) {
+			if (ADDRESS32_FIXED2(res)) {
 if (ops->memory)
 	(*ops->memory)(arg->dev, arg->context,
 	res->Data.Address32.Address.Minimum,
@@ -266,7 +266,7 @@ acpi_resource_parse_callback(ACPI_RESOUR
 			}
 			break;
 		case ACPI_IO_RANGE:
-			if (ADRRESS32_FIXED2(res)) {
+			if (ADDRESS32_FIXED2(res)) {
 if (ops->ioport)
 	(*ops->ioport)(arg->dev, arg->context,
 	res->Data.Address32.Address.Minimum,
@@ -285,7 +285,7 @@ acpi_resource_parse_callback(ACPI_RESOUR
   "Address32/BusNumber unimplemented\n"));
 			break;
 		}
-#undef ADRRESS32_FIXED2
+#undef ADDRESS32_FIXED2
 		break;
 
 	case ACPI_RESOURCE_TYPE_ADDRESS16:
@@ -294,8 +294,55 @@ acpi_resource_parse_callback(ACPI_RESOUR
 		break;
 
 	case ACPI_RESOURCE_TYPE_ADDRESS64:
+#ifdef _LP64
+		/* XXX Only fixed size supported for now */
+		if (res->Data.Address64.Address.AddressLength == 0 ||
+		res->Data.Address64.ProducerConsumer != ACPI_CONSUMER)
+			break;
+#define ADDRESS64_FIXED2(r)		\
+	((r)->Data.Address64.MinAddressFixed == ACPI_ADDRESS_FIXED &&	\
+	 (r)->Data.Address64.MaxAddressFixed == ACPI_ADDRESS_FIXED)
+		switch (res->Data.Address64.ResourceType) {
+		case ACPI_MEMORY_RANGE:
+			if (ADDRESS64_FIXED2(res)) {
+if (ops->memory)
+	(*ops->memory)(arg->dev, arg->context,
+	res->Data.Address64.Address.Minimum,
+	res->Data.Address64.Address.AddressLength);
+			} else {
+if (ops->memrange)
+	(*ops->memrange)(arg->dev, arg->context,
+	res->Data.Address64.Address.Minimum,
+	res->Data.Address64.Address.Maximum,
+	res->Data.Address64.Address.AddressLength,
+	res->Data.Address64.Address.Granularity);
+			}
+			break;
+		case ACPI_IO_RANGE:
+			if (ADDRESS64_FIXED2(res)) {
+if (ops->ioport)
+	(*ops->ioport)(arg->dev, arg->context,
+	res->Data.Address64.Address.Minimum,
+	res->Data.Address64.Address.AddressLength);
+			} else {
+if (ops->iorange)
+	(*ops->iorange)(arg->dev, arg->context,
+	res->Data.Address64.Address.Minimum,
+	res->Data.Address64.Address.Maximum,
+	res->Data.Address64.Address.AddressLength,
+	res->Data.Address64.Address.Granularity);
+			}
+			break;
+		case ACPI_BUS_NUMBER_RANGE:
+			ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
+  "Address64/BusNumber unimplemented\n"));
+			break;
+		}
+#undef ADDRESS64_FIXED2
+#else
 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
  "Address64 unimplemented\n"));
+#endif
 		break;
 	case ACPI_RESOURCE_TYPE_EXTENDED_ADDRESS64:
 		ACPI_DEBUG_PRINT((ACPI_DB_RESOURCES,
@@ -423,9 +470,11 @@ acpi_resource_print(device_t dev, struct
 		sep = "";
 		aprint_normal(" mem ");
 		SIMPLEQ_FOREACH(ar, >ar_mem, ar_list) {
-			aprint_normal("%s0x%x", sep, ar->ar_base);
+			aprint_normal("%s0x%" PRIx64, sep,
+			(uint64_t)ar->ar_base);
 			if (ar->ar_length > 1)
-aprint_normal("-0x%x", ar->ar_base +
+aprint_normal("-0x%" PRIx64,
+(uint64_t)ar->ar_base +
 ar->ar_length - 1);
 			sep = ",";
 		}
@@ -597,10 +646,10 @@ static void	acpi_res_parse_ioport(device
 static void	acpi_res_parse_iorange(device_t, void *, uint32_t,
 		uint32_t, uint32_t, uint32_t);
 
-static void	acpi_res_parse_memory(device_t, void *, uint32_t,
-		uint32_t);
-static void	

CVS commit: src/sys/dev/acpi

2018-10-23 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Tue Oct 23 09:19:02 UTC 2018

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

Log Message:
Do not complain if the _AEI method is not found, just skip installing the
interrupt handler.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/plgpio_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/plgpio_acpi.c
diff -u src/sys/dev/acpi/plgpio_acpi.c:1.3 src/sys/dev/acpi/plgpio_acpi.c:1.4
--- src/sys/dev/acpi/plgpio_acpi.c:1.3	Mon Oct 22 22:29:35 2018
+++ src/sys/dev/acpi/plgpio_acpi.c	Tue Oct 23 09:19:02 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: plgpio_acpi.c,v 1.3 2018/10/22 22:29:35 jmcneill Exp $ */
+/* $NetBSD: plgpio_acpi.c,v 1.4 2018/10/23 09:19:02 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: plgpio_acpi.c,v 1.3 2018/10/22 22:29:35 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: plgpio_acpi.c,v 1.4 2018/10/23 09:19:02 jmcneill Exp $");
 
 #include 
 #include 
@@ -123,8 +123,10 @@ plgpio_acpi_attach(device_t parent, devi
 
 	plgpio_attach(sc);
 
-	if (ACPI_FAILURE(acpi_event_create_gpio(self, asc->sc_handle, plgpio_acpi_register_event, asc))) {
-		aprint_error_dev(self, "failed to create events\n");
+	rv = acpi_event_create_gpio(self, asc->sc_handle, plgpio_acpi_register_event, asc);
+	if (ACPI_FAILURE(rv)) {
+		if (rv != AE_NOT_FOUND)
+			aprint_error_dev(self, "failed to create events: %s\n", AcpiFormatException(rv));
 		goto done;
 	}
 



  1   2   3   4   5   6   7   >