Re: [PATCH v2 12/29] venus: add common capability parser

2018-07-02 Thread Tomasz Figa
On Mon, Jul 2, 2018 at 6:59 PM Stanimir Varbanov
 wrote:
>
> Hi Tomasz,
>
> On 07/02/2018 12:23 PM, Tomasz Figa wrote:
> > On Thu, May 31, 2018 at 4:06 PM Tomasz Figa  wrote:
> >>
> >> On Thu, May 31, 2018 at 1:21 AM Stanimir Varbanov
> >>  wrote:
> >>>
> >>> Hi Tomasz,
> >>>
> >>> On 05/24/2018 05:16 PM, Tomasz Figa wrote:
>  Hi Stanimir,
> 
>  On Tue, May 15, 2018 at 5:08 PM Stanimir Varbanov <
> > [snip]
> 
> > +   break;
> > +   }
> > +
> > +   word++;
> > +   words_count--;
> 
>  If data is at |word + 1|, shouldn’t we increment |word| by |1 + |data
>  size||?
> >>>
> >>> yes, that could be possible but the firmware packets are with variable
> >>> data length and don't want to make the code so complex.
> >>>
> >>> The idea is to search for HFI_PROPERTY_PARAM* key numbers. Yes it is not
> >>> optimal but this enumeration is happen only once during driver probe.
> >>>
> >>
> >> Hmm, do we have a guarantee that we will never find a value that
> >> matches HFI_PROPERTY_PARAM*, but would be actually just some data
> >> inside the payload?
> >
> > Ping?
>
> OK, you are right there is guarantee that we not mixing keywords and

Did the auto-correction engine in my head got this correctly as "no
guarantee"? :)

> data. I can make parse_* functions to return how words they consumed and
> increment 'word' pointer with consumed words.

Yes, that or maybe just returning the pointer to the first word after
consumed data. Most of the looping functions already seem to have this
value, so it would have to be just returned. (vs having to subtract
from the start pointer)

Best regards,
Tomasz


Re: [PATCH v2 12/29] venus: add common capability parser

2018-07-02 Thread Tomasz Figa
On Mon, Jul 2, 2018 at 6:59 PM Stanimir Varbanov
 wrote:
>
> Hi Tomasz,
>
> On 07/02/2018 12:23 PM, Tomasz Figa wrote:
> > On Thu, May 31, 2018 at 4:06 PM Tomasz Figa  wrote:
> >>
> >> On Thu, May 31, 2018 at 1:21 AM Stanimir Varbanov
> >>  wrote:
> >>>
> >>> Hi Tomasz,
> >>>
> >>> On 05/24/2018 05:16 PM, Tomasz Figa wrote:
>  Hi Stanimir,
> 
>  On Tue, May 15, 2018 at 5:08 PM Stanimir Varbanov <
> > [snip]
> 
> > +   break;
> > +   }
> > +
> > +   word++;
> > +   words_count--;
> 
>  If data is at |word + 1|, shouldn’t we increment |word| by |1 + |data
>  size||?
> >>>
> >>> yes, that could be possible but the firmware packets are with variable
> >>> data length and don't want to make the code so complex.
> >>>
> >>> The idea is to search for HFI_PROPERTY_PARAM* key numbers. Yes it is not
> >>> optimal but this enumeration is happen only once during driver probe.
> >>>
> >>
> >> Hmm, do we have a guarantee that we will never find a value that
> >> matches HFI_PROPERTY_PARAM*, but would be actually just some data
> >> inside the payload?
> >
> > Ping?
>
> OK, you are right there is guarantee that we not mixing keywords and

Did the auto-correction engine in my head got this correctly as "no
guarantee"? :)

> data. I can make parse_* functions to return how words they consumed and
> increment 'word' pointer with consumed words.

Yes, that or maybe just returning the pointer to the first word after
consumed data. Most of the looping functions already seem to have this
value, so it would have to be just returned. (vs having to subtract
from the start pointer)

Best regards,
Tomasz


Re: [PATCH v2 12/29] venus: add common capability parser

2018-05-24 Thread Tomasz Figa
Hi Stanimir,

On Tue, May 15, 2018 at 5:08 PM Stanimir Varbanov <
stanimir.varba...@linaro.org> wrote:
[snip]
> diff --git a/drivers/media/platform/qcom/venus/core.c
b/drivers/media/platform/qcom/venus/core.c
> index 41eef376eb2d..381bfdd688db 100644
> --- a/drivers/media/platform/qcom/venus/core.c
> +++ b/drivers/media/platform/qcom/venus/core.c
[snip]
> +static int venus_enumerate_codecs(struct venus_core *core, u32 type)
> +{
[snip]
> +   for (i = 0; i < MAX_CODEC_NUM; i++) {
> +   codec = (1 << i) & codecs;
> +   if (!codec)
> +   continue;

Could be simplified to

  for_each_set_bit(i, , MAX_CODEC_NUM) {

after making codecs an unsigned long.

[snip]
> diff --git a/drivers/media/platform/qcom/venus/core.h
b/drivers/media/platform/qcom/venus/core.h
> index b5b9a84e9155..fe2d2b9e8af8 100644
> --- a/drivers/media/platform/qcom/venus/core.h
> +++ b/drivers/media/platform/qcom/venus/core.h
> @@ -57,6 +57,29 @@ struct venus_format {
>   u32 type;
>};

> +#define MAX_PLANES 4

We have VIDEO_MAX_PLANES (== 8) already.

[snip]
> @@ -224,22 +249,8 @@ struct venus_buffer {
> * @priv:  a private for HFI operations callbacks
> * @session_type:  the type of the session (decoder or encoder)
> * @hprop: a union used as a holder by get property
> - * @cap_width: width capability
> - * @cap_height:height capability
> - * @cap_mbs_per_frame: macroblocks per frame capability
> - * @cap_mbs_per_sec:   macroblocks per second capability
> - * @cap_framerate: framerate capability
> - * @cap_scale_x:   horizontal scaling capability
> - * @cap_scale_y:   vertical scaling capability
> - * @cap_bitrate:   bitrate capability
> - * @cap_hier_p:hier capability
> - * @cap_ltr_count: LTR count capability
> - * @cap_secure_output2_threshold: secure OUTPUT2 threshold capability
> * @cap_bufs_mode_static:  buffers allocation mode capability
> * @cap_bufs_mode_dynamic: buffers allocation mode capability
> - * @pl_count:  count of supported profiles/levels
> - * @pl:supported profiles/levels
> - * @bufreq:holds buffer requirements
> */
>struct venus_inst {
>   struct list_head list;
> @@ -276,6 +287,7 @@ struct venus_inst {
>   bool reconfig;
>   u32 reconfig_width;
>   u32 reconfig_height;
> +   u32 hfi_codec;

Respective line not added to the kerneldoc above.

>   u32 sequence_cap;
>   u32 sequence_out;
>   struct v4l2_m2m_dev *m2m_dev;
> @@ -287,22 +299,8 @@ struct venus_inst {
>   const struct hfi_inst_ops *ops;
>   u32 session_type;
>   union hfi_get_property hprop;
> -   struct hfi_capability cap_width;
> -   struct hfi_capability cap_height;
> -   struct hfi_capability cap_mbs_per_frame;
> -   struct hfi_capability cap_mbs_per_sec;
> -   struct hfi_capability cap_framerate;
> -   struct hfi_capability cap_scale_x;
> -   struct hfi_capability cap_scale_y;
> -   struct hfi_capability cap_bitrate;
> -   struct hfi_capability cap_hier_p;
> -   struct hfi_capability cap_ltr_count;
> -   struct hfi_capability cap_secure_output2_threshold;
>   bool cap_bufs_mode_static;
>   bool cap_bufs_mode_dynamic;
> -   unsigned int pl_count;
> -   struct hfi_profile_level pl[HFI_MAX_PROFILE_COUNT];
> -   struct hfi_buffer_requirements bufreq[HFI_BUFFER_TYPE_MAX];
>};

>#define IS_V1(core)((core)->res->hfi_version == HFI_VERSION_1XX)
> @@ -322,4 +320,18 @@ static inline void *to_hfi_priv(struct venus_core
*core)
>   return core->priv;
>}

> +static inline struct venus_caps *

I'd leave the decision whether to inline this or not to the compiler.
(Although these days the "inline" keyword is just a hint anyway... but
still just wasted bytes in kernel's git repo.)

> +venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
> +{
> +   unsigned int c;
> +
> +   for (c = 0; c < MAX_CODEC_NUM; c++) {

Shouldn't we iterate up to core->codecs_count?

> +   if (core->caps[c].codec == codec &&
> +   core->caps[c].domain == domain)
> +   return >caps[c];
> +   }
> +
> +   return NULL;
> +}
> +
[snip]
> +   error = hfi_parser(core, inst, num_properties, >data[0],

nit: pkt->data?

[snip]
>   static void hfi_session_init_done(struct venus_core *core,
>struct venus_inst *inst, void *packet)
>   {
>  struct hfi_msg_session_init_done_pkt *pkt = packet;
> -   unsigned int error;
> +   u32 rem_bytes, error;

>  error = pkt->error_type;
>  if (error != HFI_ERR_NONE)
> @@ -745,8 +423,14 @@ static void hfi_session_init_done(struct venus_core
*core,
>  if (core->res->hfi_version != HFI_VERSION_1XX)
>  goto done;

> - 

Re: [PATCH v2 12/29] venus: add common capability parser

2018-05-24 Thread Tomasz Figa
Hi Stanimir,

On Tue, May 15, 2018 at 5:08 PM Stanimir Varbanov <
stanimir.varba...@linaro.org> wrote:
[snip]
> diff --git a/drivers/media/platform/qcom/venus/core.c
b/drivers/media/platform/qcom/venus/core.c
> index 41eef376eb2d..381bfdd688db 100644
> --- a/drivers/media/platform/qcom/venus/core.c
> +++ b/drivers/media/platform/qcom/venus/core.c
[snip]
> +static int venus_enumerate_codecs(struct venus_core *core, u32 type)
> +{
[snip]
> +   for (i = 0; i < MAX_CODEC_NUM; i++) {
> +   codec = (1 << i) & codecs;
> +   if (!codec)
> +   continue;

Could be simplified to

  for_each_set_bit(i, , MAX_CODEC_NUM) {

after making codecs an unsigned long.

[snip]
> diff --git a/drivers/media/platform/qcom/venus/core.h
b/drivers/media/platform/qcom/venus/core.h
> index b5b9a84e9155..fe2d2b9e8af8 100644
> --- a/drivers/media/platform/qcom/venus/core.h
> +++ b/drivers/media/platform/qcom/venus/core.h
> @@ -57,6 +57,29 @@ struct venus_format {
>   u32 type;
>};

> +#define MAX_PLANES 4

We have VIDEO_MAX_PLANES (== 8) already.

[snip]
> @@ -224,22 +249,8 @@ struct venus_buffer {
> * @priv:  a private for HFI operations callbacks
> * @session_type:  the type of the session (decoder or encoder)
> * @hprop: a union used as a holder by get property
> - * @cap_width: width capability
> - * @cap_height:height capability
> - * @cap_mbs_per_frame: macroblocks per frame capability
> - * @cap_mbs_per_sec:   macroblocks per second capability
> - * @cap_framerate: framerate capability
> - * @cap_scale_x:   horizontal scaling capability
> - * @cap_scale_y:   vertical scaling capability
> - * @cap_bitrate:   bitrate capability
> - * @cap_hier_p:hier capability
> - * @cap_ltr_count: LTR count capability
> - * @cap_secure_output2_threshold: secure OUTPUT2 threshold capability
> * @cap_bufs_mode_static:  buffers allocation mode capability
> * @cap_bufs_mode_dynamic: buffers allocation mode capability
> - * @pl_count:  count of supported profiles/levels
> - * @pl:supported profiles/levels
> - * @bufreq:holds buffer requirements
> */
>struct venus_inst {
>   struct list_head list;
> @@ -276,6 +287,7 @@ struct venus_inst {
>   bool reconfig;
>   u32 reconfig_width;
>   u32 reconfig_height;
> +   u32 hfi_codec;

Respective line not added to the kerneldoc above.

>   u32 sequence_cap;
>   u32 sequence_out;
>   struct v4l2_m2m_dev *m2m_dev;
> @@ -287,22 +299,8 @@ struct venus_inst {
>   const struct hfi_inst_ops *ops;
>   u32 session_type;
>   union hfi_get_property hprop;
> -   struct hfi_capability cap_width;
> -   struct hfi_capability cap_height;
> -   struct hfi_capability cap_mbs_per_frame;
> -   struct hfi_capability cap_mbs_per_sec;
> -   struct hfi_capability cap_framerate;
> -   struct hfi_capability cap_scale_x;
> -   struct hfi_capability cap_scale_y;
> -   struct hfi_capability cap_bitrate;
> -   struct hfi_capability cap_hier_p;
> -   struct hfi_capability cap_ltr_count;
> -   struct hfi_capability cap_secure_output2_threshold;
>   bool cap_bufs_mode_static;
>   bool cap_bufs_mode_dynamic;
> -   unsigned int pl_count;
> -   struct hfi_profile_level pl[HFI_MAX_PROFILE_COUNT];
> -   struct hfi_buffer_requirements bufreq[HFI_BUFFER_TYPE_MAX];
>};

>#define IS_V1(core)((core)->res->hfi_version == HFI_VERSION_1XX)
> @@ -322,4 +320,18 @@ static inline void *to_hfi_priv(struct venus_core
*core)
>   return core->priv;
>}

> +static inline struct venus_caps *

I'd leave the decision whether to inline this or not to the compiler.
(Although these days the "inline" keyword is just a hint anyway... but
still just wasted bytes in kernel's git repo.)

> +venus_caps_by_codec(struct venus_core *core, u32 codec, u32 domain)
> +{
> +   unsigned int c;
> +
> +   for (c = 0; c < MAX_CODEC_NUM; c++) {

Shouldn't we iterate up to core->codecs_count?

> +   if (core->caps[c].codec == codec &&
> +   core->caps[c].domain == domain)
> +   return >caps[c];
> +   }
> +
> +   return NULL;
> +}
> +
[snip]
> +   error = hfi_parser(core, inst, num_properties, >data[0],

nit: pkt->data?

[snip]
>   static void hfi_session_init_done(struct venus_core *core,
>struct venus_inst *inst, void *packet)
>   {
>  struct hfi_msg_session_init_done_pkt *pkt = packet;
> -   unsigned int error;
> +   u32 rem_bytes, error;

>  error = pkt->error_type;
>  if (error != HFI_ERR_NONE)
> @@ -745,8 +423,14 @@ static void hfi_session_init_done(struct venus_core
*core,
>  if (core->res->hfi_version != HFI_VERSION_1XX)
>  goto done;

> - 

[PATCH v2 12/29] venus: add common capability parser

2018-05-15 Thread Stanimir Varbanov
This adds common capability parser for all supported Venus
versions. Having it will help to enumerate better the supported
raw formars and codecs and also the capabilities for every
codec like max/min width/height, framerate, bitrate and so on.

Signed-off-by: Stanimir Varbanov 
---
 drivers/media/platform/qcom/venus/Makefile |   3 +-
 drivers/media/platform/qcom/venus/core.c   |  85 ++
 drivers/media/platform/qcom/venus/core.h   |  68 +++--
 drivers/media/platform/qcom/venus/hfi.c|   5 +-
 drivers/media/platform/qcom/venus/hfi_helper.h |  28 +-
 drivers/media/platform/qcom/venus/hfi_msgs.c   | 348 ++---
 drivers/media/platform/qcom/venus/hfi_parser.c | 295 +
 drivers/media/platform/qcom/venus/hfi_parser.h |  45 
 drivers/media/platform/qcom/venus/vdec.c   |  38 +--
 drivers/media/platform/qcom/venus/venc.c   |  52 ++--
 10 files changed, 530 insertions(+), 437 deletions(-)
 create mode 100644 drivers/media/platform/qcom/venus/hfi_parser.c
 create mode 100644 drivers/media/platform/qcom/venus/hfi_parser.h

diff --git a/drivers/media/platform/qcom/venus/Makefile 
b/drivers/media/platform/qcom/venus/Makefile
index bfd4edf7c83f..b44b11b03e12 100644
--- a/drivers/media/platform/qcom/venus/Makefile
+++ b/drivers/media/platform/qcom/venus/Makefile
@@ -2,7 +2,8 @@
 # Makefile for Qualcomm Venus driver
 
 venus-core-objs += core.o helpers.o firmware.o \
-  hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o
+  hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
+  hfi_parser.o
 
 venus-dec-objs += vdec.o vdec_ctrls.o
 venus-enc-objs += venc.o venc_ctrls.o
diff --git a/drivers/media/platform/qcom/venus/core.c 
b/drivers/media/platform/qcom/venus/core.c
index 41eef376eb2d..381bfdd688db 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -152,6 +152,83 @@ static void venus_clks_disable(struct venus_core *core)
clk_disable_unprepare(core->clks[i]);
 }
 
+static u32 to_v4l2_codec_type(u32 codec)
+{
+   switch (codec) {
+   case HFI_VIDEO_CODEC_H264:
+   return V4L2_PIX_FMT_H264;
+   case HFI_VIDEO_CODEC_H263:
+   return V4L2_PIX_FMT_H263;
+   case HFI_VIDEO_CODEC_MPEG1:
+   return V4L2_PIX_FMT_MPEG1;
+   case HFI_VIDEO_CODEC_MPEG2:
+   return V4L2_PIX_FMT_MPEG2;
+   case HFI_VIDEO_CODEC_MPEG4:
+   return V4L2_PIX_FMT_MPEG4;
+   case HFI_VIDEO_CODEC_VC1:
+   return V4L2_PIX_FMT_VC1_ANNEX_G;
+   case HFI_VIDEO_CODEC_VP8:
+   return V4L2_PIX_FMT_VP8;
+   case HFI_VIDEO_CODEC_VP9:
+   return V4L2_PIX_FMT_VP9;
+   case HFI_VIDEO_CODEC_DIVX:
+   case HFI_VIDEO_CODEC_DIVX_311:
+   return V4L2_PIX_FMT_XVID;
+   default:
+   return 0;
+   }
+}
+
+static int venus_enumerate_codecs(struct venus_core *core, u32 type)
+{
+   const struct hfi_inst_ops dummy_ops = {};
+   struct venus_inst *inst;
+   u32 codec, codecs;
+   unsigned int i;
+   int ret;
+
+   if (core->res->hfi_version != HFI_VERSION_1XX)
+   return 0;
+
+   inst = kzalloc(sizeof(*inst), GFP_KERNEL);
+   if (!inst)
+   return -ENOMEM;
+
+   mutex_init(>lock);
+   inst->core = core;
+   inst->session_type = type;
+   if (type == VIDC_SESSION_TYPE_DEC)
+   codecs = core->dec_codecs;
+   else
+   codecs = core->enc_codecs;
+
+   ret = hfi_session_create(inst, _ops);
+   if (ret)
+   goto err;
+
+   for (i = 0; i < MAX_CODEC_NUM; i++) {
+   codec = (1 << i) & codecs;
+   if (!codec)
+   continue;
+
+   ret = hfi_session_init(inst, to_v4l2_codec_type(codec));
+   if (ret)
+   goto done;
+
+   ret = hfi_session_deinit(inst);
+   if (ret)
+   goto done;
+   }
+
+done:
+   hfi_session_destroy(inst);
+err:
+   mutex_destroy(>lock);
+   kfree(inst);
+
+   return ret;
+}
+
 static int venus_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -219,6 +296,14 @@ static int venus_probe(struct platform_device *pdev)
if (ret)
goto err_venus_shutdown;
 
+   ret = venus_enumerate_codecs(core, VIDC_SESSION_TYPE_DEC);
+   if (ret)
+   goto err_venus_shutdown;
+
+   ret = venus_enumerate_codecs(core, VIDC_SESSION_TYPE_ENC);
+   if (ret)
+   goto err_venus_shutdown;
+
ret = v4l2_device_register(dev, >v4l2_dev);
if (ret)
goto err_core_deinit;
diff --git a/drivers/media/platform/qcom/venus/core.h 
b/drivers/media/platform/qcom/venus/core.h
index b5b9a84e9155..fe2d2b9e8af8 100644
--- a/drivers/media/platform/qcom/venus/core.h
+++ 

[PATCH v2 12/29] venus: add common capability parser

2018-05-15 Thread Stanimir Varbanov
This adds common capability parser for all supported Venus
versions. Having it will help to enumerate better the supported
raw formars and codecs and also the capabilities for every
codec like max/min width/height, framerate, bitrate and so on.

Signed-off-by: Stanimir Varbanov 
---
 drivers/media/platform/qcom/venus/Makefile |   3 +-
 drivers/media/platform/qcom/venus/core.c   |  85 ++
 drivers/media/platform/qcom/venus/core.h   |  68 +++--
 drivers/media/platform/qcom/venus/hfi.c|   5 +-
 drivers/media/platform/qcom/venus/hfi_helper.h |  28 +-
 drivers/media/platform/qcom/venus/hfi_msgs.c   | 348 ++---
 drivers/media/platform/qcom/venus/hfi_parser.c | 295 +
 drivers/media/platform/qcom/venus/hfi_parser.h |  45 
 drivers/media/platform/qcom/venus/vdec.c   |  38 +--
 drivers/media/platform/qcom/venus/venc.c   |  52 ++--
 10 files changed, 530 insertions(+), 437 deletions(-)
 create mode 100644 drivers/media/platform/qcom/venus/hfi_parser.c
 create mode 100644 drivers/media/platform/qcom/venus/hfi_parser.h

diff --git a/drivers/media/platform/qcom/venus/Makefile 
b/drivers/media/platform/qcom/venus/Makefile
index bfd4edf7c83f..b44b11b03e12 100644
--- a/drivers/media/platform/qcom/venus/Makefile
+++ b/drivers/media/platform/qcom/venus/Makefile
@@ -2,7 +2,8 @@
 # Makefile for Qualcomm Venus driver
 
 venus-core-objs += core.o helpers.o firmware.o \
-  hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o
+  hfi_venus.o hfi_msgs.o hfi_cmds.o hfi.o \
+  hfi_parser.o
 
 venus-dec-objs += vdec.o vdec_ctrls.o
 venus-enc-objs += venc.o venc_ctrls.o
diff --git a/drivers/media/platform/qcom/venus/core.c 
b/drivers/media/platform/qcom/venus/core.c
index 41eef376eb2d..381bfdd688db 100644
--- a/drivers/media/platform/qcom/venus/core.c
+++ b/drivers/media/platform/qcom/venus/core.c
@@ -152,6 +152,83 @@ static void venus_clks_disable(struct venus_core *core)
clk_disable_unprepare(core->clks[i]);
 }
 
+static u32 to_v4l2_codec_type(u32 codec)
+{
+   switch (codec) {
+   case HFI_VIDEO_CODEC_H264:
+   return V4L2_PIX_FMT_H264;
+   case HFI_VIDEO_CODEC_H263:
+   return V4L2_PIX_FMT_H263;
+   case HFI_VIDEO_CODEC_MPEG1:
+   return V4L2_PIX_FMT_MPEG1;
+   case HFI_VIDEO_CODEC_MPEG2:
+   return V4L2_PIX_FMT_MPEG2;
+   case HFI_VIDEO_CODEC_MPEG4:
+   return V4L2_PIX_FMT_MPEG4;
+   case HFI_VIDEO_CODEC_VC1:
+   return V4L2_PIX_FMT_VC1_ANNEX_G;
+   case HFI_VIDEO_CODEC_VP8:
+   return V4L2_PIX_FMT_VP8;
+   case HFI_VIDEO_CODEC_VP9:
+   return V4L2_PIX_FMT_VP9;
+   case HFI_VIDEO_CODEC_DIVX:
+   case HFI_VIDEO_CODEC_DIVX_311:
+   return V4L2_PIX_FMT_XVID;
+   default:
+   return 0;
+   }
+}
+
+static int venus_enumerate_codecs(struct venus_core *core, u32 type)
+{
+   const struct hfi_inst_ops dummy_ops = {};
+   struct venus_inst *inst;
+   u32 codec, codecs;
+   unsigned int i;
+   int ret;
+
+   if (core->res->hfi_version != HFI_VERSION_1XX)
+   return 0;
+
+   inst = kzalloc(sizeof(*inst), GFP_KERNEL);
+   if (!inst)
+   return -ENOMEM;
+
+   mutex_init(>lock);
+   inst->core = core;
+   inst->session_type = type;
+   if (type == VIDC_SESSION_TYPE_DEC)
+   codecs = core->dec_codecs;
+   else
+   codecs = core->enc_codecs;
+
+   ret = hfi_session_create(inst, _ops);
+   if (ret)
+   goto err;
+
+   for (i = 0; i < MAX_CODEC_NUM; i++) {
+   codec = (1 << i) & codecs;
+   if (!codec)
+   continue;
+
+   ret = hfi_session_init(inst, to_v4l2_codec_type(codec));
+   if (ret)
+   goto done;
+
+   ret = hfi_session_deinit(inst);
+   if (ret)
+   goto done;
+   }
+
+done:
+   hfi_session_destroy(inst);
+err:
+   mutex_destroy(>lock);
+   kfree(inst);
+
+   return ret;
+}
+
 static int venus_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -219,6 +296,14 @@ static int venus_probe(struct platform_device *pdev)
if (ret)
goto err_venus_shutdown;
 
+   ret = venus_enumerate_codecs(core, VIDC_SESSION_TYPE_DEC);
+   if (ret)
+   goto err_venus_shutdown;
+
+   ret = venus_enumerate_codecs(core, VIDC_SESSION_TYPE_ENC);
+   if (ret)
+   goto err_venus_shutdown;
+
ret = v4l2_device_register(dev, >v4l2_dev);
if (ret)
goto err_core_deinit;
diff --git a/drivers/media/platform/qcom/venus/core.h 
b/drivers/media/platform/qcom/venus/core.h
index b5b9a84e9155..fe2d2b9e8af8 100644
--- a/drivers/media/platform/qcom/venus/core.h
+++