On 13.06.2025 17:48, Oleksii Kurochko wrote:
> Implements dt_processor_hartid() to get the hart ID of the given
> device tree node and do some checks if CPU is available and given device
> tree node has proper riscv,isa property.
> 
> As a helper function dt_get_hartid() is introduced to deal specifically
> with reg propery of a CPU device node.
> 
> Signed-off-by: Oleksii Kurochko <oleksii.kuroc...@gmail.com>


Acked-by: Jan Beulich <jbeul...@suse.com>

> @@ -14,3 +17,77 @@ void __init smp_prepare_boot_cpu(void)
>      cpumask_set_cpu(0, &cpu_possible_map);
>      cpumask_set_cpu(0, &cpu_online_map);
>  }
> +
> +/**
> + * dt_get_hartid - Get the hartid from a CPU device node
> + *
> + * @cpun: CPU number(logical index) for which device node is required
> + *
> + * Return: The hartid for the CPU node or ~0UL if not found.
> + */
> +static unsigned long dt_get_hartid(const struct dt_device_node *cpun)
> +{
> +    const __be32 *cell;
> +    unsigned int ac;
> +    uint32_t len;
> +
> +    ac = dt_n_addr_cells(cpun);
> +    cell = dt_get_property(cpun, "reg", &len);

I'll commit as is, but I'd like to note that such could be more compact:

    unsigned int ac = dt_n_addr_cells(cpun);
    uint32_t len;
    const __be32 *cell = dt_get_property(cpun, "reg", &len);

> +    /*
> +     * If ac > 2, the result may be truncated or meaningless unless
> +     * dt_read_number() supports wider integers.
> +     *
> +     * TODO: drop (ac > 2) when dt_read_number() will support wider
> +     *       integers.
> +     */
> +    if ( !cell || !ac || (ac > 2) || (ac > len / sizeof(*cell)) )
> +        return ~0UL;
> +
> +    return dt_read_number(cell, ac);

I'd further like to note that this will silently truncate from 64 to 32
bits (when ac == 2) for RV32.

Jan

Reply via email to