summaryrefslogtreecommitdiff
path: root/src/lib/device_tree.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/device_tree.c')
-rw-r--r--src/lib/device_tree.c178
1 files changed, 94 insertions, 84 deletions
diff --git a/src/lib/device_tree.c b/src/lib/device_tree.c
index a68e1b74c5..2e81a08779 100644
--- a/src/lib/device_tree.c
+++ b/src/lib/device_tree.c
@@ -133,7 +133,7 @@ static int print_flat_node(const void *blob, uint32_t start_offset, int depth)
offset += size;
}
- printk(BIOS_DEBUG, "\n"); // empty line between props and nodes
+ printk(BIOS_DEBUG, "\n"); /* empty line between props and nodes */
while ((size = print_flat_node(blob, offset, depth + 1)))
offset += size;
@@ -279,9 +279,9 @@ struct device_tree *fdt_unflatten(const void *blob)
uint32_t min_offset = 0;
min_offset = MIN(struct_offset, strings_offset);
min_offset = MIN(min_offset, reserve_offset);
- // Assume everything up to the first non-header component is part of
- // the header and needs to be preserved. This will protect us against
- // new elements being added in the future.
+ /* Assume everything up to the first non-header component is part of
+ the header and needs to be preserved. This will protect us against
+ new elements being added in the future. */
tree->header_size = min_offset;
struct device_tree_reserve_map_entry *entry;
@@ -309,25 +309,25 @@ struct device_tree *fdt_unflatten(const void *blob)
static void dt_flat_prop_size(struct device_tree_property *prop,
uint32_t *struct_size, uint32_t *strings_size)
{
- // Starting token.
+ /* Starting token. */
*struct_size += sizeof(uint32_t);
- // Size.
+ /* Size. */
*struct_size += sizeof(uint32_t);
- // Name offset.
+ /* Name offset. */
*struct_size += sizeof(uint32_t);
- // Property value.
+ /* Property value. */
*struct_size += ALIGN_UP(prop->prop.size, sizeof(uint32_t));
- // Property name.
+ /* Property name. */
*strings_size += strlen(prop->prop.name) + 1;
}
static void dt_flat_node_size(struct device_tree_node *node,
uint32_t *struct_size, uint32_t *strings_size)
{
- // Starting token.
+ /* Starting token. */
*struct_size += sizeof(uint32_t);
- // Node name.
+ /* Node name. */
*struct_size += ALIGN_UP(strlen(node->name) + 1, sizeof(uint32_t));
struct device_tree_property *prop;
@@ -338,7 +338,7 @@ static void dt_flat_node_size(struct device_tree_node *node,
list_for_each(child, node->children, list_node)
dt_flat_node_size(child, struct_size, strings_size);
- // End token.
+ /* End token. */
*struct_size += sizeof(uint32_t);
}
@@ -355,7 +355,7 @@ uint32_t dt_flat_size(const struct device_tree *tree)
dt_flat_node_size(tree->root, &struct_size, &strings_size);
size += struct_size;
- // End token.
+ /* End token. */
size += sizeof(uint32_t);
size += strings_size;
@@ -480,7 +480,7 @@ void dt_flatten(const struct device_tree *tree, void *start_dest)
static void print_node(const struct device_tree_node *node, int depth)
{
print_indent(depth);
- if (depth == 0) // root node has no name, print a starting slash
+ if (depth == 0) /* root node has no name, print a starting slash */
printk(BIOS_DEBUG, "/");
printk(BIOS_DEBUG, "%s {\n", node->name);
@@ -488,7 +488,7 @@ static void print_node(const struct device_tree_node *node, int depth)
list_for_each(prop, node->properties, list_node)
print_property(&prop->prop, depth + 1);
- printk(BIOS_DEBUG, "\n"); // empty line between props and nodes
+ printk(BIOS_DEBUG, "\n"); /* empty line between props and nodes */
struct device_tree_node *child;
list_for_each(child, node->children, list_node)
@@ -548,13 +548,13 @@ struct device_tree_node *dt_find_node(struct device_tree_node *parent,
{
struct device_tree_node *node, *found = NULL;
- // Update #address-cells and #size-cells for this level.
+ /* Update #address-cells and #size-cells for this level. */
dt_read_cell_props(parent, addrcp, sizecp);
if (!*path)
return parent;
- // Find the next node in the path, if it exists.
+ /* Find the next node in the path, if it exists. */
list_for_each(node, parent->children, list_node) {
if (!strcmp(node->name, *path)) {
found = node;
@@ -562,7 +562,7 @@ struct device_tree_node *dt_find_node(struct device_tree_node *parent,
}
}
- // Otherwise create it or return NULL.
+ /* Otherwise create it or return NULL. */
if (!found) {
if (!create)
return NULL;
@@ -609,8 +609,8 @@ struct device_tree_node *dt_find_node_by_path(struct device_tree *tree,
int i;
struct device_tree_node *node = NULL;
- if (path[0] == '/') { // regular path
- if (path[1] == '\0') { // special case: "/" is root node
+ if (path[0] == '/') { /* regular path */
+ if (path[1] == '\0') { /* special case: "/" is root node */
dt_read_cell_props(tree->root, addrcp, sizecp);
return tree->root;
}
@@ -620,7 +620,7 @@ struct device_tree_node *dt_find_node_by_path(struct device_tree *tree,
return NULL;
parent = tree->root;
- } else { // alias
+ } else { /* alias */
char *alias;
alias = duped_str = strdup(path);
@@ -641,7 +641,7 @@ struct device_tree_node *dt_find_node_by_path(struct device_tree *tree,
}
if (!sub_path) {
- // it's just the alias, no sub-path
+ /* it's just the alias, no sub-path */
free(duped_str);
return parent;
}
@@ -756,7 +756,7 @@ static int dt_check_compat_match(struct device_tree_node *node,
struct device_tree_node *dt_find_compat(struct device_tree_node *parent,
const char *compat)
{
- // Check if the parent node itself is compatible.
+ /* Check if the parent node itself is compatible. */
if (dt_check_compat_match(parent, compat))
return parent;
@@ -1091,11 +1091,11 @@ struct device_tree_node *dt_init_reserved_memory_node(struct device_tree *tree)
if (!reserved)
return NULL;
- // Binding doc says this should have the same #{address,size}-cells as
- // the root.
+ /* Binding doc says this should have the same #{address,size}-cells as
+ the root. */
dt_add_u32_prop(reserved, "#address-cells", addr);
dt_add_u32_prop(reserved, "#size-cells", size);
- // Binding doc says this should be empty (i.e., 1:1 mapping from root).
+ /* Binding doc says this should be empty (1:1 mapping from root). */
dt_add_bin_prop(reserved, "ranges", NULL, 0);
return reserved;
@@ -1141,7 +1141,7 @@ static uint32_t dt_adjust_phandle(struct device_tree_property *prop,
static uint32_t dt_adjust_all_phandles(struct device_tree_node *node,
uint32_t base)
{
- uint32_t new_max = MAX(base, 1); // make sure we don't return 0
+ uint32_t new_max = MAX(base, 1); /* make sure we don't return 0 */
struct device_tree_property *prop;
struct device_tree_node *child;
@@ -1154,7 +1154,7 @@ static uint32_t dt_adjust_all_phandles(struct device_tree_node *node,
if (!node->phandle)
return 0;
new_max = MAX(new_max, node->phandle);
- } // no break -- can have more than one phandle prop
+ } /* no break -- can have more than one phandle prop */
list_for_each(child, node->children, list_node)
new_max = MAX(new_max, dt_adjust_all_phandles(child, base));
@@ -1180,11 +1180,13 @@ static int dt_fixup_locals(struct device_tree_node *node,
struct device_tree_node *fixup_child;
int i;
- // For local fixups the /__local_fixup__ subtree contains the same node
- // hierarchy as the main tree we're fixing up. Each property contains
- // the fixup offsets for the respective property in the main tree. For
- // each property in the fixup node, find the corresponding property in
- // the base node and apply fixups to all offsets it specifies.
+ /*
+ * For local fixups the /__local_fixup__ subtree contains the same node
+ * hierarchy as the main tree we're fixing up. Each property contains
+ * the fixup offsets for the respective property in the main tree. For
+ * each property in the fixup node, find the corresponding property in
+ * the base node and apply fixups to all offsets it specifies.
+ */
list_for_each(fixup_prop, fixup->properties, list_node) {
struct device_tree_property *base_prop = NULL;
list_for_each(prop, node->properties, list_node)
@@ -1193,8 +1195,8 @@ static int dt_fixup_locals(struct device_tree_node *node,
break;
}
- // We should always find a corresponding base prop for a fixup,
- // and fixup props contain a list of 32-bit fixup offsets.
+ /* We should always find a corresponding base prop for a fixup,
+ and fixup props contain a list of 32-bit fixup offsets. */
if (!base_prop || fixup_prop->prop.size % sizeof(uint32_t))
return -1;
@@ -1204,8 +1206,8 @@ static int dt_fixup_locals(struct device_tree_node *node,
return -1;
}
- // Now recursively descend both the base tree and the /__local_fixups__
- // subtree in sync to apply all fixups.
+ /* Now recursively descend both the base tree and the /__local_fixups__
+ subtree in sync to apply all fixups. */
list_for_each(fixup_child, fixup->children, list_node) {
struct device_tree_node *base_child = NULL;
list_for_each(child, node->children, list_node)
@@ -1214,7 +1216,7 @@ static int dt_fixup_locals(struct device_tree_node *node,
break;
}
- // All fixup nodes should have a corresponding base node.
+ /* All fixup nodes should have a corresponding base node. */
if (!base_child)
return -1;
@@ -1238,10 +1240,10 @@ static void dt_fix_symbols(struct device_tree_node *symbols,
const char *base_path)
{
struct device_tree_property *prop;
- char buf[512]; // Should be enough for maximum DT path length?
- char node_path[64]; // easily enough for /fragment@XXXX/__overlay__
+ char buf[512]; /* Should be enough for maximum DT path length? */
+ char node_path[64]; /* easily enough for /fragment@XXXX/__overlay__ */
- if (!symbols) // If the overlay has no /__symbols__ node, we're done!
+ if (!symbols) /* If the overlay has no /__symbols__ node, we're done! */
return;
int len = snprintf(node_path, sizeof(node_path), "/%s/__overlay__",
@@ -1275,10 +1277,10 @@ static int dt_fixup_external(struct device_tree *overlay,
{
struct device_tree_property *prop;
- // External fixup properties are encoded as "<path>:<prop>:<offset>".
+ /* External fixup properties are encoded as "<path>:<prop>:<offset>". */
char *entry = fixup->prop.data;
while ((void *)entry < fixup->prop.data + fixup->prop.size) {
- // okay to destroy fixup property value, won't be needed again
+ /* okay to destroy fixup property value, won't need it again */
char *node_path = entry;
entry = strchr(node_path, ':');
if (!entry)
@@ -1303,18 +1305,18 @@ static int dt_fixup_external(struct device_tree *overlay,
break;
}
- // Move entry to first char after number, must be a '\0'.
+ /* Move entry to first char after number, must be a '\0'. */
uint32_t offset = skip_atoi(&entry);
if (!ovl_prop || offset + 4 > ovl_prop->prop.size || entry[0])
return -1;
- entry++; // jump over '\0' to potential next fixup
+ entry++; /* jump over '\0' to potential next fixup */
be32enc(ovl_prop->prop.data + offset, phandle);
- // If this is a /fragment@X:target property, update
- // references to this fragment in the overlay __symbols__ now.
+ /* If this is a /fragment@X:target property, update references
+ to this fragment in the overlay __symbols__ now. */
if (offset == 0 && !strcmp(prop_name, "target") &&
- !strchr(node_path + 1, '/')) // only toplevel nodes
+ !strchr(node_path + 1, '/')) /* only toplevel nodes */
dt_fix_symbols(overlay_symbols, ovl_node, base_path);
}
@@ -1341,27 +1343,29 @@ static int dt_fixup_all_externals(struct device_tree *tree,
{
struct device_tree_property *fix;
- // If we have any external fixups, the base tree must have /__symbols__.
+ /* If we have any external fixups, base tree must have /__symbols__. */
if (!symbols)
return -1;
- // Unlike /__local_fixups__, /__fixups__ is not a whole subtree that
- // mirrors the node hierarchy. It's just a directory of fixup properties
- // that each directly contain all information necessary to apply them.
+ /*
+ * Unlike /__local_fixups__, /__fixups__ is not a whole subtree that
+ * mirrors the node hierarchy. It's just a directory of fixup properties
+ * that each directly contain all information necessary to apply them.
+ */
list_for_each(fix, fixups->properties, list_node) {
- // The name of a fixup property is the label of the node we want
- // a property to phandle-reference. Look it up in /__symbols__.
+ /* The name of a fixup property is the label of the node we want
+ a property to phandle-reference. Look up in /__symbols__. */
const char *path = dt_find_string_prop(symbols, fix->prop.name);
if (!path)
return -1;
- // Find the node the label pointed to to figure out its phandle.
+ /* Find node the label pointed to to figure out its phandle. */
struct device_tree_node *node = dt_find_node_by_path(tree, path,
NULL, NULL, 0);
if (!node)
return -1;
- // Write it into the overlay property(s) pointing to that node.
+ /* Write into the overlay property(s) pointing to that node. */
if (dt_fixup_external(overlay, fix, node->phandle,
path, overlay_symbols) < 0)
return -1;
@@ -1448,23 +1452,23 @@ static int dt_import_fragment(struct device_tree *tree,
struct device_tree_node *fragment,
struct device_tree_node *overlay_symbols)
{
- // The actually overlaid nodes/props are in an __overlay__ child node.
+ /* The actual overlaid nodes/props are in an __overlay__ child node. */
static const char *overlay_path[] = { "__overlay__", NULL };
struct device_tree_node *overlay = dt_find_node(fragment, overlay_path,
NULL, NULL, 0);
- // If it doesn't have an __overlay__ child, it's not a fragment.
+ /* If it doesn't have an __overlay__ child, it's not a fragment. */
if (!overlay)
return 0;
- // The target node of the fragment can be given by path or by phandle.
+ /* Target node of the fragment can be given by path or by phandle. */
struct device_tree_property *prop;
struct device_tree_property *phandle = NULL;
struct device_tree_property *path = NULL;
list_for_each(prop, fragment->properties, list_node) {
if (!strcmp(prop->prop.name, "target")) {
phandle = prop;
- break; // phandle target has priority, stop looking here
+ break; /* phandle target has priority, stop looking */
}
if (!strcmp(prop->prop.name, "target-path"))
path = prop;
@@ -1476,7 +1480,7 @@ static int dt_import_fragment(struct device_tree *tree,
return -1;
target = dt_find_node_by_phandle(tree->root,
be32dec(phandle->prop.data));
- // Symbols already updated as part of dt_fixup_external(target).
+ /* Symbols already updated as part of dt_fixup_external(). */
} else if (path) {
target = dt_find_node_by_path(tree, path->prop.data,
NULL, NULL, 0);
@@ -1501,10 +1505,12 @@ static int dt_import_fragment(struct device_tree *tree,
*/
int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay)
{
- // First, we need to make sure phandles inside the overlay don't clash
- // with those in the base tree. We just define the highest phandle value
- // in the base tree as the "phandle offset" for this overlay and
- // increment all phandles in it by that value.
+ /*
+ * First, we need to make sure phandles inside the overlay don't clash
+ * with those in the base tree. We just define the highest phandle value
+ * in the base tree as the "phandle offset" for this overlay and
+ * increment all phandles in it by that value.
+ */
uint32_t phandle_base = tree->max_phandle;
uint32_t new_max = dt_adjust_all_phandles(overlay->root, phandle_base);
if (!new_max) {
@@ -1513,8 +1519,8 @@ int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay)
}
tree->max_phandle = new_max;
- // Now that we changed phandles in the overlay, we need to update any
- // nodes referring to them. Those are listed in /__local_fixups__.
+ /* Now that we changed phandles in the overlay, we need to update any
+ nodes referring to them. Those are listed in /__local_fixups__. */
struct device_tree_node *local_fixups = dt_find_node_by_path(overlay,
"/__local_fixups__", NULL, NULL, 0);
if (local_fixups && dt_fixup_locals(overlay->root, local_fixups,
@@ -1523,16 +1529,18 @@ int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay)
return -1;
}
- // Besides local phandle references (from nodes within the overlay to
- // other nodes within the overlay), the overlay may also contain phandle
- // references to the base tree. These are stored with invalid values and
- // must be updated now. /__symbols__ contains a list of all labels in
- // the base tree, and /__fixups__ describes all nodes in the overlay
- // that contain external phandle references.
- // We also take this opportunity to update all /fragment@X/__overlay__/
- // prefixes in the overlay's /__symbols__ node to the correct path that
- // the fragment will be placed in later, since this is the only step
- // where we have all necessary information for that easily available.
+ /*
+ * Besides local phandle references (from nodes within the overlay to
+ * other nodes within the overlay), the overlay may also contain phandle
+ * references to the base tree. These are stored with invalid values and
+ * must be updated now. /__symbols__ contains a list of all labels in
+ * the base tree, and /__fixups__ describes all nodes in the overlay
+ * that contain external phandle references.
+ * We also take this opportunity to update all /fragment@X/__overlay__/
+ * prefixes in the overlay's /__symbols__ node to the correct path that
+ * the fragment will be placed in later, since this is the only step
+ * where we have all necessary information for that easily available.
+ */
struct device_tree_node *symbols = dt_find_node_by_path(tree,
"/__symbols__", NULL, NULL, 0);
struct device_tree_node *fixups = dt_find_node_by_path(overlay,
@@ -1546,8 +1554,8 @@ int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay)
return -1;
}
- // After all this fixing up, we can finally merge the overlay into the
- // tree (one fragment at a time, because for some reason it's split up).
+ /* After all this fixing up, we can finally merge overlay into the tree
+ (one fragment at a time, because for some reason it's split up). */
struct device_tree_node *fragment;
list_for_each(fragment, overlay->root->children, list_node)
if (dt_import_fragment(tree, fragment, overlay_symbols) < 0) {
@@ -1556,11 +1564,13 @@ int dt_apply_overlay(struct device_tree *tree, struct device_tree *overlay)
return -1;
}
- // We need to also update /__symbols__ to include labels from this
- // overlay, in case we want to load further overlays with external
- // phandle references to it. If the base tree already has a /__symbols__
- // we merge them together, otherwise we just insert the overlay's
- // /__symbols__ node into the base tree root.
+ /*
+ * We need to also update /__symbols__ to include labels from this
+ * overlay, in case we want to load further overlays with external
+ * phandle references to it. If the base tree already has a /__symbols__
+ * we merge them together, otherwise we just insert the overlay's
+ * /__symbols__ node into the base tree root.
+ */
if (overlay_symbols) {
if (symbols)
dt_copy_subtree(symbols, overlay_symbols, 0);