Commit | Line | Data |
---|---|---|
ed9eccbe DS |
1 | /* |
2 | include/linux/comedidev.h | |
3 | header file for kernel-only structures, variables, and constants | |
4 | ||
5 | COMEDI - Linux Control and Measurement Device Interface | |
6 | Copyright (C) 1997-2000 David A. Schleef <ds@schleef.org> | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
21 | ||
22 | */ | |
23 | ||
24 | #ifndef _COMEDIDEV_H | |
25 | #define _COMEDIDEV_H | |
26 | ||
27 | #include <linux/kernel.h> | |
28 | #include <linux/module.h> | |
ed9eccbe DS |
29 | #include <linux/kdev_t.h> |
30 | #include <linux/slab.h> | |
31 | #include <linux/errno.h> | |
32 | #include <linux/spinlock.h> | |
33 | #include <linux/mutex.h> | |
34 | #include <linux/wait.h> | |
35 | #include <linux/mm.h> | |
36 | #include <linux/init.h> | |
37 | #include <linux/vmalloc.h> | |
74b847f4 | 38 | #include "interrupt.h" |
ed9eccbe | 39 | #include <linux/dma-mapping.h> |
e0dcef71 GKH |
40 | #include <linux/uaccess.h> |
41 | #include <linux/io.h> | |
ed9eccbe DS |
42 | |
43 | #include "comedi.h" | |
44 | ||
e0dcef71 GKH |
45 | #define DPRINTK(format, args...) do { \ |
46 | if (comedi_debug) \ | |
47 | printk(KERN_DEBUG "comedi: " format , ## args); \ | |
48 | } while (0) | |
ed9eccbe | 49 | |
e0dcef71 GKH |
50 | #define COMEDI_VERSION(a, b, c) (((a) << 16) + ((b) << 8) + (c)) |
51 | #define COMEDI_VERSION_CODE COMEDI_VERSION(COMEDI_MAJORVERSION, COMEDI_MINORVERSION, COMEDI_MICROVERSION) | |
ed9eccbe DS |
52 | #define COMEDI_RELEASE VERSION |
53 | ||
54 | #define COMEDI_INITCLEANUP_NOMODULE(x) \ | |
55 | static int __init x ## _init_module(void) \ | |
51b713a6 | 56 | {return comedi_driver_register(&(x)); } \ |
ed9eccbe | 57 | static void __exit x ## _cleanup_module(void) \ |
51b713a6 | 58 | {comedi_driver_unregister(&(x)); } \ |
ed9eccbe DS |
59 | module_init(x ## _init_module); \ |
60 | module_exit(x ## _cleanup_module); \ | |
61 | ||
62 | #define COMEDI_MODULE_MACROS \ | |
63 | MODULE_AUTHOR("Comedi http://www.comedi.org"); \ | |
64 | MODULE_DESCRIPTION("Comedi low-level driver"); \ | |
65 | MODULE_LICENSE("GPL"); \ | |
66 | ||
67 | #define COMEDI_INITCLEANUP(x) \ | |
68 | COMEDI_MODULE_MACROS \ | |
69 | COMEDI_INITCLEANUP_NOMODULE(x) | |
70 | ||
71 | #define COMEDI_PCI_INITCLEANUP_NOMODULE(comedi_driver, pci_id_table) \ | |
72 | static int __devinit comedi_driver ## _pci_probe(struct pci_dev *dev, \ | |
73 | const struct pci_device_id *ent) \ | |
74 | { \ | |
75 | return comedi_pci_auto_config(dev, comedi_driver.driver_name); \ | |
76 | } \ | |
77 | static void __devexit comedi_driver ## _pci_remove(struct pci_dev *dev) \ | |
78 | { \ | |
79 | comedi_pci_auto_unconfig(dev); \ | |
80 | } \ | |
81 | static struct pci_driver comedi_driver ## _pci_driver = \ | |
82 | { \ | |
83 | .id_table = pci_id_table, \ | |
e0dcef71 GKH |
84 | .probe = &comedi_driver ## _pci_probe, \ |
85 | .remove = __devexit_p(&comedi_driver ## _pci_remove) \ | |
ed9eccbe DS |
86 | }; \ |
87 | static int __init comedi_driver ## _init_module(void) \ | |
88 | { \ | |
89 | int retval; \ | |
e0dcef71 GKH |
90 | retval = comedi_driver_register(&comedi_driver); \ |
91 | if (retval < 0) \ | |
92 | return retval; \ | |
93 | comedi_driver ## _pci_driver.name = (char *)comedi_driver.driver_name; \ | |
94 | return pci_register_driver(&comedi_driver ## _pci_driver); \ | |
ed9eccbe DS |
95 | } \ |
96 | static void __exit comedi_driver ## _cleanup_module(void) \ | |
97 | { \ | |
e0dcef71 GKH |
98 | pci_unregister_driver(&comedi_driver ## _pci_driver); \ |
99 | comedi_driver_unregister(&comedi_driver); \ | |
ed9eccbe DS |
100 | } \ |
101 | module_init(comedi_driver ## _init_module); \ | |
102 | module_exit(comedi_driver ## _cleanup_module); | |
103 | ||
104 | #define COMEDI_PCI_INITCLEANUP(comedi_driver, pci_id_table) \ | |
105 | COMEDI_MODULE_MACROS \ | |
106 | COMEDI_PCI_INITCLEANUP_NOMODULE(comedi_driver, pci_id_table) | |
107 | ||
108 | #define PCI_VENDOR_ID_INOVA 0x104c | |
109 | #define PCI_VENDOR_ID_NATINST 0x1093 | |
110 | #define PCI_VENDOR_ID_DATX 0x1116 | |
111 | #define PCI_VENDOR_ID_COMPUTERBOARDS 0x1307 | |
112 | #define PCI_VENDOR_ID_ADVANTECH 0x13fe | |
113 | #define PCI_VENDOR_ID_RTD 0x1435 | |
114 | #define PCI_VENDOR_ID_AMPLICON 0x14dc | |
115 | #define PCI_VENDOR_ID_ADLINK 0x144a | |
116 | #define PCI_VENDOR_ID_ICP 0x104c | |
117 | #define PCI_VENDOR_ID_CONTEC 0x1221 | |
118 | #define PCI_VENDOR_ID_MEILHAUS 0x1402 | |
119 | ||
120 | #define COMEDI_NUM_MINORS 0x100 | |
ed9eccbe DS |
121 | #define COMEDI_NUM_BOARD_MINORS 0x30 |
122 | #define COMEDI_FIRST_SUBDEVICE_MINOR COMEDI_NUM_BOARD_MINORS | |
123 | ||
ed9eccbe DS |
124 | typedef struct comedi_driver_struct comedi_driver; |
125 | typedef struct comedi_lrange_struct comedi_lrange; | |
126 | ||
127 | typedef struct device device_create_result_type; | |
128 | ||
129 | #define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, device, fmt...) \ | |
130 | device_create(cs, ((parent) ? (parent) : (device)), devt, drvdata, fmt) | |
131 | ||
34c43922 | 132 | struct comedi_subdevice { |
71b5f4f1 | 133 | struct comedi_device *device; |
ed9eccbe DS |
134 | int type; |
135 | int n_chan; | |
136 | volatile int subdev_flags; | |
137 | int len_chanlist; /* maximum length of channel/gain list */ | |
138 | ||
139 | void *private; | |
140 | ||
d163679c | 141 | struct comedi_async *async; |
ed9eccbe DS |
142 | |
143 | void *lock; | |
144 | void *busy; | |
145 | unsigned runflags; | |
146 | spinlock_t spin_lock; | |
147 | ||
148 | int io_bits; | |
149 | ||
790c5541 BP |
150 | unsigned int maxdata; /* if maxdata==0, use list */ |
151 | const unsigned int *maxdata_list; /* list is channel specific */ | |
ed9eccbe DS |
152 | |
153 | unsigned int flags; | |
154 | const unsigned int *flaglist; | |
155 | ||
156 | unsigned int settling_time_0; | |
157 | ||
158 | const comedi_lrange *range_table; | |
159 | const comedi_lrange *const *range_table_list; | |
160 | ||
161 | unsigned int *chanlist; /* driver-owned chanlist (not used) */ | |
162 | ||
34c43922 | 163 | int (*insn_read) (struct comedi_device *, struct comedi_subdevice *, comedi_insn *, |
790c5541 | 164 | unsigned int *); |
34c43922 | 165 | int (*insn_write) (struct comedi_device *, struct comedi_subdevice *, comedi_insn *, |
790c5541 | 166 | unsigned int *); |
34c43922 | 167 | int (*insn_bits) (struct comedi_device *, struct comedi_subdevice *, comedi_insn *, |
790c5541 | 168 | unsigned int *); |
34c43922 | 169 | int (*insn_config) (struct comedi_device *, struct comedi_subdevice *, comedi_insn *, |
790c5541 | 170 | unsigned int *); |
ed9eccbe | 171 | |
34c43922 BP |
172 | int (*do_cmd) (struct comedi_device *, struct comedi_subdevice *); |
173 | int (*do_cmdtest) (struct comedi_device *, struct comedi_subdevice *, comedi_cmd *); | |
174 | int (*poll) (struct comedi_device *, struct comedi_subdevice *); | |
175 | int (*cancel) (struct comedi_device *, struct comedi_subdevice *); | |
176 | /* int (*do_lock)(struct comedi_device *,struct comedi_subdevice *); */ | |
177 | /* int (*do_unlock)(struct comedi_device *,struct comedi_subdevice *); */ | |
ed9eccbe DS |
178 | |
179 | /* called when the buffer changes */ | |
34c43922 | 180 | int (*buf_change) (struct comedi_device *dev, struct comedi_subdevice *s, |
ed9eccbe DS |
181 | unsigned long new_size); |
182 | ||
34c43922 | 183 | void (*munge) (struct comedi_device *dev, struct comedi_subdevice *s, void *data, |
ed9eccbe DS |
184 | unsigned int num_bytes, unsigned int start_chan_index); |
185 | enum dma_data_direction async_dma_dir; | |
186 | ||
187 | unsigned int state; | |
188 | ||
189 | device_create_result_type *class_dev; | |
190 | int minor; | |
191 | }; | |
192 | ||
193 | struct comedi_buf_page { | |
194 | void *virt_addr; | |
195 | dma_addr_t dma_addr; | |
196 | }; | |
197 | ||
d163679c | 198 | struct comedi_async { |
34c43922 | 199 | struct comedi_subdevice *subdevice; |
ed9eccbe DS |
200 | |
201 | void *prealloc_buf; /* pre-allocated buffer */ | |
202 | unsigned int prealloc_bufsz; /* buffer size, in bytes */ | |
203 | struct comedi_buf_page *buf_page_list; /* virtual and dma address of each page */ | |
204 | unsigned n_buf_pages; /* num elements in buf_page_list */ | |
205 | ||
206 | unsigned int max_bufsize; /* maximum buffer size, bytes */ | |
207 | unsigned int mmap_count; /* current number of mmaps of prealloc_buf */ | |
208 | ||
209 | unsigned int buf_write_count; /* byte count for writer (write completed) */ | |
210 | unsigned int buf_write_alloc_count; /* byte count for writer (allocated for writing) */ | |
211 | unsigned int buf_read_count; /* byte count for reader (read completed) */ | |
212 | unsigned int buf_read_alloc_count; /* byte count for reader (allocated for reading) */ | |
213 | ||
214 | unsigned int buf_write_ptr; /* buffer marker for writer */ | |
215 | unsigned int buf_read_ptr; /* buffer marker for reader */ | |
216 | ||
217 | unsigned int cur_chan; /* useless channel marker for interrupt */ | |
218 | /* number of bytes that have been received for current scan */ | |
219 | unsigned int scan_progress; | |
220 | /* keeps track of where we are in chanlist as for munging */ | |
221 | unsigned int munge_chan; | |
222 | /* number of bytes that have been munged */ | |
223 | unsigned int munge_count; | |
224 | /* buffer marker for munging */ | |
225 | unsigned int munge_ptr; | |
226 | ||
227 | unsigned int events; /* events that have occurred */ | |
228 | ||
229 | comedi_cmd cmd; | |
230 | ||
231 | wait_queue_head_t wait_head; | |
232 | ||
e0dcef71 | 233 | /* callback stuff */ |
ed9eccbe DS |
234 | unsigned int cb_mask; |
235 | int (*cb_func) (unsigned int flags, void *); | |
236 | void *cb_arg; | |
237 | ||
34c43922 | 238 | int (*inttrig) (struct comedi_device *dev, struct comedi_subdevice *s, |
e0dcef71 | 239 | unsigned int x); |
ed9eccbe DS |
240 | }; |
241 | ||
242 | struct comedi_driver_struct { | |
243 | struct comedi_driver_struct *next; | |
244 | ||
245 | const char *driver_name; | |
246 | struct module *module; | |
71b5f4f1 BP |
247 | int (*attach) (struct comedi_device *, comedi_devconfig *); |
248 | int (*detach) (struct comedi_device *); | |
ed9eccbe DS |
249 | |
250 | /* number of elements in board_name and board_id arrays */ | |
251 | unsigned int num_names; | |
252 | const char *const *board_name; | |
253 | /* offset in bytes from one board name pointer to the next */ | |
254 | int offset; | |
255 | }; | |
256 | ||
71b5f4f1 | 257 | struct comedi_device { |
ed9eccbe DS |
258 | int use_count; |
259 | comedi_driver *driver; | |
260 | void *private; | |
261 | ||
262 | device_create_result_type *class_dev; | |
263 | int minor; | |
e0dcef71 GKH |
264 | /* hw_dev is passed to dma_alloc_coherent when allocating async buffers |
265 | * for subdevices that have async_dma_dir set to something other than | |
266 | * DMA_NONE */ | |
ed9eccbe DS |
267 | struct device *hw_dev; |
268 | ||
269 | const char *board_name; | |
270 | const void *board_ptr; | |
271 | int attached; | |
272 | int rt; | |
273 | spinlock_t spinlock; | |
274 | struct mutex mutex; | |
275 | int in_request_module; | |
276 | ||
277 | int n_subdevices; | |
34c43922 | 278 | struct comedi_subdevice *subdevices; |
ed9eccbe DS |
279 | |
280 | /* dumb */ | |
281 | unsigned long iobase; | |
282 | unsigned int irq; | |
283 | ||
34c43922 BP |
284 | struct comedi_subdevice *read_subdev; |
285 | struct comedi_subdevice *write_subdev; | |
ed9eccbe DS |
286 | |
287 | struct fasync_struct *async_queue; | |
288 | ||
71b5f4f1 BP |
289 | void (*open) (struct comedi_device *dev); |
290 | void (*close) (struct comedi_device *dev); | |
ed9eccbe DS |
291 | }; |
292 | ||
293 | struct comedi_device_file_info { | |
71b5f4f1 | 294 | struct comedi_device *device; |
34c43922 BP |
295 | struct comedi_subdevice *read_subdevice; |
296 | struct comedi_subdevice *write_subdevice; | |
ed9eccbe DS |
297 | }; |
298 | ||
299 | #ifdef CONFIG_COMEDI_DEBUG | |
300 | extern int comedi_debug; | |
301 | #else | |
e0dcef71 | 302 | static const int comedi_debug; |
ed9eccbe DS |
303 | #endif |
304 | ||
305 | /* | |
306 | * function prototypes | |
307 | */ | |
308 | ||
34c43922 | 309 | void comedi_event(struct comedi_device *dev, struct comedi_subdevice *s); |
71b5f4f1 | 310 | void comedi_error(const struct comedi_device *dev, const char *s); |
ed9eccbe DS |
311 | |
312 | /* we can expand the number of bits used to encode devices/subdevices into | |
313 | the minor number soon, after more distros support > 8 bit minor numbers | |
314 | (like after Debian Etch gets released) */ | |
315 | enum comedi_minor_bits { | |
316 | COMEDI_DEVICE_MINOR_MASK = 0xf, | |
317 | COMEDI_SUBDEVICE_MINOR_MASK = 0xf0 | |
318 | }; | |
319 | static const unsigned COMEDI_SUBDEVICE_MINOR_SHIFT = 4; | |
320 | static const unsigned COMEDI_SUBDEVICE_MINOR_OFFSET = 1; | |
321 | ||
e0dcef71 | 322 | struct comedi_device_file_info *comedi_get_device_file_info(unsigned minor); |
ed9eccbe | 323 | |
34c43922 | 324 | static inline struct comedi_subdevice *comedi_get_read_subdevice( |
e0dcef71 | 325 | const struct comedi_device_file_info *info) |
ed9eccbe | 326 | { |
e0dcef71 GKH |
327 | if (info->read_subdevice) |
328 | return info->read_subdevice; | |
329 | if (info->device == NULL) | |
330 | return NULL; | |
ed9eccbe DS |
331 | return info->device->read_subdev; |
332 | } | |
333 | ||
34c43922 | 334 | static inline struct comedi_subdevice *comedi_get_write_subdevice( |
e0dcef71 | 335 | const struct comedi_device_file_info *info) |
ed9eccbe | 336 | { |
e0dcef71 GKH |
337 | if (info->write_subdevice) |
338 | return info->write_subdevice; | |
339 | if (info->device == NULL) | |
340 | return NULL; | |
ed9eccbe DS |
341 | return info->device->write_subdev; |
342 | } | |
343 | ||
71b5f4f1 BP |
344 | void comedi_device_detach(struct comedi_device *dev); |
345 | int comedi_device_attach(struct comedi_device *dev, comedi_devconfig *it); | |
ed9eccbe DS |
346 | int comedi_driver_register(comedi_driver *); |
347 | int comedi_driver_unregister(comedi_driver *); | |
348 | ||
349 | void init_polling(void); | |
350 | void cleanup_polling(void); | |
71b5f4f1 BP |
351 | void start_polling(struct comedi_device *); |
352 | void stop_polling(struct comedi_device *); | |
ed9eccbe | 353 | |
34c43922 | 354 | int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s, unsigned long |
ed9eccbe DS |
355 | new_size); |
356 | ||
357 | #ifdef CONFIG_PROC_FS | |
358 | void comedi_proc_init(void); | |
359 | void comedi_proc_cleanup(void); | |
360 | #else | |
361 | static inline void comedi_proc_init(void) | |
362 | { | |
363 | } | |
364 | static inline void comedi_proc_cleanup(void) | |
365 | { | |
366 | } | |
367 | #endif | |
368 | ||
369 | /* subdevice runflags */ | |
370 | enum subdevice_runflags { | |
371 | SRF_USER = 0x00000001, | |
372 | SRF_RT = 0x00000002, | |
e0dcef71 GKH |
373 | /* indicates an COMEDI_CB_ERROR event has occurred since the last |
374 | * command was started */ | |
ed9eccbe DS |
375 | SRF_ERROR = 0x00000004, |
376 | SRF_RUNNING = 0x08000000 | |
377 | }; | |
378 | ||
379 | /* | |
380 | various internal comedi functions | |
381 | */ | |
382 | ||
71b5f4f1 | 383 | int do_rangeinfo_ioctl(struct comedi_device *dev, comedi_rangeinfo *arg); |
34c43922 BP |
384 | int check_chanlist(struct comedi_subdevice *s, int n, unsigned int *chanlist); |
385 | void comedi_set_subdevice_runflags(struct comedi_subdevice *s, unsigned mask, | |
ed9eccbe | 386 | unsigned bits); |
34c43922 BP |
387 | unsigned comedi_get_subdevice_runflags(struct comedi_subdevice *s); |
388 | int insn_inval(struct comedi_device *dev, struct comedi_subdevice *s, | |
790c5541 | 389 | comedi_insn *insn, unsigned int *data); |
ed9eccbe DS |
390 | |
391 | /* range stuff */ | |
392 | ||
e0dcef71 GKH |
393 | #define RANGE(a, b) {(a)*1e6, (b)*1e6, 0} |
394 | #define RANGE_ext(a, b) {(a)*1e6, (b)*1e6, RF_EXTERNAL} | |
395 | #define RANGE_mA(a, b) {(a)*1e6, (b)*1e6, UNIT_mA} | |
396 | #define RANGE_unitless(a, b) {(a)*1e6, (b)*1e6, 0} /* XXX */ | |
397 | #define BIP_RANGE(a) {-(a)*1e6, (a)*1e6, 0} | |
398 | #define UNI_RANGE(a) {0, (a)*1e6, 0} | |
ed9eccbe DS |
399 | |
400 | extern const comedi_lrange range_bipolar10; | |
401 | extern const comedi_lrange range_bipolar5; | |
402 | extern const comedi_lrange range_bipolar2_5; | |
403 | extern const comedi_lrange range_unipolar10; | |
404 | extern const comedi_lrange range_unipolar5; | |
405 | extern const comedi_lrange range_unknown; | |
406 | ||
407 | #define range_digital range_unipolar5 | |
408 | ||
409 | #if __GNUC__ >= 3 | |
410 | #define GCC_ZERO_LENGTH_ARRAY | |
411 | #else | |
412 | #define GCC_ZERO_LENGTH_ARRAY 0 | |
413 | #endif | |
414 | ||
415 | struct comedi_lrange_struct { | |
416 | int length; | |
417 | comedi_krange range[GCC_ZERO_LENGTH_ARRAY]; | |
418 | }; | |
419 | ||
420 | /* some silly little inline functions */ | |
421 | ||
71b5f4f1 | 422 | static inline int alloc_subdevices(struct comedi_device *dev, |
e0dcef71 | 423 | unsigned int num_subdevices) |
ed9eccbe DS |
424 | { |
425 | unsigned i; | |
426 | ||
427 | dev->n_subdevices = num_subdevices; | |
428 | dev->subdevices = | |
34c43922 | 429 | kcalloc(num_subdevices, sizeof(struct comedi_subdevice), GFP_KERNEL); |
ed9eccbe DS |
430 | if (!dev->subdevices) |
431 | return -ENOMEM; | |
432 | for (i = 0; i < num_subdevices; ++i) { | |
433 | dev->subdevices[i].device = dev; | |
434 | dev->subdevices[i].async_dma_dir = DMA_NONE; | |
435 | spin_lock_init(&dev->subdevices[i].spin_lock); | |
436 | dev->subdevices[i].minor = -1; | |
437 | } | |
438 | return 0; | |
439 | } | |
440 | ||
71b5f4f1 | 441 | static inline int alloc_private(struct comedi_device *dev, int size) |
ed9eccbe DS |
442 | { |
443 | dev->private = kzalloc(size, GFP_KERNEL); | |
444 | if (!dev->private) | |
445 | return -ENOMEM; | |
446 | return 0; | |
447 | } | |
448 | ||
34c43922 | 449 | static inline unsigned int bytes_per_sample(const struct comedi_subdevice *subd) |
ed9eccbe DS |
450 | { |
451 | if (subd->subdev_flags & SDF_LSAMPL) | |
790c5541 | 452 | return sizeof(unsigned int); |
ed9eccbe | 453 | else |
790c5541 | 454 | return sizeof(short); |
ed9eccbe DS |
455 | } |
456 | ||
457 | /* must be used in attach to set dev->hw_dev if you wish to dma directly | |
458 | into comedi's buffer */ | |
71b5f4f1 | 459 | static inline void comedi_set_hw_dev(struct comedi_device *dev, struct device *hw_dev) |
ed9eccbe | 460 | { |
e0dcef71 | 461 | if (dev->hw_dev) |
ed9eccbe | 462 | put_device(dev->hw_dev); |
e0dcef71 | 463 | |
ed9eccbe DS |
464 | dev->hw_dev = hw_dev; |
465 | if (dev->hw_dev) { | |
466 | dev->hw_dev = get_device(dev->hw_dev); | |
467 | BUG_ON(dev->hw_dev == NULL); | |
468 | } | |
469 | } | |
470 | ||
d163679c BP |
471 | int comedi_buf_put(struct comedi_async *async, short x); |
472 | int comedi_buf_get(struct comedi_async *async, short *x); | |
ed9eccbe | 473 | |
d163679c BP |
474 | unsigned int comedi_buf_write_n_available(struct comedi_async *async); |
475 | unsigned int comedi_buf_write_alloc(struct comedi_async *async, unsigned int nbytes); | |
476 | unsigned int comedi_buf_write_alloc_strict(struct comedi_async *async, | |
ed9eccbe | 477 | unsigned int nbytes); |
d163679c BP |
478 | unsigned comedi_buf_write_free(struct comedi_async *async, unsigned int nbytes); |
479 | unsigned comedi_buf_read_alloc(struct comedi_async *async, unsigned nbytes); | |
480 | unsigned comedi_buf_read_free(struct comedi_async *async, unsigned int nbytes); | |
481 | unsigned int comedi_buf_read_n_available(struct comedi_async *async); | |
482 | void comedi_buf_memcpy_to(struct comedi_async *async, unsigned int offset, | |
ed9eccbe | 483 | const void *source, unsigned int num_bytes); |
d163679c | 484 | void comedi_buf_memcpy_from(struct comedi_async *async, unsigned int offset, |
ed9eccbe | 485 | void *destination, unsigned int num_bytes); |
d163679c | 486 | static inline unsigned comedi_buf_write_n_allocated(struct comedi_async *async) |
ed9eccbe DS |
487 | { |
488 | return async->buf_write_alloc_count - async->buf_write_count; | |
489 | } | |
d163679c | 490 | static inline unsigned comedi_buf_read_n_allocated(struct comedi_async *async) |
ed9eccbe DS |
491 | { |
492 | return async->buf_read_alloc_count - async->buf_read_count; | |
493 | } | |
494 | ||
d163679c | 495 | void comedi_reset_async_buf(struct comedi_async *async); |
ed9eccbe DS |
496 | |
497 | static inline void *comedi_aux_data(int options[], int n) | |
498 | { | |
499 | unsigned long address; | |
500 | unsigned long addressLow; | |
501 | int bit_shift; | |
502 | if (sizeof(int) >= sizeof(void *)) | |
503 | address = options[COMEDI_DEVCONF_AUX_DATA_LO]; | |
504 | else { | |
505 | address = options[COMEDI_DEVCONF_AUX_DATA_HI]; | |
506 | bit_shift = sizeof(int) * 8; | |
507 | address <<= bit_shift; | |
508 | addressLow = options[COMEDI_DEVCONF_AUX_DATA_LO]; | |
509 | addressLow &= (1UL << bit_shift) - 1; | |
510 | address |= addressLow; | |
511 | } | |
512 | if (n >= 1) | |
513 | address += options[COMEDI_DEVCONF_AUX_DATA0_LENGTH]; | |
514 | if (n >= 2) | |
515 | address += options[COMEDI_DEVCONF_AUX_DATA1_LENGTH]; | |
516 | if (n >= 3) | |
517 | address += options[COMEDI_DEVCONF_AUX_DATA2_LENGTH]; | |
518 | BUG_ON(n > 3); | |
519 | return (void *)address; | |
520 | } | |
521 | ||
522 | int comedi_alloc_board_minor(struct device *hardware_device); | |
523 | void comedi_free_board_minor(unsigned minor); | |
34c43922 BP |
524 | int comedi_alloc_subdevice_minor(struct comedi_device *dev, struct comedi_subdevice *s); |
525 | void comedi_free_subdevice_minor(struct comedi_subdevice *s); | |
ed9eccbe DS |
526 | int comedi_pci_auto_config(struct pci_dev *pcidev, const char *board_name); |
527 | void comedi_pci_auto_unconfig(struct pci_dev *pcidev); | |
c28264da BP |
528 | struct usb_device; /* forward declaration */ |
529 | int comedi_usb_auto_config(struct usb_device *usbdev, const char *board_name); | |
530 | void comedi_usb_auto_unconfig(struct usb_device *usbdev); | |
ed9eccbe | 531 | |
ed9eccbe | 532 | #include "comedi_rt.h" |
ed9eccbe DS |
533 | |
534 | #endif /* _COMEDIDEV_H */ |