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