From ab0592b9fb9b933f97b3795d21ce4356035aead8 Mon Sep 17 00:00:00 2001 From: Don Zickus Date: Wed, 13 May 2015 13:22:19 -0400 Subject: [PATCH] staging: unisys: Add visor device find routine If we are going to remove the bus_info structs than we need a way to find the devices when the *_create/destroy cmds are sent over the vmchannel. This function crudely impements what pci has. It takes a bus_no and dev_no and finds the matching 'struct visor_device'. This function can/should be optimzed later once we get our heads wrapped around its needs. For now, I am using dev_no=0 to mean the visorbus itself. The function is limited to chipset.c only because it is only needed to do the lookups upon receiving a vmchannel command. Future patches will make sure the resulting 'struct visor_device' is used every where else. Also allow visorbus_type to be more visible for use. Signed-off-by: Don Zickus Signed-off-by: Benjamin Romer Signed-off-by: Greg Kroah-Hartman --- .../staging/unisys/visorbus/visorchipset.c | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/staging/unisys/visorbus/visorchipset.c b/drivers/staging/unisys/visorbus/visorchipset.c index b96a40cf9124..42bf02afb807 100644 --- a/drivers/staging/unisys/visorbus/visorchipset.c +++ b/drivers/staging/unisys/visorbus/visorchipset.c @@ -711,6 +711,45 @@ dev_info_clear(void *v) memset(p, 0, sizeof(struct visorchipset_device_info)); } +struct visor_busdev { + u32 bus_no; + u32 dev_no; +}; + +static int match_visorbus_dev_by_id(struct device *dev, void *data) +{ + struct visor_device *vdev = to_visor_device(dev); + struct visor_busdev *id = (struct visor_busdev *)data; + u32 bus_no = id->bus_no; + u32 dev_no = id->dev_no; + + if (((bus_no == -1) || (vdev->chipset_bus_no == bus_no)) && + ((dev_no == -1) || (vdev->chipset_dev_no == dev_no))) + return 1; + + return 0; +} +struct visor_device *visorbus_get_device_by_id(u32 bus_no, u32 dev_no, + struct visor_device *from) +{ + struct device *dev; + struct device *dev_start = NULL; + struct visor_device *vdev = NULL; + struct visor_busdev id = { + .bus_no = bus_no, + .dev_no = dev_no + }; + + if (from) + dev_start = &from->device; + dev = bus_find_device(&visorbus_type, dev_start, (void *)&id, + match_visorbus_dev_by_id); + if (dev) + vdev = to_visor_device(dev); + return vdev; +} +EXPORT_SYMBOL(visorbus_get_device_by_id); + static struct visorchipset_bus_info * bus_find(struct list_head *list, u32 bus_no) { -- 2.34.1