ACPI: Add acpigen_write_PTC()
[coreboot.git] / src / include / acpi / acpigen.h
blob180e93779d1e3509cc2c367aaabb84edd4da8c90
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #ifndef __ACPI_ACPIGEN_H__
4 #define __ACPI_ACPIGEN_H__
6 #include <stddef.h>
7 #include <stdint.h>
8 #include <acpi/acpi.h>
9 #include <acpi/acpi_device.h>
10 #include <acpi/acpi_pld.h>
11 #include <device/pci_type.h>
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)
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)
28 /* ACPI Op/Prefix Codes */
29 enum {
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,
49 EVENT_OP = 0x02,
50 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,
153 #define FIELDLIST_OFFSET(X) { .type = OFFSET, \
154 .name = "",\
155 .bits = X * 8, \
157 #define FIELDLIST_NAMESTR(X, Y) { .type = NAME_STRING, \
158 .name = X, \
159 .bits = Y, \
161 #define FIELDLIST_RESERVED(X) { .type = RESERVED, \
162 .name = "", \
163 .bits = X, \
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)
178 enum field_type {
179 OFFSET,
180 NAME_STRING,
181 RESERVED,
182 FIELD_TYPE_MAX,
185 struct fieldlist {
186 enum field_type type;
187 const char *name;
188 u32 bits;
191 #define OPREGION(rname, space, offset, len) {.name = rname, \
192 .regionspace = space, \
193 .regionoffset = offset, \
194 .regionlen = len, \
197 enum 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,
213 enum acpi_resource_type {
214 RSRC_TYPE_MEM = 0,
215 RSRC_TYPE_IO = 1,
216 RSRC_TYPE_BUS = 2
219 enum acpi_decode_type {
220 DECODE_10,
221 DECODE_16
224 enum acpi_read_write_type {
225 READ_ONLY,
226 READ_WRITE
229 enum acpi_cacheable_type {
230 NON_CACHEABLE,
231 CACHEABLE
234 enum acpi_resource_subtype {
235 DWORD_IO,
236 DWORD_MEMORY,
238 MEMORY_32_FIXED,
239 QWORD_MEMORY,
240 WORD_BUS_NUMBER
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
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)
266 /* macro for ACPI Table 6.51 Bus Number Range Resource Flag (Resource Type = 2) */
267 #define BUS_NUM_RANGE_RESOURCE_FLAG 0x0 // reserved
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
279 struct opregion {
280 const char *name;
281 enum region_space regionspace;
282 unsigned long regionoffset;
283 unsigned long regionlen;
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, \
293 struct dsm_uuid {
294 const char *uuid;
295 void (**callbacks)(void *);
296 size_t count;
297 void *arg;
300 #define CPPC_VERSION_1 1
301 #define CPPC_VERSION_2 2
302 #define CPPC_VERSION_3 3
304 #define CPPC_PACKAGE_NAME "GCPC"
306 /*version 1 has 15 fields, version 2 has 19, and version 3 has 21 */
307 enum 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,
336 typedef struct cppc_entry {
337 enum { CPPC_TYPE_REG, CPPC_TYPE_DWORD } type;
338 union {
339 acpi_addr_t reg;
340 uint32_t dword;
342 } cppc_entry_t;
344 #define CPPC_DWORD(_dword) \
345 (cppc_entry_t){ \
346 .type = CPPC_TYPE_DWORD, \
347 .dword = _dword, \
350 #define CPPC_REG(_reg) \
351 (cppc_entry_t){ \
352 .type = CPPC_TYPE_REG, \
353 .reg = _reg, \
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)
359 struct cppc_config {
360 u32 version; /* must be 1, 2, or 3 */
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).
366 cppc_entry_t entries[CPPC_MAX_FIELDS_VER_3];
369 #define ACPI_MUTEX_NO_TIMEOUT 0xffff
371 void acpigen_write_return_integer(uint64_t arg);
372 void acpigen_write_return_namestr(const char *arg);
373 void acpigen_write_return_string(const char *arg);
374 void acpigen_write_len_f(void);
375 void acpigen_pop_len(void);
376 void acpigen_set_current(char *curr);
377 char *acpigen_get_current(void);
378 char *acpigen_write_package(int nr_el);
379 __always_inline void acpigen_write_package_end(void)
381 acpigen_pop_len();
383 void acpigen_write_zero(void);
384 void acpigen_write_one(void);
385 void acpigen_write_ones(void);
386 void acpigen_write_byte(unsigned int data);
387 void acpigen_emit_byte(unsigned char data);
388 void acpigen_emit_ext_op(uint8_t op);
389 void acpigen_emit_word(unsigned int data);
390 void acpigen_emit_dword(unsigned int data);
391 void acpigen_emit_stream(const char *data, int size);
392 void acpigen_emit_string(const char *string);
393 void acpigen_emit_namestring(const char *namepath);
394 void acpigen_emit_eisaid(const char *eisaid);
395 void acpigen_write_word(unsigned int data);
396 void acpigen_write_dword(unsigned int data);
397 void acpigen_write_qword(uint64_t data);
398 void acpigen_write_integer(uint64_t data);
399 void acpigen_write_string(const char *string);
400 void acpigen_write_name_unicode(const char *name, const char *string);
401 void acpigen_write_name(const char *name);
402 void acpigen_write_name_string(const char *name, const char *string);
403 void acpigen_write_name_dword(const char *name, uint32_t val);
404 void acpigen_write_name_qword(const char *name, uint64_t val);
405 void acpigen_write_name_byte(const char *name, uint8_t val);
406 void acpigen_write_name_integer(const char *name, uint64_t val);
407 void acpigen_write_coreboot_hid(enum coreboot_acpi_ids id);
408 void acpigen_write_scope(const char *name);
409 __always_inline void acpigen_write_scope_end(void)
411 acpigen_pop_len();
413 void acpigen_write_method(const char *name, int nargs);
414 void acpigen_write_method_serialized(const char *name, int nargs);
415 __always_inline void acpigen_write_method_end(void)
417 acpigen_pop_len();
419 void acpigen_write_device(const char *name);
420 __always_inline void acpigen_write_device_end(void)
422 acpigen_pop_len();
424 void acpigen_write_thermal_zone(const char *name);
425 __always_inline void acpigen_write_thermal_zone_end(void)
427 acpigen_pop_len();
429 void acpigen_write_LPI_package(u64 level, const struct acpi_lpi_state *states, u16 nentries);
430 void acpigen_write_PPC(u8 nr);
431 void acpigen_write_PPC_NVS(void);
432 void acpigen_write_empty_PCT(void);
433 void acpigen_write_empty_PTC(void);
434 void acpigen_write_PTC(uint8_t duty_width, uint8_t duty_offset, uint16_t p_cnt);
435 void acpigen_write_PRW(u32 wake, u32 level);
436 void acpigen_write_STA(uint8_t status);
437 void acpigen_write_STA_ext(const char *namestring);
438 void acpigen_write_TPC(const char *gnvs_tpc_limit);
439 void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat,
440 u32 busmLat, u32 control, u32 status);
441 void acpigen_write_pss_object(const struct acpi_sw_pstate *pstate_values, size_t nentries);
442 typedef enum { SW_ALL = 0xfc, SW_ANY = 0xfd, HW_ALL = 0xfe } PSD_coord;
443 void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype);
444 void acpigen_write_CST_package_entry(const acpi_cstate_t *cstate);
445 void acpigen_write_CST_package(const acpi_cstate_t *entry, int nentries);
446 typedef enum { CSD_HW_ALL = 0xfe } CSD_coord;
447 void acpigen_write_CSD_package(u32 domain, u32 numprocs, CSD_coord coordtype,
448 u32 index);
449 void acpigen_write_pct_package(const acpi_addr_t *perf_ctrl, const acpi_addr_t *perf_sts);
450 void acpigen_write_xpss_package(const struct acpi_xpss_sw_pstate *pstate_value);
451 void acpigen_write_xpss_object(const struct acpi_xpss_sw_pstate *pstate_values,
452 size_t nentries);
453 void acpigen_write_processor_namestring(unsigned int cpu_index);
454 void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len);
455 __always_inline void acpigen_write_processor_end(void)
457 acpigen_pop_len();
459 void acpigen_write_processor_device(unsigned int cpu_index);
460 __always_inline void acpigen_write_processor_device_end(void)
462 acpigen_pop_len();
464 void acpigen_write_processor_package(const char *name,
465 unsigned int first_core,
466 unsigned int core_count);
467 void acpigen_write_processor_cnot(const unsigned int number_of_cores);
468 void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list);
469 void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype);
470 void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size);
471 void acpigen_write_io16(u16 min, u16 max, u8 align, u8 len, u8 decode16);
472 void acpigen_write_register_resource(const acpi_addr_t *addr);
473 void acpigen_write_resourcetemplate_header(void);
474 void acpigen_write_resourcetemplate_footer(void);
475 void acpigen_write_mainboard_resource_template(void);
476 void acpigen_write_mainboard_resources(const char *scope, const char *name);
477 void acpigen_write_irq(u16 mask);
478 void acpigen_write_uuid(const char *uuid);
479 void acpigen_write_power_res(const char *name, uint8_t level, uint16_t order,
480 const char * const dev_states[], size_t dev_states_count);
481 __always_inline void acpigen_write_power_res_end(void)
483 acpigen_pop_len();
485 void acpigen_write_sleep(uint64_t sleep_ms);
486 void acpigen_write_store(void);
487 void acpigen_write_store_int_to_namestr(uint64_t src, const char *dst);
488 void acpigen_write_store_int_to_op(uint64_t src, uint8_t dst);
489 void acpigen_write_store_ops(uint8_t src, uint8_t dst);
490 void acpigen_write_store_op_to_namestr(uint8_t src, const char *dst);
491 void acpigen_write_store_namestr_to_op(const char *src, uint8_t dst);
492 void acpigen_write_store_namestr_to_namestr(const char *src, const char *dst);
493 void acpigen_write_or(uint8_t arg1, uint8_t arg2, uint8_t res);
494 void acpigen_write_xor(uint8_t arg1, uint8_t arg2, uint8_t res);
495 void acpigen_write_and(uint8_t arg1, uint8_t arg2, uint8_t res);
496 void acpigen_write_not(uint8_t arg, uint8_t res);
497 void acpigen_concatenate_string_string(const char *str1, const char *str2, uint8_t res);
498 void acpigen_concatenate_string_int(const char *str, uint64_t val, uint8_t res);
499 void acpigen_concatenate_string_op(const char *str, uint8_t src_res, uint8_t dest_res);
500 void acpigen_write_debug_string(const char *str);
501 void acpigen_write_debug_namestr(const char *str);
502 void acpigen_write_debug_integer(uint64_t val);
503 void acpigen_write_debug_op(uint8_t op);
504 void acpigen_write_debug_concatenate_string_string(const char *str1, const char *str2,
505 uint8_t tmp_res);
506 void acpigen_write_debug_concatenate_string_int(const char *str1, uint64_t val,
507 uint8_t tmp_res);
508 void acpigen_write_debug_concatenate_string_op(const char *str1, uint8_t res, uint8_t tmp_res);
509 void acpigen_write_if(void);
510 void acpigen_write_if_and(uint8_t arg1, uint8_t arg2);
511 void acpigen_write_if_lequal_op_op(uint8_t op, uint8_t val);
512 void acpigen_write_if_lgreater_op_op(uint8_t op1, uint8_t op2);
513 void acpigen_write_if_lequal_op_int(uint8_t op, uint64_t val);
514 void acpigen_write_if_lgreater_op_int(uint8_t op, uint64_t val);
515 void acpigen_write_if_lequal_namestr_int(const char *namestr, uint64_t val);
516 void acpigen_write_if_lgreater_namestr_int(const char *namestr, uint64_t val);
517 __always_inline void acpigen_write_if_end(void)
519 acpigen_pop_len();
521 /* Emits If (CondRefOf(NAME)) */
522 void acpigen_write_if_cond_ref_of(const char *namestring);
523 void acpigen_write_else(void);
524 void acpigen_write_shiftleft_op_int(uint8_t src_result, uint64_t count);
525 void acpigen_write_to_buffer(uint8_t src, uint8_t dst);
526 void acpigen_write_to_integer(uint8_t src, uint8_t dst);
527 void acpigen_write_to_integer_from_namestring(const char *source, uint8_t dst_op);
528 void acpigen_write_byte_buffer(uint8_t *arr, size_t size);
529 void acpigen_write_return_byte_buffer(uint8_t *arr, size_t size);
530 void acpigen_write_return_singleton_buffer(uint8_t arg);
531 void acpigen_write_return_op(uint8_t arg);
532 void acpigen_write_return_byte(uint8_t arg);
533 void acpigen_write_upc(enum acpi_upc_type type);
534 void acpigen_write_pld(const struct acpi_pld *pld);
535 void acpigen_write_ADR(uint64_t adr);
536 struct soundwire_address;
537 void acpigen_write_ADR_soundwire_device(const struct soundwire_address *address);
538 void acpigen_write_create_byte_field(uint8_t op, size_t byte_offset, const char *name);
539 void acpigen_write_create_word_field(uint8_t op, size_t byte_offset, const char *name);
540 void acpigen_write_create_dword_field(uint8_t op, size_t byte_offset, const char *name);
541 void acpigen_write_create_qword_field(uint8_t op, size_t byte_offset, const char *name);
542 void acpigen_write_field_name(const char *name, uint32_t size);
544 * Generate ACPI AML code for _DSM method.
545 * This function takes as input uuid for the device, set of callbacks and
546 * argument to pass into the callbacks. Callbacks should ensure that Local0 and
547 * Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks.
548 * If the first callback is NULL, then a default implementation of Function 0
549 * will be autogenerated, returning a package of bits corresponding to the
550 * function callbacks that are non-NULL.
552 void acpigen_write_dsm(const char *uuid, void (**callbacks)(void *),
553 size_t count, void *arg);
555 void acpigen_write_dsm_uuid_arr(struct dsm_uuid *ids, size_t count);
557 * Generate ACPI AML code for _CPC (Continuous Performance Control).
558 * Execute the package function once to create a global table, then
559 * execute the method function within each processor object to
560 * create a method that points to the global table.
562 void acpigen_write_CPPC_package(const struct cppc_config *config);
563 void acpigen_write_CPPC_method(void);
566 * Generate ACPI AML code for _ROM method.
567 * This function takes as input ROM data and ROM length.
568 * The ROM length has to be multiple of 4096 and has to be less
569 * than the current implementation limit of 0x40000.
571 void acpigen_write_rom(void *bios, const size_t length);
573 * Generate ACPI AML code for OperationRegion
574 * This function takes input region name, region space, region offset & region
575 * length.
577 void acpigen_write_opregion(const struct opregion *opreg);
579 * Generate ACPI AML code for Mutex
580 * This function takes mutex name and initial value.
582 void acpigen_write_mutex(const char *name, const uint8_t flags);
584 * Generate ACPI AML code for Acquire
585 * This function takes mutex name and privilege value.
587 void acpigen_write_acquire(const char *name, const uint16_t val);
589 * Generate ACPI AML code for Release
590 * This function takes mutex name.
592 void acpigen_write_release(const char *name);
594 * Generate ACPI AML code for Field
595 * This function takes input region name, fieldlist, count & flags.
597 void acpigen_write_field(const char *name, const struct fieldlist *l, size_t count,
598 uint8_t flags);
600 * Generate ACPI AML code for IndexField
601 * This function takes input index name, data name, fieldlist, count & flags.
603 void acpigen_write_indexfield(const char *idx, const char *data,
604 struct fieldlist *l, size_t count, uint8_t flags);
606 int get_cst_entries(const acpi_cstate_t **);
609 * Get element from package into specified destination op:
610 * <dest_op> = DeRefOf (<package_op>[<element>])
612 * Example:
613 * acpigen_get_package_op_element(ARG0_OP, 0, LOCAL0_OP)
614 * Local0 = DeRefOf (Arg0[0])
616 void acpigen_get_package_op_element(uint8_t package_op, unsigned int element, uint8_t dest_op);
618 /* Set element of package op to specified op: DeRefOf (<package>[<element>]) = <src> */
619 void acpigen_set_package_op_element_int(uint8_t package_op, unsigned int element, uint64_t src);
621 /* Get element from package to specified op: <dest_op> = <package>[<element>] */
622 void acpigen_get_package_element(const char *package, unsigned int element, uint8_t dest_op);
624 /* Set element of package to specified op: <package>[<element>] = <src> */
625 void acpigen_set_package_element_int(const char *package, unsigned int element, uint64_t src);
627 /* Set element of package to specified namestr: <package>[<element>] = <src> */
628 void acpigen_set_package_element_namestr(const char *package, unsigned int element,
629 const char *src);
632 * Delay up to wait_ms milliseconds until the provided name matches the expected value.
633 * If wait_ms is >= 32ms then it will wait in 16ms chunks. This function uses LOCAL7_OP.
635 void acpigen_write_delay_until_namestr_int(uint32_t wait_ms, const char *name, uint64_t value);
638 * Soc-implemented functions for generating ACPI AML code for GPIO handling. All
639 * these functions are expected to use only Local5, Local6 and Local7
640 * variables. If the functions call into another ACPI method, then there is no
641 * restriction on the use of Local variables. In case of get/read functions,
642 * return value is expected to be stored in Local0 variable.
644 * All functions return 0 on success and -1 on error.
647 /* Generate ACPI AML code to return Rx value of GPIO in Local0. */
648 int acpigen_soc_read_rx_gpio(unsigned int gpio_num);
650 /* Generate ACPI AML code to return Tx value of GPIO in Local0. */
651 int acpigen_soc_get_tx_gpio(unsigned int gpio_num);
653 /* Generate ACPI AML code to set Tx value of GPIO to 1. */
654 int acpigen_soc_set_tx_gpio(unsigned int gpio_num);
656 /* Generate ACPI AML code to set Tx value of GPIO to 0. */
657 int acpigen_soc_clear_tx_gpio(unsigned int gpio_num);
660 * Helper functions for enabling/disabling Tx GPIOs based on the GPIO
661 * polarity. These functions end up calling acpigen_soc_{set,clear}_tx_gpio to
662 * make callbacks into SoC acpigen code.
664 * Returns 0 on success and -1 on error.
666 int acpigen_enable_tx_gpio(const struct acpi_gpio *gpio);
667 int acpigen_disable_tx_gpio(const struct acpi_gpio *gpio);
670 * Helper function for getting a RX GPIO value based on the GPIO polarity.
671 * The return value is stored in Local0 variable.
672 * This function ends up calling acpigen_soc_get_rx_gpio to make callbacks
673 * into SoC acpigen code
675 void acpigen_get_rx_gpio(const struct acpi_gpio *gpio);
678 * Helper function for getting a TX GPIO value based on the GPIO polarity.
679 * The return value is stored in Local0 variable.
680 * This function ends up calling acpigen_soc_get_tx_gpio to make callbacks
681 * into SoC acpigen code
683 void acpigen_get_tx_gpio(const struct acpi_gpio *gpio);
685 /* refer to ACPI 6.4.3.5.3 Word Address Space Descriptor section for details */
686 void acpigen_resource_word(u16 res_type, u16 gen_flags, u16 type_flags, u16 gran,
687 u16 range_min, u16 range_max, u16 translation, u16 length);
688 /* refer to ACPI 6.4.3.5.2 DWord Address Space Descriptor section for details */
689 void acpigen_resource_dword(u16 res_type, u16 gen_flags, u16 type_flags,
690 u32 gran, u32 range_min, u32 range_max, u32 translation, u32 length);
691 /* refer to ACPI 6.4.3.5.1 QWord Address Space Descriptor section for details */
692 void acpigen_resource_qword(u16 res_type, u16 gen_flags, u16 type_flags,
693 u64 gran, u64 range_min, u64 range_max, u64 translation, u64 length);
695 /* Emits Notify(namestr, value) */
696 void acpigen_notify(const char *namestr, int value);
698 #endif /* __ACPI_ACPIGEN_H__ */