Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 268836
b: refs/heads/master
c: 8f966dc
h: refs/heads/master
v: v3
  • Loading branch information
Manohar Vanga authored and Greg Kroah-Hartman committed Oct 17, 2011
1 parent a506a21 commit 82774fc
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 109 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: 9ad2e2e1d6506252f31a142a9b04121992af25e3
refs/heads/master: 8f966dc444b11adff6011a1d1fce424abdd876d8
14 changes: 6 additions & 8 deletions trunk/drivers/staging/vme/devices/vme_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static struct driver_stats statistics;

static struct cdev *vme_user_cdev; /* Character device */
static struct class *vme_user_sysfs_class; /* Sysfs class */
static struct device *vme_user_bridge; /* Pointer to bridge device */
static struct vme_dev *vme_user_bridge; /* Pointer to user device */


static const int type[VME_DEVS] = { MASTER_MINOR, MASTER_MINOR,
Expand All @@ -135,8 +135,8 @@ 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 long vme_user_unlocked_ioctl(struct file *, unsigned int, unsigned long);

static int __devinit vme_user_probe(struct device *, int, int);
static int __devexit vme_user_remove(struct device *, int, int);
static int __devinit vme_user_probe(struct vme_dev *);
static int __devexit vme_user_remove(struct vme_dev *);

static const struct file_operations vme_user_fops = {
.open = vme_user_open,
Expand Down Expand Up @@ -689,8 +689,7 @@ static int __init vme_user_init(void)
* as practical. We will therefore reserve the buffers and request the images
* here so that we don't have to do it later.
*/
static int __devinit vme_user_probe(struct device *dev, int cur_bus,
int cur_slot)
static int __devinit vme_user_probe(struct vme_dev *vdev)
{
int i, err;
char name[12];
Expand All @@ -702,7 +701,7 @@ static int __devinit vme_user_probe(struct device *dev, int cur_bus,
err = -EINVAL;
goto err_dev;
}
vme_user_bridge = dev;
vme_user_bridge = vdev;

/* Initialise descriptors */
for (i = 0; i < VME_DEVS; i++) {
Expand Down Expand Up @@ -865,8 +864,7 @@ static int __devinit vme_user_probe(struct device *dev, int cur_bus,
return err;
}

static int __devexit vme_user_remove(struct device *dev, int cur_bus,
int cur_slot)
static int __devexit vme_user_remove(struct vme_dev *dev)
{
int i;

Expand Down
128 changes: 52 additions & 76 deletions trunk/drivers/staging/vme/vme.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,9 @@ static DEFINE_MUTEX(vme_buses_lock);
static void __exit vme_exit(void);
static int __init vme_init(void);


/*
* Find the bridge resource associated with a specific device resource
*/
static struct vme_bridge *dev_to_bridge(struct device *dev)
static struct vme_dev *dev_to_vme_dev(struct device *dev)
{
return dev->platform_data;
return container_of(dev, struct vme_dev, dev);
}

/*
Expand Down Expand Up @@ -236,7 +232,7 @@ static int vme_check_window(vme_address_t aspace, unsigned long long vme_base,
* Request a slave image with specific attributes, return some unique
* identifier.
*/
struct vme_resource *vme_slave_request(struct device *dev,
struct vme_resource *vme_slave_request(struct vme_dev *vdev,
vme_address_t address, vme_cycle_t cycle)
{
struct vme_bridge *bridge;
Expand All @@ -245,7 +241,7 @@ struct vme_resource *vme_slave_request(struct device *dev,
struct vme_slave_resource *slave_image = NULL;
struct vme_resource *resource = NULL;

bridge = dev_to_bridge(dev);
bridge = vdev->bridge;
if (bridge == NULL) {
printk(KERN_ERR "Can't find VME bus\n");
goto err_bus;
Expand Down Expand Up @@ -392,7 +388,7 @@ EXPORT_SYMBOL(vme_slave_free);
* Request a master image with specific attributes, return some unique
* identifier.
*/
struct vme_resource *vme_master_request(struct device *dev,
struct vme_resource *vme_master_request(struct vme_dev *vdev,
vme_address_t address, vme_cycle_t cycle, vme_width_t dwidth)
{
struct vme_bridge *bridge;
Expand All @@ -401,7 +397,7 @@ struct vme_resource *vme_master_request(struct device *dev,
struct vme_master_resource *master_image = NULL;
struct vme_resource *resource = NULL;

bridge = dev_to_bridge(dev);
bridge = vdev->bridge;
if (bridge == NULL) {
printk(KERN_ERR "Can't find VME bus\n");
goto err_bus;
Expand Down Expand Up @@ -650,7 +646,8 @@ EXPORT_SYMBOL(vme_master_free);
* Request a DMA controller with specific attributes, return some unique
* identifier.
*/
struct vme_resource *vme_dma_request(struct device *dev, vme_dma_route_t route)
struct vme_resource *vme_dma_request(struct vme_dev *vdev,
vme_dma_route_t route)
{
struct vme_bridge *bridge;
struct list_head *dma_pos = NULL;
Expand All @@ -661,7 +658,7 @@ struct vme_resource *vme_dma_request(struct device *dev, vme_dma_route_t route)
/* XXX Not checking resource attributes */
printk(KERN_ERR "No VME resource Attribute tests done\n");

bridge = dev_to_bridge(dev);
bridge = vdev->bridge;
if (bridge == NULL) {
printk(KERN_ERR "Can't find VME bus\n");
goto err_bus;
Expand Down Expand Up @@ -994,13 +991,13 @@ void vme_irq_handler(struct vme_bridge *bridge, int level, int statid)
}
EXPORT_SYMBOL(vme_irq_handler);

int vme_irq_request(struct device *dev, int level, int statid,
int vme_irq_request(struct vme_dev *vdev, int level, int statid,
void (*callback)(int, int, void *),
void *priv_data)
{
struct vme_bridge *bridge;

bridge = dev_to_bridge(dev);
bridge = vdev->bridge;
if (bridge == NULL) {
printk(KERN_ERR "Can't find VME bus\n");
return -EINVAL;
Expand Down Expand Up @@ -1037,11 +1034,11 @@ int vme_irq_request(struct device *dev, int level, int statid,
}
EXPORT_SYMBOL(vme_irq_request);

void vme_irq_free(struct device *dev, int level, int statid)
void vme_irq_free(struct vme_dev *vdev, int level, int statid)
{
struct vme_bridge *bridge;

bridge = dev_to_bridge(dev);
bridge = vdev->bridge;
if (bridge == NULL) {
printk(KERN_ERR "Can't find VME bus\n");
return;
Expand Down Expand Up @@ -1072,11 +1069,11 @@ void vme_irq_free(struct device *dev, int level, int statid)
}
EXPORT_SYMBOL(vme_irq_free);

int vme_irq_generate(struct device *dev, int level, int statid)
int vme_irq_generate(struct vme_dev *vdev, int level, int statid)
{
struct vme_bridge *bridge;

bridge = dev_to_bridge(dev);
bridge = vdev->bridge;
if (bridge == NULL) {
printk(KERN_ERR "Can't find VME bus\n");
return -EINVAL;
Expand All @@ -1099,15 +1096,15 @@ EXPORT_SYMBOL(vme_irq_generate);
/*
* Request the location monitor, return resource or NULL
*/
struct vme_resource *vme_lm_request(struct device *dev)
struct vme_resource *vme_lm_request(struct vme_dev *vdev)
{
struct vme_bridge *bridge;
struct list_head *lm_pos = NULL;
struct vme_lm_resource *allocated_lm = NULL;
struct vme_lm_resource *lm = NULL;
struct vme_resource *resource = NULL;

bridge = dev_to_bridge(dev);
bridge = vdev->bridge;
if (bridge == NULL) {
printk(KERN_ERR "Can't find VME bus\n");
goto err_bus;
Expand Down Expand Up @@ -1288,11 +1285,11 @@ void vme_lm_free(struct vme_resource *resource)
}
EXPORT_SYMBOL(vme_lm_free);

int vme_slot_get(struct device *bus)
int vme_slot_get(struct vme_dev *vdev)
{
struct vme_bridge *bridge;

bridge = dev_to_bridge(bus);
bridge = vdev->bridge;
if (bridge == NULL) {
printk(KERN_ERR "Can't find VME bus\n");
return -EINVAL;
Expand Down Expand Up @@ -1340,12 +1337,12 @@ static void vme_remove_bus(struct vme_bridge *bridge)

static void vme_dev_release(struct device *dev)
{
kfree(dev);
kfree(dev_to_vme_dev(dev));
}

int vme_register_bridge(struct vme_bridge *bridge)
{
struct device *dev;
struct vme_dev *vdev;
int retval;
int i;

Expand All @@ -1358,38 +1355,41 @@ int vme_register_bridge(struct vme_bridge *bridge)
* specification.
*/
for (i = 0; i < VME_SLOTS_MAX; i++) {
bridge->dev[i] = kzalloc(sizeof(struct device), GFP_KERNEL);
bridge->dev[i] = kzalloc(sizeof(struct vme_dev), GFP_KERNEL);
if (!bridge->dev[i]) {
retval = -ENOMEM;
goto err_devalloc;
}
dev = bridge->dev[i];
memset(dev, 0, sizeof(struct device));

dev->parent = bridge->parent;
dev->bus = &vme_bus_type;
dev->release = vme_dev_release;
vdev = bridge->dev[i];
memset(vdev, 0, sizeof(struct vme_dev));

vdev->id.bus = bridge->num;
vdev->id.slot = i + 1;
vdev->bridge = bridge;
vdev->dev.parent = bridge->parent;
vdev->dev.bus = &vme_bus_type;
vdev->dev.release = vme_dev_release;
/*
* 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
*/
dev->platform_data = bridge;
dev_set_name(dev, "vme-%x.%x", bridge->num, i + 1);
vdev->dev.platform_data = bridge;
dev_set_name(&vdev->dev, "vme-%x.%x", bridge->num, i + 1);

retval = device_register(dev);
retval = device_register(&vdev->dev);
if (retval)
goto err_reg;
}

return retval;

err_reg:
kfree(dev);
kfree(vdev);
err_devalloc:
while (--i >= 0) {
dev = bridge->dev[i];
device_unregister(dev);
vdev = bridge->dev[i];
device_unregister(&vdev->dev);
}
vme_remove_bus(bridge);
return retval;
Expand All @@ -1399,12 +1399,12 @@ EXPORT_SYMBOL(vme_register_bridge);
void vme_unregister_bridge(struct vme_bridge *bridge)
{
int i;
struct device *dev;
struct vme_dev *vdev;


for (i = 0; i < VME_SLOTS_MAX; i++) {
dev = bridge->dev[i];
device_unregister(dev);
vdev = bridge->dev[i];
device_unregister(&vdev->dev);
}
vme_remove_bus(bridge);
}
Expand All @@ -1430,32 +1430,6 @@ EXPORT_SYMBOL(vme_unregister_driver);

/* - Bus Registration ------------------------------------------------------ */

static int vme_calc_slot(struct device *dev)
{
struct vme_bridge *bridge;
int num;

bridge = dev_to_bridge(dev);

/* Determine slot number */
num = 0;
while (num < VME_SLOTS_MAX) {
if (bridge->dev[num] == dev)
break;

num++;
}
if (num == VME_SLOTS_MAX) {
dev_err(dev, "Failed to identify slot\n");
num = 0;
goto err_dev;
}
num++;

err_dev:
return num;
}

static struct vme_driver *dev_to_vme_driver(struct device *dev)
{
if (dev->driver == NULL)
Expand All @@ -1466,15 +1440,17 @@ static struct vme_driver *dev_to_vme_driver(struct device *dev)

static int vme_bus_match(struct device *dev, struct device_driver *drv)
{
struct vme_dev *vdev;
struct vme_bridge *bridge;
struct vme_driver *driver;
int i, num;

bridge = dev_to_bridge(dev);
vdev = dev_to_vme_dev(dev);
bridge = vdev->bridge;
driver = container_of(drv, struct vme_driver, driver);

num = vme_calc_slot(dev);
if (!num)
num = vdev->id.slot;
if (num <= 0 || num >= VME_SLOTS_MAX)
goto err_dev;

if (driver->bind_table == NULL) {
Expand All @@ -1494,7 +1470,7 @@ static int vme_bus_match(struct device *dev, struct device_driver *drv)
return 1;

if ((driver->bind_table[i].slot == VME_SLOT_CURRENT) &&
(num == vme_slot_get(dev)))
(num == vme_slot_get(vdev)))
return 1;
}
i++;
Expand All @@ -1507,30 +1483,30 @@ static int vme_bus_match(struct device *dev, struct device_driver *drv)

static int vme_bus_probe(struct device *dev)
{
struct vme_bridge *bridge;
struct vme_driver *driver;
struct vme_dev *vdev;
int retval = -ENODEV;

driver = dev_to_vme_driver(dev);
bridge = dev_to_bridge(dev);
vdev = dev_to_vme_dev(dev);

if (driver->probe != NULL)
retval = driver->probe(dev, bridge->num, vme_calc_slot(dev));
retval = driver->probe(vdev);

return retval;
}

static int vme_bus_remove(struct device *dev)
{
struct vme_bridge *bridge;
struct vme_driver *driver;
struct vme_dev *vdev;
int retval = -ENODEV;

driver = dev_to_vme_driver(dev);
bridge = dev_to_bridge(dev);
vdev = dev_to_vme_dev(dev);

if (driver->remove != NULL)
retval = driver->remove(dev, bridge->num, vme_calc_slot(dev));
retval = driver->remove(vdev);

return retval;
}
Expand Down
Loading

0 comments on commit 82774fc

Please sign in to comment.