Beispiel #1
0
int fmem_set_state(enum fmem_state new_state)
{
	int ret = 0;
	int create_sysfs = 0;

	lock_fmem_state();
	if (fmem_state == new_state)
		goto out;

	if (fmem_state == FMEM_UNINITIALIZED) {
		if (new_state == FMEM_T_STATE) {
			tmem_enable();
			create_sysfs = 1;
			goto out_set;
		} else {
			ret = -EINVAL;
			goto out;
		}
	}

#ifdef CONFIG_MEMORY_HOTPLUG
	if (fmem_state == FMEM_C_STATE && new_state == FMEM_O_STATE) {
		ret = -EAGAIN;
		goto out;
	}

	if (fmem_state == FMEM_O_STATE && new_state == FMEM_C_STATE) {
		pr_warn("attempting to use powered off memory as fmem\n");
		ret = -EAGAIN;
		goto out;
	}
#endif

	if (new_state == FMEM_T_STATE) {
		void *v;
		v = fmem_map_virtual_area(MT_DEVICE_CACHED);
		if (IS_ERR_OR_NULL(v)) {
			ret = PTR_ERR(v);
			goto out;
		}
		tmem_enable();
	} else {
		tmem_disable();
		fmem_unmap_virtual_area();
	}

out_set:
	fmem_state = new_state;
out:
	unlock_fmem_state();
#ifdef CONFIG_SYSFS
	if (create_sysfs)
		fmem_create_sysfs();
#endif
	return ret;
}
int fmem_set_state(enum fmem_state new_state)
{
	int ret = 0;
	int create_sysfs = 0;

	lock_fmem_state();
	if (fmem_state == new_state)
		goto out;

	if (fmem_state == FMEM_UNINITIALIZED) {
		if (new_state == FMEM_T_STATE) {
			tmem_enable();
			create_sysfs = 1;
			goto out_set;
		}
		if (new_state == FMEM_C_STATE) {
			ret = -EINVAL;
			goto out;
		}
	}

	if (new_state == FMEM_T_STATE) {
		void *v;
		v = fmem_map_virtual_area(MT_DEVICE_CACHED);
		if (IS_ERR_OR_NULL(v)) {
			ret = PTR_ERR(v);
			goto out;
		}
		tmem_enable();
	} else {
		tmem_disable();
		fmem_unmap_virtual_area();
	}

out_set:
	fmem_state = new_state;
out:
	unlock_fmem_state();
#ifdef CONFIG_SYSFS
	if (create_sysfs)
		fmem_create_sysfs();
#endif
	return ret;
}
int fmem_set_state(enum fmem_state new_state)
{
	int ret = 0;
	int create_sysfs = 0;

	lock_fmem_state();
	if (fmem_state == new_state)
		goto out;

	if (fmem_state == FMEM_UNINITIALIZED) {
		if (new_state == FMEM_T_STATE) {
			tmem_enable(false);
			create_sysfs = 1;
			goto out_set;
		}
		if (new_state == FMEM_C_STATE) {
			ret = -EINVAL;
			goto out;
		}
	}

	if (new_state == FMEM_T_STATE)
		tmem_enable(true);
	else
		tmem_disable();

out_set:
	fmem_state = new_state;
out:
	unlock_fmem_state();
#ifdef CONFIG_SYSFS
	if (create_sysfs)
		fmem_create_sysfs();
#endif
	return ret;
}