RE: [Intel-gfx] [PATCH v6 03/10] drm: revocation check at drm subsystem
Acked-by: Satyeshwar Singh -Original Message- From: Roper, Matthew D Sent: Monday, May 6, 2019 2:59 PM To: Daniel Vetter Cc: C, Ramalingam ; Vetter, Daniel ; intel-...@lists.freedesktop.org; dri-devel@lists.freedesktop.org; Singh, Satyeshwar Subject: Re: [Intel-gfx] [PATCH v6 03/10] drm: revocation check at drm subsystem On Mon, May 06, 2019 at 06:56:03PM +0200, Daniel Vetter wrote: > On Thu, May 02, 2019 at 06:52:56PM +0530, Ramalingam C wrote: > > On every hdcp revocation check request SRM is read from fw file > > /lib/firmware/display_hdcp_srm.bin > > > > SRM table is parsed and stored at drm_hdcp.c, with functions > > exported for the services for revocation check from drivers (which > > implements the HDCP authentication) > > > > This patch handles the HDCP1.4 and 2.2 versions of SRM table. > > > > v2: > > moved the uAPI to request_firmware_direct() [Daniel] > > v3: > > kdoc added. [Daniel] > > srm_header unified and bit field definitions are removed. [Daniel] > > locking improved. [Daniel] > > vrl length violation is fixed. [Daniel] > > > > Signed-off-by: Ramalingam C > > Suggested-by: Daniel Vetter > > Found a few small details to polish, but looks good to me. With the > details addressed: > > Reviewed-by: Daniel Vetter > > We also still need an ack on the firmware blob approach from Matt > Roper or someone else at iotg I think. +Satyeshwar Satyeshwar's probably the best person from IOTG to give the Ack since he's part of the group that needs this functionality and is involved in the userspace/compositor side as well. Matt > > Cheers, Daniel > > > --- > > Documentation/gpu/drm-kms-helpers.rst | 6 + > > drivers/gpu/drm/Makefile | 2 +- > > drivers/gpu/drm/drm_hdcp.c| 342 ++ > > drivers/gpu/drm/drm_internal.h| 4 + > > drivers/gpu/drm/drm_sysfs.c | 2 + > > include/drm/drm_hdcp.h| 24 ++ > > 6 files changed, 379 insertions(+), 1 deletion(-) create mode > > 100644 drivers/gpu/drm/drm_hdcp.c > > > > diff --git a/Documentation/gpu/drm-kms-helpers.rst > > b/Documentation/gpu/drm-kms-helpers.rst > > index 14102ae035dc..0fe726a6ee67 100644 > > --- a/Documentation/gpu/drm-kms-helpers.rst > > +++ b/Documentation/gpu/drm-kms-helpers.rst > > @@ -181,6 +181,12 @@ Panel Helper Reference .. kernel-doc:: > > drivers/gpu/drm/drm_panel_orientation_quirks.c > > :export: > > > > +HDCP Helper Functions Reference > > +=== > > + > > +.. kernel-doc:: drivers/gpu/drm/drm_hdcp.c > > + :export: > > + > > Display Port Helper Functions Reference > > === > > > > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile > > index 72f5036d9bfa..dd02e9dec810 100644 > > --- a/drivers/gpu/drm/Makefile > > +++ b/drivers/gpu/drm/Makefile > > @@ -17,7 +17,7 @@ drm-y :=drm_auth.o drm_cache.o \ > > drm_plane.o drm_color_mgmt.o drm_print.o \ > > drm_dumb_buffers.o drm_mode_config.o drm_vblank.o \ > > drm_syncobj.o drm_lease.o drm_writeback.o drm_client.o \ > > - drm_atomic_uapi.o > > + drm_atomic_uapi.o drm_hdcp.o > > > > drm-$(CONFIG_DRM_LEGACY) += drm_legacy_misc.o drm_bufs.o > > drm_context.o drm_dma.o drm_scatter.o drm_lock.o > > drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o diff --git > > a/drivers/gpu/drm/drm_hdcp.c b/drivers/gpu/drm/drm_hdcp.c new file > > mode 100644 index ..dc0e13409221 > > --- /dev/null > > +++ b/drivers/gpu/drm/drm_hdcp.c > > @@ -0,0 +1,342 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (C) 2019 Intel Corporation. > > + * > > + * Authors: > > + * Ramalingam C */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > + > > +struct hdcp_srm { > > + u8 *srm_buf; > > Allocated, but seems to not be used. > > > + size_t received_srm_sz; > > Seems to be unused. Seems to both be leftovers from the sysfs interface. > > > + u32 revoked_ksv_cnt; > > + u8 *revoked_ksv_list; > > + > > + /* Mutex to protect above struct member */ > > + struct mutex mutex; > > +} *srm_data; > > + > > +static inline void drm_hdcp_print_ksv(co
Re: [Intel-gfx] [PATCH v6 03/10] drm: revocation check at drm subsystem
On Mon, May 06, 2019 at 06:56:03PM +0200, Daniel Vetter wrote: > On Thu, May 02, 2019 at 06:52:56PM +0530, Ramalingam C wrote: > > On every hdcp revocation check request SRM is read from fw file > > /lib/firmware/display_hdcp_srm.bin > > > > SRM table is parsed and stored at drm_hdcp.c, with functions exported > > for the services for revocation check from drivers (which > > implements the HDCP authentication) > > > > This patch handles the HDCP1.4 and 2.2 versions of SRM table. > > > > v2: > > moved the uAPI to request_firmware_direct() [Daniel] > > v3: > > kdoc added. [Daniel] > > srm_header unified and bit field definitions are removed. [Daniel] > > locking improved. [Daniel] > > vrl length violation is fixed. [Daniel] > > > > Signed-off-by: Ramalingam C > > Suggested-by: Daniel Vetter > > Found a few small details to polish, but looks good to me. With the > details addressed: > > Reviewed-by: Daniel Vetter > > We also still need an ack on the firmware blob approach from Matt Roper or > someone else at iotg I think. +Satyeshwar Satyeshwar's probably the best person from IOTG to give the Ack since he's part of the group that needs this functionality and is involved in the userspace/compositor side as well. Matt > > Cheers, Daniel > > > --- > > Documentation/gpu/drm-kms-helpers.rst | 6 + > > drivers/gpu/drm/Makefile | 2 +- > > drivers/gpu/drm/drm_hdcp.c| 342 ++ > > drivers/gpu/drm/drm_internal.h| 4 + > > drivers/gpu/drm/drm_sysfs.c | 2 + > > include/drm/drm_hdcp.h| 24 ++ > > 6 files changed, 379 insertions(+), 1 deletion(-) > > create mode 100644 drivers/gpu/drm/drm_hdcp.c > > > > diff --git a/Documentation/gpu/drm-kms-helpers.rst > > b/Documentation/gpu/drm-kms-helpers.rst > > index 14102ae035dc..0fe726a6ee67 100644 > > --- a/Documentation/gpu/drm-kms-helpers.rst > > +++ b/Documentation/gpu/drm-kms-helpers.rst > > @@ -181,6 +181,12 @@ Panel Helper Reference > > .. kernel-doc:: drivers/gpu/drm/drm_panel_orientation_quirks.c > > :export: > > > > +HDCP Helper Functions Reference > > +=== > > + > > +.. kernel-doc:: drivers/gpu/drm/drm_hdcp.c > > + :export: > > + > > Display Port Helper Functions Reference > > === > > > > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile > > index 72f5036d9bfa..dd02e9dec810 100644 > > --- a/drivers/gpu/drm/Makefile > > +++ b/drivers/gpu/drm/Makefile > > @@ -17,7 +17,7 @@ drm-y :=drm_auth.o drm_cache.o \ > > drm_plane.o drm_color_mgmt.o drm_print.o \ > > drm_dumb_buffers.o drm_mode_config.o drm_vblank.o \ > > drm_syncobj.o drm_lease.o drm_writeback.o drm_client.o \ > > - drm_atomic_uapi.o > > + drm_atomic_uapi.o drm_hdcp.o > > > > drm-$(CONFIG_DRM_LEGACY) += drm_legacy_misc.o drm_bufs.o drm_context.o > > drm_dma.o drm_scatter.o drm_lock.o > > drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o > > diff --git a/drivers/gpu/drm/drm_hdcp.c b/drivers/gpu/drm/drm_hdcp.c > > new file mode 100644 > > index ..dc0e13409221 > > --- /dev/null > > +++ b/drivers/gpu/drm/drm_hdcp.c > > @@ -0,0 +1,342 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * Copyright (C) 2019 Intel Corporation. > > + * > > + * Authors: > > + * Ramalingam C > > + */ > > + > > +#include > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > +#include > > +#include > > + > > +struct hdcp_srm { > > + u8 *srm_buf; > > Allocated, but seems to not be used. > > > + size_t received_srm_sz; > > Seems to be unused. Seems to both be leftovers from the sysfs interface. > > > + u32 revoked_ksv_cnt; > > + u8 *revoked_ksv_list; > > + > > + /* Mutex to protect above struct member */ > > + struct mutex mutex; > > +} *srm_data; > > + > > +static inline void drm_hdcp_print_ksv(const u8 *ksv) > > +{ > > + DRM_DEBUG("\t%#02x, %#02x, %#02x, %#02x, %#02x\n", > > + ksv[0], ksv[1], ksv[2], ksv[3], ksv[4]); > > +} > > + > > +static u32 drm_hdcp_get_revoked_ksv_count(const u8 *buf, u32 vrls_length) > > +{ > > + u32 parsed_bytes = 0, ksv_count = 0, vrl_ksv_cnt, vrl_sz; > > + > > + while (parsed_bytes < vrls_length) { > > + vrl_ksv_cnt = *buf; > > + ksv_count += vrl_ksv_cnt; > > + > > + vrl_sz = (vrl_ksv_cnt * DRM_HDCP_KSV_LEN) + 1; > > + buf += vrl_sz; > > + parsed_bytes += vrl_sz; > > + } > > + > > + /* > > +* When vrls are not valid, ksvs are not considered. > > +* Hence SRM will be discarded. > > +*/ > > + if (parsed_bytes != vrls_length) > > + ksv_count = 0; > > + > > + return ksv_count; > > +} > > + > > +static u32 drm_hdcp_get_revoked_ksvs(const u8 *buf, u8 *revoked_ksv_list, > > +u32 vrls_length) > > +{ > > + u32
Re: [Intel-gfx] [PATCH v6 03/10] drm: revocation check at drm subsystem
On Thu, May 02, 2019 at 06:52:56PM +0530, Ramalingam C wrote: > On every hdcp revocation check request SRM is read from fw file > /lib/firmware/display_hdcp_srm.bin > > SRM table is parsed and stored at drm_hdcp.c, with functions exported > for the services for revocation check from drivers (which > implements the HDCP authentication) > > This patch handles the HDCP1.4 and 2.2 versions of SRM table. > > v2: > moved the uAPI to request_firmware_direct() [Daniel] > v3: > kdoc added. [Daniel] > srm_header unified and bit field definitions are removed. [Daniel] > locking improved. [Daniel] > vrl length violation is fixed. [Daniel] > > Signed-off-by: Ramalingam C > Suggested-by: Daniel Vetter Found a few small details to polish, but looks good to me. With the details addressed: Reviewed-by: Daniel Vetter We also still need an ack on the firmware blob approach from Matt Roper or someone else at iotg I think. Cheers, Daniel > --- > Documentation/gpu/drm-kms-helpers.rst | 6 + > drivers/gpu/drm/Makefile | 2 +- > drivers/gpu/drm/drm_hdcp.c| 342 ++ > drivers/gpu/drm/drm_internal.h| 4 + > drivers/gpu/drm/drm_sysfs.c | 2 + > include/drm/drm_hdcp.h| 24 ++ > 6 files changed, 379 insertions(+), 1 deletion(-) > create mode 100644 drivers/gpu/drm/drm_hdcp.c > > diff --git a/Documentation/gpu/drm-kms-helpers.rst > b/Documentation/gpu/drm-kms-helpers.rst > index 14102ae035dc..0fe726a6ee67 100644 > --- a/Documentation/gpu/drm-kms-helpers.rst > +++ b/Documentation/gpu/drm-kms-helpers.rst > @@ -181,6 +181,12 @@ Panel Helper Reference > .. kernel-doc:: drivers/gpu/drm/drm_panel_orientation_quirks.c > :export: > > +HDCP Helper Functions Reference > +=== > + > +.. kernel-doc:: drivers/gpu/drm/drm_hdcp.c > + :export: > + > Display Port Helper Functions Reference > === > > diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile > index 72f5036d9bfa..dd02e9dec810 100644 > --- a/drivers/gpu/drm/Makefile > +++ b/drivers/gpu/drm/Makefile > @@ -17,7 +17,7 @@ drm-y := drm_auth.o drm_cache.o \ > drm_plane.o drm_color_mgmt.o drm_print.o \ > drm_dumb_buffers.o drm_mode_config.o drm_vblank.o \ > drm_syncobj.o drm_lease.o drm_writeback.o drm_client.o \ > - drm_atomic_uapi.o > + drm_atomic_uapi.o drm_hdcp.o > > drm-$(CONFIG_DRM_LEGACY) += drm_legacy_misc.o drm_bufs.o drm_context.o > drm_dma.o drm_scatter.o drm_lock.o > drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o > diff --git a/drivers/gpu/drm/drm_hdcp.c b/drivers/gpu/drm/drm_hdcp.c > new file mode 100644 > index ..dc0e13409221 > --- /dev/null > +++ b/drivers/gpu/drm/drm_hdcp.c > @@ -0,0 +1,342 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * Copyright (C) 2019 Intel Corporation. > + * > + * Authors: > + * Ramalingam C > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include > +#include > +#include > +#include > + > +struct hdcp_srm { > + u8 *srm_buf; Allocated, but seems to not be used. > + size_t received_srm_sz; Seems to be unused. Seems to both be leftovers from the sysfs interface. > + u32 revoked_ksv_cnt; > + u8 *revoked_ksv_list; > + > + /* Mutex to protect above struct member */ > + struct mutex mutex; > +} *srm_data; > + > +static inline void drm_hdcp_print_ksv(const u8 *ksv) > +{ > + DRM_DEBUG("\t%#02x, %#02x, %#02x, %#02x, %#02x\n", > + ksv[0], ksv[1], ksv[2], ksv[3], ksv[4]); > +} > + > +static u32 drm_hdcp_get_revoked_ksv_count(const u8 *buf, u32 vrls_length) > +{ > + u32 parsed_bytes = 0, ksv_count = 0, vrl_ksv_cnt, vrl_sz; > + > + while (parsed_bytes < vrls_length) { > + vrl_ksv_cnt = *buf; > + ksv_count += vrl_ksv_cnt; > + > + vrl_sz = (vrl_ksv_cnt * DRM_HDCP_KSV_LEN) + 1; > + buf += vrl_sz; > + parsed_bytes += vrl_sz; > + } > + > + /* > + * When vrls are not valid, ksvs are not considered. > + * Hence SRM will be discarded. > + */ > + if (parsed_bytes != vrls_length) > + ksv_count = 0; > + > + return ksv_count; > +} > + > +static u32 drm_hdcp_get_revoked_ksvs(const u8 *buf, u8 *revoked_ksv_list, > + u32 vrls_length) > +{ > + u32 parsed_bytes = 0, ksv_count = 0; > + u32 vrl_ksv_cnt, vrl_ksv_sz, vrl_idx = 0; > + > + do { > + vrl_ksv_cnt = *buf; > + vrl_ksv_sz = vrl_ksv_cnt * DRM_HDCP_KSV_LEN; > + > + buf++; > + > + DRM_DEBUG("vrl: %d, Revoked KSVs: %d\n", vrl_idx++, > + vrl_ksv_cnt); > + memcpy(revoked_ksv_list, buf, vrl_ksv_sz); > + > + ksv_count += vrl_ksv_cnt; > + revoked_ksv_list += vrl_ksv_sz; > + buf
[PATCH v6 03/10] drm: revocation check at drm subsystem
On every hdcp revocation check request SRM is read from fw file /lib/firmware/display_hdcp_srm.bin SRM table is parsed and stored at drm_hdcp.c, with functions exported for the services for revocation check from drivers (which implements the HDCP authentication) This patch handles the HDCP1.4 and 2.2 versions of SRM table. v2: moved the uAPI to request_firmware_direct() [Daniel] v3: kdoc added. [Daniel] srm_header unified and bit field definitions are removed. [Daniel] locking improved. [Daniel] vrl length violation is fixed. [Daniel] Signed-off-by: Ramalingam C Suggested-by: Daniel Vetter --- Documentation/gpu/drm-kms-helpers.rst | 6 + drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_hdcp.c| 342 ++ drivers/gpu/drm/drm_internal.h| 4 + drivers/gpu/drm/drm_sysfs.c | 2 + include/drm/drm_hdcp.h| 24 ++ 6 files changed, 379 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/drm_hdcp.c diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst index 14102ae035dc..0fe726a6ee67 100644 --- a/Documentation/gpu/drm-kms-helpers.rst +++ b/Documentation/gpu/drm-kms-helpers.rst @@ -181,6 +181,12 @@ Panel Helper Reference .. kernel-doc:: drivers/gpu/drm/drm_panel_orientation_quirks.c :export: +HDCP Helper Functions Reference +=== + +.. kernel-doc:: drivers/gpu/drm/drm_hdcp.c + :export: + Display Port Helper Functions Reference === diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index 72f5036d9bfa..dd02e9dec810 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -17,7 +17,7 @@ drm-y :=drm_auth.o drm_cache.o \ drm_plane.o drm_color_mgmt.o drm_print.o \ drm_dumb_buffers.o drm_mode_config.o drm_vblank.o \ drm_syncobj.o drm_lease.o drm_writeback.o drm_client.o \ - drm_atomic_uapi.o + drm_atomic_uapi.o drm_hdcp.o drm-$(CONFIG_DRM_LEGACY) += drm_legacy_misc.o drm_bufs.o drm_context.o drm_dma.o drm_scatter.o drm_lock.o drm-$(CONFIG_DRM_LIB_RANDOM) += lib/drm_random.o diff --git a/drivers/gpu/drm/drm_hdcp.c b/drivers/gpu/drm/drm_hdcp.c new file mode 100644 index ..dc0e13409221 --- /dev/null +++ b/drivers/gpu/drm/drm_hdcp.c @@ -0,0 +1,342 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 Intel Corporation. + * + * Authors: + * Ramalingam C + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +struct hdcp_srm { + u8 *srm_buf; + size_t received_srm_sz; + u32 revoked_ksv_cnt; + u8 *revoked_ksv_list; + + /* Mutex to protect above struct member */ + struct mutex mutex; +} *srm_data; + +static inline void drm_hdcp_print_ksv(const u8 *ksv) +{ + DRM_DEBUG("\t%#02x, %#02x, %#02x, %#02x, %#02x\n", + ksv[0], ksv[1], ksv[2], ksv[3], ksv[4]); +} + +static u32 drm_hdcp_get_revoked_ksv_count(const u8 *buf, u32 vrls_length) +{ + u32 parsed_bytes = 0, ksv_count = 0, vrl_ksv_cnt, vrl_sz; + + while (parsed_bytes < vrls_length) { + vrl_ksv_cnt = *buf; + ksv_count += vrl_ksv_cnt; + + vrl_sz = (vrl_ksv_cnt * DRM_HDCP_KSV_LEN) + 1; + buf += vrl_sz; + parsed_bytes += vrl_sz; + } + + /* +* When vrls are not valid, ksvs are not considered. +* Hence SRM will be discarded. +*/ + if (parsed_bytes != vrls_length) + ksv_count = 0; + + return ksv_count; +} + +static u32 drm_hdcp_get_revoked_ksvs(const u8 *buf, u8 *revoked_ksv_list, +u32 vrls_length) +{ + u32 parsed_bytes = 0, ksv_count = 0; + u32 vrl_ksv_cnt, vrl_ksv_sz, vrl_idx = 0; + + do { + vrl_ksv_cnt = *buf; + vrl_ksv_sz = vrl_ksv_cnt * DRM_HDCP_KSV_LEN; + + buf++; + + DRM_DEBUG("vrl: %d, Revoked KSVs: %d\n", vrl_idx++, + vrl_ksv_cnt); + memcpy(revoked_ksv_list, buf, vrl_ksv_sz); + + ksv_count += vrl_ksv_cnt; + revoked_ksv_list += vrl_ksv_sz; + buf += vrl_ksv_sz; + + parsed_bytes += (vrl_ksv_sz + 1); + } while (parsed_bytes < vrls_length); + + return ksv_count; +} + +static inline u32 get_vrl_length(const u8 *buf) +{ + return (u32)(buf[0] << 16 | buf[1] << 8 | buf[2]); +} + +static int drm_hdcp_parse_hdcp1_srm(const u8 *buf, size_t count) +{ + struct hdcp_srm_header *header; + u32 vrl_length, ksv_count; + + if (count < (sizeof(struct hdcp_srm_header) + + DRM_HDCP_1_4_VRL_LENGTH_SIZE + DRM_HDCP_1_4_DCP_SIG_SIZE)) { + DRM_ERROR("Invalid blob length\n"); + return -EINVAL; +