]> git.karo-electronics.de Git - linux-beck.git/commitdiff
staging: fsl-mc: fsl_mc_io object refactoring
authorJ. German Rivera <German.Rivera@freescale.com>
Sat, 17 Oct 2015 16:18:14 +0000 (11:18 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 18 Oct 2015 03:53:38 +0000 (20:53 -0700)
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.

Signed-off-by: J. German Rivera <German.Rivera@freescale.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/fsl-mc/bus/mc-allocator.c
drivers/staging/fsl-mc/bus/mc-sys.c
drivers/staging/fsl-mc/include/mc-sys.h

index a4aa85958733e33c97a61c5a4ee3b4fde42758a3..c3222c6c7e1fb05a8e2c621edd7c91549f3a6084 100644 (file)
@@ -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;
        }
 
index b58b53fe165c7f057a20f3973b6d5e1124244ad3..e53acfaa230441c42b8ae258d3d61ba2ed6d6eea 100644 (file)
 
 #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);
index 939b7d39b36595e626f7ac1ccc552d874d0a0f41..bfbecafe75d9021ac59b7bb95dda4919d71da28e 100644 (file)
@@ -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);