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