From 247970978d3de3e46537550e83137df586d9dee9 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:37 -0600 Subject: dm: core: Reverse the argument order in ofnode_copy_props() Follow the order used by memcpy() as it may be less confusing. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 06c969c61fe..32917f66155 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1598,7 +1598,7 @@ int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep); /** * ofnode_copy_props() - copy all properties from one node to another * - * Makes a copy of all properties from the source note in the destination node. + * Makes a copy of all properties from the source node to the destination node. * Existing properties in the destination node remain unchanged, except that * any with the same name are overwritten, including changing the size of the * property. @@ -1606,9 +1606,9 @@ int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep); * For livetree, properties are copied / allocated, so the source tree does not * need to be present afterwards. * + * @dst: Destination node to write properties to * @src: Source node to read properties from - * @dst: Destination node to write properties too */ -int ofnode_copy_props(ofnode src, ofnode dst); +int ofnode_copy_props(ofnode dst, ofnode src); #endif -- cgit v1.2.3 From e0c3c21d8ba1a0abbb7effee6c5a952f3e65a03d Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:40 -0600 Subject: dm: core: Add a function to create an empty tree Provide a function to create a new, empty tree. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 32917f66155..0b96ab34ede 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -127,6 +127,15 @@ static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset) #endif /* OFNODE_MULTI_TREE */ +/** + * oftree_new() - Create a new, empty tree + * + * @treep: Returns a pointer to the tree, on success + * Returns: 0 on success, -ENOMEM if out of memory, -E2BIG if !OF_LIVE and + * there are too many (flattrees) already + */ +int oftree_new(oftree *treep); + /** * ofnode_to_np() - convert an ofnode to a live DT node pointer * -- cgit v1.2.3 From c15862ffdd5f7797338808cf7645786109bcddc3 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:41 -0600 Subject: dm: core: Add a way to copy a node Add a function to copy a node to another place under a new name. This is useful at least for testing, since copying a test node with existing properties is easier than writing the code to generate it all afresh. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0b96ab34ede..7eb04accd62 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1620,4 +1620,19 @@ int ofnode_add_subnode(ofnode parent, const char *name, ofnode *nodep); */ int ofnode_copy_props(ofnode dst, ofnode src); +/** + * ofnode_copy_node() - Copy a node to another place + * + * If a node with this name already exists in dst_parent, this returns an + * .error + * + * @dst_parent: Parent of the newly copied node + * @name: Name to give the new node + * @src: Source node to copy + * @nodep: Returns the new node, or the existing node if there is one + * Return: 0 if OK, -EEXIST if dst_parent already has a node with this parent + */ +int ofnode_copy_node(ofnode dst_parent, const char *name, ofnode src, + ofnode *nodep); + #endif -- cgit v1.2.3 From 67fb2159fb3438359fa0fc3f8cb491ffe8d57c0f Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:42 -0600 Subject: dm: core: Add a way to delete a node Add a function to delete a node in an existing tree. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 7eb04accd62..f1ee02cd837 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1635,4 +1635,17 @@ int ofnode_copy_props(ofnode dst, ofnode src); int ofnode_copy_node(ofnode dst_parent, const char *name, ofnode src, ofnode *nodep); +/** + * ofnode_delete() - Delete a node + * + * Delete a node from the tree + * + * @nodep: Pointer to node to delete (set to ofnode_null() on success) + * Return: 0 if OK, -ENOENT if the node does not exist, -EPERM if it is the root + * node (wWhich cannot be removed), -EFAULT if the tree is broken (to_remove is + * not a child of its parent), + * + */ +int ofnode_delete(ofnode *nodep); + #endif -- cgit v1.2.3 From 62b1db33778611a3023d1e3a98e869b495edc9ca Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:43 -0600 Subject: dm: core: Add a way to convert a devicetree to a dtb Add a way to flatten a devicetree into binary form. For livetree this involves generating the devicetree using fdt_property() and other calls. For flattree it simply involves providing the buffer containing the tree. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index f1ee02cd837..a8605fb718b 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -17,6 +17,7 @@ /* Enable checks to protect against invalid calls */ #undef OF_CHECKS +struct abuf; struct resource; #include @@ -136,6 +137,18 @@ static inline ofnode noffset_to_ofnode(ofnode other_node, int of_offset) */ int oftree_new(oftree *treep); +/** + * oftree_to_fdt() - Convert an oftree to a flat FDT + * + * @tree: tree to flatten (if livetree) or copy (if not) + * @buf: Returns inited buffer containing the newly created flat tree. Note + * that for flat tree the buffer is not allocated. In either case the caller + * must call abut_uninit() to free any memory used by @buf + * Return: 0 on success, -ENOMEM if out of memory, other -ve value for any other + * error + */ +int oftree_to_fdt(oftree tree, struct abuf *buf); + /** * ofnode_to_np() - convert an ofnode to a live DT node pointer * -- cgit v1.2.3 From d9216c8683fced4cbf6d437b4357c9368bf1bf86 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:44 -0600 Subject: dm: core: Support writing a boolean Add functions to write a boolean property. This involves deleting it if the value is false. Add a new ofnode_has_property() as well. Add a comment about the behaviour of of_read_property() when the property value is empty. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index a8605fb718b..ebea29d32af 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1037,10 +1037,19 @@ int ofnode_decode_panel_timing(ofnode node, * @node: node to read * @propname: property to read * @lenp: place to put length on success - * Return: pointer to property, or NULL if not found + * Return: pointer to property value, or NULL if not found or empty */ const void *ofnode_get_property(ofnode node, const char *propname, int *lenp); +/** + * ofnode_has_property() - check if a node has a named property + * + * @node: node to read + * @propname: property to read + * Return: true if the property exists in the node, false if not + */ +bool ofnode_has_property(ofnode node, const char *propname); + /** * ofnode_first_property()- get the reference of the first property * @@ -1452,6 +1461,27 @@ int ofnode_write_string(ofnode node, const char *propname, const char *value); */ int ofnode_write_u32(ofnode node, const char *propname, u32 value); +/** + * ofnode_write_bool() - Set a boolean property of an ofnode + * + * This either adds or deleted a property with a zero-length value + * + * @node: The node for whose string property should be set + * @propname: The name of the string property to set + * @value: The new value of the boolean property + * Return: 0 if successful, -ve on error + */ +int ofnode_write_bool(ofnode node, const char *propname, bool value); + +/** + * ofnode_delete_prop() - Delete a property + * + * @node: Node containing the property to delete + * @propname: Name of property to delete + * Return: 0 if successful, -ve on error + */ +int ofnode_delete_prop(ofnode node, const char *propname); + /** * ofnode_set_enabled() - Enable or disable a device tree node given by its * ofnode -- cgit v1.2.3 From 7071c82bdc55ed5d7955d8e1682b7c80af5659b5 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:45 -0600 Subject: dm: core: Support writing a 64-bit value Add support for writing a single 64-bit value into a property. Repurpose the existing tests to handle this case too. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ebea29d32af..ef1437cc556 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1461,6 +1461,16 @@ int ofnode_write_string(ofnode node, const char *propname, const char *value); */ int ofnode_write_u32(ofnode node, const char *propname, u32 value); +/** + * ofnode_write_u64() - Set an integer property of an ofnode + * + * @node: The node for whose string property should be set + * @propname: The name of the string property to set + * @value: The new value of the 64-bit integer property + * Return: 0 if successful, -ve on error + */ +int ofnode_write_u64(ofnode node, const char *propname, u64 value); + /** * ofnode_write_bool() - Set a boolean property of an ofnode * -- cgit v1.2.3 From f69d3d6d10b15872a279aeb10b7c522627aff6c2 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Tue, 26 Sep 2023 08:14:58 -0600 Subject: pci: serial: Support reading PCI-register size with base The PCI helpers read only the base address for a PCI region. In some cases the size is needed as well, e.g. to pass along to a driver which needs to know the size of its register area. Update the functions to allow the size to be returned. For serial, record the information and provided it with the serial_info() call. A limitation still exists in that the size is not available when OF_LIVE is enabled, so take account of that in the tests. Signed-off-by: Simon Glass --- include/dm/ofnode.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include/dm/ofnode.h') diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index ef1437cc556..19e97a90327 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1153,13 +1153,15 @@ const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname, * @type: pci address type (FDT_PCI_SPACE_xxx) * @propname: name of property to find * @addr: returns pci address in the form of fdt_pci_addr + * @size: if non-null, returns register-space size * Return: * 0 if ok, -ENOENT if the property did not exist, -EINVAL if the * format of the property was invalid, -ENXIO if the requested * address type was not found */ int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type, - const char *propname, struct fdt_pci_addr *addr); + const char *propname, struct fdt_pci_addr *addr, + fdt_size_t *size); /** * ofnode_read_pci_vendev() - look up PCI vendor and device id -- cgit v1.2.3