mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "J. German Rivera" <German.Rivera@freescale.com>
To: <gregkh@linuxfoundation.org>, <arnd@arndb.de>,
	<devel@driverdev.osuosl.org>, <linux-kernel@vger.kernel.org>
Cc: <stuart.yoder@freescale.com>, <itai.katz@freescale.com>,
	<lijun.pan@freescale.com>, <leoli@freescale.com>,
	<scottwood@freescale.com>, <agraf@suse.de>,
	<bhamciu1@freescale.com>, <R89243@freescale.com>,
	<bhupesh.sharma@freescale.com>, <nir.erez@freescale.com>,
	<richard.schmitt@freescale.com>, <dan.carpenter@oracle.com>,
	"J. German Rivera" <German.Rivera@freescale.com>
Subject: [PATCH v2 02/12] staging: fsl-mc: fsl_mc_io object refactoring
Date: Wed, 14 Oct 2015 14:51:41 -0500	[thread overview]
Message-ID: <1444852311-673-3-git-send-email-German.Rivera@freescale.com> (raw)
In-Reply-To: <1444852311-673-1-git-send-email-German.Rivera@freescale.com>

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


  parent reply	other threads:[~2015-10-14 20:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-14 19:51 [PATCH v2 00/12] staging: fsl-mc: Cleanup and bug fixes J. German Rivera
2015-10-14 19:51 ` [PATCH v2 01/12] staging: fsl-mc: Naming cleanup in fsl_mc-portal_allocate J. German Rivera
2015-10-17  6:15   ` Greg KH
2015-10-17 16:08     ` Jose Rivera
2015-10-14 19:51 ` J. German Rivera [this message]
2015-10-14 19:51 ` [PATCH v2 03/12] staging: fsl-mc: dpmcp opening/closing refactoring J. German Rivera
2015-10-14 19:51 ` [PATCH v2 04/12] staging: fsl-mc: Changed dev_info() calls to dev_dbg() J. German Rivera
2015-10-14 19:51 ` [PATCH v2 05/12] staging_fsl-mc: Changed types of flags, portal size in J. German Rivera
2015-10-14 19:51 ` [PATCH v2 06/12] staging: fsl-mc: Removed unused DPMCP macros J. German Rivera
2015-10-14 19:51 ` [PATCH v2 07/12] staging: fsl-mc: Fixed alignment of copyright comment J. German Rivera
2015-10-14 19:51 ` [PATCH v2 08/12] staging: fsl-mc: Fixed bug in fsl_mc_allocator_remove J. German Rivera
2015-10-14 19:51 ` [PATCH v2 09/12] staging: fsl-mc: refactored error exit in allocator probe/remove J. German Rivera
2015-10-14 19:51 ` [PATCH v2 10/12] staging: fsl-mc: Fixed WARN_ON() in fsl_mc_resource_pool_remove_device J. German Rivera
2015-10-14 19:51 ` [PATCH v2 11/12] staging: fsl-mc: fixed bug in uninitialized root dprc irq count J. German Rivera
2015-10-14 19:51 ` [PATCH v2 12/12] staging: fsl-mc: Added missing initializer in fsl_mc_bus_driver J. German Rivera

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1444852311-673-3-git-send-email-German.Rivera@freescale.com \
    --to=german.rivera@freescale.com \
    --cc=R89243@freescale.com \
    --cc=agraf@suse.de \
    --cc=arnd@arndb.de \
    --cc=bhamciu1@freescale.com \
    --cc=bhupesh.sharma@freescale.com \
    --cc=dan.carpenter@oracle.com \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=itai.katz@freescale.com \
    --cc=leoli@freescale.com \
    --cc=lijun.pan@freescale.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nir.erez@freescale.com \
    --cc=richard.schmitt@freescale.com \
    --cc=scottwood@freescale.com \
    --cc=stuart.yoder@freescale.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome