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

Commit c04a6b61 authored by Yuanfang Zhang's avatar Yuanfang Zhang
Browse files

Coresight: byte-cntr: Don't read byte-cntr when etr is diasbled



Tmc etr buffer will be read when cat /dev/byte-cntr. If tmc etr
is disabled, the buffer will be released. So exit byte-cntr-read
when etr is disabled.

Change-Id: Ia7037362dd973895f3b095a2ffbbab83570fb57e
Signed-off-by: default avatarYuanfang Zhang <zhangyuanfang@codeaurora.org>
parent c9b19cf7
Loading
Loading
Loading
Loading
+25 −11
Original line number Original line Diff line number Diff line
/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
/* Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * it under the terms of the GNU General Public License version 2 and
@@ -143,13 +143,15 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
{
{
	struct byte_cntr *byte_cntr_data = fp->private_data;
	struct byte_cntr *byte_cntr_data = fp->private_data;
	char *bufp;
	char *bufp;

	int ret = 0;
	if (!data)
	if (!data)
		return -EINVAL;
		return -EINVAL;


	mutex_lock(&byte_cntr_data->byte_cntr_lock);
	mutex_lock(&byte_cntr_data->byte_cntr_lock);
	if (!byte_cntr_data->read_active)
	if (!byte_cntr_data->read_active) {
		ret = -EINVAL;
		goto err0;
		goto err0;
	}


	bufp = (char *)(tmcdrvdata->buf + *ppos);
	bufp = (char *)(tmcdrvdata->buf + *ppos);


@@ -157,13 +159,17 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
		if (!atomic_read(&byte_cntr_data->irq_cnt)) {
		if (!atomic_read(&byte_cntr_data->irq_cnt)) {
			mutex_unlock(&byte_cntr_data->byte_cntr_lock);
			mutex_unlock(&byte_cntr_data->byte_cntr_lock);
			if (wait_event_interruptible(byte_cntr_data->wq,
			if (wait_event_interruptible(byte_cntr_data->wq,
				atomic_read(&byte_cntr_data->irq_cnt) > 0))
				atomic_read(&byte_cntr_data->irq_cnt) > 0
				|| !byte_cntr_data->enable))
				return -ERESTARTSYS;
				return -ERESTARTSYS;
			mutex_lock(&byte_cntr_data->byte_cntr_lock);
			mutex_lock(&byte_cntr_data->byte_cntr_lock);
			if (!byte_cntr_data->read_active)
			if (!byte_cntr_data->read_active) {
				ret = -EINVAL;
				goto err0;
				goto err0;
			}
			}


		}

		if (tmcdrvdata->memtype == TMC_ETR_MEM_TYPE_CONTIG)
		if (tmcdrvdata->memtype == TMC_ETR_MEM_TYPE_CONTIG)
			tmc_etr_read_bytes(byte_cntr_data, ppos,
			tmc_etr_read_bytes(byte_cntr_data, ppos,
					   byte_cntr_data->block_size, &len,
					   byte_cntr_data->block_size, &len,
@@ -183,8 +189,10 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
						    byte_cntr_data->block_size,
						    byte_cntr_data->block_size,
						    1,
						    1,
						    &len, &bufp);
						    &len, &bufp);
			if (!len)
			if (!len) {
				ret = -EINVAL;
				goto err0;
				goto err0;
			}
		} else {
		} else {
			if (tmcdrvdata->memtype == TMC_ETR_MEM_TYPE_CONTIG)
			if (tmcdrvdata->memtype == TMC_ETR_MEM_TYPE_CONTIG)
				tmc_etr_read_bytes(byte_cntr_data, ppos,
				tmc_etr_read_bytes(byte_cntr_data, ppos,
@@ -208,9 +216,14 @@ static ssize_t tmc_etr_byte_cntr_read(struct file *fp, char __user *data,
		*ppos = 0;
		*ppos = 0;
	else
	else
		*ppos += len;
		*ppos += len;

	goto out;

err0:
err0:
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);

	return ret;
out:
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);
	return len;
	return len;
}
}


@@ -221,7 +234,8 @@ void tmc_etr_byte_cntr_start(struct byte_cntr *byte_cntr_data)


	mutex_lock(&byte_cntr_data->byte_cntr_lock);
	mutex_lock(&byte_cntr_data->byte_cntr_lock);


	if (byte_cntr_data->block_size == 0) {
	if (byte_cntr_data->block_size == 0
		|| byte_cntr_data->read_active) {
		mutex_unlock(&byte_cntr_data->byte_cntr_lock);
		mutex_unlock(&byte_cntr_data->byte_cntr_lock);
		return;
		return;
	}
	}
@@ -239,6 +253,8 @@ void tmc_etr_byte_cntr_stop(struct byte_cntr *byte_cntr_data)


	mutex_lock(&byte_cntr_data->byte_cntr_lock);
	mutex_lock(&byte_cntr_data->byte_cntr_lock);
	byte_cntr_data->enable = false;
	byte_cntr_data->enable = false;
	byte_cntr_data->read_active = false;
	wake_up(&byte_cntr_data->wq);
	coresight_csr_set_byte_cntr(byte_cntr_data->csr, 0);
	coresight_csr_set_byte_cntr(byte_cntr_data->csr, 0);
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);


@@ -266,7 +282,7 @@ static int tmc_etr_byte_cntr_open(struct inode *in, struct file *fp)


	mutex_lock(&byte_cntr_data->byte_cntr_lock);
	mutex_lock(&byte_cntr_data->byte_cntr_lock);


	if (!tmcdrvdata->enable || !byte_cntr_data->block_size) {
	if (!byte_cntr_data->enable || !byte_cntr_data->block_size) {
		mutex_unlock(&byte_cntr_data->byte_cntr_lock);
		mutex_unlock(&byte_cntr_data->byte_cntr_lock);
		return -EINVAL;
		return -EINVAL;
	}
	}
@@ -279,10 +295,8 @@ static int tmc_etr_byte_cntr_open(struct inode *in, struct file *fp)


	fp->private_data = byte_cntr_data;
	fp->private_data = byte_cntr_data;
	nonseekable_open(in, fp);
	nonseekable_open(in, fp);
	byte_cntr_data->enable = true;
	byte_cntr_data->read_active = true;
	byte_cntr_data->read_active = true;
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);
	mutex_unlock(&byte_cntr_data->byte_cntr_lock);

	return 0;
	return 0;
}
}