16 #include <linux/module.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>
27 #include <linux/device.h>
32 #include <linux/slab.h>
38 static unsigned int vme_bus_numbers;
42 static void __exit vme_exit(
void);
43 static int __init vme_init(
void);
56 switch (resource->
type) {
89 if (resource ==
NULL) {
94 bridge = find_bridge(resource);
123 if (resource ==
NULL) {
128 bridge = find_bridge(resource);
129 if (bridge ==
NULL) {
154 u32 aspace, cycle, dwidth;
156 switch (resource->
type) {
159 &aspace, &cycle, &dwidth);
165 &buf_base, &aspace, &cycle);
180 static int vme_check_window(
u32 aspace,
unsigned long long vme_base,
181 unsigned long long size)
241 if (bridge ==
NULL) {
251 if (slave_image ==
NULL) {
258 if (((slave_image->
address_attr & address) == address) &&
259 ((slave_image->
cycle_attr & cycle) == cycle) &&
260 (slave_image->
locked == 0)) {
264 allocated_image = slave_image;
271 if (allocated_image ==
NULL)
275 if (resource ==
NULL) {
280 resource->
entry = &allocated_image->
list;
296 unsigned long long vme_base,
unsigned long long size,
321 retval = vme_check_window(aspace, vme_base, size);
325 return bridge->
slave_set(image, enabled, vme_base, size, buf_base,
331 unsigned long long *vme_base,
unsigned long long *size,
349 return bridge->
slave_get(image, enabled, vme_base, size, buf_base,
365 if (slave_image ==
NULL) {
372 if (slave_image->
locked == 0)
397 if (bridge ==
NULL) {
407 if (master_image ==
NULL) {
413 spin_lock(&master_image->
lock);
414 if (((master_image->
address_attr & address) == address) &&
415 ((master_image->
cycle_attr & cycle) == cycle) &&
416 ((master_image->
width_attr & dwidth) == dwidth) &&
417 (master_image->
locked == 0)) {
420 spin_unlock(&master_image->
lock);
421 allocated_image = master_image;
424 spin_unlock(&master_image->
lock);
428 if (allocated_image ==
NULL) {
434 if (resource ==
NULL) {
439 resource->
entry = &allocated_image->
list;
445 spin_lock(&master_image->
lock);
447 spin_unlock(&master_image->
lock);
455 unsigned long long vme_base,
unsigned long long size,
u32 aspace,
481 retval = vme_check_window(aspace, vme_base, size);
485 return bridge->
master_set(image, enabled, vme_base, size, aspace,
491 unsigned long long *vme_base,
unsigned long long *size,
u32 *aspace,
509 return bridge->
master_get(image, enabled, vme_base, size, aspace,
538 if (offset > length) {
543 if ((offset + count) > length)
546 return bridge->
master_read(image, buf, count, offset);
575 if (offset > length) {
580 if ((offset + count) > length)
591 unsigned int compare,
unsigned int swap, loff_t
offset)
608 return bridge->
master_rmw(image, mask, compare, swap, offset);
623 if (master_image ==
NULL) {
629 spin_lock(&master_image->
lock);
630 if (master_image->
locked == 0)
634 spin_unlock(&master_image->
lock);
657 if (bridge ==
NULL) {
667 if (dma_ctrlr ==
NULL) {
674 if (((dma_ctrlr->
route_attr & route) == route) &&
675 (dma_ctrlr->
locked == 0)) {
679 allocated_ctrlr = dma_ctrlr;
686 if (allocated_ctrlr ==
NULL)
690 if (resource ==
NULL) {
695 resource->
entry = &allocated_ctrlr->
list;
726 if (dma_list ==
NULL) {
730 INIT_LIST_HEAD(&dma_list->
entries);
747 if (attributes ==
NULL) {
748 printk(
KERN_ERR "Unable to allocate memory for attributes structure\n");
753 if (pattern_attr ==
NULL) {
754 printk(
KERN_ERR "Unable to allocate memory for pattern attributes\n");
759 attributes->
private = (
void *)pattern_attr;
784 if (attributes ==
NULL) {
785 printk(
KERN_ERR "Unable to allocate memory for attributes structure\n");
790 if (pci_attr ==
NULL) {
791 printk(
KERN_ERR "Unable to allocate memory for pci attributes\n");
798 attributes->
private = (
void *)pci_attr;
822 if (attributes ==
NULL) {
823 printk(
KERN_ERR "Unable to allocate memory for attributes structure\n");
828 if (vme_attr ==
NULL) {
829 printk(
KERN_ERR "Unable to allocate memory for vme attributes\n");
834 attributes->
private = (
void *)vme_attr;
952 if (!(list_empty(&ctrlr->
pending) && list_empty(&ctrlr->
running))) {
971 call = bridge->
irq[level - 1].callback[statid].func;
972 priv_data = bridge->
irq[level - 1].callback[statid].priv_data;
975 call(level, statid, priv_data);
989 if (bridge ==
NULL) {
994 if ((level < 1) || (level > 7)) {
1006 if (bridge->
irq[level - 1].callback[statid].func) {
1012 bridge->
irq[level - 1].count++;
1013 bridge->
irq[level - 1].callback[statid].priv_data = priv_data;
1014 bridge->
irq[level - 1].callback[statid].func =
callback;
1017 bridge->
irq_set(bridge, level, 1, 1);
1030 if (bridge ==
NULL) {
1035 if ((level < 1) || (level > 7)) {
1047 bridge->
irq[level - 1].count--;
1050 if (bridge->
irq[level - 1].count == 0)
1051 bridge->
irq_set(bridge, level, 0, 1);
1053 bridge->
irq[level - 1].callback[statid].func =
NULL;
1054 bridge->
irq[level - 1].callback[statid].priv_data =
NULL;
1065 if (bridge ==
NULL) {
1070 if ((level < 1) || (level > 7)) {
1096 if (bridge ==
NULL) {
1123 if (allocated_lm ==
NULL)
1127 if (resource ==
NULL) {
1180 return bridge->
lm_set(lm, lm_base, aspace, cycle);
1202 return bridge->
lm_get(lm, lm_base, aspace, cycle);
1280 if (bridge ==
NULL) {
1297 static void vme_dev_release(
struct device *
dev)
1299 kfree(dev_to_vme_dev(dev));
1308 for (i = 0; i <
sizeof(vme_bus_numbers) * 8; i++) {
1309 if ((vme_bus_numbers & (1 << i)) == 0) {
1310 vme_bus_numbers |= (1 <<
i);
1312 INIT_LIST_HEAD(&bridge->
devices);
1330 vme_bus_numbers &= ~(1 << bridge->
num);
1343 static int __vme_register_driver_bus(
struct vme_driver *drv,
1351 for (i = 0; i < ndevs; i++) {
1359 vdev->
dev.platform_data = drv;
1360 vdev->
dev.release = vme_dev_release;
1370 if (vdev->
dev.platform_data) {
1389 static int __vme_register_driver(
struct vme_driver *drv,
unsigned int ndevs)
1403 err = __vme_register_driver_bus(drv, bridge, ndevs);
1417 INIT_LIST_HEAD(&drv->
devices);
1423 err = __vme_register_driver(drv, ndevs);
1456 struct vme_dev *vdev = dev_to_vme_dev(dev);
1466 static int vme_bus_probe(
struct device *dev)
1470 struct vme_dev *vdev = dev_to_vme_dev(dev);
1475 retval = driver->
probe(vdev);
1480 static int vme_bus_remove(
struct device *dev)
1484 struct vme_dev *vdev = dev_to_vme_dev(dev);
1489 retval = driver->
remove(vdev);
1496 .match = vme_bus_match,
1497 .probe = vme_bus_probe,
1498 .remove = vme_bus_remove,
1502 static int __init vme_init(
void)
1507 static void __exit vme_exit(
void)