mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-20 11:55:03 +00:00
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:
parent
d8e775539e
commit
4c809aee50
2 changed files with 57 additions and 0 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <dm/lists.h>
|
#include <dm/lists.h>
|
||||||
#include <dm/root.h>
|
#include <dm/root.h>
|
||||||
|
#include <linux/err.h>
|
||||||
|
|
||||||
int cpu_probe_all(void)
|
int cpu_probe_all(void)
|
||||||
{
|
{
|
||||||
|
@ -34,6 +35,39 @@ int cpu_probe_all(void)
|
||||||
return 0;
|
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)
|
int cpu_get_desc(struct udevice *dev, char *buf, int size)
|
||||||
{
|
{
|
||||||
struct cpu_ops *ops = cpu_get_ops(dev);
|
struct cpu_ops *ops = cpu_get_ops(dev);
|
||||||
|
|
|
@ -89,6 +89,15 @@ struct cpu_ops {
|
||||||
* @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
|
* @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
|
||||||
*/
|
*/
|
||||||
int (*get_vendor)(struct udevice *dev, char *buf, int size);
|
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)
|
#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);
|
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
|
#endif
|
||||||
|
|
Loading…
Add table
Reference in a new issue