Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[CORE] vmm_devdrv: Adding vmm_devdrv_bus_find_device() function.

Adding linux-like vmm_devdrv_bus_find_device() function to find
a device on a bus by providing a match function.

Signed-off-by: Pranav Sawargaonkar <pranav.sawargaonkar@gmail.com>
  • Loading branch information...
commit f86ca3e712371979d4e676d091ca2172930d45cb 1 parent 746012d
@psawargaonkar psawargaonkar authored avpatel committed
View
4 core/include/vmm_devdrv.h
@@ -161,6 +161,10 @@ int vmm_devdrv_bus_register_device(struct vmm_bus *bus,
int vmm_devdrv_bus_unregister_device(struct vmm_bus *bus,
struct vmm_device *dev);
+/** Find device on a bus */
+struct vmm_device *vmm_devdrv_bus_find_device(struct vmm_bus *bus,
+ void *data, int (*match) (struct vmm_device *, void *));
+
/** Find device on a bus by name */
struct vmm_device *vmm_devdrv_bus_find_device_by_name(struct vmm_bus *bus,
const char *dname);
View
33 core/vmm_devdrv.c
@@ -1006,6 +1006,39 @@ int vmm_devdrv_bus_unregister_device(struct vmm_bus *bus,
return VMM_OK;
}
+struct vmm_device *vmm_devdrv_bus_find_device(struct vmm_bus *bus,
+ void *data, int (*match) (struct vmm_device *, void *))
+{
+ bool found;
+ struct dlist *l;
+ struct vmm_device *dev;
+
+ if (!bus || !match) {
+ return NULL;
+ }
+
+ found = FALSE;
+ dev = NULL;
+
+ vmm_mutex_lock(&bus->lock);
+
+ list_for_each(l, &bus->device_list) {
+ dev = list_entry(l, struct vmm_device, bus_head);
+ if (match(dev, data)) {
+ found = TRUE;
+ break;
+ }
+ }
+
+ vmm_mutex_unlock(&bus->lock);
+
+ if (!found) {
+ return NULL;
+ }
+
+ return dev;
+}
+
struct vmm_device *vmm_devdrv_bus_find_device_by_name(struct vmm_bus *bus,
const char *dname)
{
View
9 drivers/include/linux/device.h
@@ -45,6 +45,15 @@
#define dev_get_drvdata(dev) vmm_devdrv_get_data(dev)
#define dev_set_drvdata(dev, data) vmm_devdrv_set_data(dev, data)
+static inline struct device *bus_find_device(struct bus_type *bus,
+ struct device *start,
+ void *data,
+ int (*match) (struct device *, void *))
+{
+ return vmm_devdrv_bus_find_device(bus, data, match);
+
+}
+
static inline struct device *bus_find_device_by_name(struct bus_type *bus,
struct device *start,
const char *name)
Please sign in to comment.
Something went wrong with that request. Please try again.