1 // SPDX-License-Identifier: GPL-2.0
3 * Generation of ACPI (Advanced Configuration and Power Interface) tables
5 * Copyright 2019 Google LLC
6 * Mostly taken from coreboot
9 #define LOG_CATEGORY LOGC_ACPI
15 #include <acpi/acpigen.h>
16 #include <acpi/acpi_device.h>
17 #include <acpi/acpi_table.h>
21 #define ACPI_CPU_STRING "\\_PR.CP%02d"
23 u8 *acpigen_get_current(struct acpi_ctx *ctx)
28 void acpigen_emit_byte(struct acpi_ctx *ctx, uint data)
30 *(u8 *)ctx->current++ = data;
33 void acpigen_emit_word(struct acpi_ctx *ctx, uint data)
35 acpigen_emit_byte(ctx, data & 0xff);
36 acpigen_emit_byte(ctx, (data >> 8) & 0xff);
39 void acpigen_emit_dword(struct acpi_ctx *ctx, uint data)
41 /* Output the value in little-endian format */
42 acpigen_emit_byte(ctx, data & 0xff);
43 acpigen_emit_byte(ctx, (data >> 8) & 0xff);
44 acpigen_emit_byte(ctx, (data >> 16) & 0xff);
45 acpigen_emit_byte(ctx, (data >> 24) & 0xff);
49 * Maximum length for an ACPI object generated by this code,
51 * If you need to change this, change acpigen_write_len_f(ctx) and
52 * acpigen_pop_len(ctx)
54 #define ACPIGEN_MAXLEN 0xfffff
56 void acpigen_write_len_f(struct acpi_ctx *ctx)
58 assert(ctx->ltop < (ACPIGEN_LENSTACK_SIZE - 1));
59 ctx->len_stack[ctx->ltop++] = ctx->current;
60 acpigen_emit_byte(ctx, 0);
61 acpigen_emit_byte(ctx, 0);
62 acpigen_emit_byte(ctx, 0);
65 void acpigen_pop_len(struct acpi_ctx *ctx)
70 assert(ctx->ltop > 0);
71 p = ctx->len_stack[--ctx->ltop];
72 len = ctx->current - (void *)p;
73 assert(len <= ACPIGEN_MAXLEN);
74 /* generate store length for 0xfffff max */
75 p[0] = ACPI_PKG_LEN_3_BYTES | (len & 0xf);
76 p[1] = len >> 4 & 0xff;
77 p[2] = len >> 12 & 0xff;
80 void acpigen_emit_ext_op(struct acpi_ctx *ctx, uint op)
82 acpigen_emit_byte(ctx, EXT_OP_PREFIX);
83 acpigen_emit_byte(ctx, op);
86 char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el)
90 acpigen_emit_byte(ctx, PACKAGE_OP);
91 acpigen_write_len_f(ctx);
93 acpigen_emit_byte(ctx, nr_el);
98 void acpigen_write_byte(struct acpi_ctx *ctx, unsigned int data)
100 acpigen_emit_byte(ctx, BYTE_PREFIX);
101 acpigen_emit_byte(ctx, data & 0xff);
104 void acpigen_write_word(struct acpi_ctx *ctx, unsigned int data)
106 acpigen_emit_byte(ctx, WORD_PREFIX);
107 acpigen_emit_word(ctx, data);
110 void acpigen_write_dword(struct acpi_ctx *ctx, unsigned int data)
112 acpigen_emit_byte(ctx, DWORD_PREFIX);
113 acpigen_emit_dword(ctx, data);
116 void acpigen_write_qword(struct acpi_ctx *ctx, u64 data)
118 acpigen_emit_byte(ctx, QWORD_PREFIX);
119 acpigen_emit_dword(ctx, data & 0xffffffff);
120 acpigen_emit_dword(ctx, (data >> 32) & 0xffffffff);
123 void acpigen_write_zero(struct acpi_ctx *ctx)
125 acpigen_emit_byte(ctx, ZERO_OP);
128 void acpigen_write_one(struct acpi_ctx *ctx)
130 acpigen_emit_byte(ctx, ONE_OP);
133 void acpigen_write_integer(struct acpi_ctx *ctx, u64 data)
136 acpigen_write_zero(ctx);
138 acpigen_write_one(ctx);
139 else if (data <= 0xff)
140 acpigen_write_byte(ctx, (unsigned char)data);
141 else if (data <= 0xffff)
142 acpigen_write_word(ctx, (unsigned int)data);
143 else if (data <= 0xffffffff)
144 acpigen_write_dword(ctx, (unsigned int)data);
146 acpigen_write_qword(ctx, data);
149 void acpigen_write_name_zero(struct acpi_ctx *ctx, const char *name)
151 acpigen_write_name(ctx, name);
152 acpigen_write_zero(ctx);
155 void acpigen_write_name_one(struct acpi_ctx *ctx, const char *name)
157 acpigen_write_name(ctx, name);
158 acpigen_write_one(ctx);
161 void acpigen_write_name_byte(struct acpi_ctx *ctx, const char *name, uint val)
163 acpigen_write_name(ctx, name);
164 acpigen_write_byte(ctx, val);
167 void acpigen_write_name_word(struct acpi_ctx *ctx, const char *name, uint val)
169 acpigen_write_name(ctx, name);
170 acpigen_write_word(ctx, val);
173 void acpigen_write_name_dword(struct acpi_ctx *ctx, const char *name, uint val)
175 acpigen_write_name(ctx, name);
176 acpigen_write_dword(ctx, val);
179 void acpigen_write_name_qword(struct acpi_ctx *ctx, const char *name, u64 val)
181 acpigen_write_name(ctx, name);
182 acpigen_write_qword(ctx, val);
185 void acpigen_write_name_integer(struct acpi_ctx *ctx, const char *name, u64 val)
187 acpigen_write_name(ctx, name);
188 acpigen_write_integer(ctx, val);
191 void acpigen_write_name_string(struct acpi_ctx *ctx, const char *name,
194 acpigen_write_name(ctx, name);
195 acpigen_write_string(ctx, string);
198 void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size)
202 for (i = 0; i < size; i++)
203 acpigen_emit_byte(ctx, data[i]);
206 void acpigen_emit_string(struct acpi_ctx *ctx, const char *str)
208 acpigen_emit_stream(ctx, str, str ? strlen(str) : 0);
209 acpigen_emit_byte(ctx, '\0');
212 void acpigen_write_string(struct acpi_ctx *ctx, const char *str)
214 acpigen_emit_byte(ctx, STRING_PREFIX);
215 acpigen_emit_string(ctx, str);
219 * The naming conventions for ACPI namespace names are a bit tricky as
220 * each element has to be 4 chars wide ("All names are a fixed 32 bits.")
221 * and "By convention, when an ASL compiler pads a name shorter than 4
222 * characters, it is done so with trailing underscores ('_')".
224 * Check sections 5.3, 20.2.2 and 20.4 of ACPI spec 6.3 for details.
226 static void acpigen_emit_simple_namestring(struct acpi_ctx *ctx,
232 for (i = 0, ptr = name; i < 4; i++) {
233 if (!*ptr || *ptr == '.')
234 acpigen_emit_byte(ctx, '_');
236 acpigen_emit_byte(ctx, *ptr++);
240 static void acpigen_emit_double_namestring(struct acpi_ctx *ctx,
241 const char *name, int dotpos)
243 acpigen_emit_byte(ctx, DUAL_NAME_PREFIX);
244 acpigen_emit_simple_namestring(ctx, name);
245 acpigen_emit_simple_namestring(ctx, &name[dotpos + 1]);
248 static void acpigen_emit_multi_namestring(struct acpi_ctx *ctx,
251 unsigned char *pathlen;
254 acpigen_emit_byte(ctx, MULTI_NAME_PREFIX);
255 pathlen = ctx->current;
256 acpigen_emit_byte(ctx, 0);
259 acpigen_emit_simple_namestring(ctx, name);
260 /* find end or next entity */
261 while (*name != '.' && *name)
263 /* forward to next */
272 void acpigen_emit_namestring(struct acpi_ctx *ctx, const char *namepath)
278 /* We can start with a '\' */
279 if (*namepath == '\\') {
280 acpigen_emit_byte(ctx, '\\');
284 /* And there can be any number of '^' */
285 while (*namepath == '^') {
286 acpigen_emit_byte(ctx, '^');
290 for (i = 0, dotcount = 0; namepath[i]; i++) {
291 if (namepath[i] == '.') {
297 /* If we have only \\ or only ^* then we need to add a null name */
299 acpigen_emit_byte(ctx, ZERO_OP);
300 else if (dotcount == 0)
301 acpigen_emit_simple_namestring(ctx, namepath);
302 else if (dotcount == 1)
303 acpigen_emit_double_namestring(ctx, namepath, dotpos);
305 acpigen_emit_multi_namestring(ctx, namepath);
308 void acpigen_write_name(struct acpi_ctx *ctx, const char *namepath)
310 acpigen_emit_byte(ctx, NAME_OP);
311 acpigen_emit_namestring(ctx, namepath);
314 void acpigen_write_scope(struct acpi_ctx *ctx, const char *scope)
316 acpigen_emit_byte(ctx, SCOPE_OP);
317 acpigen_write_len_f(ctx);
318 acpigen_emit_namestring(ctx, scope);
321 static void acpigen_write_method_internal(struct acpi_ctx *ctx,
322 const char *name, uint flags)
324 acpigen_emit_byte(ctx, METHOD_OP);
325 acpigen_write_len_f(ctx);
326 acpigen_emit_namestring(ctx, name);
327 acpigen_emit_byte(ctx, flags);
330 /* Method (name, nargs, NotSerialized) */
331 void acpigen_write_method(struct acpi_ctx *ctx, const char *name, int nargs)
333 acpigen_write_method_internal(ctx, name,
334 nargs & ACPI_METHOD_NARGS_MASK);
337 /* Method (name, nargs, Serialized) */
338 void acpigen_write_method_serialized(struct acpi_ctx *ctx, const char *name,
341 acpigen_write_method_internal(ctx, name,
342 (nargs & ACPI_METHOD_NARGS_MASK) |
343 ACPI_METHOD_SERIALIZED_MASK);
346 void acpigen_write_processor(struct acpi_ctx *ctx, uint cpuindex,
347 u32 pblock_addr, uint pblock_len)
350 * Processor (\_PR.CPnn, cpuindex, pblock_addr, pblock_len)
355 acpigen_emit_ext_op(ctx, PROCESSOR_OP);
356 acpigen_write_len_f(ctx);
358 snprintf(pscope, sizeof(pscope), ACPI_CPU_STRING, cpuindex);
359 acpigen_emit_namestring(ctx, pscope);
360 acpigen_emit_byte(ctx, cpuindex);
361 acpigen_emit_dword(ctx, pblock_addr);
362 acpigen_emit_byte(ctx, pblock_len);
365 void acpigen_write_processor_package(struct acpi_ctx *ctx,
366 const char *const name,
367 const uint first_core,
368 const uint core_count)
373 acpigen_write_name(ctx, name);
374 acpigen_write_package(ctx, core_count);
375 for (i = first_core; i < first_core + core_count; ++i) {
376 snprintf(pscope, sizeof(pscope), ACPI_CPU_STRING, i);
377 acpigen_emit_namestring(ctx, pscope);
379 acpigen_pop_len(ctx);
382 void acpigen_write_processor_cnot(struct acpi_ctx *ctx, const uint num_cores)
386 acpigen_write_method(ctx, "\\_PR.CNOT", 1);
387 for (core_id = 0; core_id < num_cores; core_id++) {
390 snprintf(buffer, sizeof(buffer), ACPI_CPU_STRING, core_id);
391 acpigen_emit_byte(ctx, NOTIFY_OP);
392 acpigen_emit_namestring(ctx, buffer);
393 acpigen_emit_byte(ctx, ARG0_OP);
395 acpigen_pop_len(ctx);
398 void acpigen_write_device(struct acpi_ctx *ctx, const char *name)
400 acpigen_emit_ext_op(ctx, DEVICE_OP);
401 acpigen_write_len_f(ctx);
402 acpigen_emit_namestring(ctx, name);
405 void acpigen_write_sta(struct acpi_ctx *ctx, uint status)
407 /* Method (_STA, 0, NotSerialized) { Return (status) } */
408 acpigen_write_method(ctx, "_STA", 0);
409 acpigen_emit_byte(ctx, RETURN_OP);
410 acpigen_write_byte(ctx, status);
411 acpigen_pop_len(ctx);
414 static void acpigen_write_register(struct acpi_ctx *ctx,
415 const struct acpi_gen_regaddr *addr)
417 /* See ACPI v6.3 section 6.4.3.7: Generic Register Descriptor */
418 acpigen_emit_byte(ctx, ACPI_DESCRIPTOR_REGISTER);
419 acpigen_emit_byte(ctx, 0x0c); /* Register Length 7:0 */
420 acpigen_emit_byte(ctx, 0x00); /* Register Length 15:8 */
421 acpigen_emit_byte(ctx, addr->space_id);
422 acpigen_emit_byte(ctx, addr->bit_width);
423 acpigen_emit_byte(ctx, addr->bit_offset);
424 acpigen_emit_byte(ctx, addr->access_size);
425 acpigen_emit_dword(ctx, addr->addrl);
426 acpigen_emit_dword(ctx, addr->addrh);
429 void acpigen_write_resourcetemplate_header(struct acpi_ctx *ctx)
432 * A ResourceTemplate() is a Buffer() with a
433 * (Byte|Word|DWord) containing the length, followed by one or more
434 * resource items, terminated by the end tag.
435 * (small item 0xf, len 1)
437 acpigen_emit_byte(ctx, BUFFER_OP);
438 acpigen_write_len_f(ctx);
439 acpigen_emit_byte(ctx, WORD_PREFIX);
440 ctx->len_stack[ctx->ltop++] = ctx->current;
443 * Add two dummy bytes for the ACPI word (keep aligned with the
444 * calculation in acpigen_write_resourcetemplate_footer() below)
446 acpigen_emit_byte(ctx, 0x00);
447 acpigen_emit_byte(ctx, 0x00);
450 void acpigen_write_resourcetemplate_footer(struct acpi_ctx *ctx)
452 char *p = ctx->len_stack[--ctx->ltop];
455 * See ACPI v6.3 section 6.4.2.9: End Tag
457 * 0x00 is treated as a good checksum according to the spec
458 * and is what iasl generates.
460 acpigen_emit_byte(ctx, ACPI_END_TAG);
461 acpigen_emit_byte(ctx, 0x00);
464 * Start counting past the 2-bytes length added in
465 * acpigen_write_resourcetemplate_header() above
467 len = (char *)ctx->current - (p + 2);
471 p[1] = (len >> 8) & 0xff;
473 acpigen_pop_len(ctx);
476 void acpigen_write_register_resource(struct acpi_ctx *ctx,
477 const struct acpi_gen_regaddr *addr)
479 acpigen_write_resourcetemplate_header(ctx);
480 acpigen_write_register(ctx, addr);
481 acpigen_write_resourcetemplate_footer(ctx);
484 void acpigen_write_prw(struct acpi_ctx *ctx, uint wake, uint level)
486 /* Name (_PRW, Package () { wake, level } */
487 acpigen_write_name(ctx, "_PRW");
488 acpigen_write_package(ctx, 2);
489 acpigen_write_integer(ctx, wake);
490 acpigen_write_integer(ctx, level);
491 acpigen_pop_len(ctx);
497 * ACPI 6.3 Section 19.6.142 table 19-438 defines a special output order for the
498 * bytes that make up a UUID Buffer object:
500 * UUID byte order for input to this function:
501 * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp
503 * UUID byte order output by this function:
504 * ddccbbaa-ffee-hhgg-iijj-kkllmmnnoopp
506 int acpigen_write_uuid(struct acpi_ctx *ctx, const char *uuid)
508 u8 buf[UUID_BIN_LEN];
511 /* Parse UUID string into bytes */
512 ret = uuid_str_to_bin(uuid, buf, UUID_STR_FORMAT_GUID);
514 return log_msg_ret("bad hex", -EINVAL);
517 acpigen_emit_byte(ctx, BUFFER_OP);
518 acpigen_write_len_f(ctx);
520 /* Buffer length in bytes */
521 acpigen_write_word(ctx, UUID_BIN_LEN);
523 /* Output UUID in expected order */
524 acpigen_emit_stream(ctx, (char *)buf, UUID_BIN_LEN);
526 acpigen_pop_len(ctx);
531 void acpigen_write_power_res(struct acpi_ctx *ctx, const char *name, uint level,
532 uint order, const char *const dev_states[],
533 size_t dev_states_count)
537 for (i = 0; i < dev_states_count; i++) {
538 acpigen_write_name(ctx, dev_states[i]);
539 acpigen_write_package(ctx, 1);
540 acpigen_emit_simple_namestring(ctx, name);
541 acpigen_pop_len(ctx); /* Package */
544 acpigen_emit_ext_op(ctx, POWER_RES_OP);
546 acpigen_write_len_f(ctx);
548 acpigen_emit_simple_namestring(ctx, name);
549 acpigen_emit_byte(ctx, level);
550 acpigen_emit_word(ctx, order);
554 void acpigen_write_sleep(struct acpi_ctx *ctx, u64 sleep_ms)
556 acpigen_emit_ext_op(ctx, SLEEP_OP);
557 acpigen_write_integer(ctx, sleep_ms);
560 void acpigen_write_store(struct acpi_ctx *ctx)
562 acpigen_emit_byte(ctx, STORE_OP);
565 /* Or (arg1, arg2, res) */
566 void acpigen_write_or(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res)
568 acpigen_emit_byte(ctx, OR_OP);
569 acpigen_emit_byte(ctx, arg1);
570 acpigen_emit_byte(ctx, arg2);
571 acpigen_emit_byte(ctx, res);
574 /* And (arg1, arg2, res) */
575 void acpigen_write_and(struct acpi_ctx *ctx, u8 arg1, u8 arg2, u8 res)
577 acpigen_emit_byte(ctx, AND_OP);
578 acpigen_emit_byte(ctx, arg1);
579 acpigen_emit_byte(ctx, arg2);
580 acpigen_emit_byte(ctx, res);
584 void acpigen_write_not(struct acpi_ctx *ctx, u8 arg, u8 res)
586 acpigen_emit_byte(ctx, NOT_OP);
587 acpigen_emit_byte(ctx, arg);
588 acpigen_emit_byte(ctx, res);
591 /* Store (str, DEBUG) */
592 void acpigen_write_debug_string(struct acpi_ctx *ctx, const char *str)
594 acpigen_write_store(ctx);
595 acpigen_write_string(ctx, str);
596 acpigen_emit_ext_op(ctx, DEBUG_OP);
599 void acpigen_write_if(struct acpi_ctx *ctx)
601 acpigen_emit_byte(ctx, IF_OP);
602 acpigen_write_len_f(ctx);
605 void acpigen_write_if_lequal_op_int(struct acpi_ctx *ctx, uint op, u64 val)
607 acpigen_write_if(ctx);
608 acpigen_emit_byte(ctx, LEQUAL_OP);
609 acpigen_emit_byte(ctx, op);
610 acpigen_write_integer(ctx, val);
613 void acpigen_write_else(struct acpi_ctx *ctx)
615 acpigen_emit_byte(ctx, ELSE_OP);
616 acpigen_write_len_f(ctx);
619 void acpigen_write_to_buffer(struct acpi_ctx *ctx, uint src, uint dst)
621 acpigen_emit_byte(ctx, TO_BUFFER_OP);
622 acpigen_emit_byte(ctx, src);
623 acpigen_emit_byte(ctx, dst);
626 void acpigen_write_to_integer(struct acpi_ctx *ctx, uint src, uint dst)
628 acpigen_emit_byte(ctx, TO_INTEGER_OP);
629 acpigen_emit_byte(ctx, src);
630 acpigen_emit_byte(ctx, dst);
633 void acpigen_write_byte_buffer(struct acpi_ctx *ctx, u8 *arr, size_t size)
637 acpigen_emit_byte(ctx, BUFFER_OP);
638 acpigen_write_len_f(ctx);
639 acpigen_write_integer(ctx, size);
641 for (i = 0; i < size; i++)
642 acpigen_emit_byte(ctx, arr[i]);
644 acpigen_pop_len(ctx);
647 void acpigen_write_return_byte_buffer(struct acpi_ctx *ctx, u8 *arr,
650 acpigen_emit_byte(ctx, RETURN_OP);
651 acpigen_write_byte_buffer(ctx, arr, size);
654 void acpigen_write_return_singleton_buffer(struct acpi_ctx *ctx, uint arg)
658 acpigen_write_return_byte_buffer(ctx, &buf, 1);
661 void acpigen_write_return_byte(struct acpi_ctx *ctx, uint arg)
663 acpigen_emit_byte(ctx, RETURN_OP);
664 acpigen_write_byte(ctx, arg);
667 void acpigen_write_dsm_start(struct acpi_ctx *ctx)
669 /* Method (_DSM, 4, Serialized) */
670 acpigen_write_method_serialized(ctx, "_DSM", 4);
672 /* ToBuffer (Arg0, Local0) */
673 acpigen_write_to_buffer(ctx, ARG0_OP, LOCAL0_OP);
676 int acpigen_write_dsm_uuid_start(struct acpi_ctx *ctx, const char *uuid)
680 /* If (LEqual (Local0, ToUUID(uuid))) */
681 acpigen_write_if(ctx);
682 acpigen_emit_byte(ctx, LEQUAL_OP);
683 acpigen_emit_byte(ctx, LOCAL0_OP);
684 ret = acpigen_write_uuid(ctx, uuid);
686 return log_msg_ret("uuid", ret);
688 /* ToInteger (Arg2, Local1) */
689 acpigen_write_to_integer(ctx, ARG2_OP, LOCAL1_OP);
694 void acpigen_write_dsm_uuid_start_cond(struct acpi_ctx *ctx, int seq)
696 /* If (LEqual (Local1, i)) */
697 acpigen_write_if_lequal_op_int(ctx, LOCAL1_OP, seq);
700 void acpigen_write_dsm_uuid_end_cond(struct acpi_ctx *ctx)
702 acpigen_pop_len(ctx); /* If */
705 void acpigen_write_dsm_uuid_end(struct acpi_ctx *ctx)
707 /* Default case: Return (Buffer (One) { 0x0 }) */
708 acpigen_write_return_singleton_buffer(ctx, 0x0);
710 acpigen_pop_len(ctx); /* If (LEqual (Local0, ToUUID(uuid))) */
713 void acpigen_write_dsm_end(struct acpi_ctx *ctx)
715 /* Return (Buffer (One) { 0x0 }) */
716 acpigen_write_return_singleton_buffer(ctx, 0x0);
718 acpigen_pop_len(ctx); /* Method _DSM */
722 * acpigen_get_dw0_in_local5() - Generate code to put dw0 cfg0 in local5
724 * Store (\_SB.GPC0 (addr), Local5)
726 * \_SB.GPC0 is used to read cfg0 value from dw0. It is typically defined in
727 * the board's gpiolib.asl
729 * The value needs to be stored in a local variable so that it can be used in
730 * expressions in the ACPI code.
732 * @ctx: ACPI context pointer
733 * @dw0_read: Name to use to read dw0, e.g. "\\_SB.GPC0"
734 * @addr: GPIO pin configuration register address
737 static void acpigen_get_dw0_in_local5(struct acpi_ctx *ctx,
738 const char *dw0_read, ulong addr)
740 acpigen_write_store(ctx);
741 acpigen_emit_namestring(ctx, dw0_read);
742 acpigen_write_integer(ctx, addr);
743 acpigen_emit_byte(ctx, LOCAL5_OP);
747 * acpigen_set_gpio_val() - Emit code to set value of TX GPIO to on/off
749 * @ctx: ACPI context pointer
750 * @dw0_read: Method name to use to read dw0, e.g. "\\_SB.GPC0"
751 * @dw0_write: Method name to use to read dw0, e.g. "\\_SB.SPC0"
752 * @gpio_num: GPIO number to adjust
753 * @vaL: true to set on, false to set off
755 static int acpigen_set_gpio_val(struct acpi_ctx *ctx, u32 tx_state_val,
756 const char *dw0_read, const char *dw0_write,
757 struct acpi_gpio *gpio, bool val)
759 acpigen_get_dw0_in_local5(ctx, dw0_read, gpio->pin0_addr);
761 /* Store (0x40, Local0) */
762 acpigen_write_store(ctx);
763 acpigen_write_integer(ctx, tx_state_val);
764 acpigen_emit_byte(ctx, LOCAL0_OP);
767 /* Or (Local5, PAD_CFG0_TX_STATE, Local5) */
768 acpigen_write_or(ctx, LOCAL5_OP, LOCAL0_OP, LOCAL5_OP);
770 /* Not (PAD_CFG0_TX_STATE, Local6) */
771 acpigen_write_not(ctx, LOCAL0_OP, LOCAL6_OP);
773 /* And (Local5, Local6, Local5) */
774 acpigen_write_and(ctx, LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
778 * \_SB.SPC0 (addr, Local5)
779 * \_SB.SPC0 is used to write cfg0 value in dw0. It is defined in
782 acpigen_emit_namestring(ctx, dw0_write);
783 acpigen_write_integer(ctx, gpio->pin0_addr);
784 acpigen_emit_byte(ctx, LOCAL5_OP);
789 int acpigen_set_enable_tx_gpio(struct acpi_ctx *ctx, u32 tx_state_val,
790 const char *dw0_read, const char *dw0_write,
791 struct acpi_gpio *gpio, bool enable)
796 set = gpio->polarity == ACPI_GPIO_ACTIVE_HIGH ? enable : !enable;
797 ret = acpigen_set_gpio_val(ctx, tx_state_val, dw0_read, dw0_write, gpio,
800 return log_msg_ret("call", ret);