1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
3 *
4 * Copyright (c) 2017 Mark Johnston <markj@FreeBSD.org>
5 * Copyright (c) 2020 Vladimir Kondratyev <wulf@FreeBSD.org>
6 * Copyright (c) 2025 The FreeBSD Foundation
7 *
8 * Portions of this software were developed by Björn Zeeb
9 * under sponsorship from the FreeBSD Foundation.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are
13 * met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #ifndef _LINUXKPI_ACPI_ACPI_H_
35 #define _LINUXKPI_ACPI_ACPI_H_
36
37 /*
38 * LINUXKPI_WANT_LINUX_ACPI is a temporary workaround to allow drm-kmod
39 * to update all needed branches without breaking builds.
40 * Once that happened and checks are implemented based on __FreeBSD_verison
41 * we will remove these conditions again.
42 */
43
44 /*
45 * FreeBSD import of ACPICA has a typedef for BOOLEAN which conflicts with
46 * amdgpu driver. Workaround it on preprocessor level.
47 */
48 #define ACPI_USE_SYSTEM_INTTYPES
49 #define BOOLEAN unsigned char
50 typedef unsigned char UINT8;
51 typedef unsigned short UINT16;
52 typedef short INT16;
53 typedef unsigned int UINT32;
54 typedef int INT32;
55 typedef uint64_t UINT64;
56 typedef int64_t INT64;
57 #include <contrib/dev/acpica/include/acpi.h>
58 #undef BOOLEAN
59
60 typedef ACPI_IO_ADDRESS acpi_io_address;
61 typedef ACPI_HANDLE acpi_handle;
62 typedef ACPI_OBJECT_HANDLER acpi_object_handler;
63 typedef ACPI_OBJECT_TYPE acpi_object_type;
64 typedef ACPI_STATUS acpi_status;
65 typedef ACPI_STRING acpi_string;
66 typedef ACPI_SIZE acpi_size;
67 typedef ACPI_WALK_CALLBACK acpi_walk_callback;
68
69 union linuxkpi_acpi_object {
70 acpi_object_type type;
71 struct {
72 acpi_object_type type;
73 UINT64 value;
74 } integer;
75 struct {
76 acpi_object_type type;
77 UINT32 length;
78 char *pointer;
79 } string;
80 struct {
81 acpi_object_type type;
82 UINT32 length;
83 UINT8 *pointer;
84 } buffer;
85 struct {
86 acpi_object_type type;
87 UINT32 count;
88 union linuxkpi_acpi_object *elements;
89 } package;
90 struct {
91 acpi_object_type type;
92 acpi_object_type actual_type;
93 acpi_handle handle;
94 } reference;
95 struct {
96 acpi_object_type type;
97 UINT32 proc_id;
98 acpi_io_address pblk_address;
99 UINT32 pblk_length;
100 } processor;
101 struct {
102 acpi_object_type type;
103 UINT32 system_level;
104 UINT32 resource_order;
105 } power_resource;
106 };
107
108 #ifdef LINUXKPI_WANT_LINUX_ACPI
109 struct linuxkpi_acpi_buffer {
110 acpi_size length; /* Length in bytes of the buffer */
111 void *pointer; /* pointer to buffer */
112 };
113
114 typedef struct linuxkpi_acpi_buffer lkpi_acpi_buffer_t;
115 #else
116 typedef ACPI_BUFFER lkpi_acpi_buffer_t;
117 #endif
118
119 static inline ACPI_STATUS
acpi_evaluate_object(ACPI_HANDLE Object,ACPI_STRING Pathname,ACPI_OBJECT_LIST * ParameterObjects,lkpi_acpi_buffer_t * ReturnObjectBuffer)120 acpi_evaluate_object(ACPI_HANDLE Object, ACPI_STRING Pathname,
121 ACPI_OBJECT_LIST *ParameterObjects, lkpi_acpi_buffer_t *ReturnObjectBuffer)
122 {
123 return (AcpiEvaluateObject(
124 Object, Pathname, ParameterObjects, (ACPI_BUFFER *)ReturnObjectBuffer));
125 }
126
127 static inline const char *
acpi_format_exception(ACPI_STATUS Exception)128 acpi_format_exception(ACPI_STATUS Exception)
129 {
130 return (AcpiFormatException(Exception));
131 }
132
133 static inline ACPI_STATUS
acpi_get_handle(ACPI_HANDLE Parent,ACPI_STRING Pathname,ACPI_HANDLE * RetHandle)134 acpi_get_handle(ACPI_HANDLE Parent, ACPI_STRING Pathname,
135 ACPI_HANDLE *RetHandle)
136 {
137 return (AcpiGetHandle(Parent, Pathname, RetHandle));
138 }
139
140 static inline ACPI_STATUS
acpi_get_data(ACPI_HANDLE ObjHandle,ACPI_OBJECT_HANDLER Handler,void ** Data)141 acpi_get_data(ACPI_HANDLE ObjHandle, ACPI_OBJECT_HANDLER Handler, void **Data)
142 {
143 return (AcpiGetData(ObjHandle, Handler, Data));
144 }
145
146 static inline ACPI_STATUS
acpi_get_name(ACPI_HANDLE Object,UINT32 NameType,lkpi_acpi_buffer_t * RetPathPtr)147 acpi_get_name(ACPI_HANDLE Object, UINT32 NameType, lkpi_acpi_buffer_t *RetPathPtr)
148 {
149 return (AcpiGetName(Object, NameType, (ACPI_BUFFER *)RetPathPtr));
150 }
151
152 static inline ACPI_STATUS
acpi_get_table(ACPI_STRING Signature,UINT32 Instance,ACPI_TABLE_HEADER ** OutTable)153 acpi_get_table(ACPI_STRING Signature, UINT32 Instance,
154 ACPI_TABLE_HEADER **OutTable)
155 {
156 return (AcpiGetTable(Signature, Instance, OutTable));
157 }
158
159 static inline void
acpi_put_table(ACPI_TABLE_HEADER * Table)160 acpi_put_table(ACPI_TABLE_HEADER *Table)
161 {
162 AcpiPutTable(Table);
163 }
164
165 #ifdef LINUXKPI_WANT_LINUX_ACPI
166 #define acpi_object linuxkpi_acpi_object
167 #define acpi_buffer linuxkpi_acpi_buffer
168 #endif
169
170 #endif /* _LINUXKPI_ACPI_ACPI_H_ */
171