hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/gpu/drm/rockchip/dw-dp.c
....@@ -239,8 +239,14 @@
239239 #define DPTX_HDCP22GPIOCHNGSTS 0x362c
240240 #define DPTX_HDCPREG_DPK_CRC 0x3630
241241
242
+#define HDCP_KEY_SIZE 308
243
+#define HDCP_KEY_SEED_SIZE 2
244
+
242245 #define HDCP_DATA_SIZE 330
243246 #define DP_HDCP1X_ID 6
247
+
248
+#define HDCP_SIG_MAGIC 0x4B534541 /* "AESK" */
249
+#define HDCP_FLG_AES 1
244250
245251 #define DPTX_MAX_REGISTER DPTX_HDCPREG_DPK_CRC
246252
....@@ -407,6 +413,14 @@
407413 int color_format;
408414 };
409415
416
+struct hdcp_key_data_t {
417
+ unsigned int signature;
418
+ unsigned int length;
419
+ unsigned int crc;
420
+ unsigned int flags;
421
+ unsigned char data[];
422
+};
423
+
410424 enum {
411425 DPTX_VM_RGB_6BIT,
412426 DPTX_VM_RGB_8BIT,
....@@ -499,6 +513,8 @@
499513 u8 hdcp_vendor_data[HDCP_DATA_SIZE + 1];
500514 void __iomem *base;
501515 struct arm_smccc_res res;
516
+ struct hdcp_key_data_t *key_data;
517
+ bool aes_encrypt;
502518
503519 regmap_read(dp->regmap, DPTX_HDCPREG_RMLSTS, &val);
504520 if (FIELD_GET(IDPK_DATA_INDEX, val) == 40) {
....@@ -507,10 +523,16 @@
507523 }
508524
509525 size = rk_vendor_read(DP_HDCP1X_ID, hdcp_vendor_data, HDCP_DATA_SIZE);
510
- if (size < HDCP_DATA_SIZE) {
511
- dev_info(dp->dev, "HDCP: read size %d\n", size);
526
+ if (size < (HDCP_KEY_SIZE + HDCP_KEY_SEED_SIZE)) {
527
+ dev_info(dp->dev, "HDCP key read error, size: %d\n", size);
512528 return -EINVAL;
513529 }
530
+
531
+ key_data = (struct hdcp_key_data_t *)hdcp_vendor_data;
532
+ if ((key_data->signature != HDCP_SIG_MAGIC) || !(key_data->flags & HDCP_FLG_AES))
533
+ aes_encrypt = false;
534
+ else
535
+ aes_encrypt = true;
514536
515537 base = sip_hdcp_request_share_memory(dp->id ? DP_TX1 : DP_TX0);
516538 if (!base)
....@@ -518,7 +540,7 @@
518540
519541 memcpy_toio(base, hdcp_vendor_data, size);
520542
521
- res = sip_hdcp_config(HDCP_FUNC_KEY_LOAD, dp->id ? DP_TX1 : DP_TX0, 0);
543
+ res = sip_hdcp_config(HDCP_FUNC_KEY_LOAD, dp->id ? DP_TX1 : DP_TX0, !aes_encrypt);
522544 if (IS_SIP_ERROR(res.a0)) {
523545 dev_err(dp->dev, "load hdcp key failed\n");
524546 return -EBUSY;