From: Jiaxun Yang <jiaxun.yang@flygoat.com>
To: Paul Burton <paulburton@kernel.org>,
Thomas Bogendoerfer <tsbogend@alpha.franken.de>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org,
Jiaxun Yang <jiaxun.yang@flygoat.com>
Subject: [PATCH 5/5] MIPS: cm: Probe GCR address from DeviceTree
Date: Tue, 07 May 2024 10:01:53 +0100 [thread overview]
Message-ID: <20240507-cm_probe-v1-5-11dbfd598f3c@flygoat.com> (raw)
In-Reply-To: <20240507-cm_probe-v1-0-11dbfd598f3c@flygoat.com>
Traditionally, CM GCR address can be probed from CP0_CMGCRBase.
However there are chips in wild that do have CM GCR but CP0_CMGCRBase
is not available from CPU point of view. Thus we need to be able to
probe GCR address from DeviceTree.
It is implemented as:
- If only CP0_CMGCRBase present, trust CP0_CMGCRBase
- If only mti,mips-cm node present, trust mti,mips-cm reg prop
- If both present, remap address space to address specified in dt
Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
arch/mips/kernel/mips-cm.c | 58 +++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 52 insertions(+), 6 deletions(-)
diff --git a/arch/mips/kernel/mips-cm.c b/arch/mips/kernel/mips-cm.c
index dddc9428fe58..9563fc1ad438 100644
--- a/arch/mips/kernel/mips-cm.c
+++ b/arch/mips/kernel/mips-cm.c
@@ -5,6 +5,8 @@
*/
#include <linux/errno.h>
+#include <linux/of_address.h>
+#include <linux/of_fdt.h>
#include <linux/percpu.h>
#include <linux/spinlock.h>
@@ -179,23 +181,67 @@ static char *cm3_causes[32] = {
static DEFINE_PER_CPU_ALIGNED(spinlock_t, cm_core_lock);
static DEFINE_PER_CPU_ALIGNED(unsigned long, cm_core_lock_flags);
+static int __init mips_cm_fdt_scan(unsigned long node, const char *uname,
+ int depth, void *data)
+{
+ unsigned long *cmgcr = data;
+
+ if (!of_flat_dt_is_compatible(node, "mti,mips-cm"))
+ return 0;
+
+ *cmgcr = of_flat_dt_translate_address(node);
+ if (*cmgcr == OF_BAD_ADDR)
+ *cmgcr = 0;
+
+ return 0;
+}
+
phys_addr_t __init __weak mips_cm_phys_base(void)
{
- unsigned long cmgcr;
+ unsigned long gcr_reg = 0, gcr_dt = 0;
+
+ if (of_have_populated_dt()) {
+ int err;
+ struct resource res;
+ struct device_node *cm_node;
+
+ cm_node = of_find_compatible_node(of_root, NULL, "mti,mips-cm");
+ if (cm_node) {
+ err = of_address_to_resource(cm_node, 0, &res);
+ of_node_put(cm_node);
+ if (!err)
+ gcr_dt = res.start;
+ }
+ } else {
+ of_scan_flat_dt(mips_cm_fdt_scan, &gcr_dt);
+ }
/* Check the CMGCRBase register is implemented */
if (!(read_c0_config() & MIPS_CONF_M))
- return 0;
+ return gcr_dt;
if (!(read_c0_config2() & MIPS_CONF_M))
- return 0;
+ return gcr_dt;
if (!(read_c0_config3() & MIPS_CONF3_CMGCR))
- return 0;
+ return gcr_dt;
/* Read the address from CMGCRBase */
- cmgcr = read_c0_cmgcrbase();
- return (cmgcr & MIPS_CMGCRF_BASE) << (36 - 32);
+ gcr_reg = read_c0_cmgcrbase();
+ gcr_reg = (gcr_reg & MIPS_CMGCRF_BASE) << (36 - 32);
+
+ /* If no of node, return straight away */
+ if (!gcr_dt)
+ return gcr_reg;
+
+ /* If the CMGCRBase mismatches with dt, remap it */
+ if (gcr_reg != gcr_dt) {
+ pr_info("Remapping CMGCRBase from 0x%08lx to 0x%08lx\n",
+ gcr_reg, gcr_dt);
+ change_gcr_base(CM_GCR_BASE_GCRBASE, gcr_dt);
+ }
+
+ return gcr_dt;
}
phys_addr_t __init __weak mips_cm_l2sync_phys_base(void)
--
2.34.1
next prev parent reply other threads:[~2024-05-07 9:02 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-07 9:01 [PATCH 0/5] MIPS: cm: Probe GCR address from devicetree Jiaxun Yang
2024-05-07 9:01 ` [PATCH 1/5] MIPS: generic: Do __dt_setup_arch in prom_init Jiaxun Yang
2024-05-07 9:01 ` [PATCH 2/5] MIPS: cm: Prefix probe functions with __init Jiaxun Yang
2024-05-07 9:01 ` [PATCH 3/5] MIPS: Move mips_cm_probe after prom_init Jiaxun Yang
2024-05-08 12:50 ` Serge Semin
2024-05-08 16:23 ` Jiaxun Yang
2024-05-07 9:01 ` [PATCH 4/5] dt-bindings: mips: Document mti,mips-cm Jiaxun Yang
2024-05-07 16:50 ` Conor Dooley
2024-05-07 18:16 ` Jiaxun Yang
2024-05-08 17:01 ` Conor Dooley
2024-05-08 20:28 ` Jiaxun Yang
2024-05-09 17:24 ` Conor Dooley
2024-05-07 9:01 ` Jiaxun Yang [this message]
2024-05-08 4:25 ` [PATCH 5/5] MIPS: cm: Probe GCR address from DeviceTree kernel test robot
2024-05-08 12:37 ` [PATCH 0/5] MIPS: cm: Probe GCR address from devicetree Serge Semin
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=20240507-cm_probe-v1-5-11dbfd598f3c@flygoat.com \
--to=jiaxun.yang@flygoat.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=paulburton@kernel.org \
--cc=robh@kernel.org \
--cc=tsbogend@alpha.franken.de \
/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