[PATCH v2 12/16] cpu: Add loongarch_cpu driver
Simon Glass
sjg at chromium.org
Thu Jul 2 12:26:42 CEST 2026
Hi Jiaxun,
On 2026-07-01T11:17:53, Yao Zi <me at ziyao.cc> wrote:
> cpu: Add loongarch_cpu driver
>
> Implement a driver for LoongArch CPU solely for gathering
> some information bits from FDT and CPU level config registers.
>
> Signed-off-by: Jiaxun Yang <jiaxun.yang at flygoat.com>
> Signed-off-by: Yao Zi <me at ziyao.cc>
>
> drivers/cpu/Kconfig | 6 ++
> drivers/cpu/Makefile | 1 +
> drivers/cpu/loongarch_cpu.c | 148 ++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 155 insertions(+)
> diff --git a/drivers/cpu/loongarch_cpu.c b/drivers/cpu/loongarch_cpu.c
> @@ -0,0 +1,148 @@
> +static int loongarch_cpu_get_desc(const struct udevice *dev, char *buf, int size)
> +{
> + const char *cpu;
> +
> + /* We try to get CPU name from IOCSR first */
> + if ((read_cpucfg(LOONGARCH_CPUCFG1) & CPUCFG1_IOCSR)) {
> + int i;
> + char vendor_buf[9] = { 0 };
> + char name_buf[9] = { 0 };
> + u64 vendor = iocsr_read64(LOONGARCH_IOCSR_VENDOR);
> + u64 name = iocsr_read64(LOONGARCH_IOCSR_CPUNAME);
> +
> + if (!vendor || !name)
> + goto get_desc_dt;
> +
> + for (i = 0; i < sizeof(u64); i++) {
> + vendor_buf[i] = vendor & 0xff;
> + name_buf[i] = name & 0xff;
> + vendor >>= 8;
> + name >>= 8;
> + }
> +
> + snprintf(buf, size, '%s-%s', vendor_buf, name_buf);
> +
> + return 0;
> + }
> +
> +get_desc_dt:
> + cpu = dev_read_string(dev, 'compatible');
Please drop the goto - it jumps out of an if-body to a label at the
same scope. Close the if-body when the IOCSR read is valid and let
the DT path fall through.
Also, snprintf() can silently truncate if size is smaller than the
composed string; please return -ENOSPC in that case, similar to the
DT branch below.
Regards,
Simon
More information about the U-Boot
mailing list