[PATCH v2 02/12] staging: fsl-mc: fsl_mc_io object refactoring

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

 



Each fsl_mc_io object is associated with an fsl_mc_device object
of type "dpmcp" representing the MC portal associated with the
fsl_mc_io object. Before, we were representing this association with
an fsl_mc_resource pointer. To enhance code clarity, it is more
straight forward to use an fsl_mc_device pointer instead.
So, this change replaces the 'resource' field in the fsl_mc_io
object with 'dpmcp_dev'. Also, it changes parameter 'resource' of
fsl_create_mc_io() to be an fsl_mc_device pointer instead.
---
CHANGE HISTORY

Changes in v2: none

 drivers/staging/fsl-mc/bus/mc-allocator.c | 34 ++++++++++++++++++-------------
 drivers/staging/fsl-mc/bus/mc-sys.c       | 16 +++++++++++----
 drivers/staging/fsl-mc/include/mc-sys.h   |  8 +++-----
 3 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/drivers/staging/fsl-mc/bus/mc-allocator.c b/drivers/staging/fsl-mc/bus/mc-allocator.c
index a4aa859..c3222c6 100644
--- a/drivers/staging/fsl-mc/bus/mc-allocator.c
+++ b/drivers/staging/fsl-mc/bus/mc-allocator.c
@@ -320,7 +320,7 @@ int __must_check fsl_mc_portal_allocate(struct fsl_mc_device *mc_dev,

 	error = fsl_create_mc_io(&mc_bus_dev->dev,
 				 mc_portal_phys_addr,
-				 mc_portal_size, resource,
+				 mc_portal_size, dpmcp_dev,
 				 mc_io_flags, &mc_io);
 	if (error < 0)
 		goto error_cleanup_resource;
@@ -342,12 +342,22 @@ EXPORT_SYMBOL_GPL(fsl_mc_portal_allocate);
  */
 void fsl_mc_portal_free(struct fsl_mc_io *mc_io)
 {
+	struct fsl_mc_device *dpmcp_dev;
 	struct fsl_mc_resource *resource;

-	resource = mc_io->resource;
-	if (WARN_ON(resource->type != FSL_MC_POOL_DPMCP))
+	/*
+	 * Every mc_io obtained by calling fsl_mc_portal_allocate() is supposed
+	 * to have a DPMCP object associated with.
+	 */
+	dpmcp_dev = mc_io->dpmcp_dev;
+	if (WARN_ON(!dpmcp_dev))
+		return;
+
+	resource = dpmcp_dev->resource;
+	if (WARN_ON(!resource || resource->type != FSL_MC_POOL_DPMCP))
 		return;
-	if (WARN_ON(!resource->data))
+
+	if (WARN_ON(resource->data != dpmcp_dev))
 		return;

 	fsl_destroy_mc_io(mc_io);
@@ -364,30 +374,26 @@ int fsl_mc_portal_reset(struct fsl_mc_io *mc_io)
 {
 	int error;
 	u16 token;
-	struct fsl_mc_resource *resource = mc_io->resource;
-	struct fsl_mc_device *mc_dev = resource->data;
+	struct fsl_mc_device *dpmcp_dev = mc_io->dpmcp_dev;

-	if (WARN_ON(resource->type != FSL_MC_POOL_DPMCP))
-		return -EINVAL;
-
-	if (WARN_ON(!mc_dev))
+	if (WARN_ON(!dpmcp_dev))
 		return -EINVAL;

-	error = dpmcp_open(mc_io, 0, mc_dev->obj_desc.id, &token);
+	error = dpmcp_open(mc_io, 0, dpmcp_dev->obj_desc.id, &token);
 	if (error < 0) {
-		dev_err(&mc_dev->dev, "dpmcp_open() failed: %d\n", error);
+		dev_err(&dpmcp_dev->dev, "dpmcp_open() failed: %d\n", error);
 		return error;
 	}

 	error = dpmcp_reset(mc_io, 0, token);
 	if (error < 0) {
-		dev_err(&mc_dev->dev, "dpmcp_reset() failed: %d\n", error);
+		dev_err(&dpmcp_dev->dev, "dpmcp_reset() failed: %d\n", error);
 		return error;
 	}

 	error = dpmcp_close(mc_io, 0, token);
 	if (error < 0) {
-		dev_err(&mc_dev->dev, "dpmcp_close() failed: %d\n", error);
+		dev_err(&dpmcp_dev->dev, "dpmcp_close() failed: %d\n", error);
 		return error;
 	}

diff --git a/drivers/staging/fsl-mc/bus/mc-sys.c b/drivers/staging/fsl-mc/bus/mc-sys.c
index b58b53f..e53acfa 100644
--- a/drivers/staging/fsl-mc/bus/mc-sys.c
+++ b/drivers/staging/fsl-mc/bus/mc-sys.c
@@ -34,10 +34,12 @@

 #include "../include/mc-sys.h"
 #include "../include/mc-cmd.h"
+#include "../include/mc.h"
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/ioport.h>
 #include <linux/device.h>
+#include "dpmcp.h"

 /**
  * Timeout in jiffies to wait for the completion of an MC command
@@ -60,8 +62,8 @@
  * @dev: device to be associated with the MC I/O object
  * @mc_portal_phys_addr: physical address of the MC portal to use
  * @mc_portal_size: size in bytes of the MC portal
- * @resource: Pointer to MC bus object allocator resource associated
- * with this MC I/O object or NULL if none.
+ * @dpmcp-dev: Pointer to the DPMCP object associated with this MC I/O
+ * object or NULL if none.
  * @flags: flags for the new MC I/O object
  * @new_mc_io: Area to return pointer to newly created MC I/O object
  *
@@ -70,7 +72,7 @@
 int __must_check fsl_create_mc_io(struct device *dev,
 				  phys_addr_t mc_portal_phys_addr,
 				  u32 mc_portal_size,
-				  struct fsl_mc_resource *resource,
+				  struct fsl_mc_device *dpmcp_dev,
 				  u32 flags, struct fsl_mc_io **new_mc_io)
 {
 	struct fsl_mc_io *mc_io;
@@ -85,7 +87,8 @@ int __must_check fsl_create_mc_io(struct device *dev,
 	mc_io->flags = flags;
 	mc_io->portal_phys_addr = mc_portal_phys_addr;
 	mc_io->portal_size = mc_portal_size;
-	mc_io->resource = resource;
+	mc_io->dpmcp_dev = dpmcp_dev;
+	dpmcp_dev->mc_io = mc_io;
 	res = devm_request_mem_region(dev,
 				      mc_portal_phys_addr,
 				      mc_portal_size,
@@ -126,6 +129,11 @@ void fsl_destroy_mc_io(struct fsl_mc_io *mc_io)
 				mc_io->portal_size);

 	mc_io->portal_virt_addr = NULL;
+	if (mc_io->dpmcp_dev) {
+		WARN_ON(mc_io->dpmcp_dev->mc_io != mc_io);
+		mc_io->dpmcp_dev->mc_io = NULL;
+	}
+
 	devm_kfree(mc_io->dev, mc_io);
 }
 EXPORT_SYMBOL_GPL(fsl_destroy_mc_io);
diff --git a/drivers/staging/fsl-mc/include/mc-sys.h b/drivers/staging/fsl-mc/include/mc-sys.h
index 939b7d3..bfbecaf 100644
--- a/drivers/staging/fsl-mc/include/mc-sys.h
+++ b/drivers/staging/fsl-mc/include/mc-sys.h
@@ -50,9 +50,7 @@ struct mc_command;
  * @portal_size: MC command portal size in bytes
  * @portal_phys_addr: MC command portal physical address
  * @portal_virt_addr: MC command portal virtual address
- * @resource: generic resource associated with the MC portal if
- * the MC portal came from a resource pool, or NULL if the MC portal
- * is permanently bound to a device (e.g., a DPRC)
+ * @dpmcp_dev: pointer to the DPMCP device associated with the MC portal.
  */
 struct fsl_mc_io {
 	struct device *dev;
@@ -60,13 +58,13 @@ struct fsl_mc_io {
 	u32 portal_size;
 	phys_addr_t portal_phys_addr;
 	void __iomem *portal_virt_addr;
-	struct fsl_mc_resource *resource;
+	struct fsl_mc_device *dpmcp_dev;
 };

 int __must_check fsl_create_mc_io(struct device *dev,
 				  phys_addr_t mc_portal_phys_addr,
 				  u32 mc_portal_size,
-				  struct fsl_mc_resource *resource,
+				  struct fsl_mc_device *dpmcp_dev,
 				  u32 flags, struct fsl_mc_io **new_mc_io);

 void fsl_destroy_mc_io(struct fsl_mc_io *mc_io);
--
2.3.3

_______________________________________________
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