blob: e8b39335d4631ae4f57123017c9c9f663feee3d1 [file] [log] [blame]
Soby Mathewe5674e12017-11-06 13:56:40 +00001/*
David Horstmannd13dbb62021-03-01 19:34:37 +00002 * Copyright (c) 2018-2021, ARM Limited and Contributors. All rights reserved.
Soby Mathewe5674e12017-11-06 13:56:40 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/* Helper functions to offer easier navigation of Device Tree Blob */
8
Antonio Nino Diazc3cf06f2018-11-08 10:20:19 +00009#ifndef FDT_WRAPPERS_H
10#define FDT_WRAPPERS_H
Soby Mathewe5674e12017-11-06 13:56:40 +000011
Andre Przywara5a430c02020-07-09 12:33:17 +010012#include <libfdt_env.h>
13
Soby Mathewe5674e12017-11-06 13:56:40 +000014/* Number of cells, given total length in bytes. Each cell is 4 bytes long */
Antonio Nino Diaz81542c02018-10-04 09:55:23 +010015#define NCELLS(len) ((len) / 4U)
Soby Mathewe5674e12017-11-06 13:56:40 +000016
Andre Przywaraff4e6c32020-03-26 11:22:37 +000017int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
18 uint32_t *value);
Andre Przywarabe858cf2020-03-26 11:50:33 +000019uint32_t fdt_read_uint32_default(const void *dtb, int node,
20 const char *prop_name, uint32_t dflt_value);
Andre Przywaraff4e6c32020-03-26 11:22:37 +000021int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
22 uint64_t *value);
Andre Przywara6e3a89f2020-03-30 23:21:13 +010023int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name,
24 unsigned int cells, uint32_t *value);
Antonio Nino Diaz27473622018-06-26 10:34:07 +010025int fdtw_read_string(const void *dtb, int node, const char *prop,
26 char *str, size_t size);
David Horstmannd13dbb62021-03-01 19:34:37 +000027int fdtw_read_uuid(const void *dtb, int node, const char *prop,
28 unsigned int length, uint8_t *uuid);
Soby Mathewe5674e12017-11-06 13:56:40 +000029int fdtw_write_inplace_cells(void *dtb, int node, const char *prop,
30 unsigned int cells, void *value);
Alexei Fedorov0a2ab6e2020-01-29 16:21:28 +000031int fdtw_read_bytes(const void *dtb, int node, const char *prop,
32 unsigned int length, void *value);
33int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop,
34 unsigned int length, const void *data);
Andre Przywara364ad242020-03-26 11:57:43 +000035int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
36 uintptr_t *base, size_t *size);
Andre Przywara7ad6d362020-03-26 12:11:34 +000037int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
38 uintptr_t *base, size_t *size);
Andre Przywara60e2e272020-03-26 12:52:06 +000039int fdt_get_stdout_node_offset(const void *dtb);
Antonio Nino Diaz27473622018-06-26 10:34:07 +010040
Madhukar Pappireddy447870b2020-03-24 10:03:34 -050041uint64_t fdtw_translate_address(const void *dtb, int bus_node,
42 uint64_t base_address);
43
Andre Przywara5a430c02020-07-09 12:33:17 +010044static inline uint32_t fdt_blob_size(const void *dtb)
45{
46 const uint32_t *dtb_header = dtb;
47
48 return fdt32_to_cpu(dtb_header[1]);
49}
50
Antonio Nino Diazc3cf06f2018-11-08 10:20:19 +000051#endif /* FDT_WRAPPERS_H */