[v2,01/34] media: introduce common helpers for video firmware handling
Commit Message
Re-organize the video driver code by introducing a new folder
'vcodec' and placing 'venus' driver code inside that.
Introduce common helpers for trustzone based firmware
load/unload etc. which are placed in common folder
i.e. 'vcodec'.
Use these helpers in 'venus' driver. These helpers will be
used by 'iris' driver as well which is introduced later
in this patch series.
Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
---
drivers/media/platform/qcom/Kconfig | 2 +-
drivers/media/platform/qcom/Makefile | 2 +-
drivers/media/platform/qcom/vcodec/firmware.c | 147 +++++++++
drivers/media/platform/qcom/vcodec/firmware.h | 21 ++
.../media/platform/qcom/{ => vcodec}/venus/Kconfig | 0
.../platform/qcom/{ => vcodec}/venus/Makefile | 4 +-
.../media/platform/qcom/{ => vcodec}/venus/core.c | 102 +++++-
.../media/platform/qcom/{ => vcodec}/venus/core.h | 0
.../media/platform/qcom/{ => vcodec}/venus/dbgfs.c | 0
.../media/platform/qcom/{ => vcodec}/venus/dbgfs.h | 0
.../platform/qcom/vcodec/venus/firmware_no_tz.c | 194 +++++++++++
.../platform/qcom/vcodec/venus/firmware_no_tz.h | 19 ++
.../platform/qcom/{ => vcodec}/venus/helpers.c | 0
.../platform/qcom/{ => vcodec}/venus/helpers.h | 0
.../media/platform/qcom/{ => vcodec}/venus/hfi.c | 0
.../media/platform/qcom/{ => vcodec}/venus/hfi.h | 0
.../platform/qcom/{ => vcodec}/venus/hfi_cmds.c | 0
.../platform/qcom/{ => vcodec}/venus/hfi_cmds.h | 0
.../platform/qcom/{ => vcodec}/venus/hfi_helper.h | 0
.../platform/qcom/{ => vcodec}/venus/hfi_msgs.c | 0
.../platform/qcom/{ => vcodec}/venus/hfi_msgs.h | 0
.../platform/qcom/{ => vcodec}/venus/hfi_parser.c | 0
.../platform/qcom/{ => vcodec}/venus/hfi_parser.h | 0
.../qcom/{ => vcodec}/venus/hfi_plat_bufs.h | 0
.../qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c | 0
.../qcom/{ => vcodec}/venus/hfi_platform.c | 0
.../qcom/{ => vcodec}/venus/hfi_platform.h | 0
.../qcom/{ => vcodec}/venus/hfi_platform_v4.c | 0
.../qcom/{ => vcodec}/venus/hfi_platform_v6.c | 0
.../platform/qcom/{ => vcodec}/venus/hfi_venus.c | 21 +-
.../platform/qcom/{ => vcodec}/venus/hfi_venus.h | 0
.../qcom/{ => vcodec}/venus/hfi_venus_io.h | 0
.../platform/qcom/{ => vcodec}/venus/pm_helpers.c | 0
.../platform/qcom/{ => vcodec}/venus/pm_helpers.h | 0
.../media/platform/qcom/{ => vcodec}/venus/vdec.c | 0
.../media/platform/qcom/{ => vcodec}/venus/vdec.h | 0
.../platform/qcom/{ => vcodec}/venus/vdec_ctrls.c | 0
.../media/platform/qcom/{ => vcodec}/venus/venc.c | 0
.../media/platform/qcom/{ => vcodec}/venus/venc.h | 0
.../platform/qcom/{ => vcodec}/venus/venc_ctrls.c | 0
drivers/media/platform/qcom/venus/firmware.c | 363 ---------------------
drivers/media/platform/qcom/venus/firmware.h | 26 --
42 files changed, 492 insertions(+), 409 deletions(-)
create mode 100644 drivers/media/platform/qcom/vcodec/firmware.c
create mode 100644 drivers/media/platform/qcom/vcodec/firmware.h
rename drivers/media/platform/qcom/{ => vcodec}/venus/Kconfig (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/Makefile (83%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/core.c (91%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/core.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.h (100%)
create mode 100644 drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
create mode 100644 drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_helper.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v4.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v6.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.c (99%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus_io.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec_ctrls.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.c (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.h (100%)
rename drivers/media/platform/qcom/{ => vcodec}/venus/venc_ctrls.c (100%)
delete mode 100644 drivers/media/platform/qcom/venus/firmware.c
delete mode 100644 drivers/media/platform/qcom/venus/firmware.h
Comments
On 18/12/2023 13:31, Dikshita Agarwal wrote:
> Re-organize the video driver code by introducing a new folder
> 'vcodec' and placing 'venus' driver code inside that.
>
> Introduce common helpers for trustzone based firmware
> load/unload etc. which are placed in common folder
> i.e. 'vcodec'.
> Use these helpers in 'venus' driver. These helpers will be
> used by 'iris' driver as well which is introduced later
> in this patch series.
But why do you need to move the venus driver to subdir?
>
> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
> ---
> drivers/media/platform/qcom/Kconfig | 2 +-
> drivers/media/platform/qcom/Makefile | 2 +-
> drivers/media/platform/qcom/vcodec/firmware.c | 147 +++++++++
> drivers/media/platform/qcom/vcodec/firmware.h | 21 ++
> .../media/platform/qcom/{ => vcodec}/venus/Kconfig | 0
> .../platform/qcom/{ => vcodec}/venus/Makefile | 4 +-
> .../media/platform/qcom/{ => vcodec}/venus/core.c | 102 +++++-
> .../media/platform/qcom/{ => vcodec}/venus/core.h | 0
> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.c | 0
> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.h | 0
> .../platform/qcom/vcodec/venus/firmware_no_tz.c | 194 +++++++++++
> .../platform/qcom/vcodec/venus/firmware_no_tz.h | 19 ++
> .../platform/qcom/{ => vcodec}/venus/helpers.c | 0
> .../platform/qcom/{ => vcodec}/venus/helpers.h | 0
> .../media/platform/qcom/{ => vcodec}/venus/hfi.c | 0
> .../media/platform/qcom/{ => vcodec}/venus/hfi.h | 0
> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.c | 0
> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.h | 0
> .../platform/qcom/{ => vcodec}/venus/hfi_helper.h | 0
> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.c | 0
> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.h | 0
> .../platform/qcom/{ => vcodec}/venus/hfi_parser.c | 0
> .../platform/qcom/{ => vcodec}/venus/hfi_parser.h | 0
> .../qcom/{ => vcodec}/venus/hfi_plat_bufs.h | 0
> .../qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c | 0
> .../qcom/{ => vcodec}/venus/hfi_platform.c | 0
> .../qcom/{ => vcodec}/venus/hfi_platform.h | 0
> .../qcom/{ => vcodec}/venus/hfi_platform_v4.c | 0
> .../qcom/{ => vcodec}/venus/hfi_platform_v6.c | 0
> .../platform/qcom/{ => vcodec}/venus/hfi_venus.c | 21 +-
> .../platform/qcom/{ => vcodec}/venus/hfi_venus.h | 0
> .../qcom/{ => vcodec}/venus/hfi_venus_io.h | 0
> .../platform/qcom/{ => vcodec}/venus/pm_helpers.c | 0
> .../platform/qcom/{ => vcodec}/venus/pm_helpers.h | 0
> .../media/platform/qcom/{ => vcodec}/venus/vdec.c | 0
> .../media/platform/qcom/{ => vcodec}/venus/vdec.h | 0
> .../platform/qcom/{ => vcodec}/venus/vdec_ctrls.c | 0
> .../media/platform/qcom/{ => vcodec}/venus/venc.c | 0
> .../media/platform/qcom/{ => vcodec}/venus/venc.h | 0
> .../platform/qcom/{ => vcodec}/venus/venc_ctrls.c | 0
> drivers/media/platform/qcom/venus/firmware.c | 363 ---------------------
> drivers/media/platform/qcom/venus/firmware.h | 26 --
> 42 files changed, 492 insertions(+), 409 deletions(-)
> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.c
> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.h
> rename drivers/media/platform/qcom/{ => vcodec}/venus/Kconfig (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/Makefile (83%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.c (91%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.h (100%)
> create mode 100644 drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
> create mode 100644 drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_helper.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v4.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v6.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.c (99%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus_io.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec_ctrls.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.c (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.h (100%)
> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc_ctrls.c (100%)
> delete mode 100644 drivers/media/platform/qcom/venus/firmware.c
> delete mode 100644 drivers/media/platform/qcom/venus/firmware.h
>
> diff --git a/drivers/media/platform/qcom/Kconfig b/drivers/media/platform/qcom/Kconfig
> index cc5799b..e94142f 100644
> --- a/drivers/media/platform/qcom/Kconfig
> +++ b/drivers/media/platform/qcom/Kconfig
> @@ -3,4 +3,4 @@
> comment "Qualcomm media platform drivers"
>
> source "drivers/media/platform/qcom/camss/Kconfig"
> -source "drivers/media/platform/qcom/venus/Kconfig"
> +source "drivers/media/platform/qcom/vcodec/venus/Kconfig"
> diff --git a/drivers/media/platform/qcom/Makefile b/drivers/media/platform/qcom/Makefile
> index 4f055c3..3d2d82b 100644
> --- a/drivers/media/platform/qcom/Makefile
> +++ b/drivers/media/platform/qcom/Makefile
> @@ -1,3 +1,3 @@
> # SPDX-License-Identifier: GPL-2.0-only
> obj-y += camss/
> -obj-y += venus/
> +obj-y += vcodec/venus/
> diff --git a/drivers/media/platform/qcom/vcodec/firmware.c b/drivers/media/platform/qcom/vcodec/firmware.c
> new file mode 100644
> index 0000000..dbc220a
> --- /dev/null
> +++ b/drivers/media/platform/qcom/vcodec/firmware.c
> @@ -0,0 +1,147 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
> + */
> +
> +#include <linux/device.h>
> +#include <linux/dma-mapping.h>
> +#include <linux/firmware.h>
> +#include <linux/kernel.h>
> +#include <linux/iommu.h>
> +#include <linux/of_device.h>
> +#include <linux/firmware/qcom/qcom_scm.h>
> +#include <linux/of_reserved_mem.h>
> +#include <linux/platform_device.h>
> +#include <linux/soc/qcom/mdt_loader.h>
> +
> +#include "firmware.h"
> +
> +bool use_tz(struct device *core_dev)
All these functions must get some sane prefix. Otherwise a generic
'use_tz' function is too polluting for the global namespace.
> +{
> + struct device_node *np;
> +
> + np = of_get_child_by_name(core_dev->of_node, "video-firmware");
> + if (!np)
> + return true;
> +
> + return false;
> +}
> +
> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
> + u32 cp_nonpixel_size, u32 pas_id)
> +{
> + int ret;
> + /*
> + * Clues for porting using downstream data:
> + * cp_start = 0
> + * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
> + * This works, as the non-secure context bank is placed
> + * contiguously right after the Content Protection region.
> + *
> + * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
> + * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
> + */
> + ret = qcom_scm_mem_protect_video_var(cp_start,
> + cp_size,
> + cp_nonpixel_start,
> + cp_nonpixel_size);
> + if (ret)
> + qcom_scm_pas_shutdown(pas_id);
> +
> + return ret;
> +}
> +
> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
> + size_t *mem_size, u32 pas_id, bool use_tz)
> +{
> + const struct firmware *firmware = NULL;
> + struct reserved_mem *rmem;
> + struct device_node *node;
> + void *mem_virt = NULL;
> + ssize_t fw_size = 0;
> + int ret;
> +
> + if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
Why? Can you just depend on it?
> + (use_tz && !qcom_scm_is_available()))
> + return -EPROBE_DEFER;
> +
> + if (!fw_name || !(*fw_name))
> + return -EINVAL;
> +
> + *mem_phys = 0;
> + *mem_size = 0;
> +
> + node = of_parse_phandle(dev->of_node, "memory-region", 0);
> + if (!node) {
> + dev_err(dev, "no memory-region specified\n");
> + return -EINVAL;
> + }
> +
> + rmem = of_reserved_mem_lookup(node);
> + of_node_put(node);
> + if (!rmem) {
> + dev_err(dev, "failed to lookup reserved memory-region\n");
> + return -EINVAL;
> + }
> +
> + ret = request_firmware(&firmware, fw_name, dev);
> + if (ret) {
> + dev_err(dev, "%s: failed to request fw \"%s\", error %d\n",
> + __func__, fw_name, ret);
> + return ret;
> + }
> +
> + fw_size = qcom_mdt_get_size(firmware);
> + if (fw_size < 0) {
> + ret = fw_size;
> + dev_err(dev, "%s: out of bound fw image fw size: %ld\n",
> + __func__, fw_size);
> + goto err_release_fw;
> + }
> +
> + *mem_phys = rmem->base;
> + *mem_size = rmem->size;
> +
> + if (*mem_size < fw_size) {
> + ret = -EINVAL;
> + goto err_release_fw;
> + }
> +
> + mem_virt = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
> + if (!mem_virt) {
> + dev_err(dev, "unable to remap fw memory region %pa size %#zx\n",
> + mem_phys, *mem_size);
> + goto err_release_fw;
> + }
> +
> + if (use_tz)
> + ret = qcom_mdt_load(dev, firmware, fw_name, pas_id, mem_virt,
> + *mem_phys, *mem_size, NULL);
> + else
> + ret = qcom_mdt_load_no_init(dev, firmware, fw_name, pas_id, mem_virt,
> + *mem_phys, *mem_size, NULL);
> + if (ret) {
> + dev_err(dev, "%s: error %d loading fw \"%s\"\n",
> + __func__, ret, fw_name);
> + }
> +
> + memunmap(mem_virt);
> +err_release_fw:
> + release_firmware(firmware);
> + return ret;
> +}
> +
> +int auth_reset_fw(u32 pas_id)
> +{
> + return qcom_scm_pas_auth_and_reset(pas_id);
> +}
> +
> +void unload_fw(u32 pas_id)
> +{
> + qcom_scm_pas_shutdown(pas_id);
> +}
> +
> +int set_hw_state(bool resume)
> +{
> + return qcom_scm_set_remote_state(resume, 0);
> +}
> diff --git a/drivers/media/platform/qcom/vcodec/firmware.h b/drivers/media/platform/qcom/vcodec/firmware.h
> new file mode 100644
> index 0000000..7d410a8
> --- /dev/null
> +++ b/drivers/media/platform/qcom/vcodec/firmware.h
> @@ -0,0 +1,21 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
> + */
> +
> +#ifndef _FIRMWARE_H_
> +#define _FIRMWARE_H_
> +
> +#include <linux/device.h>
> +#include <linux/types.h>
> +
> +bool use_tz(struct device *core_dev);
> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
> + size_t *mem_size, u32 pas_id, bool use_tz);
> +int auth_reset_fw(u32 pas_id);
> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
> + u32 cp_nonpixel_size, u32 pas_id);
> +void unload_fw(u32 pas_id);
> +int set_hw_state(bool resume);
> +
> +#endif
> diff --git a/drivers/media/platform/qcom/venus/Kconfig b/drivers/media/platform/qcom/vcodec/venus/Kconfig
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/Kconfig
> rename to drivers/media/platform/qcom/vcodec/venus/Kconfig
> diff --git a/drivers/media/platform/qcom/venus/Makefile b/drivers/media/platform/qcom/vcodec/venus/Makefile
> similarity index 83%
> rename from drivers/media/platform/qcom/venus/Makefile
> rename to drivers/media/platform/qcom/vcodec/venus/Makefile
> index 91ee6be..f6f3a88 100644
> --- a/drivers/media/platform/qcom/venus/Makefile
> +++ b/drivers/media/platform/qcom/vcodec/venus/Makefile
> @@ -1,7 +1,9 @@
> # SPDX-License-Identifier: GPL-2.0
> # Makefile for Qualcomm Venus driver
>
> -venus-core-objs += core.o helpers.o firmware.o \
> +venus-core-objs += ../firmware.o
> +
> +venus-core-objs += core.o helpers.o firmware_no_tz.o \
> hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
> hfi_parser.o pm_helpers.o dbgfs.o \
> hfi_platform.o hfi_platform_v4.o \
> diff --git a/drivers/media/platform/qcom/venus/core.c b/drivers/media/platform/qcom/vcodec/venus/core.c
> similarity index 91%
> rename from drivers/media/platform/qcom/venus/core.c
> rename to drivers/media/platform/qcom/vcodec/venus/core.c
> index 9cffe97..56d9a53 100644
> --- a/drivers/media/platform/qcom/venus/core.c
> +++ b/drivers/media/platform/qcom/vcodec/venus/core.c
> @@ -22,7 +22,8 @@
> #include <media/v4l2-ioctl.h>
>
> #include "core.h"
> -#include "firmware.h"
> +#include "../firmware.h"
> +#include "firmware_no_tz.h"
> #include "pm_helpers.h"
> #include "hfi_venus_io.h"
>
> @@ -86,6 +87,8 @@ static void venus_sys_error_handler(struct work_struct *work)
> struct venus_core *core =
> container_of(work, struct venus_core, work.work);
> int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
> + const struct venus_resources *res = core->res;
> + const char *fwpath = NULL;
> const char *err_msg = "";
> bool failed = false;
>
> @@ -107,7 +110,10 @@ static void venus_sys_error_handler(struct work_struct *work)
>
> mutex_lock(&core->lock);
>
> - venus_shutdown(core);
> + if (core->use_tz)
> + unload_fw(VENUS_PAS_ID);
> + else
> + unload_fw_no_tz(core);
This is more than introducing helpers.
>
> venus_coredump(core);
>
> @@ -127,12 +133,39 @@ static void venus_sys_error_handler(struct work_struct *work)
> failed = true;
> }
>
> - ret = venus_boot(core);
> + ret = of_property_read_string_index(core->dev->of_node, "firmware-name", 0,
> + &fwpath);
> + if (ret)
> + fwpath = core->res->fwname;
> +
> + ret = load_fw(core->dev, fwpath, &core->fw.mem_phys, &core->fw.mem_size,
> + VENUS_PAS_ID, core->use_tz);
So, we had a nice local 'venus_boot'. Instead we now have a pile of code
with non-generic prefixes, etc. If you are introducing helpers, please
refrain from inlining of calling functions, etc. Just move the code to
your helpers.
NAK for the rest of the patch.
> if (ret && !failed) {
> - err_msg = "boot Venus";
> + err_msg = "load FW";
> failed = true;
> }
>
> + if (core->use_tz)
> + ret = auth_reset_fw(VENUS_PAS_ID);
> + else
> + ret = auth_reset_fw_no_tz(core, core->fw.mem_phys, core->fw.mem_size);
> + if (ret && !failed) {
> + err_msg = "Auth and Reset";
> + failed = true;
> + }
> +
> + if (core->use_tz && res->cp_size) {
> + ret = protect_secure_region(res->cp_start,
> + res->cp_size,
> + res->cp_nonpixel_start,
> + res->cp_nonpixel_size,
> + VENUS_PAS_ID);
> + if (ret && !failed) {
> + err_msg = "Protect CP Mem";
> + failed = true;
> + }
> + }
> +
> ret = hfi_core_resume(core, true);
> if (ret && !failed) {
> err_msg = "resume HFI";
> @@ -281,7 +314,9 @@ static irqreturn_t venus_isr_thread(int irq, void *dev_id)
>
> static int venus_probe(struct platform_device *pdev)
> {
> + const struct venus_resources *res;
> struct device *dev = &pdev->dev;
> + const char *fwpath = NULL;
> struct venus_core *core;
> int ret;
>
> @@ -362,14 +397,42 @@ static int venus_probe(struct platform_device *pdev)
> if (ret)
> goto err_runtime_disable;
>
> - ret = venus_firmware_init(core);
> + core->use_tz = use_tz(core->dev);
> +
> + if (!core->use_tz) {
> + ret = init_fw_no_tz(core);
> + if (ret)
> + goto err_of_depopulate;
> + }
> +
> + ret = of_property_read_string_index(dev->of_node, "firmware-name", 0,
> + &fwpath);
> if (ret)
> - goto err_of_depopulate;
> + fwpath = core->res->fwname;
>
> - ret = venus_boot(core);
> + ret = load_fw(core->dev, fwpath, &core->fw.mem_phys, &core->fw.mem_size,
> + VENUS_PAS_ID, core->use_tz);
> if (ret)
> goto err_firmware_deinit;
>
> + if (core->use_tz)
> + ret = auth_reset_fw(VENUS_PAS_ID);
> + else
> + ret = auth_reset_fw_no_tz(core, core->fw.mem_phys, core->fw.mem_size);
> + if (ret)
> + goto err_firmware_deinit;
> +
> + res = core->res;
> + if (core->use_tz && res->cp_size) {
> + ret = protect_secure_region(res->cp_start,
> + res->cp_size,
> + res->cp_nonpixel_start,
> + res->cp_nonpixel_size,
> + VENUS_PAS_ID);
> + if (ret)
> + goto err_firmware_deinit;
> + }
> +
> ret = hfi_core_resume(core, true);
> if (ret)
> goto err_venus_shutdown;
> @@ -399,9 +462,13 @@ static int venus_probe(struct platform_device *pdev)
> err_dev_unregister:
> v4l2_device_unregister(&core->v4l2_dev);
> err_venus_shutdown:
> - venus_shutdown(core);
> + if (core->use_tz)
> + unload_fw(VENUS_PAS_ID);
> + else
> + unload_fw_no_tz(core);
> err_firmware_deinit:
> - venus_firmware_deinit(core);
> + if (!core->use_tz)
> + deinit_fw_no_tz(core);
> err_of_depopulate:
> of_platform_depopulate(dev);
> err_runtime_disable:
> @@ -430,10 +497,15 @@ static void venus_remove(struct platform_device *pdev)
> ret = hfi_core_deinit(core, true);
> WARN_ON(ret);
>
> - venus_shutdown(core);
> + if (core->use_tz)
> + unload_fw(VENUS_PAS_ID);
> + else
> + unload_fw_no_tz(core);
> +
> of_platform_depopulate(dev);
>
> - venus_firmware_deinit(core);
> + if (!core->use_tz)
> + deinit_fw_no_tz(core);
>
> pm_runtime_put_sync(dev);
> pm_runtime_disable(dev);
> @@ -455,8 +527,12 @@ static void venus_core_shutdown(struct platform_device *pdev)
> struct venus_core *core = platform_get_drvdata(pdev);
>
> pm_runtime_get_sync(core->dev);
> - venus_shutdown(core);
> - venus_firmware_deinit(core);
> + if (core->use_tz) {
> + unload_fw(VENUS_PAS_ID);
> + } else {
> + unload_fw_no_tz(core);
> + deinit_fw_no_tz(core);
> + }
> pm_runtime_put_sync(core->dev);
> }
>
> diff --git a/drivers/media/platform/qcom/venus/core.h b/drivers/media/platform/qcom/vcodec/venus/core.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/core.h
> rename to drivers/media/platform/qcom/vcodec/venus/core.h
> diff --git a/drivers/media/platform/qcom/venus/dbgfs.c b/drivers/media/platform/qcom/vcodec/venus/dbgfs.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/dbgfs.c
> rename to drivers/media/platform/qcom/vcodec/venus/dbgfs.c
> diff --git a/drivers/media/platform/qcom/venus/dbgfs.h b/drivers/media/platform/qcom/vcodec/venus/dbgfs.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/dbgfs.h
> rename to drivers/media/platform/qcom/vcodec/venus/dbgfs.h
> diff --git a/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c b/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
> new file mode 100644
> index 0000000..9dca6e23
> --- /dev/null
> +++ b/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
> @@ -0,0 +1,194 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (C) 2017 Linaro Ltd.
> + */
> +
> +#include <linux/iommu.h>
> +#include <linux/of_device.h>
> +#include "core.h"
> +#include "firmware_no_tz.h"
> +#include "hfi_venus_io.h"
> +
> +#define VENUS_FW_MEM_SIZE (6 * SZ_1M)
> +#define VENUS_FW_START_ADDR 0x0
> +
> +int init_fw_no_tz(struct venus_core *core)
> +{
> + struct platform_device_info info;
> + struct iommu_domain *iommu_dom;
> + struct platform_device *pdev;
> + struct device_node *np;
> + int ret;
> +
> + np = of_get_child_by_name(core->dev->of_node, "video-firmware");
> +
> + memset(&info, 0, sizeof(info));
> + info.fwnode = &np->fwnode;
> + info.parent = core->dev;
> + info.name = np->name;
> + info.dma_mask = DMA_BIT_MASK(32);
> +
> + pdev = platform_device_register_full(&info);
> + if (IS_ERR(pdev)) {
> + of_node_put(np);
> + return PTR_ERR(pdev);
> + }
> +
> + pdev->dev.of_node = np;
> +
> + ret = of_dma_configure(&pdev->dev, np, true);
> + if (ret) {
> + dev_err(core->dev, "dma configure fail\n");
> + goto err_unregister;
> + }
> +
> + core->fw.dev = &pdev->dev;
> +
> + iommu_dom = iommu_domain_alloc(&platform_bus_type);
> + if (!iommu_dom) {
> + dev_err(core->fw.dev, "Failed to allocate iommu domain\n");
> + ret = -ENOMEM;
> + goto err_unregister;
> + }
> +
> + ret = iommu_attach_device(iommu_dom, core->fw.dev);
> + if (ret) {
> + dev_err(core->fw.dev, "could not attach device\n");
> + goto err_iommu_free;
> + }
> +
> + core->fw.iommu_domain = iommu_dom;
> +
> + of_node_put(np);
> +
> + return 0;
> +
> +err_iommu_free:
> + iommu_domain_free(iommu_dom);
> +err_unregister:
> + platform_device_unregister(pdev);
> + of_node_put(np);
> + return ret;
> +}
> +
> +void deinit_fw_no_tz(struct venus_core *core)
> +{
> + struct iommu_domain *iommu;
> +
> + if (!core->fw.dev)
> + return;
> +
> + iommu = core->fw.iommu_domain;
> +
> + iommu_detach_device(iommu, core->fw.dev);
> +
> + if (iommu) {
> + iommu_domain_free(iommu);
> + iommu = NULL;
> + }
> +
> + platform_device_unregister(to_platform_device(core->fw.dev));
> +}
> +
> +static void reset_cpu_no_tz(struct venus_core *core)
> +{
> + u32 fw_size = core->fw.mapped_mem_size;
> + void __iomem *wrapper_base;
> +
> + if (IS_IRIS2_1(core))
> + wrapper_base = core->wrapper_tz_base;
> + else
> + wrapper_base = core->wrapper_base;
> +
> + writel(0, wrapper_base + WRAPPER_FW_START_ADDR);
> + writel(fw_size, wrapper_base + WRAPPER_FW_END_ADDR);
> + writel(0, wrapper_base + WRAPPER_CPA_START_ADDR);
> + writel(fw_size, wrapper_base + WRAPPER_CPA_END_ADDR);
> + writel(fw_size, wrapper_base + WRAPPER_NONPIX_START_ADDR);
> + writel(fw_size, wrapper_base + WRAPPER_NONPIX_END_ADDR);
> +
> + if (IS_IRIS2_1(core)) {
> + /* Bring XTSS out of reset */
> + writel(0, wrapper_base + WRAPPER_TZ_XTSS_SW_RESET);
> + } else {
> + writel(0x0, wrapper_base + WRAPPER_CPU_CGC_DIS);
> + writel(0x0, wrapper_base + WRAPPER_CPU_CLOCK_CONFIG);
> +
> + /* Bring ARM9 out of reset */
> + writel(0, wrapper_base + WRAPPER_A9SS_SW_RESET);
> + }
> +}
> +
> +void set_hw_state_no_tz(struct venus_core *core, bool resume)
> +{
> + if (resume) {
> + reset_cpu_no_tz(core);
> + } else {
> + if (IS_IRIS2_1(core))
> + writel(WRAPPER_XTSS_SW_RESET_BIT,
> + core->wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
> + else
> + writel(WRAPPER_A9SS_SW_RESET_BIT,
> + core->wrapper_base + WRAPPER_A9SS_SW_RESET);
> + }
> +}
> +
> +int auth_reset_fw_no_tz(struct venus_core *core, phys_addr_t mem_phys,
> + size_t mem_size)
> +{
> + struct iommu_domain *iommu;
> + struct device *dev;
> + int ret;
> +
> + dev = core->fw.dev;
> + if (!dev)
> + return -EPROBE_DEFER;
> +
> + iommu = core->fw.iommu_domain;
> + core->fw.mapped_mem_size = mem_size;
> +
> + ret = iommu_map(iommu, VENUS_FW_START_ADDR, mem_phys, mem_size,
> + IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV, GFP_KERNEL);
> + if (ret) {
> + dev_err(dev, "could not map video firmware region\n");
> + return ret;
> + }
> +
> + reset_cpu_no_tz(core);
> +
> + return 0;
> +}
> +
> +void unload_fw_no_tz(struct venus_core *core)
> +{
> + const size_t mapped = core->fw.mapped_mem_size;
> + struct iommu_domain *iommu;
> + size_t unmapped;
> + u32 reg;
> + struct device *dev = core->fw.dev;
> + void __iomem *wrapper_base = core->wrapper_base;
> + void __iomem *wrapper_tz_base = core->wrapper_tz_base;
> +
> + if (IS_IRIS2_1(core)) {
> + /* Assert the reset to XTSS */
> + reg = readl(wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
> + reg |= WRAPPER_XTSS_SW_RESET_BIT;
> + writel(reg, wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
> + } else {
> + /* Assert the reset to ARM9 */
> + reg = readl(wrapper_base + WRAPPER_A9SS_SW_RESET);
> + reg |= WRAPPER_A9SS_SW_RESET_BIT;
> + writel(reg, wrapper_base + WRAPPER_A9SS_SW_RESET);
> + }
> +
> + iommu = core->fw.iommu_domain;
> +
> + if (core->fw.mapped_mem_size && iommu) {
> + unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, mapped);
> +
> + if (unmapped != mapped)
> + dev_err(dev, "failed to unmap firmware\n");
> + else
> + core->fw.mapped_mem_size = 0;
> + }
> +}
> diff --git a/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h b/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
> new file mode 100644
> index 0000000..5f008ef
> --- /dev/null
> +++ b/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
> @@ -0,0 +1,19 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Copyright (C) 2017 Linaro Ltd.
> + */
> +#ifndef __FIRMWARE_NO_TZ_H__
> +#define __FIRMWARE_NO_TZ_H__
> +
> +struct device;
> +
> +#define VENUS_PAS_ID 9
> +
> +int init_fw_no_tz(struct venus_core *core);
> +void deinit_fw_no_tz(struct venus_core *core);
> +int auth_reset_fw_no_tz(struct venus_core *core, phys_addr_t mem_phys,
> + size_t mem_size);
> +void unload_fw_no_tz(struct venus_core *core);
> +void set_hw_state_no_tz(struct venus_core *core, bool resume);
> +
> +#endif
> diff --git a/drivers/media/platform/qcom/venus/helpers.c b/drivers/media/platform/qcom/vcodec/venus/helpers.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/helpers.c
> rename to drivers/media/platform/qcom/vcodec/venus/helpers.c
> diff --git a/drivers/media/platform/qcom/venus/helpers.h b/drivers/media/platform/qcom/vcodec/venus/helpers.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/helpers.h
> rename to drivers/media/platform/qcom/vcodec/venus/helpers.h
> diff --git a/drivers/media/platform/qcom/venus/hfi.c b/drivers/media/platform/qcom/vcodec/venus/hfi.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi.c
> diff --git a/drivers/media/platform/qcom/venus/hfi.h b/drivers/media/platform/qcom/vcodec/venus/hfi.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi.h
> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.c b/drivers/media/platform/qcom/vcodec/venus/hfi_cmds.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_cmds.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_cmds.c
> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h b/drivers/media/platform/qcom/vcodec/venus/hfi_cmds.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_cmds.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_cmds.h
> diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h b/drivers/media/platform/qcom/vcodec/venus/hfi_helper.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_helper.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_helper.h
> diff --git a/drivers/media/platform/qcom/venus/hfi_msgs.c b/drivers/media/platform/qcom/vcodec/venus/hfi_msgs.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_msgs.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_msgs.c
> diff --git a/drivers/media/platform/qcom/venus/hfi_msgs.h b/drivers/media/platform/qcom/vcodec/venus/hfi_msgs.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_msgs.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_msgs.h
> diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c b/drivers/media/platform/qcom/vcodec/venus/hfi_parser.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_parser.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_parser.c
> diff --git a/drivers/media/platform/qcom/venus/hfi_parser.h b/drivers/media/platform/qcom/vcodec/venus/hfi_parser.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_parser.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_parser.h
> diff --git a/drivers/media/platform/qcom/venus/hfi_plat_bufs.h b/drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_plat_bufs.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs.h
> diff --git a/drivers/media/platform/qcom/venus/hfi_plat_bufs_v6.c b/drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs_v6.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_plat_bufs_v6.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs_v6.c
> diff --git a/drivers/media/platform/qcom/venus/hfi_platform.c b/drivers/media/platform/qcom/vcodec/venus/hfi_platform.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_platform.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform.c
> diff --git a/drivers/media/platform/qcom/venus/hfi_platform.h b/drivers/media/platform/qcom/vcodec/venus/hfi_platform.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_platform.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform.h
> diff --git a/drivers/media/platform/qcom/venus/hfi_platform_v4.c b/drivers/media/platform/qcom/vcodec/venus/hfi_platform_v4.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_platform_v4.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform_v4.c
> diff --git a/drivers/media/platform/qcom/venus/hfi_platform_v6.c b/drivers/media/platform/qcom/vcodec/venus/hfi_platform_v6.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_platform_v6.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform_v6.c
> diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c b/drivers/media/platform/qcom/vcodec/venus/hfi_venus.c
> similarity index 99%
> rename from drivers/media/platform/qcom/venus/hfi_venus.c
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus.c
> index f9437b6..5a68db9 100644
> --- a/drivers/media/platform/qcom/venus/hfi_venus.c
> +++ b/drivers/media/platform/qcom/vcodec/venus/hfi_venus.c
> @@ -13,11 +13,12 @@
> #include <linux/slab.h>
>
> #include "core.h"
> +#include "../firmware.h"
> #include "hfi_cmds.h"
> #include "hfi_msgs.h"
> #include "hfi_venus.h"
> #include "hfi_venus_io.h"
> -#include "firmware.h"
> +#include "firmware_no_tz.h"
>
> #define HFI_MASK_QHDR_TX_TYPE 0xff000000
> #define HFI_MASK_QHDR_RX_TYPE 0x00ff0000
> @@ -635,7 +636,10 @@ static int venus_power_off(struct venus_hfi_device *hdev)
> if (!hdev->power_enabled)
> return 0;
>
> - ret = venus_set_hw_state_suspend(hdev->core);
> + if (hdev->core->use_tz)
> + ret = set_hw_state(false);
> + else
> + set_hw_state_no_tz(hdev->core, false);
> if (ret)
> return ret;
>
> @@ -655,7 +659,13 @@ static int venus_power_on(struct venus_hfi_device *hdev)
> if (hdev->power_enabled)
> return 0;
>
> - ret = venus_set_hw_state_resume(hdev->core);
> + if (hdev->core->use_tz) {
> + ret = set_hw_state(true);
> + if (ret == -EINVAL)
> + ret = 0;
> + } else {
> + set_hw_state_no_tz(hdev->core, true);
> + }
> if (ret)
> goto err;
>
> @@ -668,7 +678,10 @@ static int venus_power_on(struct venus_hfi_device *hdev)
> return 0;
>
> err_suspend:
> - venus_set_hw_state_suspend(hdev->core);
> + if (hdev->core->use_tz)
> + set_hw_state(false);
> + else
> + set_hw_state_no_tz(hdev->core, false);
> err:
> hdev->power_enabled = false;
> return ret;
> diff --git a/drivers/media/platform/qcom/venus/hfi_venus.h b/drivers/media/platform/qcom/vcodec/venus/hfi_venus.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_venus.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus.h
> diff --git a/drivers/media/platform/qcom/venus/hfi_venus_io.h b/drivers/media/platform/qcom/vcodec/venus/hfi_venus_io.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/hfi_venus_io.h
> rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus_io.h
> diff --git a/drivers/media/platform/qcom/venus/pm_helpers.c b/drivers/media/platform/qcom/vcodec/venus/pm_helpers.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/pm_helpers.c
> rename to drivers/media/platform/qcom/vcodec/venus/pm_helpers.c
> diff --git a/drivers/media/platform/qcom/venus/pm_helpers.h b/drivers/media/platform/qcom/vcodec/venus/pm_helpers.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/pm_helpers.h
> rename to drivers/media/platform/qcom/vcodec/venus/pm_helpers.h
> diff --git a/drivers/media/platform/qcom/venus/vdec.c b/drivers/media/platform/qcom/vcodec/venus/vdec.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/vdec.c
> rename to drivers/media/platform/qcom/vcodec/venus/vdec.c
> diff --git a/drivers/media/platform/qcom/venus/vdec.h b/drivers/media/platform/qcom/vcodec/venus/vdec.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/vdec.h
> rename to drivers/media/platform/qcom/vcodec/venus/vdec.h
> diff --git a/drivers/media/platform/qcom/venus/vdec_ctrls.c b/drivers/media/platform/qcom/vcodec/venus/vdec_ctrls.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/vdec_ctrls.c
> rename to drivers/media/platform/qcom/vcodec/venus/vdec_ctrls.c
> diff --git a/drivers/media/platform/qcom/venus/venc.c b/drivers/media/platform/qcom/vcodec/venus/venc.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/venc.c
> rename to drivers/media/platform/qcom/vcodec/venus/venc.c
> diff --git a/drivers/media/platform/qcom/venus/venc.h b/drivers/media/platform/qcom/vcodec/venus/venc.h
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/venc.h
> rename to drivers/media/platform/qcom/vcodec/venus/venc.h
> diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c b/drivers/media/platform/qcom/vcodec/venus/venc_ctrls.c
> similarity index 100%
> rename from drivers/media/platform/qcom/venus/venc_ctrls.c
> rename to drivers/media/platform/qcom/vcodec/venus/venc_ctrls.c
> diff --git a/drivers/media/platform/qcom/venus/firmware.c b/drivers/media/platform/qcom/venus/firmware.c
> deleted file mode 100644
> index fe7da2b..0000000
> --- a/drivers/media/platform/qcom/venus/firmware.c
> +++ /dev/null
> @@ -1,363 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0-only
> -/*
> - * Copyright (C) 2017 Linaro Ltd.
> - */
> -
> -#include <linux/device.h>
> -#include <linux/firmware.h>
> -#include <linux/kernel.h>
> -#include <linux/iommu.h>
> -#include <linux/io.h>
> -#include <linux/of.h>
> -#include <linux/of_address.h>
> -#include <linux/of_reserved_mem.h>
> -#include <linux/platform_device.h>
> -#include <linux/of_device.h>
> -#include <linux/firmware/qcom/qcom_scm.h>
> -#include <linux/sizes.h>
> -#include <linux/soc/qcom/mdt_loader.h>
> -
> -#include "core.h"
> -#include "firmware.h"
> -#include "hfi_venus_io.h"
> -
> -#define VENUS_PAS_ID 9
> -#define VENUS_FW_MEM_SIZE (6 * SZ_1M)
> -#define VENUS_FW_START_ADDR 0x0
> -
> -static void venus_reset_cpu(struct venus_core *core)
> -{
> - u32 fw_size = core->fw.mapped_mem_size;
> - void __iomem *wrapper_base;
> -
> - if (IS_IRIS2_1(core))
> - wrapper_base = core->wrapper_tz_base;
> - else
> - wrapper_base = core->wrapper_base;
> -
> - writel(0, wrapper_base + WRAPPER_FW_START_ADDR);
> - writel(fw_size, wrapper_base + WRAPPER_FW_END_ADDR);
> - writel(0, wrapper_base + WRAPPER_CPA_START_ADDR);
> - writel(fw_size, wrapper_base + WRAPPER_CPA_END_ADDR);
> - writel(fw_size, wrapper_base + WRAPPER_NONPIX_START_ADDR);
> - writel(fw_size, wrapper_base + WRAPPER_NONPIX_END_ADDR);
> -
> - if (IS_IRIS2_1(core)) {
> - /* Bring XTSS out of reset */
> - writel(0, wrapper_base + WRAPPER_TZ_XTSS_SW_RESET);
> - } else {
> - writel(0x0, wrapper_base + WRAPPER_CPU_CGC_DIS);
> - writel(0x0, wrapper_base + WRAPPER_CPU_CLOCK_CONFIG);
> -
> - /* Bring ARM9 out of reset */
> - writel(0, wrapper_base + WRAPPER_A9SS_SW_RESET);
> - }
> -}
> -
> -int venus_set_hw_state(struct venus_core *core, bool resume)
> -{
> - int ret;
> -
> - if (core->use_tz) {
> - ret = qcom_scm_set_remote_state(resume, 0);
> - if (resume && ret == -EINVAL)
> - ret = 0;
> - return ret;
> - }
> -
> - if (resume) {
> - venus_reset_cpu(core);
> - } else {
> - if (IS_IRIS2_1(core))
> - writel(WRAPPER_XTSS_SW_RESET_BIT,
> - core->wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
> - else
> - writel(WRAPPER_A9SS_SW_RESET_BIT,
> - core->wrapper_base + WRAPPER_A9SS_SW_RESET);
> - }
> -
> - return 0;
> -}
> -
> -static int venus_load_fw(struct venus_core *core, const char *fwname,
> - phys_addr_t *mem_phys, size_t *mem_size)
> -{
> - const struct firmware *mdt;
> - struct reserved_mem *rmem;
> - struct device_node *node;
> - struct device *dev;
> - ssize_t fw_size;
> - void *mem_va;
> - int ret;
> -
> - *mem_phys = 0;
> - *mem_size = 0;
> -
> - dev = core->dev;
> - node = of_parse_phandle(dev->of_node, "memory-region", 0);
> - if (!node) {
> - dev_err(dev, "no memory-region specified\n");
> - return -EINVAL;
> - }
> -
> - rmem = of_reserved_mem_lookup(node);
> - of_node_put(node);
> - if (!rmem) {
> - dev_err(dev, "failed to lookup reserved memory-region\n");
> - return -EINVAL;
> - }
> -
> - ret = request_firmware(&mdt, fwname, dev);
> - if (ret < 0)
> - return ret;
> -
> - fw_size = qcom_mdt_get_size(mdt);
> - if (fw_size < 0) {
> - ret = fw_size;
> - goto err_release_fw;
> - }
> -
> - *mem_phys = rmem->base;
> - *mem_size = rmem->size;
> -
> - if (*mem_size < fw_size || fw_size > VENUS_FW_MEM_SIZE) {
> - ret = -EINVAL;
> - goto err_release_fw;
> - }
> -
> - mem_va = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
> - if (!mem_va) {
> - dev_err(dev, "unable to map memory region %pa size %#zx\n", mem_phys, *mem_size);
> - ret = -ENOMEM;
> - goto err_release_fw;
> - }
> -
> - if (core->use_tz)
> - ret = qcom_mdt_load(dev, mdt, fwname, VENUS_PAS_ID,
> - mem_va, *mem_phys, *mem_size, NULL);
> - else
> - ret = qcom_mdt_load_no_init(dev, mdt, fwname, VENUS_PAS_ID,
> - mem_va, *mem_phys, *mem_size, NULL);
> -
> - memunmap(mem_va);
> -err_release_fw:
> - release_firmware(mdt);
> - return ret;
> -}
> -
> -static int venus_boot_no_tz(struct venus_core *core, phys_addr_t mem_phys,
> - size_t mem_size)
> -{
> - struct iommu_domain *iommu;
> - struct device *dev;
> - int ret;
> -
> - dev = core->fw.dev;
> - if (!dev)
> - return -EPROBE_DEFER;
> -
> - iommu = core->fw.iommu_domain;
> - core->fw.mapped_mem_size = mem_size;
> -
> - ret = iommu_map(iommu, VENUS_FW_START_ADDR, mem_phys, mem_size,
> - IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV, GFP_KERNEL);
> - if (ret) {
> - dev_err(dev, "could not map video firmware region\n");
> - return ret;
> - }
> -
> - venus_reset_cpu(core);
> -
> - return 0;
> -}
> -
> -static int venus_shutdown_no_tz(struct venus_core *core)
> -{
> - const size_t mapped = core->fw.mapped_mem_size;
> - struct iommu_domain *iommu;
> - size_t unmapped;
> - u32 reg;
> - struct device *dev = core->fw.dev;
> - void __iomem *wrapper_base = core->wrapper_base;
> - void __iomem *wrapper_tz_base = core->wrapper_tz_base;
> -
> - if (IS_IRIS2_1(core)) {
> - /* Assert the reset to XTSS */
> - reg = readl(wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
> - reg |= WRAPPER_XTSS_SW_RESET_BIT;
> - writel(reg, wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
> - } else {
> - /* Assert the reset to ARM9 */
> - reg = readl(wrapper_base + WRAPPER_A9SS_SW_RESET);
> - reg |= WRAPPER_A9SS_SW_RESET_BIT;
> - writel(reg, wrapper_base + WRAPPER_A9SS_SW_RESET);
> - }
> -
> - iommu = core->fw.iommu_domain;
> -
> - if (core->fw.mapped_mem_size && iommu) {
> - unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, mapped);
> -
> - if (unmapped != mapped)
> - dev_err(dev, "failed to unmap firmware\n");
> - else
> - core->fw.mapped_mem_size = 0;
> - }
> -
> - return 0;
> -}
> -
> -int venus_boot(struct venus_core *core)
> -{
> - struct device *dev = core->dev;
> - const struct venus_resources *res = core->res;
> - const char *fwpath = NULL;
> - phys_addr_t mem_phys;
> - size_t mem_size;
> - int ret;
> -
> - if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
> - (core->use_tz && !qcom_scm_is_available()))
> - return -EPROBE_DEFER;
> -
> - ret = of_property_read_string_index(dev->of_node, "firmware-name", 0,
> - &fwpath);
> - if (ret)
> - fwpath = core->res->fwname;
> -
> - ret = venus_load_fw(core, fwpath, &mem_phys, &mem_size);
> - if (ret) {
> - dev_err(dev, "fail to load video firmware\n");
> - return -EINVAL;
> - }
> -
> - core->fw.mem_size = mem_size;
> - core->fw.mem_phys = mem_phys;
> -
> - if (core->use_tz)
> - ret = qcom_scm_pas_auth_and_reset(VENUS_PAS_ID);
> - else
> - ret = venus_boot_no_tz(core, mem_phys, mem_size);
> -
> - if (ret)
> - return ret;
> -
> - if (core->use_tz && res->cp_size) {
> - /*
> - * Clues for porting using downstream data:
> - * cp_start = 0
> - * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
> - * This works, as the non-secure context bank is placed
> - * contiguously right after the Content Protection region.
> - *
> - * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
> - * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
> - */
> - ret = qcom_scm_mem_protect_video_var(res->cp_start,
> - res->cp_size,
> - res->cp_nonpixel_start,
> - res->cp_nonpixel_size);
> - if (ret) {
> - qcom_scm_pas_shutdown(VENUS_PAS_ID);
> - dev_err(dev, "set virtual address ranges fail (%d)\n",
> - ret);
> - return ret;
> - }
> - }
> -
> - return 0;
> -}
> -
> -int venus_shutdown(struct venus_core *core)
> -{
> - int ret;
> -
> - if (core->use_tz)
> - ret = qcom_scm_pas_shutdown(VENUS_PAS_ID);
> - else
> - ret = venus_shutdown_no_tz(core);
> -
> - return ret;
> -}
> -
> -int venus_firmware_init(struct venus_core *core)
> -{
> - struct platform_device_info info;
> - struct iommu_domain *iommu_dom;
> - struct platform_device *pdev;
> - struct device_node *np;
> - int ret;
> -
> - np = of_get_child_by_name(core->dev->of_node, "video-firmware");
> - if (!np) {
> - core->use_tz = true;
> - return 0;
> - }
> -
> - memset(&info, 0, sizeof(info));
> - info.fwnode = &np->fwnode;
> - info.parent = core->dev;
> - info.name = np->name;
> - info.dma_mask = DMA_BIT_MASK(32);
> -
> - pdev = platform_device_register_full(&info);
> - if (IS_ERR(pdev)) {
> - of_node_put(np);
> - return PTR_ERR(pdev);
> - }
> -
> - pdev->dev.of_node = np;
> -
> - ret = of_dma_configure(&pdev->dev, np, true);
> - if (ret) {
> - dev_err(core->dev, "dma configure fail\n");
> - goto err_unregister;
> - }
> -
> - core->fw.dev = &pdev->dev;
> -
> - iommu_dom = iommu_domain_alloc(&platform_bus_type);
> - if (!iommu_dom) {
> - dev_err(core->fw.dev, "Failed to allocate iommu domain\n");
> - ret = -ENOMEM;
> - goto err_unregister;
> - }
> -
> - ret = iommu_attach_device(iommu_dom, core->fw.dev);
> - if (ret) {
> - dev_err(core->fw.dev, "could not attach device\n");
> - goto err_iommu_free;
> - }
> -
> - core->fw.iommu_domain = iommu_dom;
> -
> - of_node_put(np);
> -
> - return 0;
> -
> -err_iommu_free:
> - iommu_domain_free(iommu_dom);
> -err_unregister:
> - platform_device_unregister(pdev);
> - of_node_put(np);
> - return ret;
> -}
> -
> -void venus_firmware_deinit(struct venus_core *core)
> -{
> - struct iommu_domain *iommu;
> -
> - if (!core->fw.dev)
> - return;
> -
> - iommu = core->fw.iommu_domain;
> -
> - iommu_detach_device(iommu, core->fw.dev);
> -
> - if (core->fw.iommu_domain) {
> - iommu_domain_free(iommu);
> - core->fw.iommu_domain = NULL;
> - }
> -
> - platform_device_unregister(to_platform_device(core->fw.dev));
> -}
> diff --git a/drivers/media/platform/qcom/venus/firmware.h b/drivers/media/platform/qcom/venus/firmware.h
> deleted file mode 100644
> index aaccd84..0000000
> --- a/drivers/media/platform/qcom/venus/firmware.h
> +++ /dev/null
> @@ -1,26 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0-only */
> -/*
> - * Copyright (C) 2017 Linaro Ltd.
> - */
> -#ifndef __VENUS_FIRMWARE_H__
> -#define __VENUS_FIRMWARE_H__
> -
> -struct device;
> -
> -int venus_firmware_init(struct venus_core *core);
> -void venus_firmware_deinit(struct venus_core *core);
> -int venus_boot(struct venus_core *core);
> -int venus_shutdown(struct venus_core *core);
> -int venus_set_hw_state(struct venus_core *core, bool suspend);
> -
> -static inline int venus_set_hw_state_suspend(struct venus_core *core)
> -{
> - return venus_set_hw_state(core, false);
> -}
> -
> -static inline int venus_set_hw_state_resume(struct venus_core *core)
> -{
> - return venus_set_hw_state(core, true);
> -}
> -
> -#endif
On 18/12/2023 11:31, Dikshita Agarwal wrote:
> Re-organize the video driver code by introducing a new folder
> 'vcodec' and placing 'venus' driver code inside that.
>
> Introduce common helpers for trustzone based firmware
> load/unload etc. which are placed in common folder
> i.e. 'vcodec'.
> Use these helpers in 'venus' driver. These helpers will be
> used by 'iris' driver as well which is introduced later
> in this patch series.
>
> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
> ---
This is a very large patch, I think it needs to be broken up into
smaller chunks.
#1 Introduce common helper functions
#2 Use common helper functions
Its alot of code to try to eat in the one go.
Could you consider making patches 1-3 a standalone series to reduce the
amount of code to review here ?
* 77e7025529d7c - (HEAD -> linux-stable-master-23-12-18-iris-v2) media:
iris: add power management for encoder (21 hours ago)
* ceb6a6f023fd3 - (tag: v6.7-rc6, linux-stable/master) Linux 6.7-rc6 (2
days ago)
git diff ceb6a6f023fd3 | wc -l
21243
Also I feel it wouild give more time for the changes to "digest" though
upstream users and to find any unintended bugs.
> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
> + size_t *mem_size, u32 pas_id, bool use_tz)
> +{
> + const struct firmware *firmware = NULL;
> + struct reserved_mem *rmem;
> + struct device_node *node;
> + void *mem_virt = NULL;
> + ssize_t fw_size = 0;
> + int ret;
> +
> + if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
> + (use_tz && !qcom_scm_is_available()))
> + return -EPROBE_DEFER;
> +
> + if (!fw_name || !(*fw_name))
> + return -EINVAL;
The parameter check should come before the qcom_scm_is_available()
No matter how many times you -EPROBE_DEFER -EINVAL is still -EINVAL.
> +
> + *mem_phys = 0;
> + *mem_size = 0;
I don't think you need this, you don't appear to use these variables
before you assign them below.
> +
> + *mem_phys = rmem->base;
> + *mem_size = rmem->size;
> +
> +int auth_reset_fw(u32 pas_id)
> +{
> + return qcom_scm_pas_auth_and_reset(pas_id);
> +}
> +
> +void unload_fw(u32 pas_id)
> +{
> + qcom_scm_pas_shutdown(pas_id);
> +}
> +
Do these wrapper functions add anything ? Some kind of validity check on
the pas_id otherwise I'm not sure these are justified.
> +int set_hw_state(bool resume)
> +{
> + return qcom_scm_set_remote_state(resume, 0);
> +}
> diff --git a/drivers/media/platform/qcom/vcodec/firmware.h b/drivers/media/platform/qcom/vcodec/firmware.h
> new file mode 100644
> index 0000000..7d410a8
> --- /dev/null
---
bod
On Tue, 19 Dec 2023 at 13:40, Bryan O'Donoghue
<bryan.odonoghue@linaro.org> wrote:
>
> On 18/12/2023 11:31, Dikshita Agarwal wrote:
> > Re-organize the video driver code by introducing a new folder
> > 'vcodec' and placing 'venus' driver code inside that.
> >
> > Introduce common helpers for trustzone based firmware
> > load/unload etc. which are placed in common folder
> > i.e. 'vcodec'.
> > Use these helpers in 'venus' driver. These helpers will be
> > used by 'iris' driver as well which is introduced later
> > in this patch series.
> >
> > Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
> > ---
>
> This is a very large patch, I think it needs to be broken up into
> smaller chunks.
>
> #1 Introduce common helper functions
> #2 Use common helper functions
This will make it harder to review. It's usually preferred to have a
single 'move' patch instead of two (add + remove). But I definitely
agree that the size of the patch is big. Somewhat it is related to the
fact that this doesn't only introduce helpers, but also reshuffles the
rest of the code.
>
> Its alot of code to try to eat in the one go.
>
> Could you consider making patches 1-3 a standalone series to reduce the
> amount of code to review here ?
This sounds like a good idea.
>
> * 77e7025529d7c - (HEAD -> linux-stable-master-23-12-18-iris-v2) media:
> iris: add power management for encoder (21 hours ago)
>
> * ceb6a6f023fd3 - (tag: v6.7-rc6, linux-stable/master) Linux 6.7-rc6 (2
> days ago)
>
> git diff ceb6a6f023fd3 | wc -l
>
> 21243
>
> Also I feel it wouild give more time for the changes to "digest" though
> upstream users and to find any unintended bugs.
>
> > +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
> > + size_t *mem_size, u32 pas_id, bool use_tz)
> > +{
> > + const struct firmware *firmware = NULL;
> > + struct reserved_mem *rmem;
> > + struct device_node *node;
> > + void *mem_virt = NULL;
> > + ssize_t fw_size = 0;
> > + int ret;
> > +
> > + if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
> > + (use_tz && !qcom_scm_is_available()))
> > + return -EPROBE_DEFER;
> > +
> > + if (!fw_name || !(*fw_name))
> > + return -EINVAL;
>
> The parameter check should come before the qcom_scm_is_available()
>
> No matter how many times you -EPROBE_DEFER -EINVAL is still -EINVAL.
>
> > +
> > + *mem_phys = 0;
> > + *mem_size = 0;
>
> I don't think you need this, you don't appear to use these variables
> before you assign them below.
>
>
> > +
> > + *mem_phys = rmem->base;
> > + *mem_size = rmem->size;
>
> > +
> > +int auth_reset_fw(u32 pas_id)
> > +{
> > + return qcom_scm_pas_auth_and_reset(pas_id);
> > +}
> > +
> > +void unload_fw(u32 pas_id)
> > +{
> > + qcom_scm_pas_shutdown(pas_id);
> > +}
> > +
>
> Do these wrapper functions add anything ? Some kind of validity check on
> the pas_id otherwise I'm not sure these are justified.
>
> > +int set_hw_state(bool resume)
> > +{
> > + return qcom_scm_set_remote_state(resume, 0);
> > +}
> > diff --git a/drivers/media/platform/qcom/vcodec/firmware.h b/drivers/media/platform/qcom/vcodec/firmware.h
> > new file mode 100644
> > index 0000000..7d410a8
> > --- /dev/null
>
> ---
> bod
>
>
On 12/18/2023 11:54 PM, Dmitry Baryshkov wrote:
> On 18/12/2023 13:31, Dikshita Agarwal wrote:
>> Re-organize the video driver code by introducing a new folder
>> 'vcodec' and placing 'venus' driver code inside that.
>>
>> Introduce common helpers for trustzone based firmware
>> load/unload etc. which are placed in common folder
>> i.e. 'vcodec'.
>> Use these helpers in 'venus' driver. These helpers will be
>> used by 'iris' driver as well which is introduced later
>> in this patch series.
>
> But why do you need to move the venus driver to subdir?
Currently venus driver is present in drivers/media/platform/qcom folder
which also has camss folder. We introduced vcodec to keep common code and
moved venus inside that, to indicate that the common code is for vcodec
drivers i.e venus and iris. Keeping this in qcom folder would mean, common
code will be used for camss only which is not the case here.
>
>>
>> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
>> ---
>>  drivers/media/platform/qcom/Kconfig               |  2 +-
>>  drivers/media/platform/qcom/Makefile              |  2 +-
>>  drivers/media/platform/qcom/vcodec/firmware.c     | 147 +++++++++
>>  drivers/media/platform/qcom/vcodec/firmware.h     | 21 ++
>> Â .../media/platform/qcom/{ => vcodec}/venus/Kconfig |Â Â 0
>>  .../platform/qcom/{ => vcodec}/venus/Makefile     |  4 +-
>>  .../media/platform/qcom/{ => vcodec}/venus/core.c | 102 +++++-
>>  .../media/platform/qcom/{ => vcodec}/venus/core.h |  0
>> Â .../media/platform/qcom/{ => vcodec}/venus/dbgfs.c |Â Â 0
>> Â .../media/platform/qcom/{ => vcodec}/venus/dbgfs.h |Â Â 0
>>  .../platform/qcom/vcodec/venus/firmware_no_tz.c   | 194 +++++++++++
>>  .../platform/qcom/vcodec/venus/firmware_no_tz.h   | 19 ++
>>  .../platform/qcom/{ => vcodec}/venus/helpers.c    |  0
>>  .../platform/qcom/{ => vcodec}/venus/helpers.h    |  0
>>  .../media/platform/qcom/{ => vcodec}/venus/hfi.c  |  0
>>  .../media/platform/qcom/{ => vcodec}/venus/hfi.h  |  0
>>  .../platform/qcom/{ => vcodec}/venus/hfi_cmds.c   |  0
>>  .../platform/qcom/{ => vcodec}/venus/hfi_cmds.h   |  0
>>  .../platform/qcom/{ => vcodec}/venus/hfi_helper.h |  0
>>  .../platform/qcom/{ => vcodec}/venus/hfi_msgs.c   |  0
>>  .../platform/qcom/{ => vcodec}/venus/hfi_msgs.h   |  0
>>  .../platform/qcom/{ => vcodec}/venus/hfi_parser.c |  0
>>  .../platform/qcom/{ => vcodec}/venus/hfi_parser.h |  0
>>  .../qcom/{ => vcodec}/venus/hfi_plat_bufs.h       |  0
>>  .../qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c    |  0
>>  .../qcom/{ => vcodec}/venus/hfi_platform.c        |  0
>>  .../qcom/{ => vcodec}/venus/hfi_platform.h        |  0
>>  .../qcom/{ => vcodec}/venus/hfi_platform_v4.c     |  0
>>  .../qcom/{ => vcodec}/venus/hfi_platform_v6.c     |  0
>>  .../platform/qcom/{ => vcodec}/venus/hfi_venus.c  | 21 +-
>>  .../platform/qcom/{ => vcodec}/venus/hfi_venus.h  |  0
>>  .../qcom/{ => vcodec}/venus/hfi_venus_io.h        |  0
>>  .../platform/qcom/{ => vcodec}/venus/pm_helpers.c |  0
>>  .../platform/qcom/{ => vcodec}/venus/pm_helpers.h |  0
>>  .../media/platform/qcom/{ => vcodec}/venus/vdec.c |  0
>>  .../media/platform/qcom/{ => vcodec}/venus/vdec.h |  0
>>  .../platform/qcom/{ => vcodec}/venus/vdec_ctrls.c |  0
>>  .../media/platform/qcom/{ => vcodec}/venus/venc.c |  0
>>  .../media/platform/qcom/{ => vcodec}/venus/venc.h |  0
>>  .../platform/qcom/{ => vcodec}/venus/venc_ctrls.c |  0
>>  drivers/media/platform/qcom/venus/firmware.c      | 363
>> ---------------------
>>  drivers/media/platform/qcom/venus/firmware.h      | 26 --
>> Â 42 files changed, 492 insertions(+), 409 deletions(-)
>> Â create mode 100644 drivers/media/platform/qcom/vcodec/firmware.c
>> Â create mode 100644 drivers/media/platform/qcom/vcodec/firmware.h
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/Kconfig (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/Makefile (83%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/core.c (91%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/core.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.h (100%)
>> Â create mode 100644
>> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
>> Â create mode 100644
>> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_helper.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs.h
>> (100%)
>> Â rename drivers/media/platform/qcom/{ =>
>> vcodec}/venus/hfi_plat_bufs_v6.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.c
>> (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.h
>> (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v4.c
>> (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v6.c
>> (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.c (99%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus_io.h
>> (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec_ctrls.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.c (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.h (100%)
>> Â rename drivers/media/platform/qcom/{ => vcodec}/venus/venc_ctrls.c (100%)
>> Â delete mode 100644 drivers/media/platform/qcom/venus/firmware.c
>> Â delete mode 100644 drivers/media/platform/qcom/venus/firmware.h
>>
>> diff --git a/drivers/media/platform/qcom/Kconfig
>> b/drivers/media/platform/qcom/Kconfig
>> index cc5799b..e94142f 100644
>> --- a/drivers/media/platform/qcom/Kconfig
>> +++ b/drivers/media/platform/qcom/Kconfig
>> @@ -3,4 +3,4 @@
>> Â comment "Qualcomm media platform drivers"
>> Â Â source "drivers/media/platform/qcom/camss/Kconfig"
>> -source "drivers/media/platform/qcom/venus/Kconfig"
>> +source "drivers/media/platform/qcom/vcodec/venus/Kconfig"
>> diff --git a/drivers/media/platform/qcom/Makefile
>> b/drivers/media/platform/qcom/Makefile
>> index 4f055c3..3d2d82b 100644
>> --- a/drivers/media/platform/qcom/Makefile
>> +++ b/drivers/media/platform/qcom/Makefile
>> @@ -1,3 +1,3 @@
>> Â # SPDX-License-Identifier: GPL-2.0-only
>> Â obj-y += camss/
>> -obj-y += venus/
>> +obj-y += vcodec/venus/
>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.c
>> b/drivers/media/platform/qcom/vcodec/firmware.c
>> new file mode 100644
>> index 0000000..dbc220a
>> --- /dev/null
>> +++ b/drivers/media/platform/qcom/vcodec/firmware.c
>> @@ -0,0 +1,147 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
>> reserved.
>> + */
>> +
>> +#include <linux/device.h>
>> +#include <linux/dma-mapping.h>
>> +#include <linux/firmware.h>
>> +#include <linux/kernel.h>
>> +#include <linux/iommu.h>
>> +#include <linux/of_device.h>
>> +#include <linux/firmware/qcom/qcom_scm.h>
>> +#include <linux/of_reserved_mem.h>
>> +#include <linux/platform_device.h>
>> +#include <linux/soc/qcom/mdt_loader.h>
>> +
>> +#include "firmware.h"
>> +
>> +bool use_tz(struct device *core_dev)
>
> All these functions must get some sane prefix. Otherwise a generic 'use_tz'
> function is too polluting for the global namespace.
>
I understand, will check and do the needful.
>> +{
>> +Â Â Â struct device_node *np;
>> +
>> +Â Â Â np = of_get_child_by_name(core_dev->of_node, "video-firmware");
>> +Â Â Â if (!np)
>> +Â Â Â Â Â Â Â return true;
>> +
>> +Â Â Â return false;
>> +}
>> +
>> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â u32 cp_nonpixel_size, u32 pas_id)
>> +{
>> +Â Â Â int ret;
>> +Â Â Â /*
>> +Â Â Â Â * Clues for porting using downstream data:
>> +Â Â Â Â * cp_start = 0
>> +Â Â Â Â * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
>> +Â Â Â Â *Â Â This works, as the non-secure context bank is placed
>> +Â Â Â Â *Â Â contiguously right after the Content Protection region.
>> +Â Â Â Â *
>> +Â Â Â Â * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
>> +Â Â Â Â * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
>> +Â Â Â Â */
>> +Â Â Â ret = qcom_scm_mem_protect_video_var(cp_start,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cp_size,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cp_nonpixel_start,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â cp_nonpixel_size);
>> +Â Â Â if (ret)
>> +Â Â Â Â Â Â Â qcom_scm_pas_shutdown(pas_id);
>> +
>> +Â Â Â return ret;
>> +}
>> +
>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
>> +Â Â Â Â Â Â Â size_t *mem_size, u32 pas_id, bool use_tz)
>> +{
>> +Â Â Â const struct firmware *firmware = NULL;
>> +Â Â Â struct reserved_mem *rmem;
>> +Â Â Â struct device_node *node;
>> +Â Â Â void *mem_virt = NULL;
>> +Â Â Â ssize_t fw_size = 0;
>> +Â Â Â int ret;
>> +
>> +Â Â Â if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
>
> Why? Can you just depend on it?
>
Sure, Will check this and get back.
>> +Â Â Â Â Â Â Â (use_tz && !qcom_scm_is_available()))
>> +Â Â Â Â Â Â Â return -EPROBE_DEFER;
>> +
>> +Â Â Â if (!fw_name || !(*fw_name))
>> +Â Â Â Â Â Â Â return -EINVAL;
>> +
>> +Â Â Â *mem_phys = 0;
>> +Â Â Â *mem_size = 0;
>> +
>> +Â Â Â node = of_parse_phandle(dev->of_node, "memory-region", 0);
>> +Â Â Â if (!node) {
>> +Â Â Â Â Â Â Â dev_err(dev, "no memory-region specified\n");
>> +Â Â Â Â Â Â Â return -EINVAL;
>> +Â Â Â }
>> +
>> +Â Â Â rmem = of_reserved_mem_lookup(node);
>> +Â Â Â of_node_put(node);
>> +Â Â Â if (!rmem) {
>> +Â Â Â Â Â Â Â dev_err(dev, "failed to lookup reserved memory-region\n");
>> +Â Â Â Â Â Â Â return -EINVAL;
>> +Â Â Â }
>> +
>> +Â Â Â ret = request_firmware(&firmware, fw_name, dev);
>> +Â Â Â if (ret) {
>> +Â Â Â Â Â Â Â dev_err(dev, "%s: failed to request fw \"%s\", error %d\n",
>> +Â Â Â Â Â Â Â Â Â Â Â __func__, fw_name, ret);
>> +Â Â Â Â Â Â Â return ret;
>> +Â Â Â }
>> +
>> +Â Â Â fw_size = qcom_mdt_get_size(firmware);
>> +Â Â Â if (fw_size < 0) {
>> +Â Â Â Â Â Â Â ret = fw_size;
>> +Â Â Â Â Â Â Â dev_err(dev, "%s: out of bound fw image fw size: %ld\n",
>> +Â Â Â Â Â Â Â Â Â Â Â __func__, fw_size);
>> +Â Â Â Â Â Â Â goto err_release_fw;
>> +Â Â Â }
>> +
>> +Â Â Â *mem_phys = rmem->base;
>> +Â Â Â *mem_size = rmem->size;
>> +
>> +Â Â Â if (*mem_size < fw_size) {
>> +Â Â Â Â Â Â Â ret = -EINVAL;
>> +Â Â Â Â Â Â Â goto err_release_fw;
>> +Â Â Â }
>> +
>> +Â Â Â mem_virt = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
>> +Â Â Â if (!mem_virt) {
>> +Â Â Â Â Â Â Â dev_err(dev, "unable to remap fw memory region %pa size %#zx\n",
>> +Â Â Â Â Â Â Â Â Â Â Â mem_phys, *mem_size);
>> +Â Â Â Â Â Â Â goto err_release_fw;
>> +Â Â Â }
>> +
>> +Â Â Â if (use_tz)
>> +Â Â Â Â Â Â Â ret = qcom_mdt_load(dev, firmware, fw_name, pas_id, mem_virt,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *mem_phys, *mem_size, NULL);
>> +Â Â Â else
>> +Â Â Â Â Â Â Â ret = qcom_mdt_load_no_init(dev, firmware, fw_name, pas_id,
>> mem_virt,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â *mem_phys, *mem_size, NULL);
>> +Â Â Â if (ret) {
>> +Â Â Â Â Â Â Â dev_err(dev, "%s: error %d loading fw \"%s\"\n",
>> +Â Â Â Â Â Â Â Â Â Â Â __func__, ret, fw_name);
>> +Â Â Â }
>> +
>> +Â Â Â memunmap(mem_virt);
>> +err_release_fw:
>> +Â Â Â release_firmware(firmware);
>> +Â Â Â return ret;
>> +}
>> +
>> +int auth_reset_fw(u32 pas_id)
>> +{
>> +Â Â Â return qcom_scm_pas_auth_and_reset(pas_id);
>> +}
>> +
>> +void unload_fw(u32 pas_id)
>> +{
>> +Â Â Â qcom_scm_pas_shutdown(pas_id);
>> +}
>> +
>> +int set_hw_state(bool resume)
>> +{
>> +Â Â Â return qcom_scm_set_remote_state(resume, 0);
>> +}
>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.h
>> b/drivers/media/platform/qcom/vcodec/firmware.h
>> new file mode 100644
>> index 0000000..7d410a8
>> --- /dev/null
>> +++ b/drivers/media/platform/qcom/vcodec/firmware.h
>> @@ -0,0 +1,21 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +/*
>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
>> reserved.
>> + */
>> +
>> +#ifndef _FIRMWARE_H_
>> +#define _FIRMWARE_H_
>> +
>> +#include <linux/device.h>
>> +#include <linux/types.h>
>> +
>> +bool use_tz(struct device *core_dev);
>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
>> +Â Â Â Â Â Â Â size_t *mem_size, u32 pas_id, bool use_tz);
>> +int auth_reset_fw(u32 pas_id);
>> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â u32 cp_nonpixel_size, u32 pas_id);
>> +void unload_fw(u32 pas_id);
>> +int set_hw_state(bool resume);
>> +
>> +#endif
>> diff --git a/drivers/media/platform/qcom/venus/Kconfig
>> b/drivers/media/platform/qcom/vcodec/venus/Kconfig
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/Kconfig
>> rename to drivers/media/platform/qcom/vcodec/venus/Kconfig
>> diff --git a/drivers/media/platform/qcom/venus/Makefile
>> b/drivers/media/platform/qcom/vcodec/venus/Makefile
>> similarity index 83%
>> rename from drivers/media/platform/qcom/venus/Makefile
>> rename to drivers/media/platform/qcom/vcodec/venus/Makefile
>> index 91ee6be..f6f3a88 100644
>> --- a/drivers/media/platform/qcom/venus/Makefile
>> +++ b/drivers/media/platform/qcom/vcodec/venus/Makefile
>> @@ -1,7 +1,9 @@
>> Â # SPDX-License-Identifier: GPL-2.0
>> Â # Makefile for Qualcomm Venus driver
>> Â -venus-core-objs += core.o helpers.o firmware.o \
>> +venus-core-objs += ../firmware.o
>> +
>> +venus-core-objs += core.o helpers.o firmware_no_tz.o \
>> Â Â Â Â Â Â Â Â Â Â Â Â hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
>> Â Â Â Â Â Â Â Â Â Â Â Â hfi_parser.o pm_helpers.o dbgfs.o \
>> Â Â Â Â Â Â Â Â Â Â Â Â hfi_platform.o hfi_platform_v4.o \
>> diff --git a/drivers/media/platform/qcom/venus/core.c
>> b/drivers/media/platform/qcom/vcodec/venus/core.c
>> similarity index 91%
>> rename from drivers/media/platform/qcom/venus/core.c
>> rename to drivers/media/platform/qcom/vcodec/venus/core.c
>> index 9cffe97..56d9a53 100644
>> --- a/drivers/media/platform/qcom/venus/core.c
>> +++ b/drivers/media/platform/qcom/vcodec/venus/core.c
>> @@ -22,7 +22,8 @@
>> Â #include <media/v4l2-ioctl.h>
>> Â Â #include "core.h"
>> -#include "firmware.h"
>> +#include "../firmware.h"
>> +#include "firmware_no_tz.h"
>> Â #include "pm_helpers.h"
>> Â #include "hfi_venus_io.h"
>> Â @@ -86,6 +87,8 @@ static void venus_sys_error_handler(struct
>> work_struct *work)
>> Â Â Â Â Â struct venus_core *core =
>> Â Â Â Â Â Â Â Â Â Â Â Â Â container_of(work, struct venus_core, work.work);
>> Â Â Â Â Â int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
>> +Â Â Â const struct venus_resources *res = core->res;
>> +Â Â Â const char *fwpath = NULL;
>> Â Â Â Â Â const char *err_msg = "";
>> Â Â Â Â Â bool failed = false;
>> Â @@ -107,7 +110,10 @@ static void venus_sys_error_handler(struct
>> work_struct *work)
>> Â Â Â Â Â Â mutex_lock(&core->lock);
>> Â -Â Â Â venus_shutdown(core);
>> +Â Â Â if (core->use_tz)
>> +Â Â Â Â Â Â Â unload_fw(VENUS_PAS_ID);
>> +Â Â Â else
>> +Â Â Â Â Â Â Â unload_fw_no_tz(core);
>
> This is more than introducing helpers.
>
The new helpers are written to make the code generic for video drivers.
which requires changes in the calling function also.
>> Â Â Â Â Â Â venus_coredump(core);
>> Â @@ -127,12 +133,39 @@ static void venus_sys_error_handler(struct
>> work_struct *work)
>> Â Â Â Â Â Â Â Â Â failed = true;
>> Â Â Â Â Â }
>> Â -Â Â Â ret = venus_boot(core);
>> +Â Â Â ret = of_property_read_string_index(core->dev->of_node,
>> "firmware-name", 0,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &fwpath);
>> +Â Â Â if (ret)
>> +Â Â Â Â Â Â Â fwpath = core->res->fwname;
>> +
>> +Â Â Â ret = load_fw(core->dev, fwpath, &core->fw.mem_phys,
>> &core->fw.mem_size,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â VENUS_PAS_ID, core->use_tz);
>
> So, we had a nice local 'venus_boot'. Instead we now have a pile of code
> with non-generic prefixes, etc. If you are introducing helpers, please
> refrain from inlining of calling functions, etc. Just move the code to your
> helpers.
>
As mentioned in above comment, the common helpers are written to make the
code generic. I Will try to make it more clear, working on the same.
> NAK for the rest of the patch.
>
>> Â Â Â Â Â if (ret && !failed) {
>> -Â Â Â Â Â Â Â err_msg = "boot Venus";
>> +Â Â Â Â Â Â Â err_msg = "load FW";
>> Â Â Â Â Â Â Â Â Â failed = true;
>> Â Â Â Â Â }
>> Â +Â Â Â if (core->use_tz)
>> +Â Â Â Â Â Â Â ret = auth_reset_fw(VENUS_PAS_ID);
>> +Â Â Â else
>> +Â Â Â Â Â Â Â ret = auth_reset_fw_no_tz(core, core->fw.mem_phys,
>> core->fw.mem_size);
>> +Â Â Â if (ret && !failed) {
>> +Â Â Â Â Â Â Â err_msg = "Auth and Reset";
>> +Â Â Â Â Â Â Â failed = true;
>> +Â Â Â }
>> +
>> +Â Â Â if (core->use_tz && res->cp_size) {
>> +Â Â Â Â Â Â Â ret = protect_secure_region(res->cp_start,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_size,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_nonpixel_start,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_nonpixel_size,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â VENUS_PAS_ID);
>> +Â Â Â Â Â Â Â if (ret && !failed) {
>> +Â Â Â Â Â Â Â Â Â Â Â err_msg = "Protect CP Mem";
>> +Â Â Â Â Â Â Â Â Â Â Â failed = true;
>> +Â Â Â Â Â Â Â }
>> +Â Â Â }
>> +
>> Â Â Â Â Â ret = hfi_core_resume(core, true);
>> Â Â Â Â Â if (ret && !failed) {
>> Â Â Â Â Â Â Â Â Â err_msg = "resume HFI";
>> @@ -281,7 +314,9 @@ static irqreturn_t venus_isr_thread(int irq, void
>> *dev_id)
>> Â Â static int venus_probe(struct platform_device *pdev)
>> Â {
>> +Â Â Â const struct venus_resources *res;
>> Â Â Â Â Â struct device *dev = &pdev->dev;
>> +Â Â Â const char *fwpath = NULL;
>> Â Â Â Â Â struct venus_core *core;
>> Â Â Â Â Â int ret;
>> Â @@ -362,14 +397,42 @@ static int venus_probe(struct platform_device *pdev)
>> Â Â Â Â Â if (ret)
>> Â Â Â Â Â Â Â Â Â goto err_runtime_disable;
>> Â -Â Â Â ret = venus_firmware_init(core);
>> +Â Â Â core->use_tz = use_tz(core->dev);
>> +
>> +Â Â Â if (!core->use_tz) {
>> +Â Â Â Â Â Â Â ret = init_fw_no_tz(core);
>> +Â Â Â Â Â Â Â if (ret)
>> +Â Â Â Â Â Â Â Â Â Â Â goto err_of_depopulate;
>> +Â Â Â }
>> +
>> +Â Â Â ret = of_property_read_string_index(dev->of_node, "firmware-name", 0,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &fwpath);
>> Â Â Â Â Â if (ret)
>> -Â Â Â Â Â Â Â goto err_of_depopulate;
>> +Â Â Â Â Â Â Â fwpath = core->res->fwname;
>> Â -Â Â Â ret = venus_boot(core);
>> +Â Â Â ret = load_fw(core->dev, fwpath, &core->fw.mem_phys,
>> &core->fw.mem_size,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â VENUS_PAS_ID, core->use_tz);
>> Â Â Â Â Â if (ret)
>> Â Â Â Â Â Â Â Â Â goto err_firmware_deinit;
>> Â +Â Â Â if (core->use_tz)
>> +Â Â Â Â Â Â Â ret = auth_reset_fw(VENUS_PAS_ID);
>> +Â Â Â else
>> +Â Â Â Â Â Â Â ret = auth_reset_fw_no_tz(core, core->fw.mem_phys,
>> core->fw.mem_size);
>> +Â Â Â if (ret)
>> +Â Â Â Â Â Â Â goto err_firmware_deinit;
>> +
>> +Â Â Â res = core->res;
>> +Â Â Â if (core->use_tz && res->cp_size) {
>> +Â Â Â Â Â Â Â ret = protect_secure_region(res->cp_start,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_size,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_nonpixel_start,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_nonpixel_size,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â VENUS_PAS_ID);
>> +Â Â Â Â Â Â Â if (ret)
>> +Â Â Â Â Â Â Â Â Â Â Â goto err_firmware_deinit;
>> +Â Â Â }
>> +
>> Â Â Â Â Â ret = hfi_core_resume(core, true);
>> Â Â Â Â Â if (ret)
>> Â Â Â Â Â Â Â Â Â goto err_venus_shutdown;
>> @@ -399,9 +462,13 @@ static int venus_probe(struct platform_device *pdev)
>> Â err_dev_unregister:
>> Â Â Â Â Â v4l2_device_unregister(&core->v4l2_dev);
>> Â err_venus_shutdown:
>> -Â Â Â venus_shutdown(core);
>> +Â Â Â if (core->use_tz)
>> +Â Â Â Â Â Â Â unload_fw(VENUS_PAS_ID);
>> +Â Â Â else
>> +Â Â Â Â Â Â Â unload_fw_no_tz(core);
>> Â err_firmware_deinit:
>> -Â Â Â venus_firmware_deinit(core);
>> +Â Â Â if (!core->use_tz)
>> +Â Â Â Â Â Â Â deinit_fw_no_tz(core);
>> Â err_of_depopulate:
>> Â Â Â Â Â of_platform_depopulate(dev);
>> Â err_runtime_disable:
>> @@ -430,10 +497,15 @@ static void venus_remove(struct platform_device *pdev)
>> Â Â Â Â Â ret = hfi_core_deinit(core, true);
>> Â Â Â Â Â WARN_ON(ret);
>> Â -Â Â Â venus_shutdown(core);
>> +Â Â Â if (core->use_tz)
>> +Â Â Â Â Â Â Â unload_fw(VENUS_PAS_ID);
>> +Â Â Â else
>> +Â Â Â Â Â Â Â unload_fw_no_tz(core);
>> +
>> Â Â Â Â Â of_platform_depopulate(dev);
>> Â -Â Â Â venus_firmware_deinit(core);
>> +Â Â Â if (!core->use_tz)
>> +Â Â Â Â Â Â Â deinit_fw_no_tz(core);
>> Â Â Â Â Â Â pm_runtime_put_sync(dev);
>> Â Â Â Â Â pm_runtime_disable(dev);
>> @@ -455,8 +527,12 @@ static void venus_core_shutdown(struct
>> platform_device *pdev)
>> Â Â Â Â Â struct venus_core *core = platform_get_drvdata(pdev);
>> Â Â Â Â Â Â pm_runtime_get_sync(core->dev);
>> -Â Â Â venus_shutdown(core);
>> -Â Â Â venus_firmware_deinit(core);
>> +Â Â Â if (core->use_tz) {
>> +Â Â Â Â Â Â Â unload_fw(VENUS_PAS_ID);
>> +Â Â Â } else {
>> +Â Â Â Â Â Â Â unload_fw_no_tz(core);
>> +Â Â Â Â Â Â Â deinit_fw_no_tz(core);
>> +Â Â Â }
>> Â Â Â Â Â pm_runtime_put_sync(core->dev);
>> Â }
>> Â diff --git a/drivers/media/platform/qcom/venus/core.h
>> b/drivers/media/platform/qcom/vcodec/venus/core.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/core.h
>> rename to drivers/media/platform/qcom/vcodec/venus/core.h
>> diff --git a/drivers/media/platform/qcom/venus/dbgfs.c
>> b/drivers/media/platform/qcom/vcodec/venus/dbgfs.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/dbgfs.c
>> rename to drivers/media/platform/qcom/vcodec/venus/dbgfs.c
>> diff --git a/drivers/media/platform/qcom/venus/dbgfs.h
>> b/drivers/media/platform/qcom/vcodec/venus/dbgfs.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/dbgfs.h
>> rename to drivers/media/platform/qcom/vcodec/venus/dbgfs.h
>> diff --git a/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
>> b/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
>> new file mode 100644
>> index 0000000..9dca6e23
>> --- /dev/null
>> +++ b/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
>> @@ -0,0 +1,194 @@
>> +// SPDX-License-Identifier: GPL-2.0-only
>> +/*
>> + * Copyright (C) 2017 Linaro Ltd.
>> + */
>> +
>> +#include <linux/iommu.h>
>> +#include <linux/of_device.h>
>> +#include "core.h"
>> +#include "firmware_no_tz.h"
>> +#include "hfi_venus_io.h"
>> +
>> +#define VENUS_FW_MEM_SIZEÂ Â Â Â Â Â Â (6 * SZ_1M)
>> +#define VENUS_FW_START_ADDRÂ Â Â Â Â Â Â 0x0
>> +
>> +int init_fw_no_tz(struct venus_core *core)
>> +{
>> +Â Â Â struct platform_device_info info;
>> +Â Â Â struct iommu_domain *iommu_dom;
>> +Â Â Â struct platform_device *pdev;
>> +Â Â Â struct device_node *np;
>> +Â Â Â int ret;
>> +
>> +Â Â Â np = of_get_child_by_name(core->dev->of_node, "video-firmware");
>> +
>> +Â Â Â memset(&info, 0, sizeof(info));
>> +Â Â Â info.fwnode = &np->fwnode;
>> +Â Â Â info.parent = core->dev;
>> +Â Â Â info.name = np->name;
>> +Â Â Â info.dma_mask = DMA_BIT_MASK(32);
>> +
>> +Â Â Â pdev = platform_device_register_full(&info);
>> +Â Â Â if (IS_ERR(pdev)) {
>> +Â Â Â Â Â Â Â of_node_put(np);
>> +Â Â Â Â Â Â Â return PTR_ERR(pdev);
>> +Â Â Â }
>> +
>> +Â Â Â pdev->dev.of_node = np;
>> +
>> +Â Â Â ret = of_dma_configure(&pdev->dev, np, true);
>> +Â Â Â if (ret) {
>> +Â Â Â Â Â Â Â dev_err(core->dev, "dma configure fail\n");
>> +Â Â Â Â Â Â Â goto err_unregister;
>> +Â Â Â }
>> +
>> +Â Â Â core->fw.dev = &pdev->dev;
>> +
>> +Â Â Â iommu_dom = iommu_domain_alloc(&platform_bus_type);
>> +Â Â Â if (!iommu_dom) {
>> +Â Â Â Â Â Â Â dev_err(core->fw.dev, "Failed to allocate iommu domain\n");
>> +Â Â Â Â Â Â Â ret = -ENOMEM;
>> +Â Â Â Â Â Â Â goto err_unregister;
>> +Â Â Â }
>> +
>> +Â Â Â ret = iommu_attach_device(iommu_dom, core->fw.dev);
>> +Â Â Â if (ret) {
>> +Â Â Â Â Â Â Â dev_err(core->fw.dev, "could not attach device\n");
>> +Â Â Â Â Â Â Â goto err_iommu_free;
>> +Â Â Â }
>> +
>> +Â Â Â core->fw.iommu_domain = iommu_dom;
>> +
>> +Â Â Â of_node_put(np);
>> +
>> +Â Â Â return 0;
>> +
>> +err_iommu_free:
>> +Â Â Â iommu_domain_free(iommu_dom);
>> +err_unregister:
>> +Â Â Â platform_device_unregister(pdev);
>> +Â Â Â of_node_put(np);
>> +Â Â Â return ret;
>> +}
>> +
>> +void deinit_fw_no_tz(struct venus_core *core)
>> +{
>> +Â Â Â struct iommu_domain *iommu;
>> +
>> +Â Â Â if (!core->fw.dev)
>> +Â Â Â Â Â Â Â return;
>> +
>> +Â Â Â iommu = core->fw.iommu_domain;
>> +
>> +Â Â Â iommu_detach_device(iommu, core->fw.dev);
>> +
>> +Â Â Â if (iommu) {
>> +Â Â Â Â Â Â Â iommu_domain_free(iommu);
>> +Â Â Â Â Â Â Â iommu = NULL;
>> +Â Â Â }
>> +
>> +Â Â Â platform_device_unregister(to_platform_device(core->fw.dev));
>> +}
>> +
>> +static void reset_cpu_no_tz(struct venus_core *core)
>> +{
>> +Â Â Â u32 fw_size = core->fw.mapped_mem_size;
>> +Â Â Â void __iomem *wrapper_base;
>> +
>> +Â Â Â if (IS_IRIS2_1(core))
>> +Â Â Â Â Â Â Â wrapper_base = core->wrapper_tz_base;
>> +Â Â Â else
>> +Â Â Â Â Â Â Â wrapper_base = core->wrapper_base;
>> +
>> +Â Â Â writel(0, wrapper_base + WRAPPER_FW_START_ADDR);
>> +Â Â Â writel(fw_size, wrapper_base + WRAPPER_FW_END_ADDR);
>> +Â Â Â writel(0, wrapper_base + WRAPPER_CPA_START_ADDR);
>> +Â Â Â writel(fw_size, wrapper_base + WRAPPER_CPA_END_ADDR);
>> +Â Â Â writel(fw_size, wrapper_base + WRAPPER_NONPIX_START_ADDR);
>> +Â Â Â writel(fw_size, wrapper_base + WRAPPER_NONPIX_END_ADDR);
>> +
>> +Â Â Â if (IS_IRIS2_1(core)) {
>> +Â Â Â Â Â Â Â /* Bring XTSS out of reset */
>> +Â Â Â Â Â Â Â writel(0, wrapper_base + WRAPPER_TZ_XTSS_SW_RESET);
>> +Â Â Â } else {
>> +Â Â Â Â Â Â Â writel(0x0, wrapper_base + WRAPPER_CPU_CGC_DIS);
>> +Â Â Â Â Â Â Â writel(0x0, wrapper_base + WRAPPER_CPU_CLOCK_CONFIG);
>> +
>> +Â Â Â Â Â Â Â /* Bring ARM9 out of reset */
>> +Â Â Â Â Â Â Â writel(0, wrapper_base + WRAPPER_A9SS_SW_RESET);
>> +Â Â Â }
>> +}
>> +
>> +void set_hw_state_no_tz(struct venus_core *core, bool resume)
>> +{
>> +Â Â Â if (resume) {
>> +Â Â Â Â Â Â Â reset_cpu_no_tz(core);
>> +Â Â Â } else {
>> +Â Â Â Â Â Â Â if (IS_IRIS2_1(core))
>> +Â Â Â Â Â Â Â Â Â Â Â writel(WRAPPER_XTSS_SW_RESET_BIT,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â core->wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
>> +Â Â Â Â Â Â Â else
>> +Â Â Â Â Â Â Â Â Â Â Â writel(WRAPPER_A9SS_SW_RESET_BIT,
>> +Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â core->wrapper_base + WRAPPER_A9SS_SW_RESET);
>> +Â Â Â }
>> +}
>> +
>> +int auth_reset_fw_no_tz(struct venus_core *core, phys_addr_t mem_phys,
>> +Â Â Â Â Â Â Â Â Â Â Â size_t mem_size)
>> +{
>> +Â Â Â struct iommu_domain *iommu;
>> +Â Â Â struct device *dev;
>> +Â Â Â int ret;
>> +
>> +Â Â Â dev = core->fw.dev;
>> +Â Â Â if (!dev)
>> +Â Â Â Â Â Â Â return -EPROBE_DEFER;
>> +
>> +Â Â Â iommu = core->fw.iommu_domain;
>> +Â Â Â core->fw.mapped_mem_size = mem_size;
>> +
>> +Â Â Â ret = iommu_map(iommu, VENUS_FW_START_ADDR, mem_phys, mem_size,
>> +Â Â Â Â Â Â Â Â Â Â Â IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV, GFP_KERNEL);
>> +Â Â Â if (ret) {
>> +Â Â Â Â Â Â Â dev_err(dev, "could not map video firmware region\n");
>> +Â Â Â Â Â Â Â return ret;
>> +Â Â Â }
>> +
>> +Â Â Â reset_cpu_no_tz(core);
>> +
>> +Â Â Â return 0;
>> +}
>> +
>> +void unload_fw_no_tz(struct venus_core *core)
>> +{
>> +Â Â Â const size_t mapped = core->fw.mapped_mem_size;
>> +Â Â Â struct iommu_domain *iommu;
>> +Â Â Â size_t unmapped;
>> +Â Â Â u32 reg;
>> +Â Â Â struct device *dev = core->fw.dev;
>> +Â Â Â void __iomem *wrapper_base = core->wrapper_base;
>> +Â Â Â void __iomem *wrapper_tz_base = core->wrapper_tz_base;
>> +
>> +Â Â Â if (IS_IRIS2_1(core)) {
>> +Â Â Â Â Â Â Â /* Assert the reset to XTSS */
>> +Â Â Â Â Â Â Â reg = readl(wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
>> +Â Â Â Â Â Â Â reg |= WRAPPER_XTSS_SW_RESET_BIT;
>> +Â Â Â Â Â Â Â writel(reg, wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
>> +Â Â Â } else {
>> +Â Â Â Â Â Â Â /* Assert the reset to ARM9 */
>> +Â Â Â Â Â Â Â reg = readl(wrapper_base + WRAPPER_A9SS_SW_RESET);
>> +Â Â Â Â Â Â Â reg |= WRAPPER_A9SS_SW_RESET_BIT;
>> +Â Â Â Â Â Â Â writel(reg, wrapper_base + WRAPPER_A9SS_SW_RESET);
>> +Â Â Â }
>> +
>> +Â Â Â iommu = core->fw.iommu_domain;
>> +
>> +Â Â Â if (core->fw.mapped_mem_size && iommu) {
>> +Â Â Â Â Â Â Â unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, mapped);
>> +
>> +Â Â Â Â Â Â Â if (unmapped != mapped)
>> +Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "failed to unmap firmware\n");
>> +Â Â Â Â Â Â Â else
>> +Â Â Â Â Â Â Â Â Â Â Â core->fw.mapped_mem_size = 0;
>> +Â Â Â }
>> +}
>> diff --git a/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
>> b/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
>> new file mode 100644
>> index 0000000..5f008ef
>> --- /dev/null
>> +++ b/drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
>> @@ -0,0 +1,19 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +/*
>> + * Copyright (C) 2017 Linaro Ltd.
>> + */
>> +#ifndef __FIRMWARE_NO_TZ_H__
>> +#define __FIRMWARE_NO_TZ_H__
>> +
>> +struct device;
>> +
>> +#define VENUS_PAS_IDÂ Â Â 9
>> +
>> +int init_fw_no_tz(struct venus_core *core);
>> +void deinit_fw_no_tz(struct venus_core *core);
>> +int auth_reset_fw_no_tz(struct venus_core *core, phys_addr_t mem_phys,
>> +Â Â Â Â Â Â Â Â Â Â Â size_t mem_size);
>> +void unload_fw_no_tz(struct venus_core *core);
>> +void set_hw_state_no_tz(struct venus_core *core, bool resume);
>> +
>> +#endif
>> diff --git a/drivers/media/platform/qcom/venus/helpers.c
>> b/drivers/media/platform/qcom/vcodec/venus/helpers.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/helpers.c
>> rename to drivers/media/platform/qcom/vcodec/venus/helpers.c
>> diff --git a/drivers/media/platform/qcom/venus/helpers.h
>> b/drivers/media/platform/qcom/vcodec/venus/helpers.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/helpers.h
>> rename to drivers/media/platform/qcom/vcodec/venus/helpers.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi.c
>> diff --git a/drivers/media/platform/qcom/venus/hfi.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_cmds.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_cmds.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_cmds.c
>> diff --git a/drivers/media/platform/qcom/venus/hfi_cmds.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_cmds.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_cmds.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_cmds.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi_helper.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_helper.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_helper.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_helper.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi_msgs.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_msgs.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_msgs.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_msgs.c
>> diff --git a/drivers/media/platform/qcom/venus/hfi_msgs.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_msgs.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_msgs.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_msgs.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi_parser.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_parser.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_parser.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_parser.c
>> diff --git a/drivers/media/platform/qcom/venus/hfi_parser.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_parser.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_parser.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_parser.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi_plat_bufs.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_plat_bufs.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi_plat_bufs_v6.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs_v6.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_plat_bufs_v6.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs_v6.c
>> diff --git a/drivers/media/platform/qcom/venus/hfi_platform.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_platform.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_platform.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform.c
>> diff --git a/drivers/media/platform/qcom/venus/hfi_platform.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_platform.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_platform.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi_platform_v4.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_platform_v4.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_platform_v4.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform_v4.c
>> diff --git a/drivers/media/platform/qcom/venus/hfi_platform_v6.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_platform_v6.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_platform_v6.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform_v6.c
>> diff --git a/drivers/media/platform/qcom/venus/hfi_venus.c
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_venus.c
>> similarity index 99%
>> rename from drivers/media/platform/qcom/venus/hfi_venus.c
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus.c
>> index f9437b6..5a68db9 100644
>> --- a/drivers/media/platform/qcom/venus/hfi_venus.c
>> +++ b/drivers/media/platform/qcom/vcodec/venus/hfi_venus.c
>> @@ -13,11 +13,12 @@
>> Â #include <linux/slab.h>
>> Â Â #include "core.h"
>> +#include "../firmware.h"
>> Â #include "hfi_cmds.h"
>> Â #include "hfi_msgs.h"
>> Â #include "hfi_venus.h"
>> Â #include "hfi_venus_io.h"
>> -#include "firmware.h"
>> +#include "firmware_no_tz.h"
>> Â Â #define HFI_MASK_QHDR_TX_TYPEÂ Â Â Â Â Â Â 0xff000000
>> Â #define HFI_MASK_QHDR_RX_TYPEÂ Â Â Â Â Â Â 0x00ff0000
>> @@ -635,7 +636,10 @@ static int venus_power_off(struct venus_hfi_device
>> *hdev)
>> Â Â Â Â Â if (!hdev->power_enabled)
>> Â Â Â Â Â Â Â Â Â return 0;
>> Â -Â Â Â ret = venus_set_hw_state_suspend(hdev->core);
>> +Â Â Â if (hdev->core->use_tz)
>> +Â Â Â Â Â Â Â ret = set_hw_state(false);
>> +Â Â Â else
>> +Â Â Â Â Â Â Â set_hw_state_no_tz(hdev->core, false);
>> Â Â Â Â Â if (ret)
>> Â Â Â Â Â Â Â Â Â return ret;
>> Â @@ -655,7 +659,13 @@ static int venus_power_on(struct venus_hfi_device
>> *hdev)
>> Â Â Â Â Â if (hdev->power_enabled)
>> Â Â Â Â Â Â Â Â Â return 0;
>> Â -Â Â Â ret = venus_set_hw_state_resume(hdev->core);
>> +Â Â Â if (hdev->core->use_tz) {
>> +Â Â Â Â Â Â Â ret = set_hw_state(true);
>> +Â Â Â Â Â Â Â if (ret == -EINVAL)
>> +Â Â Â Â Â Â Â Â Â Â Â ret = 0;
>> +Â Â Â } else {
>> +Â Â Â Â Â Â Â set_hw_state_no_tz(hdev->core, true);
>> +Â Â Â }
>> Â Â Â Â Â if (ret)
>> Â Â Â Â Â Â Â Â Â goto err;
>> Â @@ -668,7 +678,10 @@ static int venus_power_on(struct venus_hfi_device
>> *hdev)
>> Â Â Â Â Â return 0;
>> Â Â err_suspend:
>> -Â Â Â venus_set_hw_state_suspend(hdev->core);
>> +Â Â Â if (hdev->core->use_tz)
>> +Â Â Â Â Â Â Â set_hw_state(false);
>> +Â Â Â else
>> +Â Â Â Â Â Â Â set_hw_state_no_tz(hdev->core, false);
>> Â err:
>> Â Â Â Â Â hdev->power_enabled = false;
>> Â Â Â Â Â return ret;
>> diff --git a/drivers/media/platform/qcom/venus/hfi_venus.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_venus.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_venus.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus.h
>> diff --git a/drivers/media/platform/qcom/venus/hfi_venus_io.h
>> b/drivers/media/platform/qcom/vcodec/venus/hfi_venus_io.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/hfi_venus_io.h
>> rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus_io.h
>> diff --git a/drivers/media/platform/qcom/venus/pm_helpers.c
>> b/drivers/media/platform/qcom/vcodec/venus/pm_helpers.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/pm_helpers.c
>> rename to drivers/media/platform/qcom/vcodec/venus/pm_helpers.c
>> diff --git a/drivers/media/platform/qcom/venus/pm_helpers.h
>> b/drivers/media/platform/qcom/vcodec/venus/pm_helpers.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/pm_helpers.h
>> rename to drivers/media/platform/qcom/vcodec/venus/pm_helpers.h
>> diff --git a/drivers/media/platform/qcom/venus/vdec.c
>> b/drivers/media/platform/qcom/vcodec/venus/vdec.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/vdec.c
>> rename to drivers/media/platform/qcom/vcodec/venus/vdec.c
>> diff --git a/drivers/media/platform/qcom/venus/vdec.h
>> b/drivers/media/platform/qcom/vcodec/venus/vdec.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/vdec.h
>> rename to drivers/media/platform/qcom/vcodec/venus/vdec.h
>> diff --git a/drivers/media/platform/qcom/venus/vdec_ctrls.c
>> b/drivers/media/platform/qcom/vcodec/venus/vdec_ctrls.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/vdec_ctrls.c
>> rename to drivers/media/platform/qcom/vcodec/venus/vdec_ctrls.c
>> diff --git a/drivers/media/platform/qcom/venus/venc.c
>> b/drivers/media/platform/qcom/vcodec/venus/venc.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/venc.c
>> rename to drivers/media/platform/qcom/vcodec/venus/venc.c
>> diff --git a/drivers/media/platform/qcom/venus/venc.h
>> b/drivers/media/platform/qcom/vcodec/venus/venc.h
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/venc.h
>> rename to drivers/media/platform/qcom/vcodec/venus/venc.h
>> diff --git a/drivers/media/platform/qcom/venus/venc_ctrls.c
>> b/drivers/media/platform/qcom/vcodec/venus/venc_ctrls.c
>> similarity index 100%
>> rename from drivers/media/platform/qcom/venus/venc_ctrls.c
>> rename to drivers/media/platform/qcom/vcodec/venus/venc_ctrls.c
>> diff --git a/drivers/media/platform/qcom/venus/firmware.c
>> b/drivers/media/platform/qcom/venus/firmware.c
>> deleted file mode 100644
>> index fe7da2b..0000000
>> --- a/drivers/media/platform/qcom/venus/firmware.c
>> +++ /dev/null
>> @@ -1,363 +0,0 @@
>> -// SPDX-License-Identifier: GPL-2.0-only
>> -/*
>> - * Copyright (C) 2017 Linaro Ltd.
>> - */
>> -
>> -#include <linux/device.h>
>> -#include <linux/firmware.h>
>> -#include <linux/kernel.h>
>> -#include <linux/iommu.h>
>> -#include <linux/io.h>
>> -#include <linux/of.h>
>> -#include <linux/of_address.h>
>> -#include <linux/of_reserved_mem.h>
>> -#include <linux/platform_device.h>
>> -#include <linux/of_device.h>
>> -#include <linux/firmware/qcom/qcom_scm.h>
>> -#include <linux/sizes.h>
>> -#include <linux/soc/qcom/mdt_loader.h>
>> -
>> -#include "core.h"
>> -#include "firmware.h"
>> -#include "hfi_venus_io.h"
>> -
>> -#define VENUS_PAS_IDÂ Â Â Â Â Â Â Â Â Â Â 9
>> -#define VENUS_FW_MEM_SIZEÂ Â Â Â Â Â Â (6 * SZ_1M)
>> -#define VENUS_FW_START_ADDRÂ Â Â Â Â Â Â 0x0
>> -
>> -static void venus_reset_cpu(struct venus_core *core)
>> -{
>> -Â Â Â u32 fw_size = core->fw.mapped_mem_size;
>> -Â Â Â void __iomem *wrapper_base;
>> -
>> -Â Â Â if (IS_IRIS2_1(core))
>> -Â Â Â Â Â Â Â wrapper_base = core->wrapper_tz_base;
>> -Â Â Â else
>> -Â Â Â Â Â Â Â wrapper_base = core->wrapper_base;
>> -
>> -Â Â Â writel(0, wrapper_base + WRAPPER_FW_START_ADDR);
>> -Â Â Â writel(fw_size, wrapper_base + WRAPPER_FW_END_ADDR);
>> -Â Â Â writel(0, wrapper_base + WRAPPER_CPA_START_ADDR);
>> -Â Â Â writel(fw_size, wrapper_base + WRAPPER_CPA_END_ADDR);
>> -Â Â Â writel(fw_size, wrapper_base + WRAPPER_NONPIX_START_ADDR);
>> -Â Â Â writel(fw_size, wrapper_base + WRAPPER_NONPIX_END_ADDR);
>> -
>> -Â Â Â if (IS_IRIS2_1(core)) {
>> -Â Â Â Â Â Â Â /* Bring XTSS out of reset */
>> -Â Â Â Â Â Â Â writel(0, wrapper_base + WRAPPER_TZ_XTSS_SW_RESET);
>> -Â Â Â } else {
>> -Â Â Â Â Â Â Â writel(0x0, wrapper_base + WRAPPER_CPU_CGC_DIS);
>> -Â Â Â Â Â Â Â writel(0x0, wrapper_base + WRAPPER_CPU_CLOCK_CONFIG);
>> -
>> -Â Â Â Â Â Â Â /* Bring ARM9 out of reset */
>> -Â Â Â Â Â Â Â writel(0, wrapper_base + WRAPPER_A9SS_SW_RESET);
>> -Â Â Â }
>> -}
>> -
>> -int venus_set_hw_state(struct venus_core *core, bool resume)
>> -{
>> -Â Â Â int ret;
>> -
>> -Â Â Â if (core->use_tz) {
>> -Â Â Â Â Â Â Â ret = qcom_scm_set_remote_state(resume, 0);
>> -Â Â Â Â Â Â Â if (resume && ret == -EINVAL)
>> -Â Â Â Â Â Â Â Â Â Â Â ret = 0;
>> -Â Â Â Â Â Â Â return ret;
>> -Â Â Â }
>> -
>> -Â Â Â if (resume) {
>> -Â Â Â Â Â Â Â venus_reset_cpu(core);
>> -Â Â Â } else {
>> -Â Â Â Â Â Â Â if (IS_IRIS2_1(core))
>> -Â Â Â Â Â Â Â Â Â Â Â writel(WRAPPER_XTSS_SW_RESET_BIT,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â core->wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
>> -Â Â Â Â Â Â Â else
>> -Â Â Â Â Â Â Â Â Â Â Â writel(WRAPPER_A9SS_SW_RESET_BIT,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â core->wrapper_base + WRAPPER_A9SS_SW_RESET);
>> -Â Â Â }
>> -
>> -Â Â Â return 0;
>> -}
>> -
>> -static int venus_load_fw(struct venus_core *core, const char *fwname,
>> -Â Â Â Â Â Â Â Â Â Â Â Â phys_addr_t *mem_phys, size_t *mem_size)
>> -{
>> -Â Â Â const struct firmware *mdt;
>> -Â Â Â struct reserved_mem *rmem;
>> -Â Â Â struct device_node *node;
>> -Â Â Â struct device *dev;
>> -Â Â Â ssize_t fw_size;
>> -Â Â Â void *mem_va;
>> -Â Â Â int ret;
>> -
>> -Â Â Â *mem_phys = 0;
>> -Â Â Â *mem_size = 0;
>> -
>> -Â Â Â dev = core->dev;
>> -Â Â Â node = of_parse_phandle(dev->of_node, "memory-region", 0);
>> -Â Â Â if (!node) {
>> -Â Â Â Â Â Â Â dev_err(dev, "no memory-region specified\n");
>> -Â Â Â Â Â Â Â return -EINVAL;
>> -Â Â Â }
>> -
>> -Â Â Â rmem = of_reserved_mem_lookup(node);
>> -Â Â Â of_node_put(node);
>> -Â Â Â if (!rmem) {
>> -Â Â Â Â Â Â Â dev_err(dev, "failed to lookup reserved memory-region\n");
>> -Â Â Â Â Â Â Â return -EINVAL;
>> -Â Â Â }
>> -
>> -Â Â Â ret = request_firmware(&mdt, fwname, dev);
>> -Â Â Â if (ret < 0)
>> -Â Â Â Â Â Â Â return ret;
>> -
>> -Â Â Â fw_size = qcom_mdt_get_size(mdt);
>> -Â Â Â if (fw_size < 0) {
>> -Â Â Â Â Â Â Â ret = fw_size;
>> -Â Â Â Â Â Â Â goto err_release_fw;
>> -Â Â Â }
>> -
>> -Â Â Â *mem_phys = rmem->base;
>> -Â Â Â *mem_size = rmem->size;
>> -
>> -Â Â Â if (*mem_size < fw_size || fw_size > VENUS_FW_MEM_SIZE) {
>> -Â Â Â Â Â Â Â ret = -EINVAL;
>> -Â Â Â Â Â Â Â goto err_release_fw;
>> -Â Â Â }
>> -
>> -Â Â Â mem_va = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
>> -Â Â Â if (!mem_va) {
>> -Â Â Â Â Â Â Â dev_err(dev, "unable to map memory region %pa size %#zx\n",
>> mem_phys, *mem_size);
>> -Â Â Â Â Â Â Â ret = -ENOMEM;
>> -Â Â Â Â Â Â Â goto err_release_fw;
>> -Â Â Â }
>> -
>> -Â Â Â if (core->use_tz)
>> -Â Â Â Â Â Â Â ret = qcom_mdt_load(dev, mdt, fwname, VENUS_PAS_ID,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â mem_va, *mem_phys, *mem_size, NULL);
>> -Â Â Â else
>> -Â Â Â Â Â Â Â ret = qcom_mdt_load_no_init(dev, mdt, fwname, VENUS_PAS_ID,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â mem_va, *mem_phys, *mem_size, NULL);
>> -
>> -Â Â Â memunmap(mem_va);
>> -err_release_fw:
>> -Â Â Â release_firmware(mdt);
>> -Â Â Â return ret;
>> -}
>> -
>> -static int venus_boot_no_tz(struct venus_core *core, phys_addr_t mem_phys,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â size_t mem_size)
>> -{
>> -Â Â Â struct iommu_domain *iommu;
>> -Â Â Â struct device *dev;
>> -Â Â Â int ret;
>> -
>> -Â Â Â dev = core->fw.dev;
>> -Â Â Â if (!dev)
>> -Â Â Â Â Â Â Â return -EPROBE_DEFER;
>> -
>> -Â Â Â iommu = core->fw.iommu_domain;
>> -Â Â Â core->fw.mapped_mem_size = mem_size;
>> -
>> -Â Â Â ret = iommu_map(iommu, VENUS_FW_START_ADDR, mem_phys, mem_size,
>> -Â Â Â Â Â Â Â Â Â Â Â IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV, GFP_KERNEL);
>> -Â Â Â if (ret) {
>> -Â Â Â Â Â Â Â dev_err(dev, "could not map video firmware region\n");
>> -Â Â Â Â Â Â Â return ret;
>> -Â Â Â }
>> -
>> -Â Â Â venus_reset_cpu(core);
>> -
>> -Â Â Â return 0;
>> -}
>> -
>> -static int venus_shutdown_no_tz(struct venus_core *core)
>> -{
>> -Â Â Â const size_t mapped = core->fw.mapped_mem_size;
>> -Â Â Â struct iommu_domain *iommu;
>> -Â Â Â size_t unmapped;
>> -Â Â Â u32 reg;
>> -Â Â Â struct device *dev = core->fw.dev;
>> -Â Â Â void __iomem *wrapper_base = core->wrapper_base;
>> -Â Â Â void __iomem *wrapper_tz_base = core->wrapper_tz_base;
>> -
>> -Â Â Â if (IS_IRIS2_1(core)) {
>> -Â Â Â Â Â Â Â /* Assert the reset to XTSS */
>> -Â Â Â Â Â Â Â reg = readl(wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
>> -Â Â Â Â Â Â Â reg |= WRAPPER_XTSS_SW_RESET_BIT;
>> -Â Â Â Â Â Â Â writel(reg, wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
>> -Â Â Â } else {
>> -Â Â Â Â Â Â Â /* Assert the reset to ARM9 */
>> -Â Â Â Â Â Â Â reg = readl(wrapper_base + WRAPPER_A9SS_SW_RESET);
>> -Â Â Â Â Â Â Â reg |= WRAPPER_A9SS_SW_RESET_BIT;
>> -Â Â Â Â Â Â Â writel(reg, wrapper_base + WRAPPER_A9SS_SW_RESET);
>> -Â Â Â }
>> -
>> -Â Â Â iommu = core->fw.iommu_domain;
>> -
>> -Â Â Â if (core->fw.mapped_mem_size && iommu) {
>> -Â Â Â Â Â Â Â unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, mapped);
>> -
>> -Â Â Â Â Â Â Â if (unmapped != mapped)
>> -Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "failed to unmap firmware\n");
>> -Â Â Â Â Â Â Â else
>> -Â Â Â Â Â Â Â Â Â Â Â core->fw.mapped_mem_size = 0;
>> -Â Â Â }
>> -
>> -Â Â Â return 0;
>> -}
>> -
>> -int venus_boot(struct venus_core *core)
>> -{
>> -Â Â Â struct device *dev = core->dev;
>> -Â Â Â const struct venus_resources *res = core->res;
>> -Â Â Â const char *fwpath = NULL;
>> -Â Â Â phys_addr_t mem_phys;
>> -Â Â Â size_t mem_size;
>> -Â Â Â int ret;
>> -
>> -Â Â Â if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
>> -Â Â Â Â Â Â Â (core->use_tz && !qcom_scm_is_available()))
>> -Â Â Â Â Â Â Â return -EPROBE_DEFER;
>> -
>> -Â Â Â ret = of_property_read_string_index(dev->of_node, "firmware-name", 0,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â &fwpath);
>> -Â Â Â if (ret)
>> -Â Â Â Â Â Â Â fwpath = core->res->fwname;
>> -
>> -Â Â Â ret = venus_load_fw(core, fwpath, &mem_phys, &mem_size);
>> -Â Â Â if (ret) {
>> -Â Â Â Â Â Â Â dev_err(dev, "fail to load video firmware\n");
>> -Â Â Â Â Â Â Â return -EINVAL;
>> -Â Â Â }
>> -
>> -Â Â Â core->fw.mem_size = mem_size;
>> -Â Â Â core->fw.mem_phys = mem_phys;
>> -
>> -Â Â Â if (core->use_tz)
>> -Â Â Â Â Â Â Â ret = qcom_scm_pas_auth_and_reset(VENUS_PAS_ID);
>> -Â Â Â else
>> -Â Â Â Â Â Â Â ret = venus_boot_no_tz(core, mem_phys, mem_size);
>> -
>> -Â Â Â if (ret)
>> -Â Â Â Â Â Â Â return ret;
>> -
>> -Â Â Â if (core->use_tz && res->cp_size) {
>> -Â Â Â Â Â Â Â /*
>> -Â Â Â Â Â Â Â Â * Clues for porting using downstream data:
>> -Â Â Â Â Â Â Â Â * cp_start = 0
>> -Â Â Â Â Â Â Â Â * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and
>> not size!
>> -Â Â Â Â Â Â Â Â *Â Â This works, as the non-secure context bank is placed
>> -Â Â Â Â Â Â Â Â *Â Â contiguously right after the Content Protection region.
>> -Â Â Â Â Â Â Â Â *
>> -Â Â Â Â Â Â Â Â * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
>> -Â Â Â Â Â Â Â Â * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
>> -Â Â Â Â Â Â Â Â */
>> -Â Â Â Â Â Â Â ret = qcom_scm_mem_protect_video_var(res->cp_start,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_size,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_nonpixel_start,
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â res->cp_nonpixel_size);
>> -Â Â Â Â Â Â Â if (ret) {
>> -Â Â Â Â Â Â Â Â Â Â Â qcom_scm_pas_shutdown(VENUS_PAS_ID);
>> -Â Â Â Â Â Â Â Â Â Â Â dev_err(dev, "set virtual address ranges fail (%d)\n",
>> -Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ret);
>> -Â Â Â Â Â Â Â Â Â Â Â return ret;
>> -Â Â Â Â Â Â Â }
>> -Â Â Â }
>> -
>> -Â Â Â return 0;
>> -}
>> -
>> -int venus_shutdown(struct venus_core *core)
>> -{
>> -Â Â Â int ret;
>> -
>> -Â Â Â if (core->use_tz)
>> -Â Â Â Â Â Â Â ret = qcom_scm_pas_shutdown(VENUS_PAS_ID);
>> -Â Â Â else
>> -Â Â Â Â Â Â Â ret = venus_shutdown_no_tz(core);
>> -
>> -Â Â Â return ret;
>> -}
>> -
>> -int venus_firmware_init(struct venus_core *core)
>> -{
>> -Â Â Â struct platform_device_info info;
>> -Â Â Â struct iommu_domain *iommu_dom;
>> -Â Â Â struct platform_device *pdev;
>> -Â Â Â struct device_node *np;
>> -Â Â Â int ret;
>> -
>> -Â Â Â np = of_get_child_by_name(core->dev->of_node, "video-firmware");
>> -Â Â Â if (!np) {
>> -Â Â Â Â Â Â Â core->use_tz = true;
>> -Â Â Â Â Â Â Â return 0;
>> -Â Â Â }
>> -
>> -Â Â Â memset(&info, 0, sizeof(info));
>> -Â Â Â info.fwnode = &np->fwnode;
>> -Â Â Â info.parent = core->dev;
>> -Â Â Â info.name = np->name;
>> -Â Â Â info.dma_mask = DMA_BIT_MASK(32);
>> -
>> -Â Â Â pdev = platform_device_register_full(&info);
>> -Â Â Â if (IS_ERR(pdev)) {
>> -Â Â Â Â Â Â Â of_node_put(np);
>> -Â Â Â Â Â Â Â return PTR_ERR(pdev);
>> -Â Â Â }
>> -
>> -Â Â Â pdev->dev.of_node = np;
>> -
>> -Â Â Â ret = of_dma_configure(&pdev->dev, np, true);
>> -Â Â Â if (ret) {
>> -Â Â Â Â Â Â Â dev_err(core->dev, "dma configure fail\n");
>> -Â Â Â Â Â Â Â goto err_unregister;
>> -Â Â Â }
>> -
>> -Â Â Â core->fw.dev = &pdev->dev;
>> -
>> -Â Â Â iommu_dom = iommu_domain_alloc(&platform_bus_type);
>> -Â Â Â if (!iommu_dom) {
>> -Â Â Â Â Â Â Â dev_err(core->fw.dev, "Failed to allocate iommu domain\n");
>> -Â Â Â Â Â Â Â ret = -ENOMEM;
>> -Â Â Â Â Â Â Â goto err_unregister;
>> -Â Â Â }
>> -
>> -Â Â Â ret = iommu_attach_device(iommu_dom, core->fw.dev);
>> -Â Â Â if (ret) {
>> -Â Â Â Â Â Â Â dev_err(core->fw.dev, "could not attach device\n");
>> -Â Â Â Â Â Â Â goto err_iommu_free;
>> -Â Â Â }
>> -
>> -Â Â Â core->fw.iommu_domain = iommu_dom;
>> -
>> -Â Â Â of_node_put(np);
>> -
>> -Â Â Â return 0;
>> -
>> -err_iommu_free:
>> -Â Â Â iommu_domain_free(iommu_dom);
>> -err_unregister:
>> -Â Â Â platform_device_unregister(pdev);
>> -Â Â Â of_node_put(np);
>> -Â Â Â return ret;
>> -}
>> -
>> -void venus_firmware_deinit(struct venus_core *core)
>> -{
>> -Â Â Â struct iommu_domain *iommu;
>> -
>> -Â Â Â if (!core->fw.dev)
>> -Â Â Â Â Â Â Â return;
>> -
>> -Â Â Â iommu = core->fw.iommu_domain;
>> -
>> -Â Â Â iommu_detach_device(iommu, core->fw.dev);
>> -
>> -Â Â Â if (core->fw.iommu_domain) {
>> -Â Â Â Â Â Â Â iommu_domain_free(iommu);
>> -Â Â Â Â Â Â Â core->fw.iommu_domain = NULL;
>> -Â Â Â }
>> -
>> -Â Â Â platform_device_unregister(to_platform_device(core->fw.dev));
>> -}
>> diff --git a/drivers/media/platform/qcom/venus/firmware.h
>> b/drivers/media/platform/qcom/venus/firmware.h
>> deleted file mode 100644
>> index aaccd84..0000000
>> --- a/drivers/media/platform/qcom/venus/firmware.h
>> +++ /dev/null
>> @@ -1,26 +0,0 @@
>> -/* SPDX-License-Identifier: GPL-2.0-only */
>> -/*
>> - * Copyright (C) 2017 Linaro Ltd.
>> - */
>> -#ifndef __VENUS_FIRMWARE_H__
>> -#define __VENUS_FIRMWARE_H__
>> -
>> -struct device;
>> -
>> -int venus_firmware_init(struct venus_core *core);
>> -void venus_firmware_deinit(struct venus_core *core);
>> -int venus_boot(struct venus_core *core);
>> -int venus_shutdown(struct venus_core *core);
>> -int venus_set_hw_state(struct venus_core *core, bool suspend);
>> -
>> -static inline int venus_set_hw_state_suspend(struct venus_core *core)
>> -{
>> -Â Â Â return venus_set_hw_state(core, false);
>> -}
>> -
>> -static inline int venus_set_hw_state_resume(struct venus_core *core)
>> -{
>> -Â Â Â return venus_set_hw_state(core, true);
>> -}
>> -
>> -#endif
>
On 12/19/2023 6:56 PM, Dmitry Baryshkov wrote:
> On Tue, 19 Dec 2023 at 13:40, Bryan O'Donoghue
> <bryan.odonoghue@linaro.org> wrote:
>>
>> On 18/12/2023 11:31, Dikshita Agarwal wrote:
>>> Re-organize the video driver code by introducing a new folder
>>> 'vcodec' and placing 'venus' driver code inside that.
>>>
>>> Introduce common helpers for trustzone based firmware
>>> load/unload etc. which are placed in common folder
>>> i.e. 'vcodec'.
>>> Use these helpers in 'venus' driver. These helpers will be
>>> used by 'iris' driver as well which is introduced later
>>> in this patch series.
>>>
>>> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
>>> ---
>>
>> This is a very large patch, I think it needs to be broken up into
>> smaller chunks.
>>
>> #1 Introduce common helper functions
>> #2 Use common helper functions
>
> This will make it harder to review. It's usually preferred to have a
> single 'move' patch instead of two (add + remove). But I definitely
> agree that the size of the patch is big. Somewhat it is related to the
> fact that this doesn't only introduce helpers, but also reshuffles the
> rest of the code.
>
Thanking along the same lines as Dmitry's, we wanted to show the usage of
these common helpers in iris driver as well, hence we added these patches
as part of this series.
I can send these patches 1-3 as separate series and mark the dependency of
iris series to that if you would prefer that way.
Also, as mentioned in comments in previous patches, to make the common
helper code generic, moving just the code from venus to vcodec was not
sufficient and more changes were needed in calling functions of venus as well.
>>
>> Its alot of code to try to eat in the one go.
>>
>> Could you consider making patches 1-3 a standalone series to reduce the
>> amount of code to review here ?
>
> This sounds like a good idea.
> >>
>> * 77e7025529d7c - (HEAD -> linux-stable-master-23-12-18-iris-v2) media:
>> iris: add power management for encoder (21 hours ago)
>>
>> * ceb6a6f023fd3 - (tag: v6.7-rc6, linux-stable/master) Linux 6.7-rc6 (2
>> days ago)
>>
>> git diff ceb6a6f023fd3 | wc -l
>>
>> 21243
>>
>> Also I feel it wouild give more time for the changes to "digest" though
>> upstream users and to find any unintended bugs.
>>
>>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
>>> + size_t *mem_size, u32 pas_id, bool use_tz)
>>> +{
>>> + const struct firmware *firmware = NULL;
>>> + struct reserved_mem *rmem;
>>> + struct device_node *node;
>>> + void *mem_virt = NULL;
>>> + ssize_t fw_size = 0;
>>> + int ret;
>>> +
>>> + if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
>>> + (use_tz && !qcom_scm_is_available()))
>>> + return -EPROBE_DEFER;
>>> +
>>> + if (!fw_name || !(*fw_name))
>>> + return -EINVAL;
>>
>> The parameter check should come before the qcom_scm_is_available()
>>
>> No matter how many times you -EPROBE_DEFER -EINVAL is still -EINVAL.
>>
Sure, will check and do the needful.
>>> +
>>> + *mem_phys = 0;
>>> + *mem_size = 0;
>>
>> I don't think you need this, you don't appear to use these variables
>> before you assign them below.
>>
That's true, will fix.
>>
>>> +
>>> + *mem_phys = rmem->base;
>>> + *mem_size = rmem->size;
>>
>>> +
>>> +int auth_reset_fw(u32 pas_id)
>>> +{
>>> + return qcom_scm_pas_auth_and_reset(pas_id);
>>> +}
>>> +
>>> +void unload_fw(u32 pas_id)
>>> +{
>>> + qcom_scm_pas_shutdown(pas_id);
>>> +}
>>> +
>>
>> Do these wrapper functions add anything ? Some kind of validity check on
>> the pas_id otherwise I'm not sure these are justified.
>>
>>> +int set_hw_state(bool resume)
>>> +{
>>> + return qcom_scm_set_remote_state(resume, 0);
>>> +}
Will check more on this and do required changes.
>>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.h b/drivers/media/platform/qcom/vcodec/firmware.h
>>> new file mode 100644
>>> index 0000000..7d410a8
>>> --- /dev/null
>>
>> ---
>> bod
>>
>>
>
>
On Wed, 20 Dec 2023 at 10:01, Dikshita Agarwal
<quic_dikshita@quicinc.com> wrote:
>
>
>
> On 12/18/2023 11:54 PM, Dmitry Baryshkov wrote:
> > On 18/12/2023 13:31, Dikshita Agarwal wrote:
> >> Re-organize the video driver code by introducing a new folder
> >> 'vcodec' and placing 'venus' driver code inside that.
> >>
> >> Introduce common helpers for trustzone based firmware
> >> load/unload etc. which are placed in common folder
> >> i.e. 'vcodec'.
> >> Use these helpers in 'venus' driver. These helpers will be
> >> used by 'iris' driver as well which is introduced later
> >> in this patch series.
> >
> > But why do you need to move the venus driver to subdir?
>
> Currently venus driver is present in drivers/media/platform/qcom folder
> which also has camss folder. We introduced vcodec to keep common code and
> moved venus inside that, to indicate that the common code is for vcodec
> drivers i.e venus and iris. Keeping this in qcom folder would mean, common
> code will be used for camss only which is not the case here.
you can have .../platform/qcom/camss, .../platform/qcom/vcodec-common,
.../platform/qcom/venus and .../platform/qcom/iris.
If you were to use build helpers in a proper kernel module, this would
be more obvious.
> >
> >>
> >> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
> >> ---
> >> drivers/media/platform/qcom/Kconfig | 2 +-
> >> drivers/media/platform/qcom/Makefile | 2 +-
> >> drivers/media/platform/qcom/vcodec/firmware.c | 147 +++++++++
> >> drivers/media/platform/qcom/vcodec/firmware.h | 21 ++
> >> .../media/platform/qcom/{ => vcodec}/venus/Kconfig | 0
> >> .../platform/qcom/{ => vcodec}/venus/Makefile | 4 +-
> >> .../media/platform/qcom/{ => vcodec}/venus/core.c | 102 +++++-
> >> .../media/platform/qcom/{ => vcodec}/venus/core.h | 0
> >> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.c | 0
> >> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.h | 0
> >> .../platform/qcom/vcodec/venus/firmware_no_tz.c | 194 +++++++++++
> >> .../platform/qcom/vcodec/venus/firmware_no_tz.h | 19 ++
> >> .../platform/qcom/{ => vcodec}/venus/helpers.c | 0
> >> .../platform/qcom/{ => vcodec}/venus/helpers.h | 0
> >> .../media/platform/qcom/{ => vcodec}/venus/hfi.c | 0
> >> .../media/platform/qcom/{ => vcodec}/venus/hfi.h | 0
> >> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.c | 0
> >> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.h | 0
> >> .../platform/qcom/{ => vcodec}/venus/hfi_helper.h | 0
> >> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.c | 0
> >> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.h | 0
> >> .../platform/qcom/{ => vcodec}/venus/hfi_parser.c | 0
> >> .../platform/qcom/{ => vcodec}/venus/hfi_parser.h | 0
> >> .../qcom/{ => vcodec}/venus/hfi_plat_bufs.h | 0
> >> .../qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c | 0
> >> .../qcom/{ => vcodec}/venus/hfi_platform.c | 0
> >> .../qcom/{ => vcodec}/venus/hfi_platform.h | 0
> >> .../qcom/{ => vcodec}/venus/hfi_platform_v4.c | 0
> >> .../qcom/{ => vcodec}/venus/hfi_platform_v6.c | 0
> >> .../platform/qcom/{ => vcodec}/venus/hfi_venus.c | 21 +-
> >> .../platform/qcom/{ => vcodec}/venus/hfi_venus.h | 0
> >> .../qcom/{ => vcodec}/venus/hfi_venus_io.h | 0
> >> .../platform/qcom/{ => vcodec}/venus/pm_helpers.c | 0
> >> .../platform/qcom/{ => vcodec}/venus/pm_helpers.h | 0
> >> .../media/platform/qcom/{ => vcodec}/venus/vdec.c | 0
> >> .../media/platform/qcom/{ => vcodec}/venus/vdec.h | 0
> >> .../platform/qcom/{ => vcodec}/venus/vdec_ctrls.c | 0
> >> .../media/platform/qcom/{ => vcodec}/venus/venc.c | 0
> >> .../media/platform/qcom/{ => vcodec}/venus/venc.h | 0
> >> .../platform/qcom/{ => vcodec}/venus/venc_ctrls.c | 0
> >> drivers/media/platform/qcom/venus/firmware.c | 363
> >> ---------------------
> >> drivers/media/platform/qcom/venus/firmware.h | 26 --
> >> 42 files changed, 492 insertions(+), 409 deletions(-)
> >> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.c
> >> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.h
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/Kconfig (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/Makefile (83%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.c (91%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.h (100%)
> >> create mode 100644
> >> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
> >> create mode 100644
> >> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_helper.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs.h
> >> (100%)
> >> rename drivers/media/platform/qcom/{ =>
> >> vcodec}/venus/hfi_plat_bufs_v6.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.c
> >> (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.h
> >> (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v4.c
> >> (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v6.c
> >> (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.c (99%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus_io.h
> >> (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec_ctrls.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.c (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.h (100%)
> >> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc_ctrls.c (100%)
> >> delete mode 100644 drivers/media/platform/qcom/venus/firmware.c
> >> delete mode 100644 drivers/media/platform/qcom/venus/firmware.h
> >>
> >> diff --git a/drivers/media/platform/qcom/Kconfig
> >> b/drivers/media/platform/qcom/Kconfig
> >> index cc5799b..e94142f 100644
> >> --- a/drivers/media/platform/qcom/Kconfig
> >> +++ b/drivers/media/platform/qcom/Kconfig
> >> @@ -3,4 +3,4 @@
> >> comment "Qualcomm media platform drivers"
> >> source "drivers/media/platform/qcom/camss/Kconfig"
> >> -source "drivers/media/platform/qcom/venus/Kconfig"
> >> +source "drivers/media/platform/qcom/vcodec/venus/Kconfig"
> >> diff --git a/drivers/media/platform/qcom/Makefile
> >> b/drivers/media/platform/qcom/Makefile
> >> index 4f055c3..3d2d82b 100644
> >> --- a/drivers/media/platform/qcom/Makefile
> >> +++ b/drivers/media/platform/qcom/Makefile
> >> @@ -1,3 +1,3 @@
> >> # SPDX-License-Identifier: GPL-2.0-only
> >> obj-y += camss/
> >> -obj-y += venus/
> >> +obj-y += vcodec/venus/
> >> diff --git a/drivers/media/platform/qcom/vcodec/firmware.c
> >> b/drivers/media/platform/qcom/vcodec/firmware.c
> >> new file mode 100644
> >> index 0000000..dbc220a
> >> --- /dev/null
> >> +++ b/drivers/media/platform/qcom/vcodec/firmware.c
> >> @@ -0,0 +1,147 @@
> >> +// SPDX-License-Identifier: GPL-2.0-only
> >> +/*
> >> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
> >> reserved.
> >> + */
> >> +
> >> +#include <linux/device.h>
> >> +#include <linux/dma-mapping.h>
> >> +#include <linux/firmware.h>
> >> +#include <linux/kernel.h>
> >> +#include <linux/iommu.h>
> >> +#include <linux/of_device.h>
> >> +#include <linux/firmware/qcom/qcom_scm.h>
> >> +#include <linux/of_reserved_mem.h>
> >> +#include <linux/platform_device.h>
> >> +#include <linux/soc/qcom/mdt_loader.h>
> >> +
> >> +#include "firmware.h"
> >> +
> >> +bool use_tz(struct device *core_dev)
> >
> > All these functions must get some sane prefix. Otherwise a generic 'use_tz'
> > function is too polluting for the global namespace.
> >
> I understand, will check and do the needful.
> >> +{
> >> + struct device_node *np;
> >> +
> >> + np = of_get_child_by_name(core_dev->of_node, "video-firmware");
> >> + if (!np)
> >> + return true;
> >> +
> >> + return false;
> >> +}
> >> +
> >> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
> >> + u32 cp_nonpixel_size, u32 pas_id)
> >> +{
> >> + int ret;
> >> + /*
> >> + * Clues for porting using downstream data:
> >> + * cp_start = 0
> >> + * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
> >> + * This works, as the non-secure context bank is placed
> >> + * contiguously right after the Content Protection region.
> >> + *
> >> + * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
> >> + * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
> >> + */
> >> + ret = qcom_scm_mem_protect_video_var(cp_start,
> >> + cp_size,
> >> + cp_nonpixel_start,
> >> + cp_nonpixel_size);
> >> + if (ret)
> >> + qcom_scm_pas_shutdown(pas_id);
> >> +
> >> + return ret;
> >> +}
> >> +
> >> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
> >> + size_t *mem_size, u32 pas_id, bool use_tz)
> >> +{
> >> + const struct firmware *firmware = NULL;
> >> + struct reserved_mem *rmem;
> >> + struct device_node *node;
> >> + void *mem_virt = NULL;
> >> + ssize_t fw_size = 0;
> >> + int ret;
> >> +
> >> + if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
> >
> > Why? Can you just depend on it?
> >
> Sure, Will check this and get back.
> >> + (use_tz && !qcom_scm_is_available()))
> >> + return -EPROBE_DEFER;
> >> +
> >> + if (!fw_name || !(*fw_name))
> >> + return -EINVAL;
> >> +
> >> + *mem_phys = 0;
> >> + *mem_size = 0;
> >> +
> >> + node = of_parse_phandle(dev->of_node, "memory-region", 0);
> >> + if (!node) {
> >> + dev_err(dev, "no memory-region specified\n");
> >> + return -EINVAL;
> >> + }
> >> +
> >> + rmem = of_reserved_mem_lookup(node);
> >> + of_node_put(node);
> >> + if (!rmem) {
> >> + dev_err(dev, "failed to lookup reserved memory-region\n");
> >> + return -EINVAL;
> >> + }
> >> +
> >> + ret = request_firmware(&firmware, fw_name, dev);
> >> + if (ret) {
> >> + dev_err(dev, "%s: failed to request fw \"%s\", error %d\n",
> >> + __func__, fw_name, ret);
> >> + return ret;
> >> + }
> >> +
> >> + fw_size = qcom_mdt_get_size(firmware);
> >> + if (fw_size < 0) {
> >> + ret = fw_size;
> >> + dev_err(dev, "%s: out of bound fw image fw size: %ld\n",
> >> + __func__, fw_size);
> >> + goto err_release_fw;
> >> + }
> >> +
> >> + *mem_phys = rmem->base;
> >> + *mem_size = rmem->size;
> >> +
> >> + if (*mem_size < fw_size) {
> >> + ret = -EINVAL;
> >> + goto err_release_fw;
> >> + }
> >> +
> >> + mem_virt = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
> >> + if (!mem_virt) {
> >> + dev_err(dev, "unable to remap fw memory region %pa size %#zx\n",
> >> + mem_phys, *mem_size);
> >> + goto err_release_fw;
> >> + }
> >> +
> >> + if (use_tz)
> >> + ret = qcom_mdt_load(dev, firmware, fw_name, pas_id, mem_virt,
> >> + *mem_phys, *mem_size, NULL);
> >> + else
> >> + ret = qcom_mdt_load_no_init(dev, firmware, fw_name, pas_id,
> >> mem_virt,
> >> + *mem_phys, *mem_size, NULL);
> >> + if (ret) {
> >> + dev_err(dev, "%s: error %d loading fw \"%s\"\n",
> >> + __func__, ret, fw_name);
> >> + }
> >> +
> >> + memunmap(mem_virt);
> >> +err_release_fw:
> >> + release_firmware(firmware);
> >> + return ret;
> >> +}
> >> +
> >> +int auth_reset_fw(u32 pas_id)
> >> +{
> >> + return qcom_scm_pas_auth_and_reset(pas_id);
> >> +}
> >> +
> >> +void unload_fw(u32 pas_id)
> >> +{
> >> + qcom_scm_pas_shutdown(pas_id);
> >> +}
> >> +
> >> +int set_hw_state(bool resume)
> >> +{
> >> + return qcom_scm_set_remote_state(resume, 0);
> >> +}
> >> diff --git a/drivers/media/platform/qcom/vcodec/firmware.h
> >> b/drivers/media/platform/qcom/vcodec/firmware.h
> >> new file mode 100644
> >> index 0000000..7d410a8
> >> --- /dev/null
> >> +++ b/drivers/media/platform/qcom/vcodec/firmware.h
> >> @@ -0,0 +1,21 @@
> >> +/* SPDX-License-Identifier: GPL-2.0-only */
> >> +/*
> >> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
> >> reserved.
> >> + */
> >> +
> >> +#ifndef _FIRMWARE_H_
> >> +#define _FIRMWARE_H_
> >> +
> >> +#include <linux/device.h>
> >> +#include <linux/types.h>
> >> +
> >> +bool use_tz(struct device *core_dev);
> >> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
> >> + size_t *mem_size, u32 pas_id, bool use_tz);
> >> +int auth_reset_fw(u32 pas_id);
> >> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
> >> + u32 cp_nonpixel_size, u32 pas_id);
> >> +void unload_fw(u32 pas_id);
> >> +int set_hw_state(bool resume);
> >> +
> >> +#endif
> >> diff --git a/drivers/media/platform/qcom/venus/Kconfig
> >> b/drivers/media/platform/qcom/vcodec/venus/Kconfig
> >> similarity index 100%
> >> rename from drivers/media/platform/qcom/venus/Kconfig
> >> rename to drivers/media/platform/qcom/vcodec/venus/Kconfig
> >> diff --git a/drivers/media/platform/qcom/venus/Makefile
> >> b/drivers/media/platform/qcom/vcodec/venus/Makefile
> >> similarity index 83%
> >> rename from drivers/media/platform/qcom/venus/Makefile
> >> rename to drivers/media/platform/qcom/vcodec/venus/Makefile
> >> index 91ee6be..f6f3a88 100644
> >> --- a/drivers/media/platform/qcom/venus/Makefile
> >> +++ b/drivers/media/platform/qcom/vcodec/venus/Makefile
> >> @@ -1,7 +1,9 @@
> >> # SPDX-License-Identifier: GPL-2.0
> >> # Makefile for Qualcomm Venus driver
> >> -venus-core-objs += core.o helpers.o firmware.o \
> >> +venus-core-objs += ../firmware.o
> >> +
> >> +venus-core-objs += core.o helpers.o firmware_no_tz.o \
> >> hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
> >> hfi_parser.o pm_helpers.o dbgfs.o \
> >> hfi_platform.o hfi_platform_v4.o \
> >> diff --git a/drivers/media/platform/qcom/venus/core.c
> >> b/drivers/media/platform/qcom/vcodec/venus/core.c
> >> similarity index 91%
> >> rename from drivers/media/platform/qcom/venus/core.c
> >> rename to drivers/media/platform/qcom/vcodec/venus/core.c
> >> index 9cffe97..56d9a53 100644
> >> --- a/drivers/media/platform/qcom/venus/core.c
> >> +++ b/drivers/media/platform/qcom/vcodec/venus/core.c
> >> @@ -22,7 +22,8 @@
> >> #include <media/v4l2-ioctl.h>
> >> #include "core.h"
> >> -#include "firmware.h"
> >> +#include "../firmware.h"
> >> +#include "firmware_no_tz.h"
> >> #include "pm_helpers.h"
> >> #include "hfi_venus_io.h"
> >> @@ -86,6 +87,8 @@ static void venus_sys_error_handler(struct
> >> work_struct *work)
> >> struct venus_core *core =
> >> container_of(work, struct venus_core, work.work);
> >> int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
> >> + const struct venus_resources *res = core->res;
> >> + const char *fwpath = NULL;
> >> const char *err_msg = "";
> >> bool failed = false;
> >> @@ -107,7 +110,10 @@ static void venus_sys_error_handler(struct
> >> work_struct *work)
> >> mutex_lock(&core->lock);
> >> - venus_shutdown(core);
> >> + if (core->use_tz)
> >> + unload_fw(VENUS_PAS_ID);
> >> + else
> >> + unload_fw_no_tz(core);
> >
> > This is more than introducing helpers.
> >
> The new helpers are written to make the code generic for video drivers.
> which requires changes in the calling function also.
> >> venus_coredump(core);
> >> @@ -127,12 +133,39 @@ static void venus_sys_error_handler(struct
> >> work_struct *work)
> >> failed = true;
> >> }
> >> - ret = venus_boot(core);
> >> + ret = of_property_read_string_index(core->dev->of_node,
> >> "firmware-name", 0,
> >> + &fwpath);
> >> + if (ret)
> >> + fwpath = core->res->fwname;
> >> +
> >> + ret = load_fw(core->dev, fwpath, &core->fw.mem_phys,
> >> &core->fw.mem_size,
> >> + VENUS_PAS_ID, core->use_tz);
> >
> > So, we had a nice local 'venus_boot'. Instead we now have a pile of code
> > with non-generic prefixes, etc. If you are introducing helpers, please
> > refrain from inlining of calling functions, etc. Just move the code to your
> > helpers.
> >
> As mentioned in above comment, the common helpers are written to make the
> code generic. I Will try to make it more clear, working on the same.
First, you move the code, then you make it generic. Or vice versa.
First you split the code, then you move it. Don't do both in the same
patch.
> > NAK for the rest of the patch.
Hi Dmitry
On 12/20/2023 12:12 AM, Dmitry Baryshkov wrote:
> On Wed, 20 Dec 2023 at 10:01, Dikshita Agarwal
> <quic_dikshita@quicinc.com> wrote:
>>
>>
>>
>> On 12/18/2023 11:54 PM, Dmitry Baryshkov wrote:
>>> On 18/12/2023 13:31, Dikshita Agarwal wrote:
>>>> Re-organize the video driver code by introducing a new folder
>>>> 'vcodec' and placing 'venus' driver code inside that.
>>>>
>>>> Introduce common helpers for trustzone based firmware
>>>> load/unload etc. which are placed in common folder
>>>> i.e. 'vcodec'.
>>>> Use these helpers in 'venus' driver. These helpers will be
>>>> used by 'iris' driver as well which is introduced later
>>>> in this patch series.
>>>
>>> But why do you need to move the venus driver to subdir?
>>
>> Currently venus driver is present in drivers/media/platform/qcom folder
>> which also has camss folder. We introduced vcodec to keep common code and
>> moved venus inside that, to indicate that the common code is for vcodec
>> drivers i.e venus and iris. Keeping this in qcom folder would mean, common
>> code will be used for camss only which is not the case here.
>
> you can have .../platform/qcom/camss, .../platform/qcom/vcodec-common,
> .../platform/qcom/venus and .../platform/qcom/iris.
>
> If you were to use build helpers in a proper kernel module, this would
> be more obvious.
>
Although your suggestion is good in terms of avoiding moving venus, I
think the location of venus was wrong to begin with. There should have
always been a vcodec (or similar) folder for venus/iris as that will
establish the boundaries of camss and video sub-system in a cleaner way
I like the mediatek separation that way as it makes the boundaries clear:
drivers/media/platform/mediatek$ ls
jpeg Kconfig Makefile mdp mdp3 vcodec vpu
So I think that this re-org of venus into a vcodec had to happen at some
point. Its just that it aligned with iris addition.
>>>
>>>>
>>>> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
>>>> ---
>>>> drivers/media/platform/qcom/Kconfig | 2 +-
>>>> drivers/media/platform/qcom/Makefile | 2 +-
>>>> drivers/media/platform/qcom/vcodec/firmware.c | 147 +++++++++
>>>> drivers/media/platform/qcom/vcodec/firmware.h | 21 ++
>>>> .../media/platform/qcom/{ => vcodec}/venus/Kconfig | 0
>>>> .../platform/qcom/{ => vcodec}/venus/Makefile | 4 +-
>>>> .../media/platform/qcom/{ => vcodec}/venus/core.c | 102 +++++-
>>>> .../media/platform/qcom/{ => vcodec}/venus/core.h | 0
>>>> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.c | 0
>>>> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.h | 0
>>>> .../platform/qcom/vcodec/venus/firmware_no_tz.c | 194 +++++++++++
>>>> .../platform/qcom/vcodec/venus/firmware_no_tz.h | 19 ++
>>>> .../platform/qcom/{ => vcodec}/venus/helpers.c | 0
>>>> .../platform/qcom/{ => vcodec}/venus/helpers.h | 0
>>>> .../media/platform/qcom/{ => vcodec}/venus/hfi.c | 0
>>>> .../media/platform/qcom/{ => vcodec}/venus/hfi.h | 0
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.c | 0
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.h | 0
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_helper.h | 0
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.c | 0
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.h | 0
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_parser.c | 0
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_parser.h | 0
>>>> .../qcom/{ => vcodec}/venus/hfi_plat_bufs.h | 0
>>>> .../qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c | 0
>>>> .../qcom/{ => vcodec}/venus/hfi_platform.c | 0
>>>> .../qcom/{ => vcodec}/venus/hfi_platform.h | 0
>>>> .../qcom/{ => vcodec}/venus/hfi_platform_v4.c | 0
>>>> .../qcom/{ => vcodec}/venus/hfi_platform_v6.c | 0
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_venus.c | 21 +-
>>>> .../platform/qcom/{ => vcodec}/venus/hfi_venus.h | 0
>>>> .../qcom/{ => vcodec}/venus/hfi_venus_io.h | 0
>>>> .../platform/qcom/{ => vcodec}/venus/pm_helpers.c | 0
>>>> .../platform/qcom/{ => vcodec}/venus/pm_helpers.h | 0
>>>> .../media/platform/qcom/{ => vcodec}/venus/vdec.c | 0
>>>> .../media/platform/qcom/{ => vcodec}/venus/vdec.h | 0
>>>> .../platform/qcom/{ => vcodec}/venus/vdec_ctrls.c | 0
>>>> .../media/platform/qcom/{ => vcodec}/venus/venc.c | 0
>>>> .../media/platform/qcom/{ => vcodec}/venus/venc.h | 0
>>>> .../platform/qcom/{ => vcodec}/venus/venc_ctrls.c | 0
>>>> drivers/media/platform/qcom/venus/firmware.c | 363
>>>> ---------------------
>>>> drivers/media/platform/qcom/venus/firmware.h | 26 --
>>>> 42 files changed, 492 insertions(+), 409 deletions(-)
>>>> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.c
>>>> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.h
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/Kconfig (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/Makefile (83%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.c (91%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.h (100%)
>>>> create mode 100644
>>>> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
>>>> create mode 100644
>>>> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_helper.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs.h
>>>> (100%)
>>>> rename drivers/media/platform/qcom/{ =>
>>>> vcodec}/venus/hfi_plat_bufs_v6.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.c
>>>> (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.h
>>>> (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v4.c
>>>> (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v6.c
>>>> (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.c (99%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus_io.h
>>>> (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec_ctrls.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.c (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.h (100%)
>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc_ctrls.c (100%)
>>>> delete mode 100644 drivers/media/platform/qcom/venus/firmware.c
>>>> delete mode 100644 drivers/media/platform/qcom/venus/firmware.h
>>>>
>>>> diff --git a/drivers/media/platform/qcom/Kconfig
>>>> b/drivers/media/platform/qcom/Kconfig
>>>> index cc5799b..e94142f 100644
>>>> --- a/drivers/media/platform/qcom/Kconfig
>>>> +++ b/drivers/media/platform/qcom/Kconfig
>>>> @@ -3,4 +3,4 @@
>>>> comment "Qualcomm media platform drivers"
>>>> source "drivers/media/platform/qcom/camss/Kconfig"
>>>> -source "drivers/media/platform/qcom/venus/Kconfig"
>>>> +source "drivers/media/platform/qcom/vcodec/venus/Kconfig"
>>>> diff --git a/drivers/media/platform/qcom/Makefile
>>>> b/drivers/media/platform/qcom/Makefile
>>>> index 4f055c3..3d2d82b 100644
>>>> --- a/drivers/media/platform/qcom/Makefile
>>>> +++ b/drivers/media/platform/qcom/Makefile
>>>> @@ -1,3 +1,3 @@
>>>> # SPDX-License-Identifier: GPL-2.0-only
>>>> obj-y += camss/
>>>> -obj-y += venus/
>>>> +obj-y += vcodec/venus/
>>>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.c
>>>> b/drivers/media/platform/qcom/vcodec/firmware.c
>>>> new file mode 100644
>>>> index 0000000..dbc220a
>>>> --- /dev/null
>>>> +++ b/drivers/media/platform/qcom/vcodec/firmware.c
>>>> @@ -0,0 +1,147 @@
>>>> +// SPDX-License-Identifier: GPL-2.0-only
>>>> +/*
>>>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
>>>> reserved.
>>>> + */
>>>> +
>>>> +#include <linux/device.h>
>>>> +#include <linux/dma-mapping.h>
>>>> +#include <linux/firmware.h>
>>>> +#include <linux/kernel.h>
>>>> +#include <linux/iommu.h>
>>>> +#include <linux/of_device.h>
>>>> +#include <linux/firmware/qcom/qcom_scm.h>
>>>> +#include <linux/of_reserved_mem.h>
>>>> +#include <linux/platform_device.h>
>>>> +#include <linux/soc/qcom/mdt_loader.h>
>>>> +
>>>> +#include "firmware.h"
>>>> +
>>>> +bool use_tz(struct device *core_dev)
>>>
>>> All these functions must get some sane prefix. Otherwise a generic 'use_tz'
>>> function is too polluting for the global namespace.
>>>
>> I understand, will check and do the needful.
>>>> +{
>>>> + struct device_node *np;
>>>> +
>>>> + np = of_get_child_by_name(core_dev->of_node, "video-firmware");
>>>> + if (!np)
>>>> + return true;
>>>> +
>>>> + return false;
>>>> +}
>>>> +
>>>> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
>>>> + u32 cp_nonpixel_size, u32 pas_id)
>>>> +{
>>>> + int ret;
>>>> + /*
>>>> + * Clues for porting using downstream data:
>>>> + * cp_start = 0
>>>> + * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
>>>> + * This works, as the non-secure context bank is placed
>>>> + * contiguously right after the Content Protection region.
>>>> + *
>>>> + * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
>>>> + * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
>>>> + */
>>>> + ret = qcom_scm_mem_protect_video_var(cp_start,
>>>> + cp_size,
>>>> + cp_nonpixel_start,
>>>> + cp_nonpixel_size);
>>>> + if (ret)
>>>> + qcom_scm_pas_shutdown(pas_id);
>>>> +
>>>> + return ret;
>>>> +}
>>>> +
>>>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
>>>> + size_t *mem_size, u32 pas_id, bool use_tz)
>>>> +{
>>>> + const struct firmware *firmware = NULL;
>>>> + struct reserved_mem *rmem;
>>>> + struct device_node *node;
>>>> + void *mem_virt = NULL;
>>>> + ssize_t fw_size = 0;
>>>> + int ret;
>>>> +
>>>> + if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
>>>
>>> Why? Can you just depend on it?
>>>
>> Sure, Will check this and get back.
>>>> + (use_tz && !qcom_scm_is_available()))
>>>> + return -EPROBE_DEFER;
>>>> +
>>>> + if (!fw_name || !(*fw_name))
>>>> + return -EINVAL;
>>>> +
>>>> + *mem_phys = 0;
>>>> + *mem_size = 0;
>>>> +
>>>> + node = of_parse_phandle(dev->of_node, "memory-region", 0);
>>>> + if (!node) {
>>>> + dev_err(dev, "no memory-region specified\n");
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + rmem = of_reserved_mem_lookup(node);
>>>> + of_node_put(node);
>>>> + if (!rmem) {
>>>> + dev_err(dev, "failed to lookup reserved memory-region\n");
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + ret = request_firmware(&firmware, fw_name, dev);
>>>> + if (ret) {
>>>> + dev_err(dev, "%s: failed to request fw \"%s\", error %d\n",
>>>> + __func__, fw_name, ret);
>>>> + return ret;
>>>> + }
>>>> +
>>>> + fw_size = qcom_mdt_get_size(firmware);
>>>> + if (fw_size < 0) {
>>>> + ret = fw_size;
>>>> + dev_err(dev, "%s: out of bound fw image fw size: %ld\n",
>>>> + __func__, fw_size);
>>>> + goto err_release_fw;
>>>> + }
>>>> +
>>>> + *mem_phys = rmem->base;
>>>> + *mem_size = rmem->size;
>>>> +
>>>> + if (*mem_size < fw_size) {
>>>> + ret = -EINVAL;
>>>> + goto err_release_fw;
>>>> + }
>>>> +
>>>> + mem_virt = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
>>>> + if (!mem_virt) {
>>>> + dev_err(dev, "unable to remap fw memory region %pa size %#zx\n",
>>>> + mem_phys, *mem_size);
>>>> + goto err_release_fw;
>>>> + }
>>>> +
>>>> + if (use_tz)
>>>> + ret = qcom_mdt_load(dev, firmware, fw_name, pas_id, mem_virt,
>>>> + *mem_phys, *mem_size, NULL);
>>>> + else
>>>> + ret = qcom_mdt_load_no_init(dev, firmware, fw_name, pas_id,
>>>> mem_virt,
>>>> + *mem_phys, *mem_size, NULL);
>>>> + if (ret) {
>>>> + dev_err(dev, "%s: error %d loading fw \"%s\"\n",
>>>> + __func__, ret, fw_name);
>>>> + }
>>>> +
>>>> + memunmap(mem_virt);
>>>> +err_release_fw:
>>>> + release_firmware(firmware);
>>>> + return ret;
>>>> +}
>>>> +
>>>> +int auth_reset_fw(u32 pas_id)
>>>> +{
>>>> + return qcom_scm_pas_auth_and_reset(pas_id);
>>>> +}
>>>> +
>>>> +void unload_fw(u32 pas_id)
>>>> +{
>>>> + qcom_scm_pas_shutdown(pas_id);
>>>> +}
>>>> +
>>>> +int set_hw_state(bool resume)
>>>> +{
>>>> + return qcom_scm_set_remote_state(resume, 0);
>>>> +}
>>>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.h
>>>> b/drivers/media/platform/qcom/vcodec/firmware.h
>>>> new file mode 100644
>>>> index 0000000..7d410a8
>>>> --- /dev/null
>>>> +++ b/drivers/media/platform/qcom/vcodec/firmware.h
>>>> @@ -0,0 +1,21 @@
>>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>>> +/*
>>>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
>>>> reserved.
>>>> + */
>>>> +
>>>> +#ifndef _FIRMWARE_H_
>>>> +#define _FIRMWARE_H_
>>>> +
>>>> +#include <linux/device.h>
>>>> +#include <linux/types.h>
>>>> +
>>>> +bool use_tz(struct device *core_dev);
>>>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
>>>> + size_t *mem_size, u32 pas_id, bool use_tz);
>>>> +int auth_reset_fw(u32 pas_id);
>>>> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
>>>> + u32 cp_nonpixel_size, u32 pas_id);
>>>> +void unload_fw(u32 pas_id);
>>>> +int set_hw_state(bool resume);
>>>> +
>>>> +#endif
>>>> diff --git a/drivers/media/platform/qcom/venus/Kconfig
>>>> b/drivers/media/platform/qcom/vcodec/venus/Kconfig
>>>> similarity index 100%
>>>> rename from drivers/media/platform/qcom/venus/Kconfig
>>>> rename to drivers/media/platform/qcom/vcodec/venus/Kconfig
>>>> diff --git a/drivers/media/platform/qcom/venus/Makefile
>>>> b/drivers/media/platform/qcom/vcodec/venus/Makefile
>>>> similarity index 83%
>>>> rename from drivers/media/platform/qcom/venus/Makefile
>>>> rename to drivers/media/platform/qcom/vcodec/venus/Makefile
>>>> index 91ee6be..f6f3a88 100644
>>>> --- a/drivers/media/platform/qcom/venus/Makefile
>>>> +++ b/drivers/media/platform/qcom/vcodec/venus/Makefile
>>>> @@ -1,7 +1,9 @@
>>>> # SPDX-License-Identifier: GPL-2.0
>>>> # Makefile for Qualcomm Venus driver
>>>> -venus-core-objs += core.o helpers.o firmware.o \
>>>> +venus-core-objs += ../firmware.o
>>>> +
>>>> +venus-core-objs += core.o helpers.o firmware_no_tz.o \
>>>> hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
>>>> hfi_parser.o pm_helpers.o dbgfs.o \
>>>> hfi_platform.o hfi_platform_v4.o \
>>>> diff --git a/drivers/media/platform/qcom/venus/core.c
>>>> b/drivers/media/platform/qcom/vcodec/venus/core.c
>>>> similarity index 91%
>>>> rename from drivers/media/platform/qcom/venus/core.c
>>>> rename to drivers/media/platform/qcom/vcodec/venus/core.c
>>>> index 9cffe97..56d9a53 100644
>>>> --- a/drivers/media/platform/qcom/venus/core.c
>>>> +++ b/drivers/media/platform/qcom/vcodec/venus/core.c
>>>> @@ -22,7 +22,8 @@
>>>> #include <media/v4l2-ioctl.h>
>>>> #include "core.h"
>>>> -#include "firmware.h"
>>>> +#include "../firmware.h"
>>>> +#include "firmware_no_tz.h"
>>>> #include "pm_helpers.h"
>>>> #include "hfi_venus_io.h"
>>>> @@ -86,6 +87,8 @@ static void venus_sys_error_handler(struct
>>>> work_struct *work)
>>>> struct venus_core *core =
>>>> container_of(work, struct venus_core, work.work);
>>>> int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
>>>> + const struct venus_resources *res = core->res;
>>>> + const char *fwpath = NULL;
>>>> const char *err_msg = "";
>>>> bool failed = false;
>>>> @@ -107,7 +110,10 @@ static void venus_sys_error_handler(struct
>>>> work_struct *work)
>>>> mutex_lock(&core->lock);
>>>> - venus_shutdown(core);
>>>> + if (core->use_tz)
>>>> + unload_fw(VENUS_PAS_ID);
>>>> + else
>>>> + unload_fw_no_tz(core);
>>>
>>> This is more than introducing helpers.
>>>
>> The new helpers are written to make the code generic for video drivers.
>> which requires changes in the calling function also.
>>>> venus_coredump(core);
>>>> @@ -127,12 +133,39 @@ static void venus_sys_error_handler(struct
>>>> work_struct *work)
>>>> failed = true;
>>>> }
>>>> - ret = venus_boot(core);
>>>> + ret = of_property_read_string_index(core->dev->of_node,
>>>> "firmware-name", 0,
>>>> + &fwpath);
>>>> + if (ret)
>>>> + fwpath = core->res->fwname;
>>>> +
>>>> + ret = load_fw(core->dev, fwpath, &core->fw.mem_phys,
>>>> &core->fw.mem_size,
>>>> + VENUS_PAS_ID, core->use_tz);
>>>
>>> So, we had a nice local 'venus_boot'. Instead we now have a pile of code
>>> with non-generic prefixes, etc. If you are introducing helpers, please
>>> refrain from inlining of calling functions, etc. Just move the code to your
>>> helpers.
>>>
>> As mentioned in above comment, the common helpers are written to make the
>> code generic. I Will try to make it more clear, working on the same.
>
> First, you move the code, then you make it generic. Or vice versa.
> First you split the code, then you move it. Don't do both in the same
> patch.
>
>>> NAK for the rest of the patch.
>
>
Hi Abhinav,
On Wed, 20 Dec 2023 at 19:10, Abhinav Kumar <quic_abhinavk@quicinc.com> wrote:
>
> Hi Dmitry
>
> On 12/20/2023 12:12 AM, Dmitry Baryshkov wrote:
> > On Wed, 20 Dec 2023 at 10:01, Dikshita Agarwal
> > <quic_dikshita@quicinc.com> wrote:
> >>
> >>
> >>
> >> On 12/18/2023 11:54 PM, Dmitry Baryshkov wrote:
> >>> On 18/12/2023 13:31, Dikshita Agarwal wrote:
> >>>> Re-organize the video driver code by introducing a new folder
> >>>> 'vcodec' and placing 'venus' driver code inside that.
> >>>>
> >>>> Introduce common helpers for trustzone based firmware
> >>>> load/unload etc. which are placed in common folder
> >>>> i.e. 'vcodec'.
> >>>> Use these helpers in 'venus' driver. These helpers will be
> >>>> used by 'iris' driver as well which is introduced later
> >>>> in this patch series.
> >>>
> >>> But why do you need to move the venus driver to subdir?
> >>
> >> Currently venus driver is present in drivers/media/platform/qcom folder
> >> which also has camss folder. We introduced vcodec to keep common code and
> >> moved venus inside that, to indicate that the common code is for vcodec
> >> drivers i.e venus and iris. Keeping this in qcom folder would mean, common
> >> code will be used for camss only which is not the case here.
> >
> > you can have .../platform/qcom/camss, .../platform/qcom/vcodec-common,
> > .../platform/qcom/venus and .../platform/qcom/iris.
> >
> > If you were to use build helpers in a proper kernel module, this would
> > be more obvious.
> >
>
> Although your suggestion is good in terms of avoiding moving venus, I
> think the location of venus was wrong to begin with. There should have
> always been a vcodec (or similar) folder for venus/iris as that will
> establish the boundaries of camss and video sub-system in a cleaner way
>
> I like the mediatek separation that way as it makes the boundaries clear:
>
> drivers/media/platform/mediatek$ ls
> jpeg Kconfig Makefile mdp mdp3 vcodec vpu
>
> So I think that this re-org of venus into a vcodec had to happen at some
> point. Its just that it aligned with iris addition.
Then it should be a clean separate step with its own justification.
>
> >>>
> >>>>
> >>>> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
> >>>> ---
> >>>> drivers/media/platform/qcom/Kconfig | 2 +-
> >>>> drivers/media/platform/qcom/Makefile | 2 +-
> >>>> drivers/media/platform/qcom/vcodec/firmware.c | 147 +++++++++
> >>>> drivers/media/platform/qcom/vcodec/firmware.h | 21 ++
> >>>> .../media/platform/qcom/{ => vcodec}/venus/Kconfig | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/Makefile | 4 +-
> >>>> .../media/platform/qcom/{ => vcodec}/venus/core.c | 102 +++++-
> >>>> .../media/platform/qcom/{ => vcodec}/venus/core.h | 0
> >>>> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.c | 0
> >>>> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.h | 0
> >>>> .../platform/qcom/vcodec/venus/firmware_no_tz.c | 194 +++++++++++
> >>>> .../platform/qcom/vcodec/venus/firmware_no_tz.h | 19 ++
> >>>> .../platform/qcom/{ => vcodec}/venus/helpers.c | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/helpers.h | 0
> >>>> .../media/platform/qcom/{ => vcodec}/venus/hfi.c | 0
> >>>> .../media/platform/qcom/{ => vcodec}/venus/hfi.h | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.c | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.h | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_helper.h | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.c | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.h | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_parser.c | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_parser.h | 0
> >>>> .../qcom/{ => vcodec}/venus/hfi_plat_bufs.h | 0
> >>>> .../qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c | 0
> >>>> .../qcom/{ => vcodec}/venus/hfi_platform.c | 0
> >>>> .../qcom/{ => vcodec}/venus/hfi_platform.h | 0
> >>>> .../qcom/{ => vcodec}/venus/hfi_platform_v4.c | 0
> >>>> .../qcom/{ => vcodec}/venus/hfi_platform_v6.c | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_venus.c | 21 +-
> >>>> .../platform/qcom/{ => vcodec}/venus/hfi_venus.h | 0
> >>>> .../qcom/{ => vcodec}/venus/hfi_venus_io.h | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/pm_helpers.c | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/pm_helpers.h | 0
> >>>> .../media/platform/qcom/{ => vcodec}/venus/vdec.c | 0
> >>>> .../media/platform/qcom/{ => vcodec}/venus/vdec.h | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/vdec_ctrls.c | 0
> >>>> .../media/platform/qcom/{ => vcodec}/venus/venc.c | 0
> >>>> .../media/platform/qcom/{ => vcodec}/venus/venc.h | 0
> >>>> .../platform/qcom/{ => vcodec}/venus/venc_ctrls.c | 0
> >>>> drivers/media/platform/qcom/venus/firmware.c | 363
> >>>> ---------------------
> >>>> drivers/media/platform/qcom/venus/firmware.h | 26 --
> >>>> 42 files changed, 492 insertions(+), 409 deletions(-)
> >>>> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.c
> >>>> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.h
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/Kconfig (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/Makefile (83%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.c (91%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.h (100%)
> >>>> create mode 100644
> >>>> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
> >>>> create mode 100644
> >>>> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_helper.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs.h
> >>>> (100%)
> >>>> rename drivers/media/platform/qcom/{ =>
> >>>> vcodec}/venus/hfi_plat_bufs_v6.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.c
> >>>> (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.h
> >>>> (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v4.c
> >>>> (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v6.c
> >>>> (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.c (99%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus_io.h
> >>>> (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec_ctrls.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.c (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.h (100%)
> >>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc_ctrls.c (100%)
> >>>> delete mode 100644 drivers/media/platform/qcom/venus/firmware.c
> >>>> delete mode 100644 drivers/media/platform/qcom/venus/firmware.h
> >>>>
> >>>> diff --git a/drivers/media/platform/qcom/Kconfig
> >>>> b/drivers/media/platform/qcom/Kconfig
> >>>> index cc5799b..e94142f 100644
> >>>> --- a/drivers/media/platform/qcom/Kconfig
> >>>> +++ b/drivers/media/platform/qcom/Kconfig
> >>>> @@ -3,4 +3,4 @@
> >>>> comment "Qualcomm media platform drivers"
> >>>> source "drivers/media/platform/qcom/camss/Kconfig"
> >>>> -source "drivers/media/platform/qcom/venus/Kconfig"
> >>>> +source "drivers/media/platform/qcom/vcodec/venus/Kconfig"
> >>>> diff --git a/drivers/media/platform/qcom/Makefile
> >>>> b/drivers/media/platform/qcom/Makefile
> >>>> index 4f055c3..3d2d82b 100644
> >>>> --- a/drivers/media/platform/qcom/Makefile
> >>>> +++ b/drivers/media/platform/qcom/Makefile
> >>>> @@ -1,3 +1,3 @@
> >>>> # SPDX-License-Identifier: GPL-2.0-only
> >>>> obj-y += camss/
> >>>> -obj-y += venus/
> >>>> +obj-y += vcodec/venus/
> >>>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.c
> >>>> b/drivers/media/platform/qcom/vcodec/firmware.c
> >>>> new file mode 100644
> >>>> index 0000000..dbc220a
> >>>> --- /dev/null
> >>>> +++ b/drivers/media/platform/qcom/vcodec/firmware.c
> >>>> @@ -0,0 +1,147 @@
> >>>> +// SPDX-License-Identifier: GPL-2.0-only
> >>>> +/*
> >>>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
> >>>> reserved.
> >>>> + */
> >>>> +
> >>>> +#include <linux/device.h>
> >>>> +#include <linux/dma-mapping.h>
> >>>> +#include <linux/firmware.h>
> >>>> +#include <linux/kernel.h>
> >>>> +#include <linux/iommu.h>
> >>>> +#include <linux/of_device.h>
> >>>> +#include <linux/firmware/qcom/qcom_scm.h>
> >>>> +#include <linux/of_reserved_mem.h>
> >>>> +#include <linux/platform_device.h>
> >>>> +#include <linux/soc/qcom/mdt_loader.h>
> >>>> +
> >>>> +#include "firmware.h"
> >>>> +
> >>>> +bool use_tz(struct device *core_dev)
> >>>
> >>> All these functions must get some sane prefix. Otherwise a generic 'use_tz'
> >>> function is too polluting for the global namespace.
> >>>
> >> I understand, will check and do the needful.
> >>>> +{
> >>>> + struct device_node *np;
> >>>> +
> >>>> + np = of_get_child_by_name(core_dev->of_node, "video-firmware");
> >>>> + if (!np)
> >>>> + return true;
> >>>> +
> >>>> + return false;
> >>>> +}
> >>>> +
> >>>> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
> >>>> + u32 cp_nonpixel_size, u32 pas_id)
> >>>> +{
> >>>> + int ret;
> >>>> + /*
> >>>> + * Clues for porting using downstream data:
> >>>> + * cp_start = 0
> >>>> + * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
> >>>> + * This works, as the non-secure context bank is placed
> >>>> + * contiguously right after the Content Protection region.
> >>>> + *
> >>>> + * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
> >>>> + * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
> >>>> + */
> >>>> + ret = qcom_scm_mem_protect_video_var(cp_start,
> >>>> + cp_size,
> >>>> + cp_nonpixel_start,
> >>>> + cp_nonpixel_size);
> >>>> + if (ret)
> >>>> + qcom_scm_pas_shutdown(pas_id);
> >>>> +
> >>>> + return ret;
> >>>> +}
> >>>> +
> >>>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
> >>>> + size_t *mem_size, u32 pas_id, bool use_tz)
> >>>> +{
> >>>> + const struct firmware *firmware = NULL;
> >>>> + struct reserved_mem *rmem;
> >>>> + struct device_node *node;
> >>>> + void *mem_virt = NULL;
> >>>> + ssize_t fw_size = 0;
> >>>> + int ret;
> >>>> +
> >>>> + if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
> >>>
> >>> Why? Can you just depend on it?
> >>>
> >> Sure, Will check this and get back.
> >>>> + (use_tz && !qcom_scm_is_available()))
> >>>> + return -EPROBE_DEFER;
> >>>> +
> >>>> + if (!fw_name || !(*fw_name))
> >>>> + return -EINVAL;
> >>>> +
> >>>> + *mem_phys = 0;
> >>>> + *mem_size = 0;
> >>>> +
> >>>> + node = of_parse_phandle(dev->of_node, "memory-region", 0);
> >>>> + if (!node) {
> >>>> + dev_err(dev, "no memory-region specified\n");
> >>>> + return -EINVAL;
> >>>> + }
> >>>> +
> >>>> + rmem = of_reserved_mem_lookup(node);
> >>>> + of_node_put(node);
> >>>> + if (!rmem) {
> >>>> + dev_err(dev, "failed to lookup reserved memory-region\n");
> >>>> + return -EINVAL;
> >>>> + }
> >>>> +
> >>>> + ret = request_firmware(&firmware, fw_name, dev);
> >>>> + if (ret) {
> >>>> + dev_err(dev, "%s: failed to request fw \"%s\", error %d\n",
> >>>> + __func__, fw_name, ret);
> >>>> + return ret;
> >>>> + }
> >>>> +
> >>>> + fw_size = qcom_mdt_get_size(firmware);
> >>>> + if (fw_size < 0) {
> >>>> + ret = fw_size;
> >>>> + dev_err(dev, "%s: out of bound fw image fw size: %ld\n",
> >>>> + __func__, fw_size);
> >>>> + goto err_release_fw;
> >>>> + }
> >>>> +
> >>>> + *mem_phys = rmem->base;
> >>>> + *mem_size = rmem->size;
> >>>> +
> >>>> + if (*mem_size < fw_size) {
> >>>> + ret = -EINVAL;
> >>>> + goto err_release_fw;
> >>>> + }
> >>>> +
> >>>> + mem_virt = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
> >>>> + if (!mem_virt) {
> >>>> + dev_err(dev, "unable to remap fw memory region %pa size %#zx\n",
> >>>> + mem_phys, *mem_size);
> >>>> + goto err_release_fw;
> >>>> + }
> >>>> +
> >>>> + if (use_tz)
> >>>> + ret = qcom_mdt_load(dev, firmware, fw_name, pas_id, mem_virt,
> >>>> + *mem_phys, *mem_size, NULL);
> >>>> + else
> >>>> + ret = qcom_mdt_load_no_init(dev, firmware, fw_name, pas_id,
> >>>> mem_virt,
> >>>> + *mem_phys, *mem_size, NULL);
> >>>> + if (ret) {
> >>>> + dev_err(dev, "%s: error %d loading fw \"%s\"\n",
> >>>> + __func__, ret, fw_name);
> >>>> + }
> >>>> +
> >>>> + memunmap(mem_virt);
> >>>> +err_release_fw:
> >>>> + release_firmware(firmware);
> >>>> + return ret;
> >>>> +}
> >>>> +
> >>>> +int auth_reset_fw(u32 pas_id)
> >>>> +{
> >>>> + return qcom_scm_pas_auth_and_reset(pas_id);
> >>>> +}
> >>>> +
> >>>> +void unload_fw(u32 pas_id)
> >>>> +{
> >>>> + qcom_scm_pas_shutdown(pas_id);
> >>>> +}
> >>>> +
> >>>> +int set_hw_state(bool resume)
> >>>> +{
> >>>> + return qcom_scm_set_remote_state(resume, 0);
> >>>> +}
> >>>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.h
> >>>> b/drivers/media/platform/qcom/vcodec/firmware.h
> >>>> new file mode 100644
> >>>> index 0000000..7d410a8
> >>>> --- /dev/null
> >>>> +++ b/drivers/media/platform/qcom/vcodec/firmware.h
> >>>> @@ -0,0 +1,21 @@
> >>>> +/* SPDX-License-Identifier: GPL-2.0-only */
> >>>> +/*
> >>>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
> >>>> reserved.
> >>>> + */
> >>>> +
> >>>> +#ifndef _FIRMWARE_H_
> >>>> +#define _FIRMWARE_H_
> >>>> +
> >>>> +#include <linux/device.h>
> >>>> +#include <linux/types.h>
> >>>> +
> >>>> +bool use_tz(struct device *core_dev);
> >>>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
> >>>> + size_t *mem_size, u32 pas_id, bool use_tz);
> >>>> +int auth_reset_fw(u32 pas_id);
> >>>> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
> >>>> + u32 cp_nonpixel_size, u32 pas_id);
> >>>> +void unload_fw(u32 pas_id);
> >>>> +int set_hw_state(bool resume);
> >>>> +
> >>>> +#endif
> >>>> diff --git a/drivers/media/platform/qcom/venus/Kconfig
> >>>> b/drivers/media/platform/qcom/vcodec/venus/Kconfig
> >>>> similarity index 100%
> >>>> rename from drivers/media/platform/qcom/venus/Kconfig
> >>>> rename to drivers/media/platform/qcom/vcodec/venus/Kconfig
> >>>> diff --git a/drivers/media/platform/qcom/venus/Makefile
> >>>> b/drivers/media/platform/qcom/vcodec/venus/Makefile
> >>>> similarity index 83%
> >>>> rename from drivers/media/platform/qcom/venus/Makefile
> >>>> rename to drivers/media/platform/qcom/vcodec/venus/Makefile
> >>>> index 91ee6be..f6f3a88 100644
> >>>> --- a/drivers/media/platform/qcom/venus/Makefile
> >>>> +++ b/drivers/media/platform/qcom/vcodec/venus/Makefile
> >>>> @@ -1,7 +1,9 @@
> >>>> # SPDX-License-Identifier: GPL-2.0
> >>>> # Makefile for Qualcomm Venus driver
> >>>> -venus-core-objs += core.o helpers.o firmware.o \
> >>>> +venus-core-objs += ../firmware.o
> >>>> +
> >>>> +venus-core-objs += core.o helpers.o firmware_no_tz.o \
> >>>> hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
> >>>> hfi_parser.o pm_helpers.o dbgfs.o \
> >>>> hfi_platform.o hfi_platform_v4.o \
> >>>> diff --git a/drivers/media/platform/qcom/venus/core.c
> >>>> b/drivers/media/platform/qcom/vcodec/venus/core.c
> >>>> similarity index 91%
> >>>> rename from drivers/media/platform/qcom/venus/core.c
> >>>> rename to drivers/media/platform/qcom/vcodec/venus/core.c
> >>>> index 9cffe97..56d9a53 100644
> >>>> --- a/drivers/media/platform/qcom/venus/core.c
> >>>> +++ b/drivers/media/platform/qcom/vcodec/venus/core.c
> >>>> @@ -22,7 +22,8 @@
> >>>> #include <media/v4l2-ioctl.h>
> >>>> #include "core.h"
> >>>> -#include "firmware.h"
> >>>> +#include "../firmware.h"
> >>>> +#include "firmware_no_tz.h"
> >>>> #include "pm_helpers.h"
> >>>> #include "hfi_venus_io.h"
> >>>> @@ -86,6 +87,8 @@ static void venus_sys_error_handler(struct
> >>>> work_struct *work)
> >>>> struct venus_core *core =
> >>>> container_of(work, struct venus_core, work.work);
> >>>> int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
> >>>> + const struct venus_resources *res = core->res;
> >>>> + const char *fwpath = NULL;
> >>>> const char *err_msg = "";
> >>>> bool failed = false;
> >>>> @@ -107,7 +110,10 @@ static void venus_sys_error_handler(struct
> >>>> work_struct *work)
> >>>> mutex_lock(&core->lock);
> >>>> - venus_shutdown(core);
> >>>> + if (core->use_tz)
> >>>> + unload_fw(VENUS_PAS_ID);
> >>>> + else
> >>>> + unload_fw_no_tz(core);
> >>>
> >>> This is more than introducing helpers.
> >>>
> >> The new helpers are written to make the code generic for video drivers.
> >> which requires changes in the calling function also.
> >>>> venus_coredump(core);
> >>>> @@ -127,12 +133,39 @@ static void venus_sys_error_handler(struct
> >>>> work_struct *work)
> >>>> failed = true;
> >>>> }
> >>>> - ret = venus_boot(core);
> >>>> + ret = of_property_read_string_index(core->dev->of_node,
> >>>> "firmware-name", 0,
> >>>> + &fwpath);
> >>>> + if (ret)
> >>>> + fwpath = core->res->fwname;
> >>>> +
> >>>> + ret = load_fw(core->dev, fwpath, &core->fw.mem_phys,
> >>>> &core->fw.mem_size,
> >>>> + VENUS_PAS_ID, core->use_tz);
> >>>
> >>> So, we had a nice local 'venus_boot'. Instead we now have a pile of code
> >>> with non-generic prefixes, etc. If you are introducing helpers, please
> >>> refrain from inlining of calling functions, etc. Just move the code to your
> >>> helpers.
> >>>
> >> As mentioned in above comment, the common helpers are written to make the
> >> code generic. I Will try to make it more clear, working on the same.
> >
> > First, you move the code, then you make it generic. Or vice versa.
> > First you split the code, then you move it. Don't do both in the same
> > patch.
> >
> >>> NAK for the rest of the patch.
> >
> >
On 12/20/2023 12:56 PM, Dmitry Baryshkov wrote:
> Hi Abhinav,
>
> On Wed, 20 Dec 2023 at 19:10, Abhinav Kumar <quic_abhinavk@quicinc.com> wrote:
>>
>> Hi Dmitry
>>
>> On 12/20/2023 12:12 AM, Dmitry Baryshkov wrote:
>>> On Wed, 20 Dec 2023 at 10:01, Dikshita Agarwal
>>> <quic_dikshita@quicinc.com> wrote:
>>>>
>>>>
>>>>
>>>> On 12/18/2023 11:54 PM, Dmitry Baryshkov wrote:
>>>>> On 18/12/2023 13:31, Dikshita Agarwal wrote:
>>>>>> Re-organize the video driver code by introducing a new folder
>>>>>> 'vcodec' and placing 'venus' driver code inside that.
>>>>>>
>>>>>> Introduce common helpers for trustzone based firmware
>>>>>> load/unload etc. which are placed in common folder
>>>>>> i.e. 'vcodec'.
>>>>>> Use these helpers in 'venus' driver. These helpers will be
>>>>>> used by 'iris' driver as well which is introduced later
>>>>>> in this patch series.
>>>>>
>>>>> But why do you need to move the venus driver to subdir?
>>>>
>>>> Currently venus driver is present in drivers/media/platform/qcom folder
>>>> which also has camss folder. We introduced vcodec to keep common code and
>>>> moved venus inside that, to indicate that the common code is for vcodec
>>>> drivers i.e venus and iris. Keeping this in qcom folder would mean, common
>>>> code will be used for camss only which is not the case here.
>>>
>>> you can have .../platform/qcom/camss, .../platform/qcom/vcodec-common,
>>> .../platform/qcom/venus and .../platform/qcom/iris.
>>>
>>> If you were to use build helpers in a proper kernel module, this would
>>> be more obvious.
>>>
>>
>> Although your suggestion is good in terms of avoiding moving venus, I
>> think the location of venus was wrong to begin with. There should have
>> always been a vcodec (or similar) folder for venus/iris as that will
>> establish the boundaries of camss and video sub-system in a cleaner way
>>
>> I like the mediatek separation that way as it makes the boundaries clear:
>>
>> drivers/media/platform/mediatek$ ls
>> jpeg Kconfig Makefile mdp mdp3 vcodec vpu
>>
>> So I think that this re-org of venus into a vcodec had to happen at some
>> point. Its just that it aligned with iris addition.
>
> Then it should be a clean separate step with its own justification.
>
Yes, I am fine with this first going as a separate series to move venus
into vcodec and anyway there was a separate request to make patches 1-3
into another series from Bryan.
So this can first be posted separately.
>>
>>>>>
>>>>>>
>>>>>> Signed-off-by: Dikshita Agarwal <quic_dikshita@quicinc.com>
>>>>>> ---
>>>>>> drivers/media/platform/qcom/Kconfig | 2 +-
>>>>>> drivers/media/platform/qcom/Makefile | 2 +-
>>>>>> drivers/media/platform/qcom/vcodec/firmware.c | 147 +++++++++
>>>>>> drivers/media/platform/qcom/vcodec/firmware.h | 21 ++
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/Kconfig | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/Makefile | 4 +-
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/core.c | 102 +++++-
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/core.h | 0
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.c | 0
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/dbgfs.h | 0
>>>>>> .../platform/qcom/vcodec/venus/firmware_no_tz.c | 194 +++++++++++
>>>>>> .../platform/qcom/vcodec/venus/firmware_no_tz.h | 19 ++
>>>>>> .../platform/qcom/{ => vcodec}/venus/helpers.c | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/helpers.h | 0
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/hfi.c | 0
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/hfi.h | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.c | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_cmds.h | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_helper.h | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.c | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_msgs.h | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_parser.c | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_parser.h | 0
>>>>>> .../qcom/{ => vcodec}/venus/hfi_plat_bufs.h | 0
>>>>>> .../qcom/{ => vcodec}/venus/hfi_plat_bufs_v6.c | 0
>>>>>> .../qcom/{ => vcodec}/venus/hfi_platform.c | 0
>>>>>> .../qcom/{ => vcodec}/venus/hfi_platform.h | 0
>>>>>> .../qcom/{ => vcodec}/venus/hfi_platform_v4.c | 0
>>>>>> .../qcom/{ => vcodec}/venus/hfi_platform_v6.c | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_venus.c | 21 +-
>>>>>> .../platform/qcom/{ => vcodec}/venus/hfi_venus.h | 0
>>>>>> .../qcom/{ => vcodec}/venus/hfi_venus_io.h | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/pm_helpers.c | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/pm_helpers.h | 0
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/vdec.c | 0
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/vdec.h | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/vdec_ctrls.c | 0
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/venc.c | 0
>>>>>> .../media/platform/qcom/{ => vcodec}/venus/venc.h | 0
>>>>>> .../platform/qcom/{ => vcodec}/venus/venc_ctrls.c | 0
>>>>>> drivers/media/platform/qcom/venus/firmware.c | 363
>>>>>> ---------------------
>>>>>> drivers/media/platform/qcom/venus/firmware.h | 26 --
>>>>>> 42 files changed, 492 insertions(+), 409 deletions(-)
>>>>>> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.c
>>>>>> create mode 100644 drivers/media/platform/qcom/vcodec/firmware.h
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/Kconfig (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/Makefile (83%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.c (91%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/core.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/dbgfs.h (100%)
>>>>>> create mode 100644
>>>>>> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.c
>>>>>> create mode 100644
>>>>>> drivers/media/platform/qcom/vcodec/venus/firmware_no_tz.h
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/helpers.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_cmds.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_helper.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_msgs.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_parser.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_plat_bufs.h
>>>>>> (100%)
>>>>>> rename drivers/media/platform/qcom/{ =>
>>>>>> vcodec}/venus/hfi_plat_bufs_v6.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.c
>>>>>> (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform.h
>>>>>> (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v4.c
>>>>>> (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_platform_v6.c
>>>>>> (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.c (99%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/hfi_venus_io.h
>>>>>> (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/pm_helpers.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/vdec_ctrls.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.c (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc.h (100%)
>>>>>> rename drivers/media/platform/qcom/{ => vcodec}/venus/venc_ctrls.c (100%)
>>>>>> delete mode 100644 drivers/media/platform/qcom/venus/firmware.c
>>>>>> delete mode 100644 drivers/media/platform/qcom/venus/firmware.h
>>>>>>
>>>>>> diff --git a/drivers/media/platform/qcom/Kconfig
>>>>>> b/drivers/media/platform/qcom/Kconfig
>>>>>> index cc5799b..e94142f 100644
>>>>>> --- a/drivers/media/platform/qcom/Kconfig
>>>>>> +++ b/drivers/media/platform/qcom/Kconfig
>>>>>> @@ -3,4 +3,4 @@
>>>>>> comment "Qualcomm media platform drivers"
>>>>>> source "drivers/media/platform/qcom/camss/Kconfig"
>>>>>> -source "drivers/media/platform/qcom/venus/Kconfig"
>>>>>> +source "drivers/media/platform/qcom/vcodec/venus/Kconfig"
>>>>>> diff --git a/drivers/media/platform/qcom/Makefile
>>>>>> b/drivers/media/platform/qcom/Makefile
>>>>>> index 4f055c3..3d2d82b 100644
>>>>>> --- a/drivers/media/platform/qcom/Makefile
>>>>>> +++ b/drivers/media/platform/qcom/Makefile
>>>>>> @@ -1,3 +1,3 @@
>>>>>> # SPDX-License-Identifier: GPL-2.0-only
>>>>>> obj-y += camss/
>>>>>> -obj-y += venus/
>>>>>> +obj-y += vcodec/venus/
>>>>>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.c
>>>>>> b/drivers/media/platform/qcom/vcodec/firmware.c
>>>>>> new file mode 100644
>>>>>> index 0000000..dbc220a
>>>>>> --- /dev/null
>>>>>> +++ b/drivers/media/platform/qcom/vcodec/firmware.c
>>>>>> @@ -0,0 +1,147 @@
>>>>>> +// SPDX-License-Identifier: GPL-2.0-only
>>>>>> +/*
>>>>>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
>>>>>> reserved.
>>>>>> + */
>>>>>> +
>>>>>> +#include <linux/device.h>
>>>>>> +#include <linux/dma-mapping.h>
>>>>>> +#include <linux/firmware.h>
>>>>>> +#include <linux/kernel.h>
>>>>>> +#include <linux/iommu.h>
>>>>>> +#include <linux/of_device.h>
>>>>>> +#include <linux/firmware/qcom/qcom_scm.h>
>>>>>> +#include <linux/of_reserved_mem.h>
>>>>>> +#include <linux/platform_device.h>
>>>>>> +#include <linux/soc/qcom/mdt_loader.h>
>>>>>> +
>>>>>> +#include "firmware.h"
>>>>>> +
>>>>>> +bool use_tz(struct device *core_dev)
>>>>>
>>>>> All these functions must get some sane prefix. Otherwise a generic 'use_tz'
>>>>> function is too polluting for the global namespace.
>>>>>
>>>> I understand, will check and do the needful.
>>>>>> +{
>>>>>> + struct device_node *np;
>>>>>> +
>>>>>> + np = of_get_child_by_name(core_dev->of_node, "video-firmware");
>>>>>> + if (!np)
>>>>>> + return true;
>>>>>> +
>>>>>> + return false;
>>>>>> +}
>>>>>> +
>>>>>> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
>>>>>> + u32 cp_nonpixel_size, u32 pas_id)
>>>>>> +{
>>>>>> + int ret;
>>>>>> + /*
>>>>>> + * Clues for porting using downstream data:
>>>>>> + * cp_start = 0
>>>>>> + * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
>>>>>> + * This works, as the non-secure context bank is placed
>>>>>> + * contiguously right after the Content Protection region.
>>>>>> + *
>>>>>> + * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
>>>>>> + * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
>>>>>> + */
>>>>>> + ret = qcom_scm_mem_protect_video_var(cp_start,
>>>>>> + cp_size,
>>>>>> + cp_nonpixel_start,
>>>>>> + cp_nonpixel_size);
>>>>>> + if (ret)
>>>>>> + qcom_scm_pas_shutdown(pas_id);
>>>>>> +
>>>>>> + return ret;
>>>>>> +}
>>>>>> +
>>>>>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
>>>>>> + size_t *mem_size, u32 pas_id, bool use_tz)
>>>>>> +{
>>>>>> + const struct firmware *firmware = NULL;
>>>>>> + struct reserved_mem *rmem;
>>>>>> + struct device_node *node;
>>>>>> + void *mem_virt = NULL;
>>>>>> + ssize_t fw_size = 0;
>>>>>> + int ret;
>>>>>> +
>>>>>> + if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
>>>>>
>>>>> Why? Can you just depend on it?
>>>>>
>>>> Sure, Will check this and get back.
>>>>>> + (use_tz && !qcom_scm_is_available()))
>>>>>> + return -EPROBE_DEFER;
>>>>>> +
>>>>>> + if (!fw_name || !(*fw_name))
>>>>>> + return -EINVAL;
>>>>>> +
>>>>>> + *mem_phys = 0;
>>>>>> + *mem_size = 0;
>>>>>> +
>>>>>> + node = of_parse_phandle(dev->of_node, "memory-region", 0);
>>>>>> + if (!node) {
>>>>>> + dev_err(dev, "no memory-region specified\n");
>>>>>> + return -EINVAL;
>>>>>> + }
>>>>>> +
>>>>>> + rmem = of_reserved_mem_lookup(node);
>>>>>> + of_node_put(node);
>>>>>> + if (!rmem) {
>>>>>> + dev_err(dev, "failed to lookup reserved memory-region\n");
>>>>>> + return -EINVAL;
>>>>>> + }
>>>>>> +
>>>>>> + ret = request_firmware(&firmware, fw_name, dev);
>>>>>> + if (ret) {
>>>>>> + dev_err(dev, "%s: failed to request fw \"%s\", error %d\n",
>>>>>> + __func__, fw_name, ret);
>>>>>> + return ret;
>>>>>> + }
>>>>>> +
>>>>>> + fw_size = qcom_mdt_get_size(firmware);
>>>>>> + if (fw_size < 0) {
>>>>>> + ret = fw_size;
>>>>>> + dev_err(dev, "%s: out of bound fw image fw size: %ld\n",
>>>>>> + __func__, fw_size);
>>>>>> + goto err_release_fw;
>>>>>> + }
>>>>>> +
>>>>>> + *mem_phys = rmem->base;
>>>>>> + *mem_size = rmem->size;
>>>>>> +
>>>>>> + if (*mem_size < fw_size) {
>>>>>> + ret = -EINVAL;
>>>>>> + goto err_release_fw;
>>>>>> + }
>>>>>> +
>>>>>> + mem_virt = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
>>>>>> + if (!mem_virt) {
>>>>>> + dev_err(dev, "unable to remap fw memory region %pa size %#zx\n",
>>>>>> + mem_phys, *mem_size);
>>>>>> + goto err_release_fw;
>>>>>> + }
>>>>>> +
>>>>>> + if (use_tz)
>>>>>> + ret = qcom_mdt_load(dev, firmware, fw_name, pas_id, mem_virt,
>>>>>> + *mem_phys, *mem_size, NULL);
>>>>>> + else
>>>>>> + ret = qcom_mdt_load_no_init(dev, firmware, fw_name, pas_id,
>>>>>> mem_virt,
>>>>>> + *mem_phys, *mem_size, NULL);
>>>>>> + if (ret) {
>>>>>> + dev_err(dev, "%s: error %d loading fw \"%s\"\n",
>>>>>> + __func__, ret, fw_name);
>>>>>> + }
>>>>>> +
>>>>>> + memunmap(mem_virt);
>>>>>> +err_release_fw:
>>>>>> + release_firmware(firmware);
>>>>>> + return ret;
>>>>>> +}
>>>>>> +
>>>>>> +int auth_reset_fw(u32 pas_id)
>>>>>> +{
>>>>>> + return qcom_scm_pas_auth_and_reset(pas_id);
>>>>>> +}
>>>>>> +
>>>>>> +void unload_fw(u32 pas_id)
>>>>>> +{
>>>>>> + qcom_scm_pas_shutdown(pas_id);
>>>>>> +}
>>>>>> +
>>>>>> +int set_hw_state(bool resume)
>>>>>> +{
>>>>>> + return qcom_scm_set_remote_state(resume, 0);
>>>>>> +}
>>>>>> diff --git a/drivers/media/platform/qcom/vcodec/firmware.h
>>>>>> b/drivers/media/platform/qcom/vcodec/firmware.h
>>>>>> new file mode 100644
>>>>>> index 0000000..7d410a8
>>>>>> --- /dev/null
>>>>>> +++ b/drivers/media/platform/qcom/vcodec/firmware.h
>>>>>> @@ -0,0 +1,21 @@
>>>>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>>>>> +/*
>>>>>> + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights
>>>>>> reserved.
>>>>>> + */
>>>>>> +
>>>>>> +#ifndef _FIRMWARE_H_
>>>>>> +#define _FIRMWARE_H_
>>>>>> +
>>>>>> +#include <linux/device.h>
>>>>>> +#include <linux/types.h>
>>>>>> +
>>>>>> +bool use_tz(struct device *core_dev);
>>>>>> +int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
>>>>>> + size_t *mem_size, u32 pas_id, bool use_tz);
>>>>>> +int auth_reset_fw(u32 pas_id);
>>>>>> +int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
>>>>>> + u32 cp_nonpixel_size, u32 pas_id);
>>>>>> +void unload_fw(u32 pas_id);
>>>>>> +int set_hw_state(bool resume);
>>>>>> +
>>>>>> +#endif
>>>>>> diff --git a/drivers/media/platform/qcom/venus/Kconfig
>>>>>> b/drivers/media/platform/qcom/vcodec/venus/Kconfig
>>>>>> similarity index 100%
>>>>>> rename from drivers/media/platform/qcom/venus/Kconfig
>>>>>> rename to drivers/media/platform/qcom/vcodec/venus/Kconfig
>>>>>> diff --git a/drivers/media/platform/qcom/venus/Makefile
>>>>>> b/drivers/media/platform/qcom/vcodec/venus/Makefile
>>>>>> similarity index 83%
>>>>>> rename from drivers/media/platform/qcom/venus/Makefile
>>>>>> rename to drivers/media/platform/qcom/vcodec/venus/Makefile
>>>>>> index 91ee6be..f6f3a88 100644
>>>>>> --- a/drivers/media/platform/qcom/venus/Makefile
>>>>>> +++ b/drivers/media/platform/qcom/vcodec/venus/Makefile
>>>>>> @@ -1,7 +1,9 @@
>>>>>> # SPDX-License-Identifier: GPL-2.0
>>>>>> # Makefile for Qualcomm Venus driver
>>>>>> -venus-core-objs += core.o helpers.o firmware.o \
>>>>>> +venus-core-objs += ../firmware.o
>>>>>> +
>>>>>> +venus-core-objs += core.o helpers.o firmware_no_tz.o \
>>>>>> hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
>>>>>> hfi_parser.o pm_helpers.o dbgfs.o \
>>>>>> hfi_platform.o hfi_platform_v4.o \
>>>>>> diff --git a/drivers/media/platform/qcom/venus/core.c
>>>>>> b/drivers/media/platform/qcom/vcodec/venus/core.c
>>>>>> similarity index 91%
>>>>>> rename from drivers/media/platform/qcom/venus/core.c
>>>>>> rename to drivers/media/platform/qcom/vcodec/venus/core.c
>>>>>> index 9cffe97..56d9a53 100644
>>>>>> --- a/drivers/media/platform/qcom/venus/core.c
>>>>>> +++ b/drivers/media/platform/qcom/vcodec/venus/core.c
>>>>>> @@ -22,7 +22,8 @@
>>>>>> #include <media/v4l2-ioctl.h>
>>>>>> #include "core.h"
>>>>>> -#include "firmware.h"
>>>>>> +#include "../firmware.h"
>>>>>> +#include "firmware_no_tz.h"
>>>>>> #include "pm_helpers.h"
>>>>>> #include "hfi_venus_io.h"
>>>>>> @@ -86,6 +87,8 @@ static void venus_sys_error_handler(struct
>>>>>> work_struct *work)
>>>>>> struct venus_core *core =
>>>>>> container_of(work, struct venus_core, work.work);
>>>>>> int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
>>>>>> + const struct venus_resources *res = core->res;
>>>>>> + const char *fwpath = NULL;
>>>>>> const char *err_msg = "";
>>>>>> bool failed = false;
>>>>>> @@ -107,7 +110,10 @@ static void venus_sys_error_handler(struct
>>>>>> work_struct *work)
>>>>>> mutex_lock(&core->lock);
>>>>>> - venus_shutdown(core);
>>>>>> + if (core->use_tz)
>>>>>> + unload_fw(VENUS_PAS_ID);
>>>>>> + else
>>>>>> + unload_fw_no_tz(core);
>>>>>
>>>>> This is more than introducing helpers.
>>>>>
>>>> The new helpers are written to make the code generic for video drivers.
>>>> which requires changes in the calling function also.
>>>>>> venus_coredump(core);
>>>>>> @@ -127,12 +133,39 @@ static void venus_sys_error_handler(struct
>>>>>> work_struct *work)
>>>>>> failed = true;
>>>>>> }
>>>>>> - ret = venus_boot(core);
>>>>>> + ret = of_property_read_string_index(core->dev->of_node,
>>>>>> "firmware-name", 0,
>>>>>> + &fwpath);
>>>>>> + if (ret)
>>>>>> + fwpath = core->res->fwname;
>>>>>> +
>>>>>> + ret = load_fw(core->dev, fwpath, &core->fw.mem_phys,
>>>>>> &core->fw.mem_size,
>>>>>> + VENUS_PAS_ID, core->use_tz);
>>>>>
>>>>> So, we had a nice local 'venus_boot'. Instead we now have a pile of code
>>>>> with non-generic prefixes, etc. If you are introducing helpers, please
>>>>> refrain from inlining of calling functions, etc. Just move the code to your
>>>>> helpers.
>>>>>
>>>> As mentioned in above comment, the common helpers are written to make the
>>>> code generic. I Will try to make it more clear, working on the same.
>>>
>>> First, you move the code, then you make it generic. Or vice versa.
>>> First you split the code, then you move it. Don't do both in the same
>>> patch.
>>>
>>>>> NAK for the rest of the patch.
>>>
>>>
>
>
>
@@ -3,4 +3,4 @@
comment "Qualcomm media platform drivers"
source "drivers/media/platform/qcom/camss/Kconfig"
-source "drivers/media/platform/qcom/venus/Kconfig"
+source "drivers/media/platform/qcom/vcodec/venus/Kconfig"
@@ -1,3 +1,3 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-y += camss/
-obj-y += venus/
+obj-y += vcodec/venus/
new file mode 100644
@@ -0,0 +1,147 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/firmware.h>
+#include <linux/kernel.h>
+#include <linux/iommu.h>
+#include <linux/of_device.h>
+#include <linux/firmware/qcom/qcom_scm.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/platform_device.h>
+#include <linux/soc/qcom/mdt_loader.h>
+
+#include "firmware.h"
+
+bool use_tz(struct device *core_dev)
+{
+ struct device_node *np;
+
+ np = of_get_child_by_name(core_dev->of_node, "video-firmware");
+ if (!np)
+ return true;
+
+ return false;
+}
+
+int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
+ u32 cp_nonpixel_size, u32 pas_id)
+{
+ int ret;
+ /*
+ * Clues for porting using downstream data:
+ * cp_start = 0
+ * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
+ * This works, as the non-secure context bank is placed
+ * contiguously right after the Content Protection region.
+ *
+ * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
+ * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
+ */
+ ret = qcom_scm_mem_protect_video_var(cp_start,
+ cp_size,
+ cp_nonpixel_start,
+ cp_nonpixel_size);
+ if (ret)
+ qcom_scm_pas_shutdown(pas_id);
+
+ return ret;
+}
+
+int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
+ size_t *mem_size, u32 pas_id, bool use_tz)
+{
+ const struct firmware *firmware = NULL;
+ struct reserved_mem *rmem;
+ struct device_node *node;
+ void *mem_virt = NULL;
+ ssize_t fw_size = 0;
+ int ret;
+
+ if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
+ (use_tz && !qcom_scm_is_available()))
+ return -EPROBE_DEFER;
+
+ if (!fw_name || !(*fw_name))
+ return -EINVAL;
+
+ *mem_phys = 0;
+ *mem_size = 0;
+
+ node = of_parse_phandle(dev->of_node, "memory-region", 0);
+ if (!node) {
+ dev_err(dev, "no memory-region specified\n");
+ return -EINVAL;
+ }
+
+ rmem = of_reserved_mem_lookup(node);
+ of_node_put(node);
+ if (!rmem) {
+ dev_err(dev, "failed to lookup reserved memory-region\n");
+ return -EINVAL;
+ }
+
+ ret = request_firmware(&firmware, fw_name, dev);
+ if (ret) {
+ dev_err(dev, "%s: failed to request fw \"%s\", error %d\n",
+ __func__, fw_name, ret);
+ return ret;
+ }
+
+ fw_size = qcom_mdt_get_size(firmware);
+ if (fw_size < 0) {
+ ret = fw_size;
+ dev_err(dev, "%s: out of bound fw image fw size: %ld\n",
+ __func__, fw_size);
+ goto err_release_fw;
+ }
+
+ *mem_phys = rmem->base;
+ *mem_size = rmem->size;
+
+ if (*mem_size < fw_size) {
+ ret = -EINVAL;
+ goto err_release_fw;
+ }
+
+ mem_virt = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
+ if (!mem_virt) {
+ dev_err(dev, "unable to remap fw memory region %pa size %#zx\n",
+ mem_phys, *mem_size);
+ goto err_release_fw;
+ }
+
+ if (use_tz)
+ ret = qcom_mdt_load(dev, firmware, fw_name, pas_id, mem_virt,
+ *mem_phys, *mem_size, NULL);
+ else
+ ret = qcom_mdt_load_no_init(dev, firmware, fw_name, pas_id, mem_virt,
+ *mem_phys, *mem_size, NULL);
+ if (ret) {
+ dev_err(dev, "%s: error %d loading fw \"%s\"\n",
+ __func__, ret, fw_name);
+ }
+
+ memunmap(mem_virt);
+err_release_fw:
+ release_firmware(firmware);
+ return ret;
+}
+
+int auth_reset_fw(u32 pas_id)
+{
+ return qcom_scm_pas_auth_and_reset(pas_id);
+}
+
+void unload_fw(u32 pas_id)
+{
+ qcom_scm_pas_shutdown(pas_id);
+}
+
+int set_hw_state(bool resume)
+{
+ return qcom_scm_set_remote_state(resume, 0);
+}
new file mode 100644
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#ifndef _FIRMWARE_H_
+#define _FIRMWARE_H_
+
+#include <linux/device.h>
+#include <linux/types.h>
+
+bool use_tz(struct device *core_dev);
+int load_fw(struct device *dev, const char *fw_name, phys_addr_t *mem_phys,
+ size_t *mem_size, u32 pas_id, bool use_tz);
+int auth_reset_fw(u32 pas_id);
+int protect_secure_region(u32 cp_start, u32 cp_size, u32 cp_nonpixel_start,
+ u32 cp_nonpixel_size, u32 pas_id);
+void unload_fw(u32 pas_id);
+int set_hw_state(bool resume);
+
+#endif
similarity index 100%
rename from drivers/media/platform/qcom/venus/Kconfig
rename to drivers/media/platform/qcom/vcodec/venus/Kconfig
similarity index 83%
rename from drivers/media/platform/qcom/venus/Makefile
rename to drivers/media/platform/qcom/vcodec/venus/Makefile
@@ -1,7 +1,9 @@
# SPDX-License-Identifier: GPL-2.0
# Makefile for Qualcomm Venus driver
-venus-core-objs += core.o helpers.o firmware.o \
+venus-core-objs += ../firmware.o
+
+venus-core-objs += core.o helpers.o firmware_no_tz.o \
hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
hfi_parser.o pm_helpers.o dbgfs.o \
hfi_platform.o hfi_platform_v4.o \
similarity index 91%
rename from drivers/media/platform/qcom/venus/core.c
rename to drivers/media/platform/qcom/vcodec/venus/core.c
@@ -22,7 +22,8 @@
#include <media/v4l2-ioctl.h>
#include "core.h"
-#include "firmware.h"
+#include "../firmware.h"
+#include "firmware_no_tz.h"
#include "pm_helpers.h"
#include "hfi_venus_io.h"
@@ -86,6 +87,8 @@ static void venus_sys_error_handler(struct work_struct *work)
struct venus_core *core =
container_of(work, struct venus_core, work.work);
int ret, i, max_attempts = RPM_WAIT_FOR_IDLE_MAX_ATTEMPTS;
+ const struct venus_resources *res = core->res;
+ const char *fwpath = NULL;
const char *err_msg = "";
bool failed = false;
@@ -107,7 +110,10 @@ static void venus_sys_error_handler(struct work_struct *work)
mutex_lock(&core->lock);
- venus_shutdown(core);
+ if (core->use_tz)
+ unload_fw(VENUS_PAS_ID);
+ else
+ unload_fw_no_tz(core);
venus_coredump(core);
@@ -127,12 +133,39 @@ static void venus_sys_error_handler(struct work_struct *work)
failed = true;
}
- ret = venus_boot(core);
+ ret = of_property_read_string_index(core->dev->of_node, "firmware-name", 0,
+ &fwpath);
+ if (ret)
+ fwpath = core->res->fwname;
+
+ ret = load_fw(core->dev, fwpath, &core->fw.mem_phys, &core->fw.mem_size,
+ VENUS_PAS_ID, core->use_tz);
if (ret && !failed) {
- err_msg = "boot Venus";
+ err_msg = "load FW";
failed = true;
}
+ if (core->use_tz)
+ ret = auth_reset_fw(VENUS_PAS_ID);
+ else
+ ret = auth_reset_fw_no_tz(core, core->fw.mem_phys, core->fw.mem_size);
+ if (ret && !failed) {
+ err_msg = "Auth and Reset";
+ failed = true;
+ }
+
+ if (core->use_tz && res->cp_size) {
+ ret = protect_secure_region(res->cp_start,
+ res->cp_size,
+ res->cp_nonpixel_start,
+ res->cp_nonpixel_size,
+ VENUS_PAS_ID);
+ if (ret && !failed) {
+ err_msg = "Protect CP Mem";
+ failed = true;
+ }
+ }
+
ret = hfi_core_resume(core, true);
if (ret && !failed) {
err_msg = "resume HFI";
@@ -281,7 +314,9 @@ static irqreturn_t venus_isr_thread(int irq, void *dev_id)
static int venus_probe(struct platform_device *pdev)
{
+ const struct venus_resources *res;
struct device *dev = &pdev->dev;
+ const char *fwpath = NULL;
struct venus_core *core;
int ret;
@@ -362,14 +397,42 @@ static int venus_probe(struct platform_device *pdev)
if (ret)
goto err_runtime_disable;
- ret = venus_firmware_init(core);
+ core->use_tz = use_tz(core->dev);
+
+ if (!core->use_tz) {
+ ret = init_fw_no_tz(core);
+ if (ret)
+ goto err_of_depopulate;
+ }
+
+ ret = of_property_read_string_index(dev->of_node, "firmware-name", 0,
+ &fwpath);
if (ret)
- goto err_of_depopulate;
+ fwpath = core->res->fwname;
- ret = venus_boot(core);
+ ret = load_fw(core->dev, fwpath, &core->fw.mem_phys, &core->fw.mem_size,
+ VENUS_PAS_ID, core->use_tz);
if (ret)
goto err_firmware_deinit;
+ if (core->use_tz)
+ ret = auth_reset_fw(VENUS_PAS_ID);
+ else
+ ret = auth_reset_fw_no_tz(core, core->fw.mem_phys, core->fw.mem_size);
+ if (ret)
+ goto err_firmware_deinit;
+
+ res = core->res;
+ if (core->use_tz && res->cp_size) {
+ ret = protect_secure_region(res->cp_start,
+ res->cp_size,
+ res->cp_nonpixel_start,
+ res->cp_nonpixel_size,
+ VENUS_PAS_ID);
+ if (ret)
+ goto err_firmware_deinit;
+ }
+
ret = hfi_core_resume(core, true);
if (ret)
goto err_venus_shutdown;
@@ -399,9 +462,13 @@ static int venus_probe(struct platform_device *pdev)
err_dev_unregister:
v4l2_device_unregister(&core->v4l2_dev);
err_venus_shutdown:
- venus_shutdown(core);
+ if (core->use_tz)
+ unload_fw(VENUS_PAS_ID);
+ else
+ unload_fw_no_tz(core);
err_firmware_deinit:
- venus_firmware_deinit(core);
+ if (!core->use_tz)
+ deinit_fw_no_tz(core);
err_of_depopulate:
of_platform_depopulate(dev);
err_runtime_disable:
@@ -430,10 +497,15 @@ static void venus_remove(struct platform_device *pdev)
ret = hfi_core_deinit(core, true);
WARN_ON(ret);
- venus_shutdown(core);
+ if (core->use_tz)
+ unload_fw(VENUS_PAS_ID);
+ else
+ unload_fw_no_tz(core);
+
of_platform_depopulate(dev);
- venus_firmware_deinit(core);
+ if (!core->use_tz)
+ deinit_fw_no_tz(core);
pm_runtime_put_sync(dev);
pm_runtime_disable(dev);
@@ -455,8 +527,12 @@ static void venus_core_shutdown(struct platform_device *pdev)
struct venus_core *core = platform_get_drvdata(pdev);
pm_runtime_get_sync(core->dev);
- venus_shutdown(core);
- venus_firmware_deinit(core);
+ if (core->use_tz) {
+ unload_fw(VENUS_PAS_ID);
+ } else {
+ unload_fw_no_tz(core);
+ deinit_fw_no_tz(core);
+ }
pm_runtime_put_sync(core->dev);
}
similarity index 100%
rename from drivers/media/platform/qcom/venus/core.h
rename to drivers/media/platform/qcom/vcodec/venus/core.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/dbgfs.c
rename to drivers/media/platform/qcom/vcodec/venus/dbgfs.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/dbgfs.h
rename to drivers/media/platform/qcom/vcodec/venus/dbgfs.h
new file mode 100644
@@ -0,0 +1,194 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017 Linaro Ltd.
+ */
+
+#include <linux/iommu.h>
+#include <linux/of_device.h>
+#include "core.h"
+#include "firmware_no_tz.h"
+#include "hfi_venus_io.h"
+
+#define VENUS_FW_MEM_SIZE (6 * SZ_1M)
+#define VENUS_FW_START_ADDR 0x0
+
+int init_fw_no_tz(struct venus_core *core)
+{
+ struct platform_device_info info;
+ struct iommu_domain *iommu_dom;
+ struct platform_device *pdev;
+ struct device_node *np;
+ int ret;
+
+ np = of_get_child_by_name(core->dev->of_node, "video-firmware");
+
+ memset(&info, 0, sizeof(info));
+ info.fwnode = &np->fwnode;
+ info.parent = core->dev;
+ info.name = np->name;
+ info.dma_mask = DMA_BIT_MASK(32);
+
+ pdev = platform_device_register_full(&info);
+ if (IS_ERR(pdev)) {
+ of_node_put(np);
+ return PTR_ERR(pdev);
+ }
+
+ pdev->dev.of_node = np;
+
+ ret = of_dma_configure(&pdev->dev, np, true);
+ if (ret) {
+ dev_err(core->dev, "dma configure fail\n");
+ goto err_unregister;
+ }
+
+ core->fw.dev = &pdev->dev;
+
+ iommu_dom = iommu_domain_alloc(&platform_bus_type);
+ if (!iommu_dom) {
+ dev_err(core->fw.dev, "Failed to allocate iommu domain\n");
+ ret = -ENOMEM;
+ goto err_unregister;
+ }
+
+ ret = iommu_attach_device(iommu_dom, core->fw.dev);
+ if (ret) {
+ dev_err(core->fw.dev, "could not attach device\n");
+ goto err_iommu_free;
+ }
+
+ core->fw.iommu_domain = iommu_dom;
+
+ of_node_put(np);
+
+ return 0;
+
+err_iommu_free:
+ iommu_domain_free(iommu_dom);
+err_unregister:
+ platform_device_unregister(pdev);
+ of_node_put(np);
+ return ret;
+}
+
+void deinit_fw_no_tz(struct venus_core *core)
+{
+ struct iommu_domain *iommu;
+
+ if (!core->fw.dev)
+ return;
+
+ iommu = core->fw.iommu_domain;
+
+ iommu_detach_device(iommu, core->fw.dev);
+
+ if (iommu) {
+ iommu_domain_free(iommu);
+ iommu = NULL;
+ }
+
+ platform_device_unregister(to_platform_device(core->fw.dev));
+}
+
+static void reset_cpu_no_tz(struct venus_core *core)
+{
+ u32 fw_size = core->fw.mapped_mem_size;
+ void __iomem *wrapper_base;
+
+ if (IS_IRIS2_1(core))
+ wrapper_base = core->wrapper_tz_base;
+ else
+ wrapper_base = core->wrapper_base;
+
+ writel(0, wrapper_base + WRAPPER_FW_START_ADDR);
+ writel(fw_size, wrapper_base + WRAPPER_FW_END_ADDR);
+ writel(0, wrapper_base + WRAPPER_CPA_START_ADDR);
+ writel(fw_size, wrapper_base + WRAPPER_CPA_END_ADDR);
+ writel(fw_size, wrapper_base + WRAPPER_NONPIX_START_ADDR);
+ writel(fw_size, wrapper_base + WRAPPER_NONPIX_END_ADDR);
+
+ if (IS_IRIS2_1(core)) {
+ /* Bring XTSS out of reset */
+ writel(0, wrapper_base + WRAPPER_TZ_XTSS_SW_RESET);
+ } else {
+ writel(0x0, wrapper_base + WRAPPER_CPU_CGC_DIS);
+ writel(0x0, wrapper_base + WRAPPER_CPU_CLOCK_CONFIG);
+
+ /* Bring ARM9 out of reset */
+ writel(0, wrapper_base + WRAPPER_A9SS_SW_RESET);
+ }
+}
+
+void set_hw_state_no_tz(struct venus_core *core, bool resume)
+{
+ if (resume) {
+ reset_cpu_no_tz(core);
+ } else {
+ if (IS_IRIS2_1(core))
+ writel(WRAPPER_XTSS_SW_RESET_BIT,
+ core->wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
+ else
+ writel(WRAPPER_A9SS_SW_RESET_BIT,
+ core->wrapper_base + WRAPPER_A9SS_SW_RESET);
+ }
+}
+
+int auth_reset_fw_no_tz(struct venus_core *core, phys_addr_t mem_phys,
+ size_t mem_size)
+{
+ struct iommu_domain *iommu;
+ struct device *dev;
+ int ret;
+
+ dev = core->fw.dev;
+ if (!dev)
+ return -EPROBE_DEFER;
+
+ iommu = core->fw.iommu_domain;
+ core->fw.mapped_mem_size = mem_size;
+
+ ret = iommu_map(iommu, VENUS_FW_START_ADDR, mem_phys, mem_size,
+ IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV, GFP_KERNEL);
+ if (ret) {
+ dev_err(dev, "could not map video firmware region\n");
+ return ret;
+ }
+
+ reset_cpu_no_tz(core);
+
+ return 0;
+}
+
+void unload_fw_no_tz(struct venus_core *core)
+{
+ const size_t mapped = core->fw.mapped_mem_size;
+ struct iommu_domain *iommu;
+ size_t unmapped;
+ u32 reg;
+ struct device *dev = core->fw.dev;
+ void __iomem *wrapper_base = core->wrapper_base;
+ void __iomem *wrapper_tz_base = core->wrapper_tz_base;
+
+ if (IS_IRIS2_1(core)) {
+ /* Assert the reset to XTSS */
+ reg = readl(wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
+ reg |= WRAPPER_XTSS_SW_RESET_BIT;
+ writel(reg, wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
+ } else {
+ /* Assert the reset to ARM9 */
+ reg = readl(wrapper_base + WRAPPER_A9SS_SW_RESET);
+ reg |= WRAPPER_A9SS_SW_RESET_BIT;
+ writel(reg, wrapper_base + WRAPPER_A9SS_SW_RESET);
+ }
+
+ iommu = core->fw.iommu_domain;
+
+ if (core->fw.mapped_mem_size && iommu) {
+ unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, mapped);
+
+ if (unmapped != mapped)
+ dev_err(dev, "failed to unmap firmware\n");
+ else
+ core->fw.mapped_mem_size = 0;
+ }
+}
new file mode 100644
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017 Linaro Ltd.
+ */
+#ifndef __FIRMWARE_NO_TZ_H__
+#define __FIRMWARE_NO_TZ_H__
+
+struct device;
+
+#define VENUS_PAS_ID 9
+
+int init_fw_no_tz(struct venus_core *core);
+void deinit_fw_no_tz(struct venus_core *core);
+int auth_reset_fw_no_tz(struct venus_core *core, phys_addr_t mem_phys,
+ size_t mem_size);
+void unload_fw_no_tz(struct venus_core *core);
+void set_hw_state_no_tz(struct venus_core *core, bool resume);
+
+#endif
similarity index 100%
rename from drivers/media/platform/qcom/venus/helpers.c
rename to drivers/media/platform/qcom/vcodec/venus/helpers.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/helpers.h
rename to drivers/media/platform/qcom/vcodec/venus/helpers.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_cmds.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi_cmds.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_cmds.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi_cmds.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_helper.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi_helper.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_msgs.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi_msgs.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_msgs.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi_msgs.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_parser.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi_parser.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_parser.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi_parser.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_plat_bufs.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_plat_bufs_v6.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi_plat_bufs_v6.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_platform.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_platform.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_platform_v4.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform_v4.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_platform_v6.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi_platform_v6.c
similarity index 99%
rename from drivers/media/platform/qcom/venus/hfi_venus.c
rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus.c
@@ -13,11 +13,12 @@
#include <linux/slab.h>
#include "core.h"
+#include "../firmware.h"
#include "hfi_cmds.h"
#include "hfi_msgs.h"
#include "hfi_venus.h"
#include "hfi_venus_io.h"
-#include "firmware.h"
+#include "firmware_no_tz.h"
#define HFI_MASK_QHDR_TX_TYPE 0xff000000
#define HFI_MASK_QHDR_RX_TYPE 0x00ff0000
@@ -635,7 +636,10 @@ static int venus_power_off(struct venus_hfi_device *hdev)
if (!hdev->power_enabled)
return 0;
- ret = venus_set_hw_state_suspend(hdev->core);
+ if (hdev->core->use_tz)
+ ret = set_hw_state(false);
+ else
+ set_hw_state_no_tz(hdev->core, false);
if (ret)
return ret;
@@ -655,7 +659,13 @@ static int venus_power_on(struct venus_hfi_device *hdev)
if (hdev->power_enabled)
return 0;
- ret = venus_set_hw_state_resume(hdev->core);
+ if (hdev->core->use_tz) {
+ ret = set_hw_state(true);
+ if (ret == -EINVAL)
+ ret = 0;
+ } else {
+ set_hw_state_no_tz(hdev->core, true);
+ }
if (ret)
goto err;
@@ -668,7 +678,10 @@ static int venus_power_on(struct venus_hfi_device *hdev)
return 0;
err_suspend:
- venus_set_hw_state_suspend(hdev->core);
+ if (hdev->core->use_tz)
+ set_hw_state(false);
+ else
+ set_hw_state_no_tz(hdev->core, false);
err:
hdev->power_enabled = false;
return ret;
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_venus.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/hfi_venus_io.h
rename to drivers/media/platform/qcom/vcodec/venus/hfi_venus_io.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/pm_helpers.c
rename to drivers/media/platform/qcom/vcodec/venus/pm_helpers.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/pm_helpers.h
rename to drivers/media/platform/qcom/vcodec/venus/pm_helpers.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/vdec.c
rename to drivers/media/platform/qcom/vcodec/venus/vdec.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/vdec.h
rename to drivers/media/platform/qcom/vcodec/venus/vdec.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/vdec_ctrls.c
rename to drivers/media/platform/qcom/vcodec/venus/vdec_ctrls.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/venc.c
rename to drivers/media/platform/qcom/vcodec/venus/venc.c
similarity index 100%
rename from drivers/media/platform/qcom/venus/venc.h
rename to drivers/media/platform/qcom/vcodec/venus/venc.h
similarity index 100%
rename from drivers/media/platform/qcom/venus/venc_ctrls.c
rename to drivers/media/platform/qcom/vcodec/venus/venc_ctrls.c
deleted file mode 100644
@@ -1,363 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * Copyright (C) 2017 Linaro Ltd.
- */
-
-#include <linux/device.h>
-#include <linux/firmware.h>
-#include <linux/kernel.h>
-#include <linux/iommu.h>
-#include <linux/io.h>
-#include <linux/of.h>
-#include <linux/of_address.h>
-#include <linux/of_reserved_mem.h>
-#include <linux/platform_device.h>
-#include <linux/of_device.h>
-#include <linux/firmware/qcom/qcom_scm.h>
-#include <linux/sizes.h>
-#include <linux/soc/qcom/mdt_loader.h>
-
-#include "core.h"
-#include "firmware.h"
-#include "hfi_venus_io.h"
-
-#define VENUS_PAS_ID 9
-#define VENUS_FW_MEM_SIZE (6 * SZ_1M)
-#define VENUS_FW_START_ADDR 0x0
-
-static void venus_reset_cpu(struct venus_core *core)
-{
- u32 fw_size = core->fw.mapped_mem_size;
- void __iomem *wrapper_base;
-
- if (IS_IRIS2_1(core))
- wrapper_base = core->wrapper_tz_base;
- else
- wrapper_base = core->wrapper_base;
-
- writel(0, wrapper_base + WRAPPER_FW_START_ADDR);
- writel(fw_size, wrapper_base + WRAPPER_FW_END_ADDR);
- writel(0, wrapper_base + WRAPPER_CPA_START_ADDR);
- writel(fw_size, wrapper_base + WRAPPER_CPA_END_ADDR);
- writel(fw_size, wrapper_base + WRAPPER_NONPIX_START_ADDR);
- writel(fw_size, wrapper_base + WRAPPER_NONPIX_END_ADDR);
-
- if (IS_IRIS2_1(core)) {
- /* Bring XTSS out of reset */
- writel(0, wrapper_base + WRAPPER_TZ_XTSS_SW_RESET);
- } else {
- writel(0x0, wrapper_base + WRAPPER_CPU_CGC_DIS);
- writel(0x0, wrapper_base + WRAPPER_CPU_CLOCK_CONFIG);
-
- /* Bring ARM9 out of reset */
- writel(0, wrapper_base + WRAPPER_A9SS_SW_RESET);
- }
-}
-
-int venus_set_hw_state(struct venus_core *core, bool resume)
-{
- int ret;
-
- if (core->use_tz) {
- ret = qcom_scm_set_remote_state(resume, 0);
- if (resume && ret == -EINVAL)
- ret = 0;
- return ret;
- }
-
- if (resume) {
- venus_reset_cpu(core);
- } else {
- if (IS_IRIS2_1(core))
- writel(WRAPPER_XTSS_SW_RESET_BIT,
- core->wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
- else
- writel(WRAPPER_A9SS_SW_RESET_BIT,
- core->wrapper_base + WRAPPER_A9SS_SW_RESET);
- }
-
- return 0;
-}
-
-static int venus_load_fw(struct venus_core *core, const char *fwname,
- phys_addr_t *mem_phys, size_t *mem_size)
-{
- const struct firmware *mdt;
- struct reserved_mem *rmem;
- struct device_node *node;
- struct device *dev;
- ssize_t fw_size;
- void *mem_va;
- int ret;
-
- *mem_phys = 0;
- *mem_size = 0;
-
- dev = core->dev;
- node = of_parse_phandle(dev->of_node, "memory-region", 0);
- if (!node) {
- dev_err(dev, "no memory-region specified\n");
- return -EINVAL;
- }
-
- rmem = of_reserved_mem_lookup(node);
- of_node_put(node);
- if (!rmem) {
- dev_err(dev, "failed to lookup reserved memory-region\n");
- return -EINVAL;
- }
-
- ret = request_firmware(&mdt, fwname, dev);
- if (ret < 0)
- return ret;
-
- fw_size = qcom_mdt_get_size(mdt);
- if (fw_size < 0) {
- ret = fw_size;
- goto err_release_fw;
- }
-
- *mem_phys = rmem->base;
- *mem_size = rmem->size;
-
- if (*mem_size < fw_size || fw_size > VENUS_FW_MEM_SIZE) {
- ret = -EINVAL;
- goto err_release_fw;
- }
-
- mem_va = memremap(*mem_phys, *mem_size, MEMREMAP_WC);
- if (!mem_va) {
- dev_err(dev, "unable to map memory region %pa size %#zx\n", mem_phys, *mem_size);
- ret = -ENOMEM;
- goto err_release_fw;
- }
-
- if (core->use_tz)
- ret = qcom_mdt_load(dev, mdt, fwname, VENUS_PAS_ID,
- mem_va, *mem_phys, *mem_size, NULL);
- else
- ret = qcom_mdt_load_no_init(dev, mdt, fwname, VENUS_PAS_ID,
- mem_va, *mem_phys, *mem_size, NULL);
-
- memunmap(mem_va);
-err_release_fw:
- release_firmware(mdt);
- return ret;
-}
-
-static int venus_boot_no_tz(struct venus_core *core, phys_addr_t mem_phys,
- size_t mem_size)
-{
- struct iommu_domain *iommu;
- struct device *dev;
- int ret;
-
- dev = core->fw.dev;
- if (!dev)
- return -EPROBE_DEFER;
-
- iommu = core->fw.iommu_domain;
- core->fw.mapped_mem_size = mem_size;
-
- ret = iommu_map(iommu, VENUS_FW_START_ADDR, mem_phys, mem_size,
- IOMMU_READ | IOMMU_WRITE | IOMMU_PRIV, GFP_KERNEL);
- if (ret) {
- dev_err(dev, "could not map video firmware region\n");
- return ret;
- }
-
- venus_reset_cpu(core);
-
- return 0;
-}
-
-static int venus_shutdown_no_tz(struct venus_core *core)
-{
- const size_t mapped = core->fw.mapped_mem_size;
- struct iommu_domain *iommu;
- size_t unmapped;
- u32 reg;
- struct device *dev = core->fw.dev;
- void __iomem *wrapper_base = core->wrapper_base;
- void __iomem *wrapper_tz_base = core->wrapper_tz_base;
-
- if (IS_IRIS2_1(core)) {
- /* Assert the reset to XTSS */
- reg = readl(wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
- reg |= WRAPPER_XTSS_SW_RESET_BIT;
- writel(reg, wrapper_tz_base + WRAPPER_TZ_XTSS_SW_RESET);
- } else {
- /* Assert the reset to ARM9 */
- reg = readl(wrapper_base + WRAPPER_A9SS_SW_RESET);
- reg |= WRAPPER_A9SS_SW_RESET_BIT;
- writel(reg, wrapper_base + WRAPPER_A9SS_SW_RESET);
- }
-
- iommu = core->fw.iommu_domain;
-
- if (core->fw.mapped_mem_size && iommu) {
- unmapped = iommu_unmap(iommu, VENUS_FW_START_ADDR, mapped);
-
- if (unmapped != mapped)
- dev_err(dev, "failed to unmap firmware\n");
- else
- core->fw.mapped_mem_size = 0;
- }
-
- return 0;
-}
-
-int venus_boot(struct venus_core *core)
-{
- struct device *dev = core->dev;
- const struct venus_resources *res = core->res;
- const char *fwpath = NULL;
- phys_addr_t mem_phys;
- size_t mem_size;
- int ret;
-
- if (!IS_ENABLED(CONFIG_QCOM_MDT_LOADER) ||
- (core->use_tz && !qcom_scm_is_available()))
- return -EPROBE_DEFER;
-
- ret = of_property_read_string_index(dev->of_node, "firmware-name", 0,
- &fwpath);
- if (ret)
- fwpath = core->res->fwname;
-
- ret = venus_load_fw(core, fwpath, &mem_phys, &mem_size);
- if (ret) {
- dev_err(dev, "fail to load video firmware\n");
- return -EINVAL;
- }
-
- core->fw.mem_size = mem_size;
- core->fw.mem_phys = mem_phys;
-
- if (core->use_tz)
- ret = qcom_scm_pas_auth_and_reset(VENUS_PAS_ID);
- else
- ret = venus_boot_no_tz(core, mem_phys, mem_size);
-
- if (ret)
- return ret;
-
- if (core->use_tz && res->cp_size) {
- /*
- * Clues for porting using downstream data:
- * cp_start = 0
- * cp_size = venus_ns/virtual-addr-pool[0] - yes, address and not size!
- * This works, as the non-secure context bank is placed
- * contiguously right after the Content Protection region.
- *
- * cp_nonpixel_start = venus_sec_non_pixel/virtual-addr-pool[0]
- * cp_nonpixel_size = venus_sec_non_pixel/virtual-addr-pool[1]
- */
- ret = qcom_scm_mem_protect_video_var(res->cp_start,
- res->cp_size,
- res->cp_nonpixel_start,
- res->cp_nonpixel_size);
- if (ret) {
- qcom_scm_pas_shutdown(VENUS_PAS_ID);
- dev_err(dev, "set virtual address ranges fail (%d)\n",
- ret);
- return ret;
- }
- }
-
- return 0;
-}
-
-int venus_shutdown(struct venus_core *core)
-{
- int ret;
-
- if (core->use_tz)
- ret = qcom_scm_pas_shutdown(VENUS_PAS_ID);
- else
- ret = venus_shutdown_no_tz(core);
-
- return ret;
-}
-
-int venus_firmware_init(struct venus_core *core)
-{
- struct platform_device_info info;
- struct iommu_domain *iommu_dom;
- struct platform_device *pdev;
- struct device_node *np;
- int ret;
-
- np = of_get_child_by_name(core->dev->of_node, "video-firmware");
- if (!np) {
- core->use_tz = true;
- return 0;
- }
-
- memset(&info, 0, sizeof(info));
- info.fwnode = &np->fwnode;
- info.parent = core->dev;
- info.name = np->name;
- info.dma_mask = DMA_BIT_MASK(32);
-
- pdev = platform_device_register_full(&info);
- if (IS_ERR(pdev)) {
- of_node_put(np);
- return PTR_ERR(pdev);
- }
-
- pdev->dev.of_node = np;
-
- ret = of_dma_configure(&pdev->dev, np, true);
- if (ret) {
- dev_err(core->dev, "dma configure fail\n");
- goto err_unregister;
- }
-
- core->fw.dev = &pdev->dev;
-
- iommu_dom = iommu_domain_alloc(&platform_bus_type);
- if (!iommu_dom) {
- dev_err(core->fw.dev, "Failed to allocate iommu domain\n");
- ret = -ENOMEM;
- goto err_unregister;
- }
-
- ret = iommu_attach_device(iommu_dom, core->fw.dev);
- if (ret) {
- dev_err(core->fw.dev, "could not attach device\n");
- goto err_iommu_free;
- }
-
- core->fw.iommu_domain = iommu_dom;
-
- of_node_put(np);
-
- return 0;
-
-err_iommu_free:
- iommu_domain_free(iommu_dom);
-err_unregister:
- platform_device_unregister(pdev);
- of_node_put(np);
- return ret;
-}
-
-void venus_firmware_deinit(struct venus_core *core)
-{
- struct iommu_domain *iommu;
-
- if (!core->fw.dev)
- return;
-
- iommu = core->fw.iommu_domain;
-
- iommu_detach_device(iommu, core->fw.dev);
-
- if (core->fw.iommu_domain) {
- iommu_domain_free(iommu);
- core->fw.iommu_domain = NULL;
- }
-
- platform_device_unregister(to_platform_device(core->fw.dev));
-}
deleted file mode 100644
@@ -1,26 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-/*
- * Copyright (C) 2017 Linaro Ltd.
- */
-#ifndef __VENUS_FIRMWARE_H__
-#define __VENUS_FIRMWARE_H__
-
-struct device;
-
-int venus_firmware_init(struct venus_core *core);
-void venus_firmware_deinit(struct venus_core *core);
-int venus_boot(struct venus_core *core);
-int venus_shutdown(struct venus_core *core);
-int venus_set_hw_state(struct venus_core *core, bool suspend);
-
-static inline int venus_set_hw_state_suspend(struct venus_core *core)
-{
- return venus_set_hw_state(core, false);
-}
-
-static inline int venus_set_hw_state_resume(struct venus_core *core)
-{
- return venus_set_hw_state(core, true);
-}
-
-#endif