[PATCH 128/141] staging: unisys: Convert the bus/device creation to visor_device

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Don Zickus <dzickus@xxxxxxxxxx>

The next layer is the bus/device creation to be converted over to
struct visor_device.  Again because memory was allocated already
and the channel created, the code is simplified.  No lookups,
very few sanity checks.

Eventually most of these functions could be dissolved into the parent
function because there isn't really anything left.

Signed-off-by: Don Zickus <dzickus@xxxxxxxxxx>
Signed-off-by: Benjamin Romer <benjamin.romer@xxxxxxxxxx>
---
 drivers/staging/unisys/visorbus/visorbus_main.c | 162 ++++++------------------
 1 file changed, 37 insertions(+), 125 deletions(-)

diff --git a/drivers/staging/unisys/visorbus/visorbus_main.c b/drivers/staging/unisys/visorbus/visorbus_main.c
index 2863d15..a3062ea 100644
--- a/drivers/staging/unisys/visorbus/visorbus_main.c
+++ b/drivers/staging/unisys/visorbus/visorbus_main.c
@@ -1028,42 +1028,15 @@ EXPORT_SYMBOL_GPL(visorbus_disable_channel_interrupts);
  *  device.
  */
 static int
-create_visor_device(struct visorbus_devdata *devdata,
-		    unsigned long chipset_bus_no, unsigned long chipset_dev_no,
-		    struct visorchipset_channel_info chan_info,
-		    u64 partition_handle)
+create_visor_device(struct visor_device *dev)
 {
 	int rc = -1;
-	struct visorchannel *visorchannel = NULL;
-	struct visor_device *dev = NULL;
-	bool gotten = false, registered1 = false, registered2 = false;
+	u32 chipset_bus_no = dev->chipset_bus_no;
+	u32 chipset_dev_no = dev->chipset_dev_no;
 
 	POSTCODE_LINUX_4(DEVICE_CREATE_ENTRY_PC, chipset_dev_no, chipset_bus_no,
 			 POSTCODE_SEVERITY_INFO);
-	/* prepare chan_hdr (abstraction to read/write channel memory) */
-	visorchannel = visorchannel_create(chan_info.channel_addr,
-					   chan_info.n_channel_bytes,
-					   GFP_KERNEL,
-					   chan_info.channel_type_uuid);
-	if (!visorchannel) {
-		POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, chipset_dev_no,
-				 DIAG_SEVERITY_ERR);
-		goto away;
-	}
-	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 = visorchannel;
-	dev->channel_type_guid = chan_info.channel_type_uuid;
-	dev->channel_bytes = chan_info.n_channel_bytes;
-	dev->chipset_bus_no = chipset_bus_no;
-	dev->chipset_dev_no = chipset_dev_no;
-	dev->device.parent = &devdata->dev;
 	sema_init(&dev->visordriver_callback_lock, 1);	/* unlocked */
 	dev->device.bus = &visorbus_type;
 	dev->device.groups = visorbus_dev_groups;
@@ -1071,7 +1044,6 @@ create_visor_device(struct visorbus_devdata *devdata,
 	dev->device.release = visorbus_release_device;
 	/* keep a reference just for us (now 2) */
 	get_device(&dev->device);
-	gotten = true;
 	dev->periodic_work =
 		visor_periodic_work_create(POLLJIFFIES_NORMALCHANNEL,
 					   periodic_dev_workqueue,
@@ -1087,7 +1059,7 @@ create_visor_device(struct visorbus_devdata *devdata,
 	 * (NOT bus instance).  That's why we need to include the bus
 	 * number within the name.
 	 */
-	dev_set_name(&dev->device, "vbus%lu:dev%lu",
+	dev_set_name(&dev->device, "vbus%u:dev%u",
 		     chipset_bus_no, chipset_dev_no);
 
 	/*  device_add does this:
@@ -1113,9 +1085,6 @@ create_visor_device(struct visorbus_devdata *devdata,
 		goto away;
 	}
 
-	/* note: device_register is simply device_initialize + device_add */
-	registered1 = true;
-
 	rc = register_devmajorminor_attributes(dev);
 	if (rc < 0) {
 		POSTCODE_LINUX_3(DEVICE_REGISTER_FAILURE_PC, chipset_dev_no,
@@ -1123,22 +1092,13 @@ create_visor_device(struct visorbus_devdata *devdata,
 		goto away;
 	}
 
-	registered2 = true;
-	rc = 0;
+	total_devices_created++;
+	list_add_tail(&dev->list_all, &list_all_device_instances);
+
+	return rc;
 
 away:
-	if (rc < 0) {
-		if (registered2)
-			unregister_devmajorminor_attributes(dev);
-		if (gotten)
-			put_device(&dev->device);
-		if (visorchannel)
-			visorchannel_destroy(visorchannel);
-		kfree(dev);
-	} else {
-		total_devices_created++;
-		list_add_tail(&dev->list_all, &list_all_device_instances);
-	}
+	put_device(&dev->device);
 	return rc;
 }
 
@@ -1356,75 +1316,36 @@ fix_vbus_dev_info(struct visor_device *visordev)
 
 /** Create a device instance for the visor bus itself.
  */
-static struct visorbus_devdata *
-create_bus_instance(int id)
+static int
+create_bus_instance(struct visor_device *vdev)
 {
-	struct visorbus_devdata *rc = NULL;
-	struct visorbus_devdata *devdata = NULL;
-	struct visorchipset_bus_info bus_info;
+	int rc;
+	u32 id = vdev->chipset_bus_no;
 
 	POSTCODE_LINUX_2(BUS_CREATE_ENTRY_PC, POSTCODE_SEVERITY_INFO);
-	devdata = kzalloc(sizeof(*devdata), GFP_KERNEL);
-	if (!devdata) {
-		POSTCODE_LINUX_2(MALLOC_FAILURE_PC, POSTCODE_SEVERITY_ERR);
-		rc = NULL;
-		goto away;
-	}
-	dev_set_name(&devdata->dev, "visorbus%d", id);
-	devdata->dev.bus = &visorbus_type;
-	devdata->dev.groups = visorbus_groups;
-	devdata->dev.release = visorbus_release_busdevice;
-	if (device_register(&devdata->dev) < 0) {
+	dev_set_name(&vdev->device, "visorbus%d", id);
+	vdev->device.bus = &visorbus_type;
+	vdev->device.groups = visorbus_groups;
+	vdev->device.release = visorbus_release_busdevice;
+	rc = device_register(&vdev->device);
+	if (rc < 0) {
 		POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, id,
 				 POSTCODE_SEVERITY_ERR);
-		rc = NULL;
 		goto away;
 	}
-	devdata->devno = id;
-	if ((visorchipset_get_bus_info(id, &bus_info)) &&
-	    (bus_info.chan_info.channel_addr > 0) &&
-	    (bus_info.chan_info.n_channel_bytes > 0)) {
-		u64 channel_addr = bus_info.chan_info.channel_addr;
-		unsigned long n_channel_bytes =
-				(unsigned long)
-				bus_info.chan_info.n_channel_bytes;
-		uuid_le channel_type_guid =
-				bus_info.chan_info.channel_type_uuid;
-
-		devdata->chan = visorchannel_create(channel_addr,
-						    n_channel_bytes,
-						    GFP_KERNEL,
-						    channel_type_guid);
-		if (!devdata->chan) {
-			POSTCODE_LINUX_3(DEVICE_CREATE_FAILURE_PC, channel_addr,
-					 POSTCODE_SEVERITY_ERR);
-		} else {
-			if (bus_info.flags.server) {
-				init_vbus_channel(devdata->chan);
-			} else {
-				if (get_vbus_header_info(devdata->chan,
-							 &devdata->
-							 vbus_hdr_info) >= 0) {
-					devdata->vbus_valid = true;
-					write_vbus_chp_info(devdata->chan,
-							    &devdata->
-							    vbus_hdr_info,
-							    &chipset_driverinfo
-							    );
-					write_vbus_bus_info(devdata->chan,
-							    &devdata->
-								vbus_hdr_info,
-							&clientbus_driverinfo);
-				}
-			}
+	if (vdev->visorchannel) {
+		struct visorchannel *channel = vdev->visorchannel;
+
+		if (get_vbus_header_info(channel, &vdev->vbus_hdr_info) >= 0) {
+			write_vbus_chp_info(channel, &vdev->vbus_hdr_info,
+					    &chipset_driverinfo);
+			write_vbus_bus_info(channel, &vdev->vbus_hdr_info,
+					    &clientbus_driverinfo);
 		}
 	}
 	bus_count++;
-	list_add_tail(&devdata->list_all, &list_all_bus_instances);
-	if (id == 0)
-			devdata = devdata;	/* for testing ONLY */
-	dev_set_drvdata(&devdata->dev, devdata);
-	rc = devdata;
+	list_add_tail(&vdev->list_all, &list_all_bus_instances);
+	dev_set_drvdata(&vdev->device, vdev);
 away:
 	return rc;
 }
@@ -1432,7 +1353,7 @@ away:
 /** Remove a device instance for the visor bus itself.
  */
 static void
-remove_bus_instance(struct visorbus_devdata *devdata)
+remove_bus_instance(struct visor_device *dev)
 {
 	/* Note that this will result in the release method for
 	 * devdata->dev being called, which will call
@@ -1442,12 +1363,12 @@ remove_bus_instance(struct visorbus_devdata *devdata)
 	 * release() gets called.  But I know it does.
 	 */
 	bus_count--;
-	if (devdata->chan) {
-		visorchannel_destroy(devdata->chan);
-		devdata->chan = NULL;
+	if (dev->visorchannel) {
+		visorchannel_destroy(dev->visorchannel);
+		dev->visorchannel = NULL;
 	}
-	list_del(&devdata->list_all);
-	device_unregister(&devdata->dev);
+	list_del(&dev->list_all);
+	device_unregister(&dev->device);
 }
 
 /** Create and register the one-and-only one instance of
@@ -1588,13 +1509,11 @@ resume_state_change_complete(struct visor_device *dev, int status)
  * callback function.
  */
 static void
-initiate_chipset_device_pause_resume(u32 bus_no, u32 dev_no, bool is_pause)
+initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
 {
-	struct visorchipset_device_info dev_info;
-	struct visor_device *dev = NULL;
 	int rc = -1, x;
 	struct visor_driver *drv = NULL;
-	void (*notify_func)(u32 bus_no, u32 dev_no, int response) = NULL;
+	void (*notify_func)(struct visor_device *dev, int response) = NULL;
 
 	if (is_pause)
 		notify_func = chipset_responders.device_pause;
@@ -1603,13 +1522,6 @@ initiate_chipset_device_pause_resume(u32 bus_no, u32 dev_no, bool is_pause)
 	if (!notify_func)
 			goto away;
 
-	if (!visorchipset_get_device_info(bus_no, dev_no, &dev_info))
-			goto away;
-
-	dev = find_visor_device_by_channel(dev_info.chan_info.channel_addr);
-	if (!dev)
-			goto away;
-
 	drv = to_visor_driver(dev->device.driver);
 	if (!drv)
 			goto away;
-- 
2.1.4

_______________________________________________
devel mailing list
devel@xxxxxxxxxxxxxxxxxxxxxx
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel




[Index of Archives]     [Linux Driver Backports]     [DMA Engine]     [Linux GPIO]     [Linux SPI]     [Video for Linux]     [Linux USB Devel]     [Linux Coverity]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]
  Powered by Linux