1 // SPDX-License-Identifier: GPL-2.0+
6 * COMEDI - Linux Control and Measurement Device Interface
7 * Copyright (C) 1997-2007 David A. Schleef <ds@schleef.org>
9 * Author: Ian Abbott, MEV Ltd. <abbotti@mev.co.uk>
10 * Copyright (C) 2007 MEV Ltd. <http://www.mev.co.uk/>
13 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15 #include <linux/module.h>
16 #include <linux/errno.h>
17 #include <linux/kernel.h>
18 #include <linux/sched/signal.h>
19 #include <linux/fcntl.h>
20 #include <linux/delay.h>
22 #include <linux/slab.h>
23 #include <linux/poll.h>
24 #include <linux/device.h>
26 #include <linux/comedi/comedidev.h>
27 #include <linux/cdev.h>
30 #include <linux/uaccess.h>
31 #include <linux/compat.h>
33 #include "comedi_internal.h"
36 * comedi_subdevice "runflags"
37 * COMEDI_SRF_RT: DEPRECATED: command is running real-time
38 * COMEDI_SRF_ERROR: indicates an COMEDI_CB_ERROR event has occurred
39 * since the last command was started
40 * COMEDI_SRF_RUNNING: command is running
41 * COMEDI_SRF_FREE_SPRIV: free s->private on detach
43 * COMEDI_SRF_BUSY_MASK: runflags that indicate the subdevice is "busy"
45 #define COMEDI_SRF_RT BIT(1)
46 #define COMEDI_SRF_ERROR BIT(2)
47 #define COMEDI_SRF_RUNNING BIT(27)
48 #define COMEDI_SRF_FREE_SPRIV BIT(31)
50 #define COMEDI_SRF_BUSY_MASK (COMEDI_SRF_ERROR | COMEDI_SRF_RUNNING)
53 * struct comedi_file - Per-file private data for COMEDI device
54 * @dev: COMEDI device.
55 * @read_subdev: Current "read" subdevice.
56 * @write_subdev: Current "write" subdevice.
57 * @last_detach_count: Last known detach count.
58 * @last_attached: Last known attached/detached state.
61 struct comedi_device
*dev
;
62 struct comedi_subdevice
*read_subdev
;
63 struct comedi_subdevice
*write_subdev
;
64 unsigned int last_detach_count
;
65 unsigned int last_attached
:1;
68 #define COMEDI_NUM_MINORS 0x100
69 #define COMEDI_NUM_SUBDEVICE_MINORS \
70 (COMEDI_NUM_MINORS - COMEDI_NUM_BOARD_MINORS)
72 static unsigned short comedi_num_legacy_minors
;
73 module_param(comedi_num_legacy_minors
, ushort
, 0444);
74 MODULE_PARM_DESC(comedi_num_legacy_minors
,
75 "number of comedi minor devices to reserve for non-auto-configured devices (default 0)"
78 unsigned int comedi_default_buf_size_kb
= CONFIG_COMEDI_DEFAULT_BUF_SIZE_KB
;
79 module_param(comedi_default_buf_size_kb
, uint
, 0644);
80 MODULE_PARM_DESC(comedi_default_buf_size_kb
,
81 "default asynchronous buffer size in KiB (default "
82 __MODULE_STRING(CONFIG_COMEDI_DEFAULT_BUF_SIZE_KB
) ")");
84 unsigned int comedi_default_buf_maxsize_kb
=
85 CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB
;
86 module_param(comedi_default_buf_maxsize_kb
, uint
, 0644);
87 MODULE_PARM_DESC(comedi_default_buf_maxsize_kb
,
88 "default maximum size of asynchronous buffer in KiB (default "
89 __MODULE_STRING(CONFIG_COMEDI_DEFAULT_BUF_MAXSIZE_KB
) ")");
91 static DEFINE_MUTEX(comedi_board_minor_table_lock
);
92 static struct comedi_device
93 *comedi_board_minor_table
[COMEDI_NUM_BOARD_MINORS
];
95 static DEFINE_MUTEX(comedi_subdevice_minor_table_lock
);
96 /* Note: indexed by minor - COMEDI_NUM_BOARD_MINORS. */
97 static struct comedi_subdevice
98 *comedi_subdevice_minor_table
[COMEDI_NUM_SUBDEVICE_MINORS
];
100 static struct cdev comedi_cdev
;
102 static void comedi_device_init(struct comedi_device
*dev
)
104 kref_init(&dev
->refcount
);
105 spin_lock_init(&dev
->spinlock
);
106 mutex_init(&dev
->mutex
);
107 init_rwsem(&dev
->attach_lock
);
111 static void comedi_dev_kref_release(struct kref
*kref
)
113 struct comedi_device
*dev
=
114 container_of(kref
, struct comedi_device
, refcount
);
116 mutex_destroy(&dev
->mutex
);
117 put_device(dev
->class_dev
);
122 * comedi_dev_put() - Release a use of a COMEDI device
123 * @dev: COMEDI device.
125 * Must be called when a user of a COMEDI device is finished with it.
126 * When the last user of the COMEDI device calls this function, the
127 * COMEDI device is destroyed.
129 * Return: 1 if the COMEDI device is destroyed by this call or @dev is
130 * NULL, otherwise return 0. Callers must not assume the COMEDI
131 * device is still valid if this function returns 0.
133 int comedi_dev_put(struct comedi_device
*dev
)
136 return kref_put(&dev
->refcount
, comedi_dev_kref_release
);
139 EXPORT_SYMBOL_GPL(comedi_dev_put
);
141 static struct comedi_device
*comedi_dev_get(struct comedi_device
*dev
)
144 kref_get(&dev
->refcount
);
148 static void comedi_device_cleanup(struct comedi_device
*dev
)
150 struct module
*driver_module
= NULL
;
154 mutex_lock(&dev
->mutex
);
156 driver_module
= dev
->driver
->module
;
157 comedi_device_detach(dev
);
158 if (driver_module
&& dev
->use_count
)
159 module_put(driver_module
);
160 mutex_unlock(&dev
->mutex
);
163 static bool comedi_clear_board_dev(struct comedi_device
*dev
)
165 unsigned int i
= dev
->minor
;
166 bool cleared
= false;
168 lockdep_assert_held(&dev
->mutex
);
169 mutex_lock(&comedi_board_minor_table_lock
);
170 if (dev
== comedi_board_minor_table
[i
]) {
171 comedi_board_minor_table
[i
] = NULL
;
174 mutex_unlock(&comedi_board_minor_table_lock
);
178 static struct comedi_device
*comedi_clear_board_minor(unsigned int minor
)
180 struct comedi_device
*dev
;
182 mutex_lock(&comedi_board_minor_table_lock
);
183 dev
= comedi_board_minor_table
[minor
];
184 comedi_board_minor_table
[minor
] = NULL
;
185 mutex_unlock(&comedi_board_minor_table_lock
);
189 static struct comedi_subdevice
*
190 comedi_subdevice_from_minor(const struct comedi_device
*dev
, unsigned int minor
)
192 struct comedi_subdevice
*s
;
193 unsigned int i
= minor
- COMEDI_NUM_BOARD_MINORS
;
195 mutex_lock(&comedi_subdevice_minor_table_lock
);
196 s
= comedi_subdevice_minor_table
[i
];
197 if (s
&& s
->device
!= dev
)
199 mutex_unlock(&comedi_subdevice_minor_table_lock
);
203 static struct comedi_device
*comedi_dev_get_from_board_minor(unsigned int minor
)
205 struct comedi_device
*dev
;
207 mutex_lock(&comedi_board_minor_table_lock
);
208 dev
= comedi_dev_get(comedi_board_minor_table
[minor
]);
209 mutex_unlock(&comedi_board_minor_table_lock
);
213 static struct comedi_device
*
214 comedi_dev_get_from_subdevice_minor(unsigned int minor
)
216 struct comedi_device
*dev
;
217 struct comedi_subdevice
*s
;
218 unsigned int i
= minor
- COMEDI_NUM_BOARD_MINORS
;
220 mutex_lock(&comedi_subdevice_minor_table_lock
);
221 s
= comedi_subdevice_minor_table
[i
];
222 dev
= comedi_dev_get(s
? s
->device
: NULL
);
223 mutex_unlock(&comedi_subdevice_minor_table_lock
);
228 * comedi_dev_get_from_minor() - Get COMEDI device by minor device number
229 * @minor: Minor device number.
231 * Finds the COMEDI device associated with the minor device number, if any,
232 * and increments its reference count. The COMEDI device is prevented from
233 * being freed until a matching call is made to comedi_dev_put().
235 * Return: A pointer to the COMEDI device if it exists, with its usage
236 * reference incremented. Return NULL if no COMEDI device exists with the
237 * specified minor device number.
239 struct comedi_device
*comedi_dev_get_from_minor(unsigned int minor
)
241 if (minor
< COMEDI_NUM_BOARD_MINORS
)
242 return comedi_dev_get_from_board_minor(minor
);
244 return comedi_dev_get_from_subdevice_minor(minor
);
246 EXPORT_SYMBOL_GPL(comedi_dev_get_from_minor
);
248 static struct comedi_subdevice
*
249 comedi_read_subdevice(const struct comedi_device
*dev
, unsigned int minor
)
251 struct comedi_subdevice
*s
;
253 lockdep_assert_held(&dev
->mutex
);
254 if (minor
>= COMEDI_NUM_BOARD_MINORS
) {
255 s
= comedi_subdevice_from_minor(dev
, minor
);
256 if (!s
|| (s
->subdev_flags
& SDF_CMD_READ
))
259 return dev
->read_subdev
;
262 static struct comedi_subdevice
*
263 comedi_write_subdevice(const struct comedi_device
*dev
, unsigned int minor
)
265 struct comedi_subdevice
*s
;
267 lockdep_assert_held(&dev
->mutex
);
268 if (minor
>= COMEDI_NUM_BOARD_MINORS
) {
269 s
= comedi_subdevice_from_minor(dev
, minor
);
270 if (!s
|| (s
->subdev_flags
& SDF_CMD_WRITE
))
273 return dev
->write_subdev
;
276 static void comedi_file_reset(struct file
*file
)
278 struct comedi_file
*cfp
= file
->private_data
;
279 struct comedi_device
*dev
= cfp
->dev
;
280 struct comedi_subdevice
*s
, *read_s
, *write_s
;
281 unsigned int minor
= iminor(file_inode(file
));
283 read_s
= dev
->read_subdev
;
284 write_s
= dev
->write_subdev
;
285 if (minor
>= COMEDI_NUM_BOARD_MINORS
) {
286 s
= comedi_subdevice_from_minor(dev
, minor
);
287 if (!s
|| s
->subdev_flags
& SDF_CMD_READ
)
289 if (!s
|| s
->subdev_flags
& SDF_CMD_WRITE
)
292 cfp
->last_attached
= dev
->attached
;
293 cfp
->last_detach_count
= dev
->detach_count
;
294 WRITE_ONCE(cfp
->read_subdev
, read_s
);
295 WRITE_ONCE(cfp
->write_subdev
, write_s
);
298 static void comedi_file_check(struct file
*file
)
300 struct comedi_file
*cfp
= file
->private_data
;
301 struct comedi_device
*dev
= cfp
->dev
;
303 if (cfp
->last_attached
!= dev
->attached
||
304 cfp
->last_detach_count
!= dev
->detach_count
)
305 comedi_file_reset(file
);
308 static struct comedi_subdevice
*comedi_file_read_subdevice(struct file
*file
)
310 struct comedi_file
*cfp
= file
->private_data
;
312 comedi_file_check(file
);
313 return READ_ONCE(cfp
->read_subdev
);
316 static struct comedi_subdevice
*comedi_file_write_subdevice(struct file
*file
)
318 struct comedi_file
*cfp
= file
->private_data
;
320 comedi_file_check(file
);
321 return READ_ONCE(cfp
->write_subdev
);
324 static int resize_async_buffer(struct comedi_device
*dev
,
325 struct comedi_subdevice
*s
,
326 unsigned int new_size
)
328 struct comedi_async
*async
= s
->async
;
331 lockdep_assert_held(&dev
->mutex
);
333 if (new_size
> async
->max_bufsize
)
337 dev_dbg(dev
->class_dev
,
338 "subdevice is busy, cannot resize buffer\n");
341 if (comedi_buf_is_mmapped(s
)) {
342 dev_dbg(dev
->class_dev
,
343 "subdevice is mmapped, cannot resize buffer\n");
347 /* make sure buffer is an integral number of pages (we round up) */
348 new_size
= (new_size
+ PAGE_SIZE
- 1) & PAGE_MASK
;
350 retval
= comedi_buf_alloc(dev
, s
, new_size
);
355 retval
= s
->buf_change(dev
, s
);
360 dev_dbg(dev
->class_dev
, "subd %d buffer resized to %i bytes\n",
361 s
->index
, async
->prealloc_bufsz
);
365 /* sysfs attribute files */
367 static ssize_t
max_read_buffer_kb_show(struct device
*csdev
,
368 struct device_attribute
*attr
, char *buf
)
370 unsigned int minor
= MINOR(csdev
->devt
);
371 struct comedi_device
*dev
;
372 struct comedi_subdevice
*s
;
373 unsigned int size
= 0;
375 dev
= comedi_dev_get_from_minor(minor
);
379 mutex_lock(&dev
->mutex
);
380 s
= comedi_read_subdevice(dev
, minor
);
381 if (s
&& (s
->subdev_flags
& SDF_CMD_READ
) && s
->async
)
382 size
= s
->async
->max_bufsize
/ 1024;
383 mutex_unlock(&dev
->mutex
);
386 return sysfs_emit(buf
, "%u\n", size
);
389 static ssize_t
max_read_buffer_kb_store(struct device
*csdev
,
390 struct device_attribute
*attr
,
391 const char *buf
, size_t count
)
393 unsigned int minor
= MINOR(csdev
->devt
);
394 struct comedi_device
*dev
;
395 struct comedi_subdevice
*s
;
399 err
= kstrtouint(buf
, 10, &size
);
402 if (size
> (UINT_MAX
/ 1024))
406 dev
= comedi_dev_get_from_minor(minor
);
410 mutex_lock(&dev
->mutex
);
411 s
= comedi_read_subdevice(dev
, minor
);
412 if (s
&& (s
->subdev_flags
& SDF_CMD_READ
) && s
->async
)
413 s
->async
->max_bufsize
= size
;
416 mutex_unlock(&dev
->mutex
);
419 return err
? err
: count
;
421 static DEVICE_ATTR_RW(max_read_buffer_kb
);
423 static ssize_t
read_buffer_kb_show(struct device
*csdev
,
424 struct device_attribute
*attr
, char *buf
)
426 unsigned int minor
= MINOR(csdev
->devt
);
427 struct comedi_device
*dev
;
428 struct comedi_subdevice
*s
;
429 unsigned int size
= 0;
431 dev
= comedi_dev_get_from_minor(minor
);
435 mutex_lock(&dev
->mutex
);
436 s
= comedi_read_subdevice(dev
, minor
);
437 if (s
&& (s
->subdev_flags
& SDF_CMD_READ
) && s
->async
)
438 size
= s
->async
->prealloc_bufsz
/ 1024;
439 mutex_unlock(&dev
->mutex
);
442 return sysfs_emit(buf
, "%u\n", size
);
445 static ssize_t
read_buffer_kb_store(struct device
*csdev
,
446 struct device_attribute
*attr
,
447 const char *buf
, size_t count
)
449 unsigned int minor
= MINOR(csdev
->devt
);
450 struct comedi_device
*dev
;
451 struct comedi_subdevice
*s
;
455 err
= kstrtouint(buf
, 10, &size
);
458 if (size
> (UINT_MAX
/ 1024))
462 dev
= comedi_dev_get_from_minor(minor
);
466 mutex_lock(&dev
->mutex
);
467 s
= comedi_read_subdevice(dev
, minor
);
468 if (s
&& (s
->subdev_flags
& SDF_CMD_READ
) && s
->async
)
469 err
= resize_async_buffer(dev
, s
, size
);
472 mutex_unlock(&dev
->mutex
);
475 return err
? err
: count
;
477 static DEVICE_ATTR_RW(read_buffer_kb
);
479 static ssize_t
max_write_buffer_kb_show(struct device
*csdev
,
480 struct device_attribute
*attr
,
483 unsigned int minor
= MINOR(csdev
->devt
);
484 struct comedi_device
*dev
;
485 struct comedi_subdevice
*s
;
486 unsigned int size
= 0;
488 dev
= comedi_dev_get_from_minor(minor
);
492 mutex_lock(&dev
->mutex
);
493 s
= comedi_write_subdevice(dev
, minor
);
494 if (s
&& (s
->subdev_flags
& SDF_CMD_WRITE
) && s
->async
)
495 size
= s
->async
->max_bufsize
/ 1024;
496 mutex_unlock(&dev
->mutex
);
499 return sysfs_emit(buf
, "%u\n", size
);
502 static ssize_t
max_write_buffer_kb_store(struct device
*csdev
,
503 struct device_attribute
*attr
,
504 const char *buf
, size_t count
)
506 unsigned int minor
= MINOR(csdev
->devt
);
507 struct comedi_device
*dev
;
508 struct comedi_subdevice
*s
;
512 err
= kstrtouint(buf
, 10, &size
);
515 if (size
> (UINT_MAX
/ 1024))
519 dev
= comedi_dev_get_from_minor(minor
);
523 mutex_lock(&dev
->mutex
);
524 s
= comedi_write_subdevice(dev
, minor
);
525 if (s
&& (s
->subdev_flags
& SDF_CMD_WRITE
) && s
->async
)
526 s
->async
->max_bufsize
= size
;
529 mutex_unlock(&dev
->mutex
);
532 return err
? err
: count
;
534 static DEVICE_ATTR_RW(max_write_buffer_kb
);
536 static ssize_t
write_buffer_kb_show(struct device
*csdev
,
537 struct device_attribute
*attr
, char *buf
)
539 unsigned int minor
= MINOR(csdev
->devt
);
540 struct comedi_device
*dev
;
541 struct comedi_subdevice
*s
;
542 unsigned int size
= 0;
544 dev
= comedi_dev_get_from_minor(minor
);
548 mutex_lock(&dev
->mutex
);
549 s
= comedi_write_subdevice(dev
, minor
);
550 if (s
&& (s
->subdev_flags
& SDF_CMD_WRITE
) && s
->async
)
551 size
= s
->async
->prealloc_bufsz
/ 1024;
552 mutex_unlock(&dev
->mutex
);
555 return sysfs_emit(buf
, "%u\n", size
);
558 static ssize_t
write_buffer_kb_store(struct device
*csdev
,
559 struct device_attribute
*attr
,
560 const char *buf
, size_t count
)
562 unsigned int minor
= MINOR(csdev
->devt
);
563 struct comedi_device
*dev
;
564 struct comedi_subdevice
*s
;
568 err
= kstrtouint(buf
, 10, &size
);
571 if (size
> (UINT_MAX
/ 1024))
575 dev
= comedi_dev_get_from_minor(minor
);
579 mutex_lock(&dev
->mutex
);
580 s
= comedi_write_subdevice(dev
, minor
);
581 if (s
&& (s
->subdev_flags
& SDF_CMD_WRITE
) && s
->async
)
582 err
= resize_async_buffer(dev
, s
, size
);
585 mutex_unlock(&dev
->mutex
);
588 return err
? err
: count
;
590 static DEVICE_ATTR_RW(write_buffer_kb
);
592 static struct attribute
*comedi_dev_attrs
[] = {
593 &dev_attr_max_read_buffer_kb
.attr
,
594 &dev_attr_read_buffer_kb
.attr
,
595 &dev_attr_max_write_buffer_kb
.attr
,
596 &dev_attr_write_buffer_kb
.attr
,
599 ATTRIBUTE_GROUPS(comedi_dev
);
601 static const struct class comedi_class
= {
603 .dev_groups
= comedi_dev_groups
,
606 static void comedi_free_board_dev(struct comedi_device
*dev
)
609 comedi_device_cleanup(dev
);
610 if (dev
->class_dev
) {
611 device_destroy(&comedi_class
,
612 MKDEV(COMEDI_MAJOR
, dev
->minor
));
618 static void __comedi_clear_subdevice_runflags(struct comedi_subdevice
*s
,
621 s
->runflags
&= ~bits
;
624 static void __comedi_set_subdevice_runflags(struct comedi_subdevice
*s
,
630 static void comedi_update_subdevice_runflags(struct comedi_subdevice
*s
,
636 spin_lock_irqsave(&s
->spin_lock
, flags
);
637 __comedi_clear_subdevice_runflags(s
, mask
);
638 __comedi_set_subdevice_runflags(s
, bits
& mask
);
639 spin_unlock_irqrestore(&s
->spin_lock
, flags
);
642 static unsigned int __comedi_get_subdevice_runflags(struct comedi_subdevice
*s
)
647 static unsigned int comedi_get_subdevice_runflags(struct comedi_subdevice
*s
)
650 unsigned int runflags
;
652 spin_lock_irqsave(&s
->spin_lock
, flags
);
653 runflags
= __comedi_get_subdevice_runflags(s
);
654 spin_unlock_irqrestore(&s
->spin_lock
, flags
);
658 static bool comedi_is_runflags_running(unsigned int runflags
)
660 return runflags
& COMEDI_SRF_RUNNING
;
663 static bool comedi_is_runflags_in_error(unsigned int runflags
)
665 return runflags
& COMEDI_SRF_ERROR
;
669 * comedi_is_subdevice_running() - Check if async command running on subdevice
670 * @s: COMEDI subdevice.
672 * Return: %true if an asynchronous COMEDI command is active on the
673 * subdevice, else %false.
675 bool comedi_is_subdevice_running(struct comedi_subdevice
*s
)
677 unsigned int runflags
= comedi_get_subdevice_runflags(s
);
679 return comedi_is_runflags_running(runflags
);
681 EXPORT_SYMBOL_GPL(comedi_is_subdevice_running
);
683 static bool __comedi_is_subdevice_running(struct comedi_subdevice
*s
)
685 unsigned int runflags
= __comedi_get_subdevice_runflags(s
);
687 return comedi_is_runflags_running(runflags
);
690 bool comedi_can_auto_free_spriv(struct comedi_subdevice
*s
)
692 unsigned int runflags
= __comedi_get_subdevice_runflags(s
);
694 return runflags
& COMEDI_SRF_FREE_SPRIV
;
698 * comedi_set_spriv_auto_free() - Mark subdevice private data as freeable
699 * @s: COMEDI subdevice.
701 * Mark the subdevice as having a pointer to private data that can be
702 * automatically freed when the COMEDI device is detached from the low-level
705 void comedi_set_spriv_auto_free(struct comedi_subdevice
*s
)
707 __comedi_set_subdevice_runflags(s
, COMEDI_SRF_FREE_SPRIV
);
709 EXPORT_SYMBOL_GPL(comedi_set_spriv_auto_free
);
712 * comedi_alloc_spriv - Allocate memory for the subdevice private data
713 * @s: COMEDI subdevice.
714 * @size: Size of the memory to allocate.
716 * Allocate memory for the subdevice private data and point @s->private
717 * to it. The memory will be freed automatically when the COMEDI device
718 * is detached from the low-level driver.
720 * Return: A pointer to the allocated memory @s->private on success.
721 * Return NULL on failure.
723 void *comedi_alloc_spriv(struct comedi_subdevice
*s
, size_t size
)
725 s
->private = kzalloc(size
, GFP_KERNEL
);
727 comedi_set_spriv_auto_free(s
);
730 EXPORT_SYMBOL_GPL(comedi_alloc_spriv
);
733 * This function restores a subdevice to an idle state.
735 static void do_become_nonbusy(struct comedi_device
*dev
,
736 struct comedi_subdevice
*s
)
738 struct comedi_async
*async
= s
->async
;
740 lockdep_assert_held(&dev
->mutex
);
741 comedi_update_subdevice_runflags(s
, COMEDI_SRF_RUNNING
, 0);
744 async
->inttrig
= NULL
;
745 kfree(async
->cmd
.chanlist
);
746 async
->cmd
.chanlist
= NULL
;
748 wake_up_interruptible_all(&async
->wait_head
);
750 dev_err(dev
->class_dev
,
751 "BUG: (?) %s called with async=NULL\n", __func__
);
756 static int do_cancel(struct comedi_device
*dev
, struct comedi_subdevice
*s
)
760 lockdep_assert_held(&dev
->mutex
);
761 if (comedi_is_subdevice_running(s
) && s
->cancel
)
762 ret
= s
->cancel(dev
, s
);
764 do_become_nonbusy(dev
, s
);
769 void comedi_device_cancel_all(struct comedi_device
*dev
)
771 struct comedi_subdevice
*s
;
774 lockdep_assert_held(&dev
->mutex
);
778 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
779 s
= &dev
->subdevices
[i
];
785 static int is_device_busy(struct comedi_device
*dev
)
787 struct comedi_subdevice
*s
;
790 lockdep_assert_held(&dev
->mutex
);
794 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
795 s
= &dev
->subdevices
[i
];
798 if (s
->async
&& comedi_buf_is_mmapped(s
))
806 * COMEDI_DEVCONFIG ioctl
807 * attaches (and configures) or detaches a legacy device
810 * pointer to comedi_devconfig structure (NULL if detaching)
813 * comedi_devconfig structure (if attaching)
818 static int do_devconfig_ioctl(struct comedi_device
*dev
,
819 struct comedi_devconfig __user
*arg
)
821 struct comedi_devconfig it
;
823 lockdep_assert_held(&dev
->mutex
);
824 if (!capable(CAP_SYS_ADMIN
))
828 if (is_device_busy(dev
))
831 struct module
*driver_module
= dev
->driver
->module
;
833 comedi_device_detach(dev
);
834 module_put(driver_module
);
839 if (copy_from_user(&it
, arg
, sizeof(it
)))
842 it
.board_name
[COMEDI_NAMELEN
- 1] = 0;
844 if (it
.options
[COMEDI_DEVCONF_AUX_DATA_LENGTH
]) {
845 dev_warn(dev
->class_dev
,
846 "comedi_config --init_data is deprecated\n");
850 if (dev
->minor
>= comedi_num_legacy_minors
)
851 /* don't re-use dynamically allocated comedi devices */
854 /* This increments the driver module count on success. */
855 return comedi_device_attach(dev
, &it
);
859 * COMEDI_BUFCONFIG ioctl
860 * buffer configuration
863 * pointer to comedi_bufconfig structure
866 * comedi_bufconfig structure
869 * modified comedi_bufconfig structure
871 static int do_bufconfig_ioctl(struct comedi_device
*dev
,
872 struct comedi_bufconfig __user
*arg
)
874 struct comedi_bufconfig bc
;
875 struct comedi_async
*async
;
876 struct comedi_subdevice
*s
;
879 lockdep_assert_held(&dev
->mutex
);
880 if (copy_from_user(&bc
, arg
, sizeof(bc
)))
883 if (bc
.subdevice
>= dev
->n_subdevices
)
886 s
= &dev
->subdevices
[bc
.subdevice
];
890 dev_dbg(dev
->class_dev
,
891 "subdevice does not have async capability\n");
897 if (bc
.maximum_size
) {
898 if (!capable(CAP_SYS_ADMIN
))
901 async
->max_bufsize
= bc
.maximum_size
;
905 retval
= resize_async_buffer(dev
, s
, bc
.size
);
910 bc
.size
= async
->prealloc_bufsz
;
911 bc
.maximum_size
= async
->max_bufsize
;
914 if (copy_to_user(arg
, &bc
, sizeof(bc
)))
921 * COMEDI_DEVINFO ioctl
925 * pointer to comedi_devinfo structure
931 * comedi_devinfo structure
933 static int do_devinfo_ioctl(struct comedi_device
*dev
,
934 struct comedi_devinfo __user
*arg
,
937 struct comedi_subdevice
*s
;
938 struct comedi_devinfo devinfo
;
940 lockdep_assert_held(&dev
->mutex
);
941 memset(&devinfo
, 0, sizeof(devinfo
));
943 /* fill devinfo structure */
944 devinfo
.version_code
= COMEDI_VERSION_CODE
;
945 devinfo
.n_subdevs
= dev
->n_subdevices
;
946 strscpy(devinfo
.driver_name
, dev
->driver
->driver_name
, COMEDI_NAMELEN
);
947 strscpy(devinfo
.board_name
, dev
->board_name
, COMEDI_NAMELEN
);
949 s
= comedi_file_read_subdevice(file
);
951 devinfo
.read_subdevice
= s
->index
;
953 devinfo
.read_subdevice
= -1;
955 s
= comedi_file_write_subdevice(file
);
957 devinfo
.write_subdevice
= s
->index
;
959 devinfo
.write_subdevice
= -1;
961 if (copy_to_user(arg
, &devinfo
, sizeof(devinfo
)))
968 * COMEDI_SUBDINFO ioctl
972 * pointer to array of comedi_subdinfo structures
978 * array of comedi_subdinfo structures
980 static int do_subdinfo_ioctl(struct comedi_device
*dev
,
981 struct comedi_subdinfo __user
*arg
, void *file
)
984 struct comedi_subdinfo
*tmp
, *us
;
985 struct comedi_subdevice
*s
;
987 lockdep_assert_held(&dev
->mutex
);
988 tmp
= kcalloc(dev
->n_subdevices
, sizeof(*tmp
), GFP_KERNEL
);
992 /* fill subdinfo structs */
993 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
994 s
= &dev
->subdevices
[i
];
998 us
->n_chan
= s
->n_chan
;
999 us
->subd_flags
= s
->subdev_flags
;
1000 if (comedi_is_subdevice_running(s
))
1001 us
->subd_flags
|= SDF_RUNNING
;
1002 #define TIMER_nanosec 5 /* backwards compatibility */
1003 us
->timer_type
= TIMER_nanosec
;
1004 us
->len_chanlist
= s
->len_chanlist
;
1005 us
->maxdata
= s
->maxdata
;
1006 if (s
->range_table
) {
1008 (i
<< 24) | (0 << 16) | (s
->range_table
->length
);
1010 us
->range_type
= 0; /* XXX */
1014 us
->subd_flags
|= SDF_BUSY
;
1015 if (s
->busy
== file
)
1016 us
->subd_flags
|= SDF_BUSY_OWNER
;
1018 us
->subd_flags
|= SDF_LOCKED
;
1019 if (s
->lock
== file
)
1020 us
->subd_flags
|= SDF_LOCK_OWNER
;
1021 if (!s
->maxdata
&& s
->maxdata_list
)
1022 us
->subd_flags
|= SDF_MAXDATA
;
1023 if (s
->range_table_list
)
1024 us
->subd_flags
|= SDF_RANGETYPE
;
1026 us
->subd_flags
|= SDF_CMD
;
1028 if (s
->insn_bits
!= &insn_inval
)
1029 us
->insn_bits_support
= COMEDI_SUPPORTED
;
1031 us
->insn_bits_support
= COMEDI_UNSUPPORTED
;
1034 ret
= copy_to_user(arg
, tmp
, dev
->n_subdevices
* sizeof(*tmp
));
1038 return ret
? -EFAULT
: 0;
1042 * COMEDI_CHANINFO ioctl
1043 * subdevice channel info
1046 * pointer to comedi_chaninfo structure
1049 * comedi_chaninfo structure
1052 * array of maxdata values to chaninfo->maxdata_list if requested
1053 * array of range table lengths to chaninfo->range_table_list if requested
1055 static int do_chaninfo_ioctl(struct comedi_device
*dev
,
1056 struct comedi_chaninfo
*it
)
1058 struct comedi_subdevice
*s
;
1060 lockdep_assert_held(&dev
->mutex
);
1062 if (it
->subdev
>= dev
->n_subdevices
)
1064 s
= &dev
->subdevices
[it
->subdev
];
1066 if (it
->maxdata_list
) {
1067 if (s
->maxdata
|| !s
->maxdata_list
)
1069 if (copy_to_user(it
->maxdata_list
, s
->maxdata_list
,
1070 s
->n_chan
* sizeof(unsigned int)))
1075 return -EINVAL
; /* flaglist not supported */
1077 if (it
->rangelist
) {
1080 if (!s
->range_table_list
)
1082 for (i
= 0; i
< s
->n_chan
; i
++) {
1085 x
= (dev
->minor
<< 28) | (it
->subdev
<< 24) | (i
<< 16) |
1086 (s
->range_table_list
[i
]->length
);
1087 if (put_user(x
, it
->rangelist
+ i
))
1096 * COMEDI_BUFINFO ioctl
1097 * buffer information
1100 * pointer to comedi_bufinfo structure
1103 * comedi_bufinfo structure
1106 * modified comedi_bufinfo structure
1108 static int do_bufinfo_ioctl(struct comedi_device
*dev
,
1109 struct comedi_bufinfo __user
*arg
, void *file
)
1111 struct comedi_bufinfo bi
;
1112 struct comedi_subdevice
*s
;
1113 struct comedi_async
*async
;
1114 unsigned int runflags
;
1116 bool become_nonbusy
= false;
1118 lockdep_assert_held(&dev
->mutex
);
1119 if (copy_from_user(&bi
, arg
, sizeof(bi
)))
1122 if (bi
.subdevice
>= dev
->n_subdevices
)
1125 s
= &dev
->subdevices
[bi
.subdevice
];
1129 if (!async
|| s
->busy
!= file
)
1132 runflags
= comedi_get_subdevice_runflags(s
);
1133 if (!(async
->cmd
.flags
& CMDF_WRITE
)) {
1134 /* command was set up in "read" direction */
1135 if (bi
.bytes_read
) {
1136 comedi_buf_read_alloc(s
, bi
.bytes_read
);
1137 bi
.bytes_read
= comedi_buf_read_free(s
, bi
.bytes_read
);
1140 * If nothing left to read, and command has stopped, and
1141 * {"read" position not updated or command stopped normally},
1142 * then become non-busy.
1144 if (comedi_buf_read_n_available(s
) == 0 &&
1145 !comedi_is_runflags_running(runflags
) &&
1146 (bi
.bytes_read
== 0 ||
1147 !comedi_is_runflags_in_error(runflags
))) {
1148 become_nonbusy
= true;
1149 if (comedi_is_runflags_in_error(runflags
))
1152 bi
.bytes_written
= 0;
1154 /* command was set up in "write" direction */
1155 if (!comedi_is_runflags_running(runflags
)) {
1156 bi
.bytes_written
= 0;
1157 become_nonbusy
= true;
1158 if (comedi_is_runflags_in_error(runflags
))
1160 } else if (bi
.bytes_written
) {
1161 comedi_buf_write_alloc(s
, bi
.bytes_written
);
1163 comedi_buf_write_free(s
, bi
.bytes_written
);
1168 bi
.buf_write_count
= async
->buf_write_count
;
1169 bi
.buf_write_ptr
= async
->buf_write_ptr
;
1170 bi
.buf_read_count
= async
->buf_read_count
;
1171 bi
.buf_read_ptr
= async
->buf_read_ptr
;
1174 do_become_nonbusy(dev
, s
);
1179 if (copy_to_user(arg
, &bi
, sizeof(bi
)))
1185 static int check_insn_config_length(struct comedi_insn
*insn
,
1192 case INSN_CONFIG_DIO_OUTPUT
:
1193 case INSN_CONFIG_DIO_INPUT
:
1194 case INSN_CONFIG_DISARM
:
1195 case INSN_CONFIG_RESET
:
1199 case INSN_CONFIG_ARM
:
1200 case INSN_CONFIG_DIO_QUERY
:
1201 case INSN_CONFIG_BLOCK_SIZE
:
1202 case INSN_CONFIG_FILTER
:
1203 case INSN_CONFIG_SERIAL_CLOCK
:
1204 case INSN_CONFIG_BIDIRECTIONAL_DATA
:
1205 case INSN_CONFIG_ALT_SOURCE
:
1206 case INSN_CONFIG_SET_COUNTER_MODE
:
1207 case INSN_CONFIG_8254_READ_STATUS
:
1208 case INSN_CONFIG_SET_ROUTING
:
1209 case INSN_CONFIG_GET_ROUTING
:
1210 case INSN_CONFIG_GET_PWM_STATUS
:
1211 case INSN_CONFIG_PWM_SET_PERIOD
:
1212 case INSN_CONFIG_PWM_GET_PERIOD
:
1216 case INSN_CONFIG_SET_GATE_SRC
:
1217 case INSN_CONFIG_GET_GATE_SRC
:
1218 case INSN_CONFIG_SET_CLOCK_SRC
:
1219 case INSN_CONFIG_GET_CLOCK_SRC
:
1220 case INSN_CONFIG_SET_OTHER_SRC
:
1221 case INSN_CONFIG_GET_COUNTER_STATUS
:
1222 case INSN_CONFIG_GET_PWM_OUTPUT
:
1223 case INSN_CONFIG_PWM_SET_H_BRIDGE
:
1224 case INSN_CONFIG_PWM_GET_H_BRIDGE
:
1225 case INSN_CONFIG_GET_HARDWARE_BUFFER_SIZE
:
1229 case INSN_CONFIG_PWM_OUTPUT
:
1230 case INSN_CONFIG_ANALOG_TRIG
:
1231 case INSN_CONFIG_TIMER_1
:
1235 case INSN_CONFIG_DIGITAL_TRIG
:
1239 case INSN_CONFIG_GET_CMD_TIMING_CONSTRAINTS
:
1244 * by default we allow the insn since we don't have checks for
1245 * all possible cases yet
1248 pr_warn("No check for data length of config insn id %i is implemented\n",
1250 pr_warn("Add a check to %s in %s\n", __func__
, __FILE__
);
1251 pr_warn("Assuming n=%i is correct\n", insn
->n
);
1257 static int check_insn_device_config_length(struct comedi_insn
*insn
,
1264 case INSN_DEVICE_CONFIG_TEST_ROUTE
:
1265 case INSN_DEVICE_CONFIG_CONNECT_ROUTE
:
1266 case INSN_DEVICE_CONFIG_DISCONNECT_ROUTE
:
1270 case INSN_DEVICE_CONFIG_GET_ROUTES
:
1272 * Big enough for config_id and the length of the userland
1273 * memory buffer. Additional length should be in factors of 2
1274 * to communicate any returned route pairs (source,destination).
1284 * get_valid_routes() - Calls low-level driver get_valid_routes function to
1285 * either return a count of valid routes to user, or copy
1286 * of list of all valid device routes to buffer in
1288 * @dev: comedi device pointer
1289 * @data: data from user insn call. The length of the data must be >= 2.
1290 * data[0] must contain the INSN_DEVICE_CONFIG config_id.
1291 * data[1](input) contains the number of _pairs_ for which memory is
1292 * allotted from the user. If the user specifies '0', then only
1293 * the number of pairs available is returned.
1294 * data[1](output) returns either the number of pairs available (if none
1295 * where requested) or the number of _pairs_ that are copied back
1297 * data[2::2] returns each (source, destination) pair.
1299 * Return: -EINVAL if low-level driver does not allocate and return routes as
1300 * expected. Returns 0 otherwise.
1302 static int get_valid_routes(struct comedi_device
*dev
, unsigned int *data
)
1304 lockdep_assert_held(&dev
->mutex
);
1305 data
[1] = dev
->get_valid_routes(dev
, data
[1], data
+ 2);
1309 static int parse_insn(struct comedi_device
*dev
, struct comedi_insn
*insn
,
1310 unsigned int *data
, void *file
)
1312 struct comedi_subdevice
*s
;
1316 lockdep_assert_held(&dev
->mutex
);
1317 if (insn
->insn
& INSN_MASK_SPECIAL
) {
1318 /* a non-subdevice instruction */
1320 switch (insn
->insn
) {
1323 struct timespec64 tv
;
1330 ktime_get_real_ts64(&tv
);
1331 /* unsigned data safe until 2106 */
1332 data
[0] = (unsigned int)tv
.tv_sec
;
1333 data
[1] = tv
.tv_nsec
/ NSEC_PER_USEC
;
1339 if (insn
->n
!= 1 || data
[0] >= 100000) {
1343 udelay(data
[0] / 1000);
1351 if (insn
->subdev
>= dev
->n_subdevices
) {
1352 dev_dbg(dev
->class_dev
,
1353 "%d not usable subdevice\n",
1358 s
= &dev
->subdevices
[insn
->subdev
];
1360 dev_dbg(dev
->class_dev
, "no async\n");
1364 if (!s
->async
->inttrig
) {
1365 dev_dbg(dev
->class_dev
, "no inttrig\n");
1369 ret
= s
->async
->inttrig(dev
, s
, data
[0]);
1373 case INSN_DEVICE_CONFIG
:
1374 ret
= check_insn_device_config_length(insn
, data
);
1378 if (data
[0] == INSN_DEVICE_CONFIG_GET_ROUTES
) {
1380 * data[1] should be the number of _pairs_ that
1381 * the memory can hold.
1383 data
[1] = (insn
->n
- 2) / 2;
1384 ret
= get_valid_routes(dev
, data
);
1388 /* other global device config instructions. */
1389 ret
= dev
->insn_device_config(dev
, insn
, data
);
1392 dev_dbg(dev
->class_dev
, "invalid insn\n");
1397 /* a subdevice instruction */
1398 unsigned int maxdata
;
1400 if (insn
->subdev
>= dev
->n_subdevices
) {
1401 dev_dbg(dev
->class_dev
, "subdevice %d out of range\n",
1406 s
= &dev
->subdevices
[insn
->subdev
];
1408 if (s
->type
== COMEDI_SUBD_UNUSED
) {
1409 dev_dbg(dev
->class_dev
, "%d not usable subdevice\n",
1415 /* are we locked? (ioctl lock) */
1416 if (s
->lock
&& s
->lock
!= file
) {
1417 dev_dbg(dev
->class_dev
, "device locked\n");
1422 ret
= comedi_check_chanlist(s
, 1, &insn
->chanspec
);
1425 dev_dbg(dev
->class_dev
, "bad chanspec\n");
1433 /* This looks arbitrary. It is. */
1434 s
->busy
= parse_insn
;
1435 switch (insn
->insn
) {
1437 ret
= s
->insn_read(dev
, s
, insn
, data
);
1438 if (ret
== -ETIMEDOUT
) {
1439 dev_dbg(dev
->class_dev
,
1440 "subdevice %d read instruction timed out\n",
1445 maxdata
= s
->maxdata_list
1446 ? s
->maxdata_list
[CR_CHAN(insn
->chanspec
)]
1448 for (i
= 0; i
< insn
->n
; ++i
) {
1449 if (data
[i
] > maxdata
) {
1451 dev_dbg(dev
->class_dev
,
1452 "bad data value(s)\n");
1457 ret
= s
->insn_write(dev
, s
, insn
, data
);
1458 if (ret
== -ETIMEDOUT
) {
1459 dev_dbg(dev
->class_dev
,
1460 "subdevice %d write instruction timed out\n",
1470 * Most drivers ignore the base channel in
1471 * insn->chanspec. Fix this here if
1472 * the subdevice has <= 32 channels.
1474 unsigned int orig_mask
= data
[0];
1475 unsigned int shift
= 0;
1477 if (s
->n_chan
<= 32) {
1478 shift
= CR_CHAN(insn
->chanspec
);
1485 ret
= s
->insn_bits(dev
, s
, insn
, data
);
1486 data
[0] = orig_mask
;
1492 ret
= check_insn_config_length(insn
, data
);
1495 ret
= s
->insn_config(dev
, s
, insn
, data
);
1510 * COMEDI_INSNLIST ioctl
1511 * synchronous instruction list
1514 * pointer to comedi_insnlist structure
1517 * comedi_insnlist structure
1518 * array of comedi_insn structures from insnlist->insns pointer
1519 * data (for writes) from insns[].data pointers
1522 * data (for reads) to insns[].data pointers
1524 /* arbitrary limits */
1525 #define MIN_SAMPLES 16
1526 #define MAX_SAMPLES 65536
1527 static int do_insnlist_ioctl(struct comedi_device
*dev
,
1528 struct comedi_insn
*insns
,
1529 unsigned int n_insns
,
1532 unsigned int *data
= NULL
;
1533 unsigned int max_n_data_required
= MIN_SAMPLES
;
1537 lockdep_assert_held(&dev
->mutex
);
1539 /* Determine maximum memory needed for all instructions. */
1540 for (i
= 0; i
< n_insns
; ++i
) {
1541 if (insns
[i
].n
> MAX_SAMPLES
) {
1542 dev_dbg(dev
->class_dev
,
1543 "number of samples too large\n");
1547 max_n_data_required
= max(max_n_data_required
, insns
[i
].n
);
1550 /* Allocate scratch space for all instruction data. */
1551 data
= kmalloc_array(max_n_data_required
, sizeof(unsigned int),
1558 for (i
= 0; i
< n_insns
; ++i
) {
1559 if (insns
[i
].insn
& INSN_MASK_WRITE
) {
1560 if (copy_from_user(data
, insns
[i
].data
,
1561 insns
[i
].n
* sizeof(unsigned int))) {
1562 dev_dbg(dev
->class_dev
,
1563 "copy_from_user failed\n");
1568 ret
= parse_insn(dev
, insns
+ i
, data
, file
);
1571 if (insns
[i
].insn
& INSN_MASK_READ
) {
1572 if (copy_to_user(insns
[i
].data
, data
,
1573 insns
[i
].n
* sizeof(unsigned int))) {
1574 dev_dbg(dev
->class_dev
,
1575 "copy_to_user failed\n");
1594 * synchronous instruction
1597 * pointer to comedi_insn structure
1600 * comedi_insn structure
1601 * data (for writes) from insn->data pointer
1604 * data (for reads) to insn->data pointer
1606 static int do_insn_ioctl(struct comedi_device
*dev
,
1607 struct comedi_insn
*insn
, void *file
)
1609 unsigned int *data
= NULL
;
1610 unsigned int n_data
= MIN_SAMPLES
;
1613 lockdep_assert_held(&dev
->mutex
);
1615 n_data
= max(n_data
, insn
->n
);
1617 /* This is where the behavior of insn and insnlist deviate. */
1618 if (insn
->n
> MAX_SAMPLES
) {
1619 insn
->n
= MAX_SAMPLES
;
1620 n_data
= MAX_SAMPLES
;
1623 data
= kmalloc_array(n_data
, sizeof(unsigned int), GFP_KERNEL
);
1629 if (insn
->insn
& INSN_MASK_WRITE
) {
1630 if (copy_from_user(data
,
1632 insn
->n
* sizeof(unsigned int))) {
1637 ret
= parse_insn(dev
, insn
, data
, file
);
1640 if (insn
->insn
& INSN_MASK_READ
) {
1641 if (copy_to_user(insn
->data
,
1643 insn
->n
* sizeof(unsigned int))) {
1656 static int __comedi_get_user_cmd(struct comedi_device
*dev
,
1657 struct comedi_cmd
*cmd
)
1659 struct comedi_subdevice
*s
;
1661 lockdep_assert_held(&dev
->mutex
);
1662 if (cmd
->subdev
>= dev
->n_subdevices
) {
1663 dev_dbg(dev
->class_dev
, "%d no such subdevice\n", cmd
->subdev
);
1667 s
= &dev
->subdevices
[cmd
->subdev
];
1669 if (s
->type
== COMEDI_SUBD_UNUSED
) {
1670 dev_dbg(dev
->class_dev
, "%d not valid subdevice\n",
1675 if (!s
->do_cmd
|| !s
->do_cmdtest
|| !s
->async
) {
1676 dev_dbg(dev
->class_dev
,
1677 "subdevice %d does not support commands\n",
1682 /* make sure channel/gain list isn't too long */
1683 if (cmd
->chanlist_len
> s
->len_chanlist
) {
1684 dev_dbg(dev
->class_dev
, "channel/gain list too long %d > %d\n",
1685 cmd
->chanlist_len
, s
->len_chanlist
);
1690 * Set the CMDF_WRITE flag to the correct state if the subdevice
1691 * supports only "read" commands or only "write" commands.
1693 switch (s
->subdev_flags
& (SDF_CMD_READ
| SDF_CMD_WRITE
)) {
1695 cmd
->flags
&= ~CMDF_WRITE
;
1698 cmd
->flags
|= CMDF_WRITE
;
1707 static int __comedi_get_user_chanlist(struct comedi_device
*dev
,
1708 struct comedi_subdevice
*s
,
1709 unsigned int __user
*user_chanlist
,
1710 struct comedi_cmd
*cmd
)
1712 unsigned int *chanlist
;
1715 lockdep_assert_held(&dev
->mutex
);
1716 cmd
->chanlist
= NULL
;
1717 chanlist
= memdup_array_user(user_chanlist
,
1718 cmd
->chanlist_len
, sizeof(unsigned int));
1719 if (IS_ERR(chanlist
))
1720 return PTR_ERR(chanlist
);
1722 /* make sure each element in channel/gain list is valid */
1723 ret
= comedi_check_chanlist(s
, cmd
->chanlist_len
, chanlist
);
1729 cmd
->chanlist
= chanlist
;
1736 * asynchronous acquisition command set-up
1739 * pointer to comedi_cmd structure
1742 * comedi_cmd structure
1743 * channel/range list from cmd->chanlist pointer
1746 * possibly modified comedi_cmd structure (when -EAGAIN returned)
1748 static int do_cmd_ioctl(struct comedi_device
*dev
,
1749 struct comedi_cmd
*cmd
, bool *copy
, void *file
)
1751 struct comedi_subdevice
*s
;
1752 struct comedi_async
*async
;
1753 unsigned int __user
*user_chanlist
;
1756 lockdep_assert_held(&dev
->mutex
);
1758 /* do some simple cmd validation */
1759 ret
= __comedi_get_user_cmd(dev
, cmd
);
1763 /* save user's chanlist pointer so it can be restored later */
1764 user_chanlist
= (unsigned int __user
*)cmd
->chanlist
;
1766 s
= &dev
->subdevices
[cmd
->subdev
];
1769 /* are we locked? (ioctl lock) */
1770 if (s
->lock
&& s
->lock
!= file
) {
1771 dev_dbg(dev
->class_dev
, "subdevice locked\n");
1777 dev_dbg(dev
->class_dev
, "subdevice busy\n");
1781 /* make sure channel/gain list isn't too short */
1782 if (cmd
->chanlist_len
< 1) {
1783 dev_dbg(dev
->class_dev
, "channel/gain list too short %u < 1\n",
1789 async
->cmd
.data
= NULL
;
1791 /* load channel/gain list */
1792 ret
= __comedi_get_user_chanlist(dev
, s
, user_chanlist
, &async
->cmd
);
1796 ret
= s
->do_cmdtest(dev
, s
, &async
->cmd
);
1798 if (async
->cmd
.flags
& CMDF_BOGUS
|| ret
) {
1799 dev_dbg(dev
->class_dev
, "test returned %d\n", ret
);
1801 /* restore chanlist pointer before copying back */
1802 cmd
->chanlist
= (unsigned int __force
*)user_chanlist
;
1809 if (!async
->prealloc_bufsz
) {
1811 dev_dbg(dev
->class_dev
, "no buffer (?)\n");
1815 comedi_buf_reset(s
);
1817 async
->cb_mask
= COMEDI_CB_BLOCK
| COMEDI_CB_CANCEL_MASK
;
1818 if (async
->cmd
.flags
& CMDF_WAKE_EOS
)
1819 async
->cb_mask
|= COMEDI_CB_EOS
;
1821 comedi_update_subdevice_runflags(s
, COMEDI_SRF_BUSY_MASK
,
1822 COMEDI_SRF_RUNNING
);
1825 * Set s->busy _after_ setting COMEDI_SRF_RUNNING flag to avoid
1826 * race with comedi_read() or comedi_write().
1829 ret
= s
->do_cmd(dev
, s
);
1834 do_become_nonbusy(dev
, s
);
1840 * COMEDI_CMDTEST ioctl
1841 * asynchronous acquisition command testing
1844 * pointer to comedi_cmd structure
1847 * comedi_cmd structure
1848 * channel/range list from cmd->chanlist pointer
1851 * possibly modified comedi_cmd structure
1853 static int do_cmdtest_ioctl(struct comedi_device
*dev
,
1854 struct comedi_cmd
*cmd
, bool *copy
, void *file
)
1856 struct comedi_subdevice
*s
;
1857 unsigned int __user
*user_chanlist
;
1860 lockdep_assert_held(&dev
->mutex
);
1862 /* do some simple cmd validation */
1863 ret
= __comedi_get_user_cmd(dev
, cmd
);
1867 /* save user's chanlist pointer so it can be restored later */
1868 user_chanlist
= (unsigned int __user
*)cmd
->chanlist
;
1870 s
= &dev
->subdevices
[cmd
->subdev
];
1872 /* user_chanlist can be NULL for COMEDI_CMDTEST ioctl */
1873 if (user_chanlist
) {
1874 /* load channel/gain list */
1875 ret
= __comedi_get_user_chanlist(dev
, s
, user_chanlist
, cmd
);
1880 ret
= s
->do_cmdtest(dev
, s
, cmd
);
1882 kfree(cmd
->chanlist
); /* free kernel copy of user chanlist */
1884 /* restore chanlist pointer before copying back */
1885 cmd
->chanlist
= (unsigned int __force
*)user_chanlist
;
1904 static int do_lock_ioctl(struct comedi_device
*dev
, unsigned long arg
,
1908 unsigned long flags
;
1909 struct comedi_subdevice
*s
;
1911 lockdep_assert_held(&dev
->mutex
);
1912 if (arg
>= dev
->n_subdevices
)
1914 s
= &dev
->subdevices
[arg
];
1916 spin_lock_irqsave(&s
->spin_lock
, flags
);
1917 if (s
->busy
|| s
->lock
)
1921 spin_unlock_irqrestore(&s
->spin_lock
, flags
);
1927 * COMEDI_UNLOCK ioctl
1939 static int do_unlock_ioctl(struct comedi_device
*dev
, unsigned long arg
,
1942 struct comedi_subdevice
*s
;
1944 lockdep_assert_held(&dev
->mutex
);
1945 if (arg
>= dev
->n_subdevices
)
1947 s
= &dev
->subdevices
[arg
];
1952 if (s
->lock
&& s
->lock
!= file
)
1955 if (s
->lock
== file
)
1962 * COMEDI_CANCEL ioctl
1963 * cancel asynchronous acquisition
1974 static int do_cancel_ioctl(struct comedi_device
*dev
, unsigned long arg
,
1977 struct comedi_subdevice
*s
;
1979 lockdep_assert_held(&dev
->mutex
);
1980 if (arg
>= dev
->n_subdevices
)
1982 s
= &dev
->subdevices
[arg
];
1989 if (s
->busy
!= file
)
1992 return do_cancel(dev
, s
);
1997 * instructs driver to synchronize buffers
2008 static int do_poll_ioctl(struct comedi_device
*dev
, unsigned long arg
,
2011 struct comedi_subdevice
*s
;
2013 lockdep_assert_held(&dev
->mutex
);
2014 if (arg
>= dev
->n_subdevices
)
2016 s
= &dev
->subdevices
[arg
];
2021 if (s
->busy
!= file
)
2025 return s
->poll(dev
, s
);
2031 * COMEDI_SETRSUBD ioctl
2032 * sets the current "read" subdevice on a per-file basis
2043 static int do_setrsubd_ioctl(struct comedi_device
*dev
, unsigned long arg
,
2046 struct comedi_file
*cfp
= file
->private_data
;
2047 struct comedi_subdevice
*s_old
, *s_new
;
2049 lockdep_assert_held(&dev
->mutex
);
2050 if (arg
>= dev
->n_subdevices
)
2053 s_new
= &dev
->subdevices
[arg
];
2054 s_old
= comedi_file_read_subdevice(file
);
2056 return 0; /* no change */
2058 if (!(s_new
->subdev_flags
& SDF_CMD_READ
))
2062 * Check the file isn't still busy handling a "read" command on the
2063 * old subdevice (if any).
2065 if (s_old
&& s_old
->busy
== file
&& s_old
->async
&&
2066 !(s_old
->async
->cmd
.flags
& CMDF_WRITE
))
2069 WRITE_ONCE(cfp
->read_subdev
, s_new
);
2074 * COMEDI_SETWSUBD ioctl
2075 * sets the current "write" subdevice on a per-file basis
2086 static int do_setwsubd_ioctl(struct comedi_device
*dev
, unsigned long arg
,
2089 struct comedi_file
*cfp
= file
->private_data
;
2090 struct comedi_subdevice
*s_old
, *s_new
;
2092 lockdep_assert_held(&dev
->mutex
);
2093 if (arg
>= dev
->n_subdevices
)
2096 s_new
= &dev
->subdevices
[arg
];
2097 s_old
= comedi_file_write_subdevice(file
);
2099 return 0; /* no change */
2101 if (!(s_new
->subdev_flags
& SDF_CMD_WRITE
))
2105 * Check the file isn't still busy handling a "write" command on the
2106 * old subdevice (if any).
2108 if (s_old
&& s_old
->busy
== file
&& s_old
->async
&&
2109 (s_old
->async
->cmd
.flags
& CMDF_WRITE
))
2112 WRITE_ONCE(cfp
->write_subdev
, s_new
);
2116 static long comedi_unlocked_ioctl(struct file
*file
, unsigned int cmd
,
2119 unsigned int minor
= iminor(file_inode(file
));
2120 struct comedi_file
*cfp
= file
->private_data
;
2121 struct comedi_device
*dev
= cfp
->dev
;
2124 mutex_lock(&dev
->mutex
);
2127 * Device config is special, because it must work on
2128 * an unconfigured device.
2130 if (cmd
== COMEDI_DEVCONFIG
) {
2131 if (minor
>= COMEDI_NUM_BOARD_MINORS
) {
2132 /* Device config not appropriate on non-board minors. */
2136 rc
= do_devconfig_ioctl(dev
,
2137 (struct comedi_devconfig __user
*)arg
);
2140 dev
->minor
>= comedi_num_legacy_minors
) {
2142 * Successfully unconfigured a dynamically
2143 * allocated device. Try and remove it.
2145 if (comedi_clear_board_dev(dev
)) {
2146 mutex_unlock(&dev
->mutex
);
2147 comedi_free_board_dev(dev
);
2155 if (!dev
->attached
) {
2156 dev_dbg(dev
->class_dev
, "no driver attached\n");
2162 case COMEDI_BUFCONFIG
:
2163 rc
= do_bufconfig_ioctl(dev
,
2164 (struct comedi_bufconfig __user
*)arg
);
2166 case COMEDI_DEVINFO
:
2167 rc
= do_devinfo_ioctl(dev
, (struct comedi_devinfo __user
*)arg
,
2170 case COMEDI_SUBDINFO
:
2171 rc
= do_subdinfo_ioctl(dev
,
2172 (struct comedi_subdinfo __user
*)arg
,
2175 case COMEDI_CHANINFO
: {
2176 struct comedi_chaninfo it
;
2178 if (copy_from_user(&it
, (void __user
*)arg
, sizeof(it
)))
2181 rc
= do_chaninfo_ioctl(dev
, &it
);
2184 case COMEDI_RANGEINFO
: {
2185 struct comedi_rangeinfo it
;
2187 if (copy_from_user(&it
, (void __user
*)arg
, sizeof(it
)))
2190 rc
= do_rangeinfo_ioctl(dev
, &it
);
2193 case COMEDI_BUFINFO
:
2194 rc
= do_bufinfo_ioctl(dev
,
2195 (struct comedi_bufinfo __user
*)arg
,
2199 rc
= do_lock_ioctl(dev
, arg
, file
);
2202 rc
= do_unlock_ioctl(dev
, arg
, file
);
2205 rc
= do_cancel_ioctl(dev
, arg
, file
);
2208 struct comedi_cmd cmd
;
2211 if (copy_from_user(&cmd
, (void __user
*)arg
, sizeof(cmd
))) {
2215 rc
= do_cmd_ioctl(dev
, &cmd
, ©
, file
);
2216 if (copy
&& copy_to_user((void __user
*)arg
, &cmd
, sizeof(cmd
)))
2220 case COMEDI_CMDTEST
: {
2221 struct comedi_cmd cmd
;
2224 if (copy_from_user(&cmd
, (void __user
*)arg
, sizeof(cmd
))) {
2228 rc
= do_cmdtest_ioctl(dev
, &cmd
, ©
, file
);
2229 if (copy
&& copy_to_user((void __user
*)arg
, &cmd
, sizeof(cmd
)))
2233 case COMEDI_INSNLIST
: {
2234 struct comedi_insnlist insnlist
;
2235 struct comedi_insn
*insns
= NULL
;
2237 if (copy_from_user(&insnlist
, (void __user
*)arg
,
2238 sizeof(insnlist
))) {
2242 insns
= kcalloc(insnlist
.n_insns
, sizeof(*insns
), GFP_KERNEL
);
2247 if (copy_from_user(insns
, insnlist
.insns
,
2248 sizeof(*insns
) * insnlist
.n_insns
)) {
2253 rc
= do_insnlist_ioctl(dev
, insns
, insnlist
.n_insns
, file
);
2258 struct comedi_insn insn
;
2260 if (copy_from_user(&insn
, (void __user
*)arg
, sizeof(insn
)))
2263 rc
= do_insn_ioctl(dev
, &insn
, file
);
2267 rc
= do_poll_ioctl(dev
, arg
, file
);
2269 case COMEDI_SETRSUBD
:
2270 rc
= do_setrsubd_ioctl(dev
, arg
, file
);
2272 case COMEDI_SETWSUBD
:
2273 rc
= do_setwsubd_ioctl(dev
, arg
, file
);
2281 mutex_unlock(&dev
->mutex
);
2285 static void comedi_vm_open(struct vm_area_struct
*area
)
2287 struct comedi_buf_map
*bm
;
2289 bm
= area
->vm_private_data
;
2290 comedi_buf_map_get(bm
);
2293 static void comedi_vm_close(struct vm_area_struct
*area
)
2295 struct comedi_buf_map
*bm
;
2297 bm
= area
->vm_private_data
;
2298 comedi_buf_map_put(bm
);
2301 static int comedi_vm_access(struct vm_area_struct
*vma
, unsigned long addr
,
2302 void *buf
, int len
, int write
)
2304 struct comedi_buf_map
*bm
= vma
->vm_private_data
;
2305 unsigned long offset
=
2306 addr
- vma
->vm_start
+ (vma
->vm_pgoff
<< PAGE_SHIFT
);
2310 if (len
> vma
->vm_end
- addr
)
2311 len
= vma
->vm_end
- addr
;
2312 return comedi_buf_map_access(bm
, offset
, buf
, len
, write
);
2315 static const struct vm_operations_struct comedi_vm_ops
= {
2316 .open
= comedi_vm_open
,
2317 .close
= comedi_vm_close
,
2318 .access
= comedi_vm_access
,
2321 static int comedi_mmap(struct file
*file
, struct vm_area_struct
*vma
)
2323 struct comedi_file
*cfp
= file
->private_data
;
2324 struct comedi_device
*dev
= cfp
->dev
;
2325 struct comedi_subdevice
*s
;
2326 struct comedi_async
*async
;
2327 struct comedi_buf_map
*bm
= NULL
;
2328 struct comedi_buf_page
*buf
;
2329 unsigned long start
= vma
->vm_start
;
2336 * 'trylock' avoids circular dependency with current->mm->mmap_lock
2337 * and down-reading &dev->attach_lock should normally succeed without
2338 * contention unless the device is in the process of being attached
2341 if (!down_read_trylock(&dev
->attach_lock
))
2344 if (!dev
->attached
) {
2345 dev_dbg(dev
->class_dev
, "no driver attached\n");
2350 if (vma
->vm_flags
& VM_WRITE
)
2351 s
= comedi_file_write_subdevice(file
);
2353 s
= comedi_file_read_subdevice(file
);
2365 if (vma
->vm_pgoff
!= 0) {
2366 dev_dbg(dev
->class_dev
, "mmap() offset must be 0.\n");
2371 size
= vma
->vm_end
- vma
->vm_start
;
2372 if (size
> async
->prealloc_bufsz
) {
2376 if (offset_in_page(size
)) {
2381 n_pages
= vma_pages(vma
);
2383 /* get reference to current buf map (if any) */
2384 bm
= comedi_buf_map_from_subdev_get(s
);
2385 if (!bm
|| n_pages
> bm
->n_pages
) {
2389 if (bm
->dma_dir
!= DMA_NONE
) {
2391 * DMA buffer was allocated as a single block.
2392 * Address is in page_list[0].
2394 buf
= &bm
->page_list
[0];
2395 retval
= dma_mmap_coherent(bm
->dma_hw_dev
, vma
, buf
->virt_addr
,
2396 buf
->dma_addr
, n_pages
* PAGE_SIZE
);
2398 for (i
= 0; i
< n_pages
; ++i
) {
2401 buf
= &bm
->page_list
[i
];
2402 pfn
= page_to_pfn(virt_to_page(buf
->virt_addr
));
2403 retval
= remap_pfn_range(vma
, start
, pfn
, PAGE_SIZE
,
2413 * Leaving behind a partial mapping of a buffer we're about to
2414 * drop is unsafe, see remap_pfn_range_notrack().
2415 * We need to zap the range here ourselves instead of relying
2416 * on the automatic zapping in remap_pfn_range() because we call
2417 * remap_pfn_range() in a loop.
2420 zap_vma_ptes(vma
, vma
->vm_start
, size
);
2425 vma
->vm_ops
= &comedi_vm_ops
;
2426 vma
->vm_private_data
= bm
;
2428 vma
->vm_ops
->open(vma
);
2432 up_read(&dev
->attach_lock
);
2433 comedi_buf_map_put(bm
); /* put reference to buf map - okay if NULL */
2437 static __poll_t
comedi_poll(struct file
*file
, poll_table
*wait
)
2440 struct comedi_file
*cfp
= file
->private_data
;
2441 struct comedi_device
*dev
= cfp
->dev
;
2442 struct comedi_subdevice
*s
, *s_read
;
2444 down_read(&dev
->attach_lock
);
2446 if (!dev
->attached
) {
2447 dev_dbg(dev
->class_dev
, "no driver attached\n");
2451 s
= comedi_file_read_subdevice(file
);
2453 if (s
&& s
->async
) {
2454 poll_wait(file
, &s
->async
->wait_head
, wait
);
2455 if (s
->busy
!= file
|| !comedi_is_subdevice_running(s
) ||
2456 (s
->async
->cmd
.flags
& CMDF_WRITE
) ||
2457 comedi_buf_read_n_available(s
) > 0)
2458 mask
|= EPOLLIN
| EPOLLRDNORM
;
2461 s
= comedi_file_write_subdevice(file
);
2462 if (s
&& s
->async
) {
2463 unsigned int bps
= comedi_bytes_per_sample(s
);
2466 poll_wait(file
, &s
->async
->wait_head
, wait
);
2467 if (s
->busy
!= file
|| !comedi_is_subdevice_running(s
) ||
2468 !(s
->async
->cmd
.flags
& CMDF_WRITE
) ||
2469 comedi_buf_write_n_available(s
) >= bps
)
2470 mask
|= EPOLLOUT
| EPOLLWRNORM
;
2474 up_read(&dev
->attach_lock
);
2478 static ssize_t
comedi_write(struct file
*file
, const char __user
*buf
,
2479 size_t nbytes
, loff_t
*offset
)
2481 struct comedi_subdevice
*s
;
2482 struct comedi_async
*async
;
2486 DECLARE_WAITQUEUE(wait
, current
);
2487 struct comedi_file
*cfp
= file
->private_data
;
2488 struct comedi_device
*dev
= cfp
->dev
;
2489 bool become_nonbusy
= false;
2491 unsigned int old_detach_count
;
2493 /* Protect against device detachment during operation. */
2494 down_read(&dev
->attach_lock
);
2495 attach_locked
= true;
2496 old_detach_count
= dev
->detach_count
;
2498 if (!dev
->attached
) {
2499 dev_dbg(dev
->class_dev
, "no driver attached\n");
2504 s
= comedi_file_write_subdevice(file
);
2505 if (!s
|| !s
->async
) {
2511 if (s
->busy
!= file
|| !(async
->cmd
.flags
& CMDF_WRITE
)) {
2516 add_wait_queue(&async
->wait_head
, &wait
);
2517 while (count
== 0 && !retval
) {
2518 unsigned int runflags
;
2519 unsigned int wp
, n1
, n2
;
2521 set_current_state(TASK_INTERRUPTIBLE
);
2523 runflags
= comedi_get_subdevice_runflags(s
);
2524 if (!comedi_is_runflags_running(runflags
)) {
2525 if (comedi_is_runflags_in_error(runflags
))
2527 if (retval
|| nbytes
)
2528 become_nonbusy
= true;
2534 /* Allocate all free buffer space. */
2535 comedi_buf_write_alloc(s
, async
->prealloc_bufsz
);
2536 m
= comedi_buf_write_n_allocated(s
);
2537 n
= min_t(size_t, m
, nbytes
);
2540 if (file
->f_flags
& O_NONBLOCK
) {
2545 if (signal_pending(current
)) {
2546 retval
= -ERESTARTSYS
;
2549 if (s
->busy
!= file
||
2550 !(async
->cmd
.flags
& CMDF_WRITE
)) {
2557 set_current_state(TASK_RUNNING
);
2558 wp
= async
->buf_write_ptr
;
2559 n1
= min(n
, async
->prealloc_bufsz
- wp
);
2561 m
= copy_from_user(async
->prealloc_buf
+ wp
, buf
, n1
);
2565 m
= copy_from_user(async
->prealloc_buf
, buf
+ n1
, n2
);
2570 comedi_buf_write_free(s
, n
);
2577 remove_wait_queue(&async
->wait_head
, &wait
);
2578 set_current_state(TASK_RUNNING
);
2579 if (become_nonbusy
&& count
== 0) {
2580 struct comedi_subdevice
*new_s
;
2583 * To avoid deadlock, cannot acquire dev->mutex
2584 * while dev->attach_lock is held.
2586 up_read(&dev
->attach_lock
);
2587 attach_locked
= false;
2588 mutex_lock(&dev
->mutex
);
2590 * Check device hasn't become detached behind our back.
2591 * Checking dev->detach_count is unchanged ought to be
2592 * sufficient (unless there have been 2**32 detaches in the
2593 * meantime!), but check the subdevice pointer as well just in
2596 * Also check the subdevice is still in a suitable state to
2597 * become non-busy in case it changed behind our back.
2599 new_s
= comedi_file_write_subdevice(file
);
2600 if (dev
->attached
&& old_detach_count
== dev
->detach_count
&&
2601 s
== new_s
&& new_s
->async
== async
&& s
->busy
== file
&&
2602 (async
->cmd
.flags
& CMDF_WRITE
) &&
2603 !comedi_is_subdevice_running(s
))
2604 do_become_nonbusy(dev
, s
);
2605 mutex_unlock(&dev
->mutex
);
2609 up_read(&dev
->attach_lock
);
2611 return count
? count
: retval
;
2614 static ssize_t
comedi_read(struct file
*file
, char __user
*buf
, size_t nbytes
,
2617 struct comedi_subdevice
*s
;
2618 struct comedi_async
*async
;
2622 DECLARE_WAITQUEUE(wait
, current
);
2623 struct comedi_file
*cfp
= file
->private_data
;
2624 struct comedi_device
*dev
= cfp
->dev
;
2625 unsigned int old_detach_count
;
2626 bool become_nonbusy
= false;
2629 /* Protect against device detachment during operation. */
2630 down_read(&dev
->attach_lock
);
2631 attach_locked
= true;
2632 old_detach_count
= dev
->detach_count
;
2634 if (!dev
->attached
) {
2635 dev_dbg(dev
->class_dev
, "no driver attached\n");
2640 s
= comedi_file_read_subdevice(file
);
2641 if (!s
|| !s
->async
) {
2647 if (s
->busy
!= file
|| (async
->cmd
.flags
& CMDF_WRITE
)) {
2652 add_wait_queue(&async
->wait_head
, &wait
);
2653 while (count
== 0 && !retval
) {
2654 unsigned int rp
, n1
, n2
;
2656 set_current_state(TASK_INTERRUPTIBLE
);
2658 m
= comedi_buf_read_n_available(s
);
2659 n
= min_t(size_t, m
, nbytes
);
2662 unsigned int runflags
=
2663 comedi_get_subdevice_runflags(s
);
2665 if (!comedi_is_runflags_running(runflags
)) {
2666 if (comedi_is_runflags_in_error(runflags
))
2668 if (retval
|| nbytes
)
2669 become_nonbusy
= true;
2674 if (file
->f_flags
& O_NONBLOCK
) {
2679 if (signal_pending(current
)) {
2680 retval
= -ERESTARTSYS
;
2683 if (s
->busy
!= file
||
2684 (async
->cmd
.flags
& CMDF_WRITE
)) {
2691 set_current_state(TASK_RUNNING
);
2692 rp
= async
->buf_read_ptr
;
2693 n1
= min(n
, async
->prealloc_bufsz
- rp
);
2695 m
= copy_to_user(buf
, async
->prealloc_buf
+ rp
, n1
);
2699 m
= copy_to_user(buf
+ n1
, async
->prealloc_buf
, n2
);
2705 comedi_buf_read_alloc(s
, n
);
2706 comedi_buf_read_free(s
, n
);
2713 remove_wait_queue(&async
->wait_head
, &wait
);
2714 set_current_state(TASK_RUNNING
);
2715 if (become_nonbusy
&& count
== 0) {
2716 struct comedi_subdevice
*new_s
;
2719 * To avoid deadlock, cannot acquire dev->mutex
2720 * while dev->attach_lock is held.
2722 up_read(&dev
->attach_lock
);
2723 attach_locked
= false;
2724 mutex_lock(&dev
->mutex
);
2726 * Check device hasn't become detached behind our back.
2727 * Checking dev->detach_count is unchanged ought to be
2728 * sufficient (unless there have been 2**32 detaches in the
2729 * meantime!), but check the subdevice pointer as well just in
2732 * Also check the subdevice is still in a suitable state to
2733 * become non-busy in case it changed behind our back.
2735 new_s
= comedi_file_read_subdevice(file
);
2736 if (dev
->attached
&& old_detach_count
== dev
->detach_count
&&
2737 s
== new_s
&& new_s
->async
== async
&& s
->busy
== file
&&
2738 !(async
->cmd
.flags
& CMDF_WRITE
) &&
2739 !comedi_is_subdevice_running(s
) &&
2740 comedi_buf_read_n_available(s
) == 0)
2741 do_become_nonbusy(dev
, s
);
2742 mutex_unlock(&dev
->mutex
);
2746 up_read(&dev
->attach_lock
);
2748 return count
? count
: retval
;
2751 static int comedi_open(struct inode
*inode
, struct file
*file
)
2753 const unsigned int minor
= iminor(inode
);
2754 struct comedi_file
*cfp
;
2755 struct comedi_device
*dev
= comedi_dev_get_from_minor(minor
);
2759 pr_debug("invalid minor number\n");
2763 cfp
= kzalloc(sizeof(*cfp
), GFP_KERNEL
);
2765 comedi_dev_put(dev
);
2771 mutex_lock(&dev
->mutex
);
2772 if (!dev
->attached
&& !capable(CAP_SYS_ADMIN
)) {
2773 dev_dbg(dev
->class_dev
, "not attached and not CAP_SYS_ADMIN\n");
2777 if (dev
->attached
&& dev
->use_count
== 0) {
2778 if (!try_module_get(dev
->driver
->module
)) {
2783 rc
= dev
->open(dev
);
2785 module_put(dev
->driver
->module
);
2792 file
->private_data
= cfp
;
2793 comedi_file_reset(file
);
2797 mutex_unlock(&dev
->mutex
);
2799 comedi_dev_put(dev
);
2805 static int comedi_fasync(int fd
, struct file
*file
, int on
)
2807 struct comedi_file
*cfp
= file
->private_data
;
2808 struct comedi_device
*dev
= cfp
->dev
;
2810 return fasync_helper(fd
, file
, on
, &dev
->async_queue
);
2813 static int comedi_close(struct inode
*inode
, struct file
*file
)
2815 struct comedi_file
*cfp
= file
->private_data
;
2816 struct comedi_device
*dev
= cfp
->dev
;
2817 struct comedi_subdevice
*s
= NULL
;
2820 mutex_lock(&dev
->mutex
);
2822 if (dev
->subdevices
) {
2823 for (i
= 0; i
< dev
->n_subdevices
; i
++) {
2824 s
= &dev
->subdevices
[i
];
2826 if (s
->busy
== file
)
2828 if (s
->lock
== file
)
2832 if (dev
->attached
&& dev
->use_count
== 1) {
2835 module_put(dev
->driver
->module
);
2840 mutex_unlock(&dev
->mutex
);
2841 comedi_dev_put(dev
);
2847 #ifdef CONFIG_COMPAT
2849 #define COMEDI32_CHANINFO _IOR(CIO, 3, struct comedi32_chaninfo_struct)
2850 #define COMEDI32_RANGEINFO _IOR(CIO, 8, struct comedi32_rangeinfo_struct)
2852 * N.B. COMEDI32_CMD and COMEDI_CMD ought to use _IOWR, not _IOR.
2853 * It's too late to change it now, but it only affects the command number.
2855 #define COMEDI32_CMD _IOR(CIO, 9, struct comedi32_cmd_struct)
2857 * N.B. COMEDI32_CMDTEST and COMEDI_CMDTEST ought to use _IOWR, not _IOR.
2858 * It's too late to change it now, but it only affects the command number.
2860 #define COMEDI32_CMDTEST _IOR(CIO, 10, struct comedi32_cmd_struct)
2861 #define COMEDI32_INSNLIST _IOR(CIO, 11, struct comedi32_insnlist_struct)
2862 #define COMEDI32_INSN _IOR(CIO, 12, struct comedi32_insn_struct)
2864 struct comedi32_chaninfo_struct
{
2865 unsigned int subdev
;
2866 compat_uptr_t maxdata_list
; /* 32-bit 'unsigned int *' */
2867 compat_uptr_t flaglist
; /* 32-bit 'unsigned int *' */
2868 compat_uptr_t rangelist
; /* 32-bit 'unsigned int *' */
2869 unsigned int unused
[4];
2872 struct comedi32_rangeinfo_struct
{
2873 unsigned int range_type
;
2874 compat_uptr_t range_ptr
; /* 32-bit 'void *' */
2877 struct comedi32_cmd_struct
{
2878 unsigned int subdev
;
2880 unsigned int start_src
;
2881 unsigned int start_arg
;
2882 unsigned int scan_begin_src
;
2883 unsigned int scan_begin_arg
;
2884 unsigned int convert_src
;
2885 unsigned int convert_arg
;
2886 unsigned int scan_end_src
;
2887 unsigned int scan_end_arg
;
2888 unsigned int stop_src
;
2889 unsigned int stop_arg
;
2890 compat_uptr_t chanlist
; /* 32-bit 'unsigned int *' */
2891 unsigned int chanlist_len
;
2892 compat_uptr_t data
; /* 32-bit 'short *' */
2893 unsigned int data_len
;
2896 struct comedi32_insn_struct
{
2899 compat_uptr_t data
; /* 32-bit 'unsigned int *' */
2900 unsigned int subdev
;
2901 unsigned int chanspec
;
2902 unsigned int unused
[3];
2905 struct comedi32_insnlist_struct
{
2906 unsigned int n_insns
;
2907 compat_uptr_t insns
; /* 32-bit 'struct comedi_insn *' */
2910 /* Handle 32-bit COMEDI_CHANINFO ioctl. */
2911 static int compat_chaninfo(struct file
*file
, unsigned long arg
)
2913 struct comedi_file
*cfp
= file
->private_data
;
2914 struct comedi_device
*dev
= cfp
->dev
;
2915 struct comedi32_chaninfo_struct chaninfo32
;
2916 struct comedi_chaninfo chaninfo
;
2919 if (copy_from_user(&chaninfo32
, compat_ptr(arg
), sizeof(chaninfo32
)))
2922 memset(&chaninfo
, 0, sizeof(chaninfo
));
2923 chaninfo
.subdev
= chaninfo32
.subdev
;
2924 chaninfo
.maxdata_list
= compat_ptr(chaninfo32
.maxdata_list
);
2925 chaninfo
.flaglist
= compat_ptr(chaninfo32
.flaglist
);
2926 chaninfo
.rangelist
= compat_ptr(chaninfo32
.rangelist
);
2928 mutex_lock(&dev
->mutex
);
2929 err
= do_chaninfo_ioctl(dev
, &chaninfo
);
2930 mutex_unlock(&dev
->mutex
);
2934 /* Handle 32-bit COMEDI_RANGEINFO ioctl. */
2935 static int compat_rangeinfo(struct file
*file
, unsigned long arg
)
2937 struct comedi_file
*cfp
= file
->private_data
;
2938 struct comedi_device
*dev
= cfp
->dev
;
2939 struct comedi32_rangeinfo_struct rangeinfo32
;
2940 struct comedi_rangeinfo rangeinfo
;
2943 if (copy_from_user(&rangeinfo32
, compat_ptr(arg
), sizeof(rangeinfo32
)))
2945 memset(&rangeinfo
, 0, sizeof(rangeinfo
));
2946 rangeinfo
.range_type
= rangeinfo32
.range_type
;
2947 rangeinfo
.range_ptr
= compat_ptr(rangeinfo32
.range_ptr
);
2949 mutex_lock(&dev
->mutex
);
2950 err
= do_rangeinfo_ioctl(dev
, &rangeinfo
);
2951 mutex_unlock(&dev
->mutex
);
2955 /* Copy 32-bit cmd structure to native cmd structure. */
2956 static int get_compat_cmd(struct comedi_cmd
*cmd
,
2957 struct comedi32_cmd_struct __user
*cmd32
)
2959 struct comedi32_cmd_struct v32
;
2961 if (copy_from_user(&v32
, cmd32
, sizeof(v32
)))
2964 cmd
->subdev
= v32
.subdev
;
2965 cmd
->flags
= v32
.flags
;
2966 cmd
->start_src
= v32
.start_src
;
2967 cmd
->start_arg
= v32
.start_arg
;
2968 cmd
->scan_begin_src
= v32
.scan_begin_src
;
2969 cmd
->scan_begin_arg
= v32
.scan_begin_arg
;
2970 cmd
->convert_src
= v32
.convert_src
;
2971 cmd
->convert_arg
= v32
.convert_arg
;
2972 cmd
->scan_end_src
= v32
.scan_end_src
;
2973 cmd
->scan_end_arg
= v32
.scan_end_arg
;
2974 cmd
->stop_src
= v32
.stop_src
;
2975 cmd
->stop_arg
= v32
.stop_arg
;
2976 cmd
->chanlist
= (unsigned int __force
*)compat_ptr(v32
.chanlist
);
2977 cmd
->chanlist_len
= v32
.chanlist_len
;
2978 cmd
->data
= compat_ptr(v32
.data
);
2979 cmd
->data_len
= v32
.data_len
;
2983 /* Copy native cmd structure to 32-bit cmd structure. */
2984 static int put_compat_cmd(struct comedi32_cmd_struct __user
*cmd32
,
2985 struct comedi_cmd
*cmd
)
2987 struct comedi32_cmd_struct v32
;
2989 memset(&v32
, 0, sizeof(v32
));
2990 v32
.subdev
= cmd
->subdev
;
2991 v32
.flags
= cmd
->flags
;
2992 v32
.start_src
= cmd
->start_src
;
2993 v32
.start_arg
= cmd
->start_arg
;
2994 v32
.scan_begin_src
= cmd
->scan_begin_src
;
2995 v32
.scan_begin_arg
= cmd
->scan_begin_arg
;
2996 v32
.convert_src
= cmd
->convert_src
;
2997 v32
.convert_arg
= cmd
->convert_arg
;
2998 v32
.scan_end_src
= cmd
->scan_end_src
;
2999 v32
.scan_end_arg
= cmd
->scan_end_arg
;
3000 v32
.stop_src
= cmd
->stop_src
;
3001 v32
.stop_arg
= cmd
->stop_arg
;
3002 /* Assume chanlist pointer is unchanged. */
3003 v32
.chanlist
= ptr_to_compat((unsigned int __user
*)cmd
->chanlist
);
3004 v32
.chanlist_len
= cmd
->chanlist_len
;
3005 v32
.data
= ptr_to_compat(cmd
->data
);
3006 v32
.data_len
= cmd
->data_len
;
3007 if (copy_to_user(cmd32
, &v32
, sizeof(v32
)))
3012 /* Handle 32-bit COMEDI_CMD ioctl. */
3013 static int compat_cmd(struct file
*file
, unsigned long arg
)
3015 struct comedi_file
*cfp
= file
->private_data
;
3016 struct comedi_device
*dev
= cfp
->dev
;
3017 struct comedi_cmd cmd
;
3021 rc
= get_compat_cmd(&cmd
, compat_ptr(arg
));
3025 mutex_lock(&dev
->mutex
);
3026 rc
= do_cmd_ioctl(dev
, &cmd
, ©
, file
);
3027 mutex_unlock(&dev
->mutex
);
3029 /* Special case: copy cmd back to user. */
3030 err
= put_compat_cmd(compat_ptr(arg
), &cmd
);
3037 /* Handle 32-bit COMEDI_CMDTEST ioctl. */
3038 static int compat_cmdtest(struct file
*file
, unsigned long arg
)
3040 struct comedi_file
*cfp
= file
->private_data
;
3041 struct comedi_device
*dev
= cfp
->dev
;
3042 struct comedi_cmd cmd
;
3046 rc
= get_compat_cmd(&cmd
, compat_ptr(arg
));
3050 mutex_lock(&dev
->mutex
);
3051 rc
= do_cmdtest_ioctl(dev
, &cmd
, ©
, file
);
3052 mutex_unlock(&dev
->mutex
);
3054 err
= put_compat_cmd(compat_ptr(arg
), &cmd
);
3061 /* Copy 32-bit insn structure to native insn structure. */
3062 static int get_compat_insn(struct comedi_insn
*insn
,
3063 struct comedi32_insn_struct __user
*insn32
)
3065 struct comedi32_insn_struct v32
;
3067 /* Copy insn structure. Ignore the unused members. */
3068 if (copy_from_user(&v32
, insn32
, sizeof(v32
)))
3070 memset(insn
, 0, sizeof(*insn
));
3071 insn
->insn
= v32
.insn
;
3073 insn
->data
= compat_ptr(v32
.data
);
3074 insn
->subdev
= v32
.subdev
;
3075 insn
->chanspec
= v32
.chanspec
;
3079 /* Handle 32-bit COMEDI_INSNLIST ioctl. */
3080 static int compat_insnlist(struct file
*file
, unsigned long arg
)
3082 struct comedi_file
*cfp
= file
->private_data
;
3083 struct comedi_device
*dev
= cfp
->dev
;
3084 struct comedi32_insnlist_struct insnlist32
;
3085 struct comedi32_insn_struct __user
*insn32
;
3086 struct comedi_insn
*insns
;
3090 if (copy_from_user(&insnlist32
, compat_ptr(arg
), sizeof(insnlist32
)))
3093 insns
= kcalloc(insnlist32
.n_insns
, sizeof(*insns
), GFP_KERNEL
);
3097 /* Copy insn structures. */
3098 insn32
= compat_ptr(insnlist32
.insns
);
3099 for (n
= 0; n
< insnlist32
.n_insns
; n
++) {
3100 rc
= get_compat_insn(insns
+ n
, insn32
+ n
);
3107 mutex_lock(&dev
->mutex
);
3108 rc
= do_insnlist_ioctl(dev
, insns
, insnlist32
.n_insns
, file
);
3109 mutex_unlock(&dev
->mutex
);
3114 /* Handle 32-bit COMEDI_INSN ioctl. */
3115 static int compat_insn(struct file
*file
, unsigned long arg
)
3117 struct comedi_file
*cfp
= file
->private_data
;
3118 struct comedi_device
*dev
= cfp
->dev
;
3119 struct comedi_insn insn
;
3122 rc
= get_compat_insn(&insn
, (void __user
*)arg
);
3126 mutex_lock(&dev
->mutex
);
3127 rc
= do_insn_ioctl(dev
, &insn
, file
);
3128 mutex_unlock(&dev
->mutex
);
3133 * compat_ioctl file operation.
3135 * Returns -ENOIOCTLCMD for unrecognised ioctl codes.
3137 static long comedi_compat_ioctl(struct file
*file
, unsigned int cmd
, unsigned long arg
)
3142 case COMEDI_DEVCONFIG
:
3143 case COMEDI_DEVINFO
:
3144 case COMEDI_SUBDINFO
:
3145 case COMEDI_BUFCONFIG
:
3146 case COMEDI_BUFINFO
:
3147 /* Just need to translate the pointer argument. */
3148 arg
= (unsigned long)compat_ptr(arg
);
3149 rc
= comedi_unlocked_ioctl(file
, cmd
, arg
);
3155 case COMEDI_SETRSUBD
:
3156 case COMEDI_SETWSUBD
:
3157 /* No translation needed. */
3158 rc
= comedi_unlocked_ioctl(file
, cmd
, arg
);
3160 case COMEDI32_CHANINFO
:
3161 rc
= compat_chaninfo(file
, arg
);
3163 case COMEDI32_RANGEINFO
:
3164 rc
= compat_rangeinfo(file
, arg
);
3167 rc
= compat_cmd(file
, arg
);
3169 case COMEDI32_CMDTEST
:
3170 rc
= compat_cmdtest(file
, arg
);
3172 case COMEDI32_INSNLIST
:
3173 rc
= compat_insnlist(file
, arg
);
3176 rc
= compat_insn(file
, arg
);
3185 #define comedi_compat_ioctl NULL
3188 static const struct file_operations comedi_fops
= {
3189 .owner
= THIS_MODULE
,
3190 .unlocked_ioctl
= comedi_unlocked_ioctl
,
3191 .compat_ioctl
= comedi_compat_ioctl
,
3192 .open
= comedi_open
,
3193 .release
= comedi_close
,
3194 .read
= comedi_read
,
3195 .write
= comedi_write
,
3196 .mmap
= comedi_mmap
,
3197 .poll
= comedi_poll
,
3198 .fasync
= comedi_fasync
,
3199 .llseek
= noop_llseek
,
3203 * comedi_event() - Handle events for asynchronous COMEDI command
3204 * @dev: COMEDI device.
3205 * @s: COMEDI subdevice.
3206 * Context: in_interrupt() (usually), @s->spin_lock spin-lock not held.
3208 * If an asynchronous COMEDI command is active on the subdevice, process
3209 * any %COMEDI_CB_... event flags that have been set, usually by an
3210 * interrupt handler. These may change the run state of the asynchronous
3211 * command, wake a task, and/or send a %SIGIO signal.
3213 void comedi_event(struct comedi_device
*dev
, struct comedi_subdevice
*s
)
3215 struct comedi_async
*async
= s
->async
;
3216 unsigned int events
;
3218 unsigned long flags
;
3220 spin_lock_irqsave(&s
->spin_lock
, flags
);
3222 events
= async
->events
;
3224 if (!__comedi_is_subdevice_running(s
)) {
3225 spin_unlock_irqrestore(&s
->spin_lock
, flags
);
3229 if (events
& COMEDI_CB_CANCEL_MASK
)
3230 __comedi_clear_subdevice_runflags(s
, COMEDI_SRF_RUNNING
);
3233 * Remember if an error event has occurred, so an error can be
3234 * returned the next time the user does a read() or write().
3236 if (events
& COMEDI_CB_ERROR_MASK
)
3237 __comedi_set_subdevice_runflags(s
, COMEDI_SRF_ERROR
);
3239 if (async
->cb_mask
& events
) {
3240 wake_up_interruptible(&async
->wait_head
);
3241 si_code
= async
->cmd
.flags
& CMDF_WRITE
? POLL_OUT
: POLL_IN
;
3244 spin_unlock_irqrestore(&s
->spin_lock
, flags
);
3247 kill_fasync(&dev
->async_queue
, SIGIO
, si_code
);
3249 EXPORT_SYMBOL_GPL(comedi_event
);
3251 /* Note: the ->mutex is pre-locked on successful return */
3252 struct comedi_device
*comedi_alloc_board_minor(struct device
*hardware_device
)
3254 struct comedi_device
*dev
;
3255 struct device
*csdev
;
3258 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
3260 return ERR_PTR(-ENOMEM
);
3261 comedi_device_init(dev
);
3262 comedi_set_hw_dev(dev
, hardware_device
);
3263 mutex_lock(&dev
->mutex
);
3264 mutex_lock(&comedi_board_minor_table_lock
);
3265 for (i
= hardware_device
? comedi_num_legacy_minors
: 0;
3266 i
< COMEDI_NUM_BOARD_MINORS
; ++i
) {
3267 if (!comedi_board_minor_table
[i
]) {
3268 comedi_board_minor_table
[i
] = dev
;
3272 mutex_unlock(&comedi_board_minor_table_lock
);
3273 if (i
== COMEDI_NUM_BOARD_MINORS
) {
3274 mutex_unlock(&dev
->mutex
);
3275 comedi_device_cleanup(dev
);
3276 comedi_dev_put(dev
);
3277 dev_err(hardware_device
,
3278 "ran out of minor numbers for board device files\n");
3279 return ERR_PTR(-EBUSY
);
3282 csdev
= device_create(&comedi_class
, hardware_device
,
3283 MKDEV(COMEDI_MAJOR
, i
), NULL
, "comedi%i", i
);
3285 dev
->class_dev
= get_device(csdev
);
3287 /* Note: dev->mutex needs to be unlocked by the caller. */
3291 void comedi_release_hardware_device(struct device
*hardware_device
)
3294 struct comedi_device
*dev
;
3296 for (minor
= comedi_num_legacy_minors
; minor
< COMEDI_NUM_BOARD_MINORS
;
3298 mutex_lock(&comedi_board_minor_table_lock
);
3299 dev
= comedi_board_minor_table
[minor
];
3300 if (dev
&& dev
->hw_dev
== hardware_device
) {
3301 comedi_board_minor_table
[minor
] = NULL
;
3302 mutex_unlock(&comedi_board_minor_table_lock
);
3303 comedi_free_board_dev(dev
);
3306 mutex_unlock(&comedi_board_minor_table_lock
);
3310 int comedi_alloc_subdevice_minor(struct comedi_subdevice
*s
)
3312 struct comedi_device
*dev
= s
->device
;
3313 struct device
*csdev
;
3316 mutex_lock(&comedi_subdevice_minor_table_lock
);
3317 for (i
= 0; i
< COMEDI_NUM_SUBDEVICE_MINORS
; ++i
) {
3318 if (!comedi_subdevice_minor_table
[i
]) {
3319 comedi_subdevice_minor_table
[i
] = s
;
3323 mutex_unlock(&comedi_subdevice_minor_table_lock
);
3324 if (i
== COMEDI_NUM_SUBDEVICE_MINORS
) {
3325 dev_err(dev
->class_dev
,
3326 "ran out of minor numbers for subdevice files\n");
3329 i
+= COMEDI_NUM_BOARD_MINORS
;
3331 csdev
= device_create(&comedi_class
, dev
->class_dev
,
3332 MKDEV(COMEDI_MAJOR
, i
), NULL
, "comedi%i_subd%i",
3333 dev
->minor
, s
->index
);
3335 s
->class_dev
= csdev
;
3340 void comedi_free_subdevice_minor(struct comedi_subdevice
*s
)
3346 if (s
->minor
< COMEDI_NUM_BOARD_MINORS
||
3347 s
->minor
>= COMEDI_NUM_MINORS
)
3350 i
= s
->minor
- COMEDI_NUM_BOARD_MINORS
;
3351 mutex_lock(&comedi_subdevice_minor_table_lock
);
3352 if (s
== comedi_subdevice_minor_table
[i
])
3353 comedi_subdevice_minor_table
[i
] = NULL
;
3354 mutex_unlock(&comedi_subdevice_minor_table_lock
);
3356 device_destroy(&comedi_class
, MKDEV(COMEDI_MAJOR
, s
->minor
));
3357 s
->class_dev
= NULL
;
3361 static void comedi_cleanup_board_minors(void)
3363 struct comedi_device
*dev
;
3366 for (i
= 0; i
< COMEDI_NUM_BOARD_MINORS
; i
++) {
3367 dev
= comedi_clear_board_minor(i
);
3368 comedi_free_board_dev(dev
);
3372 static int __init
comedi_init(void)
3377 pr_info("version " COMEDI_RELEASE
" - http://www.comedi.org\n");
3379 if (comedi_num_legacy_minors
> COMEDI_NUM_BOARD_MINORS
) {
3380 pr_err("invalid value for module parameter \"comedi_num_legacy_minors\". Valid values are 0 through %i.\n",
3381 COMEDI_NUM_BOARD_MINORS
);
3385 retval
= register_chrdev_region(MKDEV(COMEDI_MAJOR
, 0),
3386 COMEDI_NUM_MINORS
, "comedi");
3390 cdev_init(&comedi_cdev
, &comedi_fops
);
3391 comedi_cdev
.owner
= THIS_MODULE
;
3393 retval
= kobject_set_name(&comedi_cdev
.kobj
, "comedi");
3395 goto out_unregister_chrdev_region
;
3397 retval
= cdev_add(&comedi_cdev
, MKDEV(COMEDI_MAJOR
, 0),
3400 goto out_unregister_chrdev_region
;
3402 retval
= class_register(&comedi_class
);
3404 pr_err("failed to create class\n");
3408 /* create devices files for legacy/manual use */
3409 for (i
= 0; i
< comedi_num_legacy_minors
; i
++) {
3410 struct comedi_device
*dev
;
3412 dev
= comedi_alloc_board_minor(NULL
);
3414 retval
= PTR_ERR(dev
);
3415 goto out_cleanup_board_minors
;
3417 /* comedi_alloc_board_minor() locked the mutex */
3418 lockdep_assert_held(&dev
->mutex
);
3419 mutex_unlock(&dev
->mutex
);
3422 /* XXX requires /proc interface */
3427 out_cleanup_board_minors
:
3428 comedi_cleanup_board_minors();
3429 class_unregister(&comedi_class
);
3431 cdev_del(&comedi_cdev
);
3432 out_unregister_chrdev_region
:
3433 unregister_chrdev_region(MKDEV(COMEDI_MAJOR
, 0), COMEDI_NUM_MINORS
);
3436 module_init(comedi_init
);
3438 static void __exit
comedi_cleanup(void)
3440 comedi_cleanup_board_minors();
3441 class_unregister(&comedi_class
);
3442 cdev_del(&comedi_cdev
);
3443 unregister_chrdev_region(MKDEV(COMEDI_MAJOR
, 0), COMEDI_NUM_MINORS
);
3445 comedi_proc_cleanup();
3447 module_exit(comedi_cleanup
);
3449 MODULE_AUTHOR("https://www.comedi.org");
3450 MODULE_DESCRIPTION("Comedi core module");
3451 MODULE_LICENSE("GPL");