equal
deleted
inserted
replaced
55 #define ATTRIBUTES __attribute__ ((__noinline__)) |
55 #define ATTRIBUTES __attribute__ ((__noinline__)) |
56 #else |
56 #else |
57 #define ATTRIBUTES |
57 #define ATTRIBUTES |
58 #endif |
58 #endif |
59 |
59 |
|
60 #ifndef EC_IOCTL_RTDM |
|
61 #define ec_copy_to_user copy_to_user |
|
62 #define ec_copy_from_user copy_from_user |
|
63 #else |
|
64 /* RTDM provides rtdm_copy_{to,from}_user but they need fd argument |
|
65 for no good reason. This is is just a shortcut to real call */ |
|
66 #define ec_copy_to_user __copy_to_user_inatomic |
|
67 #define ec_copy_from_user __copy_from_user_inatomic |
|
68 #endif |
|
69 |
|
70 |
60 /*****************************************************************************/ |
71 /*****************************************************************************/ |
61 |
72 |
62 /** Copies a string to an ioctl structure. |
73 /** Copies a string to an ioctl structure. |
63 */ |
74 */ |
64 static void ec_ioctl_strcpy( |
75 static void ec_ioctl_strcpy( |
87 ec_ioctl_module_t data; |
98 ec_ioctl_module_t data; |
88 |
99 |
89 data.ioctl_version_magic = EC_IOCTL_VERSION_MAGIC; |
100 data.ioctl_version_magic = EC_IOCTL_VERSION_MAGIC; |
90 data.master_count = ec_master_count(); |
101 data.master_count = ec_master_count(); |
91 |
102 |
92 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
103 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
93 return -EFAULT; |
104 return -EFAULT; |
94 |
105 |
95 return 0; |
106 return 0; |
96 } |
107 } |
97 |
108 |
181 |
192 |
182 io.app_time = master->app_time; |
193 io.app_time = master->app_time; |
183 io.ref_clock = |
194 io.ref_clock = |
184 master->dc_ref_clock ? master->dc_ref_clock->ring_position : 0xffff; |
195 master->dc_ref_clock ? master->dc_ref_clock->ring_position : 0xffff; |
185 |
196 |
186 if (copy_to_user((void __user *) arg, &io, sizeof(io))) { |
197 if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) { |
187 return -EFAULT; |
198 return -EFAULT; |
188 } |
199 } |
189 |
200 |
190 return 0; |
201 return 0; |
191 } |
202 } |
203 { |
214 { |
204 ec_ioctl_slave_t data; |
215 ec_ioctl_slave_t data; |
205 const ec_slave_t *slave; |
216 const ec_slave_t *slave; |
206 int i; |
217 int i; |
207 |
218 |
208 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
219 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
209 return -EFAULT; |
220 return -EFAULT; |
210 } |
221 } |
211 |
222 |
212 if (down_interruptible(&master->master_sem)) |
223 if (down_interruptible(&master->master_sem)) |
213 return -EINTR; |
224 return -EINTR; |
269 ec_ioctl_strcpy(data.order, slave->sii.order); |
280 ec_ioctl_strcpy(data.order, slave->sii.order); |
270 ec_ioctl_strcpy(data.name, slave->sii.name); |
281 ec_ioctl_strcpy(data.name, slave->sii.name); |
271 |
282 |
272 up(&master->master_sem); |
283 up(&master->master_sem); |
273 |
284 |
274 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
285 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
275 return -EFAULT; |
286 return -EFAULT; |
276 |
287 |
277 return 0; |
288 return 0; |
278 } |
289 } |
279 |
290 |
290 { |
301 { |
291 ec_ioctl_slave_sync_t data; |
302 ec_ioctl_slave_sync_t data; |
292 const ec_slave_t *slave; |
303 const ec_slave_t *slave; |
293 const ec_sync_t *sync; |
304 const ec_sync_t *sync; |
294 |
305 |
295 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
306 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
296 return -EFAULT; |
307 return -EFAULT; |
297 } |
308 } |
298 |
309 |
299 if (down_interruptible(&master->master_sem)) |
310 if (down_interruptible(&master->master_sem)) |
300 return -EINTR; |
311 return -EINTR; |
322 data.enable = sync->enable; |
333 data.enable = sync->enable; |
323 data.pdo_count = ec_pdo_list_count(&sync->pdos); |
334 data.pdo_count = ec_pdo_list_count(&sync->pdos); |
324 |
335 |
325 up(&master->master_sem); |
336 up(&master->master_sem); |
326 |
337 |
327 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
338 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
328 return -EFAULT; |
339 return -EFAULT; |
329 |
340 |
330 return 0; |
341 return 0; |
331 } |
342 } |
332 |
343 |
344 ec_ioctl_slave_sync_pdo_t data; |
355 ec_ioctl_slave_sync_pdo_t data; |
345 const ec_slave_t *slave; |
356 const ec_slave_t *slave; |
346 const ec_sync_t *sync; |
357 const ec_sync_t *sync; |
347 const ec_pdo_t *pdo; |
358 const ec_pdo_t *pdo; |
348 |
359 |
349 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
360 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
350 return -EFAULT; |
361 return -EFAULT; |
351 } |
362 } |
352 |
363 |
353 if (down_interruptible(&master->master_sem)) |
364 if (down_interruptible(&master->master_sem)) |
354 return -EINTR; |
365 return -EINTR; |
381 data.entry_count = ec_pdo_entry_count(pdo); |
392 data.entry_count = ec_pdo_entry_count(pdo); |
382 ec_ioctl_strcpy(data.name, pdo->name); |
393 ec_ioctl_strcpy(data.name, pdo->name); |
383 |
394 |
384 up(&master->master_sem); |
395 up(&master->master_sem); |
385 |
396 |
386 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
397 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
387 return -EFAULT; |
398 return -EFAULT; |
388 |
399 |
389 return 0; |
400 return 0; |
390 } |
401 } |
391 |
402 |
404 const ec_slave_t *slave; |
415 const ec_slave_t *slave; |
405 const ec_sync_t *sync; |
416 const ec_sync_t *sync; |
406 const ec_pdo_t *pdo; |
417 const ec_pdo_t *pdo; |
407 const ec_pdo_entry_t *entry; |
418 const ec_pdo_entry_t *entry; |
408 |
419 |
409 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
420 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
410 return -EFAULT; |
421 return -EFAULT; |
411 } |
422 } |
412 |
423 |
413 if (down_interruptible(&master->master_sem)) |
424 if (down_interruptible(&master->master_sem)) |
414 return -EINTR; |
425 return -EINTR; |
450 data.bit_length = entry->bit_length; |
461 data.bit_length = entry->bit_length; |
451 ec_ioctl_strcpy(data.name, entry->name); |
462 ec_ioctl_strcpy(data.name, entry->name); |
452 |
463 |
453 up(&master->master_sem); |
464 up(&master->master_sem); |
454 |
465 |
455 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
466 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
456 return -EFAULT; |
467 return -EFAULT; |
457 |
468 |
458 return 0; |
469 return 0; |
459 } |
470 } |
460 |
471 |
471 { |
482 { |
472 ec_ioctl_domain_t data; |
483 ec_ioctl_domain_t data; |
473 const ec_domain_t *domain; |
484 const ec_domain_t *domain; |
474 unsigned int dev_idx; |
485 unsigned int dev_idx; |
475 |
486 |
476 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
487 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
477 return -EFAULT; |
488 return -EFAULT; |
478 } |
489 } |
479 |
490 |
480 if (down_interruptible(&master->master_sem)) |
491 if (down_interruptible(&master->master_sem)) |
481 return -EINTR; |
492 return -EINTR; |
495 data.expected_working_counter = domain->expected_working_counter; |
506 data.expected_working_counter = domain->expected_working_counter; |
496 data.fmmu_count = ec_domain_fmmu_count(domain); |
507 data.fmmu_count = ec_domain_fmmu_count(domain); |
497 |
508 |
498 up(&master->master_sem); |
509 up(&master->master_sem); |
499 |
510 |
500 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
511 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
501 return -EFAULT; |
512 return -EFAULT; |
502 |
513 |
503 return 0; |
514 return 0; |
504 } |
515 } |
505 |
516 |
516 { |
527 { |
517 ec_ioctl_domain_fmmu_t data; |
528 ec_ioctl_domain_fmmu_t data; |
518 const ec_domain_t *domain; |
529 const ec_domain_t *domain; |
519 const ec_fmmu_config_t *fmmu; |
530 const ec_fmmu_config_t *fmmu; |
520 |
531 |
521 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
532 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
522 return -EFAULT; |
533 return -EFAULT; |
523 } |
534 } |
524 |
535 |
525 if (down_interruptible(&master->master_sem)) |
536 if (down_interruptible(&master->master_sem)) |
526 return -EINTR; |
537 return -EINTR; |
547 data.logical_address = fmmu->logical_start_address; |
558 data.logical_address = fmmu->logical_start_address; |
548 data.data_size = fmmu->data_size; |
559 data.data_size = fmmu->data_size; |
549 |
560 |
550 up(&master->master_sem); |
561 up(&master->master_sem); |
551 |
562 |
552 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
563 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
553 return -EFAULT; |
564 return -EFAULT; |
554 |
565 |
555 return 0; |
566 return 0; |
556 } |
567 } |
557 |
568 |
567 ) |
578 ) |
568 { |
579 { |
569 ec_ioctl_domain_data_t data; |
580 ec_ioctl_domain_data_t data; |
570 const ec_domain_t *domain; |
581 const ec_domain_t *domain; |
571 |
582 |
572 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
583 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
573 return -EFAULT; |
584 return -EFAULT; |
574 } |
585 } |
575 |
586 |
576 if (down_interruptible(&master->master_sem)) |
587 if (down_interruptible(&master->master_sem)) |
577 return -EINTR; |
588 return -EINTR; |
588 EC_MASTER_ERR(master, "Data size mismatch %u/%zu!\n", |
599 EC_MASTER_ERR(master, "Data size mismatch %u/%zu!\n", |
589 data.data_size, domain->data_size); |
600 data.data_size, domain->data_size); |
590 return -EFAULT; |
601 return -EFAULT; |
591 } |
602 } |
592 |
603 |
593 if (copy_to_user((void __user *) data.target, domain->data, |
604 if (ec_copy_to_user((void __user *) data.target, domain->data, |
594 domain->data_size)) { |
605 domain->data_size)) { |
595 up(&master->master_sem); |
606 up(&master->master_sem); |
596 return -EFAULT; |
607 return -EFAULT; |
597 } |
608 } |
598 |
609 |
641 ) |
652 ) |
642 { |
653 { |
643 ec_ioctl_slave_state_t data; |
654 ec_ioctl_slave_state_t data; |
644 ec_slave_t *slave; |
655 ec_slave_t *slave; |
645 |
656 |
646 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
657 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
647 return -EFAULT; |
658 return -EFAULT; |
648 } |
659 } |
649 |
660 |
650 if (down_interruptible(&master->master_sem)) |
661 if (down_interruptible(&master->master_sem)) |
651 return -EINTR; |
662 return -EINTR; |
677 { |
688 { |
678 ec_ioctl_slave_sdo_t data; |
689 ec_ioctl_slave_sdo_t data; |
679 const ec_slave_t *slave; |
690 const ec_slave_t *slave; |
680 const ec_sdo_t *sdo; |
691 const ec_sdo_t *sdo; |
681 |
692 |
682 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
693 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
683 return -EFAULT; |
694 return -EFAULT; |
684 } |
695 } |
685 |
696 |
686 if (down_interruptible(&master->master_sem)) |
697 if (down_interruptible(&master->master_sem)) |
687 return -EINTR; |
698 return -EINTR; |
705 data.max_subindex = sdo->max_subindex; |
716 data.max_subindex = sdo->max_subindex; |
706 ec_ioctl_strcpy(data.name, sdo->name); |
717 ec_ioctl_strcpy(data.name, sdo->name); |
707 |
718 |
708 up(&master->master_sem); |
719 up(&master->master_sem); |
709 |
720 |
710 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
721 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
711 return -EFAULT; |
722 return -EFAULT; |
712 |
723 |
713 return 0; |
724 return 0; |
714 } |
725 } |
715 |
726 |
727 ec_ioctl_slave_sdo_entry_t data; |
738 ec_ioctl_slave_sdo_entry_t data; |
728 const ec_slave_t *slave; |
739 const ec_slave_t *slave; |
729 const ec_sdo_t *sdo; |
740 const ec_sdo_t *sdo; |
730 const ec_sdo_entry_t *entry; |
741 const ec_sdo_entry_t *entry; |
731 |
742 |
732 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
743 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
733 return -EFAULT; |
744 return -EFAULT; |
734 } |
745 } |
735 |
746 |
736 if (down_interruptible(&master->master_sem)) |
747 if (down_interruptible(&master->master_sem)) |
737 return -EINTR; |
748 return -EINTR; |
785 entry->write_access[EC_SDO_ENTRY_ACCESS_OP]; |
796 entry->write_access[EC_SDO_ENTRY_ACCESS_OP]; |
786 ec_ioctl_strcpy(data.description, entry->description); |
797 ec_ioctl_strcpy(data.description, entry->description); |
787 |
798 |
788 up(&master->master_sem); |
799 up(&master->master_sem); |
789 |
800 |
790 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
801 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
791 return -EFAULT; |
802 return -EFAULT; |
792 |
803 |
793 return 0; |
804 return 0; |
794 } |
805 } |
795 |
806 |
806 { |
817 { |
807 ec_ioctl_slave_sdo_upload_t data; |
818 ec_ioctl_slave_sdo_upload_t data; |
808 uint8_t *target; |
819 uint8_t *target; |
809 int ret; |
820 int ret; |
810 |
821 |
811 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
822 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
812 return -EFAULT; |
823 return -EFAULT; |
813 } |
824 } |
814 |
825 |
815 if (!(target = kmalloc(data.target_size, GFP_KERNEL))) { |
826 if (!(target = kmalloc(data.target_size, GFP_KERNEL))) { |
816 EC_MASTER_ERR(master, "Failed to allocate %zu bytes" |
827 EC_MASTER_ERR(master, "Failed to allocate %zu bytes" |
821 ret = ecrt_master_sdo_upload(master, data.slave_position, |
832 ret = ecrt_master_sdo_upload(master, data.slave_position, |
822 data.sdo_index, data.sdo_entry_subindex, target, |
833 data.sdo_index, data.sdo_entry_subindex, target, |
823 data.target_size, &data.data_size, &data.abort_code); |
834 data.target_size, &data.data_size, &data.abort_code); |
824 |
835 |
825 if (!ret) { |
836 if (!ret) { |
826 if (copy_to_user((void __user *) data.target, |
837 if (ec_copy_to_user((void __user *) data.target, |
827 target, data.data_size)) { |
838 target, data.data_size)) { |
828 kfree(target); |
839 kfree(target); |
829 return -EFAULT; |
840 return -EFAULT; |
830 } |
841 } |
831 } |
842 } |
832 |
843 |
833 kfree(target); |
844 kfree(target); |
834 |
845 |
835 if (__copy_to_user((void __user *) arg, &data, sizeof(data))) { |
846 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) { |
836 return -EFAULT; |
847 return -EFAULT; |
837 } |
848 } |
838 |
849 |
839 return ret; |
850 return ret; |
840 } |
851 } |
852 { |
863 { |
853 ec_ioctl_slave_sdo_download_t data; |
864 ec_ioctl_slave_sdo_download_t data; |
854 uint8_t *sdo_data; |
865 uint8_t *sdo_data; |
855 int retval; |
866 int retval; |
856 |
867 |
857 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
868 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
858 return -EFAULT; |
869 return -EFAULT; |
859 } |
870 } |
860 |
871 |
861 if (!(sdo_data = kmalloc(data.data_size, GFP_KERNEL))) { |
872 if (!(sdo_data = kmalloc(data.data_size, GFP_KERNEL))) { |
862 EC_MASTER_ERR(master, "Failed to allocate %zu bytes" |
873 EC_MASTER_ERR(master, "Failed to allocate %zu bytes" |
863 " for SDO download.\n", data.data_size); |
874 " for SDO download.\n", data.data_size); |
864 return -ENOMEM; |
875 return -ENOMEM; |
865 } |
876 } |
866 |
877 |
867 if (copy_from_user(sdo_data, (void __user *) data.data, data.data_size)) { |
878 if (ec_copy_from_user(sdo_data, (void __user *) data.data, data.data_size)) { |
868 kfree(sdo_data); |
879 kfree(sdo_data); |
869 return -EFAULT; |
880 return -EFAULT; |
870 } |
881 } |
871 |
882 |
872 if (data.complete_access) { |
883 if (data.complete_access) { |
878 data.data_size, &data.abort_code); |
889 data.data_size, &data.abort_code); |
879 } |
890 } |
880 |
891 |
881 kfree(sdo_data); |
892 kfree(sdo_data); |
882 |
893 |
883 if (__copy_to_user((void __user *) arg, &data, sizeof(data))) { |
894 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) { |
884 retval = -EFAULT; |
895 retval = -EFAULT; |
885 } |
896 } |
886 |
897 |
887 return retval; |
898 return retval; |
888 } |
899 } |
900 { |
911 { |
901 ec_ioctl_slave_sii_t data; |
912 ec_ioctl_slave_sii_t data; |
902 const ec_slave_t *slave; |
913 const ec_slave_t *slave; |
903 int retval; |
914 int retval; |
904 |
915 |
905 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
916 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
906 return -EFAULT; |
917 return -EFAULT; |
907 } |
918 } |
908 |
919 |
909 if (down_interruptible(&master->master_sem)) |
920 if (down_interruptible(&master->master_sem)) |
910 return -EINTR; |
921 return -EINTR; |
923 EC_SLAVE_ERR(slave, "Invalid SII read offset/size %u/%u for slave SII" |
934 EC_SLAVE_ERR(slave, "Invalid SII read offset/size %u/%u for slave SII" |
924 " size %zu!\n", data.offset, data.nwords, slave->sii_nwords); |
935 " size %zu!\n", data.offset, data.nwords, slave->sii_nwords); |
925 return -EINVAL; |
936 return -EINVAL; |
926 } |
937 } |
927 |
938 |
928 if (copy_to_user((void __user *) data.words, |
939 if (ec_copy_to_user((void __user *) data.words, |
929 slave->sii_words + data.offset, data.nwords * 2)) |
940 slave->sii_words + data.offset, data.nwords * 2)) |
930 retval = -EFAULT; |
941 retval = -EFAULT; |
931 else |
942 else |
932 retval = 0; |
943 retval = 0; |
933 |
944 |
950 ec_slave_t *slave; |
961 ec_slave_t *slave; |
951 unsigned int byte_size; |
962 unsigned int byte_size; |
952 uint16_t *words; |
963 uint16_t *words; |
953 ec_sii_write_request_t request; |
964 ec_sii_write_request_t request; |
954 |
965 |
955 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
966 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
956 return -EFAULT; |
967 return -EFAULT; |
957 } |
968 } |
958 |
969 |
959 if (!data.nwords) { |
970 if (!data.nwords) { |
960 return 0; |
971 return 0; |
965 EC_MASTER_ERR(master, "Failed to allocate %u bytes" |
976 EC_MASTER_ERR(master, "Failed to allocate %u bytes" |
966 " for SII contents.\n", byte_size); |
977 " for SII contents.\n", byte_size); |
967 return -ENOMEM; |
978 return -ENOMEM; |
968 } |
979 } |
969 |
980 |
970 if (copy_from_user(words, |
981 if (ec_copy_from_user(words, |
971 (void __user *) data.words, byte_size)) { |
982 (void __user *) data.words, byte_size)) { |
972 kfree(words); |
983 kfree(words); |
973 return -EFAULT; |
984 return -EFAULT; |
974 } |
985 } |
975 |
986 |
1037 ec_ioctl_slave_reg_t io; |
1048 ec_ioctl_slave_reg_t io; |
1038 ec_slave_t *slave; |
1049 ec_slave_t *slave; |
1039 ec_reg_request_t request; |
1050 ec_reg_request_t request; |
1040 int ret; |
1051 int ret; |
1041 |
1052 |
1042 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
1053 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
1043 return -EFAULT; |
1054 return -EFAULT; |
1044 } |
1055 } |
1045 |
1056 |
1046 if (!io.size) { |
1057 if (!io.size) { |
1047 return 0; |
1058 return 0; |
1091 |
1102 |
1092 // wait until master FSM has finished processing |
1103 // wait until master FSM has finished processing |
1093 wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY); |
1104 wait_event(master->request_queue, request.state != EC_INT_REQUEST_BUSY); |
1094 |
1105 |
1095 if (request.state == EC_INT_REQUEST_SUCCESS) { |
1106 if (request.state == EC_INT_REQUEST_SUCCESS) { |
1096 if (copy_to_user((void __user *) io.data, request.data, io.size)) { |
1107 if (ec_copy_to_user((void __user *) io.data, request.data, io.size)) { |
1097 return -EFAULT; |
1108 return -EFAULT; |
1098 } |
1109 } |
1099 } |
1110 } |
1100 ec_reg_request_clear(&request); |
1111 ec_reg_request_clear(&request); |
1101 |
1112 |
1116 ec_ioctl_slave_reg_t io; |
1127 ec_ioctl_slave_reg_t io; |
1117 ec_slave_t *slave; |
1128 ec_slave_t *slave; |
1118 ec_reg_request_t request; |
1129 ec_reg_request_t request; |
1119 int ret; |
1130 int ret; |
1120 |
1131 |
1121 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
1132 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
1122 return -EFAULT; |
1133 return -EFAULT; |
1123 } |
1134 } |
1124 |
1135 |
1125 if (!io.size) { |
1136 if (!io.size) { |
1126 return 0; |
1137 return 0; |
1130 ret = ec_reg_request_init(&request, io.size); |
1141 ret = ec_reg_request_init(&request, io.size); |
1131 if (ret) { |
1142 if (ret) { |
1132 return ret; |
1143 return ret; |
1133 } |
1144 } |
1134 |
1145 |
1135 if (copy_from_user(request.data, (void __user *) io.data, io.size)) { |
1146 if (ec_copy_from_user(request.data, (void __user *) io.data, io.size)) { |
1136 ec_reg_request_clear(&request); |
1147 ec_reg_request_clear(&request); |
1137 return -EFAULT; |
1148 return -EFAULT; |
1138 } |
1149 } |
1139 |
1150 |
1140 ecrt_reg_request_write(&request, io.address, io.size); |
1151 ecrt_reg_request_write(&request, io.address, io.size); |
1200 { |
1211 { |
1201 ec_ioctl_config_t data; |
1212 ec_ioctl_config_t data; |
1202 const ec_slave_config_t *sc; |
1213 const ec_slave_config_t *sc; |
1203 uint8_t i; |
1214 uint8_t i; |
1204 |
1215 |
1205 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1216 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1206 return -EFAULT; |
1217 return -EFAULT; |
1207 } |
1218 } |
1208 |
1219 |
1209 if (down_interruptible(&master->master_sem)) |
1220 if (down_interruptible(&master->master_sem)) |
1210 return -EINTR; |
1221 return -EINTR; |
1237 data.dc_sync[i] = sc->dc_sync[i]; |
1248 data.dc_sync[i] = sc->dc_sync[i]; |
1238 } |
1249 } |
1239 |
1250 |
1240 up(&master->master_sem); |
1251 up(&master->master_sem); |
1241 |
1252 |
1242 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
1253 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
1243 return -EFAULT; |
1254 return -EFAULT; |
1244 |
1255 |
1245 return 0; |
1256 return 0; |
1246 } |
1257 } |
1247 |
1258 |
1258 { |
1269 { |
1259 ec_ioctl_config_pdo_t data; |
1270 ec_ioctl_config_pdo_t data; |
1260 const ec_slave_config_t *sc; |
1271 const ec_slave_config_t *sc; |
1261 const ec_pdo_t *pdo; |
1272 const ec_pdo_t *pdo; |
1262 |
1273 |
1263 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1274 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1264 return -EFAULT; |
1275 return -EFAULT; |
1265 } |
1276 } |
1266 |
1277 |
1267 if (data.sync_index >= EC_MAX_SYNC_MANAGERS) { |
1278 if (data.sync_index >= EC_MAX_SYNC_MANAGERS) { |
1268 EC_MASTER_ERR(master, "Invalid sync manager index %u!\n", |
1279 EC_MASTER_ERR(master, "Invalid sync manager index %u!\n", |
1293 data.entry_count = ec_pdo_entry_count(pdo); |
1304 data.entry_count = ec_pdo_entry_count(pdo); |
1294 ec_ioctl_strcpy(data.name, pdo->name); |
1305 ec_ioctl_strcpy(data.name, pdo->name); |
1295 |
1306 |
1296 up(&master->master_sem); |
1307 up(&master->master_sem); |
1297 |
1308 |
1298 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
1309 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
1299 return -EFAULT; |
1310 return -EFAULT; |
1300 |
1311 |
1301 return 0; |
1312 return 0; |
1302 } |
1313 } |
1303 |
1314 |
1315 ec_ioctl_config_pdo_entry_t data; |
1326 ec_ioctl_config_pdo_entry_t data; |
1316 const ec_slave_config_t *sc; |
1327 const ec_slave_config_t *sc; |
1317 const ec_pdo_t *pdo; |
1328 const ec_pdo_t *pdo; |
1318 const ec_pdo_entry_t *entry; |
1329 const ec_pdo_entry_t *entry; |
1319 |
1330 |
1320 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1331 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1321 return -EFAULT; |
1332 return -EFAULT; |
1322 } |
1333 } |
1323 |
1334 |
1324 if (data.sync_index >= EC_MAX_SYNC_MANAGERS) { |
1335 if (data.sync_index >= EC_MAX_SYNC_MANAGERS) { |
1325 EC_MASTER_ERR(master, "Invalid sync manager index %u!\n", |
1336 EC_MASTER_ERR(master, "Invalid sync manager index %u!\n", |
1358 data.bit_length = entry->bit_length; |
1369 data.bit_length = entry->bit_length; |
1359 ec_ioctl_strcpy(data.name, entry->name); |
1370 ec_ioctl_strcpy(data.name, entry->name); |
1360 |
1371 |
1361 up(&master->master_sem); |
1372 up(&master->master_sem); |
1362 |
1373 |
1363 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
1374 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
1364 return -EFAULT; |
1375 return -EFAULT; |
1365 |
1376 |
1366 return 0; |
1377 return 0; |
1367 } |
1378 } |
1368 |
1379 |
1383 |
1394 |
1384 if (!(ioctl = kmalloc(sizeof(*ioctl), GFP_KERNEL))) { |
1395 if (!(ioctl = kmalloc(sizeof(*ioctl), GFP_KERNEL))) { |
1385 return -ENOMEM; |
1396 return -ENOMEM; |
1386 } |
1397 } |
1387 |
1398 |
1388 if (copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) { |
1399 if (ec_copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) { |
1389 kfree(ioctl); |
1400 kfree(ioctl); |
1390 return -EFAULT; |
1401 return -EFAULT; |
1391 } |
1402 } |
1392 |
1403 |
1393 if (down_interruptible(&master->master_sem)) { |
1404 if (down_interruptible(&master->master_sem)) { |
1419 min((u32) ioctl->size, (u32) EC_MAX_SDO_DATA_SIZE)); |
1430 min((u32) ioctl->size, (u32) EC_MAX_SDO_DATA_SIZE)); |
1420 ioctl->complete_access = req->complete_access; |
1431 ioctl->complete_access = req->complete_access; |
1421 |
1432 |
1422 up(&master->master_sem); |
1433 up(&master->master_sem); |
1423 |
1434 |
1424 if (copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) { |
1435 if (ec_copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) { |
1425 kfree(ioctl); |
1436 kfree(ioctl); |
1426 return -EFAULT; |
1437 return -EFAULT; |
1427 } |
1438 } |
1428 |
1439 |
1429 kfree(ioctl); |
1440 kfree(ioctl); |
1447 |
1458 |
1448 if (!(ioctl = kmalloc(sizeof(*ioctl), GFP_KERNEL))) { |
1459 if (!(ioctl = kmalloc(sizeof(*ioctl), GFP_KERNEL))) { |
1449 return -ENOMEM; |
1460 return -ENOMEM; |
1450 } |
1461 } |
1451 |
1462 |
1452 if (copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) { |
1463 if (ec_copy_from_user(ioctl, (void __user *) arg, sizeof(*ioctl))) { |
1453 kfree(ioctl); |
1464 kfree(ioctl); |
1454 return -EFAULT; |
1465 return -EFAULT; |
1455 } |
1466 } |
1456 |
1467 |
1457 if (down_interruptible(&master->master_sem)) { |
1468 if (down_interruptible(&master->master_sem)) { |
1483 memcpy(ioctl->data, req->data, |
1494 memcpy(ioctl->data, req->data, |
1484 min((u32) ioctl->size, (u32) EC_MAX_IDN_DATA_SIZE)); |
1495 min((u32) ioctl->size, (u32) EC_MAX_IDN_DATA_SIZE)); |
1485 |
1496 |
1486 up(&master->master_sem); |
1497 up(&master->master_sem); |
1487 |
1498 |
1488 if (copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) { |
1499 if (ec_copy_to_user((void __user *) arg, ioctl, sizeof(*ioctl))) { |
1489 kfree(ioctl); |
1500 kfree(ioctl); |
1490 return -EFAULT; |
1501 return -EFAULT; |
1491 } |
1502 } |
1492 |
1503 |
1493 kfree(ioctl); |
1504 kfree(ioctl); |
1508 ) |
1519 ) |
1509 { |
1520 { |
1510 ec_ioctl_eoe_handler_t data; |
1521 ec_ioctl_eoe_handler_t data; |
1511 const ec_eoe_t *eoe; |
1522 const ec_eoe_t *eoe; |
1512 |
1523 |
1513 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1524 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1514 return -EFAULT; |
1525 return -EFAULT; |
1515 } |
1526 } |
1516 |
1527 |
1517 if (down_interruptible(&master->master_sem)) |
1528 if (down_interruptible(&master->master_sem)) |
1518 return -EINTR; |
1529 return -EINTR; |
1538 data.tx_queued_frames = eoe->tx_queued_frames; |
1549 data.tx_queued_frames = eoe->tx_queued_frames; |
1539 data.tx_queue_size = eoe->tx_queue_size; |
1550 data.tx_queue_size = eoe->tx_queue_size; |
1540 |
1551 |
1541 up(&master->master_sem); |
1552 up(&master->master_sem); |
1542 |
1553 |
1543 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
1554 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
1544 return -EFAULT; |
1555 return -EFAULT; |
1545 |
1556 |
1546 return 0; |
1557 return 0; |
1547 } |
1558 } |
1548 |
1559 |
1613 ec_slave_config_t *sc, *entry; |
1624 ec_slave_config_t *sc, *entry; |
1614 |
1625 |
1615 if (unlikely(!ctx->requested)) |
1626 if (unlikely(!ctx->requested)) |
1616 return -EPERM; |
1627 return -EPERM; |
1617 |
1628 |
1618 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1629 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1619 return -EFAULT; |
1630 return -EFAULT; |
1620 } |
1631 } |
1621 |
1632 |
1622 sc = ecrt_master_slave_config_err(master, data.alias, data.position, |
1633 sc = ecrt_master_slave_config_err(master, data.alias, data.position, |
1623 data.vendor_id, data.product_code); |
1634 data.vendor_id, data.product_code); |
1635 data.config_index++; |
1646 data.config_index++; |
1636 } |
1647 } |
1637 |
1648 |
1638 up(&master->master_sem); |
1649 up(&master->master_sem); |
1639 |
1650 |
1640 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
1651 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
1641 return -EFAULT; |
1652 return -EFAULT; |
1642 |
1653 |
1643 return 0; |
1654 return 0; |
1644 } |
1655 } |
1645 |
1656 |
1744 |
1755 |
1745 ret = ecrt_master_activate(master); |
1756 ret = ecrt_master_activate(master); |
1746 if (ret < 0) |
1757 if (ret < 0) |
1747 return ret; |
1758 return ret; |
1748 |
1759 |
1749 if (copy_to_user((void __user *) arg, &io, |
1760 if (ec_copy_to_user((void __user *) arg, &io, |
1750 sizeof(ec_ioctl_master_activate_t))) |
1761 sizeof(ec_ioctl_master_activate_t))) |
1751 return -EFAULT; |
1762 return -EFAULT; |
1752 |
1763 |
1753 return 0; |
1764 return 0; |
1754 } |
1765 } |
1788 |
1799 |
1789 if (unlikely(!ctx->requested)) { |
1800 if (unlikely(!ctx->requested)) { |
1790 return -EPERM; |
1801 return -EPERM; |
1791 } |
1802 } |
1792 |
1803 |
1793 if (copy_from_user(&send_interval, (void __user *) arg, |
1804 if (ec_copy_from_user(&send_interval, (void __user *) arg, |
1794 sizeof(send_interval))) { |
1805 sizeof(send_interval))) { |
1795 return -EFAULT; |
1806 return -EFAULT; |
1796 } |
1807 } |
1797 |
1808 |
1798 if (down_interruptible(&master->master_sem)) |
1809 if (down_interruptible(&master->master_sem)) |
1858 { |
1869 { |
1859 ec_master_state_t data; |
1870 ec_master_state_t data; |
1860 |
1871 |
1861 ecrt_master_state(master, &data); |
1872 ecrt_master_state(master, &data); |
1862 |
1873 |
1863 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
1874 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
1864 return -EFAULT; |
1875 return -EFAULT; |
1865 |
1876 |
1866 return 0; |
1877 return 0; |
1867 } |
1878 } |
1868 |
1879 |
1880 { |
1891 { |
1881 ec_ioctl_link_state_t ioctl; |
1892 ec_ioctl_link_state_t ioctl; |
1882 ec_master_link_state_t state; |
1893 ec_master_link_state_t state; |
1883 int ret; |
1894 int ret; |
1884 |
1895 |
1885 if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) { |
1896 if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) { |
1886 return -EFAULT; |
1897 return -EFAULT; |
1887 } |
1898 } |
1888 |
1899 |
1889 ret = ecrt_master_link_state(master, ioctl.dev_idx, &state); |
1900 ret = ecrt_master_link_state(master, ioctl.dev_idx, &state); |
1890 if (ret < 0) { |
1901 if (ret < 0) { |
1891 return ret; |
1902 return ret; |
1892 } |
1903 } |
1893 |
1904 |
1894 if (copy_to_user((void __user *) ioctl.state, &state, sizeof(state))) { |
1905 if (ec_copy_to_user((void __user *) ioctl.state, &state, sizeof(state))) { |
1895 return -EFAULT; |
1906 return -EFAULT; |
1896 } |
1907 } |
1897 |
1908 |
1898 return 0; |
1909 return 0; |
1899 } |
1910 } |
1913 ec_ioctl_app_time_t data; |
1924 ec_ioctl_app_time_t data; |
1914 |
1925 |
1915 if (unlikely(!ctx->requested)) |
1926 if (unlikely(!ctx->requested)) |
1916 return -EPERM; |
1927 return -EPERM; |
1917 |
1928 |
1918 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1929 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
1919 return -EFAULT; |
1930 return -EFAULT; |
1920 } |
1931 } |
1921 |
1932 |
1922 ecrt_master_application_time(master, data.app_time); |
1933 ecrt_master_application_time(master, data.app_time); |
1923 return 0; |
1934 return 0; |
1985 ret = ecrt_master_reference_clock_time(master, &time); |
1996 ret = ecrt_master_reference_clock_time(master, &time); |
1986 if (ret) { |
1997 if (ret) { |
1987 return ret; |
1998 return ret; |
1988 } |
1999 } |
1989 |
2000 |
1990 if (copy_to_user((void __user *) arg, &time, sizeof(time))) { |
2001 if (ec_copy_to_user((void __user *) arg, &time, sizeof(time))) { |
1991 return -EFAULT; |
2002 return -EFAULT; |
1992 } |
2003 } |
1993 |
2004 |
1994 return 0; |
2005 return 0; |
1995 } |
2006 } |
2031 if (unlikely(!ctx->requested)) |
2042 if (unlikely(!ctx->requested)) |
2032 return -EPERM; |
2043 return -EPERM; |
2033 |
2044 |
2034 time_diff = ecrt_master_sync_monitor_process(master); |
2045 time_diff = ecrt_master_sync_monitor_process(master); |
2035 |
2046 |
2036 if (copy_to_user((void __user *) arg, &time_diff, sizeof(time_diff))) |
2047 if (ec_copy_to_user((void __user *) arg, &time_diff, sizeof(time_diff))) |
2037 return -EFAULT; |
2048 return -EFAULT; |
2038 |
2049 |
2039 return 0; |
2050 return 0; |
2040 } |
2051 } |
2041 |
2052 |
2077 if (unlikely(!ctx->requested)) { |
2088 if (unlikely(!ctx->requested)) { |
2078 ret = -EPERM; |
2089 ret = -EPERM; |
2079 goto out_return; |
2090 goto out_return; |
2080 } |
2091 } |
2081 |
2092 |
2082 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2093 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2083 ret = -EFAULT; |
2094 ret = -EFAULT; |
2084 goto out_return; |
2095 goto out_return; |
2085 } |
2096 } |
2086 |
2097 |
2087 if (down_interruptible(&master->master_sem)) { |
2098 if (down_interruptible(&master->master_sem)) { |
2129 if (unlikely(!ctx->requested)) { |
2140 if (unlikely(!ctx->requested)) { |
2130 ret = -EPERM; |
2141 ret = -EPERM; |
2131 goto out_return; |
2142 goto out_return; |
2132 } |
2143 } |
2133 |
2144 |
2134 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2145 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2135 ret = -EFAULT; |
2146 ret = -EFAULT; |
2136 goto out_return; |
2147 goto out_return; |
2137 } |
2148 } |
2138 |
2149 |
2139 if (down_interruptible(&master->master_sem)) { |
2150 if (down_interruptible(&master->master_sem)) { |
2171 ec_slave_config_t *sc; |
2182 ec_slave_config_t *sc; |
2172 |
2183 |
2173 if (unlikely(!ctx->requested)) |
2184 if (unlikely(!ctx->requested)) |
2174 return -EPERM; |
2185 return -EPERM; |
2175 |
2186 |
2176 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2187 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2177 return -EFAULT; |
2188 return -EFAULT; |
2178 |
2189 |
2179 if (down_interruptible(&master->master_sem)) |
2190 if (down_interruptible(&master->master_sem)) |
2180 return -EINTR; |
2191 return -EINTR; |
2181 |
2192 |
2205 ec_slave_config_t *sc; |
2216 ec_slave_config_t *sc; |
2206 |
2217 |
2207 if (unlikely(!ctx->requested)) |
2218 if (unlikely(!ctx->requested)) |
2208 return -EPERM; |
2219 return -EPERM; |
2209 |
2220 |
2210 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2221 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2211 return -EFAULT; |
2222 return -EFAULT; |
2212 |
2223 |
2213 if (down_interruptible(&master->master_sem)) |
2224 if (down_interruptible(&master->master_sem)) |
2214 return -EINTR; |
2225 return -EINTR; |
2215 |
2226 |
2240 ec_slave_config_t *sc; |
2251 ec_slave_config_t *sc; |
2241 |
2252 |
2242 if (unlikely(!ctx->requested)) |
2253 if (unlikely(!ctx->requested)) |
2243 return -EPERM; |
2254 return -EPERM; |
2244 |
2255 |
2245 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2256 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2246 return -EFAULT; |
2257 return -EFAULT; |
2247 |
2258 |
2248 if (down_interruptible(&master->master_sem)) |
2259 if (down_interruptible(&master->master_sem)) |
2249 return -EINTR; |
2260 return -EINTR; |
2250 |
2261 |
2275 ec_slave_config_t *sc; |
2286 ec_slave_config_t *sc; |
2276 |
2287 |
2277 if (unlikely(!ctx->requested)) |
2288 if (unlikely(!ctx->requested)) |
2278 return -EPERM; |
2289 return -EPERM; |
2279 |
2290 |
2280 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2291 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2281 return -EFAULT; |
2292 return -EFAULT; |
2282 |
2293 |
2283 if (down_interruptible(&master->master_sem)) |
2294 if (down_interruptible(&master->master_sem)) |
2284 return -EINTR; |
2295 return -EINTR; |
2285 |
2296 |
2312 int ret; |
2323 int ret; |
2313 |
2324 |
2314 if (unlikely(!ctx->requested)) |
2325 if (unlikely(!ctx->requested)) |
2315 return -EPERM; |
2326 return -EPERM; |
2316 |
2327 |
2317 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2328 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2318 return -EFAULT; |
2329 return -EFAULT; |
2319 |
2330 |
2320 if (down_interruptible(&master->master_sem)) |
2331 if (down_interruptible(&master->master_sem)) |
2321 return -EINTR; |
2332 return -EINTR; |
2322 |
2333 |
2333 up(&master->master_sem); /** \todo sc or domain could be invalidated */ |
2344 up(&master->master_sem); /** \todo sc or domain could be invalidated */ |
2334 |
2345 |
2335 ret = ecrt_slave_config_reg_pdo_entry(sc, data.entry_index, |
2346 ret = ecrt_slave_config_reg_pdo_entry(sc, data.entry_index, |
2336 data.entry_subindex, domain, &data.bit_position); |
2347 data.entry_subindex, domain, &data.bit_position); |
2337 |
2348 |
2338 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
2349 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
2339 return -EFAULT; |
2350 return -EFAULT; |
2340 |
2351 |
2341 return ret; |
2352 return ret; |
2342 } |
2353 } |
2343 |
2354 |
2360 |
2371 |
2361 if (unlikely(!ctx->requested)) { |
2372 if (unlikely(!ctx->requested)) { |
2362 return -EPERM; |
2373 return -EPERM; |
2363 } |
2374 } |
2364 |
2375 |
2365 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2376 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2366 return -EFAULT; |
2377 return -EFAULT; |
2367 } |
2378 } |
2368 |
2379 |
2369 if (down_interruptible(&master->master_sem)) { |
2380 if (down_interruptible(&master->master_sem)) { |
2370 return -EINTR; |
2381 return -EINTR; |
2383 up(&master->master_sem); /** \todo sc or domain could be invalidated */ |
2394 up(&master->master_sem); /** \todo sc or domain could be invalidated */ |
2384 |
2395 |
2385 ret = ecrt_slave_config_reg_pdo_entry_pos(sc, io.sync_index, |
2396 ret = ecrt_slave_config_reg_pdo_entry_pos(sc, io.sync_index, |
2386 io.pdo_pos, io.entry_pos, domain, &io.bit_position); |
2397 io.pdo_pos, io.entry_pos, domain, &io.bit_position); |
2387 |
2398 |
2388 if (copy_to_user((void __user *) arg, &io, sizeof(io))) |
2399 if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) |
2389 return -EFAULT; |
2400 return -EFAULT; |
2390 |
2401 |
2391 return ret; |
2402 return ret; |
2392 } |
2403 } |
2393 |
2404 |
2407 ec_slave_config_t *sc; |
2418 ec_slave_config_t *sc; |
2408 |
2419 |
2409 if (unlikely(!ctx->requested)) |
2420 if (unlikely(!ctx->requested)) |
2410 return -EPERM; |
2421 return -EPERM; |
2411 |
2422 |
2412 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2423 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2413 return -EFAULT; |
2424 return -EFAULT; |
2414 |
2425 |
2415 if (down_interruptible(&master->master_sem)) |
2426 if (down_interruptible(&master->master_sem)) |
2416 return -EINTR; |
2427 return -EINTR; |
2417 |
2428 |
2449 int ret; |
2460 int ret; |
2450 |
2461 |
2451 if (unlikely(!ctx->requested)) |
2462 if (unlikely(!ctx->requested)) |
2452 return -EPERM; |
2463 return -EPERM; |
2453 |
2464 |
2454 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2465 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
2455 return -EFAULT; |
2466 return -EFAULT; |
2456 |
2467 |
2457 if (!data.size) |
2468 if (!data.size) |
2458 return -EINVAL; |
2469 return -EINVAL; |
2459 |
2470 |
2460 if (!(sdo_data = kmalloc(data.size, GFP_KERNEL))) { |
2471 if (!(sdo_data = kmalloc(data.size, GFP_KERNEL))) { |
2461 return -ENOMEM; |
2472 return -ENOMEM; |
2462 } |
2473 } |
2463 |
2474 |
2464 if (copy_from_user(sdo_data, (void __user *) data.data, data.size)) { |
2475 if (ec_copy_from_user(sdo_data, (void __user *) data.data, data.size)) { |
2465 kfree(sdo_data); |
2476 kfree(sdo_data); |
2466 return -EFAULT; |
2477 return -EFAULT; |
2467 } |
2478 } |
2468 |
2479 |
2469 if (down_interruptible(&master->master_sem)) { |
2480 if (down_interruptible(&master->master_sem)) { |
2507 int ret; |
2518 int ret; |
2508 |
2519 |
2509 if (unlikely(!ctx->requested)) |
2520 if (unlikely(!ctx->requested)) |
2510 return -EPERM; |
2521 return -EPERM; |
2511 |
2522 |
2512 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) |
2523 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) |
2513 return -EFAULT; |
2524 return -EFAULT; |
2514 |
2525 |
2515 if (down_interruptible(&master->master_sem)) { |
2526 if (down_interruptible(&master->master_sem)) { |
2516 return -EINTR; |
2527 return -EINTR; |
2517 } |
2528 } |
2547 |
2558 |
2548 if (unlikely(!ctx->requested)) { |
2559 if (unlikely(!ctx->requested)) { |
2549 return -EPERM; |
2560 return -EPERM; |
2550 } |
2561 } |
2551 |
2562 |
2552 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2563 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2553 return -EFAULT; |
2564 return -EFAULT; |
2554 } |
2565 } |
2555 |
2566 |
2556 /* no locking of master_sem needed, because configuration will not be |
2567 /* no locking of master_sem needed, because configuration will not be |
2557 * deleted in the meantime. */ |
2568 * deleted in the meantime. */ |
2563 ret = ecrt_slave_config_emerg_pop(sc, msg); |
2574 ret = ecrt_slave_config_emerg_pop(sc, msg); |
2564 if (ret < 0) { |
2575 if (ret < 0) { |
2565 return ret; |
2576 return ret; |
2566 } |
2577 } |
2567 |
2578 |
2568 if (copy_to_user((void __user *) io.target, msg, sizeof(msg))) { |
2579 if (ec_copy_to_user((void __user *) io.target, msg, sizeof(msg))) { |
2569 return -EFAULT; |
2580 return -EFAULT; |
2570 } |
2581 } |
2571 |
2582 |
2572 return ret; |
2583 return ret; |
2573 } |
2584 } |
2589 |
2600 |
2590 if (unlikely(!ctx->requested)) { |
2601 if (unlikely(!ctx->requested)) { |
2591 return -EPERM; |
2602 return -EPERM; |
2592 } |
2603 } |
2593 |
2604 |
2594 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2605 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2595 return -EFAULT; |
2606 return -EFAULT; |
2596 } |
2607 } |
2597 |
2608 |
2598 /* no locking of master_sem needed, because configuration will not be |
2609 /* no locking of master_sem needed, because configuration will not be |
2599 * deleted in the meantime. */ |
2610 * deleted in the meantime. */ |
2623 |
2634 |
2624 if (unlikely(!ctx->requested)) { |
2635 if (unlikely(!ctx->requested)) { |
2625 return -EPERM; |
2636 return -EPERM; |
2626 } |
2637 } |
2627 |
2638 |
2628 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2639 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2629 return -EFAULT; |
2640 return -EFAULT; |
2630 } |
2641 } |
2631 |
2642 |
2632 /* no locking of master_sem needed, because configuration will not be |
2643 /* no locking of master_sem needed, because configuration will not be |
2633 * deleted in the meantime. */ |
2644 * deleted in the meantime. */ |
2641 return ret; |
2652 return ret; |
2642 } |
2653 } |
2643 |
2654 |
2644 io.overruns = ret; |
2655 io.overruns = ret; |
2645 |
2656 |
2646 if (copy_to_user((void __user *) arg, &io, sizeof(io))) { |
2657 if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) { |
2647 return -EFAULT; |
2658 return -EFAULT; |
2648 } |
2659 } |
2649 |
2660 |
2650 return 0; |
2661 return 0; |
2651 } |
2662 } |
2667 ec_sdo_request_t *req; |
2678 ec_sdo_request_t *req; |
2668 |
2679 |
2669 if (unlikely(!ctx->requested)) |
2680 if (unlikely(!ctx->requested)) |
2670 return -EPERM; |
2681 return -EPERM; |
2671 |
2682 |
2672 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2683 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2673 return -EFAULT; |
2684 return -EFAULT; |
2674 } |
2685 } |
2675 |
2686 |
2676 data.request_index = 0; |
2687 data.request_index = 0; |
2677 |
2688 |
2693 req = ecrt_slave_config_create_sdo_request_err(sc, data.sdo_index, |
2704 req = ecrt_slave_config_create_sdo_request_err(sc, data.sdo_index, |
2694 data.sdo_subindex, data.size); |
2705 data.sdo_subindex, data.size); |
2695 if (IS_ERR(req)) |
2706 if (IS_ERR(req)) |
2696 return PTR_ERR(req); |
2707 return PTR_ERR(req); |
2697 |
2708 |
2698 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
2709 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
2699 return -EFAULT; |
2710 return -EFAULT; |
2700 |
2711 |
2701 return 0; |
2712 return 0; |
2702 } |
2713 } |
2703 |
2714 |
2719 |
2730 |
2720 if (unlikely(!ctx->requested)) { |
2731 if (unlikely(!ctx->requested)) { |
2721 return -EPERM; |
2732 return -EPERM; |
2722 } |
2733 } |
2723 |
2734 |
2724 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2735 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
2725 return -EFAULT; |
2736 return -EFAULT; |
2726 } |
2737 } |
2727 |
2738 |
2728 io.request_index = 0; |
2739 io.request_index = 0; |
2729 |
2740 |
2746 reg = ecrt_slave_config_create_reg_request_err(sc, io.mem_size); |
2757 reg = ecrt_slave_config_create_reg_request_err(sc, io.mem_size); |
2747 if (IS_ERR(reg)) { |
2758 if (IS_ERR(reg)) { |
2748 return PTR_ERR(reg); |
2759 return PTR_ERR(reg); |
2749 } |
2760 } |
2750 |
2761 |
2751 if (copy_to_user((void __user *) arg, &io, sizeof(io))) { |
2762 if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) { |
2752 return -EFAULT; |
2763 return -EFAULT; |
2753 } |
2764 } |
2754 |
2765 |
2755 return 0; |
2766 return 0; |
2756 } |
2767 } |
2772 ec_voe_handler_t *voe; |
2783 ec_voe_handler_t *voe; |
2773 |
2784 |
2774 if (unlikely(!ctx->requested)) |
2785 if (unlikely(!ctx->requested)) |
2775 return -EPERM; |
2786 return -EPERM; |
2776 |
2787 |
2777 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2788 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2778 return -EFAULT; |
2789 return -EFAULT; |
2779 } |
2790 } |
2780 |
2791 |
2781 data.voe_index = 0; |
2792 data.voe_index = 0; |
2782 |
2793 |
2797 |
2808 |
2798 voe = ecrt_slave_config_create_voe_handler_err(sc, data.size); |
2809 voe = ecrt_slave_config_create_voe_handler_err(sc, data.size); |
2799 if (IS_ERR(voe)) |
2810 if (IS_ERR(voe)) |
2800 return PTR_ERR(voe); |
2811 return PTR_ERR(voe); |
2801 |
2812 |
2802 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
2813 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
2803 return -EFAULT; |
2814 return -EFAULT; |
2804 |
2815 |
2805 return 0; |
2816 return 0; |
2806 } |
2817 } |
2807 |
2818 |
2822 ec_slave_config_state_t state; |
2833 ec_slave_config_state_t state; |
2823 |
2834 |
2824 if (unlikely(!ctx->requested)) |
2835 if (unlikely(!ctx->requested)) |
2825 return -EPERM; |
2836 return -EPERM; |
2826 |
2837 |
2827 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2838 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
2828 return -EFAULT; |
2839 return -EFAULT; |
2829 } |
2840 } |
2830 |
2841 |
2831 /* no locking of master_sem needed, because sc will not be deleted in the |
2842 /* no locking of master_sem needed, because sc will not be deleted in the |
2832 * meantime. */ |
2843 * meantime. */ |
2835 return -ENOENT; |
2846 return -ENOENT; |
2836 } |
2847 } |
2837 |
2848 |
2838 ecrt_slave_config_state(sc, &state); |
2849 ecrt_slave_config_state(sc, &state); |
2839 |
2850 |
2840 if (copy_to_user((void __user *) data.state, &state, sizeof(state))) |
2851 if (ec_copy_to_user((void __user *) data.state, &state, sizeof(state))) |
2841 return -EFAULT; |
2852 return -EFAULT; |
2842 |
2853 |
2843 return 0; |
2854 return 0; |
2844 } |
2855 } |
2845 |
2856 |
2861 int ret; |
2872 int ret; |
2862 |
2873 |
2863 if (unlikely(!ctx->requested)) |
2874 if (unlikely(!ctx->requested)) |
2864 return -EPERM; |
2875 return -EPERM; |
2865 |
2876 |
2866 if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) |
2877 if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) |
2867 return -EFAULT; |
2878 return -EFAULT; |
2868 |
2879 |
2869 if (!ioctl.size) |
2880 if (!ioctl.size) |
2870 return -EINVAL; |
2881 return -EINVAL; |
2871 |
2882 |
2872 if (!(data = kmalloc(ioctl.size, GFP_KERNEL))) { |
2883 if (!(data = kmalloc(ioctl.size, GFP_KERNEL))) { |
2873 return -ENOMEM; |
2884 return -ENOMEM; |
2874 } |
2885 } |
2875 |
2886 |
2876 if (copy_from_user(data, (void __user *) ioctl.data, ioctl.size)) { |
2887 if (ec_copy_from_user(data, (void __user *) ioctl.data, ioctl.size)) { |
2877 kfree(data); |
2888 kfree(data); |
2878 return -EFAULT; |
2889 return -EFAULT; |
2879 } |
2890 } |
2880 |
2891 |
2881 if (down_interruptible(&master->master_sem)) { |
2892 if (down_interruptible(&master->master_sem)) { |
3038 ec_domain_state_t state; |
3049 ec_domain_state_t state; |
3039 |
3050 |
3040 if (unlikely(!ctx->requested)) |
3051 if (unlikely(!ctx->requested)) |
3041 return -EPERM; |
3052 return -EPERM; |
3042 |
3053 |
3043 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
3054 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) { |
3044 return -EFAULT; |
3055 return -EFAULT; |
3045 } |
3056 } |
3046 |
3057 |
3047 /* no locking of master_sem needed, because domain will not be deleted in |
3058 /* no locking of master_sem needed, because domain will not be deleted in |
3048 * the meantime. */ |
3059 * the meantime. */ |
3051 return -ENOENT; |
3062 return -ENOENT; |
3052 } |
3063 } |
3053 |
3064 |
3054 ecrt_domain_state(domain, &state); |
3065 ecrt_domain_state(domain, &state); |
3055 |
3066 |
3056 if (copy_to_user((void __user *) data.state, &state, sizeof(state))) |
3067 if (ec_copy_to_user((void __user *) data.state, &state, sizeof(state))) |
3057 return -EFAULT; |
3068 return -EFAULT; |
3058 |
3069 |
3059 return 0; |
3070 return 0; |
3060 } |
3071 } |
3061 |
3072 |
3076 ec_sdo_request_t *req; |
3087 ec_sdo_request_t *req; |
3077 |
3088 |
3078 if (unlikely(!ctx->requested)) |
3089 if (unlikely(!ctx->requested)) |
3079 return -EPERM; |
3090 return -EPERM; |
3080 |
3091 |
3081 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3092 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3082 return -EFAULT; |
3093 return -EFAULT; |
3083 |
3094 |
3084 /* no locking of master_sem needed, because neither sc nor req will not be |
3095 /* no locking of master_sem needed, because neither sc nor req will not be |
3085 * deleted in the meantime. */ |
3096 * deleted in the meantime. */ |
3086 |
3097 |
3113 ec_sdo_request_t *req; |
3124 ec_sdo_request_t *req; |
3114 |
3125 |
3115 if (unlikely(!ctx->requested)) |
3126 if (unlikely(!ctx->requested)) |
3116 return -EPERM; |
3127 return -EPERM; |
3117 |
3128 |
3118 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3129 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3119 return -EFAULT; |
3130 return -EFAULT; |
3120 |
3131 |
3121 /* no locking of master_sem needed, because neither sc nor req will not be |
3132 /* no locking of master_sem needed, because neither sc nor req will not be |
3122 * deleted in the meantime. */ |
3133 * deleted in the meantime. */ |
3123 |
3134 |
3150 ec_sdo_request_t *req; |
3161 ec_sdo_request_t *req; |
3151 |
3162 |
3152 if (unlikely(!ctx->requested)) |
3163 if (unlikely(!ctx->requested)) |
3153 return -EPERM; |
3164 return -EPERM; |
3154 |
3165 |
3155 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3166 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3156 return -EFAULT; |
3167 return -EFAULT; |
3157 |
3168 |
3158 /* no locking of master_sem needed, because neither sc nor req will not be |
3169 /* no locking of master_sem needed, because neither sc nor req will not be |
3159 * deleted in the meantime. */ |
3170 * deleted in the meantime. */ |
3160 |
3171 |
3170 if (data.state == EC_REQUEST_SUCCESS && req->dir == EC_DIR_INPUT) |
3181 if (data.state == EC_REQUEST_SUCCESS && req->dir == EC_DIR_INPUT) |
3171 data.size = ecrt_sdo_request_data_size(req); |
3182 data.size = ecrt_sdo_request_data_size(req); |
3172 else |
3183 else |
3173 data.size = 0; |
3184 data.size = 0; |
3174 |
3185 |
3175 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
3186 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
3176 return -EFAULT; |
3187 return -EFAULT; |
3177 |
3188 |
3178 return 0; |
3189 return 0; |
3179 } |
3190 } |
3180 |
3191 |
3195 ec_sdo_request_t *req; |
3206 ec_sdo_request_t *req; |
3196 |
3207 |
3197 if (unlikely(!ctx->requested)) |
3208 if (unlikely(!ctx->requested)) |
3198 return -EPERM; |
3209 return -EPERM; |
3199 |
3210 |
3200 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3211 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3201 return -EFAULT; |
3212 return -EFAULT; |
3202 |
3213 |
3203 /* no locking of master_sem needed, because neither sc nor req will not be |
3214 /* no locking of master_sem needed, because neither sc nor req will not be |
3204 * deleted in the meantime. */ |
3215 * deleted in the meantime. */ |
3205 |
3216 |
3233 int ret; |
3244 int ret; |
3234 |
3245 |
3235 if (unlikely(!ctx->requested)) |
3246 if (unlikely(!ctx->requested)) |
3236 return -EPERM; |
3247 return -EPERM; |
3237 |
3248 |
3238 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3249 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3239 return -EFAULT; |
3250 return -EFAULT; |
3240 |
3251 |
3241 if (!data.size) { |
3252 if (!data.size) { |
3242 EC_MASTER_ERR(master, "SDO download: Data size may not be zero!\n"); |
3253 EC_MASTER_ERR(master, "SDO download: Data size may not be zero!\n"); |
3243 return -EINVAL; |
3254 return -EINVAL; |
3256 |
3267 |
3257 ret = ec_sdo_request_alloc(req, data.size); |
3268 ret = ec_sdo_request_alloc(req, data.size); |
3258 if (ret) |
3269 if (ret) |
3259 return ret; |
3270 return ret; |
3260 |
3271 |
3261 if (copy_from_user(req->data, (void __user *) data.data, data.size)) |
3272 if (ec_copy_from_user(req->data, (void __user *) data.data, data.size)) |
3262 return -EFAULT; |
3273 return -EFAULT; |
3263 |
3274 |
3264 req->data_size = data.size; |
3275 req->data_size = data.size; |
3265 ecrt_sdo_request_write(req); |
3276 ecrt_sdo_request_write(req); |
3266 return 0; |
3277 return 0; |
3283 ec_sdo_request_t *req; |
3294 ec_sdo_request_t *req; |
3284 |
3295 |
3285 if (unlikely(!ctx->requested)) |
3296 if (unlikely(!ctx->requested)) |
3286 return -EPERM; |
3297 return -EPERM; |
3287 |
3298 |
3288 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3299 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3289 return -EFAULT; |
3300 return -EFAULT; |
3290 |
3301 |
3291 /* no locking of master_sem needed, because neither sc nor req will not be |
3302 /* no locking of master_sem needed, because neither sc nor req will not be |
3292 * deleted in the meantime. */ |
3303 * deleted in the meantime. */ |
3293 |
3304 |
3297 |
3308 |
3298 if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) { |
3309 if (!(req = ec_slave_config_find_sdo_request(sc, data.request_index))) { |
3299 return -ENOENT; |
3310 return -ENOENT; |
3300 } |
3311 } |
3301 |
3312 |
3302 if (copy_to_user((void __user *) data.data, ecrt_sdo_request_data(req), |
3313 if (ec_copy_to_user((void __user *) data.data, ecrt_sdo_request_data(req), |
3303 ecrt_sdo_request_data_size(req))) |
3314 ecrt_sdo_request_data_size(req))) |
3304 return -EFAULT; |
3315 return -EFAULT; |
3305 |
3316 |
3306 return 0; |
3317 return 0; |
3307 } |
3318 } |
3324 |
3335 |
3325 if (unlikely(!ctx->requested)) { |
3336 if (unlikely(!ctx->requested)) { |
3326 return -EPERM; |
3337 return -EPERM; |
3327 } |
3338 } |
3328 |
3339 |
3329 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3340 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3330 return -EFAULT; |
3341 return -EFAULT; |
3331 } |
3342 } |
3332 |
3343 |
3333 if (io.mem_size <= 0) { |
3344 if (io.mem_size <= 0) { |
3334 return 0; |
3345 return 0; |
3343 |
3354 |
3344 if (!(reg = ec_slave_config_find_reg_request(sc, io.request_index))) { |
3355 if (!(reg = ec_slave_config_find_reg_request(sc, io.request_index))) { |
3345 return -ENOENT; |
3356 return -ENOENT; |
3346 } |
3357 } |
3347 |
3358 |
3348 if (copy_to_user((void __user *) io.data, ecrt_reg_request_data(reg), |
3359 if (ec_copy_to_user((void __user *) io.data, ecrt_reg_request_data(reg), |
3349 min(reg->mem_size, io.mem_size))) { |
3360 min(reg->mem_size, io.mem_size))) { |
3350 return -EFAULT; |
3361 return -EFAULT; |
3351 } |
3362 } |
3352 |
3363 |
3353 return 0; |
3364 return 0; |
3371 |
3382 |
3372 if (unlikely(!ctx->requested)) { |
3383 if (unlikely(!ctx->requested)) { |
3373 return -EPERM; |
3384 return -EPERM; |
3374 } |
3385 } |
3375 |
3386 |
3376 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3387 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3377 return -EFAULT; |
3388 return -EFAULT; |
3378 } |
3389 } |
3379 |
3390 |
3380 /* no locking of master_sem needed, because neither sc nor reg will not be |
3391 /* no locking of master_sem needed, because neither sc nor reg will not be |
3381 * deleted in the meantime. */ |
3392 * deleted in the meantime. */ |
3389 } |
3400 } |
3390 |
3401 |
3391 io.state = ecrt_reg_request_state(reg); |
3402 io.state = ecrt_reg_request_state(reg); |
3392 io.new_data = io.state == EC_REQUEST_SUCCESS && reg->dir == EC_DIR_INPUT; |
3403 io.new_data = io.state == EC_REQUEST_SUCCESS && reg->dir == EC_DIR_INPUT; |
3393 |
3404 |
3394 if (copy_to_user((void __user *) arg, &io, sizeof(io))) { |
3405 if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) { |
3395 return -EFAULT; |
3406 return -EFAULT; |
3396 } |
3407 } |
3397 |
3408 |
3398 return 0; |
3409 return 0; |
3399 } |
3410 } |
3416 |
3427 |
3417 if (unlikely(!ctx->requested)) { |
3428 if (unlikely(!ctx->requested)) { |
3418 return -EPERM; |
3429 return -EPERM; |
3419 } |
3430 } |
3420 |
3431 |
3421 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3432 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3422 return -EFAULT; |
3433 return -EFAULT; |
3423 } |
3434 } |
3424 |
3435 |
3425 /* no locking of master_sem needed, because neither sc nor reg will not be |
3436 /* no locking of master_sem needed, because neither sc nor reg will not be |
3426 * deleted in the meantime. */ |
3437 * deleted in the meantime. */ |
3435 |
3446 |
3436 if (io.transfer_size > reg->mem_size) { |
3447 if (io.transfer_size > reg->mem_size) { |
3437 return -EOVERFLOW; |
3448 return -EOVERFLOW; |
3438 } |
3449 } |
3439 |
3450 |
3440 if (copy_from_user(reg->data, (void __user *) io.data, |
3451 if (ec_copy_from_user(reg->data, (void __user *) io.data, |
3441 io.transfer_size)) { |
3452 io.transfer_size)) { |
3442 return -EFAULT; |
3453 return -EFAULT; |
3443 } |
3454 } |
3444 |
3455 |
3445 ecrt_reg_request_write(reg, io.address, io.transfer_size); |
3456 ecrt_reg_request_write(reg, io.address, io.transfer_size); |
3464 |
3475 |
3465 if (unlikely(!ctx->requested)) { |
3476 if (unlikely(!ctx->requested)) { |
3466 return -EPERM; |
3477 return -EPERM; |
3467 } |
3478 } |
3468 |
3479 |
3469 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3480 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3470 return -EFAULT; |
3481 return -EFAULT; |
3471 } |
3482 } |
3472 |
3483 |
3473 /* no locking of master_sem needed, because neither sc nor reg will not be |
3484 /* no locking of master_sem needed, because neither sc nor reg will not be |
3474 * deleted in the meantime. */ |
3485 * deleted in the meantime. */ |
3508 uint16_t vendor_type; |
3519 uint16_t vendor_type; |
3509 |
3520 |
3510 if (unlikely(!ctx->requested)) |
3521 if (unlikely(!ctx->requested)) |
3511 return -EPERM; |
3522 return -EPERM; |
3512 |
3523 |
3513 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3524 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3514 return -EFAULT; |
3525 return -EFAULT; |
3515 |
3526 |
3516 if (get_user(vendor_id, data.vendor_id)) |
3527 if (get_user(vendor_id, data.vendor_id)) |
3517 return -EFAULT; |
3528 return -EFAULT; |
3518 |
3529 |
3553 uint16_t vendor_type; |
3564 uint16_t vendor_type; |
3554 |
3565 |
3555 if (unlikely(!ctx->requested)) |
3566 if (unlikely(!ctx->requested)) |
3556 return -EPERM; |
3567 return -EPERM; |
3557 |
3568 |
3558 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3569 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3559 return -EFAULT; |
3570 return -EFAULT; |
3560 |
3571 |
3561 /* no locking of master_sem needed, because neither sc nor voe will not be |
3572 /* no locking of master_sem needed, because neither sc nor voe will not be |
3562 * deleted in the meantime. */ |
3573 * deleted in the meantime. */ |
3563 |
3574 |
3599 ec_voe_handler_t *voe; |
3610 ec_voe_handler_t *voe; |
3600 |
3611 |
3601 if (unlikely(!ctx->requested)) |
3612 if (unlikely(!ctx->requested)) |
3602 return -EPERM; |
3613 return -EPERM; |
3603 |
3614 |
3604 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3615 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3605 return -EFAULT; |
3616 return -EFAULT; |
3606 |
3617 |
3607 /* no locking of master_sem needed, because neither sc nor voe will not be |
3618 /* no locking of master_sem needed, because neither sc nor voe will not be |
3608 * deleted in the meantime. */ |
3619 * deleted in the meantime. */ |
3609 |
3620 |
3636 ec_voe_handler_t *voe; |
3647 ec_voe_handler_t *voe; |
3637 |
3648 |
3638 if (unlikely(!ctx->requested)) |
3649 if (unlikely(!ctx->requested)) |
3639 return -EPERM; |
3650 return -EPERM; |
3640 |
3651 |
3641 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3652 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3642 return -EFAULT; |
3653 return -EFAULT; |
3643 |
3654 |
3644 /* no locking of master_sem needed, because neither sc nor voe will not be |
3655 /* no locking of master_sem needed, because neither sc nor voe will not be |
3645 * deleted in the meantime. */ |
3656 * deleted in the meantime. */ |
3646 |
3657 |
3673 ec_voe_handler_t *voe; |
3684 ec_voe_handler_t *voe; |
3674 |
3685 |
3675 if (unlikely(!ctx->requested)) |
3686 if (unlikely(!ctx->requested)) |
3676 return -EPERM; |
3687 return -EPERM; |
3677 |
3688 |
3678 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3689 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3679 return -EFAULT; |
3690 return -EFAULT; |
3680 |
3691 |
3681 /* no locking of master_sem needed, because neither sc nor voe will not be |
3692 /* no locking of master_sem needed, because neither sc nor voe will not be |
3682 * deleted in the meantime. */ |
3693 * deleted in the meantime. */ |
3683 |
3694 |
3691 |
3702 |
3692 if (data.size) { |
3703 if (data.size) { |
3693 if (data.size > ec_voe_handler_mem_size(voe)) |
3704 if (data.size > ec_voe_handler_mem_size(voe)) |
3694 return -EOVERFLOW; |
3705 return -EOVERFLOW; |
3695 |
3706 |
3696 if (copy_from_user(ecrt_voe_handler_data(voe), |
3707 if (ec_copy_from_user(ecrt_voe_handler_data(voe), |
3697 (void __user *) data.data, data.size)) |
3708 (void __user *) data.data, data.size)) |
3698 return -EFAULT; |
3709 return -EFAULT; |
3699 } |
3710 } |
3700 |
3711 |
3701 ecrt_voe_handler_write(voe, data.size); |
3712 ecrt_voe_handler_write(voe, data.size); |
3719 ec_voe_handler_t *voe; |
3730 ec_voe_handler_t *voe; |
3720 |
3731 |
3721 if (unlikely(!ctx->requested)) |
3732 if (unlikely(!ctx->requested)) |
3722 return -EPERM; |
3733 return -EPERM; |
3723 |
3734 |
3724 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3735 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3725 return -EFAULT; |
3736 return -EFAULT; |
3726 |
3737 |
3727 /* no locking of master_sem needed, because neither sc nor voe will not be |
3738 /* no locking of master_sem needed, because neither sc nor voe will not be |
3728 * deleted in the meantime. */ |
3739 * deleted in the meantime. */ |
3729 |
3740 |
3739 if (data.state == EC_REQUEST_SUCCESS && voe->dir == EC_DIR_INPUT) |
3750 if (data.state == EC_REQUEST_SUCCESS && voe->dir == EC_DIR_INPUT) |
3740 data.size = ecrt_voe_handler_data_size(voe); |
3751 data.size = ecrt_voe_handler_data_size(voe); |
3741 else |
3752 else |
3742 data.size = 0; |
3753 data.size = 0; |
3743 |
3754 |
3744 if (copy_to_user((void __user *) arg, &data, sizeof(data))) |
3755 if (ec_copy_to_user((void __user *) arg, &data, sizeof(data))) |
3745 return -EFAULT; |
3756 return -EFAULT; |
3746 |
3757 |
3747 return 0; |
3758 return 0; |
3748 } |
3759 } |
3749 |
3760 |
3764 ec_voe_handler_t *voe; |
3775 ec_voe_handler_t *voe; |
3765 |
3776 |
3766 if (unlikely(!ctx->requested)) |
3777 if (unlikely(!ctx->requested)) |
3767 return -EPERM; |
3778 return -EPERM; |
3768 |
3779 |
3769 if (copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3780 if (ec_copy_from_user(&data, (void __user *) arg, sizeof(data))) |
3770 return -EFAULT; |
3781 return -EFAULT; |
3771 |
3782 |
3772 /* no locking of master_sem needed, because neither sc nor voe will not be |
3783 /* no locking of master_sem needed, because neither sc nor voe will not be |
3773 * deleted in the meantime. */ |
3784 * deleted in the meantime. */ |
3774 |
3785 |
3778 |
3789 |
3779 if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) { |
3790 if (!(voe = ec_slave_config_find_voe_handler(sc, data.voe_index))) { |
3780 return -ENOENT; |
3791 return -ENOENT; |
3781 } |
3792 } |
3782 |
3793 |
3783 if (copy_to_user((void __user *) data.data, ecrt_voe_handler_data(voe), |
3794 if (ec_copy_to_user((void __user *) data.data, ecrt_voe_handler_data(voe), |
3784 ecrt_voe_handler_data_size(voe))) |
3795 ecrt_voe_handler_data_size(voe))) |
3785 return -EFAULT; |
3796 return -EFAULT; |
3786 |
3797 |
3787 return 0; |
3798 return 0; |
3788 } |
3799 } |
3801 ec_ioctl_slave_foe_t io; |
3812 ec_ioctl_slave_foe_t io; |
3802 ec_foe_request_t request; |
3813 ec_foe_request_t request; |
3803 ec_slave_t *slave; |
3814 ec_slave_t *slave; |
3804 int ret; |
3815 int ret; |
3805 |
3816 |
3806 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3817 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3807 return -EFAULT; |
3818 return -EFAULT; |
3808 } |
3819 } |
3809 |
3820 |
3810 ec_foe_request_init(&request, io.file_name); |
3821 ec_foe_request_init(&request, io.file_name); |
3811 ret = ec_foe_request_alloc(&request, 10000); // FIXME |
3822 ret = ec_foe_request_alloc(&request, 10000); // FIXME |
3865 EC_SLAVE_ERR(slave, "%s(): Buffer too small.\n", __func__); |
3876 EC_SLAVE_ERR(slave, "%s(): Buffer too small.\n", __func__); |
3866 ec_foe_request_clear(&request); |
3877 ec_foe_request_clear(&request); |
3867 return -EOVERFLOW; |
3878 return -EOVERFLOW; |
3868 } |
3879 } |
3869 io.data_size = request.data_size; |
3880 io.data_size = request.data_size; |
3870 if (copy_to_user((void __user *) io.buffer, |
3881 if (ec_copy_to_user((void __user *) io.buffer, |
3871 request.buffer, io.data_size)) { |
3882 request.buffer, io.data_size)) { |
3872 ec_foe_request_clear(&request); |
3883 ec_foe_request_clear(&request); |
3873 return -EFAULT; |
3884 return -EFAULT; |
3874 } |
3885 } |
3875 ret = 0; |
3886 ret = 0; |
3876 } |
3887 } |
3877 |
3888 |
3878 if (__copy_to_user((void __user *) arg, &io, sizeof(io))) { |
3889 if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) { |
3879 ret = -EFAULT; |
3890 ret = -EFAULT; |
3880 } |
3891 } |
3881 |
3892 |
3882 ec_foe_request_clear(&request); |
3893 ec_foe_request_clear(&request); |
3883 return ret; |
3894 return ret; |
3897 ec_ioctl_slave_foe_t io; |
3908 ec_ioctl_slave_foe_t io; |
3898 ec_foe_request_t request; |
3909 ec_foe_request_t request; |
3899 ec_slave_t *slave; |
3910 ec_slave_t *slave; |
3900 int ret; |
3911 int ret; |
3901 |
3912 |
3902 if (copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3913 if (ec_copy_from_user(&io, (void __user *) arg, sizeof(io))) { |
3903 return -EFAULT; |
3914 return -EFAULT; |
3904 } |
3915 } |
3905 |
3916 |
3906 ec_foe_request_init(&request, io.file_name); |
3917 ec_foe_request_init(&request, io.file_name); |
3907 |
3918 |
3909 if (ret) { |
3920 if (ret) { |
3910 ec_foe_request_clear(&request); |
3921 ec_foe_request_clear(&request); |
3911 return ret; |
3922 return ret; |
3912 } |
3923 } |
3913 |
3924 |
3914 if (copy_from_user(request.buffer, |
3925 if (ec_copy_from_user(request.buffer, |
3915 (void __user *) io.buffer, io.buffer_size)) { |
3926 (void __user *) io.buffer, io.buffer_size)) { |
3916 ec_foe_request_clear(&request); |
3927 ec_foe_request_clear(&request); |
3917 return -EFAULT; |
3928 return -EFAULT; |
3918 } |
3929 } |
3919 |
3930 |
3961 io.result = request.result; |
3972 io.result = request.result; |
3962 io.error_code = request.error_code; |
3973 io.error_code = request.error_code; |
3963 |
3974 |
3964 ret = request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO; |
3975 ret = request.state == EC_INT_REQUEST_SUCCESS ? 0 : -EIO; |
3965 |
3976 |
3966 if (__copy_to_user((void __user *) arg, &io, sizeof(io))) { |
3977 if (ec_copy_to_user((void __user *) arg, &io, sizeof(io))) { |
3967 ret = -EFAULT; |
3978 ret = -EFAULT; |
3968 } |
3979 } |
3969 |
3980 |
3970 ec_foe_request_clear(&request); |
3981 ec_foe_request_clear(&request); |
3971 return ret; |
3982 return ret; |
3984 { |
3995 { |
3985 ec_ioctl_slave_soe_read_t ioctl; |
3996 ec_ioctl_slave_soe_read_t ioctl; |
3986 u8 *data; |
3997 u8 *data; |
3987 int retval; |
3998 int retval; |
3988 |
3999 |
3989 if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) { |
4000 if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) { |
3990 return -EFAULT; |
4001 return -EFAULT; |
3991 } |
4002 } |
3992 |
4003 |
3993 data = kmalloc(ioctl.mem_size, GFP_KERNEL); |
4004 data = kmalloc(ioctl.mem_size, GFP_KERNEL); |
3994 if (!data) { |
4005 if (!data) { |
4003 if (retval) { |
4014 if (retval) { |
4004 kfree(data); |
4015 kfree(data); |
4005 return retval; |
4016 return retval; |
4006 } |
4017 } |
4007 |
4018 |
4008 if (copy_to_user((void __user *) ioctl.data, |
4019 if (ec_copy_to_user((void __user *) ioctl.data, |
4009 data, ioctl.data_size)) { |
4020 data, ioctl.data_size)) { |
4010 kfree(data); |
4021 kfree(data); |
4011 return -EFAULT; |
4022 return -EFAULT; |
4012 } |
4023 } |
4013 kfree(data); |
4024 kfree(data); |
4014 |
4025 |
4015 if (__copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) { |
4026 if (ec_copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) { |
4016 retval = -EFAULT; |
4027 retval = -EFAULT; |
4017 } |
4028 } |
4018 |
4029 |
4019 EC_MASTER_DBG(master, 1, "Finished SoE read request.\n"); |
4030 EC_MASTER_DBG(master, 1, "Finished SoE read request.\n"); |
4020 return retval; |
4031 return retval; |
4033 { |
4044 { |
4034 ec_ioctl_slave_soe_write_t ioctl; |
4045 ec_ioctl_slave_soe_write_t ioctl; |
4035 u8 *data; |
4046 u8 *data; |
4036 int retval; |
4047 int retval; |
4037 |
4048 |
4038 if (copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) { |
4049 if (ec_copy_from_user(&ioctl, (void __user *) arg, sizeof(ioctl))) { |
4039 return -EFAULT; |
4050 return -EFAULT; |
4040 } |
4051 } |
4041 |
4052 |
4042 data = kmalloc(ioctl.data_size, GFP_KERNEL); |
4053 data = kmalloc(ioctl.data_size, GFP_KERNEL); |
4043 if (!data) { |
4054 if (!data) { |
4044 EC_MASTER_ERR(master, "Failed to allocate %zu bytes of IDN data.\n", |
4055 EC_MASTER_ERR(master, "Failed to allocate %zu bytes of IDN data.\n", |
4045 ioctl.data_size); |
4056 ioctl.data_size); |
4046 return -ENOMEM; |
4057 return -ENOMEM; |
4047 } |
4058 } |
4048 if (copy_from_user(data, (void __user *) ioctl.data, ioctl.data_size)) { |
4059 if (ec_copy_from_user(data, (void __user *) ioctl.data, ioctl.data_size)) { |
4049 kfree(data); |
4060 kfree(data); |
4050 return -EFAULT; |
4061 return -EFAULT; |
4051 } |
4062 } |
4052 |
4063 |
4053 retval = ecrt_master_write_idn(master, ioctl.slave_position, |
4064 retval = ecrt_master_write_idn(master, ioctl.slave_position, |
4056 kfree(data); |
4067 kfree(data); |
4057 if (retval) { |
4068 if (retval) { |
4058 return retval; |
4069 return retval; |
4059 } |
4070 } |
4060 |
4071 |
4061 if (__copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) { |
4072 if (ec_copy_to_user((void __user *) arg, &ioctl, sizeof(ioctl))) { |
4062 retval = -EFAULT; |
4073 retval = -EFAULT; |
4063 } |
4074 } |
4064 |
4075 |
4065 EC_MASTER_DBG(master, 1, "Finished SoE write request.\n"); |
4076 EC_MASTER_DBG(master, 1, "Finished SoE write request.\n"); |
4066 return retval; |
4077 return retval; |