| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#define ACPIGEN_LENSTACK_SIZE 15 |
| 5 |
|
| 6 |
|
| 7 |
#define ACPIGEN_RSVD_PKGLEN_BYTES 3 |
| 8 |
|
| 9 |
#include <lib.h> |
| 10 |
#include <string.h> |
| 11 |
#include <acpi/acpigen.h> |
| 12 |
#include <assert.h> |
| 13 |
#include <commonlib/helpers.h> |
| 14 |
#include <console/console.h> |
| 15 |
#include <device/device.h> |
| 16 |
#include <device/soundwire.h> |
| 17 |
#include <stdio.h> |
| 18 |
#include <types.h> |
| 19 |
|
| 20 |
static char *gencurrent; |
| 21 |
|
| 22 |
char *len_stack[ACPIGEN_LENSTACK_SIZE]; |
| 23 |
int ltop = 0; |
| 24 |
|
| 25 |
void acpigen_write_len_f(void) |
| 26 |
{ |
| 27 |
ASSERT(ltop < (ACPIGEN_LENSTACK_SIZE - 1)) |
| 28 |
len_stack[ltop++] = gencurrent; |
| 29 |
|
| 30 |
|
| 31 |
for (size_t i = 0; i < ACPIGEN_RSVD_PKGLEN_BYTES; i++) |
| 32 |
acpigen_emit_byte(0); |
| 33 |
} |
| 34 |
|
| 35 |
void acpigen_pop_len(void) |
| 36 |
{ |
| 37 |
size_t len; |
| 38 |
ASSERT(ltop > 0) |
| 39 |
char *p = len_stack[--ltop]; |
| 40 |
len = gencurrent - p; |
| 41 |
const size_t payload_len = len - ACPIGEN_RSVD_PKGLEN_BYTES; |
| 42 |
|
| 43 |
if (len <= 0x3f + 2) { |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
memmove(&p[ACPIGEN_RSVD_PKGLEN_BYTES - 2], |
| 48 |
&p[ACPIGEN_RSVD_PKGLEN_BYTES], payload_len); |
| 49 |
|
| 50 |
|
| 51 |
len -= 2; |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
p[0] = len; |
| 56 |
|
| 57 |
acpigen_set_current(p + len); |
| 58 |
} else if (len <= 0xfff + 1) { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
memmove(&p[ACPIGEN_RSVD_PKGLEN_BYTES - 1], |
| 63 |
&p[ACPIGEN_RSVD_PKGLEN_BYTES], payload_len); |
| 64 |
|
| 65 |
|
| 66 |
len -= 1; |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
p[0] = (0x1 << 6 | (len & 0xf)); |
| 71 |
p[1] = (len >> 4 & 0xff); |
| 72 |
|
| 73 |
acpigen_set_current(p + len); |
| 74 |
} else if (len <= 0xfffff) { |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
p[0] = (0x2 << 6 | (len & 0xf)); |
| 82 |
p[1] = (len >> 4 & 0xff); |
| 83 |
p[2] = (len >> 12 & 0xff); |
| 84 |
|
| 85 |
} else { |
| 86 |
|
| 87 |
printk(BIOS_ERR, "%s: package length exceeds maximum of 0xfffff.\n", __func__); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
void acpigen_set_current(char *curr) |
| 92 |
{ |
| 93 |
gencurrent = curr; |
| 94 |
} |
| 95 |
|
| 96 |
char *acpigen_get_current(void) |
| 97 |
{ |
| 98 |
return gencurrent; |
| 99 |
} |
| 100 |
|
| 101 |
void acpigen_emit_byte(unsigned char b) |
| 102 |
{ |
| 103 |
(*gencurrent++) = b; |
| 104 |
} |
| 105 |
|
| 106 |
void acpigen_emit_ext_op(uint8_t op) |
| 107 |
{ |
| 108 |
acpigen_emit_byte(EXT_OP_PREFIX); |
| 109 |
acpigen_emit_byte(op); |
| 110 |
} |
| 111 |
|
| 112 |
void acpigen_emit_word(unsigned int data) |
| 113 |
{ |
| 114 |
acpigen_emit_byte(data & 0xff); |
| 115 |
acpigen_emit_byte((data >> 8) & 0xff); |
| 116 |
} |
| 117 |
|
| 118 |
void acpigen_emit_dword(unsigned int data) |
| 119 |
{ |
| 120 |
acpigen_emit_byte(data & 0xff); |
| 121 |
acpigen_emit_byte((data >> 8) & 0xff); |
| 122 |
acpigen_emit_byte((data >> 16) & 0xff); |
| 123 |
acpigen_emit_byte((data >> 24) & 0xff); |
| 124 |
} |
| 125 |
|
| 126 |
char *acpigen_write_package(int nr_el) |
| 127 |
{ |
| 128 |
char *p; |
| 129 |
acpigen_emit_byte(PACKAGE_OP); |
| 130 |
acpigen_write_len_f(); |
| 131 |
p = acpigen_get_current(); |
| 132 |
acpigen_emit_byte(nr_el); |
| 133 |
return p; |
| 134 |
} |
| 135 |
|
| 136 |
void acpigen_write_byte(unsigned int data) |
| 137 |
{ |
| 138 |
acpigen_emit_byte(BYTE_PREFIX); |
| 139 |
acpigen_emit_byte(data & 0xff); |
| 140 |
} |
| 141 |
|
| 142 |
void acpigen_write_word(unsigned int data) |
| 143 |
{ |
| 144 |
acpigen_emit_byte(WORD_PREFIX); |
| 145 |
acpigen_emit_word(data); |
| 146 |
} |
| 147 |
|
| 148 |
void acpigen_write_dword(unsigned int data) |
| 149 |
{ |
| 150 |
acpigen_emit_byte(DWORD_PREFIX); |
| 151 |
acpigen_emit_dword(data); |
| 152 |
} |
| 153 |
|
| 154 |
void acpigen_write_qword(uint64_t data) |
| 155 |
{ |
| 156 |
acpigen_emit_byte(QWORD_PREFIX); |
| 157 |
acpigen_emit_dword(data & 0xffffffff); |
| 158 |
acpigen_emit_dword((data >> 32) & 0xffffffff); |
| 159 |
} |
| 160 |
|
| 161 |
void acpigen_write_zero(void) |
| 162 |
{ |
| 163 |
acpigen_emit_byte(ZERO_OP); |
| 164 |
} |
| 165 |
|
| 166 |
void acpigen_write_one(void) |
| 167 |
{ |
| 168 |
acpigen_emit_byte(ONE_OP); |
| 169 |
} |
| 170 |
|
| 171 |
void acpigen_write_ones(void) |
| 172 |
{ |
| 173 |
acpigen_emit_byte(ONES_OP); |
| 174 |
} |
| 175 |
|
| 176 |
void acpigen_write_integer(uint64_t data) |
| 177 |
{ |
| 178 |
if (data == 0) |
| 179 |
acpigen_write_zero(); |
| 180 |
else if (data == 1) |
| 181 |
acpigen_write_one(); |
| 182 |
else if (data <= 0xff) |
| 183 |
acpigen_write_byte((unsigned char)data); |
| 184 |
else if (data <= 0xffff) |
| 185 |
acpigen_write_word((unsigned int)data); |
| 186 |
else if (data <= 0xffffffff) |
| 187 |
acpigen_write_dword((unsigned int)data); |
| 188 |
else |
| 189 |
acpigen_write_qword(data); |
| 190 |
} |
| 191 |
|
| 192 |
void acpigen_write_name_byte(const char *name, uint8_t val) |
| 193 |
{ |
| 194 |
acpigen_write_name(name); |
| 195 |
acpigen_write_byte(val); |
| 196 |
} |
| 197 |
|
| 198 |
void acpigen_write_name_dword(const char *name, uint32_t val) |
| 199 |
{ |
| 200 |
acpigen_write_name(name); |
| 201 |
acpigen_write_dword(val); |
| 202 |
} |
| 203 |
|
| 204 |
void acpigen_write_name_qword(const char *name, uint64_t val) |
| 205 |
{ |
| 206 |
acpigen_write_name(name); |
| 207 |
acpigen_write_qword(val); |
| 208 |
} |
| 209 |
|
| 210 |
void acpigen_write_name_integer(const char *name, uint64_t val) |
| 211 |
{ |
| 212 |
acpigen_write_name(name); |
| 213 |
acpigen_write_integer(val); |
| 214 |
} |
| 215 |
|
| 216 |
void acpigen_write_name_string(const char *name, const char *string) |
| 217 |
{ |
| 218 |
acpigen_write_name(name); |
| 219 |
acpigen_write_string(string); |
| 220 |
} |
| 221 |
|
| 222 |
void acpigen_write_name_unicode(const char *name, const char *string) |
| 223 |
{ |
| 224 |
const size_t len = strlen(string) + 1; |
| 225 |
acpigen_write_name(name); |
| 226 |
acpigen_emit_byte(BUFFER_OP); |
| 227 |
acpigen_write_len_f(); |
| 228 |
acpigen_write_integer(2 * len); |
| 229 |
for (size_t i = 0; i < len; i++) { |
| 230 |
const signed char c = string[i]; |
| 231 |
|
| 232 |
acpigen_emit_word(c >= 0 ? c : '?'); |
| 233 |
} |
| 234 |
acpigen_pop_len(); |
| 235 |
} |
| 236 |
|
| 237 |
void acpigen_emit_stream(const char *data, int size) |
| 238 |
{ |
| 239 |
int i; |
| 240 |
for (i = 0; i < size; i++) |
| 241 |
acpigen_emit_byte(data[i]); |
| 242 |
} |
| 243 |
|
| 244 |
void acpigen_emit_string(const char *string) |
| 245 |
{ |
| 246 |
acpigen_emit_stream(string, string ? strlen(string) : 0); |
| 247 |
acpigen_emit_byte('\0'); |
| 248 |
} |
| 249 |
|
| 250 |
void acpigen_write_string(const char *string) |
| 251 |
{ |
| 252 |
acpigen_emit_byte(STRING_PREFIX); |
| 253 |
acpigen_emit_string(string); |
| 254 |
} |
| 255 |
|
| 256 |
void acpigen_write_coreboot_hid(enum coreboot_acpi_ids id) |
| 257 |
{ |
| 258 |
char hid[9]; |
| 259 |
|
| 260 |
snprintf(hid, sizeof(hid), "%.4s%04X", COREBOOT_ACPI_ID, id); |
| 261 |
acpigen_write_name_string("_HID", hid); |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
static void acpigen_emit_simple_namestring(const char *name) |
| 274 |
{ |
| 275 |
int i; |
| 276 |
char ud[] = "____"; |
| 277 |
for (i = 0; i < 4; i++) { |
| 278 |
if ((name[i] == '\0') || (name[i] == '.')) { |
| 279 |
acpigen_emit_stream(ud, 4 - i); |
| 280 |
break; |
| 281 |
} |
| 282 |
acpigen_emit_byte(name[i]); |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
static void acpigen_emit_double_namestring(const char *name, int dotpos) |
| 287 |
{ |
| 288 |
acpigen_emit_byte(DUAL_NAME_PREFIX); |
| 289 |
acpigen_emit_simple_namestring(name); |
| 290 |
acpigen_emit_simple_namestring(&name[dotpos + 1]); |
| 291 |
} |
| 292 |
|
| 293 |
static void acpigen_emit_multi_namestring(const char *name) |
| 294 |
{ |
| 295 |
int count = 0; |
| 296 |
unsigned char *pathlen; |
| 297 |
acpigen_emit_byte(MULTI_NAME_PREFIX); |
| 298 |
acpigen_emit_byte(ZERO_OP); |
| 299 |
pathlen = ((unsigned char *)acpigen_get_current()) - 1; |
| 300 |
|
| 301 |
while (name[0] != '\0') { |
| 302 |
acpigen_emit_simple_namestring(name); |
| 303 |
|
| 304 |
while ((name[0] != '.') && (name[0] != '\0')) |
| 305 |
name++; |
| 306 |
|
| 307 |
if (name[0] == '.') |
| 308 |
name++; |
| 309 |
count++; |
| 310 |
} |
| 311 |
|
| 312 |
pathlen[0] = count; |
| 313 |
} |
| 314 |
|
| 315 |
void acpigen_emit_namestring(const char *namepath) |
| 316 |
{ |
| 317 |
int dotcount = 0, i; |
| 318 |
int dotpos = 0; |
| 319 |
|
| 320 |
|
| 321 |
if (!namepath) |
| 322 |
return; |
| 323 |
|
| 324 |
|
| 325 |
if (namepath[0] == '\\') { |
| 326 |
acpigen_emit_byte('\\'); |
| 327 |
namepath++; |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
while (namepath[0] == '^') { |
| 332 |
acpigen_emit_byte('^'); |
| 333 |
namepath++; |
| 334 |
} |
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
if (namepath[0] == '\0') { |
| 339 |
acpigen_emit_byte(ZERO_OP); |
| 340 |
return; |
| 341 |
} |
| 342 |
|
| 343 |
i = 0; |
| 344 |
while (namepath[i] != '\0') { |
| 345 |
if (namepath[i] == '.') { |
| 346 |
dotcount++; |
| 347 |
dotpos = i; |
| 348 |
} |
| 349 |
i++; |
| 350 |
} |
| 351 |
|
| 352 |
if (dotcount == 0) |
| 353 |
acpigen_emit_simple_namestring(namepath); |
| 354 |
else if (dotcount == 1) |
| 355 |
acpigen_emit_double_namestring(namepath, dotpos); |
| 356 |
else |
| 357 |
acpigen_emit_multi_namestring(namepath); |
| 358 |
} |
| 359 |
|
| 360 |
void acpigen_write_name(const char *name) |
| 361 |
{ |
| 362 |
acpigen_emit_byte(NAME_OP); |
| 363 |
acpigen_emit_namestring(name); |
| 364 |
} |
| 365 |
|
| 366 |
void acpigen_write_scope(const char *name) |
| 367 |
{ |
| 368 |
acpigen_emit_byte(SCOPE_OP); |
| 369 |
acpigen_write_len_f(); |
| 370 |
acpigen_emit_namestring(name); |
| 371 |
} |
| 372 |
|
| 373 |
void acpigen_get_package_op_element(uint8_t package_op, unsigned int element, uint8_t dest_op) |
| 374 |
{ |
| 375 |
|
| 376 |
acpigen_write_store(); |
| 377 |
acpigen_emit_byte(DEREF_OP); |
| 378 |
acpigen_emit_byte(INDEX_OP); |
| 379 |
acpigen_emit_byte(package_op); |
| 380 |
acpigen_write_integer(element); |
| 381 |
acpigen_emit_byte(ZERO_OP); |
| 382 |
acpigen_emit_byte(dest_op); |
| 383 |
} |
| 384 |
|
| 385 |
void acpigen_set_package_op_element_int(uint8_t package_op, unsigned int element, uint64_t src) |
| 386 |
{ |
| 387 |
|
| 388 |
acpigen_write_store(); |
| 389 |
acpigen_write_integer(src); |
| 390 |
acpigen_emit_byte(DEREF_OP); |
| 391 |
acpigen_emit_byte(INDEX_OP); |
| 392 |
acpigen_emit_byte(package_op); |
| 393 |
acpigen_write_integer(element); |
| 394 |
acpigen_emit_byte(ZERO_OP); |
| 395 |
} |
| 396 |
|
| 397 |
void acpigen_get_package_element(const char *package, unsigned int element, uint8_t dest_op) |
| 398 |
{ |
| 399 |
|
| 400 |
acpigen_write_store(); |
| 401 |
acpigen_emit_byte(INDEX_OP); |
| 402 |
acpigen_emit_namestring(package); |
| 403 |
acpigen_write_integer(element); |
| 404 |
acpigen_emit_byte(ZERO_OP); |
| 405 |
acpigen_emit_byte(dest_op); |
| 406 |
} |
| 407 |
|
| 408 |
void acpigen_set_package_element_int(const char *package, unsigned int element, uint64_t src) |
| 409 |
{ |
| 410 |
|
| 411 |
acpigen_write_store(); |
| 412 |
acpigen_write_integer(src); |
| 413 |
acpigen_emit_byte(INDEX_OP); |
| 414 |
acpigen_emit_namestring(package); |
| 415 |
acpigen_write_integer(element); |
| 416 |
acpigen_emit_byte(ZERO_OP); |
| 417 |
} |
| 418 |
|
| 419 |
void acpigen_set_package_element_namestr(const char *package, unsigned int element, |
| 420 |
const char *src) |
| 421 |
{ |
| 422 |
|
| 423 |
acpigen_write_store(); |
| 424 |
acpigen_emit_namestring(src); |
| 425 |
acpigen_emit_byte(INDEX_OP); |
| 426 |
acpigen_emit_namestring(package); |
| 427 |
acpigen_write_integer(element); |
| 428 |
acpigen_emit_byte(ZERO_OP); |
| 429 |
} |
| 430 |
|
| 431 |
void acpigen_write_processor_namestring(unsigned int cpu_index) |
| 432 |
{ |
| 433 |
char buffer[16]; |
| 434 |
snprintf(buffer, sizeof(buffer), "\\_SB." CONFIG_ACPI_CPU_STRING, cpu_index); |
| 435 |
acpigen_emit_namestring(buffer); |
| 436 |
} |
| 437 |
|
| 438 |
|
| 439 |
void acpigen_write_processor(u8 cpuindex, u32 pblock_addr, u8 pblock_len) |
| 440 |
{ |
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
acpigen_emit_ext_op(PROCESSOR_OP); |
| 446 |
acpigen_write_len_f(); |
| 447 |
acpigen_write_processor_namestring(cpuindex); |
| 448 |
acpigen_emit_byte(cpuindex); |
| 449 |
acpigen_emit_dword(pblock_addr); |
| 450 |
acpigen_emit_byte(pblock_len); |
| 451 |
} |
| 452 |
|
| 453 |
void acpigen_write_processor_device(unsigned int cpu_index) |
| 454 |
{ |
| 455 |
acpigen_emit_ext_op(DEVICE_OP); |
| 456 |
acpigen_write_len_f(); |
| 457 |
acpigen_write_processor_namestring(cpu_index); |
| 458 |
acpigen_write_name_string("_HID", "ACPI0007"); |
| 459 |
acpigen_write_name_integer("_UID", cpu_index); |
| 460 |
} |
| 461 |
|
| 462 |
void acpigen_write_processor_package(const char *const name, const unsigned int first_core, |
| 463 |
const unsigned int core_count) |
| 464 |
{ |
| 465 |
unsigned int i; |
| 466 |
|
| 467 |
acpigen_write_name(name); |
| 468 |
acpigen_write_package(core_count); |
| 469 |
|
| 470 |
for (i = first_core; i < first_core + core_count; ++i) |
| 471 |
acpigen_write_processor_namestring(i); |
| 472 |
|
| 473 |
acpigen_pop_len(); |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
void acpigen_write_processor_cnot(const unsigned int number_of_cores) |
| 478 |
{ |
| 479 |
int core_id; |
| 480 |
|
| 481 |
acpigen_write_method("\\_SB.CNOT", 1); |
| 482 |
for (core_id = 0; core_id < number_of_cores; core_id++) { |
| 483 |
acpigen_emit_byte(NOTIFY_OP); |
| 484 |
acpigen_write_processor_namestring(core_id); |
| 485 |
acpigen_emit_byte(ARG0_OP); |
| 486 |
} |
| 487 |
acpigen_pop_len(); |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
void acpigen_write_opregion(const struct opregion *opreg) |
| 498 |
{ |
| 499 |
|
| 500 |
acpigen_emit_ext_op(OPREGION_OP); |
| 501 |
|
| 502 |
acpigen_emit_simple_namestring(opreg->name); |
| 503 |
|
| 504 |
acpigen_emit_byte(opreg->regionspace); |
| 505 |
|
| 506 |
acpigen_write_integer(opreg->regionoffset); |
| 507 |
acpigen_write_integer(opreg->regionlen); |
| 508 |
} |
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
void acpigen_write_mutex(const char *name, const uint8_t flags) |
| 516 |
{ |
| 517 |
|
| 518 |
acpigen_emit_ext_op(MUTEX_OP); |
| 519 |
acpigen_emit_namestring(name); |
| 520 |
acpigen_emit_byte(flags); |
| 521 |
} |
| 522 |
|
| 523 |
void acpigen_write_acquire(const char *name, const uint16_t val) |
| 524 |
{ |
| 525 |
|
| 526 |
acpigen_emit_ext_op(ACQUIRE_OP); |
| 527 |
acpigen_emit_namestring(name); |
| 528 |
acpigen_emit_word(val); |
| 529 |
} |
| 530 |
|
| 531 |
void acpigen_write_release(const char *name) |
| 532 |
{ |
| 533 |
|
| 534 |
acpigen_emit_ext_op(RELEASE_OP); |
| 535 |
acpigen_emit_namestring(name); |
| 536 |
} |
| 537 |
|
| 538 |
static void acpigen_write_field_length(uint32_t len) |
| 539 |
{ |
| 540 |
uint8_t i, j; |
| 541 |
uint8_t emit[4]; |
| 542 |
|
| 543 |
i = 1; |
| 544 |
if (len < 0x40) { |
| 545 |
emit[0] = len & 0x3F; |
| 546 |
} else { |
| 547 |
emit[0] = len & 0xF; |
| 548 |
len >>= 4; |
| 549 |
while (len) { |
| 550 |
emit[i] = len & 0xFF; |
| 551 |
i++; |
| 552 |
len >>= 8; |
| 553 |
} |
| 554 |
} |
| 555 |
|
| 556 |
emit[0] |= (i - 1) << 6; |
| 557 |
|
| 558 |
for (j = 0; j < i; j++) |
| 559 |
acpigen_emit_byte(emit[j]); |
| 560 |
} |
| 561 |
|
| 562 |
static void acpigen_write_field_offset(uint32_t offset, uint32_t current_bit_pos) |
| 563 |
{ |
| 564 |
uint32_t diff_bits; |
| 565 |
|
| 566 |
if (offset < current_bit_pos) { |
| 567 |
printk(BIOS_WARNING, "%s: Cannot move offset backward", __func__); |
| 568 |
return; |
| 569 |
} |
| 570 |
|
| 571 |
diff_bits = offset - current_bit_pos; |
| 572 |
|
| 573 |
if (diff_bits > 0xFFFFFFF) { |
| 574 |
printk(BIOS_WARNING, "%s: Offset very large to encode", __func__); |
| 575 |
return; |
| 576 |
} |
| 577 |
|
| 578 |
acpigen_emit_byte(0); |
| 579 |
acpigen_write_field_length(diff_bits); |
| 580 |
} |
| 581 |
|
| 582 |
void acpigen_write_field_name(const char *name, uint32_t size) |
| 583 |
{ |
| 584 |
acpigen_emit_simple_namestring(name); |
| 585 |
acpigen_write_field_length(size); |
| 586 |
} |
| 587 |
|
| 588 |
static void acpigen_write_field_reserved(uint32_t size) |
| 589 |
{ |
| 590 |
acpigen_emit_byte(0); |
| 591 |
acpigen_write_field_length(size); |
| 592 |
} |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
void acpigen_write_field(const char *name, const struct fieldlist *l, size_t count, |
| 617 |
uint8_t flags) |
| 618 |
{ |
| 619 |
uint16_t i; |
| 620 |
uint32_t current_bit_pos = 0; |
| 621 |
|
| 622 |
|
| 623 |
acpigen_emit_ext_op(FIELD_OP); |
| 624 |
|
| 625 |
acpigen_write_len_f(); |
| 626 |
|
| 627 |
acpigen_emit_simple_namestring(name); |
| 628 |
|
| 629 |
acpigen_emit_byte(flags); |
| 630 |
|
| 631 |
for (i = 0; i < count; i++) { |
| 632 |
switch (l[i].type) { |
| 633 |
case NAME_STRING: |
| 634 |
acpigen_write_field_name(l[i].name, l[i].bits); |
| 635 |
current_bit_pos += l[i].bits; |
| 636 |
break; |
| 637 |
case RESERVED: |
| 638 |
acpigen_write_field_reserved(l[i].bits); |
| 639 |
current_bit_pos += l[i].bits; |
| 640 |
break; |
| 641 |
case OFFSET: |
| 642 |
acpigen_write_field_offset(l[i].bits, current_bit_pos); |
| 643 |
current_bit_pos = l[i].bits; |
| 644 |
break; |
| 645 |
default: |
| 646 |
printk(BIOS_ERR, "%s: Invalid field type 0x%X\n", __func__, l[i].type); |
| 647 |
break; |
| 648 |
} |
| 649 |
} |
| 650 |
acpigen_pop_len(); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
void acpigen_write_indexfield(const char *idx, const char *data, struct fieldlist *l, |
| 675 |
size_t count, uint8_t flags) |
| 676 |
{ |
| 677 |
uint16_t i; |
| 678 |
uint32_t current_bit_pos = 0; |
| 679 |
|
| 680 |
|
| 681 |
acpigen_emit_ext_op(INDEX_FIELD_OP); |
| 682 |
|
| 683 |
acpigen_write_len_f(); |
| 684 |
|
| 685 |
acpigen_emit_simple_namestring(idx); |
| 686 |
|
| 687 |
acpigen_emit_simple_namestring(data); |
| 688 |
|
| 689 |
acpigen_emit_byte(flags); |
| 690 |
|
| 691 |
for (i = 0; i < count; i++) { |
| 692 |
switch (l[i].type) { |
| 693 |
case NAME_STRING: |
| 694 |
acpigen_write_field_name(l[i].name, l[i].bits); |
| 695 |
current_bit_pos += l[i].bits; |
| 696 |
break; |
| 697 |
case OFFSET: |
| 698 |
acpigen_write_field_offset(l[i].bits, current_bit_pos); |
| 699 |
current_bit_pos = l[i].bits; |
| 700 |
break; |
| 701 |
default: |
| 702 |
printk(BIOS_ERR, "%s: Invalid field type 0x%X\n", __func__, l[i].type); |
| 703 |
break; |
| 704 |
} |
| 705 |
} |
| 706 |
acpigen_pop_len(); |
| 707 |
} |
| 708 |
|
| 709 |
void acpigen_write_empty_PCT(void) |
| 710 |
{ |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
static char stream[] = { |
| 734 |
|
| 735 |
0x08, 0x5F, 0x50, 0x43, 0x54, 0x12, 0x2C, |
| 736 |
|
| 737 |
0x02, 0x11, 0x14, 0x0A, 0x11, 0x82, 0x0C, 0x00, |
| 738 |
|
| 739 |
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 740 |
|
| 741 |
0x00, 0x00, 0x00, 0x00, 0x79, 0x00, 0x11, 0x14, |
| 742 |
|
| 743 |
0x0A, 0x11, 0x82, 0x0C, 0x00, 0x7F, 0x00, 0x00, |
| 744 |
|
| 745 |
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 746 |
0x00, 0x79, 0x00 |
| 747 |
}; |
| 748 |
acpigen_emit_stream(stream, ARRAY_SIZE(stream)); |
| 749 |
} |
| 750 |
|
| 751 |
void acpigen_write_PTC(uint8_t duty_width, uint8_t duty_offset, uint16_t p_cnt) |
| 752 |
{ |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
acpi_addr_t addr = { |
| 776 |
.bit_width = duty_width, |
| 777 |
.bit_offset = duty_offset, |
| 778 |
.access_size = ACPI_ACCESS_SIZE_UNDEFINED, |
| 779 |
.addrl = p_cnt, |
| 780 |
.addrh = 0, |
| 781 |
}; |
| 782 |
|
| 783 |
if (addr.addrl != 0) |
| 784 |
addr.space_id = ACPI_ADDRESS_SPACE_IO; |
| 785 |
else |
| 786 |
addr.space_id = ACPI_ADDRESS_SPACE_FIXED; |
| 787 |
|
| 788 |
acpigen_write_name("_PTC"); |
| 789 |
acpigen_write_package(2); |
| 790 |
|
| 791 |
|
| 792 |
acpigen_write_register_resource(&addr); |
| 793 |
|
| 794 |
|
| 795 |
acpigen_write_register_resource(&addr); |
| 796 |
|
| 797 |
acpigen_pop_len(); |
| 798 |
} |
| 799 |
|
| 800 |
void acpigen_write_empty_PTC(void) |
| 801 |
{ |
| 802 |
acpigen_write_PTC(0, 0, 0); |
| 803 |
} |
| 804 |
|
| 805 |
static void __acpigen_write_method(const char *name, uint8_t flags) |
| 806 |
{ |
| 807 |
acpigen_emit_byte(METHOD_OP); |
| 808 |
acpigen_write_len_f(); |
| 809 |
acpigen_emit_namestring(name); |
| 810 |
acpigen_emit_byte(flags); |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
void acpigen_write_method(const char *name, int nargs) |
| 815 |
{ |
| 816 |
__acpigen_write_method(name, (nargs & 7)); |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
void acpigen_write_method_serialized(const char *name, int nargs) |
| 821 |
{ |
| 822 |
__acpigen_write_method(name, (nargs & 7) | (1 << 3)); |
| 823 |
} |
| 824 |
|
| 825 |
void acpigen_write_device(const char *name) |
| 826 |
{ |
| 827 |
acpigen_emit_ext_op(DEVICE_OP); |
| 828 |
acpigen_write_len_f(); |
| 829 |
acpigen_emit_namestring(name); |
| 830 |
} |
| 831 |
|
| 832 |
void acpigen_write_thermal_zone(const char *name) |
| 833 |
{ |
| 834 |
acpigen_emit_ext_op(THERMAL_ZONE_OP); |
| 835 |
acpigen_write_len_f(); |
| 836 |
acpigen_emit_namestring(name); |
| 837 |
} |
| 838 |
|
| 839 |
void acpigen_write_STA(uint8_t status) |
| 840 |
{ |
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
acpigen_write_method("_STA", 0); |
| 845 |
acpigen_emit_byte(RETURN_OP); |
| 846 |
acpigen_write_byte(status); |
| 847 |
acpigen_pop_len(); |
| 848 |
} |
| 849 |
|
| 850 |
void acpigen_write_STA_ext(const char *namestring) |
| 851 |
{ |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
acpigen_write_method("_STA", 0); |
| 856 |
acpigen_emit_byte(RETURN_OP); |
| 857 |
acpigen_emit_namestring(namestring); |
| 858 |
acpigen_pop_len(); |
| 859 |
} |
| 860 |
|
| 861 |
void acpigen_write_BBN(uint8_t base_bus_number) |
| 862 |
{ |
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
acpigen_write_method("_BBN", 0); |
| 867 |
acpigen_emit_byte(RETURN_OP); |
| 868 |
acpigen_write_byte(base_bus_number); |
| 869 |
acpigen_pop_len(); |
| 870 |
} |
| 871 |
|
| 872 |
void acpigen_write_SEG(uint8_t segment_group_number) |
| 873 |
{ |
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
acpigen_write_method("_SEG", 0); |
| 878 |
acpigen_emit_byte(RETURN_OP); |
| 879 |
acpigen_write_byte(segment_group_number); |
| 880 |
acpigen_pop_len(); |
| 881 |
} |
| 882 |
|
| 883 |
void acpigen_write_LPI_package(u64 level, const struct acpi_lpi_state *states, u16 nentries) |
| 884 |
{ |
| 885 |
|
| 886 |
|
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
acpigen_write_name("_LPI"); |
| 933 |
acpigen_write_package(3 + nentries); |
| 934 |
acpigen_write_word(0); |
| 935 |
acpigen_write_qword(level); |
| 936 |
acpigen_write_word(nentries); |
| 937 |
|
| 938 |
for (size_t i = 0; i < nentries; i++, states++) { |
| 939 |
acpigen_write_package(0xA); |
| 940 |
acpigen_write_dword(states->min_residency_us); |
| 941 |
acpigen_write_dword(states->worst_case_wakeup_latency_us); |
| 942 |
acpigen_write_dword(states->flags); |
| 943 |
acpigen_write_dword(states->arch_context_lost_flags); |
| 944 |
acpigen_write_dword(states->residency_counter_frequency_hz); |
| 945 |
acpigen_write_dword(states->enabled_parent_state); |
| 946 |
acpigen_write_register_resource(&states->entry_method); |
| 947 |
acpigen_write_register_resource(&states->residency_counter_register); |
| 948 |
acpigen_write_register_resource(&states->usage_counter_register); |
| 949 |
acpigen_write_string(states->state_name); |
| 950 |
acpigen_pop_len(); |
| 951 |
} |
| 952 |
acpigen_pop_len(); |
| 953 |
} |
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
void acpigen_write_PPC(u8 nr) |
| 959 |
{ |
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
acpigen_write_method("_PPC", 0); |
| 967 |
acpigen_emit_byte(RETURN_OP); |
| 968 |
|
| 969 |
acpigen_write_byte(nr); |
| 970 |
acpigen_pop_len(); |
| 971 |
} |
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
void acpigen_write_PPC_NVS(void) |
| 978 |
{ |
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
acpigen_write_method("_PPC", 0); |
| 986 |
acpigen_emit_byte(RETURN_OP); |
| 987 |
|
| 988 |
acpigen_emit_namestring("PPCM"); |
| 989 |
acpigen_pop_len(); |
| 990 |
} |
| 991 |
|
| 992 |
void acpigen_write_TPC(const char *gnvs_tpc_limit) |
| 993 |
{ |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
acpigen_write_method("_TPC", 0); |
| 1002 |
acpigen_emit_byte(RETURN_OP); |
| 1003 |
acpigen_emit_namestring(gnvs_tpc_limit); |
| 1004 |
acpigen_pop_len(); |
| 1005 |
} |
| 1006 |
|
| 1007 |
void acpigen_write_PRW(u32 wake, u32 level) |
| 1008 |
{ |
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
acpigen_write_name("_PRW"); |
| 1013 |
acpigen_write_package(2); |
| 1014 |
acpigen_write_integer(wake); |
| 1015 |
acpigen_write_integer(level); |
| 1016 |
acpigen_pop_len(); |
| 1017 |
} |
| 1018 |
|
| 1019 |
void acpigen_write_PSS_package(u32 coreFreq, u32 power, u32 transLat, u32 busmLat, u32 control, |
| 1020 |
u32 status) |
| 1021 |
{ |
| 1022 |
acpigen_write_package(6); |
| 1023 |
acpigen_write_dword(coreFreq); |
| 1024 |
acpigen_write_dword(power); |
| 1025 |
acpigen_write_dword(transLat); |
| 1026 |
acpigen_write_dword(busmLat); |
| 1027 |
acpigen_write_dword(control); |
| 1028 |
acpigen_write_dword(status); |
| 1029 |
acpigen_pop_len(); |
| 1030 |
|
| 1031 |
printk(BIOS_DEBUG, "PSS: %uMHz power %u control 0x%x status 0x%x\n", coreFreq, power, |
| 1032 |
control, status); |
| 1033 |
} |
| 1034 |
|
| 1035 |
void acpigen_write_pss_object(const struct acpi_sw_pstate *pstate_values, size_t nentries) |
| 1036 |
{ |
| 1037 |
size_t pstate; |
| 1038 |
|
| 1039 |
acpigen_write_name("_PSS"); |
| 1040 |
acpigen_write_package(nentries); |
| 1041 |
for (pstate = 0; pstate < nentries; pstate++) { |
| 1042 |
acpigen_write_PSS_package( |
| 1043 |
pstate_values->core_freq, pstate_values->power, |
| 1044 |
pstate_values->transition_latency, pstate_values->bus_master_latency, |
| 1045 |
pstate_values->control_value, pstate_values->status_value); |
| 1046 |
pstate_values++; |
| 1047 |
} |
| 1048 |
|
| 1049 |
acpigen_pop_len(); |
| 1050 |
} |
| 1051 |
|
| 1052 |
void acpigen_write_PSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
| 1053 |
{ |
| 1054 |
acpigen_write_name("_PSD"); |
| 1055 |
acpigen_write_package(1); |
| 1056 |
acpigen_write_package(5); |
| 1057 |
acpigen_write_byte(5); |
| 1058 |
acpigen_write_byte(0); |
| 1059 |
acpigen_write_dword(domain); |
| 1060 |
acpigen_write_dword(coordtype); |
| 1061 |
acpigen_write_dword(numprocs); |
| 1062 |
acpigen_pop_len(); |
| 1063 |
acpigen_pop_len(); |
| 1064 |
} |
| 1065 |
|
| 1066 |
void acpigen_write_CST_package_entry(const acpi_cstate_t *cstate) |
| 1067 |
{ |
| 1068 |
acpigen_write_package(4); |
| 1069 |
acpigen_write_register_resource(&cstate->resource); |
| 1070 |
acpigen_write_byte(cstate->ctype); |
| 1071 |
acpigen_write_word(cstate->latency); |
| 1072 |
acpigen_write_dword(cstate->power); |
| 1073 |
acpigen_pop_len(); |
| 1074 |
} |
| 1075 |
|
| 1076 |
void acpigen_write_CST_package(const acpi_cstate_t *cstate, int nentries) |
| 1077 |
{ |
| 1078 |
int i; |
| 1079 |
acpigen_write_name("_CST"); |
| 1080 |
acpigen_write_package(nentries+1); |
| 1081 |
acpigen_write_integer(nentries); |
| 1082 |
|
| 1083 |
for (i = 0; i < nentries; i++) |
| 1084 |
acpigen_write_CST_package_entry(cstate + i); |
| 1085 |
|
| 1086 |
acpigen_pop_len(); |
| 1087 |
} |
| 1088 |
|
| 1089 |
void acpigen_write_CSD_package(u32 domain, u32 numprocs, CSD_coord coordtype, |
| 1090 |
u32 index) |
| 1091 |
{ |
| 1092 |
acpigen_write_name("_CSD"); |
| 1093 |
acpigen_write_package(1); |
| 1094 |
acpigen_write_package(6); |
| 1095 |
acpigen_write_integer(6); |
| 1096 |
acpigen_write_byte(0); |
| 1097 |
acpigen_write_dword(domain); |
| 1098 |
acpigen_write_dword(coordtype); |
| 1099 |
acpigen_write_dword(numprocs); |
| 1100 |
acpigen_write_dword(index); |
| 1101 |
acpigen_pop_len(); |
| 1102 |
acpigen_pop_len(); |
| 1103 |
} |
| 1104 |
|
| 1105 |
void acpigen_write_TSS_package(int entries, acpi_tstate_t *tstate_list) |
| 1106 |
{ |
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
int i; |
| 1116 |
acpi_tstate_t *tstate = tstate_list; |
| 1117 |
|
| 1118 |
acpigen_write_name("_TSS"); |
| 1119 |
acpigen_write_package(entries); |
| 1120 |
|
| 1121 |
for (i = 0; i < entries; i++) { |
| 1122 |
acpigen_write_package(5); |
| 1123 |
acpigen_write_dword(tstate->percent); |
| 1124 |
acpigen_write_dword(tstate->power); |
| 1125 |
acpigen_write_dword(tstate->latency); |
| 1126 |
acpigen_write_dword(tstate->control); |
| 1127 |
acpigen_write_dword(tstate->status); |
| 1128 |
acpigen_pop_len(); |
| 1129 |
tstate++; |
| 1130 |
} |
| 1131 |
|
| 1132 |
acpigen_pop_len(); |
| 1133 |
} |
| 1134 |
|
| 1135 |
void acpigen_write_TSD_package(u32 domain, u32 numprocs, PSD_coord coordtype) |
| 1136 |
{ |
| 1137 |
acpigen_write_name("_TSD"); |
| 1138 |
acpigen_write_package(1); |
| 1139 |
acpigen_write_package(5); |
| 1140 |
acpigen_write_byte(5); |
| 1141 |
acpigen_write_byte(0); |
| 1142 |
acpigen_write_dword(domain); |
| 1143 |
acpigen_write_dword(coordtype); |
| 1144 |
acpigen_write_dword(numprocs); |
| 1145 |
acpigen_pop_len(); |
| 1146 |
acpigen_pop_len(); |
| 1147 |
} |
| 1148 |
|
| 1149 |
void acpigen_write_mem32fixed(int readwrite, u32 base, u32 size) |
| 1150 |
{ |
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
acpigen_emit_byte(0x86); |
| 1158 |
|
| 1159 |
acpigen_emit_byte(0x09); |
| 1160 |
acpigen_emit_byte(0x00); |
| 1161 |
|
| 1162 |
acpigen_emit_byte(readwrite ? 0x01 : 0x00); |
| 1163 |
acpigen_emit_dword(base); |
| 1164 |
acpigen_emit_dword(size); |
| 1165 |
} |
| 1166 |
|
| 1167 |
static void acpigen_write_register(const acpi_addr_t *addr) |
| 1168 |
{ |
| 1169 |
acpigen_emit_byte(0x82); |
| 1170 |
acpigen_emit_byte(0x0c); |
| 1171 |
acpigen_emit_byte(0x00); |
| 1172 |
acpigen_emit_byte(addr->space_id); |
| 1173 |
acpigen_emit_byte(addr->bit_width); |
| 1174 |
acpigen_emit_byte(addr->bit_offset); |
| 1175 |
acpigen_emit_byte(addr->access_size); |
| 1176 |
acpigen_emit_dword(addr->addrl); |
| 1177 |
acpigen_emit_dword(addr->addrh); |
| 1178 |
} |
| 1179 |
|
| 1180 |
void acpigen_write_register_resource(const acpi_addr_t *addr) |
| 1181 |
{ |
| 1182 |
acpigen_write_resourcetemplate_header(); |
| 1183 |
acpigen_write_register(addr); |
| 1184 |
acpigen_write_resourcetemplate_footer(); |
| 1185 |
} |
| 1186 |
|
| 1187 |
void acpigen_write_irq(u16 mask) |
| 1188 |
{ |
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
acpigen_emit_byte(0x22); |
| 1197 |
acpigen_emit_byte(mask & 0xff); |
| 1198 |
acpigen_emit_byte((mask >> 8) & 0xff); |
| 1199 |
} |
| 1200 |
|
| 1201 |
void acpigen_write_io16(u16 min, u16 max, u8 align, u8 len, u8 decode16) |
| 1202 |
{ |
| 1203 |
|
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
acpigen_emit_byte(0x47); |
| 1211 |
|
| 1212 |
|
| 1213 |
acpigen_emit_byte(decode16 ? 0x01 : 0x00); |
| 1214 |
|
| 1215 |
acpigen_emit_byte(min & 0xff); |
| 1216 |
acpigen_emit_byte((min >> 8) & 0xff); |
| 1217 |
|
| 1218 |
acpigen_emit_byte(max & 0xff); |
| 1219 |
acpigen_emit_byte((max >> 8) & 0xff); |
| 1220 |
|
| 1221 |
acpigen_emit_byte(align & 0xff); |
| 1222 |
acpigen_emit_byte(len & 0xff); |
| 1223 |
} |
| 1224 |
|
| 1225 |
void acpigen_write_resourcetemplate_header(void) |
| 1226 |
{ |
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
acpigen_emit_byte(BUFFER_OP); |
| 1234 |
acpigen_write_len_f(); |
| 1235 |
acpigen_emit_byte(WORD_PREFIX); |
| 1236 |
len_stack[ltop++] = acpigen_get_current(); |
| 1237 |
|
| 1238 |
|
| 1239 |
acpigen_emit_byte(0x00); |
| 1240 |
acpigen_emit_byte(0x00); |
| 1241 |
} |
| 1242 |
|
| 1243 |
void acpigen_write_resourcetemplate_footer(void) |
| 1244 |
{ |
| 1245 |
char *p = len_stack[--ltop]; |
| 1246 |
int len; |
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
acpigen_emit_byte(0x79); |
| 1254 |
acpigen_emit_byte(0x00); |
| 1255 |
|
| 1256 |
|
| 1257 |
|
| 1258 |
len = acpigen_get_current() - (p + 2); |
| 1259 |
|
| 1260 |
|
| 1261 |
p[0] = len & 0xff; |
| 1262 |
p[1] = (len >> 8) & 0xff; |
| 1263 |
|
| 1264 |
acpigen_pop_len(); |
| 1265 |
} |
| 1266 |
|
| 1267 |
static void acpigen_add_mainboard_rsvd_mem32(void *gp, struct device *dev, struct resource *res) |
| 1268 |
{ |
| 1269 |
acpigen_write_mem32fixed(0, res->base, res->size); |
| 1270 |
} |
| 1271 |
|
| 1272 |
static void acpigen_add_mainboard_rsvd_io(void *gp, struct device *dev, struct resource *res) |
| 1273 |
{ |
| 1274 |
resource_t base = res->base; |
| 1275 |
resource_t size = res->size; |
| 1276 |
while (size > 0) { |
| 1277 |
resource_t sz = size > 255 ? 255 : size; |
| 1278 |
acpigen_write_io16(base, base, 0, sz, 1); |
| 1279 |
size -= sz; |
| 1280 |
base += sz; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
|
| 1284 |
void acpigen_write_mainboard_resource_template(void) |
| 1285 |
{ |
| 1286 |
acpigen_write_resourcetemplate_header(); |
| 1287 |
|
| 1288 |
|
| 1289 |
search_global_resources( |
| 1290 |
IORESOURCE_MEM | IORESOURCE_RESERVE, |
| 1291 |
IORESOURCE_MEM | IORESOURCE_RESERVE, |
| 1292 |
acpigen_add_mainboard_rsvd_mem32, 0); |
| 1293 |
|
| 1294 |
|
| 1295 |
search_global_resources( |
| 1296 |
IORESOURCE_IO | IORESOURCE_RESERVE, |
| 1297 |
IORESOURCE_IO | IORESOURCE_RESERVE, |
| 1298 |
acpigen_add_mainboard_rsvd_io, 0); |
| 1299 |
|
| 1300 |
acpigen_write_resourcetemplate_footer(); |
| 1301 |
} |
| 1302 |
|
| 1303 |
void acpigen_write_mainboard_resources(const char *scope, const char *name) |
| 1304 |
{ |
| 1305 |
acpigen_write_scope(scope); |
| 1306 |
acpigen_write_name(name); |
| 1307 |
acpigen_write_mainboard_resource_template(); |
| 1308 |
acpigen_pop_len(); |
| 1309 |
} |
| 1310 |
|
| 1311 |
static int hex2bin(const char c) |
| 1312 |
{ |
| 1313 |
if (c >= 'A' && c <= 'F') |
| 1314 |
return c - 'A' + 10; |
| 1315 |
if (c >= 'a' && c <= 'f') |
| 1316 |
return c - 'a' + 10; |
| 1317 |
return c - '0'; |
| 1318 |
} |
| 1319 |
|
| 1320 |
void acpigen_emit_eisaid(const char *eisaid) |
| 1321 |
{ |
| 1322 |
u32 compact = 0; |
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
compact |= (eisaid[0] - 'A' + 1) << 26; |
| 1330 |
compact |= (eisaid[1] - 'A' + 1) << 21; |
| 1331 |
compact |= (eisaid[2] - 'A' + 1) << 16; |
| 1332 |
compact |= hex2bin(eisaid[3]) << 12; |
| 1333 |
compact |= hex2bin(eisaid[4]) << 8; |
| 1334 |
compact |= hex2bin(eisaid[5]) << 4; |
| 1335 |
compact |= hex2bin(eisaid[6]); |
| 1336 |
|
| 1337 |
acpigen_emit_byte(0xc); |
| 1338 |
acpigen_emit_byte((compact >> 24) & 0xff); |
| 1339 |
acpigen_emit_byte((compact >> 16) & 0xff); |
| 1340 |
acpigen_emit_byte((compact >> 8) & 0xff); |
| 1341 |
acpigen_emit_byte(compact & 0xff); |
| 1342 |
} |
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
#define UUID_LEN 16 |
| 1355 |
void acpigen_write_uuid(const char *uuid) |
| 1356 |
{ |
| 1357 |
uint8_t buf[UUID_LEN]; |
| 1358 |
size_t i, order[UUID_LEN] = { 3, 2, 1, 0, 5, 4, 7, 6, |
| 1359 |
8, 9, 10, 11, 12, 13, 14, 15 }; |
| 1360 |
|
| 1361 |
|
| 1362 |
if (hexstrtobin(uuid, buf, UUID_LEN) < UUID_LEN) |
| 1363 |
return; |
| 1364 |
|
| 1365 |
|
| 1366 |
acpigen_emit_byte(BUFFER_OP); |
| 1367 |
acpigen_write_len_f(); |
| 1368 |
|
| 1369 |
|
| 1370 |
acpigen_write_word(UUID_LEN); |
| 1371 |
|
| 1372 |
|
| 1373 |
for (i = 0; i < UUID_LEN; i++) |
| 1374 |
acpigen_emit_byte(buf[order[i]]); |
| 1375 |
|
| 1376 |
acpigen_pop_len(); |
| 1377 |
} |
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
void acpigen_write_power_res(const char *name, uint8_t level, uint16_t order, |
| 1385 |
const char * const dev_states[], size_t dev_states_count) |
| 1386 |
{ |
| 1387 |
size_t i; |
| 1388 |
for (i = 0; i < dev_states_count; i++) { |
| 1389 |
acpigen_write_name(dev_states[i]); |
| 1390 |
acpigen_write_package(1); |
| 1391 |
acpigen_emit_simple_namestring(name); |
| 1392 |
acpigen_pop_len(); |
| 1393 |
} |
| 1394 |
|
| 1395 |
acpigen_emit_ext_op(POWER_RES_OP); |
| 1396 |
|
| 1397 |
acpigen_write_len_f(); |
| 1398 |
|
| 1399 |
acpigen_emit_simple_namestring(name); |
| 1400 |
acpigen_emit_byte(level); |
| 1401 |
acpigen_emit_word(order); |
| 1402 |
} |
| 1403 |
|
| 1404 |
|
| 1405 |
void acpigen_write_sleep(uint64_t sleep_ms) |
| 1406 |
{ |
| 1407 |
acpigen_emit_ext_op(SLEEP_OP); |
| 1408 |
acpigen_write_integer(sleep_ms); |
| 1409 |
} |
| 1410 |
|
| 1411 |
void acpigen_write_store(void) |
| 1412 |
{ |
| 1413 |
acpigen_emit_byte(STORE_OP); |
| 1414 |
} |
| 1415 |
|
| 1416 |
|
| 1417 |
void acpigen_write_store_ops(uint8_t src, uint8_t dst) |
| 1418 |
{ |
| 1419 |
acpigen_write_store(); |
| 1420 |
acpigen_emit_byte(src); |
| 1421 |
acpigen_emit_byte(dst); |
| 1422 |
} |
| 1423 |
|
| 1424 |
|
| 1425 |
void acpigen_write_store_op_to_namestr(uint8_t src, const char *dst) |
| 1426 |
{ |
| 1427 |
acpigen_write_store(); |
| 1428 |
acpigen_emit_byte(src); |
| 1429 |
acpigen_emit_namestring(dst); |
| 1430 |
} |
| 1431 |
|
| 1432 |
|
| 1433 |
void acpigen_write_store_int_to_namestr(uint64_t src, const char *dst) |
| 1434 |
{ |
| 1435 |
acpigen_write_store(); |
| 1436 |
acpigen_write_integer(src); |
| 1437 |
acpigen_emit_namestring(dst); |
| 1438 |
} |
| 1439 |
|
| 1440 |
|
| 1441 |
void acpigen_write_store_namestr_to_op(const char *src, uint8_t dst) |
| 1442 |
{ |
| 1443 |
acpigen_write_store(); |
| 1444 |
acpigen_emit_namestring(src); |
| 1445 |
acpigen_emit_byte(dst); |
| 1446 |
} |
| 1447 |
|
| 1448 |
|
| 1449 |
void acpigen_write_store_int_to_op(uint64_t src, uint8_t dst) |
| 1450 |
{ |
| 1451 |
acpigen_write_store(); |
| 1452 |
acpigen_write_integer(src); |
| 1453 |
acpigen_emit_byte(dst); |
| 1454 |
} |
| 1455 |
|
| 1456 |
|
| 1457 |
void acpigen_write_store_namestr_to_namestr(const char *src, const char *dst) |
| 1458 |
{ |
| 1459 |
acpigen_write_store(); |
| 1460 |
acpigen_emit_namestring(src); |
| 1461 |
acpigen_emit_namestring(dst); |
| 1462 |
} |
| 1463 |
|
| 1464 |
|
| 1465 |
void acpigen_write_or(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 1466 |
{ |
| 1467 |
acpigen_emit_byte(OR_OP); |
| 1468 |
acpigen_emit_byte(arg1); |
| 1469 |
acpigen_emit_byte(arg2); |
| 1470 |
acpigen_emit_byte(res); |
| 1471 |
} |
| 1472 |
|
| 1473 |
|
| 1474 |
void acpigen_write_xor(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 1475 |
{ |
| 1476 |
acpigen_emit_byte(XOR_OP); |
| 1477 |
acpigen_emit_byte(arg1); |
| 1478 |
acpigen_emit_byte(arg2); |
| 1479 |
acpigen_emit_byte(res); |
| 1480 |
} |
| 1481 |
|
| 1482 |
|
| 1483 |
void acpigen_write_and(uint8_t arg1, uint8_t arg2, uint8_t res) |
| 1484 |
{ |
| 1485 |
acpigen_emit_byte(AND_OP); |
| 1486 |
acpigen_emit_byte(arg1); |
| 1487 |
acpigen_emit_byte(arg2); |
| 1488 |
acpigen_emit_byte(res); |
| 1489 |
} |
| 1490 |
|
| 1491 |
|
| 1492 |
void acpigen_write_not(uint8_t arg, uint8_t res) |
| 1493 |
{ |
| 1494 |
acpigen_emit_byte(NOT_OP); |
| 1495 |
acpigen_emit_byte(arg); |
| 1496 |
acpigen_emit_byte(res); |
| 1497 |
} |
| 1498 |
|
| 1499 |
|
| 1500 |
void acpigen_concatenate_string_op(const char *str, uint8_t src_res, uint8_t dest_res) |
| 1501 |
{ |
| 1502 |
acpigen_emit_byte(CONCATENATE_OP); |
| 1503 |
acpigen_write_string(str); |
| 1504 |
acpigen_emit_byte(src_res); |
| 1505 |
acpigen_emit_byte(dest_res); |
| 1506 |
} |
| 1507 |
|
| 1508 |
|
| 1509 |
void acpigen_write_debug_string(const char *str) |
| 1510 |
{ |
| 1511 |
acpigen_write_store(); |
| 1512 |
acpigen_write_string(str); |
| 1513 |
acpigen_emit_ext_op(DEBUG_OP); |
| 1514 |
} |
| 1515 |
|
| 1516 |
|
| 1517 |
void acpigen_write_debug_integer(uint64_t val) |
| 1518 |
{ |
| 1519 |
acpigen_write_store(); |
| 1520 |
acpigen_write_integer(val); |
| 1521 |
acpigen_emit_ext_op(DEBUG_OP); |
| 1522 |
} |
| 1523 |
|
| 1524 |
|
| 1525 |
void acpigen_write_debug_op(uint8_t op) |
| 1526 |
{ |
| 1527 |
acpigen_write_store(); |
| 1528 |
acpigen_emit_byte(op); |
| 1529 |
acpigen_emit_ext_op(DEBUG_OP); |
| 1530 |
} |
| 1531 |
|
| 1532 |
|
| 1533 |
void acpigen_write_debug_namestr(const char *str) |
| 1534 |
{ |
| 1535 |
acpigen_write_store(); |
| 1536 |
acpigen_emit_namestring(str); |
| 1537 |
acpigen_emit_ext_op(DEBUG_OP); |
| 1538 |
} |
| 1539 |
|
| 1540 |
|
| 1541 |
|
| 1542 |
void acpigen_write_debug_concatenate_string_op(const char *str, uint8_t res, |
| 1543 |
uint8_t tmp_res) |
| 1544 |
{ |
| 1545 |
acpigen_concatenate_string_op(str, res, tmp_res); |
| 1546 |
acpigen_write_debug_op(tmp_res); |
| 1547 |
} |
| 1548 |
|
| 1549 |
static void acpigen_tx_byte(unsigned char byte, void *data) |
| 1550 |
{ |
| 1551 |
acpigen_emit_byte(byte); |
| 1552 |
} |
| 1553 |
|
| 1554 |
|
| 1555 |
void acpigen_write_debug_sprintf(const char *fmt, ...) |
| 1556 |
{ |
| 1557 |
va_list args; |
| 1558 |
|
| 1559 |
acpigen_write_store(); |
| 1560 |
|
| 1561 |
acpigen_emit_byte(STRING_PREFIX); |
| 1562 |
va_start(args, fmt); |
| 1563 |
vtxprintf(acpigen_tx_byte, fmt, args, NULL); |
| 1564 |
va_end(args); |
| 1565 |
acpigen_emit_byte('\0'); |
| 1566 |
|
| 1567 |
acpigen_emit_ext_op(DEBUG_OP); |
| 1568 |
} |
| 1569 |
|
| 1570 |
void acpigen_write_if(void) |
| 1571 |
{ |
| 1572 |
acpigen_emit_byte(IF_OP); |
| 1573 |
acpigen_write_len_f(); |
| 1574 |
} |
| 1575 |
|
| 1576 |
|
| 1577 |
void acpigen_write_if_and(uint8_t arg1, uint8_t arg2) |
| 1578 |
{ |
| 1579 |
acpigen_write_if(); |
| 1580 |
acpigen_emit_byte(AND_OP); |
| 1581 |
acpigen_emit_byte(arg1); |
| 1582 |
acpigen_emit_byte(arg2); |
| 1583 |
} |
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
|
| 1588 |
|
| 1589 |
|
| 1590 |
|
| 1591 |
void acpigen_write_if_lequal_op_op(uint8_t op1, uint8_t op2) |
| 1592 |
{ |
| 1593 |
acpigen_write_if(); |
| 1594 |
acpigen_emit_byte(LEQUAL_OP); |
| 1595 |
acpigen_emit_byte(op1); |
| 1596 |
acpigen_emit_byte(op2); |
| 1597 |
} |
| 1598 |
|
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
void acpigen_write_if_lnotequal_op_op(uint8_t op1, uint8_t op2) |
| 1610 |
{ |
| 1611 |
acpigen_write_if(); |
| 1612 |
acpigen_emit_byte(LNOT_OP); |
| 1613 |
acpigen_emit_byte(LEQUAL_OP); |
| 1614 |
acpigen_emit_byte(op1); |
| 1615 |
acpigen_emit_byte(op2); |
| 1616 |
} |
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
void acpigen_write_if_lgreater_op_op(uint8_t op1, uint8_t op2) |
| 1625 |
{ |
| 1626 |
acpigen_write_if(); |
| 1627 |
acpigen_emit_byte(LGREATER_OP); |
| 1628 |
acpigen_emit_byte(op1); |
| 1629 |
acpigen_emit_byte(op2); |
| 1630 |
} |
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
void acpigen_write_if_lequal_op_int(uint8_t op, uint64_t val) |
| 1639 |
{ |
| 1640 |
acpigen_write_if(); |
| 1641 |
acpigen_emit_byte(LEQUAL_OP); |
| 1642 |
acpigen_emit_byte(op); |
| 1643 |
acpigen_write_integer(val); |
| 1644 |
} |
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
void acpigen_write_if_lnotequal_op_int(uint8_t op, uint64_t val) |
| 1657 |
{ |
| 1658 |
acpigen_write_if(); |
| 1659 |
acpigen_emit_byte(LNOT_OP); |
| 1660 |
acpigen_emit_byte(LEQUAL_OP); |
| 1661 |
acpigen_emit_byte(op); |
| 1662 |
acpigen_write_integer(val); |
| 1663 |
} |
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
void acpigen_write_if_lgreater_op_int(uint8_t op, uint64_t val) |
| 1672 |
{ |
| 1673 |
acpigen_write_if(); |
| 1674 |
acpigen_emit_byte(LGREATER_OP); |
| 1675 |
acpigen_emit_byte(op); |
| 1676 |
acpigen_write_integer(val); |
| 1677 |
} |
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
void acpigen_write_if_lequal_namestr_int(const char *namestr, uint64_t val) |
| 1686 |
{ |
| 1687 |
acpigen_write_if(); |
| 1688 |
acpigen_emit_byte(LEQUAL_OP); |
| 1689 |
acpigen_emit_namestring(namestr); |
| 1690 |
acpigen_write_integer(val); |
| 1691 |
} |
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
void acpigen_write_if_lnotequal_namestr_int(const char *namestr, uint64_t val) |
| 1704 |
{ |
| 1705 |
acpigen_write_if(); |
| 1706 |
acpigen_emit_byte(LNOT_OP); |
| 1707 |
acpigen_emit_byte(LEQUAL_OP); |
| 1708 |
acpigen_emit_namestring(namestr); |
| 1709 |
acpigen_write_integer(val); |
| 1710 |
} |
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
void acpigen_write_if_lgreater_namestr_int(const char *namestr, uint64_t val) |
| 1719 |
{ |
| 1720 |
acpigen_write_if(); |
| 1721 |
acpigen_emit_byte(LGREATER_OP); |
| 1722 |
acpigen_emit_namestring(namestr); |
| 1723 |
acpigen_write_integer(val); |
| 1724 |
} |
| 1725 |
|
| 1726 |
|
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
void acpigen_write_if_cond_ref_of(const char *namestring) |
| 1734 |
{ |
| 1735 |
acpigen_write_if(); |
| 1736 |
acpigen_emit_ext_op(COND_REFOF_OP); |
| 1737 |
acpigen_emit_namestring(namestring); |
| 1738 |
acpigen_emit_byte(ZERO_OP); |
| 1739 |
} |
| 1740 |
|
| 1741 |
|
| 1742 |
void acpigen_write_else(void) |
| 1743 |
{ |
| 1744 |
acpigen_pop_len(); |
| 1745 |
acpigen_emit_byte(ELSE_OP); |
| 1746 |
acpigen_write_len_f(); |
| 1747 |
} |
| 1748 |
|
| 1749 |
void acpigen_write_shiftleft_op_int(uint8_t src_result, uint64_t count) |
| 1750 |
{ |
| 1751 |
acpigen_emit_byte(SHIFT_LEFT_OP); |
| 1752 |
acpigen_emit_byte(src_result); |
| 1753 |
acpigen_write_integer(count); |
| 1754 |
acpigen_emit_byte(ZERO_OP); |
| 1755 |
} |
| 1756 |
|
| 1757 |
void acpigen_write_to_buffer(uint8_t src, uint8_t dst) |
| 1758 |
{ |
| 1759 |
acpigen_emit_byte(TO_BUFFER_OP); |
| 1760 |
acpigen_emit_byte(src); |
| 1761 |
acpigen_emit_byte(dst); |
| 1762 |
} |
| 1763 |
|
| 1764 |
void acpigen_write_to_integer(uint8_t src, uint8_t dst) |
| 1765 |
{ |
| 1766 |
acpigen_emit_byte(TO_INTEGER_OP); |
| 1767 |
acpigen_emit_byte(src); |
| 1768 |
acpigen_emit_byte(dst); |
| 1769 |
} |
| 1770 |
|
| 1771 |
void acpigen_write_to_integer_from_namestring(const char *source, uint8_t dst_op) |
| 1772 |
{ |
| 1773 |
acpigen_emit_byte(TO_INTEGER_OP); |
| 1774 |
acpigen_emit_namestring(source); |
| 1775 |
acpigen_emit_byte(dst_op); |
| 1776 |
} |
| 1777 |
|
| 1778 |
|
| 1779 |
|
| 1780 |
void acpigen_write_byte_buffer(uint8_t *arr, size_t size) |
| 1781 |
{ |
| 1782 |
size_t i; |
| 1783 |
|
| 1784 |
acpigen_emit_byte(BUFFER_OP); |
| 1785 |
acpigen_write_len_f(); |
| 1786 |
acpigen_write_integer(size); |
| 1787 |
|
| 1788 |
if (arr != NULL) { |
| 1789 |
for (i = 0; i < size; i++) |
| 1790 |
acpigen_emit_byte(arr[i]); |
| 1791 |
} |
| 1792 |
|
| 1793 |
acpigen_pop_len(); |
| 1794 |
} |
| 1795 |
|
| 1796 |
void acpigen_write_return_byte_buffer(uint8_t *arr, size_t size) |
| 1797 |
{ |
| 1798 |
acpigen_emit_byte(RETURN_OP); |
| 1799 |
acpigen_write_byte_buffer(arr, size); |
| 1800 |
} |
| 1801 |
|
| 1802 |
void acpigen_write_return_singleton_buffer(uint8_t arg) |
| 1803 |
{ |
| 1804 |
acpigen_write_return_byte_buffer(&arg, 1); |
| 1805 |
} |
| 1806 |
|
| 1807 |
void acpigen_write_return_op(uint8_t arg) |
| 1808 |
{ |
| 1809 |
acpigen_emit_byte(RETURN_OP); |
| 1810 |
acpigen_emit_byte(arg); |
| 1811 |
} |
| 1812 |
|
| 1813 |
void acpigen_write_return_byte(uint8_t arg) |
| 1814 |
{ |
| 1815 |
acpigen_emit_byte(RETURN_OP); |
| 1816 |
acpigen_write_byte(arg); |
| 1817 |
} |
| 1818 |
|
| 1819 |
void acpigen_write_return_integer(uint64_t arg) |
| 1820 |
{ |
| 1821 |
acpigen_emit_byte(RETURN_OP); |
| 1822 |
acpigen_write_integer(arg); |
| 1823 |
} |
| 1824 |
|
| 1825 |
void acpigen_write_return_namestr(const char *arg) |
| 1826 |
{ |
| 1827 |
acpigen_emit_byte(RETURN_OP); |
| 1828 |
acpigen_emit_namestring(arg); |
| 1829 |
} |
| 1830 |
|
| 1831 |
void acpigen_write_return_string(const char *arg) |
| 1832 |
{ |
| 1833 |
acpigen_emit_byte(RETURN_OP); |
| 1834 |
acpigen_write_string(arg); |
| 1835 |
} |
| 1836 |
|
| 1837 |
void acpigen_write_upc(enum acpi_upc_type type) |
| 1838 |
{ |
| 1839 |
acpigen_write_name("_UPC"); |
| 1840 |
acpigen_write_package(4); |
| 1841 |
|
| 1842 |
acpigen_write_byte(type == UPC_TYPE_UNUSED ? 0 : 0xff); |
| 1843 |
|
| 1844 |
acpigen_write_byte(type); |
| 1845 |
|
| 1846 |
acpigen_write_zero(); |
| 1847 |
|
| 1848 |
acpigen_write_zero(); |
| 1849 |
acpigen_pop_len(); |
| 1850 |
} |
| 1851 |
|
| 1852 |
void acpigen_write_pld(const struct acpi_pld *pld) |
| 1853 |
{ |
| 1854 |
uint8_t buf[20]; |
| 1855 |
|
| 1856 |
if (acpi_pld_to_buffer(pld, buf, ARRAY_SIZE(buf)) < 0) |
| 1857 |
return; |
| 1858 |
|
| 1859 |
acpigen_write_name("_PLD"); |
| 1860 |
acpigen_write_package(1); |
| 1861 |
acpigen_write_byte_buffer(buf, ARRAY_SIZE(buf)); |
| 1862 |
acpigen_pop_len(); |
| 1863 |
} |
| 1864 |
|
| 1865 |
void acpigen_write_dsm(const char *uuid, void (**callbacks)(void *), size_t count, void *arg) |
| 1866 |
{ |
| 1867 |
struct dsm_uuid id = DSM_UUID(uuid, callbacks, count, arg); |
| 1868 |
acpigen_write_dsm_uuid_arr(&id, 1); |
| 1869 |
} |
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
#if defined(__GNUC__) && !defined(__clang__) |
| 1878 |
#pragma GCC diagnostic ignored "-Wstack-usage=" |
| 1879 |
#endif |
| 1880 |
static void acpigen_dsm_uuid_enum_functions(const struct dsm_uuid *id) |
| 1881 |
{ |
| 1882 |
const size_t bytes = DIV_ROUND_UP(id->count, BITS_PER_BYTE); |
| 1883 |
uint8_t *buffer = alloca(bytes); |
| 1884 |
bool set = false; |
| 1885 |
size_t cb_idx = 0; |
| 1886 |
|
| 1887 |
memset(buffer, 0, bytes); |
| 1888 |
|
| 1889 |
for (size_t i = 0; i < bytes; i++) { |
| 1890 |
for (size_t j = 0; j < BITS_PER_BYTE; j++) { |
| 1891 |
if (cb_idx >= id->count) |
| 1892 |
break; |
| 1893 |
|
| 1894 |
if (id->callbacks[cb_idx++]) { |
| 1895 |
set = true; |
| 1896 |
buffer[i] |= BIT(j); |
| 1897 |
} |
| 1898 |
} |
| 1899 |
} |
| 1900 |
|
| 1901 |
if (set) |
| 1902 |
buffer[0] |= BIT(0); |
| 1903 |
|
| 1904 |
acpigen_write_return_byte_buffer(buffer, bytes); |
| 1905 |
} |
| 1906 |
|
| 1907 |
static void acpigen_write_dsm_uuid(struct dsm_uuid *id) |
| 1908 |
{ |
| 1909 |
size_t i; |
| 1910 |
|
| 1911 |
|
| 1912 |
acpigen_write_if(); |
| 1913 |
acpigen_emit_byte(LEQUAL_OP); |
| 1914 |
acpigen_emit_byte(LOCAL0_OP); |
| 1915 |
acpigen_write_uuid(id->uuid); |
| 1916 |
|
| 1917 |
|
| 1918 |
acpigen_write_to_integer(ARG2_OP, LOCAL1_OP); |
| 1919 |
|
| 1920 |
|
| 1921 |
{ |
| 1922 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 0); |
| 1923 |
if (id->callbacks[0]) |
| 1924 |
id->callbacks[0](id->arg); |
| 1925 |
else if (id->count) |
| 1926 |
acpigen_dsm_uuid_enum_functions(id); |
| 1927 |
acpigen_write_if_end(); |
| 1928 |
} |
| 1929 |
|
| 1930 |
for (i = 1; i < id->count; i++) { |
| 1931 |
|
| 1932 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, i); |
| 1933 |
|
| 1934 |
|
| 1935 |
if (id->callbacks[i]) |
| 1936 |
id->callbacks[i](id->arg); |
| 1937 |
|
| 1938 |
acpigen_write_if_end(); |
| 1939 |
} |
| 1940 |
|
| 1941 |
|
| 1942 |
acpigen_write_return_singleton_buffer(0x0); |
| 1943 |
|
| 1944 |
acpigen_write_if_end(); |
| 1945 |
} |
| 1946 |
|
| 1947 |
|
| 1948 |
|
| 1949 |
|
| 1950 |
|
| 1951 |
|
| 1952 |
|
| 1953 |
|
| 1954 |
|
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
|
| 1960 |
|
| 1961 |
|
| 1962 |
|
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
|
| 1976 |
|
| 1977 |
|
| 1978 |
|
| 1979 |
|
| 1980 |
|
| 1981 |
void acpigen_write_dsm_uuid_arr(struct dsm_uuid *ids, size_t count) |
| 1982 |
{ |
| 1983 |
size_t i; |
| 1984 |
|
| 1985 |
|
| 1986 |
acpigen_write_method_serialized("_DSM", 0x4); |
| 1987 |
|
| 1988 |
|
| 1989 |
acpigen_write_to_buffer(ARG0_OP, LOCAL0_OP); |
| 1990 |
|
| 1991 |
for (i = 0; i < count; i++) |
| 1992 |
acpigen_write_dsm_uuid(&ids[i]); |
| 1993 |
|
| 1994 |
|
| 1995 |
acpigen_write_return_singleton_buffer(0x0); |
| 1996 |
|
| 1997 |
acpigen_pop_len(); |
| 1998 |
} |
| 1999 |
|
| 2000 |
void acpigen_write_CPPC_package(const struct cppc_config *config) |
| 2001 |
{ |
| 2002 |
u32 i; |
| 2003 |
u32 max; |
| 2004 |
switch (config->version) { |
| 2005 |
case 1: |
| 2006 |
max = CPPC_MAX_FIELDS_VER_1; |
| 2007 |
break; |
| 2008 |
case 2: |
| 2009 |
max = CPPC_MAX_FIELDS_VER_2; |
| 2010 |
break; |
| 2011 |
case 3: |
| 2012 |
max = CPPC_MAX_FIELDS_VER_3; |
| 2013 |
break; |
| 2014 |
default: |
| 2015 |
printk(BIOS_ERR, "CPPC version %u is not implemented\n", config->version); |
| 2016 |
return; |
| 2017 |
} |
| 2018 |
acpigen_write_name(CPPC_PACKAGE_NAME); |
| 2019 |
|
| 2020 |
|
| 2021 |
acpigen_write_package(max + 2); |
| 2022 |
acpigen_write_dword(max + 2); |
| 2023 |
|
| 2024 |
acpigen_write_byte(config->version); |
| 2025 |
|
| 2026 |
for (i = 0; i < max; ++i) { |
| 2027 |
const cppc_entry_t *entry = &config->entries[i]; |
| 2028 |
if (entry->type == CPPC_TYPE_DWORD) |
| 2029 |
acpigen_write_dword(entry->dword); |
| 2030 |
else |
| 2031 |
acpigen_write_register_resource(&entry->reg); |
| 2032 |
} |
| 2033 |
acpigen_pop_len(); |
| 2034 |
} |
| 2035 |
|
| 2036 |
void acpigen_write_CPPC_method(void) |
| 2037 |
{ |
| 2038 |
char pscope[16]; |
| 2039 |
snprintf(pscope, sizeof(pscope), |
| 2040 |
"\\_SB." CONFIG_ACPI_CPU_STRING "." CPPC_PACKAGE_NAME, 0); |
| 2041 |
|
| 2042 |
acpigen_write_method("_CPC", 0); |
| 2043 |
acpigen_emit_byte(RETURN_OP); |
| 2044 |
acpigen_emit_namestring(pscope); |
| 2045 |
acpigen_pop_len(); |
| 2046 |
} |
| 2047 |
|
| 2048 |
|
| 2049 |
|
| 2050 |
|
| 2051 |
|
| 2052 |
|
| 2053 |
|
| 2054 |
|
| 2055 |
|
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
|
| 2097 |
|
| 2098 |
|
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
void acpigen_write_rom(void *bios, const size_t length) |
| 2109 |
{ |
| 2110 |
ASSERT(bios) |
| 2111 |
ASSERT(length) |
| 2112 |
|
| 2113 |
|
| 2114 |
acpigen_write_method_serialized("_ROM", 2); |
| 2115 |
|
| 2116 |
|
| 2117 |
struct opregion opreg = OPREGION("ROMS", SYSTEMMEMORY, (uintptr_t)bios, length); |
| 2118 |
acpigen_write_opregion(&opreg); |
| 2119 |
|
| 2120 |
struct fieldlist l[] = { |
| 2121 |
FIELDLIST_OFFSET(0), |
| 2122 |
FIELDLIST_NAMESTR("RBF0", 8 * length), |
| 2123 |
}; |
| 2124 |
|
| 2125 |
|
| 2126 |
|
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
acpigen_write_field(opreg.name, l, 2, FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE); |
| 2131 |
|
| 2132 |
|
| 2133 |
acpigen_write_store_ops(ARG0_OP, LOCAL0_OP); |
| 2134 |
|
| 2135 |
|
| 2136 |
acpigen_write_store_ops(ARG1_OP, LOCAL1_OP); |
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
acpigen_write_if_lgreater_op_int(LOCAL1_OP, 0x1000); |
| 2141 |
|
| 2142 |
|
| 2143 |
acpigen_write_store_int_to_op(0x1000, LOCAL1_OP); |
| 2144 |
|
| 2145 |
|
| 2146 |
acpigen_pop_len(); |
| 2147 |
|
| 2148 |
|
| 2149 |
acpigen_write_store_ops(LOCAL1_OP, LOCAL3_OP); |
| 2150 |
|
| 2151 |
|
| 2152 |
acpigen_write_if_lgreater_op_int(LOCAL0_OP, length); |
| 2153 |
|
| 2154 |
|
| 2155 |
acpigen_emit_byte(RETURN_OP); |
| 2156 |
acpigen_emit_byte(BUFFER_OP); |
| 2157 |
acpigen_write_len_f(); |
| 2158 |
acpigen_emit_byte(LOCAL1_OP); |
| 2159 |
acpigen_emit_byte(0); |
| 2160 |
acpigen_pop_len(); |
| 2161 |
|
| 2162 |
|
| 2163 |
acpigen_pop_len(); |
| 2164 |
|
| 2165 |
|
| 2166 |
acpigen_write_if_lgreater_op_int(LOCAL0_OP, length - 4096); |
| 2167 |
|
| 2168 |
|
| 2169 |
acpigen_emit_byte(SUBTRACT_OP); |
| 2170 |
acpigen_write_integer(length); |
| 2171 |
acpigen_emit_byte(LOCAL0_OP); |
| 2172 |
acpigen_emit_byte(LOCAL2_OP); |
| 2173 |
|
| 2174 |
|
| 2175 |
acpigen_write_if_lgreater_op_op(LOCAL1_OP, LOCAL2_OP); |
| 2176 |
|
| 2177 |
|
| 2178 |
acpigen_write_store_ops(LOCAL2_OP, LOCAL1_OP); |
| 2179 |
|
| 2180 |
|
| 2181 |
acpigen_pop_len(); |
| 2182 |
|
| 2183 |
|
| 2184 |
acpigen_pop_len(); |
| 2185 |
|
| 2186 |
|
| 2187 |
acpigen_write_name("ROM1"); |
| 2188 |
acpigen_emit_byte(BUFFER_OP); |
| 2189 |
acpigen_write_len_f(); |
| 2190 |
acpigen_emit_byte(LOCAL3_OP); |
| 2191 |
acpigen_emit_byte(0); |
| 2192 |
acpigen_pop_len(); |
| 2193 |
|
| 2194 |
|
| 2195 |
acpigen_emit_byte(MULTIPLY_OP); |
| 2196 |
acpigen_emit_byte(LOCAL1_OP); |
| 2197 |
acpigen_write_integer(0x08); |
| 2198 |
acpigen_emit_byte(LOCAL1_OP); |
| 2199 |
|
| 2200 |
|
| 2201 |
acpigen_emit_byte(MULTIPLY_OP); |
| 2202 |
acpigen_emit_byte(LOCAL0_OP); |
| 2203 |
acpigen_write_integer(0x08); |
| 2204 |
acpigen_emit_byte(LOCAL0_OP); |
| 2205 |
|
| 2206 |
|
| 2207 |
acpigen_emit_ext_op(CREATEFIELD_OP); |
| 2208 |
acpigen_emit_namestring("RBF0"); |
| 2209 |
acpigen_emit_byte(LOCAL0_OP); |
| 2210 |
acpigen_emit_byte(LOCAL1_OP); |
| 2211 |
acpigen_emit_namestring("TMPB"); |
| 2212 |
|
| 2213 |
|
| 2214 |
acpigen_write_store_namestr_to_namestr("TMPB", "ROM1"); |
| 2215 |
|
| 2216 |
|
| 2217 |
acpigen_emit_byte(RETURN_OP); |
| 2218 |
acpigen_emit_namestring("ROM1"); |
| 2219 |
|
| 2220 |
|
| 2221 |
acpigen_pop_len(); |
| 2222 |
} |
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
int acpigen_enable_tx_gpio(const struct acpi_gpio *gpio) |
| 2232 |
{ |
| 2233 |
if (gpio->active_low) |
| 2234 |
return acpigen_soc_clear_tx_gpio(gpio->pins[0]); |
| 2235 |
else |
| 2236 |
return acpigen_soc_set_tx_gpio(gpio->pins[0]); |
| 2237 |
} |
| 2238 |
|
| 2239 |
int acpigen_disable_tx_gpio(const struct acpi_gpio *gpio) |
| 2240 |
{ |
| 2241 |
if (gpio->active_low) |
| 2242 |
return acpigen_soc_set_tx_gpio(gpio->pins[0]); |
| 2243 |
else |
| 2244 |
return acpigen_soc_clear_tx_gpio(gpio->pins[0]); |
| 2245 |
} |
| 2246 |
|
| 2247 |
void acpigen_get_rx_gpio(const struct acpi_gpio *gpio) |
| 2248 |
{ |
| 2249 |
acpigen_soc_read_rx_gpio(gpio->pins[0]); |
| 2250 |
|
| 2251 |
if (gpio->active_low) |
| 2252 |
acpigen_write_xor(LOCAL0_OP, 1, LOCAL0_OP); |
| 2253 |
} |
| 2254 |
|
| 2255 |
void acpigen_get_tx_gpio(const struct acpi_gpio *gpio) |
| 2256 |
{ |
| 2257 |
acpigen_soc_get_tx_gpio(gpio->pins[0]); |
| 2258 |
|
| 2259 |
if (gpio->active_low) |
| 2260 |
acpigen_write_xor(LOCAL0_OP, 1, LOCAL0_OP); |
| 2261 |
} |
| 2262 |
|
| 2263 |
|
| 2264 |
void acpigen_resource_word(u16 res_type, u16 gen_flags, u16 type_flags, u16 gran, u16 range_min, |
| 2265 |
u16 range_max, u16 translation, u16 length) |
| 2266 |
{ |
| 2267 |
|
| 2268 |
acpigen_emit_byte(0x88); |
| 2269 |
|
| 2270 |
acpigen_emit_byte(0x0d); |
| 2271 |
acpigen_emit_byte(0x00); |
| 2272 |
|
| 2273 |
acpigen_emit_byte(res_type); |
| 2274 |
|
| 2275 |
acpigen_emit_byte(gen_flags); |
| 2276 |
|
| 2277 |
|
| 2278 |
acpigen_emit_byte(type_flags); |
| 2279 |
|
| 2280 |
acpigen_emit_word(gran); |
| 2281 |
acpigen_emit_word(range_min); |
| 2282 |
acpigen_emit_word(range_max); |
| 2283 |
acpigen_emit_word(translation); |
| 2284 |
acpigen_emit_word(length); |
| 2285 |
} |
| 2286 |
|
| 2287 |
|
| 2288 |
void acpigen_resource_dword(u16 res_type, u16 gen_flags, u16 type_flags, u32 gran, |
| 2289 |
u32 range_min, u32 range_max, u32 translation, u32 length) |
| 2290 |
{ |
| 2291 |
|
| 2292 |
acpigen_emit_byte(0x87); |
| 2293 |
|
| 2294 |
acpigen_emit_byte(23); |
| 2295 |
acpigen_emit_byte(0x00); |
| 2296 |
|
| 2297 |
acpigen_emit_byte(res_type); |
| 2298 |
|
| 2299 |
acpigen_emit_byte(gen_flags); |
| 2300 |
|
| 2301 |
|
| 2302 |
acpigen_emit_byte(type_flags); |
| 2303 |
|
| 2304 |
acpigen_emit_dword(gran); |
| 2305 |
acpigen_emit_dword(range_min); |
| 2306 |
acpigen_emit_dword(range_max); |
| 2307 |
acpigen_emit_dword(translation); |
| 2308 |
acpigen_emit_dword(length); |
| 2309 |
} |
| 2310 |
|
| 2311 |
static void acpigen_emit_qword(u64 data) |
| 2312 |
{ |
| 2313 |
acpigen_emit_dword(data & 0xffffffff); |
| 2314 |
acpigen_emit_dword((data >> 32) & 0xffffffff); |
| 2315 |
} |
| 2316 |
|
| 2317 |
|
| 2318 |
void acpigen_resource_qword(u16 res_type, u16 gen_flags, u16 type_flags, u64 gran, |
| 2319 |
u64 range_min, u64 range_max, u64 translation, u64 length) |
| 2320 |
{ |
| 2321 |
|
| 2322 |
acpigen_emit_byte(0x8a); |
| 2323 |
|
| 2324 |
acpigen_emit_byte(0x2b); |
| 2325 |
acpigen_emit_byte(0x00); |
| 2326 |
|
| 2327 |
acpigen_emit_byte(res_type); |
| 2328 |
|
| 2329 |
acpigen_emit_byte(gen_flags); |
| 2330 |
|
| 2331 |
|
| 2332 |
acpigen_emit_byte(type_flags); |
| 2333 |
|
| 2334 |
acpigen_emit_qword(gran); |
| 2335 |
acpigen_emit_qword(range_min); |
| 2336 |
acpigen_emit_qword(range_max); |
| 2337 |
acpigen_emit_qword(translation); |
| 2338 |
acpigen_emit_qword(length); |
| 2339 |
} |
| 2340 |
|
| 2341 |
void acpigen_resource_producer_bus_number(u16 bus_base, u16 bus_limit) |
| 2342 |
{ |
| 2343 |
acpigen_resource_word(RSRC_TYPE_BUS, |
| 2344 |
ADDR_SPACE_GENERAL_FLAG_MAX_FIXED |
| 2345 |
| ADDR_SPACE_GENERAL_FLAG_MIN_FIXED |
| 2346 |
| ADDR_SPACE_GENERAL_FLAG_DEC_POS |
| 2347 |
| ADDR_SPACE_GENERAL_FLAG_PRODUCER, |
| 2348 |
BUS_NUM_RANGE_RESOURCE_FLAG, |
| 2349 |
0, |
| 2350 |
bus_base, |
| 2351 |
bus_limit, |
| 2352 |
0x0, |
| 2353 |
bus_limit - bus_base + 1); |
| 2354 |
} |
| 2355 |
|
| 2356 |
void acpigen_resource_producer_io(u16 io_base, u16 io_limit) |
| 2357 |
{ |
| 2358 |
acpigen_resource_dword(RSRC_TYPE_IO, |
| 2359 |
ADDR_SPACE_GENERAL_FLAG_MAX_FIXED |
| 2360 |
| ADDR_SPACE_GENERAL_FLAG_MIN_FIXED |
| 2361 |
| ADDR_SPACE_GENERAL_FLAG_DEC_POS |
| 2362 |
| ADDR_SPACE_GENERAL_FLAG_PRODUCER, |
| 2363 |
IO_RSRC_FLAG_ENTIRE_RANGE, |
| 2364 |
0, |
| 2365 |
io_base, |
| 2366 |
io_limit, |
| 2367 |
0x0, |
| 2368 |
io_limit - io_base + 1); |
| 2369 |
} |
| 2370 |
|
| 2371 |
static void acpigen_resource_mmio32(u32 mmio_base, u32 mmio_limit, u16 gen_flags, |
| 2372 |
u16 type_flags) |
| 2373 |
{ |
| 2374 |
acpigen_resource_dword(RSRC_TYPE_MEM, |
| 2375 |
gen_flags, |
| 2376 |
type_flags, |
| 2377 |
0, |
| 2378 |
mmio_base, |
| 2379 |
mmio_limit, |
| 2380 |
0x0, |
| 2381 |
mmio_limit - mmio_base + 1); |
| 2382 |
} |
| 2383 |
|
| 2384 |
static void acpigen_resource_mmio64(u64 mmio_base, u64 mmio_limit, u16 gen_flags, |
| 2385 |
u16 type_flags) |
| 2386 |
{ |
| 2387 |
acpigen_resource_qword(RSRC_TYPE_MEM, |
| 2388 |
gen_flags, |
| 2389 |
type_flags, |
| 2390 |
0, |
| 2391 |
mmio_base, |
| 2392 |
mmio_limit, |
| 2393 |
0x0, |
| 2394 |
mmio_limit - mmio_base + 1); |
| 2395 |
} |
| 2396 |
|
| 2397 |
static void acpigen_resource_mmio(u64 mmio_base, u64 mmio_limit, bool is_producer, u16 type_flags) |
| 2398 |
{ |
| 2399 |
const u16 gen_flags = ADDR_SPACE_GENERAL_FLAG_MAX_FIXED |
| 2400 |
| ADDR_SPACE_GENERAL_FLAG_MIN_FIXED |
| 2401 |
| ADDR_SPACE_GENERAL_FLAG_DEC_POS |
| 2402 |
| (is_producer ? ADDR_SPACE_GENERAL_FLAG_PRODUCER |
| 2403 |
: ADDR_SPACE_GENERAL_FLAG_CONSUMER); |
| 2404 |
|
| 2405 |
if (mmio_base < 4ULL * GiB && mmio_limit < 4ULL * GiB) |
| 2406 |
acpigen_resource_mmio32(mmio_base, mmio_limit, gen_flags, type_flags); |
| 2407 |
else |
| 2408 |
acpigen_resource_mmio64(mmio_base, mmio_limit, gen_flags, type_flags); |
| 2409 |
} |
| 2410 |
|
| 2411 |
void acpigen_resource_producer_mmio(u64 mmio_base, u64 mmio_limit, u16 type_flags) |
| 2412 |
{ |
| 2413 |
acpigen_resource_mmio(mmio_base, mmio_limit, true, type_flags); |
| 2414 |
} |
| 2415 |
|
| 2416 |
void acpigen_resource_consumer_mmio(u64 mmio_base, u64 mmio_limit, u16 type_flags) |
| 2417 |
{ |
| 2418 |
acpigen_resource_mmio(mmio_base, mmio_limit, false, type_flags); |
| 2419 |
} |
| 2420 |
|
| 2421 |
void acpigen_write_ADR(uint64_t adr) |
| 2422 |
{ |
| 2423 |
acpigen_write_name_qword("_ADR", adr); |
| 2424 |
} |
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
void acpigen_write_ADR_soundwire_device(const struct soundwire_address *address) |
| 2444 |
{ |
| 2445 |
acpigen_write_ADR((((uint64_t)address->link_id & 0xf) << 48) | |
| 2446 |
(((uint64_t)address->version & 0xf) << 44) | |
| 2447 |
(((uint64_t)address->unique_id & 0xf) << 40) | |
| 2448 |
(((uint64_t)address->manufacturer_id & 0xffff) << 24) | |
| 2449 |
(((uint64_t)address->part_id & 0xffff) << 8) | |
| 2450 |
(((uint64_t)address->class & 0xff))); |
| 2451 |
} |
| 2452 |
|
| 2453 |
void acpigen_notify(const char *namestr, int value) |
| 2454 |
{ |
| 2455 |
acpigen_emit_byte(NOTIFY_OP); |
| 2456 |
acpigen_emit_namestring(namestr); |
| 2457 |
acpigen_write_integer(value); |
| 2458 |
} |
| 2459 |
|
| 2460 |
static void _create_field(uint8_t aml_op, uint8_t srcop, size_t byte_offset, const char *name) |
| 2461 |
{ |
| 2462 |
acpigen_emit_byte(aml_op); |
| 2463 |
acpigen_emit_byte(srcop); |
| 2464 |
acpigen_write_integer(byte_offset); |
| 2465 |
acpigen_emit_namestring(name); |
| 2466 |
} |
| 2467 |
|
| 2468 |
void acpigen_write_create_bit_field(uint8_t op, size_t bit_offset, const char *name) |
| 2469 |
{ |
| 2470 |
_create_field(CREATE_BIT_OP, op, bit_offset, name); |
| 2471 |
} |
| 2472 |
|
| 2473 |
void acpigen_write_create_byte_field(uint8_t op, size_t byte_offset, const char *name) |
| 2474 |
{ |
| 2475 |
_create_field(CREATE_BYTE_OP, op, byte_offset, name); |
| 2476 |
} |
| 2477 |
|
| 2478 |
void acpigen_write_create_word_field(uint8_t op, size_t byte_offset, const char *name) |
| 2479 |
{ |
| 2480 |
_create_field(CREATE_WORD_OP, op, byte_offset, name); |
| 2481 |
} |
| 2482 |
|
| 2483 |
void acpigen_write_create_dword_field(uint8_t op, size_t byte_offset, const char *name) |
| 2484 |
{ |
| 2485 |
_create_field(CREATE_DWORD_OP, op, byte_offset, name); |
| 2486 |
} |
| 2487 |
|
| 2488 |
void acpigen_write_create_qword_field(uint8_t op, size_t byte_offset, const char *name) |
| 2489 |
{ |
| 2490 |
_create_field(CREATE_QWORD_OP, op, byte_offset, name); |
| 2491 |
} |
| 2492 |
|
| 2493 |
static void _create_buffer_field(uint8_t aml_op, const char *src_buf, size_t byte_offset, |
| 2494 |
const char *field) |
| 2495 |
{ |
| 2496 |
acpigen_emit_byte(aml_op); |
| 2497 |
acpigen_emit_namestring(src_buf); |
| 2498 |
acpigen_write_integer(byte_offset); |
| 2499 |
acpigen_emit_namestring(field); |
| 2500 |
} |
| 2501 |
|
| 2502 |
void acpigen_write_create_buffer_bit_field(const char *src_buf, size_t bit_offset, const char *field) |
| 2503 |
{ |
| 2504 |
_create_buffer_field(CREATE_BIT_OP, src_buf, bit_offset, field); |
| 2505 |
} |
| 2506 |
|
| 2507 |
void acpigen_write_create_buffer_byte_field(const char *src_buf, size_t byte_offset, const char *field) |
| 2508 |
{ |
| 2509 |
_create_buffer_field(CREATE_BYTE_OP, src_buf, byte_offset, field); |
| 2510 |
} |
| 2511 |
|
| 2512 |
void acpigen_write_create_buffer_word_field(const char *src_buf, size_t byte_offset, const char *field) |
| 2513 |
{ |
| 2514 |
_create_buffer_field(CREATE_WORD_OP, src_buf, byte_offset, field); |
| 2515 |
} |
| 2516 |
|
| 2517 |
void acpigen_write_create_buffer_dword_field(const char *src_buf, size_t byte_offset, const char *field) |
| 2518 |
{ |
| 2519 |
_create_buffer_field(CREATE_DWORD_OP, src_buf, byte_offset, field); |
| 2520 |
} |
| 2521 |
|
| 2522 |
void acpigen_write_create_buffer_qword_field(const char *src_buf, size_t byte_offset, const char *field) |
| 2523 |
{ |
| 2524 |
_create_buffer_field(CREATE_QWORD_OP, src_buf, byte_offset, field); |
| 2525 |
} |
| 2526 |
|
| 2527 |
void acpigen_write_pct_package(const acpi_addr_t *perf_ctrl, const acpi_addr_t *perf_sts) |
| 2528 |
{ |
| 2529 |
acpigen_write_name("_PCT"); |
| 2530 |
acpigen_write_package(0x02); |
| 2531 |
acpigen_write_register_resource(perf_ctrl); |
| 2532 |
acpigen_write_register_resource(perf_sts); |
| 2533 |
|
| 2534 |
acpigen_pop_len(); |
| 2535 |
} |
| 2536 |
|
| 2537 |
void acpigen_write_xpss_package(const struct acpi_xpss_sw_pstate *pstate_value) |
| 2538 |
{ |
| 2539 |
acpigen_write_package(0x08); |
| 2540 |
acpigen_write_dword(pstate_value->core_freq); |
| 2541 |
acpigen_write_dword(pstate_value->power); |
| 2542 |
acpigen_write_dword(pstate_value->transition_latency); |
| 2543 |
acpigen_write_dword(pstate_value->bus_master_latency); |
| 2544 |
|
| 2545 |
acpigen_write_byte_buffer((uint8_t *)&pstate_value->control_value, sizeof(uint64_t)); |
| 2546 |
acpigen_write_byte_buffer((uint8_t *)&pstate_value->status_value, sizeof(uint64_t)); |
| 2547 |
acpigen_write_byte_buffer((uint8_t *)&pstate_value->control_mask, sizeof(uint64_t)); |
| 2548 |
acpigen_write_byte_buffer((uint8_t *)&pstate_value->status_mask, sizeof(uint64_t)); |
| 2549 |
|
| 2550 |
acpigen_pop_len(); |
| 2551 |
} |
| 2552 |
|
| 2553 |
void acpigen_write_xpss_object(const struct acpi_xpss_sw_pstate *pstate_values, size_t nentries) |
| 2554 |
{ |
| 2555 |
size_t pstate; |
| 2556 |
|
| 2557 |
acpigen_write_name("XPSS"); |
| 2558 |
acpigen_write_package(nentries); |
| 2559 |
for (pstate = 0; pstate < nentries; pstate++) { |
| 2560 |
acpigen_write_xpss_package(pstate_values); |
| 2561 |
pstate_values++; |
| 2562 |
} |
| 2563 |
|
| 2564 |
acpigen_pop_len(); |
| 2565 |
} |
| 2566 |
|
| 2567 |
|
| 2568 |
void acpigen_write_delay_until_namestr_int(uint32_t wait_ms, const char *name, uint64_t value) |
| 2569 |
{ |
| 2570 |
uint32_t wait_ms_segment = 1; |
| 2571 |
uint32_t segments = wait_ms; |
| 2572 |
|
| 2573 |
|
| 2574 |
if (wait_ms > 2) { |
| 2575 |
wait_ms_segment = 2; |
| 2576 |
segments = wait_ms / wait_ms_segment; |
| 2577 |
} |
| 2578 |
|
| 2579 |
acpigen_write_store_int_to_op(segments, LOCAL7_OP); |
| 2580 |
acpigen_emit_byte(WHILE_OP); |
| 2581 |
acpigen_write_len_f(); |
| 2582 |
acpigen_emit_byte(LGREATER_OP); |
| 2583 |
acpigen_emit_byte(LOCAL7_OP); |
| 2584 |
acpigen_emit_byte(ZERO_OP); |
| 2585 |
|
| 2586 |
|
| 2587 |
if (name) { |
| 2588 |
acpigen_write_if_lequal_namestr_int(name, value); |
| 2589 |
acpigen_emit_byte(BREAK_OP); |
| 2590 |
acpigen_pop_len(); |
| 2591 |
} |
| 2592 |
|
| 2593 |
acpigen_write_sleep(wait_ms_segment); |
| 2594 |
acpigen_emit_byte(DECREMENT_OP); |
| 2595 |
acpigen_emit_byte(LOCAL7_OP); |
| 2596 |
acpigen_pop_len(); |
| 2597 |
|
| 2598 |
if (name) { |
| 2599 |
acpigen_write_if_lequal_op_op(LOCAL7_OP, ZERO_OP); |
| 2600 |
acpigen_write_debug_sprintf("WARN: Wait loop timeout for variable %s", |
| 2601 |
name); |
| 2602 |
acpigen_pop_len(); |
| 2603 |
} |
| 2604 |
} |
| 2605 |
|
| 2606 |
void acpigen_ssdt_override_sleep_states(bool enable_s1, bool enable_s2, bool enable_s3, |
| 2607 |
bool enable_s4) |
| 2608 |
{ |
| 2609 |
assert(!(enable_s1 && CONFIG(ACPI_S1_NOT_SUPPORTED))); |
| 2610 |
assert(!(enable_s3 && !CONFIG(HAVE_ACPI_RESUME))); |
| 2611 |
assert(!(enable_s4 && CONFIG(DISABLE_ACPI_HIBERNATE))); |
| 2612 |
|
| 2613 |
acpigen_write_scope("\\"); |
| 2614 |
uint32_t sleep_enable = (enable_s1 << 0) | (enable_s2 << 1) |
| 2615 |
| (enable_s3 << 2) | (enable_s4 << 3); |
| 2616 |
acpigen_write_name_dword("OSFG", sleep_enable); |
| 2617 |
acpigen_pop_len(); |
| 2618 |
} |