Simon Glass | 98528d4 | 2020-07-07 13:11:42 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Core ACPI (Advanced Configuration and Power Interface) support |
| 4 | * |
| 5 | * Copyright 2019 Google LLC |
| 6 | * |
| 7 | * Modified from coreboot file acpigen.h |
| 8 | */ |
| 9 | |
| 10 | #ifndef __ACPI_ACPIGEN_H |
| 11 | #define __ACPI_ACPIGEN_H |
| 12 | |
| 13 | #include <linux/types.h> |
| 14 | |
| 15 | struct acpi_ctx; |
| 16 | |
Simon Glass | 0f27763 | 2020-07-07 13:11:50 -0600 | [diff] [blame] | 17 | /* Top 4 bits of the value used to indicate a three-byte length value */ |
| 18 | #define ACPI_PKG_LEN_3_BYTES 0x80 |
| 19 | |
Simon Glass | edc2680 | 2020-07-07 13:11:51 -0600 | [diff] [blame] | 20 | /* ACPI Op/Prefix codes */ |
| 21 | enum { |
Simon Glass | 8715ce0 | 2020-07-07 13:11:52 -0600 | [diff] [blame^] | 22 | ZERO_OP = 0x00, |
| 23 | ONE_OP = 0x01, |
| 24 | BYTE_PREFIX = 0x0a, |
| 25 | WORD_PREFIX = 0x0b, |
| 26 | DWORD_PREFIX = 0x0c, |
| 27 | QWORD_PREFIX = 0x0e, |
Simon Glass | edc2680 | 2020-07-07 13:11:51 -0600 | [diff] [blame] | 28 | PACKAGE_OP = 0x12, |
| 29 | }; |
| 30 | |
Simon Glass | 98528d4 | 2020-07-07 13:11:42 -0600 | [diff] [blame] | 31 | /** |
| 32 | * acpigen_get_current() - Get the current ACPI code output pointer |
| 33 | * |
| 34 | * @ctx: ACPI context pointer |
| 35 | * @return output pointer |
| 36 | */ |
| 37 | u8 *acpigen_get_current(struct acpi_ctx *ctx); |
| 38 | |
| 39 | /** |
| 40 | * acpigen_emit_byte() - Emit a byte to the ACPI code |
| 41 | * |
| 42 | * @ctx: ACPI context pointer |
| 43 | * @data: Value to output |
| 44 | */ |
| 45 | void acpigen_emit_byte(struct acpi_ctx *ctx, uint data); |
| 46 | |
| 47 | /** |
| 48 | * acpigen_emit_word() - Emit a 16-bit word to the ACPI code |
| 49 | * |
| 50 | * @ctx: ACPI context pointer |
| 51 | * @data: Value to output |
| 52 | */ |
| 53 | void acpigen_emit_word(struct acpi_ctx *ctx, uint data); |
| 54 | |
| 55 | /** |
| 56 | * acpigen_emit_dword() - Emit a 32-bit 'double word' to the ACPI code |
| 57 | * |
| 58 | * @ctx: ACPI context pointer |
| 59 | * @data: Value to output |
| 60 | */ |
| 61 | void acpigen_emit_dword(struct acpi_ctx *ctx, uint data); |
| 62 | |
Simon Glass | 071c4a5 | 2020-07-07 13:11:45 -0600 | [diff] [blame] | 63 | /** |
| 64 | * acpigen_emit_stream() - Emit a stream of bytes |
| 65 | * |
| 66 | * @ctx: ACPI context pointer |
| 67 | * @data: Data to output |
| 68 | * @size: Size of data in bytes |
| 69 | */ |
| 70 | void acpigen_emit_stream(struct acpi_ctx *ctx, const char *data, int size); |
| 71 | |
| 72 | /** |
| 73 | * acpigen_emit_string() - Emit a string |
| 74 | * |
| 75 | * Emit a string with a null terminator |
| 76 | * |
| 77 | * @ctx: ACPI context pointer |
| 78 | * @str: String to output, or NULL for an empty string |
| 79 | */ |
| 80 | void acpigen_emit_string(struct acpi_ctx *ctx, const char *str); |
| 81 | |
Simon Glass | 0f27763 | 2020-07-07 13:11:50 -0600 | [diff] [blame] | 82 | /** |
| 83 | * acpigen_write_len_f() - Write a 'forward' length placeholder |
| 84 | * |
| 85 | * This adds space for a length value in the ACPI stream and pushes the current |
| 86 | * position (before the length) on the stack. After calling this you can write |
| 87 | * some data and then call acpigen_pop_len() to update the length value. |
| 88 | * |
| 89 | * Usage: |
| 90 | * |
| 91 | * acpigen_write_len_f() ------\ |
| 92 | * acpigen_write...() | |
| 93 | * acpigen_write...() | |
| 94 | * acpigen_write_len_f() --\ | |
| 95 | * acpigen_write...() | | |
| 96 | * acpigen_write...() | | |
| 97 | * acpigen_pop_len() ------/ | |
| 98 | * acpigen_write...() | |
| 99 | * acpigen_pop_len() ----------/ |
| 100 | * |
| 101 | * See ACPI 6.3 section 20.2.4 Package Length Encoding |
| 102 | * |
| 103 | * This implementation always uses a 3-byte packet length for simplicity. It |
| 104 | * could be adjusted to support other lengths. |
| 105 | * |
| 106 | * @ctx: ACPI context pointer |
| 107 | */ |
| 108 | void acpigen_write_len_f(struct acpi_ctx *ctx); |
| 109 | |
| 110 | /** |
| 111 | * acpigen_pop_len() - Update the previously stacked length placeholder |
| 112 | * |
| 113 | * Call this after the data for the block has been written. It updates the |
| 114 | * top length value in the stack and pops it off. |
| 115 | * |
| 116 | * @ctx: ACPI context pointer |
| 117 | */ |
| 118 | void acpigen_pop_len(struct acpi_ctx *ctx); |
| 119 | |
Simon Glass | edc2680 | 2020-07-07 13:11:51 -0600 | [diff] [blame] | 120 | /** |
| 121 | * acpigen_write_package() - Start writing a package |
| 122 | * |
| 123 | * A package collects together a number of elements in the ACPI code. To write |
| 124 | * a package use: |
| 125 | * |
| 126 | * acpigen_write_package(ctx, 3); |
| 127 | * ...write things |
| 128 | * acpigen_pop_len() |
| 129 | * |
| 130 | * If you don't know the number of elements in advance, acpigen_write_package() |
| 131 | * returns a pointer to the value so you can update it later: |
| 132 | * |
| 133 | * char *num_elements = acpigen_write_package(ctx, 0); |
| 134 | * ...write things |
| 135 | * *num_elements += 1; |
| 136 | * ...write things |
| 137 | * *num_elements += 1; |
| 138 | * acpigen_pop_len() |
| 139 | * |
| 140 | * @ctx: ACPI context pointer |
| 141 | * @nr_el: Number of elements (0 if not known) |
| 142 | * @returns pointer to the number of elements, which can be updated by the |
| 143 | * caller if needed |
| 144 | */ |
| 145 | char *acpigen_write_package(struct acpi_ctx *ctx, int nr_el); |
| 146 | |
Simon Glass | 8715ce0 | 2020-07-07 13:11:52 -0600 | [diff] [blame^] | 147 | /** |
| 148 | * acpigen_write_integer() - Write an integer |
| 149 | * |
| 150 | * This writes an operation (BYTE_OP, WORD_OP, DWORD_OP, QWORD_OP depending on |
| 151 | * the integer size) and an integer value. Note that WORD means 16 bits in ACPI. |
| 152 | * |
| 153 | * @ctx: ACPI context pointer |
| 154 | * @data: Integer to write |
| 155 | */ |
| 156 | void acpigen_write_integer(struct acpi_ctx *ctx, u64 data); |
| 157 | |
Simon Glass | 98528d4 | 2020-07-07 13:11:42 -0600 | [diff] [blame] | 158 | #endif |