Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b8a3e388 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "msm: vidc: Load hfi packetization based on Venus version"

parents 747a2c9a 08440bf0
Loading
Loading
Loading
Loading
+57 −1
Original line number Diff line number Diff line
@@ -259,7 +259,7 @@ int create_pkt_cmd_sys_coverage_config(
	return 0;
}

int create_pkt_set_cmd_sys_resource(
int create_pkt_cmd_sys_set_resource(
		struct hfi_cmd_sys_set_resource_packet *pkt,
		struct vidc_resource_hdr *resource_hdr,
		void *resource_value)
@@ -1927,3 +1927,59 @@ int create_pkt_cmd_sys_image_version(
	pkt->rg_property_data[0] = HFI_PROPERTY_SYS_IMAGE_VERSION;
	return 0;
}

static struct hfi_packetization_ops hfi_default = {
	.sys_init = create_pkt_cmd_sys_init,
	.sys_pc_prep = create_pkt_cmd_sys_pc_prep,
	.sys_idle_indicator = create_pkt_cmd_sys_idle_indicator,
	.sys_power_control = create_pkt_cmd_sys_power_control,
	.sys_set_resource = create_pkt_cmd_sys_set_resource,
	.sys_debug_config = create_pkt_cmd_sys_debug_config,
	.sys_coverage_config = create_pkt_cmd_sys_coverage_config,
	.sys_release_resource = create_pkt_cmd_sys_release_resource,
	.sys_ping = create_pkt_cmd_sys_ping,
	.sys_image_version = create_pkt_cmd_sys_image_version,
	.ssr_cmd = create_pkt_ssr_cmd,
	.session_init = create_pkt_cmd_sys_session_init,
	.session_cmd = create_pkt_cmd_session_cmd,
	.session_set_buffers = create_pkt_cmd_session_set_buffers,
	.session_release_buffers = create_pkt_cmd_session_release_buffers,
	.session_etb_decoder = create_pkt_cmd_session_etb_decoder,
	.session_etb_encoder = create_pkt_cmd_session_etb_encoder,
	.session_ftb = create_pkt_cmd_session_ftb,
	.session_parse_seq_header = create_pkt_cmd_session_parse_seq_header,
	.session_get_seq_hdr = create_pkt_cmd_session_get_seq_hdr,
	.session_get_buf_req = create_pkt_cmd_session_get_buf_req,
	.session_flush = create_pkt_cmd_session_flush,
	.session_get_property = create_pkt_cmd_session_get_property,
	.session_set_property = create_pkt_cmd_session_set_property,
};

struct hfi_packetization_ops *get_venus_3_x_ops(void)
{
	static struct hfi_packetization_ops hfi_venus_3_x;

	hfi_venus_3_x = hfi_default;

	/* Override new HFI functions for HFI_3XX here. */

	return &hfi_venus_3_x;
}

struct hfi_packetization_ops *hfi_get_pkt_ops_handle(
			enum hfi_packetization_type type)
{
	dprintk(VIDC_DBG, "%s selected\n",
		type == HFI_PACKETIZATION_LEGACY ? "legacy packetization" :
		type == HFI_PACKETIZATION_3XX ? "3xx packetization" :
		"Unknown hfi");

	switch (type) {
	case HFI_PACKETIZATION_LEGACY:
		return &hfi_default;
	case HFI_PACKETIZATION_3XX:
		return get_venus_3_x_ops();
	}

	return NULL;
}
+43 −56
Original line number Diff line number Diff line
@@ -18,95 +18,82 @@
#include "vidc_hfi.h"
#include "vidc_hfi_api.h"

int create_pkt_cmd_sys_init(struct hfi_cmd_sys_init_packet *pkt,
		u32 arch_type);
int create_pkt_cmd_sys_pc_prep(struct hfi_cmd_sys_pc_prep_packet *pkt);

int create_pkt_cmd_sys_idle_indicator(
		struct hfi_cmd_sys_set_property_packet *pkt,
#define call_hfi_pkt_op(q, op, args...)			\
	(((q) && (q)->pkt_ops && (q)->pkt_ops->op) ?	\
	((q)->pkt_ops->op(args)) : 0)

enum hfi_packetization_type {
	HFI_PACKETIZATION_LEGACY,
	HFI_PACKETIZATION_3XX,
};

struct hfi_packetization_ops {
	int (*sys_init)(struct hfi_cmd_sys_init_packet *pkt, u32 arch_type);
	int (*sys_pc_prep)(struct hfi_cmd_sys_pc_prep_packet *pkt);
	int (*sys_idle_indicator)(struct hfi_cmd_sys_set_property_packet *pkt,
		u32 enable);

int create_pkt_cmd_sys_power_control(
	struct hfi_cmd_sys_set_property_packet *pkt, u32 enable);

int create_pkt_set_cmd_sys_resource(
	int (*sys_power_control)(struct hfi_cmd_sys_set_property_packet *pkt,
		u32 enable);
	int (*sys_set_resource)(
		struct hfi_cmd_sys_set_resource_packet *pkt,
		struct vidc_resource_hdr *resource_hdr,
		void *resource_value);

int create_pkt_cmd_sys_debug_config(
		struct hfi_cmd_sys_set_property_packet *pkt,
	int (*sys_debug_config)(struct hfi_cmd_sys_set_property_packet *pkt,
			u32 mode);

int create_pkt_cmd_sys_coverage_config(
		struct hfi_cmd_sys_set_property_packet *pkt,
	int (*sys_coverage_config)(struct hfi_cmd_sys_set_property_packet *pkt,
			u32 mode);

int create_pkt_cmd_sys_release_resource(
	int (*sys_release_resource)(
		struct hfi_cmd_sys_release_resource_packet *pkt,
		struct vidc_resource_hdr *resource_hdr);

int create_pkt_cmd_sys_ping(struct hfi_cmd_sys_ping_packet *pkt);

int create_pkt_cmd_sys_session_init(
	int (*sys_ping)(struct hfi_cmd_sys_ping_packet *pkt);
	int (*sys_image_version)(struct hfi_cmd_sys_get_property_packet *pkt);
	int (*ssr_cmd)(enum hal_ssr_trigger_type type,
		struct hfi_cmd_sys_test_ssr_packet *pkt);
	int (*session_init)(
		struct hfi_cmd_sys_session_init_packet *pkt,
		struct hal_session *session,
		u32 session_domain, u32 session_codec);

int create_pkt_cmd_session_cmd(struct vidc_hal_session_cmd_pkt *pkt,
	int (*session_cmd)(struct vidc_hal_session_cmd_pkt *pkt,
		int pkt_type, struct hal_session *session);

int create_pkt_cmd_session_set_buffers(
	int (*session_set_buffers)(
		struct hfi_cmd_session_set_buffers_packet *pkt,
		struct hal_session *session,
		struct vidc_buffer_addr_info *buffer_info);

int create_pkt_cmd_session_release_buffers(
	int (*session_release_buffers)(
		struct hfi_cmd_session_release_buffer_packet *pkt,
		struct hal_session *session,
		struct vidc_buffer_addr_info *buffer_info);

int create_pkt_cmd_session_etb_decoder(
	int (*session_etb_decoder)(
		struct hfi_cmd_session_empty_buffer_compressed_packet *pkt,
		struct hal_session *session,
		struct vidc_frame_data *input_frame);

int create_pkt_cmd_session_etb_encoder(
	int (*session_etb_encoder)(
		struct hfi_cmd_session_empty_buffer_uncompressed_plane0_packet
		*pkt, struct hal_session *session,
		struct vidc_frame_data *input_frame);

int create_pkt_cmd_session_ftb(struct hfi_cmd_session_fill_buffer_packet *pkt,
	int (*session_ftb)(struct hfi_cmd_session_fill_buffer_packet *pkt,
		struct hal_session *session,
		struct vidc_frame_data *output_frame);

int create_pkt_cmd_session_parse_seq_header(
	int (*session_parse_seq_header)(
		struct hfi_cmd_session_parse_sequence_header_packet *pkt,
		struct hal_session *session, struct vidc_seq_hdr *seq_hdr);

int create_pkt_cmd_session_get_seq_hdr(
	int (*session_get_seq_hdr)(
		struct hfi_cmd_session_get_sequence_header_packet *pkt,
		struct hal_session *session, struct vidc_seq_hdr *seq_hdr);

int create_pkt_cmd_session_get_buf_req(
	int (*session_get_buf_req)(
		struct hfi_cmd_session_get_property_packet *pkt,
		struct hal_session *session);

int create_pkt_cmd_session_flush(struct hfi_cmd_session_flush_packet *pkt,
	int (*session_flush)(struct hfi_cmd_session_flush_packet *pkt,
		struct hal_session *session, enum hal_flush flush_mode);

int create_pkt_cmd_session_set_property(
	int (*session_get_property)(
		struct hfi_cmd_session_get_property_packet *pkt,
		struct hal_session *session, enum hal_property ptype);
	int (*session_set_property)(
		struct hfi_cmd_session_set_property_packet *pkt,
		struct hal_session *session,
		enum hal_property ptype, void *pdata);
};

int create_pkt_cmd_session_get_property(
		struct hfi_cmd_session_get_property_packet *pkt,
		struct hal_session *session, enum hal_property ptype);

int create_pkt_ssr_cmd(enum hal_ssr_trigger_type type,
		struct hfi_cmd_sys_test_ssr_packet *pkt);

int create_pkt_cmd_sys_image_version(
		struct hfi_cmd_sys_get_property_packet *pkt);
struct hfi_packetization_ops *hfi_get_pkt_ops_handle(
		enum hfi_packetization_type);
#endif
+32 −20
Original line number Diff line number Diff line
@@ -364,6 +364,13 @@ static void *q6_hfi_get_device(u32 device_id,
			dprintk(VIDC_ERR, "Failed to init resources: %d\n", rc);
		goto err_fail_init_res;
	}

	device->pkt_ops = hfi_get_pkt_ops_handle(HFI_PACKETIZATION_LEGACY);
	if (!device->pkt_ops) {
		dprintk(VIDC_ERR, "Failed to get pkt_ops handle\n");
		goto err_fail_init_res;
	}

	return device;

err_fail_init_res:
@@ -510,7 +517,7 @@ static int q6_hfi_core_init(void *device)

	q6_hfi_add_apr_hdr(dev, &apr.hdr, sizeof(apr));

	rc = create_pkt_cmd_sys_init(&apr.pkt, HFI_VIDEO_ARCH_OX);
	rc = call_hfi_pkt_op(dev, sys_init, &apr.pkt, HFI_VIDEO_ARCH_OX);
	if (rc) {
		dprintk(VIDC_ERR, "Failed to create sys init pkt\n");
		goto err_core_init;
@@ -569,8 +576,8 @@ static void *q6_hfi_session_init(void *device, void *session_id,

	q6_hfi_add_apr_hdr(dev, &apr.hdr, sizeof(apr));

	if (create_pkt_cmd_sys_session_init(&apr.pkt, new_session,
					session_type, codec_type)) {
	if (call_hfi_pkt_op(dev, session_init,
			&apr.pkt, new_session, session_type, codec_type)) {
		dprintk(VIDC_ERR, "session_init: failed to create packet\n");
		goto err_session_init;
	}
@@ -619,7 +626,7 @@ static int q6_hal_send_session_cmd(void *sess,

	q6_hfi_add_apr_hdr(dev, &apr.hdr, sizeof(apr));

	rc = create_pkt_cmd_session_cmd(&apr.pkt, pkt_type, session);
	rc = call_hfi_pkt_op(dev, session_cmd, &apr.pkt, pkt_type, session);
	if (rc) {
		dprintk(VIDC_ERR, "send session cmd: create pkt failed\n");
		goto err_create_pkt;
@@ -688,7 +695,8 @@ static int q6_hfi_session_set_buffers(void *sess,

	q6_hfi_add_apr_hdr(dev, &apr->hdr, VIDC_IFACEQ_VAR_LARGE_PKT_SIZE);

	rc = create_pkt_cmd_session_set_buffers(

	rc = call_hfi_pkt_op(dev, session_set_buffers,
			&apr->pkt, session, buffer_info);
	if (rc) {
		dprintk(VIDC_ERR, "set buffers: failed to create packet\n");
@@ -730,7 +738,7 @@ static int q6_hfi_session_release_buffers(void *sess,

	q6_hfi_add_apr_hdr(dev, &apr->hdr, VIDC_IFACEQ_VAR_LARGE_PKT_SIZE);

	rc = create_pkt_cmd_session_release_buffers(
	rc = call_hfi_pkt_op(dev, session_release_buffers,
			&apr->pkt, session, buffer_info);
	if (rc) {
		dprintk(VIDC_ERR, "release buffers: failed to create packet\n");
@@ -792,7 +800,7 @@ static int q6_hfi_session_etb(void *sess,
		struct q6_apr_cmd_session_empty_buffer_compressed_packet apr;
		q6_hfi_add_apr_hdr(dev, &apr.hdr, sizeof(apr));

		rc = create_pkt_cmd_session_etb_decoder(
		rc = call_hfi_pkt_op(dev, session_etb_decoder,
				&apr.pkt, session, input_frame);
		if (rc) {
			dprintk(VIDC_ERR,
@@ -814,7 +822,7 @@ static int q6_hfi_session_etb(void *sess,
		q6_apr_cmd_session_empty_buffer_uncompressed_plane0_packet apr;
		q6_hfi_add_apr_hdr(dev, &apr.hdr, sizeof(apr));

		rc =  create_pkt_cmd_session_etb_encoder(
		rc = call_hfi_pkt_op(dev, session_etb_encoder,
				&apr.pkt, session, input_frame);
		if (rc) {
			dprintk(VIDC_ERR,
@@ -850,7 +858,8 @@ static int q6_hfi_session_ftb(void *sess,

	q6_hfi_add_apr_hdr(dev, &apr.hdr, sizeof(apr));

	rc = create_pkt_cmd_session_ftb(&apr.pkt, session, output_frame);
	rc = call_hfi_pkt_op(dev, session_ftb,
			&apr.pkt, session, output_frame);
	if (rc) {
		dprintk(VIDC_ERR, "Session ftb: failed to create pkt\n");
		goto err_create_pkt;
@@ -887,7 +896,7 @@ static int q6_hfi_session_parse_seq_hdr(void *sess,

	q6_hfi_add_apr_hdr(dev, &apr->hdr, VIDC_IFACEQ_VAR_SMALL_PKT_SIZE);

	rc = create_pkt_cmd_session_parse_seq_header(
	rc = call_hfi_pkt_op(dev, session_parse_seq_header,
			&apr->pkt, session, seq_hdr);
	if (rc) {
		dprintk(VIDC_ERR,
@@ -925,7 +934,8 @@ static int q6_hfi_session_get_seq_hdr(void *sess,

	q6_hfi_add_apr_hdr(dev, &apr->hdr, VIDC_IFACEQ_VAR_SMALL_PKT_SIZE);

	rc = create_pkt_cmd_session_get_seq_hdr(&apr->pkt, session, seq_hdr);
	rc = call_hfi_pkt_op(dev, session_get_seq_hdr,
			&apr->pkt, session, seq_hdr);
	if (rc) {
		dprintk(VIDC_ERR, "Session get seqhdr: failed to create pkt\n");
		goto err_create_pkt;
@@ -958,7 +968,8 @@ static int q6_hfi_session_get_buf_req(void *sess)

	q6_hfi_add_apr_hdr(dev, &apr.hdr, sizeof(apr));

	rc = create_pkt_cmd_session_get_buf_req(&apr.pkt, session);
	rc = call_hfi_pkt_op(dev, session_get_buf_req,
			&apr.pkt, session);
	if (rc) {
		dprintk(VIDC_ERR, "Session get bufreq: failed to create pkt\n");
		goto err_create_pkt;
@@ -990,7 +1001,8 @@ static int q6_hfi_session_flush(void *sess, enum hal_flush flush_mode)

	q6_hfi_add_apr_hdr(dev, &apr.hdr, sizeof(apr));

	rc = create_pkt_cmd_session_flush(&apr.pkt, session, flush_mode);
	rc = call_hfi_pkt_op(dev, session_flush,
			&apr.pkt, session, flush_mode);
	if (rc) {
		dprintk(VIDC_ERR, "Session flush: failed to create pkt\n");
		goto err_create_pkt;
@@ -1032,7 +1044,7 @@ static int q6_hfi_session_set_property(void *sess,

	q6_hfi_add_apr_hdr(dev, &apr->hdr, VIDC_IFACEQ_VAR_LARGE_PKT_SIZE);

	rc = create_pkt_cmd_session_set_property(
	rc = call_hfi_pkt_op(dev, session_set_property,
			&apr->pkt, session, ptype, pdata);
	if (rc) {
		dprintk(VIDC_ERR, "set property: failed to create packet\n");
+2 −1
Original line number Diff line number Diff line
/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
/* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
@@ -53,6 +53,7 @@ struct q6_hfi_device {
	struct msm_vidc_platform_resources *res;
	void *apr;
	struct mutex session_lock;
	struct hfi_packetization_ops *pkt_ops;
};

struct q6_apr_cmd_sys_init_packet {
+157 −74
Original line number Diff line number Diff line
@@ -1044,12 +1044,13 @@ static int venus_hfi_core_set_resource(void *device,

	pkt = (struct hfi_cmd_sys_set_resource_packet *) packet;

	rc = create_pkt_set_cmd_sys_resource(pkt, resource_hdr,
						resource_value);
	rc = call_hfi_pkt_op(dev, sys_set_resource,
			pkt, resource_hdr, resource_value);
	if (rc) {
		dprintk(VIDC_ERR, "set_res: failed to create packet\n");
		goto err_create_pkt;
	}

	rc = locked ? venus_hfi_iface_cmdq_write(dev, pkt) :
			venus_hfi_iface_cmdq_write_nolock(dev, pkt);
	if (rc)
@@ -1073,7 +1074,8 @@ static int venus_hfi_core_release_resource(void *device,
		dev = device;
	}

	rc = create_pkt_cmd_sys_release_resource(&pkt, resource_hdr);
	rc = call_hfi_pkt_op(dev, sys_release_resource,
			&pkt, resource_hdr);
	if (rc) {
		dprintk(VIDC_ERR, "release_res: failed to create packet\n");
		goto err_create_pkt;
@@ -2156,7 +2158,8 @@ static int venus_hfi_sys_set_debug(struct venus_hfi_device *device, u32 debug)
	int rc = 0;
	struct hfi_cmd_sys_set_property_packet *pkt =
		(struct hfi_cmd_sys_set_property_packet *) &packet;
	rc = create_pkt_cmd_sys_debug_config(pkt, debug);

	rc = call_hfi_pkt_op(device, sys_debug_config, pkt, debug);
	if (rc) {
		dprintk(VIDC_WARN,
			"Debug mode setting to FW failed\n");
@@ -2173,7 +2176,9 @@ static int venus_hfi_sys_set_coverage(struct venus_hfi_device *device, u32 mode)
	int rc = 0;
	struct hfi_cmd_sys_set_property_packet *pkt =
		(struct hfi_cmd_sys_set_property_packet *) &packet;
	rc = create_pkt_cmd_sys_coverage_config(pkt, mode);

	rc = call_hfi_pkt_op(device, sys_coverage_config,
			pkt, mode);
	if (rc) {
		dprintk(VIDC_WARN,
			"Coverage mode setting to FW failed\n");
@@ -2196,7 +2201,7 @@ static int venus_hfi_sys_set_idle_message(struct venus_hfi_device *device,
		dprintk(VIDC_DBG, "sys_idle_indicator is not enabled\n");
		return 0;
	}
	create_pkt_cmd_sys_idle_indicator(pkt, enable);
	call_hfi_pkt_op(device, sys_idle_indicator, pkt, enable);
	if (venus_hfi_iface_cmdq_write(device, pkt))
		return -ENOTEMPTY;
	return 0;
@@ -2221,7 +2226,7 @@ static int venus_hfi_sys_set_power_control(struct venus_hfi_device *device,
	if (!supported)
		return 0;

	create_pkt_cmd_sys_power_control(pkt, enable);
	call_hfi_pkt_op(device, sys_power_control, pkt, enable);
	if (venus_hfi_iface_cmdq_write(device, pkt))
		return -ENOTEMPTY;
	return 0;
@@ -2279,7 +2284,7 @@ static int venus_hfi_core_init(void *device)
		goto err_core_init;
	}

	rc = create_pkt_cmd_sys_init(&pkt, HFI_VIDEO_ARCH_OX);
	rc =  call_hfi_pkt_op(dev, sys_init, &pkt, HFI_VIDEO_ARCH_OX);
	if (rc) {
		dprintk(VIDC_ERR, "Failed to create sys init pkt\n");
		goto err_core_init;
@@ -2288,7 +2293,8 @@ static int venus_hfi_core_init(void *device)
		rc = -ENOTEMPTY;
		goto err_core_init;
	}
	rc = create_pkt_cmd_sys_image_version(&version_pkt);

	rc = call_hfi_pkt_op(dev, sys_image_version, &version_pkt);
	if (rc || venus_hfi_iface_cmdq_write(dev, &version_pkt))
		dprintk(VIDC_WARN, "Failed to send image version pkt to f/w\n");

@@ -2412,7 +2418,7 @@ static int venus_hfi_core_ping(void *device)
		return -ENODEV;
	}

	rc = create_pkt_cmd_sys_ping(&pkt);
	rc = call_hfi_pkt_op(dev, sys_ping, &pkt);
	if (rc) {
		dprintk(VIDC_ERR, "core_ping: failed to create packet\n");
		goto err_create_pkt;
@@ -2439,7 +2445,7 @@ static int venus_hfi_core_trigger_ssr(void *device,
		return -ENODEV;
	}

	rc = create_pkt_ssr_cmd(type, &pkt);
	rc = call_hfi_pkt_op(dev, ssr_cmd, type, &pkt);
	if (rc) {
		dprintk(VIDC_ERR, "core_ping: failed to create packet\n");
		goto err_create_pkt;
@@ -2458,19 +2464,21 @@ static int venus_hfi_session_set_property(void *sess,
	u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
	struct hfi_cmd_session_set_property_packet *pkt =
		(struct hfi_cmd_session_set_property_packet *) &packet;
	struct hal_session *session;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;
	int rc = 0;

	if (!sess || !pdata) {
	if (!session || !session->device || !pdata) {
		dprintk(VIDC_ERR, "Invalid Params\n");
		return -EINVAL;
	} else {
		session = sess;
	}
	device = session->device;

	dprintk(VIDC_INFO, "in set_prop,with prop id: 0x%x\n", ptype);

	if (create_pkt_cmd_session_set_property(pkt, session, ptype, pdata)) {
	rc = call_hfi_pkt_op(device, session_set_property,
			pkt, session, ptype, pdata);
	if (rc) {
		dprintk(VIDC_ERR, "set property: failed to create packet\n");
		return -EINVAL;
	}
@@ -2485,21 +2493,25 @@ static int venus_hfi_session_get_property(void *sess,
					enum hal_property ptype)
{
	struct hfi_cmd_session_get_property_packet pkt = {0};
	struct hal_session *session;
	struct hal_session *session = sess;
	int rc = 0;
	if (!sess) {
	struct venus_hfi_device *device;

	if (!session || !session->device) {
		dprintk(VIDC_ERR, "Invalid Params\n");
		return -EINVAL;
	} else {
		session = sess;
	}
	device = session->device;

	dprintk(VIDC_INFO, "%s: property id: %d\n", __func__, ptype);

	rc = create_pkt_cmd_session_get_property(&pkt, session, ptype);
	rc = call_hfi_pkt_op(device, session_get_property,
				&pkt, session, ptype);
	if (rc) {
		dprintk(VIDC_ERR, "get property profile: pkt failed\n");
		goto err_create_pkt;
	}

	if (venus_hfi_iface_cmdq_write(session->device, &pkt)) {
		rc = -ENOTEMPTY;
		dprintk(VIDC_ERR, "%s cmdq_write error\n", __func__);
@@ -2553,8 +2565,8 @@ static void *venus_hfi_session_init(void *device, void *session_id,

	venus_hfi_set_default_sys_properties(device);

	if (create_pkt_cmd_sys_session_init(&pkt, new_session,
				session_type, codec_type)) {
	if (call_hfi_pkt_op(dev, session_init, &pkt,
			new_session, session_type, codec_type)) {
		dprintk(VIDC_ERR, "session_init: failed to create packet\n");
		goto err_session_init_fail;
	}
@@ -2573,16 +2585,17 @@ static int venus_hfi_send_session_cmd(void *session_id,
{
	struct vidc_hal_session_cmd_pkt pkt;
	int rc = 0;
	struct hal_session *session;
	struct hal_session *session = session_id;
	struct venus_hfi_device *device;

	if (session_id) {
		session = session_id;
	} else {
	if (!session || !session->device) {
		dprintk(VIDC_ERR, "invalid session");
		return -ENODEV;
	}
	device = session->device;

	rc = create_pkt_cmd_session_cmd(&pkt, pkt_type, session);
	rc = call_hfi_pkt_op(device, session_cmd,
			&pkt, pkt_type, session);
	if (rc) {
		dprintk(VIDC_ERR, "send session cmd: create pkt failed\n");
		goto err_create_pkt;
@@ -2646,22 +2659,22 @@ static int venus_hfi_session_set_buffers(void *sess,
	struct hfi_cmd_session_set_buffers_packet *pkt;
	u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
	int rc = 0;
	struct hal_session *session;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;

	if (!sess || !buffer_info) {
	if (!session || !session->device || !buffer_info) {
		dprintk(VIDC_ERR, "Invalid Params\n");
		return -EINVAL;
	} else {
		session = sess;
	}
	device = session->device;

	if (buffer_info->buffer_type == HAL_BUFFER_INPUT)
		return 0;

	pkt = (struct hfi_cmd_session_set_buffers_packet *)packet;

	rc = create_pkt_cmd_session_set_buffers(pkt,
			session, buffer_info);
	rc = call_hfi_pkt_op(device, session_set_buffers,
			pkt, session, buffer_info);
	if (rc) {
		dprintk(VIDC_ERR, "set buffers: failed to create packet\n");
		goto err_create_pkt;
@@ -2681,18 +2694,21 @@ static int venus_hfi_session_release_buffers(void *sess,
	u8 packet[VIDC_IFACEQ_VAR_LARGE_PKT_SIZE];
	int rc = 0;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;

	if (!session || !buffer_info) {
	if (!session || !session->device || !buffer_info) {
		dprintk(VIDC_ERR, "Invalid Params\n");
		return -EINVAL;
	}
	device = session->device;

	if (buffer_info->buffer_type == HAL_BUFFER_INPUT)
		return 0;

	pkt = (struct hfi_cmd_session_release_buffer_packet *) packet;

	rc = create_pkt_cmd_session_release_buffers(pkt, session, buffer_info);
	rc = call_hfi_pkt_op(device, session_release_buffers,
			pkt, session, buffer_info);
	if (rc) {
		dprintk(VIDC_ERR, "release buffers: failed to create packet\n");
		goto err_create_pkt;
@@ -2733,20 +2749,20 @@ static int venus_hfi_session_etb(void *sess,
				struct vidc_frame_data *input_frame)
{
	int rc = 0;
	struct hal_session *session;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;

	if (!sess || !input_frame) {
	if (!session || !session->device || !input_frame) {
		dprintk(VIDC_ERR, "Invalid Params\n");
		return -EINVAL;
	} else {
		session = sess;
	}
	device = session->device;

	if (session->is_decoder) {
		struct hfi_cmd_session_empty_buffer_compressed_packet pkt;

		rc = create_pkt_cmd_session_etb_decoder(&pkt,
						session, input_frame);
		rc = call_hfi_pkt_op(device, session_etb_decoder,
				&pkt, session, input_frame);
		if (rc) {
			dprintk(VIDC_ERR,
			"Session etb decoder: failed to create pkt\n");
@@ -2759,8 +2775,9 @@ static int venus_hfi_session_etb(void *sess,
		struct hfi_cmd_session_empty_buffer_uncompressed_plane0_packet
			pkt;

		rc =  create_pkt_cmd_session_etb_encoder(&pkt,
						session, input_frame);

		rc = call_hfi_pkt_op(device, session_etb_encoder,
					 &pkt, session, input_frame);
		if (rc) {
			dprintk(VIDC_ERR,
			"Session etb encoder: failed to create pkt\n");
@@ -2779,16 +2796,17 @@ static int venus_hfi_session_ftb(void *sess,
{
	struct hfi_cmd_session_fill_buffer_packet pkt;
	int rc = 0;
	struct hal_session *session;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;

	if (!sess || !output_frame) {
	if (!session || !session->device || !output_frame) {
		dprintk(VIDC_ERR, "Invalid Params\n");
		return -EINVAL;
	} else {
		session = sess;
	}
	device = session->device;

	rc = create_pkt_cmd_session_ftb(&pkt, session, output_frame);
	rc = call_hfi_pkt_op(device, session_ftb,
			&pkt, session, output_frame);
	if (rc) {
		dprintk(VIDC_ERR, "Session ftb: failed to create pkt\n");
		goto err_create_pkt;
@@ -2806,18 +2824,19 @@ static int venus_hfi_session_parse_seq_hdr(void *sess,
	struct hfi_cmd_session_parse_sequence_header_packet *pkt;
	int rc = 0;
	u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
	struct hal_session *session;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;

	if (!sess || !seq_hdr) {
	if (!session || !session->device || !seq_hdr) {
		dprintk(VIDC_ERR, "Invalid Params\n");
		return -EINVAL;
	} else {
		session = sess;
	}
	device = session->device;

	pkt = (struct hfi_cmd_session_parse_sequence_header_packet *) packet;

	rc = create_pkt_cmd_session_parse_seq_header(pkt, session, seq_hdr);
	rc = call_hfi_pkt_op(device, session_parse_seq_header,
			pkt, session, seq_hdr);
	if (rc) {
		dprintk(VIDC_ERR,
		"Session parse seq hdr: failed to create pkt\n");
@@ -2836,17 +2855,19 @@ static int venus_hfi_session_get_seq_hdr(void *sess,
	struct hfi_cmd_session_get_sequence_header_packet *pkt;
	int rc = 0;
	u8 packet[VIDC_IFACEQ_VAR_SMALL_PKT_SIZE];
	struct hal_session *session;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;

	if (!sess || !seq_hdr) {
	if (!session || !session->device || !seq_hdr) {
		dprintk(VIDC_ERR, "Invalid Params\n");
		return -EINVAL;
	} else {
		session = sess;
	}
	device = session->device;

	pkt = (struct hfi_cmd_session_get_sequence_header_packet *) packet;
	rc = create_pkt_cmd_session_get_seq_hdr(pkt, session, seq_hdr);

	rc = call_hfi_pkt_op(device, session_get_seq_hdr,
			pkt, session, seq_hdr);
	if (rc) {
		dprintk(VIDC_ERR,
				"Session get seq hdr: failed to create pkt\n");
@@ -2863,16 +2884,17 @@ static int venus_hfi_session_get_buf_req(void *sess)
{
	struct hfi_cmd_session_get_property_packet pkt;
	int rc = 0;
	struct hal_session *session;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;

	if (sess) {
		session = sess;
	} else {
	if (!session || !session->device) {
		dprintk(VIDC_ERR, "invalid session");
		return -ENODEV;
	}
	device = session->device;

	rc = create_pkt_cmd_session_get_buf_req(&pkt, session);
	rc = call_hfi_pkt_op(device, session_get_buf_req,
			&pkt, session);
	if (rc) {
		dprintk(VIDC_ERR,
				"Session get buf req: failed to create pkt\n");
@@ -2889,16 +2911,17 @@ static int venus_hfi_session_flush(void *sess, enum hal_flush flush_mode)
{
	struct hfi_cmd_session_flush_packet pkt;
	int rc = 0;
	struct hal_session *session;
	struct hal_session *session = sess;
	struct venus_hfi_device *device;

	if (sess) {
		session = sess;
	} else {
	if (!session || !session->device) {
		dprintk(VIDC_ERR, "invalid session");
		return -ENODEV;
	}
	device = session->device;

	rc = create_pkt_cmd_session_flush(&pkt, session, flush_mode);
	rc = call_hfi_pkt_op(device, session_flush,
			&pkt, session, flush_mode);
	if (rc) {
		dprintk(VIDC_ERR, "Session flush: failed to create pkt\n");
		goto err_create_pkt;
@@ -2973,16 +2996,14 @@ static int venus_hfi_core_pc_prep(void *device)
{
	struct hfi_cmd_sys_pc_prep_packet pkt;
	int rc = 0;
	struct venus_hfi_device *dev;
	struct venus_hfi_device *dev = device;

	if (device) {
		dev = device;
	} else {
	if (!dev) {
		dprintk(VIDC_ERR, "invalid device\n");
		return -ENODEV;
	}

	rc = create_pkt_cmd_sys_pc_prep(&pkt);
	rc = call_hfi_pkt_op(dev, sys_pc_prep, &pkt);
	if (rc) {
		dprintk(VIDC_ERR, "Failed to create sys pc prep pkt\n");
		goto err_create_pkt;
@@ -4104,6 +4125,62 @@ int venus_hfi_get_core_capabilities(void)
	return rc;
}

static int venus_hfi_initialize_packetization(struct venus_hfi_device *device)
{
	int major_version;
	enum hfi_packetization_type packetization_type;
	int rc = 0;

	if (!device) {
		dprintk(VIDC_ERR, "%s - invalid param\n", __func__);
		return -EINVAL;
	}

	rc = venus_hfi_enable_regulators(device);
	if (rc) {
		dprintk(VIDC_ERR, "Failed to enable GDSC in %s Err code = %d\n",
			__func__, rc);
		goto exit;
	}

	rc = venus_hfi_prepare_enable_clks(device);
	if (rc) {
		dprintk(VIDC_ERR, "Failed to enable clocks\n");
		goto exit;
	}

	rc = venus_hfi_read_register(device, VIDC_WRAPPER_HW_VERSION);
	major_version = (rc & VIDC_WRAPPER_HW_VERSION_MAJOR_VERSION_MASK) >>
			VIDC_WRAPPER_HW_VERSION_MAJOR_VERSION_SHIFT;

	venus_hfi_disable_unprepare_clks(device);

	rc = venus_hfi_disable_regulators(device);
	if (rc) {
		dprintk(VIDC_ERR, "Failed to disable gdsc\n");
		goto exit;
	}

	dprintk(VIDC_DBG, "VENUS H/w Version is %d.%d.%d\n",
		major_version,
		(rc & VIDC_WRAPPER_HW_VERSION_MINOR_VERSION_MASK) >>
		VIDC_WRAPPER_HW_VERSION_MINOR_VERSION_SHIFT,
		rc & VIDC_WRAPPER_HW_VERSION_STEP_VERSION_MASK);

	if (major_version <= 2)
		packetization_type = HFI_PACKETIZATION_LEGACY;
	else
		packetization_type = HFI_PACKETIZATION_3XX;

	device->pkt_ops = hfi_get_pkt_ops_handle(packetization_type);
	if (!device->pkt_ops) {
		rc = -EINVAL;
		dprintk(VIDC_ERR, "Failed to get pkt_ops handle\n");
	}
exit:
	return rc;
}

static void *venus_hfi_add_device(u32 device_id,
			struct msm_vidc_platform_resources *res,
			hfi_cmd_response_callback callback)
@@ -4190,6 +4267,12 @@ static void *venus_hfi_get_device(u32 device_id,
			dprintk(VIDC_ERR, "Failed to init resources: %d\n", rc);
		goto err_fail_init_res;
	}

	rc = venus_hfi_initialize_packetization(device);
	if (rc) {
		dprintk(VIDC_ERR, "Failed to initialize packetization\n");
		goto err_fail_init_res;
	}
	return device;

err_fail_init_res:
Loading