1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (c) 2017 Google, Inc
4  * Written by Simon Glass <sjg@chromium.org>
5  */
6 
7 #ifndef _DM_OF_EXTRA_H
8 #define _DM_OF_EXTRA_H
9 
10 #include <dm/ofnode.h>
11 
12 enum fmap_compress_t {
13 	FMAP_COMPRESS_NONE,
14 	FMAP_COMPRESS_LZMA,
15 	FMAP_COMPRESS_LZ4,
16 
17 	FMAP_COMPRESS_COUNT,
18 	FMAP_COMPRESS_UNKNOWN,
19 };
20 
21 enum fmap_hash_t {
22 	FMAP_HASH_NONE,
23 	FMAP_HASH_SHA1,
24 	FMAP_HASH_SHA256,
25 };
26 
27 /* A flash map entry, containing an offset and length */
28 struct fmap_entry {
29 	uint32_t offset;
30 	uint32_t length;
31 	uint32_t used;			/* Number of bytes used in region */
32 	enum fmap_compress_t compress_algo;	/* Compression type */
33 	uint32_t unc_length;			/* Uncompressed length */
34 	enum fmap_hash_t hash_algo;		/* Hash algorithm */
35 	const uint8_t *hash;			/* Hash value */
36 	int hash_size;				/* Hash size */
37 	/* Node pointer if CBFS, else NULL */
38 	const struct cbfs_cachenode *cbfs_node;
39 	/* Hash node pointer if CBFS, else NULL */
40 	const struct cbfs_cachenode *cbfs_hash_node;
41 };
42 
43 /**
44  * Read a flash entry from the fdt
45  *
46  * @param node		Reference to node to read
47  * @param entry		Place to put offset and size of this node
48  * @return 0 if ok, -ve on error
49  */
50 int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry);
51 
52 /**
53  * ofnode_decode_region() - Decode a memory region from a node
54  *
55  * Look up a property in a node which contains a memory region address and
56  * size. Then return a pointer to this address.
57  *
58  * The property must hold one address with a length. This is only tested on
59  * 32-bit machines.
60  *
61  * @param node		ofnode to examine
62  * @param prop_name	name of property to find
63  * @param basep		Returns base address of region
64  * @param size		Returns size of region
65  * @return 0 if ok, -1 on error (property not found)
66  */
67 int ofnode_decode_region(ofnode node, const char *prop_name, fdt_addr_t *basep,
68 			 fdt_size_t *sizep);
69 
70 /**
71  * ofnode_decode_memory_region()- Decode a named region within a memory bank
72  *
73  * This function handles selection of a memory region. The region is
74  * specified as an offset/size within a particular type of memory.
75  *
76  * The properties used are:
77  *
78  *	<mem_type>-memory<suffix> for the name of the memory bank
79  *	<mem_type>-offset<suffix> for the offset in that bank
80  *
81  * The property value must have an offset and a size. The function checks
82  * that the region is entirely within the memory bank.5
83  *
84  * @param node		ofnode containing the properties (-1 for /config)
85  * @param mem_type	Type of memory to use, which is a name, such as
86  *			"u-boot" or "kernel".
87  * @param suffix	String to append to the memory/offset
88  *			property names
89  * @param basep		Returns base of region
90  * @param sizep		Returns size of region
91  * @return 0 if OK, -ive on error
92  */
93 int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
94 				const char *suffix, fdt_addr_t *basep,
95 				fdt_size_t *sizep);
96 
97 /**
98  * ofnode_phy_is_fixed_link() - Detect fixed-link pseudo-PHY device
99  *
100  * This function detects whether the ethernet controller connects to a
101  * fixed-link pseudo-PHY device.
102  *
103  * This function supports the following two DT bindings:
104  * - the new DT binding, where 'fixed-link' is a sub-node of the
105  *   Ethernet device
106  * - the old DT binding, where 'fixed-link' is a property with 5
107  *   cells encoding various information about the fixed PHY
108  *
109  * If both new and old bindings exist, the new one is preferred.
110  *
111  * @param eth_node	ofnode containing the fixed-link subnode/property
112  * @param phy_node	if fixed-link PHY detected, containing the PHY ofnode
113  * @return true if a fixed-link pseudo-PHY device exists, false otherwise
114  */
115 bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node);
116 
117 #endif
118