Commit d436521d7d93fc08ac96b2f822eb62553b2f64ff

Authored by Ye Li
1 parent cfe5dc4a4a

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 <ye.li@nxp.com>
(cherry picked from commit 53cc0b214c0ebb057b72b93071980d3ceab9e655)

Showing 2 changed files with 41 additions and 0 deletions Side-by-side Diff

drivers/cpu/cpu-uclass.c
... ... @@ -34,6 +34,32 @@
34 34 return 0;
35 35 }
36 36  
  37 +struct udevice *cpu_get_current_dev(void)
  38 +{
  39 + struct udevice *cpu = NULL;
  40 + int ret;
  41 +
  42 + for (uclass_first_device(UCLASS_CPU, &cpu); cpu;
  43 + uclass_next_device(&cpu)) {
  44 + struct cpu_ops *ops = cpu_get_ops(cpu);
  45 + if (ops->is_current_cpu) {
  46 + if (ops->is_current_cpu(cpu))
  47 + return cpu;
  48 + }
  49 + }
  50 +
  51 + /* If can't find current cpu device, use the first dev insteaded */
  52 + ret = uclass_first_device_err(UCLASS_CPU, &cpu);
  53 + if (ret) {
  54 + debug("%s: Could not get CPU device (err = %d)\n",
  55 + __func__, ret);
  56 + return NULL;
  57 + }
  58 +
  59 + return cpu;
  60 +}
  61 +
  62 +
37 63 int cpu_get_desc(struct udevice *dev, char *buf, int size)
38 64 {
39 65 struct cpu_ops *ops = cpu_get_ops(dev);
... ... @@ -87,6 +87,14 @@
87 87 * @return 0 if OK, -ENOSPC if buffer is too small, other -ve on error
88 88 */
89 89 int (*get_vendor)(struct udevice *dev, char *buf, int size);
  90 +
  91 + /**
  92 + * is_current_cpu() - Check if the device is for current CPU
  93 + *
  94 + * @dev: Device to check (UCLASS_CPU)
  95 + * @return true if the device is current CPU, false if the device is not.
  96 + */
  97 + bool (*is_current_cpu)(struct udevice *dev);
90 98 };
91 99  
92 100 #define cpu_get_ops(dev) ((struct cpu_ops *)(dev)->driver->ops)
... ... @@ -134,6 +142,13 @@
134 142 * Return: 0 if OK, -ve on error
135 143 */
136 144 int cpu_probe_all(void);
  145 +
  146 +/**
  147 + * cpu_get_current_dev() - Get CPU udevice for current CPU
  148 + *
  149 + * Return: udevice if OK, - NULL on error
  150 + */
  151 +struct udevice *cpu_get_current_dev(void);
137 152  
138 153 #endif