All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: linux-remoteproc@vger.kernel.org
Cc: David Lechner <david@lechnology.com>,
	Ohad Ben-Cohen <ohad@wizery.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Grzegorz Jaszczyk <grzegorz.jaszczyk@linaro.org>,
	Suman Anna <s-anna@ti.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH] remoteproc: pru: future-proof PRU ID matching
Date: Mon,  4 Jan 2021 15:18:16 -0600	[thread overview]
Message-ID: <20210104211816.420602-1-david@lechnology.com> (raw)

Currently, to determine the ID (0 or 1) of a PRU core, the last 19 bits
of the physical address of the cores IRAM are compared to known values.
However, the PRUs on TI AM18XX have IRAM at 0x01c38000 and 0x01c3c000
respectively. The former conflicts with PRU1_IRAM_ADDR_MASK which could
cause PRU0 to be detected as PRU1. (The latter also conflicts with
TX_PRU1_IRAM_ADDR_MASK but it would still be correctly detected as
PRU1.)

This fixes the problem by moving the address matching offset values to
the device-specific data. This way the compatible string does half of
the work of narrowing down the addresses to two possibilities instead
of checking the address against all possible PRU types. This also lets
us narrow down the scope of the match from 19 bits to 16 bits for all
PRU types.

After this, the TI AM18XX PRUs will be able to be added without running
into the problems stated above.

We can also drop the local ret variable while touching this code.

Signed-off-by: David Lechner <david@lechnology.com>
---
 drivers/remoteproc/pru_rproc.c | 49 ++++++++++++++--------------------
 1 file changed, 20 insertions(+), 29 deletions(-)

diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c
index 2667919d76b3..94ce48df2f48 100644
--- a/drivers/remoteproc/pru_rproc.c
+++ b/drivers/remoteproc/pru_rproc.c
@@ -46,15 +46,6 @@
 #define PRU_DEBUG_GPREG(x)	(0x0000 + (x) * 4)
 #define PRU_DEBUG_CT_REG(x)	(0x0080 + (x) * 4)
 
-/* PRU/RTU/Tx_PRU Core IRAM address masks */
-#define PRU_IRAM_ADDR_MASK	0x3ffff
-#define PRU0_IRAM_ADDR_MASK	0x34000
-#define PRU1_IRAM_ADDR_MASK	0x38000
-#define RTU0_IRAM_ADDR_MASK	0x4000
-#define RTU1_IRAM_ADDR_MASK	0x6000
-#define TX_PRU0_IRAM_ADDR_MASK	0xa000
-#define TX_PRU1_IRAM_ADDR_MASK	0xc000
-
 /* PRU device addresses for various type of PRU RAMs */
 #define PRU_IRAM_DA	0	/* Instruction RAM */
 #define PRU_PDRAM_DA	0	/* Primary Data RAM */
@@ -96,10 +87,14 @@ enum pru_type {
 /**
  * struct pru_private_data - device data for a PRU core
  * @type: type of the PRU core (PRU, RTU, Tx_PRU)
+ * @pru0_iram_offset: used to identify PRU core 0
+ * @pru1_iram_offset: used to identify PRU core 1
  * @is_k3: flag used to identify the need for special load handling
  */
 struct pru_private_data {
 	enum pru_type type;
+	u16 pru0_iram_offset;
+	u16 pru1_iram_offset;
 	unsigned int is_k3 : 1;
 };
 
@@ -693,33 +688,21 @@ static int pru_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
 }
 
 /*
- * Compute PRU id based on the IRAM addresses. The PRU IRAMs are
+ * Compute PRU id based on the last 16 bits of IRAM addresses. The PRU IRAMs are
  * always at a particular offset within the PRUSS address space.
  */
 static int pru_rproc_set_id(struct pru_rproc *pru)
 {
-	int ret = 0;
-
-	switch (pru->mem_regions[PRU_IOMEM_IRAM].pa & PRU_IRAM_ADDR_MASK) {
-	case TX_PRU0_IRAM_ADDR_MASK:
-		fallthrough;
-	case RTU0_IRAM_ADDR_MASK:
-		fallthrough;
-	case PRU0_IRAM_ADDR_MASK:
+	u16 offset = pru->mem_regions[PRU_IOMEM_IRAM].pa;
+
+	if (offset == pru->data->pru0_iram_offset)
 		pru->id = 0;
-		break;
-	case TX_PRU1_IRAM_ADDR_MASK:
-		fallthrough;
-	case RTU1_IRAM_ADDR_MASK:
-		fallthrough;
-	case PRU1_IRAM_ADDR_MASK:
+	else if (offset == pru->data->pru1_iram_offset)
 		pru->id = 1;
-		break;
-	default:
-		ret = -EINVAL;
-	}
+	else
+		return -EINVAL;
 
-	return ret;
+	return 0;
 }
 
 static int pru_rproc_probe(struct platform_device *pdev)
@@ -825,20 +808,28 @@ static int pru_rproc_remove(struct platform_device *pdev)
 
 static const struct pru_private_data pru_data = {
 	.type = PRU_TYPE_PRU,
+	.pru0_iram_offset = 0x4000,
+	.pru1_iram_offset = 0x8000,
 };
 
 static const struct pru_private_data k3_pru_data = {
 	.type = PRU_TYPE_PRU,
+	.pru0_iram_offset = 0x4000,
+	.pru1_iram_offset = 0x8000,
 	.is_k3 = 1,
 };
 
 static const struct pru_private_data k3_rtu_data = {
 	.type = PRU_TYPE_RTU,
+	.pru0_iram_offset = 0x4000,
+	.pru1_iram_offset = 0x6000,
 	.is_k3 = 1,
 };
 
 static const struct pru_private_data k3_tx_pru_data = {
 	.type = PRU_TYPE_TX_PRU,
+	.pru0_iram_offset = 0xa000,
+	.pru1_iram_offset = 0xc000,
 	.is_k3 = 1,
 };
 
-- 
2.25.1


             reply	other threads:[~2021-01-04 21:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-04 21:18 David Lechner [this message]
2021-01-16  0:53 ` [PATCH] remoteproc: pru: future-proof PRU ID matching Suman Anna
2021-01-28 22:55   ` Suman Anna
2021-01-28 23:21     ` David Lechner
2021-01-28 23:37       ` Suman Anna

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=20210104211816.420602-1-david@lechnology.com \
    --to=david@lechnology.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=grzegorz.jaszczyk@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=ohad@wizery.com \
    --cc=s-anna@ti.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.