[PATCH v1 2/2] dp_hdcp: Get the hdcp key from the connector prop

From: Mark Yacoub
Date: Fri Apr 21 2023 - 12:13:03 EST


From: Mark Yacoub <markyacoub@xxxxxxxxxxxx>

[Why]
To support protected content, the driver requires a key.
Currently, it's being injected from debugfs, which is not super useful
to run a user space in the wild.

[How]
When the key is needed, fetch the "Content Protection Property" on the
connector and get the key blob. Verify that the size is valid and use
it.

Signed-off-by: Mark Yacoub <markyacoub@xxxxxxxxxxxx>
---
drivers/gpu/drm/msm/dp/dp_hdcp.c | 66 +++++++++++++++++++++++++++++---
1 file changed, 61 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/msm/dp/dp_hdcp.c b/drivers/gpu/drm/msm/dp/dp_hdcp.c
index 191340971f943..4321d245b36c9 100644
--- a/drivers/gpu/drm/msm/dp/dp_hdcp.c
+++ b/drivers/gpu/drm/msm/dp/dp_hdcp.c
@@ -117,19 +117,61 @@ static bool dp_hdcp_are_keys_valid(struct drm_connector *connector,
return FIELD_GET(DP_HDCP_KEY_STATUS, val) == DP_HDCP_KEY_STATUS_VALID;
}

+static bool dp_hdcp_get_key_from_connector(struct drm_connector *connector,
+ struct drm_bridge *bridge)
+{
+ struct drm_property_blob *key_blob;
+ u8 *raw_key;
+ int ret;
+ struct dp_hdcp *hdcp;
+ struct drm_device *dev = connector->dev;
+ struct drm_property *prop =
+ dev->mode_config.content_protection_key_property;
+
+ if (!prop)
+ return false;
+
+ key_blob = connector->state->content_protection_key;
+ if (!key_blob)
+ return false;
+
+ raw_key = key_blob->data;
+
+ if (key_blob->length !=
+ DRM_HDCP_KSV_LEN + DP_HDCP_NUM_KEYS * DP_HDCP_KEY_LEN) {
+ drm_dbg_atomic(
+ dev,
+ "[CONNECTOR:%d:%s] Content Protection Key is a blob that we don't expect.\n",
+ connector->base.id, connector->name);
+ return false;
+ }
+
+ hdcp = dp_display_bridge_to_hdcp(bridge);
+ ret = dp_hdcp_ingest_key(hdcp, key_blob->data, key_blob->length);
+ if (ret)
+ return false;
+
+ return true;
+}
+
static int dp_hdcp_load_keys(struct drm_connector *connector, void *driver_data)
{
struct drm_bridge *bridge = (struct drm_bridge *)driver_data;
struct dp_hdcp *hdcp = dp_display_bridge_to_hdcp(bridge);
int i, ret = 0;
+ bool is_hdcp_key_valid;

mutex_lock(&hdcp->key_lock);
+ is_hdcp_key_valid = hdcp->key.valid;
+ mutex_unlock(&hdcp->key_lock);

- if (!hdcp->key.valid) {
- ret = -ENOENT;
- goto out;
+ if (!is_hdcp_key_valid &&
+ !dp_hdcp_get_key_from_connector(connector, bridge)) {
+ return -ENOENT;
}

+ mutex_lock(&hdcp->key_lock);
+
dp_catalog_hdcp_write_aksv(hdcp->catalog, hdcp->key.ksv.words);


@@ -139,7 +181,6 @@ static int dp_hdcp_load_keys(struct drm_connector *connector, void *driver_data)
}
dp_catalog_hdcp_post_write_key(hdcp->catalog);

-out:
mutex_unlock(&hdcp->key_lock);
return ret;
}
@@ -346,6 +387,8 @@ int dp_hdcp_attach(struct dp_hdcp *hdcp, struct drm_connector *connector,
struct drm_bridge *bridge, struct dp_catalog *catalog)
{
struct drm_hdcp_helper_data *helper_data;
+ struct drm_device *dev;
+ struct drm_property *prop;

/* HDCP is not configured for this device */
if (!hdcp->parser->io.dp_controller.hdcp_key.base)
@@ -357,7 +400,20 @@ int dp_hdcp_attach(struct dp_hdcp *hdcp, struct drm_connector *connector,
return PTR_ERR(helper_data);

helper_data->driver_data = bridge;
- hdcp->dev = connector->dev;
+
+ dev = connector->dev;
+ prop = dev->mode_config.content_protection_key_property;
+ if (!prop) {
+ prop = drm_property_create(dev, DRM_MODE_PROP_BLOB,
+ "Content Protection Key", 0);
+ }
+ if (!prop)
+ return -1;
+ drm_object_attach_property(&connector->base, prop,
+ DRM_MODE_HDCP_CONTENT_TYPE0);
+ dev->mode_config.content_protection_key_property = prop;
+
+ hdcp->dev = dev;
hdcp->connector = connector;
hdcp->helper_data = helper_data;
hdcp->catalog = catalog;
--
2.40.0.634.g4ca3ef3211-goog