Lines Matching full:dev

47 static void amd_pmf_prepare_args(struct amd_pmf_dev *dev, int cmd,  in amd_pmf_prepare_args()  argument
55 arg->session = dev->session_id; in amd_pmf_prepare_args()
61 param[0].u.memref.shm = dev->fw_shm_pool; in amd_pmf_prepare_args()
65 static void amd_pmf_update_uevents(struct amd_pmf_dev *dev, u16 event) in amd_pmf_update_uevents() argument
67 input_report_key(dev->pmf_idev, event, 1); /* key press */ in amd_pmf_update_uevents()
68 input_sync(dev->pmf_idev); in amd_pmf_update_uevents()
69 input_report_key(dev->pmf_idev, event, 0); /* key release */ in amd_pmf_update_uevents()
70 input_sync(dev->pmf_idev); in amd_pmf_update_uevents()
73 static void amd_pmf_apply_policies(struct amd_pmf_dev *dev, struct ta_pmf_enact_result *out) in amd_pmf_apply_policies() argument
82 if (dev->prev_data->spl != val) { in amd_pmf_apply_policies()
83 amd_pmf_send_cmd(dev, SET_SPL, false, val, NULL); in amd_pmf_apply_policies()
84 dev_dbg(dev->dev, "update SPL: %u\n", val); in amd_pmf_apply_policies()
85 dev->prev_data->spl = val; in amd_pmf_apply_policies()
90 if (dev->prev_data->sppt != val) { in amd_pmf_apply_policies()
91 amd_pmf_send_cmd(dev, SET_SPPT, false, val, NULL); in amd_pmf_apply_policies()
92 dev_dbg(dev->dev, "update SPPT: %u\n", val); in amd_pmf_apply_policies()
93 dev->prev_data->sppt = val; in amd_pmf_apply_policies()
98 if (dev->prev_data->fppt != val) { in amd_pmf_apply_policies()
99 amd_pmf_send_cmd(dev, SET_FPPT, false, val, NULL); in amd_pmf_apply_policies()
100 dev_dbg(dev->dev, "update FPPT: %u\n", val); in amd_pmf_apply_policies()
101 dev->prev_data->fppt = val; in amd_pmf_apply_policies()
106 if (dev->prev_data->sppt_apuonly != val) { in amd_pmf_apply_policies()
107 amd_pmf_send_cmd(dev, SET_SPPT_APU_ONLY, false, val, NULL); in amd_pmf_apply_policies()
108 dev_dbg(dev->dev, "update SPPT_APU_ONLY: %u\n", val); in amd_pmf_apply_policies()
109 dev->prev_data->sppt_apuonly = val; in amd_pmf_apply_policies()
114 if (dev->prev_data->stt_minlimit != val) { in amd_pmf_apply_policies()
115 amd_pmf_send_cmd(dev, SET_STT_MIN_LIMIT, false, val, NULL); in amd_pmf_apply_policies()
116 dev_dbg(dev->dev, "update STT_MIN: %u\n", val); in amd_pmf_apply_policies()
117 dev->prev_data->stt_minlimit = val; in amd_pmf_apply_policies()
122 if (dev->prev_data->stt_skintemp_apu != val) { in amd_pmf_apply_policies()
123 amd_pmf_send_cmd(dev, SET_STT_LIMIT_APU, false, val, NULL); in amd_pmf_apply_policies()
124 dev_dbg(dev->dev, "update STT_SKINTEMP_APU: %u\n", val); in amd_pmf_apply_policies()
125 dev->prev_data->stt_skintemp_apu = val; in amd_pmf_apply_policies()
130 if (dev->prev_data->stt_skintemp_hs2 != val) { in amd_pmf_apply_policies()
131 amd_pmf_send_cmd(dev, SET_STT_LIMIT_HS2, false, val, NULL); in amd_pmf_apply_policies()
132 dev_dbg(dev->dev, "update STT_SKINTEMP_HS2: %u\n", val); in amd_pmf_apply_policies()
133 dev->prev_data->stt_skintemp_hs2 = val; in amd_pmf_apply_policies()
138 if (dev->prev_data->p3t_limit != val) { in amd_pmf_apply_policies()
139 amd_pmf_send_cmd(dev, SET_P3T, false, val, NULL); in amd_pmf_apply_policies()
140 dev_dbg(dev->dev, "update P3T: %u\n", val); in amd_pmf_apply_policies()
141 dev->prev_data->p3t_limit = val; in amd_pmf_apply_policies()
148 amd_pmf_update_uevents(dev, KEY_SLEEP); in amd_pmf_apply_policies()
151 amd_pmf_update_uevents(dev, KEY_SUSPEND); in amd_pmf_apply_policies()
154 amd_pmf_update_uevents(dev, KEY_SCREENLOCK); in amd_pmf_apply_policies()
157 dev_err(dev->dev, "Invalid PMF policy system state: %d\n", val); in amd_pmf_apply_policies()
160 dev_dbg(dev->dev, "update SYSTEM_STATE: %s\n", in amd_pmf_apply_policies()
165 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(0), 0); in amd_pmf_apply_policies()
169 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(1), 1); in amd_pmf_apply_policies()
173 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(2), 2); in amd_pmf_apply_policies()
177 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(3), 3); in amd_pmf_apply_policies()
181 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(4), 4); in amd_pmf_apply_policies()
185 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(5), 5); in amd_pmf_apply_policies()
189 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(6), 6); in amd_pmf_apply_policies()
193 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(7), 7); in amd_pmf_apply_policies()
197 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(8), 8); in amd_pmf_apply_policies()
201 amd_pmf_smartpc_apply_bios_output(dev, val, BIT(9), 9); in amd_pmf_apply_policies()
207 static int amd_pmf_invoke_cmd_enact(struct amd_pmf_dev *dev) in amd_pmf_invoke_cmd_enact() argument
216 if (!dev->tee_ctx) in amd_pmf_invoke_cmd_enact()
219 memset(dev->shbuf, 0, dev->policy_sz); in amd_pmf_invoke_cmd_enact()
220 ta_sm = dev->shbuf; in amd_pmf_invoke_cmd_enact()
228 amd_pmf_populate_ta_inputs(dev, in); in amd_pmf_invoke_cmd_enact()
229 amd_pmf_prepare_args(dev, TA_PMF_COMMAND_POLICY_BUILDER_ENACT_POLICIES, &arg, param); in amd_pmf_invoke_cmd_enact()
231 ret = tee_client_invoke_func(dev->tee_ctx, &arg, param); in amd_pmf_invoke_cmd_enact()
233 dev_err(dev->dev, "TEE enact cmd failed. err: %x, ret:%d\n", arg.ret, ret); in amd_pmf_invoke_cmd_enact()
238 amd_pmf_dump_ta_inputs(dev, in); in amd_pmf_invoke_cmd_enact()
239 dev_dbg(dev->dev, "action count:%u result:%x\n", out->actions_count, in amd_pmf_invoke_cmd_enact()
241 amd_pmf_apply_policies(dev, out); in amd_pmf_invoke_cmd_enact()
247 static int amd_pmf_invoke_cmd_init(struct amd_pmf_dev *dev) in amd_pmf_invoke_cmd_init() argument
255 if (!dev->tee_ctx) { in amd_pmf_invoke_cmd_init()
256 dev_err(dev->dev, "Failed to get TEE context\n"); in amd_pmf_invoke_cmd_init()
260 dev_dbg(dev->dev, "Policy Binary size: %u bytes\n", dev->policy_sz); in amd_pmf_invoke_cmd_init()
261 memset(dev->shbuf, 0, dev->policy_sz); in amd_pmf_invoke_cmd_init()
262 ta_sm = dev->shbuf; in amd_pmf_invoke_cmd_init()
272 in->policies_table.table_size = dev->policy_sz; in amd_pmf_invoke_cmd_init()
274 memcpy(in->policies_table.table, dev->policy_buf, dev->policy_sz); in amd_pmf_invoke_cmd_init()
275 amd_pmf_prepare_args(dev, TA_PMF_COMMAND_POLICY_BUILDER_INITIALIZE, &arg, param); in amd_pmf_invoke_cmd_init()
277 ret = tee_client_invoke_func(dev->tee_ctx, &arg, param); in amd_pmf_invoke_cmd_init()
279 dev_err(dev->dev, "Failed to invoke TEE init cmd. err: %x, ret:%d\n", arg.ret, ret); in amd_pmf_invoke_cmd_init()
288 struct amd_pmf_dev *dev = container_of(work, struct amd_pmf_dev, pb_work.work); in amd_pmf_invoke_cmd() local
290 amd_pmf_invoke_cmd_enact(dev); in amd_pmf_invoke_cmd()
291 schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms)); in amd_pmf_invoke_cmd()
294 static int amd_pmf_start_policy_engine(struct amd_pmf_dev *dev) in amd_pmf_start_policy_engine() argument
299 if (dev->policy_sz < POLICY_COOKIE_OFFSET + sizeof(*header)) in amd_pmf_start_policy_engine()
302 header = (struct cookie_header *)(dev->policy_buf + POLICY_COOKIE_OFFSET); in amd_pmf_start_policy_engine()
305 dev_dbg(dev->dev, "cookie doesn't match\n"); in amd_pmf_start_policy_engine()
309 if (dev->policy_sz < header->length + 512) in amd_pmf_start_policy_engine()
313 dev->policy_sz = header->length + 512; in amd_pmf_start_policy_engine()
314 res = amd_pmf_invoke_cmd_init(dev); in amd_pmf_start_policy_engine()
317 dev->smart_pc_enabled = true; in amd_pmf_start_policy_engine()
322 schedule_delayed_work(&dev->pb_work, msecs_to_jiffies(pb_actions_ms * 3)); in amd_pmf_start_policy_engine()
324 dev_err(dev->dev, "ta invoke cmd init failed err: %x\n", res); in amd_pmf_start_policy_engine()
325 dev->smart_pc_enabled = false; in amd_pmf_start_policy_engine()
333 static void amd_pmf_hex_dump_pb(struct amd_pmf_dev *dev) in amd_pmf_hex_dump_pb() argument
335 print_hex_dump_debug("(pb): ", DUMP_PREFIX_OFFSET, 16, 1, dev->policy_buf, in amd_pmf_hex_dump_pb()
336 dev->policy_sz, false); in amd_pmf_hex_dump_pb()
342 struct amd_pmf_dev *dev = filp->private_data; in amd_pmf_get_pb_data() local
355 kfree(dev->policy_buf); in amd_pmf_get_pb_data()
356 dev->policy_buf = new_policy_buf; in amd_pmf_get_pb_data()
357 dev->policy_sz = length; in amd_pmf_get_pb_data()
359 amd_pmf_hex_dump_pb(dev); in amd_pmf_get_pb_data()
360 ret = amd_pmf_start_policy_engine(dev); in amd_pmf_get_pb_data()
372 static void amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root) in amd_pmf_open_pb() argument
374 dev->esbin = debugfs_create_dir("pb", debugfs_root); in amd_pmf_open_pb()
375 debugfs_create_file("update_policy", 0644, dev->esbin, dev, &pb_fops); in amd_pmf_open_pb()
378 static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) in amd_pmf_remove_pb() argument
380 debugfs_remove_recursive(dev->esbin); in amd_pmf_remove_pb()
383 static void amd_pmf_open_pb(struct amd_pmf_dev *dev, struct dentry *debugfs_root) {} in amd_pmf_open_pb() argument
384 static void amd_pmf_remove_pb(struct amd_pmf_dev *dev) {} in amd_pmf_remove_pb() argument
385 static void amd_pmf_hex_dump_pb(struct amd_pmf_dev *dev) {} in amd_pmf_hex_dump_pb() argument
413 static int amd_pmf_register_input_device(struct amd_pmf_dev *dev) in amd_pmf_register_input_device() argument
417 dev->pmf_idev = devm_input_allocate_device(dev->dev); in amd_pmf_register_input_device()
418 if (!dev->pmf_idev) in amd_pmf_register_input_device()
421 dev->pmf_idev->name = "PMF-TA output events"; in amd_pmf_register_input_device()
422 dev->pmf_idev->phys = "amd-pmf/input0"; in amd_pmf_register_input_device()
424 input_set_capability(dev->pmf_idev, EV_KEY, KEY_SLEEP); in amd_pmf_register_input_device()
425 input_set_capability(dev->pmf_idev, EV_KEY, KEY_SCREENLOCK); in amd_pmf_register_input_device()
426 input_set_capability(dev->pmf_idev, EV_KEY, KEY_SUSPEND); in amd_pmf_register_input_device()
428 err = input_register_device(dev->pmf_idev); in amd_pmf_register_input_device()
430 dev_err(dev->dev, "Failed to register input device: %d\n", err); in amd_pmf_register_input_device()
437 static int amd_pmf_tee_init(struct amd_pmf_dev *dev) in amd_pmf_tee_init() argument
442 dev->tee_ctx = tee_client_open_context(NULL, amd_pmf_amdtee_ta_match, NULL, NULL); in amd_pmf_tee_init()
443 if (IS_ERR(dev->tee_ctx)) { in amd_pmf_tee_init()
444 dev_err(dev->dev, "Failed to open TEE context\n"); in amd_pmf_tee_init()
445 return PTR_ERR(dev->tee_ctx); in amd_pmf_tee_init()
448 ret = amd_pmf_ta_open_session(dev->tee_ctx, &dev->session_id); in amd_pmf_tee_init()
450 dev_err(dev->dev, "Failed to open TA session (%d)\n", ret); in amd_pmf_tee_init()
455 size = sizeof(struct ta_pmf_shared_memory) + dev->policy_sz; in amd_pmf_tee_init()
456 dev->fw_shm_pool = tee_shm_alloc_kernel_buf(dev->tee_ctx, size); in amd_pmf_tee_init()
457 if (IS_ERR(dev->fw_shm_pool)) { in amd_pmf_tee_init()
458 dev_err(dev->dev, "Failed to alloc TEE shared memory\n"); in amd_pmf_tee_init()
459 ret = PTR_ERR(dev->fw_shm_pool); in amd_pmf_tee_init()
463 dev->shbuf = tee_shm_get_va(dev->fw_shm_pool, 0); in amd_pmf_tee_init()
464 if (IS_ERR(dev->shbuf)) { in amd_pmf_tee_init()
465 dev_err(dev->dev, "Failed to get TEE virtual address\n"); in amd_pmf_tee_init()
466 ret = PTR_ERR(dev->shbuf); in amd_pmf_tee_init()
469 dev_dbg(dev->dev, "TEE init done\n"); in amd_pmf_tee_init()
474 tee_shm_free(dev->fw_shm_pool); in amd_pmf_tee_init()
476 tee_client_close_session(dev->tee_ctx, dev->session_id); in amd_pmf_tee_init()
478 tee_client_close_context(dev->tee_ctx); in amd_pmf_tee_init()
483 static void amd_pmf_tee_deinit(struct amd_pmf_dev *dev) in amd_pmf_tee_deinit() argument
485 tee_shm_free(dev->fw_shm_pool); in amd_pmf_tee_deinit()
486 tee_client_close_session(dev->tee_ctx, dev->session_id); in amd_pmf_tee_deinit()
487 tee_client_close_context(dev->tee_ctx); in amd_pmf_tee_deinit()
490 int amd_pmf_init_smart_pc(struct amd_pmf_dev *dev) in amd_pmf_init_smart_pc() argument
494 ret = apmf_check_smart_pc(dev); in amd_pmf_init_smart_pc()
501 dev_info(dev->dev, "PMF Smart PC not advertised in BIOS!:%d\n", ret); in amd_pmf_init_smart_pc()
505 ret = amd_pmf_tee_init(dev); in amd_pmf_init_smart_pc()
509 INIT_DELAYED_WORK(&dev->pb_work, amd_pmf_invoke_cmd); in amd_pmf_init_smart_pc()
511 ret = amd_pmf_set_dram_addr(dev, true); in amd_pmf_init_smart_pc()
515 dev->policy_base = devm_ioremap(dev->dev, dev->policy_addr, dev->policy_sz); in amd_pmf_init_smart_pc()
516 if (!dev->policy_base) { in amd_pmf_init_smart_pc()
521 dev->policy_buf = kzalloc(dev->policy_sz, GFP_KERNEL); in amd_pmf_init_smart_pc()
522 if (!dev->policy_buf) { in amd_pmf_init_smart_pc()
527 memcpy_fromio(dev->policy_buf, dev->policy_base, dev->policy_sz); in amd_pmf_init_smart_pc()
529 amd_pmf_hex_dump_pb(dev); in amd_pmf_init_smart_pc()
531 dev->prev_data = kzalloc(sizeof(*dev->prev_data), GFP_KERNEL); in amd_pmf_init_smart_pc()
532 if (!dev->prev_data) { in amd_pmf_init_smart_pc()
537 ret = amd_pmf_start_policy_engine(dev); in amd_pmf_init_smart_pc()
542 amd_pmf_open_pb(dev, dev->dbgfs_dir); in amd_pmf_init_smart_pc()
544 ret = amd_pmf_register_input_device(dev); in amd_pmf_init_smart_pc()
551 amd_pmf_deinit_smart_pc(dev); in amd_pmf_init_smart_pc()
556 void amd_pmf_deinit_smart_pc(struct amd_pmf_dev *dev) in amd_pmf_deinit_smart_pc() argument
558 if (dev->pmf_idev) in amd_pmf_deinit_smart_pc()
559 input_unregister_device(dev->pmf_idev); in amd_pmf_deinit_smart_pc()
561 if (pb_side_load && dev->esbin) in amd_pmf_deinit_smart_pc()
562 amd_pmf_remove_pb(dev); in amd_pmf_deinit_smart_pc()
564 cancel_delayed_work_sync(&dev->pb_work); in amd_pmf_deinit_smart_pc()
565 kfree(dev->prev_data); in amd_pmf_deinit_smart_pc()
566 dev->prev_data = NULL; in amd_pmf_deinit_smart_pc()
567 kfree(dev->policy_buf); in amd_pmf_deinit_smart_pc()
568 dev->policy_buf = NULL; in amd_pmf_deinit_smart_pc()
569 kfree(dev->buf); in amd_pmf_deinit_smart_pc()
570 dev->buf = NULL; in amd_pmf_deinit_smart_pc()
571 amd_pmf_tee_deinit(dev); in amd_pmf_deinit_smart_pc()