Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Rudolf Marek <r.marek@assembler.cz> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Uwe Hermann | c70e9fc | 2010-02-15 23:10:19 +0000 | [diff] [blame] | 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 20 | /* How much nesting do we support? */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 21 | #define ACPIGEN_LENSTACK_SIZE 10 |
| 22 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 23 | /* |
| 24 | * If you need to change this, change acpigen_write_f and |
Vladimir Serbinenko | 8104da7 | 2014-11-09 03:33:51 +0100 | [diff] [blame^] | 25 | * acpigen_pop_len |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 26 | */ |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 27 | |
| 28 | #define ACPIGEN_MAXLEN 0xfff |
| 29 | |
| 30 | #include <string.h> |
| 31 | #include <arch/acpigen.h> |
| 32 | #include <console/console.h> |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 33 | #include <device/device.h> |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 34 | |
| 35 | static char *gencurrent; |
| 36 | |
| 37 | char *len_stack[ACPIGEN_LENSTACK_SIZE]; |
| 38 | int ltop = 0; |
| 39 | |
Stefan Reinauer | 5b73d4d | 2012-04-27 21:55:05 +0200 | [diff] [blame] | 40 | int acpigen_write_len_f(void) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 41 | { |
| 42 | ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1)) |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 43 | len_stack[ltop++] = gencurrent; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 44 | acpigen_emit_byte(0); |
| 45 | acpigen_emit_byte(0); |
| 46 | return 2; |
| 47 | } |
| 48 | |
Vladimir Serbinenko | 430363a | 2014-11-02 21:51:22 +0100 | [diff] [blame] | 49 | void acpigen_pop_len(void) |
| 50 | { |
| 51 | int len; |
| 52 | ASSERT(ltop > 0) |
| 53 | char *p = len_stack[--ltop]; |
| 54 | len = gencurrent - p; |
| 55 | ASSERT(len <= ACPIGEN_MAXLEN) |
| 56 | /* generate store length for 0xfff max */ |
| 57 | p[0] = (0x40 | (len & 0xf)); |
| 58 | p[1] = (len >> 4 & 0xff); |
| 59 | |
| 60 | } |
| 61 | |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 62 | void acpigen_set_current(char *curr) |
| 63 | { |
| 64 | gencurrent = curr; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 67 | char *acpigen_get_current(void) |
| 68 | { |
| 69 | return gencurrent; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | int acpigen_emit_byte(unsigned char b) |
| 73 | { |
| 74 | (*gencurrent++) = b; |
| 75 | return 1; |
| 76 | } |
| 77 | |
| 78 | int acpigen_write_package(int nr_el) |
| 79 | { |
| 80 | int len; |
| 81 | /* package op */ |
| 82 | acpigen_emit_byte(0x12); |
| 83 | len = acpigen_write_len_f(); |
| 84 | acpigen_emit_byte(nr_el); |
| 85 | return len + 2; |
| 86 | } |
| 87 | |
| 88 | int acpigen_write_byte(unsigned int data) |
| 89 | { |
| 90 | /* byte op */ |
| 91 | acpigen_emit_byte(0xa); |
| 92 | acpigen_emit_byte(data & 0xff); |
| 93 | return 2; |
| 94 | } |
| 95 | |
| 96 | int acpigen_write_dword(unsigned int data) |
| 97 | { |
| 98 | /* dword op */ |
| 99 | acpigen_emit_byte(0xc); |
| 100 | acpigen_emit_byte(data & 0xff); |
| 101 | acpigen_emit_byte((data >> 8) & 0xff); |
| 102 | acpigen_emit_byte((data >> 16) & 0xff); |
| 103 | acpigen_emit_byte((data >> 24) & 0xff); |
| 104 | return 5; |
| 105 | } |
| 106 | |
Carl-Daniel Hailfinger | d58671c | 2009-02-17 21:38:51 +0000 | [diff] [blame] | 107 | int acpigen_write_qword(uint64_t data) |
| 108 | { |
| 109 | /* qword op */ |
| 110 | acpigen_emit_byte(0xe); |
| 111 | acpigen_emit_byte(data & 0xff); |
| 112 | acpigen_emit_byte((data >> 8) & 0xff); |
| 113 | acpigen_emit_byte((data >> 16) & 0xff); |
| 114 | acpigen_emit_byte((data >> 24) & 0xff); |
| 115 | acpigen_emit_byte((data >> 32) & 0xff); |
| 116 | acpigen_emit_byte((data >> 40) & 0xff); |
| 117 | acpigen_emit_byte((data >> 48) & 0xff); |
| 118 | acpigen_emit_byte((data >> 56) & 0xff); |
| 119 | return 9; |
| 120 | } |
| 121 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 122 | int acpigen_write_name_byte(const char *name, uint8_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 123 | { |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 124 | int len; |
| 125 | len = acpigen_write_name(name); |
| 126 | len += acpigen_write_byte(val); |
| 127 | return len; |
| 128 | } |
| 129 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 130 | int acpigen_write_name_dword(const char *name, uint32_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 131 | { |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 132 | int len; |
| 133 | len = acpigen_write_name(name); |
| 134 | len += acpigen_write_dword(val); |
| 135 | return len; |
| 136 | } |
| 137 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 138 | int acpigen_write_name_qword(const char *name, uint64_t val) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 139 | { |
Carl-Daniel Hailfinger | d58671c | 2009-02-17 21:38:51 +0000 | [diff] [blame] | 140 | int len; |
| 141 | len = acpigen_write_name(name); |
| 142 | len += acpigen_write_qword(val); |
| 143 | return len; |
| 144 | } |
| 145 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 146 | int acpigen_emit_stream(const char *data, int size) |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 147 | { |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 148 | int i; |
| 149 | for (i = 0; i < size; i++) { |
| 150 | acpigen_emit_byte(data[i]); |
| 151 | } |
| 152 | return size; |
| 153 | } |
| 154 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 155 | /* |
| 156 | * The naming conventions for ACPI namespace names are a bit tricky as |
| 157 | * each element has to be 4 chars wide (»All names are a fixed 32 bits.«) |
| 158 | * and »By convention, when an ASL compiler pads a name shorter than 4 |
| 159 | * characters, it is done so with trailing underscores (‘_’).«. |
| 160 | * |
| 161 | * Check sections 5.3, 18.2.2 and 18.4 of ACPI spec 3.0 for details. |
| 162 | */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 163 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 164 | static int acpigen_emit_simple_namestring(const char *name) { |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 165 | int i, len = 0; |
| 166 | char ud[] = "____"; |
| 167 | for (i = 0; i < 4; i++) { |
| 168 | if ((name[i] == '\0') || (name[i] == '.')) { |
| 169 | len += acpigen_emit_stream(ud, 4 - i); |
| 170 | break; |
| 171 | } else { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 172 | len += acpigen_emit_byte(name[i]); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 173 | } |
| 174 | } |
| 175 | return len; |
| 176 | } |
| 177 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 178 | static int acpigen_emit_double_namestring(const char *name, int dotpos) { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 179 | int len = 0; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 180 | /* mark dual name prefix */ |
| 181 | len += acpigen_emit_byte(0x2e); |
| 182 | len += acpigen_emit_simple_namestring(name); |
| 183 | len += acpigen_emit_simple_namestring(&name[dotpos + 1]); |
| 184 | return len; |
| 185 | } |
| 186 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 187 | static int acpigen_emit_multi_namestring(const char *name) { |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 188 | int len = 0, count = 0; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 189 | unsigned char *pathlen; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 190 | /* mark multi name prefix */ |
| 191 | len += acpigen_emit_byte(0x2f); |
| 192 | len += acpigen_emit_byte(0x0); |
| 193 | pathlen = ((unsigned char *) acpigen_get_current()) - 1; |
| 194 | |
| 195 | while (name[0] != '\0') { |
| 196 | len += acpigen_emit_simple_namestring(name); |
| 197 | /* find end or next entity */ |
| 198 | while ((name[0] != '.') && (name[0] != '\0')) |
| 199 | name++; |
| 200 | /* forward to next */ |
| 201 | if (name[0] == '.') |
| 202 | name++; |
| 203 | count++; |
| 204 | } |
| 205 | |
| 206 | pathlen[0] = count; |
| 207 | return len; |
| 208 | } |
| 209 | |
| 210 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 211 | int acpigen_emit_namestring(const char *namepath) { |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 212 | int dotcount = 0, i; |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 213 | int dotpos = 0; |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 214 | int len = 0; |
| 215 | |
Ronald G. Minnich | be738eb | 2013-03-07 11:05:28 -0600 | [diff] [blame] | 216 | /* We can start with a '\'. */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 217 | if (namepath[0] == '\\') { |
| 218 | len += acpigen_emit_byte('\\'); |
| 219 | namepath++; |
| 220 | } |
| 221 | |
Ronald G. Minnich | be738eb | 2013-03-07 11:05:28 -0600 | [diff] [blame] | 222 | /* And there can be any number of '^' */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 223 | while (namepath[0] == '^') { |
| 224 | len += acpigen_emit_byte('^'); |
| 225 | namepath++; |
| 226 | } |
| 227 | |
Vladimir Serbinenko | d942ed9 | 2014-08-30 20:44:37 +0200 | [diff] [blame] | 228 | /* If we have only \\ or only ^...^. Then we need to put a null |
| 229 | name (0x00). */ |
| 230 | if(namepath[0] == '\0') { |
| 231 | len += acpigen_emit_byte(0x00); |
| 232 | return len; |
| 233 | } |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 234 | |
| 235 | i = 0; |
| 236 | while (namepath[i] != '\0') { |
| 237 | if (namepath[i] == '.') { |
| 238 | dotcount++; |
| 239 | dotpos = i; |
| 240 | } |
| 241 | i++; |
| 242 | } |
| 243 | |
| 244 | if (dotcount == 0) { |
| 245 | len += acpigen_emit_simple_namestring(namepath); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 246 | } else if (dotcount == 1) { |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 247 | len += acpigen_emit_double_namestring(namepath, dotpos); |
| 248 | } else { |
| 249 | len += acpigen_emit_multi_namestring(namepath); |
| 250 | } |
| 251 | return len; |
| 252 | } |
| 253 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 254 | int acpigen_write_name(const char *name) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 255 | { |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 256 | int len; |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 257 | /* name op */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 258 | len = acpigen_emit_byte(0x8); |
| 259 | return len + acpigen_emit_namestring(name); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Myles Watson | 3fe6b70 | 2009-10-09 20:13:43 +0000 | [diff] [blame] | 262 | int acpigen_write_scope(const char *name) |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 263 | { |
| 264 | int len; |
| 265 | /* scope op */ |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 266 | len = acpigen_emit_byte(0x10); |
| 267 | len += acpigen_write_len_f(); |
| 268 | return len + acpigen_emit_namestring(name); |
Rudolf Marek | 293b5f5 | 2009-02-01 18:35:15 +0000 | [diff] [blame] | 269 | } |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 270 | |
| 271 | int acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len) |
| 272 | { |
| 273 | /* |
| 274 | Processor (\_PR.CPUcpuindex, cpuindex, pblock_addr, pblock_len) |
| 275 | { |
| 276 | */ |
| 277 | char pscope[16]; |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 278 | int len; |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 279 | /* processor op */ |
| 280 | acpigen_emit_byte(0x5b); |
| 281 | acpigen_emit_byte(0x83); |
| 282 | len = acpigen_write_len_f(); |
| 283 | |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 284 | snprintf(pscope, sizeof (pscope), |
Timothy Pearson | 033bb4b | 2015-02-10 22:21:39 -0600 | [diff] [blame] | 285 | "\\_PR.CP%02d", (unsigned int) cpuindex); |
Rudolf Marek | 3310d75 | 2009-06-21 20:26:13 +0000 | [diff] [blame] | 286 | len += acpigen_emit_namestring(pscope); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 287 | acpigen_emit_byte(cpuindex); |
| 288 | acpigen_emit_byte(pblock_addr & 0xff); |
| 289 | acpigen_emit_byte((pblock_addr >> 8) & 0xff); |
| 290 | acpigen_emit_byte((pblock_addr >> 16) & 0xff); |
| 291 | acpigen_emit_byte((pblock_addr >> 24) & 0xff); |
| 292 | acpigen_emit_byte(pblock_len); |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 293 | return 6 + 2 + len; |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | int acpigen_write_empty_PCT(void) |
| 297 | { |
| 298 | /* |
| 299 | Name (_PCT, Package (0x02) |
| 300 | { |
| 301 | ResourceTemplate () |
| 302 | { |
| 303 | Register (FFixedHW, |
| 304 | 0x00, // Bit Width |
| 305 | 0x00, // Bit Offset |
| 306 | 0x0000000000000000, // Address |
| 307 | ,) |
| 308 | }, |
| 309 | |
| 310 | ResourceTemplate () |
| 311 | { |
| 312 | Register (FFixedHW, |
| 313 | 0x00, // Bit Width |
| 314 | 0x00, // Bit Offset |
| 315 | 0x0000000000000000, // Address |
| 316 | ,) |
| 317 | } |
| 318 | }) |
| 319 | */ |
| 320 | static char stream[] = { |
| 321 | 0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, /* 00000030 "0._PCT.," */ |
| 322 | 0x02, 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, /* 00000038 "........" */ |
| 323 | 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000040 "........" */ |
| 324 | 0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, /* 00000048 "....y..." */ |
| 325 | 0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, /* 00000050 "........" */ |
| 326 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 00000058 "........" */ |
| 327 | 0x00, 0x79, 0x00 |
| 328 | }; |
| 329 | return acpigen_emit_stream(stream, ARRAY_SIZE(stream)); |
| 330 | } |
| 331 | |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 332 | int acpigen_write_empty_PTC(void) |
| 333 | { |
| 334 | /* |
| 335 | Name (_PTC, Package (0x02) |
| 336 | { |
| 337 | ResourceTemplate () |
| 338 | { |
| 339 | Register (FFixedHW, |
| 340 | 0x00, // Bit Width |
| 341 | 0x00, // Bit Offset |
| 342 | 0x0000000000000000, // Address |
| 343 | ,) |
| 344 | }, |
| 345 | |
| 346 | ResourceTemplate () |
| 347 | { |
| 348 | Register (FFixedHW, |
| 349 | 0x00, // Bit Width |
| 350 | 0x00, // Bit Offset |
| 351 | 0x0000000000000000, // Address |
| 352 | ,) |
| 353 | } |
| 354 | }) |
| 355 | */ |
| 356 | int len, nlen, rlen; |
| 357 | acpi_addr_t addr = { |
| 358 | .space_id = ACPI_ADDRESS_SPACE_FIXED, |
| 359 | .bit_width = 0, |
| 360 | .bit_offset = 0, |
zbao | ee8a9f6c | 2012-05-29 14:59:38 +0800 | [diff] [blame] | 361 | { |
| 362 | .resv = 0 |
| 363 | }, |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 364 | .addrl = 0, |
| 365 | .addrh = 0, |
| 366 | }; |
| 367 | |
| 368 | nlen = acpigen_write_name("_PTC"); |
| 369 | len = acpigen_write_package(2); |
| 370 | |
| 371 | /* ControlRegister */ |
| 372 | rlen = acpigen_write_resourcetemplate_header(); |
| 373 | rlen += acpigen_write_register(&addr); |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 374 | len += acpigen_write_resourcetemplate_footer(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 375 | len += rlen; |
| 376 | |
| 377 | /* StatusRegister */ |
| 378 | rlen = acpigen_write_resourcetemplate_header(); |
| 379 | rlen += acpigen_write_register(&addr); |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 380 | len += acpigen_write_resourcetemplate_footer(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 381 | len += rlen; |
| 382 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 383 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 384 | return len + nlen; |
| 385 | } |
| 386 | |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 387 | int acpigen_write_method(const char *name, int nargs) |
| 388 | { |
| 389 | int len; |
| 390 | |
| 391 | /* method op */ |
| 392 | len = acpigen_emit_byte(0x14); |
| 393 | len += acpigen_write_len_f(); |
| 394 | len += acpigen_emit_namestring(name); |
| 395 | len += acpigen_emit_byte(nargs & 7); |
| 396 | |
| 397 | return len; |
| 398 | } |
| 399 | |
Vladimir Serbinenko | 663be6e | 2014-11-05 21:29:45 +0100 | [diff] [blame] | 400 | int acpigen_write_device(const char *name) |
| 401 | { |
| 402 | int len; |
| 403 | |
| 404 | /* method op */ |
| 405 | len = acpigen_emit_byte(0x5b); |
| 406 | len += acpigen_emit_byte(0x82); |
| 407 | len += acpigen_write_len_f(); |
| 408 | len += acpigen_emit_namestring(name); |
| 409 | |
| 410 | return len; |
| 411 | } |
| 412 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 413 | /* |
| 414 | * Generates a func with max supported P-states. |
| 415 | */ |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 416 | int acpigen_write_PPC(u8 nr) |
| 417 | { |
| 418 | /* |
| 419 | Method (_PPC, 0, NotSerialized) |
| 420 | { |
| 421 | Return (nr) |
| 422 | } |
| 423 | */ |
| 424 | int len; |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 425 | len = acpigen_write_method("_PPC", 0); |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 426 | /* return */ |
| 427 | acpigen_emit_byte(0xa4); |
| 428 | /* arg */ |
| 429 | len += acpigen_write_byte(nr); |
Rudolf Marek | 6b2e760 | 2009-03-02 22:45:31 +0000 | [diff] [blame] | 430 | /* add all single bytes */ |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 431 | len += 1; |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 432 | acpigen_pop_len(); |
Rudolf Marek | 6b2e760 | 2009-03-02 22:45:31 +0000 | [diff] [blame] | 433 | return len; |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 434 | } |
| 435 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 436 | /* |
| 437 | * Generates a func with max supported P-states saved |
| 438 | * in the variable PPCM. |
| 439 | */ |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 440 | int acpigen_write_PPC_NVS(void) |
| 441 | { |
| 442 | /* |
| 443 | Method (_PPC, 0, NotSerialized) |
| 444 | { |
| 445 | Return (PPCM) |
| 446 | } |
| 447 | */ |
| 448 | int len; |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 449 | |
| 450 | len = acpigen_write_method("_PPC", 0); |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 451 | /* return */ |
| 452 | acpigen_emit_byte(0xa4); |
| 453 | /* arg */ |
| 454 | len += acpigen_emit_namestring("PPCM"); |
| 455 | /* add all single bytes */ |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 456 | len += 1; |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 457 | acpigen_pop_len(); |
Duncan Laurie | 0eefa00 | 2012-07-16 12:11:53 -0700 | [diff] [blame] | 458 | return len; |
| 459 | } |
| 460 | |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 461 | int acpigen_write_TPC(const char *gnvs_tpc_limit) |
| 462 | { |
| 463 | /* |
| 464 | // Sample _TPC method |
| 465 | Method (_TPC, 0, NotSerialized) |
| 466 | { |
| 467 | Return (\TLVL) |
| 468 | } |
| 469 | */ |
| 470 | int len; |
| 471 | |
Vladimir Serbinenko | 80fb8ed | 2014-11-05 10:28:28 +0100 | [diff] [blame] | 472 | len = acpigen_write_method("_TPC", 0); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 473 | len += acpigen_emit_byte(0xa4); /* ReturnOp */ |
| 474 | len += acpigen_emit_namestring(gnvs_tpc_limit); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 475 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 476 | return len; |
| 477 | } |
| 478 | |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 479 | int acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, |
| 480 | u32 busmLat, u32 control, u32 status) |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 481 | { |
| 482 | int len; |
| 483 | len = acpigen_write_package(6); |
| 484 | len += acpigen_write_dword(coreFreq); |
| 485 | len += acpigen_write_dword(power); |
| 486 | len += acpigen_write_dword(transLat); |
| 487 | len += acpigen_write_dword(busmLat); |
| 488 | len += acpigen_write_dword(control); |
| 489 | len += acpigen_write_dword(status); |
Stefan Reinauer | d4bacf9 | 2012-05-02 16:38:47 -0700 | [diff] [blame] | 490 | // pkglen without the len opcode |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 491 | acpigen_pop_len(); |
Stefan Reinauer | d4bacf9 | 2012-05-02 16:38:47 -0700 | [diff] [blame] | 492 | |
| 493 | printk(BIOS_DEBUG, "PSS: %uMHz power %u control 0x%x status 0x%x\n", |
| 494 | coreFreq, power, control, status); |
| 495 | |
Rudolf Marek | f997b55 | 2009-02-14 15:40:23 +0000 | [diff] [blame] | 496 | return len; |
| 497 | } |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 498 | |
| 499 | int acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
| 500 | { |
| 501 | int len, lenh, lenp; |
| 502 | lenh = acpigen_write_name("_PSD"); |
| 503 | lenp = acpigen_write_package(1); |
| 504 | len = acpigen_write_package(5); |
Stefan Reinauer | f96c2d9 | 2009-04-22 16:23:47 +0000 | [diff] [blame] | 505 | len += acpigen_write_byte(5); // 5 values |
| 506 | len += acpigen_write_byte(0); // revision 0 |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 507 | len += acpigen_write_dword(domain); |
| 508 | len += acpigen_write_dword(coordtype); |
| 509 | len += acpigen_write_dword(numprocs); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 510 | acpigen_pop_len(); |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 511 | len += lenp; |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 512 | acpigen_pop_len(); |
Patrick Georgi | df444bf | 2009-04-21 20:34:36 +0000 | [diff] [blame] | 513 | return len + lenh; |
| 514 | } |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 515 | |
Stefan Reinauer | f69b468 | 2012-04-27 23:12:08 +0200 | [diff] [blame] | 516 | int acpigen_write_CST_package_entry(acpi_cstate_t *cstate) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 517 | { |
| 518 | int len, len0; |
| 519 | char *start, *end; |
| 520 | |
| 521 | len0 = acpigen_write_package(4); |
| 522 | len = acpigen_write_resourcetemplate_header(); |
| 523 | start = acpigen_get_current(); |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 524 | acpigen_write_register(&cstate->resource); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 525 | end = acpigen_get_current(); |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 526 | len += end - start; |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 527 | len += acpigen_write_resourcetemplate_footer(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 528 | len += len0; |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 529 | len += acpigen_write_dword(cstate->ctype); |
| 530 | len += acpigen_write_dword(cstate->latency); |
| 531 | len += acpigen_write_dword(cstate->power); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 532 | acpigen_pop_len(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 533 | return len; |
| 534 | } |
| 535 | |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 536 | int acpigen_write_CST_package(acpi_cstate_t *cstate, int nentries) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 537 | { |
| 538 | int len, lenh, lenp, i; |
| 539 | lenh = acpigen_write_name("_CST"); |
| 540 | lenp = acpigen_write_package(nentries+1); |
| 541 | len = acpigen_write_dword(nentries); |
| 542 | |
| 543 | for (i = 0; i < nentries; i++) |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 544 | len += acpigen_write_CST_package_entry(cstate + i); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 545 | |
| 546 | len += lenp; |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 547 | acpigen_pop_len(); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 548 | return len + lenh; |
| 549 | } |
| 550 | |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 551 | int acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list) |
| 552 | { |
| 553 | /* |
| 554 | Sample _TSS package with 100% and 50% duty cycles |
| 555 | Name (_TSS, Package (0x02) |
| 556 | { |
| 557 | Package(){100, 1000, 0, 0x00, 0) |
| 558 | Package(){50, 520, 0, 0x18, 0) |
| 559 | }) |
| 560 | */ |
| 561 | int i, len, plen, nlen; |
| 562 | acpi_tstate_t *tstate = tstate_list; |
| 563 | |
| 564 | nlen = acpigen_write_name("_TSS"); |
| 565 | plen = acpigen_write_package(entries); |
| 566 | |
| 567 | for (i = 0; i < entries; i++) { |
| 568 | len = acpigen_write_package(5); |
| 569 | len += acpigen_write_dword(tstate->percent); |
| 570 | len += acpigen_write_dword(tstate->power); |
| 571 | len += acpigen_write_dword(tstate->latency); |
| 572 | len += acpigen_write_dword(tstate->control); |
| 573 | len += acpigen_write_dword(tstate->status); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 574 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 575 | tstate++; |
| 576 | plen += len; |
| 577 | } |
| 578 | |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 579 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 580 | return plen + nlen; |
| 581 | } |
| 582 | |
| 583 | int acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
| 584 | { |
| 585 | int len, lenh, lenp; |
| 586 | lenh = acpigen_write_name("_TSD"); |
| 587 | lenp = acpigen_write_package(1); |
| 588 | len = acpigen_write_package(5); |
| 589 | len += acpigen_write_byte(5); // 5 values |
| 590 | len += acpigen_write_byte(0); // revision 0 |
| 591 | len += acpigen_write_dword(domain); |
| 592 | len += acpigen_write_dword(coordtype); |
| 593 | len += acpigen_write_dword(numprocs); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 594 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 595 | len += lenp; |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 596 | acpigen_pop_len(); |
Stefan Reinauer | 39205c6 | 2012-04-27 21:49:28 +0200 | [diff] [blame] | 597 | return len + lenh; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 602 | int acpigen_write_mem32fixed(int readwrite, u32 base, u32 size) |
| 603 | { |
| 604 | /* |
| 605 | * acpi 4.0 section 6.4.3.4: 32-Bit Fixed Memory Range Descriptor |
| 606 | * Byte 0: |
| 607 | * Bit7 : 1 => big item |
| 608 | * Bit6-0: 0000110 (0x6) => 32-bit fixed memory |
| 609 | */ |
| 610 | acpigen_emit_byte(0x86); |
| 611 | /* Byte 1+2: length (0x0009) */ |
| 612 | acpigen_emit_byte(0x09); |
| 613 | acpigen_emit_byte(0x00); |
| 614 | /* bit1-7 are ignored */ |
| 615 | acpigen_emit_byte(readwrite ? 0x01 : 0x00); |
| 616 | acpigen_emit_byte(base & 0xff); |
| 617 | acpigen_emit_byte((base >> 8) & 0xff); |
| 618 | acpigen_emit_byte((base >> 16) & 0xff); |
| 619 | acpigen_emit_byte((base >> 24) & 0xff); |
| 620 | acpigen_emit_byte(size & 0xff); |
| 621 | acpigen_emit_byte((size >> 8) & 0xff); |
| 622 | acpigen_emit_byte((size >> 16) & 0xff); |
| 623 | acpigen_emit_byte((size >> 24) & 0xff); |
| 624 | return 12; |
| 625 | } |
| 626 | |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 627 | int acpigen_write_register(acpi_addr_t *addr) |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 628 | { |
Stefan Reinauer | 4cc8c70 | 2012-04-27 21:34:16 +0200 | [diff] [blame] | 629 | acpigen_emit_byte(0x82); /* Register Descriptor */ |
| 630 | acpigen_emit_byte(0x0c); /* Register Length 7:0 */ |
| 631 | acpigen_emit_byte(0x00); /* Register Length 15:8 */ |
| 632 | acpigen_emit_byte(addr->space_id); /* Address Space ID */ |
| 633 | acpigen_emit_byte(addr->bit_width); /* Register Bit Width */ |
| 634 | acpigen_emit_byte(addr->bit_offset); /* Register Bit Offset */ |
| 635 | acpigen_emit_byte(addr->resv); /* Register Access Size */ |
| 636 | acpigen_emit_byte(addr->addrl & 0xff); /* Register Address Low */ |
| 637 | acpigen_emit_byte((addr->addrl >> 8) & 0xff); |
| 638 | acpigen_emit_byte((addr->addrl >> 16) & 0xff); |
| 639 | acpigen_emit_byte((addr->addrl >> 24) & 0xff); |
| 640 | acpigen_emit_byte(addr->addrh & 0xff); /* Register Address High */ |
| 641 | acpigen_emit_byte((addr->addrh >> 8) & 0xff); |
| 642 | acpigen_emit_byte((addr->addrh >> 16) & 0xff); |
| 643 | acpigen_emit_byte((addr->addrh >> 24) & 0xff); |
Sven Schnelle | 0b86c76 | 2011-10-21 21:46:47 +0200 | [diff] [blame] | 644 | return 15; |
| 645 | } |
| 646 | |
Vladimir Serbinenko | 20ea040 | 2014-02-15 18:57:17 +0100 | [diff] [blame] | 647 | int acpigen_write_irq(u16 mask) |
| 648 | { |
| 649 | /* |
| 650 | * acpi 3.0b section 6.4.2.1: IRQ Descriptor |
| 651 | * Byte 0: |
| 652 | * Bit7 : 0 => small item |
| 653 | * Bit6-3: 0100 (0x4) => IRQ port descriptor |
| 654 | * Bit2-0: 010 (0x2) => 2 Bytes long |
| 655 | */ |
| 656 | acpigen_emit_byte(0x22); |
| 657 | acpigen_emit_byte(mask & 0xff); |
| 658 | acpigen_emit_byte((mask >> 8) & 0xff); |
| 659 | return 3; |
| 660 | } |
| 661 | |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 662 | int acpigen_write_io16(u16 min, u16 max, u8 align, u8 len, u8 decode16) |
| 663 | { |
| 664 | /* |
| 665 | * acpi 4.0 section 6.4.2.6: I/O Port Descriptor |
| 666 | * Byte 0: |
| 667 | * Bit7 : 0 => small item |
| 668 | * Bit6-3: 1000 (0x8) => I/O port descriptor |
| 669 | * Bit2-0: 111 (0x7) => 7 Bytes long |
| 670 | */ |
| 671 | acpigen_emit_byte(0x47); |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 672 | /* Does the device decode all 16 or just 10 bits? */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 673 | /* bit1-7 are ignored */ |
| 674 | acpigen_emit_byte(decode16 ? 0x01 : 0x00); |
| 675 | /* minimum base address the device may be configured for */ |
| 676 | acpigen_emit_byte(min & 0xff); |
| 677 | acpigen_emit_byte((min >> 8) & 0xff); |
| 678 | /* maximum base address the device may be configured for */ |
| 679 | acpigen_emit_byte(max & 0xff); |
| 680 | acpigen_emit_byte((max >> 8) & 0xff); |
| 681 | /* alignment for min base */ |
| 682 | acpigen_emit_byte(align & 0xff); |
| 683 | acpigen_emit_byte(len & 0xff); |
| 684 | return 8; |
| 685 | } |
| 686 | |
| 687 | int acpigen_write_resourcetemplate_header(void) |
| 688 | { |
| 689 | int len; |
| 690 | /* |
| 691 | * A ResourceTemplate() is a Buffer() with a |
| 692 | * (Byte|Word|DWord) containing the length, followed by one or more |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 693 | * resource items, terminated by the end tag. |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 694 | * (small item 0xf, len 1) |
| 695 | */ |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 696 | len = acpigen_emit_byte(0x11); /* Buffer opcode */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 697 | len += acpigen_write_len_f(); |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 698 | len += acpigen_emit_byte(0x0b); /* Word opcode */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 699 | len_stack[ltop++] = acpigen_get_current(); |
| 700 | len += acpigen_emit_byte(0x00); |
| 701 | len += acpigen_emit_byte(0x00); |
| 702 | return len; |
| 703 | } |
| 704 | |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 705 | int acpigen_write_resourcetemplate_footer(void) |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 706 | { |
| 707 | char *p = len_stack[--ltop]; |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 708 | int len; |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 709 | /* |
| 710 | * end tag (acpi 4.0 Section 6.4.2.8) |
| 711 | * 0x79 <checksum> |
| 712 | * 0x00 is treated as a good checksum according to the spec |
| 713 | * and is what iasl generates. |
| 714 | */ |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 715 | acpigen_emit_byte(0x79); |
| 716 | acpigen_emit_byte(0x00); |
| 717 | |
| 718 | len = gencurrent - p; |
| 719 | |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 720 | /* patch len word */ |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 721 | p[0] = len & 0xff; |
| 722 | p[1] = (len >> 8) & 0xff; |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 723 | /* patch len field */ |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 724 | acpigen_pop_len(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 725 | return 2; |
| 726 | } |
| 727 | |
| 728 | static void acpigen_add_mainboard_rsvd_mem32(void *gp, struct device *dev, |
| 729 | struct resource *res) |
| 730 | { |
| 731 | acpigen_write_mem32fixed(0, res->base, res->size); |
| 732 | } |
| 733 | |
| 734 | static void acpigen_add_mainboard_rsvd_io(void *gp, struct device *dev, |
| 735 | struct resource *res) |
| 736 | { |
| 737 | resource_t base = res->base; |
| 738 | resource_t size = res->size; |
| 739 | while (size > 0) { |
| 740 | resource_t sz = size > 255 ? 255 : size; |
| 741 | acpigen_write_io16(base, base, 0, sz, 1); |
| 742 | size -= sz; |
| 743 | base += sz; |
| 744 | } |
| 745 | } |
| 746 | |
| 747 | int acpigen_write_mainboard_resource_template(void) |
| 748 | { |
| 749 | int len; |
| 750 | char *start; |
| 751 | char *end; |
| 752 | len = acpigen_write_resourcetemplate_header(); |
| 753 | start = acpigen_get_current(); |
| 754 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 755 | /* Add reserved memory ranges. */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 756 | search_global_resources( |
| 757 | IORESOURCE_MEM | IORESOURCE_RESERVE, |
| 758 | IORESOURCE_MEM | IORESOURCE_RESERVE, |
| 759 | acpigen_add_mainboard_rsvd_mem32, 0); |
| 760 | |
Paul Menzel | 0f4c0e2 | 2013-02-22 12:33:08 +0100 | [diff] [blame] | 761 | /* Add reserved io ranges. */ |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 762 | search_global_resources( |
| 763 | IORESOURCE_IO | IORESOURCE_RESERVE, |
| 764 | IORESOURCE_IO | IORESOURCE_RESERVE, |
| 765 | acpigen_add_mainboard_rsvd_io, 0); |
| 766 | |
| 767 | end = acpigen_get_current(); |
| 768 | len += end-start; |
Vladimir Serbinenko | 9acc1e8 | 2014-11-09 03:37:28 +0100 | [diff] [blame] | 769 | len += acpigen_write_resourcetemplate_footer(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 770 | return len; |
| 771 | } |
| 772 | |
| 773 | int acpigen_write_mainboard_resources(const char *scope, const char *name) |
| 774 | { |
| 775 | int len; |
| 776 | len = acpigen_write_scope(scope); |
| 777 | len += acpigen_write_name(name); |
| 778 | len += acpigen_write_mainboard_resource_template(); |
Vladimir Serbinenko | a09f4db | 2014-11-09 03:32:58 +0100 | [diff] [blame] | 779 | acpigen_pop_len(); |
Tobias Diedrich | 0fe6e9a | 2010-11-17 16:27:06 +0000 | [diff] [blame] | 780 | return len; |
| 781 | } |
Vladimir Serbinenko | 8ecdc9e | 2014-02-15 18:59:40 +0100 | [diff] [blame] | 782 | |
| 783 | static int hex2bin(const char c) |
| 784 | { |
| 785 | if (c >= 'A' && c <= 'F') |
| 786 | return c - 'A' + 10; |
| 787 | if (c >= 'a' && c <= 'f') |
| 788 | return c - 'a' + 10; |
| 789 | return c - '0'; |
| 790 | } |
| 791 | |
| 792 | int acpigen_emit_eisaid(const char *eisaid) |
| 793 | { |
| 794 | u32 compact = 0; |
| 795 | |
| 796 | /* Clamping individual values would be better but |
| 797 | there is a disagreement over what is a valid |
| 798 | EISA id, so accept anything and don't clamp, |
| 799 | parent code should create a valid EISAid. |
| 800 | */ |
| 801 | compact |= (eisaid[0] - 'A' + 1) << 26; |
| 802 | compact |= (eisaid[1] - 'A' + 1) << 21; |
| 803 | compact |= (eisaid[2] - 'A' + 1) << 16; |
| 804 | compact |= hex2bin(eisaid[3]) << 12; |
| 805 | compact |= hex2bin(eisaid[4]) << 8; |
| 806 | compact |= hex2bin(eisaid[5]) << 4; |
| 807 | compact |= hex2bin(eisaid[6]); |
| 808 | |
| 809 | acpigen_emit_byte(0xc); |
| 810 | acpigen_emit_byte((compact >> 24) & 0xff); |
| 811 | acpigen_emit_byte((compact >> 16) & 0xff); |
| 812 | acpigen_emit_byte((compact >> 8) & 0xff); |
| 813 | acpigen_emit_byte(compact & 0xff); |
| 814 | return 5; |
| 815 | } |