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