f9535d28ac
Similar to commit b8d8436840ca ("drm/i915/gt: Hold RPM wakelock during PXP suspend") but to fix the same warning for unbind during shutdown: ------------[ cut here ]------------ RPM wakelock ref not held during HW access WARNING: CPU: 0 PID: 4139 at drivers/gpu/drm/i915/intel_runtime_pm.h:115 gen12_fwtable_write32+0x1b7/0 Modules linked in: 8021q ccm rfcomm cmac algif_hash algif_skcipher af_alg uinput snd_hda_codec_hdmi vf industrialio iwl7000_mac80211 cros_ec_sensorhub lzo_rle lzo_compress zram iwlwifi cfg80211 joydev CPU: 0 PID: 4139 Comm: halt Tainted: G U W 5.10.84 #13 344e11e079c4a03940d949e537eab645f6 RIP: 0010:gen12_fwtable_write32+0x1b7/0x200 Code: 48 c7 c7 fc b3 b5 89 31 c0 e8 2c f3 ad ff 0f 0b e9 04 ff ff ff c6 05 71 e9 1d 01 01 48 c7 c7 d67 RSP: 0018:ffffa09ec0bb3bb0 EFLAGS: 00010246 RAX: 12dde97bbd260300 RBX: 00000000000320f0 RCX: ffffffff89e60ea0 RDX: 0000000000000000 RSI: 00000000ffffdfff RDI: ffffffff89e60e70 RBP: ffffa09ec0bb3bd8 R08: 0000000000000000 R09: ffffa09ec0bb3950 R10: 00000000ffffdfff R11: ffffffff89e91160 R12: 0000000000000000 R13: 0000000028121969 R14: ffff9515c32f0990 R15: 0000000040000000 FS: 0000790dcf225740(0000) GS:ffff951737800000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000058b25efae147 CR3: 0000000133ea6001 CR4: 0000000000770ef0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000ffff07f0 DR7: 0000000000000400 PKRU: 55555554 Call Trace: intel_pxp_fini_hw+0x2f/0x39 i915_pxp_tee_component_unbind+0x1c/0x42 component_unbind+0x32/0x48 component_unbind_all+0x80/0x9d take_down_master+0x24/0x36 component_master_del+0x56/0x70 mei_pxp_remove+0x2c/0x68 mei_cl_device_remove+0x35/0x68 device_release_driver_internal+0x100/0x1a1 mei_cl_bus_remove_device+0x21/0x79 mei_cl_bus_remove_devices+0x3b/0x51 mei_stop+0x3b/0xae mei_me_shutdown+0x23/0x58 device_shutdown+0x144/0x1d3 kernel_power_off+0x13/0x4c __se_sys_reboot+0x1d4/0x1e9 do_syscall_64+0x43/0x55 entry_SYSCALL_64_after_hwframe+0x44/0xa9 RIP: 0033:0x790dcf316273 Code: 64 89 01 48 83 c8 ff c3 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 89 fa be 69 19 12 28 bf ad8 RSP: 002b:00007ffca0df9198 EFLAGS: 00000202 ORIG_RAX: 00000000000000a9 RAX: ffffffffffffffda RBX: 000000004321fedc RCX: 0000790dcf316273 RDX: 000000004321fedc RSI: 0000000028121969 RDI: 00000000fee1dead RBP: 00007ffca0df9200 R08: 0000000000000007 R09: 0000563ce8cd8970 R10: 0000000000000000 R11: 0000000000000202 R12: 00007ffca0df9308 R13: 0000000000000001 R14: 0000000000000000 R15: 0000000000000003 ---[ end trace 2f501b01b348f114 ]--- ACPI: Preparing to enter system sleep state S5 reboot: Power down Changes since v1: - Rebase to latest drm-tip Fixes: 0cfab4cb3c4e ("drm/i915/pxp: Enable PXP power management") Suggested-by: Lee Shawn C <shawn.c.lee@intel.com> Signed-off-by: Juston Li <juston.li@intel.com> Reviewed-by: Daniele Ceraolo Spurio <daniele.ceraolospurio@intel.com> Signed-off-by: John Harrison <John.C.Harrison@Intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/20220106200236.489656-2-juston.li@intel.com (cherry picked from commit 57ded5fc98b11d76dae505ca3591b61c9dbbbda7) Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
180 lines
4.6 KiB
C
180 lines
4.6 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright(c) 2020 Intel Corporation.
|
|
*/
|
|
|
|
#include <linux/component.h>
|
|
|
|
#include <drm/i915_pxp_tee_interface.h>
|
|
#include <drm/i915_component.h>
|
|
|
|
#include "i915_drv.h"
|
|
#include "intel_pxp.h"
|
|
#include "intel_pxp_session.h"
|
|
#include "intel_pxp_tee.h"
|
|
#include "intel_pxp_tee_interface.h"
|
|
|
|
static inline struct intel_pxp *i915_dev_to_pxp(struct device *i915_kdev)
|
|
{
|
|
struct drm_i915_private *i915 = kdev_to_i915(i915_kdev);
|
|
|
|
return &to_gt(i915)->pxp;
|
|
}
|
|
|
|
static int intel_pxp_tee_io_message(struct intel_pxp *pxp,
|
|
void *msg_in, u32 msg_in_size,
|
|
void *msg_out, u32 msg_out_max_size,
|
|
u32 *msg_out_rcv_size)
|
|
{
|
|
struct drm_i915_private *i915 = pxp_to_gt(pxp)->i915;
|
|
struct i915_pxp_component *pxp_component = pxp->pxp_component;
|
|
int ret = 0;
|
|
|
|
mutex_lock(&pxp->tee_mutex);
|
|
|
|
/*
|
|
* The binding of the component is asynchronous from i915 probe, so we
|
|
* can't be sure it has happened.
|
|
*/
|
|
if (!pxp_component) {
|
|
ret = -ENODEV;
|
|
goto unlock;
|
|
}
|
|
|
|
ret = pxp_component->ops->send(pxp_component->tee_dev, msg_in, msg_in_size);
|
|
if (ret) {
|
|
drm_err(&i915->drm, "Failed to send PXP TEE message\n");
|
|
goto unlock;
|
|
}
|
|
|
|
ret = pxp_component->ops->recv(pxp_component->tee_dev, msg_out, msg_out_max_size);
|
|
if (ret < 0) {
|
|
drm_err(&i915->drm, "Failed to receive PXP TEE message\n");
|
|
goto unlock;
|
|
}
|
|
|
|
if (ret > msg_out_max_size) {
|
|
drm_err(&i915->drm,
|
|
"Failed to receive PXP TEE message due to unexpected output size\n");
|
|
ret = -ENOSPC;
|
|
goto unlock;
|
|
}
|
|
|
|
if (msg_out_rcv_size)
|
|
*msg_out_rcv_size = ret;
|
|
|
|
ret = 0;
|
|
unlock:
|
|
mutex_unlock(&pxp->tee_mutex);
|
|
return ret;
|
|
}
|
|
|
|
/**
|
|
* i915_pxp_tee_component_bind - bind function to pass the function pointers to pxp_tee
|
|
* @i915_kdev: pointer to i915 kernel device
|
|
* @tee_kdev: pointer to tee kernel device
|
|
* @data: pointer to pxp_tee_master containing the function pointers
|
|
*
|
|
* This bind function is called during the system boot or resume from system sleep.
|
|
*
|
|
* Return: return 0 if successful.
|
|
*/
|
|
static int i915_pxp_tee_component_bind(struct device *i915_kdev,
|
|
struct device *tee_kdev, void *data)
|
|
{
|
|
struct drm_i915_private *i915 = kdev_to_i915(i915_kdev);
|
|
struct intel_pxp *pxp = i915_dev_to_pxp(i915_kdev);
|
|
intel_wakeref_t wakeref;
|
|
|
|
mutex_lock(&pxp->tee_mutex);
|
|
pxp->pxp_component = data;
|
|
pxp->pxp_component->tee_dev = tee_kdev;
|
|
mutex_unlock(&pxp->tee_mutex);
|
|
|
|
/* if we are suspended, the HW will be re-initialized on resume */
|
|
wakeref = intel_runtime_pm_get_if_in_use(&i915->runtime_pm);
|
|
if (!wakeref)
|
|
return 0;
|
|
|
|
/* the component is required to fully start the PXP HW */
|
|
intel_pxp_init_hw(pxp);
|
|
|
|
intel_runtime_pm_put(&i915->runtime_pm, wakeref);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void i915_pxp_tee_component_unbind(struct device *i915_kdev,
|
|
struct device *tee_kdev, void *data)
|
|
{
|
|
struct drm_i915_private *i915 = kdev_to_i915(i915_kdev);
|
|
struct intel_pxp *pxp = i915_dev_to_pxp(i915_kdev);
|
|
intel_wakeref_t wakeref;
|
|
|
|
with_intel_runtime_pm_if_in_use(&i915->runtime_pm, wakeref)
|
|
intel_pxp_fini_hw(pxp);
|
|
|
|
mutex_lock(&pxp->tee_mutex);
|
|
pxp->pxp_component = NULL;
|
|
mutex_unlock(&pxp->tee_mutex);
|
|
}
|
|
|
|
static const struct component_ops i915_pxp_tee_component_ops = {
|
|
.bind = i915_pxp_tee_component_bind,
|
|
.unbind = i915_pxp_tee_component_unbind,
|
|
};
|
|
|
|
int intel_pxp_tee_component_init(struct intel_pxp *pxp)
|
|
{
|
|
int ret;
|
|
struct intel_gt *gt = pxp_to_gt(pxp);
|
|
struct drm_i915_private *i915 = gt->i915;
|
|
|
|
ret = component_add_typed(i915->drm.dev, &i915_pxp_tee_component_ops,
|
|
I915_COMPONENT_PXP);
|
|
if (ret < 0) {
|
|
drm_err(&i915->drm, "Failed to add PXP component (%d)\n", ret);
|
|
return ret;
|
|
}
|
|
|
|
pxp->pxp_component_added = true;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void intel_pxp_tee_component_fini(struct intel_pxp *pxp)
|
|
{
|
|
struct drm_i915_private *i915 = pxp_to_gt(pxp)->i915;
|
|
|
|
if (!pxp->pxp_component_added)
|
|
return;
|
|
|
|
component_del(i915->drm.dev, &i915_pxp_tee_component_ops);
|
|
pxp->pxp_component_added = false;
|
|
}
|
|
|
|
int intel_pxp_tee_cmd_create_arb_session(struct intel_pxp *pxp,
|
|
int arb_session_id)
|
|
{
|
|
struct drm_i915_private *i915 = pxp_to_gt(pxp)->i915;
|
|
struct pxp_tee_create_arb_in msg_in = {0};
|
|
struct pxp_tee_create_arb_out msg_out = {0};
|
|
int ret;
|
|
|
|
msg_in.header.api_version = PXP_TEE_APIVER;
|
|
msg_in.header.command_id = PXP_TEE_ARB_CMDID;
|
|
msg_in.header.buffer_len = sizeof(msg_in) - sizeof(msg_in.header);
|
|
msg_in.protection_mode = PXP_TEE_ARB_PROTECTION_MODE;
|
|
msg_in.session_id = arb_session_id;
|
|
|
|
ret = intel_pxp_tee_io_message(pxp,
|
|
&msg_in, sizeof(msg_in),
|
|
&msg_out, sizeof(msg_out),
|
|
NULL);
|
|
|
|
if (ret)
|
|
drm_err(&i915->drm, "Failed to send tee msg ret=[%d]\n", ret);
|
|
|
|
return ret;
|
|
}
|