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