Module Name: src
Committed By: jmcneill
Date: Fri Oct 12 23:25:29 UTC 2018
Modified Files:
src/sys/dev/acpi: acpi_util.c acpi_util.h
Log Message:
Add helper function to match a PCI-defined class/subclass/interface
against a _CLS object.
To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/dev/acpi/acpi_util.c
cvs rdiff -u -r1.5 -r1.6 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.12 src/sys/dev/acpi/acpi_util.c:1.13
--- src/sys/dev/acpi/acpi_util.c:1.12 Fri Oct 12 21:19:11 2018
+++ src/sys/dev/acpi/acpi_util.c Fri Oct 12 23:25:29 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_util.c,v 1.12 2018/10/12 21:19:11 jmcneill Exp $ */
+/* $NetBSD: acpi_util.c,v 1.13 2018/10/12 23:25:29 jmcneill Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.12 2018/10/12 21:19:11 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_util.c,v 1.13 2018/10/12 23:25:29 jmcneill Exp $");
#include <sys/param.h>
#include <sys/kmem.h>
@@ -340,6 +340,43 @@ acpi_match_hid(ACPI_DEVICE_INFO *ad, con
}
/*
+ * Match a PCI-defined bass-class, sub-class, and programming interface
+ * against a handle's _CLS object.
+ */
+int
+acpi_match_class(ACPI_HANDLE handle, uint8_t pci_class, uint8_t pci_subclass,
+ uint8_t pci_interface)
+{
+ ACPI_BUFFER buf;
+ ACPI_OBJECT *obj;
+ ACPI_STATUS rv;
+ int match = 0;
+
+ rv = acpi_eval_struct(handle, "_CLS", &buf);
+ if (ACPI_FAILURE(rv))
+ goto done;
+
+ obj = buf.Pointer;
+ if (obj->Type != ACPI_TYPE_PACKAGE)
+ goto done;
+ if (obj->Package.Count != 3)
+ goto done;
+ if (obj->Package.Elements[0].Type != ACPI_TYPE_INTEGER ||
+ obj->Package.Elements[1].Type != ACPI_TYPE_INTEGER ||
+ obj->Package.Elements[2].Type != ACPI_TYPE_INTEGER)
+ goto done;
+
+ match = obj->Package.Elements[0].Integer.Value == pci_class &&
+ obj->Package.Elements[1].Integer.Value == pci_subclass &&
+ obj->Package.Elements[2].Integer.Value == pci_interface;
+
+done:
+ if (buf.Pointer)
+ ACPI_FREE(buf.Pointer);
+ return match;
+}
+
+/*
* Match a device node from a handle.
*/
struct acpi_devnode *
Index: src/sys/dev/acpi/acpi_util.h
diff -u src/sys/dev/acpi/acpi_util.h:1.5 src/sys/dev/acpi/acpi_util.h:1.6
--- src/sys/dev/acpi/acpi_util.h:1.5 Tue Jun 21 03:37:21 2011
+++ src/sys/dev/acpi/acpi_util.h Fri Oct 12 23:25:29 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_util.h,v 1.5 2011/06/21 03:37:21 jruoho Exp $ */
+/* $NetBSD: acpi_util.h,v 1.6 2018/10/12 23:25:29 jmcneill Exp $ */
/*-
* Copyright (c) 2003, 2007 The NetBSD Foundation, Inc.
@@ -84,6 +84,7 @@ void acpi_match_node_init(struct a
const char *acpi_name(ACPI_HANDLE);
int acpi_match_hid(ACPI_DEVICE_INFO *, const char * const *);
+int acpi_match_class(ACPI_HANDLE, uint8_t, uint8_t, uint8_t);
ACPI_HANDLE acpi_match_cpu_info(struct cpu_info *);
struct cpu_info *acpi_match_cpu_handle(ACPI_HANDLE);