Source-Changes-HG archive

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

[src/trunk]: src/sys/external/bsd/drm2/dist/drm/i915 Restore local intel_acpi...



details:   https://anonhg.NetBSD.org/src/rev/ae86e9d81d99
branches:  trunk
changeset: 1028294:ae86e9d81d99
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 10:25:15 2021 +0000

description:
Restore local intel_acpi changes.

diffstat:

 sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.c |  174 ++++++++++++++-
 sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.h |   12 +-
 sys/external/bsd/drm2/dist/drm/i915/i915_drv.c           |    8 +-
 3 files changed, 189 insertions(+), 5 deletions(-)

diffs (truncated from 308 to 300 lines):

diff -r 9351344f5558 -r ae86e9d81d99 sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.c
--- a/sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.c  Sun Dec 19 10:25:07 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.c  Sun Dec 19 10:25:15 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intel_acpi.c,v 1.2 2021/12/18 23:45:29 riastradh Exp $ */
+/*     $NetBSD: intel_acpi.c,v 1.3 2021/12/19 10:25:15 riastradh Exp $ */
 
 // SPDX-License-Identifier: GPL-2.0
 /*
@@ -8,7 +8,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intel_acpi.c,v 1.2 2021/12/18 23:45:29 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intel_acpi.c,v 1.3 2021/12/19 10:25:15 riastradh Exp $");
 
 #include <linux/pci.h>
 #include <linux/acpi.h>
@@ -16,6 +16,105 @@
 #include "i915_drv.h"
 #include "intel_acpi.h"
 
+#ifdef __NetBSD__
+
+#include <dev/acpi/acpireg.h>
+#define _COMPONENT ACPI_BUTTON_COMPONENT
+ACPI_MODULE_NAME("acpi_intel_brightness")
+
+#define acpi_handle    ACPI_HANDLE
+#define        buffer          Buffer
+#define        elements        Elements
+#define        integer         Integer
+#define        package         Package
+#define        value           Value
+
+static ACPI_OBJECT *
+acpi_evaluate_dsm(ACPI_HANDLE handle, const uint8_t *uuid, int rev, int func,
+    ACPI_OBJECT *argv4)
+{
+       ACPI_OBJECT_LIST arg;
+       ACPI_OBJECT params[4];
+       ACPI_BUFFER buf;
+       ACPI_STATUS rv;
+
+       if (handle == NULL)
+               handle = ACPI_ROOT_OBJECT;
+
+       arg.Count = 4;
+       arg.Pointer = params;
+       params[0].Type = ACPI_TYPE_BUFFER;
+       params[0].Buffer.Length = 16;
+       params[0].Buffer.Pointer = (char *)__UNCONST(uuid);
+       params[1].Type = ACPI_TYPE_INTEGER;
+       params[1].Integer.Value = rev;
+       params[2].Type = ACPI_TYPE_INTEGER;
+       params[2].Integer.Value = func;
+       if (argv4 != NULL) {
+               params[3] = *argv4;
+       } else {
+               params[3].Type = ACPI_TYPE_PACKAGE;
+               params[3].Package.Count = 0;
+               params[3].Package.Elements = NULL;
+       }
+
+       buf.Pointer = NULL;
+       buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
+
+       rv = AcpiEvaluateObject(handle, "_DSM", &arg, &buf);
+       if (ACPI_SUCCESS(rv))
+               return (ACPI_OBJECT *)buf.Pointer;
+       return NULL;
+}
+
+static inline ACPI_OBJECT *
+acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const uint8_t *uuid, int rev,
+    int func, ACPI_OBJECT *argv4, ACPI_OBJECT_TYPE type)
+{
+       ACPI_OBJECT *obj;
+
+       obj = acpi_evaluate_dsm(handle, uuid, rev, func, argv4);
+       if (obj != NULL && obj->Type != type) {
+               ACPI_FREE(obj);
+               obj = NULL;
+       }
+       return obj;
+}
+
+#define        ACPI_INIT_DSM_ARGV4(cnt, eles)          \
+{                                              \
+       .Package.Type = ACPI_TYPE_PACKAGE,      \
+       .Package.Count = (cnt),                 \
+       .Package.Elements = (eles)              \
+}
+
+static bool
+acpi_check_dsm(ACPI_HANDLE handle, const uint8_t *uuid, int rev, uint64_t funcs)
+{
+       ACPI_OBJECT *obj;
+       uint64_t mask = 0;
+       int i;
+
+       if (funcs == 0)
+               return false;
+
+       obj = acpi_evaluate_dsm(handle, uuid, rev, 0, NULL);
+       if (obj == NULL)
+               return false;
+
+       if (obj->Type == ACPI_TYPE_INTEGER)
+               mask = obj->Integer.Value;
+       else if (obj->Type == ACPI_TYPE_BUFFER)
+               for (i = 0; i < obj->Buffer.Length && i < 8; i++)
+                       mask |= (uint64_t)obj->Buffer.Pointer[i] << (i * 8);
+       ACPI_FREE(obj);
+
+       if ((mask & 0x1) == 0x1 && (mask & funcs) == funcs)
+               return true;
+       return false;
+}
+#endif
+
 #define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */
 #define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */
 
@@ -78,7 +177,11 @@
 static void intel_dsm_platform_mux_info(acpi_handle dhandle)
 {
        int i;
+#ifdef __NetBSD__
+       ACPI_OBJECT *pkg, *connector_count;
+#else
        union acpi_object *pkg, *connector_count;
+#endif
 
        pkg = acpi_evaluate_dsm_typed(dhandle, &intel_dsm_guid,
                        INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO,
@@ -92,9 +195,15 @@
        DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
                  (unsigned long long)connector_count->integer.value);
        for (i = 1; i < pkg->package.count; i++) {
+#ifdef __NetBSD__
+               ACPI_OBJECT *obj = &pkg->package.elements[i];
+               ACPI_OBJECT *connector_id = &obj->package.elements[0];
+               ACPI_OBJECT *info = &obj->package.elements[1];
+#else
                union acpi_object *obj = &pkg->package.elements[i];
                union acpi_object *connector_id = &obj->package.elements[0];
                union acpi_object *info = &obj->package.elements[1];
+#endif
                DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
                          (unsigned long long)connector_id->integer.value);
                DRM_DEBUG_DRIVER("  port id: %s\n",
@@ -110,13 +219,19 @@
        ACPI_FREE(pkg);
 }
 
+#ifdef __NetBSD__
+static bool intel_dsm_pci_probe(ACPI_HANDLE dhandle)
+#else
 static acpi_handle intel_dsm_pci_probe(struct pci_dev *pdev)
+#endif
 {
+#ifndef __NetBSD__
        acpi_handle dhandle;
 
        dhandle = ACPI_HANDLE(&pdev->dev);
        if (!dhandle)
                return NULL;
+#endif
 
        if (!acpi_check_dsm(dhandle, &intel_dsm_guid, INTEL_DSM_REVISION_ID,
                            1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) {
@@ -129,6 +244,52 @@
        return dhandle;
 }
 
+#ifdef __NetBSD__
+
+static int vga_count;
+static bool has_dsm;
+
+/* XXX from sys/dev/pci/vga_pcivar.h */
+#define        DEVICE_IS_VGA_PCI(class, id)                                    \
+           (((PCI_CLASS(class) == PCI_CLASS_DISPLAY &&                 \
+             PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_VGA) ||       \
+            (PCI_CLASS(class) == PCI_CLASS_PREHISTORIC &&              \
+             PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA)) ? 1 : 0)
+
+static int
+intel_dsm_vga_match(const struct pci_attach_args *pa)
+{
+
+       if (!DEVICE_IS_VGA_PCI(pa->pa_class, pa->pa_id))
+               return 0;
+
+       vga_count++;
+       struct acpi_devnode *node = acpi_pcidev_find(0 /*XXX segment*/,
+           pa->pa_bus, pa->pa_device, pa->pa_function);
+       if (node != NULL)
+               has_dsm |= intel_dsm_pci_probe(node->ad_handle);
+       return 0;
+}
+
+static bool intel_dsm_detect(struct drm_device *dev)
+{
+       char acpi_method_name[255] = { 0 };
+
+       vga_count = 0;
+       has_dsm = false;
+       pci_find_device(&dev->pdev->pd_pa, intel_dsm_vga_match);
+
+       if (vga_count == 2 && has_dsm) {
+               const char *name = acpi_name(intel_dsm_priv.dhandle);
+               strlcpy(acpi_method_name, name, sizeof(acpi_method_name));
+               DRM_DEBUG_DRIVER("VGA switcheroo: detected DSM switching method %s handle\n",
+                                acpi_method_name);
+               return true;
+       }
+
+       return false;
+}
+#else
 static bool intel_dsm_detect(void)
 {
        acpi_handle dhandle = NULL;
@@ -151,12 +312,21 @@
 
        return false;
 }
+#endif
 
+#ifdef __NetBSD__
+void intel_register_dsm_handler(struct drm_i915_private *i915)
+{
+       if (!intel_dsm_detect(i915->base.pdev))
+               return;
+}
+#else
 void intel_register_dsm_handler(void)
 {
        if (!intel_dsm_detect())
                return;
 }
+#endif
 
 void intel_unregister_dsm_handler(void)
 {
diff -r 9351344f5558 -r ae86e9d81d99 sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.h
--- a/sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.h  Sun Dec 19 10:25:07 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.h  Sun Dec 19 10:25:15 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intel_acpi.h,v 1.2 2021/12/18 23:45:29 riastradh Exp $ */
+/*     $NetBSD: intel_acpi.h,v 1.3 2021/12/19 10:25:15 riastradh Exp $ */
 
 /* SPDX-License-Identifier: MIT */
 /*
@@ -8,11 +8,21 @@
 #ifndef __INTEL_ACPI_H__
 #define __INTEL_ACPI_H__
 
+struct drm_i915_private;
+
 #ifdef CONFIG_ACPI
+#ifdef __NetBSD__
+void intel_register_dsm_handler(struct drm_i915_private *);
+#else
 void intel_register_dsm_handler(void);
+#endif
 void intel_unregister_dsm_handler(void);
 #else
+#ifdef __NetBSD__
+static inline void intel_register_dsm_handler(struct drm_i915_private *) { return; }
+#else
 static inline void intel_register_dsm_handler(void) { return; }
+#endif
 static inline void intel_unregister_dsm_handler(void) { return; }
 #endif /* CONFIG_ACPI */
 
diff -r 9351344f5558 -r ae86e9d81d99 sys/external/bsd/drm2/dist/drm/i915/i915_drv.c
--- a/sys/external/bsd/drm2/dist/drm/i915/i915_drv.c    Sun Dec 19 10:25:07 2021 +0000
+++ b/sys/external/bsd/drm2/dist/drm/i915/i915_drv.c    Sun Dec 19 10:25:15 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: i915_drv.c,v 1.23 2021/12/19 10:25:00 riastradh Exp $  */
+/*     $NetBSD: i915_drv.c,v 1.24 2021/12/19 10:25:15 riastradh Exp $  */
 
 /* i915_drv.c -- i830,i845,i855,i865,i915 driver -*- linux-c -*-
  */
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i915_drv.c,v 1.23 2021/12/19 10:25:00 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i915_drv.c,v 1.24 2021/12/19 10:25:15 riastradh Exp $");
 
 #include <linux/acpi.h>
 #include <linux/device.h>
@@ -308,7 +308,11 @@
                goto out;
 #endif
 



Home | Main Index | Thread Index | Old Index