Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 2 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 3 | /* How much nesting do we support? */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 4 | #define ACPIGEN_LENSTACK_SIZE 10 |
| 5 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 6 | /* |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 7 | * If you need to change this, change acpigen_write_len_f and |
Vladimir Serbinenko | 8104da7 | 2014-11-09 03:33:51 +0100 | [diff] [blame] | 8 | * acpigen_pop_len |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 9 | */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 10 | |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 11 | #define ACPIGEN_MAXLEN 0xfffff |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 12 | |
Duncan Laurie | 3829f23 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 13 | #include <lib.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 14 | #include <string.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 15 | #include <acpi/acpigen.h> |
Elyes HAOUAS | cd4fe0f | 2019-03-29 17:12:15 +0100 | [diff] [blame] | 16 | #include <assert.h> |
Tim Wawrzynczak | d96f3a2 | 2021-07-14 15:56:57 -0600 | [diff] [blame] | 17 | #include <commonlib/helpers.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 18 | #include <console/console.h> |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 19 | #include <device/device.h> |
Duncan Laurie | 08a942f | 2020-04-29 12:13:14 -0700 | [diff] [blame] | 20 | #include <device/soundwire.h> |
Elyes HAOUAS | cdd2f63 | 2021-02-11 19:37:11 +0100 | [diff] [blame] | 21 | #include <types.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 22 | |
| 23 | static char *gencurrent; |
| 24 | |
| 25 | char *len_stack[ACPIGEN_LENSTACK_SIZE]; |
| 26 | int ltop = 0; |
| 27 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 28 | void acpigen_write_len_f(void) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 29 | { |
| 30 | ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1)) |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 31 | len_stack[ltop++] = gencurrent; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 32 | acpigen_emit_byte(0); |
| 33 | acpigen_emit_byte(0); |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 34 | acpigen_emit_byte(0); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 35 | } |
| 36 | |
Vladimir Serbinenko | 430363a | 2014-11-02 21:51:22 +0100 | [diff] [blame] | 37 | void acpigen_pop_len(void) |
| 38 | { |
| 39 | int len; |
| 40 | ASSERT(ltop > 0) |
| 41 | char *p = len_stack[--ltop]; |
| 42 | len = gencurrent - p; |
| 43 | ASSERT(len <= ACPIGEN_MAXLEN) |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 44 | /* generate store length for 0xfffff max */ |
| 45 | p[0] = (0x80 | (len & 0xf)); |
Vladimir Serbinenko | 430363a | 2014-11-02 21:51:22 +0100 | [diff] [blame] | 46 | p[1] = (len >> 4 & 0xff); |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 47 | p[2] = (len >> 12 & 0xff); |
Vladimir Serbinenko | 430363a | 2014-11-02 21:51:22 +0100 | [diff] [blame] | 48 | |
| 49 | } |
| 50 | |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 51 | void acpigen_set_current(char *curr) |
| 52 | { |
| 53 | gencurrent = curr; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 56 | char *acpigen_get_current(void) |
| 57 | { |
| 58 | return gencurrent; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 59 | } |
| 60 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 61 | void acpigen_emit_byte(unsigned char b) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 62 | { |
| 63 | (*gencurrent++) = b; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 66 | void acpigen_emit_ext_op(uint8_t op) |
| 67 | { |
| 68 | acpigen_emit_byte(EXT_OP_PREFIX); |
| 69 | acpigen_emit_byte(op); |
| 70 | } |
| 71 | |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 72 | void acpigen_emit_word(unsigned int data) |
| 73 | { |
| 74 | acpigen_emit_byte(data & 0xff); |
| 75 | acpigen_emit_byte((data >> 8) & 0xff); |
| 76 | } |
| 77 | |
| 78 | void acpigen_emit_dword(unsigned int data) |
| 79 | { |
| 80 | acpigen_emit_byte(data & 0xff); |
| 81 | acpigen_emit_byte((data >> 8) & 0xff); |
| 82 | acpigen_emit_byte((data >> 16) & 0xff); |
| 83 | acpigen_emit_byte((data >> 24) & 0xff); |
| 84 | } |
| 85 | |
Duncan Laurie | 85d8027 | 2016-07-02 19:53:54 -0700 | [diff] [blame] | 86 | char *acpigen_write_package(int nr_el) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 87 | { |
Duncan Laurie | 85d8027 | 2016-07-02 19:53:54 -0700 | [diff] [blame] | 88 | char *p; |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 89 | acpigen_emit_byte(PACKAGE_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 90 | acpigen_write_len_f(); |
Duncan Laurie | 85d8027 | 2016-07-02 19:53:54 -0700 | [diff] [blame] | 91 | p = acpigen_get_current(); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 92 | acpigen_emit_byte(nr_el); |
Duncan Laurie | 85d8027 | 2016-07-02 19:53:54 -0700 | [diff] [blame] | 93 | return p; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 94 | } |
| 95 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 96 | void acpigen_write_byte(unsigned int data) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 97 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 98 | acpigen_emit_byte(BYTE_PREFIX); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 99 | acpigen_emit_byte(data & 0xff); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 102 | void acpigen_write_word(unsigned int data) |
| 103 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 104 | acpigen_emit_byte(WORD_PREFIX); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 105 | acpigen_emit_word(data); |
| 106 | } |
| 107 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 108 | void acpigen_write_dword(unsigned int data) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 109 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 110 | acpigen_emit_byte(DWORD_PREFIX); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 111 | acpigen_emit_dword(data); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 112 | } |
| 113 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 114 | void acpigen_write_qword(uint64_t data) |
Carl-Daniel Hailfinger | d58671c | 2009-02-17 21:38:51 +0000 | [diff] [blame] | 115 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 116 | acpigen_emit_byte(QWORD_PREFIX); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 117 | acpigen_emit_dword(data & 0xffffffff); |
| 118 | acpigen_emit_dword((data >> 32) & 0xffffffff); |
Carl-Daniel Hailfinger | d58671c | 2009-02-17 21:38:51 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 121 | void acpigen_write_zero(void) |
| 122 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 123 | acpigen_emit_byte(ZERO_OP); |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void acpigen_write_one(void) |
| 127 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 128 | acpigen_emit_byte(ONE_OP); |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | void acpigen_write_ones(void) |
| 132 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 133 | acpigen_emit_byte(ONES_OP); |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void acpigen_write_integer(uint64_t data) |
| 137 | { |
| 138 | if (data == 0) |
| 139 | acpigen_write_zero(); |
| 140 | else if (data == 1) |
| 141 | acpigen_write_one(); |
| 142 | else if (data <= 0xff) |
| 143 | acpigen_write_byte((unsigned char)data); |
| 144 | else if (data <= 0xffff) |
| 145 | acpigen_write_word((unsigned int)data); |
| 146 | else if (data <= 0xffffffff) |
| 147 | acpigen_write_dword((unsigned int)data); |
| 148 | else |
| 149 | acpigen_write_qword(data); |
| 150 | } |
| 151 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 152 | void acpigen_write_name_byte(const char *name, uint8_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 153 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 154 | acpigen_write_name(name); |
| 155 | acpigen_write_byte(val); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 156 | } |
| 157 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 158 | void acpigen_write_name_dword(const char *name, uint32_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 159 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 160 | acpigen_write_name(name); |
| 161 | acpigen_write_dword(val); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 162 | } |
| 163 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 164 | void acpigen_write_name_qword(const char *name, uint64_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 165 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 166 | acpigen_write_name(name); |
| 167 | acpigen_write_qword(val); |
Carl-Daniel Hailfinger | d58671c | 2009-02-17 21:38:51 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 170 | void acpigen_write_name_integer(const char *name, uint64_t val) |
| 171 | { |
| 172 | acpigen_write_name(name); |
| 173 | acpigen_write_integer(val); |
| 174 | } |
| 175 | |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 176 | void acpigen_write_name_string(const char *name, const char *string) |
| 177 | { |
| 178 | acpigen_write_name(name); |
| 179 | acpigen_write_string(string); |
| 180 | } |
| 181 | |
Patrick Rudolph | 389c827 | 2019-12-17 13:54:41 +0100 | [diff] [blame] | 182 | void acpigen_write_name_unicode(const char *name, const char *string) |
| 183 | { |
| 184 | const size_t len = strlen(string) + 1; |
| 185 | acpigen_write_name(name); |
| 186 | acpigen_emit_byte(BUFFER_OP); |
| 187 | acpigen_write_len_f(); |
| 188 | acpigen_write_integer(len); |
| 189 | for (size_t i = 0; i < len; i++) { |
| 190 | const char c = string[i]; |
| 191 | /* Simple ASCII to UTF-16 conversion, replace non ASCII characters */ |
| 192 | acpigen_emit_word(c >= 0 ? c : '?'); |
| 193 | } |
| 194 | acpigen_pop_len(); |
| 195 | } |
| 196 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 197 | void acpigen_emit_stream(const char *data, int size) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 198 | { |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 199 | int i; |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 200 | for (i = 0; i < size; i++) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 201 | acpigen_emit_byte(data[i]); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 202 | } |
| 203 | |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 204 | void acpigen_emit_string(const char *string) |
| 205 | { |
Jonathan Neuschäfer | 0ba307f | 2016-05-17 17:40:09 +0200 | [diff] [blame] | 206 | acpigen_emit_stream(string, string ? strlen(string) : 0); |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 207 | acpigen_emit_byte('\0'); /* NUL */ |
| 208 | } |
| 209 | |
| 210 | void acpigen_write_string(const char *string) |
| 211 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 212 | acpigen_emit_byte(STRING_PREFIX); |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 213 | acpigen_emit_string(string); |
| 214 | } |
| 215 | |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 216 | void acpigen_write_coreboot_hid(enum coreboot_acpi_ids id) |
| 217 | { |
Joel Kitching | 3ab36b84 | 2018-03-08 12:09:32 +0800 | [diff] [blame] | 218 | char hid[9]; /* BOOTxxxx */ |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 219 | |
Duncan Laurie | 02fdb3e | 2016-09-22 14:08:33 -0700 | [diff] [blame] | 220 | snprintf(hid, sizeof(hid), "%.4s%04X", COREBOOT_ACPI_ID, id); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 221 | acpigen_write_name_string("_HID", hid); |
| 222 | } |
| 223 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 224 | /* |
| 225 | * The naming conventions for ACPI namespace names are a bit tricky as |
Martin Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 226 | * each element has to be 4 chars wide ("All names are a fixed 32 bits.") |
| 227 | * and "By convention, when an ASL compiler pads a name shorter than 4 |
| 228 | * characters, it is done so with trailing underscores ('_')". |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 229 | * |
| 230 | * Check sections 5.3, 18.2.2 and 18.4 of ACPI spec 3.0 for details. |
| 231 | */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 232 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 233 | static void acpigen_emit_simple_namestring(const char *name) |
| 234 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 235 | int i; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 236 | char ud[] = "____"; |
| 237 | for (i = 0; i < 4; i++) { |
| 238 | if ((name[i] == '\0') || (name[i] == '.')) { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 239 | acpigen_emit_stream(ud, 4 - i); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 240 | break; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 241 | } |
Lee Leahy | 0b5678f | 2017-03-16 16:01:40 -0700 | [diff] [blame] | 242 | acpigen_emit_byte(name[i]); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 243 | } |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 246 | static void acpigen_emit_double_namestring(const char *name, int dotpos) |
| 247 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 248 | acpigen_emit_byte(DUAL_NAME_PREFIX); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 249 | acpigen_emit_simple_namestring(name); |
| 250 | acpigen_emit_simple_namestring(&name[dotpos + 1]); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 253 | static void acpigen_emit_multi_namestring(const char *name) |
| 254 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 255 | int count = 0; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 256 | unsigned char *pathlen; |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 257 | acpigen_emit_byte(MULTI_NAME_PREFIX); |
| 258 | acpigen_emit_byte(ZERO_OP); |
Elyes Haouas | 3141fbad | 2022-11-18 15:22:32 +0100 | [diff] [blame] | 259 | pathlen = ((unsigned char *)acpigen_get_current()) - 1; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 260 | |
| 261 | while (name[0] != '\0') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 262 | acpigen_emit_simple_namestring(name); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 263 | /* find end or next entity */ |
| 264 | while ((name[0] != '.') && (name[0] != '\0')) |
| 265 | name++; |
| 266 | /* forward to next */ |
| 267 | if (name[0] == '.') |
| 268 | name++; |
| 269 | count++; |
| 270 | } |
| 271 | |
| 272 | pathlen[0] = count; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 273 | } |
| 274 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 275 | void acpigen_emit_namestring(const char *namepath) |
| 276 | { |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 277 | int dotcount = 0, i; |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 278 | int dotpos = 0; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 279 | |
Ronak Kanabar | 7c0f007 | 2020-11-30 15:40:51 +0530 | [diff] [blame] | 280 | /* Check for NULL pointer */ |
| 281 | if (!namepath) |
| 282 | return; |
| 283 | |
Ronald G. Minnich | be738eb | 2013-03-07 11:05:28 -0600 | [diff] [blame] | 284 | /* We can start with a '\'. */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 285 | if (namepath[0] == '\\') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 286 | acpigen_emit_byte('\\'); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 287 | namepath++; |
| 288 | } |
| 289 | |
Ronald G. Minnich | be738eb | 2013-03-07 11:05:28 -0600 | [diff] [blame] | 290 | /* And there can be any number of '^' */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 291 | while (namepath[0] == '^') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 292 | acpigen_emit_byte('^'); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 293 | namepath++; |
| 294 | } |
| 295 | |
Vladimir Serbinenko | d942ed9 | 2014-08-30 20:44:37 +0200 | [diff] [blame] | 296 | /* If we have only \\ or only ^...^. Then we need to put a null |
| 297 | name (0x00). */ |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 298 | if (namepath[0] == '\0') { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 299 | acpigen_emit_byte(ZERO_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 300 | return; |
Vladimir Serbinenko | d942ed9 | 2014-08-30 20:44:37 +0200 | [diff] [blame] | 301 | } |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 302 | |
| 303 | i = 0; |
| 304 | while (namepath[i] != '\0') { |
| 305 | if (namepath[i] == '.') { |
| 306 | dotcount++; |
| 307 | dotpos = i; |
| 308 | } |
| 309 | i++; |
| 310 | } |
| 311 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 312 | if (dotcount == 0) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 313 | acpigen_emit_simple_namestring(namepath); |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 314 | else if (dotcount == 1) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 315 | acpigen_emit_double_namestring(namepath, dotpos); |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame] | 316 | else |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 317 | acpigen_emit_multi_namestring(namepath); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 318 | } |
| 319 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 320 | void acpigen_write_name(const char *name) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 321 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 322 | acpigen_emit_byte(NAME_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 323 | acpigen_emit_namestring(name); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 326 | void acpigen_write_scope(const char *name) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 327 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 328 | acpigen_emit_byte(SCOPE_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 329 | acpigen_write_len_f(); |
| 330 | acpigen_emit_namestring(name); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 331 | } |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 332 | |
Duncan Laurie | 2fe7471 | 2020-06-01 17:36:56 -0700 | [diff] [blame] | 333 | void acpigen_get_package_op_element(uint8_t package_op, unsigned int element, uint8_t dest_op) |
| 334 | { |
Duncan Laurie | ec2e3e4 | 2020-11-03 15:19:08 -0800 | [diff] [blame] | 335 | /* <dest_op> = DeRefOf (<package_op>[<element>]) */ |
Duncan Laurie | 2fe7471 | 2020-06-01 17:36:56 -0700 | [diff] [blame] | 336 | acpigen_write_store(); |
| 337 | acpigen_emit_byte(DEREF_OP); |
| 338 | acpigen_emit_byte(INDEX_OP); |
| 339 | acpigen_emit_byte(package_op); |
| 340 | acpigen_write_integer(element); |
| 341 | acpigen_emit_byte(ZERO_OP); /* Ignore Index() Destination */ |
| 342 | acpigen_emit_byte(dest_op); |
| 343 | } |
| 344 | |
Duncan Laurie | ec2e3e4 | 2020-11-03 15:19:08 -0800 | [diff] [blame] | 345 | void acpigen_set_package_op_element_int(uint8_t package_op, unsigned int element, uint64_t src) |
| 346 | { |
| 347 | /* DeRefOf (<package>[<element>]) = <src> */ |
| 348 | acpigen_write_store(); |
| 349 | acpigen_write_integer(src); |
| 350 | acpigen_emit_byte(DEREF_OP); |
| 351 | acpigen_emit_byte(INDEX_OP); |
| 352 | acpigen_emit_byte(package_op); |
| 353 | acpigen_write_integer(element); |
| 354 | acpigen_emit_byte(ZERO_OP); /* Ignore Index() Destination */ |
| 355 | } |
| 356 | |
| 357 | void acpigen_get_package_element(const char *package, unsigned int element, uint8_t dest_op) |
| 358 | { |
| 359 | /* <dest_op> = <package>[<element>] */ |
| 360 | acpigen_write_store(); |
| 361 | acpigen_emit_byte(INDEX_OP); |
| 362 | acpigen_emit_namestring(package); |
| 363 | acpigen_write_integer(element); |
| 364 | acpigen_emit_byte(ZERO_OP); /* Ignore Index() Destination */ |
| 365 | acpigen_emit_byte(dest_op); |
| 366 | } |
| 367 | |
| 368 | void acpigen_set_package_element_int(const char *package, unsigned int element, uint64_t src) |
| 369 | { |
| 370 | /* <package>[<element>] = <src> */ |
| 371 | acpigen_write_store(); |
| 372 | acpigen_write_integer(src); |
| 373 | acpigen_emit_byte(INDEX_OP); |
| 374 | acpigen_emit_namestring(package); |
| 375 | acpigen_write_integer(element); |
| 376 | acpigen_emit_byte(ZERO_OP); /* Ignore Index() Destination */ |
| 377 | } |
| 378 | |
| 379 | void acpigen_set_package_element_namestr(const char *package, unsigned int element, |
| 380 | const char *src) |
| 381 | { |
| 382 | /* <package>[<element>] = <src> */ |
| 383 | acpigen_write_store(); |
| 384 | acpigen_emit_namestring(src); |
| 385 | acpigen_emit_byte(INDEX_OP); |
| 386 | acpigen_emit_namestring(package); |
| 387 | acpigen_write_integer(element); |
| 388 | acpigen_emit_byte(ZERO_OP); /* Ignore Index() Destination */ |
| 389 | } |
| 390 | |
Felix Held | b57b12f | 2023-01-24 19:31:00 +0100 | [diff] [blame] | 391 | void acpigen_write_processor_namestring(unsigned int cpu_index) |
| 392 | { |
| 393 | char buffer[16]; |
Felix Held | f0a8b04 | 2023-05-12 15:55:06 +0200 | [diff] [blame] | 394 | snprintf(buffer, sizeof(buffer), "\\_SB." CONFIG_ACPI_CPU_STRING, cpu_index); |
Felix Held | b57b12f | 2023-01-24 19:31:00 +0100 | [diff] [blame] | 395 | acpigen_emit_namestring(buffer); |
| 396 | } |
| 397 | |
Elyes Haouas | 9c82491 | 2023-01-28 09:13:17 +0100 | [diff] [blame] | 398 | /* Processor() operator is deprecated as of ACPI 6.0, use Device() instead. */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 399 | void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 400 | { |
| 401 | /* |
Christian Walter | be3979c | 2019-12-18 15:07:59 +0100 | [diff] [blame] | 402 | Processor (\_SB.CPcpuindex, cpuindex, pblock_addr, pblock_len) |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 403 | { |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 404 | */ |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 405 | acpigen_emit_ext_op(PROCESSOR_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 406 | acpigen_write_len_f(); |
Felix Held | b57b12f | 2023-01-24 19:31:00 +0100 | [diff] [blame] | 407 | acpigen_write_processor_namestring(cpuindex); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 408 | acpigen_emit_byte(cpuindex); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 409 | acpigen_emit_dword(pblock_addr); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 410 | acpigen_emit_byte(pblock_len); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 411 | } |
| 412 | |
Felix Held | 32bba18 | 2023-01-28 03:37:21 +0100 | [diff] [blame] | 413 | void acpigen_write_processor_device(unsigned int cpu_index) |
| 414 | { |
| 415 | acpigen_emit_ext_op(DEVICE_OP); |
| 416 | acpigen_write_len_f(); |
| 417 | acpigen_write_processor_namestring(cpu_index); |
| 418 | acpigen_write_name_string("_HID", "ACPI0007"); |
| 419 | acpigen_write_name_integer("_UID", cpu_index); |
| 420 | } |
| 421 | |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 422 | void acpigen_write_processor_package(const char *const name, const unsigned int first_core, |
Nico Huber | 4d211ac | 2017-09-01 21:14:36 +0200 | [diff] [blame] | 423 | const unsigned int core_count) |
| 424 | { |
| 425 | unsigned int i; |
Nico Huber | 4d211ac | 2017-09-01 21:14:36 +0200 | [diff] [blame] | 426 | |
| 427 | acpigen_write_name(name); |
| 428 | acpigen_write_package(core_count); |
Felix Held | b57b12f | 2023-01-24 19:31:00 +0100 | [diff] [blame] | 429 | |
| 430 | for (i = first_core; i < first_core + core_count; ++i) |
| 431 | acpigen_write_processor_namestring(i); |
| 432 | |
Nico Huber | 4d211ac | 2017-09-01 21:14:36 +0200 | [diff] [blame] | 433 | acpigen_pop_len(); |
| 434 | } |
| 435 | |
Arthur Heymans | 8f05527 | 2018-11-28 13:18:57 +0100 | [diff] [blame] | 436 | /* Method to notify all CPU cores */ |
| 437 | void acpigen_write_processor_cnot(const unsigned int number_of_cores) |
| 438 | { |
| 439 | int core_id; |
| 440 | |
Christian Walter | be3979c | 2019-12-18 15:07:59 +0100 | [diff] [blame] | 441 | acpigen_write_method("\\_SB.CNOT", 1); |
Arthur Heymans | 8f05527 | 2018-11-28 13:18:57 +0100 | [diff] [blame] | 442 | for (core_id = 0; core_id < number_of_cores; core_id++) { |
Arthur Heymans | 8f05527 | 2018-11-28 13:18:57 +0100 | [diff] [blame] | 443 | acpigen_emit_byte(NOTIFY_OP); |
Felix Held | b57b12f | 2023-01-24 19:31:00 +0100 | [diff] [blame] | 444 | acpigen_write_processor_namestring(core_id); |
Arthur Heymans | 8f05527 | 2018-11-28 13:18:57 +0100 | [diff] [blame] | 445 | acpigen_emit_byte(ARG0_OP); |
| 446 | } |
| 447 | acpigen_pop_len(); |
| 448 | } |
| 449 | |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 450 | /* |
| 451 | * Generate ACPI AML code for OperationRegion |
| 452 | * Arg0: Pointer to struct opregion opreg = OPREGION(rname, space, offset, len) |
| 453 | * where rname is region name, space is region space, offset is region offset & |
| 454 | * len is region length. |
| 455 | * OperationRegion(regionname, regionspace, regionoffset, regionlength) |
| 456 | */ |
Duncan Laurie | 3502960 | 2020-10-09 17:50:25 +0000 | [diff] [blame] | 457 | void acpigen_write_opregion(const struct opregion *opreg) |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 458 | { |
| 459 | /* OpregionOp */ |
| 460 | acpigen_emit_ext_op(OPREGION_OP); |
| 461 | /* NameString 4 chars only */ |
| 462 | acpigen_emit_simple_namestring(opreg->name); |
| 463 | /* RegionSpace */ |
| 464 | acpigen_emit_byte(opreg->regionspace); |
| 465 | /* RegionOffset & RegionLen, it can be byte word or double word */ |
| 466 | acpigen_write_integer(opreg->regionoffset); |
| 467 | acpigen_write_integer(opreg->regionlen); |
| 468 | } |
| 469 | |
Patrick Rudolph | 32bae49 | 2019-08-08 12:47:30 +0200 | [diff] [blame] | 470 | /* |
| 471 | * Generate ACPI AML code for Mutex |
| 472 | * Arg0: Pointer to name of mutex |
| 473 | * Arg1: Initial value of mutex |
| 474 | */ |
| 475 | void acpigen_write_mutex(const char *name, const uint8_t flags) |
| 476 | { |
| 477 | /* MutexOp */ |
| 478 | acpigen_emit_ext_op(MUTEX_OP); |
| 479 | /* NameString 4 chars only */ |
| 480 | acpigen_emit_simple_namestring(name); |
| 481 | acpigen_emit_byte(flags); |
| 482 | } |
| 483 | |
| 484 | void acpigen_write_acquire(const char *name, const uint16_t val) |
| 485 | { |
| 486 | /* AcquireOp */ |
| 487 | acpigen_emit_ext_op(ACQUIRE_OP); |
| 488 | /* NameString 4 chars only */ |
| 489 | acpigen_emit_simple_namestring(name); |
| 490 | acpigen_emit_word(val); |
| 491 | } |
| 492 | |
| 493 | void acpigen_write_release(const char *name) |
| 494 | { |
| 495 | /* ReleaseOp */ |
| 496 | acpigen_emit_ext_op(RELEASE_OP); |
| 497 | /* NameString 4 chars only */ |
| 498 | acpigen_emit_simple_namestring(name); |
| 499 | } |
| 500 | |
Patrick Rudolph | 894977b | 2017-07-01 16:15:05 +0200 | [diff] [blame] | 501 | static void acpigen_write_field_length(uint32_t len) |
| 502 | { |
| 503 | uint8_t i, j; |
| 504 | uint8_t emit[4]; |
| 505 | |
| 506 | i = 1; |
| 507 | if (len < 0x40) { |
| 508 | emit[0] = len & 0x3F; |
| 509 | } else { |
| 510 | emit[0] = len & 0xF; |
| 511 | len >>= 4; |
| 512 | while (len) { |
| 513 | emit[i] = len & 0xFF; |
| 514 | i++; |
| 515 | len >>= 8; |
| 516 | } |
| 517 | } |
| 518 | /* Update bit 7:6 : Number of bytes followed by emit[0] */ |
| 519 | emit[0] |= (i - 1) << 6; |
| 520 | |
| 521 | for (j = 0; j < i; j++) |
| 522 | acpigen_emit_byte(emit[j]); |
| 523 | } |
| 524 | |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 525 | static void acpigen_write_field_offset(uint32_t offset, uint32_t current_bit_pos) |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 526 | { |
| 527 | uint32_t diff_bits; |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 528 | |
| 529 | if (offset < current_bit_pos) { |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 530 | printk(BIOS_WARNING, "%s: Cannot move offset backward", __func__); |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 531 | return; |
| 532 | } |
| 533 | |
| 534 | diff_bits = offset - current_bit_pos; |
| 535 | /* Upper limit */ |
| 536 | if (diff_bits > 0xFFFFFFF) { |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 537 | printk(BIOS_WARNING, "%s: Offset very large to encode", __func__); |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 538 | return; |
| 539 | } |
| 540 | |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 541 | acpigen_emit_byte(0); |
Patrick Rudolph | 894977b | 2017-07-01 16:15:05 +0200 | [diff] [blame] | 542 | acpigen_write_field_length(diff_bits); |
| 543 | } |
| 544 | |
Michael Niewöhner | 060dc7b | 2022-05-13 00:04:19 +0200 | [diff] [blame] | 545 | void acpigen_write_field_name(const char *name, uint32_t size) |
Patrick Rudolph | 894977b | 2017-07-01 16:15:05 +0200 | [diff] [blame] | 546 | { |
| 547 | acpigen_emit_simple_namestring(name); |
| 548 | acpigen_write_field_length(size); |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 549 | } |
| 550 | |
Duncan Laurie | 095bbf9 | 2020-09-30 23:09:29 +0000 | [diff] [blame] | 551 | static void acpigen_write_field_reserved(uint32_t size) |
| 552 | { |
| 553 | acpigen_emit_byte(0); |
| 554 | acpigen_write_field_length(size); |
| 555 | } |
| 556 | |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 557 | /* |
| 558 | * Generate ACPI AML code for Field |
| 559 | * Arg0: region name |
| 560 | * Arg1: Pointer to struct fieldlist. |
| 561 | * Arg2: no. of entries in Arg1 |
| 562 | * Arg3: flags which indicate filed access type, lock rule & update rule. |
| 563 | * Example with fieldlist |
| 564 | * struct fieldlist l[] = { |
| 565 | * FIELDLIST_OFFSET(0x84), |
| 566 | * FIELDLIST_NAMESTR("PMCS", 2), |
Duncan Laurie | 095bbf9 | 2020-09-30 23:09:29 +0000 | [diff] [blame] | 567 | * FIELDLIST_RESERVED(6), |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 568 | * }; |
Elyes HAOUAS | a342f39 | 2018-10-17 10:56:26 +0200 | [diff] [blame] | 569 | * acpigen_write_field("UART", l, ARRAY_SIZE(l), FIELD_ANYACC | FIELD_NOLOCK | |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 570 | * FIELD_PRESERVE); |
| 571 | * Output: |
| 572 | * Field (UART, AnyAcc, NoLock, Preserve) |
| 573 | * { |
| 574 | * Offset (0x84), |
Duncan Laurie | 095bbf9 | 2020-09-30 23:09:29 +0000 | [diff] [blame] | 575 | * PMCS, 2, |
| 576 | * , 6, |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 577 | * } |
| 578 | */ |
Furquan Shaikh | f939299 | 2020-04-27 23:18:12 -0700 | [diff] [blame] | 579 | void acpigen_write_field(const char *name, const struct fieldlist *l, size_t count, |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 580 | uint8_t flags) |
| 581 | { |
| 582 | uint16_t i; |
| 583 | uint32_t current_bit_pos = 0; |
| 584 | |
| 585 | /* FieldOp */ |
| 586 | acpigen_emit_ext_op(FIELD_OP); |
| 587 | /* Package Length */ |
| 588 | acpigen_write_len_f(); |
| 589 | /* NameString 4 chars only */ |
| 590 | acpigen_emit_simple_namestring(name); |
| 591 | /* Field Flag */ |
| 592 | acpigen_emit_byte(flags); |
| 593 | |
| 594 | for (i = 0; i < count; i++) { |
| 595 | switch (l[i].type) { |
| 596 | case NAME_STRING: |
Patrick Rudolph | 894977b | 2017-07-01 16:15:05 +0200 | [diff] [blame] | 597 | acpigen_write_field_name(l[i].name, l[i].bits); |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 598 | current_bit_pos += l[i].bits; |
| 599 | break; |
Duncan Laurie | 095bbf9 | 2020-09-30 23:09:29 +0000 | [diff] [blame] | 600 | case RESERVED: |
| 601 | acpigen_write_field_reserved(l[i].bits); |
| 602 | current_bit_pos += l[i].bits; |
| 603 | break; |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 604 | case OFFSET: |
| 605 | acpigen_write_field_offset(l[i].bits, current_bit_pos); |
| 606 | current_bit_pos = l[i].bits; |
| 607 | break; |
| 608 | default: |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 609 | printk(BIOS_ERR, "%s: Invalid field type 0x%X\n", __func__, l[i].type); |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 610 | break; |
| 611 | } |
| 612 | } |
| 613 | acpigen_pop_len(); |
| 614 | } |
| 615 | |
Patrick Rudolph | 34846ad | 2019-05-22 11:59:23 +0200 | [diff] [blame] | 616 | /* |
| 617 | * Generate ACPI AML code for IndexField |
| 618 | * Arg0: region name |
| 619 | * Arg1: Pointer to struct fieldlist. |
| 620 | * Arg2: no. of entries in Arg1 |
| 621 | * Arg3: flags which indicate filed access type, lock rule & update rule. |
| 622 | * Example with fieldlist |
| 623 | * struct fieldlist l[] = { |
| 624 | * FIELDLIST_OFFSET(0x84), |
| 625 | * FIELDLIST_NAMESTR("PMCS", 2), |
| 626 | * }; |
| 627 | * acpigen_write_field("IDX", "DATA" l, ARRAY_SIZE(l), FIELD_ANYACC | |
| 628 | * FIELD_NOLOCK | |
| 629 | * FIELD_PRESERVE); |
| 630 | * Output: |
| 631 | * IndexField (IDX, DATA, AnyAcc, NoLock, Preserve) |
| 632 | * { |
| 633 | * Offset (0x84), |
| 634 | * PMCS, 2 |
| 635 | * } |
| 636 | */ |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 637 | void acpigen_write_indexfield(const char *idx, const char *data, struct fieldlist *l, |
| 638 | size_t count, uint8_t flags) |
Patrick Rudolph | 34846ad | 2019-05-22 11:59:23 +0200 | [diff] [blame] | 639 | { |
| 640 | uint16_t i; |
| 641 | uint32_t current_bit_pos = 0; |
| 642 | |
| 643 | /* FieldOp */ |
| 644 | acpigen_emit_ext_op(INDEX_FIELD_OP); |
| 645 | /* Package Length */ |
| 646 | acpigen_write_len_f(); |
| 647 | /* NameString 4 chars only */ |
| 648 | acpigen_emit_simple_namestring(idx); |
| 649 | /* NameString 4 chars only */ |
| 650 | acpigen_emit_simple_namestring(data); |
| 651 | /* Field Flag */ |
| 652 | acpigen_emit_byte(flags); |
| 653 | |
| 654 | for (i = 0; i < count; i++) { |
| 655 | switch (l[i].type) { |
| 656 | case NAME_STRING: |
| 657 | acpigen_write_field_name(l[i].name, l[i].bits); |
| 658 | current_bit_pos += l[i].bits; |
| 659 | break; |
| 660 | case OFFSET: |
| 661 | acpigen_write_field_offset(l[i].bits, current_bit_pos); |
| 662 | current_bit_pos = l[i].bits; |
| 663 | break; |
| 664 | default: |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 665 | printk(BIOS_ERR, "%s: Invalid field type 0x%X\n", __func__, l[i].type); |
Patrick Rudolph | 34846ad | 2019-05-22 11:59:23 +0200 | [diff] [blame] | 666 | break; |
| 667 | } |
| 668 | } |
| 669 | acpigen_pop_len(); |
| 670 | } |
| 671 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 672 | void acpigen_write_empty_PCT(void) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 673 | { |
| 674 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 675 | Name (_PCT, Package (0x02) |
| 676 | { |
| 677 | ResourceTemplate () |
| 678 | { |
| 679 | Register (FFixedHW, |
| 680 | 0x00, // Bit Width |
| 681 | 0x00, // Bit Offset |
| 682 | 0x0000000000000000, // Address |
| 683 | ,) |
| 684 | }, |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 685 | |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 686 | ResourceTemplate () |
| 687 | { |
| 688 | Register (FFixedHW, |
| 689 | 0x00, // Bit Width |
| 690 | 0x00, // Bit Offset |
| 691 | 0x0000000000000000, // Address |
| 692 | ,) |
| 693 | } |
| 694 | }) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 695 | */ |
| 696 | static char stream[] = { |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 697 | /* 00000030 "0._PCT.," */ |
| 698 | 0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, |
| 699 | /* 00000038 "........" */ |
| 700 | 0x02, 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, |
| 701 | /* 00000040 "........" */ |
| 702 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 703 | /* 00000048 "....y..." */ |
| 704 | 0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, |
| 705 | /* 00000050 "........" */ |
| 706 | 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, |
| 707 | /* 00000058 "........" */ |
| 708 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 709 | 0x00, 0x79, 0x00 |
| 710 | }; |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 711 | acpigen_emit_stream(stream, ARRAY_SIZE(stream)); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 712 | } |
| 713 | |
Kyösti Mälkki | ddc37d6 | 2023-04-17 12:11:03 +0300 | [diff] [blame] | 714 | void acpigen_write_PTC(uint8_t duty_width, uint8_t duty_offset, uint16_t p_cnt) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 715 | { |
| 716 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 717 | Name (_PTC, Package (0x02) |
| 718 | { |
| 719 | ResourceTemplate () |
| 720 | { |
| 721 | Register (FFixedHW, |
Kyösti Mälkki | ddc37d6 | 2023-04-17 12:11:03 +0300 | [diff] [blame] | 722 | 0x00, // Duty Width |
| 723 | 0x00, // Duty Offset |
| 724 | 0x0000000000000000, // P_CNT IO Address |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 725 | ,) |
| 726 | }, |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 727 | |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 728 | ResourceTemplate () |
| 729 | { |
| 730 | Register (FFixedHW, |
Kyösti Mälkki | ddc37d6 | 2023-04-17 12:11:03 +0300 | [diff] [blame] | 731 | 0x00, // Duty Width |
| 732 | 0x00, // Duty Offset |
| 733 | 0x0000000000000000, // P_CNT IO Address |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 734 | ,) |
| 735 | } |
| 736 | }) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 737 | */ |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 738 | acpi_addr_t addr = { |
Kyösti Mälkki | ddc37d6 | 2023-04-17 12:11:03 +0300 | [diff] [blame] | 739 | .bit_width = duty_width, |
| 740 | .bit_offset = duty_offset, |
Elyes HAOUAS | 721cb8a | 2020-06-23 09:13:42 +0200 | [diff] [blame] | 741 | .access_size = ACPI_ACCESS_SIZE_UNDEFINED, |
Kyösti Mälkki | ddc37d6 | 2023-04-17 12:11:03 +0300 | [diff] [blame] | 742 | .addrl = p_cnt, |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 743 | .addrh = 0, |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 744 | }; |
| 745 | |
Kyösti Mälkki | ddc37d6 | 2023-04-17 12:11:03 +0300 | [diff] [blame] | 746 | if (addr.addrl != 0) |
| 747 | addr.space_id = ACPI_ADDRESS_SPACE_IO; |
| 748 | else |
| 749 | addr.space_id = ACPI_ADDRESS_SPACE_FIXED; |
| 750 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 751 | acpigen_write_name("_PTC"); |
| 752 | acpigen_write_package(2); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 753 | |
| 754 | /* ControlRegister */ |
Matt Delco | c3f9d7a | 2018-07-27 14:01:05 -0700 | [diff] [blame] | 755 | acpigen_write_register_resource(&addr); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 756 | |
| 757 | /* StatusRegister */ |
Matt Delco | c3f9d7a | 2018-07-27 14:01:05 -0700 | [diff] [blame] | 758 | acpigen_write_register_resource(&addr); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 759 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 760 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 761 | } |
| 762 | |
Kyösti Mälkki | ddc37d6 | 2023-04-17 12:11:03 +0300 | [diff] [blame] | 763 | void acpigen_write_empty_PTC(void) |
| 764 | { |
| 765 | acpigen_write_PTC(0, 0, 0); |
| 766 | } |
| 767 | |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 768 | static void __acpigen_write_method(const char *name, uint8_t flags) |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 769 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 770 | acpigen_emit_byte(METHOD_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 771 | acpigen_write_len_f(); |
| 772 | acpigen_emit_namestring(name); |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 773 | acpigen_emit_byte(flags); |
| 774 | } |
| 775 | |
| 776 | /* Method (name, nargs, NotSerialized) */ |
| 777 | void acpigen_write_method(const char *name, int nargs) |
| 778 | { |
| 779 | __acpigen_write_method(name, (nargs & 7)); |
| 780 | } |
| 781 | |
| 782 | /* Method (name, nargs, Serialized) */ |
| 783 | void acpigen_write_method_serialized(const char *name, int nargs) |
| 784 | { |
| 785 | __acpigen_write_method(name, (nargs & 7) | (1 << 3)); |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 786 | } |
| 787 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 788 | void acpigen_write_device(const char *name) |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 789 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 790 | acpigen_emit_ext_op(DEVICE_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 791 | acpigen_write_len_f(); |
| 792 | acpigen_emit_namestring(name); |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 793 | } |
| 794 | |
Raul E Rangel | 052c963 | 2021-05-12 17:01:30 -0600 | [diff] [blame] | 795 | void acpigen_write_thermal_zone(const char *name) |
| 796 | { |
| 797 | acpigen_emit_ext_op(THERMAL_ZONE_OP); |
| 798 | acpigen_write_len_f(); |
| 799 | acpigen_emit_namestring(name); |
| 800 | } |
| 801 | |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 802 | void acpigen_write_STA(uint8_t status) |
| 803 | { |
| 804 | /* |
| 805 | * Method (_STA, 0, NotSerialized) { Return (status) } |
| 806 | */ |
| 807 | acpigen_write_method("_STA", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 808 | acpigen_emit_byte(RETURN_OP); |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 809 | acpigen_write_byte(status); |
| 810 | acpigen_pop_len(); |
| 811 | } |
| 812 | |
Sugnan Prabhu S | 4f77f61 | 2020-06-10 09:51:02 +0530 | [diff] [blame] | 813 | void acpigen_write_STA_ext(const char *namestring) |
| 814 | { |
| 815 | /* |
| 816 | * Method (_STA, 0, NotSerialized) { Return (ext_val) } |
| 817 | */ |
| 818 | acpigen_write_method("_STA", 0); |
| 819 | acpigen_emit_byte(RETURN_OP); |
| 820 | acpigen_emit_namestring(namestring); |
| 821 | acpigen_pop_len(); |
| 822 | } |
| 823 | |
Felix Held | 2d4112f | 2023-05-04 23:00:06 +0200 | [diff] [blame] | 824 | void acpigen_write_BBN(uint8_t base_bus_number) |
| 825 | { |
| 826 | /* |
| 827 | * Method (_BBN, 0, NotSerialized) { Return (status) } |
| 828 | */ |
| 829 | acpigen_write_method("_BBN", 0); |
| 830 | acpigen_emit_byte(RETURN_OP); |
| 831 | acpigen_write_byte(base_bus_number); |
| 832 | acpigen_pop_len(); |
| 833 | } |
| 834 | |
Raul E Rangel | c704832 | 2021-04-19 15:58:25 -0600 | [diff] [blame] | 835 | void acpigen_write_LPI_package(u64 level, const struct acpi_lpi_state *states, u16 nentries) |
| 836 | { |
| 837 | /* |
| 838 | * Name (_LPI, Package (0x06) // _LPI: Low Power Idle States |
| 839 | * { |
| 840 | * 0x0000, |
| 841 | * 0x0000000000000000, |
| 842 | * 0x0003, |
| 843 | * Package (0x0A) |
| 844 | * { |
| 845 | * 0x00000002, |
| 846 | * 0x00000001, |
| 847 | * 0x00000001, |
| 848 | * 0x00000000, |
| 849 | * 0x00000000, |
| 850 | * 0x00000000, |
| 851 | * ResourceTemplate () |
| 852 | * { |
| 853 | * Register (FFixedHW, |
| 854 | * 0x02, // Bit Width |
| 855 | * 0x02, // Bit Offset |
| 856 | * 0x0000000000000000, // Address |
| 857 | * ,) |
| 858 | * }, |
| 859 | * |
| 860 | * ResourceTemplate () |
| 861 | * { |
| 862 | * Register (SystemMemory, |
| 863 | * 0x00, // Bit Width |
| 864 | * 0x00, // Bit Offset |
| 865 | * 0x0000000000000000, // Address |
| 866 | * ,) |
| 867 | * }, |
| 868 | * |
| 869 | * ResourceTemplate () |
| 870 | * { |
| 871 | * Register (SystemMemory, |
| 872 | * 0x00, // Bit Width |
| 873 | * 0x00, // Bit Offset |
| 874 | * 0x0000000000000000, // Address |
| 875 | * ,) |
| 876 | * }, |
| 877 | * |
| 878 | * "C1" |
| 879 | * }, |
| 880 | * ... |
| 881 | * } |
| 882 | */ |
| 883 | |
| 884 | acpigen_write_name("_LPI"); |
| 885 | acpigen_write_package(3 + nentries); |
| 886 | acpigen_write_word(0); /* Revision */ |
| 887 | acpigen_write_qword(level); |
| 888 | acpigen_write_word(nentries); |
| 889 | |
| 890 | for (size_t i = 0; i < nentries; i++, states++) { |
| 891 | acpigen_write_package(0xA); |
| 892 | acpigen_write_dword(states->min_residency_us); |
| 893 | acpigen_write_dword(states->worst_case_wakeup_latency_us); |
| 894 | acpigen_write_dword(states->flags); |
| 895 | acpigen_write_dword(states->arch_context_lost_flags); |
| 896 | acpigen_write_dword(states->residency_counter_frequency_hz); |
| 897 | acpigen_write_dword(states->enabled_parent_state); |
| 898 | acpigen_write_register_resource(&states->entry_method); |
| 899 | acpigen_write_register_resource(&states->residency_counter_register); |
| 900 | acpigen_write_register_resource(&states->usage_counter_register); |
| 901 | acpigen_write_string(states->state_name); |
| 902 | acpigen_pop_len(); |
| 903 | } |
| 904 | acpigen_pop_len(); |
| 905 | } |
| 906 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 907 | /* |
| 908 | * Generates a func with max supported P-states. |
| 909 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 910 | void acpigen_write_PPC(u8 nr) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 911 | { |
| 912 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 913 | Method (_PPC, 0, NotSerialized) |
| 914 | { |
| 915 | Return (nr) |
| 916 | } |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 917 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 918 | acpigen_write_method("_PPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 919 | acpigen_emit_byte(RETURN_OP); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 920 | /* arg */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 921 | acpigen_write_byte(nr); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 922 | acpigen_pop_len(); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 923 | } |
| 924 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 925 | /* |
| 926 | * Generates a func with max supported P-states saved |
| 927 | * in the variable PPCM. |
| 928 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 929 | void acpigen_write_PPC_NVS(void) |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 930 | { |
| 931 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 932 | Method (_PPC, 0, NotSerialized) |
| 933 | { |
| 934 | Return (PPCM) |
| 935 | } |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 936 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 937 | acpigen_write_method("_PPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 938 | acpigen_emit_byte(RETURN_OP); |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 939 | /* arg */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 940 | acpigen_emit_namestring("PPCM"); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 941 | acpigen_pop_len(); |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 942 | } |
| 943 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 944 | void acpigen_write_TPC(const char *gnvs_tpc_limit) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 945 | { |
| 946 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 947 | // Sample _TPC method |
| 948 | Method (_TPC, 0, NotSerialized) |
| 949 | { |
| 950 | Return (\TLVL) |
| 951 | } |
| 952 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 953 | acpigen_write_method("_TPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 954 | acpigen_emit_byte(RETURN_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 955 | acpigen_emit_namestring(gnvs_tpc_limit); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 956 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 957 | } |
| 958 | |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 959 | void acpigen_write_PRW(u32 wake, u32 level) |
| 960 | { |
| 961 | /* |
| 962 | * Name (_PRW, Package () { wake, level } |
| 963 | */ |
| 964 | acpigen_write_name("_PRW"); |
| 965 | acpigen_write_package(2); |
| 966 | acpigen_write_integer(wake); |
| 967 | acpigen_write_integer(level); |
| 968 | acpigen_pop_len(); |
| 969 | } |
| 970 | |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 971 | void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, u32 busmLat, u32 control, |
| 972 | u32 status) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 973 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 974 | acpigen_write_package(6); |
| 975 | acpigen_write_dword(coreFreq); |
| 976 | acpigen_write_dword(power); |
| 977 | acpigen_write_dword(transLat); |
| 978 | acpigen_write_dword(busmLat); |
| 979 | acpigen_write_dword(control); |
| 980 | acpigen_write_dword(status); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 981 | acpigen_pop_len(); |
Stefan Reinauer | d4bacf9 | 2012-05-02 16:38:47 -0700 | [diff] [blame] | 982 | |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 983 | printk(BIOS_DEBUG, "PSS: %uMHz power %u control 0x%x status 0x%x\n", coreFreq, power, |
| 984 | control, status); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 985 | } |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 986 | |
Jason Glenesk | ca36aed | 2020-09-15 21:01:57 -0700 | [diff] [blame] | 987 | void acpigen_write_pss_object(const struct acpi_sw_pstate *pstate_values, size_t nentries) |
| 988 | { |
| 989 | size_t pstate; |
| 990 | |
| 991 | acpigen_write_name("_PSS"); |
| 992 | acpigen_write_package(nentries); |
| 993 | for (pstate = 0; pstate < nentries; pstate++) { |
| 994 | acpigen_write_PSS_package( |
| 995 | pstate_values->core_freq, pstate_values->power, |
| 996 | pstate_values->transition_latency, pstate_values->bus_master_latency, |
| 997 | pstate_values->control_value, pstate_values->status_value); |
| 998 | pstate_values++; |
| 999 | } |
| 1000 | |
| 1001 | acpigen_pop_len(); |
| 1002 | } |
| 1003 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1004 | void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 1005 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1006 | acpigen_write_name("_PSD"); |
| 1007 | acpigen_write_package(1); |
| 1008 | acpigen_write_package(5); |
| 1009 | acpigen_write_byte(5); // 5 values |
| 1010 | acpigen_write_byte(0); // revision 0 |
| 1011 | acpigen_write_dword(domain); |
| 1012 | acpigen_write_dword(coordtype); |
| 1013 | acpigen_write_dword(numprocs); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1014 | acpigen_pop_len(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1015 | acpigen_pop_len(); |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 1016 | } |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1017 | |
Angel Pons | d2794ce | 2021-10-17 12:59:43 +0200 | [diff] [blame] | 1018 | void acpigen_write_CST_package_entry(const acpi_cstate_t *cstate) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 1019 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1020 | acpigen_write_package(4); |
Matt Delco | c3f9d7a | 2018-07-27 14:01:05 -0700 | [diff] [blame] | 1021 | acpigen_write_register_resource(&cstate->resource); |
Jason Glenesk | 201acca | 2020-09-11 12:36:15 -0700 | [diff] [blame] | 1022 | acpigen_write_byte(cstate->ctype); |
| 1023 | acpigen_write_word(cstate->latency); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1024 | acpigen_write_dword(cstate->power); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1025 | acpigen_pop_len(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 1026 | } |
| 1027 | |
Angel Pons | d2794ce | 2021-10-17 12:59:43 +0200 | [diff] [blame] | 1028 | void acpigen_write_CST_package(const acpi_cstate_t *cstate, int nentries) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 1029 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1030 | int i; |
| 1031 | acpigen_write_name("_CST"); |
| 1032 | acpigen_write_package(nentries+1); |
Jason Glenesk | 201acca | 2020-09-11 12:36:15 -0700 | [diff] [blame] | 1033 | acpigen_write_integer(nentries); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 1034 | |
| 1035 | for (i = 0; i < nentries; i++) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1036 | acpigen_write_CST_package_entry(cstate + i); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 1037 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1038 | acpigen_pop_len(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 1039 | } |
| 1040 | |
Lee Leahy | 6f80ccc | 2017-03-16 15:18:22 -0700 | [diff] [blame] | 1041 | void acpigen_write_CSD_package(u32 domain, u32 numprocs, CSD_coord coordtype, |
| 1042 | u32 index) |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 1043 | { |
| 1044 | acpigen_write_name("_CSD"); |
| 1045 | acpigen_write_package(1); |
| 1046 | acpigen_write_package(6); |
Jason Glenesk | 201acca | 2020-09-11 12:36:15 -0700 | [diff] [blame] | 1047 | acpigen_write_integer(6); // 6 values |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 1048 | acpigen_write_byte(0); // revision 0 |
| 1049 | acpigen_write_dword(domain); |
| 1050 | acpigen_write_dword(coordtype); |
| 1051 | acpigen_write_dword(numprocs); |
| 1052 | acpigen_write_dword(index); |
| 1053 | acpigen_pop_len(); |
| 1054 | acpigen_pop_len(); |
| 1055 | } |
| 1056 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1057 | void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 1058 | { |
| 1059 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 1060 | Sample _TSS package with 100% and 50% duty cycles |
| 1061 | Name (_TSS, Package (0x02) |
| 1062 | { |
| 1063 | Package(){100, 1000, 0, 0x00, 0) |
| 1064 | Package(){50, 520, 0, 0x18, 0) |
| 1065 | }) |
| 1066 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1067 | int i; |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 1068 | acpi_tstate_t *tstate = tstate_list; |
| 1069 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1070 | acpigen_write_name("_TSS"); |
| 1071 | acpigen_write_package(entries); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 1072 | |
| 1073 | for (i = 0; i < entries; i++) { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1074 | acpigen_write_package(5); |
| 1075 | acpigen_write_dword(tstate->percent); |
| 1076 | acpigen_write_dword(tstate->power); |
| 1077 | acpigen_write_dword(tstate->latency); |
| 1078 | acpigen_write_dword(tstate->control); |
| 1079 | acpigen_write_dword(tstate->status); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1080 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 1081 | tstate++; |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 1082 | } |
| 1083 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1084 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 1085 | } |
| 1086 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1087 | void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 1088 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1089 | acpigen_write_name("_TSD"); |
| 1090 | acpigen_write_package(1); |
| 1091 | acpigen_write_package(5); |
| 1092 | acpigen_write_byte(5); // 5 values |
| 1093 | acpigen_write_byte(0); // revision 0 |
| 1094 | acpigen_write_dword(domain); |
| 1095 | acpigen_write_dword(coordtype); |
| 1096 | acpigen_write_dword(numprocs); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1097 | acpigen_pop_len(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1098 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 1099 | } |
| 1100 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1101 | void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1102 | { |
| 1103 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 1104 | * ACPI 4.0 section 6.4.3.4: 32-Bit Fixed Memory Range Descriptor |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1105 | * Byte 0: |
| 1106 | * Bit7 : 1 => big item |
| 1107 | * Bit6-0: 0000110 (0x6) => 32-bit fixed memory |
| 1108 | */ |
| 1109 | acpigen_emit_byte(0x86); |
| 1110 | /* Byte 1+2: length (0x0009) */ |
| 1111 | acpigen_emit_byte(0x09); |
| 1112 | acpigen_emit_byte(0x00); |
| 1113 | /* bit1-7 are ignored */ |
| 1114 | acpigen_emit_byte(readwrite ? 0x01 : 0x00); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 1115 | acpigen_emit_dword(base); |
| 1116 | acpigen_emit_dword(size); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1117 | } |
| 1118 | |
Matt Delco | c3f9d7a | 2018-07-27 14:01:05 -0700 | [diff] [blame] | 1119 | static void acpigen_write_register(const acpi_addr_t *addr) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 1120 | { |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 1121 | acpigen_emit_byte(0x82); /* Register Descriptor */ |
| 1122 | acpigen_emit_byte(0x0c); /* Register Length 7:0 */ |
| 1123 | acpigen_emit_byte(0x00); /* Register Length 15:8 */ |
| 1124 | acpigen_emit_byte(addr->space_id); /* Address Space ID */ |
| 1125 | acpigen_emit_byte(addr->bit_width); /* Register Bit Width */ |
| 1126 | acpigen_emit_byte(addr->bit_offset); /* Register Bit Offset */ |
Elyes HAOUAS | 8ee161d | 2019-03-03 12:49:56 +0100 | [diff] [blame] | 1127 | acpigen_emit_byte(addr->access_size); /* Register Access Size */ |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 1128 | acpigen_emit_dword(addr->addrl); /* Register Address Low */ |
| 1129 | acpigen_emit_dword(addr->addrh); /* Register Address High */ |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 1130 | } |
| 1131 | |
Matt Delco | c3f9d7a | 2018-07-27 14:01:05 -0700 | [diff] [blame] | 1132 | void acpigen_write_register_resource(const acpi_addr_t *addr) |
| 1133 | { |
| 1134 | acpigen_write_resourcetemplate_header(); |
| 1135 | acpigen_write_register(addr); |
| 1136 | acpigen_write_resourcetemplate_footer(); |
| 1137 | } |
| 1138 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1139 | void acpigen_write_irq(u16 mask) |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 1140 | { |
| 1141 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 1142 | * ACPI 3.0b section 6.4.2.1: IRQ Descriptor |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 1143 | * Byte 0: |
| 1144 | * Bit7 : 0 => small item |
| 1145 | * Bit6-3: 0100 (0x4) => IRQ port descriptor |
| 1146 | * Bit2-0: 010 (0x2) => 2 Bytes long |
| 1147 | */ |
| 1148 | acpigen_emit_byte(0x22); |
| 1149 | acpigen_emit_byte(mask & 0xff); |
| 1150 | acpigen_emit_byte((mask >> 8) & 0xff); |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 1151 | } |
| 1152 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1153 | void acpigen_write_io16(u16 min, u16 max, u8 align, u8 len, u8 decode16) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1154 | { |
| 1155 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 1156 | * ACPI 4.0 section 6.4.2.6: I/O Port Descriptor |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1157 | * Byte 0: |
| 1158 | * Bit7 : 0 => small item |
| 1159 | * Bit6-3: 1000 (0x8) => I/O port descriptor |
| 1160 | * Bit2-0: 111 (0x7) => 7 Bytes long |
| 1161 | */ |
| 1162 | acpigen_emit_byte(0x47); |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 1163 | /* Does the device decode all 16 or just 10 bits? */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1164 | /* bit1-7 are ignored */ |
| 1165 | acpigen_emit_byte(decode16 ? 0x01 : 0x00); |
| 1166 | /* minimum base address the device may be configured for */ |
| 1167 | acpigen_emit_byte(min & 0xff); |
| 1168 | acpigen_emit_byte((min >> 8) & 0xff); |
| 1169 | /* maximum base address the device may be configured for */ |
| 1170 | acpigen_emit_byte(max & 0xff); |
| 1171 | acpigen_emit_byte((max >> 8) & 0xff); |
| 1172 | /* alignment for min base */ |
| 1173 | acpigen_emit_byte(align & 0xff); |
| 1174 | acpigen_emit_byte(len & 0xff); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1177 | void acpigen_write_resourcetemplate_header(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1178 | { |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1179 | /* |
| 1180 | * A ResourceTemplate() is a Buffer() with a |
| 1181 | * (Byte|Word|DWord) containing the length, followed by one or more |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 1182 | * resource items, terminated by the end tag. |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1183 | * (small item 0xf, len 1) |
| 1184 | */ |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 1185 | acpigen_emit_byte(BUFFER_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1186 | acpigen_write_len_f(); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 1187 | acpigen_emit_byte(WORD_PREFIX); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1188 | len_stack[ltop++] = acpigen_get_current(); |
Nico Huber | 7d89ce3 | 2017-04-14 00:08:18 +0200 | [diff] [blame] | 1189 | /* Add 2 dummy bytes for the ACPI word (keep aligned with |
Elyes HAOUAS | 6716bab | 2020-01-09 21:29:25 +0100 | [diff] [blame] | 1190 | the calculation in acpigen_write_resourcetemplate() below). */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1191 | acpigen_emit_byte(0x00); |
| 1192 | acpigen_emit_byte(0x00); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1195 | void acpigen_write_resourcetemplate_footer(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1196 | { |
| 1197 | char *p = len_stack[--ltop]; |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 1198 | int len; |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1199 | /* |
| 1200 | * end tag (acpi 4.0 Section 6.4.2.8) |
| 1201 | * 0x79 <checksum> |
| 1202 | * 0x00 is treated as a good checksum according to the spec |
| 1203 | * and is what iasl generates. |
| 1204 | */ |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 1205 | acpigen_emit_byte(0x79); |
| 1206 | acpigen_emit_byte(0x00); |
| 1207 | |
Nico Huber | 7d89ce3 | 2017-04-14 00:08:18 +0200 | [diff] [blame] | 1208 | /* Start counting past the 2-bytes length added in |
| 1209 | acpigen_write_resourcetemplate() above. */ |
| 1210 | len = acpigen_get_current() - (p + 2); |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 1211 | |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1212 | /* patch len word */ |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 1213 | p[0] = len & 0xff; |
| 1214 | p[1] = (len >> 8) & 0xff; |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1215 | /* patch len field */ |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1216 | acpigen_pop_len(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1217 | } |
| 1218 | |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 1219 | static void acpigen_add_mainboard_rsvd_mem32(void *gp, struct device *dev, struct resource *res) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1220 | { |
| 1221 | acpigen_write_mem32fixed(0, res->base, res->size); |
| 1222 | } |
| 1223 | |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 1224 | static void acpigen_add_mainboard_rsvd_io(void *gp, struct device *dev, struct resource *res) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1225 | { |
| 1226 | resource_t base = res->base; |
| 1227 | resource_t size = res->size; |
| 1228 | while (size > 0) { |
| 1229 | resource_t sz = size > 255 ? 255 : size; |
| 1230 | acpigen_write_io16(base, base, 0, sz, 1); |
| 1231 | size -= sz; |
| 1232 | base += sz; |
| 1233 | } |
| 1234 | } |
| 1235 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1236 | void acpigen_write_mainboard_resource_template(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1237 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1238 | acpigen_write_resourcetemplate_header(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1239 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 1240 | /* Add reserved memory ranges. */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1241 | search_global_resources( |
| 1242 | IORESOURCE_MEM | IORESOURCE_RESERVE, |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 1243 | IORESOURCE_MEM | IORESOURCE_RESERVE, |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1244 | acpigen_add_mainboard_rsvd_mem32, 0); |
| 1245 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 1246 | /* Add reserved io ranges. */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1247 | search_global_resources( |
| 1248 | IORESOURCE_IO | IORESOURCE_RESERVE, |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 1249 | IORESOURCE_IO | IORESOURCE_RESERVE, |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1250 | acpigen_add_mainboard_rsvd_io, 0); |
| 1251 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1252 | acpigen_write_resourcetemplate_footer(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1253 | } |
| 1254 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1255 | void acpigen_write_mainboard_resources(const char *scope, const char *name) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1256 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1257 | acpigen_write_scope(scope); |
| 1258 | acpigen_write_name(name); |
| 1259 | acpigen_write_mainboard_resource_template(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 1260 | acpigen_pop_len(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 1261 | } |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 1262 | |
| 1263 | static int hex2bin(const char c) |
| 1264 | { |
| 1265 | if (c >= 'A' && c <= 'F') |
| 1266 | return c - 'A' + 10; |
| 1267 | if (c >= 'a' && c <= 'f') |
| 1268 | return c - 'a' + 10; |
| 1269 | return c - '0'; |
| 1270 | } |
| 1271 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 1272 | void acpigen_emit_eisaid(const char *eisaid) |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 1273 | { |
| 1274 | u32 compact = 0; |
| 1275 | |
| 1276 | /* Clamping individual values would be better but |
| 1277 | there is a disagreement over what is a valid |
| 1278 | EISA id, so accept anything and don't clamp, |
| 1279 | parent code should create a valid EISAid. |
| 1280 | */ |
| 1281 | compact |= (eisaid[0] - 'A' + 1) << 26; |
| 1282 | compact |= (eisaid[1] - 'A' + 1) << 21; |
| 1283 | compact |= (eisaid[2] - 'A' + 1) << 16; |
| 1284 | compact |= hex2bin(eisaid[3]) << 12; |
| 1285 | compact |= hex2bin(eisaid[4]) << 8; |
| 1286 | compact |= hex2bin(eisaid[5]) << 4; |
| 1287 | compact |= hex2bin(eisaid[6]); |
| 1288 | |
| 1289 | acpigen_emit_byte(0xc); |
| 1290 | acpigen_emit_byte((compact >> 24) & 0xff); |
| 1291 | acpigen_emit_byte((compact >> 16) & 0xff); |
| 1292 | acpigen_emit_byte((compact >> 8) & 0xff); |
| 1293 | acpigen_emit_byte(compact & 0xff); |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 1294 | } |
Duncan Laurie | 3829f23 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 1295 | |
| 1296 | /* |
| 1297 | * ToUUID(uuid) |
| 1298 | * |
| 1299 | * ACPI 6.1 Section 19.6.136 table 19-385 defines a special output |
| 1300 | * order for the bytes that make up a UUID Buffer object. |
| 1301 | * UUID byte order for input: |
| 1302 | * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp |
| 1303 | * UUID byte order for output: |
| 1304 | * ddccbbaa-ffee-hhgg-iijj-kkllmmnnoopp |
| 1305 | */ |
| 1306 | #define UUID_LEN 16 |
| 1307 | void acpigen_write_uuid(const char *uuid) |
| 1308 | { |
| 1309 | uint8_t buf[UUID_LEN]; |
| 1310 | size_t i, order[UUID_LEN] = { 3, 2, 1, 0, 5, 4, 7, 6, |
| 1311 | 8, 9, 10, 11, 12, 13, 14, 15 }; |
| 1312 | |
| 1313 | /* Parse UUID string into bytes */ |
| 1314 | if (hexstrtobin(uuid, buf, UUID_LEN) < UUID_LEN) |
| 1315 | return; |
| 1316 | |
| 1317 | /* BufferOp */ |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 1318 | acpigen_emit_byte(BUFFER_OP); |
Duncan Laurie | 3829f23 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 1319 | acpigen_write_len_f(); |
| 1320 | |
| 1321 | /* Buffer length in bytes */ |
| 1322 | acpigen_write_word(UUID_LEN); |
| 1323 | |
| 1324 | /* Output UUID in expected order */ |
| 1325 | for (i = 0; i < UUID_LEN; i++) |
| 1326 | acpigen_emit_byte(buf[order[i]]); |
| 1327 | |
| 1328 | acpigen_pop_len(); |
| 1329 | } |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1330 | |
| 1331 | /* |
| 1332 | * Name (_PRx, Package(One) { name }) |
| 1333 | * ... |
| 1334 | * PowerResource (name, level, order) |
| 1335 | */ |
| 1336 | void acpigen_write_power_res(const char *name, uint8_t level, uint16_t order, |
Furquan Shaikh | dc78275 | 2020-04-30 22:49:39 -0700 | [diff] [blame] | 1337 | const char * const dev_states[], size_t dev_states_count) |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1338 | { |
Elyes HAOUAS | cca6e00 | 2019-06-26 12:12:00 +0200 | [diff] [blame] | 1339 | size_t i; |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1340 | for (i = 0; i < dev_states_count; i++) { |
| 1341 | acpigen_write_name(dev_states[i]); |
| 1342 | acpigen_write_package(1); |
| 1343 | acpigen_emit_simple_namestring(name); |
| 1344 | acpigen_pop_len(); /* Package */ |
| 1345 | } |
| 1346 | |
| 1347 | acpigen_emit_ext_op(POWER_RES_OP); |
| 1348 | |
| 1349 | acpigen_write_len_f(); |
| 1350 | |
| 1351 | acpigen_emit_simple_namestring(name); |
| 1352 | acpigen_emit_byte(level); |
| 1353 | acpigen_emit_word(order); |
| 1354 | } |
| 1355 | |
| 1356 | /* Sleep (ms) */ |
| 1357 | void acpigen_write_sleep(uint64_t sleep_ms) |
| 1358 | { |
| 1359 | acpigen_emit_ext_op(SLEEP_OP); |
| 1360 | acpigen_write_integer(sleep_ms); |
| 1361 | } |
| 1362 | |
| 1363 | void acpigen_write_store(void) |
| 1364 | { |
| 1365 | acpigen_emit_byte(STORE_OP); |
| 1366 | } |
| 1367 | |
| 1368 | /* Store (src, dst) */ |
| 1369 | void acpigen_write_store_ops(uint8_t src, uint8_t dst) |
| 1370 | { |
| 1371 | acpigen_write_store(); |
| 1372 | acpigen_emit_byte(src); |
| 1373 | acpigen_emit_byte(dst); |
| 1374 | } |
| 1375 | |
Furquan Shaikh | 2c213d3 | 2020-04-27 23:06:30 -0700 | [diff] [blame] | 1376 | /* Store (src, "namestr") */ |
| 1377 | void acpigen_write_store_op_to_namestr(uint8_t src, const char *dst) |
| 1378 | { |
| 1379 | acpigen_write_store(); |
| 1380 | acpigen_emit_byte(src); |
| 1381 | acpigen_emit_namestring(dst); |
| 1382 | } |
| 1383 | |
Duncan Laurie | 8e391d3 | 2020-09-30 23:17:41 +0000 | [diff] [blame] | 1384 | /* Store (src, "namestr") */ |
| 1385 | void acpigen_write_store_int_to_namestr(uint64_t src, const char *dst) |
| 1386 | { |
| 1387 | acpigen_write_store(); |
| 1388 | acpigen_write_integer(src); |
| 1389 | acpigen_emit_namestring(dst); |
| 1390 | } |
| 1391 | |
Cliff Huang | 24f3dc8 | 2023-02-04 21:11:51 -0800 | [diff] [blame] | 1392 | /* Store ("namestr", dst) */ |
| 1393 | void acpigen_write_store_namestr_to_op(const char *src, uint8_t dst) |
| 1394 | { |
| 1395 | acpigen_write_store(); |
| 1396 | acpigen_emit_namestring(src); |
| 1397 | acpigen_emit_byte(dst); |
| 1398 | } |
| 1399 | |
Duncan Laurie | 8e391d3 | 2020-09-30 23:17:41 +0000 | [diff] [blame] | 1400 | /* Store (src, dst) */ |
| 1401 | void acpigen_write_store_int_to_op(uint64_t src, uint8_t dst) |
| 1402 | { |
| 1403 | acpigen_write_store(); |
| 1404 | acpigen_write_integer(src); |
| 1405 | acpigen_emit_byte(dst); |
| 1406 | } |
| 1407 | |
Felix Held | 178cf35 | 2023-02-09 16:29:46 +0100 | [diff] [blame] | 1408 | /* Store ("namestr", "namestr") */ |
| 1409 | void acpigen_write_store_namestr_to_namestr(const char *src, const char *dst) |
| 1410 | { |
| 1411 | acpigen_write_store(); |
| 1412 | acpigen_emit_namestring(src); |
| 1413 | acpigen_emit_namestring(dst); |
| 1414 | } |
| 1415 | |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1416 | /* Or (arg1, arg2, res) */ |
| 1417 | void acpigen_write_or(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 1418 | { |
| 1419 | acpigen_emit_byte(OR_OP); |
| 1420 | acpigen_emit_byte(arg1); |
| 1421 | acpigen_emit_byte(arg2); |
| 1422 | acpigen_emit_byte(res); |
| 1423 | } |
| 1424 | |
Rajat Jain | 310623b | 2020-02-26 11:02:53 -0800 | [diff] [blame] | 1425 | /* Xor (arg1, arg2, res) */ |
| 1426 | void acpigen_write_xor(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 1427 | { |
| 1428 | acpigen_emit_byte(XOR_OP); |
| 1429 | acpigen_emit_byte(arg1); |
| 1430 | acpigen_emit_byte(arg2); |
| 1431 | acpigen_emit_byte(res); |
| 1432 | } |
| 1433 | |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1434 | /* And (arg1, arg2, res) */ |
| 1435 | void acpigen_write_and(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 1436 | { |
| 1437 | acpigen_emit_byte(AND_OP); |
| 1438 | acpigen_emit_byte(arg1); |
| 1439 | acpigen_emit_byte(arg2); |
| 1440 | acpigen_emit_byte(res); |
| 1441 | } |
| 1442 | |
| 1443 | /* Not (arg, res) */ |
| 1444 | void acpigen_write_not(uint8_t arg, uint8_t res) |
| 1445 | { |
| 1446 | acpigen_emit_byte(NOT_OP); |
| 1447 | acpigen_emit_byte(arg); |
| 1448 | acpigen_emit_byte(res); |
| 1449 | } |
| 1450 | |
Cliff Huang | e608308 | 2023-01-19 21:18:23 -0800 | [diff] [blame] | 1451 | /* Concatenate (str, src_res, dest_res) */ |
| 1452 | void acpigen_concatenate_string_op(const char *str, uint8_t src_res, uint8_t dest_res) |
| 1453 | { |
| 1454 | acpigen_emit_byte(CONCATENATE_OP); |
| 1455 | acpigen_write_string(str); |
| 1456 | acpigen_emit_byte(src_res); |
| 1457 | acpigen_emit_byte(dest_res); |
| 1458 | } |
| 1459 | |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1460 | /* Store (str, DEBUG) */ |
| 1461 | void acpigen_write_debug_string(const char *str) |
| 1462 | { |
| 1463 | acpigen_write_store(); |
| 1464 | acpigen_write_string(str); |
| 1465 | acpigen_emit_ext_op(DEBUG_OP); |
| 1466 | } |
| 1467 | |
| 1468 | /* Store (val, DEBUG) */ |
| 1469 | void acpigen_write_debug_integer(uint64_t val) |
| 1470 | { |
| 1471 | acpigen_write_store(); |
| 1472 | acpigen_write_integer(val); |
| 1473 | acpigen_emit_ext_op(DEBUG_OP); |
| 1474 | } |
| 1475 | |
| 1476 | /* Store (op, DEBUG) */ |
| 1477 | void acpigen_write_debug_op(uint8_t op) |
| 1478 | { |
| 1479 | acpigen_write_store(); |
| 1480 | acpigen_emit_byte(op); |
| 1481 | acpigen_emit_ext_op(DEBUG_OP); |
| 1482 | } |
| 1483 | |
Duncan Laurie | ec2e3e4 | 2020-11-03 15:19:08 -0800 | [diff] [blame] | 1484 | /* Store (str, DEBUG) */ |
| 1485 | void acpigen_write_debug_namestr(const char *str) |
| 1486 | { |
| 1487 | acpigen_write_store(); |
| 1488 | acpigen_emit_namestring(str); |
| 1489 | acpigen_emit_ext_op(DEBUG_OP); |
| 1490 | } |
| 1491 | |
Cliff Huang | e608308 | 2023-01-19 21:18:23 -0800 | [diff] [blame] | 1492 | /* Concatenate (str1, res, tmp_res) |
| 1493 | Store(tmp_res, DEBUG) */ |
| 1494 | void acpigen_write_debug_concatenate_string_op(const char *str, uint8_t res, |
| 1495 | uint8_t tmp_res) |
| 1496 | { |
| 1497 | acpigen_concatenate_string_op(str, res, tmp_res); |
| 1498 | acpigen_write_debug_op(tmp_res); |
| 1499 | } |
| 1500 | |
Cliff Huang | 063a1b8 | 2023-02-18 00:17:26 -0800 | [diff] [blame] | 1501 | static void acpigen_tx_byte(unsigned char byte, void *data) |
| 1502 | { |
| 1503 | acpigen_emit_byte(byte); |
| 1504 | } |
| 1505 | |
| 1506 | /* Store("formatted string", DEBUG) */ |
| 1507 | void acpigen_write_debug_sprintf(const char *fmt, ...) |
| 1508 | { |
| 1509 | va_list args; |
| 1510 | |
| 1511 | acpigen_write_store(); |
| 1512 | |
| 1513 | acpigen_emit_byte(STRING_PREFIX); |
| 1514 | va_start(args, fmt); |
| 1515 | vtxprintf(acpigen_tx_byte, fmt, args, NULL); |
| 1516 | va_end(args); |
| 1517 | acpigen_emit_byte('\0'); |
| 1518 | |
| 1519 | acpigen_emit_ext_op(DEBUG_OP); |
| 1520 | } |
| 1521 | |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1522 | void acpigen_write_if(void) |
| 1523 | { |
| 1524 | acpigen_emit_byte(IF_OP); |
| 1525 | acpigen_write_len_f(); |
| 1526 | } |
| 1527 | |
| 1528 | /* If (And (arg1, arg2)) */ |
| 1529 | void acpigen_write_if_and(uint8_t arg1, uint8_t arg2) |
| 1530 | { |
| 1531 | acpigen_write_if(); |
| 1532 | acpigen_emit_byte(AND_OP); |
| 1533 | acpigen_emit_byte(arg1); |
| 1534 | acpigen_emit_byte(arg2); |
| 1535 | } |
| 1536 | |
Furquan Shaikh | 1fc6bb9 | 2016-11-14 14:16:26 -0800 | [diff] [blame] | 1537 | /* |
Duncan Laurie | 2fe7471 | 2020-06-01 17:36:56 -0700 | [diff] [blame] | 1538 | * Generates ACPI code for checking if operand1 and operand2 are equal. |
| 1539 | * Both operand1 and operand2 are ACPI ops. |
| 1540 | * |
| 1541 | * If (Lequal (op,1 op2)) |
| 1542 | */ |
| 1543 | void acpigen_write_if_lequal_op_op(uint8_t op1, uint8_t op2) |
| 1544 | { |
| 1545 | acpigen_write_if(); |
| 1546 | acpigen_emit_byte(LEQUAL_OP); |
| 1547 | acpigen_emit_byte(op1); |
| 1548 | acpigen_emit_byte(op2); |
| 1549 | } |
| 1550 | |
| 1551 | /* |
Cliff Huang | 24f3dc8 | 2023-02-04 21:11:51 -0800 | [diff] [blame] | 1552 | * Generates ACPI code for checking if operand1 is greater than operand2. |
| 1553 | * Both operand1 and operand2 are ACPI ops. |
| 1554 | * |
| 1555 | * If (Lgreater (op1 op2)) |
| 1556 | */ |
| 1557 | void acpigen_write_if_lgreater_op_op(uint8_t op1, uint8_t op2) |
| 1558 | { |
| 1559 | acpigen_write_if(); |
| 1560 | acpigen_emit_byte(LGREATER_OP); |
| 1561 | acpigen_emit_byte(op1); |
| 1562 | acpigen_emit_byte(op2); |
| 1563 | } |
| 1564 | |
| 1565 | /* |
Furquan Shaikh | 1fc6bb9 | 2016-11-14 14:16:26 -0800 | [diff] [blame] | 1566 | * Generates ACPI code for checking if operand1 and operand2 are equal, where, |
| 1567 | * operand1 is ACPI op and operand2 is an integer. |
| 1568 | * |
| 1569 | * If (Lequal (op, val)) |
| 1570 | */ |
| 1571 | void acpigen_write_if_lequal_op_int(uint8_t op, uint64_t val) |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1572 | { |
| 1573 | acpigen_write_if(); |
| 1574 | acpigen_emit_byte(LEQUAL_OP); |
Furquan Shaikh | 1fc6bb9 | 2016-11-14 14:16:26 -0800 | [diff] [blame] | 1575 | acpigen_emit_byte(op); |
| 1576 | acpigen_write_integer(val); |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
Furquan Shaikh | 2c213d3 | 2020-04-27 23:06:30 -0700 | [diff] [blame] | 1579 | /* |
Cliff Huang | 24f3dc8 | 2023-02-04 21:11:51 -0800 | [diff] [blame] | 1580 | * Generates ACPI code for checking if operand is greater than the value, where, |
| 1581 | * operand is ACPI op and val is an integer. |
| 1582 | * |
| 1583 | * If (Lgreater (op, val)) |
| 1584 | */ |
| 1585 | void acpigen_write_if_lgreater_op_int(uint8_t op, uint64_t val) |
| 1586 | { |
| 1587 | acpigen_write_if(); |
| 1588 | acpigen_emit_byte(LGREATER_OP); |
| 1589 | acpigen_emit_byte(op); |
| 1590 | acpigen_write_integer(val); |
| 1591 | } |
| 1592 | |
| 1593 | /* |
Furquan Shaikh | 2c213d3 | 2020-04-27 23:06:30 -0700 | [diff] [blame] | 1594 | * Generates ACPI code for checking if operand1 and operand2 are equal, where, |
| 1595 | * operand1 is namestring and operand2 is an integer. |
| 1596 | * |
| 1597 | * If (Lequal ("namestr", val)) |
| 1598 | */ |
| 1599 | void acpigen_write_if_lequal_namestr_int(const char *namestr, uint64_t val) |
| 1600 | { |
| 1601 | acpigen_write_if(); |
| 1602 | acpigen_emit_byte(LEQUAL_OP); |
| 1603 | acpigen_emit_namestring(namestr); |
| 1604 | acpigen_write_integer(val); |
| 1605 | } |
| 1606 | |
Tim Wawrzynczak | c4ca2f6 | 2021-07-01 11:18:50 -0600 | [diff] [blame] | 1607 | /* |
Cliff Huang | 24f3dc8 | 2023-02-04 21:11:51 -0800 | [diff] [blame] | 1608 | * Generates ACPI code for checking if operand1 and operand2 are equal, where, |
| 1609 | * operand1 is namestring and operand2 is an integer. |
| 1610 | * |
| 1611 | * If (Lgreater ("namestr", val)) |
| 1612 | */ |
| 1613 | void acpigen_write_if_lgreater_namestr_int(const char *namestr, uint64_t val) |
| 1614 | { |
| 1615 | acpigen_write_if(); |
| 1616 | acpigen_emit_byte(LGREATER_OP); |
| 1617 | acpigen_emit_namestring(namestr); |
| 1618 | acpigen_write_integer(val); |
| 1619 | } |
| 1620 | |
| 1621 | /* |
Tim Wawrzynczak | c4ca2f6 | 2021-07-01 11:18:50 -0600 | [diff] [blame] | 1622 | * Generates ACPI code to check at runtime if an object named `namestring` |
| 1623 | * exists, and leaves the If scope open to continue execute code when this |
| 1624 | * is true. NOTE: Requires matching acpigen_write_if_end(). |
| 1625 | * |
| 1626 | * If (CondRefOf (NAME)) |
| 1627 | */ |
| 1628 | void acpigen_write_if_cond_ref_of(const char *namestring) |
| 1629 | { |
| 1630 | acpigen_write_if(); |
| 1631 | acpigen_emit_ext_op(COND_REFOF_OP); |
| 1632 | acpigen_emit_namestring(namestring); |
| 1633 | acpigen_emit_byte(ZERO_OP); /* ignore COND_REFOF_OP destination */ |
| 1634 | } |
| 1635 | |
Jakub Czapiga | 61fcb7e | 2021-02-19 11:44:22 +0100 | [diff] [blame] | 1636 | /* Closes previously opened if statement and generates ACPI code for else statement. */ |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1637 | void acpigen_write_else(void) |
| 1638 | { |
Jakub Czapiga | 61fcb7e | 2021-02-19 11:44:22 +0100 | [diff] [blame] | 1639 | acpigen_pop_len(); |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1640 | acpigen_emit_byte(ELSE_OP); |
| 1641 | acpigen_write_len_f(); |
| 1642 | } |
Furquan Shaikh | 0a48aee | 2016-10-20 07:12:49 -0700 | [diff] [blame] | 1643 | |
Duncan Laurie | 3685820 | 2020-10-06 21:01:51 +0000 | [diff] [blame] | 1644 | void acpigen_write_shiftleft_op_int(uint8_t src_result, uint64_t count) |
| 1645 | { |
| 1646 | acpigen_emit_byte(SHIFT_LEFT_OP); |
| 1647 | acpigen_emit_byte(src_result); |
| 1648 | acpigen_write_integer(count); |
| 1649 | acpigen_emit_byte(ZERO_OP); |
| 1650 | } |
| 1651 | |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1652 | void acpigen_write_to_buffer(uint8_t src, uint8_t dst) |
| 1653 | { |
| 1654 | acpigen_emit_byte(TO_BUFFER_OP); |
| 1655 | acpigen_emit_byte(src); |
| 1656 | acpigen_emit_byte(dst); |
| 1657 | } |
| 1658 | |
| 1659 | void acpigen_write_to_integer(uint8_t src, uint8_t dst) |
| 1660 | { |
| 1661 | acpigen_emit_byte(TO_INTEGER_OP); |
| 1662 | acpigen_emit_byte(src); |
| 1663 | acpigen_emit_byte(dst); |
| 1664 | } |
| 1665 | |
Aaron Durbin | 80bc091 | 2020-08-19 23:17:42 -0600 | [diff] [blame] | 1666 | void acpigen_write_to_integer_from_namestring(const char *source, uint8_t dst_op) |
| 1667 | { |
| 1668 | acpigen_emit_byte(TO_INTEGER_OP); |
| 1669 | acpigen_emit_namestring(source); |
| 1670 | acpigen_emit_byte(dst_op); |
| 1671 | } |
| 1672 | |
Rizwan Qureshi | aca4c94 | 2017-03-06 21:50:26 +0530 | [diff] [blame] | 1673 | void acpigen_write_byte_buffer(uint8_t *arr, size_t size) |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1674 | { |
Rizwan Qureshi | aca4c94 | 2017-03-06 21:50:26 +0530 | [diff] [blame] | 1675 | size_t i; |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1676 | |
| 1677 | acpigen_emit_byte(BUFFER_OP); |
| 1678 | acpigen_write_len_f(); |
Rizwan Qureshi | aca4c94 | 2017-03-06 21:50:26 +0530 | [diff] [blame] | 1679 | acpigen_write_integer(size); |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1680 | |
| 1681 | for (i = 0; i < size; i++) |
| 1682 | acpigen_emit_byte(arr[i]); |
| 1683 | |
| 1684 | acpigen_pop_len(); |
| 1685 | } |
| 1686 | |
Rizwan Qureshi | aca4c94 | 2017-03-06 21:50:26 +0530 | [diff] [blame] | 1687 | void acpigen_write_return_byte_buffer(uint8_t *arr, size_t size) |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1688 | { |
| 1689 | acpigen_emit_byte(RETURN_OP); |
| 1690 | acpigen_write_byte_buffer(arr, size); |
| 1691 | } |
| 1692 | |
| 1693 | void acpigen_write_return_singleton_buffer(uint8_t arg) |
| 1694 | { |
| 1695 | acpigen_write_return_byte_buffer(&arg, 1); |
| 1696 | } |
| 1697 | |
Duncan Laurie | 2fe7471 | 2020-06-01 17:36:56 -0700 | [diff] [blame] | 1698 | void acpigen_write_return_op(uint8_t arg) |
| 1699 | { |
| 1700 | acpigen_emit_byte(RETURN_OP); |
| 1701 | acpigen_emit_byte(arg); |
| 1702 | } |
| 1703 | |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1704 | void acpigen_write_return_byte(uint8_t arg) |
| 1705 | { |
| 1706 | acpigen_emit_byte(RETURN_OP); |
| 1707 | acpigen_write_byte(arg); |
| 1708 | } |
| 1709 | |
Naresh G Solanki | 05abe43 | 2016-11-17 00:16:29 +0530 | [diff] [blame] | 1710 | void acpigen_write_return_integer(uint64_t arg) |
| 1711 | { |
| 1712 | acpigen_emit_byte(RETURN_OP); |
| 1713 | acpigen_write_integer(arg); |
| 1714 | } |
| 1715 | |
Duncan Laurie | ec2e3e4 | 2020-11-03 15:19:08 -0800 | [diff] [blame] | 1716 | void acpigen_write_return_namestr(const char *arg) |
| 1717 | { |
| 1718 | acpigen_emit_byte(RETURN_OP); |
| 1719 | acpigen_emit_namestring(arg); |
| 1720 | } |
| 1721 | |
Naresh G Solanki | 05abe43 | 2016-11-17 00:16:29 +0530 | [diff] [blame] | 1722 | void acpigen_write_return_string(const char *arg) |
| 1723 | { |
| 1724 | acpigen_emit_byte(RETURN_OP); |
| 1725 | acpigen_write_string(arg); |
| 1726 | } |
| 1727 | |
Duncan Laurie | beb2af4 | 2018-05-07 14:26:59 -0700 | [diff] [blame] | 1728 | void acpigen_write_upc(enum acpi_upc_type type) |
| 1729 | { |
| 1730 | acpigen_write_name("_UPC"); |
| 1731 | acpigen_write_package(4); |
| 1732 | /* Connectable */ |
| 1733 | acpigen_write_byte(type == UPC_TYPE_UNUSED ? 0 : 0xff); |
| 1734 | /* Type */ |
| 1735 | acpigen_write_byte(type); |
| 1736 | /* Reserved0 */ |
| 1737 | acpigen_write_zero(); |
| 1738 | /* Reserved1 */ |
| 1739 | acpigen_write_zero(); |
| 1740 | acpigen_pop_len(); |
| 1741 | } |
| 1742 | |
Duncan Laurie | 3e7197a | 2018-05-07 14:18:13 -0700 | [diff] [blame] | 1743 | void acpigen_write_pld(const struct acpi_pld *pld) |
| 1744 | { |
| 1745 | uint8_t buf[20]; |
| 1746 | |
| 1747 | if (acpi_pld_to_buffer(pld, buf, ARRAY_SIZE(buf)) < 0) |
| 1748 | return; |
| 1749 | |
| 1750 | acpigen_write_name("_PLD"); |
Matt Delco | 4929f43 | 2019-01-30 11:40:44 -0800 | [diff] [blame] | 1751 | acpigen_write_package(1); |
Duncan Laurie | 3e7197a | 2018-05-07 14:18:13 -0700 | [diff] [blame] | 1752 | acpigen_write_byte_buffer(buf, ARRAY_SIZE(buf)); |
Matt Delco | 4929f43 | 2019-01-30 11:40:44 -0800 | [diff] [blame] | 1753 | acpigen_pop_len(); |
Duncan Laurie | 3e7197a | 2018-05-07 14:18:13 -0700 | [diff] [blame] | 1754 | } |
| 1755 | |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 1756 | void acpigen_write_dsm(const char *uuid, void (**callbacks)(void *), size_t count, void *arg) |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1757 | { |
| 1758 | struct dsm_uuid id = DSM_UUID(uuid, callbacks, count, arg); |
| 1759 | acpigen_write_dsm_uuid_arr(&id, 1); |
| 1760 | } |
| 1761 | |
Tim Wawrzynczak | d96f3a2 | 2021-07-14 15:56:57 -0600 | [diff] [blame] | 1762 | /* |
| 1763 | * Create a supported functions bitmask |
| 1764 | * bit 0: other functions than 0 are supported |
| 1765 | * bits 1-x: function x supported |
| 1766 | */ |
| 1767 | static void acpigen_dsm_uuid_enum_functions(const struct dsm_uuid *id) |
| 1768 | { |
| 1769 | const size_t bytes = DIV_ROUND_UP(id->count, BITS_PER_BYTE); |
| 1770 | uint8_t *buffer = alloca(bytes); |
| 1771 | bool set = false; |
| 1772 | size_t cb_idx = 0; |
| 1773 | |
| 1774 | memset(buffer, 0, bytes); |
| 1775 | |
| 1776 | for (size_t i = 0; i < bytes; i++) { |
| 1777 | for (size_t j = 0; j < BITS_PER_BYTE; j++) { |
| 1778 | if (cb_idx >= id->count) |
| 1779 | break; |
| 1780 | |
| 1781 | if (id->callbacks[cb_idx++]) { |
| 1782 | set = true; |
| 1783 | buffer[i] |= BIT(j); |
| 1784 | } |
| 1785 | } |
| 1786 | } |
| 1787 | |
| 1788 | if (set) |
| 1789 | buffer[0] |= BIT(0); |
| 1790 | |
| 1791 | acpigen_write_return_byte_buffer(buffer, bytes); |
| 1792 | } |
| 1793 | |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1794 | static void acpigen_write_dsm_uuid(struct dsm_uuid *id) |
| 1795 | { |
| 1796 | size_t i; |
| 1797 | |
| 1798 | /* If (LEqual (Local0, ToUUID(uuid))) */ |
| 1799 | acpigen_write_if(); |
| 1800 | acpigen_emit_byte(LEQUAL_OP); |
| 1801 | acpigen_emit_byte(LOCAL0_OP); |
| 1802 | acpigen_write_uuid(id->uuid); |
| 1803 | |
| 1804 | /* ToInteger (Arg2, Local1) */ |
| 1805 | acpigen_write_to_integer(ARG2_OP, LOCAL1_OP); |
| 1806 | |
Tim Wawrzynczak | d96f3a2 | 2021-07-14 15:56:57 -0600 | [diff] [blame] | 1807 | /* If (LEqual(Local1, 0)) */ |
| 1808 | { |
| 1809 | acpigen_write_if_lequal_op_int(LOCAL1_OP, 0); |
| 1810 | if (id->callbacks[0]) |
| 1811 | id->callbacks[0](id->arg); |
| 1812 | else if (id->count) |
| 1813 | acpigen_dsm_uuid_enum_functions(id); |
| 1814 | acpigen_write_if_end(); |
| 1815 | } |
| 1816 | |
| 1817 | for (i = 1; i < id->count; i++) { |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1818 | /* If (LEqual (Local1, i)) */ |
| 1819 | acpigen_write_if_lequal_op_int(LOCAL1_OP, i); |
| 1820 | |
| 1821 | /* Callback to write if handler. */ |
| 1822 | if (id->callbacks[i]) |
| 1823 | id->callbacks[i](id->arg); |
| 1824 | |
Tim Wawrzynczak | d96f3a2 | 2021-07-14 15:56:57 -0600 | [diff] [blame] | 1825 | acpigen_write_if_end(); /* If */ |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | /* Default case: Return (Buffer (One) { 0x0 }) */ |
| 1829 | acpigen_write_return_singleton_buffer(0x0); |
| 1830 | |
Tim Wawrzynczak | d96f3a2 | 2021-07-14 15:56:57 -0600 | [diff] [blame] | 1831 | acpigen_write_if_end(); /* If (LEqual (Local0, ToUUID(uuid))) */ |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1832 | |
| 1833 | } |
| 1834 | |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1835 | /* |
| 1836 | * Generate ACPI AML code for _DSM method. |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1837 | * This function takes as input array of uuid for the device, set of callbacks |
| 1838 | * and argument to pass into the callbacks. Callbacks should ensure that Local0 |
| 1839 | * and Local1 are left untouched. Use of Local2-Local7 is permitted in |
| 1840 | * callbacks. |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1841 | * |
| 1842 | * Arguments passed into _DSM method: |
| 1843 | * Arg0 = UUID |
| 1844 | * Arg1 = Revision |
| 1845 | * Arg2 = Function index |
| 1846 | * Arg3 = Function specific arguments |
| 1847 | * |
| 1848 | * AML code generated would look like: |
| 1849 | * Method (_DSM, 4, Serialized) { |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1850 | * ToBuffer (Arg0, Local0) |
| 1851 | * If (LEqual (Local0, ToUUID(uuid))) { |
| 1852 | * ToInteger (Arg2, Local1) |
| 1853 | * If (LEqual (Local1, 0)) { |
| 1854 | * <acpigen by callback[0]> |
| 1855 | * } |
| 1856 | * ... |
| 1857 | * If (LEqual (Local1, n)) { |
| 1858 | * <acpigen by callback[n]> |
| 1859 | * } |
| 1860 | * Return (Buffer (One) { 0x0 }) |
| 1861 | * } |
| 1862 | * ... |
| 1863 | * If (LEqual (Local0, ToUUID(uuidn))) { |
| 1864 | * ... |
| 1865 | * } |
| 1866 | * Return (Buffer (One) { 0x0 }) |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1867 | * } |
| 1868 | */ |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1869 | void acpigen_write_dsm_uuid_arr(struct dsm_uuid *ids, size_t count) |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1870 | { |
| 1871 | size_t i; |
| 1872 | |
| 1873 | /* Method (_DSM, 4, Serialized) */ |
| 1874 | acpigen_write_method_serialized("_DSM", 0x4); |
| 1875 | |
| 1876 | /* ToBuffer (Arg0, Local0) */ |
| 1877 | acpigen_write_to_buffer(ARG0_OP, LOCAL0_OP); |
| 1878 | |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1879 | for (i = 0; i < count; i++) |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1880 | acpigen_write_dsm_uuid(&ids[i]); |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1881 | |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1882 | /* Return (Buffer (One) { 0x0 }) */ |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1883 | acpigen_write_return_singleton_buffer(0x0); |
| 1884 | |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1885 | acpigen_pop_len(); /* Method _DSM */ |
| 1886 | } |
| 1887 | |
Matt Delco | b425bc8 | 2018-08-13 13:36:27 -0700 | [diff] [blame] | 1888 | void acpigen_write_CPPC_package(const struct cppc_config *config) |
| 1889 | { |
| 1890 | u32 i; |
| 1891 | u32 max; |
| 1892 | switch (config->version) { |
| 1893 | case 1: |
| 1894 | max = CPPC_MAX_FIELDS_VER_1; |
| 1895 | break; |
| 1896 | case 2: |
| 1897 | max = CPPC_MAX_FIELDS_VER_2; |
| 1898 | break; |
| 1899 | case 3: |
| 1900 | max = CPPC_MAX_FIELDS_VER_3; |
| 1901 | break; |
| 1902 | default: |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 1903 | printk(BIOS_ERR, "CPPC version %u is not implemented\n", config->version); |
Matt Delco | b425bc8 | 2018-08-13 13:36:27 -0700 | [diff] [blame] | 1904 | return; |
| 1905 | } |
| 1906 | acpigen_write_name(CPPC_PACKAGE_NAME); |
| 1907 | |
| 1908 | /* Adding 2 to account for length and version fields */ |
| 1909 | acpigen_write_package(max + 2); |
| 1910 | acpigen_write_dword(max + 2); |
| 1911 | |
| 1912 | acpigen_write_byte(config->version); |
| 1913 | |
| 1914 | for (i = 0; i < max; ++i) { |
Michael Niewöhner | 38107fa | 2021-10-05 22:22:21 +0200 | [diff] [blame] | 1915 | const cppc_entry_t *entry = &config->entries[i]; |
| 1916 | if (entry->type == CPPC_TYPE_DWORD) |
| 1917 | acpigen_write_dword(entry->dword); |
| 1918 | else |
| 1919 | acpigen_write_register_resource(&entry->reg); |
Matt Delco | b425bc8 | 2018-08-13 13:36:27 -0700 | [diff] [blame] | 1920 | } |
| 1921 | acpigen_pop_len(); |
| 1922 | } |
| 1923 | |
| 1924 | void acpigen_write_CPPC_method(void) |
| 1925 | { |
Michael Niewöhner | b20aac0 | 2020-10-14 19:30:46 +0200 | [diff] [blame] | 1926 | char pscope[16]; |
Felix Held | f0a8b04 | 2023-05-12 15:55:06 +0200 | [diff] [blame] | 1927 | snprintf(pscope, sizeof(pscope), |
| 1928 | "\\_SB." CONFIG_ACPI_CPU_STRING "." CPPC_PACKAGE_NAME, 0); |
Michael Niewöhner | b20aac0 | 2020-10-14 19:30:46 +0200 | [diff] [blame] | 1929 | |
Matt Delco | b425bc8 | 2018-08-13 13:36:27 -0700 | [diff] [blame] | 1930 | acpigen_write_method("_CPC", 0); |
| 1931 | acpigen_emit_byte(RETURN_OP); |
Michael Niewöhner | b20aac0 | 2020-10-14 19:30:46 +0200 | [diff] [blame] | 1932 | acpigen_emit_namestring(pscope); |
Matt Delco | b425bc8 | 2018-08-13 13:36:27 -0700 | [diff] [blame] | 1933 | acpigen_pop_len(); |
| 1934 | } |
| 1935 | |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 1936 | /* |
| 1937 | * Generate ACPI AML code for _ROM method. |
| 1938 | * This function takes as input ROM data and ROM length. |
| 1939 | * |
Patrick Rudolph | 65cbbe7 | 2018-05-02 19:07:57 +0200 | [diff] [blame] | 1940 | * The ACPI spec isn't clear about what should happen at the end of the |
| 1941 | * ROM. Tests showed that it shouldn't truncate, but fill the remaining |
| 1942 | * bytes in the returned buffer with zeros. |
| 1943 | * |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 1944 | * Arguments passed into _DSM method: |
| 1945 | * Arg0 = Offset in Bytes |
| 1946 | * Arg1 = Bytes to return |
| 1947 | * |
| 1948 | * Example: |
| 1949 | * acpigen_write_rom(0xdeadbeef, 0x10000) |
| 1950 | * |
| 1951 | * AML code generated would look like: |
| 1952 | * Method (_ROM, 2, NotSerialized) { |
| 1953 | * |
| 1954 | * OperationRegion("ROMS", SYSTEMMEMORY, 0xdeadbeef, 0x10000) |
| 1955 | * Field (ROMS, AnyAcc, NoLock, Preserve) |
| 1956 | * { |
| 1957 | * Offset (0), |
| 1958 | * RBF0, 0x80000 |
| 1959 | * } |
| 1960 | * |
| 1961 | * Store (Arg0, Local0) |
| 1962 | * Store (Arg1, Local1) |
| 1963 | * |
| 1964 | * If (LGreater (Local1, 0x1000)) |
| 1965 | * { |
| 1966 | * Store (0x1000, Local1) |
| 1967 | * } |
| 1968 | * |
Patrick Rudolph | 65cbbe7 | 2018-05-02 19:07:57 +0200 | [diff] [blame] | 1969 | * Store (Local1, Local3) |
| 1970 | * |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 1971 | * If (LGreater (Local0, 0x10000)) |
| 1972 | * { |
| 1973 | * Return(Buffer(Local1){0}) |
| 1974 | * } |
| 1975 | * |
| 1976 | * If (LGreater (Local0, 0x0f000)) |
| 1977 | * { |
| 1978 | * Subtract (0x10000, Local0, Local2) |
| 1979 | * If (LGreater (Local1, Local2)) |
| 1980 | * { |
| 1981 | * Store (Local2, Local1) |
| 1982 | * } |
| 1983 | * } |
| 1984 | * |
Patrick Rudolph | 65cbbe7 | 2018-05-02 19:07:57 +0200 | [diff] [blame] | 1985 | * Name (ROM1, Buffer (Local3) {0}) |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 1986 | * |
| 1987 | * Multiply (Local0, 0x08, Local0) |
| 1988 | * Multiply (Local1, 0x08, Local1) |
| 1989 | * |
| 1990 | * CreateField (RBF0, Local0, Local1, TMPB) |
| 1991 | * Store (TMPB, ROM1) |
| 1992 | * Return (ROM1) |
| 1993 | * } |
| 1994 | */ |
| 1995 | |
| 1996 | void acpigen_write_rom(void *bios, const size_t length) |
| 1997 | { |
| 1998 | ASSERT(bios) |
| 1999 | ASSERT(length) |
| 2000 | |
Jonathan Neuschäfer | 6b0102d | 2018-09-12 12:26:45 +0200 | [diff] [blame] | 2001 | /* Method (_ROM, 2, Serialized) */ |
Marc Jones | 24462e6 | 2018-08-15 23:57:28 -0600 | [diff] [blame] | 2002 | acpigen_write_method_serialized("_ROM", 2); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2003 | |
| 2004 | /* OperationRegion("ROMS", SYSTEMMEMORY, current, length) */ |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 2005 | struct opregion opreg = OPREGION("ROMS", SYSTEMMEMORY, (uintptr_t)bios, length); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2006 | acpigen_write_opregion(&opreg); |
| 2007 | |
| 2008 | struct fieldlist l[] = { |
| 2009 | FIELDLIST_OFFSET(0), |
| 2010 | FIELDLIST_NAMESTR("RBF0", 8 * length), |
| 2011 | }; |
| 2012 | |
| 2013 | /* Field (ROMS, AnyAcc, NoLock, Preserve) |
| 2014 | * { |
| 2015 | * Offset (0), |
| 2016 | * RBF0, 0x80000 |
| 2017 | * } */ |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 2018 | acpigen_write_field(opreg.name, l, 2, FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2019 | |
| 2020 | /* Store (Arg0, Local0) */ |
Felix Held | f28f27b | 2023-02-09 16:26:26 +0100 | [diff] [blame] | 2021 | acpigen_write_store_ops(ARG0_OP, LOCAL0_OP); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2022 | |
| 2023 | /* Store (Arg1, Local1) */ |
Felix Held | f28f27b | 2023-02-09 16:26:26 +0100 | [diff] [blame] | 2024 | acpigen_write_store_ops(ARG1_OP, LOCAL1_OP); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2025 | |
| 2026 | /* ACPI SPEC requires to return at maximum 4KiB */ |
| 2027 | /* If (LGreater (Local1, 0x1000)) */ |
Felix Held | 383a06e | 2023-02-09 16:25:38 +0100 | [diff] [blame] | 2028 | acpigen_write_if_lgreater_op_int(LOCAL1_OP, 0x1000); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2029 | |
| 2030 | /* Store (0x1000, Local1) */ |
Felix Held | f28f27b | 2023-02-09 16:26:26 +0100 | [diff] [blame] | 2031 | acpigen_write_store_int_to_op(0x1000, LOCAL1_OP); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2032 | |
| 2033 | /* Pop if */ |
| 2034 | acpigen_pop_len(); |
| 2035 | |
Patrick Rudolph | 65cbbe7 | 2018-05-02 19:07:57 +0200 | [diff] [blame] | 2036 | /* Store (Local1, Local3) */ |
Felix Held | f28f27b | 2023-02-09 16:26:26 +0100 | [diff] [blame] | 2037 | acpigen_write_store_ops(LOCAL1_OP, LOCAL3_OP); |
Patrick Rudolph | 65cbbe7 | 2018-05-02 19:07:57 +0200 | [diff] [blame] | 2038 | |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2039 | /* If (LGreater (Local0, length)) */ |
Felix Held | 383a06e | 2023-02-09 16:25:38 +0100 | [diff] [blame] | 2040 | acpigen_write_if_lgreater_op_int(LOCAL0_OP, length); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2041 | |
| 2042 | /* Return(Buffer(Local1){0}) */ |
| 2043 | acpigen_emit_byte(RETURN_OP); |
| 2044 | acpigen_emit_byte(BUFFER_OP); |
| 2045 | acpigen_write_len_f(); |
| 2046 | acpigen_emit_byte(LOCAL1_OP); |
| 2047 | acpigen_emit_byte(0); |
| 2048 | acpigen_pop_len(); |
| 2049 | |
| 2050 | /* Pop if */ |
| 2051 | acpigen_pop_len(); |
| 2052 | |
| 2053 | /* If (LGreater (Local0, length - 4096)) */ |
Felix Held | 383a06e | 2023-02-09 16:25:38 +0100 | [diff] [blame] | 2054 | acpigen_write_if_lgreater_op_int(LOCAL0_OP, length - 4096); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2055 | |
| 2056 | /* Subtract (length, Local0, Local2) */ |
| 2057 | acpigen_emit_byte(SUBTRACT_OP); |
| 2058 | acpigen_write_integer(length); |
| 2059 | acpigen_emit_byte(LOCAL0_OP); |
| 2060 | acpigen_emit_byte(LOCAL2_OP); |
| 2061 | |
| 2062 | /* If (LGreater (Local1, Local2)) */ |
Felix Held | 383a06e | 2023-02-09 16:25:38 +0100 | [diff] [blame] | 2063 | acpigen_write_if_lgreater_op_op(LOCAL1_OP, LOCAL2_OP); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2064 | |
| 2065 | /* Store (Local2, Local1) */ |
Felix Held | f28f27b | 2023-02-09 16:26:26 +0100 | [diff] [blame] | 2066 | acpigen_write_store_ops(LOCAL2_OP, LOCAL1_OP); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2067 | |
| 2068 | /* Pop if */ |
| 2069 | acpigen_pop_len(); |
| 2070 | |
| 2071 | /* Pop if */ |
| 2072 | acpigen_pop_len(); |
| 2073 | |
Patrick Rudolph | 65cbbe7 | 2018-05-02 19:07:57 +0200 | [diff] [blame] | 2074 | /* Name (ROM1, Buffer (Local3) {0}) */ |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2075 | acpigen_write_name("ROM1"); |
| 2076 | acpigen_emit_byte(BUFFER_OP); |
| 2077 | acpigen_write_len_f(); |
Patrick Rudolph | 65cbbe7 | 2018-05-02 19:07:57 +0200 | [diff] [blame] | 2078 | acpigen_emit_byte(LOCAL3_OP); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2079 | acpigen_emit_byte(0); |
| 2080 | acpigen_pop_len(); |
| 2081 | |
| 2082 | /* Multiply (Local1, 0x08, Local1) */ |
| 2083 | acpigen_emit_byte(MULTIPLY_OP); |
| 2084 | acpigen_emit_byte(LOCAL1_OP); |
| 2085 | acpigen_write_integer(0x08); |
| 2086 | acpigen_emit_byte(LOCAL1_OP); |
| 2087 | |
| 2088 | /* Multiply (Local0, 0x08, Local0) */ |
| 2089 | acpigen_emit_byte(MULTIPLY_OP); |
| 2090 | acpigen_emit_byte(LOCAL0_OP); |
| 2091 | acpigen_write_integer(0x08); |
| 2092 | acpigen_emit_byte(LOCAL0_OP); |
| 2093 | |
| 2094 | /* CreateField (RBF0, Local0, Local1, TMPB) */ |
| 2095 | acpigen_emit_ext_op(CREATEFIELD_OP); |
| 2096 | acpigen_emit_namestring("RBF0"); |
| 2097 | acpigen_emit_byte(LOCAL0_OP); |
| 2098 | acpigen_emit_byte(LOCAL1_OP); |
| 2099 | acpigen_emit_namestring("TMPB"); |
| 2100 | |
| 2101 | /* Store (TMPB, ROM1) */ |
Felix Held | f28f27b | 2023-02-09 16:26:26 +0100 | [diff] [blame] | 2102 | acpigen_write_store_namestr_to_namestr("TMPB", "ROM1"); |
Patrick Rudolph | 6be6df0 | 2017-04-28 16:34:26 +0200 | [diff] [blame] | 2103 | |
| 2104 | /* Return (ROM1) */ |
| 2105 | acpigen_emit_byte(RETURN_OP); |
| 2106 | acpigen_emit_namestring("ROM1"); |
| 2107 | |
| 2108 | /* Pop method */ |
| 2109 | acpigen_pop_len(); |
| 2110 | } |
| 2111 | |
Furquan Shaikh | bf4845d | 2017-02-20 22:56:25 -0800 | [diff] [blame] | 2112 | /* |
| 2113 | * Helper functions for enabling/disabling Tx GPIOs based on the GPIO |
| 2114 | * polarity. These functions end up calling acpigen_soc_{set,clear}_tx_gpio to |
| 2115 | * make callbacks into SoC acpigen code. |
| 2116 | * |
| 2117 | * Returns 0 on success and -1 on error. |
| 2118 | */ |
Duncan Laurie | 30c3f91 | 2020-10-09 04:48:53 +0000 | [diff] [blame] | 2119 | int acpigen_enable_tx_gpio(const struct acpi_gpio *gpio) |
Furquan Shaikh | bf4845d | 2017-02-20 22:56:25 -0800 | [diff] [blame] | 2120 | { |
Furquan Shaikh | d2d5e44 | 2020-07-01 01:37:13 -0700 | [diff] [blame] | 2121 | if (gpio->active_low) |
Furquan Shaikh | bf4845d | 2017-02-20 22:56:25 -0800 | [diff] [blame] | 2122 | return acpigen_soc_clear_tx_gpio(gpio->pins[0]); |
Furquan Shaikh | d2d5e44 | 2020-07-01 01:37:13 -0700 | [diff] [blame] | 2123 | else |
| 2124 | return acpigen_soc_set_tx_gpio(gpio->pins[0]); |
Furquan Shaikh | bf4845d | 2017-02-20 22:56:25 -0800 | [diff] [blame] | 2125 | } |
| 2126 | |
Duncan Laurie | 30c3f91 | 2020-10-09 04:48:53 +0000 | [diff] [blame] | 2127 | int acpigen_disable_tx_gpio(const struct acpi_gpio *gpio) |
Furquan Shaikh | bf4845d | 2017-02-20 22:56:25 -0800 | [diff] [blame] | 2128 | { |
Furquan Shaikh | d2d5e44 | 2020-07-01 01:37:13 -0700 | [diff] [blame] | 2129 | if (gpio->active_low) |
Furquan Shaikh | bf4845d | 2017-02-20 22:56:25 -0800 | [diff] [blame] | 2130 | return acpigen_soc_set_tx_gpio(gpio->pins[0]); |
| 2131 | else |
| 2132 | return acpigen_soc_clear_tx_gpio(gpio->pins[0]); |
| 2133 | } |
Jonathan Zhang | 71299c2 | 2020-01-27 11:38:57 -0800 | [diff] [blame] | 2134 | |
Duncan Laurie | 30c3f91 | 2020-10-09 04:48:53 +0000 | [diff] [blame] | 2135 | void acpigen_get_rx_gpio(const struct acpi_gpio *gpio) |
Rajat Jain | 310623b | 2020-02-26 11:02:53 -0800 | [diff] [blame] | 2136 | { |
| 2137 | acpigen_soc_read_rx_gpio(gpio->pins[0]); |
| 2138 | |
Furquan Shaikh | d2d5e44 | 2020-07-01 01:37:13 -0700 | [diff] [blame] | 2139 | if (gpio->active_low) |
Rajat Jain | 310623b | 2020-02-26 11:02:53 -0800 | [diff] [blame] | 2140 | acpigen_write_xor(LOCAL0_OP, 1, LOCAL0_OP); |
| 2141 | } |
| 2142 | |
Duncan Laurie | 30c3f91 | 2020-10-09 04:48:53 +0000 | [diff] [blame] | 2143 | void acpigen_get_tx_gpio(const struct acpi_gpio *gpio) |
Duncan Laurie | 2fe7471 | 2020-06-01 17:36:56 -0700 | [diff] [blame] | 2144 | { |
| 2145 | acpigen_soc_get_tx_gpio(gpio->pins[0]); |
| 2146 | |
Furquan Shaikh | d2d5e44 | 2020-07-01 01:37:13 -0700 | [diff] [blame] | 2147 | if (gpio->active_low) |
Duncan Laurie | 2fe7471 | 2020-06-01 17:36:56 -0700 | [diff] [blame] | 2148 | acpigen_write_xor(LOCAL0_OP, 1, LOCAL0_OP); |
| 2149 | } |
| 2150 | |
Jonathan Zhang | 71299c2 | 2020-01-27 11:38:57 -0800 | [diff] [blame] | 2151 | /* refer to ACPI 6.4.3.5.3 Word Address Space Descriptor section for details */ |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 2152 | void acpigen_resource_word(u16 res_type, u16 gen_flags, u16 type_flags, u16 gran, u16 range_min, |
| 2153 | u16 range_max, u16 translation, u16 length) |
Jonathan Zhang | 71299c2 | 2020-01-27 11:38:57 -0800 | [diff] [blame] | 2154 | { |
Felix Held | b2f2b53 | 2023-05-11 22:22:06 +0200 | [diff] [blame] | 2155 | /* Byte 0: Type 1, Large Item Value 0x8: Word Address Space Descriptor */ |
Jonathan Zhang | 71299c2 | 2020-01-27 11:38:57 -0800 | [diff] [blame] | 2156 | acpigen_emit_byte(0x88); |
| 2157 | /* Byte 1+2: length (0x000d) */ |
| 2158 | acpigen_emit_byte(0x0d); |
| 2159 | acpigen_emit_byte(0x00); |
| 2160 | /* resource type */ |
| 2161 | acpigen_emit_byte(res_type); // 0 - mem, 1 - io, 2 - bus |
| 2162 | /* general flags */ |
| 2163 | acpigen_emit_byte(gen_flags); |
| 2164 | /* type flags */ |
| 2165 | // refer to ACPI Table 6-234 (Memory), 6-235 (IO), 6-236 (Bus) for details |
| 2166 | acpigen_emit_byte(type_flags); |
| 2167 | /* granularity, min, max, translation, length */ |
| 2168 | acpigen_emit_word(gran); |
| 2169 | acpigen_emit_word(range_min); |
| 2170 | acpigen_emit_word(range_max); |
| 2171 | acpigen_emit_word(translation); |
| 2172 | acpigen_emit_word(length); |
| 2173 | } |
| 2174 | |
| 2175 | /* refer to ACPI 6.4.3.5.2 DWord Address Space Descriptor section for details */ |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 2176 | void acpigen_resource_dword(u16 res_type, u16 gen_flags, u16 type_flags, u32 gran, |
| 2177 | u32 range_min, u32 range_max, u32 translation, u32 length) |
Jonathan Zhang | 71299c2 | 2020-01-27 11:38:57 -0800 | [diff] [blame] | 2178 | { |
Felix Held | b2f2b53 | 2023-05-11 22:22:06 +0200 | [diff] [blame] | 2179 | /* Byte 0: Type 1, Large Item Value 0x7: DWord Address Space Descriptor */ |
Jonathan Zhang | 71299c2 | 2020-01-27 11:38:57 -0800 | [diff] [blame] | 2180 | acpigen_emit_byte(0x87); |
| 2181 | /* Byte 1+2: length (0023) */ |
| 2182 | acpigen_emit_byte(23); |
| 2183 | acpigen_emit_byte(0x00); |
| 2184 | /* resource type */ |
| 2185 | acpigen_emit_byte(res_type); // 0 - mem, 1 - io, 2 - bus |
| 2186 | /* general flags */ |
| 2187 | acpigen_emit_byte(gen_flags); |
| 2188 | /* type flags */ |
| 2189 | // refer to ACPI Table 6-234 (Memory), 6-235 (IO), 6-236 (Bus) for details |
| 2190 | acpigen_emit_byte(type_flags); |
| 2191 | /* granularity, min, max, translation, length */ |
| 2192 | acpigen_emit_dword(gran); |
| 2193 | acpigen_emit_dword(range_min); |
| 2194 | acpigen_emit_dword(range_max); |
| 2195 | acpigen_emit_dword(translation); |
| 2196 | acpigen_emit_dword(length); |
| 2197 | } |
| 2198 | |
| 2199 | static void acpigen_emit_qword(u64 data) |
| 2200 | { |
| 2201 | acpigen_emit_dword(data & 0xffffffff); |
| 2202 | acpigen_emit_dword((data >> 32) & 0xffffffff); |
| 2203 | } |
| 2204 | |
| 2205 | /* refer to ACPI 6.4.3.5.1 QWord Address Space Descriptor section for details */ |
Elyes Haouas | 1f5e1b4 | 2022-02-17 17:44:07 +0100 | [diff] [blame] | 2206 | void acpigen_resource_qword(u16 res_type, u16 gen_flags, u16 type_flags, u64 gran, |
| 2207 | u64 range_min, u64 range_max, u64 translation, u64 length) |
Jonathan Zhang | 71299c2 | 2020-01-27 11:38:57 -0800 | [diff] [blame] | 2208 | { |
Felix Held | b2f2b53 | 2023-05-11 22:22:06 +0200 | [diff] [blame] | 2209 | /* Byte 0: Type 1, Large Item Value 0xa: QWord Address Space Descriptor */ |
Jonathan Zhang | 71299c2 | 2020-01-27 11:38:57 -0800 | [diff] [blame] | 2210 | acpigen_emit_byte(0x8a); |
| 2211 | /* Byte 1+2: length (0x002b) */ |
| 2212 | acpigen_emit_byte(0x2b); |
| 2213 | acpigen_emit_byte(0x00); |
| 2214 | /* resource type */ |
| 2215 | acpigen_emit_byte(res_type); // 0 - mem, 1 - io, 2 - bus |
| 2216 | /* general flags */ |
| 2217 | acpigen_emit_byte(gen_flags); |
| 2218 | /* type flags */ |
| 2219 | // refer to ACPI Table 6-234 (Memory), 6-235 (IO), 6-236 (Bus) for details |
| 2220 | acpigen_emit_byte(type_flags); |
| 2221 | /* granularity, min, max, translation, length */ |
| 2222 | acpigen_emit_qword(gran); |
| 2223 | acpigen_emit_qword(range_min); |
| 2224 | acpigen_emit_qword(range_max); |
| 2225 | acpigen_emit_qword(translation); |
| 2226 | acpigen_emit_qword(length); |
| 2227 | } |
Furquan Shaikh | 1a82923 | 2020-04-23 11:11:05 -0700 | [diff] [blame] | 2228 | |
Felix Held | 5a82f0d | 2023-05-09 16:10:35 +0200 | [diff] [blame] | 2229 | void acpigen_resource_bus_number(u16 bus_base, u16 bus_limit) |
| 2230 | { |
| 2231 | acpigen_resource_word(RSRC_TYPE_BUS, /* res_type */ |
| 2232 | ADDR_SPACE_GENERAL_FLAG_MAX_FIXED |
| 2233 | | ADDR_SPACE_GENERAL_FLAG_MIN_FIXED |
| 2234 | | ADDR_SPACE_GENERAL_FLAG_DEC_POS, /* gen_flags */ |
| 2235 | BUS_NUM_RANGE_RESOURCE_FLAG, /* type_flags */ |
| 2236 | 0, /* gran */ |
| 2237 | bus_base, /* range_min */ |
| 2238 | bus_limit, /* range_max */ |
| 2239 | 0x0, /* translation */ |
| 2240 | bus_limit - bus_base + 1); /* length */ |
| 2241 | } |
| 2242 | |
Felix Held | 6695be6 | 2023-05-09 16:18:51 +0200 | [diff] [blame] | 2243 | void acpigen_resource_io(u16 io_base, u16 io_limit) |
| 2244 | { |
| 2245 | acpigen_resource_word(RSRC_TYPE_IO, /* res_type */ |
| 2246 | ADDR_SPACE_GENERAL_FLAG_MAX_FIXED |
| 2247 | | ADDR_SPACE_GENERAL_FLAG_MIN_FIXED |
| 2248 | | ADDR_SPACE_GENERAL_FLAG_DEC_POS, /* gen_flags */ |
| 2249 | IO_RSRC_FLAG_ENTIRE_RANGE, /* type_flags */ |
| 2250 | 0, /* gran */ |
| 2251 | io_base, /* range_min */ |
| 2252 | io_limit, /* range_max */ |
| 2253 | 0x0, /* translation */ |
| 2254 | io_limit - io_base + 1); /* length */ |
| 2255 | } |
| 2256 | |
Furquan Shaikh | 1a82923 | 2020-04-23 11:11:05 -0700 | [diff] [blame] | 2257 | void acpigen_write_ADR(uint64_t adr) |
| 2258 | { |
| 2259 | acpigen_write_name_qword("_ADR", adr); |
| 2260 | } |
| 2261 | |
Duncan Laurie | 08a942f | 2020-04-29 12:13:14 -0700 | [diff] [blame] | 2262 | /** |
| 2263 | * acpigen_write_ADR_soundwire_device() - SoundWire ACPI Device Address Encoding. |
| 2264 | * @address: SoundWire device address properties. |
| 2265 | * |
| 2266 | * From SoundWire Discovery and Configuration Specification Version 1.0 Table 3. |
| 2267 | * |
| 2268 | * 63..52 - Reserved (0) |
| 2269 | * 51..48 - Zero-based SoundWire Link ID, relative to the immediate parent. |
| 2270 | * Used when a Controller has multiple master devices, each producing a |
| 2271 | * separate SoundWire Link. Set to 0 for single-link controllers. |
| 2272 | * 47..0 - SoundWire Device ID Encoding from specification version 1.2 table 88 |
| 2273 | * 47..44 - SoundWire specification version that this device supports |
| 2274 | * 43..40 - Unique ID for multiple devices |
| 2275 | * 39..24 - MIPI standard manufacturer code |
| 2276 | * 23..08 - Vendor defined part ID |
| 2277 | * 07..00 - MIPI class encoding |
| 2278 | */ |
| 2279 | void acpigen_write_ADR_soundwire_device(const struct soundwire_address *address) |
| 2280 | { |
| 2281 | acpigen_write_ADR((((uint64_t)address->link_id & 0xf) << 48) | |
| 2282 | (((uint64_t)address->version & 0xf) << 44) | |
| 2283 | (((uint64_t)address->unique_id & 0xf) << 40) | |
| 2284 | (((uint64_t)address->manufacturer_id & 0xffff) << 24) | |
| 2285 | (((uint64_t)address->part_id & 0xffff) << 8) | |
| 2286 | (((uint64_t)address->class & 0xff))); |
| 2287 | } |
Tim Wawrzynczak | f694502 | 2020-06-04 15:18:47 -0600 | [diff] [blame] | 2288 | |
| 2289 | void acpigen_notify(const char *namestr, int value) |
| 2290 | { |
| 2291 | acpigen_emit_byte(NOTIFY_OP); |
| 2292 | acpigen_emit_namestring(namestr); |
| 2293 | acpigen_write_integer(value); |
| 2294 | } |
Aaron Durbin | 80bc091 | 2020-08-19 23:17:42 -0600 | [diff] [blame] | 2295 | |
| 2296 | static void _create_field(uint8_t aml_op, uint8_t srcop, size_t byte_offset, const char *name) |
| 2297 | { |
| 2298 | acpigen_emit_byte(aml_op); |
| 2299 | acpigen_emit_byte(srcop); |
| 2300 | acpigen_write_integer(byte_offset); |
| 2301 | acpigen_emit_namestring(name); |
| 2302 | } |
| 2303 | |
| 2304 | void acpigen_write_create_byte_field(uint8_t op, size_t byte_offset, const char *name) |
| 2305 | { |
| 2306 | _create_field(CREATE_BYTE_OP, op, byte_offset, name); |
| 2307 | } |
| 2308 | |
| 2309 | void acpigen_write_create_word_field(uint8_t op, size_t byte_offset, const char *name) |
| 2310 | { |
| 2311 | _create_field(CREATE_WORD_OP, op, byte_offset, name); |
| 2312 | } |
| 2313 | |
| 2314 | void acpigen_write_create_dword_field(uint8_t op, size_t byte_offset, const char *name) |
| 2315 | { |
| 2316 | _create_field(CREATE_DWORD_OP, op, byte_offset, name); |
| 2317 | } |
| 2318 | |
| 2319 | void acpigen_write_create_qword_field(uint8_t op, size_t byte_offset, const char *name) |
| 2320 | { |
| 2321 | _create_field(CREATE_QWORD_OP, op, byte_offset, name); |
| 2322 | } |
Jason Glenesk | ca36aed | 2020-09-15 21:01:57 -0700 | [diff] [blame] | 2323 | |
| 2324 | void acpigen_write_pct_package(const acpi_addr_t *perf_ctrl, const acpi_addr_t *perf_sts) |
| 2325 | { |
| 2326 | acpigen_write_name("_PCT"); |
| 2327 | acpigen_write_package(0x02); |
| 2328 | acpigen_write_register_resource(perf_ctrl); |
| 2329 | acpigen_write_register_resource(perf_sts); |
| 2330 | |
| 2331 | acpigen_pop_len(); |
| 2332 | } |
| 2333 | |
| 2334 | void acpigen_write_xpss_package(const struct acpi_xpss_sw_pstate *pstate_value) |
| 2335 | { |
| 2336 | acpigen_write_package(0x08); |
| 2337 | acpigen_write_dword(pstate_value->core_freq); |
| 2338 | acpigen_write_dword(pstate_value->power); |
| 2339 | acpigen_write_dword(pstate_value->transition_latency); |
| 2340 | acpigen_write_dword(pstate_value->bus_master_latency); |
| 2341 | |
| 2342 | acpigen_write_byte_buffer((uint8_t *)&pstate_value->control_value, sizeof(uint64_t)); |
| 2343 | acpigen_write_byte_buffer((uint8_t *)&pstate_value->status_value, sizeof(uint64_t)); |
| 2344 | acpigen_write_byte_buffer((uint8_t *)&pstate_value->control_mask, sizeof(uint64_t)); |
| 2345 | acpigen_write_byte_buffer((uint8_t *)&pstate_value->status_mask, sizeof(uint64_t)); |
| 2346 | |
| 2347 | acpigen_pop_len(); |
| 2348 | } |
| 2349 | |
| 2350 | void acpigen_write_xpss_object(const struct acpi_xpss_sw_pstate *pstate_values, size_t nentries) |
| 2351 | { |
| 2352 | size_t pstate; |
| 2353 | |
| 2354 | acpigen_write_name("XPSS"); |
| 2355 | acpigen_write_package(nentries); |
| 2356 | for (pstate = 0; pstate < nentries; pstate++) { |
| 2357 | acpigen_write_xpss_package(pstate_values); |
| 2358 | pstate_values++; |
| 2359 | } |
| 2360 | |
| 2361 | acpigen_pop_len(); |
| 2362 | } |
Duncan Laurie | ec2e3e4 | 2020-11-03 15:19:08 -0800 | [diff] [blame] | 2363 | |
| 2364 | /* Delay up to wait_ms until provided namestr matches expected value. */ |
| 2365 | void acpigen_write_delay_until_namestr_int(uint32_t wait_ms, const char *name, uint64_t value) |
| 2366 | { |
| 2367 | uint32_t wait_ms_segment = 1; |
| 2368 | uint32_t segments = wait_ms; |
| 2369 | |
| 2370 | /* Sleep in 16ms segments if delay is more than 32ms. */ |
| 2371 | if (wait_ms > 32) { |
| 2372 | wait_ms_segment = 16; |
| 2373 | segments = wait_ms / 16; |
| 2374 | } |
| 2375 | |
| 2376 | acpigen_write_store_int_to_op(segments, LOCAL7_OP); |
| 2377 | acpigen_emit_byte(WHILE_OP); |
| 2378 | acpigen_write_len_f(); |
| 2379 | acpigen_emit_byte(LGREATER_OP); |
| 2380 | acpigen_emit_byte(LOCAL7_OP); |
| 2381 | acpigen_emit_byte(ZERO_OP); |
| 2382 | |
| 2383 | /* If name is not provided then just delay in a loop. */ |
| 2384 | if (name) { |
| 2385 | acpigen_write_if_lequal_namestr_int(name, value); |
| 2386 | acpigen_emit_byte(BREAK_OP); |
| 2387 | acpigen_pop_len(); /* If */ |
| 2388 | } |
| 2389 | |
| 2390 | acpigen_write_sleep(wait_ms_segment); |
| 2391 | acpigen_emit_byte(DECREMENT_OP); |
| 2392 | acpigen_emit_byte(LOCAL7_OP); |
| 2393 | acpigen_pop_len(); /* While */ |
Cliff Huang | f97598f | 2023-03-01 14:30:41 -0800 | [diff] [blame] | 2394 | |
| 2395 | if (name) { |
| 2396 | acpigen_write_if_lequal_op_op(LOCAL7_OP, ZERO_OP); |
| 2397 | acpigen_write_debug_sprintf("WARN: Wait loop timeout for variable %s", |
| 2398 | name); |
| 2399 | acpigen_pop_len(); /* If */ |
| 2400 | } |
Duncan Laurie | ec2e3e4 | 2020-11-03 15:19:08 -0800 | [diff] [blame] | 2401 | } |
Arthur Heymans | 0eb5974 | 2023-04-25 16:23:37 +0200 | [diff] [blame] | 2402 | |
| 2403 | void acpigen_ssdt_override_sleep_states(bool enable_s1, bool enable_s2, bool enable_s3, |
| 2404 | bool enable_s4) |
| 2405 | { |
| 2406 | assert(!(enable_s1 && CONFIG(ACPI_S1_NOT_SUPPORTED))); |
| 2407 | assert(!(enable_s3 && !CONFIG(HAVE_ACPI_RESUME))); |
| 2408 | assert(!(enable_s4 && CONFIG(DISABLE_ACPI_HIBERNATE))); |
| 2409 | |
| 2410 | acpigen_write_scope("\\"); |
| 2411 | uint32_t sleep_enable = (enable_s1 << 0) | (enable_s2 << 1) |
| 2412 | | (enable_s3 << 2) | (enable_s4 << 3); |
| 2413 | acpigen_write_name_dword("OSFG", sleep_enable); |
| 2414 | acpigen_pop_len(); |
| 2415 | } |