acpigen.h
1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef __ACPI_ACPIGEN_H__ 4 #define __ACPI_ACPIGEN_H__ 5 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> 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 */ 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, 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 } 161 #define FIELDLIST_RESERVED(X) { .type = RESERVED, \ 162 .name = "", \ 163 .bits = X, \ 164 } 165 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 178 enum field_type { 179 OFFSET, 180 NAME_STRING, 181 RESERVED, 182 FIELD_TYPE_MAX, 183 }; 184 185 struct 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 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, 211 }; 212 213 enum acpi_resource_type { 214 RSRC_TYPE_MEM = 0, 215 RSRC_TYPE_IO = 1, 216 RSRC_TYPE_BUS = 2 217 }; 218 219 enum acpi_decode_type { 220 DECODE_10, 221 DECODE_16 222 }; 223 224 enum acpi_read_write_type { 225 READ_ONLY, 226 READ_WRITE 227 }; 228 229 enum acpi_cacheable_type { 230 NON_CACHEABLE, 231 CACHEABLE 232 }; 233 234 enum 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 279 struct 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 293 struct dsm_uuid { 294 const char *uuid; 295 void (**callbacks)(void *); 296 size_t count; 297 void *arg; 298 }; 299 300 #define CPPC_VERSION_1 1 301 #define CPPC_VERSION_2 2 302 #define CPPC_VERSION_3 3 303 304 #define CPPC_PACKAGE_NAME "GCPC" 305 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, 334 }; 335 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; 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 359 struct 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). 365 */ 366 cppc_entry_t entries[CPPC_MAX_FIELDS_VER_3]; 367 }; 368 369 #define ACPI_MUTEX_NO_TIMEOUT 0xffff 370 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) 380 { 381 acpigen_pop_len(); 382 } 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) 410 { 411 acpigen_pop_len(); 412 } 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) 416 { 417 acpigen_pop_len(); 418 } 419 void acpigen_write_device(const char *name); 420 __always_inline void acpigen_write_device_end(void) 421 { 422 acpigen_pop_len(); 423 } 424 void acpigen_write_thermal_zone(const char *name); 425 __always_inline void acpigen_write_thermal_zone_end(void) 426 { 427 acpigen_pop_len(); 428 } 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_BBN(uint8_t base_bus_number); 439 void acpigen_write_SEG(uint8_t segment_group_number); 440 void acpigen_write_TPC(const char *gnvs_tpc_limit); 441 void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, 442 u32 busmLat, u32 control, u32 status); 443 void acpigen_write_pss_object(const struct acpi_sw_pstate *pstate_values, size_t nentries); 444 typedef enum { SW_ALL = 0xfc, SW_ANY = 0xfd, HW_ALL = 0xfe } PSD_coord; 445 void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype); 446 void acpigen_write_CST_package_entry(const acpi_cstate_t *cstate); 447 void acpigen_write_CST_package(const acpi_cstate_t *entry, int nentries); 448 typedef enum { CSD_HW_ALL = 0xfe } CSD_coord; 449 void acpigen_write_CSD_package(u32 domain, u32 numprocs, CSD_coord coordtype, 450 u32 index); 451 void acpigen_write_pct_package(const acpi_addr_t *perf_ctrl, const acpi_addr_t *perf_sts); 452 void acpigen_write_xpss_package(const struct acpi_xpss_sw_pstate *pstate_value); 453 void acpigen_write_xpss_object(const struct acpi_xpss_sw_pstate *pstate_values, 454 size_t nentries); 455 void acpigen_write_processor_namestring(unsigned int cpu_index); 456 void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len); 457 __always_inline void acpigen_write_processor_end(void) 458 { 459 acpigen_pop_len(); 460 } 461 void acpigen_write_processor_device(unsigned int cpu_index); 462 __always_inline void acpigen_write_processor_device_end(void) 463 { 464 acpigen_pop_len(); 465 } 466 void acpigen_write_processor_package(const char *name, 467 unsigned int first_core, 468 unsigned int core_count); 469 void acpigen_write_processor_cnot(const unsigned int number_of_cores); 470 void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list); 471 void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype); 472 void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size); 473 void acpigen_write_io16(u16 min, u16 max, u8 align, u8 len, u8 decode16); 474 void acpigen_write_register_resource(const acpi_addr_t *addr); 475 void acpigen_write_resourcetemplate_header(void); 476 void acpigen_write_resourcetemplate_footer(void); 477 void acpigen_write_mainboard_resource_template(void); 478 void acpigen_write_mainboard_resources(const char *scope, const char *name); 479 void acpigen_write_irq(u16 mask); 480 void acpigen_write_uuid(const char *uuid); 481 void acpigen_write_power_res(const char *name, uint8_t level, uint16_t order, 482 const char * const dev_states[], size_t dev_states_count); 483 __always_inline void acpigen_write_power_res_end(void) 484 { 485 acpigen_pop_len(); 486 } 487 void acpigen_write_sleep(uint64_t sleep_ms); 488 void acpigen_write_store(void); 489 void acpigen_write_store_int_to_namestr(uint64_t src, const char *dst); 490 void acpigen_write_store_int_to_op(uint64_t src, uint8_t dst); 491 void acpigen_write_store_ops(uint8_t src, uint8_t dst); 492 void acpigen_write_store_op_to_namestr(uint8_t src, const char *dst); 493 void acpigen_write_store_namestr_to_op(const char *src, uint8_t dst); 494 void acpigen_write_store_namestr_to_namestr(const char *src, const char *dst); 495 void acpigen_write_or(uint8_t arg1, uint8_t arg2, uint8_t res); 496 void acpigen_write_xor(uint8_t arg1, uint8_t arg2, uint8_t res); 497 void acpigen_write_and(uint8_t arg1, uint8_t arg2, uint8_t res); 498 void acpigen_write_not(uint8_t arg, 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_op(const char *str1, uint8_t res, uint8_t tmp_res); 505 void acpigen_write_debug_sprintf(const char *fmt, ...) __printf(1, 2); 506 void acpigen_write_if(void); 507 void acpigen_write_if_and(uint8_t arg1, uint8_t arg2); 508 void acpigen_write_if_lequal_op_op(uint8_t op, uint8_t val); 509 void acpigen_write_if_lgreater_op_op(uint8_t op1, uint8_t op2); 510 void acpigen_write_if_lequal_op_int(uint8_t op, uint64_t val); 511 void acpigen_write_if_lgreater_op_int(uint8_t op, uint64_t val); 512 void acpigen_write_if_lequal_namestr_int(const char *namestr, uint64_t val); 513 void acpigen_write_if_lgreater_namestr_int(const char *namestr, uint64_t val); 514 __always_inline void acpigen_write_if_end(void) 515 { 516 acpigen_pop_len(); 517 } 518 /* Emits If (CondRefOf(NAME)) */ 519 void acpigen_write_if_cond_ref_of(const char *namestring); 520 void acpigen_write_else(void); 521 void acpigen_write_shiftleft_op_int(uint8_t src_result, uint64_t count); 522 void acpigen_write_to_buffer(uint8_t src, uint8_t dst); 523 void acpigen_write_to_integer(uint8_t src, uint8_t dst); 524 void acpigen_write_to_integer_from_namestring(const char *source, uint8_t dst_op); 525 void acpigen_write_byte_buffer(uint8_t *arr, size_t size); 526 void acpigen_write_return_byte_buffer(uint8_t *arr, size_t size); 527 void acpigen_write_return_singleton_buffer(uint8_t arg); 528 void acpigen_write_return_op(uint8_t arg); 529 void acpigen_write_return_byte(uint8_t arg); 530 void acpigen_write_upc(enum acpi_upc_type type); 531 void acpigen_write_pld(const struct acpi_pld *pld); 532 void acpigen_write_ADR(uint64_t adr); 533 struct soundwire_address; 534 void acpigen_write_ADR_soundwire_device(const struct soundwire_address *address); 535 void acpigen_write_create_byte_field(uint8_t op, size_t byte_offset, const char *name); 536 void acpigen_write_create_word_field(uint8_t op, size_t byte_offset, const char *name); 537 void acpigen_write_create_dword_field(uint8_t op, size_t byte_offset, const char *name); 538 void acpigen_write_create_qword_field(uint8_t op, size_t byte_offset, const char *name); 539 void acpigen_write_create_buffer_byte_field(const char *src_buf, size_t byte_offset, const char *name); 540 void acpigen_write_create_buffer_word_field(const char *src_buf, size_t byte_offset, const char *name); 541 void acpigen_write_create_buffer_dword_field(const char *src_buf, size_t byte_offset, const char *name); 542 void acpigen_write_create_buffer_qword_field(const char *src_buf, size_t byte_offset, const char *name); 543 void acpigen_write_field_name(const char *name, uint32_t size); 544 /* 545 * Generate ACPI AML code for _DSM method. 546 * This function takes as input uuid for the device, set of callbacks and 547 * argument to pass into the callbacks. Callbacks should ensure that Local0 and 548 * Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks. 549 * If the first callback is NULL, then a default implementation of Function 0 550 * will be autogenerated, returning a package of bits corresponding to the 551 * function callbacks that are non-NULL. 552 */ 553 void acpigen_write_dsm(const char *uuid, void (**callbacks)(void *), 554 size_t count, void *arg); 555 556 void acpigen_write_dsm_uuid_arr(struct dsm_uuid *ids, size_t count); 557 /* 558 * Generate ACPI AML code for _CPC (Continuous Performance Control). 559 * Execute the package function once to create a global table, then 560 * execute the method function within each processor object to 561 * create a method that points to the global table. 562 */ 563 void acpigen_write_CPPC_package(const struct cppc_config *config); 564 void acpigen_write_CPPC_method(void); 565 566 /* 567 * Generate ACPI AML code for _ROM method. 568 * This function takes as input ROM data and ROM length. 569 * The ROM length has to be multiple of 4096 and has to be less 570 * than the current implementation limit of 0x40000. 571 */ 572 void acpigen_write_rom(void *bios, const size_t length); 573 /* 574 * Generate ACPI AML code for OperationRegion 575 * This function takes input region name, region space, region offset & region 576 * length. 577 */ 578 void acpigen_write_opregion(const struct opregion *opreg); 579 /* 580 * Generate ACPI AML code for Mutex 581 * This function takes mutex name and initial value. 582 */ 583 void acpigen_write_mutex(const char *name, const uint8_t flags); 584 /* 585 * Generate ACPI AML code for Acquire 586 * This function takes mutex name and privilege value. 587 */ 588 void acpigen_write_acquire(const char *name, const uint16_t val); 589 /* 590 * Generate ACPI AML code for Release 591 * This function takes mutex name. 592 */ 593 void acpigen_write_release(const char *name); 594 /* 595 * Generate ACPI AML code for Field 596 * This function takes input region name, fieldlist, count & flags. 597 */ 598 void acpigen_write_field(const char *name, const struct fieldlist *l, size_t count, 599 uint8_t flags); 600 /* 601 * Generate ACPI AML code for IndexField 602 * This function takes input index name, data name, fieldlist, count & flags. 603 */ 604 void acpigen_write_indexfield(const char *idx, const char *data, 605 struct fieldlist *l, size_t count, uint8_t flags); 606 607 int get_cst_entries(const acpi_cstate_t **); 608 609 /* 610 * Get element from package into specified destination op: 611 * <dest_op> = DeRefOf (<package_op>[<element>]) 612 * 613 * Example: 614 * acpigen_get_package_op_element(ARG0_OP, 0, LOCAL0_OP) 615 * Local0 = DeRefOf (Arg0[0]) 616 */ 617 void acpigen_get_package_op_element(uint8_t package_op, unsigned int element, uint8_t dest_op); 618 619 /* Set element of package op to specified op: DeRefOf (<package>[<element>]) = <src> */ 620 void acpigen_set_package_op_element_int(uint8_t package_op, unsigned int element, uint64_t src); 621 622 /* Get element from package to specified op: <dest_op> = <package>[<element>] */ 623 void acpigen_get_package_element(const char *package, unsigned int element, uint8_t dest_op); 624 625 /* Set element of package to specified op: <package>[<element>] = <src> */ 626 void acpigen_set_package_element_int(const char *package, unsigned int element, uint64_t src); 627 628 /* Set element of package to specified namestr: <package>[<element>] = <src> */ 629 void acpigen_set_package_element_namestr(const char *package, unsigned int element, 630 const char *src); 631 632 /* 633 * Delay up to wait_ms milliseconds until the provided name matches the expected value. 634 * If wait_ms is >= 32ms then it will wait in 16ms chunks. This function uses LOCAL7_OP. 635 */ 636 void acpigen_write_delay_until_namestr_int(uint32_t wait_ms, const char *name, uint64_t value); 637 638 /* 639 * Soc-implemented functions for generating ACPI AML code for GPIO handling. All 640 * these functions are expected to use only Local5, Local6 and Local7 641 * variables. If the functions call into another ACPI method, then there is no 642 * restriction on the use of Local variables. In case of get/read functions, 643 * return value is expected to be stored in Local0 variable. 644 * 645 * All functions return 0 on success and -1 on error. 646 */ 647 648 /* Generate ACPI AML code to return Rx value of GPIO in Local0. */ 649 int acpigen_soc_read_rx_gpio(unsigned int gpio_num); 650 651 /* Generate ACPI AML code to return Tx value of GPIO in Local0. */ 652 int acpigen_soc_get_tx_gpio(unsigned int gpio_num); 653 654 /* Generate ACPI AML code to set Tx value of GPIO to 1. */ 655 int acpigen_soc_set_tx_gpio(unsigned int gpio_num); 656 657 /* Generate ACPI AML code to set Tx value of GPIO to 0. */ 658 int acpigen_soc_clear_tx_gpio(unsigned int gpio_num); 659 660 /* 661 * Helper functions for enabling/disabling Tx GPIOs based on the GPIO 662 * polarity. These functions end up calling acpigen_soc_{set,clear}_tx_gpio to 663 * make callbacks into SoC acpigen code. 664 * 665 * Returns 0 on success and -1 on error. 666 */ 667 int acpigen_enable_tx_gpio(const struct acpi_gpio *gpio); 668 int acpigen_disable_tx_gpio(const struct acpi_gpio *gpio); 669 670 /* 671 * Helper function for getting a RX GPIO value based on the GPIO polarity. 672 * The return value is stored in Local0 variable. 673 * This function ends up calling acpigen_soc_get_rx_gpio to make callbacks 674 * into SoC acpigen code 675 */ 676 void acpigen_get_rx_gpio(const struct acpi_gpio *gpio); 677 678 /* 679 * Helper function for getting a TX GPIO value based on the GPIO polarity. 680 * The return value is stored in Local0 variable. 681 * This function ends up calling acpigen_soc_get_tx_gpio to make callbacks 682 * into SoC acpigen code 683 */ 684 void acpigen_get_tx_gpio(const struct acpi_gpio *gpio); 685 686 /* refer to ACPI 6.4.3.5.3 Word Address Space Descriptor section for details */ 687 void acpigen_resource_word(u16 res_type, u16 gen_flags, u16 type_flags, u16 gran, 688 u16 range_min, u16 range_max, u16 translation, u16 length); 689 /* refer to ACPI 6.4.3.5.2 DWord Address Space Descriptor section for details */ 690 void acpigen_resource_dword(u16 res_type, u16 gen_flags, u16 type_flags, 691 u32 gran, u32 range_min, u32 range_max, u32 translation, u32 length); 692 /* refer to ACPI 6.4.3.5.1 QWord Address Space Descriptor section for details */ 693 void acpigen_resource_qword(u16 res_type, u16 gen_flags, u16 type_flags, 694 u64 gran, u64 range_min, u64 range_max, u64 translation, u64 length); 695 696 void acpigen_resource_producer_bus_number(u16 bus_base, u16 bus_limit); 697 void acpigen_resource_producer_io(u16 io_base, u16 io_limit); 698 void acpigen_resource_producer_mmio(u64 mmio_base, u64 mmio_limit, u16 type_flags); 699 void acpigen_resource_consumer_mmio(u64 mmio_base, u64 mmio_limit, u16 type_flags); 700 701 /* Emits Notify(namestr, value) */ 702 void acpigen_notify(const char *namestr, int value); 703 704 /* Create a namespace \OSFG to override the enabled sleep states */ 705 void acpigen_ssdt_override_sleep_states(bool enable_s1, bool enable_s2, bool enable_s3, 706 bool enable_s4); 707 708 #endif /* __ACPI_ACPIGEN_H__ */