Commit 71d276d7 authored by Stephen Rothwell's avatar Stephen Rothwell Committed by Paul Mackerras

[PATCH] Create vio_bus_ops

Create vio_bus_ops so that we just pass a structure to vio_bus_init
instead of three separate function pointers.

Rearrange vio.h to avoid forward references. vio.h only needs
struct device_node from prom.h so remove the include and just
declare it.
Signed-off-by: default avatarStephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent b877b90f
...@@ -131,6 +131,10 @@ static int vio_match_device_iseries(const struct vio_device_id *id, ...@@ -131,6 +131,10 @@ static int vio_match_device_iseries(const struct vio_device_id *id,
return strncmp(dev->type, id->type, strlen(id->type)) == 0; return strncmp(dev->type, id->type, strlen(id->type)) == 0;
} }
static struct vio_bus_ops vio_bus_ops_iseries = {
.match = vio_match_device_iseries,
};
/** /**
* vio_bus_init_iseries: - Initialize the iSeries virtual IO bus * vio_bus_init_iseries: - Initialize the iSeries virtual IO bus
*/ */
...@@ -138,7 +142,7 @@ static int __init vio_bus_init_iseries(void) ...@@ -138,7 +142,7 @@ static int __init vio_bus_init_iseries(void)
{ {
int err; int err;
err = vio_bus_init(vio_match_device_iseries, NULL, NULL); err = vio_bus_init(&vio_bus_ops_iseries);
if (err == 0) { if (err == 0) {
iommu_vio_init(); iommu_vio_init();
vio_bus_device.iommu_table = &vio_iommu_table; vio_bus_device.iommu_table = &vio_iommu_table;
......
...@@ -76,6 +76,12 @@ static void vio_unregister_device_pseries(struct vio_dev *viodev) ...@@ -76,6 +76,12 @@ static void vio_unregister_device_pseries(struct vio_dev *viodev)
device_remove_file(&viodev->dev, &dev_attr_devspec); device_remove_file(&viodev->dev, &dev_attr_devspec);
} }
static struct vio_bus_ops vio_bus_ops_pseries = {
.match = vio_match_device_pseries,
.unregister_device = vio_unregister_device_pseries,
.release_device = vio_release_device_pseries,
};
/** /**
* vio_bus_init_pseries: - Initialize the pSeries virtual IO bus * vio_bus_init_pseries: - Initialize the pSeries virtual IO bus
*/ */
...@@ -83,9 +89,7 @@ static int __init vio_bus_init_pseries(void) ...@@ -83,9 +89,7 @@ static int __init vio_bus_init_pseries(void)
{ {
int err; int err;
err = vio_bus_init(vio_match_device_pseries, err = vio_bus_init(&vio_bus_ops_pseries);
vio_unregister_device_pseries,
vio_release_device_pseries);
if (err == 0) if (err == 0)
probe_bus_pseries(); probe_bus_pseries();
return err; return err;
......
...@@ -32,10 +32,7 @@ struct vio_dev vio_bus_device = { /* fake "parent" device */ ...@@ -32,10 +32,7 @@ struct vio_dev vio_bus_device = { /* fake "parent" device */
.dev.bus = &vio_bus_type, .dev.bus = &vio_bus_type,
}; };
static int (*is_match)(const struct vio_device_id *id, static struct vio_bus_ops vio_bus_ops;
const struct vio_dev *dev);
static void (*unregister_device_callback)(struct vio_dev *dev);
static void (*release_device_callback)(struct device *dev);
/* /*
* Convert from struct device to struct vio_dev and pass to driver. * Convert from struct device to struct vio_dev and pass to driver.
...@@ -115,7 +112,7 @@ static const struct vio_device_id *vio_match_device( ...@@ -115,7 +112,7 @@ static const struct vio_device_id *vio_match_device(
const struct vio_device_id *ids, const struct vio_dev *dev) const struct vio_device_id *ids, const struct vio_dev *dev)
{ {
while (ids->type) { while (ids->type) {
if (is_match(ids, dev)) if (vio_bus_ops.match(ids, dev))
return ids; return ids;
ids++; ids++;
} }
...@@ -125,16 +122,11 @@ static const struct vio_device_id *vio_match_device( ...@@ -125,16 +122,11 @@ static const struct vio_device_id *vio_match_device(
/** /**
* vio_bus_init: - Initialize the virtual IO bus * vio_bus_init: - Initialize the virtual IO bus
*/ */
int __init vio_bus_init(int (*match_func)(const struct vio_device_id *id, int __init vio_bus_init(struct vio_bus_ops *ops)
const struct vio_dev *dev),
void (*unregister_dev)(struct vio_dev *),
void (*release_dev)(struct device *))
{ {
int err; int err;
is_match = match_func; vio_bus_ops = *ops;
unregister_device_callback = unregister_dev;
release_device_callback = release_dev;
err = bus_register(&vio_bus_type); err = bus_register(&vio_bus_type);
if (err) { if (err) {
...@@ -159,8 +151,8 @@ int __init vio_bus_init(int (*match_func)(const struct vio_device_id *id, ...@@ -159,8 +151,8 @@ int __init vio_bus_init(int (*match_func)(const struct vio_device_id *id,
/* vio_dev refcount hit 0 */ /* vio_dev refcount hit 0 */
static void __devinit vio_dev_release(struct device *dev) static void __devinit vio_dev_release(struct device *dev)
{ {
if (release_device_callback) if (vio_bus_ops.release_device)
release_device_callback(dev); vio_bus_ops.release_device(dev);
kfree(to_vio_dev(dev)); kfree(to_vio_dev(dev));
} }
...@@ -191,8 +183,8 @@ struct vio_dev * __devinit vio_register_device(struct vio_dev *viodev) ...@@ -191,8 +183,8 @@ struct vio_dev * __devinit vio_register_device(struct vio_dev *viodev)
void __devinit vio_unregister_device(struct vio_dev *viodev) void __devinit vio_unregister_device(struct vio_dev *viodev)
{ {
if (unregister_device_callback) if (vio_bus_ops.unregister_device)
unregister_device_callback(viodev); vio_bus_ops.unregister_device(viodev);
device_remove_file(&viodev->dev, &dev_attr_name); device_remove_file(&viodev->dev, &dev_attr_name);
device_unregister(&viodev->dev); device_unregister(&viodev->dev);
} }
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
*/ */
#include <asm/vio.h> #include <asm/vio.h>
#include <asm/prom.h>
#include <asm/iommu.h> #include <asm/iommu.h>
#include <asm/hvcall.h> #include <asm/hvcall.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
......
...@@ -19,13 +19,14 @@ ...@@ -19,13 +19,14 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <asm/hvcall.h> #include <asm/hvcall.h>
#include <asm/prom.h>
#include <asm/scatterlist.h> #include <asm/scatterlist.h>
/*
/*
* Architecture-specific constants for drivers to * Architecture-specific constants for drivers to
* extract attributes of the device using vio_get_attribute() * extract attributes of the device using vio_get_attribute()
*/ */
#define VETH_MAC_ADDR "local-mac-address" #define VETH_MAC_ADDR "local-mac-address"
#define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters" #define VETH_MCAST_FILTER_SIZE "ibm,mac-address-filters"
...@@ -37,30 +38,19 @@ ...@@ -37,30 +38,19 @@
#define VIO_IRQ_DISABLE 0UL #define VIO_IRQ_DISABLE 0UL
#define VIO_IRQ_ENABLE 1UL #define VIO_IRQ_ENABLE 1UL
struct vio_dev;
struct vio_driver;
struct vio_device_id;
struct iommu_table; struct iommu_table;
int vio_register_driver(struct vio_driver *drv); /*
void vio_unregister_driver(struct vio_driver *drv); * The vio_dev structure is used to describe virtual I/O devices.
*/
#ifdef CONFIG_PPC_PSERIES struct vio_dev {
struct vio_dev * __devinit vio_register_device_node( struct iommu_table *iommu_table; /* vio_map_* uses this */
struct device_node *node_vdev); char *name;
#endif char *type;
void __devinit vio_unregister_device(struct vio_dev *dev); uint32_t unit_address;
struct vio_dev *vio_find_node(struct device_node *vnode); unsigned int irq;
struct device dev;
const void * vio_get_attribute(struct vio_dev *vdev, void* which, int* length); };
int vio_get_irq(struct vio_dev *dev);
int vio_enable_interrupts(struct vio_dev *dev);
int vio_disable_interrupts(struct vio_dev *dev);
extern struct vio_dev * __devinit vio_register_device(struct vio_dev *viodev);
extern struct dma_mapping_ops vio_dma_ops;
extern struct bus_type vio_bus_type;
struct vio_device_id { struct vio_device_id {
char *type; char *type;
...@@ -70,42 +60,51 @@ struct vio_device_id { ...@@ -70,42 +60,51 @@ struct vio_device_id {
struct vio_driver { struct vio_driver {
struct list_head node; struct list_head node;
char *name; char *name;
const struct vio_device_id *id_table; /* NULL if wants all devices */ const struct vio_device_id *id_table;
int (*probe) (struct vio_dev *dev, const struct vio_device_id *id); /* New device inserted */ int (*probe)(struct vio_dev *dev, const struct vio_device_id *id);
int (*remove) (struct vio_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */ int (*remove)(struct vio_dev *dev);
unsigned long driver_data; unsigned long driver_data;
struct device_driver driver; struct device_driver driver;
}; };
struct vio_bus_ops {
int (*match)(const struct vio_device_id *id, const struct vio_dev *dev);
void (*unregister_device)(struct vio_dev *);
void (*release_device)(struct device *);
};
extern struct dma_mapping_ops vio_dma_ops;
extern struct bus_type vio_bus_type;
extern struct vio_dev vio_bus_device;
extern int vio_register_driver(struct vio_driver *drv);
extern void vio_unregister_driver(struct vio_driver *drv);
extern struct vio_dev * __devinit vio_register_device(struct vio_dev *viodev);
extern void __devinit vio_unregister_device(struct vio_dev *dev);
extern int vio_bus_init(struct vio_bus_ops *);
#ifdef CONFIG_PPC_PSERIES
struct device_node;
extern struct vio_dev * __devinit vio_register_device_node(
struct device_node *node_vdev);
extern struct vio_dev *vio_find_node(struct device_node *vnode);
extern const void *vio_get_attribute(struct vio_dev *vdev, void *which,
int *length);
extern int vio_enable_interrupts(struct vio_dev *dev);
extern int vio_disable_interrupts(struct vio_dev *dev);
#endif
static inline struct vio_driver *to_vio_driver(struct device_driver *drv) static inline struct vio_driver *to_vio_driver(struct device_driver *drv)
{ {
return container_of(drv, struct vio_driver, driver); return container_of(drv, struct vio_driver, driver);
} }
/*
* The vio_dev structure is used to describe virtual I/O devices.
*/
struct vio_dev {
struct iommu_table *iommu_table; /* vio_map_* uses this */
char *name;
char *type;
uint32_t unit_address;
unsigned int irq;
struct device dev;
};
extern struct vio_dev vio_bus_device;
static inline struct vio_dev *to_vio_dev(struct device *dev) static inline struct vio_dev *to_vio_dev(struct device *dev)
{ {
return container_of(dev, struct vio_dev, dev); return container_of(dev, struct vio_dev, dev);
} }
extern int vio_bus_init(int (*is_match)(const struct vio_device_id *id,
const struct vio_dev *dev),
void (*)(struct vio_dev *),
void (*)(struct device *));
#endif /* _ASM_VIO_H */ #endif /* _ASM_VIO_H */
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