| 1 |
|
| 2 |
|
| 3 |
#include <types.h> |
| 4 |
#include <acpi/acpigen.h> |
| 5 |
#include <acpi/acpi_device.h> |
| 6 |
#include <cbmem.h> |
| 7 |
#include <console/console.h> |
| 8 |
#include <security/tpm/tss.h> |
| 9 |
|
| 10 |
#include "tpm_ppi.h" |
| 11 |
|
| 12 |
#define BCD(x, y) (((x) << 4) | ((y) << 0)) |
| 13 |
|
| 14 |
static void set_package_element_op(const char *package_name, unsigned int element, |
| 15 |
uint8_t src_op) |
| 16 |
{ |
| 17 |
acpigen_write_store(); |
| 18 |
acpigen_emit_byte(src_op); |
| 19 |
acpigen_emit_byte(INDEX_OP); |
| 20 |
acpigen_emit_namestring(package_name); |
| 21 |
acpigen_write_integer(element); |
| 22 |
acpigen_emit_byte(ZERO_OP); |
| 23 |
} |
| 24 |
|
| 25 |
static void set_package_element_name(const char *package_name, unsigned int element, |
| 26 |
const char *src) |
| 27 |
{ |
| 28 |
acpigen_write_store(); |
| 29 |
acpigen_emit_namestring(src); |
| 30 |
acpigen_emit_byte(INDEX_OP); |
| 31 |
acpigen_emit_namestring(package_name); |
| 32 |
acpigen_write_integer(element); |
| 33 |
acpigen_emit_byte(ZERO_OP); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
static void verify_supported_ppi(uint8_t src_op) |
| 38 |
{ |
| 39 |
enum tpm_family family = tlcl_get_family(); |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
acpigen_write_store(); |
| 48 |
acpigen_emit_byte(OBJ_TYPE_OP); |
| 49 |
acpigen_emit_byte(src_op); |
| 50 |
acpigen_emit_byte(LOCAL1_OP); |
| 51 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 4); |
| 52 |
acpigen_get_package_op_element(src_op, 0, LOCAL2_OP); |
| 53 |
acpigen_pop_len(); |
| 54 |
|
| 55 |
|
| 56 |
acpigen_write_store(); |
| 57 |
acpigen_emit_byte(OBJ_TYPE_OP); |
| 58 |
acpigen_emit_byte(src_op); |
| 59 |
acpigen_emit_byte(LOCAL1_OP); |
| 60 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 3); |
| 61 |
acpigen_write_to_integer(src_op, LOCAL2_OP); |
| 62 |
acpigen_pop_len(); |
| 63 |
|
| 64 |
|
| 65 |
acpigen_write_store(); |
| 66 |
acpigen_emit_namestring("^FSUP"); |
| 67 |
acpigen_emit_byte(LOCAL2_OP); |
| 68 |
acpigen_emit_byte(family == TPM_1 ? ONE_OP : ZERO_OP); |
| 69 |
acpigen_emit_byte(LOCAL1_OP); |
| 70 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 0); |
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
acpigen_write_store(); |
| 88 |
acpigen_emit_namestring("^FSUP"); |
| 89 |
acpigen_emit_byte(LOCAL2_OP); |
| 90 |
acpigen_emit_byte(family == TPM_1 ? ZERO_OP : ONE_OP); |
| 91 |
acpigen_emit_byte(LOCAL1_OP); |
| 92 |
|
| 93 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 1); |
| 94 |
acpigen_write_return_integer(PPI2_RET_SUCCESS); |
| 95 |
acpigen_pop_len(); |
| 96 |
acpigen_write_return_integer(PPI2_RET_NOT_SUPPORTED); |
| 97 |
|
| 98 |
acpigen_pop_len(); |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
static void tpm_ppi_func0_cb(void *arg) |
| 104 |
{ |
| 105 |
|
| 106 |
u8 buf[] = {0xff, 0x01}; |
| 107 |
acpigen_write_return_byte_buffer(buf, 2); |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
static void tpm_ppi_func1_cb(void *arg) |
| 119 |
{ |
| 120 |
if (tlcl_get_family() == TPM_2) |
| 121 |
|
| 122 |
acpigen_write_return_string("1.3"); |
| 123 |
else |
| 124 |
|
| 125 |
acpigen_write_return_string("1.2"); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
static void tpm_ppi_func2_cb(void *arg) |
| 144 |
{ |
| 145 |
|
| 146 |
acpigen_write_to_integer(ARG1_OP, LOCAL0_OP); |
| 147 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, 1); |
| 148 |
|
| 149 |
|
| 150 |
verify_supported_ppi(ARG3_OP); |
| 151 |
|
| 152 |
acpigen_write_store_op_to_namestr(LOCAL2_OP, "^CMDR"); |
| 153 |
acpigen_write_store_op_to_namestr(ZERO_OP, "^OARG"); |
| 154 |
acpigen_write_store_op_to_namestr(ZERO_OP, "^USER"); |
| 155 |
|
| 156 |
acpigen_write_return_integer(PPI2_RET_SUCCESS); |
| 157 |
acpigen_pop_len(); |
| 158 |
|
| 159 |
acpigen_write_return_integer(PPI2_RET_GENERAL_FAILURE); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
static void tpm_ppi_func3_cb(void *arg) |
| 180 |
{ |
| 181 |
acpigen_write_store(); |
| 182 |
acpigen_write_integer(PPI3_RET_GENERAL_FAILURE); |
| 183 |
acpigen_emit_byte(LOCAL0_OP); |
| 184 |
|
| 185 |
|
| 186 |
set_package_element_op("^TPM3", 0, LOCAL0_OP); |
| 187 |
|
| 188 |
|
| 189 |
set_package_element_op("^TPM2", 0, LOCAL0_OP); |
| 190 |
|
| 191 |
acpigen_write_to_integer(ARG1_OP, LOCAL0_OP); |
| 192 |
|
| 193 |
|
| 194 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, 1); |
| 195 |
|
| 196 |
|
| 197 |
acpigen_write_store(); |
| 198 |
acpigen_write_integer(PPI3_RET_SUCCESS); |
| 199 |
acpigen_emit_byte(LOCAL1_OP); |
| 200 |
set_package_element_op("^TPM2", 0, LOCAL1_OP); |
| 201 |
|
| 202 |
|
| 203 |
set_package_element_name("^TPM2", 1, "^CMDR"); |
| 204 |
|
| 205 |
acpigen_emit_byte(RETURN_OP); |
| 206 |
acpigen_emit_namestring("^TPM2"); |
| 207 |
acpigen_pop_len(); |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, 2); |
| 216 |
|
| 217 |
|
| 218 |
acpigen_write_store(); |
| 219 |
acpigen_write_integer(PPI3_RET_SUCCESS); |
| 220 |
acpigen_emit_byte(LOCAL1_OP); |
| 221 |
set_package_element_op("^TPM3", 0, LOCAL1_OP); |
| 222 |
|
| 223 |
|
| 224 |
set_package_element_name("^TPM3", 1, "^CMDR"); |
| 225 |
|
| 226 |
|
| 227 |
set_package_element_name("^TPM3", 2, "^OARG"); |
| 228 |
|
| 229 |
acpigen_emit_byte(RETURN_OP); |
| 230 |
acpigen_emit_namestring("^TPM3"); |
| 231 |
acpigen_pop_len(); |
| 232 |
|
| 233 |
acpigen_emit_byte(RETURN_OP); |
| 234 |
acpigen_emit_namestring("^TPM3"); |
| 235 |
} |
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
static void tpm_ppi_func4_cb(void *arg) |
| 251 |
{ |
| 252 |
|
| 253 |
acpigen_write_return_byte(PPI4_RET_REBOOT); |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
static void tpm_ppi_func5_cb(void *arg) |
| 274 |
{ |
| 275 |
|
| 276 |
acpigen_write_store(); |
| 277 |
acpigen_write_integer(PPI5_RET_GENERAL_FAILURE); |
| 278 |
acpigen_emit_byte(LOCAL1_OP); |
| 279 |
set_package_element_op("^TPM3", 0, LOCAL1_OP); |
| 280 |
|
| 281 |
acpigen_write_to_integer(ARG1_OP, LOCAL0_OP); |
| 282 |
|
| 283 |
|
| 284 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, 1); |
| 285 |
|
| 286 |
|
| 287 |
acpigen_write_store(); |
| 288 |
acpigen_write_integer(PPI5_RET_SUCCESS); |
| 289 |
acpigen_emit_byte(LOCAL1_OP); |
| 290 |
set_package_element_op("^TPM3", 0, LOCAL1_OP); |
| 291 |
|
| 292 |
|
| 293 |
set_package_element_name("^TPM3", 1, "^LCMD"); |
| 294 |
|
| 295 |
|
| 296 |
set_package_element_name("^TPM3", 2, "^RESU"); |
| 297 |
|
| 298 |
acpigen_pop_len(); |
| 299 |
|
| 300 |
acpigen_emit_byte(RETURN_OP); |
| 301 |
acpigen_emit_namestring("^TPM3"); |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
static void tpm_ppi_func6_cb(void *arg) |
| 312 |
{ |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
acpigen_write_return_byte(PPI6_RET_NOT_IMPLEMENTED); |
| 318 |
} |
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
static void tpm_ppi_func7_cb(void *arg) |
| 335 |
{ |
| 336 |
acpigen_write_to_integer(ARG1_OP, LOCAL0_OP); |
| 337 |
|
| 338 |
|
| 339 |
verify_supported_ppi(ARG3_OP); |
| 340 |
|
| 341 |
|
| 342 |
acpigen_write_store(); |
| 343 |
acpigen_emit_byte(OBJ_TYPE_OP); |
| 344 |
acpigen_emit_byte(ARG3_OP); |
| 345 |
acpigen_emit_byte(LOCAL1_OP); |
| 346 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 3); |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
acpigen_write_store(); |
| 352 |
acpigen_emit_byte(ONE_OP); |
| 353 |
acpigen_emit_byte(LOCAL0_OP); |
| 354 |
|
| 355 |
acpigen_pop_len(); |
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, 1); |
| 361 |
|
| 362 |
|
| 363 |
acpigen_write_store_op_to_namestr(LOCAL2_OP, "^CMDR"); |
| 364 |
|
| 365 |
|
| 366 |
acpigen_write_store_op_to_namestr(ZERO_OP, "^OARG"); |
| 367 |
|
| 368 |
acpigen_write_return_byte(PPI7_RET_SUCCESS); |
| 369 |
acpigen_pop_len(); |
| 370 |
|
| 371 |
|
| 372 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, 2); |
| 373 |
|
| 374 |
acpigen_write_store_op_to_namestr(LOCAL2_OP, "^CMDR"); |
| 375 |
|
| 376 |
|
| 377 |
acpigen_get_package_op_element(ARG3_OP, 1, LOCAL3_OP); |
| 378 |
acpigen_write_store(); |
| 379 |
acpigen_emit_byte(LOCAL3_OP); |
| 380 |
acpigen_emit_namestring("^OARG"); |
| 381 |
|
| 382 |
acpigen_write_return_byte(PPI7_RET_SUCCESS); |
| 383 |
acpigen_pop_len(); |
| 384 |
|
| 385 |
acpigen_write_return_byte(PPI7_RET_GENERAL_FAILURE); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
static void tpm_ppi_func8_cb(void *arg) |
| 405 |
{ |
| 406 |
enum tpm_family family = tlcl_get_family(); |
| 407 |
|
| 408 |
acpigen_write_to_integer(ARG1_OP, LOCAL0_OP); |
| 409 |
|
| 410 |
|
| 411 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, 1); |
| 412 |
acpigen_get_package_op_element(ARG3_OP, 0, LOCAL2_OP); |
| 413 |
|
| 414 |
|
| 415 |
acpigen_write_store(); |
| 416 |
acpigen_emit_namestring("^FSUP"); |
| 417 |
acpigen_emit_byte(LOCAL2_OP); |
| 418 |
acpigen_emit_byte(family == TPM_1 ? ONE_OP : ZERO_OP); |
| 419 |
acpigen_emit_byte(LOCAL1_OP); |
| 420 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 0); |
| 421 |
acpigen_write_return_byte(0); |
| 422 |
acpigen_pop_len(); |
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
if (family == TPM_1) { |
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
static const u32 tpm1_funcs[] = { |
| 432 |
TPM_NOOP, |
| 433 |
TPM_SET_NOPPICLEAR_TRUE, |
| 434 |
TPM_SET_NOPPIMAINTAINANCE_TRUE, |
| 435 |
TPM_SET_NOPPIPROVISION_TRUE, |
| 436 |
}; |
| 437 |
for (size_t i = 0; i < ARRAY_SIZE(tpm1_funcs); i++) { |
| 438 |
acpigen_write_if_lequal_op_int(LOCAL2_OP, tpm1_funcs[i]); |
| 439 |
acpigen_write_return_integer(PPI8_RET_ALLOWED); |
| 440 |
acpigen_pop_len(); |
| 441 |
} |
| 442 |
} else if (family == TPM_2) { |
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
static const u32 tpm2_funcs[] = { |
| 448 |
TPM2_NOOP, |
| 449 |
TPM2_SET_PP_REQUIRED_FOR_CLEAR_TRUE, |
| 450 |
TPM2_SET_PP_REQUIRED_FOR_CHANGE_PCRS_TRUE, |
| 451 |
TPM2_SET_PP_REQUIRED_FOR_TURN_ON_TRUE, |
| 452 |
TPM2_SET_PP_REQUIRED_FOR_CHANGE_EPS_TRUE, |
| 453 |
TPM2_SET_PP_REQUIRED_FOR_TURN_OFF_TRUE, |
| 454 |
TPM2_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_TRUE, |
| 455 |
TPM2_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_TRUE, |
| 456 |
}; |
| 457 |
for (size_t i = 0; i < ARRAY_SIZE(tpm2_funcs); i++) { |
| 458 |
acpigen_write_if_lequal_op_int(LOCAL2_OP, tpm2_funcs[i]); |
| 459 |
acpigen_write_return_integer(PPI8_RET_ALLOWED); |
| 460 |
acpigen_pop_len(); |
| 461 |
} |
| 462 |
} |
| 463 |
acpigen_write_return_integer(PPI8_RET_ALLOWED_WITH_PP); |
| 464 |
|
| 465 |
acpigen_pop_len(); |
| 466 |
|
| 467 |
acpigen_write_return_integer(PPI8_RET_NOT_IMPLEMENTED); |
| 468 |
} |
| 469 |
|
| 470 |
static void (*tpm_ppi_callbacks[])(void *) = { |
| 471 |
tpm_ppi_func0_cb, |
| 472 |
tpm_ppi_func1_cb, |
| 473 |
tpm_ppi_func2_cb, |
| 474 |
tpm_ppi_func3_cb, |
| 475 |
tpm_ppi_func4_cb, |
| 476 |
tpm_ppi_func5_cb, |
| 477 |
tpm_ppi_func6_cb, |
| 478 |
tpm_ppi_func7_cb, |
| 479 |
tpm_ppi_func8_cb, |
| 480 |
}; |
| 481 |
|
| 482 |
static void tpm_mci_func0_cb(void *arg) |
| 483 |
{ |
| 484 |
|
| 485 |
acpigen_write_return_singleton_buffer(0x3); |
| 486 |
} |
| 487 |
static void tpm_mci_func1_cb(void *arg) |
| 488 |
{ |
| 489 |
|
| 490 |
acpigen_write_return_byte(0); |
| 491 |
} |
| 492 |
|
| 493 |
static void (*tpm_mci_callbacks[])(void *) = { |
| 494 |
tpm_mci_func0_cb, |
| 495 |
tpm_mci_func1_cb, |
| 496 |
}; |
| 497 |
|
| 498 |
void tpm_ppi_acpi_fill_ssdt(const struct device *dev) |
| 499 |
{ |
| 500 |
struct cb_tpm_ppi_payload_handshake *ppib; |
| 501 |
|
| 502 |
static const struct fieldlist list[] = { |
| 503 |
FIELDLIST_OFFSET(0x100), |
| 504 |
FIELDLIST_NAMESTR("PPIN", 8), |
| 505 |
FIELDLIST_NAMESTR("PPIP", 32), |
| 506 |
FIELDLIST_NAMESTR("RESU", 32), |
| 507 |
FIELDLIST_NAMESTR("CMDR", 32), |
| 508 |
FIELDLIST_NAMESTR("OARG", 32), |
| 509 |
FIELDLIST_NAMESTR("LCMD", 32), |
| 510 |
FIELDLIST_NAMESTR("FRET", 32), |
| 511 |
}; |
| 512 |
static const u8 tpm1_funcs[] = { |
| 513 |
TPM_NOOP, |
| 514 |
TPM_ENABLE, |
| 515 |
TPM_DISABLE, |
| 516 |
TPM_ACTIVATE, |
| 517 |
TPM_DEACTIVATE, |
| 518 |
TPM_CLEAR, |
| 519 |
TPM_ENABLE_ACTIVATE, |
| 520 |
TPM_DEACTIVATE_DISABLE, |
| 521 |
TPM_SETOWNERINSTALL_TRUE, |
| 522 |
TPM_SETOWNERINSTALL_FALSE, |
| 523 |
TPM_ENABLE_ACTIVATE_SETOWNERINSTALL_TRUE, |
| 524 |
TPM_SETOWNERINSTALL_FALSE_DEACTIVATE_DISABLE, |
| 525 |
TPM_CLEAR_ENABLE_ACTIVATE, |
| 526 |
TPM_SET_NOPPIPROVISION_FALSE, |
| 527 |
TPM_SET_NOPPIPROVISION_TRUE, |
| 528 |
TPM_ENABLE_ACTIVE_CLEAR, |
| 529 |
TPM_ENABLE_ACTIVE_CLEAR_ENABLE_ACTIVE, |
| 530 |
}; |
| 531 |
static const u8 tpm2_funcs[] = { |
| 532 |
TPM2_NOOP, |
| 533 |
TPM2_ENABLE, |
| 534 |
TPM2_DISABLE, |
| 535 |
TPM2_CLEAR, |
| 536 |
TPM2_CLEAR_ENABLE_ACTIVE, |
| 537 |
TPM2_SET_PP_REQUIRED_FOR_CLEAR_TRUE, |
| 538 |
TPM2_SET_PP_REQUIRED_FOR_CLEAR_FALSE, |
| 539 |
TPM2_ENABLE_CLEAR, |
| 540 |
TPM2_ENABLE_CLEAR2, |
| 541 |
TPM2_SET_PCR_BANKS, |
| 542 |
TPM2_CHANGE_EPS, |
| 543 |
TPM2_SET_PP_REQUIRED_FOR_CHANGE_PCRS_FALSE, |
| 544 |
TPM2_SET_PP_REQUIRED_FOR_CHANGE_PCRS_TRUE, |
| 545 |
TPM2_SET_PP_REQUIRED_FOR_TURN_ON_FALSE, |
| 546 |
TPM2_SET_PP_REQUIRED_FOR_TURN_ON_TRUE, |
| 547 |
TPM2_SET_PP_REQUIRED_FOR_TURN_OFF_FALSE, |
| 548 |
TPM2_SET_PP_REQUIRED_FOR_TURN_OFF_TRUE, |
| 549 |
TPM2_SET_PP_REQUIRED_FOR_CHANGE_EPS_FALSE, |
| 550 |
TPM2_SET_PP_REQUIRED_FOR_CHANGE_EPS_TRUE, |
| 551 |
TPM2_LOG_ALL_DIGEST, |
| 552 |
TPM2_DISABLE_ENDORSMENT_ENABLE_STORAGE_HISTORY, |
| 553 |
TPM2_ENABLE_BLOCK_SID, |
| 554 |
TPM2_DISABLE_BLOCK_SID, |
| 555 |
TPM2_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_TRUE, |
| 556 |
TPM2_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FALSE, |
| 557 |
TPM2_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_TRUE, |
| 558 |
TPM2_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FALSE, |
| 559 |
}; |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
ppib = (void *)cbmem_add(CBMEM_ID_TPM_PPI, sizeof(*ppib)); |
| 565 |
if (!ppib) { |
| 566 |
printk(BIOS_ERR, "PPI: Failed to add CBMEM\n"); |
| 567 |
return; |
| 568 |
} |
| 569 |
printk(BIOS_DEBUG, "PPI: Pending OS request: 0x%x (0x%x)\n", ppib->pprq, ppib->pprm); |
| 570 |
printk(BIOS_DEBUG, "PPI: OS response: CMD 0x%x = 0x%x\n", ppib->lppr, ppib->pprp); |
| 571 |
|
| 572 |
enum tpm_family family = tlcl_get_family(); |
| 573 |
if (family == TPM_UNKNOWN) { |
| 574 |
printk(BIOS_WARNING, "PPI: %s: aborting, because no TPM detected\n", __func__); |
| 575 |
return; |
| 576 |
} |
| 577 |
|
| 578 |
|
| 579 |
ppib->next_step = 0; |
| 580 |
ppib->ppin = 1; |
| 581 |
ppib->ppip = 0; |
| 582 |
ppib->fret = 0; |
| 583 |
ppib->next_step = 0; |
| 584 |
|
| 585 |
bool found = false; |
| 586 |
|
| 587 |
memset(ppib->func, 0, sizeof(ppib->func)); |
| 588 |
if (family == TPM_1) { |
| 589 |
for (size_t i = 0; i < ARRAY_SIZE(tpm1_funcs); i++) { |
| 590 |
ppib->func[tpm1_funcs[i]] = 1; |
| 591 |
if (ppib->pprq == tpm1_funcs[i]) |
| 592 |
found = true; |
| 593 |
} |
| 594 |
} else { |
| 595 |
for (size_t i = 0; i < ARRAY_SIZE(tpm2_funcs); i++) { |
| 596 |
ppib->func[tpm2_funcs[i]] = 1; |
| 597 |
if (ppib->pprq == tpm2_funcs[i]) |
| 598 |
found = true; |
| 599 |
} |
| 600 |
} |
| 601 |
if (!found) { |
| 602 |
|
| 603 |
ppib->pprq = 0; |
| 604 |
ppib->pprm = 0; |
| 605 |
ppib->pprp = 0; |
| 606 |
} |
| 607 |
|
| 608 |
|
| 609 |
struct opregion opreg = OPREGION("PPOP", SYSTEMMEMORY, (uintptr_t)ppib, |
| 610 |
sizeof(*ppib)); |
| 611 |
|
| 612 |
acpigen_write_opregion(&opreg); |
| 613 |
acpigen_write_field(opreg.name, list, ARRAY_SIZE(list), |
| 614 |
FIELD_ANYACC | FIELD_NOLOCK | FIELD_PRESERVE); |
| 615 |
|
| 616 |
acpigen_write_name("TPM2"); |
| 617 |
acpigen_write_package(2); |
| 618 |
acpigen_write_dword(0); |
| 619 |
acpigen_write_dword(0); |
| 620 |
acpigen_pop_len(); |
| 621 |
|
| 622 |
acpigen_write_name("TPM3"); |
| 623 |
acpigen_write_package(3); |
| 624 |
acpigen_write_dword(0); |
| 625 |
acpigen_write_dword(0); |
| 626 |
acpigen_write_dword(0); |
| 627 |
acpigen_pop_len(); |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
acpigen_write_method_serialized("FUNC", 1); |
| 635 |
|
| 636 |
acpigen_write_to_integer(ARG0_OP, LOCAL0_OP); |
| 637 |
acpigen_write_if(); |
| 638 |
acpigen_emit_byte(LGREATER_OP); |
| 639 |
acpigen_emit_byte(LOCAL0_OP); |
| 640 |
acpigen_write_integer(VENDOR_SPECIFIC_OFFSET); |
| 641 |
acpigen_write_return_integer(0); |
| 642 |
acpigen_pop_len(); |
| 643 |
|
| 644 |
|
| 645 |
acpigen_emit_byte(CREATE_BYTE_OP); |
| 646 |
acpigen_emit_namestring("PPOP"); |
| 647 |
acpigen_emit_byte(LOCAL0_OP); |
| 648 |
acpigen_emit_namestring("TPPF"); |
| 649 |
|
| 650 |
|
| 651 |
acpigen_emit_byte(TO_INTEGER_OP); |
| 652 |
acpigen_emit_namestring("TPPF"); |
| 653 |
acpigen_emit_byte(LOCAL0_OP); |
| 654 |
|
| 655 |
acpigen_write_return_op(LOCAL0_OP); |
| 656 |
acpigen_pop_len(); |
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
acpigen_write_method("FSUP", 2); |
| 667 |
|
| 668 |
acpigen_write_to_integer(ARG0_OP, LOCAL0_OP); |
| 669 |
acpigen_write_to_integer(ARG1_OP, LOCAL1_OP); |
| 670 |
acpigen_write_if(); |
| 671 |
acpigen_emit_byte(LGREATER_OP); |
| 672 |
acpigen_emit_byte(LOCAL0_OP); |
| 673 |
acpigen_write_integer(VENDOR_SPECIFIC_OFFSET); |
| 674 |
acpigen_write_return_integer(0); |
| 675 |
acpigen_pop_len(); |
| 676 |
|
| 677 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 1); |
| 678 |
for (size_t i = 0; i < ARRAY_SIZE(tpm1_funcs); i++) { |
| 679 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, tpm1_funcs[i]); |
| 680 |
acpigen_write_return_integer(1); |
| 681 |
acpigen_pop_len(); |
| 682 |
} |
| 683 |
acpigen_pop_len(); |
| 684 |
|
| 685 |
acpigen_write_if_lequal_op_int(LOCAL1_OP, 0); |
| 686 |
|
| 687 |
for (size_t i = 0; i < ARRAY_SIZE(tpm2_funcs); i++) { |
| 688 |
acpigen_write_if_lequal_op_int(LOCAL0_OP, tpm2_funcs[i]); |
| 689 |
acpigen_write_return_integer(1); |
| 690 |
acpigen_pop_len(); |
| 691 |
} |
| 692 |
acpigen_pop_len(); |
| 693 |
|
| 694 |
acpigen_write_return_integer(0); |
| 695 |
acpigen_pop_len(); |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
struct dsm_uuid ids[] = { |
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
DSM_UUID(TPM_PPI_UUID, &tpm_ppi_callbacks[0], |
| 707 |
ARRAY_SIZE(tpm_ppi_callbacks), NULL), |
| 708 |
|
| 709 |
DSM_UUID(TPM_MCI_UUID, &tpm_mci_callbacks[0], |
| 710 |
ARRAY_SIZE(tpm_mci_callbacks), NULL), |
| 711 |
}; |
| 712 |
|
| 713 |
acpigen_write_dsm_uuid_arr(ids, ARRAY_SIZE(ids)); |
| 714 |
} |
| 715 |
|
| 716 |
void lb_tpm_ppi(struct lb_header *header) |
| 717 |
{ |
| 718 |
struct lb_tpm_physical_presence *tpm_ppi; |
| 719 |
enum tpm_family family; |
| 720 |
void *ppib; |
| 721 |
|
| 722 |
ppib = cbmem_find(CBMEM_ID_TPM_PPI); |
| 723 |
if (!ppib) |
| 724 |
return; |
| 725 |
|
| 726 |
family = tlcl_get_family(); |
| 727 |
if (family == TPM_UNKNOWN) { |
| 728 |
printk(BIOS_WARNING, "PPI: %s: aborting, because no TPM detected\n", __func__); |
| 729 |
return; |
| 730 |
} |
| 731 |
|
| 732 |
tpm_ppi = (struct lb_tpm_physical_presence *)lb_new_record(header); |
| 733 |
tpm_ppi->tag = LB_TAG_TPM_PPI_HANDOFF; |
| 734 |
tpm_ppi->size = sizeof(*tpm_ppi); |
| 735 |
tpm_ppi->ppi_address = (uintptr_t)ppib; |
| 736 |
tpm_ppi->tpm_version = family == TPM_1 ? LB_TPM_VERSION_TPM_VERSION_1_2 : |
| 737 |
LB_TPM_VERSION_TPM_VERSION_2; |
| 738 |
|
| 739 |
tpm_ppi->ppi_version = BCD(1, 3); |
| 740 |
} |