Module Name:    src
Committed By:   christos
Date:           Sat May  5 17:16:23 UTC 2018

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

Log Message:
introduce acpi_device_present() to replace the previous _STA checks.


To generate a diff of this commit:
cvs rdiff -u -r1.269 -r1.270 src/sys/dev/acpi/acpi.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/acpi/acpi_i2c.c
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/acpi/acpi_pci.c
cvs rdiff -u -r1.74 -r1.75 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.269 src/sys/dev/acpi/acpi.c:1.270
--- src/sys/dev/acpi/acpi.c:1.269	Sat Apr  7 11:49:52 2018
+++ src/sys/dev/acpi/acpi.c	Sat May  5 13:16:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpi.c,v 1.269 2018/04/07 15:49:52 christos Exp $	*/
+/*	$NetBSD: acpi.c,v 1.270 2018/05/05 17:16:23 christos Exp $	*/
 
 /*-
  * Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -100,7 +100,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.269 2018/04/07 15:49:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi.c,v 1.270 2018/05/05 17:16:23 christos Exp $");
 
 #include "pci.h"
 #include "opt_acpi.h"
@@ -898,6 +898,17 @@ acpi_rescan_nodes(struct acpi_softc *sc)
 
 		di = ad->ad_devinfo;
 
+		/*
+		 * We only attach devices which are present, enabled, and
+		 * functioning properly. However, if a device is enabled,
+		 * it is decoding resources and we should claim these,
+		 * if possible. This requires changes to bus_space(9).
+		 */
+		if (di->Type == ACPI_TYPE_DEVICE &&
+		    !acpi_device_present(ad->ad_handle)) {
+			continue;
+		}
+
 		if (di->Type == ACPI_TYPE_POWER)
 			continue;
 
@@ -1749,6 +1760,22 @@ acpi_is_scope(struct acpi_devnode *ad)
 	return false;
 }
 
+bool
+acpi_device_present(ACPI_HANDLE handle)
+{
+	ACPI_STATUS rv;
+	ACPI_INTEGER sta;
+
+	rv = acpi_eval_integer(handle, "_STA", &sta);
+
+	if (ACPI_FAILURE(rv)) {
+		/* No _STA method -> must be there */
+		return rv == AE_NOT_FOUND;
+	}
+
+	return (sta & ACPI_STA_OK) == ACPI_STA_OK;
+}
+
 /*
  * ACPIVERBOSE.
  */
@@ -1797,6 +1824,7 @@ acpi_activate_device(ACPI_HANDLE handle,
 	ACPI_DEVICE_INFO *newdi;
 	ACPI_STATUS rv;
 
+
 	/*
 	 * If the device is valid and present,
 	 * but not enabled, try to activate it.
@@ -1804,6 +1832,9 @@ acpi_activate_device(ACPI_HANDLE handle,
 	if (((*di)->Valid & valid) != valid)
 		return;
 
+	if (!acpi_device_present(handle))
+		return;
+
 	rv = acpi_allocate_resources(handle);
 
 	if (ACPI_FAILURE(rv))

Index: src/sys/dev/acpi/acpi_i2c.c
diff -u src/sys/dev/acpi/acpi_i2c.c:1.3 src/sys/dev/acpi/acpi_i2c.c:1.4
--- src/sys/dev/acpi/acpi_i2c.c:1.3	Sat Apr  7 11:49:52 2018
+++ src/sys/dev/acpi/acpi_i2c.c	Sat May  5 13:16:23 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_i2c.c,v 1.3 2018/04/07 15:49:52 christos Exp $ */
+/* $NetBSD: acpi_i2c.c,v 1.4 2018/05/05 17:16:23 christos Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.3 2018/04/07 15:49:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.4 2018/05/05 17:16:23 christos Exp $");
 
 #include <dev/acpi/acpireg.h>
 #include <dev/acpi/acpivar.h>
@@ -228,6 +228,8 @@ acpi_enter_i2c_devs(struct acpi_devnode 
 	SIMPLEQ_FOREACH(ad, &devnode->ad_child_head, ad_child_list) {
 		if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE)
 			continue;
+		if (!acpi_device_present(ad->ad_handle))
+			continue;
 		acpi_enter_i2c_device(ad, array);
 	}
 	return array;

Index: src/sys/dev/acpi/acpi_pci.c
diff -u src/sys/dev/acpi/acpi_pci.c:1.21 src/sys/dev/acpi/acpi_pci.c:1.22
--- src/sys/dev/acpi/acpi_pci.c:1.21	Sat Apr  7 11:49:52 2018
+++ src/sys/dev/acpi/acpi_pci.c	Sat May  5 13:16:23 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_pci.c,v 1.21 2018/04/07 15:49:52 christos Exp $ */
+/* $NetBSD: acpi_pci.c,v 1.22 2018/05/05 17:16:23 christos Exp $ */
 
 /*
  * Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.21 2018/04/07 15:49:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_pci.c,v 1.22 2018/05/05 17:16:23 christos Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -185,6 +185,9 @@ acpi_pcidev_scan(struct acpi_devnode *ad
 	if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE)
 		goto rec;
 
+	if (!acpi_device_present(ad->ad_handle))
+		goto rec;
+
 	if (ad->ad_devinfo->Flags & ACPI_PCI_ROOT_BRIDGE) {
 
 		ap = kmem_zalloc(sizeof(*ap), KM_SLEEP);

Index: src/sys/dev/acpi/acpivar.h
diff -u src/sys/dev/acpi/acpivar.h:1.74 src/sys/dev/acpi/acpivar.h:1.75
--- src/sys/dev/acpi/acpivar.h:1.74	Tue Jun 21 07:33:33 2016
+++ src/sys/dev/acpi/acpivar.h	Sat May  5 13:16:23 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: acpivar.h,v 1.74 2016/06/21 11:33:33 nonaka Exp $	*/
+/*	$NetBSD: acpivar.h,v 1.75 2018/05/05 17:16:23 christos Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -303,6 +303,8 @@ int		acpi_probe(void);
 void		acpi_disable(void);
 int		acpi_check(device_t, const char *);
 
+bool    	acpi_device_present(ACPI_HANDLE);
+
 int		acpi_reset(void);
 
 ACPI_PHYSICAL_ADDRESS	acpi_OsGetRootPointer(void);

Reply via email to