1f652e6afSaurel32 /* 2f652e6afSaurel32 * Header with function prototypes to help device tree manipulation using 3f652e6afSaurel32 * libfdt. It also provides functions to read entries from device tree proc 4f652e6afSaurel32 * interface. 5f652e6afSaurel32 * 6f652e6afSaurel32 * Copyright 2008 IBM Corporation. 7f652e6afSaurel32 * Authors: Jerone Young <jyoung5@us.ibm.com> 8f652e6afSaurel32 * Hollis Blanchard <hollisb@us.ibm.com> 9f652e6afSaurel32 * 10f652e6afSaurel32 * This work is licensed under the GNU GPL license version 2 or later. 11f652e6afSaurel32 * 12f652e6afSaurel32 */ 13f652e6afSaurel32 14f652e6afSaurel32 #ifndef __DEVICE_TREE_H__ 15f652e6afSaurel32 #define __DEVICE_TREE_H__ 16f652e6afSaurel32 17ce36252cSAlexander Graf void *create_device_tree(int *sizep); 187ec632b4Spbrook void *load_device_tree(const char *filename_path, int *sizep); 19f652e6afSaurel32 20*5a4348d1SPeter Crosthwaite int qemu_fdt_setprop(void *fdt, const char *node_path, 2145e9dfb2SAlexander Graf const char *property, const void *val_array, int size); 22*5a4348d1SPeter Crosthwaite int qemu_fdt_setprop_cell(void *fdt, const char *node_path, 23f652e6afSaurel32 const char *property, uint32_t val); 24*5a4348d1SPeter Crosthwaite int qemu_fdt_setprop_u64(void *fdt, const char *node_path, 25bb28eb37SAlexander Graf const char *property, uint64_t val); 26*5a4348d1SPeter Crosthwaite int qemu_fdt_setprop_string(void *fdt, const char *node_path, 27f652e6afSaurel32 const char *property, const char *string); 28*5a4348d1SPeter Crosthwaite int qemu_fdt_setprop_phandle(void *fdt, const char *node_path, 298535ab12SAlexander Graf const char *property, 308535ab12SAlexander Graf const char *target_node_path); 31*5a4348d1SPeter Crosthwaite const void *qemu_fdt_getprop(void *fdt, const char *node_path, 32f0aa713fSPeter Maydell const char *property, int *lenp); 33*5a4348d1SPeter Crosthwaite uint32_t qemu_fdt_getprop_cell(void *fdt, const char *node_path, 34f0aa713fSPeter Maydell const char *property); 35*5a4348d1SPeter Crosthwaite uint32_t qemu_fdt_get_phandle(void *fdt, const char *path); 36*5a4348d1SPeter Crosthwaite uint32_t qemu_fdt_alloc_phandle(void *fdt); 37*5a4348d1SPeter Crosthwaite int qemu_fdt_nop_node(void *fdt, const char *node_path); 38*5a4348d1SPeter Crosthwaite int qemu_fdt_add_subnode(void *fdt, const char *name); 39f652e6afSaurel32 40*5a4348d1SPeter Crosthwaite #define qemu_fdt_setprop_cells(fdt, node_path, property, ...) \ 417ae2291eSAlexander Graf do { \ 427ae2291eSAlexander Graf uint32_t qdt_tmp[] = { __VA_ARGS__ }; \ 437ae2291eSAlexander Graf int i; \ 447ae2291eSAlexander Graf \ 457ae2291eSAlexander Graf for (i = 0; i < ARRAY_SIZE(qdt_tmp); i++) { \ 467ae2291eSAlexander Graf qdt_tmp[i] = cpu_to_be32(qdt_tmp[i]); \ 477ae2291eSAlexander Graf } \ 48*5a4348d1SPeter Crosthwaite qemu_fdt_setprop(fdt, node_path, property, qdt_tmp, \ 497ae2291eSAlexander Graf sizeof(qdt_tmp)); \ 507ae2291eSAlexander Graf } while (0) 517ae2291eSAlexander Graf 52*5a4348d1SPeter Crosthwaite void qemu_fdt_dumpdtb(void *fdt, int size); 5371193433SAlexander Graf 5497c38f8cSPeter Maydell /** 55*5a4348d1SPeter Crosthwaite * qemu_fdt_setprop_sized_cells_from_array: 5697c38f8cSPeter Maydell * @fdt: device tree blob 5797c38f8cSPeter Maydell * @node_path: node to set property on 5897c38f8cSPeter Maydell * @property: property to set 5997c38f8cSPeter Maydell * @numvalues: number of values 6097c38f8cSPeter Maydell * @values: array of number-of-cells, value pairs 6197c38f8cSPeter Maydell * 6297c38f8cSPeter Maydell * Set the specified property on the specified node in the device tree 6397c38f8cSPeter Maydell * to be an array of cells. The values of the cells are specified via 6497c38f8cSPeter Maydell * the values list, which alternates between "number of cells used by 6597c38f8cSPeter Maydell * this value" and "value". 6697c38f8cSPeter Maydell * number-of-cells must be either 1 or 2 (other values will result in 6797c38f8cSPeter Maydell * an error being returned). If a value is too large to fit in the 6897c38f8cSPeter Maydell * number of cells specified for it, an error is returned. 6997c38f8cSPeter Maydell * 7097c38f8cSPeter Maydell * This function is useful because device tree nodes often have cell arrays 7197c38f8cSPeter Maydell * which are either lists of addresses or lists of address,size tuples, but 7297c38f8cSPeter Maydell * the number of cells used for each element vary depending on the 7397c38f8cSPeter Maydell * #address-cells and #size-cells properties of their parent node. 7497c38f8cSPeter Maydell * If you know all your cell elements are one cell wide you can use the 75*5a4348d1SPeter Crosthwaite * simpler qemu_fdt_setprop_cells(). If you're not setting up the 76*5a4348d1SPeter Crosthwaite * array programmatically, qemu_fdt_setprop_sized_cells may be more 7797c38f8cSPeter Maydell * convenient. 7897c38f8cSPeter Maydell * 7997c38f8cSPeter Maydell * Return value: 0 on success, <0 on error. 8097c38f8cSPeter Maydell */ 81*5a4348d1SPeter Crosthwaite int qemu_fdt_setprop_sized_cells_from_array(void *fdt, 8297c38f8cSPeter Maydell const char *node_path, 8397c38f8cSPeter Maydell const char *property, 8497c38f8cSPeter Maydell int numvalues, 8597c38f8cSPeter Maydell uint64_t *values); 8697c38f8cSPeter Maydell 8797c38f8cSPeter Maydell /** 88*5a4348d1SPeter Crosthwaite * qemu_fdt_setprop_sized_cells: 8997c38f8cSPeter Maydell * @fdt: device tree blob 9097c38f8cSPeter Maydell * @node_path: node to set property on 9197c38f8cSPeter Maydell * @property: property to set 9297c38f8cSPeter Maydell * @...: list of number-of-cells, value pairs 9397c38f8cSPeter Maydell * 9497c38f8cSPeter Maydell * Set the specified property on the specified node in the device tree 9597c38f8cSPeter Maydell * to be an array of cells. The values of the cells are specified via 9697c38f8cSPeter Maydell * the variable arguments, which alternates between "number of cells 9797c38f8cSPeter Maydell * used by this value" and "value". 9897c38f8cSPeter Maydell * 9997c38f8cSPeter Maydell * This is a convenience wrapper for the function 100*5a4348d1SPeter Crosthwaite * qemu_fdt_setprop_sized_cells_from_array(). 10197c38f8cSPeter Maydell * 10297c38f8cSPeter Maydell * Return value: 0 on success, <0 on error. 10397c38f8cSPeter Maydell */ 104*5a4348d1SPeter Crosthwaite #define qemu_fdt_setprop_sized_cells(fdt, node_path, property, ...) \ 10597c38f8cSPeter Maydell ({ \ 10697c38f8cSPeter Maydell uint64_t qdt_tmp[] = { __VA_ARGS__ }; \ 107*5a4348d1SPeter Crosthwaite qemu_fdt_setprop_sized_cells_from_array(fdt, node_path, \ 10897c38f8cSPeter Maydell property, \ 10997c38f8cSPeter Maydell ARRAY_SIZE(qdt_tmp) / 2, \ 11097c38f8cSPeter Maydell qdt_tmp); \ 11197c38f8cSPeter Maydell }) 11297c38f8cSPeter Maydell 113f652e6afSaurel32 #endif /* __DEVICE_TREE_H__ */ 114