Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively." stable-1.5
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Fri, 05 Oct 2018 01:26:51 +0200
branchstable-1.5
changeset 2719 94c9657e0bee
parent 2718 137cdf41bcec
child 2720 4645c990fd79
Xenomai 2 to 3 migration says "RTDM drivers implementing differentiated ioctl() support for both domains should serve all real-time only requests from ioctl_rt(), returning -ENOSYS for any unrecognized request, which will cause the adaptive switch to take place automatically to the ioctl_nrt() handler. The ioctl_nrt() should then implement all requests which may be valid from the regular Linux domain exclusively."
master/ioctl.c
master/rtdm.c
--- a/master/ioctl.c	Mon Oct 01 22:05:31 2018 +0200
+++ b/master/ioctl.c	Fri Oct 05 01:26:51 2018 +0200
@@ -57,6 +57,17 @@
 #define ATTRIBUTES
 #endif
 
+#ifndef EC_IOCTL_RTDM
+#define ec_copy_to_user copy_to_user
+#define ec_copy_from_user copy_from_user
+#else
+/* RTDM provides rtdm_copy_{to,from}_user but they need fd argument 
+   for no good reason. This is is just a shortcut to real call */
+#define ec_copy_to_user __copy_to_user_inatomic
+#define ec_copy_from_user __copy_from_user_inatomic
+#endif
+
+
 /*****************************************************************************/
 
 /** Copies a string to an ioctl structure.
@@ -89,7 +100,7 @@
     data.ioctl_version_magic = EC_IOCTL_VERSION_MAGIC;
     data.master_count = ec_master_count();
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -183,7 +194,7 @@
     io.ref_clock =
         master->dc_ref_clock ? master->dc_ref_clock->ring_position : 0xffff;
 
-    if (copy_to_user((void __user *) arg, &io, sizeof(io))) {
+    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -205,7 +216,7 @@
     const ec_slave_t *slave;
     int i;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -271,7 +282,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -292,7 +303,7 @@
     const ec_slave_t *slave;
     const ec_sync_t *sync;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -324,7 +335,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -346,7 +357,7 @@
     const ec_sync_t *sync;
     const ec_pdo_t *pdo;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -383,7 +394,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -406,7 +417,7 @@
     const ec_pdo_t *pdo;
     const ec_pdo_entry_t *entry;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -452,7 +463,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -473,7 +484,7 @@
     const ec_domain_t *domain;
     unsigned int dev_idx;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -497,7 +508,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -518,7 +529,7 @@
     const ec_domain_t *domain;
     const ec_fmmu_config_t *fmmu;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -549,7 +560,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -569,7 +580,7 @@
     ec_ioctl_domain_data_t data;
     const ec_domain_t *domain;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -590,7 +601,7 @@
         return -EFAULT;
     }
 
-    if (copy_to_user((void __user *) data.target, domain->data,
+    if (ec_copy_to_user((void __user *) data.target, domain->data,
                 domain->data_size)) {
         up(&master->master_sem);
         return -EFAULT;
@@ -643,7 +654,7 @@
     ec_ioctl_slave_state_t data;
     ec_slave_t *slave;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -679,7 +690,7 @@
     const ec_slave_t *slave;
     const ec_sdo_t *sdo;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -707,7 +718,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -729,7 +740,7 @@
     const ec_sdo_t *sdo;
     const ec_sdo_entry_t *entry;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -787,7 +798,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -808,7 +819,7 @@
     uint8_t *target;
     int ret;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -823,7 +834,7 @@
             data.target_size, &data.data_size, &data.abort_code);
 
     if (!ret) {
-        if (copy_to_user((void __user *) data.target,
+        if (ec_copy_to_user((void __user *) data.target,
                     target, data.data_size)) {
             kfree(target);
             return -EFAULT;
@@ -832,7 +843,7 @@
 
     kfree(target);
 
-    if (__copy_to_user((void __user *) arg, &data, sizeof(data))) {
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -854,7 +865,7 @@
     uint8_t *sdo_data;
     int retval;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -864,7 +875,7 @@
         return -ENOMEM;
     }
 
-    if (copy_from_user(sdo_data, (void __user *) data.data, data.data_size)) {
+    if (ec_copy_from_user(sdo_data, (void __user *) data.data, data.data_size)) {
         kfree(sdo_data);
         return -EFAULT;
     }
@@ -880,7 +891,7 @@
 
     kfree(sdo_data);
 
-    if (__copy_to_user((void __user *) arg, &data, sizeof(data))) {
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) {
         retval = -EFAULT;
     }
 
@@ -902,7 +913,7 @@
     const ec_slave_t *slave;
     int retval;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -925,7 +936,7 @@
         return -EINVAL;
     }
 
-    if (copy_to_user((void __user *) data.words,
+    if (ec_copy_to_user((void __user *) data.words,
                 slave->sii_words + data.offset, data.nwords * 2))
         retval = -EFAULT;
     else
@@ -952,7 +963,7 @@
     uint16_t *words;
     ec_sii_write_request_t request;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -967,7 +978,7 @@
         return -ENOMEM;
     }
 
-    if (copy_from_user(words,
+    if (ec_copy_from_user(words,
                 (void __user *) data.words, byte_size)) {
         kfree(words);
         return -EFAULT;
@@ -1039,7 +1050,7 @@
     ec_reg_request_t request;
     int ret;
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -1093,7 +1104,7 @@
     wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY);
 
     if (request.state == EC_INT_REQUEST_SUCCESS) {
-        if (copy_to_user((void __user *) io.data, request.data, io.size)) {
+        if (ec_copy_to_user((void __user *) io.data, request.data, io.size)) {
             return -EFAULT;
         }
     }
@@ -1118,7 +1129,7 @@
     ec_reg_request_t request;
     int ret;
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -1132,7 +1143,7 @@
         return ret;
     }
 
-    if (copy_from_user(request.data, (void __user *) io.data, io.size)) {
+    if (ec_copy_from_user(request.data, (void __user *) io.data, io.size)) {
         ec_reg_request_clear(&request);
         return -EFAULT;
     }
@@ -1202,7 +1213,7 @@
     const ec_slave_config_t *sc;
     uint8_t i;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -1239,7 +1250,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -1260,7 +1271,7 @@
     const ec_slave_config_t *sc;
     const ec_pdo_t *pdo;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -1295,7 +1306,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -1317,7 +1328,7 @@
     const ec_pdo_t *pdo;
     const ec_pdo_entry_t *entry;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -1360,7 +1371,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -1385,7 +1396,7 @@
         return -ENOMEM;
     }
 
-    if (copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) {
+    if (ec_copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) {
         kfree(ioctl);
         return -EFAULT;
     }
@@ -1421,7 +1432,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) {
+    if (ec_copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) {
         kfree(ioctl);
         return -EFAULT;
     }
@@ -1449,7 +1460,7 @@
         return -ENOMEM;
     }
 
-    if (copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) {
+    if (ec_copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) {
         kfree(ioctl);
         return -EFAULT;
     }
@@ -1485,7 +1496,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) {
+    if (ec_copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) {
         kfree(ioctl);
         return -EFAULT;
     }
@@ -1510,7 +1521,7 @@
     ec_ioctl_eoe_handler_t data;
     const ec_eoe_t *eoe;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -1540,7 +1551,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -1615,7 +1626,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -1637,7 +1648,7 @@
 
     up(&master->master_sem);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -1746,7 +1757,7 @@
     if (ret < 0)
         return ret;
 
-    if (copy_to_user((void __user *) arg, &io,
+    if (ec_copy_to_user((void __user *) arg, &io,
                 sizeof(ec_ioctl_master_activate_t)))
         return -EFAULT;
 
@@ -1790,7 +1801,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&send_interval, (void __user *) arg,
+    if (ec_copy_from_user(&send_interval, (void __user *) arg,
                 sizeof(send_interval))) {
         return -EFAULT;
     }
@@ -1860,7 +1871,7 @@
 
     ecrt_master_state(master, &data);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -1882,7 +1893,7 @@
     ec_master_link_state_t state;
     int ret;
 
-    if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
+    if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
         return -EFAULT;
     }
 
@@ -1891,7 +1902,7 @@
         return ret;
     }
 
-    if (copy_to_user((void __user *) ioctl.state, &state, sizeof(state))) {
+    if (ec_copy_to_user((void __user *) ioctl.state, &state, sizeof(state))) {
         return -EFAULT;
     }
 
@@ -1915,7 +1926,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -1987,7 +1998,7 @@
         return ret;
     }
 
-    if (copy_to_user((void __user *) arg, &time, sizeof(time))) {
+    if (ec_copy_to_user((void __user *) arg, &time, sizeof(time))) {
         return -EFAULT;
     }
 
@@ -2033,7 +2044,7 @@
 
     time_diff = ecrt_master_sync_monitor_process(master);
 
-    if (copy_to_user((void __user *) arg, &time_diff, sizeof(time_diff)))
+    if (ec_copy_to_user((void __user *) arg, &time_diff, sizeof(time_diff)))
         return -EFAULT;
 
     return 0;
@@ -2079,7 +2090,7 @@
         goto out_return;
     }
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         ret = -EFAULT;
         goto out_return;
     }
@@ -2131,7 +2142,7 @@
         goto out_return;
     }
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         ret = -EFAULT;
         goto out_return;
     }
@@ -2173,7 +2184,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (down_interruptible(&master->master_sem))
@@ -2207,7 +2218,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (down_interruptible(&master->master_sem))
@@ -2242,7 +2253,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (down_interruptible(&master->master_sem))
@@ -2277,7 +2288,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (down_interruptible(&master->master_sem))
@@ -2314,7 +2325,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (down_interruptible(&master->master_sem))
@@ -2335,7 +2346,7 @@
     ret = ecrt_slave_config_reg_pdo_entry(sc, data.entry_index,
             data.entry_subindex, domain, &data.bit_position);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return ret;
@@ -2362,7 +2373,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -2385,7 +2396,7 @@
     ret = ecrt_slave_config_reg_pdo_entry_pos(sc, io.sync_index,
             io.pdo_pos, io.entry_pos, domain, &io.bit_position);
 
-    if (copy_to_user((void __user *) arg, &io, sizeof(io)))
+    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io)))
         return -EFAULT;
 
     return ret;
@@ -2409,7 +2420,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (down_interruptible(&master->master_sem))
@@ -2451,7 +2462,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (!data.size)
@@ -2461,7 +2472,7 @@
         return -ENOMEM;
     }
 
-    if (copy_from_user(sdo_data, (void __user *) data.data, data.size)) {
+    if (ec_copy_from_user(sdo_data, (void __user *) data.data, data.size)) {
         kfree(sdo_data);
         return -EFAULT;
     }
@@ -2509,7 +2520,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io)))
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io)))
         return -EFAULT;
 
     if (down_interruptible(&master->master_sem)) {
@@ -2549,7 +2560,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -2565,7 +2576,7 @@
         return ret;
     }
 
-    if (copy_to_user((void __user *) io.target, msg, sizeof(msg))) {
+    if (ec_copy_to_user((void __user *) io.target, msg, sizeof(msg))) {
         return -EFAULT;
     }
 
@@ -2591,7 +2602,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -2625,7 +2636,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -2643,7 +2654,7 @@
 
     io.overruns = ret;
 
-    if (copy_to_user((void __user *) arg, &io, sizeof(io))) {
+    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -2669,7 +2680,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -2695,7 +2706,7 @@
     if (IS_ERR(req))
         return PTR_ERR(req);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -2721,7 +2732,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -2748,7 +2759,7 @@
         return PTR_ERR(reg);
     }
 
-    if (copy_to_user((void __user *) arg, &io, sizeof(io))) {
+    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -2774,7 +2785,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -2799,7 +2810,7 @@
     if (IS_ERR(voe))
         return PTR_ERR(voe);
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -2824,7 +2835,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -2837,7 +2848,7 @@
 
     ecrt_slave_config_state(sc, &state);
 
-    if (copy_to_user((void __user *) data.state, &state, sizeof(state)))
+    if (ec_copy_to_user((void __user *) data.state, &state, sizeof(state)))
         return -EFAULT;
 
     return 0;
@@ -2863,7 +2874,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl)))
+    if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl)))
         return -EFAULT;
 
     if (!ioctl.size)
@@ -2873,7 +2884,7 @@
         return -ENOMEM;
     }
 
-    if (copy_from_user(data, (void __user *) ioctl.data, ioctl.size)) {
+    if (ec_copy_from_user(data, (void __user *) ioctl.data, ioctl.size)) {
         kfree(data);
         return -EFAULT;
     }
@@ -3040,7 +3051,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data))) {
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) {
         return -EFAULT;
     }
 
@@ -3053,7 +3064,7 @@
 
     ecrt_domain_state(domain, &state);
 
-    if (copy_to_user((void __user *) data.state, &state, sizeof(state)))
+    if (ec_copy_to_user((void __user *) data.state, &state, sizeof(state)))
         return -EFAULT;
 
     return 0;
@@ -3078,7 +3089,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor req will not be
@@ -3115,7 +3126,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor req will not be
@@ -3152,7 +3163,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor req will not be
@@ -3172,7 +3183,7 @@
     else
         data.size = 0;
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -3197,7 +3208,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor req will not be
@@ -3235,7 +3246,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (!data.size) {
@@ -3258,7 +3269,7 @@
     if (ret)
         return ret;
 
-    if (copy_from_user(req->data, (void __user *) data.data, data.size))
+    if (ec_copy_from_user(req->data, (void __user *) data.data, data.size))
         return -EFAULT;
 
     req->data_size = data.size;
@@ -3285,7 +3296,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor req will not be
@@ -3299,7 +3310,7 @@
         return -ENOENT;
     }
 
-    if (copy_to_user((void __user *) data.data, ecrt_sdo_request_data(req),
+    if (ec_copy_to_user((void __user *) data.data, ecrt_sdo_request_data(req),
                 ecrt_sdo_request_data_size(req)))
         return -EFAULT;
 
@@ -3326,7 +3337,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -3345,7 +3356,7 @@
         return -ENOENT;
     }
 
-    if (copy_to_user((void __user *) io.data, ecrt_reg_request_data(reg),
+    if (ec_copy_to_user((void __user *) io.data, ecrt_reg_request_data(reg),
                 min(reg->mem_size, io.mem_size))) {
         return -EFAULT;
     }
@@ -3373,7 +3384,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -3391,7 +3402,7 @@
     io.state = ecrt_reg_request_state(reg);
     io.new_data = io.state == EC_REQUEST_SUCCESS && reg->dir == EC_DIR_INPUT;
 
-    if (copy_to_user((void __user *) arg, &io, sizeof(io))) {
+    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -3418,7 +3429,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -3437,7 +3448,7 @@
         return -EOVERFLOW;
     }
 
-    if (copy_from_user(reg->data, (void __user *) io.data,
+    if (ec_copy_from_user(reg->data, (void __user *) io.data,
                 io.transfer_size)) {
         return -EFAULT;
     }
@@ -3466,7 +3477,7 @@
         return -EPERM;
     }
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -3510,7 +3521,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     if (get_user(vendor_id, data.vendor_id))
@@ -3555,7 +3566,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor voe will not be
@@ -3601,7 +3612,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor voe will not be
@@ -3638,7 +3649,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor voe will not be
@@ -3675,7 +3686,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor voe will not be
@@ -3693,7 +3704,7 @@
         if (data.size > ec_voe_handler_mem_size(voe))
             return -EOVERFLOW;
 
-        if (copy_from_user(ecrt_voe_handler_data(voe),
+        if (ec_copy_from_user(ecrt_voe_handler_data(voe),
                     (void __user *) data.data, data.size))
             return -EFAULT;
     }
@@ -3721,7 +3732,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor voe will not be
@@ -3741,7 +3752,7 @@
     else
         data.size = 0;
 
-    if (copy_to_user((void __user *) arg, &data, sizeof(data)))
+    if (ec_copy_to_user((void __user *) arg, &data, sizeof(data)))
         return -EFAULT;
 
     return 0;
@@ -3766,7 +3777,7 @@
     if (unlikely(!ctx->requested))
         return -EPERM;
 
-    if (copy_from_user(&data, (void __user *) arg, sizeof(data)))
+    if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data)))
         return -EFAULT;
 
     /* no locking of master_sem needed, because neither sc nor voe will not be
@@ -3780,7 +3791,7 @@
         return -ENOENT;
     }
 
-    if (copy_to_user((void __user *) data.data, ecrt_voe_handler_data(voe),
+    if (ec_copy_to_user((void __user *) data.data, ecrt_voe_handler_data(voe),
                 ecrt_voe_handler_data_size(voe)))
         return -EFAULT;
 
@@ -3803,7 +3814,7 @@
     ec_slave_t *slave;
     int ret;
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -3867,7 +3878,7 @@
             return -EOVERFLOW;
         }
         io.data_size = request.data_size;
-        if (copy_to_user((void __user *) io.buffer,
+        if (ec_copy_to_user((void __user *) io.buffer,
                     request.buffer, io.data_size)) {
             ec_foe_request_clear(&request);
             return -EFAULT;
@@ -3875,7 +3886,7 @@
         ret = 0;
     }
 
-    if (__copy_to_user((void __user *) arg, &io, sizeof(io))) {
+    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
         ret = -EFAULT;
     }
 
@@ -3899,7 +3910,7 @@
     ec_slave_t *slave;
     int ret;
 
-    if (copy_from_user(&io, (void __user *) arg, sizeof(io))) {
+    if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) {
         return -EFAULT;
     }
 
@@ -3911,7 +3922,7 @@
         return ret;
     }
 
-    if (copy_from_user(request.buffer,
+    if (ec_copy_from_user(request.buffer,
                 (void __user *) io.buffer, io.buffer_size)) {
         ec_foe_request_clear(&request);
         return -EFAULT;
@@ -3963,7 +3974,7 @@
 
     ret = request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO;
 
-    if (__copy_to_user((void __user *) arg, &io, sizeof(io))) {
+    if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) {
         ret = -EFAULT;
     }
 
@@ -3986,7 +3997,7 @@
     u8 *data;
     int retval;
 
-    if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
+    if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
         return -EFAULT;
     }
 
@@ -4005,14 +4016,14 @@
         return retval;
     }
 
-    if (copy_to_user((void __user *) ioctl.data,
+    if (ec_copy_to_user((void __user *) ioctl.data,
                 data, ioctl.data_size)) {
         kfree(data);
         return -EFAULT;
     }
     kfree(data);
 
-    if (__copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) {
+    if (ec_copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) {
         retval = -EFAULT;
     }
 
@@ -4035,7 +4046,7 @@
     u8 *data;
     int retval;
 
-    if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
+    if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) {
         return -EFAULT;
     }
 
@@ -4045,7 +4056,7 @@
                 ioctl.data_size);
         return -ENOMEM;
     }
-    if (copy_from_user(data, (void __user *) ioctl.data, ioctl.data_size)) {
+    if (ec_copy_from_user(data, (void __user *) ioctl.data, ioctl.data_size)) {
         kfree(data);
         return -EFAULT;
     }
@@ -4058,7 +4069,7 @@
         return retval;
     }
 
-    if (__copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) {
+    if (ec_copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) {
         retval = -EFAULT;
     }
 
--- a/master/rtdm.c	Mon Oct 01 22:05:31 2018 +0200
+++ b/master/rtdm.c	Fri Oct 05 01:26:51 2018 +0200
@@ -49,6 +49,8 @@
 
 int ec_rtdm_open(struct rtdm_fd *, int);
 void ec_rtdm_close(struct rtdm_fd *);
+int ec_rtdm_rt_ioctl(struct rtdm_fd *,
+        unsigned int, void __user *);
 int ec_rtdm_ioctl(struct rtdm_fd *,
         unsigned int, void __user *);
 int ec_rtdm_mmap(struct rtdm_fd *fd, struct vm_area_struct *vma);
@@ -66,7 +68,7 @@
 	.ops = {
         .open      = ec_rtdm_open,
         .close     = ec_rtdm_close,
-        .ioctl_rt  = ec_rtdm_ioctl,
+        .ioctl_rt  = ec_rtdm_rt_ioctl,
         .ioctl_nrt = ec_rtdm_ioctl,
         .mmap      = ec_rtdm_mmap
 	},
@@ -192,6 +194,32 @@
  *
  * \return ioctl() return code.
  */
+int ec_rtdm_rt_ioctl(
+        struct rtdm_fd *fd, /**< User data. */
+        unsigned int request, /**< Request. */
+        void __user *arg /**< Argument. */
+        )
+{
+    switch (request) {
+        /*
+            Requests to be handled directly in primary domain
+        */
+        case EC_IOCTL_SEND:
+        case EC_IOCTL_RECEIVE:
+        case EC_IOCTL_MASTER_STATE:
+        case EC_IOCTL_DOMAIN_STATE:
+        case EC_IOCTL_DOMAIN_PROCESS:
+        case EC_IOCTL_DOMAIN_QUEUE:
+            return ec_rtdm_ioctl(fd, request, arg);
+        default:
+            break;
+    }
+    /* When a call is not supposed to happen in primary domain,
+       syscall catches -ENOSYS, then switch to secondary mode,
+       and calls .ioctl_nrt */
+    return -ENOSYS;
+}
+
 int ec_rtdm_ioctl(
         struct rtdm_fd *fd, /**< User data. */
         unsigned int request, /**< Request. */