|
14 | 14 | #include <linux/acpi.h>
|
15 | 15 | #include <linux/platform_profile.h>
|
16 | 16 |
|
| 17 | +#define POLICY_BUF_MAX_SZ 0x4b000 |
| 18 | +#define POLICY_SIGN_COOKIE 0x31535024 |
| 19 | +#define POLICY_COOKIE_OFFSET 0x10 |
| 20 | +#define POLICY_COOKIE_LEN 0x14 |
| 21 | + |
17 | 22 | /* APMF Functions */
|
18 | 23 | #define APMF_FUNC_VERIFY_INTERFACE 0
|
19 | 24 | #define APMF_FUNC_GET_SYS_PARAMS 1
|
|
59 | 64 | #define ARG_NONE 0
|
60 | 65 | #define AVG_SAMPLE_SIZE 3
|
61 | 66 |
|
| 67 | +/* Policy Actions */ |
| 68 | +#define PMF_POLICY_SPL 2 |
| 69 | +#define PMF_POLICY_SPPT 3 |
| 70 | +#define PMF_POLICY_FPPT 4 |
| 71 | +#define PMF_POLICY_SPPT_APU_ONLY 5 |
| 72 | +#define PMF_POLICY_STT_MIN 6 |
| 73 | +#define PMF_POLICY_STT_SKINTEMP_APU 7 |
| 74 | +#define PMF_POLICY_STT_SKINTEMP_HS2 8 |
| 75 | + |
62 | 76 | /* TA macros */
|
63 | 77 | #define PMF_TA_IF_VERSION_MAJOR 1
|
| 78 | +#define TA_PMF_ACTION_MAX 32 |
| 79 | +#define TA_PMF_UNDO_MAX 8 |
| 80 | +#define TA_OUTPUT_RESERVED_MEM 906 |
| 81 | +#define MAX_OPERATION_PARAMS 4 |
64 | 82 |
|
65 | 83 | /* AMD PMF BIOS interfaces */
|
66 | 84 | struct apmf_verify_interface {
|
@@ -183,11 +201,16 @@ struct amd_pmf_dev {
|
183 | 201 | bool cnqf_supported;
|
184 | 202 | struct notifier_block pwr_src_notifier;
|
185 | 203 | /* Smart PC solution builder */
|
| 204 | + unsigned char *policy_buf; |
| 205 | + u32 policy_sz; |
186 | 206 | struct tee_context *tee_ctx;
|
187 | 207 | struct tee_shm *fw_shm_pool;
|
188 | 208 | u32 session_id;
|
189 | 209 | void *shbuf;
|
190 | 210 | struct delayed_work pb_work;
|
| 211 | + struct pmf_action_table *prev_data; |
| 212 | + u64 policy_addr; |
| 213 | + void *policy_base; |
191 | 214 | bool smart_pc_enabled;
|
192 | 215 | };
|
193 | 216 |
|
@@ -399,17 +422,134 @@ struct apmf_dyn_slider_output {
|
399 | 422 | struct apmf_cnqf_power_set ps[APMF_CNQF_MAX];
|
400 | 423 | } __packed;
|
401 | 424 |
|
| 425 | +enum smart_pc_status { |
| 426 | + PMF_SMART_PC_ENABLED, |
| 427 | + PMF_SMART_PC_DISABLED, |
| 428 | +}; |
| 429 | + |
| 430 | +/* Smart PC - TA internals */ |
| 431 | +enum ta_slider { |
| 432 | + TA_BEST_BATTERY, |
| 433 | + TA_BETTER_BATTERY, |
| 434 | + TA_BETTER_PERFORMANCE, |
| 435 | + TA_BEST_PERFORMANCE, |
| 436 | + TA_MAX, |
| 437 | +}; |
| 438 | + |
402 | 439 | /* Command ids for TA communication */
|
403 | 440 | enum ta_pmf_command {
|
404 | 441 | TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE,
|
405 | 442 | TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES,
|
406 | 443 | };
|
407 | 444 |
|
| 445 | +enum ta_pmf_error_type { |
| 446 | + TA_PMF_TYPE_SUCCESS, |
| 447 | + TA_PMF_ERROR_TYPE_GENERIC, |
| 448 | + TA_PMF_ERROR_TYPE_CRYPTO, |
| 449 | + TA_PMF_ERROR_TYPE_CRYPTO_VALIDATE, |
| 450 | + TA_PMF_ERROR_TYPE_CRYPTO_VERIFY_OEM, |
| 451 | + TA_PMF_ERROR_TYPE_POLICY_BUILDER, |
| 452 | + TA_PMF_ERROR_TYPE_PB_CONVERT, |
| 453 | + TA_PMF_ERROR_TYPE_PB_SETUP, |
| 454 | + TA_PMF_ERROR_TYPE_PB_ENACT, |
| 455 | + TA_PMF_ERROR_TYPE_ASD_GET_DEVICE_INFO, |
| 456 | + TA_PMF_ERROR_TYPE_ASD_GET_DEVICE_PCIE_INFO, |
| 457 | + TA_PMF_ERROR_TYPE_SYS_DRV_FW_VALIDATION, |
| 458 | + TA_PMF_ERROR_TYPE_MAX, |
| 459 | +}; |
| 460 | + |
| 461 | +struct pmf_action_table { |
| 462 | + u32 spl; /* in mW */ |
| 463 | + u32 sppt; /* in mW */ |
| 464 | + u32 sppt_apuonly; /* in mW */ |
| 465 | + u32 fppt; /* in mW */ |
| 466 | + u32 stt_minlimit; /* in mW */ |
| 467 | + u32 stt_skintemp_apu; /* in C */ |
| 468 | + u32 stt_skintemp_hs2; /* in C */ |
| 469 | +}; |
| 470 | + |
| 471 | +/* Input conditions */ |
| 472 | +struct ta_pmf_condition_info { |
| 473 | + u32 power_source; |
| 474 | + u32 bat_percentage; |
| 475 | + u32 power_slider; |
| 476 | + u32 lid_state; |
| 477 | + bool user_present; |
| 478 | + u32 rsvd1[2]; |
| 479 | + u32 monitor_count; |
| 480 | + u32 rsvd2[2]; |
| 481 | + u32 bat_design; |
| 482 | + u32 full_charge_capacity; |
| 483 | + int drain_rate; |
| 484 | + bool user_engaged; |
| 485 | + u32 device_state; |
| 486 | + u32 socket_power; |
| 487 | + u32 skin_temperature; |
| 488 | + u32 rsvd3[5]; |
| 489 | + u32 ambient_light; |
| 490 | + u32 length; |
| 491 | + u32 avg_c0residency; |
| 492 | + u32 max_c0residency; |
| 493 | + u32 s0i3_entry; |
| 494 | + u32 gfx_busy; |
| 495 | + u32 rsvd4[7]; |
| 496 | + bool camera_state; |
| 497 | + u32 workload_type; |
| 498 | + u32 display_type; |
| 499 | + u32 display_state; |
| 500 | + u32 rsvd5[150]; |
| 501 | +}; |
| 502 | + |
| 503 | +struct ta_pmf_load_policy_table { |
| 504 | + u32 table_size; |
| 505 | + u8 table[POLICY_BUF_MAX_SZ]; |
| 506 | +}; |
| 507 | + |
| 508 | +/* TA initialization params */ |
| 509 | +struct ta_pmf_init_table { |
| 510 | + u32 frequency; /* SMU sampling frequency */ |
| 511 | + bool validate; |
| 512 | + bool sku_check; |
| 513 | + bool metadata_macrocheck; |
| 514 | + struct ta_pmf_load_policy_table policies_table; |
| 515 | +}; |
| 516 | + |
| 517 | +/* Everything the TA needs to Enact Policies */ |
| 518 | +struct ta_pmf_enact_table { |
| 519 | + struct ta_pmf_condition_info ev_info; |
| 520 | + u32 name; |
| 521 | +}; |
| 522 | + |
| 523 | +struct ta_pmf_action { |
| 524 | + u32 action_index; |
| 525 | + u32 value; |
| 526 | +}; |
| 527 | + |
| 528 | +/* Output actions from TA */ |
| 529 | +struct ta_pmf_enact_result { |
| 530 | + u32 actions_count; |
| 531 | + struct ta_pmf_action actions_list[TA_PMF_ACTION_MAX]; |
| 532 | + u32 undo_count; |
| 533 | + struct ta_pmf_action undo_list[TA_PMF_UNDO_MAX]; |
| 534 | +}; |
| 535 | + |
| 536 | +union ta_pmf_input { |
| 537 | + struct ta_pmf_enact_table enact_table; |
| 538 | + struct ta_pmf_init_table init_table; |
| 539 | +}; |
| 540 | + |
| 541 | +union ta_pmf_output { |
| 542 | + struct ta_pmf_enact_result policy_apply_table; |
| 543 | + u32 rsvd[TA_OUTPUT_RESERVED_MEM]; |
| 544 | +}; |
| 545 | + |
408 | 546 | struct ta_pmf_shared_memory {
|
409 | 547 | int command_id;
|
410 | 548 | int resp_id;
|
411 | 549 | u32 pmf_result;
|
412 | 550 | u32 if_version;
|
| 551 | + union ta_pmf_output pmf_output; |
| 552 | + union ta_pmf_input pmf_input; |
413 | 553 | };
|
414 | 554 |
|
415 | 555 | /* Core Layer */
|
@@ -460,4 +600,5 @@ extern const struct attribute_group cnqf_feature_attribute_group;
|
460 | 600 | /* Smart PC builder Layer */
|
461 | 601 | int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev);
|
462 | 602 | void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev);
|
| 603 | +int apmf_check_smart_pc(struct amd_pmf_dev *pmf_dev); |
463 | 604 | #endif /* PMF_H */
|
0 commit comments