hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/scripts/dtc/dtc.h
....@@ -1,24 +1,9 @@
1
+/* SPDX-License-Identifier: GPL-2.0-or-later */
12 #ifndef DTC_H
23 #define DTC_H
34
45 /*
56 * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005.
6
- *
7
- *
8
- * This program is free software; you can redistribute it and/or
9
- * modify it under the terms of the GNU General Public License as
10
- * published by the Free Software Foundation; either version 2 of the
11
- * License, or (at your option) any later version.
12
- *
13
- * This program is distributed in the hope that it will be useful,
14
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
- * General Public License for more details.
17
- *
18
- * You should have received a copy of the GNU General Public License
19
- * along with this program; if not, write to the Free Software
20
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21
- * USA
227 */
238
249 #include <stdio.h>
....@@ -58,6 +43,7 @@
5843 extern int generate_symbols; /* generate symbols for nodes with labels */
5944 extern int generate_fixups; /* generate fixups */
6045 extern int auto_label_aliases; /* auto generate labels -> aliases */
46
+extern int annotate; /* annotate .dts with input source location */
6147
6248 #define PHANDLE_LEGACY 0x1
6349 #define PHANDLE_EPAPR 0x2
....@@ -65,6 +51,37 @@
6551
6652 typedef uint32_t cell_t;
6753
54
+static inline uint16_t dtb_ld16(const void *p)
55
+{
56
+ const uint8_t *bp = (const uint8_t *)p;
57
+
58
+ return ((uint16_t)bp[0] << 8)
59
+ | bp[1];
60
+}
61
+
62
+static inline uint32_t dtb_ld32(const void *p)
63
+{
64
+ const uint8_t *bp = (const uint8_t *)p;
65
+
66
+ return ((uint32_t)bp[0] << 24)
67
+ | ((uint32_t)bp[1] << 16)
68
+ | ((uint32_t)bp[2] << 8)
69
+ | bp[3];
70
+}
71
+
72
+static inline uint64_t dtb_ld64(const void *p)
73
+{
74
+ const uint8_t *bp = (const uint8_t *)p;
75
+
76
+ return ((uint64_t)bp[0] << 56)
77
+ | ((uint64_t)bp[1] << 48)
78
+ | ((uint64_t)bp[2] << 40)
79
+ | ((uint64_t)bp[3] << 32)
80
+ | ((uint64_t)bp[4] << 24)
81
+ | ((uint64_t)bp[5] << 16)
82
+ | ((uint64_t)bp[6] << 8)
83
+ | bp[7];
84
+}
6885
6986 #define streq(a, b) (strcmp((a), (b)) == 0)
7087 #define strstarts(s, prefix) (strncmp((s), (prefix), strlen(prefix)) == 0)
....@@ -74,10 +91,17 @@
7491
7592 /* Data blobs */
7693 enum markertype {
94
+ TYPE_NONE,
7795 REF_PHANDLE,
7896 REF_PATH,
7997 LABEL,
98
+ TYPE_UINT8,
99
+ TYPE_UINT16,
100
+ TYPE_UINT32,
101
+ TYPE_UINT64,
102
+ TYPE_STRING,
80103 };
104
+extern const char *markername(enum markertype markertype);
81105
82106 struct marker {
83107 enum markertype type;
....@@ -100,6 +124,8 @@
100124 #define for_each_marker_of_type(m, t) \
101125 for_each_marker(m) \
102126 if ((m)->type == (t))
127
+
128
+size_t type_marker_length(struct marker *m);
103129
104130 void data_free(struct data d);
105131
....@@ -149,6 +175,7 @@
149175 struct property *next;
150176
151177 struct label *labels;
178
+ struct srcpos *srcpos;
152179 };
153180
154181 struct node {
....@@ -168,6 +195,7 @@
168195
169196 struct label *labels;
170197 const struct bus_type *bus;
198
+ struct srcpos *srcpos;
171199
172200 bool omit_if_unused, is_referenced;
173201 };
....@@ -196,13 +224,15 @@
196224 void add_label(struct label **labels, char *label);
197225 void delete_labels(struct label **labels);
198226
199
-struct property *build_property(char *name, struct data val);
227
+struct property *build_property(char *name, struct data val,
228
+ struct srcpos *srcpos);
200229 struct property *build_property_delete(char *name);
201230 struct property *chain_property(struct property *first, struct property *list);
202231 struct property *reverse_properties(struct property *first);
203232
204
-struct node *build_node(struct property *proplist, struct node *children);
205
-struct node *build_node_delete(void);
233
+struct node *build_node(struct property *proplist, struct node *children,
234
+ struct srcpos *srcpos);
235
+struct node *build_node_delete(struct srcpos *srcpos);
206236 struct node *name_node(struct node *node, char *name);
207237 struct node *omit_node_if_unused(struct node *node);
208238 struct node *reference_node(struct node *node);
....@@ -217,7 +247,8 @@
217247 void delete_node_by_name(struct node *parent, char *name);
218248 void delete_node(struct node *node);
219249 void append_to_property(struct node *node,
220
- char *name, const void *data, int len);
250
+ char *name, const void *data, int len,
251
+ enum markertype type);
221252
222253 const char *get_unitname(struct node *node);
223254 struct property *get_property(struct node *node, const char *propname);
....@@ -290,6 +321,10 @@
290321 void dt_to_source(FILE *f, struct dt_info *dti);
291322 struct dt_info *dt_from_source(const char *f);
292323
324
+/* YAML source */
325
+
326
+void dt_to_yaml(FILE *f, struct dt_info *dti);
327
+
293328 /* FS trees */
294329
295330 struct dt_info *dt_from_fs(const char *dirname);