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

Commit 5f03e1ad authored by qctecmdr's avatar qctecmdr Committed by Gerrit - the friendly Code Review server
Browse files

Merge "msm: npu: Support enable/disable NPU via set_property"

parents b89c1f40 6aa2beaa
Loading
Loading
Loading
Loading
+27 −14
Original line number Diff line number Diff line
@@ -438,23 +438,20 @@ static ssize_t npu_store_fw_state(struct device *dev,
					  const char *buf, size_t count)
{
	struct npu_device *npu_dev = dev_get_drvdata(dev);
	struct npu_client client;
	bool enable = false;
	int rc;

	if (strtobool(buf, &enable) < 0)
		return -EINVAL;

	if (enable) {
		pr_debug("%s: fw init\n", __func__);
		rc = fw_init(npu_dev);
	client.npu_dev = npu_dev;
	rc = npu_set_fw_state(&client, enable ? 1 : 0);

	if (rc) {
			pr_err("fw init failed\n");
		pr_err("%s fw failed\n", enable ? "enable" : "disable");
		return rc;
	}
	} else {
		pr_debug("%s: fw deinit\n", __func__);
		fw_deinit(npu_dev, false, true);
	}

	return count;
}
@@ -1615,16 +1612,32 @@ static int npu_receive_event(struct npu_client *client,
static int npu_set_fw_state(struct npu_client *client, uint32_t enable)
{
	struct npu_device *npu_dev = client->npu_dev;
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	int rc = 0;

	if (host_ctx->network_num > 0) {
		pr_err("Need to unload network first\n");
		mutex_unlock(&npu_dev->dev_lock);
		return -EINVAL;
	}

	if (enable) {
		pr_debug("%s: enable fw\n", __func__);
		pr_debug("enable fw\n");
		rc = fw_init(npu_dev);
		if (rc)
		if (rc) {
			pr_err("enable fw failed\n");
		} else {
		pr_debug("%s: disable fw\n", __func__);
			host_ctx->npu_init_cnt++;
			pr_debug("npu_init_cnt %d\n",
				host_ctx->npu_init_cnt);
		}
	} else if (host_ctx->npu_init_cnt > 0) {
		pr_debug("disable fw\n");
		fw_deinit(npu_dev, false, true);
		host_ctx->npu_init_cnt--;
		pr_debug("npu_init_cnt %d\n", host_ctx->npu_init_cnt);
	} else {
		pr_err("can't disable fw %d\n", host_ctx->npu_init_cnt);
	}

	return rc;
+11 −3
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ int fw_init(struct npu_device *npu_dev)
	mutex_lock(&host_ctx->lock);
	if (host_ctx->fw_state == FW_ENABLED) {
		host_ctx->fw_ref_cnt++;
		pr_debug("fw_ref_cnt %d\n", host_ctx->fw_ref_cnt);
		mutex_unlock(&host_ctx->lock);
		return 0;
	}
@@ -178,6 +179,7 @@ int fw_init(struct npu_device *npu_dev)

	mutex_unlock(&host_ctx->lock);
	pr_debug("firmware init complete\n");
	pr_debug("fw_ref_cnt %d\n", host_ctx->fw_ref_cnt);

	/* Set logging state */
	if (!npu_hw_log_enabled()) {
@@ -928,6 +930,8 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
			prop_rsp_pkt->prop_id,
			param[0]);

		host_ctx->cmd_ret_status = prop_rsp_pkt->header.status;

		complete_all(&host_ctx->property_done);
		break;
	}
@@ -1314,10 +1318,12 @@ int32_t npu_host_set_fw_property(struct npu_device *npu_dev,
	} else if (ret < 0) {
		pr_err("Wait for set_property done interrupted by signal\n");
		goto set_prop_exit;
	} else if (ret > 0) {
		ret = 0;
	}

	ret = host_ctx->cmd_ret_status;
	if (ret)
		pr_err("set fw property failed %d\n", ret);

set_prop_exit:
	kfree(prop_packet);
	return ret;
@@ -1334,7 +1340,7 @@ int32_t npu_host_get_fw_property(struct npu_device *npu_dev,

	num_of_params = min_t(uint32_t, property->num_of_params,
		(uint32_t)PROP_PARAM_MAX_SIZE);
	pkt_size = sizeof(*prop_packet);
	pkt_size = sizeof(*prop_packet) + num_of_params * sizeof(uint32_t);
	prop_packet = kzalloc(pkt_size, GFP_KERNEL);

	if (!prop_packet)
@@ -1349,6 +1355,8 @@ int32_t npu_host_get_fw_property(struct npu_device *npu_dev,
	prop_packet->prop_id = property->prop_id;
	prop_packet->num_params = num_of_params;
	prop_packet->network_hdl = property->network_hdl;
	for (i = 0; i < num_of_params; i++)
		prop_packet->prop_param[i] = property->prop_param[i];

	reinit_completion(&host_ctx->property_done);
	ret = npu_send_misc_cmd(npu_dev, IPC_QUEUE_APPS_EXEC,
+1 −0
Original line number Diff line number Diff line
@@ -78,6 +78,7 @@ struct npu_host_ctx {
	struct npu_device *npu_dev;
	enum fw_state fw_state;
	int32_t fw_ref_cnt;
	int32_t npu_init_cnt;
	int32_t power_vote_num;
	struct work_struct irq_work;
	struct delayed_work fw_deinit_work;