mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-23 04:48:14 +00:00
feat(fdt-wrappers): add CPU enumeration utility function
This change adds a new utility function - `fdtw_for_each_cpu` - to invoke a callback for every CPU node listed in a flattened device tree (FDT) with the node identifier and the MPIDR of the core it describes. Signed-off-by: Chris Kay <chris.kay@arm.com> Change-Id: Iabb5c0f0c9d11928a4a7a41cdc7d1e09aadeb2bc
This commit is contained in:
parent
1fa05dab07
commit
2d9ea36035
2 changed files with 47 additions and 0 deletions
|
@ -572,3 +572,47 @@ uint64_t fdtw_translate_address(const void *dtb, int node,
|
||||||
/* Translate the local device address recursively */
|
/* Translate the local device address recursively */
|
||||||
return fdtw_translate_address(dtb, local_bus_node, global_address);
|
return fdtw_translate_address(dtb, local_bus_node, global_address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For every CPU node (`/cpus/cpu@n`) in an FDT, execute a callback passing a
|
||||||
|
* pointer to the FDT and the offset of the CPU node. If the return value of the
|
||||||
|
* callback is negative, it is treated as an error and the loop is aborted. In
|
||||||
|
* this situation, the value of the callback is returned from the function.
|
||||||
|
*
|
||||||
|
* Returns `0` on success, or a negative integer representing an error code.
|
||||||
|
*/
|
||||||
|
int fdtw_for_each_cpu(const void *dtb,
|
||||||
|
int (*callback)(const void *dtb, int node, uintptr_t mpidr))
|
||||||
|
{
|
||||||
|
int ret = 0;
|
||||||
|
int parent, node = 0;
|
||||||
|
|
||||||
|
parent = fdt_path_offset(dtb, "/cpus");
|
||||||
|
if (parent < 0) {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
fdt_for_each_subnode(node, dtb, parent) {
|
||||||
|
const char *name;
|
||||||
|
int len;
|
||||||
|
|
||||||
|
uintptr_t mpidr = 0U;
|
||||||
|
|
||||||
|
name = fdt_get_name(dtb, node, &len);
|
||||||
|
if (strncmp(name, "cpu@", 4) != 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = fdt_get_reg_props_by_index(dtb, node, 0, &mpidr, NULL);
|
||||||
|
if (ret < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = callback(dtb, node, mpidr);
|
||||||
|
if (ret < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -41,6 +41,9 @@ int fdt_get_stdout_node_offset(const void *dtb);
|
||||||
uint64_t fdtw_translate_address(const void *dtb, int bus_node,
|
uint64_t fdtw_translate_address(const void *dtb, int bus_node,
|
||||||
uint64_t base_address);
|
uint64_t base_address);
|
||||||
|
|
||||||
|
int fdtw_for_each_cpu(const void *fdt,
|
||||||
|
int (*callback)(const void *dtb, int node, uintptr_t mpidr));
|
||||||
|
|
||||||
static inline uint32_t fdt_blob_size(const void *dtb)
|
static inline uint32_t fdt_blob_size(const void *dtb)
|
||||||
{
|
{
|
||||||
const uint32_t *dtb_header = dtb;
|
const uint32_t *dtb_header = dtb;
|
||||||
|
|
Loading…
Add table
Reference in a new issue