master/rtdm.c
author Edouard Tisserant <edouard.tisserant@gmail.com>
Fri, 05 Oct 2018 18:01:39 +0200
branchstable-1.5
changeset 2721 d3855a6b0a9f
parent 2720 4645c990fd79
permissions -rw-r--r--
RTDM : dropped wrong size check in mmap
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
/*****************************************************************************
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
 *  $Id$
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
 *  Copyright (C) 2009-2010  Moehwald GmbH B. Benner
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
 *                     2011  IgH Andreas Stewering-Bone
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
 *                     2012  Florian Pose <fp@igh-essen.com>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     9
 *  This file is part of the IgH EtherCAT master.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    10
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    11
 *  The IgH EtherCAT master is free software; you can redistribute it and/or
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    12
 *  modify it under the terms of the GNU General Public License as published
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    13
 *  by the Free Software Foundation; version 2 of the License.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    14
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    15
 *  The IgH EtherCAT master is distributed in the hope that it will be useful,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    18
 *  Public License for more details.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    19
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    20
 *  You should have received a copy of the GNU General Public License along
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    21
 *  with the IgH EtherCAT master. If not, see <http://www.gnu.org/licenses/>.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    22
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    23
 *  The license mentioned above concerns the source code only. Using the
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    24
 *  EtherCAT technology and brand is only permitted in compliance with the
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    25
 *  industrial property and similar rights of Beckhoff Automation GmbH.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
 *
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
 ****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    29
/** \file
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    30
 * RTDM interface.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    31
 */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    32
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <linux/module.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
#include <linux/slab.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include <linux/mman.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    37
#include <rtdm/driver.h>
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
#include "master.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
#include "ioctl.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#include "rtdm.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
/** Set to 1 to enable device operations debugging.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#define DEBUG 0
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    47
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    48
/****************************************************************************/
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    49
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    50
int ec_rtdm_open(struct rtdm_fd *, int);
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    51
void ec_rtdm_close(struct rtdm_fd *);
2719
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
    52
int ec_rtdm_rt_ioctl(struct rtdm_fd *,
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
    53
        unsigned int, void __user *);
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    54
int ec_rtdm_ioctl(struct rtdm_fd *,
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
        unsigned int, void __user *);
2712
5d21d80777a6 Use new RTDM's mmap, not anymore a special case compared to normal linux mmap.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2707
diff changeset
    56
int ec_rtdm_mmap(struct rtdm_fd *fd, struct vm_area_struct *vma);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    60
static struct rtdm_driver ec_rtdm_driver = {
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    61
	.profile_info		=	RTDM_PROFILE_INFO(foo,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    62
							  RTDM_CLASS_EXPERIMENTAL,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    63
							  222,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    64
							  1),
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    65
	.device_flags		=	RTDM_NAMED_DEVICE,
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    66
	.device_count		=	1,
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    67
	.context_size		=	sizeof(ec_ioctl_context_t),
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    68
	.ops = {
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    69
        .open      = ec_rtdm_open,
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    70
        .close     = ec_rtdm_close,
2719
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
    71
        .ioctl_rt  = ec_rtdm_rt_ioctl,
2712
5d21d80777a6 Use new RTDM's mmap, not anymore a special case compared to normal linux mmap.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2707
diff changeset
    72
        .ioctl_nrt = ec_rtdm_ioctl,
5d21d80777a6 Use new RTDM's mmap, not anymore a special case compared to normal linux mmap.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2707
diff changeset
    73
        .mmap      = ec_rtdm_mmap
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    74
	},
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    75
};
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    76
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    77
/** Initialize an RTDM device.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    78
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    79
 * \return Zero on success, otherwise a negative error code.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    80
 */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
int ec_rtdm_dev_init(
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    82
        ec_rtdm_dev_t *rtdm_dev, /**< EtherCAT RTDM device. */
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
    83
        ec_master_t *master /**< EtherCAT master. */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    int ret;
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    87
    char* devlabel;
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    88
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    rtdm_dev->master = master;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    rtdm_dev->dev = kzalloc(sizeof(struct rtdm_device), GFP_KERNEL);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    if (!rtdm_dev->dev) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
        EC_MASTER_ERR(master, "Failed to reserve memory for RTDM device.\n");
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
    }
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    96
    
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    97
    devlabel = kzalloc(RTDM_MAX_DEVNAME_LEN+1, GFP_KERNEL);
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
    98
    if (!devlabel) {
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
    99
        EC_MASTER_ERR(master, "Failed to reserve memory for RTDM device name.\n");
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   100
        return -ENOMEM;
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   101
        kfree(rtdm_dev->dev);
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   102
    }
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   103
    snprintf(devlabel, RTDM_MAX_DEVNAME_LEN,
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   104
            "EtherCAT%u", master->index);
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   105
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   106
    rtdm_dev->dev->label = devlabel;
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   107
    rtdm_dev->dev->driver = &ec_rtdm_driver;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
    rtdm_dev->dev->device_data = rtdm_dev; /* pointer to parent */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   110
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
    EC_MASTER_INFO(master, "Registering RTDM device %s.\n",
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   112
            devlabel);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
    ret = rtdm_dev_register(rtdm_dev->dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    if (ret) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
        EC_MASTER_ERR(master, "Initialization of RTDM interface failed"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
                " (return value %i).\n", ret);
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   117
        kfree(rtdm_dev->dev->label);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
        kfree(rtdm_dev->dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   120
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   121
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   123
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   124
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   125
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   126
/** Clear an RTDM device.
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   127
 */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
void ec_rtdm_dev_clear(
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   129
        ec_rtdm_dev_t *rtdm_dev /**< EtherCAT RTDM device. */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
    EC_MASTER_INFO(rtdm_dev->master, "Unregistering RTDM device %s.\n",
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   133
            rtdm_dev->dev->label);
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   134
    rtdm_dev_unregister(rtdm_dev->dev);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
2700
93ef210e9b56 Intermediate state while updating master's RTDM part to Xenomai 3
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2524
diff changeset
   136
    kfree(rtdm_dev->dev->label);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    kfree(rtdm_dev->dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   139
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   140
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
/** Driver open.
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   143
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   144
 * \return Always zero (success).
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   145
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   146
int ec_rtdm_open(
2706
43f8e40a183d Continued update of master's rtdm part to xenomai 3 : rtdm_user_info_t now replaced by rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2700
diff changeset
   147
        struct rtdm_fd *fd, /**< User data. */
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   148
        int oflags /**< Open flags. */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
{
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   151
    ec_ioctl_context_t *ctx = (ec_ioctl_context_t *) rtdm_fd_to_private(fd);
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   152
#if DEBUG
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   153
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) rtdm_fd_device(fd)->device_data;
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   154
#endif
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   155
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   156
    ctx->writable = oflags & O_WRONLY || oflags & O_RDWR;
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   157
    ctx->requested = 0;
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   158
    ctx->process_data = NULL;
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   159
    ctx->process_data_size = 0;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
    EC_MASTER_INFO(rtdm_dev->master, "RTDM device %s opened.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   166
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   167
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   169
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
/** Driver close.
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   171
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   172
 * \return Always zero (success).
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   173
 */
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   174
void ec_rtdm_close(
2706
43f8e40a183d Continued update of master's rtdm part to xenomai 3 : rtdm_user_info_t now replaced by rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2700
diff changeset
   175
        struct rtdm_fd *fd /**< User data. */
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   176
        )
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
{
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   178
    ec_ioctl_context_t *ctx = (ec_ioctl_context_t *) rtdm_fd_to_private(fd);
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   179
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) rtdm_fd_device(fd)->device_data;
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   180
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   181
    if (ctx->requested) {
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        ecrt_release_master(rtdm_dev->master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   183
	}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   184
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   185
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    EC_MASTER_INFO(rtdm_dev->master, "RTDM device %s closed.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   190
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   191
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
/** Driver ioctl.
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   194
 *
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   195
 * \return ioctl() return code.
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
 */
2719
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   197
int ec_rtdm_rt_ioctl(
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   198
        struct rtdm_fd *fd, /**< User data. */
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   199
        unsigned int request, /**< Request. */
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   200
        void __user *arg /**< Argument. */
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   201
        )
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   202
{
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   203
    switch (request) {
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   204
        /*
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   205
            Requests to be handled directly in primary domain
2720
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   206
            
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   207
            Note: list was made by selecting calls in ioctl.c 
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   208
                  that seems not to make calls forbiden in primary mode
2719
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   209
        */
2720
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   210
        case EC_IOCTL_MASTER_RESCAN:
2719
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   211
        case EC_IOCTL_SEND:
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   212
        case EC_IOCTL_RECEIVE:
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   213
        case EC_IOCTL_MASTER_STATE:
2720
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   214
        case EC_IOCTL_MASTER_LINK_STATE:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   215
        case EC_IOCTL_APP_TIME:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   216
        case EC_IOCTL_SYNC_REF:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   217
        case EC_IOCTL_SYNC_SLAVES:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   218
        case EC_IOCTL_REF_CLOCK_TIME:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   219
        case EC_IOCTL_SYNC_MON_QUEUE:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   220
        case EC_IOCTL_SYNC_MON_PROCESS:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   221
        case EC_IOCTL_SC_EMERG_POP:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   222
        case EC_IOCTL_SC_EMERG_CLEAR:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   223
        case EC_IOCTL_SC_EMERG_OVERRUNS:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   224
        case EC_IOCTL_SC_STATE:
2719
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   225
        case EC_IOCTL_DOMAIN_STATE:
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   226
        case EC_IOCTL_DOMAIN_PROCESS:
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   227
        case EC_IOCTL_DOMAIN_QUEUE:
2720
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   228
        case EC_IOCTL_SDO_REQUEST_INDEX:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   229
        case EC_IOCTL_SDO_REQUEST_TIMEOUT:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   230
        case EC_IOCTL_SDO_REQUEST_STATE:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   231
        case EC_IOCTL_SDO_REQUEST_READ:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   232
        case EC_IOCTL_SDO_REQUEST_WRITE:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   233
        case EC_IOCTL_SDO_REQUEST_DATA:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   234
        case EC_IOCTL_REG_REQUEST_DATA:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   235
        case EC_IOCTL_REG_REQUEST_STATE:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   236
        case EC_IOCTL_REG_REQUEST_WRITE:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   237
        case EC_IOCTL_REG_REQUEST_READ:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   238
        case EC_IOCTL_VOE_SEND_HEADER:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   239
        case EC_IOCTL_VOE_REC_HEADER:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   240
        case EC_IOCTL_VOE_READ:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   241
        case EC_IOCTL_VOE_READ_NOSYNC:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   242
        case EC_IOCTL_VOE_WRITE:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   243
        case EC_IOCTL_VOE_EXEC:
4645c990fd79 RTDM: More IOCTL requests to be handled in primary mode
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2719
diff changeset
   244
        case EC_IOCTL_VOE_DATA:
2719
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   245
            return ec_rtdm_ioctl(fd, request, arg);
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   246
        default:
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   247
            break;
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   248
    }
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   249
    /* When a call is not supposed to happen in primary domain,
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   250
       syscall catches -ENOSYS, then switch to secondary mode,
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   251
       and calls .ioctl_nrt */
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   252
    return -ENOSYS;
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   253
}
94c9657e0bee 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."
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2713
diff changeset
   254
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   255
int ec_rtdm_ioctl(
2706
43f8e40a183d Continued update of master's rtdm part to xenomai 3 : rtdm_user_info_t now replaced by rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2700
diff changeset
   256
        struct rtdm_fd *fd, /**< User data. */
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   257
        unsigned int request, /**< Request. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   258
        void __user *arg /**< Argument. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   259
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   260
{
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   261
    ec_ioctl_context_t *ctx = (ec_ioctl_context_t *) rtdm_fd_to_private(fd);
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   262
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) rtdm_fd_device(fd)->device_data;
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   263
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   264
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   265
    EC_MASTER_INFO(rtdm_dev->master, "ioctl(request = %u, ctl = %02x)"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   266
            " on RTDM device %s.\n", request, _IOC_NR(request),
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   267
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   268
#endif
2707
245d8592cfdc Continued update of master's rtdm part to xenomai 3 : ioctl context now obtained from rtdm_fd
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2706
diff changeset
   269
    return ec_ioctl_rtdm(rtdm_dev->master, ctx, request, arg);
2433
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   270
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   272
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   273
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
/** Memory-map process data to user space.
2524
6d9865c37b6f Some more doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents: 2522
diff changeset
   275
 *
2712
5d21d80777a6 Use new RTDM's mmap, not anymore a special case compared to normal linux mmap.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2707
diff changeset
   276
 */
5d21d80777a6 Use new RTDM's mmap, not anymore a special case compared to normal linux mmap.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2707
diff changeset
   277
int ec_rtdm_mmap(struct rtdm_fd *fd, struct vm_area_struct *vma)
5d21d80777a6 Use new RTDM's mmap, not anymore a special case compared to normal linux mmap.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2707
diff changeset
   278
{
2713
2e2f57fd2131 More check in rtdm mmap, also use kernel memory instead of virtual memory.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   279
	size_t len;
2e2f57fd2131 More check in rtdm mmap, also use kernel memory instead of virtual memory.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   280
    ec_ioctl_context_t *ctx = (ec_ioctl_context_t *) rtdm_fd_to_private(fd);
2e2f57fd2131 More check in rtdm mmap, also use kernel memory instead of virtual memory.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   281
	len = vma->vm_end - vma->vm_start;
2e2f57fd2131 More check in rtdm mmap, also use kernel memory instead of virtual memory.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   282
	return rtdm_mmap_kmem(vma, (void *)ctx->process_data);
2e2f57fd2131 More check in rtdm mmap, also use kernel memory instead of virtual memory.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   283
}
2e2f57fd2131 More check in rtdm mmap, also use kernel memory instead of virtual memory.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   284
2e2f57fd2131 More check in rtdm mmap, also use kernel memory instead of virtual memory.
Edouard Tisserant <edouard.tisserant@gmail.com>
parents: 2712
diff changeset
   285
/****************************************************************************/