uclass: cpu: Add new API to get udevice for current CPU
Subsystems (2)
PATCH 1/7 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.
--- drivers/cpu/cpu-uclass.c | 31 +++++++++++++++++++++++++++++++ include/cpu.h | 15 +++++++++++++++ 2 files changed, 46 insertions(+)
drivers/cpu/cpu-uclass.c +31 -0
@@ -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,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);
include/cpu.h +15 -0
@@ -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
Signature · 1 line
2.16.4
PATCH 2/7 common: board_f: Use cpu_get_current_dev in print_cpuinfo
From: Ye Li <[email protected]>
Current print_cpuinfo gets the first udevice in CPU class to return the cpu info. This has problem if the boot CPU is not fixed.
Changing to use new API cpu_get_current_dev to fix the issue.
--- common/board_f.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
common/board_f.c +5 -5
@@ -183,11 +183,11 @@ static int print_cpuinfo(void)char desc[512 ];int ret; - ret =uclass_first_device_err (UCLASS_CPU , &dev); -if (ret) { -debug ("%s: Could not get CPU device (err = %d)\n" , - __func__, ret); -return ret; + dev =cpu_get_current_dev (); +if (!dev) { +debug ("%s: Could not get CPU device\n" , + __func__); +return -ENODEV ; } ret =cpu_get_desc (dev, desc,sizeof (desc));
Signature · 1 line
2.16.4
PATCH 2/7 common: board_f: Use cpu_get_current_dev in print_cpuinfo
Quoted 6 lines · Peng Fan
From: Ye Li <[email protected]>
Current
print_cpuinfogets the first udevice in CPU class to return the cpu info. This has problem if the boot CPU is not fixed.
Quoted 7 lines
Changing to use new API
cpu_get_current_devto fix the issue.Signed-off-by Ye Li <[email protected]>Signed-off-by Peng Fan <[email protected]>--- common/board_f.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
PATCH 3/7 cpu: imx8: reimplement get cpu count
In reply to Peng FanReturn 4 is not correct on i.MX8DX/DXL/8QM and etc. we need to count available cpu node with device_type "cpu".
--- drivers/cpu/imx8_cpu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
drivers/cpu/imx8_cpu.c +18 -1
@@ -118,7 +118,24 @@ static int cpu_imx_get_info(struct udevice *dev, struct cpu_info *info)static int cpu_imx_get_count (struct udevice *dev) { -return 4 ; +ofnode node; +int num =0 ; + +ofnode_for_each_subnode (node,dev_ofnode (dev->parent)) { +const char *device_type; + +if (!ofnode_is_available (node)) +continue ; + + device_type =ofnode_read_string (node,"device_type" ); +if (!device_type) +continue ; + +if (!strcmp (device_type,"cpu" )) + num++; + } + +return num; }static int cpu_imx_get_vendor (struct udevice *dev,char *buf,int size)
Signature · 1 line
2.16.4
PATCH 3/7 cpu: imx8: reimplement get cpu count
Quoted 9 lines · Peng Fan
Return 4 is not correct on i.MX8DX/DXL/8QM and etc. we need to count available cpu node with
device_type"cpu".Signed-off-by Peng Fan <[email protected]>--- drivers/cpu/imx8_cpu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
PATCH 4/7 cpu: imx8: support a72 as boot cpu
In reply to Peng FanSupport booting i.MX8QM with A72 as boot cpu
--- drivers/cpu/imx8_cpu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
drivers/cpu/imx8_cpu.c +19 -0
@@ -20,6 +20,7 @@ struct cpu_imx_platdata {const char *type;u32 cpurev;u32 freq_mhz; +u32 mpidr; };const char *get_imx8_type (u32 imxtype)
@@ -144,16 +145,28 @@ static int cpu_imx_get_vendor(struct udevice *dev, char *buf, int size)return 0 ; } +static bool cpu_imx_is_current (struct udevice *dev) +{ +struct cpu_imx_platdata *plat =dev_get_platdata (dev); + +if (plat->mpidr == (read_mpidr () &0xffff )) +return true; + +return false; +} +static const struct cpu_ops cpu_imx8_ops = { .get_desc = cpu_imx_get_desc, .get_info = cpu_imx_get_info, .get_count = cpu_imx_get_count, .get_vendor = cpu_imx_get_vendor, + .is_current_cpu = cpu_imx_is_current, };static const struct udevice_id cpu_imx8_ids[] = { { .compatible ="arm,cortex-a35" }, { .compatible ="arm,cortex-a53" }, + { .compatible ="arm,cortex-a72" }, { } };
@@ -185,6 +198,12 @@ static int imx8_cpu_probe(struct udevice *dev) plat->rev =get_imx8_rev (cpurev &0xFFF ); plat->type =get_imx8_type ((cpurev &0xFF000 ) >>12 ); plat->freq_mhz =imx8_get_cpu_rate () /1000000 ; + plat->mpidr =dev_read_addr (dev); +if (plat->mpidr ==FDT_ADDR_T_NONE ) { +printf ("%s: Failed to get CPU reg property\n" , __func__); +return -EINVAL ; + } +return 0 ; }
Signature · 1 line
2.16.4
PATCH 4/7 cpu: imx8: support a72 as boot cpu
Quoted 8 lines · Peng Fan
Support booting i.MX8QM with A72 as boot cpu
Signed-off-by Peng Fan <[email protected]>--- drivers/cpu/imx8_cpu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
PATCH 5/7 cpu: imx8: fix get core name and rate
In reply to Peng FanWhen current cpu is A53, using is_cortex_a53 could not detect A72 information, so check cpu device compatible property to get the correct information.
--- drivers/cpu/imx8_cpu.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
drivers/cpu/imx8_cpu.c +17 -10
@@ -48,13 +48,13 @@ const char *get_imx8_rev(u32 rev) } } -const char *get_core_name (void ) +const char *get_core_name (struct udevice *dev) { -if (is_cortex_a35 ()) +if (!device_is_compatible (dev,"arm,cortex-a35" ))return "A35" ; -else if (is_cortex_a53 ()) +else if (!device_is_compatible (dev,"arm,cortex-a53" ))return "A53" ; -else if (is_cortex_a72 ()) +else if (!device_is_compatible (dev,"arm,cortex-a72" ))return "A72" ;else return "?" ;
@@ -170,12 +170,19 @@ static const struct udevice_id cpu_imx8_ids[] = { { } }; -static ulong imx8_get_cpu_rate (void ) +static ulong imx8_get_cpu_rate (struct udevice *dev) {ulong rate; -int ret; -int type =is_cortex_a35 () ?SC_R_A35 :is_cortex_a53 () ? -SC_R_A53 :SC_R_A72 ; +int ret, type; + +if (!device_is_compatible (dev,"arm,cortex-a35" )) + type =SC_R_A35 ; +else if (!device_is_compatible (dev,"arm,cortex-a53" )) + type =SC_R_A53 ; +else if (!device_is_compatible (dev,"arm,cortex-a72" )) + type =SC_R_A72 ; +else +return 0 ; ret =sc_pm_get_clock_rate (-1 , type,SC_PM_CLK_CPU , (sc_pm_clock_rate_t *)&rate);
@@ -194,10 +201,10 @@ static int imx8_cpu_probe(struct udevice *dev) cpurev =get_cpu_rev (); plat->cpurev = cpurev; - plat->name =get_core_name (); + plat->name =get_core_name (dev); plat->rev =get_imx8_rev (cpurev &0xFFF ); plat->type =get_imx8_type ((cpurev &0xFF000 ) >>12 ); - plat->freq_mhz =imx8_get_cpu_rate () /1000000 ; + plat->freq_mhz =imx8_get_cpu_rate (dev) /1000000 ; plat->mpidr =dev_read_addr (dev);if (plat->mpidr ==FDT_ADDR_T_NONE ) {printf ("%s: Failed to get CPU reg property\n" , __func__);
Signature · 1 line
2.16.4
PATCH 5/7 cpu: imx8: fix get core name and rate
Quoted 9 lines · Peng Fan
When current cpu is A53, using
is_cortex_a53could not detect A72 information, so check cpu device compatible property to get the correct information.Signed-off-by Peng Fan <[email protected]>--- drivers/cpu/imx8_cpu.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-)
PATCH 6/7 cpu: imx_cpu: Print the CPU temperature for iMX8QM A72
In reply to Peng FanFrom: Ye Li <[email protected]>
iMX8QM registers two thermal devices for CPUs, get the temperature from "cpu-thermal1" device for A72
--- drivers/cpu/imx8_cpu.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/cpu/imx8_cpu.c +14 -6
@@ -61,13 +61,17 @@ const char *get_core_name(struct udevice *dev) }#if IS_ENABLED (CONFIG_IMX_SCU_THERMAL ) -static int cpu_imx_get_temp (void ) +static int cpu_imx_get_temp (struct cpu_imx_platdata *plat) {struct udevice *thermal_dev;int cpu_tmp, ret; - ret =uclass_get_device_by_name (UCLASS_THERMAL ,"cpu-thermal0" , - &thermal_dev); +if (!strcmp (plat->name,"A72" )) + ret =uclass_get_device_by_name (UCLASS_THERMAL ,"cpu-thermal1" , + &thermal_dev); +else + ret =uclass_get_device_by_name (UCLASS_THERMAL ,"cpu-thermal0" , + &thermal_dev);if (!ret) { ret =thermal_get_temp (thermal_dev, &cpu_tmp);
@@ -80,7 +84,7 @@ static int cpu_imx_get_temp(void) return cpu_tmp; }#else -static int cpu_imx_get_temp (void ) +static int cpu_imx_get_temp (struct cpu_imx_platdata *plat) {return 0 ; }
@@ -89,7 +93,7 @@ static int cpu_imx_get_temp(void)int cpu_imx_get_desc (struct udevice *dev,char *buf,int size) {struct cpu_imx_platdata *plat =dev_get_platdata (dev); -int ret; +int ret, temp;if (size <100 )return -ENOSPC ;
@@ -98,9 +102,13 @@ int cpu_imx_get_desc(struct udevice *dev, char *buf, int size) plat->type, plat->rev, plat->name, plat->freq_mhz);if (IS_ENABLED (CONFIG_IMX_SCU_THERMAL )) { + temp =cpu_imx_get_temp (plat); buf = buf + ret; size = size - ret; - ret =snprintf (buf, size," at %dC" ,cpu_imx_get_temp ()); +if (temp !=0xdeadbeef ) + ret =snprintf (buf, size," at %dC" , temp); +else + ret =snprintf (buf, size," - invalid sensor data" ); }snprintf (buf + ret, size - ret,"\n" );
Signature · 1 line
2.16.4
PATCH 6/7 cpu: imx_cpu: Print the CPU temperature for iMX8QM A72
Hi Peng,
Quoted 21 lines · Peng Fan
From: Ye Li <[email protected]>
iMX8QM registers two thermal devices for CPUs, get the temperature from "cpu-thermal1" device for A72
Signed-off-by Ye Li <[email protected]>Signed-off-by Peng Fan <[email protected]>--- drivers/cpu/imx8_cpu.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)drivers/cpu/imx8_cpu.c +0
-1@@ -61,13 +61,17 @@ const char *get_core_name(struct udevice *dev) }#if IS_ENABLED (CONFIG_IMX_SCU_THERMAL ) -static int cpu_imx_get_temp (void )
drivers/cpu/imx8_cpu.c const char *get_core_name(struct udevice *dev) · line 71
Quoted 10 lines
drivers/cpu/imx8_cpu.c +4
-2+static int cpu_imx_get_temp (struct cpu_imx_platdata *plat) {struct udevice *thermal_dev;int cpu_tmp, ret; - ret =uclass_get_device_by_name (UCLASS_THERMAL ,"cpu-thermal0" , - &thermal_dev); +if (!strcmp (plat->name,"A72" )) + ret =uclass_get_device_by_name (UCLASS_THERMAL ,"cpu-thermal1" , + &thermal_dev);
This is very slow.
Use uclass_get_device_by_seq()
or just uclass_get_device(UCLASS_THERMAL, 0..1..2)
Quoted 40 lines
drivers/cpu/imx8_cpu.c +10
-4+else + ret =uclass_get_device_by_name (UCLASS_THERMAL ,"cpu-thermal0" , + &thermal_dev);if (!ret) { ret =thermal_get_temp (thermal_dev, &cpu_tmp);@@ -80,7 +84,7 @@ static int cpu_imx_get_temp(void) return cpu_tmp; }#else -static int cpu_imx_get_temp (void ) +static int cpu_imx_get_temp (struct cpu_imx_platdata *plat) {return 0 ; }@@ -89,7 +93,7 @@ static int cpu_imx_get_temp(void)int cpu_imx_get_desc (struct udevice *dev,char *buf,int size) {struct cpu_imx_platdata *plat =dev_get_platdata (dev); -int ret; +int ret, temp;if (size <100 )return -ENOSPC ;@@ -98,9 +102,13 @@ int cpu_imx_get_desc(struct udevice *dev, char *buf, int size) plat->type, plat->rev, plat->name, plat->freq_mhz);if (IS_ENABLED (CONFIG_IMX_SCU_THERMAL )) { + temp =cpu_imx_get_temp (plat); buf = buf + ret; size = size - ret; - ret =snprintf (buf, size," at %dC" ,cpu_imx_get_temp ()); +if (temp !=0xdeadbeef ) + ret =snprintf (buf, size," at %dC" , temp); +else + ret =snprintf (buf, size," - invalid sensor data" ); }snprintf (buf + ret, size - ret,"\n" ); --
Quoted 2 lines
2.16.4
Regards,
Simon
PATCH 7/7 cpu: imx8: show RevC instead of Rev? at boot log
In reply to Peng FanFrom: Frank Li <[email protected]>
Add REVC informaiton.
--- arch/arm/include/asm/arch-imx/cpu.h | 1 + drivers/cpu/imx8_cpu.c | 2 ++ 2 files changed, 3 insertions(+)
arch/arm/include/asm/arch-imx/cpu.h +1 -0
@@ -57,6 +57,7 @@#define CHIP_REV_A 0x0#define CHIP_REV_B 0x1 +#define CHIP_REV_C 0x2#define BOARD_REV_1_0 0x0#define BOARD_REV_2_0 0x1
drivers/cpu/imx8_cpu.c +2 -0
@@ -43,6 +43,8 @@ const char *get_imx8_rev(u32 rev)return "A" ;case CHIP_REV_B :return "B" ; +case CHIP_REV_C : +return "C" ;default :return "?" ; }
Signature · 1 line
2.16.4
PATCH 7/7 cpu: imx8: show RevC instead of Rev? at boot log
Quoted 11 lines · Peng Fan
From: Frank Li <[email protected]>
Add REVC informaiton.
Signed-off-by Frank Li <[email protected]>Signed-off-by Peng Fan <[email protected]>--- arch/arm/include/asm/arch-imx/cpu.h | 1 + drivers/cpu/imx8_cpu.c | 2 ++ 2 files changed, 3 insertions(+)
PATCH 1/7 uclass: cpu: Add new API to get udevice for current CPU
In reply to Peng FanHi Peng,
Quoted 8 lines · Peng Fan
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_cpuinterface for this feature, otherwise the API only returns the first udevice in cpu uclass.
Quoted 7 lines
Signed-off-by Peng Fan <[email protected]>Signed-off-by Ye Li <[email protected]>--- drivers/cpu/cpu-uclass.c | 31 +++++++++++++++++++++++++++++++ include/cpu.h | 15 +++++++++++++++ 2 files changed, 46 insertions(+)
This looks reasonable but please add it to the test and I have some comments below.
Quoted 18 lines
drivers/cpu/cpu-uclass.c +3
-0@@ -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,36 @@ int cpu_probe_all(void)return 0 ; } +struct udevice *cpu_get_current_dev (void ) +{
drivers/cpu/cpu-uclass.c int cpu_probe_all(void) · line 49
Quoted 10 lines
drivers/cpu/cpu-uclass.c +10
-0+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) {
Do you want to probe the CPU? See uclass_foreach_dev_probe() if you do.
drivers/cpu/cpu-uclass.c int cpu_probe_all(void) · line 51
Quoted 2 lines
drivers/cpu/cpu-uclass.c +2
-0+ ops =cpu_get_ops (cpu); +if (ops->is_current_cpu) {
Can you please create a cpu_is_current() function which just does the ops call and needs to handle -ENOSYS. THen call it here.
Quoted 24 lines
drivers/cpu/cpu-uclass.c +16
-0+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);include/cpu.h +0
-0
include/cpu.h struct cpu_ops { · line 95
Quoted 7 lines
include/cpu.h +4
-0@@ -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 +*
Can you expand that a little bit, and below? It is the CPU that U-Boot is currently running from, right?
include/cpu.h struct cpu_ops { · line 99
Quoted 4 lines
include/cpu.h +4
-0+* @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);
is_current() since it is always a cpu.
Also please use int instead of bool as the return value, since we need to support an error, when we cannot tell, for example.
Quoted 16 lines
include/cpu.h +7
-1};#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 --
Quoted 1 line
2.16.4
Regards,
Simon