1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/init.h>
17#include <linux/export.h>
18#include <linux/mm.h>
19#include <linux/types.h>
20#include <linux/kernel.h>
21#include <linux/errno.h>
22#include <linux/pci.h>
23#include <linux/poll.h>
24#include <linux/highmem.h>
25#include <linux/interrupt.h>
26#include <linux/pagemap.h>
27#include <linux/device.h>
28#include <linux/dma-mapping.h>
29#include <linux/syscalls.h>
30#include <linux/mutex.h>
31#include <linux/spinlock.h>
32#include <linux/slab.h>
33#include <linux/vme.h>
34
35#include "vme_bridge.h"
36
37
38static unsigned int vme_bus_numbers;
39static LIST_HEAD(vme_bus_list);
40static DEFINE_MUTEX(vme_buses_lock);
41
42static int __init vme_init(void);
43
44static struct vme_dev *dev_to_vme_dev(struct device *dev)
45{
46 return container_of(dev, struct vme_dev, dev);
47}
48
49
50
51
52static struct vme_bridge *find_bridge(struct vme_resource *resource)
53{
54
55 switch (resource->type) {
56 case VME_MASTER:
57 return list_entry(resource->entry, struct vme_master_resource,
58 list)->parent;
59 break;
60 case VME_SLAVE:
61 return list_entry(resource->entry, struct vme_slave_resource,
62 list)->parent;
63 break;
64 case VME_DMA:
65 return list_entry(resource->entry, struct vme_dma_resource,
66 list)->parent;
67 break;
68 case VME_LM:
69 return list_entry(resource->entry, struct vme_lm_resource,
70 list)->parent;
71 break;
72 default:
73 printk(KERN_ERR "Unknown resource type\n");
74 return NULL;
75 break;
76 }
77}
78
79
80
81
82
83
84
85
86
87
88
89
90void *vme_alloc_consistent(struct vme_resource *resource, size_t size,
91 dma_addr_t *dma)
92{
93 struct vme_bridge *bridge;
94
95 if (!resource) {
96 printk(KERN_ERR "No resource\n");
97 return NULL;
98 }
99
100 bridge = find_bridge(resource);
101 if (!bridge) {
102 printk(KERN_ERR "Can't find bridge\n");
103 return NULL;
104 }
105
106 if (!bridge->parent) {
107 printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name);
108 return NULL;
109 }
110
111 if (!bridge->alloc_consistent) {
112 printk(KERN_ERR "alloc_consistent not supported by bridge %s\n",
113 bridge->name);
114 return NULL;
115 }
116
117 return bridge->alloc_consistent(bridge->parent, size, dma);
118}
119EXPORT_SYMBOL(vme_alloc_consistent);
120
121
122
123
124
125
126
127
128
129
130void vme_free_consistent(struct vme_resource *resource, size_t size,
131 void *vaddr, dma_addr_t dma)
132{
133 struct vme_bridge *bridge;
134
135 if (!resource) {
136 printk(KERN_ERR "No resource\n");
137 return;
138 }
139
140 bridge = find_bridge(resource);
141 if (!bridge) {
142 printk(KERN_ERR "Can't find bridge\n");
143 return;
144 }
145
146 if (!bridge->parent) {
147 printk(KERN_ERR "Dev entry NULL for bridge %s\n", bridge->name);
148 return;
149 }
150
151 if (!bridge->free_consistent) {
152 printk(KERN_ERR "free_consistent not supported by bridge %s\n",
153 bridge->name);
154 return;
155 }
156
157 bridge->free_consistent(bridge->parent, size, vaddr, dma);
158}
159EXPORT_SYMBOL(vme_free_consistent);
160
161
162
163
164
165
166
167
168
169
170
171size_t vme_get_size(struct vme_resource *resource)
172{
173 int enabled, retval;
174 unsigned long long base, size;
175 dma_addr_t buf_base;
176 u32 aspace, cycle, dwidth;
177
178 switch (resource->type) {
179 case VME_MASTER:
180 retval = vme_master_get(resource, &enabled, &base, &size,
181 &aspace, &cycle, &dwidth);
182 if (retval)
183 return 0;
184
185 return size;
186 break;
187 case VME_SLAVE:
188 retval = vme_slave_get(resource, &enabled, &base, &size,
189 &buf_base, &aspace, &cycle);
190 if (retval)
191 return 0;
192
193 return size;
194 break;
195 case VME_DMA:
196 return 0;
197 break;
198 default:
199 printk(KERN_ERR "Unknown resource type\n");
200 return 0;
201 break;
202 }
203}
204EXPORT_SYMBOL(vme_get_size);
205
206int vme_check_window(u32 aspace, unsigned long long vme_base,
207 unsigned long long size)
208{
209 int retval = 0;
210
211 if (vme_base + size < size)
212 return -EINVAL;
213
214 switch (aspace) {
215 case VME_A16:
216 if (vme_base + size > VME_A16_MAX)
217 retval = -EFAULT;
218 break;
219 case VME_A24:
220 if (vme_base + size > VME_A24_MAX)
221 retval = -EFAULT;
222 break;
223 case VME_A32:
224 if (vme_base + size > VME_A32_MAX)
225 retval = -EFAULT;
226 break;
227 case VME_A64:
228
229 break;
230 case VME_CRCSR:
231 if (vme_base + size > VME_CRCSR_MAX)
232 retval = -EFAULT;
233 break;
234 case VME_USER1:
235 case VME_USER2:
236 case VME_USER3:
237 case VME_USER4:
238
239 break;
240 default:
241 printk(KERN_ERR "Invalid address space\n");
242 retval = -EINVAL;
243 break;
244 }
245
246 return retval;
247}
248EXPORT_SYMBOL(vme_check_window);
249
250static u32 vme_get_aspace(int am)
251{
252 switch (am) {
253 case 0x29:
254 case 0x2D:
255 return VME_A16;
256 case 0x38:
257 case 0x39:
258 case 0x3A:
259 case 0x3B:
260 case 0x3C:
261 case 0x3D:
262 case 0x3E:
263 case 0x3F:
264 return VME_A24;
265 case 0x8:
266 case 0x9:
267 case 0xA:
268 case 0xB:
269 case 0xC:
270 case 0xD:
271 case 0xE:
272 case 0xF:
273 return VME_A32;
274 case 0x0:
275 case 0x1:
276 case 0x3:
277 return VME_A64;
278 }
279
280 return 0;
281}
282
283
284
285
286
287
288
289
290
291
292
293
294struct vme_resource *vme_slave_request(struct vme_dev *vdev, u32 address,
295 u32 cycle)
296{
297 struct vme_bridge *bridge;
298 struct list_head *slave_pos = NULL;
299 struct vme_slave_resource *allocated_image = NULL;
300 struct vme_slave_resource *slave_image = NULL;
301 struct vme_resource *resource = NULL;
302
303 bridge = vdev->bridge;
304 if (!bridge) {
305 printk(KERN_ERR "Can't find VME bus\n");
306 goto err_bus;
307 }
308
309
310 list_for_each(slave_pos, &bridge->slave_resources) {
311 slave_image = list_entry(slave_pos,
312 struct vme_slave_resource, list);
313
314 if (!slave_image) {
315 printk(KERN_ERR "Registered NULL Slave resource\n");
316 continue;
317 }
318
319
320 mutex_lock(&slave_image->mtx);
321 if (((slave_image->address_attr & address) == address) &&
322 ((slave_image->cycle_attr & cycle) == cycle) &&
323 (slave_image->locked == 0)) {
324
325 slave_image->locked = 1;
326 mutex_unlock(&slave_image->mtx);
327 allocated_image = slave_image;
328 break;
329 }
330 mutex_unlock(&slave_image->mtx);
331 }
332
333
334 if (!allocated_image)
335 goto err_image;
336
337 resource = kmalloc(sizeof(*resource), GFP_KERNEL);
338 if (!resource)
339 goto err_alloc;
340
341 resource->type = VME_SLAVE;
342 resource->entry = &allocated_image->list;
343
344 return resource;
345
346err_alloc:
347
348 mutex_lock(&slave_image->mtx);
349 slave_image->locked = 0;
350 mutex_unlock(&slave_image->mtx);
351err_image:
352err_bus:
353 return NULL;
354}
355EXPORT_SYMBOL(vme_slave_request);
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374int vme_slave_set(struct vme_resource *resource, int enabled,
375 unsigned long long vme_base, unsigned long long size,
376 dma_addr_t buf_base, u32 aspace, u32 cycle)
377{
378 struct vme_bridge *bridge = find_bridge(resource);
379 struct vme_slave_resource *image;
380 int retval;
381
382 if (resource->type != VME_SLAVE) {
383 printk(KERN_ERR "Not a slave resource\n");
384 return -EINVAL;
385 }
386
387 image = list_entry(resource->entry, struct vme_slave_resource, list);
388
389 if (!bridge->slave_set) {
390 printk(KERN_ERR "Function not supported\n");
391 return -ENOSYS;
392 }
393
394 if (!(((image->address_attr & aspace) == aspace) &&
395 ((image->cycle_attr & cycle) == cycle))) {
396 printk(KERN_ERR "Invalid attributes\n");
397 return -EINVAL;
398 }
399
400 retval = vme_check_window(aspace, vme_base, size);
401 if (retval)
402 return retval;
403
404 return bridge->slave_set(image, enabled, vme_base, size, buf_base,
405 aspace, cycle);
406}
407EXPORT_SYMBOL(vme_slave_set);
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424int vme_slave_get(struct vme_resource *resource, int *enabled,
425 unsigned long long *vme_base, unsigned long long *size,
426 dma_addr_t *buf_base, u32 *aspace, u32 *cycle)
427{
428 struct vme_bridge *bridge = find_bridge(resource);
429 struct vme_slave_resource *image;
430
431 if (resource->type != VME_SLAVE) {
432 printk(KERN_ERR "Not a slave resource\n");
433 return -EINVAL;
434 }
435
436 image = list_entry(resource->entry, struct vme_slave_resource, list);
437
438 if (!bridge->slave_get) {
439 printk(KERN_ERR "vme_slave_get not supported\n");
440 return -EINVAL;
441 }
442
443 return bridge->slave_get(image, enabled, vme_base, size, buf_base,
444 aspace, cycle);
445}
446EXPORT_SYMBOL(vme_slave_get);
447
448
449
450
451
452
453
454void vme_slave_free(struct vme_resource *resource)
455{
456 struct vme_slave_resource *slave_image;
457
458 if (resource->type != VME_SLAVE) {
459 printk(KERN_ERR "Not a slave resource\n");
460 return;
461 }
462
463 slave_image = list_entry(resource->entry, struct vme_slave_resource,
464 list);
465 if (!slave_image) {
466 printk(KERN_ERR "Can't find slave resource\n");
467 return;
468 }
469
470
471 mutex_lock(&slave_image->mtx);
472 if (slave_image->locked == 0)
473 printk(KERN_ERR "Image is already free\n");
474
475 slave_image->locked = 0;
476 mutex_unlock(&slave_image->mtx);
477
478
479 kfree(resource);
480}
481EXPORT_SYMBOL(vme_slave_free);
482
483
484
485
486
487
488
489
490
491
492
493
494
495struct vme_resource *vme_master_request(struct vme_dev *vdev, u32 address,
496 u32 cycle, u32 dwidth)
497{
498 struct vme_bridge *bridge;
499 struct list_head *master_pos = NULL;
500 struct vme_master_resource *allocated_image = NULL;
501 struct vme_master_resource *master_image = NULL;
502 struct vme_resource *resource = NULL;
503
504 bridge = vdev->bridge;
505 if (!bridge) {
506 printk(KERN_ERR "Can't find VME bus\n");
507 goto err_bus;
508 }
509
510
511 list_for_each(master_pos, &bridge->master_resources) {
512 master_image = list_entry(master_pos,
513 struct vme_master_resource, list);
514
515 if (!master_image) {
516 printk(KERN_WARNING "Registered NULL master resource\n");
517 continue;
518 }
519
520
521 spin_lock(&master_image->lock);
522 if (((master_image->address_attr & address) == address) &&
523 ((master_image->cycle_attr & cycle) == cycle) &&
524 ((master_image->width_attr & dwidth) == dwidth) &&
525 (master_image->locked == 0)) {
526
527 master_image->locked = 1;
528 spin_unlock(&master_image->lock);
529 allocated_image = master_image;
530 break;
531 }
532 spin_unlock(&master_image->lock);
533 }
534
535
536 if (!allocated_image) {
537 printk(KERN_ERR "Can't find a suitable resource\n");
538 goto err_image;
539 }
540
541 resource = kmalloc(sizeof(*resource), GFP_KERNEL);
542 if (!resource)
543 goto err_alloc;
544
545 resource->type = VME_MASTER;
546 resource->entry = &allocated_image->list;
547
548 return resource;
549
550err_alloc:
551
552 spin_lock(&master_image->lock);
553 master_image->locked = 0;
554 spin_unlock(&master_image->lock);
555err_image:
556err_bus:
557 return NULL;
558}
559EXPORT_SYMBOL(vme_master_request);
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578int vme_master_set(struct vme_resource *resource, int enabled,
579 unsigned long long vme_base, unsigned long long size, u32 aspace,
580 u32 cycle, u32 dwidth)
581{
582 struct vme_bridge *bridge = find_bridge(resource);
583 struct vme_master_resource *image;
584 int retval;
585
586 if (resource->type != VME_MASTER) {
587 printk(KERN_ERR "Not a master resource\n");
588 return -EINVAL;
589 }
590
591 image = list_entry(resource->entry, struct vme_master_resource, list);
592
593 if (!bridge->master_set) {
594 printk(KERN_WARNING "vme_master_set not supported\n");
595 return -EINVAL;
596 }
597
598 if (!(((image->address_attr & aspace) == aspace) &&
599 ((image->cycle_attr & cycle) == cycle) &&
600 ((image->width_attr & dwidth) == dwidth))) {
601 printk(KERN_WARNING "Invalid attributes\n");
602 return -EINVAL;
603 }
604
605 retval = vme_check_window(aspace, vme_base, size);
606 if (retval)
607 return retval;
608
609 return bridge->master_set(image, enabled, vme_base, size, aspace,
610 cycle, dwidth);
611}
612EXPORT_SYMBOL(vme_master_set);
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629int vme_master_get(struct vme_resource *resource, int *enabled,
630 unsigned long long *vme_base, unsigned long long *size, u32 *aspace,
631 u32 *cycle, u32 *dwidth)
632{
633 struct vme_bridge *bridge = find_bridge(resource);
634 struct vme_master_resource *image;
635
636 if (resource->type != VME_MASTER) {
637 printk(KERN_ERR "Not a master resource\n");
638 return -EINVAL;
639 }
640
641 image = list_entry(resource->entry, struct vme_master_resource, list);
642
643 if (!bridge->master_get) {
644 printk(KERN_WARNING "%s not supported\n", __func__);
645 return -EINVAL;
646 }
647
648 return bridge->master_get(image, enabled, vme_base, size, aspace,
649 cycle, dwidth);
650}
651EXPORT_SYMBOL(vme_master_get);
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668ssize_t vme_master_read(struct vme_resource *resource, void *buf, size_t count,
669 loff_t offset)
670{
671 struct vme_bridge *bridge = find_bridge(resource);
672 struct vme_master_resource *image;
673 size_t length;
674
675 if (!bridge->master_read) {
676 printk(KERN_WARNING "Reading from resource not supported\n");
677 return -EINVAL;
678 }
679
680 if (resource->type != VME_MASTER) {
681 printk(KERN_ERR "Not a master resource\n");
682 return -EINVAL;
683 }
684
685 image = list_entry(resource->entry, struct vme_master_resource, list);
686
687 length = vme_get_size(resource);
688
689 if (offset > length) {
690 printk(KERN_WARNING "Invalid Offset\n");
691 return -EFAULT;
692 }
693
694 if ((offset + count) > length)
695 count = length - offset;
696
697 return bridge->master_read(image, buf, count, offset);
698
699}
700EXPORT_SYMBOL(vme_master_read);
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717ssize_t vme_master_write(struct vme_resource *resource, void *buf,
718 size_t count, loff_t offset)
719{
720 struct vme_bridge *bridge = find_bridge(resource);
721 struct vme_master_resource *image;
722 size_t length;
723
724 if (!bridge->master_write) {
725 printk(KERN_WARNING "Writing to resource not supported\n");
726 return -EINVAL;
727 }
728
729 if (resource->type != VME_MASTER) {
730 printk(KERN_ERR "Not a master resource\n");
731 return -EINVAL;
732 }
733
734 image = list_entry(resource->entry, struct vme_master_resource, list);
735
736 length = vme_get_size(resource);
737
738 if (offset > length) {
739 printk(KERN_WARNING "Invalid Offset\n");
740 return -EFAULT;
741 }
742
743 if ((offset + count) > length)
744 count = length - offset;
745
746 return bridge->master_write(image, buf, count, offset);
747}
748EXPORT_SYMBOL(vme_master_write);
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769unsigned int vme_master_rmw(struct vme_resource *resource, unsigned int mask,
770 unsigned int compare, unsigned int swap, loff_t offset)
771{
772 struct vme_bridge *bridge = find_bridge(resource);
773 struct vme_master_resource *image;
774
775 if (!bridge->master_rmw) {
776 printk(KERN_WARNING "Writing to resource not supported\n");
777 return -EINVAL;
778 }
779
780 if (resource->type != VME_MASTER) {
781 printk(KERN_ERR "Not a master resource\n");
782 return -EINVAL;
783 }
784
785 image = list_entry(resource->entry, struct vme_master_resource, list);
786
787 return bridge->master_rmw(image, mask, compare, swap, offset);
788}
789EXPORT_SYMBOL(vme_master_rmw);
790
791
792
793
794
795
796
797
798
799
800
801
802int vme_master_mmap(struct vme_resource *resource, struct vm_area_struct *vma)
803{
804 struct vme_master_resource *image;
805 phys_addr_t phys_addr;
806 unsigned long vma_size;
807
808 if (resource->type != VME_MASTER) {
809 pr_err("Not a master resource\n");
810 return -EINVAL;
811 }
812
813 image = list_entry(resource->entry, struct vme_master_resource, list);
814 phys_addr = image->bus_resource.start + (vma->vm_pgoff << PAGE_SHIFT);
815 vma_size = vma->vm_end - vma->vm_start;
816
817 if (phys_addr + vma_size > image->bus_resource.end + 1) {
818 pr_err("Map size cannot exceed the window size\n");
819 return -EFAULT;
820 }
821
822 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
823
824 return vm_iomap_memory(vma, phys_addr, vma->vm_end - vma->vm_start);
825}
826EXPORT_SYMBOL(vme_master_mmap);
827
828
829
830
831
832
833
834void vme_master_free(struct vme_resource *resource)
835{
836 struct vme_master_resource *master_image;
837
838 if (resource->type != VME_MASTER) {
839 printk(KERN_ERR "Not a master resource\n");
840 return;
841 }
842
843 master_image = list_entry(resource->entry, struct vme_master_resource,
844 list);
845 if (!master_image) {
846 printk(KERN_ERR "Can't find master resource\n");
847 return;
848 }
849
850
851 spin_lock(&master_image->lock);
852 if (master_image->locked == 0)
853 printk(KERN_ERR "Image is already free\n");
854
855 master_image->locked = 0;
856 spin_unlock(&master_image->lock);
857
858
859 kfree(resource);
860}
861EXPORT_SYMBOL(vme_master_free);
862
863
864
865
866
867
868
869
870
871
872
873struct vme_resource *vme_dma_request(struct vme_dev *vdev, u32 route)
874{
875 struct vme_bridge *bridge;
876 struct list_head *dma_pos = NULL;
877 struct vme_dma_resource *allocated_ctrlr = NULL;
878 struct vme_dma_resource *dma_ctrlr = NULL;
879 struct vme_resource *resource = NULL;
880
881
882 printk(KERN_ERR "No VME resource Attribute tests done\n");
883
884 bridge = vdev->bridge;
885 if (!bridge) {
886 printk(KERN_ERR "Can't find VME bus\n");
887 goto err_bus;
888 }
889
890
891 list_for_each(dma_pos, &bridge->dma_resources) {
892 dma_ctrlr = list_entry(dma_pos,
893 struct vme_dma_resource, list);
894 if (!dma_ctrlr) {
895 printk(KERN_ERR "Registered NULL DMA resource\n");
896 continue;
897 }
898
899
900 mutex_lock(&dma_ctrlr->mtx);
901 if (((dma_ctrlr->route_attr & route) == route) &&
902 (dma_ctrlr->locked == 0)) {
903
904 dma_ctrlr->locked = 1;
905 mutex_unlock(&dma_ctrlr->mtx);
906 allocated_ctrlr = dma_ctrlr;
907 break;
908 }
909 mutex_unlock(&dma_ctrlr->mtx);
910 }
911
912
913 if (!allocated_ctrlr)
914 goto err_ctrlr;
915
916 resource = kmalloc(sizeof(*resource), GFP_KERNEL);
917 if (!resource)
918 goto err_alloc;
919
920 resource->type = VME_DMA;
921 resource->entry = &allocated_ctrlr->list;
922
923 return resource;
924
925err_alloc:
926
927 mutex_lock(&dma_ctrlr->mtx);
928 dma_ctrlr->locked = 0;
929 mutex_unlock(&dma_ctrlr->mtx);
930err_ctrlr:
931err_bus:
932 return NULL;
933}
934EXPORT_SYMBOL(vme_dma_request);
935
936
937
938
939
940
941
942
943
944
945
946struct vme_dma_list *vme_new_dma_list(struct vme_resource *resource)
947{
948 struct vme_dma_list *dma_list;
949
950 if (resource->type != VME_DMA) {
951 printk(KERN_ERR "Not a DMA resource\n");
952 return NULL;
953 }
954
955 dma_list = kmalloc(sizeof(*dma_list), GFP_KERNEL);
956 if (!dma_list)
957 return NULL;
958
959 INIT_LIST_HEAD(&dma_list->entries);
960 dma_list->parent = list_entry(resource->entry,
961 struct vme_dma_resource,
962 list);
963 mutex_init(&dma_list->mtx);
964
965 return dma_list;
966}
967EXPORT_SYMBOL(vme_new_dma_list);
968
969
970
971
972
973
974
975
976
977
978
979
980struct vme_dma_attr *vme_dma_pattern_attribute(u32 pattern, u32 type)
981{
982 struct vme_dma_attr *attributes;
983 struct vme_dma_pattern *pattern_attr;
984
985 attributes = kmalloc(sizeof(*attributes), GFP_KERNEL);
986 if (!attributes)
987 goto err_attr;
988
989 pattern_attr = kmalloc(sizeof(*pattern_attr), GFP_KERNEL);
990 if (!pattern_attr)
991 goto err_pat;
992
993 attributes->type = VME_DMA_PATTERN;
994 attributes->private = (void *)pattern_attr;
995
996 pattern_attr->pattern = pattern;
997 pattern_attr->type = type;
998
999 return attributes;
1000
1001err_pat:
1002 kfree(attributes);
1003err_attr:
1004 return NULL;
1005}
1006EXPORT_SYMBOL(vme_dma_pattern_attribute);
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018struct vme_dma_attr *vme_dma_pci_attribute(dma_addr_t address)
1019{
1020 struct vme_dma_attr *attributes;
1021 struct vme_dma_pci *pci_attr;
1022
1023
1024
1025 attributes = kmalloc(sizeof(*attributes), GFP_KERNEL);
1026 if (!attributes)
1027 goto err_attr;
1028
1029 pci_attr = kmalloc(sizeof(*pci_attr), GFP_KERNEL);
1030 if (!pci_attr)
1031 goto err_pci;
1032
1033 attributes->type = VME_DMA_PCI;
1034 attributes->private = (void *)pci_attr;
1035
1036 pci_attr->address = address;
1037
1038 return attributes;
1039
1040err_pci:
1041 kfree(attributes);
1042err_attr:
1043 return NULL;
1044}
1045EXPORT_SYMBOL(vme_dma_pci_attribute);
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060struct vme_dma_attr *vme_dma_vme_attribute(unsigned long long address,
1061 u32 aspace, u32 cycle, u32 dwidth)
1062{
1063 struct vme_dma_attr *attributes;
1064 struct vme_dma_vme *vme_attr;
1065
1066 attributes = kmalloc(sizeof(*attributes), GFP_KERNEL);
1067 if (!attributes)
1068 goto err_attr;
1069
1070 vme_attr = kmalloc(sizeof(*vme_attr), GFP_KERNEL);
1071 if (!vme_attr)
1072 goto err_vme;
1073
1074 attributes->type = VME_DMA_VME;
1075 attributes->private = (void *)vme_attr;
1076
1077 vme_attr->address = address;
1078 vme_attr->aspace = aspace;
1079 vme_attr->cycle = cycle;
1080 vme_attr->dwidth = dwidth;
1081
1082 return attributes;
1083
1084err_vme:
1085 kfree(attributes);
1086err_attr:
1087 return NULL;
1088}
1089EXPORT_SYMBOL(vme_dma_vme_attribute);
1090
1091
1092
1093
1094
1095
1096
1097
1098void vme_dma_free_attribute(struct vme_dma_attr *attributes)
1099{
1100 kfree(attributes->private);
1101 kfree(attributes);
1102}
1103EXPORT_SYMBOL(vme_dma_free_attribute);
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122int vme_dma_list_add(struct vme_dma_list *list, struct vme_dma_attr *src,
1123 struct vme_dma_attr *dest, size_t count)
1124{
1125 struct vme_bridge *bridge = list->parent->parent;
1126 int retval;
1127
1128 if (!bridge->dma_list_add) {
1129 printk(KERN_WARNING "Link List DMA generation not supported\n");
1130 return -EINVAL;
1131 }
1132
1133 if (!mutex_trylock(&list->mtx)) {
1134 printk(KERN_ERR "Link List already submitted\n");
1135 return -EINVAL;
1136 }
1137
1138 retval = bridge->dma_list_add(list, src, dest, count);
1139
1140 mutex_unlock(&list->mtx);
1141
1142 return retval;
1143}
1144EXPORT_SYMBOL(vme_dma_list_add);
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156int vme_dma_list_exec(struct vme_dma_list *list)
1157{
1158 struct vme_bridge *bridge = list->parent->parent;
1159 int retval;
1160
1161 if (!bridge->dma_list_exec) {
1162 printk(KERN_ERR "Link List DMA execution not supported\n");
1163 return -EINVAL;
1164 }
1165
1166 mutex_lock(&list->mtx);
1167
1168 retval = bridge->dma_list_exec(list);
1169
1170 mutex_unlock(&list->mtx);
1171
1172 return retval;
1173}
1174EXPORT_SYMBOL(vme_dma_list_exec);
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185int vme_dma_list_free(struct vme_dma_list *list)
1186{
1187 struct vme_bridge *bridge = list->parent->parent;
1188 int retval;
1189
1190 if (!bridge->dma_list_empty) {
1191 printk(KERN_WARNING "Emptying of Link Lists not supported\n");
1192 return -EINVAL;
1193 }
1194
1195 if (!mutex_trylock(&list->mtx)) {
1196 printk(KERN_ERR "Link List in use\n");
1197 return -EBUSY;
1198 }
1199
1200
1201
1202
1203
1204 retval = bridge->dma_list_empty(list);
1205 if (retval) {
1206 printk(KERN_ERR "Unable to empty link-list entries\n");
1207 mutex_unlock(&list->mtx);
1208 return retval;
1209 }
1210 mutex_unlock(&list->mtx);
1211 kfree(list);
1212
1213 return retval;
1214}
1215EXPORT_SYMBOL(vme_dma_list_free);
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226int vme_dma_free(struct vme_resource *resource)
1227{
1228 struct vme_dma_resource *ctrlr;
1229
1230 if (resource->type != VME_DMA) {
1231 printk(KERN_ERR "Not a DMA resource\n");
1232 return -EINVAL;
1233 }
1234
1235 ctrlr = list_entry(resource->entry, struct vme_dma_resource, list);
1236
1237 if (!mutex_trylock(&ctrlr->mtx)) {
1238 printk(KERN_ERR "Resource busy, can't free\n");
1239 return -EBUSY;
1240 }
1241
1242 if (!(list_empty(&ctrlr->pending) && list_empty(&ctrlr->running))) {
1243 printk(KERN_WARNING "Resource still processing transfers\n");
1244 mutex_unlock(&ctrlr->mtx);
1245 return -EBUSY;
1246 }
1247
1248 ctrlr->locked = 0;
1249
1250 mutex_unlock(&ctrlr->mtx);
1251
1252 kfree(resource);
1253
1254 return 0;
1255}
1256EXPORT_SYMBOL(vme_dma_free);
1257
1258void vme_bus_error_handler(struct vme_bridge *bridge,
1259 unsigned long long address, int am)
1260{
1261 struct list_head *handler_pos = NULL;
1262 struct vme_error_handler *handler;
1263 int handler_triggered = 0;
1264 u32 aspace = vme_get_aspace(am);
1265
1266 list_for_each(handler_pos, &bridge->vme_error_handlers) {
1267 handler = list_entry(handler_pos, struct vme_error_handler,
1268 list);
1269 if ((aspace == handler->aspace) &&
1270 (address >= handler->start) &&
1271 (address < handler->end)) {
1272 if (!handler->num_errors)
1273 handler->first_error = address;
1274 if (handler->num_errors != UINT_MAX)
1275 handler->num_errors++;
1276 handler_triggered = 1;
1277 }
1278 }
1279
1280 if (!handler_triggered)
1281 dev_err(bridge->parent,
1282 "Unhandled VME access error at address 0x%llx\n",
1283 address);
1284}
1285EXPORT_SYMBOL(vme_bus_error_handler);
1286
1287struct vme_error_handler *vme_register_error_handler(
1288 struct vme_bridge *bridge, u32 aspace,
1289 unsigned long long address, size_t len)
1290{
1291 struct vme_error_handler *handler;
1292
1293 handler = kmalloc(sizeof(*handler), GFP_ATOMIC);
1294 if (!handler)
1295 return NULL;
1296
1297 handler->aspace = aspace;
1298 handler->start = address;
1299 handler->end = address + len;
1300 handler->num_errors = 0;
1301 handler->first_error = 0;
1302 list_add_tail(&handler->list, &bridge->vme_error_handlers);
1303
1304 return handler;
1305}
1306EXPORT_SYMBOL(vme_register_error_handler);
1307
1308void vme_unregister_error_handler(struct vme_error_handler *handler)
1309{
1310 list_del(&handler->list);
1311 kfree(handler);
1312}
1313EXPORT_SYMBOL(vme_unregister_error_handler);
1314
1315void vme_irq_handler(struct vme_bridge *bridge, int level, int statid)
1316{
1317 void (*call)(int, int, void *);
1318 void *priv_data;
1319
1320 call = bridge->irq[level - 1].callback[statid].func;
1321 priv_data = bridge->irq[level - 1].callback[statid].priv_data;
1322 if (call)
1323 call(level, statid, priv_data);
1324 else
1325 printk(KERN_WARNING "Spurious VME interrupt, level:%x, vector:%x\n",
1326 level, statid);
1327}
1328EXPORT_SYMBOL(vme_irq_handler);
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346int vme_irq_request(struct vme_dev *vdev, int level, int statid,
1347 void (*callback)(int, int, void *),
1348 void *priv_data)
1349{
1350 struct vme_bridge *bridge;
1351
1352 bridge = vdev->bridge;
1353 if (!bridge) {
1354 printk(KERN_ERR "Can't find VME bus\n");
1355 return -EINVAL;
1356 }
1357
1358 if ((level < 1) || (level > 7)) {
1359 printk(KERN_ERR "Invalid interrupt level\n");
1360 return -EINVAL;
1361 }
1362
1363 if (!bridge->irq_set) {
1364 printk(KERN_ERR "Configuring interrupts not supported\n");
1365 return -EINVAL;
1366 }
1367
1368 mutex_lock(&bridge->irq_mtx);
1369
1370 if (bridge->irq[level - 1].callback[statid].func) {
1371 mutex_unlock(&bridge->irq_mtx);
1372 printk(KERN_WARNING "VME Interrupt already taken\n");
1373 return -EBUSY;
1374 }
1375
1376 bridge->irq[level - 1].count++;
1377 bridge->irq[level - 1].callback[statid].priv_data = priv_data;
1378 bridge->irq[level - 1].callback[statid].func = callback;
1379
1380
1381 bridge->irq_set(bridge, level, 1, 1);
1382
1383 mutex_unlock(&bridge->irq_mtx);
1384
1385 return 0;
1386}
1387EXPORT_SYMBOL(vme_irq_request);
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397void vme_irq_free(struct vme_dev *vdev, int level, int statid)
1398{
1399 struct vme_bridge *bridge;
1400
1401 bridge = vdev->bridge;
1402 if (!bridge) {
1403 printk(KERN_ERR "Can't find VME bus\n");
1404 return;
1405 }
1406
1407 if ((level < 1) || (level > 7)) {
1408 printk(KERN_ERR "Invalid interrupt level\n");
1409 return;
1410 }
1411
1412 if (!bridge->irq_set) {
1413 printk(KERN_ERR "Configuring interrupts not supported\n");
1414 return;
1415 }
1416
1417 mutex_lock(&bridge->irq_mtx);
1418
1419 bridge->irq[level - 1].count--;
1420
1421
1422 if (bridge->irq[level - 1].count == 0)
1423 bridge->irq_set(bridge, level, 0, 1);
1424
1425 bridge->irq[level - 1].callback[statid].func = NULL;
1426 bridge->irq[level - 1].callback[statid].priv_data = NULL;
1427
1428 mutex_unlock(&bridge->irq_mtx);
1429}
1430EXPORT_SYMBOL(vme_irq_free);
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444int vme_irq_generate(struct vme_dev *vdev, int level, int statid)
1445{
1446 struct vme_bridge *bridge;
1447
1448 bridge = vdev->bridge;
1449 if (!bridge) {
1450 printk(KERN_ERR "Can't find VME bus\n");
1451 return -EINVAL;
1452 }
1453
1454 if ((level < 1) || (level > 7)) {
1455 printk(KERN_WARNING "Invalid interrupt level\n");
1456 return -EINVAL;
1457 }
1458
1459 if (!bridge->irq_generate) {
1460 printk(KERN_WARNING "Interrupt generation not supported\n");
1461 return -EINVAL;
1462 }
1463
1464 return bridge->irq_generate(bridge, level, statid);
1465}
1466EXPORT_SYMBOL(vme_irq_generate);
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478struct vme_resource *vme_lm_request(struct vme_dev *vdev)
1479{
1480 struct vme_bridge *bridge;
1481 struct list_head *lm_pos = NULL;
1482 struct vme_lm_resource *allocated_lm = NULL;
1483 struct vme_lm_resource *lm = NULL;
1484 struct vme_resource *resource = NULL;
1485
1486 bridge = vdev->bridge;
1487 if (!bridge) {
1488 printk(KERN_ERR "Can't find VME bus\n");
1489 goto err_bus;
1490 }
1491
1492
1493 list_for_each(lm_pos, &bridge->lm_resources) {
1494 lm = list_entry(lm_pos,
1495 struct vme_lm_resource, list);
1496 if (!lm) {
1497 printk(KERN_ERR "Registered NULL Location Monitor resource\n");
1498 continue;
1499 }
1500
1501
1502 mutex_lock(&lm->mtx);
1503 if (lm->locked == 0) {
1504 lm->locked = 1;
1505 mutex_unlock(&lm->mtx);
1506 allocated_lm = lm;
1507 break;
1508 }
1509 mutex_unlock(&lm->mtx);
1510 }
1511
1512
1513 if (!allocated_lm)
1514 goto err_lm;
1515
1516 resource = kmalloc(sizeof(*resource), GFP_KERNEL);
1517 if (!resource)
1518 goto err_alloc;
1519
1520 resource->type = VME_LM;
1521 resource->entry = &allocated_lm->list;
1522
1523 return resource;
1524
1525err_alloc:
1526
1527 mutex_lock(&lm->mtx);
1528 lm->locked = 0;
1529 mutex_unlock(&lm->mtx);
1530err_lm:
1531err_bus:
1532 return NULL;
1533}
1534EXPORT_SYMBOL(vme_lm_request);
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547int vme_lm_count(struct vme_resource *resource)
1548{
1549 struct vme_lm_resource *lm;
1550
1551 if (resource->type != VME_LM) {
1552 printk(KERN_ERR "Not a Location Monitor resource\n");
1553 return -EINVAL;
1554 }
1555
1556 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1557
1558 return lm->monitors;
1559}
1560EXPORT_SYMBOL(vme_lm_count);
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576int vme_lm_set(struct vme_resource *resource, unsigned long long lm_base,
1577 u32 aspace, u32 cycle)
1578{
1579 struct vme_bridge *bridge = find_bridge(resource);
1580 struct vme_lm_resource *lm;
1581
1582 if (resource->type != VME_LM) {
1583 printk(KERN_ERR "Not a Location Monitor resource\n");
1584 return -EINVAL;
1585 }
1586
1587 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1588
1589 if (!bridge->lm_set) {
1590 printk(KERN_ERR "vme_lm_set not supported\n");
1591 return -EINVAL;
1592 }
1593
1594 return bridge->lm_set(lm, lm_base, aspace, cycle);
1595}
1596EXPORT_SYMBOL(vme_lm_set);
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612int vme_lm_get(struct vme_resource *resource, unsigned long long *lm_base,
1613 u32 *aspace, u32 *cycle)
1614{
1615 struct vme_bridge *bridge = find_bridge(resource);
1616 struct vme_lm_resource *lm;
1617
1618 if (resource->type != VME_LM) {
1619 printk(KERN_ERR "Not a Location Monitor resource\n");
1620 return -EINVAL;
1621 }
1622
1623 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1624
1625 if (!bridge->lm_get) {
1626 printk(KERN_ERR "vme_lm_get not supported\n");
1627 return -EINVAL;
1628 }
1629
1630 return bridge->lm_get(lm, lm_base, aspace, cycle);
1631}
1632EXPORT_SYMBOL(vme_lm_get);
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649int vme_lm_attach(struct vme_resource *resource, int monitor,
1650 void (*callback)(void *), void *data)
1651{
1652 struct vme_bridge *bridge = find_bridge(resource);
1653 struct vme_lm_resource *lm;
1654
1655 if (resource->type != VME_LM) {
1656 printk(KERN_ERR "Not a Location Monitor resource\n");
1657 return -EINVAL;
1658 }
1659
1660 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1661
1662 if (!bridge->lm_attach) {
1663 printk(KERN_ERR "vme_lm_attach not supported\n");
1664 return -EINVAL;
1665 }
1666
1667 return bridge->lm_attach(lm, monitor, callback, data);
1668}
1669EXPORT_SYMBOL(vme_lm_attach);
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683int vme_lm_detach(struct vme_resource *resource, int monitor)
1684{
1685 struct vme_bridge *bridge = find_bridge(resource);
1686 struct vme_lm_resource *lm;
1687
1688 if (resource->type != VME_LM) {
1689 printk(KERN_ERR "Not a Location Monitor resource\n");
1690 return -EINVAL;
1691 }
1692
1693 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1694
1695 if (!bridge->lm_detach) {
1696 printk(KERN_ERR "vme_lm_detach not supported\n");
1697 return -EINVAL;
1698 }
1699
1700 return bridge->lm_detach(lm, monitor);
1701}
1702EXPORT_SYMBOL(vme_lm_detach);
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716void vme_lm_free(struct vme_resource *resource)
1717{
1718 struct vme_lm_resource *lm;
1719
1720 if (resource->type != VME_LM) {
1721 printk(KERN_ERR "Not a Location Monitor resource\n");
1722 return;
1723 }
1724
1725 lm = list_entry(resource->entry, struct vme_lm_resource, list);
1726
1727 mutex_lock(&lm->mtx);
1728
1729
1730
1731
1732
1733
1734 lm->locked = 0;
1735
1736 mutex_unlock(&lm->mtx);
1737
1738 kfree(resource);
1739}
1740EXPORT_SYMBOL(vme_lm_free);
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752int vme_slot_num(struct vme_dev *vdev)
1753{
1754 struct vme_bridge *bridge;
1755
1756 bridge = vdev->bridge;
1757 if (!bridge) {
1758 printk(KERN_ERR "Can't find VME bus\n");
1759 return -EINVAL;
1760 }
1761
1762 if (!bridge->slot_get) {
1763 printk(KERN_WARNING "vme_slot_num not supported\n");
1764 return -EINVAL;
1765 }
1766
1767 return bridge->slot_get(bridge);
1768}
1769EXPORT_SYMBOL(vme_slot_num);
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780int vme_bus_num(struct vme_dev *vdev)
1781{
1782 struct vme_bridge *bridge;
1783
1784 bridge = vdev->bridge;
1785 if (!bridge) {
1786 pr_err("Can't find VME bus\n");
1787 return -EINVAL;
1788 }
1789
1790 return bridge->num;
1791}
1792EXPORT_SYMBOL(vme_bus_num);
1793
1794
1795
1796static void vme_dev_release(struct device *dev)
1797{
1798 kfree(dev_to_vme_dev(dev));
1799}
1800
1801
1802struct vme_bridge *vme_init_bridge(struct vme_bridge *bridge)
1803{
1804 INIT_LIST_HEAD(&bridge->vme_error_handlers);
1805 INIT_LIST_HEAD(&bridge->master_resources);
1806 INIT_LIST_HEAD(&bridge->slave_resources);
1807 INIT_LIST_HEAD(&bridge->dma_resources);
1808 INIT_LIST_HEAD(&bridge->lm_resources);
1809 mutex_init(&bridge->irq_mtx);
1810
1811 return bridge;
1812}
1813EXPORT_SYMBOL(vme_init_bridge);
1814
1815int vme_register_bridge(struct vme_bridge *bridge)
1816{
1817 int i;
1818 int ret = -1;
1819
1820 mutex_lock(&vme_buses_lock);
1821 for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) {
1822 if ((vme_bus_numbers & (1 << i)) == 0) {
1823 vme_bus_numbers |= (1 << i);
1824 bridge->num = i;
1825 INIT_LIST_HEAD(&bridge->devices);
1826 list_add_tail(&bridge->bus_list, &vme_bus_list);
1827 ret = 0;
1828 break;
1829 }
1830 }
1831 mutex_unlock(&vme_buses_lock);
1832
1833 return ret;
1834}
1835EXPORT_SYMBOL(vme_register_bridge);
1836
1837void vme_unregister_bridge(struct vme_bridge *bridge)
1838{
1839 struct vme_dev *vdev;
1840 struct vme_dev *tmp;
1841
1842 mutex_lock(&vme_buses_lock);
1843 vme_bus_numbers &= ~(1 << bridge->num);
1844 list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) {
1845 list_del(&vdev->drv_list);
1846 list_del(&vdev->bridge_list);
1847 device_unregister(&vdev->dev);
1848 }
1849 list_del(&bridge->bus_list);
1850 mutex_unlock(&vme_buses_lock);
1851}
1852EXPORT_SYMBOL(vme_unregister_bridge);
1853
1854
1855
1856static int __vme_register_driver_bus(struct vme_driver *drv,
1857 struct vme_bridge *bridge, unsigned int ndevs)
1858{
1859 int err;
1860 unsigned int i;
1861 struct vme_dev *vdev;
1862 struct vme_dev *tmp;
1863
1864 for (i = 0; i < ndevs; i++) {
1865 vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
1866 if (!vdev) {
1867 err = -ENOMEM;
1868 goto err_devalloc;
1869 }
1870 vdev->num = i;
1871 vdev->bridge = bridge;
1872 vdev->dev.platform_data = drv;
1873 vdev->dev.release = vme_dev_release;
1874 vdev->dev.parent = bridge->parent;
1875 vdev->dev.bus = &vme_bus_type;
1876 dev_set_name(&vdev->dev, "%s.%u-%u", drv->name, bridge->num,
1877 vdev->num);
1878
1879 err = device_register(&vdev->dev);
1880 if (err)
1881 goto err_reg;
1882
1883 if (vdev->dev.platform_data) {
1884 list_add_tail(&vdev->drv_list, &drv->devices);
1885 list_add_tail(&vdev->bridge_list, &bridge->devices);
1886 } else
1887 device_unregister(&vdev->dev);
1888 }
1889 return 0;
1890
1891err_reg:
1892 put_device(&vdev->dev);
1893err_devalloc:
1894 list_for_each_entry_safe(vdev, tmp, &drv->devices, drv_list) {
1895 list_del(&vdev->drv_list);
1896 list_del(&vdev->bridge_list);
1897 device_unregister(&vdev->dev);
1898 }
1899 return err;
1900}
1901
1902static int __vme_register_driver(struct vme_driver *drv, unsigned int ndevs)
1903{
1904 struct vme_bridge *bridge;
1905 int err = 0;
1906
1907 mutex_lock(&vme_buses_lock);
1908 list_for_each_entry(bridge, &vme_bus_list, bus_list) {
1909
1910
1911
1912
1913
1914
1915
1916 err = __vme_register_driver_bus(drv, bridge, ndevs);
1917 if (err)
1918 break;
1919 }
1920 mutex_unlock(&vme_buses_lock);
1921 return err;
1922}
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933int vme_register_driver(struct vme_driver *drv, unsigned int ndevs)
1934{
1935 int err;
1936
1937 drv->driver.name = drv->name;
1938 drv->driver.bus = &vme_bus_type;
1939 INIT_LIST_HEAD(&drv->devices);
1940
1941 err = driver_register(&drv->driver);
1942 if (err)
1943 return err;
1944
1945 err = __vme_register_driver(drv, ndevs);
1946 if (err)
1947 driver_unregister(&drv->driver);
1948
1949 return err;
1950}
1951EXPORT_SYMBOL(vme_register_driver);
1952
1953
1954
1955
1956
1957
1958
1959void vme_unregister_driver(struct vme_driver *drv)
1960{
1961 struct vme_dev *dev, *dev_tmp;
1962
1963 mutex_lock(&vme_buses_lock);
1964 list_for_each_entry_safe(dev, dev_tmp, &drv->devices, drv_list) {
1965 list_del(&dev->drv_list);
1966 list_del(&dev->bridge_list);
1967 device_unregister(&dev->dev);
1968 }
1969 mutex_unlock(&vme_buses_lock);
1970
1971 driver_unregister(&drv->driver);
1972}
1973EXPORT_SYMBOL(vme_unregister_driver);
1974
1975
1976
1977static int vme_bus_match(struct device *dev, struct device_driver *drv)
1978{
1979 struct vme_driver *vme_drv;
1980
1981 vme_drv = container_of(drv, struct vme_driver, driver);
1982
1983 if (dev->platform_data == vme_drv) {
1984 struct vme_dev *vdev = dev_to_vme_dev(dev);
1985
1986 if (vme_drv->match && vme_drv->match(vdev))
1987 return 1;
1988
1989 dev->platform_data = NULL;
1990 }
1991 return 0;
1992}
1993
1994static int vme_bus_probe(struct device *dev)
1995{
1996 struct vme_driver *driver;
1997 struct vme_dev *vdev = dev_to_vme_dev(dev);
1998
1999 driver = dev->platform_data;
2000 if (driver->probe)
2001 return driver->probe(vdev);
2002
2003 return -ENODEV;
2004}
2005
2006static int vme_bus_remove(struct device *dev)
2007{
2008 struct vme_driver *driver;
2009 struct vme_dev *vdev = dev_to_vme_dev(dev);
2010
2011 driver = dev->platform_data;
2012 if (driver->remove)
2013 return driver->remove(vdev);
2014
2015 return -ENODEV;
2016}
2017
2018struct bus_type vme_bus_type = {
2019 .name = "vme",
2020 .match = vme_bus_match,
2021 .probe = vme_bus_probe,
2022 .remove = vme_bus_remove,
2023};
2024EXPORT_SYMBOL(vme_bus_type);
2025
2026static int __init vme_init(void)
2027{
2028 return bus_register(&vme_bus_type);
2029}
2030subsys_initcall(vme_init);
2031