Exemplo n.º 1
0
static int param_dsi_status_disable(const char *val, struct kernel_param *kp)
{
	int ret = 0;
	int int_val;

	ret = kstrtos32(val, 0, &int_val);
	if (ret)
		return ret;

	pr_info("%s: Set DSI status disable to %d\n",
			__func__, int_val);
	*((int *)kp->arg) = int_val;
	return ret;
}
Exemplo n.º 2
0
static ssize_t pm_qos_latency_tolerance_store(struct device *dev,
					      struct device_attribute *attr,
					      const char *buf, size_t n)
{
	s32 value;
	int ret;

	if (kstrtos32(buf, 0, &value)) {
		if (!strcmp(buf, "auto") || !strcmp(buf, "auto\n"))
			value = PM_QOS_LATENCY_TOLERANCE_NO_CONSTRAINT;
		else if (!strcmp(buf, "any") || !strcmp(buf, "any\n"))
			value = PM_QOS_LATENCY_ANY;
	}
	ret = dev_pm_qos_update_user_latency_tolerance(dev, value);
	return ret < 0 ? ret : n;
}
static ssize_t pm_qos_latency_store(struct device *dev,
				    struct device_attribute *attr,
				    const char *buf, size_t n)
{
	s32 value;
	int ret;

	if (kstrtos32(buf, 0, &value))
		return -EINVAL;

	if (value < 0)
		return -EINVAL;

	ret = dev_pm_qos_update_request(dev->power.pq_req, value);
	return ret < 0 ? ret : n;
}
Exemplo n.º 4
0
static int param_set_interval(const char *val, struct kernel_param *kp)
{
	int ret = 0;
	int int_val;

	ret = kstrtos32(val, 0, &int_val);
	if (ret)
		return ret;
	if (int_val < STATUS_CHECK_INTERVAL_MIN_MS) {
		pr_err("%s: Invalid value %d used, ignoring\n",
						__func__, int_val);
		ret = -EINVAL;
	} else {
		pr_info("%s: Set check interval to %d msecs\n",
						__func__, int_val);
		*((int *)kp->arg) = int_val;
	}
	return ret;
}
static ssize_t
debugfs_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *ppos)
{
	char buf[128];
	char *cmd = NULL;
	char *_cmd = NULL;
	int users;
	int type;
	s32 value;

	if (copy_from_user(buf, ubuf, cnt - 1)) {
		pr_err("[DDR DEVFREQ DEBUGFS] can not copy from user\n");
		cnt = -EINVAL;
		goto out;
	}

	buf[cnt - 1] = '\0';
	cmd = buf;
	_cmd = buf;
	pr_info("[DDR DEVFREQ DEBUGFS] [cmd: %s[cnt: %d]]\n", cmd, cnt);

	if (!strncmp("add ", _cmd, strlen("add "))) {
		cmd = cmd + strlen("add ");
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';

		if (kstrtos32(cmd, 10, &type)) {
			pr_err("[DDR DEVFREQ DEBUGFS] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		debugfs_add_request(type);
	} else if (!strncmp("remove user-", _cmd, strlen("remove user-"))) {
		cmd = cmd + strlen("remove user-");
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';

		if (kstrtos32(cmd, 10, &users)) {
			pr_err("[DDR DEVFREQ DEBUGFS] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		debugfs_remove_request(users);
	} else if (!strncmp("update user-", _cmd, strlen("update user-"))) {
		cmd = cmd + strlen("update user-");
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;

		if ('\0' == *_cmd) {
			pr_err("[DDR DEVFREQ DEBUGFS] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}
		*_cmd = '\0';

		if (kstrtos32(cmd, 10, &users)) {
			pr_err("[DDR DEVFREQ DEBUGFS] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		cmd = _cmd + 1;
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';

		if (kstrtos32(cmd, 10, &value)) {
			pr_err("[DDR DEVFREQ DEBUGFS] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		debugfs_update_request(users, value);
	} else if (!strncmp("request user-", _cmd, strlen("request user-"))) {
		cmd = cmd + strlen("request user-");
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';

		if (kstrtos32(cmd, 10, &users)) {
			pr_err("[DDR DEVFREQ DEBUGFS] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		pr_info("[DDR DEVFREQ DEBUGFS] memory throughput %d\n",
			debugfs_request_value(users));
	} else {
		pr_err("[DDR DEVFREQ DEBUGFS] cmd error\n");
		cnt = -EINVAL;
	}
out:
	return cnt;
}
static ssize_t
debugfs_write(struct file *filp, const char __user *ubuf, size_t cnt, loff_t *ppos)
{
	struct hwspinlock *__hwlock;
	char buf[128];
	char *cmd = NULL;
	char *_cmd = NULL;
	int id;
	int timeout;
	int unlock;
	int ret ;

	if (NULL == ubuf || 0 == cnt){
		pr_err("buf is null !\n");
		return (-EINVAL);
	}
	if(cnt > sizeof(buf))
	{
		pr_err("input count larger! \n");
		return (-ENOMEM);
	}

	if (copy_from_user(buf, ubuf, cnt - 1)) {
		pr_err("[Hwspinlock Debugfs] can not copy from user\n");
		cnt = -EINVAL;
		goto out;
	}

	buf[cnt - 1] = '\0';
	cmd = buf;
	_cmd = buf;
	pr_debug("[Hwspinlock Debugfs] [cmd: %s[cnt: %d]]\n", cmd, (int)cnt);

	if (!strncmp("request ", _cmd, strlen("request "))) {
		cmd = cmd + strlen("request ");
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';

		if (kstrtos32(cmd, 10, &id)) {
			pr_err("Hwspinlock Debugfs cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		hwlock = hwspin_lock_request_specific(id);
		if (!hwlock)
			pr_err("hwspinlock %u is already in use\n", id);
		else
			pr_info("[debug] Request hwspinlock %d sucess!",id);
	} else if (!strncmp("free_lock ", _cmd, strlen("free_lock "))) {
		cmd = cmd + strlen("free_lock ");
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';
		if (kstrtos32(cmd, 10, &id)) {
			pr_err("Hwspinlock Debugfs cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		if (!hwlock){
			__hwlock = hwspin_lock_lookup(id);
			if (__hwlock){
				debugfs_hwspinlock_lock_free(__hwlock);
				__hwlock = NULL;
			}else{
				pr_err("Current haven't requested the hwspinlock %d\n",id);
				goto out;
			}
		}else if (hwlock_to_id(hwlock) == id){
			debugfs_hwspinlock_lock_free(hwlock);
			hwlock = NULL;
		}else
			pr_err("[debug] please freelock the correct lock!\n");
	} else if (!strncmp("trylock ", _cmd, strlen("trylock "))) {
		cmd = cmd + strlen("trylock ");
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;

		if ('\0' == *_cmd) {
			pr_err("[debug] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}
		*_cmd = '\0';

		if (kstrtos32(cmd, 10, &id)) {
			pr_err("[debug] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		cmd = _cmd + 1;
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';
		if (kstrtos32(cmd, 10, &timeout)) {
			pr_err("[debug] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		cmd = _cmd + 1;
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';

		if (kstrtos32(cmd, 10, &unlock)) {
			pr_err("[debug] cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

		if (!hwlock){
			pr_err("Current haven't requested the hwspinlock %d\n",id);
			goto out;
		}else if (hwlock_to_id(hwlock) == id && timeout >= 0){
			ret =debugfs_hwspinlock_trylock_timeout(id, timeout, unlock);
			if (!ret){
				if (0 == timeout)
					pr_info("[debug] hwspin_trylock %d sucess!\n",id);
				else
					pr_info("[debug] hwspin_trylock_timout %d sucess!\n",id);
			}
		}else if(timeout < 0)
			pr_err("[debug] cmd err! timeout must > 0\n");
		else
			pr_err("[debug] please trylock the correct lock!\n");
	}else if (!strncmp("unlock ", _cmd, strlen("unlock "))) {
		cmd = cmd + strlen("unlock ");
		_cmd = cmd;
		while ((' ' != *_cmd) && ('\0' != *_cmd))
			_cmd++;
		*_cmd = '\0';
		if (kstrtos32(cmd, 10, &id)) {
			pr_err("Hwspinlock Debugfs cmd error\n");
			cnt = -EINVAL;
			goto out;
		}

                if (!hwlock){
			pr_err("Current don't echo request the hwspinlock %d\n",id);
			goto out;
		}else if(hwlock_to_id(hwlock) == id && locked == 1){
			hwspin_unlock(hwlock);
			pr_info("[debug] hwspin_unlock id=%d sucess!\n",id);
		}else
			pr_err("[debug] please free the correct request lock!\n");
	} else {
		pr_err("Hwspinlock Debugfs cmd error\n");
		cnt = -EINVAL;
	}
out:
	return cnt;
}
static ssize_t
mbox_debugfs_write(struct file *filp, const char __user *ubuf,
					size_t cnt, loff_t *ppos)
{
	char debugfs_cmd[128];
	char *_cmd = NULL;
	char *_tmp = NULL;
	char rp_name[24];
	u32 _mbox_index;
	mbox_msg_t msg[8];
	mbox_msg_len_t len;

	if (NULL == ubuf || 0 == cnt) {
		cnt = -EINVAL;
		goto out;
	}

	/*to avoid overflow*/
	if (sizeof(debugfs_cmd)/sizeof(char) < cnt) {
		cnt = -EINVAL;
		goto out;
	}

	if (copy_from_user(debugfs_cmd, ubuf, cnt - 1)) {
		cnt = -EINVAL;
		goto out;
	}

	debugfs_cmd[cnt - 1] = '\0';
	_cmd = debugfs_cmd;
	pr_debug("%s: [cmd: %s[cnt: %d]]\n", MODULE_NAME, debugfs_cmd, (int)cnt);

	if (!strncmp("get ", _cmd, strlen("get "))) {
		_cmd = _cmd + strlen("get ");
		if (mbox_debugfs_mbox_get(_cmd)) {
			cnt = -EINVAL;
			goto out;
		}
	} else if (!strncmp("put ", _cmd, strlen("put "))) {
		_cmd = _cmd + strlen("put ");
		if (!strncmp("mailbox-", _cmd, strlen("mailbox-"))) {
			_cmd = _cmd + strlen("mailbox-");
			if (kstrtou32(_cmd, 10, &_mbox_index)) {
				cnt = -EINVAL;
				goto out;
			} else {
				if (mbox_debugfs_mbox_put(_mbox_index)) {
					cnt = -EINVAL;
					goto out;
				}
			}
		} else {
			cnt = -EINVAL;
			goto out;
		}
	} else if (!strncmp("show", _cmd, strlen("show"))) {
		mbox_debufs_mbox_show();
	} else if (!strncmp("config ", _cmd, strlen("config "))) {
		_cmd = _cmd + strlen("config ");
		if (!strncmp("mailbox-", _cmd, strlen("mailbox-"))) {
			_cmd = _cmd + strlen("mailbox-");
			_tmp = _cmd;
			while ((' ' != *_tmp) && ('\0' != *_tmp))
				_tmp++;
			if ('\0' == *_tmp) {
				cnt = -EINVAL;
				goto out;
			}

			*_tmp = '\0';
			if (kstrtou32(_cmd, 10, &_mbox_index)) {
				cnt = -EINVAL;
				goto out;
			}

			*_tmp = ' ';
			_cmd = _tmp + 1;
			_tmp = _cmd;
			while ((' ' != *_tmp) && ('\0' != *_tmp))
				_tmp++;
			strncpy(rp_name, _cmd, _tmp - _cmd);
			rp_name[_tmp - _cmd] = '\0';

			if (mbox_debugfs_mbox_config(_mbox_index, rp_name)) {
				cnt = -EINVAL;
				goto out;
			}
		} else {
			cnt = -EINVAL;
			goto out;
		}
	} else if (!strncmp("send ", _cmd, strlen("send "))) {
		_cmd = _cmd + strlen("send ");
		if (!strncmp("mailbox-", _cmd, strlen("mailbox-"))) {
			_cmd = _cmd + strlen("mailbox-");
			_tmp = _cmd;
			while ((' ' != *_tmp) && ('\0' != *_tmp))
				_tmp++;
			if ('\0' == *_tmp) {
				cnt = -EINVAL;
				goto out;
			}
			*_tmp = '\0';
			if (kstrtou32(_cmd, 10, &_mbox_index)) {
				cnt = -EINVAL;
				goto out;
			}
			*_tmp = ' ';
			_cmd = _tmp + 1;

			len = mbox_debugfs_msg_get(_cmd, msg);
			if (len < 0) {
				cnt = -EINVAL;
				goto out;
			}

			if (mbox_debugfs_msg_send(_mbox_index, msg, len)) {
				cnt = -EINVAL;
				goto out;
			}
		} else {
			cnt = -EINVAL;
			goto out;
		}
	} else if (!strncmp("set times ", _cmd, strlen("set times "))) {
		_cmd = _cmd + strlen("set times ");
		_tmp = _cmd;
		while ((' ' != *_tmp) && ('\0' != *_tmp))
				_tmp++;
		*_tmp = '\0';
		if (kstrtos32(_cmd, 10, &debugfs_ipc_times)) {
			cnt = -EINVAL;
			goto out;
		}

		pr_info("set ipc times %d\n", debugfs_ipc_times);
	} else {
		cnt = -EINVAL;
		goto out;
	}

out:
	return cnt;
}