blob: 17e85a819be01daf6bac4d32e7d39f660aab6313 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassb7e0d732017-05-18 20:09:02 -06002/*
3 * Copyright (c) 2017 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
Simon Glassb7e0d732017-05-18 20:09:02 -06005 */
6
7#ifndef _DM_OF_EXTRA_H
8#define _DM_OF_EXTRA_H
9
10#include <dm/ofnode.h>
11
12enum fmap_compress_t {
13 FMAP_COMPRESS_NONE,
Simon Glassb8bccce2021-03-15 18:00:29 +130014 FMAP_COMPRESS_LZMA,
Simon Glasse6c5c942018-10-01 12:22:08 -060015 FMAP_COMPRESS_LZ4,
Simon Glassb8bccce2021-03-15 18:00:29 +130016
17 FMAP_COMPRESS_COUNT,
18 FMAP_COMPRESS_UNKNOWN,
Simon Glassb7e0d732017-05-18 20:09:02 -060019};
20
21enum 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 */
28struct 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 */
Simon Glasse6c5c942018-10-01 12:22:08 -060033 uint32_t unc_length; /* Uncompressed length */
Simon Glassb7e0d732017-05-18 20:09:02 -060034 enum fmap_hash_t hash_algo; /* Hash algorithm */
35 const uint8_t *hash; /* Hash value */
36 int hash_size; /* Hash size */
Simon Glassb8bccce2021-03-15 18:00:29 +130037 /* 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;
Simon Glassb7e0d732017-05-18 20:09:02 -060041};
42
43/**
Patrick Delaunaybe74f712022-01-12 10:53:49 +010044 * ofnode_read_fmap_entry() - Read a flash entry from the fdt
Simon Glassb7e0d732017-05-18 20:09:02 -060045 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +010046 * @node: Reference to node to read
47 * @entry: Place to put offset and size of this node
48 * Return: 0 if ok, -ve on error
Simon Glassb7e0d732017-05-18 20:09:02 -060049 */
Simon Glass5e0a7342018-06-11 13:07:17 -060050int ofnode_read_fmap_entry(ofnode node, struct fmap_entry *entry);
Simon Glassb7e0d732017-05-18 20:09:02 -060051
Simon Glass964cadc2018-06-11 13:07:18 -060052/**
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 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +010061 * @node: ofnode to examine
62 * @prop_name: name of property to find
63 * @basep: Returns base address of region
64 * @sizep: Returns size of region
65 * Return: 0 if ok, -1 on error (property not found)
Simon Glass964cadc2018-06-11 13:07:18 -060066 */
67int 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 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +010084 * @config_node: ofnode containing the properties (invalid for "/config")
85 * @mem_type: Type of memory to use, which is a name, such as
86 * "u-boot" or "kernel".
87 * @suffix: String to append to the memory/offset
88 * property names
89 * @basep: Returns base of region
90 * @sizep: Returns size of region
91 * Return: 0 if OK, -ive on error
Simon Glass964cadc2018-06-11 13:07:18 -060092 */
93int 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
Bin Meng173c66b2021-03-14 20:14:46 +080097/**
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
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100105 * Ethernet device
Bin Meng173c66b2021-03-14 20:14:46 +0800106 * - the old DT binding, where 'fixed-link' is a property with 5
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100107 * cells encoding various information about the fixed PHY
Bin Meng173c66b2021-03-14 20:14:46 +0800108 *
109 * If both new and old bindings exist, the new one is preferred.
110 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100111 * @eth_node: ofnode containing the fixed-link subnode/property
112 * @phy_node: if fixed-link PHY detected, containing the PHY ofnode
113 * Return: true if a fixed-link pseudo-PHY device exists, false otherwise
Bin Meng173c66b2021-03-14 20:14:46 +0800114 */
115bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node);
116
Vladimir Oltean2dd6acb2021-09-29 18:04:39 +0300117/**
118 * ofnode_eth_uses_inband_aneg() - Detect whether MAC should use in-band autoneg
119 *
120 * This function detects whether the Ethernet controller should use IEEE 802.3
121 * clause 37 in-band autonegotiation for serial protocols such as 1000base-x,
122 * SGMII, USXGMII, etc. The property is relevant when the Ethernet controller
123 * is connected to an on-board PHY or an SFP cage, and is not relevant when it
124 * has a fixed link (in that case, in-band autoneg should not be used).
125 *
Patrick Delaunaybe74f712022-01-12 10:53:49 +0100126 * @eth_node: ofnode belonging to the Ethernet controller
127 * Return: true if in-band autoneg should be used, false otherwise
Vladimir Oltean2dd6acb2021-09-29 18:04:39 +0300128 */
129bool ofnode_eth_uses_inband_aneg(ofnode eth_node);
130
Simon Glassb7e0d732017-05-18 20:09:02 -0600131#endif