Message ID | 20231223182932.27683-1-jason-jh.lin@mediatek.com |
---|---|
Headers | show |
Series | Add mediate-drm secure flow for SVP | expand |
Hi, Jason: On Sun, 2023-12-24 at 02:29 +0800, Jason-JH.Lin wrote: > From: CK Hu <ck.hu@mediatek.com> > > Add an interface to allocate MediaTek GEM buffers, allow the IOCTLs > to be used by render nodes. > This patch also sets the RENDER driver feature. > > Signed-off-by: CK Hu <ck.hu@mediatek.com> > Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> > Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de> > Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com> > Reviewed-by: Daniel Kurtz <djkurtz@chromium.org> > Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> > Tested-by: Daniel Kurtz <djkurtz@chromium.org> > Tested-by: Pi-Hsun Shih <pihsun@chromium.org> > --- > drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 ++++++ > drivers/gpu/drm/mediatek/mtk_drm_gem.c | 39 +++++++++++++++++ > drivers/gpu/drm/mediatek/mtk_drm_gem.h | 12 ++++++ > include/uapi/drm/mediatek_drm.h | 58 > ++++++++++++++++++++++++++ > 4 files changed, 122 insertions(+) > create mode 100644 include/uapi/drm/mediatek_drm.h > > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c > b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > index 2b0c35cacbc6..5d2a39e491aa 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c > @@ -24,6 +24,7 @@ > #include <drm/drm_of.h> > #include <drm/drm_probe_helper.h> > #include <drm/drm_vblank.h> > +#include <drm/mediatek_drm.h> > > #include "mtk_drm_crtc.h" > #include "mtk_drm_ddp_comp.h" > @@ -569,6 +570,14 @@ static void mtk_drm_kms_deinit(struct drm_device > *drm) > component_unbind_all(drm->dev, drm); > } > > +static const struct drm_ioctl_desc mtk_ioctls[] = { > + DRM_IOCTL_DEF_DRV(MTK_GEM_CREATE, mtk_gem_create_ioctl, > + DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW), > + DRM_IOCTL_DEF_DRV(MTK_GEM_MAP_OFFSET, > + mtk_gem_map_offset_ioctl, > + DRM_UNLOCKED | DRM_AUTH | DRM_RENDER_ALLOW), For secure buffer, we don't need map offset function. If you really need this function, separate this to another patch and describe why need this. Regards, CK > +}; > + > DEFINE_DRM_GEM_FOPS(mtk_drm_fops); > > /* > @@ -590,6 +599,10 @@ static const struct drm_driver mtk_drm_driver = > { > > .gem_prime_import = mtk_drm_gem_prime_import, > .gem_prime_import_sg_table = mtk_gem_prime_import_sg_table, > + > + .ioctls = mtk_ioctls, > + .num_ioctls = ARRAY_SIZE(mtk_ioctls), > + > .fops = &mtk_drm_fops, > > .name = DRIVER_NAME, > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c > b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > index 4f2e3feabc0f..30e347adcbe9 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c > +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c > @@ -4,6 +4,7 @@ > */ > > #include <linux/dma-buf.h> > +#include <drm/mediatek_drm.h> > > #include <drm/drm.h> > #include <drm/drm_device.h> > @@ -283,3 +284,41 @@ void mtk_drm_gem_prime_vunmap(struct > drm_gem_object *obj, > mtk_gem->kvaddr = NULL; > kfree(mtk_gem->pages); > } > + > +int mtk_gem_map_offset_ioctl(struct drm_device *drm, void *data, > + struct drm_file *file_priv) > +{ > + struct drm_mtk_gem_map_off *args = data; > + > + return drm_gem_dumb_map_offset(file_priv, drm, args->handle, > + &args->offset); > +} > + > +int mtk_gem_create_ioctl(struct drm_device *dev, void *data, > + struct drm_file *file_priv) > +{ > + struct mtk_drm_gem_obj *mtk_gem; > + struct drm_mtk_gem_create *args = data; > + int ret; > + > + mtk_gem = mtk_drm_gem_create(dev, args->size, false); > + if (IS_ERR(mtk_gem)) > + return PTR_ERR(mtk_gem); > + > + /* > + * allocate a id of idr table where the obj is registered > + * and handle has the id what user can see. > + */ > + ret = drm_gem_handle_create(file_priv, &mtk_gem->base, &args- > >handle); > + if (ret) > + goto err_handle_create; > + > + /* drop reference from allocate - handle holds it now. */ > + drm_gem_object_put(&mtk_gem->base); > + > + return 0; > + > +err_handle_create: > + mtk_drm_gem_free_object(&mtk_gem->base); > + return ret; > +} > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.h > b/drivers/gpu/drm/mediatek/mtk_drm_gem.h > index 78f23b07a02e..90f3d2916ec5 100644 > --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.h > +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.h > @@ -46,4 +46,16 @@ int mtk_drm_gem_prime_vmap(struct drm_gem_object > *obj, struct iosys_map *map); > void mtk_drm_gem_prime_vunmap(struct drm_gem_object *obj, > struct iosys_map *map); > > +/* > + * request gem object creation and buffer allocation as the size > + * that it is calculated with framebuffer information such as width, > + * height and bpp. > + */ > +int mtk_gem_create_ioctl(struct drm_device *dev, void *data, > + struct drm_file *file_priv); > + > +/* get buffer offset to map to user space. */ > +int mtk_gem_map_offset_ioctl(struct drm_device *dev, void *data, > + struct drm_file *file_priv); > + > #endif > diff --git a/include/uapi/drm/mediatek_drm.h > b/include/uapi/drm/mediatek_drm.h > new file mode 100644 > index 000000000000..f4d47577c94e > --- /dev/null > +++ b/include/uapi/drm/mediatek_drm.h > @@ -0,0 +1,58 @@ > +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ > +/* > + * Copyright (c) 2015 MediaTek Inc. > + * > + * This program is free software; you can redistribute it and/or > modify > + * it under the terms of the GNU General Public License version 2 as > + * published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ > + > +#ifndef _UAPI_MEDIATEK_DRM_H > +#define _UAPI_MEDIATEK_DRM_H > + > +#include <drm/drm.h> > + > +/** > + * struct drm_mtk_gem_create - User-desired buffer creation > information structure. > + * > + * @size: user-desired memory allocation size. > + * - this size value would be page-aligned internally. > + * @flags: user request for setting memory type or cache attributes. > + * @handle: returned a handle to created gem object. > + * - this handle will be set by gem module of kernel side. > + */ > +struct drm_mtk_gem_create { > + uint64_t size; > + uint32_t flags; > + uint32_t handle; > +}; > + > +/** > + * struct drm_mtk_gem_map_off - A structure for getting buffer > offset. > + * > + * @handle: a pointer to gem object created. > + * @pad: just padding to be 64-bit aligned. > + * @offset: relatived offset value of the memory region allocated. > + * - this value should be set by user. > + */ > +struct drm_mtk_gem_map_off { > + uint32_t handle; > + uint32_t pad; > + uint64_t offset; > +}; > + > +#define DRM_MTK_GEM_CREATE 0x00 > +#define DRM_MTK_GEM_MAP_OFFSET 0x01 > + > +#define DRM_IOCTL_MTK_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + \ > + DRM_MTK_GEM_CREATE, struct drm_mtk_gem_create) > + > +#define DRM_IOCTL_MTK_GEM_MAP_OFFSET DRM_IOWR(DRM_COMMAND_BASE + \ > + DRM_MTK_GEM_MAP_OFFSET, struct drm_mtk_gem_map_off) > + > +#endif /* _UAPI_MEDIATEK_DRM_H */
Hi, Jason: On Sun, 2023-12-24 at 02:29 +0800, Jason-JH.Lin wrote: > From: Jason-jh Lin <jason-jh.lin@mediatek.corp-partner.google.com> > > Memory Definitions: > secure memory - Memory allocated in the TEE (Trusted Execution > Environment) which is inaccessible in the REE (Rich Execution > Environment, i.e. linux kernel/userspace). > secure handle - Integer value which acts as reference to 'secure > memory'. Used in communication between TEE and REE to reference > 'secure memory'. > secure buffer - 'secure memory' that is used to store decrypted, > compressed video or for other general purposes in the TEE. > secure surface - 'secure memory' that is used to store graphic > buffers. > > Memory Usage in SVP: > The overall flow of SVP starts with encrypted video coming in from an > outside source into the REE. The REE will then allocate a 'secure > buffer' and send the corresponding 'secure handle' along with the > encrypted, compressed video data to the TEE. The TEE will then > decrypt > the video and store the result in the 'secure buffer'. The REE will > then allocate a 'secure surface'. The REE will pass the 'secure > handles' for both the 'secure buffer' and 'secure surface' into the > TEE for video decoding. The video decoder HW will then decode the > contents of the 'secure buffer' and place the result in the 'secure > surface'. The REE will then attach the 'secure surface' to the > overlay > plane for rendering of the video. > > Everything relating to ensuring security of the actual contents of > the > 'secure buffer' and 'secure surface' is out of scope for the REE and > is the responsibility of the TEE. > > DRM driver handles allocation of gem objects that are backed by a > 'secure > surface' and for displaying a 'secure surface' on the overlay plane. > This introduces a new flag for object creation called > DRM_MTK_GEM_CREATE_ENCRYPTED which indicates it should be a 'secure > surface'. All changes here are in MediaTek specific code. I would like to decouple secure display and secure decode. One reason is that I would like secure display could be tested itself without secure decode. Another reason is that if someone has draw an image and want to display securely, this is not related to decode. To achieve this, mediatek drm driver should provide render function on secure surface. The most simple function is to bitblt a normal surface onto secure surface. User could allocate both normal surface and secure surface, draw on normal surface and bitblt normal surface onto secure surface. We could have limitation that normal surface and secure surface have the same width, height, pitch, pixel format, and the bitblt is the full image bitblt. So mediatek drm driver just need a TEE function that do memory copy from normal surface to secure surface. This is not a must-be function, but it has some benefit for secure display. Regards, CK > --- > TODO: > 1) Remove get sec larb port interface in ddp_comp, ovl and > ovl_adaptor. > 2) Verify instruction for enabling/disabling dapc and larb port in > TEE > drop the sec_engine flags in normal world and. > 3) Move DISP_REG_OVL_SECURE setting to secure world for > mtk_disp_ovl.c. > 4) Change the parameter register address in mtk_ddp_sec_write() > from "u32 addr" to "struct cmdq_client_reg *cmdq_reg". > 5) Implement setting mmsys routing table in the secure world series. > --- > Based on 5 series and 1 patch: > [1] v3 dma-buf: heaps: Add MediaTek secure heap > - > https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek/list/?series=809023__;!!CTRNKA9wMg0ARbw!lYGWfjjIBlxJvwBXWyxHTyc2vew5YagqT_qJZrYONTH20h95qxC3PH9V91vjplYU3S0ayseyHpxRQFSqATHgDnU$ > > [2] v3 add driver to support secure video decoder > - > https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek/list/?series=807308__;!!CTRNKA9wMg0ARbw!lYGWfjjIBlxJvwBXWyxHTyc2vew5YagqT_qJZrYONTH20h95qxC3PH9V91vjplYU3S0ayseyHpxRQFSq9TXMSIQ$ > > [3] v4 soc: mediatek: Add register definitions for GCE > - > https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek/patch/20231212121957.19231-2-shawn.sung@mediatek.com/__;!!CTRNKA9wMg0ARbw!lYGWfjjIBlxJvwBXWyxHTyc2vew5YagqT_qJZrYONTH20h95qxC3PH9V91vjplYU3S0ayseyHpxRQFSqkO4_0ac$ > > [4] v2 Add CMDQ driver support for mt8188 > - > https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek/list/?series=810302__;!!CTRNKA9wMg0ARbw!lYGWfjjIBlxJvwBXWyxHTyc2vew5YagqT_qJZrYONTH20h95qxC3PH9V91vjplYU3S0ayseyHpxRQFSqcXdKnXU$ > > [5] Add mediatek,gce-events definition to mediatek,gce-mailbox > bindings > - > https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek/list/?series=810938__;!!CTRNKA9wMg0ARbw!lYGWfjjIBlxJvwBXWyxHTyc2vew5YagqT_qJZrYONTH20h95qxC3PH9V91vjplYU3S0ayseyHpxRQFSqqGM08aE$ > > [6] v3 Add CMDQ secure driver for SVP > - > https://urldefense.com/v3/__https://patchwork.kernel.org/project/linux-mediatek/list/?series=812379__;!!CTRNKA9wMg0ARbw!lYGWfjjIBlxJvwBXWyxHTyc2vew5YagqT_qJZrYONTH20h95qxC3PH9V91vjplYU3S0ayseyHpxRQFSq_YXTH9A$ > > --- > Change in v3: > 1. fix kerneldoc problems > 2. fix typo in title and commit message > 3. adjust naming for secure variable > 4. add the missing part for is_suecure plane implementation > 5. use BIT_ULL macro to replace bit shifting > 6. move modification of ovl_adaptor part to the correct patch > 7. add TODO list in commit message > 8. add commit message for using share memory to store execute count > > Change in v2: > > 1. remove the DRIVER_RDNDER flag for mtk_drm_ioctl > 2. move cmdq_insert_backup_cookie into client driver > 3. move secure gce node define from mt8195-cherry.dtsi to mt8195.dtsi > --- > CK Hu (1): > drm/mediatek: Add interface to allocate MediaTek GEM buffer. > > Jason-JH.Lin (10): > drm/mediatek/uapi: Add DRM_MTK_GEM_CREATE_ENCRYPTED flag > drm/mediatek: Add secure buffer control flow to mtk_drm_gem > drm/mediatek: Add secure identify flag and funcution to > mtk_drm_plane > drm/mediatek: Add mtk_ddp_sec_write to config secure buffer info > drm/mediatek: Add get_sec_port interface to mtk_ddp_comp > drm/mediatek: Add secure layer config support for ovl > drm/mediatek: Add secure layer config support for ovl_adaptor > drm/mediatek: Add secure flow support to mediatek-drm > drm/mediatek: Add cmdq_insert_backup_cookie before secure pkt > finalize > arm64: dts: mt8195: Add secure mbox settings for vdosys > > arch/arm64/boot/dts/mediatek/mt8195.dtsi | 6 +- > drivers/gpu/drm/mediatek/mtk_disp_drv.h | 3 + > drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 31 +- > .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 15 + > drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 274 > +++++++++++++++++- > drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 1 + > drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 30 ++ > drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 14 + > drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 + > drivers/gpu/drm/mediatek/mtk_drm_gem.c | 122 ++++++++ > drivers/gpu/drm/mediatek/mtk_drm_gem.h | 16 + > drivers/gpu/drm/mediatek/mtk_drm_plane.c | 26 ++ > drivers/gpu/drm/mediatek/mtk_drm_plane.h | 2 + > drivers/gpu/drm/mediatek/mtk_mdp_rdma.c | 11 +- > drivers/gpu/drm/mediatek/mtk_mdp_rdma.h | 2 + > include/uapi/drm/mediatek_drm.h | 59 ++++ > 16 files changed, 607 insertions(+), 18 deletions(-) > create mode 100644 include/uapi/drm/mediatek_drm.h >
From: Jason-jh Lin <jason-jh.lin@mediatek.corp-partner.google.com> Memory Definitions: secure memory - Memory allocated in the TEE (Trusted Execution Environment) which is inaccessible in the REE (Rich Execution Environment, i.e. linux kernel/userspace). secure handle - Integer value which acts as reference to 'secure memory'. Used in communication between TEE and REE to reference 'secure memory'. secure buffer - 'secure memory' that is used to store decrypted, compressed video or for other general purposes in the TEE. secure surface - 'secure memory' that is used to store graphic buffers. Memory Usage in SVP: The overall flow of SVP starts with encrypted video coming in from an outside source into the REE. The REE will then allocate a 'secure buffer' and send the corresponding 'secure handle' along with the encrypted, compressed video data to the TEE. The TEE will then decrypt the video and store the result in the 'secure buffer'. The REE will then allocate a 'secure surface'. The REE will pass the 'secure handles' for both the 'secure buffer' and 'secure surface' into the TEE for video decoding. The video decoder HW will then decode the contents of the 'secure buffer' and place the result in the 'secure surface'. The REE will then attach the 'secure surface' to the overlay plane for rendering of the video. Everything relating to ensuring security of the actual contents of the 'secure buffer' and 'secure surface' is out of scope for the REE and is the responsibility of the TEE. DRM driver handles allocation of gem objects that are backed by a 'secure surface' and for displaying a 'secure surface' on the overlay plane. This introduces a new flag for object creation called DRM_MTK_GEM_CREATE_ENCRYPTED which indicates it should be a 'secure surface'. All changes here are in MediaTek specific code. --- TODO: 1) Remove get sec larb port interface in ddp_comp, ovl and ovl_adaptor. 2) Verify instruction for enabling/disabling dapc and larb port in TEE drop the sec_engine flags in normal world and. 3) Move DISP_REG_OVL_SECURE setting to secure world for mtk_disp_ovl.c. 4) Change the parameter register address in mtk_ddp_sec_write() from "u32 addr" to "struct cmdq_client_reg *cmdq_reg". 5) Implement setting mmsys routing table in the secure world series. --- Based on 5 series and 1 patch: [1] v3 dma-buf: heaps: Add MediaTek secure heap - https://patchwork.kernel.org/project/linux-mediatek/list/?series=809023 [2] v3 add driver to support secure video decoder - https://patchwork.kernel.org/project/linux-mediatek/list/?series=807308 [3] v4 soc: mediatek: Add register definitions for GCE - https://patchwork.kernel.org/project/linux-mediatek/patch/20231212121957.19231-2-shawn.sung@mediatek.com/ [4] v2 Add CMDQ driver support for mt8188 - https://patchwork.kernel.org/project/linux-mediatek/list/?series=810302 [5] Add mediatek,gce-events definition to mediatek,gce-mailbox bindings - https://patchwork.kernel.org/project/linux-mediatek/list/?series=810938 [6] v3 Add CMDQ secure driver for SVP - https://patchwork.kernel.org/project/linux-mediatek/list/?series=812379 --- Change in v3: 1. fix kerneldoc problems 2. fix typo in title and commit message 3. adjust naming for secure variable 4. add the missing part for is_suecure plane implementation 5. use BIT_ULL macro to replace bit shifting 6. move modification of ovl_adaptor part to the correct patch 7. add TODO list in commit message 8. add commit message for using share memory to store execute count Change in v2: 1. remove the DRIVER_RDNDER flag for mtk_drm_ioctl 2. move cmdq_insert_backup_cookie into client driver 3. move secure gce node define from mt8195-cherry.dtsi to mt8195.dtsi --- CK Hu (1): drm/mediatek: Add interface to allocate MediaTek GEM buffer. Jason-JH.Lin (10): drm/mediatek/uapi: Add DRM_MTK_GEM_CREATE_ENCRYPTED flag drm/mediatek: Add secure buffer control flow to mtk_drm_gem drm/mediatek: Add secure identify flag and funcution to mtk_drm_plane drm/mediatek: Add mtk_ddp_sec_write to config secure buffer info drm/mediatek: Add get_sec_port interface to mtk_ddp_comp drm/mediatek: Add secure layer config support for ovl drm/mediatek: Add secure layer config support for ovl_adaptor drm/mediatek: Add secure flow support to mediatek-drm drm/mediatek: Add cmdq_insert_backup_cookie before secure pkt finalize arm64: dts: mt8195: Add secure mbox settings for vdosys arch/arm64/boot/dts/mediatek/mt8195.dtsi | 6 +- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 3 + drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 31 +- .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 15 + drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 274 +++++++++++++++++- drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 1 + drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 30 ++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 14 + drivers/gpu/drm/mediatek/mtk_drm_drv.c | 13 + drivers/gpu/drm/mediatek/mtk_drm_gem.c | 122 ++++++++ drivers/gpu/drm/mediatek/mtk_drm_gem.h | 16 + drivers/gpu/drm/mediatek/mtk_drm_plane.c | 26 ++ drivers/gpu/drm/mediatek/mtk_drm_plane.h | 2 + drivers/gpu/drm/mediatek/mtk_mdp_rdma.c | 11 +- drivers/gpu/drm/mediatek/mtk_mdp_rdma.h | 2 + include/uapi/drm/mediatek_drm.h | 59 ++++ 16 files changed, 607 insertions(+), 18 deletions(-) create mode 100644 include/uapi/drm/mediatek_drm.h