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

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

Merge "drivers/misc/hdcp: load HDCP SRM app" into dev/msm-4.14-display

parents 875b97f6 3f81a442
Loading
Loading
Loading
Loading
+111 −93
Original line number Diff line number Diff line
@@ -33,8 +33,9 @@

#include "qseecom_kernel.h"

#define TZAPP_NAME            "hdcp2p2"
#define HDCP2P2_APP_NAME      "hdcp2p2"
#define HDCP1_APP_NAME        "hdcp1"
#define HDCPSRM_APP_NAME      "hdcpsrm"
#define QSEECOM_SBUFF_SIZE    0x1000

#define MAX_TX_MESSAGE_SIZE	129
@@ -141,7 +142,8 @@
	struct hdcp_##x##_rsp *rsp_buf = NULL; \
	if (!handle->qseecom_handle) { \
		pr_err("invalid qseecom_handle while processing %s\n", #x); \
		return -EINVAL; \
		rc = -EINVAL; \
		goto error; \
	} \
	req_buf = (struct hdcp_##x##_req *) handle->qseecom_handle->sbuf; \
	rsp_buf = (struct hdcp_##x##_rsp *) (handle->qseecom_handle->sbuf + \
@@ -454,6 +456,7 @@ struct hdcp2_handle {
	bool feature_supported;
	enum hdcp_state hdcp_state;
	struct qseecom_handle *qseecom_handle;
	struct qseecom_handle *hdcpsrm_qseecom_handle;
	uint32_t session_id;
	bool legacy_app;
	uint32_t device_type;
@@ -566,12 +569,12 @@ static int hdcp_get_version(struct hdcp2_handle *handle)

	if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
		pr_err("library already loaded\n");
		return rc;
		goto error;
	}

	rc = hdcp2_app_process_cmd(version);
	if (rc)
		goto exit;
		goto error;

	app_major_version = HCDP_TXMTR_GET_MAJOR_VERSION(rsp_buf->appversion);

@@ -580,7 +583,7 @@ static int hdcp_get_version(struct hdcp2_handle *handle)

	if (app_major_version == 1)
		handle->legacy_app = true;
exit:
error:
	return rc;
}

@@ -592,20 +595,21 @@ static int hdcp2_app_init_legacy(struct hdcp2_handle *handle)

	if (!handle->legacy_app) {
		pr_err("wrong init function\n");
		goto exit;
		rc = -EINVAL;
		goto error;
	}

	if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
		pr_err("library already loaded\n");
		goto exit;
		goto error;
	}

	rc = hdcp2_app_process_cmd(init_v1);
	if (rc)
		goto exit;
		goto error;

	pr_debug("success\n");
exit:
error:
	return rc;
}

@@ -618,12 +622,13 @@ static int hdcp2_app_init(struct hdcp2_handle *handle)

	if (handle->legacy_app) {
		pr_err("wrong init function\n");
		goto exit;
		rc = -EINVAL;
		goto error;
	}

	if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
		pr_err("library already loaded\n");
		goto exit;
		goto error;
	}

	req_buf->clientversion =
@@ -633,7 +638,7 @@ static int hdcp2_app_init(struct hdcp2_handle *handle)

	rc = hdcp2_app_process_cmd(init);
	if (rc)
		goto exit;
		goto error;

	app_minor_version = HCDP_TXMTR_GET_MINOR_VERSION(rsp_buf->appversion);
	if (app_minor_version != HDCP_CLIENT_MINOR_VERSION) {
@@ -641,7 +646,7 @@ static int hdcp2_app_init(struct hdcp2_handle *handle)
		    ("client-app minor version mismatch app(%d), client(%d)\n",
		     app_minor_version, HDCP_CLIENT_MINOR_VERSION);
		rc = -1;
		goto exit;
		goto error;
	}

	pr_debug("success\n");
@@ -654,7 +659,7 @@ static int hdcp2_app_init(struct hdcp2_handle *handle)
		 HCDP_TXMTR_GET_MAJOR_VERSION(rsp_buf->appversion),
		 HCDP_TXMTR_GET_MINOR_VERSION(rsp_buf->appversion),
		 HCDP_TXMTR_GET_PATCH_VERSION(rsp_buf->appversion));
exit:
error:
	return rc;
}

@@ -666,25 +671,26 @@ static int hdcp2_app_tx_init(struct hdcp2_handle *handle)

	if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
		pr_err("session not initialized\n");
		goto exit;
		rc = -EINVAL;
		goto error;
	}

	if (handle->hdcp_state & HDCP_STATE_TXMTR_INIT) {
		pr_err("txmtr already initialized\n");
		goto exit;
		goto error;
	}

	req_buf->sessionid = handle->session_id;

	rc = hdcp2_app_process_cmd(tx_init);
	if (rc)
		goto exit;
		goto error;

	handle->tz_ctxhandle = rsp_buf->ctxhandle;
	handle->hdcp_state |= HDCP_STATE_TXMTR_INIT;

	pr_debug("success\n");
exit:
error:
	return rc;
}

@@ -696,17 +702,18 @@ static int hdcp2_app_tx_init_legacy(struct hdcp2_handle *handle)

	if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
		pr_err("app not loaded\n");
		goto exit;
		rc = -EINVAL;
		goto error;
	}

	if (handle->hdcp_state & HDCP_STATE_TXMTR_INIT) {
		pr_err("txmtr already initialized\n");
		goto exit;
		goto error;
	}

	rc = hdcp2_app_process_cmd(tx_init_v1);
	if (rc)
		goto exit;
		goto error;

	handle->app_data.response.data = rsp_buf->message;
	handle->app_data.response.length = rsp_buf->msglen;
@@ -716,7 +723,7 @@ static int hdcp2_app_tx_init_legacy(struct hdcp2_handle *handle)
	handle->hdcp_state |= HDCP_STATE_TXMTR_INIT;

	pr_debug("success\n");
exit:
error:
	return rc;
}

@@ -726,19 +733,27 @@ static int hdcp2_app_load(struct hdcp2_handle *handle)

	if (!handle) {
		pr_err("invalid input\n");
		goto exit;
		rc = -EINVAL;
		goto error;
	}

	if (handle->hdcp_state & HDCP_STATE_APP_LOADED) {
		pr_err("library already loaded\n");
		goto exit;
		goto error;
	}

	rc = qseecom_start_app(&handle->qseecom_handle,
		 TZAPP_NAME, QSEECOM_SBUFF_SIZE);
		 HDCP2P2_APP_NAME, QSEECOM_SBUFF_SIZE);
	if (rc) {
		pr_err("qseecom_start_app failed %d\n", rc);
		goto exit;
		pr_err("qseecom_start_app failed for HDCP2P2 (%d)\n", rc);
		goto error;
	}

	rc = qseecom_start_app(&handle->hdcpsrm_qseecom_handle,
		 HDCPSRM_APP_NAME, QSEECOM_SBUFF_SIZE);
	if (rc) {
		pr_err("qseecom_start_app failed for HDCPSRM (%d)\n", rc);
		goto hdcpsrm_error;
	}

	pr_debug("qseecom_start_app success\n");
@@ -746,7 +761,7 @@ static int hdcp2_app_load(struct hdcp2_handle *handle)
	rc = hdcp_get_version(handle);
	if (rc) {
		pr_err("library get version failed\n");
		goto exit;
		goto get_version_error;
	}

	if (handle->legacy_app) {
@@ -757,19 +772,20 @@ static int hdcp2_app_load(struct hdcp2_handle *handle)
		handle->tx_init = hdcp2_app_tx_init;
	}

	if (handle->app_init == NULL) {
		pr_err("invalid app init function pointer\n");
		goto exit;
	}

	rc = handle->app_init(handle);
	if (rc) {
		pr_err("app init failed\n");
		goto exit;
		goto get_version_error;
	}

	handle->hdcp_state |= HDCP_STATE_APP_LOADED;
exit:

	return rc;
get_version_error:
	qseecom_shutdown_app(&handle->hdcpsrm_qseecom_handle);
hdcpsrm_error:
	qseecom_shutdown_app(&handle->qseecom_handle);
error:
	return rc;
}

@@ -779,20 +795,26 @@ static int hdcp2_app_unload(struct hdcp2_handle *handle)

	hdcp2_app_init_var(deinit);

	rc = hdcp2_app_process_cmd(deinit);
	hdcp2_app_process_cmd(deinit);

	/* deallocate the resources for qseecom HDCPSRM handle */
	rc = qseecom_shutdown_app(&handle->hdcpsrm_qseecom_handle);
	if (rc)
		goto exit;
		pr_err("qseecom_shutdown_app failed for HDCPSRM (%d)\n", rc);

	/* deallocate the resources for qseecom handle */
	/* deallocate the resources for qseecom HDCP2P2 handle */
	rc = qseecom_shutdown_app(&handle->qseecom_handle);
	if (rc) {
		pr_err("qseecom_shutdown_app failed err: %d\n", rc);
		goto exit;
		pr_err("qseecom_shutdown_app failed for HDCP2P2 (%d)\n", rc);
		return rc;
	}

	handle->hdcp_state &= ~HDCP_STATE_APP_LOADED;
	pr_debug("success\n");
exit:

	return rc;
error:
	qseecom_shutdown_app(&handle->hdcpsrm_qseecom_handle);
	return rc;
}

@@ -804,12 +826,13 @@ bool hdcp2_feature_supported(void *data)

	if (!handle) {
		pr_err("invalid input\n");
		goto exit;
		rc = -EINVAL;
		goto error;
	}

	if (handle->feature_supported) {
		supported = true;
		goto exit;
		goto error;
	}

	rc = hdcp2_app_load(handle);
@@ -821,7 +844,7 @@ bool hdcp2_feature_supported(void *data)
		hdcp2_app_unload(handle);
		supported = true;
	}
exit:
error:
	return supported;
}

@@ -834,25 +857,25 @@ static int hdcp2_app_session_init(struct hdcp2_handle *handle)
	if (!handle->qseecom_handle || !handle->qseecom_handle->sbuf) {
		pr_err("invalid handle\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
		pr_err("app not loaded\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	if (handle->hdcp_state & HDCP_STATE_SESSION_INIT) {
		pr_err("session already initialized\n");
		goto exit;
		goto error;
	}

	req_buf->deviceid = handle->device_type;

	rc = hdcp2_app_process_cmd(session_init);
	if (rc)
		goto exit;
		goto error;

	pr_debug("session id %d\n", rsp_buf->sessionid);

@@ -860,7 +883,7 @@ static int hdcp2_app_session_init(struct hdcp2_handle *handle)
	handle->hdcp_state |= HDCP_STATE_SESSION_INIT;

	pr_debug("success\n");
exit:
error:
	return rc;
}

@@ -873,25 +896,24 @@ static int hdcp2_app_session_deinit(struct hdcp2_handle *handle)
	if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
		pr_err("app not loaded\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
		/* unload library here */
		pr_err("session not initialized\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	req_buf->sessionid = handle->session_id;

	rc = hdcp2_app_process_cmd(session_deinit);
	if (rc)
		goto exit;
		goto error;

	handle->hdcp_state &= ~HDCP_STATE_SESSION_INIT;
	pr_debug("success\n");
exit:
error:
	return rc;
}

@@ -904,25 +926,24 @@ static int hdcp2_app_tx_deinit(struct hdcp2_handle *handle)
	if (!(handle->hdcp_state & HDCP_STATE_APP_LOADED)) {
		pr_err("app not loaded\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	if (!(handle->hdcp_state & HDCP_STATE_TXMTR_INIT)) {
		/* unload library here */
		pr_err("txmtr not initialized\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	req_buf->ctxhandle = handle->tz_ctxhandle;

	rc = hdcp2_app_process_cmd(tx_deinit);
	if (rc)
		goto exit;
		goto error;

	handle->hdcp_state &= ~HDCP_STATE_TXMTR_INIT;
	pr_debug("success\n");
exit:
error:
	return rc;
}

@@ -935,20 +956,20 @@ static int hdcp2_app_start_auth(struct hdcp2_handle *handle)
	if (!(handle->hdcp_state & HDCP_STATE_SESSION_INIT)) {
		pr_err("session not initialized\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	if (!(handle->hdcp_state & HDCP_STATE_TXMTR_INIT)) {
		pr_err("txmtr not initialized\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	req_buf->ctxHandle = handle->tz_ctxhandle;

	rc = hdcp2_app_process_cmd(start_auth);
	if (rc)
		goto exit;
		goto error;

	handle->app_data.response.data = rsp_buf->message;
	handle->app_data.response.length = rsp_buf->msglen;
@@ -957,7 +978,7 @@ static int hdcp2_app_start_auth(struct hdcp2_handle *handle)
	handle->tz_ctxhandle = rsp_buf->ctxhandle;

	pr_debug("success\n");
exit:
error:
	return rc;
}

@@ -967,30 +988,27 @@ static int hdcp2_app_start(struct hdcp2_handle *handle)

	rc = hdcp2_app_load(handle);
	if (rc)
		goto exit;
		goto error;

	if (!handle->legacy_app) {
		rc = hdcp2_app_session_init(handle);
		if (rc)
			goto exit;
			goto error;
	}

	if (handle->tx_init == NULL) {
		pr_err("invalid txmtr init function pointer\n");
		rc = -EINVAL;
		goto exit;
		goto error;
	}

	rc = handle->tx_init(handle);
	if (rc)
		goto exit;
		goto error;

	if (!handle->legacy_app) {
	if (!handle->legacy_app)
		rc = hdcp2_app_start_auth(handle);
		if (rc)
			goto exit;
	}
exit:
error:
	return rc;
}

@@ -1021,7 +1039,8 @@ static int hdcp2_app_process_msg(struct hdcp2_handle *handle)

	if (!handle->app_data.request.data) {
		pr_err("invalid request buffer\n");
		return -EINVAL;
		rc = -EINVAL;
		goto error;
	}

	req_buf->msglen = handle->app_data.request.length;
@@ -1029,7 +1048,7 @@ static int hdcp2_app_process_msg(struct hdcp2_handle *handle)

	rc = hdcp2_app_process_cmd(rcvd_msg);
	if (rc)
		goto exit;
		goto error;

	/* check if it's a repeater */
	if (rsp_buf->flag == HDCP_TXMTR_SUBSTATE_WAITING_FOR_RECIEVERID_LIST)
@@ -1040,7 +1059,7 @@ static int hdcp2_app_process_msg(struct hdcp2_handle *handle)
	handle->app_data.response.data = rsp_buf->msg;
	handle->app_data.response.length = rsp_buf->msglen;
	handle->app_data.timeout = rsp_buf->timeout;
exit:
error:
	return rc;
}

@@ -1052,12 +1071,12 @@ static int hdcp2_app_timeout(struct hdcp2_handle *handle)

	rc = hdcp2_app_process_cmd(send_timeout);
	if (rc)
		goto exit;
		goto error;

	handle->app_data.response.data = rsp_buf->message;
	handle->app_data.response.length = rsp_buf->msglen;
	handle->app_data.timeout = rsp_buf->timeout;
exit:
error:
	return rc;
}

@@ -1069,7 +1088,7 @@ static int hdcp2_app_enable_encryption(struct hdcp2_handle *handle)

	/*
	 * wait at least 200ms before enabling encryption
	 * as per hdcp2p2 sepcifications.
	 * as per hdcp2p2 specifications.
	 */
	msleep(SLEEP_SET_HW_KEY_MS);

@@ -1077,14 +1096,13 @@ static int hdcp2_app_enable_encryption(struct hdcp2_handle *handle)

	rc = hdcp2_app_process_cmd(set_hw_key);
	if (rc)
		goto exit;
		goto error;

	handle->hdcp_state |= HDCP_STATE_AUTHENTICATED;

	pr_debug("success\n");
	return 0;
exit:
	pr_err("failed, rc=%d\n", rc);
	return rc;
error:
	return rc;
}

@@ -1098,12 +1116,12 @@ static int hdcp2_app_query_stream(struct hdcp2_handle *handle)

	rc = hdcp2_app_process_cmd(query_stream_type);
	if (rc)
		goto exit;
		goto error;

	handle->app_data.response.data = rsp_buf->msg;
	handle->app_data.response.length = rsp_buf->msglen;
	handle->app_data.timeout = rsp_buf->timeout;
exit:
error:
	return rc;
}

@@ -1150,11 +1168,11 @@ int hdcp2_app_comm(void *ctx, enum hdcp2_app_cmd cmd,
	case HDCP2_CMD_STOP:
		rc = hdcp2_app_stop(handle);
	default:
		goto exit;
		goto error;
	}

	if (rc)
		goto exit;
		goto error;

	handle->app_data.request.data = hdcp2_get_recv_buf(handle);

@@ -1164,7 +1182,7 @@ int hdcp2_app_comm(void *ctx, enum hdcp2_app_cmd cmd,
	app_data->response.length = handle->app_data.response.length;
	app_data->timeout = handle->app_data.timeout;
	app_data->repeater_flag = handle->app_data.repeater_flag;
exit:
error:
	return rc;
}

@@ -1174,10 +1192,10 @@ void *hdcp2_init(u32 device_type)

	handle = kzalloc(sizeof(struct hdcp2_handle), GFP_KERNEL);
	if (!handle)
		goto exit;
		goto error;

	handle->device_type = device_type;
exit:
error:
	return handle;
}

@@ -1208,25 +1226,25 @@ bool hdcp1_feature_supported(void *data)

	if (!handle) {
		pr_err("invalid input\n");
		goto exit;
		goto error;
	}

	if (handle->feature_supported) {
		supported = true;
		goto exit;
		goto error;
	}

	rc = qseecom_start_app(&handle->qseecom_handle, HDCP1_APP_NAME,
			QSEECOM_SBUFF_SIZE);
	if (rc) {
		pr_err("qseecom_start_app failed %d\n", rc);
		goto exit;
		goto error;
	}

	pr_debug("HDCP 1.x supported\n");
	handle->feature_supported = true;
	supported = true;
exit:
error:
	return supported;
}