From: Jani Nikula Date: Thu, 24 Apr 2025 20:01:35 +0000 (+0300) Subject: drm/i915/hdcp: split HDCP GSC message alloc/save responsibilities X-Git-Tag: v6.16-rc1~144^2~12^2~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a07d04146b68cd6027ec9b58c97138f50e0b110f;p=thirdparty%2Flinux.git drm/i915/hdcp: split HDCP GSC message alloc/save responsibilities Allocate and initialize the HDCP GSC message in intel_hdcp_gsc_hdcp2_init() as before, but store the pointer to display->hdcp.hdcp_message in the caller. Similarly, pass in the pointer to intel_hdcp_gsc_free_message(). Cc: Suraj Kandpal Reviewed-by: Suraj Kandpal Link: https://lore.kernel.org/r/a74fcc941126bf92d12115b5faf4f75099e26242.1745524803.git.jani.nikula@intel.com Signed-off-by: Jani Nikula --- diff --git a/drivers/gpu/drm/i915/display/intel_hdcp_gsc.c b/drivers/gpu/drm/i915/display/intel_hdcp_gsc.c index 92a3ad2166f64..68d912dbd658d 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp_gsc.c +++ b/drivers/gpu/drm/i915/display/intel_hdcp_gsc.c @@ -90,37 +90,35 @@ out_unpin: return err; } -int intel_hdcp_gsc_hdcp2_init(struct intel_display *display) +struct intel_hdcp_gsc_message *intel_hdcp_gsc_hdcp2_init(struct intel_display *display) { struct drm_i915_private *i915 = to_i915(display->drm); struct intel_hdcp_gsc_message *hdcp_message; int ret; hdcp_message = kzalloc(sizeof(*hdcp_message), GFP_KERNEL); - if (!hdcp_message) - return -ENOMEM; + return ERR_PTR(-ENOMEM); /* * NOTE: No need to lock the comp mutex here as it is already * going to be taken before this function called */ - display->hdcp.hdcp_message = hdcp_message; ret = intel_hdcp_gsc_initialize_message(i915, hdcp_message); - - if (ret) + if (ret) { drm_err(display->drm, "Could not initialize hdcp_message\n"); + kfree(hdcp_message); + hdcp_message = ERR_PTR(ret); + } - return ret; + return hdcp_message; } -void intel_hdcp_gsc_free_message(struct intel_display *display) +void intel_hdcp_gsc_free_message(struct intel_hdcp_gsc_message *hdcp_message) { - struct intel_hdcp_gsc_message *hdcp_message = - display->hdcp.hdcp_message; + if (!hdcp_message) + return; - hdcp_message->hdcp_cmd_in = NULL; - hdcp_message->hdcp_cmd_out = NULL; i915_vma_unpin_and_release(&hdcp_message->vma, I915_VMA_RELEASE_MAP); kfree(hdcp_message); } diff --git a/drivers/gpu/drm/i915/display/intel_hdcp_gsc.h b/drivers/gpu/drm/i915/display/intel_hdcp_gsc.h index ad41e7e800955..f3362720d7428 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp_gsc.h +++ b/drivers/gpu/drm/i915/display/intel_hdcp_gsc.h @@ -19,7 +19,7 @@ ssize_t intel_hdcp_gsc_msg_send(struct drm_i915_private *i915, u8 *msg_in, size_t msg_out_len); bool intel_hdcp_gsc_check_status(struct intel_display *display); -int intel_hdcp_gsc_hdcp2_init(struct intel_display *display); -void intel_hdcp_gsc_free_message(struct intel_display *display); +struct intel_hdcp_gsc_message *intel_hdcp_gsc_hdcp2_init(struct intel_display *display); +void intel_hdcp_gsc_free_message(struct intel_hdcp_gsc_message *hdcp_message); #endif /* __INTEL_HDCP_GCS_H__ */ diff --git a/drivers/gpu/drm/i915/display/intel_hdcp_gsc_message.c b/drivers/gpu/drm/i915/display/intel_hdcp_gsc_message.c index 8e2aafff71d5a..11aa6772f2720 100644 --- a/drivers/gpu/drm/i915/display/intel_hdcp_gsc_message.c +++ b/drivers/gpu/drm/i915/display/intel_hdcp_gsc_message.c @@ -633,8 +633,9 @@ static const struct i915_hdcp_ops gsc_hdcp_ops = { int intel_hdcp_gsc_init(struct intel_display *display) { + struct intel_hdcp_gsc_message *hdcp_message; struct i915_hdcp_arbiter *arbiter; - int ret; + int ret = 0; arbiter = kzalloc(sizeof(*arbiter), GFP_KERNEL); if (!arbiter) @@ -642,8 +643,9 @@ int intel_hdcp_gsc_init(struct intel_display *display) mutex_lock(&display->hdcp.hdcp_mutex); - ret = intel_hdcp_gsc_hdcp2_init(display); - if (ret) { + hdcp_message = intel_hdcp_gsc_hdcp2_init(display); + if (IS_ERR(hdcp_message)) { + ret = PTR_ERR(hdcp_message); kfree(arbiter); goto out; } @@ -651,6 +653,7 @@ int intel_hdcp_gsc_init(struct intel_display *display) display->hdcp.arbiter = arbiter; display->hdcp.arbiter->hdcp_dev = display->drm->dev; display->hdcp.arbiter->ops = &gsc_hdcp_ops; + display->hdcp.hdcp_message = hdcp_message; out: mutex_unlock(&display->hdcp.hdcp_mutex); @@ -660,7 +663,8 @@ out: void intel_hdcp_gsc_fini(struct intel_display *display) { - intel_hdcp_gsc_free_message(display); + intel_hdcp_gsc_free_message(display->hdcp.hdcp_message); + display->hdcp.hdcp_message = NULL; kfree(display->hdcp.arbiter); display->hdcp.arbiter = NULL; } diff --git a/drivers/gpu/drm/xe/display/xe_hdcp_gsc.c b/drivers/gpu/drm/xe/display/xe_hdcp_gsc.c index 21cfecf077bff..d15565bf2f9ff 100644 --- a/drivers/gpu/drm/xe/display/xe_hdcp_gsc.c +++ b/drivers/gpu/drm/xe/display/xe_hdcp_gsc.c @@ -99,15 +99,14 @@ out: return ret; } -int intel_hdcp_gsc_hdcp2_init(struct intel_display *display) +struct intel_hdcp_gsc_message *intel_hdcp_gsc_hdcp2_init(struct intel_display *display) { struct intel_hdcp_gsc_message *hdcp_message; int ret; hdcp_message = kzalloc(sizeof(*hdcp_message), GFP_KERNEL); - if (!hdcp_message) - return -ENOMEM; + return ERR_PTR(-ENOMEM); /* * NOTE: No need to lock the comp mutex here as it is already @@ -117,22 +116,19 @@ int intel_hdcp_gsc_hdcp2_init(struct intel_display *display) if (ret) { drm_err(display->drm, "Could not initialize hdcp_message\n"); kfree(hdcp_message); - return ret; + hdcp_message = ERR_PTR(ret); } - display->hdcp.hdcp_message = hdcp_message; - return ret; + return hdcp_message; } -void intel_hdcp_gsc_free_message(struct intel_display *display) +void intel_hdcp_gsc_free_message(struct intel_hdcp_gsc_message *hdcp_message) { - struct intel_hdcp_gsc_message *hdcp_message = display->hdcp.hdcp_message; + if (!hdcp_message) + return; - if (hdcp_message) { - xe_bo_unpin_map_no_vm(hdcp_message->hdcp_bo); - kfree(hdcp_message); - display->hdcp.hdcp_message = NULL; - } + xe_bo_unpin_map_no_vm(hdcp_message->hdcp_bo); + kfree(hdcp_message); } static int xe_gsc_send_sync(struct xe_device *xe,