From patchwork Wed Apr 29 02:17:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peng Fan X-Patchwork-Id: 238779 List-Id: U-Boot discussion From: peng.fan at nxp.com (Peng Fan) Date: Wed, 29 Apr 2020 10:17:14 +0800 Subject: [PATCH 1/7] uclass: cpu: Add new API to get udevice for current CPU Message-ID: <20200429021720.6653-1-peng.fan@nxp.com> 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 Signed-off-by: Ye Li --- drivers/cpu/cpu-uclass.c | 31 +++++++++++++++++++++++++++++++ include/cpu.h | 15 +++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/cpu/cpu-uclass.c b/drivers/cpu/cpu-uclass.c index 457f77b7c8..488b1f5050 100644 --- a/drivers/cpu/cpu-uclass.c +++ b/drivers/cpu/cpu-uclass.c @@ -10,6 +10,7 @@ #include #include #include +#include int cpu_probe_all(void) { @@ -34,6 +35,36 @@ int cpu_probe_all(void) return 0; } +struct udevice *cpu_get_current_dev(void) +{ + struct udevice *cpu; + struct uclass *uc; + struct cpu_ops *ops; + int ret; + + ret = uclass_get(UCLASS_CPU, &uc); + if (ret) + return ERR_PTR(ret); + + uclass_foreach_dev(cpu, uc) { + ops = cpu_get_ops(cpu); + if (ops->is_current_cpu) { + if (ops->is_current_cpu(cpu)) + 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..7ffe412b18 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -89,6 +89,14 @@ 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_cpu() - Check if the device is for current CPU + * + * @dev: Device to check (UCLASS_CPU) + * @return true if the device is current CPU, false if the device is not. + */ + bool (*is_current_cpu)(struct udevice *dev); }; #define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops) @@ -137,4 +145,11 @@ int cpu_get_vendor(struct udevice *dev, char *buf, int size); */ int cpu_probe_all(void); +/** + * 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