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

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

msm: npu: Allocate ipc buffer during driver initialization



This change is to allocate ipc buffer during driver initialization
to improve the performance. It also increases the ipc buffer size
to the same as ipc queue size to avoid buffer overflow issue.

Change-Id: I41ebaf6830d2578aa5f5bc21304bf5616de04445
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent 13e878c8
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -236,6 +236,13 @@ static int ipc_queue_read(struct npu_device *npu_dev,
		status = -EPERM;
		goto exit;
	}

	if (packet_size > NPU_IPC_BUF_LENGTH) {
		NPU_ERR("Invalid packet size %d\n", packet_size);
		status = -EINVAL;
		goto exit;
	}

	new_read_idx = queue.qhdr_read_idx + packet_size;

	if (new_read_idx < (queue.qhdr_q_size)) {
+20 −1
Original line number Diff line number Diff line
@@ -590,12 +590,14 @@ int npu_host_init(struct npu_device *npu_dev)
	if (IS_ERR(host_ctx->notif_hdle)) {
		NPU_ERR("register event notification failed\n");
		sts = PTR_ERR(host_ctx->notif_hdle);
		return sts;
		host_ctx->notif_hdle = NULL;
		goto fail;
	}

	host_ctx->wq = create_workqueue("npu_irq_hdl");
	if (!host_ctx->wq) {
		sts = -EPERM;
		goto fail;
	} else {
		INIT_WORK(&host_ctx->ipc_irq_work, npu_ipc_irq_work);
		INIT_WORK(&host_ctx->wdg_err_irq_work, npu_wdg_err_irq_work);
@@ -606,8 +608,23 @@ int npu_host_init(struct npu_device *npu_dev)
			npu_disable_fw_work);
	}

	host_ctx->ipc_msg_buf = kzalloc(NPU_IPC_BUF_LENGTH, GFP_KERNEL);
	if (!host_ctx->ipc_msg_buf) {
		NPU_ERR("Failed to allocate ipc buffer\n");
		sts = -ENOMEM;
		goto fail;
	}

	host_ctx->auto_pil_disable = false;

	return sts;
fail:
	if (host_ctx->wq)
		destroy_workqueue(host_ctx->wq);
	if (host_ctx->notif_hdle)
		subsys_notif_unregister_notifier(host_ctx->notif_hdle,
			&host_ctx->nb);
	mutex_destroy(&host_ctx->lock);
	return sts;
}

@@ -615,7 +632,9 @@ void npu_host_deinit(struct npu_device *npu_dev)
{
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;

	kfree(host_ctx->ipc_msg_buf);
	destroy_workqueue(host_ctx->wq);
	subsys_notif_unregister_notifier(host_ctx->notif_hdle, &host_ctx->nb);
	mutex_destroy(&host_ctx->lock);
}

+2 −1
Original line number Diff line number Diff line
@@ -26,7 +26,7 @@
#define NPU_MBOX_IDLE_TIMEOUT msecs_to_jiffies(NPU_MBOX_IDLE_TIMEOUT_MS)
#define FIRMWARE_VERSION 0x00001000
#define MAX_LOADED_NETWORK 32
#define NPU_IPC_BUF_LENGTH 512
#define NPU_IPC_BUF_LENGTH 4096

#define FW_DBG_MODE_PAUSE        (1 << 0)
#define FW_DBG_MODE_INC_TIMEOUT  (1 << 1)
@@ -105,6 +105,7 @@ struct npu_host_ctx {
	void *notif_hdle;
	spinlock_t bridge_mbox_lock;
	bool bridge_mbox_pwr_on;
	void *ipc_msg_buf;
};

struct npu_device;