Soby Mathew | b9fccca | 2017-11-06 13:56:40 +0000 | [diff] [blame] | 1 | /* |
Ruchika Gupta | d480202 | 2022-04-08 13:16:16 +0530 | [diff] [blame] | 2 | * Copyright (c) 2018-2022, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | b9fccca | 2017-11-06 13:56:40 +0000 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | /* Helper functions to offer easier navigation of Device Tree Blob */ |
| 8 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 9 | #ifndef FDT_WRAPPERS_H |
| 10 | #define FDT_WRAPPERS_H |
Soby Mathew | b9fccca | 2017-11-06 13:56:40 +0000 | [diff] [blame] | 11 | |
Andre Przywara | 97c6e90 | 2020-07-09 12:33:17 +0100 | [diff] [blame] | 12 | #include <libfdt_env.h> |
| 13 | |
Soby Mathew | b9fccca | 2017-11-06 13:56:40 +0000 | [diff] [blame] | 14 | /* Number of cells, given total length in bytes. Each cell is 4 bytes long */ |
Antonio Nino Diaz | f0b14cf | 2018-10-04 09:55:23 +0100 | [diff] [blame] | 15 | #define NCELLS(len) ((len) / 4U) |
Soby Mathew | b9fccca | 2017-11-06 13:56:40 +0000 | [diff] [blame] | 16 | |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 17 | int fdt_read_uint32(const void *dtb, int node, const char *prop_name, |
| 18 | uint32_t *value); |
Andre Przywara | 2d5690c | 2020-03-26 11:50:33 +0000 | [diff] [blame] | 19 | uint32_t fdt_read_uint32_default(const void *dtb, int node, |
| 20 | const char *prop_name, uint32_t dflt_value); |
Andre Przywara | fe5bdf5 | 2020-03-26 11:22:37 +0000 | [diff] [blame] | 21 | int fdt_read_uint64(const void *dtb, int node, const char *prop_name, |
| 22 | uint64_t *value); |
Andre Przywara | 6cf6a1b | 2020-03-30 23:21:13 +0100 | [diff] [blame] | 23 | int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name, |
| 24 | unsigned int cells, uint32_t *value); |
Antonio Nino Diaz | d85c878 | 2018-06-26 10:34:07 +0100 | [diff] [blame] | 25 | int fdtw_read_string(const void *dtb, int node, const char *prop, |
| 26 | char *str, size_t size); |
David Horstmann | a65a8ff | 2021-03-01 19:34:37 +0000 | [diff] [blame] | 27 | int fdtw_read_uuid(const void *dtb, int node, const char *prop, |
| 28 | unsigned int length, uint8_t *uuid); |
Soby Mathew | b9fccca | 2017-11-06 13:56:40 +0000 | [diff] [blame] | 29 | int fdtw_write_inplace_cells(void *dtb, int node, const char *prop, |
| 30 | unsigned int cells, void *value); |
Alexei Fedorov | 2de82fc | 2020-01-29 16:21:28 +0000 | [diff] [blame] | 31 | int fdtw_read_bytes(const void *dtb, int node, const char *prop, |
| 32 | unsigned int length, void *value); |
| 33 | int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop, |
| 34 | unsigned int length, const void *data); |
Andre Przywara | e183e15 | 2020-03-26 11:57:43 +0000 | [diff] [blame] | 35 | int fdt_get_reg_props_by_index(const void *dtb, int node, int index, |
| 36 | uintptr_t *base, size_t *size); |
Andre Przywara | 4a1c874 | 2020-03-26 12:11:34 +0000 | [diff] [blame] | 37 | int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name, |
| 38 | uintptr_t *base, size_t *size); |
Andre Przywara | a0eaca5 | 2020-03-26 12:52:06 +0000 | [diff] [blame] | 39 | int fdt_get_stdout_node_offset(const void *dtb); |
Antonio Nino Diaz | d85c878 | 2018-06-26 10:34:07 +0100 | [diff] [blame] | 40 | |
Madhukar Pappireddy | 361c1b3 | 2020-03-24 10:03:34 -0500 | [diff] [blame] | 41 | uint64_t fdtw_translate_address(const void *dtb, int bus_node, |
| 42 | uint64_t base_address); |
| 43 | |
Chris Kay | 93c9db0 | 2021-09-28 16:06:25 +0100 | [diff] [blame] | 44 | int fdtw_for_each_cpu(const void *fdt, |
| 45 | int (*callback)(const void *dtb, int node, uintptr_t mpidr)); |
| 46 | |
Ruchika Gupta | d480202 | 2022-04-08 13:16:16 +0530 | [diff] [blame] | 47 | int fdtw_find_or_add_subnode(void *fdt, int parentoffset, const char *name); |
| 48 | |
Andre Przywara | 97c6e90 | 2020-07-09 12:33:17 +0100 | [diff] [blame] | 49 | static inline uint32_t fdt_blob_size(const void *dtb) |
| 50 | { |
| 51 | const uint32_t *dtb_header = dtb; |
| 52 | |
| 53 | return fdt32_to_cpu(dtb_header[1]); |
| 54 | } |
| 55 | |
Laurent Carlier | 246b1ad | 2021-09-30 15:57:09 +0100 | [diff] [blame] | 56 | #define fdt_for_each_compatible_node(dtb, node, compatible_str) \ |
| 57 | for (node = fdt_node_offset_by_compatible(dtb, -1, compatible_str); \ |
| 58 | node >= 0; \ |
| 59 | node = fdt_node_offset_by_compatible(dtb, node, compatible_str)) |
| 60 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 61 | #endif /* FDT_WRAPPERS_H */ |