Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/acpi Add helper function to match a PCI-defined clas...



details:   https://anonhg.NetBSD.org/src/rev/8f99634029da
branches:  trunk
changeset: 836348:8f99634029da
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Oct 12 23:25:29 2018 +0000

description:
Add helper function to match a PCI-defined class/subclass/interface
against a _CLS object.

diffstat:

 sys/dev/acpi/acpi_util.c |  41 +++++++++++++++++++++++++++++++++++++++--
 sys/dev/acpi/acpi_util.h |   3 ++-
 2 files changed, 41 insertions(+), 3 deletions(-)

diffs (79 lines):

diff -r ed2043cd9fa4 -r 8f99634029da sys/dev/acpi/acpi_util.c
--- a/sys/dev/acpi/acpi_util.c  Fri Oct 12 22:22:21 2018 +0000
+++ b/sys/dev/acpi/acpi_util.c  Fri Oct 12 23:25:29 2018 +0000
@@ -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 @@
 }
 
 /*
+ * 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 *
diff -r ed2043cd9fa4 -r 8f99634029da sys/dev/acpi/acpi_util.h
--- a/sys/dev/acpi/acpi_util.h  Fri Oct 12 22:22:21 2018 +0000
+++ b/sys/dev/acpi/acpi_util.h  Fri Oct 12 23:25:29 2018 +0000
@@ -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 @@
 
 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);
 



Home | Main Index | Thread Index | Old Index