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 (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,327 +1,242 @@ @@ -1,327 +1,242 @@
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:
133 return "Reserved"; 48 return "Reserved";
134 case 1: 49 case 1:
135 return "Analog VGA"; 50 return "Analog VGA";
136 case 2: 51 case 2:
137 return "LVDS"; 52 return "LVDS";
138 case 3: 53 case 3:
139 return "Reserved"; 54 return "Reserved";
140 case 4: 55 case 4:
141 return "HDMI/DVI_B"; 56 return "HDMI/DVI_B";
142 case 5: 57 case 5:
143 return "HDMI/DVI_C"; 58 return "HDMI/DVI_C";
144 case 6: 59 case 6:
145 return "HDMI/DVI_D"; 60 return "HDMI/DVI_D";
146 case 7: 61 case 7:
147 return "DisplayPort_A"; 62 return "DisplayPort_A";
148 case 8: 63 case 8:
149 return "DisplayPort_B"; 64 return "DisplayPort_B";
150 case 9: 65 case 9:
151 return "DisplayPort_C"; 66 return "DisplayPort_C";
152 case 0xa: 67 case 0xa:
153 return "DisplayPort_D"; 68 return "DisplayPort_D";
154 case 0xb: 69 case 0xb:
155 case 0xc: 70 case 0xc:
156 case 0xd: 71 case 0xd:
157 return "Reserved"; 72 return "Reserved";
158 case 0xe: 73 case 0xe:
159 return "WiDi"; 74 return "WiDi";
160 default: 75 default:
161 return "bad type"; 76 return "bad type";
162 } 77 }
163} 78}
164 79
165static const char *intel_dsm_mux_type(u8 type) 80static const char *intel_dsm_mux_type(u8 type)
166{ 81{
167 switch (type) { 82 switch (type) {
168 case 0: 83 case 0:
169 return "unknown"; 84 return "unknown";
170 case 1: 85 case 1:
171 return "No MUX, iGPU only"; 86 return "No MUX, iGPU only";
172 case 2: 87 case 2:
173 return "No MUX, dGPU only"; 88 return "No MUX, dGPU only";
174 case 3: 89 case 3:
175 return "MUXed between iGPU and dGPU"; 90 return "MUXed between iGPU and dGPU";
176 default: 91 default:
177 return "bad type"; 92 return "bad type";
178 } 93 }
179} 94}
180 95
181static void intel_dsm_platform_mux_info(acpi_handle dhandle) 96static void intel_dsm_platform_mux_info(acpi_handle dhandle)
182{ 97{
183 int i; 98 int i;
184 union acpi_object *pkg, *connector_count; 99 union acpi_object *pkg, *connector_count;
185 100
186 pkg = acpi_evaluate_dsm_typed(dhandle, &intel_dsm_guid, 101 pkg = acpi_evaluate_dsm_typed(dhandle, &intel_dsm_guid,
187 INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO, 102 INTEL_DSM_REVISION_ID, INTEL_DSM_FN_PLATFORM_MUX_INFO,
188 NULL, ACPI_TYPE_PACKAGE); 103 NULL, ACPI_TYPE_PACKAGE);
189 if (!pkg) { 104 if (!pkg) {
190 DRM_DEBUG_DRIVER("failed to evaluate _DSM\n"); 105 DRM_DEBUG_DRIVER("failed to evaluate _DSM\n");
191 return; 106 return;
192 } 107 }
193 108
194 connector_count = &pkg->package.elements[0]; 109 connector_count = &pkg->package.elements[0];
195 DRM_DEBUG_DRIVER("MUX info connectors: %lld\n", 110 DRM_DEBUG_DRIVER("MUX info connectors: %lld\n",
196 (unsigned long long)connector_count->integer.value); 111 (unsigned long long)connector_count->integer.value);
197 for (i = 1; i < pkg->package.count; i++) { 112 for (i = 1; i < pkg->package.count; i++) {
198 union acpi_object *obj = &pkg->package.elements[i]; 113 union acpi_object *obj = &pkg->package.elements[i];
199 union acpi_object *connector_id = &obj->package.elements[0]; 114 union acpi_object *connector_id = &obj->package.elements[0];
200 union acpi_object *info = &obj->package.elements[1]; 115 union acpi_object *info = &obj->package.elements[1];
201 DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n", 116 DRM_DEBUG_DRIVER("Connector id: 0x%016llx\n",
202 (unsigned long long)connector_id->integer.value); 117 (unsigned long long)connector_id->integer.value);
203 DRM_DEBUG_DRIVER(" port id: %s\n", 118 DRM_DEBUG_DRIVER(" port id: %s\n",
204 intel_dsm_port_name(info->buffer.pointer[0])); 119 intel_dsm_port_name(info->buffer.pointer[0]));
205 DRM_DEBUG_DRIVER(" display mux info: %s\n", 120 DRM_DEBUG_DRIVER(" display mux info: %s\n",
206 intel_dsm_mux_type(info->buffer.pointer[1])); 121 intel_dsm_mux_type(info->buffer.pointer[1]));
207 DRM_DEBUG_DRIVER(" aux/dc mux info: %s\n", 122 DRM_DEBUG_DRIVER(" aux/dc mux info: %s\n",
208 intel_dsm_mux_type(info->buffer.pointer[2])); 123 intel_dsm_mux_type(info->buffer.pointer[2]));
209 DRM_DEBUG_DRIVER(" hpd mux info: %s\n", 124 DRM_DEBUG_DRIVER(" hpd mux info: %s\n",
210 intel_dsm_mux_type(info->buffer.pointer[3])); 125 intel_dsm_mux_type(info->buffer.pointer[3]));
211 } 126 }
212 127
213 ACPI_FREE(pkg); 128 ACPI_FREE(pkg);
214} 129}
215 130
216#ifdef __NetBSD__ 131#ifdef __NetBSD__
217static ACPI_HANDLE intel_dsm_pci_probe(ACPI_HANDLE dhandle) 132static ACPI_HANDLE intel_dsm_pci_probe(ACPI_HANDLE dhandle)
218#else 133#else
219static acpi_handle intel_dsm_pci_probe(struct pci_dev *pdev) 134static acpi_handle intel_dsm_pci_probe(struct pci_dev *pdev)
220#endif 135#endif
221{ 136{
222#ifndef __NetBSD__ 137#ifndef __NetBSD__
223 acpi_handle dhandle; 138 acpi_handle dhandle;
224 139
225 dhandle = ACPI_HANDLE(&pdev->dev); 140 dhandle = ACPI_HANDLE(&pdev->dev);
226 if (!dhandle) 141 if (!dhandle)
227 return NULL; 142 return NULL;
228#endif 143#endif
229 144
230 if (!acpi_check_dsm(dhandle, &intel_dsm_guid, INTEL_DSM_REVISION_ID, 145 if (!acpi_check_dsm(dhandle, &intel_dsm_guid, INTEL_DSM_REVISION_ID,
231 1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) { 146 1 << INTEL_DSM_FN_PLATFORM_MUX_INFO)) {
232 DRM_DEBUG_KMS("no _DSM method for intel device\n"); 147 DRM_DEBUG_KMS("no _DSM method for intel device\n");
233 return NULL; 148 return NULL;
234 } 149 }
235 150
236 intel_dsm_platform_mux_info(dhandle); 151 intel_dsm_platform_mux_info(dhandle);
237 152
238 return dhandle; 153 return dhandle;
239} 154}
240 155
241#ifdef __NetBSD__ 156#ifdef __NetBSD__
242 157
243static int vga_count; 158static int vga_count;
244static ACPI_HANDLE intel_dsm_handle; 159static ACPI_HANDLE intel_dsm_handle;
245 160
246/* XXX from sys/dev/pci/vga_pcivar.h */ 161/* XXX from sys/dev/pci/vga_pcivar.h */
247#define DEVICE_IS_VGA_PCI(class, id) \ 162#define DEVICE_IS_VGA_PCI(class, id) \
248 (((PCI_CLASS(class) == PCI_CLASS_DISPLAY && \ 163 (((PCI_CLASS(class) == PCI_CLASS_DISPLAY && \
249 PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_VGA) || \ 164 PCI_SUBCLASS(class) == PCI_SUBCLASS_DISPLAY_VGA) || \
250 (PCI_CLASS(class) == PCI_CLASS_PREHISTORIC && \ 165 (PCI_CLASS(class) == PCI_CLASS_PREHISTORIC && \
251 PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA)) ? 1 : 0) 166 PCI_SUBCLASS(class) == PCI_SUBCLASS_PREHISTORIC_VGA)) ? 1 : 0)
252 167
253static int 168static int
254intel_dsm_vga_match(const struct pci_attach_args *pa) 169intel_dsm_vga_match(const struct pci_attach_args *pa)
255{ 170{
256 171
257 if (!DEVICE_IS_VGA_PCI(pa->pa_class, pa->pa_id)) 172 if (!DEVICE_IS_VGA_PCI(pa->pa_class, pa->pa_id))
258 return 0; 173 return 0;
259 174
260 vga_count++; 175 vga_count++;
261 struct acpi_devnode *node = 176 struct acpi_devnode *node =
262 acpi_pcidev_find(pci_get_segment(pa->pa_pc), 177 acpi_pcidev_find(pci_get_segment(pa->pa_pc),
263 pa->pa_bus, pa->pa_device, pa->pa_function); 178 pa->pa_bus, pa->pa_device, pa->pa_function);
264 if (node != NULL && intel_dsm_handle == NULL) 179 if (node != NULL && intel_dsm_handle == NULL)
265 intel_dsm_handle = intel_dsm_pci_probe(node->ad_handle); 180 intel_dsm_handle = intel_dsm_pci_probe(node->ad_handle);
266 return 0; 181 return 0;
267} 182}
268 183
269static bool intel_dsm_detect(struct drm_device *dev) 184static bool intel_dsm_detect(struct drm_device *dev)
270{ 185{
271 char acpi_method_name[255] = { 0 }; 186 char acpi_method_name[255] = { 0 };
272 187
273 vga_count = 0; 188 vga_count = 0;
274 pci_find_device(&dev->pdev->pd_pa, intel_dsm_vga_match); 189 pci_find_device(&dev->pdev->pd_pa, intel_dsm_vga_match);
275 190
276 if (vga_count == 2 && intel_dsm_handle) { 191 if (vga_count == 2 && intel_dsm_handle) {
277 const char *name = acpi_name(intel_dsm_handle); 192 const char *name = acpi_name(intel_dsm_handle);
278 strlcpy(acpi_method_name, name, sizeof(acpi_method_name)); 193 strlcpy(acpi_method_name, name, sizeof(acpi_method_name));
279 DRM_DEBUG_DRIVER("VGA switcheroo: detected DSM switching method %s handle\n", 194 DRM_DEBUG_DRIVER("VGA switcheroo: detected DSM switching method %s handle\n",
280 acpi_method_name); 195 acpi_method_name);
281 return true; 196 return true;
282 } 197 }
283 198
284 return false; 199 return false;
285} 200}
286#else 201#else
287static bool intel_dsm_detect(void) 202static bool intel_dsm_detect(void)
288{ 203{
289 acpi_handle dhandle = NULL; 204 acpi_handle dhandle = NULL;
290 char acpi_method_name[255] = { 0 }; 205 char acpi_method_name[255] = { 0 };
291 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name}; 206 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
292 struct pci_dev *pdev = NULL; 207 struct pci_dev *pdev = NULL;
293 int vga_count = 0; 208 int vga_count = 0;
294 209
295 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) { 210 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
296 vga_count++; 211 vga_count++;
297 dhandle = intel_dsm_pci_probe(pdev) ?: dhandle; 212 dhandle = intel_dsm_pci_probe(pdev) ?: dhandle;
298 } 213 }
299 214
300 if (vga_count == 2 && dhandle) { 215 if (vga_count == 2 && dhandle) {
301 acpi_get_name(dhandle, ACPI_FULL_PATHNAME, &buffer); 216 acpi_get_name(dhandle, ACPI_FULL_PATHNAME, &buffer);
302 DRM_DEBUG_DRIVER("vga_switcheroo: detected DSM switching method %s handle\n", 217 DRM_DEBUG_DRIVER("vga_switcheroo: detected DSM switching method %s handle\n",
303 acpi_method_name); 218 acpi_method_name);
304 return true; 219 return true;
305 } 220 }
306 221
307 return false; 222 return false;
308} 223}
309#endif 224#endif
310 225
311#ifdef __NetBSD__ 226#ifdef __NetBSD__
312void intel_register_dsm_handler(struct drm_i915_private *i915) 227void intel_register_dsm_handler(struct drm_i915_private *i915)
313{ 228{
314 if (!intel_dsm_detect(&i915->drm)) 229 if (!intel_dsm_detect(&i915->drm))
315 return; 230 return;
316} 231}
317#else 232#else
318void intel_register_dsm_handler(void) 233void intel_register_dsm_handler(void)
319{ 234{
320 if (!intel_dsm_detect()) 235 if (!intel_dsm_detect())
321 return; 236 return;
322} 237}
323#endif 238#endif
324 239
325void intel_unregister_dsm_handler(void) 240void intel_unregister_dsm_handler(void)
326{ 241{
327} 242}

cvs diff -r1.6 -r1.7 src/sys/external/bsd/drm2/include/linux/acpi.h (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,49 +1,64 @@ @@ -1,49 +1,64 @@
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.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#ifndef _LINUX_ACPI_H_ 32#ifndef _LINUX_ACPI_H_
33#define _LINUX_ACPI_H_ 33#define _LINUX_ACPI_H_
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 (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,36 +1,37 @@ @@ -1,36 +1,37 @@
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
21file external/bsd/drm2/linux/linux_irq_work.c drmkms_linux 22file external/bsd/drm2/linux/linux_irq_work.c drmkms_linux
22file external/bsd/drm2/linux/linux_kmap.c drmkms_linux 23file external/bsd/drm2/linux/linux_kmap.c drmkms_linux
23file external/bsd/drm2/linux/linux_kthread.c drmkms_linux 24file external/bsd/drm2/linux/linux_kthread.c drmkms_linux
24file external/bsd/drm2/linux/linux_list_sort.c drmkms_linux 25file external/bsd/drm2/linux/linux_list_sort.c drmkms_linux
25file external/bsd/drm2/linux/linux_module.c drmkms_linux 26file external/bsd/drm2/linux/linux_module.c drmkms_linux
26file external/bsd/drm2/linux/linux_notifier.c drmkms_linux 27file external/bsd/drm2/linux/linux_notifier.c drmkms_linux
27file external/bsd/drm2/linux/linux_pci.c drmkms_linux 28file external/bsd/drm2/linux/linux_pci.c drmkms_linux
28file external/bsd/drm2/linux/linux_radixtree.c drmkms_linux 29file external/bsd/drm2/linux/linux_radixtree.c drmkms_linux
29file external/bsd/drm2/linux/linux_rwsem.c drmkms_linux 30file external/bsd/drm2/linux/linux_rwsem.c drmkms_linux
30file external/bsd/drm2/linux/linux_sgt.c drmkms_linux 31file external/bsd/drm2/linux/linux_sgt.c drmkms_linux
31file external/bsd/drm2/linux/linux_stop_machine.c drmkms_linux 32file external/bsd/drm2/linux/linux_stop_machine.c drmkms_linux
32file external/bsd/drm2/linux/linux_sync_file.c drmkms_linux 33file external/bsd/drm2/linux/linux_sync_file.c drmkms_linux
33file external/bsd/drm2/linux/linux_wait_bit.c drmkms_linux 34file external/bsd/drm2/linux/linux_wait_bit.c drmkms_linux
34file external/bsd/drm2/linux/linux_writecomb.c drmkms_linux 35file external/bsd/drm2/linux/linux_writecomb.c drmkms_linux
35file external/bsd/drm2/linux/linux_ww_mutex.c drmkms_linux 36file external/bsd/drm2/linux/linux_ww_mutex.c drmkms_linux
36file external/bsd/drm2/linux/linux_xa.c drmkms_linux 37file external/bsd/drm2/linux/linux_xa.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;
}