xref: /openbmc/u-boot/include/dm/of_extra.h (revision 3d5ced9e22d32112a20f9dc0f5fb1f22ef088079)
183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
2b7e0d73bSSimon Glass /*
3b7e0d73bSSimon Glass  * Copyright (c) 2017 Google, Inc
4b7e0d73bSSimon Glass  * Written by Simon Glass <sjg@chromium.org>
5b7e0d73bSSimon Glass  */
6b7e0d73bSSimon Glass 
7b7e0d73bSSimon Glass #ifndef _DM_OF_EXTRA_H
8b7e0d73bSSimon Glass #define _DM_OF_EXTRA_H
9b7e0d73bSSimon Glass 
10b7e0d73bSSimon Glass #include <dm/ofnode.h>
11b7e0d73bSSimon Glass 
12b7e0d73bSSimon Glass enum fmap_compress_t {
13b7e0d73bSSimon Glass 	FMAP_COMPRESS_NONE,
14*e6c5c94aSSimon Glass 	FMAP_COMPRESS_LZ4,
15b7e0d73bSSimon Glass };
16b7e0d73bSSimon Glass 
17b7e0d73bSSimon Glass enum fmap_hash_t {
18b7e0d73bSSimon Glass 	FMAP_HASH_NONE,
19b7e0d73bSSimon Glass 	FMAP_HASH_SHA1,
20b7e0d73bSSimon Glass 	FMAP_HASH_SHA256,
21b7e0d73bSSimon Glass };
22b7e0d73bSSimon Glass 
23b7e0d73bSSimon Glass /* A flash map entry, containing an offset and length */
24b7e0d73bSSimon Glass struct fmap_entry {
25b7e0d73bSSimon Glass 	uint32_t offset;
26b7e0d73bSSimon Glass 	uint32_t length;
27b7e0d73bSSimon Glass 	uint32_t used;			/* Number of bytes used in region */
28b7e0d73bSSimon Glass 	enum fmap_compress_t compress_algo;	/* Compression type */
29*e6c5c94aSSimon Glass 	uint32_t unc_length;			/* Uncompressed length */
30b7e0d73bSSimon Glass 	enum fmap_hash_t hash_algo;		/* Hash algorithm */
31b7e0d73bSSimon Glass 	const uint8_t *hash;			/* Hash value */
32b7e0d73bSSimon Glass 	int hash_size;				/* Hash size */
33b7e0d73bSSimon Glass };
34b7e0d73bSSimon Glass 
35b7e0d73bSSimon Glass /**
36b7e0d73bSSimon Glass  * Read a flash entry from the fdt
37b7e0d73bSSimon Glass  *
38b7e0d73bSSimon Glass  * @param node		Reference to node to read
39b7e0d73bSSimon Glass  * @param entry		Place to put offset and size of this node
40b7e0d73bSSimon Glass  * @return 0 if ok, -ve on error
41b7e0d73bSSimon Glass  */
425e0a7341SSimon Glass int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry);
43b7e0d73bSSimon Glass 
44964cadc4SSimon Glass /**
45964cadc4SSimon Glass  * ofnode_decode_region() - Decode a memory region from a node
46964cadc4SSimon Glass  *
47964cadc4SSimon Glass  * Look up a property in a node which contains a memory region address and
48964cadc4SSimon Glass  * size. Then return a pointer to this address.
49964cadc4SSimon Glass  *
50964cadc4SSimon Glass  * The property must hold one address with a length. This is only tested on
51964cadc4SSimon Glass  * 32-bit machines.
52964cadc4SSimon Glass  *
53964cadc4SSimon Glass  * @param node		ofnode to examine
54964cadc4SSimon Glass  * @param prop_name	name of property to find
55964cadc4SSimon Glass  * @param basep		Returns base address of region
56964cadc4SSimon Glass  * @param size		Returns size of region
57964cadc4SSimon Glass  * @return 0 if ok, -1 on error (property not found)
58964cadc4SSimon Glass  */
59964cadc4SSimon Glass int ofnode_decode_region(ofnode node, const char *prop_name, fdt_addr_t *basep,
60964cadc4SSimon Glass 			 fdt_size_t *sizep);
61964cadc4SSimon Glass 
62964cadc4SSimon Glass /**
63964cadc4SSimon Glass  * ofnode_decode_memory_region()- Decode a named region within a memory bank
64964cadc4SSimon Glass  *
65964cadc4SSimon Glass  * This function handles selection of a memory region. The region is
66964cadc4SSimon Glass  * specified as an offset/size within a particular type of memory.
67964cadc4SSimon Glass  *
68964cadc4SSimon Glass  * The properties used are:
69964cadc4SSimon Glass  *
70964cadc4SSimon Glass  *	<mem_type>-memory<suffix> for the name of the memory bank
71964cadc4SSimon Glass  *	<mem_type>-offset<suffix> for the offset in that bank
72964cadc4SSimon Glass  *
73964cadc4SSimon Glass  * The property value must have an offset and a size. The function checks
74964cadc4SSimon Glass  * that the region is entirely within the memory bank.5
75964cadc4SSimon Glass  *
76964cadc4SSimon Glass  * @param node		ofnode containing the properties (-1 for /config)
77964cadc4SSimon Glass  * @param mem_type	Type of memory to use, which is a name, such as
78964cadc4SSimon Glass  *			"u-boot" or "kernel".
79964cadc4SSimon Glass  * @param suffix	String to append to the memory/offset
80964cadc4SSimon Glass  *			property names
81964cadc4SSimon Glass  * @param basep		Returns base of region
82964cadc4SSimon Glass  * @param sizep		Returns size of region
83964cadc4SSimon Glass  * @return 0 if OK, -ive on error
84964cadc4SSimon Glass  */
85964cadc4SSimon Glass int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
86964cadc4SSimon Glass 				const char *suffix, fdt_addr_t *basep,
87964cadc4SSimon Glass 				fdt_size_t *sizep);
88964cadc4SSimon Glass 
89b7e0d73bSSimon Glass #endif
90