Commit 733e3ef0 authored by Manohar Vanga's avatar Manohar Vanga Committed by Greg Kroah-Hartman

staging: vme: keep track of registered buses

This patch adds a list which keeps track of all registered VME
buses. This is required for adding refcounting later to bridge
modules, something that is not currently implemented.

This is based on the changes introduced by Emilio G. Cota in the
patch:

    https://lkml.org/lkml/2010/10/25/486Signed-off-by: default avatarManohar Vanga <manohar.vanga@cern.ch>
Acked-by: default avatarMartyn Welch <martyn.welch@ge.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 7f58f025
...@@ -34,9 +34,10 @@ ...@@ -34,9 +34,10 @@
#include "vme.h" #include "vme.h"
#include "vme_bridge.h" #include "vme_bridge.h"
/* Bitmask and mutex to keep track of bridge numbers */ /* Bitmask and list of registered buses both protected by common mutex */
static unsigned int vme_bus_numbers; static unsigned int vme_bus_numbers;
static DEFINE_MUTEX(vme_bus_num_mtx); static LIST_HEAD(vme_bus_list);
static DEFINE_MUTEX(vme_buses_lock);
static void __exit vme_exit(void); static void __exit vme_exit(void);
static int __init vme_init(void); static int __init vme_init(void);
...@@ -1309,27 +1310,32 @@ EXPORT_SYMBOL(vme_slot_get); ...@@ -1309,27 +1310,32 @@ EXPORT_SYMBOL(vme_slot_get);
/* - Bridge Registration --------------------------------------------------- */ /* - Bridge Registration --------------------------------------------------- */
static int vme_alloc_bus_num(void) static int vme_add_bus(struct vme_bridge *bridge)
{ {
int i; int i;
int ret = -1;
mutex_lock(&vme_bus_num_mtx); mutex_lock(&vme_buses_lock);
for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) { for (i = 0; i < sizeof(vme_bus_numbers) * 8; i++) {
if (((vme_bus_numbers >> i) & 0x1) == 0) { if ((vme_bus_numbers & (1 << i)) == 0) {
vme_bus_numbers |= (0x1 << i); vme_bus_numbers |= (1 << i);
bridge->num = i;
list_add_tail(&bridge->bus_list, &vme_bus_list);
ret = 0;
break; break;
} }
} }
mutex_unlock(&vme_bus_num_mtx); mutex_unlock(&vme_buses_lock);
return i; return ret;
} }
static void vme_free_bus_num(int bus) static void vme_remove_bus(struct vme_bridge *bridge)
{ {
mutex_lock(&vme_bus_num_mtx); mutex_lock(&vme_buses_lock);
vme_bus_numbers &= ~(0x1 << bus); vme_bus_numbers &= ~(1 << bridge->num);
mutex_unlock(&vme_bus_num_mtx); list_del(&bridge->bus_list);
mutex_unlock(&vme_buses_lock);
} }
int vme_register_bridge(struct vme_bridge *bridge) int vme_register_bridge(struct vme_bridge *bridge)
...@@ -1338,7 +1344,9 @@ int vme_register_bridge(struct vme_bridge *bridge) ...@@ -1338,7 +1344,9 @@ int vme_register_bridge(struct vme_bridge *bridge)
int retval; int retval;
int i; int i;
bridge->num = vme_alloc_bus_num(); retval = vme_add_bus(bridge);
if (retval)
return retval;
/* This creates 32 vme "slot" devices. This equates to a slot for each /* This creates 32 vme "slot" devices. This equates to a slot for each
* ID available in a system conforming to the ANSI/VITA 1-1994 * ID available in a system conforming to the ANSI/VITA 1-1994
...@@ -1370,7 +1378,7 @@ int vme_register_bridge(struct vme_bridge *bridge) ...@@ -1370,7 +1378,7 @@ int vme_register_bridge(struct vme_bridge *bridge)
dev = &bridge->dev[i]; dev = &bridge->dev[i];
device_unregister(dev); device_unregister(dev);
} }
vme_free_bus_num(bridge->num); vme_remove_bus(bridge);
return retval; return retval;
} }
EXPORT_SYMBOL(vme_register_bridge); EXPORT_SYMBOL(vme_register_bridge);
...@@ -1385,7 +1393,7 @@ void vme_unregister_bridge(struct vme_bridge *bridge) ...@@ -1385,7 +1393,7 @@ void vme_unregister_bridge(struct vme_bridge *bridge)
dev = &bridge->dev[i]; dev = &bridge->dev[i];
device_unregister(dev); device_unregister(dev);
} }
vme_free_bus_num(bridge->num); vme_remove_bus(bridge);
} }
EXPORT_SYMBOL(vme_unregister_bridge); EXPORT_SYMBOL(vme_unregister_bridge);
......
...@@ -112,6 +112,7 @@ struct vme_bridge { ...@@ -112,6 +112,7 @@ struct vme_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 device dev[VME_SLOTS_MAX]; /* Device registered with struct device dev[VME_SLOTS_MAX]; /* Device registered with
* device model on VME bus * device model on VME bus
......
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