author | Florian Pose <fp@igh.de> |
Fri, 27 Oct 2017 12:33:30 +0200 | |
branch | stable-1.5 |
changeset 2691 | 9149adda56ed |
parent 2682 | 8d6833867a56 |
permissions | -rw-r--r-- |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
1 |
/****************************************************************************** |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
2 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
3 |
* $Id$ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
4 |
* |
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
5 |
* Copyright (C) 2006-2012 Florian Pose, Ingenieurgemeinschaft IgH |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
6 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
7 |
* This file is part of the IgH EtherCAT Master. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
8 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
9 |
* The IgH EtherCAT Master is free software; you can redistribute it and/or |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
10 |
* modify it under the terms of the GNU General Public License version 2, as |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
11 |
* published by the Free Software Foundation. |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
12 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
13 |
* The IgH EtherCAT Master is distributed in the hope that it will be useful, |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
16 |
* Public License for more details. |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
17 |
* |
1326
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
18 |
* You should have received a copy of the GNU General Public License along |
ef907b0b5125
merge -c1603 branches/stable-1.4: Changed licence headers to avoid conflicts with the GPL; restricted licence to GPLv2 only.
Florian Pose <fp@igh-essen.com>
parents:
1314
diff
changeset
|
19 |
* with the IgH EtherCAT Master; if not, write to the Free Software |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
20 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
21 |
* |
1363
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1362
diff
changeset
|
22 |
* --- |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1362
diff
changeset
|
23 |
* |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1362
diff
changeset
|
24 |
* The license mentioned above concerns the source code only. Using the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1362
diff
changeset
|
25 |
* EtherCAT technology and brand is only permitted in compliance with the |
11c0b2caa253
Improved and added license headers.
Florian Pose <fp@igh-essen.com>
parents:
1362
diff
changeset
|
26 |
* industrial property and similar rights of Beckhoff Automation GmbH. |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
27 |
* |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
28 |
*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
29 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
30 |
/** |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
31 |
\file |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
32 |
EtherCAT master character device. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
33 |
*/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
34 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
35 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
36 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
37 |
#include <linux/module.h> |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
38 |
#include <linux/vmalloc.h> |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
39 |
#include <linux/mm.h> |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
40 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
41 |
#include "cdev.h" |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
42 |
#include "master.h" |
950
8b00e63fff90
'ethercat domain' shows domain contents and process data.
Florian Pose <fp@igh-essen.com>
parents:
949
diff
changeset
|
43 |
#include "slave_config.h" |
1264
e7882f246d7a
Implemented VoE handler in userspace.
Florian Pose <fp@igh-essen.com>
parents:
1259
diff
changeset
|
44 |
#include "voe_handler.h" |
1485 | 45 |
#include "ethernet.h" |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
46 |
#include "ioctl.h" |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
47 |
|
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
48 |
/** Set to 1 to enable device operations debugging. |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
49 |
*/ |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
50 |
#define DEBUG 0 |
2306
4c0c7347a956
Removed some locks causing latency when using the library; added ioctl()
Florian Pose <fp@igh-essen.com>
parents:
2267
diff
changeset
|
51 |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
52 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
53 |
|
1268 | 54 |
static int eccdev_open(struct inode *, struct file *); |
55 |
static int eccdev_release(struct inode *, struct file *); |
|
56 |
static long eccdev_ioctl(struct file *, unsigned int, unsigned long); |
|
57 |
static int eccdev_mmap(struct file *, struct vm_area_struct *); |
|
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
58 |
|
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
59 |
/** This is the kernel version from which the .fault member of the |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
60 |
* vm_operations_struct is usable. |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
61 |
*/ |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
62 |
#define PAGE_FAULT_VERSION KERNEL_VERSION(2, 6, 23) |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
63 |
|
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
64 |
#if LINUX_VERSION_CODE >= PAGE_FAULT_VERSION |
2682 | 65 |
static int eccdev_vma_fault( |
66 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) |
|
67 |
struct vm_area_struct *, |
|
68 |
#endif |
|
69 |
struct vm_fault *); |
|
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
70 |
#else |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
71 |
static struct page *eccdev_vma_nopage( |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
72 |
struct vm_area_struct *, unsigned long, int *); |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
73 |
#endif |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
74 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
75 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
76 |
|
1268 | 77 |
/** File operation callbacks for the EtherCAT character device. |
78 |
*/ |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
79 |
static struct file_operations eccdev_fops = { |
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
80 |
.owner = THIS_MODULE, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
81 |
.open = eccdev_open, |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
82 |
.release = eccdev_release, |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
83 |
.unlocked_ioctl = eccdev_ioctl, |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
84 |
.mmap = eccdev_mmap |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
85 |
}; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
86 |
|
1268 | 87 |
/** Callbacks for a virtual memory area retrieved with ecdevc_mmap(). |
88 |
*/ |
|
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
89 |
struct vm_operations_struct eccdev_vm_ops = { |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
90 |
#if LINUX_VERSION_CODE >= PAGE_FAULT_VERSION |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
91 |
.fault = eccdev_vma_fault |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
92 |
#else |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
93 |
.nopage = eccdev_vma_nopage |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
94 |
#endif |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
95 |
}; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
96 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
97 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
98 |
|
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
99 |
/** Private data structure for file handles. |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
100 |
*/ |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
101 |
typedef struct { |
1268 | 102 |
ec_cdev_t *cdev; /**< Character device. */ |
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
103 |
ec_ioctl_context_t ctx; /**< Context. */ |
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
104 |
} ec_cdev_priv_t; |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
105 |
|
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
106 |
/*****************************************************************************/ |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
107 |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
108 |
/** Constructor. |
2421 | 109 |
* |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
110 |
* \return 0 in case of success, else < 0 |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
111 |
*/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
112 |
int ec_cdev_init( |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
113 |
ec_cdev_t *cdev, /**< EtherCAT master character device. */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
114 |
ec_master_t *master, /**< Parent master. */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
115 |
dev_t dev_num /**< Device number. */ |
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
116 |
) |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
117 |
{ |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
118 |
int ret; |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
119 |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
120 |
cdev->master = master; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
121 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
122 |
cdev_init(&cdev->cdev, &eccdev_fops); |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
123 |
cdev->cdev.owner = THIS_MODULE; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
124 |
|
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
125 |
ret = cdev_add(&cdev->cdev, |
1507
68e89abadd19
Removed unwanted tabulators.
Florian Pose <fp@igh-essen.com>
parents:
1500
diff
changeset
|
126 |
MKDEV(MAJOR(dev_num), master->index), 1); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
127 |
if (ret) { |
1921 | 128 |
EC_MASTER_ERR(master, "Failed to add character device!\n"); |
1313
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
129 |
} |
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
130 |
|
ed15eef57d5c
Improved error case return codes of many functions.
Florian Pose <fp@igh-essen.com>
parents:
1312
diff
changeset
|
131 |
return ret; |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
132 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
133 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
134 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
135 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
136 |
/** Destructor. |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
137 |
*/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
138 |
void ec_cdev_clear(ec_cdev_t *cdev /**< EtherCAT XML device */) |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
139 |
{ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
140 |
cdev_del(&cdev->cdev); |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
141 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
142 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
143 |
/****************************************************************************** |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
144 |
* File operations |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
145 |
*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
146 |
|
1092 | 147 |
/** Called when the cdev is opened. |
148 |
*/ |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
149 |
int eccdev_open(struct inode *inode, struct file *filp) |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
150 |
{ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
151 |
ec_cdev_t *cdev = container_of(inode->i_cdev, ec_cdev_t, cdev); |
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
152 |
ec_cdev_priv_t *priv; |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
153 |
|
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
154 |
priv = kmalloc(sizeof(ec_cdev_priv_t), GFP_KERNEL); |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
155 |
if (!priv) { |
1922 | 156 |
EC_MASTER_ERR(cdev->master, |
157 |
"Failed to allocate memory for private data structure.\n"); |
|
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
158 |
return -ENOMEM; |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
159 |
} |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
160 |
|
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
161 |
priv->cdev = cdev; |
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
162 |
priv->ctx.writable = (filp->f_mode & FMODE_WRITE) != 0; |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
163 |
priv->ctx.requested = 0; |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
164 |
priv->ctx.process_data = NULL; |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
165 |
priv->ctx.process_data_size = 0; |
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
166 |
|
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
167 |
filp->private_data = priv; |
1397 | 168 |
|
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
169 |
#if DEBUG |
1931 | 170 |
EC_MASTER_DBG(cdev->master, 0, "File opened.\n"); |
1397 | 171 |
#endif |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
172 |
return 0; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
173 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
174 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
175 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
176 |
|
1092 | 177 |
/** Called when the cdev is closed. |
178 |
*/ |
|
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
179 |
int eccdev_release(struct inode *inode, struct file *filp) |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
180 |
{ |
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
181 |
ec_cdev_priv_t *priv = (ec_cdev_priv_t *) filp->private_data; |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
182 |
ec_master_t *master = priv->cdev->master; |
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
183 |
|
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
184 |
if (priv->ctx.requested) { |
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
185 |
ecrt_release_master(master); |
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
186 |
} |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
187 |
|
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
188 |
if (priv->ctx.process_data) { |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
189 |
vfree(priv->ctx.process_data); |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
190 |
} |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
191 |
|
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
192 |
#if DEBUG |
1931 | 193 |
EC_MASTER_DBG(master, 0, "File closed.\n"); |
1397 | 194 |
#endif |
195 |
||
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
196 |
kfree(priv); |
922
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
197 |
return 0; |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
198 |
} |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
199 |
|
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
200 |
/*****************************************************************************/ |
fede1d8f5b71
Added the new ethercat comman-line tool with lsec functionality.
Florian Pose <fp@igh-essen.com>
parents:
diff
changeset
|
201 |
|
1092 | 202 |
/** Called when an ioctl() command is issued. |
203 |
*/ |
|
935
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
204 |
long eccdev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) |
b954e9d91ea5
Added 'pdos' command to ethercat tool.
Florian Pose <fp@igh-essen.com>
parents:
922
diff
changeset
|
205 |
{ |
1242
632a6b91f8e4
First version of userspace library with requesting/releasing.
Florian Pose <fp@igh-essen.com>
parents:
1223
diff
changeset
|
206 |
ec_cdev_priv_t *priv = (ec_cdev_priv_t *) filp->private_data; |
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
207 |
|
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
208 |
#if DEBUG |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
209 |
EC_MASTER_DBG(priv->cdev->master, 0, |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
210 |
"ioctl(filp = 0x%p, cmd = 0x%08x (0x%02x), arg = 0x%lx)\n", |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
211 |
filp, cmd, _IOC_NR(cmd), arg); |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
212 |
#endif |
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
213 |
|
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
214 |
return ec_ioctl(priv->cdev->master, &priv->ctx, cmd, (void __user *) arg); |
1079
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
215 |
} |
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
216 |
|
ef1266652c4d
Improved locking between ioctl()s and master state machine; separate
Florian Pose <fp@igh-essen.com>
parents:
1075
diff
changeset
|
217 |
/*****************************************************************************/ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
218 |
|
2516
3680924f6f87
Replaced VM_RESERVED for kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents:
2433
diff
changeset
|
219 |
#ifndef VM_DONTDUMP |
3680924f6f87
Replaced VM_RESERVED for kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents:
2433
diff
changeset
|
220 |
/** VM_RESERVED disappeared in 3.7. |
3680924f6f87
Replaced VM_RESERVED for kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents:
2433
diff
changeset
|
221 |
*/ |
3680924f6f87
Replaced VM_RESERVED for kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents:
2433
diff
changeset
|
222 |
#define VM_DONTDUMP VM_RESERVED |
3680924f6f87
Replaced VM_RESERVED for kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents:
2433
diff
changeset
|
223 |
#endif |
3680924f6f87
Replaced VM_RESERVED for kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents:
2433
diff
changeset
|
224 |
|
1268 | 225 |
/** Memory-map callback for the EtherCAT character device. |
226 |
* |
|
227 |
* The actual mapping will be done in the eccdev_vma_nopage() callback of the |
|
228 |
* virtual memory area. |
|
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2516
diff
changeset
|
229 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2516
diff
changeset
|
230 |
* \return Always zero (success). |
1268 | 231 |
*/ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
232 |
int eccdev_mmap( |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
233 |
struct file *filp, |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
234 |
struct vm_area_struct *vma |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
235 |
) |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
236 |
{ |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
237 |
ec_cdev_priv_t *priv = (ec_cdev_priv_t *) filp->private_data; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
238 |
|
1921 | 239 |
EC_MASTER_DBG(priv->cdev->master, 1, "mmap()\n"); |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
240 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
241 |
vma->vm_ops = &eccdev_vm_ops; |
2516
3680924f6f87
Replaced VM_RESERVED for kernel 3.7.
Florian Pose <fp@igh-essen.com>
parents:
2433
diff
changeset
|
242 |
vma->vm_flags |= VM_DONTDUMP; /* Pages will not be swapped out */ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
243 |
vma->vm_private_data = priv; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
244 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
245 |
return 0; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
246 |
} |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
247 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
248 |
/*****************************************************************************/ |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
249 |
|
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
250 |
#if LINUX_VERSION_CODE >= PAGE_FAULT_VERSION |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
251 |
|
1268 | 252 |
/** Page fault callback for a virtual memory area. |
253 |
* |
|
254 |
* Called at the first access on a virtual-memory area retrieved with |
|
255 |
* ecdev_mmap(). |
|
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2516
diff
changeset
|
256 |
* |
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2516
diff
changeset
|
257 |
* \return Zero on success, otherwise a negative error code. |
1268 | 258 |
*/ |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
259 |
static int eccdev_vma_fault( |
2681
9953c0d372ab
Adapted vm_operations_struct for kernels >= 4.11
Florian Pose <fp@igh.de>
parents:
2522
diff
changeset
|
260 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 11, 0) |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
261 |
struct vm_area_struct *vma, /**< Virtual memory area. */ |
2681
9953c0d372ab
Adapted vm_operations_struct for kernels >= 4.11
Florian Pose <fp@igh.de>
parents:
2522
diff
changeset
|
262 |
#endif |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
263 |
struct vm_fault *vmf /**< Fault data. */ |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
264 |
) |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
265 |
{ |
2681
9953c0d372ab
Adapted vm_operations_struct for kernels >= 4.11
Florian Pose <fp@igh.de>
parents:
2522
diff
changeset
|
266 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) |
9953c0d372ab
Adapted vm_operations_struct for kernels >= 4.11
Florian Pose <fp@igh.de>
parents:
2522
diff
changeset
|
267 |
struct vm_area_struct *vma = vmf->vma; |
9953c0d372ab
Adapted vm_operations_struct for kernels >= 4.11
Florian Pose <fp@igh.de>
parents:
2522
diff
changeset
|
268 |
#endif |
1284 | 269 |
unsigned long offset = vmf->pgoff << PAGE_SHIFT; |
270 |
ec_cdev_priv_t *priv = (ec_cdev_priv_t *) vma->vm_private_data; |
|
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
271 |
struct page *page; |
1284 | 272 |
|
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2516
diff
changeset
|
273 |
if (offset >= priv->ctx.process_data_size) { |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
274 |
return VM_FAULT_SIGBUS; |
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2516
diff
changeset
|
275 |
} |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
276 |
|
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
277 |
page = vmalloc_to_page(priv->ctx.process_data + offset); |
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2516
diff
changeset
|
278 |
if (!page) { |
1284 | 279 |
return VM_FAULT_SIGBUS; |
2522
ec403cf308eb
Updated Doxygen documentation.
Florian Pose <fp@igh-essen.com>
parents:
2516
diff
changeset
|
280 |
} |
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
281 |
|
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
282 |
get_page(page); |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
283 |
vmf->page = page; |
1284 | 284 |
|
2682 | 285 |
EC_MASTER_DBG(priv->cdev->master, 1, "Vma fault," |
286 |
" offset = %lu, page = %p\n", offset, page); |
|
1284 | 287 |
|
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
288 |
return 0; |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
289 |
} |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
290 |
|
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
291 |
#else |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
292 |
|
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
293 |
/** Nopage callback for a virtual memory area. |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
294 |
* |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
295 |
* Called at the first access on a virtual-memory area retrieved with |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
296 |
* ecdev_mmap(). |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
297 |
*/ |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
298 |
struct page *eccdev_vma_nopage( |
1268 | 299 |
struct vm_area_struct *vma, /**< Virtual memory area initialized by |
300 |
the kernel. */ |
|
301 |
unsigned long address, /**< Requested virtual address. */ |
|
302 |
int *type /**< Type output parameter. */ |
|
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
303 |
) |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
304 |
{ |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
305 |
unsigned long offset; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
306 |
struct page *page = NOPAGE_SIGBUS; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
307 |
ec_cdev_priv_t *priv = (ec_cdev_priv_t *) vma->vm_private_data; |
2061
7982704c8599
Fixed compiler error for kernel versions < 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
2009
diff
changeset
|
308 |
ec_master_t *master = priv->cdev->master; |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
309 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
310 |
offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
311 |
|
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
312 |
if (offset >= priv->ctx.process_data_size) |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
313 |
return NOPAGE_SIGBUS; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
314 |
|
2433
3bdd7a747fae
Re-worked and seamlessly integrated RTDM interface.
Florian Pose <fp@igh-essen.com>
parents:
2421
diff
changeset
|
315 |
page = vmalloc_to_page(priv->ctx.process_data + offset); |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
316 |
|
2061
7982704c8599
Fixed compiler error for kernel versions < 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
2009
diff
changeset
|
317 |
EC_MASTER_DBG(master, 1, "Nopage fault vma, address = %#lx," |
1921 | 318 |
" offset = %#lx, page = %p\n", address, offset, page); |
1258
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
319 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
320 |
get_page(page); |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
321 |
if (type) |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
322 |
*type = VM_FAULT_MINOR; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
323 |
|
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
324 |
return page; |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
325 |
} |
900f1124e8f8
Memory-mapped process data.
Florian Pose <fp@igh-essen.com>
parents:
1255
diff
changeset
|
326 |
|
1272
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
327 |
#endif |
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
328 |
|
288c982acd23
Use .fault handler instead of .nopage handler from 2.6.23.
Florian Pose <fp@igh-essen.com>
parents:
1268
diff
changeset
|
329 |
/*****************************************************************************/ |