Sun Feb 27 14:22:21 2022 UTC ()
drm: Move acpi_check_dsm &c. from intel_acpi.c to new linux_acpi.c.


(riastradh)
diff -r1.6 -r1.7 src/sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.c
diff -r1.6 -r1.7 src/sys/external/bsd/drm2/include/linux/acpi.h
diff -r1.40 -r1.41 src/sys/external/bsd/drm2/linux/files.drmkms_linux
diff -r0 -r1.1 src/sys/external/bsd/drm2/linux/linux_acpi.c

cvs diff -r1.6 -r1.7 src/sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.c (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.c 2022/02/27 14:20:30 1.6
+++ src/sys/external/bsd/drm2/dist/drm/i915/display/intel_acpi.c 2022/02/27 14:22:21 1.7
@@ -1,132 +1,47 @@ @@ -1,132 +1,47 @@
1/* $NetBSD: intel_acpi.c,v 1.6 2022/02/27 14:20:30 riastradh Exp $ */ 1/* $NetBSD: intel_acpi.c,v 1.7 2022/02/27 14:22:21 riastradh Exp $ */
2 2
3// SPDX-License-Identifier: GPL-2.0 3// SPDX-License-Identifier: GPL-2.0
4/* 4/*
5 * Intel ACPI functions 5 * Intel ACPI functions
6 * 6 *
7 * _DSM related code stolen from nouveau_acpi.c. 7 * _DSM related code stolen from nouveau_acpi.c.
8 */ 8 */
9 9
10#include <sys/cdefs.h> 10#include <sys/cdefs.h>
11__KERNEL_RCSID(0, "$NetBSD: intel_acpi.c,v 1.6 2022/02/27 14:20:30 riastradh Exp $"); 11__KERNEL_RCSID(0, "$NetBSD: intel_acpi.c,v 1.7 2022/02/27 14:22:21 riastradh Exp $");
12 12
13#include <linux/pci.h> 13#include <linux/pci.h>
14#include <linux/acpi.h> 14#include <linux/acpi.h>
15 15
16#include "i915_drv.h" 16#include "i915_drv.h"
17#include "intel_acpi.h" 17#include "intel_acpi.h"
18 18
19#ifdef __NetBSD__ 19#ifdef __NetBSD__
20 20
21#include <dev/acpi/acpireg.h> 21#include <dev/acpi/acpireg.h>
22#define _COMPONENT ACPI_BUTTON_COMPONENT 22#define _COMPONENT ACPI_BUTTON_COMPONENT
23ACPI_MODULE_NAME("acpi_intel_brightness") 23ACPI_MODULE_NAME("acpi_intel_brightness")
24 24
25#include <dev/acpi/acpi_pci.h> 25#include <dev/acpi/acpi_pci.h>
26 26
27#define acpi_handle ACPI_HANDLE 27#define acpi_handle ACPI_HANDLE
28#define buffer Buffer 28#define buffer Buffer
29#define count Count 29#define count Count
30#define elements Elements 30#define elements Elements
31#define integer Integer 31#define integer Integer
32#define package Package 32#define package Package
33#define pointer Pointer 33#define pointer Pointer
34#define value Value 34#define value Value
35 
36static ACPI_OBJECT * 
37acpi_evaluate_dsm(ACPI_HANDLE handle, const guid_t *uuid, int rev, int func, 
38 ACPI_OBJECT *argv4) 
39{ 
40 ACPI_OBJECT_LIST arg; 
41 ACPI_OBJECT params[4]; 
42 ACPI_BUFFER buf; 
43 ACPI_STATUS rv; 
44 
45 if (handle == NULL) 
46 handle = ACPI_ROOT_OBJECT; 
47 
48 arg.Count = 4; 
49 arg.Pointer = params; 
50 params[0].Type = ACPI_TYPE_BUFFER; 
51 params[0].Buffer.Length = 16; 
52 params[0].Buffer.Pointer = (char *)__UNCONST(uuid); 
53 params[1].Type = ACPI_TYPE_INTEGER; 
54 params[1].Integer.Value = rev; 
55 params[2].Type = ACPI_TYPE_INTEGER; 
56 params[2].Integer.Value = func; 
57 if (argv4 != NULL) { 
58 params[3] = *argv4; 
59 } else { 
60 params[3].Type = ACPI_TYPE_PACKAGE; 
61 params[3].Package.Count = 0; 
62 params[3].Package.Elements = NULL; 
63 } 
64 
65 buf.Pointer = NULL; 
66 buf.Length = ACPI_ALLOCATE_LOCAL_BUFFER; 
67 
68 rv = AcpiEvaluateObject(handle, "_DSM", &arg, &buf); 
69 if (ACPI_SUCCESS(rv)) 
70 return (ACPI_OBJECT *)buf.Pointer; 
71 return NULL; 
72} 
73 
74static inline ACPI_OBJECT * 
75acpi_evaluate_dsm_typed(ACPI_HANDLE handle, const guid_t *uuid, int rev, 
76 int func, ACPI_OBJECT *argv4, ACPI_OBJECT_TYPE type) 
77{ 
78 ACPI_OBJECT *obj; 
79 
80 obj = acpi_evaluate_dsm(handle, uuid, rev, func, argv4); 
81 if (obj != NULL && obj->Type != type) { 
82 ACPI_FREE(obj); 
83 obj = NULL; 
84 } 
85 return obj; 
86} 
87 
88#define ACPI_INIT_DSM_ARGV4(cnt, eles) \ 
89{ \ 
90 .Package.Type = ACPI_TYPE_PACKAGE, \ 
91 .Package.Count = (cnt), \ 
92 .Package.Elements = (eles) \ 
93} 
94 
95static bool 
96acpi_check_dsm(ACPI_HANDLE handle, const guid_t *uuid, int rev, uint64_t funcs) 
97{ 
98 ACPI_OBJECT *obj; 
99 uint64_t mask = 0; 
100 int i; 
101 
102 if (funcs == 0) 
103 return false; 
104 
105 obj = acpi_evaluate_dsm(handle, uuid, rev, 0, NULL); 
106 if (obj == NULL) 
107 return false; 
108 
109 if (obj->Type == ACPI_TYPE_INTEGER) 
110 mask = obj->Integer.Value; 
111 else if (obj->Type == ACPI_TYPE_BUFFER) 
112 for (i = 0; i < obj->Buffer.Length && i < 8; i++) 
113 mask |= (uint64_t)obj->Buffer.Pointer[i] << (i * 8); 
114 ACPI_FREE(obj); 
115 
116 if ((mask & 0x1) == 0x1 && (mask & funcs) == funcs) 
117 return true; 
118 return false; 
119} 
120#endif 35#endif
121 36
122#define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */ 37#define INTEL_DSM_REVISION_ID 1 /* For Calpella anyway... */
123#define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */ 38#define INTEL_DSM_FN_PLATFORM_MUX_INFO 1 /* No args */
124 39
125static const guid_t intel_dsm_guid = 40static const guid_t intel_dsm_guid =
126 GUID_INIT(0x7ed873d3, 0xc2d0, 0x4e4f, 41 GUID_INIT(0x7ed873d3, 0xc2d0, 0x4e4f,
127 0xa8, 0x54, 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c); 42 0xa8, 0x54, 0x0f, 0x13, 0x17, 0xb0, 0x1c, 0x2c);
128 43
129static const char *intel_dsm_port_name(u8 id) 44static const char *intel_dsm_port_name(u8 id)
130{ 45{
131 switch (id) { 46 switch (id) {
132 case 0: 47 case 0:

cvs diff -r1.6 -r1.7 src/sys/external/bsd/drm2/include/linux/acpi.h (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/include/linux/acpi.h 2021/12/19 11:38:04 1.6
+++ src/sys/external/bsd/drm2/include/linux/acpi.h 2022/02/27 14:22:21 1.7
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: acpi.h,v 1.6 2021/12/19 11:38:04 riastradh Exp $ */ 1/* $NetBSD: acpi.h,v 1.7 2022/02/27 14:22:21 riastradh Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Taylor R. Campbell. 8 * by Taylor R. Campbell.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -34,16 +34,31 @@ @@ -34,16 +34,31 @@
34 34
35#ifdef _KERNEL_OPT 35#ifdef _KERNEL_OPT
36#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) 36#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__)
37#include "acpica.h" 37#include "acpica.h"
38#else 38#else
39#define NACPICA 0 39#define NACPICA 0
40#endif 40#endif
41#endif 41#endif
42 42
43#if NACPICA > 0 43#if NACPICA > 0
44#include <dev/acpi/acpivar.h> 44#include <dev/acpi/acpivar.h>
45#endif 45#endif
46 46
 47#include <linux/types.h>
47#include <linux/uuid.h> 48#include <linux/uuid.h>
48 49
 50typedef ACPI_HANDLE acpi_handle;
 51typedef ACPI_OBJECT_TYPE acpi_object_type;
 52typedef ACPI_STATUS acpi_status;
 53
 54#define acpi_evaluate_dsm linux_acpi_evaluate_dsm
 55#define acpi_evaluate_dsm_typed linux_acpi_evaluate_dsm_typed
 56#define acpi_check_dsm linux_acpi_check_dsm
 57
 58union acpi_object *acpi_evaluate_dsm(acpi_handle, const guid_t *,
 59 uint64_t, uint64_t, union acpi_object *);
 60union acpi_object *acpi_evaluate_dsm_typed(acpi_handle, const guid_t *,
 61 uint64_t, uint64_t, union acpi_object *, acpi_object_type);
 62bool acpi_check_dsm(acpi_handle, const guid_t *, uint64_t, uint64_t);
 63
49#endif /* _LINUX_ACPI_H_ */ 64#endif /* _LINUX_ACPI_H_ */

cvs diff -r1.40 -r1.41 src/sys/external/bsd/drm2/linux/files.drmkms_linux (expand / switch to unified diff)

--- src/sys/external/bsd/drm2/linux/files.drmkms_linux 2021/12/19 12:28:04 1.40
+++ src/sys/external/bsd/drm2/linux/files.drmkms_linux 2022/02/27 14:22:21 1.41
@@ -1,20 +1,21 @@ @@ -1,20 +1,21 @@
1# $NetBSD: files.drmkms_linux,v 1.40 2021/12/19 12:28:04 riastradh Exp $ 1# $NetBSD: files.drmkms_linux,v 1.41 2022/02/27 14:22:21 riastradh Exp $
2 2
3define drmkms_linux: i2cexec, i2c_bitbang 3define drmkms_linux: i2cexec, i2c_bitbang
4 4
5makeoptions drmkms_linux "CPPFLAGS.drmkms_linux"+="-I$S/external/bsd/common/include" 5makeoptions drmkms_linux "CPPFLAGS.drmkms_linux"+="-I$S/external/bsd/common/include"
6makeoptions drmkms_linux "CPPFLAGS.drmkms_linux"+="-I$S/external/bsd/drm2/include" 6makeoptions drmkms_linux "CPPFLAGS.drmkms_linux"+="-I$S/external/bsd/drm2/include"
7 7
 8file external/bsd/drm2/linux/linux_acpi.c drmkms_linux
8file external/bsd/drm2/linux/linux_atomic64.c drmkms_linux 9file external/bsd/drm2/linux/linux_atomic64.c drmkms_linux
9file external/bsd/drm2/linux/linux_backlight.c drmkms_linux 10file external/bsd/drm2/linux/linux_backlight.c drmkms_linux
10file external/bsd/drm2/linux/linux_dma_buf.c drmkms_linux 11file external/bsd/drm2/linux/linux_dma_buf.c drmkms_linux
11file external/bsd/drm2/linux/linux_dma_fence.c drmkms_linux 12file external/bsd/drm2/linux/linux_dma_fence.c drmkms_linux
12file external/bsd/drm2/linux/linux_dma_fence_array.c drmkms_linux 13file external/bsd/drm2/linux/linux_dma_fence_array.c drmkms_linux
13file external/bsd/drm2/linux/linux_dma_fence_chain.c drmkms_linux 14file external/bsd/drm2/linux/linux_dma_fence_chain.c drmkms_linux
14file external/bsd/drm2/linux/linux_dma_resv.c drmkms_linux 15file external/bsd/drm2/linux/linux_dma_resv.c drmkms_linux
15file external/bsd/drm2/linux/linux_dmi.c drmkms_linux 16file external/bsd/drm2/linux/linux_dmi.c drmkms_linux
16file external/bsd/drm2/linux/linux_firmware.c drmkms_linux 17file external/bsd/drm2/linux/linux_firmware.c drmkms_linux
17file external/bsd/drm2/linux/linux_hrtimer.c drmkms_linux 18file external/bsd/drm2/linux/linux_hrtimer.c drmkms_linux
18file external/bsd/drm2/linux/linux_i2c.c drmkms_linux 19file external/bsd/drm2/linux/linux_i2c.c drmkms_linux
19file external/bsd/drm2/linux/linux_idr.c drmkms_linux 20file external/bsd/drm2/linux/linux_idr.c drmkms_linux
20file external/bsd/drm2/linux/linux_io_mapping.c drmkms_linux 21file external/bsd/drm2/linux/linux_io_mapping.c drmkms_linux

File Added: src/sys/external/bsd/drm2/linux/linux_acpi.c
/*	$NetBSD: linux_acpi.c,v 1.1 2022/02/27 14:22:21 riastradh Exp $	*/

/*-
 * Copyright (c) 2022 The NetBSD Foundation, Inc.
 * 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.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: linux_acpi.c,v 1.1 2022/02/27 14:22:21 riastradh Exp $");

#include <linux/acpi.h>

union acpi_object *
acpi_evaluate_dsm(acpi_handle handle, const guid_t *uuid, u64 rev, u64 func,
    union 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;
}

union acpi_object *
acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *uuid, u64 rev,
    u64 func, union acpi_object *argv4, acpi_object_type type)
{
	union 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)		\
}

bool
acpi_check_dsm(acpi_handle handle, const guid_t *uuid, u64 rev, u64 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;
}