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