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

Commit f3c107a5 authored by Jilai Wang's avatar Jilai Wang
Browse files

msm: npu: Use worker thread to load NPU firmware



Load NPU firmware will be done during system boot up time and
it takes hundreds ms. To avoid increase system boot up time,
use worker thread to load it.

Change-Id: I93401891d2922d17755fe13328f746680a90fec7
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent abd143e1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -320,7 +320,7 @@ static ssize_t boot_store(struct device *dev,
			return rc;
		}
	} else {
		NPU_INFO("%s: unload fw\n", __func__);
		NPU_DBG("%s: unload fw\n", __func__);
		unload_fw(npu_dev);
	}

+27 −10
Original line number Diff line number Diff line
@@ -150,20 +150,36 @@ static int load_fw_nolock(struct npu_device *npu_dev, bool enable)
	return ret;
}

static void npu_load_fw_work(struct work_struct *work)
{
	int ret;
	struct npu_host_ctx *host_ctx;
	struct npu_device *npu_dev;

	host_ctx = container_of(work, struct npu_host_ctx, load_fw_work);
	npu_dev = container_of(host_ctx, struct npu_device, host_ctx);

	mutex_lock(&host_ctx->lock);
	ret = load_fw_nolock(npu_dev, false);
	mutex_unlock(&host_ctx->lock);

	if (ret)
		NPU_ERR("load fw failed %d\n", ret);
}

int load_fw(struct npu_device *npu_dev)
{
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	int ret = 0;

	if (host_ctx->auto_pil_disable) {
		NPU_WARN("auto pil is disabled\n");
		return ret;
		return -EINVAL;
	}
	mutex_lock(&host_ctx->lock);
	ret = load_fw_nolock(npu_dev, false);
	mutex_unlock(&host_ctx->lock);

	return ret;
	if (host_ctx->wq)
		queue_work(host_ctx->wq, &host_ctx->load_fw_work);

	return 0;
}

int unload_fw(struct npu_device *npu_dev)
@@ -545,6 +561,7 @@ int npu_host_init(struct npu_device *npu_dev)
		INIT_WORK(&host_ctx->ipc_irq_work, npu_ipc_irq_work);
		INIT_WORK(&host_ctx->wdg_err_irq_work, npu_wdg_err_irq_work);
		INIT_WORK(&host_ctx->bridge_mbox_work, npu_bridge_mbox_work);
		INIT_WORK(&host_ctx->load_fw_work, npu_load_fw_work);
		INIT_DELAYED_WORK(&host_ctx->disable_fw_work,
			npu_disable_fw_work);
	}
@@ -821,10 +838,6 @@ static void npu_bridge_mbox_work(struct work_struct *work)
	host_ctx = container_of(work, struct npu_host_ctx, bridge_mbox_work);
	npu_dev = container_of(host_ctx, struct npu_device, host_ctx);

	/* queue or modify delayed work to disable fw */
	mod_delayed_work(host_ctx->wq, &host_ctx->disable_fw_work,
		NPU_MBOX_IDLE_TIMEOUT);

	mutex_lock(&host_ctx->lock);
	if (host_ctx->fw_state == FW_UNLOADED) {
		NPU_WARN("NPU fw is not loaded\n");
@@ -832,6 +845,10 @@ static void npu_bridge_mbox_work(struct work_struct *work)
		return;
	}

	/* queue or modify delayed work to disable fw */
	mod_delayed_work(host_ctx->wq, &host_ctx->disable_fw_work,
		NPU_MBOX_IDLE_TIMEOUT);

	if (!host_ctx->bridge_mbox_pwr_on) {
		ret = enable_fw_nolock(npu_dev);
		if (ret) {
+1 −0
Original line number Diff line number Diff line
@@ -77,6 +77,7 @@ struct npu_host_ctx {
	struct work_struct ipc_irq_work;
	struct work_struct wdg_err_irq_work;
	struct work_struct bridge_mbox_work;
	struct work_struct load_fw_work;
	struct delayed_work disable_fw_work;
	struct workqueue_struct *wq;
	struct completion misc_cmd_done;