master/rtdm.c
author Florian Pose <fp@igh-essen.com>
Tue, 12 Feb 2013 11:52:03 +0100
branchstable-1.5
changeset 2518 e5640f5e10a2
parent 2433 3bdd7a747fae
child 2522 ec403cf308eb
permissions -rw-r--r--
TTY: termios structure was included in 'struct tty' with kernel 3.7.
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
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
#include <linux/module.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#include <linux/slab.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
#include <linux/mman.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
#include <rtdm/rtdm_driver.h>
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    34
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
#include "master.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#include "ioctl.h"
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
#include "rtdm.h"
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
/** 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
    40
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
#define DEBUG 0
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
/****************************************************************************/
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
/** Context structure for an open RTDM file handle.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
typedef struct {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
    rtdm_user_info_t *user_info;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    ec_ioctl_context_t ioctl_ctx;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
} ec_rtdm_context_t;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
int ec_rtdm_open(struct rtdm_dev_context *, rtdm_user_info_t *, int);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
int ec_rtdm_close(struct rtdm_dev_context *, rtdm_user_info_t *);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
int ec_rtdm_ioctl(struct rtdm_dev_context *, rtdm_user_info_t *,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
        unsigned int, void __user *);
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
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
int ec_rtdm_dev_init(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
        ec_rtdm_dev_t *rtdm_dev,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
        ec_master_t *master
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    65
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    67
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
    rtdm_dev->master = master;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
    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
    71
    if (!rtdm_dev->dev) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
        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
    73
        return -ENOMEM;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
    rtdm_dev->dev->struct_version = RTDM_DEVICE_STRUCT_VER;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
    rtdm_dev->dev->device_flags = RTDM_NAMED_DEVICE;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
    rtdm_dev->dev->context_size = sizeof(ec_rtdm_context_t);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
    snprintf(rtdm_dev->dev->device_name, RTDM_MAX_DEVNAME_LEN,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    80
            "EtherCAT%u", master->index);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    rtdm_dev->dev->open_nrt = ec_rtdm_open;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
    rtdm_dev->dev->ops.close_nrt = ec_rtdm_close;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
    rtdm_dev->dev->ops.ioctl_rt = ec_rtdm_ioctl;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
    rtdm_dev->dev->ops.ioctl_nrt = ec_rtdm_ioctl;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
    rtdm_dev->dev->device_class = RTDM_CLASS_EXPERIMENTAL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
    rtdm_dev->dev->device_sub_class = 222;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
    rtdm_dev->dev->driver_name = "EtherCAT";
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
    rtdm_dev->dev->driver_version = RTDM_DRIVER_VER(1, 0, 2);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    89
    rtdm_dev->dev->peripheral_name = rtdm_dev->dev->device_name;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    rtdm_dev->dev->provider_name = "EtherLab Community";
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
    rtdm_dev->dev->proc_name = rtdm_dev->dev->device_name;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
    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
    93
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
    EC_MASTER_INFO(master, "Registering RTDM device %s.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
            rtdm_dev->dev->driver_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
    ret = rtdm_dev_register(rtdm_dev->dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
    if (ret) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
        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
    99
                " (return value %i).\n", ret);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   100
        kfree(rtdm_dev->dev);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   101
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   102
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   103
    return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   104
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   105
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   106
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   107
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   108
void ec_rtdm_dev_clear(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   109
        ec_rtdm_dev_t *rtdm_dev
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   110
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   111
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   112
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   113
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   114
    EC_MASTER_INFO(rtdm_dev->master, "Unregistering RTDM device %s.\n",
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   115
            rtdm_dev->dev->driver_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   116
    ret = rtdm_dev_unregister(rtdm_dev->dev, 1000 /* poll delay [ms] */);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   117
    if (ret < 0) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   118
        EC_MASTER_WARN(rtdm_dev->master,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   119
                "Failed to unregister RTDM device (code %i).\n", ret);
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
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   122
    kfree(rtdm_dev->dev);
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
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   126
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   127
/** Driver open.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   128
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   129
int ec_rtdm_open(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   130
        struct rtdm_dev_context *context,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   131
        rtdm_user_info_t *user_info,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   132
        int oflags
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   133
        )
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   134
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   135
    ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   136
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   137
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   138
#endif
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
    ctx->user_info = user_info;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   141
    ctx->ioctl_ctx.writable = oflags & O_WRONLY || oflags & O_RDWR;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   142
    ctx->ioctl_ctx.requested = 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   143
    ctx->ioctl_ctx.process_data = NULL;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   144
    ctx->ioctl_ctx.process_data_size = 0;
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
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   147
    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
   148
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   149
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   150
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   151
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   152
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   153
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   154
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   155
/** Driver close.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   156
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   157
int ec_rtdm_close(struct rtdm_dev_context *context,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   158
        rtdm_user_info_t *user_info)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   159
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   160
    ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   161
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   162
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   163
    if (ctx->ioctl_ctx.requested) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   164
        ecrt_release_master(rtdm_dev->master);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   165
	}
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
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   168
    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
   169
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   170
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   171
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   172
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   173
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   174
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   175
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   176
/** Driver ioctl.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   177
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   178
int ec_rtdm_ioctl(
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   179
        struct rtdm_dev_context *context, /**< Context. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   180
        rtdm_user_info_t *user_info, /**< User data. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   181
        unsigned int request, /**< Request. */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   182
        void __user *arg /**< Argument. */
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
    ec_rtdm_context_t *ctx = (ec_rtdm_context_t *) context->dev_private;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   186
    ec_rtdm_dev_t *rtdm_dev = (ec_rtdm_dev_t *) context->device->device_data;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   187
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   188
#if DEBUG
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   189
    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
   190
            " 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
   191
            context->device->device_name);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   192
#endif
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   193
    return ec_ioctl_rtdm(rtdm_dev->master, &ctx->ioctl_ctx, request, arg);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   194
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   195
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   196
/****************************************************************************/
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   197
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   198
/** Memory-map process data to user space.
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   199
 */
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   200
int ec_rtdm_mmap(ec_ioctl_context_t *ioctl_ctx, void **user_address)
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   201
{
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   202
    ec_rtdm_context_t *ctx =
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   203
        container_of(ioctl_ctx, ec_rtdm_context_t, ioctl_ctx);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   204
    int ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   205
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   206
    ret = rtdm_mmap_to_user(ctx->user_info,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   207
            ioctl_ctx->process_data, ioctl_ctx->process_data_size,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   208
            PROT_READ | PROT_WRITE,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   209
            user_address,
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   210
            NULL, NULL);
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   211
    if (ret < 0) {
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   212
        return ret;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
    }
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   214
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   215
    return 0;
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   216
}
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   217
3bdd7a747fae Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   218
/****************************************************************************/