summaryrefslogtreecommitdiff
path: root/include/dm/of_extra.h
blob: f0d205491c16f7e76f6cbd01fb5c0bd165ac5fcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* SPDX-License-Identifier: GPL-2.0+ */
/*
 * Copyright (c) 2017 Google, Inc
 * Written by Simon Glass <sjg@chromium.org>
 */

#ifndef _DM_OF_EXTRA_H
#define _DM_OF_EXTRA_H

#include <dm/ofnode.h>

enum fmap_compress_t {
	FMAP_COMPRESS_NONE,
	FMAP_COMPRESS_LZMA,
	FMAP_COMPRESS_LZ4,

	FMAP_COMPRESS_COUNT,
	FMAP_COMPRESS_UNKNOWN,
};

enum fmap_hash_t {
	FMAP_HASH_NONE,
	FMAP_HASH_SHA1,
	FMAP_HASH_SHA256,
};

/* A flash map entry, containing an offset and length */
struct fmap_entry {
	uint32_t offset;
	uint32_t length;
	uint32_t used;			/* Number of bytes used in region */
	enum fmap_compress_t compress_algo;	/* Compression type */
	uint32_t unc_length;			/* Uncompressed length */
	enum fmap_hash_t hash_algo;		/* Hash algorithm */
	const uint8_t *hash;			/* Hash value */
	int hash_size;				/* Hash size */
	/* Node pointer if CBFS, else NULL */
	const struct cbfs_cachenode *cbfs_node;
	/* Hash node pointer if CBFS, else NULL */
	const struct cbfs_cachenode *cbfs_hash_node;
};

/**
 * Read a flash entry from the fdt
 *
 * @param node		Reference to node to read
 * @param entry		Place to put offset and size of this node
 * @return 0 if ok, -ve on error
 */
int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry);

/**
 * ofnode_decode_region() - Decode a memory region from a node
 *
 * Look up a property in a node which contains a memory region address and
 * size. Then return a pointer to this address.
 *
 * The property must hold one address with a length. This is only tested on
 * 32-bit machines.
 *
 * @param node		ofnode to examine
 * @param prop_name	name of property to find
 * @param basep		Returns base address of region
 * @param size		Returns size of region
 * @return 0 if ok, -1 on error (property not found)
 */
int ofnode_decode_region(ofnode node, const char *prop_name, fdt_addr_t *basep,
			 fdt_size_t *sizep);

/**
 * ofnode_decode_memory_region()- Decode a named region within a memory bank
 *
 * This function handles selection of a memory region. The region is
 * specified as an offset/size within a particular type of memory.
 *
 * The properties used are:
 *
 *	<mem_type>-memory<suffix> for the name of the memory bank
 *	<mem_type>-offset<suffix> for the offset in that bank
 *
 * The property value must have an offset and a size. The function checks
 * that the region is entirely within the memory bank.5
 *
 * @param node		ofnode containing the properties (-1 for /config)
 * @param mem_type	Type of memory to use, which is a name, such as
 *			"u-boot" or "kernel".
 * @param suffix	String to append to the memory/offset
 *			property names
 * @param basep		Returns base of region
 * @param sizep		Returns size of region
 * @return 0 if OK, -ive on error
 */
int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,
				const char *suffix, fdt_addr_t *basep,
				fdt_size_t *sizep);

/**
 * ofnode_phy_is_fixed_link() - Detect fixed-link pseudo-PHY device
 *
 * This function detects whether the ethernet controller connects to a
 * fixed-link pseudo-PHY device.
 *
 * This function supports the following two DT bindings:
 * - the new DT binding, where 'fixed-link' is a sub-node of the
 *   Ethernet device
 * - the old DT binding, where 'fixed-link' is a property with 5
 *   cells encoding various information about the fixed PHY
 *
 * If both new and old bindings exist, the new one is preferred.
 *
 * @param eth_node	ofnode containing the fixed-link subnode/property
 * @param phy_node	if fixed-link PHY detected, containing the PHY ofnode
 * @return true if a fixed-link pseudo-PHY device exists, false otherwise
 */
bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node);

#endif