Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 267604
b: refs/heads/master
c: 733e3ef
h: refs/heads/master
v: v3
  • Loading branch information
Manohar Vanga authored and Greg Kroah-Hartman committed Aug 23, 2011
1 parent 9b05447 commit 3e3d7d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7f58f0255aec0b933e0b26ef64d3d533c362a3d3
refs/heads/master: 733e3ef0d364b7e6757a897e7f1862a70c89305a
38 changes: 23 additions & 15 deletions trunk/drivers/staging/vme/vme.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
#include "vme.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 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 int __init vme_init(void);
Expand Down Expand Up @@ -1309,27 +1310,32 @@ EXPORT_SYMBOL(vme_slot_get);

/* - Bridge Registration --------------------------------------------------- */

static int vme_alloc_bus_num(void)
static int vme_add_bus(struct vme_bridge *bridge)
{
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++) {
if (((vme_bus_numbers >> i) & 0x1) == 0) {
vme_bus_numbers |= (0x1 << i);
if ((vme_bus_numbers & (1 << i)) == 0) {
vme_bus_numbers |= (1 << i);
bridge->num = i;
list_add_tail(&bridge->bus_list, &vme_bus_list);
ret = 0;
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);
vme_bus_numbers &= ~(0x1 << bus);
mutex_unlock(&vme_bus_num_mtx);
mutex_lock(&vme_buses_lock);
vme_bus_numbers &= ~(1 << bridge->num);
list_del(&bridge->bus_list);
mutex_unlock(&vme_buses_lock);
}

int vme_register_bridge(struct vme_bridge *bridge)
Expand All @@ -1338,7 +1344,9 @@ int vme_register_bridge(struct vme_bridge *bridge)
int retval;
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
* ID available in a system conforming to the ANSI/VITA 1-1994
Expand Down Expand Up @@ -1370,7 +1378,7 @@ int vme_register_bridge(struct vme_bridge *bridge)
dev = &bridge->dev[i];
device_unregister(dev);
}
vme_free_bus_num(bridge->num);
vme_remove_bus(bridge);
return retval;
}
EXPORT_SYMBOL(vme_register_bridge);
Expand All @@ -1385,7 +1393,7 @@ void vme_unregister_bridge(struct vme_bridge *bridge)
dev = &bridge->dev[i];
device_unregister(dev);
}
vme_free_bus_num(bridge->num);
vme_remove_bus(bridge);
}
EXPORT_SYMBOL(vme_unregister_bridge);

Expand Down
1 change: 1 addition & 0 deletions trunk/drivers/staging/vme/vme_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct vme_bridge {
/* Bridge Info - XXX Move to private structure? */
struct device *parent; /* Parent device (eg. pdev->dev for PCI) */
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
* device model on VME bus
Expand Down

0 comments on commit 3e3d7d6

Please sign in to comment.