Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 4 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 5 | * Copyright (C) 2009 Rudolf Marek <r.marek@assembler.cz> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 17 | /* How much nesting do we support? */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 18 | #define ACPIGEN_LENSTACK_SIZE 10 |
| 19 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 20 | /* |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 21 | * If you need to change this, change acpigen_write_len_f and |
Vladimir Serbinenko | 8104da7 | 2014-11-09 03:33:51 +0100 | [diff] [blame] | 22 | * acpigen_pop_len |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 23 | */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 24 | |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 25 | #define ACPIGEN_MAXLEN 0xfffff |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 26 | |
Duncan Laurie | 3829f23 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 27 | #include <lib.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 28 | #include <string.h> |
| 29 | #include <arch/acpigen.h> |
| 30 | #include <console/console.h> |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 31 | #include <device/device.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 32 | |
| 33 | static char *gencurrent; |
| 34 | |
| 35 | char *len_stack[ACPIGEN_LENSTACK_SIZE]; |
| 36 | int ltop = 0; |
| 37 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 38 | void acpigen_write_len_f(void) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 39 | { |
| 40 | ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1)) |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 41 | len_stack[ltop++] = gencurrent; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 42 | acpigen_emit_byte(0); |
| 43 | acpigen_emit_byte(0); |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 44 | acpigen_emit_byte(0); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Vladimir Serbinenko | 430363a | 2014-11-02 21:51:22 +0100 | [diff] [blame] | 47 | void acpigen_pop_len(void) |
| 48 | { |
| 49 | int len; |
| 50 | ASSERT(ltop > 0) |
| 51 | char *p = len_stack[--ltop]; |
| 52 | len = gencurrent - p; |
| 53 | ASSERT(len <= ACPIGEN_MAXLEN) |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 54 | /* generate store length for 0xfffff max */ |
| 55 | p[0] = (0x80 | (len & 0xf)); |
Vladimir Serbinenko | 430363a | 2014-11-02 21:51:22 +0100 | [diff] [blame] | 56 | p[1] = (len >> 4 & 0xff); |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 57 | p[2] = (len >> 12 & 0xff); |
Vladimir Serbinenko | 430363a | 2014-11-02 21:51:22 +0100 | [diff] [blame] | 58 | |
| 59 | } |
| 60 | |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 61 | void acpigen_set_current(char *curr) |
| 62 | { |
| 63 | gencurrent = curr; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 66 | char *acpigen_get_current(void) |
| 67 | { |
| 68 | return gencurrent; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 69 | } |
| 70 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 71 | void acpigen_emit_byte(unsigned char b) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 72 | { |
| 73 | (*gencurrent++) = b; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 76 | void acpigen_emit_ext_op(uint8_t op) |
| 77 | { |
| 78 | acpigen_emit_byte(EXT_OP_PREFIX); |
| 79 | acpigen_emit_byte(op); |
| 80 | } |
| 81 | |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 82 | void acpigen_emit_word(unsigned int data) |
| 83 | { |
| 84 | acpigen_emit_byte(data & 0xff); |
| 85 | acpigen_emit_byte((data >> 8) & 0xff); |
| 86 | } |
| 87 | |
| 88 | void acpigen_emit_dword(unsigned int data) |
| 89 | { |
| 90 | acpigen_emit_byte(data & 0xff); |
| 91 | acpigen_emit_byte((data >> 8) & 0xff); |
| 92 | acpigen_emit_byte((data >> 16) & 0xff); |
| 93 | acpigen_emit_byte((data >> 24) & 0xff); |
| 94 | } |
| 95 | |
Duncan Laurie | 85d8027 | 2016-07-02 19:53:54 -0700 | [diff] [blame] | 96 | char *acpigen_write_package(int nr_el) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 97 | { |
Duncan Laurie | 85d8027 | 2016-07-02 19:53:54 -0700 | [diff] [blame] | 98 | char *p; |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 99 | acpigen_emit_byte(PACKAGE_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 100 | acpigen_write_len_f(); |
Duncan Laurie | 85d8027 | 2016-07-02 19:53:54 -0700 | [diff] [blame] | 101 | p = acpigen_get_current(); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 102 | acpigen_emit_byte(nr_el); |
Duncan Laurie | 85d8027 | 2016-07-02 19:53:54 -0700 | [diff] [blame] | 103 | return p; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 106 | void acpigen_write_byte(unsigned int data) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 107 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 108 | acpigen_emit_byte(BYTE_PREFIX); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 109 | acpigen_emit_byte(data & 0xff); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 110 | } |
| 111 | |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 112 | void acpigen_write_word(unsigned int data) |
| 113 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 114 | acpigen_emit_byte(WORD_PREFIX); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 115 | acpigen_emit_word(data); |
| 116 | } |
| 117 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 118 | void acpigen_write_dword(unsigned int data) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 119 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 120 | acpigen_emit_byte(DWORD_PREFIX); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 121 | acpigen_emit_dword(data); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 124 | void acpigen_write_qword(uint64_t data) |
Carl-Daniel Hailfinger | d58671c | 2009-02-17 21:38:51 +0000 | [diff] [blame] | 125 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 126 | acpigen_emit_byte(QWORD_PREFIX); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 127 | acpigen_emit_dword(data & 0xffffffff); |
| 128 | acpigen_emit_dword((data >> 32) & 0xffffffff); |
Carl-Daniel Hailfinger | d58671c | 2009-02-17 21:38:51 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 131 | void acpigen_write_zero(void) |
| 132 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 133 | acpigen_emit_byte(ZERO_OP); |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | void acpigen_write_one(void) |
| 137 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 138 | acpigen_emit_byte(ONE_OP); |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | void acpigen_write_ones(void) |
| 142 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 143 | acpigen_emit_byte(ONES_OP); |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void acpigen_write_integer(uint64_t data) |
| 147 | { |
| 148 | if (data == 0) |
| 149 | acpigen_write_zero(); |
| 150 | else if (data == 1) |
| 151 | acpigen_write_one(); |
| 152 | else if (data <= 0xff) |
| 153 | acpigen_write_byte((unsigned char)data); |
| 154 | else if (data <= 0xffff) |
| 155 | acpigen_write_word((unsigned int)data); |
| 156 | else if (data <= 0xffffffff) |
| 157 | acpigen_write_dword((unsigned int)data); |
| 158 | else |
| 159 | acpigen_write_qword(data); |
| 160 | } |
| 161 | |
| 162 | void acpigen_write_name_zero(const char *name) |
| 163 | { |
| 164 | acpigen_write_name(name); |
| 165 | acpigen_write_one(); |
| 166 | } |
| 167 | |
| 168 | void acpigen_write_name_one(const char *name) |
| 169 | { |
| 170 | acpigen_write_name(name); |
| 171 | acpigen_write_zero(); |
| 172 | } |
| 173 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 174 | void acpigen_write_name_byte(const char *name, uint8_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 175 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 176 | acpigen_write_name(name); |
| 177 | acpigen_write_byte(val); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 180 | void acpigen_write_name_dword(const char *name, uint32_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 181 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 182 | acpigen_write_name(name); |
| 183 | acpigen_write_dword(val); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 186 | void acpigen_write_name_qword(const char *name, uint64_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 187 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 188 | acpigen_write_name(name); |
| 189 | acpigen_write_qword(val); |
Carl-Daniel Hailfinger | d58671c | 2009-02-17 21:38:51 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Duncan Laurie | f7c3876 | 2016-05-09 08:20:38 -0700 | [diff] [blame] | 192 | void acpigen_write_name_integer(const char *name, uint64_t val) |
| 193 | { |
| 194 | acpigen_write_name(name); |
| 195 | acpigen_write_integer(val); |
| 196 | } |
| 197 | |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 198 | void acpigen_write_name_string(const char *name, const char *string) |
| 199 | { |
| 200 | acpigen_write_name(name); |
| 201 | acpigen_write_string(string); |
| 202 | } |
| 203 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 204 | void acpigen_emit_stream(const char *data, int size) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 205 | { |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 206 | int i; |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame^] | 207 | for (i = 0; i < size; i++) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 208 | acpigen_emit_byte(data[i]); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 209 | } |
| 210 | |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 211 | void acpigen_emit_string(const char *string) |
| 212 | { |
Jonathan Neuschäfer | 0ba307f | 2016-05-17 17:40:09 +0200 | [diff] [blame] | 213 | acpigen_emit_stream(string, string ? strlen(string) : 0); |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 214 | acpigen_emit_byte('\0'); /* NUL */ |
| 215 | } |
| 216 | |
| 217 | void acpigen_write_string(const char *string) |
| 218 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 219 | acpigen_emit_byte(STRING_PREFIX); |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 220 | acpigen_emit_string(string); |
| 221 | } |
| 222 | |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 223 | void acpigen_write_coreboot_hid(enum coreboot_acpi_ids id) |
| 224 | { |
| 225 | char hid[9]; /* CORExxxx */ |
| 226 | |
Duncan Laurie | 02fdb3e | 2016-09-22 14:08:33 -0700 | [diff] [blame] | 227 | snprintf(hid, sizeof(hid), "%.4s%04X", COREBOOT_ACPI_ID, id); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 228 | acpigen_write_name_string("_HID", hid); |
| 229 | } |
| 230 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 231 | /* |
| 232 | * The naming conventions for ACPI namespace names are a bit tricky as |
Martin Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 233 | * each element has to be 4 chars wide ("All names are a fixed 32 bits.") |
| 234 | * and "By convention, when an ASL compiler pads a name shorter than 4 |
| 235 | * characters, it is done so with trailing underscores ('_')". |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 236 | * |
| 237 | * Check sections 5.3, 18.2.2 and 18.4 of ACPI spec 3.0 for details. |
| 238 | */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 239 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame^] | 240 | static void acpigen_emit_simple_namestring(const char *name) |
| 241 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 242 | int i; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 243 | char ud[] = "____"; |
| 244 | for (i = 0; i < 4; i++) { |
| 245 | if ((name[i] == '\0') || (name[i] == '.')) { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 246 | acpigen_emit_stream(ud, 4 - i); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 247 | break; |
| 248 | } else { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 249 | acpigen_emit_byte(name[i]); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame^] | 254 | static void acpigen_emit_double_namestring(const char *name, int dotpos) |
| 255 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 256 | acpigen_emit_byte(DUAL_NAME_PREFIX); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 257 | acpigen_emit_simple_namestring(name); |
| 258 | acpigen_emit_simple_namestring(&name[dotpos + 1]); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 259 | } |
| 260 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame^] | 261 | static void acpigen_emit_multi_namestring(const char *name) |
| 262 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 263 | int count = 0; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 264 | unsigned char *pathlen; |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 265 | acpigen_emit_byte(MULTI_NAME_PREFIX); |
| 266 | acpigen_emit_byte(ZERO_OP); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 267 | pathlen = ((unsigned char *) acpigen_get_current()) - 1; |
| 268 | |
| 269 | while (name[0] != '\0') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 270 | acpigen_emit_simple_namestring(name); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 271 | /* find end or next entity */ |
| 272 | while ((name[0] != '.') && (name[0] != '\0')) |
| 273 | name++; |
| 274 | /* forward to next */ |
| 275 | if (name[0] == '.') |
| 276 | name++; |
| 277 | count++; |
| 278 | } |
| 279 | |
| 280 | pathlen[0] = count; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame^] | 284 | void acpigen_emit_namestring(const char *namepath) |
| 285 | { |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 286 | int dotcount = 0, i; |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 287 | int dotpos = 0; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 288 | |
Ronald G. Minnich | be738eb | 2013-03-07 11:05:28 -0600 | [diff] [blame] | 289 | /* We can start with a '\'. */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 290 | if (namepath[0] == '\\') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 291 | acpigen_emit_byte('\\'); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 292 | namepath++; |
| 293 | } |
| 294 | |
Ronald G. Minnich | be738eb | 2013-03-07 11:05:28 -0600 | [diff] [blame] | 295 | /* And there can be any number of '^' */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 296 | while (namepath[0] == '^') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 297 | acpigen_emit_byte('^'); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 298 | namepath++; |
| 299 | } |
| 300 | |
Vladimir Serbinenko | d942ed9 | 2014-08-30 20:44:37 +0200 | [diff] [blame] | 301 | /* If we have only \\ or only ^...^. Then we need to put a null |
| 302 | name (0x00). */ |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 303 | if (namepath[0] == '\0') { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 304 | acpigen_emit_byte(ZERO_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 305 | return; |
Vladimir Serbinenko | d942ed9 | 2014-08-30 20:44:37 +0200 | [diff] [blame] | 306 | } |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 307 | |
| 308 | i = 0; |
| 309 | while (namepath[i] != '\0') { |
| 310 | if (namepath[i] == '.') { |
| 311 | dotcount++; |
| 312 | dotpos = i; |
| 313 | } |
| 314 | i++; |
| 315 | } |
| 316 | |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame^] | 317 | if (dotcount == 0) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 318 | acpigen_emit_simple_namestring(namepath); |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame^] | 319 | else if (dotcount == 1) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 320 | acpigen_emit_double_namestring(namepath, dotpos); |
Lee Leahy | 9c7c6f7 | 2017-03-16 11:24:09 -0700 | [diff] [blame^] | 321 | else |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 322 | acpigen_emit_multi_namestring(namepath); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 323 | } |
| 324 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 325 | void acpigen_write_name(const char *name) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 326 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 327 | acpigen_emit_byte(NAME_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 328 | acpigen_emit_namestring(name); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 329 | } |
| 330 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 331 | void acpigen_write_scope(const char *name) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 332 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 333 | acpigen_emit_byte(SCOPE_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 334 | acpigen_write_len_f(); |
| 335 | acpigen_emit_namestring(name); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 336 | } |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 337 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 338 | void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 339 | { |
| 340 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 341 | Processor (\_PR.CPUcpuindex, cpuindex, pblock_addr, pblock_len) |
| 342 | { |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 343 | */ |
| 344 | char pscope[16]; |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 345 | acpigen_emit_ext_op(PROCESSOR_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 346 | acpigen_write_len_f(); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 347 | |
Elyes HAOUAS | 7d87e76 | 2016-10-03 22:11:07 +0200 | [diff] [blame] | 348 | snprintf(pscope, sizeof(pscope), |
Timothy Pearson | 033bb4b | 2015-02-10 22:21:39 -0600 | [diff] [blame] | 349 | "\\_PR.CP%02d", (unsigned int) cpuindex); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 350 | acpigen_emit_namestring(pscope); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 351 | acpigen_emit_byte(cpuindex); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 352 | acpigen_emit_dword(pblock_addr); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 353 | acpigen_emit_byte(pblock_len); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 354 | } |
| 355 | |
Naresh G Solanki | 8535c66 | 2016-10-25 00:51:24 +0530 | [diff] [blame] | 356 | /* |
| 357 | * Generate ACPI AML code for OperationRegion |
| 358 | * Arg0: Pointer to struct opregion opreg = OPREGION(rname, space, offset, len) |
| 359 | * where rname is region name, space is region space, offset is region offset & |
| 360 | * len is region length. |
| 361 | * OperationRegion(regionname, regionspace, regionoffset, regionlength) |
| 362 | */ |
| 363 | void acpigen_write_opregion(struct opregion *opreg) |
| 364 | { |
| 365 | /* OpregionOp */ |
| 366 | acpigen_emit_ext_op(OPREGION_OP); |
| 367 | /* NameString 4 chars only */ |
| 368 | acpigen_emit_simple_namestring(opreg->name); |
| 369 | /* RegionSpace */ |
| 370 | acpigen_emit_byte(opreg->regionspace); |
| 371 | /* RegionOffset & RegionLen, it can be byte word or double word */ |
| 372 | acpigen_write_integer(opreg->regionoffset); |
| 373 | acpigen_write_integer(opreg->regionlen); |
| 374 | } |
| 375 | |
| 376 | static void acpigen_write_field_offset(uint32_t offset, |
| 377 | uint32_t current_bit_pos) |
| 378 | { |
| 379 | uint32_t diff_bits; |
| 380 | uint8_t i, j; |
| 381 | uint8_t emit[4]; |
| 382 | |
| 383 | if (offset < current_bit_pos) { |
| 384 | printk(BIOS_WARNING, "%s: Cannot move offset backward", |
| 385 | __func__); |
| 386 | return; |
| 387 | } |
| 388 | |
| 389 | diff_bits = offset - current_bit_pos; |
| 390 | /* Upper limit */ |
| 391 | if (diff_bits > 0xFFFFFFF) { |
| 392 | printk(BIOS_WARNING, "%s: Offset very large to encode", |
| 393 | __func__); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | i = 1; |
| 398 | if (diff_bits < 0x40) { |
| 399 | emit[0] = diff_bits & 0x3F; |
| 400 | } else { |
| 401 | emit[0] = diff_bits & 0xF; |
| 402 | diff_bits >>= 4; |
| 403 | while (diff_bits) { |
| 404 | emit[i] = diff_bits & 0xFF; |
| 405 | i++; |
| 406 | diff_bits >>= 8; |
| 407 | } |
| 408 | } |
| 409 | /* Update bit 7:6 : Number of bytes followed by emit[0] */ |
| 410 | emit[0] |= (i - 1) << 6; |
| 411 | |
| 412 | acpigen_emit_byte(0); |
| 413 | for (j = 0; j < i; j++) |
| 414 | acpigen_emit_byte(emit[j]); |
| 415 | } |
| 416 | |
| 417 | /* |
| 418 | * Generate ACPI AML code for Field |
| 419 | * Arg0: region name |
| 420 | * Arg1: Pointer to struct fieldlist. |
| 421 | * Arg2: no. of entries in Arg1 |
| 422 | * Arg3: flags which indicate filed access type, lock rule & update rule. |
| 423 | * Example with fieldlist |
| 424 | * struct fieldlist l[] = { |
| 425 | * FIELDLIST_OFFSET(0x84), |
| 426 | * FIELDLIST_NAMESTR("PMCS", 2), |
| 427 | * }; |
| 428 | * acpigen_write_field("UART", l ,ARRAY_SIZE(l), FIELD_ANYACC | FIELD_NOLOCK | |
| 429 | * FIELD_PRESERVE); |
| 430 | * Output: |
| 431 | * Field (UART, AnyAcc, NoLock, Preserve) |
| 432 | * { |
| 433 | * Offset (0x84), |
| 434 | * PMCS, 2 |
| 435 | * } |
| 436 | */ |
| 437 | void acpigen_write_field(const char *name, struct fieldlist *l, size_t count, |
| 438 | uint8_t flags) |
| 439 | { |
| 440 | uint16_t i; |
| 441 | uint32_t current_bit_pos = 0; |
| 442 | |
| 443 | /* FieldOp */ |
| 444 | acpigen_emit_ext_op(FIELD_OP); |
| 445 | /* Package Length */ |
| 446 | acpigen_write_len_f(); |
| 447 | /* NameString 4 chars only */ |
| 448 | acpigen_emit_simple_namestring(name); |
| 449 | /* Field Flag */ |
| 450 | acpigen_emit_byte(flags); |
| 451 | |
| 452 | for (i = 0; i < count; i++) { |
| 453 | switch (l[i].type) { |
| 454 | case NAME_STRING: |
| 455 | acpigen_emit_simple_namestring(l[i].name); |
| 456 | acpigen_emit_byte(l[i].bits); |
| 457 | current_bit_pos += l[i].bits; |
| 458 | break; |
| 459 | case OFFSET: |
| 460 | acpigen_write_field_offset(l[i].bits, current_bit_pos); |
| 461 | current_bit_pos = l[i].bits; |
| 462 | break; |
| 463 | default: |
| 464 | printk(BIOS_ERR, "%s: Invalid field type 0x%X\n" |
| 465 | , __func__, l[i].type); |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | acpigen_pop_len(); |
| 470 | } |
| 471 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 472 | void acpigen_write_empty_PCT(void) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 473 | { |
| 474 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 475 | Name (_PCT, Package (0x02) |
| 476 | { |
| 477 | ResourceTemplate () |
| 478 | { |
| 479 | Register (FFixedHW, |
| 480 | 0x00, // Bit Width |
| 481 | 0x00, // Bit Offset |
| 482 | 0x0000000000000000, // Address |
| 483 | ,) |
| 484 | }, |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 485 | |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 486 | ResourceTemplate () |
| 487 | { |
| 488 | Register (FFixedHW, |
| 489 | 0x00, // Bit Width |
| 490 | 0x00, // Bit Offset |
| 491 | 0x0000000000000000, // Address |
| 492 | ,) |
| 493 | } |
| 494 | }) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 495 | */ |
| 496 | static char stream[] = { |
| 497 | 0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, /* 00000030 "0._PCT.," */ |
| 498 | 0x02, 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, /* 00000038 "........" */ |
| 499 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000040 "........" */ |
| 500 | 0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, /* 00000048 "....y..." */ |
| 501 | 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, /* 00000050 "........" */ |
| 502 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000058 "........" */ |
| 503 | 0x00, 0x79, 0x00 |
| 504 | }; |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 505 | acpigen_emit_stream(stream, ARRAY_SIZE(stream)); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 506 | } |
| 507 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 508 | void acpigen_write_empty_PTC(void) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 509 | { |
| 510 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 511 | Name (_PTC, Package (0x02) |
| 512 | { |
| 513 | ResourceTemplate () |
| 514 | { |
| 515 | Register (FFixedHW, |
| 516 | 0x00, // Bit Width |
| 517 | 0x00, // Bit Offset |
| 518 | 0x0000000000000000, // Address |
| 519 | ,) |
| 520 | }, |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 521 | |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 522 | ResourceTemplate () |
| 523 | { |
| 524 | Register (FFixedHW, |
| 525 | 0x00, // Bit Width |
| 526 | 0x00, // Bit Offset |
| 527 | 0x0000000000000000, // Address |
| 528 | ,) |
| 529 | } |
| 530 | }) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 531 | */ |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 532 | acpi_addr_t addr = { |
| 533 | .space_id = ACPI_ADDRESS_SPACE_FIXED, |
| 534 | .bit_width = 0, |
| 535 | .bit_offset = 0, |
zbao | ee8a9f6c | 2012-05-29 14:59:38 +0800 | [diff] [blame] | 536 | { |
| 537 | .resv = 0 |
| 538 | }, |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 539 | .addrl = 0, |
| 540 | .addrh = 0, |
| 541 | }; |
| 542 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 543 | acpigen_write_name("_PTC"); |
| 544 | acpigen_write_package(2); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 545 | |
| 546 | /* ControlRegister */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 547 | acpigen_write_resourcetemplate_header(); |
| 548 | acpigen_write_register(&addr); |
| 549 | acpigen_write_resourcetemplate_footer(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 550 | |
| 551 | /* StatusRegister */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 552 | acpigen_write_resourcetemplate_header(); |
| 553 | acpigen_write_register(&addr); |
| 554 | acpigen_write_resourcetemplate_footer(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 555 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 556 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 557 | } |
| 558 | |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 559 | static void __acpigen_write_method(const char *name, uint8_t flags) |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 560 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 561 | acpigen_emit_byte(METHOD_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 562 | acpigen_write_len_f(); |
| 563 | acpigen_emit_namestring(name); |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 564 | acpigen_emit_byte(flags); |
| 565 | } |
| 566 | |
| 567 | /* Method (name, nargs, NotSerialized) */ |
| 568 | void acpigen_write_method(const char *name, int nargs) |
| 569 | { |
| 570 | __acpigen_write_method(name, (nargs & 7)); |
| 571 | } |
| 572 | |
| 573 | /* Method (name, nargs, Serialized) */ |
| 574 | void acpigen_write_method_serialized(const char *name, int nargs) |
| 575 | { |
| 576 | __acpigen_write_method(name, (nargs & 7) | (1 << 3)); |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 577 | } |
| 578 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 579 | void acpigen_write_device(const char *name) |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 580 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 581 | acpigen_emit_ext_op(DEVICE_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 582 | acpigen_write_len_f(); |
| 583 | acpigen_emit_namestring(name); |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 584 | } |
| 585 | |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 586 | void acpigen_write_STA(uint8_t status) |
| 587 | { |
| 588 | /* |
| 589 | * Method (_STA, 0, NotSerialized) { Return (status) } |
| 590 | */ |
| 591 | acpigen_write_method("_STA", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 592 | acpigen_emit_byte(RETURN_OP); |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 593 | acpigen_write_byte(status); |
| 594 | acpigen_pop_len(); |
| 595 | } |
| 596 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 597 | /* |
| 598 | * Generates a func with max supported P-states. |
| 599 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 600 | void acpigen_write_PPC(u8 nr) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 601 | { |
| 602 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 603 | Method (_PPC, 0, NotSerialized) |
| 604 | { |
| 605 | Return (nr) |
| 606 | } |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 607 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 608 | acpigen_write_method("_PPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 609 | acpigen_emit_byte(RETURN_OP); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 610 | /* arg */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 611 | acpigen_write_byte(nr); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 612 | acpigen_pop_len(); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 615 | /* |
| 616 | * Generates a func with max supported P-states saved |
| 617 | * in the variable PPCM. |
| 618 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 619 | void acpigen_write_PPC_NVS(void) |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 620 | { |
| 621 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 622 | Method (_PPC, 0, NotSerialized) |
| 623 | { |
| 624 | Return (PPCM) |
| 625 | } |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 626 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 627 | acpigen_write_method("_PPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 628 | acpigen_emit_byte(RETURN_OP); |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 629 | /* arg */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 630 | acpigen_emit_namestring("PPCM"); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 631 | acpigen_pop_len(); |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 634 | void acpigen_write_TPC(const char *gnvs_tpc_limit) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 635 | { |
| 636 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 637 | // Sample _TPC method |
| 638 | Method (_TPC, 0, NotSerialized) |
| 639 | { |
| 640 | Return (\TLVL) |
| 641 | } |
| 642 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 643 | acpigen_write_method("_TPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 644 | acpigen_emit_byte(RETURN_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 645 | acpigen_emit_namestring(gnvs_tpc_limit); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 646 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 647 | } |
| 648 | |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 649 | void acpigen_write_PRW(u32 wake, u32 level) |
| 650 | { |
| 651 | /* |
| 652 | * Name (_PRW, Package () { wake, level } |
| 653 | */ |
| 654 | acpigen_write_name("_PRW"); |
| 655 | acpigen_write_package(2); |
| 656 | acpigen_write_integer(wake); |
| 657 | acpigen_write_integer(level); |
| 658 | acpigen_pop_len(); |
| 659 | } |
| 660 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 661 | void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 662 | u32 busmLat, u32 control, u32 status) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 663 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 664 | acpigen_write_package(6); |
| 665 | acpigen_write_dword(coreFreq); |
| 666 | acpigen_write_dword(power); |
| 667 | acpigen_write_dword(transLat); |
| 668 | acpigen_write_dword(busmLat); |
| 669 | acpigen_write_dword(control); |
| 670 | acpigen_write_dword(status); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 671 | acpigen_pop_len(); |
Stefan Reinauer | d4bacf9 | 2012-05-02 16:38:47 -0700 | [diff] [blame] | 672 | |
| 673 | printk(BIOS_DEBUG, "PSS: %uMHz power %u control 0x%x status 0x%x\n", |
| 674 | coreFreq, power, control, status); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 675 | } |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 676 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 677 | void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 678 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 679 | acpigen_write_name("_PSD"); |
| 680 | acpigen_write_package(1); |
| 681 | acpigen_write_package(5); |
| 682 | acpigen_write_byte(5); // 5 values |
| 683 | acpigen_write_byte(0); // revision 0 |
| 684 | acpigen_write_dword(domain); |
| 685 | acpigen_write_dword(coordtype); |
| 686 | acpigen_write_dword(numprocs); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 687 | acpigen_pop_len(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 688 | acpigen_pop_len(); |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 689 | } |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 690 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 691 | void acpigen_write_CST_package_entry(acpi_cstate_t *cstate) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 692 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 693 | acpigen_write_package(4); |
| 694 | acpigen_write_resourcetemplate_header(); |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 695 | acpigen_write_register(&cstate->resource); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 696 | acpigen_write_resourcetemplate_footer(); |
| 697 | acpigen_write_dword(cstate->ctype); |
| 698 | acpigen_write_dword(cstate->latency); |
| 699 | acpigen_write_dword(cstate->power); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 700 | acpigen_pop_len(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 701 | } |
| 702 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 703 | void acpigen_write_CST_package(acpi_cstate_t *cstate, int nentries) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 704 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 705 | int i; |
| 706 | acpigen_write_name("_CST"); |
| 707 | acpigen_write_package(nentries+1); |
| 708 | acpigen_write_dword(nentries); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 709 | |
| 710 | for (i = 0; i < nentries; i++) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 711 | acpigen_write_CST_package_entry(cstate + i); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 712 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 713 | acpigen_pop_len(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 714 | } |
| 715 | |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 716 | void acpigen_write_CSD_package(u32 domain, u32 numprocs, CSD_coord coordtype, u32 index) |
| 717 | { |
| 718 | acpigen_write_name("_CSD"); |
| 719 | acpigen_write_package(1); |
| 720 | acpigen_write_package(6); |
| 721 | acpigen_write_byte(6); // 6 values |
| 722 | acpigen_write_byte(0); // revision 0 |
| 723 | acpigen_write_dword(domain); |
| 724 | acpigen_write_dword(coordtype); |
| 725 | acpigen_write_dword(numprocs); |
| 726 | acpigen_write_dword(index); |
| 727 | acpigen_pop_len(); |
| 728 | acpigen_pop_len(); |
| 729 | } |
| 730 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 731 | void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 732 | { |
| 733 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 734 | Sample _TSS package with 100% and 50% duty cycles |
| 735 | Name (_TSS, Package (0x02) |
| 736 | { |
| 737 | Package(){100, 1000, 0, 0x00, 0) |
| 738 | Package(){50, 520, 0, 0x18, 0) |
| 739 | }) |
| 740 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 741 | int i; |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 742 | acpi_tstate_t *tstate = tstate_list; |
| 743 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 744 | acpigen_write_name("_TSS"); |
| 745 | acpigen_write_package(entries); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 746 | |
| 747 | for (i = 0; i < entries; i++) { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 748 | acpigen_write_package(5); |
| 749 | acpigen_write_dword(tstate->percent); |
| 750 | acpigen_write_dword(tstate->power); |
| 751 | acpigen_write_dword(tstate->latency); |
| 752 | acpigen_write_dword(tstate->control); |
| 753 | acpigen_write_dword(tstate->status); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 754 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 755 | tstate++; |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 756 | } |
| 757 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 758 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 759 | } |
| 760 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 761 | void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 762 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 763 | acpigen_write_name("_TSD"); |
| 764 | acpigen_write_package(1); |
| 765 | acpigen_write_package(5); |
| 766 | acpigen_write_byte(5); // 5 values |
| 767 | acpigen_write_byte(0); // revision 0 |
| 768 | acpigen_write_dword(domain); |
| 769 | acpigen_write_dword(coordtype); |
| 770 | acpigen_write_dword(numprocs); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 771 | acpigen_pop_len(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 772 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | |
| 776 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 777 | void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 778 | { |
| 779 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 780 | * 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] | 781 | * Byte 0: |
| 782 | * Bit7 : 1 => big item |
| 783 | * Bit6-0: 0000110 (0x6) => 32-bit fixed memory |
| 784 | */ |
| 785 | acpigen_emit_byte(0x86); |
| 786 | /* Byte 1+2: length (0x0009) */ |
| 787 | acpigen_emit_byte(0x09); |
| 788 | acpigen_emit_byte(0x00); |
| 789 | /* bit1-7 are ignored */ |
| 790 | acpigen_emit_byte(readwrite ? 0x01 : 0x00); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 791 | acpigen_emit_dword(base); |
| 792 | acpigen_emit_dword(size); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 793 | } |
| 794 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 795 | void acpigen_write_register(acpi_addr_t *addr) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 796 | { |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 797 | acpigen_emit_byte(0x82); /* Register Descriptor */ |
| 798 | acpigen_emit_byte(0x0c); /* Register Length 7:0 */ |
| 799 | acpigen_emit_byte(0x00); /* Register Length 15:8 */ |
| 800 | acpigen_emit_byte(addr->space_id); /* Address Space ID */ |
| 801 | acpigen_emit_byte(addr->bit_width); /* Register Bit Width */ |
| 802 | acpigen_emit_byte(addr->bit_offset); /* Register Bit Offset */ |
| 803 | acpigen_emit_byte(addr->resv); /* Register Access Size */ |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 804 | acpigen_emit_dword(addr->addrl); /* Register Address Low */ |
| 805 | acpigen_emit_dword(addr->addrh); /* Register Address High */ |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 806 | } |
| 807 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 808 | void acpigen_write_irq(u16 mask) |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 809 | { |
| 810 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 811 | * ACPI 3.0b section 6.4.2.1: IRQ Descriptor |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 812 | * Byte 0: |
| 813 | * Bit7 : 0 => small item |
| 814 | * Bit6-3: 0100 (0x4) => IRQ port descriptor |
| 815 | * Bit2-0: 010 (0x2) => 2 Bytes long |
| 816 | */ |
| 817 | acpigen_emit_byte(0x22); |
| 818 | acpigen_emit_byte(mask & 0xff); |
| 819 | acpigen_emit_byte((mask >> 8) & 0xff); |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 820 | } |
| 821 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 822 | 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] | 823 | { |
| 824 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 825 | * ACPI 4.0 section 6.4.2.6: I/O Port Descriptor |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 826 | * Byte 0: |
| 827 | * Bit7 : 0 => small item |
| 828 | * Bit6-3: 1000 (0x8) => I/O port descriptor |
| 829 | * Bit2-0: 111 (0x7) => 7 Bytes long |
| 830 | */ |
| 831 | acpigen_emit_byte(0x47); |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 832 | /* Does the device decode all 16 or just 10 bits? */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 833 | /* bit1-7 are ignored */ |
| 834 | acpigen_emit_byte(decode16 ? 0x01 : 0x00); |
| 835 | /* minimum base address the device may be configured for */ |
| 836 | acpigen_emit_byte(min & 0xff); |
| 837 | acpigen_emit_byte((min >> 8) & 0xff); |
| 838 | /* maximum base address the device may be configured for */ |
| 839 | acpigen_emit_byte(max & 0xff); |
| 840 | acpigen_emit_byte((max >> 8) & 0xff); |
| 841 | /* alignment for min base */ |
| 842 | acpigen_emit_byte(align & 0xff); |
| 843 | acpigen_emit_byte(len & 0xff); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 844 | } |
| 845 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 846 | void acpigen_write_resourcetemplate_header(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 847 | { |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 848 | /* |
| 849 | * A ResourceTemplate() is a Buffer() with a |
| 850 | * (Byte|Word|DWord) containing the length, followed by one or more |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 851 | * resource items, terminated by the end tag. |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 852 | * (small item 0xf, len 1) |
| 853 | */ |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 854 | acpigen_emit_byte(BUFFER_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 855 | acpigen_write_len_f(); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 856 | acpigen_emit_byte(WORD_PREFIX); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 857 | len_stack[ltop++] = acpigen_get_current(); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 858 | acpigen_emit_byte(0x00); |
| 859 | acpigen_emit_byte(0x00); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 860 | } |
| 861 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 862 | void acpigen_write_resourcetemplate_footer(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 863 | { |
| 864 | char *p = len_stack[--ltop]; |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 865 | int len; |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 866 | /* |
| 867 | * end tag (acpi 4.0 Section 6.4.2.8) |
| 868 | * 0x79 <checksum> |
| 869 | * 0x00 is treated as a good checksum according to the spec |
| 870 | * and is what iasl generates. |
| 871 | */ |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 872 | acpigen_emit_byte(0x79); |
| 873 | acpigen_emit_byte(0x00); |
| 874 | |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 875 | len = gencurrent - p; |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 876 | |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 877 | /* patch len word */ |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 878 | p[0] = len & 0xff; |
| 879 | p[1] = (len >> 8) & 0xff; |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 880 | /* patch len field */ |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 881 | acpigen_pop_len(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | static void acpigen_add_mainboard_rsvd_mem32(void *gp, struct device *dev, |
| 885 | struct resource *res) |
| 886 | { |
| 887 | acpigen_write_mem32fixed(0, res->base, res->size); |
| 888 | } |
| 889 | |
| 890 | static void acpigen_add_mainboard_rsvd_io(void *gp, struct device *dev, |
| 891 | struct resource *res) |
| 892 | { |
| 893 | resource_t base = res->base; |
| 894 | resource_t size = res->size; |
| 895 | while (size > 0) { |
| 896 | resource_t sz = size > 255 ? 255 : size; |
| 897 | acpigen_write_io16(base, base, 0, sz, 1); |
| 898 | size -= sz; |
| 899 | base += sz; |
| 900 | } |
| 901 | } |
| 902 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 903 | void acpigen_write_mainboard_resource_template(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 904 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 905 | acpigen_write_resourcetemplate_header(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 906 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 907 | /* Add reserved memory ranges. */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 908 | search_global_resources( |
| 909 | IORESOURCE_MEM | IORESOURCE_RESERVE, |
| 910 | IORESOURCE_MEM | IORESOURCE_RESERVE, |
| 911 | acpigen_add_mainboard_rsvd_mem32, 0); |
| 912 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 913 | /* Add reserved io ranges. */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 914 | search_global_resources( |
| 915 | IORESOURCE_IO | IORESOURCE_RESERVE, |
| 916 | IORESOURCE_IO | IORESOURCE_RESERVE, |
| 917 | acpigen_add_mainboard_rsvd_io, 0); |
| 918 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 919 | acpigen_write_resourcetemplate_footer(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 920 | } |
| 921 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 922 | void acpigen_write_mainboard_resources(const char *scope, const char *name) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 923 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 924 | acpigen_write_scope(scope); |
| 925 | acpigen_write_name(name); |
| 926 | acpigen_write_mainboard_resource_template(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 927 | acpigen_pop_len(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 928 | } |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 929 | |
| 930 | static int hex2bin(const char c) |
| 931 | { |
| 932 | if (c >= 'A' && c <= 'F') |
| 933 | return c - 'A' + 10; |
| 934 | if (c >= 'a' && c <= 'f') |
| 935 | return c - 'a' + 10; |
| 936 | return c - '0'; |
| 937 | } |
| 938 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 939 | void acpigen_emit_eisaid(const char *eisaid) |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 940 | { |
| 941 | u32 compact = 0; |
| 942 | |
| 943 | /* Clamping individual values would be better but |
| 944 | there is a disagreement over what is a valid |
| 945 | EISA id, so accept anything and don't clamp, |
| 946 | parent code should create a valid EISAid. |
| 947 | */ |
| 948 | compact |= (eisaid[0] - 'A' + 1) << 26; |
| 949 | compact |= (eisaid[1] - 'A' + 1) << 21; |
| 950 | compact |= (eisaid[2] - 'A' + 1) << 16; |
| 951 | compact |= hex2bin(eisaid[3]) << 12; |
| 952 | compact |= hex2bin(eisaid[4]) << 8; |
| 953 | compact |= hex2bin(eisaid[5]) << 4; |
| 954 | compact |= hex2bin(eisaid[6]); |
| 955 | |
| 956 | acpigen_emit_byte(0xc); |
| 957 | acpigen_emit_byte((compact >> 24) & 0xff); |
| 958 | acpigen_emit_byte((compact >> 16) & 0xff); |
| 959 | acpigen_emit_byte((compact >> 8) & 0xff); |
| 960 | acpigen_emit_byte(compact & 0xff); |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 961 | } |
Duncan Laurie | 3829f23 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 962 | |
| 963 | /* |
| 964 | * ToUUID(uuid) |
| 965 | * |
| 966 | * ACPI 6.1 Section 19.6.136 table 19-385 defines a special output |
| 967 | * order for the bytes that make up a UUID Buffer object. |
| 968 | * UUID byte order for input: |
| 969 | * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp |
| 970 | * UUID byte order for output: |
| 971 | * ddccbbaa-ffee-hhgg-iijj-kkllmmnnoopp |
| 972 | */ |
| 973 | #define UUID_LEN 16 |
| 974 | void acpigen_write_uuid(const char *uuid) |
| 975 | { |
| 976 | uint8_t buf[UUID_LEN]; |
| 977 | size_t i, order[UUID_LEN] = { 3, 2, 1, 0, 5, 4, 7, 6, |
| 978 | 8, 9, 10, 11, 12, 13, 14, 15 }; |
| 979 | |
| 980 | /* Parse UUID string into bytes */ |
| 981 | if (hexstrtobin(uuid, buf, UUID_LEN) < UUID_LEN) |
| 982 | return; |
| 983 | |
| 984 | /* BufferOp */ |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 985 | acpigen_emit_byte(BUFFER_OP); |
Duncan Laurie | 3829f23 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 986 | acpigen_write_len_f(); |
| 987 | |
| 988 | /* Buffer length in bytes */ |
| 989 | acpigen_write_word(UUID_LEN); |
| 990 | |
| 991 | /* Output UUID in expected order */ |
| 992 | for (i = 0; i < UUID_LEN; i++) |
| 993 | acpigen_emit_byte(buf[order[i]]); |
| 994 | |
| 995 | acpigen_pop_len(); |
| 996 | } |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 997 | |
| 998 | /* |
| 999 | * Name (_PRx, Package(One) { name }) |
| 1000 | * ... |
| 1001 | * PowerResource (name, level, order) |
| 1002 | */ |
| 1003 | void acpigen_write_power_res(const char *name, uint8_t level, uint16_t order, |
| 1004 | const char *dev_states[], size_t dev_states_count) |
| 1005 | { |
| 1006 | int i; |
| 1007 | for (i = 0; i < dev_states_count; i++) { |
| 1008 | acpigen_write_name(dev_states[i]); |
| 1009 | acpigen_write_package(1); |
| 1010 | acpigen_emit_simple_namestring(name); |
| 1011 | acpigen_pop_len(); /* Package */ |
| 1012 | } |
| 1013 | |
| 1014 | acpigen_emit_ext_op(POWER_RES_OP); |
| 1015 | |
| 1016 | acpigen_write_len_f(); |
| 1017 | |
| 1018 | acpigen_emit_simple_namestring(name); |
| 1019 | acpigen_emit_byte(level); |
| 1020 | acpigen_emit_word(order); |
| 1021 | } |
| 1022 | |
| 1023 | /* Sleep (ms) */ |
| 1024 | void acpigen_write_sleep(uint64_t sleep_ms) |
| 1025 | { |
| 1026 | acpigen_emit_ext_op(SLEEP_OP); |
| 1027 | acpigen_write_integer(sleep_ms); |
| 1028 | } |
| 1029 | |
| 1030 | void acpigen_write_store(void) |
| 1031 | { |
| 1032 | acpigen_emit_byte(STORE_OP); |
| 1033 | } |
| 1034 | |
| 1035 | /* Store (src, dst) */ |
| 1036 | void acpigen_write_store_ops(uint8_t src, uint8_t dst) |
| 1037 | { |
| 1038 | acpigen_write_store(); |
| 1039 | acpigen_emit_byte(src); |
| 1040 | acpigen_emit_byte(dst); |
| 1041 | } |
| 1042 | |
| 1043 | /* Or (arg1, arg2, res) */ |
| 1044 | void acpigen_write_or(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 1045 | { |
| 1046 | acpigen_emit_byte(OR_OP); |
| 1047 | acpigen_emit_byte(arg1); |
| 1048 | acpigen_emit_byte(arg2); |
| 1049 | acpigen_emit_byte(res); |
| 1050 | } |
| 1051 | |
| 1052 | /* And (arg1, arg2, res) */ |
| 1053 | void acpigen_write_and(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 1054 | { |
| 1055 | acpigen_emit_byte(AND_OP); |
| 1056 | acpigen_emit_byte(arg1); |
| 1057 | acpigen_emit_byte(arg2); |
| 1058 | acpigen_emit_byte(res); |
| 1059 | } |
| 1060 | |
| 1061 | /* Not (arg, res) */ |
| 1062 | void acpigen_write_not(uint8_t arg, uint8_t res) |
| 1063 | { |
| 1064 | acpigen_emit_byte(NOT_OP); |
| 1065 | acpigen_emit_byte(arg); |
| 1066 | acpigen_emit_byte(res); |
| 1067 | } |
| 1068 | |
| 1069 | /* Store (str, DEBUG) */ |
| 1070 | void acpigen_write_debug_string(const char *str) |
| 1071 | { |
| 1072 | acpigen_write_store(); |
| 1073 | acpigen_write_string(str); |
| 1074 | acpigen_emit_ext_op(DEBUG_OP); |
| 1075 | } |
| 1076 | |
| 1077 | /* Store (val, DEBUG) */ |
| 1078 | void acpigen_write_debug_integer(uint64_t val) |
| 1079 | { |
| 1080 | acpigen_write_store(); |
| 1081 | acpigen_write_integer(val); |
| 1082 | acpigen_emit_ext_op(DEBUG_OP); |
| 1083 | } |
| 1084 | |
| 1085 | /* Store (op, DEBUG) */ |
| 1086 | void acpigen_write_debug_op(uint8_t op) |
| 1087 | { |
| 1088 | acpigen_write_store(); |
| 1089 | acpigen_emit_byte(op); |
| 1090 | acpigen_emit_ext_op(DEBUG_OP); |
| 1091 | } |
| 1092 | |
| 1093 | void acpigen_write_if(void) |
| 1094 | { |
| 1095 | acpigen_emit_byte(IF_OP); |
| 1096 | acpigen_write_len_f(); |
| 1097 | } |
| 1098 | |
| 1099 | /* If (And (arg1, arg2)) */ |
| 1100 | void acpigen_write_if_and(uint8_t arg1, uint8_t arg2) |
| 1101 | { |
| 1102 | acpigen_write_if(); |
| 1103 | acpigen_emit_byte(AND_OP); |
| 1104 | acpigen_emit_byte(arg1); |
| 1105 | acpigen_emit_byte(arg2); |
| 1106 | } |
| 1107 | |
Furquan Shaikh | 1fc6bb9 | 2016-11-14 14:16:26 -0800 | [diff] [blame] | 1108 | /* |
| 1109 | * Generates ACPI code for checking if operand1 and operand2 are equal, where, |
| 1110 | * operand1 is ACPI op and operand2 is an integer. |
| 1111 | * |
| 1112 | * If (Lequal (op, val)) |
| 1113 | */ |
| 1114 | 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] | 1115 | { |
| 1116 | acpigen_write_if(); |
| 1117 | acpigen_emit_byte(LEQUAL_OP); |
Furquan Shaikh | 1fc6bb9 | 2016-11-14 14:16:26 -0800 | [diff] [blame] | 1118 | acpigen_emit_byte(op); |
| 1119 | acpigen_write_integer(val); |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame] | 1122 | void acpigen_write_else(void) |
| 1123 | { |
| 1124 | acpigen_emit_byte(ELSE_OP); |
| 1125 | acpigen_write_len_f(); |
| 1126 | } |
Furquan Shaikh | 0a48aee | 2016-10-20 07:12:49 -0700 | [diff] [blame] | 1127 | |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1128 | void acpigen_write_to_buffer(uint8_t src, uint8_t dst) |
| 1129 | { |
| 1130 | acpigen_emit_byte(TO_BUFFER_OP); |
| 1131 | acpigen_emit_byte(src); |
| 1132 | acpigen_emit_byte(dst); |
| 1133 | } |
| 1134 | |
| 1135 | void acpigen_write_to_integer(uint8_t src, uint8_t dst) |
| 1136 | { |
| 1137 | acpigen_emit_byte(TO_INTEGER_OP); |
| 1138 | acpigen_emit_byte(src); |
| 1139 | acpigen_emit_byte(dst); |
| 1140 | } |
| 1141 | |
| 1142 | void acpigen_write_byte_buffer(uint8_t *arr, uint8_t size) |
| 1143 | { |
| 1144 | uint8_t i; |
| 1145 | |
| 1146 | acpigen_emit_byte(BUFFER_OP); |
| 1147 | acpigen_write_len_f(); |
Naresh G Solanki | c70cc4d | 2016-11-16 10:10:09 +0530 | [diff] [blame] | 1148 | acpigen_write_byte(size); |
Furquan Shaikh | 9b39adb | 2016-10-21 16:21:07 -0700 | [diff] [blame] | 1149 | |
| 1150 | for (i = 0; i < size; i++) |
| 1151 | acpigen_emit_byte(arr[i]); |
| 1152 | |
| 1153 | acpigen_pop_len(); |
| 1154 | } |
| 1155 | |
| 1156 | void acpigen_write_return_byte_buffer(uint8_t *arr, uint8_t size) |
| 1157 | { |
| 1158 | acpigen_emit_byte(RETURN_OP); |
| 1159 | acpigen_write_byte_buffer(arr, size); |
| 1160 | } |
| 1161 | |
| 1162 | void acpigen_write_return_singleton_buffer(uint8_t arg) |
| 1163 | { |
| 1164 | acpigen_write_return_byte_buffer(&arg, 1); |
| 1165 | } |
| 1166 | |
| 1167 | void acpigen_write_return_byte(uint8_t arg) |
| 1168 | { |
| 1169 | acpigen_emit_byte(RETURN_OP); |
| 1170 | acpigen_write_byte(arg); |
| 1171 | } |
| 1172 | |
Naresh G Solanki | 05abe43 | 2016-11-17 00:16:29 +0530 | [diff] [blame] | 1173 | void acpigen_write_return_integer(uint64_t arg) |
| 1174 | { |
| 1175 | acpigen_emit_byte(RETURN_OP); |
| 1176 | acpigen_write_integer(arg); |
| 1177 | } |
| 1178 | |
| 1179 | void acpigen_write_return_string(const char *arg) |
| 1180 | { |
| 1181 | acpigen_emit_byte(RETURN_OP); |
| 1182 | acpigen_write_string(arg); |
| 1183 | } |
| 1184 | |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1185 | void acpigen_write_dsm(const char *uuid, void (**callbacks)(void *), |
| 1186 | size_t count, void *arg) |
| 1187 | { |
| 1188 | struct dsm_uuid id = DSM_UUID(uuid, callbacks, count, arg); |
| 1189 | acpigen_write_dsm_uuid_arr(&id, 1); |
| 1190 | } |
| 1191 | |
| 1192 | static void acpigen_write_dsm_uuid(struct dsm_uuid *id) |
| 1193 | { |
| 1194 | size_t i; |
| 1195 | |
| 1196 | /* If (LEqual (Local0, ToUUID(uuid))) */ |
| 1197 | acpigen_write_if(); |
| 1198 | acpigen_emit_byte(LEQUAL_OP); |
| 1199 | acpigen_emit_byte(LOCAL0_OP); |
| 1200 | acpigen_write_uuid(id->uuid); |
| 1201 | |
| 1202 | /* ToInteger (Arg2, Local1) */ |
| 1203 | acpigen_write_to_integer(ARG2_OP, LOCAL1_OP); |
| 1204 | |
| 1205 | for (i = 0; i < id->count; i++) { |
| 1206 | /* If (LEqual (Local1, i)) */ |
| 1207 | acpigen_write_if_lequal_op_int(LOCAL1_OP, i); |
| 1208 | |
| 1209 | /* Callback to write if handler. */ |
| 1210 | if (id->callbacks[i]) |
| 1211 | id->callbacks[i](id->arg); |
| 1212 | |
| 1213 | acpigen_pop_len(); /* If */ |
| 1214 | } |
| 1215 | |
| 1216 | /* Default case: Return (Buffer (One) { 0x0 }) */ |
| 1217 | acpigen_write_return_singleton_buffer(0x0); |
| 1218 | |
| 1219 | acpigen_pop_len(); /* If (LEqual (Local0, ToUUID(uuid))) */ |
| 1220 | |
| 1221 | } |
| 1222 | |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1223 | /* |
| 1224 | * Generate ACPI AML code for _DSM method. |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1225 | * This function takes as input array of uuid for the device, set of callbacks |
| 1226 | * and argument to pass into the callbacks. Callbacks should ensure that Local0 |
| 1227 | * and Local1 are left untouched. Use of Local2-Local7 is permitted in |
| 1228 | * callbacks. |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1229 | * |
| 1230 | * Arguments passed into _DSM method: |
| 1231 | * Arg0 = UUID |
| 1232 | * Arg1 = Revision |
| 1233 | * Arg2 = Function index |
| 1234 | * Arg3 = Function specific arguments |
| 1235 | * |
| 1236 | * AML code generated would look like: |
| 1237 | * Method (_DSM, 4, Serialized) { |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1238 | * ToBuffer (Arg0, Local0) |
| 1239 | * If (LEqual (Local0, ToUUID(uuid))) { |
| 1240 | * ToInteger (Arg2, Local1) |
| 1241 | * If (LEqual (Local1, 0)) { |
| 1242 | * <acpigen by callback[0]> |
| 1243 | * } |
| 1244 | * ... |
| 1245 | * If (LEqual (Local1, n)) { |
| 1246 | * <acpigen by callback[n]> |
| 1247 | * } |
| 1248 | * Return (Buffer (One) { 0x0 }) |
| 1249 | * } |
| 1250 | * ... |
| 1251 | * If (LEqual (Local0, ToUUID(uuidn))) { |
| 1252 | * ... |
| 1253 | * } |
| 1254 | * Return (Buffer (One) { 0x0 }) |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1255 | * } |
| 1256 | */ |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1257 | 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] | 1258 | { |
| 1259 | size_t i; |
| 1260 | |
| 1261 | /* Method (_DSM, 4, Serialized) */ |
| 1262 | acpigen_write_method_serialized("_DSM", 0x4); |
| 1263 | |
| 1264 | /* ToBuffer (Arg0, Local0) */ |
| 1265 | acpigen_write_to_buffer(ARG0_OP, LOCAL0_OP); |
| 1266 | |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1267 | for (i = 0; i < count; i++) |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1268 | acpigen_write_dsm_uuid(&ids[i]); |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1269 | |
Naresh G Solanki | ab77cd4 | 2016-11-15 10:13:15 +0530 | [diff] [blame] | 1270 | /* Return (Buffer (One) { 0x0 }) */ |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1271 | acpigen_write_return_singleton_buffer(0x0); |
| 1272 | |
Furquan Shaikh | c00bd18 | 2016-10-21 16:37:41 -0700 | [diff] [blame] | 1273 | acpigen_pop_len(); /* Method _DSM */ |
| 1274 | } |
| 1275 | |
Furquan Shaikh | 0a48aee | 2016-10-20 07:12:49 -0700 | [diff] [blame] | 1276 | /* Soc-implemented functions -- weak definitions. */ |
| 1277 | int __attribute__((weak)) acpigen_soc_read_rx_gpio(unsigned int gpio_num) |
| 1278 | { |
| 1279 | printk(BIOS_ERR, "ERROR: %s not implemented\n", __func__); |
| 1280 | acpigen_write_debug_string("read_rx_gpio not available"); |
| 1281 | return -1; |
| 1282 | } |
| 1283 | |
| 1284 | int __attribute__((weak)) acpigen_soc_get_tx_gpio(unsigned int gpio_num) |
| 1285 | { |
| 1286 | printk(BIOS_ERR, "ERROR: %s not implemented\n", __func__); |
| 1287 | acpigen_write_debug_string("get_tx_gpio not available"); |
| 1288 | return -1; |
| 1289 | } |
| 1290 | |
| 1291 | int __attribute__((weak)) acpigen_soc_set_tx_gpio(unsigned int gpio_num) |
| 1292 | { |
| 1293 | printk(BIOS_ERR, "ERROR: %s not implemented\n", __func__); |
| 1294 | acpigen_write_debug_string("set_tx_gpio not available"); |
| 1295 | return -1; |
| 1296 | } |
| 1297 | |
| 1298 | int __attribute__((weak)) acpigen_soc_clear_tx_gpio(unsigned int gpio_num) |
| 1299 | { |
| 1300 | printk(BIOS_ERR, "ERROR: %s not implemented\n", __func__); |
| 1301 | acpigen_write_debug_string("clear_tx_gpio not available"); |
| 1302 | return -1; |
| 1303 | } |
Furquan Shaikh | bf4845d | 2017-02-20 22:56:25 -0800 | [diff] [blame] | 1304 | |
| 1305 | /* |
| 1306 | * Helper functions for enabling/disabling Tx GPIOs based on the GPIO |
| 1307 | * polarity. These functions end up calling acpigen_soc_{set,clear}_tx_gpio to |
| 1308 | * make callbacks into SoC acpigen code. |
| 1309 | * |
| 1310 | * Returns 0 on success and -1 on error. |
| 1311 | */ |
| 1312 | int acpigen_enable_tx_gpio(struct acpi_gpio *gpio) |
| 1313 | { |
| 1314 | if (gpio->polarity == ACPI_GPIO_ACTIVE_HIGH) |
| 1315 | return acpigen_soc_set_tx_gpio(gpio->pins[0]); |
| 1316 | else |
| 1317 | return acpigen_soc_clear_tx_gpio(gpio->pins[0]); |
| 1318 | } |
| 1319 | |
| 1320 | int acpigen_disable_tx_gpio(struct acpi_gpio *gpio) |
| 1321 | { |
| 1322 | if (gpio->polarity == ACPI_GPIO_ACTIVE_LOW) |
| 1323 | return acpigen_soc_set_tx_gpio(gpio->pins[0]); |
| 1324 | else |
| 1325 | return acpigen_soc_clear_tx_gpio(gpio->pins[0]); |
| 1326 | } |