All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Fan <peng.fan@nxp.com>
To: u-boot@lists.denx.de
Subject: [PATCH V2 1/9] uclass: cpu: Add new API to get udevice for current CPU
Date: Fri,  1 May 2020 21:44:10 +0800	[thread overview]
Message-ID: <20200501134418.7319-1-peng.fan@nxp.com> (raw)

When running on SoC with multiple clusters, the boot CPU may
not be fixed, saying booting from cluster A or cluster B.
Add a API that can return the udevice for current boot CPU.
Cpu driver needs to implement is_current_cpu interface for this
feature, otherwise the API only returns the first udevice in
cpu uclass.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Ye Li <ye.li@nxp.com>
---

V2:
 Per Simon's comment,
  - Add cpu_is_current
  - use uclass_foreach_dev_probe
  - Update code comment

 drivers/cpu/cpu-uclass.c | 34 ++++++++++++++++++++++++++++++++++
 include/cpu.h            | 23 +++++++++++++++++++++++
 2 files changed, 57 insertions(+)

diff --git a/drivers/cpu/cpu-uclass.c b/drivers/cpu/cpu-uclass.c
index 457f77b7c8..33d38a0fde 100644
--- a/drivers/cpu/cpu-uclass.c
+++ b/drivers/cpu/cpu-uclass.c
@@ -10,6 +10,7 @@
 #include <errno.h>
 #include <dm/lists.h>
 #include <dm/root.h>
+#include <linux/err.h>
 
 int cpu_probe_all(void)
 {
@@ -34,6 +35,39 @@ int cpu_probe_all(void)
 	return 0;
 }
 
+int cpu_is_current(struct udevice *cpu)
+{
+	struct cpu_ops *ops = cpu_get_ops(cpu);
+
+	if (ops && ops->is_current) {
+		if (ops->is_current(cpu))
+			return 1;
+	}
+
+	return -ENOSYS;
+}
+
+struct udevice *cpu_get_current_dev(void)
+{
+	struct udevice *cpu;
+	int ret;
+
+	uclass_foreach_dev_probe(UCLASS_CPU, cpu) {
+		if (cpu_is_current(cpu) > 0)
+			return cpu;
+	}
+
+	/* If can't find current cpu device, use the first dev instead */
+	ret = uclass_first_device_err(UCLASS_CPU, &cpu);
+	if (ret) {
+		debug("%s: Could not get CPU device (err = %d)\n",
+		      __func__, ret);
+		return NULL;
+	}
+
+	return cpu;
+}
+
 int cpu_get_desc(struct udevice *dev, char *buf, int size)
 {
 	struct cpu_ops *ops = cpu_get_ops(dev);
diff --git a/include/cpu.h b/include/cpu.h
index 6b1b6b37b3..2f283fe244 100644
--- a/include/cpu.h
+++ b/include/cpu.h
@@ -89,6 +89,15 @@ struct cpu_ops {
 	 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
 	 */
 	int (*get_vendor)(struct udevice *dev, char *buf, int size);
+
+	/**
+	 * is_current() - Check if the CPU that U-Boot is currently running from
+	 *
+	 * @dev:	Device to check (UCLASS_CPU)
+	 * @return 1 if the CPU that U-Boot is currently running from, 0
+	 *         if not.
+	 */
+	int (*is_current)(struct udevice *dev);
 };
 
 #define cpu_get_ops(dev)        ((struct cpu_ops *)(dev)->driver->ops)
@@ -137,4 +146,18 @@ int cpu_get_vendor(struct udevice *dev, char *buf, int size);
  */
 int cpu_probe_all(void);
 
+/**
+ * cpu_is_current() - Check if the CPU that U-Boot is currently running from
+ *
+ * Return: 1 if yes, - 0 if not
+ */
+int cpu_is_current(struct udevice *cpu);
+
+/**
+ * cpu_get_current_dev() - Get CPU udevice for current CPU
+ *
+ * Return: udevice if OK, - NULL on error
+ */
+struct udevice *cpu_get_current_dev(void);
+
 #endif
-- 
2.16.4

             reply	other threads:[~2020-05-01 13:44 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01 13:44 Peng Fan [this message]
2020-05-01 13:44 ` [PATCH V2 2/9] cpu: sandbox: support is_current Peng Fan
2020-05-03  2:26   ` Simon Glass
2020-05-01 13:44 ` [PATCH V2 3/9] test: cpu: test current cpu Peng Fan
2020-05-03  2:26   ` Simon Glass
2020-05-01 13:44 ` [PATCH V2 4/9] common: board_f: Use cpu_get_current_dev in print_cpuinfo Peng Fan
2020-05-01 13:44 ` [PATCH V2 5/9] cpu: imx8: reimplement get cpu count Peng Fan
2020-05-01 13:44 ` [PATCH V2 6/9] cpu: imx8: support a72 as boot cpu Peng Fan
2020-05-01 13:44 ` [PATCH V2 7/9] cpu: imx8: fix get core name and rate Peng Fan
2020-05-01 13:44 ` [PATCH V2 8/9] cpu: imx_cpu: Print the CPU temperature for iMX8QM A72 Peng Fan
2020-05-03  2:26   ` Simon Glass
2020-05-01 13:44 ` [PATCH V2 9/9] cpu: imx8: show RevC instead of Rev? at boot log Peng Fan
2020-05-03  2:26 ` [PATCH V2 1/9] uclass: cpu: Add new API to get udevice for current CPU Simon Glass
2020-05-03 13:14   ` Peng Fan
2020-05-04 12:53     ` Simon Glass
2020-05-04 12:56       ` Peng Fan

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=20200501134418.7319-1-peng.fan@nxp.com \
    --to=peng.fan@nxp.com \
    --cc=u-boot@lists.denx.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 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.