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>
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user