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

Commit f4c81064 authored by Jilai Wang's avatar Jilai Wang Committed by Gerrit - the friendly Code Review server
Browse files

msm: npu: fix driver warnings



This change is to fix warnings generated when running sparse check.

Change-Id: I67bc66d1fc6d3fe39cd3d566e00b67e14e61bb7d
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent 7fbe930d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -246,7 +246,8 @@ struct npu_device {
struct npu_kevent {
	struct list_head list;
	struct msm_npu_event evt;
	uint64_t reserved[4];
	void *stats_buf;
	void __user *stats_buf_u;
};

struct npu_client {
+1 −194
Original line number Diff line number Diff line
@@ -27,14 +27,6 @@
 */
static int npu_debug_open(struct inode *inode, struct file *file);
static int npu_debug_release(struct inode *inode, struct file *file);
static int npu_debug_reg_open(struct inode *inode, struct file *file);
static int npu_debug_reg_release(struct inode *inode, struct file *file);
static ssize_t npu_debug_reg_read(struct file *file,
		char __user *user_buf, size_t count, loff_t *ppos);
static ssize_t npu_debug_off_write(struct file *file,
		const char __user *user_buf, size_t count, loff_t *ppos);
static ssize_t npu_debug_off_read(struct file *file,
		char __user *user_buf, size_t count, loff_t *ppos);
static ssize_t npu_debug_log_read(struct file *file,
		char __user *user_buf, size_t count, loff_t *ppos);
static ssize_t npu_debug_ctrl_write(struct file *file,
@@ -44,20 +36,7 @@ static ssize_t npu_debug_ctrl_write(struct file *file,
 * Variables
 * -------------------------------------------------------------------------
 */
struct npu_device *g_npu_dev;

static const struct file_operations npu_reg_fops = {
	.open = npu_debug_reg_open,
	.release = npu_debug_reg_release,
	.read = npu_debug_reg_read,
};

static const struct file_operations npu_off_fops = {
	.open = npu_debug_open,
	.release = npu_debug_release,
	.read = npu_debug_off_read,
	.write = npu_debug_off_write,
};
static struct npu_device *g_npu_dev;

static const struct file_operations npu_log_fops = {
	.open = npu_debug_open,
@@ -90,166 +69,6 @@ static int npu_debug_release(struct inode *inode, struct file *file)
	return 0;
}

static int npu_debug_reg_open(struct inode *inode, struct file *file)
{
	struct npu_debugfs_reg_ctx *reg_ctx;

	reg_ctx = kzalloc(sizeof(*reg_ctx), GFP_KERNEL);
	if (!reg_ctx)
		return -ENOMEM;

	/* non-seekable */
	file->f_mode &= ~(FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE);
	reg_ctx->npu_dev = inode->i_private;
	file->private_data = reg_ctx;
	return 0;
}

static int npu_debug_reg_release(struct inode *inode, struct file *file)
{
	struct npu_debugfs_reg_ctx *reg_ctx = file->private_data;

	kfree(reg_ctx->buf);
	kfree(reg_ctx);
	file->private_data = NULL;
	return 0;
}

/* -------------------------------------------------------------------------
 * Function Implementations - Reg Read/Write
 * -------------------------------------------------------------------------
 */
static ssize_t npu_debug_reg_read(struct file *file,
			char __user *user_buf, size_t count, loff_t *ppos)
{
	struct npu_debugfs_reg_ctx *reg_ctx = file->private_data;
	struct npu_device *npu_dev = reg_ctx->npu_dev;
	struct npu_debugfs_ctx *debugfs;
	size_t len;

	debugfs = &npu_dev->debugfs_ctx;

	if (debugfs->reg_cnt == 0)
		return 0;

	if (!reg_ctx->buf) {
		char dump_buf[64];
		char *ptr;
		int cnt, tot, off;

		reg_ctx->buf_len = sizeof(dump_buf) *
			DIV_ROUND_UP(debugfs->reg_cnt, ROW_BYTES);
		reg_ctx->buf = kzalloc(reg_ctx->buf_len, GFP_KERNEL);

		if (!reg_ctx->buf)
			return -ENOMEM;

		ptr = npu_dev->core_io.base + debugfs->reg_off;
		tot = 0;
		off = (int)debugfs->reg_off;

		if (npu_enable_core_power(npu_dev))
			return -EPERM;

		for (cnt = debugfs->reg_cnt * 4; cnt > 0; cnt -= ROW_BYTES) {
			hex_dump_to_buffer(ptr, min(cnt, ROW_BYTES),
					   ROW_BYTES, GROUP_BYTES, dump_buf,
					   sizeof(dump_buf), false);
			len = scnprintf(reg_ctx->buf + tot,
				reg_ctx->buf_len - tot, "0x%08x: %s\n",
				((int) (unsigned long) ptr) -
				((int) (unsigned long) npu_dev->core_io.base),
				dump_buf);

			ptr += ROW_BYTES;
			tot += len;
			if (tot >= reg_ctx->buf_len)
				break;
		}
		npu_disable_core_power(npu_dev);

		reg_ctx->buf_len = tot;
	}

	if (*ppos >= reg_ctx->buf_len)
		return 0; /* done reading */

	len = min(count, reg_ctx->buf_len - (size_t) *ppos);
	pr_debug("read %zi %zi\n", count, reg_ctx->buf_len - (size_t) *ppos);
	if (copy_to_user(user_buf, reg_ctx->buf + *ppos, len)) {
		pr_err("failed to copy to user\n");
		return -EFAULT;
	}

	*ppos += len;	/* increase offset */
	return len;
}

/* -------------------------------------------------------------------------
 * Function Implementations - Offset Read/Write
 * -------------------------------------------------------------------------
 */
static ssize_t npu_debug_off_write(struct file *file,
		const char __user *user_buf, size_t count, loff_t *ppos)
{
	size_t off = 0;
	uint32_t cnt, reg_cnt;
	char buf[24];
	struct npu_device *npu_dev = file->private_data;
	struct npu_debugfs_ctx *debugfs;

	pr_debug("npu_dev %pK %pK\n", npu_dev, g_npu_dev);
	npu_dev = g_npu_dev;
	debugfs = &npu_dev->debugfs_ctx;

	if (count >= sizeof(buf))
		return -EINVAL;

	if (copy_from_user(buf, user_buf, count))
		return -EFAULT;

	buf[count] = 0;	/* end of string */

	cnt = sscanf(buf, "%zx %x", &off, &reg_cnt);
	if (cnt == 1)
		reg_cnt = DEFAULT_REG_DUMP_NUM;
	pr_debug("reg off = %zx, %d cnt=%d\n", off, reg_cnt, cnt);
	if (cnt >= 1) {
		debugfs->reg_off = off;
		debugfs->reg_cnt = reg_cnt;
	}

	return count;
}

static ssize_t npu_debug_off_read(struct file *file,
			char __user *user_buf, size_t count, loff_t *ppos)
{
	size_t len;
	char buf[64];
	struct npu_device *npu_dev = file->private_data;
	struct npu_debugfs_ctx *debugfs;

	pr_debug("npu_dev %pK %pK\n", npu_dev, g_npu_dev);
	npu_dev = g_npu_dev;
	debugfs = &npu_dev->debugfs_ctx;

	if (*ppos)
		return 0;	/* the end */

	len = scnprintf(buf, sizeof(buf), "offset=0x%08x cnt=%d\n",
		debugfs->reg_off, debugfs->reg_cnt);
	len = min(len, count);

	if (copy_to_user(user_buf, buf, len)) {
		pr_err("failed to copy to user\n");
		return -EFAULT;
	}

	*ppos += len;	/* increase offset */
	return len;
}

/* -------------------------------------------------------------------------
 * Function Implementations - DebugFS Log
 * -------------------------------------------------------------------------
@@ -374,18 +193,6 @@ int npu_debugfs_init(struct npu_device *npu_dev)
		return -ENODEV;
	}

	if (!debugfs_create_file("reg", 0644, debugfs->root,
		npu_dev, &npu_reg_fops)) {
		pr_err("debugfs_create_file reg fail\n");
		goto err;
	}

	if (!debugfs_create_file("off", 0644, debugfs->root,
		npu_dev, &npu_off_fops)) {
		pr_err("debugfs_create_file off fail\n");
		goto err;
	}

	if (!debugfs_create_file("log", 0644, debugfs->root,
		npu_dev, &npu_log_fops)) {
		pr_err("debugfs_create_file log fail\n");
+13 −13
Original line number Diff line number Diff line
@@ -111,7 +111,7 @@ static int npu_get_property(struct npu_client *client,
	unsigned long arg);
static long npu_ioctl(struct file *file, unsigned int cmd,
					unsigned long arg);
static unsigned int npu_poll(struct file *filp, struct poll_table_struct *p);
static __poll_t npu_poll(struct file *filp, struct poll_table_struct *p);
static int npu_parse_dt_clock(struct npu_device *npu_dev);
static int npu_parse_dt_regulator(struct npu_device *npu_dev);
static int npu_of_parse_pwrlevels(struct npu_device *npu_dev,
@@ -541,7 +541,7 @@ static int npu_set_cdsprm_corner_limit(enum cdsprm_npu_corner corner)
	return npu_set_power_level(g_npu_dev, false);
}

const struct cdsprm_npu_limit_cbs cdsprm_npu_limit_cbs = {
static const struct cdsprm_npu_limit_cbs cdsprm_npu_limit_cbs = {
	.set_corner_limit = npu_set_cdsprm_corner_limit,
};

@@ -573,7 +573,7 @@ static uint32_t npu_notify_cdsprm_cxlimit_corner(
	return pwr_lvl_to_set;
}

int npu_cdsprm_cxlimit_init(struct npu_device *npu_dev)
static int npu_cdsprm_cxlimit_init(struct npu_device *npu_dev)
{
	bool enabled;
	int ret = 0;
@@ -597,7 +597,7 @@ int npu_cdsprm_cxlimit_init(struct npu_device *npu_dev)
	return ret;
}

int npu_cdsprm_cxlimit_deinit(struct npu_device *npu_dev)
static int npu_cdsprm_cxlimit_deinit(struct npu_device *npu_dev)
{
	int ret = 0;

@@ -1565,8 +1565,8 @@ static int npu_process_kevent(struct npu_kevent *kevt)

	switch (kevt->evt.type) {
	case MSM_NPU_EVENT_TYPE_EXEC_V2_DONE:
		ret = copy_to_user((void __user *)kevt->reserved[1],
			(void *)kevt->reserved[0],
		ret = copy_to_user(kevt->stats_buf_u,
			kevt->stats_buf,
			kevt->evt.u.exec_v2_done.stats_buf_size);
		if (ret) {
			pr_err("fail to copy to user\n");
@@ -1777,21 +1777,21 @@ static long npu_ioctl(struct file *file, unsigned int cmd,
	return ret;
}

static unsigned int npu_poll(struct file *filp, struct poll_table_struct *p)
static __poll_t npu_poll(struct file *filp, struct poll_table_struct *p)
{
	struct npu_client *client = filp->private_data;
	int rc = 0;
	__poll_t mask = 0;

	poll_wait(filp, &client->wait, p);

	mutex_lock(&client->list_lock);
	if (!list_empty(&client->evt_list)) {
		pr_debug("poll cmd done\n");
		rc = POLLIN | POLLRDNORM;
		mask = EPOLLIN | EPOLLRDNORM;
	}
	mutex_unlock(&client->list_lock);

	return rc;
	return mask;
}

/* -------------------------------------------------------------------------
@@ -2135,9 +2135,9 @@ static int npu_hw_info_init(struct npu_device *npu_dev)
static int npu_probe(struct platform_device *pdev)
{
	int rc = 0;
	struct resource *res = 0;
	struct npu_device *npu_dev = 0;
	struct thermal_cooling_device *tcdev = 0;
	struct resource *res = NULL;
	struct npu_device *npu_dev = NULL;
	struct thermal_cooling_device *tcdev = NULL;

	npu_dev = devm_kzalloc(&pdev->dev,
		sizeof(struct npu_device), GFP_KERNEL);
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ static int npu_host_ipc_init_hfi(struct npu_device *npu_dev)
	struct hfi_queue_tbl_header *q_tbl_hdr = NULL;
	struct hfi_queue_header *q_hdr_arr = NULL;
	struct hfi_queue_header *q_hdr = NULL;
	void *q_tbl_addr = 0;
	void *q_tbl_addr = NULL;
	uint32_t reg_val = 0;
	uint32_t q_idx = 0;
	uint32_t q_tbl_size = sizeof(struct hfi_queue_tbl_header) +
+5 −5
Original line number Diff line number Diff line
@@ -103,7 +103,7 @@ void npu_mem_write(struct npu_device *npu_dev, void *dst, void *src,
{
	size_t dst_off = (size_t)dst;
	uint32_t *src_ptr32 = (uint32_t *)src;
	uint8_t *src_ptr8 = 0;
	uint8_t *src_ptr8 = NULL;
	uint32_t i = 0;
	uint32_t num = 0;

@@ -138,7 +138,7 @@ int32_t npu_mem_read(struct npu_device *npu_dev, void *src, void *dst,
{
	size_t src_off = (size_t)src;
	uint32_t *out32 = (uint32_t *)dst;
	uint8_t *out8 = 0;
	uint8_t *out8 = NULL;
	uint32_t i = 0;
	uint32_t num = 0;

@@ -367,7 +367,7 @@ void npu_mem_invalidate(struct npu_client *client, int buf_hdl)

bool npu_mem_verify_addr(struct npu_client *client, uint64_t addr)
{
	struct npu_ion_buf *ion_buf = 0;
	struct npu_ion_buf *ion_buf = NULL;
	struct list_head *pos = NULL;
	bool valid = false;

@@ -387,7 +387,7 @@ bool npu_mem_verify_addr(struct npu_client *client, uint64_t addr)
void npu_mem_unmap(struct npu_client *client, int buf_hdl,  uint64_t addr)
{
	struct npu_device *npu_dev = client->npu_dev;
	struct npu_ion_buf *ion_buf = 0;
	struct npu_ion_buf *ion_buf = NULL;

	/* clear entry and retrieve the corresponding buffer */
	ion_buf = npu_get_npu_ion_buffer(client, buf_hdl);
@@ -466,7 +466,7 @@ void npu_process_log_message(struct npu_device *npu_dev, uint32_t *message,
			debugfs->log_buf_size) {
			/* Wrap around case */
			uint8_t *src_addr = (uint8_t *)message;
			uint8_t *dst_addr = 0;
			uint8_t *dst_addr = NULL;
			uint32_t remaining_to_end = debugfs->log_buf_size -
				debugfs->log_write_index + 1;
			dst_addr = debugfs->log_buf + debugfs->log_write_index;
Loading