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

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

Merge "msm: npu: update debugfs functions"

parents 1c760a55 834b5cab
Loading
Loading
Loading
Loading
+16 −81
Original line number Diff line number Diff line
@@ -26,8 +26,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_release(struct inode *inode, struct file *file);
static ssize_t npu_debug_reg_write(struct file *file,
		const char __user *user_buf, size_t count, loff_t *ppos);
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,
@@ -43,13 +41,12 @@ static ssize_t npu_debug_ctrl_write(struct file *file,
 * Variables
 * -------------------------------------------------------------------------
 */
struct npu_device *g_npu_dev;
static struct npu_device *g_npu_dev;

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

static const struct file_operations npu_off_fops = {
@@ -107,41 +104,6 @@ static int npu_debug_reg_release(struct inode *inode, struct file *file)
 * Function Implementations - Reg Read/Write
 * -------------------------------------------------------------------------
 */
static ssize_t npu_debug_reg_write(struct file *file,
		const char __user *user_buf, size_t count, loff_t *ppos)
{
	size_t off;
	uint32_t data, cnt;
	struct npu_device *npu_dev = file->private_data;
	char buf[24];

	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, &data);
	NPU_DBG("%s 0x%zx, 0x%08x\n", buf, off, data);

	return count;
	if (cnt < 2)
		return -EINVAL;

	if (npu_enable_core_power(npu_dev))
		return -EPERM;

	REGW(npu_dev, off, data);

	npu_disable_core_power(npu_dev);

	NPU_DBG("write: addr=%zx data=%x\n", off, data);

	return count;
}

static ssize_t npu_debug_reg_read(struct file *file,
			char __user *user_buf, size_t count, loff_t *ppos)
{
@@ -261,6 +223,7 @@ static ssize_t npu_debug_off_read(struct file *file,

	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)) {
		NPU_ERR("failed to copy to user\n");
@@ -290,49 +253,21 @@ static ssize_t npu_debug_log_read(struct file *file,
	mutex_lock(&debugfs->log_lock);

	if (debugfs->log_num_bytes_buffered != 0) {
		if ((debugfs->log_read_index +
			debugfs->log_num_bytes_buffered) >
			debugfs->log_buf_size) {
			/* Wrap around case */
			uint32_t remaining_to_end = debugfs->log_buf_size -
				debugfs->log_read_index;
			uint8_t *src_addr = debugfs->log_buf +
				debugfs->log_read_index;
			uint8_t *dst_addr = user_buf;

			if (copy_to_user(dst_addr, src_addr,
				remaining_to_end)) {
				NPU_ERR("failed to copy to user\n");
				mutex_unlock(&debugfs->log_lock);
				return -EFAULT;
			}
			src_addr = debugfs->log_buf;
			dst_addr = user_buf + remaining_to_end;
			if (copy_to_user(dst_addr, src_addr,
				debugfs->log_num_bytes_buffered -
				remaining_to_end)) {
				NPU_ERR("failed to copy to user\n");
				mutex_unlock(&debugfs->log_lock);
				return -EFAULT;
			}
			debugfs->log_read_index =
				debugfs->log_num_bytes_buffered -
				remaining_to_end;
		} else {
		len = min(debugfs->log_num_bytes_buffered,
			debugfs->log_buf_size - debugfs->log_read_index);
		len = min(count, len);
		if (copy_to_user(user_buf, (debugfs->log_buf +
				debugfs->log_read_index),
				debugfs->log_num_bytes_buffered)) {
			debugfs->log_read_index), len)) {
			NPU_ERR("failed to copy to user\n");
			mutex_unlock(&debugfs->log_lock);
			return -EFAULT;
		}
			debugfs->log_read_index +=
				debugfs->log_num_bytes_buffered;
		debugfs->log_read_index += len;
		if (debugfs->log_read_index == debugfs->log_buf_size)
			debugfs->log_read_index = 0;
		}
		len = debugfs->log_num_bytes_buffered;
		debugfs->log_num_bytes_buffered = 0;

		debugfs->log_num_bytes_buffered -= len;
		*ppos += len;
	}

	/* mutex log unlock */
+69 −29
Original line number Diff line number Diff line
@@ -20,67 +20,93 @@
 * Functions - Register
 * -------------------------------------------------------------------------
 */
uint32_t npu_core_reg_read(struct npu_device *npu_dev, uint32_t off)
static uint32_t npu_reg_read(void __iomem *base, size_t size, uint32_t off)
{
	uint32_t ret = 0;
	if (!base) {
		NPU_ERR("NULL base address\n");
		return 0;
	}

	ret = readl(npu_dev->core_io.base + off);
	return ret;
	if ((off % 4) != 0) {
		NPU_ERR("offset %x is not aligned\n", off);
		return 0;
	}

void npu_core_reg_write(struct npu_device *npu_dev, uint32_t off, uint32_t val)
	if (off >= size) {
		NPU_ERR("offset exceeds io region %x:%x\n", off, size);
		return 0;
	}

	return readl_relaxed(base + off);
}

static void npu_reg_write(void __iomem *base, size_t size, uint32_t off,
	uint32_t val)
{
	writel_relaxed(val, npu_dev->core_io.base + off);
	if (!base) {
		NPU_ERR("NULL base address\n");
		return;
	}

	if ((off % 4) != 0) {
		NPU_ERR("offset %x is not aligned\n", off);
		return;
	}

	if (off >= size) {
		NPU_ERR("offset exceeds io region %x:%x\n", off, size);
		return;
	}

	writel_relaxed(val, base + off);
	__iowmb();
}

uint32_t npu_tcsr_reg_read(struct npu_device *npu_dev, uint32_t off)
uint32_t npu_core_reg_read(struct npu_device *npu_dev, uint32_t off)
{
	uint32_t ret = 0;
	return npu_reg_read(npu_dev->core_io.base, npu_dev->core_io.size, off);
}

	ret = readl_relaxed(npu_dev->tcsr_io.base + off);
	return ret;
void npu_core_reg_write(struct npu_device *npu_dev, uint32_t off, uint32_t val)
{
	npu_reg_write(npu_dev->core_io.base, npu_dev->core_io.size,
		off, val);
}

uint32_t npu_apss_shared_reg_read(struct npu_device *npu_dev, uint32_t off)
uint32_t npu_tcsr_reg_read(struct npu_device *npu_dev, uint32_t off)
{
	uint32_t ret = 0;
	return npu_reg_read(npu_dev->tcsr_io.base, npu_dev->tcsr_io.size, off);
}

	ret = readl(npu_dev->apss_shared_io.base + off);
	return ret;
uint32_t npu_apss_shared_reg_read(struct npu_device *npu_dev, uint32_t off)
{
	return npu_reg_read(npu_dev->apss_shared_io.base,
		npu_dev->apss_shared_io.size, off);
}

void npu_apss_shared_reg_write(struct npu_device *npu_dev, uint32_t off,
	uint32_t val)
{
	writel_relaxed(val, npu_dev->apss_shared_io.base + off);
	__iowmb();
	npu_reg_write(npu_dev->apss_shared_io.base,
		npu_dev->apss_shared_io.size, off, val);
}

uint32_t npu_cc_reg_read(struct npu_device *npu_dev, uint32_t off)
{
	uint32_t ret = 0;

	ret = readl_relaxed(npu_dev->cc_io.base + off);

	return ret;
	return npu_reg_read(npu_dev->cc_io.base, npu_dev->cc_io.size, off);
}

void npu_cc_reg_write(struct npu_device *npu_dev, uint32_t off,
	uint32_t val)
{
	writel_relaxed(val, npu_dev->cc_io.base + off);
	__iowmb();
	npu_reg_write(npu_dev->cc_io.base, npu_dev->cc_io.size,
		off, val);
}

uint32_t npu_qfprom_reg_read(struct npu_device *npu_dev, uint32_t off)
{
	uint32_t ret = 0;

	if (npu_dev->qfprom_io.base)
		ret = readl(npu_dev->qfprom_io.base + off);

	return ret;
	return npu_reg_read(npu_dev->qfprom_io.base,
		npu_dev->qfprom_io.size, off);
}

/* -------------------------------------------------------------------------
@@ -96,6 +122,13 @@ void npu_mem_write(struct npu_device *npu_dev, void *dst, void *src,
	uint32_t i = 0;
	uint32_t num = 0;

	if (dst_off >= npu_dev->tcm_io.size ||
		(npu_dev->tcm_io.size - dst_off) < size) {
		NPU_ERR("memory write exceeds io region %x:%x:%x\n",
			dst_off, size, npu_dev->tcm_io.size);
		return;
	}

	num = size/4;
	for (i = 0; i < num; i++) {
		writel_relaxed(src_ptr32[i], npu_dev->tcm_io.base + dst_off);
@@ -122,6 +155,13 @@ int32_t npu_mem_read(struct npu_device *npu_dev, void *src, void *dst,
	uint32_t i = 0;
	uint32_t num = 0;

	if (src_off >= npu_dev->tcm_io.size ||
		(npu_dev->tcm_io.size - src_off) < size) {
		NPU_ERR("memory read exceeds io region %x:%x:%x\n",
			src_off, size, npu_dev->tcm_io.size);
		return 0;
	}

	num = size/4;
	for (i = 0; i < num; i++) {
		out32[i] = readl_relaxed(npu_dev->tcm_io.base + src_off);