blob: 7a5be515ccfe0d217cd95905d71647a645f04cb2 [file] [log] [blame]
Furquan Shaikhe0844632020-05-02 10:23:37 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Furquan Shaikhe0844632020-05-02 10:23:37 -07002
Furquan Shaikh56eafbb2020-04-30 18:38:55 -07003#ifndef __ACPI_ACPIGEN_H__
4#define __ACPI_ACPIGEN_H__
Furquan Shaikhe0844632020-05-02 10:23:37 -07005
Elyes HAOUAS5817c562020-07-12 09:03:22 +02006#include <stddef.h>
Furquan Shaikhe0844632020-05-02 10:23:37 -07007#include <stdint.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07008#include <acpi/acpi.h>
9#include <acpi/acpi_device.h>
10#include <acpi/acpi_pld.h>
Furquan Shaikhe0844632020-05-02 10:23:37 -070011#include <device/pci_type.h>
12
13/* Values that can be returned for ACPI Device _STA method */
14#define ACPI_STATUS_DEVICE_PRESENT (1 << 0)
15#define ACPI_STATUS_DEVICE_ENABLED (1 << 1)
16#define ACPI_STATUS_DEVICE_SHOW_IN_UI (1 << 2)
17#define ACPI_STATUS_DEVICE_STATE_OK (1 << 3)
18
19#define ACPI_STATUS_DEVICE_ALL_OFF 0
20#define ACPI_STATUS_DEVICE_ALL_ON (ACPI_STATUS_DEVICE_PRESENT |\
21 ACPI_STATUS_DEVICE_ENABLED |\
22 ACPI_STATUS_DEVICE_SHOW_IN_UI |\
23 ACPI_STATUS_DEVICE_STATE_OK)
24#define ACPI_STATUS_DEVICE_HIDDEN_ON (ACPI_STATUS_DEVICE_PRESENT |\
25 ACPI_STATUS_DEVICE_ENABLED |\
26 ACPI_STATUS_DEVICE_STATE_OK)
27
28/* ACPI Op/Prefix Codes */
29enum {
30 ZERO_OP = 0x00,
31 ONE_OP = 0x01,
32 ALIAS_OP = 0x06,
33 NAME_OP = 0x08,
34 BYTE_PREFIX = 0x0A,
35 WORD_PREFIX = 0x0B,
36 DWORD_PREFIX = 0x0C,
37 STRING_PREFIX = 0x0D,
38 QWORD_PREFIX = 0x0E,
39 SCOPE_OP = 0x10,
40 BUFFER_OP = 0x11,
41 PACKAGE_OP = 0x12,
42 VARIABLE_PACKAGE_OP = 0x13,
43 METHOD_OP = 0x14,
44 EXTERNAL_OP = 0x15,
45 DUAL_NAME_PREFIX = 0x2E,
46 MULTI_NAME_PREFIX = 0x2F,
47 EXT_OP_PREFIX = 0x5B,
48 MUTEX_OP = 0x01,
Elyes Haouasb2d5e462023-02-07 13:03:09 +010049 EVENT_OP = 0x02,
Furquan Shaikhe0844632020-05-02 10:23:37 -070050 SF_RIGHT_OP = 0x10,
51 SF_LEFT_OP = 0x11,
52 COND_REFOF_OP = 0x12,
53 CREATEFIELD_OP = 0x13,
54 LOAD_TABLE_OP = 0x1f,
55 LOAD_OP = 0x20,
56 STALL_OP = 0x21,
57 SLEEP_OP = 0x22,
58 ACQUIRE_OP = 0x23,
59 SIGNAL_OP = 0x24,
60 WAIT_OP = 0x25,
61 RST_OP = 0x26,
62 RELEASE_OP = 0x27,
63 FROM_BCD_OP = 0x28,
64 TO_BCD_OP = 0x29,
65 UNLOAD_OP = 0x2A,
66 REVISON_OP = 0x30,
67 DEBUG_OP = 0x31,
68 FATAL_OP = 0x32,
69 TIMER_OP = 0x33,
70 OPREGION_OP = 0x80,
71 FIELD_OP = 0x81,
72 DEVICE_OP = 0x82,
73 PROCESSOR_OP = 0x83,
74 POWER_RES_OP = 0x84,
75 THERMAL_ZONE_OP = 0x85,
76 INDEX_FIELD_OP = 0x86,
77 BANK_FIELD_OP = 0x87,
78 DATA_REGION_OP = 0x88,
79 ROOT_PREFIX = 0x5C,
80 PARENT_PREFIX = 0x5E,
81 LOCAL0_OP = 0x60,
82 LOCAL1_OP = 0x61,
83 LOCAL2_OP = 0x62,
84 LOCAL3_OP = 0x63,
85 LOCAL4_OP = 0x64,
86 LOCAL5_OP = 0x65,
87 LOCAL6_OP = 0x66,
88 LOCAL7_OP = 0x67,
89 ARG0_OP = 0x68,
90 ARG1_OP = 0x69,
91 ARG2_OP = 0x6A,
92 ARG3_OP = 0x6B,
93 ARG4_OP = 0x6C,
94 ARG5_OP = 0x6D,
95 ARG6_OP = 0x6E,
96 STORE_OP = 0x70,
97 REF_OF_OP = 0x71,
98 ADD_OP = 0x72,
99 CONCATENATE_OP = 0x73,
100 SUBTRACT_OP = 0x74,
101 INCREMENT_OP = 0x75,
102 DECREMENT_OP = 0x76,
103 MULTIPLY_OP = 0x77,
104 DIVIDE_OP = 0x78,
105 SHIFT_LEFT_OP = 0x79,
106 SHIFT_RIGHT_OP = 0x7A,
107 AND_OP = 0x7B,
108 NAND_OP = 0x7C,
109 OR_OP = 0x7D,
110 NOR_OP = 0x7E,
111 XOR_OP = 0x7F,
112 NOT_OP = 0x80,
113 FD_SHIFT_LEFT_BIT_OR = 0x81,
114 FD_SHIFT_RIGHT_BIT_OR = 0x82,
115 DEREF_OP = 0x83,
116 CONCATENATE_TEMP_OP = 0x84,
117 MOD_OP = 0x85,
118 NOTIFY_OP = 0x86,
119 SIZEOF_OP = 0x87,
120 INDEX_OP = 0x88,
121 MATCH_OP = 0x89,
122 CREATE_DWORD_OP = 0x8A,
123 CREATE_WORD_OP = 0x8B,
124 CREATE_BYTE_OP = 0x8C,
125 CREATE_BIT_OP = 0x8D,
126 OBJ_TYPE_OP = 0x8E,
127 CREATE_QWORD_OP = 0x8F,
128 LAND_OP = 0x90,
129 LOR_OP = 0x91,
130 LNOT_OP = 0x92,
131 LEQUAL_OP = 0x93,
132 LGREATER_OP = 0x94,
133 LLESS_OP = 0x95,
134 TO_BUFFER_OP = 0x96,
135 TO_DEC_STRING_OP = 0x97,
136 TO_HEX_STRING_OP = 0x98,
137 TO_INTEGER_OP = 0x99,
138 TO_STRING_OP = 0x9C,
139 CP_OBJ_OP = 0x9D,
140 MID_OP = 0x9E,
141 CONTINUE_OP = 0x9F,
142 IF_OP = 0xA0,
143 ELSE_OP = 0xA1,
144 WHILE_OP = 0xA2,
145 NOOP_OP = 0xA3,
146 RETURN_OP = 0xA4,
147 BREAK_OP = 0xA5,
148 COMMENT_OP = 0xA9,
149 BREAKPIONT_OP = 0xCC,
150 ONES_OP = 0xFF,
151};
152
153#define FIELDLIST_OFFSET(X) { .type = OFFSET, \
154 .name = "",\
155 .bits = X * 8, \
156 }
157#define FIELDLIST_NAMESTR(X, Y) { .type = NAME_STRING, \
158 .name = X, \
159 .bits = Y, \
160 }
Duncan Laurie095bbf92020-09-30 23:09:29 +0000161#define FIELDLIST_RESERVED(X) { .type = RESERVED, \
162 .name = "", \
163 .bits = X, \
164 }
Furquan Shaikhe0844632020-05-02 10:23:37 -0700165
166#define FIELD_ANYACC 0
167#define FIELD_BYTEACC 1
168#define FIELD_WORDACC 2
169#define FIELD_DWORDACC 3
170#define FIELD_QWORDACC 4
171#define FIELD_BUFFERACC 5
172#define FIELD_NOLOCK (0<<4)
173#define FIELD_LOCK (1<<4)
174#define FIELD_PRESERVE (0<<5)
175#define FIELD_WRITEASONES (1<<5)
176#define FIELD_WRITEASZEROS (2<<5)
177
178enum field_type {
179 OFFSET,
180 NAME_STRING,
Duncan Laurie095bbf92020-09-30 23:09:29 +0000181 RESERVED,
Furquan Shaikhe0844632020-05-02 10:23:37 -0700182 FIELD_TYPE_MAX,
183};
184
185struct fieldlist {
186 enum field_type type;
187 const char *name;
188 u32 bits;
189};
190
191#define OPREGION(rname, space, offset, len) {.name = rname, \
192 .regionspace = space, \
193 .regionoffset = offset, \
194 .regionlen = len, \
195 }
196
197enum region_space {
198 SYSTEMMEMORY,
199 SYSTEMIO,
200 PCI_CONFIG,
201 EMBEDDEDCONTROL,
202 SMBUS,
203 CMOS,
204 PCIBARTARGET,
205 IPMI,
206 GPIO_REGION,
207 GPSERIALBUS,
208 PCC,
209 FIXED_HARDWARE = 0x7F,
210 REGION_SPACE_MAX,
211};
212
Eran Mitranif39e2962022-07-11 10:46:46 -0700213enum acpi_resource_type {
214 RSRC_TYPE_MEM = 0,
215 RSRC_TYPE_IO = 1,
216 RSRC_TYPE_BUS = 2
217};
218
219enum acpi_decode_type {
220 DECODE_10,
221 DECODE_16
222};
223
224enum acpi_read_write_type {
225 READ_ONLY,
226 READ_WRITE
227};
228
229enum acpi_cacheable_type {
230 NON_CACHEABLE,
231 CACHEABLE
232};
233
234enum acpi_resource_subtype {
235 DWORD_IO,
236 DWORD_MEMORY,
237 IO,
238 MEMORY_32_FIXED,
239 QWORD_MEMORY,
240 WORD_BUS_NUMBER
241};
242
243/* macros for ACPI Table 6.49 Memory Resource Flag (Resource Type = 0) */
244#define MEM_RSRC_FLAG_TRNSL_TYPE_STATIC 0x0
245#define MEM_RSRC_FLAG_TRNSL_TYPE_TRANSLATION (0x1 << 5)
246#define MEM_RSRC_FLAG_ADDR_RNG_MEM 0x0
247#define MEM_RSRC_FLAG_ADDR_RNG_RSV (0x1 << 3)
248#define MEM_RSRC_FLAG_ADDR_RNG_ACPI (0x2 << 3)
249#define MEM_RSRC_FLAG_ADDR_RNG_NVA (0x3 << 3)
250#define MEM_RSRC_FLAG_MEM_ATTR_NON_CACHE 0x0
251#define MEM_RSRC_FLAG_MEM_ATTR_CACHE (0x1 << 1)
252#define MEM_RSRC_FLAG_MEM_ATTR_CACHE_WRT (0x2 << 1)
253#define MEM_RSRC_FLAG_MEM_ATTR_CACHE_PREFETCH (0x3 << 1)
254#define MEM_RSRC_FLAG_MEM_READ_ONLY 0x0
255#define MEM_RSRC_FLAG_MEM_READ_WRITE 0x1
256
257/* macros for ACPI Table 6.50 I/O Resource Flag (Resource Type = 1) */
258#define IO_RSRC_FLAG_ENTIRE_RANGE 0x3
259#define IO_RSRC_FLAG_ISA_ONLY 0x2
260#define IO_RSRC_FLAG_NON_ISA_ONLY 0x1
261#define IO_RSRC_FLAG_TRASL_TYPE_STATIC 0x0
262#define IO_RSRC_FLAG_TRNSL_TYPE_TRANSLATION (0x1 << 4)
263#define IO_RSRC_FLAG_SPRS_TRASL_DENSE 0x0
264#define IO_RSRC_FLAG_SPRS_TRNSL_SPARSE (0x1 << 5)
265
266/* macro for ACPI Table 6.51 Bus Number Range Resource Flag (Resource Type = 2) */
267#define BUS_NUM_RANGE_RESOURCE_FLAG 0x0 // reserved
268
269/* General Flags for WORD Address Space Descriptor Definition (ACPI Table 6.47, byte 4)*/
270#define ADDR_SPACE_GENERAL_FLAG_MAX_FIXED (0x1 << 3)
271#define ADDR_SPACE_GENERAL_FLAG_MAX_NOT_FIXED 0x0
272#define ADDR_SPACE_GENERAL_FLAG_MIN_FIXED (0x1 << 2)
273#define ADDR_SPACE_GENERAL_FLAG_MIN_NOT_FIXED 0x0
274#define ADDR_SPACE_GENERAL_FLAG_DEC_SUB (0x1 << 1)
275#define ADDR_SPACE_GENERAL_FLAG_DEC_POS 0x0
276#define ADDR_SPACE_GENERAL_FLAG_CONSUMER 0x10
277#define ADDR_SPACE_GENERAL_FLAG_PRODUCER 0x0
278
Furquan Shaikhe0844632020-05-02 10:23:37 -0700279struct opregion {
280 const char *name;
281 enum region_space regionspace;
282 unsigned long regionoffset;
283 unsigned long regionlen;
284};
285
286#define DSM_UUID(DSM_UUID, DSM_CALLBACKS, DSM_COUNT, DSM_ARG) \
287 { .uuid = DSM_UUID, \
288 .callbacks = DSM_CALLBACKS, \
289 .count = DSM_COUNT, \
290 .arg = DSM_ARG, \
291 }
292
293struct dsm_uuid {
294 const char *uuid;
295 void (**callbacks)(void *);
296 size_t count;
297 void *arg;
298};
299
Michael Niewöhnerd5fc04b2020-10-29 22:38:32 +0100300#define CPPC_VERSION_1 1
301#define CPPC_VERSION_2 2
302#define CPPC_VERSION_3 3
303
Sridhar Siricilla0fd73402021-11-15 17:12:49 +0530304#define CPPC_PACKAGE_NAME "GCPC"
305
Furquan Shaikhe0844632020-05-02 10:23:37 -0700306/*version 1 has 15 fields, version 2 has 19, and version 3 has 21 */
307enum cppc_fields {
308 CPPC_HIGHEST_PERF, /* can be DWORD */
309 CPPC_NOMINAL_PERF, /* can be DWORD */
310 CPPC_LOWEST_NONL_PERF, /* can be DWORD */
311 CPPC_LOWEST_PERF, /* can be DWORD */
312 CPPC_GUARANTEED_PERF,
313 CPPC_DESIRED_PERF,
314 CPPC_MIN_PERF,
315 CPPC_MAX_PERF,
316 CPPC_PERF_REDUCE_TOLERANCE,
317 CPPC_TIME_WINDOW,
318 CPPC_COUNTER_WRAP, /* can be DWORD */
319 CPPC_REF_PERF_COUNTER,
320 CPPC_DELIVERED_PERF_COUNTER,
321 CPPC_PERF_LIMITED,
322 CPPC_ENABLE, /* can be System I/O */
323 CPPC_MAX_FIELDS_VER_1,
324 CPPC_AUTO_SELECT = /* can be DWORD */
325 CPPC_MAX_FIELDS_VER_1,
326 CPPC_AUTO_ACTIVITY_WINDOW,
327 CPPC_PERF_PREF,
328 CPPC_REF_PERF, /* can be DWORD */
329 CPPC_MAX_FIELDS_VER_2,
330 CPPC_LOWEST_FREQ = /* can be DWORD */
331 CPPC_MAX_FIELDS_VER_2,
332 CPPC_NOMINAL_FREQ, /* can be DWORD */
333 CPPC_MAX_FIELDS_VER_3,
334};
335
Michael Niewöhner38107fa2021-10-05 22:22:21 +0200336typedef struct cppc_entry {
337 enum { CPPC_TYPE_REG, CPPC_TYPE_DWORD } type;
338 union {
339 acpi_addr_t reg;
340 uint32_t dword;
341 };
342} cppc_entry_t;
343
344#define CPPC_DWORD(_dword) \
345 (cppc_entry_t){ \
346 .type = CPPC_TYPE_DWORD, \
347 .dword = _dword, \
348 }
349
350#define CPPC_REG(_reg) \
351 (cppc_entry_t){ \
352 .type = CPPC_TYPE_REG, \
353 .reg = _reg, \
354 }
355
356#define CPPC_REG_MSR(address, offset, width) CPPC_REG(ACPI_REG_MSR(address, offset, width))
357#define CPPC_UNSUPPORTED CPPC_REG(ACPI_REG_UNSUPPORTED)
358
Furquan Shaikhe0844632020-05-02 10:23:37 -0700359struct cppc_config {
360 u32 version; /* must be 1, 2, or 3 */
361 /*
362 * The generic acpi_addr_t structure is being used, though
363 * anything besides PPC or FFIXED generally requires checking
364 * if the OS has advertised support for it (via _OSC).
Furquan Shaikhe0844632020-05-02 10:23:37 -0700365 */
Michael Niewöhner38107fa2021-10-05 22:22:21 +0200366 cppc_entry_t entries[CPPC_MAX_FIELDS_VER_3];
Furquan Shaikhe0844632020-05-02 10:23:37 -0700367};
368
Tim Wawrzynczak18831062021-12-02 15:56:42 -0700369#define ACPI_MUTEX_NO_TIMEOUT 0xffff
370
Furquan Shaikhe0844632020-05-02 10:23:37 -0700371void acpigen_write_return_integer(uint64_t arg);
Duncan Laurieec2e3e42020-11-03 15:19:08 -0800372void acpigen_write_return_namestr(const char *arg);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700373void acpigen_write_return_string(const char *arg);
374void acpigen_write_len_f(void);
375void acpigen_pop_len(void);
376void acpigen_set_current(char *curr);
377char *acpigen_get_current(void);
378char *acpigen_write_package(int nr_el);
Jakub Czapiga17992902022-10-27 14:12:55 +0200379__always_inline void acpigen_write_package_end(void)
Jakub Czapiga61fcb7e2021-02-19 11:44:22 +0100380{
381 acpigen_pop_len();
382}
Furquan Shaikhe0844632020-05-02 10:23:37 -0700383void acpigen_write_zero(void);
384void acpigen_write_one(void);
385void acpigen_write_ones(void);
386void acpigen_write_byte(unsigned int data);
387void acpigen_emit_byte(unsigned char data);
388void acpigen_emit_ext_op(uint8_t op);
389void acpigen_emit_word(unsigned int data);
390void acpigen_emit_dword(unsigned int data);
391void acpigen_emit_stream(const char *data, int size);
392void acpigen_emit_string(const char *string);
393void acpigen_emit_namestring(const char *namepath);
394void acpigen_emit_eisaid(const char *eisaid);
395void acpigen_write_word(unsigned int data);
396void acpigen_write_dword(unsigned int data);
397void acpigen_write_qword(uint64_t data);
398void acpigen_write_integer(uint64_t data);
399void acpigen_write_string(const char *string);
400void acpigen_write_name_unicode(const char *name, const char *string);
401void acpigen_write_name(const char *name);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700402void acpigen_write_name_string(const char *name, const char *string);
403void acpigen_write_name_dword(const char *name, uint32_t val);
404void acpigen_write_name_qword(const char *name, uint64_t val);
405void acpigen_write_name_byte(const char *name, uint8_t val);
406void acpigen_write_name_integer(const char *name, uint64_t val);
407void acpigen_write_coreboot_hid(enum coreboot_acpi_ids id);
408void acpigen_write_scope(const char *name);
Jakub Czapiga17992902022-10-27 14:12:55 +0200409__always_inline void acpigen_write_scope_end(void)
Jakub Czapiga61fcb7e2021-02-19 11:44:22 +0100410{
411 acpigen_pop_len();
412}
Furquan Shaikhe0844632020-05-02 10:23:37 -0700413void acpigen_write_method(const char *name, int nargs);
414void acpigen_write_method_serialized(const char *name, int nargs);
Jakub Czapiga17992902022-10-27 14:12:55 +0200415__always_inline void acpigen_write_method_end(void)
Jakub Czapiga61fcb7e2021-02-19 11:44:22 +0100416{
417 acpigen_pop_len();
418}
Furquan Shaikhe0844632020-05-02 10:23:37 -0700419void acpigen_write_device(const char *name);
Jakub Czapiga17992902022-10-27 14:12:55 +0200420__always_inline void acpigen_write_device_end(void)
Jakub Czapiga61fcb7e2021-02-19 11:44:22 +0100421{
422 acpigen_pop_len();
423}
Raul E Rangel052c9632021-05-12 17:01:30 -0600424void acpigen_write_thermal_zone(const char *name);
Jakub Czapiga17992902022-10-27 14:12:55 +0200425__always_inline void acpigen_write_thermal_zone_end(void)
Raul E Rangel052c9632021-05-12 17:01:30 -0600426{
427 acpigen_pop_len();
428}
Raul E Rangelc7048322021-04-19 15:58:25 -0600429void acpigen_write_LPI_package(u64 level, const struct acpi_lpi_state *states, u16 nentries);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700430void acpigen_write_PPC(u8 nr);
431void acpigen_write_PPC_NVS(void);
432void acpigen_write_empty_PCT(void);
433void acpigen_write_empty_PTC(void);
Kyösti Mälkkiddc37d62023-04-17 12:11:03 +0300434void acpigen_write_PTC(uint8_t duty_width, uint8_t duty_offset, uint16_t p_cnt);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700435void acpigen_write_PRW(u32 wake, u32 level);
436void acpigen_write_STA(uint8_t status);
Sugnan Prabhu S4f77f612020-06-10 09:51:02 +0530437void acpigen_write_STA_ext(const char *namestring);
Felix Held2d4112f2023-05-04 23:00:06 +0200438void acpigen_write_BBN(uint8_t base_bus_number);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700439void acpigen_write_TPC(const char *gnvs_tpc_limit);
440void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat,
441 u32 busmLat, u32 control, u32 status);
Jason Gleneskca36aed2020-09-15 21:01:57 -0700442void acpigen_write_pss_object(const struct acpi_sw_pstate *pstate_values, size_t nentries);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700443typedef enum { SW_ALL = 0xfc, SW_ANY = 0xfd, HW_ALL = 0xfe } PSD_coord;
444void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype);
Angel Ponsd2794ce2021-10-17 12:59:43 +0200445void acpigen_write_CST_package_entry(const acpi_cstate_t *cstate);
446void acpigen_write_CST_package(const acpi_cstate_t *entry, int nentries);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700447typedef enum { CSD_HW_ALL = 0xfe } CSD_coord;
448void acpigen_write_CSD_package(u32 domain, u32 numprocs, CSD_coord coordtype,
449 u32 index);
Jason Gleneskca36aed2020-09-15 21:01:57 -0700450void acpigen_write_pct_package(const acpi_addr_t *perf_ctrl, const acpi_addr_t *perf_sts);
451void acpigen_write_xpss_package(const struct acpi_xpss_sw_pstate *pstate_value);
452void acpigen_write_xpss_object(const struct acpi_xpss_sw_pstate *pstate_values,
453 size_t nentries);
Felix Heldb57b12f2023-01-24 19:31:00 +0100454void acpigen_write_processor_namestring(unsigned int cpu_index);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700455void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len);
Jakub Czapiga17992902022-10-27 14:12:55 +0200456__always_inline void acpigen_write_processor_end(void)
Jakub Czapiga61fcb7e2021-02-19 11:44:22 +0100457{
458 acpigen_pop_len();
459}
Felix Held32bba182023-01-28 03:37:21 +0100460void acpigen_write_processor_device(unsigned int cpu_index);
461__always_inline void acpigen_write_processor_device_end(void)
462{
463 acpigen_pop_len();
464}
Furquan Shaikhe0844632020-05-02 10:23:37 -0700465void acpigen_write_processor_package(const char *name,
466 unsigned int first_core,
467 unsigned int core_count);
468void acpigen_write_processor_cnot(const unsigned int number_of_cores);
469void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list);
470void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype);
471void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size);
472void acpigen_write_io16(u16 min, u16 max, u8 align, u8 len, u8 decode16);
473void acpigen_write_register_resource(const acpi_addr_t *addr);
474void acpigen_write_resourcetemplate_header(void);
475void acpigen_write_resourcetemplate_footer(void);
476void acpigen_write_mainboard_resource_template(void);
477void acpigen_write_mainboard_resources(const char *scope, const char *name);
478void acpigen_write_irq(u16 mask);
479void acpigen_write_uuid(const char *uuid);
480void acpigen_write_power_res(const char *name, uint8_t level, uint16_t order,
481 const char * const dev_states[], size_t dev_states_count);
Jakub Czapiga17992902022-10-27 14:12:55 +0200482__always_inline void acpigen_write_power_res_end(void)
Jakub Czapiga61fcb7e2021-02-19 11:44:22 +0100483{
484 acpigen_pop_len();
485}
Furquan Shaikhe0844632020-05-02 10:23:37 -0700486void acpigen_write_sleep(uint64_t sleep_ms);
487void acpigen_write_store(void);
Duncan Laurie8e391d32020-09-30 23:17:41 +0000488void acpigen_write_store_int_to_namestr(uint64_t src, const char *dst);
489void acpigen_write_store_int_to_op(uint64_t src, uint8_t dst);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700490void acpigen_write_store_ops(uint8_t src, uint8_t dst);
491void acpigen_write_store_op_to_namestr(uint8_t src, const char *dst);
Cliff Huang24f3dc82023-02-04 21:11:51 -0800492void acpigen_write_store_namestr_to_op(const char *src, uint8_t dst);
Felix Held178cf352023-02-09 16:29:46 +0100493void acpigen_write_store_namestr_to_namestr(const char *src, const char *dst);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700494void acpigen_write_or(uint8_t arg1, uint8_t arg2, uint8_t res);
495void acpigen_write_xor(uint8_t arg1, uint8_t arg2, uint8_t res);
496void acpigen_write_and(uint8_t arg1, uint8_t arg2, uint8_t res);
497void acpigen_write_not(uint8_t arg, uint8_t res);
Cliff Huange6083082023-01-19 21:18:23 -0800498void acpigen_concatenate_string_op(const char *str, uint8_t src_res, uint8_t dest_res);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700499void acpigen_write_debug_string(const char *str);
Duncan Laurieec2e3e42020-11-03 15:19:08 -0800500void acpigen_write_debug_namestr(const char *str);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700501void acpigen_write_debug_integer(uint64_t val);
502void acpigen_write_debug_op(uint8_t op);
Cliff Huange6083082023-01-19 21:18:23 -0800503void acpigen_write_debug_concatenate_string_op(const char *str1, uint8_t res, uint8_t tmp_res);
Cliff Huang063a1b82023-02-18 00:17:26 -0800504void acpigen_write_debug_sprintf(const char *fmt, ...) __printf(1, 2);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700505void acpigen_write_if(void);
506void acpigen_write_if_and(uint8_t arg1, uint8_t arg2);
Duncan Laurie2fe74712020-06-01 17:36:56 -0700507void acpigen_write_if_lequal_op_op(uint8_t op, uint8_t val);
Cliff Huang24f3dc82023-02-04 21:11:51 -0800508void acpigen_write_if_lgreater_op_op(uint8_t op1, uint8_t op2);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700509void acpigen_write_if_lequal_op_int(uint8_t op, uint64_t val);
Cliff Huang24f3dc82023-02-04 21:11:51 -0800510void acpigen_write_if_lgreater_op_int(uint8_t op, uint64_t val);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700511void acpigen_write_if_lequal_namestr_int(const char *namestr, uint64_t val);
Cliff Huang24f3dc82023-02-04 21:11:51 -0800512void acpigen_write_if_lgreater_namestr_int(const char *namestr, uint64_t val);
Jakub Czapiga17992902022-10-27 14:12:55 +0200513__always_inline void acpigen_write_if_end(void)
Jakub Czapiga61fcb7e2021-02-19 11:44:22 +0100514{
515 acpigen_pop_len();
516}
Tim Wawrzynczakc4ca2f62021-07-01 11:18:50 -0600517/* Emits If (CondRefOf(NAME)) */
518void acpigen_write_if_cond_ref_of(const char *namestring);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700519void acpigen_write_else(void);
Duncan Laurie36858202020-10-06 21:01:51 +0000520void acpigen_write_shiftleft_op_int(uint8_t src_result, uint64_t count);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700521void acpigen_write_to_buffer(uint8_t src, uint8_t dst);
522void acpigen_write_to_integer(uint8_t src, uint8_t dst);
Aaron Durbin80bc0912020-08-19 23:17:42 -0600523void acpigen_write_to_integer_from_namestring(const char *source, uint8_t dst_op);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700524void acpigen_write_byte_buffer(uint8_t *arr, size_t size);
525void acpigen_write_return_byte_buffer(uint8_t *arr, size_t size);
526void acpigen_write_return_singleton_buffer(uint8_t arg);
Duncan Laurie2fe74712020-06-01 17:36:56 -0700527void acpigen_write_return_op(uint8_t arg);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700528void acpigen_write_return_byte(uint8_t arg);
529void acpigen_write_upc(enum acpi_upc_type type);
530void acpigen_write_pld(const struct acpi_pld *pld);
531void acpigen_write_ADR(uint64_t adr);
Duncan Laurie08a942f2020-04-29 12:13:14 -0700532struct soundwire_address;
533void acpigen_write_ADR_soundwire_device(const struct soundwire_address *address);
Aaron Durbin80bc0912020-08-19 23:17:42 -0600534void acpigen_write_create_byte_field(uint8_t op, size_t byte_offset, const char *name);
535void acpigen_write_create_word_field(uint8_t op, size_t byte_offset, const char *name);
536void acpigen_write_create_dword_field(uint8_t op, size_t byte_offset, const char *name);
537void acpigen_write_create_qword_field(uint8_t op, size_t byte_offset, const char *name);
Michael Niewöhner060dc7b2022-05-13 00:04:19 +0200538void acpigen_write_field_name(const char *name, uint32_t size);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700539/*
540 * Generate ACPI AML code for _DSM method.
541 * This function takes as input uuid for the device, set of callbacks and
542 * argument to pass into the callbacks. Callbacks should ensure that Local0 and
543 * Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks.
Tim Wawrzynczakd96f3a22021-07-14 15:56:57 -0600544 * If the first callback is NULL, then a default implementation of Function 0
545 * will be autogenerated, returning a package of bits corresponding to the
546 * function callbacks that are non-NULL.
Furquan Shaikhe0844632020-05-02 10:23:37 -0700547 */
548void acpigen_write_dsm(const char *uuid, void (**callbacks)(void *),
549 size_t count, void *arg);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700550
Tim Wawrzynczakd96f3a22021-07-14 15:56:57 -0600551void acpigen_write_dsm_uuid_arr(struct dsm_uuid *ids, size_t count);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700552/*
553 * Generate ACPI AML code for _CPC (Continuous Performance Control).
554 * Execute the package function once to create a global table, then
555 * execute the method function within each processor object to
556 * create a method that points to the global table.
557 */
558void acpigen_write_CPPC_package(const struct cppc_config *config);
559void acpigen_write_CPPC_method(void);
560
561/*
562 * Generate ACPI AML code for _ROM method.
563 * This function takes as input ROM data and ROM length.
564 * The ROM length has to be multiple of 4096 and has to be less
565 * than the current implementation limit of 0x40000.
566 */
567void acpigen_write_rom(void *bios, const size_t length);
568/*
569 * Generate ACPI AML code for OperationRegion
570 * This function takes input region name, region space, region offset & region
571 * length.
572 */
Duncan Laurie35029602020-10-09 17:50:25 +0000573void acpigen_write_opregion(const struct opregion *opreg);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700574/*
575 * Generate ACPI AML code for Mutex
576 * This function takes mutex name and initial value.
577 */
578void acpigen_write_mutex(const char *name, const uint8_t flags);
579/*
580 * Generate ACPI AML code for Acquire
581 * This function takes mutex name and privilege value.
582 */
583void acpigen_write_acquire(const char *name, const uint16_t val);
584/*
585 * Generate ACPI AML code for Release
586 * This function takes mutex name.
587 */
588void acpigen_write_release(const char *name);
589/*
590 * Generate ACPI AML code for Field
591 * This function takes input region name, fieldlist, count & flags.
592 */
593void acpigen_write_field(const char *name, const struct fieldlist *l, size_t count,
594 uint8_t flags);
595/*
596 * Generate ACPI AML code for IndexField
597 * This function takes input index name, data name, fieldlist, count & flags.
598 */
599void acpigen_write_indexfield(const char *idx, const char *data,
600 struct fieldlist *l, size_t count, uint8_t flags);
601
Angel Ponsafd268a2021-10-17 13:35:23 +0200602int get_cst_entries(const acpi_cstate_t **);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700603
604/*
Duncan Laurie2fe74712020-06-01 17:36:56 -0700605 * Get element from package into specified destination op:
Duncan Laurieec2e3e42020-11-03 15:19:08 -0800606 * <dest_op> = DeRefOf (<package_op>[<element>])
Duncan Laurie2fe74712020-06-01 17:36:56 -0700607 *
608 * Example:
609 * acpigen_get_package_op_element(ARG0_OP, 0, LOCAL0_OP)
610 * Local0 = DeRefOf (Arg0[0])
611 */
612void acpigen_get_package_op_element(uint8_t package_op, unsigned int element, uint8_t dest_op);
613
Duncan Laurieec2e3e42020-11-03 15:19:08 -0800614/* Set element of package op to specified op: DeRefOf (<package>[<element>]) = <src> */
615void acpigen_set_package_op_element_int(uint8_t package_op, unsigned int element, uint64_t src);
616
617/* Get element from package to specified op: <dest_op> = <package>[<element>] */
618void acpigen_get_package_element(const char *package, unsigned int element, uint8_t dest_op);
619
620/* Set element of package to specified op: <package>[<element>] = <src> */
621void acpigen_set_package_element_int(const char *package, unsigned int element, uint64_t src);
622
623/* Set element of package to specified namestr: <package>[<element>] = <src> */
624void acpigen_set_package_element_namestr(const char *package, unsigned int element,
625 const char *src);
626
627/*
628 * Delay up to wait_ms milliseconds until the provided name matches the expected value.
629 * If wait_ms is >= 32ms then it will wait in 16ms chunks. This function uses LOCAL7_OP.
630 */
631void acpigen_write_delay_until_namestr_int(uint32_t wait_ms, const char *name, uint64_t value);
632
Duncan Laurie2fe74712020-06-01 17:36:56 -0700633/*
Furquan Shaikhe0844632020-05-02 10:23:37 -0700634 * Soc-implemented functions for generating ACPI AML code for GPIO handling. All
635 * these functions are expected to use only Local5, Local6 and Local7
636 * variables. If the functions call into another ACPI method, then there is no
637 * restriction on the use of Local variables. In case of get/read functions,
638 * return value is expected to be stored in Local0 variable.
639 *
640 * All functions return 0 on success and -1 on error.
641 */
642
643/* Generate ACPI AML code to return Rx value of GPIO in Local0. */
644int acpigen_soc_read_rx_gpio(unsigned int gpio_num);
645
646/* Generate ACPI AML code to return Tx value of GPIO in Local0. */
647int acpigen_soc_get_tx_gpio(unsigned int gpio_num);
648
649/* Generate ACPI AML code to set Tx value of GPIO to 1. */
650int acpigen_soc_set_tx_gpio(unsigned int gpio_num);
651
652/* Generate ACPI AML code to set Tx value of GPIO to 0. */
653int acpigen_soc_clear_tx_gpio(unsigned int gpio_num);
654
655/*
656 * Helper functions for enabling/disabling Tx GPIOs based on the GPIO
657 * polarity. These functions end up calling acpigen_soc_{set,clear}_tx_gpio to
658 * make callbacks into SoC acpigen code.
659 *
660 * Returns 0 on success and -1 on error.
661 */
Duncan Laurie30c3f912020-10-09 04:48:53 +0000662int acpigen_enable_tx_gpio(const struct acpi_gpio *gpio);
663int acpigen_disable_tx_gpio(const struct acpi_gpio *gpio);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700664
665/*
666 * Helper function for getting a RX GPIO value based on the GPIO polarity.
667 * The return value is stored in Local0 variable.
668 * This function ends up calling acpigen_soc_get_rx_gpio to make callbacks
669 * into SoC acpigen code
670 */
Duncan Laurie30c3f912020-10-09 04:48:53 +0000671void acpigen_get_rx_gpio(const struct acpi_gpio *gpio);
Furquan Shaikhe0844632020-05-02 10:23:37 -0700672
Duncan Laurie2fe74712020-06-01 17:36:56 -0700673/*
674 * Helper function for getting a TX GPIO value based on the GPIO polarity.
675 * The return value is stored in Local0 variable.
676 * This function ends up calling acpigen_soc_get_tx_gpio to make callbacks
677 * into SoC acpigen code
678 */
Duncan Laurie30c3f912020-10-09 04:48:53 +0000679void acpigen_get_tx_gpio(const struct acpi_gpio *gpio);
Duncan Laurie2fe74712020-06-01 17:36:56 -0700680
Furquan Shaikhe0844632020-05-02 10:23:37 -0700681/* refer to ACPI 6.4.3.5.3 Word Address Space Descriptor section for details */
682void acpigen_resource_word(u16 res_type, u16 gen_flags, u16 type_flags, u16 gran,
683 u16 range_min, u16 range_max, u16 translation, u16 length);
684/* refer to ACPI 6.4.3.5.2 DWord Address Space Descriptor section for details */
685void acpigen_resource_dword(u16 res_type, u16 gen_flags, u16 type_flags,
686 u32 gran, u32 range_min, u32 range_max, u32 translation, u32 length);
687/* refer to ACPI 6.4.3.5.1 QWord Address Space Descriptor section for details */
688void acpigen_resource_qword(u16 res_type, u16 gen_flags, u16 type_flags,
689 u64 gran, u64 range_min, u64 range_max, u64 translation, u64 length);
690
Felix Held0fdede02023-05-27 01:02:37 +0200691void acpigen_resource_producer_bus_number(u16 bus_base, u16 bus_limit);
692void acpigen_resource_producer_io(u16 io_base, u16 io_limit);
693void acpigen_resource_producer_mmio(u64 mmio_base, u64 mmio_limit, u16 type_flags);
Arthur Heymans62f788e2023-11-21 18:49:33 +0100694void acpigen_resource_consumer_mmio(u64 mmio_base, u64 mmio_limit, u16 type_flags);
Felix Held5a82f0d2023-05-09 16:10:35 +0200695
Tim Wawrzynczakf6945022020-06-04 15:18:47 -0600696/* Emits Notify(namestr, value) */
697void acpigen_notify(const char *namestr, int value);
698
Arthur Heymans0eb59742023-04-25 16:23:37 +0200699/* Create a namespace \OSFG to override the enabled sleep states */
700void acpigen_ssdt_override_sleep_states(bool enable_s1, bool enable_s2, bool enable_s3,
701 bool enable_s4);
702
Furquan Shaikh56eafbb2020-04-30 18:38:55 -0700703#endif /* __ACPI_ACPIGEN_H__ */