blob: 44492864b4ef2555f32035d53b3082a6bc1d24e6 [file] [log] [blame]
Parth Dixit30e1a762019-07-08 21:37:33 +05301/* Copyright (c) 2012-2014,2017-2019 The Linux Foundation. All rights reserved.
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -07002 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*/
28
29#include <debug.h>
Lijuan Gao9f152862014-08-18 13:45:24 +080030#include <list.h>
Mayank Grover1b6da5d2017-12-19 16:05:46 +053031#include <bits.h>
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070032
33#ifndef __DEVICE_TREE__
34#define __DEVICE_TREE__
35
36#define DEV_TREE_SUCCESS 0
37#define DEV_TREE_MAGIC 0x54444351 /* "QCDT" */
38#define DEV_TREE_MAGIC_LEN 4
Joel Kingaa335dc2013-06-03 16:11:08 -070039#define DEV_TREE_VERSION_V1 1
40#define DEV_TREE_VERSION_V2 2
Lijuan Gao9f152862014-08-18 13:45:24 +080041#define DEV_TREE_VERSION_V3 3
42
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -070043#define DEV_TREE_HEADER_SIZE 12
44
Channagoud Kadabi11682e92013-02-28 11:21:46 -080045#define DTB_MAGIC 0xedfe0dd0
46#define DTB_OFFSET 0x2C
47
Dima Zavin77e41f32013-03-06 16:10:43 -080048#define DTB_PAD_SIZE 1024
Mayank Grover1b6da5d2017-12-19 16:05:46 +053049#define DTBO_TABLE_MAGIC 0xD7B7AB1E
50#define DTBO_CUSTOM_MAX 4
51#define PLATFORM_FOUNDRY_SHIFT 16
52#define SOC_MASK (0xffff)
53#define VARIANT_MASK (0x000000ff)
54#define VARIANT_MINOR_MASK (0x0000ff00)
55#define VARIANT_MAJOR_MASK (0x00ff0000)
56#define PMIC_MODEL_MASK (0x000000ff)
57#define PMIC_REV_MASK (0xffffff00)
58#define PMIC_SHIFT_IDX (2)
59#define PLATFORM_SUBTYPE_SHIFT_ID (0x18)
60#define FOUNDRY_ID_MASK (0x00ff0000)
Mayank Groverb61c0c22018-09-04 15:09:32 +053061#define MAX_SUPPORTED_DTBO_IMG_BUF (8388608) /* 8MB 8 * 1024 * 1024 */
62#define DTBO_IMG_BUF (10485760) /* 10MB 10 * 1024 * 1024 */
Mayank Grover9df84c02018-08-30 15:46:35 +053063#define MAX_SUPPORTED_VBMETA_IMG_BUF (65536) /* 64 KB 64 * 1024 */
Channagoud Kadabia4dbe332013-09-05 17:44:11 -070064/*
65 * For DTB V1: The DTB entries would be of the format
66 * qcom,msm-id = <msm8974, CDP, rev_1>; (3 * sizeof(uint32_t))
67 * For DTB V2: The DTB entries would be of the format
68 * qcom,msm-id = <msm8974, rev_1>; (2 * sizeof(uint32_t))
69 * qcom,board-id = <CDP, subtype_ID>; (2 * sizeof(uint32_t))
70 * The macros below are defined based on these.
71 */
72#define DT_ENTRY_V1_SIZE 0xC
73#define PLAT_ID_SIZE 0x8
74#define BOARD_ID_SIZE 0x8
Lijuan Gao9f152862014-08-18 13:45:24 +080075#define PMIC_ID_SIZE 0x8
76
Mayank Grover1b6da5d2017-12-19 16:05:46 +053077typedef enum {
78 NONE_MATCH,
79 PMIC_MATCH_BEST_REV_IDX0,
80 PMIC_MATCH_EXACT_REV_IDX0,
81 PMIC_MATCH_BEST_REV_IDX1,
82 PMIC_MATCH_EXACT_REV_IDX1,
83 PMIC_MATCH_BEST_REV_IDX2,
84 PMIC_MATCH_EXACT_REV_IDX2,
85 PMIC_MATCH_BEST_REV_IDX3,
86 PMIC_MATCH_EXACT_REV_IDX3,
87 VARIANT_MINOR_BEST_MATCH,
88 VARIANT_MINOR_EXACT_MATCH,
89 VARIANT_MAJOR_BEST_MATCH,
90 VARIANT_MAJOR_EXACT_MATCH,
91 VERSION_BEST_MATCH,
92 VERSION_EXACT_MATCH,
93 FOUNDRYID_DEFAULT_MATCH,
94 FOUNDRYID_EXACT_MATCH,
95 PMIC_MATCH_DEFAULT_MODEL_IDX0,
96 PMIC_MATCH_EXACT_MODEL_IDX0,
97 PMIC_MATCH_DEFAULT_MODEL_IDX1,
98 PMIC_MATCH_EXACT_MODEL_IDX1,
99 PMIC_MATCH_DEFAULT_MODEL_IDX2,
100 PMIC_MATCH_EXACT_MODEL_IDX2,
101 PMIC_MATCH_DEFAULT_MODEL_IDX3,
102 PMIC_MATCH_EXACT_MODEL_IDX3,
103 SUBTYPE_DEFAULT_MATCH,
104 SUBTYPE_EXACT_MATCH,
105 VARIANT_MATCH,
106 SOC_MATCH,
107 MAX_MATCH,
108}dt_match_params;
109
110#define TOTAL_MATCH_BITS 6
111#define ALL_BITS_SET (BIT (SOC_MATCH) | BIT (VARIANT_MATCH) | \
112 BIT (SUBTYPE_EXACT_MATCH) | BIT (FOUNDRYID_EXACT_MATCH) \
113 | BIT (PMIC_MATCH_EXACT_MODEL_IDX0) | \
114 BIT (PMIC_MATCH_EXACT_MODEL_IDX1))
115
116typedef enum {
117 PMIC_IDX0,
118 PMIC_IDX1,
119 PMIC_IDX2,
120 PMIC_IDX3,
121 MAX_PMIC_IDX,
122}pmic_indexes;
123
124
125typedef struct dt_info
126{
127 uint32_t dt_platform_id;
128 uint32_t dt_soc_rev;
129 uint32_t dt_foundry_id;
130 uint32_t dt_variant_id;
131 uint32_t dt_variant_major;
132 uint32_t dt_variant_minor;
133 uint32_t dt_platform_subtype;
134 uint32_t dt_pmic_model[MAX_PMIC_IDX];
135 uint32_t dt_pmic_rev[MAX_PMIC_IDX];
136 uint32_t dt_match_val;
137 void *dtb;
138}dt_info;
139
140typedef struct pmic_info
141{
142 uint32_t dt_pmic_model[MAX_PMIC_IDX];
143 uint32_t dt_pmic_rev[MAX_PMIC_IDX];
144 uint32_t dt_match_val;
145}pmic_info;
Lijuan Gao9f152862014-08-18 13:45:24 +0800146
147struct dt_entry_v2
148{
149 uint32_t platform_id;
150 uint32_t variant_id;
151 uint32_t board_hw_subtype;
152 uint32_t soc_rev;
153 uint32_t offset;
154 uint32_t size;
155};
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700156
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700157struct dt_entry
158{
159 uint32_t platform_id;
160 uint32_t variant_id;
Joel Kingaa335dc2013-06-03 16:11:08 -0700161 uint32_t board_hw_subtype;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700162 uint32_t soc_rev;
Lijuan Gao9f152862014-08-18 13:45:24 +0800163 uint32_t pmic_rev[4];
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700164 uint32_t offset;
165 uint32_t size;
Parth Dixit30e1a762019-07-08 21:37:33 +0530166 uint32_t idx;
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700167};
168
169struct dt_table
170{
171 uint32_t magic;
172 uint32_t version;
173 uint32_t num_entries;
174};
175
Channagoud Kadabia4dbe332013-09-05 17:44:11 -0700176struct plat_id
177{
178 uint32_t platform_id;
179 uint32_t soc_rev;
180};
181
182struct board_id
183{
184 uint32_t variant_id;
185 uint32_t platform_subtype;
186};
187
Lijuan Gao9f152862014-08-18 13:45:24 +0800188struct pmic_id
189{
190 uint32_t pmic_version[4];
191};
192
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -0700193struct dt_mem_node_info
194{
195 uint32_t offset;
196 uint32_t mem_info_cnt;
197 uint32_t addr_cell_size;
198 uint32_t size_cell_size;
199};
200
Lijuan Gao9f152862014-08-18 13:45:24 +0800201enum dt_entry_info
202{
203 DTB_FOUNDRY = 0,
204 DTB_SOC,
205 DTB_MAJOR_MINOR,
206 DTB_PMIC0,
207 DTB_PMIC1,
208 DTB_PMIC2,
209 DTB_PMIC3,
210 DTB_PMIC_MODEL,
Lijuan Gaof8e95722014-12-23 03:03:12 -0500211 DTB_PANEL_TYPE,
212 DTB_BOOT_DEVICE,
Lijuan Gao9f152862014-08-18 13:45:24 +0800213};
214
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700215enum dt_err_codes
216{
217 DT_OP_SUCCESS,
218 DT_OP_FAILURE = -1,
219};
220
Lijuan Gao9f152862014-08-18 13:45:24 +0800221typedef struct dt_entry_node {
222 struct list_node node;
223 struct dt_entry * dt_entry_m;
224}dt_node;
Sundarajan Srinivasan763c0db2014-05-20 17:08:36 -0700225
Mayank Grover1b6da5d2017-12-19 16:05:46 +0530226struct dtbo_table_hdr {
227 uint32_t magic; //dtb table magic
228 uint32_t total_size; //Includes dt_table_hdr + all dt_table_entry and all dtb/dtbo
229 uint32_t hdr_size; //sizeof(dt_table_hdr)
230 uint32_t dt_entry_size; //sizeof(dt_table_entry)
231 uint32_t dt_entry_count; //number of dt_table_entry
232 uint32_t dt_entry_offset; //offset to the first dt_table_entry
233 uint32_t page_size; //flash pagesize we assume
234 uint32_t reserved[1]; //must zeros
235};
236
237struct dtbo_table_entry {
238 uint32_t dt_size;
239 uint32_t dt_offset; //offset from head of dt_table_hdr
240 uint32_t id; //optional, must zero if unused
241 uint32_t revision; //optional, must zero if unused
242 uint32_t custom[DTBO_CUSTOM_MAX]; //optional, must zero if unused
243};
244
Mayank Groverb61c0c22018-09-04 15:09:32 +0530245typedef enum dtbo_error
246{
247 DTBO_ERROR = 0,
248 DTBO_NOT_SUPPORTED = 1,
249 DTBO_SUCCESS = 2
250}dtbo_error;
251
252dtbo_error load_validate_dtbo_image(void **dtbo_img, uint32_t *dtbo_img_size);
Mayank Grover3dcc95b2018-09-04 20:31:38 +0530253void get_recovery_dtbo_info(uint32_t *dtbo_size, void **dtbo_buf);
Deepa Dinamani87252952013-09-09 13:58:27 -0700254int dev_tree_validate(struct dt_table *table, unsigned int page_size, uint32_t *dt_hdr_size);
Joel Kingaa335dc2013-06-03 16:11:08 -0700255int dev_tree_get_entry_info(struct dt_table *table, struct dt_entry *dt_entry_info);
Sundarajan Srinivasan44de4342013-07-08 14:47:13 -0700256int update_device_tree(void *fdt, const char *, void *, unsigned);
257int dev_tree_add_mem_info(void *fdt, uint32_t offset, uint64_t size, uint64_t addr);
Matthew Qinbb7923d2015-02-09 10:56:09 +0800258void *dev_tree_appended(void *kernel, uint32_t kernel_size, uint32_t dtb_offset, void *tags);
lijuang0cce8bf2018-08-23 10:56:42 +0800259int get_dtbo_idx (void);
Parth Dixit30e1a762019-07-08 21:37:33 +0530260int get_dtb_idx (void);
Deepa Dinamani28c0ffe2012-09-24 11:45:21 -0700261#endif