aboutsummaryrefslogtreecommitdiff
path: root/drivers/cpu
diff options
context:
space:
mode:
authorPeng Fan2020-05-03 21:58:47 +0800
committerStefano Babic2020-05-03 15:45:49 +0200
commit4c809aee50f5128f815a7f272cdf2d30a1e1e76e (patch)
tree41fba222d2362cf5efe94369a81b3828703c3b95 /drivers/cpu
parentd8e775539e6d69a2bf9d4de721f6ad1560de7823 (diff)
uclass: cpu: Add new API to get udevice for current CPU
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. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Peng Fan <peng.fan@nxp.com> Signed-off-by: Ye Li <ye.li@nxp.com>
Diffstat (limited to 'drivers/cpu')
-rw-r--r--drivers/cpu/cpu-uclass.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/drivers/cpu/cpu-uclass.c b/drivers/cpu/cpu-uclass.c
index 457f77b7c89..8352e2eb0bc 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->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);