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