Commit a298bc0b authored by Don Zickus's avatar Don Zickus Committed by Greg Kroah-Hartman

staging: unisys: Convert device creation to use visor_device

This patch removes the legacy dev_info struct and instead creates
and passes around a traditional struct device.

This allows us to remove a lot of the various look up code and
removes the doubt if the struct exists or not.

Half of the churn is just the conversion of visorchipset_device_info
to visor_device.  Various cleanups include re-arranging the failure
paths to make more sense.

Pay attention to the create_visor_device function.  This had a lot of
churn to simplify everything.

Lots of functions disappeared because they are not needed any more.
Signed-off-by: default avatarDon Zickus <dzickus@redhat.com>
Signed-off-by: default avatarBenjamin Romer <benjamin.romer@unisys.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d32517e3
...@@ -43,7 +43,7 @@ struct visor_device; ...@@ -43,7 +43,7 @@ struct visor_device;
extern struct bus_type visorbus_type; extern struct bus_type visorbus_type;
typedef void (*visorbus_state_complete_func) (struct visor_device *dev, typedef void (*visorbus_state_complete_func) (struct visor_device *dev,
int status, void *dev_info); int status);
struct visorchipset_state { struct visorchipset_state {
u32 created:1; u32 created:1;
u32 attached:1; u32 attached:1;
...@@ -106,11 +106,9 @@ struct visor_driver { ...@@ -106,11 +106,9 @@ struct visor_driver {
* fails or completes successfully. * fails or completes successfully.
*/ */
int (*pause)(struct visor_device *dev, int (*pause)(struct visor_device *dev,
visorbus_state_complete_func complete_func, visorbus_state_complete_func complete_func);
void *dev_info);
int (*resume)(struct visor_device *dev, int (*resume)(struct visor_device *dev,
visorbus_state_complete_func complete_func, visorbus_state_complete_func complete_func);
void *dev_info);
/** These fields are for private use by the bus driver only. */ /** These fields are for private use by the bus driver only. */
struct device_driver driver; struct device_driver driver;
......
...@@ -95,10 +95,10 @@ static long long bus_count; /** number of bus instances */ ...@@ -95,10 +95,10 @@ static long long bus_count; /** number of bus instances */
static void chipset_bus_create(struct visor_device *bus_info); static void chipset_bus_create(struct visor_device *bus_info);
static void chipset_bus_destroy(struct visor_device *bus_info); static void chipset_bus_destroy(struct visor_device *bus_info);
static void chipset_device_create(struct visorchipset_device_info *dev_info); static void chipset_device_create(struct visor_device *dev_info);
static void chipset_device_destroy(struct visorchipset_device_info *dev_info); static void chipset_device_destroy(struct visor_device *dev_info);
static void chipset_device_pause(struct visorchipset_device_info *dev_info); static void chipset_device_pause(struct visor_device *dev_info);
static void chipset_device_resume(struct visorchipset_device_info *dev_info); static void chipset_device_resume(struct visor_device *dev_info);
/** These functions are implemented herein, and are called by the chipset /** These functions are implemented herein, and are called by the chipset
* driver to notify us about specific events. * driver to notify us about specific events.
...@@ -184,7 +184,6 @@ visorbus_release_busdevice(struct device *xdev) ...@@ -184,7 +184,6 @@ visorbus_release_busdevice(struct device *xdev)
dev_set_drvdata(xdev, NULL); dev_set_drvdata(xdev, NULL);
kfree(dev); kfree(dev);
kfree(xdev);
} }
/** This is called when device_unregister() is called for each child /** This is called when device_unregister() is called for each child
...@@ -754,17 +753,10 @@ visordriver_probe_device(struct device *xdev) ...@@ -754,17 +753,10 @@ visordriver_probe_device(struct device *xdev)
* initialized. * initialized.
*/ */
if (!dev->responded_to_device_create) { if (!dev->responded_to_device_create) {
struct visorchipset_device_info dev_info;
if (!visorchipset_get_device_info(dev->chipset_bus_no,
dev->chipset_dev_no,
&dev_info))
/* hmm, what to do here */
return rc;
dev->responded_to_device_create = true; dev->responded_to_device_create = true;
if (chipset_responders.device_create) if (chipset_responders.device_create)
(*chipset_responders.device_create)(&dev_info, rc); (*chipset_responders.device_create)(dev, rc);
} }
return rc; return rc;
} }
...@@ -949,30 +941,15 @@ EXPORT_SYMBOL_GPL(visorbus_disable_channel_interrupts); ...@@ -949,30 +941,15 @@ EXPORT_SYMBOL_GPL(visorbus_disable_channel_interrupts);
* device. * device.
*/ */
static int static int
create_visor_device(struct visor_device *bdev, create_visor_device(struct visor_device *dev)
struct visorchipset_device_info *dev_info)
{ {
int rc = -1; int rc = -1;
struct visor_device *dev = NULL; u32 chipset_bus_no = dev->chipset_bus_no;
bool gotten = false, registered1 = false, registered2 = false; u32 chipset_dev_no = dev->chipset_dev_no;
u32 chipset_bus_no = dev_info->bus_no;
u32 chipset_dev_no = dev_info->dev_no;
POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, chipset_dev_no, chipset_bus_no, POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, chipset_dev_no, chipset_bus_no,
POSTCODE_SEVERITY_INFO); POSTCODE_SEVERITY_INFO);
dev = kmalloc(sizeof(*dev), GFP_KERNEL);
if (!dev) {
POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no,
DIAG_SEVERITY_ERR);
goto away;
}
memset(dev, 0, sizeof(struct visor_device));
dev->visorchannel = dev_info->visorchannel;
dev->channel_type_guid = dev_info->channel_type_guid;
dev->chipset_bus_no = chipset_bus_no;
dev->chipset_dev_no = chipset_dev_no;
dev->device.parent = &bdev->device;
sema_init(&dev->visordriver_callback_lock, 1); /* unlocked */ sema_init(&dev->visordriver_callback_lock, 1); /* unlocked */
dev->device.bus = &visorbus_type; dev->device.bus = &visorbus_type;
dev->device.groups = visorbus_dev_groups; dev->device.groups = visorbus_dev_groups;
...@@ -980,7 +957,6 @@ create_visor_device(struct visor_device *bdev, ...@@ -980,7 +957,6 @@ create_visor_device(struct visor_device *bdev,
dev->device.release = visorbus_release_device; dev->device.release = visorbus_release_device;
/* keep a reference just for us (now 2) */ /* keep a reference just for us (now 2) */
get_device(&dev->device); get_device(&dev->device);
gotten = true;
dev->periodic_work = dev->periodic_work =
visor_periodic_work_create(POLLJIFFIES_NORMALCHANNEL, visor_periodic_work_create(POLLJIFFIES_NORMALCHANNEL,
periodic_dev_workqueue, periodic_dev_workqueue,
...@@ -1022,29 +998,20 @@ create_visor_device(struct visor_device *bdev, ...@@ -1022,29 +998,20 @@ create_visor_device(struct visor_device *bdev,
goto away; goto away;
} }
/* note: device_register is simply device_initialize + device_add */
registered1 = true;
rc = register_devmajorminor_attributes(dev); rc = register_devmajorminor_attributes(dev);
if (rc < 0) { if (rc < 0) {
POSTCODE_LINUX_3(DEVICE_REGISTER_FAILURE_PC, chipset_dev_no, POSTCODE_LINUX_3(DEVICE_REGISTER_FAILURE_PC, chipset_dev_no,
DIAG_SEVERITY_ERR); DIAG_SEVERITY_ERR);
goto away; goto away_register;
} }
registered2 = true; list_add_tail(&dev->list_all, &list_all_device_instances);
rc = 0; return 0;
away_register:
device_unregister(&dev->device);
away: away:
if (rc < 0) { put_device(&dev->device);
if (registered2)
unregister_devmajorminor_attributes(dev);
if (gotten)
put_device(&dev->device);
kfree(dev);
} else {
list_add_tail(&dev->list_all, &list_all_device_instances);
}
return rc; return rc;
} }
...@@ -1057,21 +1024,6 @@ remove_visor_device(struct visor_device *dev) ...@@ -1057,21 +1024,6 @@ remove_visor_device(struct visor_device *dev)
device_unregister(&dev->device); device_unregister(&dev->device);
} }
static struct visor_device *
find_visor_device_by_channel(struct visorchannel *channel)
{
struct list_head *listentry, *listtmp;
list_for_each_safe(listentry, listtmp, &list_all_device_instances) {
struct visor_device *dev = list_entry(listentry,
struct visor_device,
list_all);
if (dev->visorchannel == channel)
return dev;
}
return NULL;
}
static int static int
get_vbus_header_info(struct visorchannel *chan, get_vbus_header_info(struct visorchannel *chan,
struct spar_vbus_headerinfo *hdr_info) struct spar_vbus_headerinfo *hdr_info)
...@@ -1344,25 +1296,16 @@ chipset_bus_destroy(struct visor_device *dev) ...@@ -1344,25 +1296,16 @@ chipset_bus_destroy(struct visor_device *dev)
} }
static void static void
chipset_device_create(struct visorchipset_device_info *dev_info) chipset_device_create(struct visor_device *dev_info)
{ {
struct visor_device *bdev;
int rc = -1; int rc = -1;
u32 bus_no = dev_info->bus_no; u32 bus_no = dev_info->chipset_bus_no;
u32 dev_no = dev_info->dev_no; u32 dev_no = dev_info->chipset_dev_no;
POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no, POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, dev_no, bus_no,
POSTCODE_SEVERITY_INFO); POSTCODE_SEVERITY_INFO);
bdev = visorbus_get_device_by_id(bus_no, BUS_ROOT_DEVICE, NULL); rc = create_visor_device(dev_info);
if (!bdev)
goto away;
POSTCODE_LINUX_4(DEVICE_CREATE_EXIT_PC, dev_no, bus_no,
POSTCODE_SEVERITY_INFO);
rc = create_visor_device(bdev, dev_info);
away:
if (rc < 0) { if (rc < 0) {
POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no, POSTCODE_LINUX_4(DEVICE_CREATE_FAILURE_PC, dev_no, bus_no,
POSTCODE_SEVERITY_ERR); POSTCODE_SEVERITY_ERR);
...@@ -1375,22 +1318,12 @@ chipset_device_create(struct visorchipset_device_info *dev_info) ...@@ -1375,22 +1318,12 @@ chipset_device_create(struct visorchipset_device_info *dev_info)
} }
static void static void
chipset_device_destroy(struct visorchipset_device_info *dev_info) chipset_device_destroy(struct visor_device *dev_info)
{ {
struct visor_device *dev; remove_visor_device(dev_info);
int rc = -1;
dev = find_visor_device_by_channel(dev_info->visorchannel);
if (!dev)
goto away;
rc = 0;
away:
if (rc < 0)
return;
if (chipset_responders.device_destroy) if (chipset_responders.device_destroy)
(*chipset_responders.device_destroy) (dev_info, rc); (*chipset_responders.device_destroy) (dev_info, 0);
remove_visor_device(dev);
} }
/* This is the callback function specified for a function driver, to /* This is the callback function specified for a function driver, to
...@@ -1398,11 +1331,8 @@ chipset_device_destroy(struct visorchipset_device_info *dev_info) ...@@ -1398,11 +1331,8 @@ chipset_device_destroy(struct visorchipset_device_info *dev_info)
* completed. * completed.
*/ */
static void static void
pause_state_change_complete(struct visor_device *dev, int status, pause_state_change_complete(struct visor_device *dev, int status)
void *info)
{ {
struct visorchipset_device_info *dev_info = info;
if (!dev->pausing) if (!dev->pausing)
return; return;
...@@ -1413,7 +1343,7 @@ pause_state_change_complete(struct visor_device *dev, int status, ...@@ -1413,7 +1343,7 @@ pause_state_change_complete(struct visor_device *dev, int status,
/* Notify the chipset driver that the pause is complete, which /* Notify the chipset driver that the pause is complete, which
* will presumably want to send some sort of response to the * will presumably want to send some sort of response to the
* initiator. */ * initiator. */
(*chipset_responders.device_pause) (dev_info, status); (*chipset_responders.device_pause) (dev, status);
} }
/* This is the callback function specified for a function driver, to /* This is the callback function specified for a function driver, to
...@@ -1421,11 +1351,8 @@ pause_state_change_complete(struct visor_device *dev, int status, ...@@ -1421,11 +1351,8 @@ pause_state_change_complete(struct visor_device *dev, int status,
* completed. * completed.
*/ */
static void static void
resume_state_change_complete(struct visor_device *dev, int status, resume_state_change_complete(struct visor_device *dev, int status)
void *info)
{ {
struct visorchipset_device_info *dev_info = info;
if (!dev->resuming) if (!dev->resuming)
return; return;
...@@ -1436,7 +1363,7 @@ resume_state_change_complete(struct visor_device *dev, int status, ...@@ -1436,7 +1363,7 @@ resume_state_change_complete(struct visor_device *dev, int status,
/* Notify the chipset driver that the resume is complete, /* Notify the chipset driver that the resume is complete,
* which will presumably want to send some sort of response to * which will presumably want to send some sort of response to
* the initiator. */ * the initiator. */
(*chipset_responders.device_resume) (dev_info, status); (*chipset_responders.device_resume) (dev, status);
} }
/* Tell the subordinate function driver for a specific device to pause /* Tell the subordinate function driver for a specific device to pause
...@@ -1444,14 +1371,11 @@ resume_state_change_complete(struct visor_device *dev, int status, ...@@ -1444,14 +1371,11 @@ resume_state_change_complete(struct visor_device *dev, int status,
* callback function. * callback function.
*/ */
static void static void
initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info, initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
bool is_pause)
{ {
struct visor_device *dev = NULL;
int rc = -1, x; int rc = -1, x;
struct visor_driver *drv = NULL; struct visor_driver *drv = NULL;
void (*notify_func)(struct visorchipset_device_info *dev_info, void (*notify_func)(struct visor_device *dev, int response) = NULL;
int response) = NULL;
if (is_pause) if (is_pause)
notify_func = chipset_responders.device_pause; notify_func = chipset_responders.device_pause;
...@@ -1460,10 +1384,6 @@ initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info, ...@@ -1460,10 +1384,6 @@ initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info,
if (!notify_func) if (!notify_func)
goto away; goto away;
dev = find_visor_device_by_channel(dev_info->visorchannel);
if (!dev)
goto away;
drv = to_visor_driver(dev->device.driver); drv = to_visor_driver(dev->device.driver);
if (!drv) if (!drv)
goto away; goto away;
...@@ -1483,8 +1403,7 @@ initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info, ...@@ -1483,8 +1403,7 @@ initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info,
goto away; goto away;
dev->pausing = true; dev->pausing = true;
x = drv->pause(dev, pause_state_change_complete, x = drv->pause(dev, pause_state_change_complete);
(void *)dev_info);
} else { } else {
/* This should be done at BUS resume time, but an /* This should be done at BUS resume time, but an
* existing problem prevents us from ever getting a bus * existing problem prevents us from ever getting a bus
...@@ -1496,8 +1415,7 @@ initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info, ...@@ -1496,8 +1415,7 @@ initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info,
goto away; goto away;
dev->resuming = true; dev->resuming = true;
x = drv->resume(dev, resume_state_change_complete, x = drv->resume(dev, resume_state_change_complete);
(void *)dev_info);
} }
if (x < 0) { if (x < 0) {
if (is_pause) if (is_pause)
...@@ -1510,18 +1428,18 @@ initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info, ...@@ -1510,18 +1428,18 @@ initiate_chipset_device_pause_resume(struct visorchipset_device_info *dev_info,
away: away:
if (rc < 0) { if (rc < 0) {
if (notify_func) if (notify_func)
(*notify_func)(dev_info, rc); (*notify_func)(dev, rc);
} }
} }
static void static void
chipset_device_pause(struct visorchipset_device_info *dev_info) chipset_device_pause(struct visor_device *dev_info)
{ {
initiate_chipset_device_pause_resume(dev_info, true); initiate_chipset_device_pause_resume(dev_info, true);
} }
static void static void
chipset_device_resume(struct visorchipset_device_info *dev_info) chipset_device_resume(struct visor_device *dev_info)
{ {
initiate_chipset_device_pause_resume(dev_info, false); initiate_chipset_device_pause_resume(dev_info, false);
} }
......
...@@ -20,35 +20,10 @@ ...@@ -20,35 +20,10 @@
#include <linux/uuid.h> #include <linux/uuid.h>
#include "channel.h"
#include "controlvmchannel.h" #include "controlvmchannel.h"
#include "vbusdeviceinfo.h" #include "vbusdeviceinfo.h"
#include "vbushelper.h" #include "vbushelper.h"
struct visorchannel;
/** Attributes for a particular Supervisor device.
* Any visorchipset client can query these attributes using
* visorchipset_get_client_device_info() or
* visorchipset_get_server_device_info().
*/
struct visorchipset_device_info {
struct list_head entry;
u32 bus_no;
u32 dev_no;
uuid_le dev_inst_uuid;
struct visorchipset_state state;
struct visorchannel *visorchannel;
uuid_le channel_type_guid;
u32 reserved1; /* control_vm_id */
u64 reserved2;
u32 switch_no; /* when devState.attached==1 */
u32 internal_port_no; /* when devState.attached==1 */
struct controlvm_message_header *pending_msg_hdr;/* CONTROLVM_MESSAGE */
/** For private use by the bus driver */
void *bus_driver_context;
};
/* These functions will be called from within visorchipset when certain /* These functions will be called from within visorchipset when certain
* events happen. (The implementation of these functions is outside of * events happen. (The implementation of these functions is outside of
* visorchipset.) * visorchipset.)
...@@ -56,10 +31,10 @@ struct visorchipset_device_info { ...@@ -56,10 +31,10 @@ struct visorchipset_device_info {
struct visorchipset_busdev_notifiers { struct visorchipset_busdev_notifiers {
void (*bus_create)(struct visor_device *bus_info); void (*bus_create)(struct visor_device *bus_info);
void (*bus_destroy)(struct visor_device *bus_info); void (*bus_destroy)(struct visor_device *bus_info);
void (*device_create)(struct visorchipset_device_info *bus_info); void (*device_create)(struct visor_device *bus_info);
void (*device_destroy)(struct visorchipset_device_info *bus_info); void (*device_destroy)(struct visor_device *bus_info);
void (*device_pause)(struct visorchipset_device_info *bus_info); void (*device_pause)(struct visor_device *bus_info);
void (*device_resume)(struct visorchipset_device_info *bus_info); void (*device_resume)(struct visor_device *bus_info);
}; };
/* These functions live inside visorchipset, and will be called to indicate /* These functions live inside visorchipset, and will be called to indicate
...@@ -71,11 +46,10 @@ struct visorchipset_busdev_notifiers { ...@@ -71,11 +46,10 @@ struct visorchipset_busdev_notifiers {
struct visorchipset_busdev_responders { struct visorchipset_busdev_responders {
void (*bus_create)(struct visor_device *p, int response); void (*bus_create)(struct visor_device *p, int response);
void (*bus_destroy)(struct visor_device *p, int response); void (*bus_destroy)(struct visor_device *p, int response);
void (*device_create)(struct visorchipset_device_info *p, int response); void (*device_create)(struct visor_device *p, int response);
void (*device_destroy)(struct visorchipset_device_info *p, void (*device_destroy)(struct visor_device *p, int response);
int response); void (*device_pause)(struct visor_device *p, int response);
void (*device_pause)(struct visorchipset_device_info *p, int response); void (*device_resume)(struct visor_device *p, int response);
void (*device_resume)(struct visorchipset_device_info *p, int response);
}; };
/** Register functions (in the bus driver) to get called by visorchipset /** Register functions (in the bus driver) to get called by visorchipset
...@@ -89,13 +63,6 @@ visorchipset_register_busdev( ...@@ -89,13 +63,6 @@ visorchipset_register_busdev(
struct visorchipset_busdev_responders *responders, struct visorchipset_busdev_responders *responders,
struct ultra_vbus_deviceinfo *driver_info); struct ultra_vbus_deviceinfo *driver_info);
bool visorchipset_get_bus_info(u32 bus_no,
struct visor_device *bus_info);
bool visorchipset_get_device_info(u32 bus_no, u32 dev_no,
struct visorchipset_device_info *dev_info);
bool visorchipset_set_bus_context(struct visor_device *bus_info,
void *context);
/* visorbus init and exit functions */ /* visorbus init and exit functions */
int visorbus_init(void); int visorbus_init(void);
void visorbus_exit(void); void visorbus_exit(void);
......
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