of/flattree: Add of_flat_dt_match() helper function
This patch adds of_flat_dt_match() which tests a node for compatibility with a list of values and converts the relevant powerpc platform code to use it. This approach simplifies the board support code a bit. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Reviewed-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
This commit is contained in:
@@ -78,19 +78,23 @@ void *of_fdt_get_property(struct boot_param_header *blob,
|
||||
* @blob: A device tree blob
|
||||
* @node: node to test
|
||||
* @compat: compatible string to compare with compatible list.
|
||||
*
|
||||
* On match, returns a non-zero value with smaller values returned for more
|
||||
* specific compatible values.
|
||||
*/
|
||||
int of_fdt_is_compatible(struct boot_param_header *blob,
|
||||
unsigned long node, const char *compat)
|
||||
{
|
||||
const char *cp;
|
||||
unsigned long cplen, l;
|
||||
unsigned long cplen, l, score = 0;
|
||||
|
||||
cp = of_fdt_get_property(blob, node, "compatible", &cplen);
|
||||
if (cp == NULL)
|
||||
return 0;
|
||||
while (cplen > 0) {
|
||||
score++;
|
||||
if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
|
||||
return 1;
|
||||
return score;
|
||||
l = strlen(cp) + 1;
|
||||
cp += l;
|
||||
cplen -= l;
|
||||
@@ -99,6 +103,27 @@ int of_fdt_is_compatible(struct boot_param_header *blob,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* of_fdt_match - Return true if node matches a list of compatible values
|
||||
*/
|
||||
int of_fdt_match(struct boot_param_header *blob, unsigned long node,
|
||||
const char **compat)
|
||||
{
|
||||
unsigned int tmp, score = 0;
|
||||
|
||||
if (!compat)
|
||||
return 0;
|
||||
|
||||
while (*compat) {
|
||||
tmp = of_fdt_is_compatible(blob, node, *compat);
|
||||
if (tmp && (score == 0 || (tmp < score)))
|
||||
score = tmp;
|
||||
compat++;
|
||||
}
|
||||
|
||||
return score;
|
||||
}
|
||||
|
||||
static void *unflatten_dt_alloc(unsigned long *mem, unsigned long size,
|
||||
unsigned long align)
|
||||
{
|
||||
@@ -511,6 +536,14 @@ int __init of_flat_dt_is_compatible(unsigned long node, const char *compat)
|
||||
return of_fdt_is_compatible(initial_boot_params, node, compat);
|
||||
}
|
||||
|
||||
/**
|
||||
* of_flat_dt_match - Return true if node matches a list of compatible values
|
||||
*/
|
||||
int __init of_flat_dt_match(unsigned long node, const char **compat)
|
||||
{
|
||||
return of_fdt_match(initial_boot_params, node, compat);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BLK_DEV_INITRD
|
||||
/**
|
||||
* early_init_dt_check_for_initrd - Decode initrd location from flat tree
|
||||
|
Reference in New Issue
Block a user