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; |
| 207 | for (i = 0; i < size; i++) { |
| 208 | acpigen_emit_byte(data[i]); |
| 209 | } |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 212 | void acpigen_emit_string(const char *string) |
| 213 | { |
Jonathan Neuschäfer | 0ba307f | 2016-05-17 17:40:09 +0200 | [diff] [blame] | 214 | acpigen_emit_stream(string, string ? strlen(string) : 0); |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 215 | acpigen_emit_byte('\0'); /* NUL */ |
| 216 | } |
| 217 | |
| 218 | void acpigen_write_string(const char *string) |
| 219 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 220 | acpigen_emit_byte(STRING_PREFIX); |
Duncan Laurie | 56b69aa | 2016-05-09 08:17:02 -0700 | [diff] [blame] | 221 | acpigen_emit_string(string); |
| 222 | } |
| 223 | |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 224 | void acpigen_write_coreboot_hid(enum coreboot_acpi_ids id) |
| 225 | { |
| 226 | char hid[9]; /* CORExxxx */ |
| 227 | |
Duncan Laurie | 02fdb3e | 2016-09-22 14:08:33 -0700 | [diff] [blame] | 228 | snprintf(hid, sizeof(hid), "%.4s%04X", COREBOOT_ACPI_ID, id); |
Duncan Laurie | 3731903 | 2016-05-26 12:47:05 -0700 | [diff] [blame] | 229 | acpigen_write_name_string("_HID", hid); |
| 230 | } |
| 231 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 232 | /* |
| 233 | * The naming conventions for ACPI namespace names are a bit tricky as |
Martin Roth | 0cd338e | 2016-07-29 14:07:30 -0600 | [diff] [blame] | 234 | * each element has to be 4 chars wide ("All names are a fixed 32 bits.") |
| 235 | * and "By convention, when an ASL compiler pads a name shorter than 4 |
| 236 | * characters, it is done so with trailing underscores ('_')". |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 237 | * |
| 238 | * Check sections 5.3, 18.2.2 and 18.4 of ACPI spec 3.0 for details. |
| 239 | */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 240 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 241 | static void acpigen_emit_simple_namestring(const char *name) { |
| 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 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 254 | static void acpigen_emit_double_namestring(const char *name, int dotpos) { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 255 | acpigen_emit_byte(DUAL_NAME_PREFIX); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 256 | acpigen_emit_simple_namestring(name); |
| 257 | acpigen_emit_simple_namestring(&name[dotpos + 1]); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 260 | static void acpigen_emit_multi_namestring(const char *name) { |
| 261 | int count = 0; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 262 | unsigned char *pathlen; |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 263 | acpigen_emit_byte(MULTI_NAME_PREFIX); |
| 264 | acpigen_emit_byte(ZERO_OP); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 265 | pathlen = ((unsigned char *) acpigen_get_current()) - 1; |
| 266 | |
| 267 | while (name[0] != '\0') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 268 | acpigen_emit_simple_namestring(name); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 269 | /* find end or next entity */ |
| 270 | while ((name[0] != '.') && (name[0] != '\0')) |
| 271 | name++; |
| 272 | /* forward to next */ |
| 273 | if (name[0] == '.') |
| 274 | name++; |
| 275 | count++; |
| 276 | } |
| 277 | |
| 278 | pathlen[0] = count; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 282 | void acpigen_emit_namestring(const char *namepath) { |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 283 | int dotcount = 0, i; |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 284 | int dotpos = 0; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 285 | |
Ronald G. Minnich | be738eb | 2013-03-07 11:05:28 -0600 | [diff] [blame] | 286 | /* We can start with a '\'. */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 287 | if (namepath[0] == '\\') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 288 | acpigen_emit_byte('\\'); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 289 | namepath++; |
| 290 | } |
| 291 | |
Ronald G. Minnich | be738eb | 2013-03-07 11:05:28 -0600 | [diff] [blame] | 292 | /* And there can be any number of '^' */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 293 | while (namepath[0] == '^') { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 294 | acpigen_emit_byte('^'); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 295 | namepath++; |
| 296 | } |
| 297 | |
Vladimir Serbinenko | d942ed9 | 2014-08-30 20:44:37 +0200 | [diff] [blame] | 298 | /* If we have only \\ or only ^...^. Then we need to put a null |
| 299 | name (0x00). */ |
Elyes HAOUAS | dbf3067 | 2016-08-21 17:37:15 +0200 | [diff] [blame] | 300 | if (namepath[0] == '\0') { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 301 | acpigen_emit_byte(ZERO_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 302 | return; |
Vladimir Serbinenko | d942ed9 | 2014-08-30 20:44:37 +0200 | [diff] [blame] | 303 | } |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 304 | |
| 305 | i = 0; |
| 306 | while (namepath[i] != '\0') { |
| 307 | if (namepath[i] == '.') { |
| 308 | dotcount++; |
| 309 | dotpos = i; |
| 310 | } |
| 311 | i++; |
| 312 | } |
| 313 | |
| 314 | if (dotcount == 0) { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 315 | acpigen_emit_simple_namestring(namepath); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 316 | } else if (dotcount == 1) { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 317 | acpigen_emit_double_namestring(namepath, dotpos); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 318 | } else { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 319 | acpigen_emit_multi_namestring(namepath); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 320 | } |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 323 | void acpigen_write_name(const char *name) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 324 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 325 | acpigen_emit_byte(NAME_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 326 | acpigen_emit_namestring(name); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 329 | void acpigen_write_scope(const char *name) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 330 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 331 | acpigen_emit_byte(SCOPE_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 332 | acpigen_write_len_f(); |
| 333 | acpigen_emit_namestring(name); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 334 | } |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 335 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 336 | void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 337 | { |
| 338 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 339 | Processor (\_PR.CPUcpuindex, cpuindex, pblock_addr, pblock_len) |
| 340 | { |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 341 | */ |
| 342 | char pscope[16]; |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 343 | acpigen_emit_ext_op(PROCESSOR_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 344 | acpigen_write_len_f(); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 345 | |
Elyes HAOUAS | 7d87e76 | 2016-10-03 22:11:07 +0200 | [diff] [blame] | 346 | snprintf(pscope, sizeof(pscope), |
Timothy Pearson | 033bb4b | 2015-02-10 22:21:39 -0600 | [diff] [blame] | 347 | "\\_PR.CP%02d", (unsigned int) cpuindex); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 348 | acpigen_emit_namestring(pscope); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 349 | acpigen_emit_byte(cpuindex); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 350 | acpigen_emit_dword(pblock_addr); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 351 | acpigen_emit_byte(pblock_len); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 352 | } |
| 353 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 354 | void acpigen_write_empty_PCT(void) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 355 | { |
| 356 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 357 | Name (_PCT, Package (0x02) |
| 358 | { |
| 359 | ResourceTemplate () |
| 360 | { |
| 361 | Register (FFixedHW, |
| 362 | 0x00, // Bit Width |
| 363 | 0x00, // Bit Offset |
| 364 | 0x0000000000000000, // Address |
| 365 | ,) |
| 366 | }, |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 367 | |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 368 | ResourceTemplate () |
| 369 | { |
| 370 | Register (FFixedHW, |
| 371 | 0x00, // Bit Width |
| 372 | 0x00, // Bit Offset |
| 373 | 0x0000000000000000, // Address |
| 374 | ,) |
| 375 | } |
| 376 | }) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 377 | */ |
| 378 | static char stream[] = { |
| 379 | 0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, /* 00000030 "0._PCT.," */ |
| 380 | 0x02, 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, /* 00000038 "........" */ |
| 381 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000040 "........" */ |
| 382 | 0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, /* 00000048 "....y..." */ |
| 383 | 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, /* 00000050 "........" */ |
| 384 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000058 "........" */ |
| 385 | 0x00, 0x79, 0x00 |
| 386 | }; |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 387 | acpigen_emit_stream(stream, ARRAY_SIZE(stream)); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 390 | void acpigen_write_empty_PTC(void) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 391 | { |
| 392 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 393 | Name (_PTC, Package (0x02) |
| 394 | { |
| 395 | ResourceTemplate () |
| 396 | { |
| 397 | Register (FFixedHW, |
| 398 | 0x00, // Bit Width |
| 399 | 0x00, // Bit Offset |
| 400 | 0x0000000000000000, // Address |
| 401 | ,) |
| 402 | }, |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 403 | |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 404 | ResourceTemplate () |
| 405 | { |
| 406 | Register (FFixedHW, |
| 407 | 0x00, // Bit Width |
| 408 | 0x00, // Bit Offset |
| 409 | 0x0000000000000000, // Address |
| 410 | ,) |
| 411 | } |
| 412 | }) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 413 | */ |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 414 | acpi_addr_t addr = { |
| 415 | .space_id = ACPI_ADDRESS_SPACE_FIXED, |
| 416 | .bit_width = 0, |
| 417 | .bit_offset = 0, |
zbao | ee8a9f6c | 2012-05-29 14:59:38 +0800 | [diff] [blame] | 418 | { |
| 419 | .resv = 0 |
| 420 | }, |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 421 | .addrl = 0, |
| 422 | .addrh = 0, |
| 423 | }; |
| 424 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 425 | acpigen_write_name("_PTC"); |
| 426 | acpigen_write_package(2); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 427 | |
| 428 | /* ControlRegister */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 429 | acpigen_write_resourcetemplate_header(); |
| 430 | acpigen_write_register(&addr); |
| 431 | acpigen_write_resourcetemplate_footer(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 432 | |
| 433 | /* StatusRegister */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 434 | acpigen_write_resourcetemplate_header(); |
| 435 | acpigen_write_register(&addr); |
| 436 | acpigen_write_resourcetemplate_footer(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 437 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 438 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 439 | } |
| 440 | |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame^] | 441 | static void __acpigen_write_method(const char *name, uint8_t flags) |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 442 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 443 | acpigen_emit_byte(METHOD_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 444 | acpigen_write_len_f(); |
| 445 | acpigen_emit_namestring(name); |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame^] | 446 | acpigen_emit_byte(flags); |
| 447 | } |
| 448 | |
| 449 | /* Method (name, nargs, NotSerialized) */ |
| 450 | void acpigen_write_method(const char *name, int nargs) |
| 451 | { |
| 452 | __acpigen_write_method(name, (nargs & 7)); |
| 453 | } |
| 454 | |
| 455 | /* Method (name, nargs, Serialized) */ |
| 456 | void acpigen_write_method_serialized(const char *name, int nargs) |
| 457 | { |
| 458 | __acpigen_write_method(name, (nargs & 7) | (1 << 3)); |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 459 | } |
| 460 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 461 | void acpigen_write_device(const char *name) |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 462 | { |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 463 | acpigen_emit_ext_op(DEVICE_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 464 | acpigen_write_len_f(); |
| 465 | acpigen_emit_namestring(name); |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 466 | } |
| 467 | |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 468 | void acpigen_write_STA(uint8_t status) |
| 469 | { |
| 470 | /* |
| 471 | * Method (_STA, 0, NotSerialized) { Return (status) } |
| 472 | */ |
| 473 | acpigen_write_method("_STA", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 474 | acpigen_emit_byte(RETURN_OP); |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 475 | acpigen_write_byte(status); |
| 476 | acpigen_pop_len(); |
| 477 | } |
| 478 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 479 | /* |
| 480 | * Generates a func with max supported P-states. |
| 481 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 482 | void acpigen_write_PPC(u8 nr) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 483 | { |
| 484 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 485 | Method (_PPC, 0, NotSerialized) |
| 486 | { |
| 487 | Return (nr) |
| 488 | } |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 489 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 490 | acpigen_write_method("_PPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 491 | acpigen_emit_byte(RETURN_OP); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 492 | /* arg */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 493 | acpigen_write_byte(nr); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 494 | acpigen_pop_len(); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 495 | } |
| 496 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 497 | /* |
| 498 | * Generates a func with max supported P-states saved |
| 499 | * in the variable PPCM. |
| 500 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 501 | void acpigen_write_PPC_NVS(void) |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 502 | { |
| 503 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 504 | Method (_PPC, 0, NotSerialized) |
| 505 | { |
| 506 | Return (PPCM) |
| 507 | } |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 508 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 509 | acpigen_write_method("_PPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 510 | acpigen_emit_byte(RETURN_OP); |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 511 | /* arg */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 512 | acpigen_emit_namestring("PPCM"); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 513 | acpigen_pop_len(); |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 516 | void acpigen_write_TPC(const char *gnvs_tpc_limit) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 517 | { |
| 518 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 519 | // Sample _TPC method |
| 520 | Method (_TPC, 0, NotSerialized) |
| 521 | { |
| 522 | Return (\TLVL) |
| 523 | } |
| 524 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 525 | acpigen_write_method("_TPC", 0); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 526 | acpigen_emit_byte(RETURN_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 527 | acpigen_emit_namestring(gnvs_tpc_limit); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 528 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 529 | } |
| 530 | |
Duncan Laurie | abe2de8 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 531 | void acpigen_write_PRW(u32 wake, u32 level) |
| 532 | { |
| 533 | /* |
| 534 | * Name (_PRW, Package () { wake, level } |
| 535 | */ |
| 536 | acpigen_write_name("_PRW"); |
| 537 | acpigen_write_package(2); |
| 538 | acpigen_write_integer(wake); |
| 539 | acpigen_write_integer(level); |
| 540 | acpigen_pop_len(); |
| 541 | } |
| 542 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 543 | void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 544 | u32 busmLat, u32 control, u32 status) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 545 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 546 | acpigen_write_package(6); |
| 547 | acpigen_write_dword(coreFreq); |
| 548 | acpigen_write_dword(power); |
| 549 | acpigen_write_dword(transLat); |
| 550 | acpigen_write_dword(busmLat); |
| 551 | acpigen_write_dword(control); |
| 552 | acpigen_write_dword(status); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 553 | acpigen_pop_len(); |
Stefan Reinauer | d4bacf9 | 2012-05-02 16:38:47 -0700 | [diff] [blame] | 554 | |
| 555 | printk(BIOS_DEBUG, "PSS: %uMHz power %u control 0x%x status 0x%x\n", |
| 556 | coreFreq, power, control, status); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 557 | } |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 558 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 559 | void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 560 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 561 | acpigen_write_name("_PSD"); |
| 562 | acpigen_write_package(1); |
| 563 | acpigen_write_package(5); |
| 564 | acpigen_write_byte(5); // 5 values |
| 565 | acpigen_write_byte(0); // revision 0 |
| 566 | acpigen_write_dword(domain); |
| 567 | acpigen_write_dword(coordtype); |
| 568 | acpigen_write_dword(numprocs); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 569 | acpigen_pop_len(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 570 | acpigen_pop_len(); |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 571 | } |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 572 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 573 | void acpigen_write_CST_package_entry(acpi_cstate_t *cstate) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 574 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 575 | acpigen_write_package(4); |
| 576 | acpigen_write_resourcetemplate_header(); |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 577 | acpigen_write_register(&cstate->resource); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 578 | acpigen_write_resourcetemplate_footer(); |
| 579 | acpigen_write_dword(cstate->ctype); |
| 580 | acpigen_write_dword(cstate->latency); |
| 581 | acpigen_write_dword(cstate->power); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 582 | acpigen_pop_len(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 583 | } |
| 584 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 585 | void acpigen_write_CST_package(acpi_cstate_t *cstate, int nentries) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 586 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 587 | int i; |
| 588 | acpigen_write_name("_CST"); |
| 589 | acpigen_write_package(nentries+1); |
| 590 | acpigen_write_dword(nentries); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 591 | |
| 592 | for (i = 0; i < nentries; i++) |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 593 | acpigen_write_CST_package_entry(cstate + i); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 594 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 595 | acpigen_pop_len(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 596 | } |
| 597 | |
Timothy Pearson | 83abd81 | 2015-06-08 19:35:06 -0500 | [diff] [blame] | 598 | void acpigen_write_CSD_package(u32 domain, u32 numprocs, CSD_coord coordtype, u32 index) |
| 599 | { |
| 600 | acpigen_write_name("_CSD"); |
| 601 | acpigen_write_package(1); |
| 602 | acpigen_write_package(6); |
| 603 | acpigen_write_byte(6); // 6 values |
| 604 | acpigen_write_byte(0); // revision 0 |
| 605 | acpigen_write_dword(domain); |
| 606 | acpigen_write_dword(coordtype); |
| 607 | acpigen_write_dword(numprocs); |
| 608 | acpigen_write_dword(index); |
| 609 | acpigen_pop_len(); |
| 610 | acpigen_pop_len(); |
| 611 | } |
| 612 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 613 | void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 614 | { |
| 615 | /* |
Elyes HAOUAS | 6b72787 | 2016-09-03 08:28:48 +0200 | [diff] [blame] | 616 | Sample _TSS package with 100% and 50% duty cycles |
| 617 | Name (_TSS, Package (0x02) |
| 618 | { |
| 619 | Package(){100, 1000, 0, 0x00, 0) |
| 620 | Package(){50, 520, 0, 0x18, 0) |
| 621 | }) |
| 622 | */ |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 623 | int i; |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 624 | acpi_tstate_t *tstate = tstate_list; |
| 625 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 626 | acpigen_write_name("_TSS"); |
| 627 | acpigen_write_package(entries); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 628 | |
| 629 | for (i = 0; i < entries; i++) { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 630 | acpigen_write_package(5); |
| 631 | acpigen_write_dword(tstate->percent); |
| 632 | acpigen_write_dword(tstate->power); |
| 633 | acpigen_write_dword(tstate->latency); |
| 634 | acpigen_write_dword(tstate->control); |
| 635 | acpigen_write_dword(tstate->status); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 636 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 637 | tstate++; |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 638 | } |
| 639 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 640 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 641 | } |
| 642 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 643 | void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 644 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 645 | acpigen_write_name("_TSD"); |
| 646 | acpigen_write_package(1); |
| 647 | acpigen_write_package(5); |
| 648 | acpigen_write_byte(5); // 5 values |
| 649 | acpigen_write_byte(0); // revision 0 |
| 650 | acpigen_write_dword(domain); |
| 651 | acpigen_write_dword(coordtype); |
| 652 | acpigen_write_dword(numprocs); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 653 | acpigen_pop_len(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 654 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | |
| 658 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 659 | void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 660 | { |
| 661 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 662 | * 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] | 663 | * Byte 0: |
| 664 | * Bit7 : 1 => big item |
| 665 | * Bit6-0: 0000110 (0x6) => 32-bit fixed memory |
| 666 | */ |
| 667 | acpigen_emit_byte(0x86); |
| 668 | /* Byte 1+2: length (0x0009) */ |
| 669 | acpigen_emit_byte(0x09); |
| 670 | acpigen_emit_byte(0x00); |
| 671 | /* bit1-7 are ignored */ |
| 672 | acpigen_emit_byte(readwrite ? 0x01 : 0x00); |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 673 | acpigen_emit_dword(base); |
| 674 | acpigen_emit_dword(size); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 677 | void acpigen_write_register(acpi_addr_t *addr) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 678 | { |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 679 | acpigen_emit_byte(0x82); /* Register Descriptor */ |
| 680 | acpigen_emit_byte(0x0c); /* Register Length 7:0 */ |
| 681 | acpigen_emit_byte(0x00); /* Register Length 15:8 */ |
| 682 | acpigen_emit_byte(addr->space_id); /* Address Space ID */ |
| 683 | acpigen_emit_byte(addr->bit_width); /* Register Bit Width */ |
| 684 | acpigen_emit_byte(addr->bit_offset); /* Register Bit Offset */ |
| 685 | acpigen_emit_byte(addr->resv); /* Register Access Size */ |
Duncan Laurie | 9ccae75 | 2016-05-09 07:43:19 -0700 | [diff] [blame] | 686 | acpigen_emit_dword(addr->addrl); /* Register Address Low */ |
| 687 | acpigen_emit_dword(addr->addrh); /* Register Address High */ |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 688 | } |
| 689 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 690 | void acpigen_write_irq(u16 mask) |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 691 | { |
| 692 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 693 | * ACPI 3.0b section 6.4.2.1: IRQ Descriptor |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 694 | * Byte 0: |
| 695 | * Bit7 : 0 => small item |
| 696 | * Bit6-3: 0100 (0x4) => IRQ port descriptor |
| 697 | * Bit2-0: 010 (0x2) => 2 Bytes long |
| 698 | */ |
| 699 | acpigen_emit_byte(0x22); |
| 700 | acpigen_emit_byte(mask & 0xff); |
| 701 | acpigen_emit_byte((mask >> 8) & 0xff); |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 702 | } |
| 703 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 704 | 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] | 705 | { |
| 706 | /* |
Elyes HAOUAS | 2078e75 | 2016-08-21 10:41:44 +0200 | [diff] [blame] | 707 | * ACPI 4.0 section 6.4.2.6: I/O Port Descriptor |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 708 | * Byte 0: |
| 709 | * Bit7 : 0 => small item |
| 710 | * Bit6-3: 1000 (0x8) => I/O port descriptor |
| 711 | * Bit2-0: 111 (0x7) => 7 Bytes long |
| 712 | */ |
| 713 | acpigen_emit_byte(0x47); |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 714 | /* Does the device decode all 16 or just 10 bits? */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 715 | /* bit1-7 are ignored */ |
| 716 | acpigen_emit_byte(decode16 ? 0x01 : 0x00); |
| 717 | /* minimum base address the device may be configured for */ |
| 718 | acpigen_emit_byte(min & 0xff); |
| 719 | acpigen_emit_byte((min >> 8) & 0xff); |
| 720 | /* maximum base address the device may be configured for */ |
| 721 | acpigen_emit_byte(max & 0xff); |
| 722 | acpigen_emit_byte((max >> 8) & 0xff); |
| 723 | /* alignment for min base */ |
| 724 | acpigen_emit_byte(align & 0xff); |
| 725 | acpigen_emit_byte(len & 0xff); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 728 | void acpigen_write_resourcetemplate_header(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 729 | { |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 730 | /* |
| 731 | * A ResourceTemplate() is a Buffer() with a |
| 732 | * (Byte|Word|DWord) containing the length, followed by one or more |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 733 | * resource items, terminated by the end tag. |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 734 | * (small item 0xf, len 1) |
| 735 | */ |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 736 | acpigen_emit_byte(BUFFER_OP); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 737 | acpigen_write_len_f(); |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 738 | acpigen_emit_byte(WORD_PREFIX); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 739 | len_stack[ltop++] = acpigen_get_current(); |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 740 | acpigen_emit_byte(0x00); |
| 741 | acpigen_emit_byte(0x00); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 744 | void acpigen_write_resourcetemplate_footer(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 745 | { |
| 746 | char *p = len_stack[--ltop]; |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 747 | int len; |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 748 | /* |
| 749 | * end tag (acpi 4.0 Section 6.4.2.8) |
| 750 | * 0x79 <checksum> |
| 751 | * 0x00 is treated as a good checksum according to the spec |
| 752 | * and is what iasl generates. |
| 753 | */ |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 754 | acpigen_emit_byte(0x79); |
| 755 | acpigen_emit_byte(0x00); |
| 756 | |
Martin Roth | e369010 | 2016-01-06 15:21:02 -0700 | [diff] [blame] | 757 | len = gencurrent - p; |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 758 | |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 759 | /* patch len word */ |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 760 | p[0] = len & 0xff; |
| 761 | p[1] = (len >> 8) & 0xff; |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 762 | /* patch len field */ |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 763 | acpigen_pop_len(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | static void acpigen_add_mainboard_rsvd_mem32(void *gp, struct device *dev, |
| 767 | struct resource *res) |
| 768 | { |
| 769 | acpigen_write_mem32fixed(0, res->base, res->size); |
| 770 | } |
| 771 | |
| 772 | static void acpigen_add_mainboard_rsvd_io(void *gp, struct device *dev, |
| 773 | struct resource *res) |
| 774 | { |
| 775 | resource_t base = res->base; |
| 776 | resource_t size = res->size; |
| 777 | while (size > 0) { |
| 778 | resource_t sz = size > 255 ? 255 : size; |
| 779 | acpigen_write_io16(base, base, 0, sz, 1); |
| 780 | size -= sz; |
| 781 | base += sz; |
| 782 | } |
| 783 | } |
| 784 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 785 | void acpigen_write_mainboard_resource_template(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 786 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 787 | acpigen_write_resourcetemplate_header(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 788 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 789 | /* Add reserved memory ranges. */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 790 | search_global_resources( |
| 791 | IORESOURCE_MEM | IORESOURCE_RESERVE, |
| 792 | IORESOURCE_MEM | IORESOURCE_RESERVE, |
| 793 | acpigen_add_mainboard_rsvd_mem32, 0); |
| 794 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 795 | /* Add reserved io ranges. */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 796 | search_global_resources( |
| 797 | IORESOURCE_IO | IORESOURCE_RESERVE, |
| 798 | IORESOURCE_IO | IORESOURCE_RESERVE, |
| 799 | acpigen_add_mainboard_rsvd_io, 0); |
| 800 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 801 | acpigen_write_resourcetemplate_footer(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 802 | } |
| 803 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 804 | void acpigen_write_mainboard_resources(const char *scope, const char *name) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 805 | { |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 806 | acpigen_write_scope(scope); |
| 807 | acpigen_write_name(name); |
| 808 | acpigen_write_mainboard_resource_template(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 809 | acpigen_pop_len(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 810 | } |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 811 | |
| 812 | static int hex2bin(const char c) |
| 813 | { |
| 814 | if (c >= 'A' && c <= 'F') |
| 815 | return c - 'A' + 10; |
| 816 | if (c >= 'a' && c <= 'f') |
| 817 | return c - 'a' + 10; |
| 818 | return c - '0'; |
| 819 | } |
| 820 | |
Vladimir Serbinenko | 9bb5c5c | 2014-11-09 03:51:32 +0100 | [diff] [blame] | 821 | void acpigen_emit_eisaid(const char *eisaid) |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 822 | { |
| 823 | u32 compact = 0; |
| 824 | |
| 825 | /* Clamping individual values would be better but |
| 826 | there is a disagreement over what is a valid |
| 827 | EISA id, so accept anything and don't clamp, |
| 828 | parent code should create a valid EISAid. |
| 829 | */ |
| 830 | compact |= (eisaid[0] - 'A' + 1) << 26; |
| 831 | compact |= (eisaid[1] - 'A' + 1) << 21; |
| 832 | compact |= (eisaid[2] - 'A' + 1) << 16; |
| 833 | compact |= hex2bin(eisaid[3]) << 12; |
| 834 | compact |= hex2bin(eisaid[4]) << 8; |
| 835 | compact |= hex2bin(eisaid[5]) << 4; |
| 836 | compact |= hex2bin(eisaid[6]); |
| 837 | |
| 838 | acpigen_emit_byte(0xc); |
| 839 | acpigen_emit_byte((compact >> 24) & 0xff); |
| 840 | acpigen_emit_byte((compact >> 16) & 0xff); |
| 841 | acpigen_emit_byte((compact >> 8) & 0xff); |
| 842 | acpigen_emit_byte(compact & 0xff); |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 843 | } |
Duncan Laurie | 3829f23 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 844 | |
| 845 | /* |
| 846 | * ToUUID(uuid) |
| 847 | * |
| 848 | * ACPI 6.1 Section 19.6.136 table 19-385 defines a special output |
| 849 | * order for the bytes that make up a UUID Buffer object. |
| 850 | * UUID byte order for input: |
| 851 | * aabbccdd-eeff-gghh-iijj-kkllmmnnoopp |
| 852 | * UUID byte order for output: |
| 853 | * ddccbbaa-ffee-hhgg-iijj-kkllmmnnoopp |
| 854 | */ |
| 855 | #define UUID_LEN 16 |
| 856 | void acpigen_write_uuid(const char *uuid) |
| 857 | { |
| 858 | uint8_t buf[UUID_LEN]; |
| 859 | size_t i, order[UUID_LEN] = { 3, 2, 1, 0, 5, 4, 7, 6, |
| 860 | 8, 9, 10, 11, 12, 13, 14, 15 }; |
| 861 | |
| 862 | /* Parse UUID string into bytes */ |
| 863 | if (hexstrtobin(uuid, buf, UUID_LEN) < UUID_LEN) |
| 864 | return; |
| 865 | |
| 866 | /* BufferOp */ |
Furquan Shaikh | e4e9b94 | 2016-10-20 23:09:05 -0700 | [diff] [blame] | 867 | acpigen_emit_byte(BUFFER_OP); |
Duncan Laurie | 3829f23 | 2016-05-09 11:08:46 -0700 | [diff] [blame] | 868 | acpigen_write_len_f(); |
| 869 | |
| 870 | /* Buffer length in bytes */ |
| 871 | acpigen_write_word(UUID_LEN); |
| 872 | |
| 873 | /* Output UUID in expected order */ |
| 874 | for (i = 0; i < UUID_LEN; i++) |
| 875 | acpigen_emit_byte(buf[order[i]]); |
| 876 | |
| 877 | acpigen_pop_len(); |
| 878 | } |
Furquan Shaikh | fcc7a04 | 2016-10-20 23:12:38 -0700 | [diff] [blame^] | 879 | |
| 880 | /* |
| 881 | * Name (_PRx, Package(One) { name }) |
| 882 | * ... |
| 883 | * PowerResource (name, level, order) |
| 884 | */ |
| 885 | void acpigen_write_power_res(const char *name, uint8_t level, uint16_t order, |
| 886 | const char *dev_states[], size_t dev_states_count) |
| 887 | { |
| 888 | int i; |
| 889 | for (i = 0; i < dev_states_count; i++) { |
| 890 | acpigen_write_name(dev_states[i]); |
| 891 | acpigen_write_package(1); |
| 892 | acpigen_emit_simple_namestring(name); |
| 893 | acpigen_pop_len(); /* Package */ |
| 894 | } |
| 895 | |
| 896 | acpigen_emit_ext_op(POWER_RES_OP); |
| 897 | |
| 898 | acpigen_write_len_f(); |
| 899 | |
| 900 | acpigen_emit_simple_namestring(name); |
| 901 | acpigen_emit_byte(level); |
| 902 | acpigen_emit_word(order); |
| 903 | } |
| 904 | |
| 905 | /* Sleep (ms) */ |
| 906 | void acpigen_write_sleep(uint64_t sleep_ms) |
| 907 | { |
| 908 | acpigen_emit_ext_op(SLEEP_OP); |
| 909 | acpigen_write_integer(sleep_ms); |
| 910 | } |
| 911 | |
| 912 | void acpigen_write_store(void) |
| 913 | { |
| 914 | acpigen_emit_byte(STORE_OP); |
| 915 | } |
| 916 | |
| 917 | /* Store (src, dst) */ |
| 918 | void acpigen_write_store_ops(uint8_t src, uint8_t dst) |
| 919 | { |
| 920 | acpigen_write_store(); |
| 921 | acpigen_emit_byte(src); |
| 922 | acpigen_emit_byte(dst); |
| 923 | } |
| 924 | |
| 925 | /* Or (arg1, arg2, res) */ |
| 926 | void acpigen_write_or(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 927 | { |
| 928 | acpigen_emit_byte(OR_OP); |
| 929 | acpigen_emit_byte(arg1); |
| 930 | acpigen_emit_byte(arg2); |
| 931 | acpigen_emit_byte(res); |
| 932 | } |
| 933 | |
| 934 | /* And (arg1, arg2, res) */ |
| 935 | void acpigen_write_and(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 936 | { |
| 937 | acpigen_emit_byte(AND_OP); |
| 938 | acpigen_emit_byte(arg1); |
| 939 | acpigen_emit_byte(arg2); |
| 940 | acpigen_emit_byte(res); |
| 941 | } |
| 942 | |
| 943 | /* Not (arg, res) */ |
| 944 | void acpigen_write_not(uint8_t arg, uint8_t res) |
| 945 | { |
| 946 | acpigen_emit_byte(NOT_OP); |
| 947 | acpigen_emit_byte(arg); |
| 948 | acpigen_emit_byte(res); |
| 949 | } |
| 950 | |
| 951 | /* Store (str, DEBUG) */ |
| 952 | void acpigen_write_debug_string(const char *str) |
| 953 | { |
| 954 | acpigen_write_store(); |
| 955 | acpigen_write_string(str); |
| 956 | acpigen_emit_ext_op(DEBUG_OP); |
| 957 | } |
| 958 | |
| 959 | /* Store (val, DEBUG) */ |
| 960 | void acpigen_write_debug_integer(uint64_t val) |
| 961 | { |
| 962 | acpigen_write_store(); |
| 963 | acpigen_write_integer(val); |
| 964 | acpigen_emit_ext_op(DEBUG_OP); |
| 965 | } |
| 966 | |
| 967 | /* Store (op, DEBUG) */ |
| 968 | void acpigen_write_debug_op(uint8_t op) |
| 969 | { |
| 970 | acpigen_write_store(); |
| 971 | acpigen_emit_byte(op); |
| 972 | acpigen_emit_ext_op(DEBUG_OP); |
| 973 | } |
| 974 | |
| 975 | void acpigen_write_if(void) |
| 976 | { |
| 977 | acpigen_emit_byte(IF_OP); |
| 978 | acpigen_write_len_f(); |
| 979 | } |
| 980 | |
| 981 | /* If (And (arg1, arg2)) */ |
| 982 | void acpigen_write_if_and(uint8_t arg1, uint8_t arg2) |
| 983 | { |
| 984 | acpigen_write_if(); |
| 985 | acpigen_emit_byte(AND_OP); |
| 986 | acpigen_emit_byte(arg1); |
| 987 | acpigen_emit_byte(arg2); |
| 988 | } |
| 989 | |
| 990 | void acpigen_write_else(void) |
| 991 | { |
| 992 | acpigen_emit_byte(ELSE_OP); |
| 993 | acpigen_write_len_f(); |
| 994 | } |