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

Commit 8d774dde authored by Jilai Wang's avatar Jilai Wang
Browse files

msm: npu: Support both auto and manual PIL



Add a debugfs node to enable/disable auto PIL. By default, it is
only enabled for Kona.

Change-Id: I13236e2f416c6679a79ecd3b6dc252f58108f17d
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent 8797d0cb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -242,6 +242,8 @@ struct npu_device {
	struct llcc_slice_desc *sys_cache;
	uint32_t execute_v2_flag;
	bool cxlimit_registered;

	uint32_t hw_version;
};

struct npu_kevent {
+6 −0
Original line number Diff line number Diff line
@@ -436,6 +436,12 @@ int npu_debugfs_init(struct npu_device *npu_dev)
		goto err;
	}

	if (!debugfs_create_bool("auto_pil_disable", 0644,
		debugfs->root, &(host_ctx->auto_pil_disable))) {
		NPU_ERR("debugfs_creat_bool fail for auto pil\n");
		goto err;
	}

	if (!debugfs_create_u32("fw_dbg_mode", 0644,
		debugfs->root, &(host_ctx->fw_dbg_mode))) {
		NPU_ERR("debugfs_create_u32 fail for fw_dbg_mode\n");
+21 −0
Original line number Diff line number Diff line
@@ -1670,6 +1670,23 @@ static void npu_mbox_deinit(struct npu_device *npu_dev)
	}
}

static int npu_hw_info_init(struct npu_device *npu_dev)
{
	int rc = 0;

	rc = npu_enable_core_power(npu_dev);
	if (rc) {
		NPU_ERR("Failed to enable power\n");
		return rc;
	}

	npu_dev->hw_version = REGR(npu_dev, NPU_HW_VERSION);
	NPU_DBG("NPU_HW_VERSION 0x%x\n", npu_dev->hw_version);
	npu_disable_core_power(npu_dev);

	return rc;
}

/* -------------------------------------------------------------------------
 * Probe/Remove
 * -------------------------------------------------------------------------
@@ -1810,6 +1827,10 @@ static int npu_probe(struct platform_device *pdev)
	if (rc)
		goto error_get_dev_num;

	rc = npu_hw_info_init(npu_dev);
	if (rc)
		goto error_get_dev_num;

	rc = npu_pwrctrl_init(npu_dev);
	if (rc)
		goto error_get_dev_num;
+45 −5
Original line number Diff line number Diff line
@@ -60,14 +60,14 @@ static int npu_queue_event(struct npu_client *client, struct npu_kevent *evt);
static int npu_notify_aop(struct npu_device *npu_dev, bool on);
static int npu_notify_fw_pwr_state(struct npu_device *npu_dev,
	uint32_t pwr_level, bool post);
static int load_fw_nolock(struct npu_device *npu_dev);
static int load_fw_nolock(struct npu_device *npu_dev, bool enable);
static void disable_fw_nolock(struct npu_device *npu_dev);

/* -------------------------------------------------------------------------
 * Function Definitions - Init / Deinit
 * -------------------------------------------------------------------------
 */
static int load_fw_nolock(struct npu_device *npu_dev)
static int load_fw_nolock(struct npu_device *npu_dev, bool enable)
{
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	int ret = 0;
@@ -98,6 +98,15 @@ static int load_fw_nolock(struct npu_device *npu_dev)
	NPU_DBG("firmware init complete\n");

	host_ctx->fw_state = FW_ENABLED;
	if (enable) {
		ret = npu_notify_fw_pwr_state(npu_dev,
			npu_dev->pwrctrl.active_pwrlevel, true);
		if (ret) {
			NPU_ERR("notify fw pwr on failed\n");
			goto load_fw_fail;
		}
		return ret;
	}

	reinit_completion(&host_ctx->fw_shutdown_done);
	ret = npu_notify_fw_pwr_state(npu_dev, NPU_PWRLEVEL_OFF, false);
@@ -119,6 +128,7 @@ static int load_fw_nolock(struct npu_device *npu_dev)
	npu_disable_irq(npu_dev);
	npu_disable_sys_cache(npu_dev);
	npu_disable_core_power(npu_dev);
	npu_notify_aop(npu_dev, false);
	if (!ret) {
		host_ctx->fw_state = FW_LOADED;
	} else {
@@ -135,8 +145,12 @@ 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;
	}
	mutex_lock(&host_ctx->lock);
	ret = load_fw_nolock(npu_dev);
	ret = load_fw_nolock(npu_dev, false);
	mutex_unlock(&host_ctx->lock);

	return ret;
@@ -146,6 +160,11 @@ int unload_fw(struct npu_device *npu_dev)
{
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;

	if (host_ctx->auto_pil_disable) {
		NPU_WARN("auto pil is disabled\n");
		return 0;
	}

	mutex_lock(&host_ctx->lock);
	if (host_ctx->fw_state == FW_UNLOADED) {
		NPU_INFO("fw is unloaded already\n");
@@ -173,12 +192,20 @@ int enable_fw(struct npu_device *npu_dev)
	mutex_lock(&host_ctx->lock);

	if (host_ctx->fw_state == FW_UNLOADED) {
		ret = load_fw_nolock(npu_dev);
		ret = load_fw_nolock(npu_dev,
			host_ctx->auto_pil_disable ? true : false);
		if (ret) {
			NPU_ERR("load fw failed\n");
			mutex_unlock(&host_ctx->lock);
			return ret;
		}

		if (host_ctx->auto_pil_disable) {
			host_ctx->fw_error = false;
			host_ctx->fw_ref_cnt++;
			mutex_unlock(&host_ctx->lock);
			goto enable_log;
		}
	}

	if (host_ctx->fw_state == FW_ENABLED) {
@@ -241,6 +268,7 @@ int enable_fw(struct npu_device *npu_dev)
	host_ctx->fw_ref_cnt++;
	mutex_unlock(&host_ctx->lock);

enable_log:
	/* Set logging state */
	if (!npu_hw_log_enabled()) {
		NPU_DBG("fw logging disabled\n");
@@ -289,7 +317,8 @@ static void disable_fw_nolock(struct npu_device *npu_dev)
		msleep(500);
	}

	if (!wait_for_completion_interruptible_timeout(
	if (!host_ctx->auto_pil_disable
		&& !wait_for_completion_interruptible_timeout(
		&host_ctx->fw_shutdown_done, NW_CMD_TIMEOUT))
		NPU_ERR("Wait for fw shutdown timedout\n");

@@ -301,6 +330,12 @@ static void disable_fw_nolock(struct npu_device *npu_dev)
	NPU_DBG("firmware is disabled\n");
	npu_notify_aop(npu_dev, false);
	complete(&host_ctx->fw_deinit_done);

	if (host_ctx->auto_pil_disable) {
		subsystem_put_local(host_ctx->subsystem_handle);
		host_ctx->fw_state = FW_UNLOADED;
		NPU_DBG("fw is unloaded\n");
	}
}

void disable_fw(struct npu_device *npu_dev)
@@ -491,6 +526,11 @@ int npu_host_init(struct npu_device *npu_dev)
		INIT_WORK(&host_ctx->wdg_err_irq_work, npu_wdg_err_irq_work);
	}

	if (npu_dev->hw_version != 0x20000000)
		host_ctx->auto_pil_disable = true;
	else
		host_ctx->auto_pil_disable = false;

	return sts;
}

+1 −0
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ struct npu_host_ctx {
	int32_t network_num;
	struct npu_network networks[MAX_LOADED_NETWORK];
	bool sys_cache_disable;
	bool auto_pil_disable;
	uint32_t fw_dbg_mode;
	uint32_t exec_flags_override;
	atomic_t ipc_trans_id;