fdt_wrappers.h 1.8 KB
Newer Older
1
/*
2
 * Copyright (c) 2018-2021, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
8
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/* Helper functions to offer easier navigation of Device Tree Blob */

9
10
#ifndef FDT_WRAPPERS_H
#define FDT_WRAPPERS_H
11

12
13
#include <libfdt_env.h>

14
/* Number of cells, given total length in bytes. Each cell is 4 bytes long */
15
#define NCELLS(len) ((len) / 4U)
16

17
18
int fdt_read_uint32(const void *dtb, int node, const char *prop_name,
		    uint32_t *value);
19
20
uint32_t fdt_read_uint32_default(const void *dtb, int node,
				 const char *prop_name, uint32_t dflt_value);
21
22
int fdt_read_uint64(const void *dtb, int node, const char *prop_name,
		    uint64_t *value);
23
24
int fdt_read_uint32_array(const void *dtb, int node, const char *prop_name,
			  unsigned int cells, uint32_t *value);
25
26
int fdtw_read_string(const void *dtb, int node, const char *prop,
		char *str, size_t size);
27
28
int fdtw_read_uuid(const void *dtb, int node, const char *prop,
		   unsigned int length, uint8_t *uuid);
29
30
int fdtw_write_inplace_cells(void *dtb, int node, const char *prop,
		unsigned int cells, void *value);
31
32
33
34
int fdtw_read_bytes(const void *dtb, int node, const char *prop,
		unsigned int length, void *value);
int fdtw_write_inplace_bytes(void *dtb, int node, const char *prop,
		unsigned int length, const void *data);
35
36
int fdt_get_reg_props_by_index(const void *dtb, int node, int index,
			       uintptr_t *base, size_t *size);
37
38
int fdt_get_reg_props_by_name(const void *dtb, int node, const char *name,
			      uintptr_t *base, size_t *size);
39
int fdt_get_stdout_node_offset(const void *dtb);
40

41
42
43
uint64_t fdtw_translate_address(const void *dtb, int bus_node,
				uint64_t base_address);

44
45
46
47
48
49
50
static inline uint32_t fdt_blob_size(const void *dtb)
{
	const uint32_t *dtb_header = dtb;

	return fdt32_to_cpu(dtb_header[1]);
}

51
#endif /* FDT_WRAPPERS_H */