Commit 5d6abf37 authored by Manohar Vanga's avatar Manohar Vanga Committed by Greg Kroah-Hartman

staging: vme: make match() driver specific to improve non-VME64x support

For jumper based boards (non VME64x), there is no mechanism
for detecting the card that is plugged into a specific slot. This
leads to issues in non-autodiscovery crates/cards when a card is
plugged into a slot that is "claimed" by a different driver. In
reality, there is no problem, but the driver rejects such a
configuration due to its dependence on the concept of slots.

This patch makes the concept of slots less critical and pushes the
driver match() to individual drivers (similar to what happens in the
ISA bus in driver/base/isa.c). This allows drivers to register the
number of devices that they expect without any restrictions. Devices
in this new model are now formatted as $driver_name-$bus_id.$device_id
(as compared to the earlier vme-$bus_id.$slot_number).

This model also makes the device model more logical as devices
are only registered when they actually exist whereas earlier,
a set of devices were being created automatically regardless of
them actually being there.

Another change introduced in this patch is that devices are now created
within the VME driver structure rather than in the VME bridge structure.
This way, things don't go haywire if the bridge driver is removed while
a driver is using it.
Signed-off-by: default avatarManohar Vanga <manohar.vanga@cern.ch>
Cc: Martyn Welch <martyn.welch@ge.com>
Reviewed-by: default avatarEmilio G. Cota <cota@braap.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 8f966dc4
...@@ -135,6 +135,7 @@ static ssize_t vme_user_write(struct file *, const char __user *, size_t, ...@@ -135,6 +135,7 @@ static ssize_t vme_user_write(struct file *, const char __user *, size_t,
static loff_t vme_user_llseek(struct file *, loff_t, int); static loff_t vme_user_llseek(struct file *, loff_t, int);
static long vme_user_unlocked_ioctl(struct file *, unsigned int, unsigned long); static long vme_user_unlocked_ioctl(struct file *, unsigned int, unsigned long);
static int vme_user_match(struct vme_dev *);
static int __devinit vme_user_probe(struct vme_dev *); static int __devinit vme_user_probe(struct vme_dev *);
static int __devexit vme_user_remove(struct vme_dev *); static int __devexit vme_user_remove(struct vme_dev *);
...@@ -620,6 +621,7 @@ static void buf_unalloc(int num) ...@@ -620,6 +621,7 @@ static void buf_unalloc(int num)
static struct vme_driver vme_user_driver = { static struct vme_driver vme_user_driver = {
.name = driver_name, .name = driver_name,
.match = vme_user_match,
.probe = vme_user_probe, .probe = vme_user_probe,
.remove = __devexit_p(vme_user_remove), .remove = __devexit_p(vme_user_remove),
}; };
...@@ -628,8 +630,6 @@ static struct vme_driver vme_user_driver = { ...@@ -628,8 +630,6 @@ static struct vme_driver vme_user_driver = {
static int __init vme_user_init(void) static int __init vme_user_init(void)
{ {
int retval = 0; int retval = 0;
int i;
struct vme_device_id *ids;
printk(KERN_INFO "VME User Space Access Driver\n"); printk(KERN_INFO "VME User Space Access Driver\n");
...@@ -649,41 +649,30 @@ static int __init vme_user_init(void) ...@@ -649,41 +649,30 @@ static int __init vme_user_init(void)
bus_num = USER_BUS_MAX; bus_num = USER_BUS_MAX;
} }
/*
/* Dynamically create the bind table based on module parameters */ * Here we just register the maximum number of devices we can and
ids = kzalloc(sizeof(struct vme_device_id) * (bus_num + 1), GFP_KERNEL); * leave vme_user_match() to allow only 1 to go through to probe().
if (ids == NULL) { * This way, if we later want to allow multiple user access devices,
printk(KERN_ERR "%s: Unable to allocate ID table\n", * we just change the code in vme_user_match().
driver_name); */
retval = -ENOMEM; retval = vme_register_driver(&vme_user_driver, VME_MAX_SLOTS);
goto err_id;
}
for (i = 0; i < bus_num; i++) {
ids[i].bus = bus[i];
/*
* We register the driver against the slot occupied by *this*
* card, since it's really a low level way of controlling
* the VME bridge
*/
ids[i].slot = VME_SLOT_CURRENT;
}
vme_user_driver.bind_table = ids;
retval = vme_register_driver(&vme_user_driver);
if (retval != 0) if (retval != 0)
goto err_reg; goto err_reg;
return retval; return retval;
err_reg: err_reg:
kfree(ids);
err_id:
err_nocard: err_nocard:
return retval; return retval;
} }
static int vme_user_match(struct vme_dev *vdev)
{
if (vdev->id.num >= USER_BUS_MAX)
return 0;
return 1;
}
/* /*
* In this simple access driver, the old behaviour is being preserved as much * In this simple access driver, the old behaviour is being preserved as much
* as practical. We will therefore reserve the buffers and request the images * as practical. We will therefore reserve the buffers and request the images
...@@ -896,8 +885,6 @@ static int __devexit vme_user_remove(struct vme_dev *dev) ...@@ -896,8 +885,6 @@ static int __devexit vme_user_remove(struct vme_dev *dev)
static void __exit vme_user_exit(void) static void __exit vme_user_exit(void)
{ {
vme_unregister_driver(&vme_user_driver); vme_unregister_driver(&vme_user_driver);
kfree(vme_user_driver.bind_table);
} }
......
...@@ -1317,6 +1317,7 @@ static int vme_add_bus(struct vme_bridge *bridge) ...@@ -1317,6 +1317,7 @@ static int vme_add_bus(struct vme_bridge *bridge)
if ((vme_bus_numbers & (1 << i)) == 0) { if ((vme_bus_numbers & (1 << i)) == 0) {
vme_bus_numbers |= (1 << i); vme_bus_numbers |= (1 << i);
bridge->num = i; bridge->num = i;
INIT_LIST_HEAD(&bridge->devices);
list_add_tail(&bridge->bus_list, &vme_bus_list); list_add_tail(&bridge->bus_list, &vme_bus_list);
ret = 0; ret = 0;
break; break;
...@@ -1329,8 +1330,16 @@ static int vme_add_bus(struct vme_bridge *bridge) ...@@ -1329,8 +1330,16 @@ static int vme_add_bus(struct vme_bridge *bridge)
static void vme_remove_bus(struct vme_bridge *bridge) static void vme_remove_bus(struct vme_bridge *bridge)
{ {
struct vme_dev *vdev;
struct vme_dev *tmp;
mutex_lock(&vme_buses_lock); mutex_lock(&vme_buses_lock);
vme_bus_numbers &= ~(1 << bridge->num); vme_bus_numbers &= ~(1 << bridge->num);
list_for_each_entry_safe(vdev, tmp, &bridge->devices, bridge_list) {
list_del(&vdev->drv_list);
list_del(&vdev->bridge_list);
device_unregister(&vdev->dev);
}
list_del(&bridge->bus_list); list_del(&bridge->bus_list);
mutex_unlock(&vme_buses_lock); mutex_unlock(&vme_buses_lock);
} }
...@@ -1342,153 +1351,153 @@ static void vme_dev_release(struct device *dev) ...@@ -1342,153 +1351,153 @@ static void vme_dev_release(struct device *dev)
int vme_register_bridge(struct vme_bridge *bridge) int vme_register_bridge(struct vme_bridge *bridge)
{ {
struct vme_dev *vdev; return vme_add_bus(bridge);
int retval; }
int i; EXPORT_SYMBOL(vme_register_bridge);
retval = vme_add_bus(bridge); void vme_unregister_bridge(struct vme_bridge *bridge)
if (retval) {
return retval; vme_remove_bus(bridge);
}
EXPORT_SYMBOL(vme_unregister_bridge);
/* This creates 32 vme "slot" devices. This equates to a slot for each /* - Driver Registration --------------------------------------------------- */
* ID available in a system conforming to the ANSI/VITA 1-1994
* specification. static int __vme_register_driver_bus(struct vme_driver *drv,
*/ struct vme_bridge *bridge, unsigned int ndevs)
for (i = 0; i < VME_SLOTS_MAX; i++) { {
bridge->dev[i] = kzalloc(sizeof(struct vme_dev), GFP_KERNEL); int err;
if (!bridge->dev[i]) { unsigned int i;
retval = -ENOMEM; struct vme_dev *vdev;
struct vme_dev *tmp;
for (i = 0; i < ndevs; i++) {
vdev = kzalloc(sizeof(struct vme_dev), GFP_KERNEL);
if (!vdev) {
err = -ENOMEM;
goto err_devalloc; goto err_devalloc;
} }
vdev = bridge->dev[i]; vdev->id.num = i;
memset(vdev, 0, sizeof(struct vme_dev));
vdev->id.bus = bridge->num; vdev->id.bus = bridge->num;
vdev->id.slot = i + 1; vdev->id.slot = i + 1;
vdev->bridge = bridge; vdev->bridge = bridge;
vdev->dev.platform_data = drv;
vdev->dev.release = vme_dev_release;
vdev->dev.parent = bridge->parent; vdev->dev.parent = bridge->parent;
vdev->dev.bus = &vme_bus_type; vdev->dev.bus = &vme_bus_type;
vdev->dev.release = vme_dev_release; dev_set_name(&vdev->dev, "%s.%u-%u", drv->name, vdev->id.bus,
/* vdev->id.num);
* We save a pointer to the bridge in platform_data so that we
* can get to it later. We keep driver_data for use by the
* driver that binds against the slot
*/
vdev->dev.platform_data = bridge;
dev_set_name(&vdev->dev, "vme-%x.%x", bridge->num, i + 1);
retval = device_register(&vdev->dev); err = device_register(&vdev->dev);
if (retval) if (err)
goto err_reg; goto err_reg;
}
return retval; if (vdev->dev.platform_data) {
list_add_tail(&vdev->drv_list, &drv->devices);
list_add_tail(&vdev->bridge_list, &bridge->devices);
} else
device_unregister(&vdev->dev);
}
return 0;
err_reg: err_reg:
kfree(vdev); kfree(vdev);
err_devalloc: err_devalloc:
while (--i >= 0) { list_for_each_entry_safe(vdev, tmp, &drv->devices, drv_list) {
vdev = bridge->dev[i]; list_del(&vdev->drv_list);
list_del(&vdev->bridge_list);
device_unregister(&vdev->dev); device_unregister(&vdev->dev);
} }
vme_remove_bus(bridge); return err;
return retval;
} }
EXPORT_SYMBOL(vme_register_bridge);
void vme_unregister_bridge(struct vme_bridge *bridge) static int __vme_register_driver(struct vme_driver *drv, unsigned int ndevs)
{ {
int i; struct vme_bridge *bridge;
struct vme_dev *vdev; int err = 0;
for (i = 0; i < VME_SLOTS_MAX; i++) { mutex_lock(&vme_buses_lock);
vdev = bridge->dev[i]; list_for_each_entry(bridge, &vme_bus_list, bus_list) {
device_unregister(&vdev->dev); /*
* This cannot cause trouble as we already have vme_buses_lock
* and if the bridge is removed, it will have to go through
* vme_unregister_bridge() to do it (which calls remove() on
* the bridge which in turn tries to acquire vme_buses_lock and
* will have to wait). The probe() called after device
* registration in __vme_register_driver below will also fail
* as the bridge is being removed (since the probe() calls
* vme_bridge_get()).
*/
err = __vme_register_driver_bus(drv, bridge, ndevs);
if (err)
break;
} }
vme_remove_bus(bridge); mutex_unlock(&vme_buses_lock);
return err;
} }
EXPORT_SYMBOL(vme_unregister_bridge);
/* - Driver Registration --------------------------------------------------- */
int vme_register_driver(struct vme_driver *drv) int vme_register_driver(struct vme_driver *drv, unsigned int ndevs)
{ {
int err;
drv->driver.name = drv->name; drv->driver.name = drv->name;
drv->driver.bus = &vme_bus_type; drv->driver.bus = &vme_bus_type;
INIT_LIST_HEAD(&drv->devices);
err = driver_register(&drv->driver);
if (err)
return err;
return driver_register(&drv->driver); err = __vme_register_driver(drv, ndevs);
if (err)
driver_unregister(&drv->driver);
return err;
} }
EXPORT_SYMBOL(vme_register_driver); EXPORT_SYMBOL(vme_register_driver);
void vme_unregister_driver(struct vme_driver *drv) void vme_unregister_driver(struct vme_driver *drv)
{ {
struct vme_dev *dev, *dev_tmp;
mutex_lock(&vme_buses_lock);
list_for_each_entry_safe(dev, dev_tmp, &drv->devices, drv_list) {
list_del(&dev->drv_list);
list_del(&dev->bridge_list);
device_unregister(&dev->dev);
}
mutex_unlock(&vme_buses_lock);
driver_unregister(&drv->driver); driver_unregister(&drv->driver);
} }
EXPORT_SYMBOL(vme_unregister_driver); EXPORT_SYMBOL(vme_unregister_driver);
/* - Bus Registration ------------------------------------------------------ */ /* - Bus Registration ------------------------------------------------------ */
static struct vme_driver *dev_to_vme_driver(struct device *dev)
{
if (dev->driver == NULL)
printk(KERN_ERR "Bugger dev->driver is NULL\n");
return container_of(dev->driver, struct vme_driver, driver);
}
static int vme_bus_match(struct device *dev, struct device_driver *drv) static int vme_bus_match(struct device *dev, struct device_driver *drv)
{ {
struct vme_dev *vdev; struct vme_driver *vme_drv;
struct vme_bridge *bridge;
struct vme_driver *driver;
int i, num;
vdev = dev_to_vme_dev(dev);
bridge = vdev->bridge;
driver = container_of(drv, struct vme_driver, driver);
num = vdev->id.slot; vme_drv = container_of(drv, struct vme_driver, driver);
if (num <= 0 || num >= VME_SLOTS_MAX)
goto err_dev;
if (driver->bind_table == NULL) {
dev_err(dev, "Bind table NULL\n");
goto err_table;
}
i = 0; if (dev->platform_data == vme_drv) {
while ((driver->bind_table[i].bus != 0) || struct vme_dev *vdev = dev_to_vme_dev(dev);
(driver->bind_table[i].slot != 0)) {
if (bridge->num == driver->bind_table[i].bus) { if (vme_drv->match && vme_drv->match(vdev))
if (num == driver->bind_table[i].slot) return 1;
return 1;
if (driver->bind_table[i].slot == VME_SLOT_ALL) dev->platform_data = NULL;
return 1;
if ((driver->bind_table[i].slot == VME_SLOT_CURRENT) &&
(num == vme_slot_get(vdev)))
return 1;
}
i++;
} }
err_dev:
err_table:
return 0; return 0;
} }
static int vme_bus_probe(struct device *dev) static int vme_bus_probe(struct device *dev)
{ {
struct vme_driver *driver;
struct vme_dev *vdev;
int retval = -ENODEV; int retval = -ENODEV;
struct vme_driver *driver;
struct vme_dev *vdev = dev_to_vme_dev(dev);
driver = dev_to_vme_driver(dev); driver = dev->platform_data;
vdev = dev_to_vme_dev(dev);
if (driver->probe != NULL) if (driver->probe != NULL)
retval = driver->probe(vdev); retval = driver->probe(vdev);
...@@ -1498,12 +1507,11 @@ static int vme_bus_probe(struct device *dev) ...@@ -1498,12 +1507,11 @@ static int vme_bus_probe(struct device *dev)
static int vme_bus_remove(struct device *dev) static int vme_bus_remove(struct device *dev)
{ {
struct vme_driver *driver;
struct vme_dev *vdev;
int retval = -ENODEV; int retval = -ENODEV;
struct vme_driver *driver;
struct vme_dev *vdev = dev_to_vme_dev(dev);
driver = dev_to_vme_driver(dev); driver = dev->platform_data;
vdev = dev_to_vme_dev(dev);
if (driver->remove != NULL) if (driver->remove != NULL)
retval = driver->remove(vdev); retval = driver->remove(vdev);
......
...@@ -88,15 +88,21 @@ struct vme_resource { ...@@ -88,15 +88,21 @@ struct vme_resource {
extern struct bus_type vme_bus_type; extern struct bus_type vme_bus_type;
/* VME_MAX_BRIDGES comes from the type of vme_bus_numbers */
#define VME_MAX_BRIDGES (sizeof(unsigned int)*8)
#define VME_MAX_SLOTS 32
#define VME_SLOT_CURRENT -1 #define VME_SLOT_CURRENT -1
#define VME_SLOT_ALL -2 #define VME_SLOT_ALL -2
/** /**
* VME device identifier structure * VME device identifier structure
* @num: The device ID (ranges from 0 to N-1 for N devices)
* @bus: The bus ID of the bus the device is on * @bus: The bus ID of the bus the device is on
* @slot: The slot this device is plugged into * @slot: The slot this device is plugged into
*/ */
struct vme_device_id { struct vme_device_id {
int num;
int bus; int bus;
int slot; int slot;
}; };
...@@ -106,21 +112,26 @@ struct vme_device_id { ...@@ -106,21 +112,26 @@ struct vme_device_id {
* @id: The ID of the device (currently the bus and slot number) * @id: The ID of the device (currently the bus and slot number)
* @bridge: Pointer to the bridge device this device is on * @bridge: Pointer to the bridge device this device is on
* @dev: Internal device structure * @dev: Internal device structure
* @drv_list: List of devices (per driver)
* @bridge_list: List of devices (per bridge)
*/ */
struct vme_dev { struct vme_dev {
struct vme_device_id id; struct vme_device_id id;
struct vme_bridge *bridge; struct vme_bridge *bridge;
struct device dev; struct device dev;
struct list_head drv_list;
struct list_head bridge_list;
}; };
struct vme_driver { struct vme_driver {
struct list_head node; struct list_head node;
const char *name; const char *name;
const struct vme_device_id *bind_table; int (*match)(struct vme_dev *);
int (*probe) (struct vme_dev *); int (*probe)(struct vme_dev *);
int (*remove) (struct vme_dev *); int (*remove)(struct vme_dev *);
void (*shutdown) (void); void (*shutdown)(void);
struct device_driver driver; struct device_driver driver;
struct list_head devices;
}; };
void *vme_alloc_consistent(struct vme_resource *, size_t, dma_addr_t *); void *vme_alloc_consistent(struct vme_resource *, size_t, dma_addr_t *);
...@@ -179,7 +190,7 @@ void vme_lm_free(struct vme_resource *); ...@@ -179,7 +190,7 @@ void vme_lm_free(struct vme_resource *);
int vme_slot_get(struct vme_dev *); int vme_slot_get(struct vme_dev *);
int vme_register_driver(struct vme_driver *); int vme_register_driver(struct vme_driver *, unsigned int);
void vme_unregister_driver(struct vme_driver *); void vme_unregister_driver(struct vme_driver *);
......
...@@ -18,24 +18,37 @@ registration function. The structure is as follows: ...@@ -18,24 +18,37 @@ registration function. The structure is as follows:
struct vme_driver { struct vme_driver {
struct list_head node; struct list_head node;
char *name; const char *name;
const struct vme_device_id *bind_table; int (*match)(struct vme_dev *);
int (*probe) (struct vme_dev *); int (*probe)(struct vme_dev *);
int (*remove) (struct vme_dev *); int (*remove)(struct vme_dev *);
void (*shutdown) (void); void (*shutdown)(void);
struct device_driver driver; struct device_driver driver;
struct list_head devices;
unsigned int ndev;
}; };
At the minimum, the '.name', '.probe' and '.bind_table' elements of this At the minimum, the '.name', '.match' and '.probe' elements of this structure
structure should be correctly set. The '.name' element is a pointer to a string should be correctly set. The '.name' element is a pointer to a string holding
holding the device driver's name. The '.probe' element should contain a pointer the device driver's name.
to the probe routine.
The arguments of the probe routine are as follows: The '.match' function allows controlling the number of devices that need to
be registered. The match function should return 1 if a device should be
probed and 0 otherwise. This example match function (from vme_user.c) limits
the number of devices probed to one:
probe(struct vme_dev *dev); #define USER_BUS_MAX 1
...
static int vme_user_match(struct vme_dev *vdev)
{
if (vdev->id.num >= USER_BUS_MAX)
return 0;
return 1;
}
The device structure looks like the following: The '.probe' element should contain a pointer to the probe routine. The
probe routine is passed a 'struct vme_dev' pointer as an argument. The
'struct vme_dev' structure looks like the following:
struct vme_dev { struct vme_dev {
struct vme_device_id id; struct vme_device_id id;
...@@ -49,25 +62,12 @@ contains information useful for the probe function: ...@@ -49,25 +62,12 @@ contains information useful for the probe function:
struct vme_device_id { struct vme_device_id {
int bus; int bus;
int slot; int slot;
int num;
}; };
'bus' is the number of the bus the device being probed is on. 'slot' refers Here, 'bus' is the number of the bus the device being probed is on. 'slot'
to the specific slot on the VME bus. refers to the specific slot on the VME bus. The 'num' field refers to the
sequential device ID for this specific driver.
The '.bind_table' is a pointer to an array of type 'vme_device_id':
struct vme_device_id {
int bus;
int slot;
};
Each structure in this array should provide a bus and slot number where the core
should probe, using the driver's probe routine, for a device on the specified
VME bus.
The VME subsystem supports a single VME driver per 'slot'. There are considered
to be 32 slots per bus, one for each slot-ID as defined in the ANSI/VITA 1-1994
specification and are analogious to the physical slots on the VME backplane.
A function is also provided to unregister the driver from the VME core and is A function is also provided to unregister the driver from the VME core and is
usually called from the device driver's exit routine: usually called from the device driver's exit routine:
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define _VME_BRIDGE_H_ #define _VME_BRIDGE_H_
#define VME_CRCSR_BUF_SIZE (508*1024) #define VME_CRCSR_BUF_SIZE (508*1024)
#define VME_SLOTS_MAX 32
/* /*
* Resource structures * Resource structures
*/ */
...@@ -108,15 +107,13 @@ struct vme_bridge { ...@@ -108,15 +107,13 @@ struct vme_bridge {
struct list_head lm_resources; struct list_head lm_resources;
struct list_head vme_errors; /* List for errors generated on VME */ struct list_head vme_errors; /* List for errors generated on VME */
struct list_head devices; /* List of devices on this bridge */
/* Bridge Info - XXX Move to private structure? */ /* Bridge Info - XXX Move to private structure? */
struct device *parent; /* Parent device (eg. pdev->dev for PCI) */ struct device *parent; /* Parent device (eg. pdev->dev for PCI) */
void *driver_priv; /* Private pointer for the bridge driver */ void *driver_priv; /* Private pointer for the bridge driver */
struct list_head bus_list; /* list of VME buses */ struct list_head bus_list; /* list of VME buses */
struct vme_dev *dev[VME_SLOTS_MAX]; /* Device registered
* on VME bus */
/* Interrupt callbacks */ /* Interrupt callbacks */
struct vme_irq irq[7]; struct vme_irq irq[7];
/* Locking for VME irq callback configuration */ /* Locking for VME irq callback configuration */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment