Commit 57318023 authored by Philippe Gerum's avatar Philippe Gerum
Browse files

evl/control: move thread-related requests to the thread device


Signed-off-by: Philippe Gerum's avatarPhilippe Gerum <rpm@xenomai.org>
parent c6c03173
......@@ -256,8 +256,6 @@ int evl_switch_oob(void);
void evl_switch_inband(int cause);
int evl_update_mode(__u32 mask, bool set);
int evl_detach_self(void);
void __evl_kick_thread(struct evl_thread *thread);
......
......@@ -16,10 +16,5 @@ struct evl_core_info {
#define EVL_CONTROL_IOCBASE 'C'
#define EVL_CTLIOC_GET_COREINFO _IOR(EVL_CONTROL_IOCBASE, 0, struct evl_core_info)
#define EVL_CTLIOC_SWITCH_OOB _IO(EVL_CONTROL_IOCBASE, 1)
#define EVL_CTLIOC_SWITCH_INBAND _IO(EVL_CONTROL_IOCBASE, 2)
#define EVL_CTLIOC_DETACH_SELF _IO(EVL_CONTROL_IOCBASE, 3)
#define EVL_CTLIOC_SET_MODE _IOW(EVL_CONTROL_IOCBASE, 4, __u32)
#define EVL_CTLIOC_CLEAR_MODE _IOW(EVL_CONTROL_IOCBASE, 5, __u32)
#endif /* !_EVENLESS_UAPI_CONTROL_H */
......@@ -86,5 +86,10 @@ struct evl_thread_state {
#define EVL_THRIOC_GET_SCHEDPARAM _IOR(EVL_THREAD_IOCBASE, 2, struct evl_sched_attrs)
#define EVL_THRIOC_JOIN _IO(EVL_THREAD_IOCBASE, 3)
#define EVL_THRIOC_GET_STATE _IOR(EVL_THREAD_IOCBASE, 4, struct evl_thread_state)
#define EVL_THRIOC_SWITCH_OOB _IO(EVL_THREAD_IOCBASE, 5)
#define EVL_THRIOC_SWITCH_INBAND _IO(EVL_THREAD_IOCBASE, 6)
#define EVL_THRIOC_DETACH_SELF _IO(EVL_THREAD_IOCBASE, 7)
#define EVL_THRIOC_SET_MODE _IOW(EVL_THREAD_IOCBASE, 8, __u32)
#define EVL_THRIOC_CLEAR_MODE _IOW(EVL_THREAD_IOCBASE, 9, __u32)
#endif /* !_EVENLESS_UAPI_THREAD_H */
......@@ -99,16 +99,8 @@ static long control_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
struct evl_core_info info;
__u32 mask;
long ret;
/*
* NOTE: OOB <-> in-band switching services can only apply to
* the current thread, which should not need a file descriptor
* on its own element for issuing them. The control device is
* the right channel for requesting such services.
*/
switch (cmd) {
case EVL_CTLIOC_GET_COREINFO:
info.abi_level = EVL_ABI_LEVEL;
......@@ -117,26 +109,6 @@ static long control_ioctl(struct file *filp, unsigned int cmd,
ret = raw_copy_to_user((struct evl_core_info __user *)arg,
&info, sizeof(info)) ? -EFAULT : 0;
break;
case EVL_CTLIOC_SWITCH_OOB:
ret = evl_switch_oob();
break;
case EVL_CTLIOC_SWITCH_INBAND:
/*
* We already switched an OOB caller to inband mode as
* a result of handling this ioctl() call. Yummie.
*/
ret = 0;
break;
case EVL_CTLIOC_SET_MODE:
case EVL_CTLIOC_CLEAR_MODE:
ret = raw_get_user(mask, (__u32 *)arg);
if (ret)
return -EFAULT;
ret = evl_update_mode(mask, cmd == EVL_CTLIOC_SET_MODE);
break;
case EVL_CTLIOC_DETACH_SELF:
ret = evl_detach_self();
break;
default:
ret = -ENOTTY;
}
......
......@@ -143,8 +143,8 @@ int evl_init_thread(struct evl_thread *thread,
/*
* We mirror the global user debug state into the per-thread
* state, to speed up branch taking in libevenless wherever this
* needs to be tested.
* state, to speed up branch taking in user-space wherever
* this needs to be tested.
*/
if (IS_ENABLED(CONFIG_EVENLESS_DEBUG_MUTEX_SLEEP))
flags |= T_DEBUG;
......@@ -1028,6 +1028,7 @@ int evl_detach_self(void)
return 0;
}
EXPORT_SYMBOL_GPL(evl_detach_self);
struct wait_grace_struct {
struct completion done;
......@@ -2131,12 +2132,38 @@ static long thread_ioctl(struct file *filp, unsigned int cmd,
unsigned long arg)
{
struct evl_thread *thread = element_of(filp, struct evl_thread);
long ret;
struct evl_thread *curr = evl_current();
long ret = -EPERM;
__u32 mask;
if (thread->state & T_ZOMBIE)
return -ESTALE;
switch (cmd) {
case EVL_THRIOC_SWITCH_OOB:
if (thread == curr)
ret = evl_switch_oob();
break;
case EVL_THRIOC_SWITCH_INBAND:
/*
* If we got there, we were already switched from oob
* to inband mode as a result of calling ioctl().
* Yummie.
*/
ret = 0;
break;
case EVL_THRIOC_SET_MODE:
case EVL_THRIOC_CLEAR_MODE:
if (thread == curr) {
ret = raw_get_user(mask, (__u32 *)arg);
if (ret)
return -EFAULT;
ret = evl_update_mode(mask, cmd == EVL_THRIOC_SET_MODE);
}
break;
case EVL_THRIOC_DETACH_SELF:
ret = evl_detach_self();
break;
case EVL_THRIOC_JOIN:
ret = evl_join_thread(thread, false);
break;
......@@ -2268,7 +2295,7 @@ thread_factory_build(struct evl_factory *fac, const char *name,
* thread here to block automatic disposal on last file
* release. put_current_thread() drops this reference when the
* thread exits, or voluntarily detaches by sending the
* EVL_CTLIOC_DETACH_SELF control request.
* EVL_THRIOC_DETACH_SELF control request.
*/
evl_get_element(&curr->element);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment