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