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