From 53cc0b214c0ebb057b72b93071980d3ceab9e655 Mon Sep 17 00:00:00 2001 From: Ye Li Date: Thu, 7 Mar 2019 23:55:50 -0800 Subject: [PATCH] MLK-21828-1 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. 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: Ye Li --- drivers/cpu/cpu-uclass.c | 26 ++++++++++++++++++++++++++ include/cpu.h | 15 +++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/drivers/cpu/cpu-uclass.c b/drivers/cpu/cpu-uclass.c index 457f77b7c8..06bb49610f 100644 --- a/drivers/cpu/cpu-uclass.c +++ b/drivers/cpu/cpu-uclass.c @@ -34,6 +34,32 @@ int cpu_probe_all(void) return 0; } +struct udevice *cpu_get_current_dev(void) +{ + struct udevice *cpu = NULL; + int ret; + + for (uclass_first_device(UCLASS_CPU, &cpu); cpu; + uclass_next_device(&cpu)) { + struct cpu_ops *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 insteaded */ + 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 28dd48feb8..4583e328b8 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -87,6 +87,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) @@ -135,4 +143,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 -- 2.17.1