.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * (C) Copyright David Gibson <dwg@au1.ibm.com>, IBM Corporation. 2005. |
---|
3 | | - * |
---|
4 | | - * |
---|
5 | | - * This program is free software; you can redistribute it and/or |
---|
6 | | - * modify it under the terms of the GNU General Public License as |
---|
7 | | - * published by the Free Software Foundation; either version 2 of the |
---|
8 | | - * License, or (at your option) any later version. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, |
---|
11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
13 | | - * General Public License for more details. |
---|
14 | | - * |
---|
15 | | - * You should have received a copy of the GNU General Public License |
---|
16 | | - * along with this program; if not, write to the Free Software |
---|
17 | | - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
---|
18 | | - * USA |
---|
19 | 4 | */ |
---|
| 5 | +%locations |
---|
| 6 | + |
---|
20 | 7 | %{ |
---|
21 | 8 | #include <stdio.h> |
---|
22 | 9 | #include <inttypes.h> |
---|
.. | .. |
---|
31 | 18 | srcpos_error((loc), "Error", __VA_ARGS__); \ |
---|
32 | 19 | treesource_error = true; \ |
---|
33 | 20 | } while (0) |
---|
| 21 | + |
---|
| 22 | +#define YYERROR_CALL(msg) yyerror(msg) |
---|
34 | 23 | |
---|
35 | 24 | extern struct dt_info *parser_output; |
---|
36 | 25 | extern bool treesource_error; |
---|
.. | .. |
---|
70 | 59 | %token <byte> DT_BYTE |
---|
71 | 60 | %token <data> DT_STRING |
---|
72 | 61 | %token <labelref> DT_LABEL |
---|
73 | | -%token <labelref> DT_REF |
---|
| 62 | +%token <labelref> DT_LABEL_REF |
---|
| 63 | +%token <labelref> DT_PATH_REF |
---|
74 | 64 | %token DT_INCBIN |
---|
75 | 65 | |
---|
76 | 66 | %type <data> propdata |
---|
.. | .. |
---|
83 | 73 | %type <data> bytestring |
---|
84 | 74 | %type <prop> propdef |
---|
85 | 75 | %type <proplist> proplist |
---|
| 76 | +%type <labelref> dt_ref |
---|
86 | 77 | |
---|
87 | 78 | %type <node> devicetree |
---|
88 | 79 | %type <node> nodedef |
---|
.. | .. |
---|
158 | 149 | } |
---|
159 | 150 | ; |
---|
160 | 151 | |
---|
| 152 | +dt_ref: DT_LABEL_REF | DT_PATH_REF; |
---|
| 153 | + |
---|
161 | 154 | devicetree: |
---|
162 | 155 | '/' nodedef |
---|
163 | 156 | { |
---|
.. | .. |
---|
167 | 160 | { |
---|
168 | 161 | $$ = merge_nodes($1, $3); |
---|
169 | 162 | } |
---|
170 | | - | DT_REF nodedef |
---|
| 163 | + | dt_ref nodedef |
---|
171 | 164 | { |
---|
172 | 165 | /* |
---|
173 | 166 | * We rely on the rule being always: |
---|
.. | .. |
---|
176 | 169 | */ |
---|
177 | 170 | if (!($<flags>-1 & DTSF_PLUGIN)) |
---|
178 | 171 | ERROR(&@2, "Label or path %s not found", $1); |
---|
179 | | - $$ = add_orphan_node(name_node(build_node(NULL, NULL), ""), $2, $1); |
---|
| 172 | + $$ = add_orphan_node( |
---|
| 173 | + name_node(build_node(NULL, NULL, NULL), |
---|
| 174 | + ""), |
---|
| 175 | + $2, $1); |
---|
180 | 176 | } |
---|
181 | | - | devicetree DT_LABEL DT_REF nodedef |
---|
| 177 | + | devicetree DT_LABEL dt_ref nodedef |
---|
182 | 178 | { |
---|
183 | 179 | struct node *target = get_node_by_ref($1, $3); |
---|
184 | 180 | |
---|
.. | .. |
---|
189 | 185 | ERROR(&@3, "Label or path %s not found", $3); |
---|
190 | 186 | $$ = $1; |
---|
191 | 187 | } |
---|
192 | | - | devicetree DT_REF nodedef |
---|
| 188 | + | devicetree DT_PATH_REF nodedef |
---|
193 | 189 | { |
---|
194 | 190 | /* |
---|
195 | 191 | * We rely on the rule being always: |
---|
.. | .. |
---|
208 | 204 | } |
---|
209 | 205 | $$ = $1; |
---|
210 | 206 | } |
---|
211 | | - | devicetree DT_DEL_NODE DT_REF ';' |
---|
| 207 | + | devicetree DT_LABEL_REF nodedef |
---|
| 208 | + { |
---|
| 209 | + struct node *target = get_node_by_ref($1, $2); |
---|
| 210 | + |
---|
| 211 | + if (target) { |
---|
| 212 | + merge_nodes(target, $3); |
---|
| 213 | + } else { |
---|
| 214 | + /* |
---|
| 215 | + * We rely on the rule being always: |
---|
| 216 | + * versioninfo plugindecl memreserves devicetree |
---|
| 217 | + * so $-1 is what we want (plugindecl) |
---|
| 218 | + */ |
---|
| 219 | + if ($<flags>-1 & DTSF_PLUGIN) |
---|
| 220 | + add_orphan_node($1, $3, $2); |
---|
| 221 | + else |
---|
| 222 | + ERROR(&@2, "Label or path %s not found", $2); |
---|
| 223 | + } |
---|
| 224 | + $$ = $1; |
---|
| 225 | + } |
---|
| 226 | + | devicetree DT_DEL_NODE dt_ref ';' |
---|
212 | 227 | { |
---|
213 | 228 | struct node *target = get_node_by_ref($1, $3); |
---|
214 | 229 | |
---|
.. | .. |
---|
220 | 235 | |
---|
221 | 236 | $$ = $1; |
---|
222 | 237 | } |
---|
223 | | - | devicetree DT_OMIT_NO_REF DT_REF ';' |
---|
| 238 | + | devicetree DT_OMIT_NO_REF dt_ref ';' |
---|
224 | 239 | { |
---|
225 | 240 | struct node *target = get_node_by_ref($1, $3); |
---|
226 | 241 | |
---|
.. | .. |
---|
237 | 252 | nodedef: |
---|
238 | 253 | '{' proplist subnodes '}' ';' |
---|
239 | 254 | { |
---|
240 | | - $$ = build_node($2, $3); |
---|
| 255 | + $$ = build_node($2, $3, &@$); |
---|
241 | 256 | } |
---|
242 | 257 | ; |
---|
243 | 258 | |
---|
.. | .. |
---|
255 | 270 | propdef: |
---|
256 | 271 | DT_PROPNODENAME '=' propdata ';' |
---|
257 | 272 | { |
---|
258 | | - $$ = build_property($1, $3); |
---|
| 273 | + $$ = build_property($1, $3, &@$); |
---|
259 | 274 | } |
---|
260 | 275 | | DT_PROPNODENAME ';' |
---|
261 | 276 | { |
---|
262 | | - $$ = build_property($1, empty_data); |
---|
| 277 | + $$ = build_property($1, empty_data, &@$); |
---|
263 | 278 | } |
---|
264 | 279 | | DT_DEL_PROP DT_PROPNODENAME ';' |
---|
265 | 280 | { |
---|
.. | .. |
---|
285 | 300 | { |
---|
286 | 301 | $$ = data_merge($1, $3); |
---|
287 | 302 | } |
---|
288 | | - | propdataprefix DT_REF |
---|
| 303 | + | propdataprefix dt_ref |
---|
289 | 304 | { |
---|
| 305 | + $1 = data_add_marker($1, TYPE_STRING, $2); |
---|
290 | 306 | $$ = data_add_marker($1, REF_PATH, $2); |
---|
291 | 307 | } |
---|
292 | 308 | | propdataprefix DT_INCBIN '(' DT_STRING ',' integer_prim ',' integer_prim ')' |
---|
.. | .. |
---|
340 | 356 | DT_BITS DT_LITERAL '<' |
---|
341 | 357 | { |
---|
342 | 358 | unsigned long long bits; |
---|
| 359 | + enum markertype type = TYPE_UINT32; |
---|
343 | 360 | |
---|
344 | 361 | bits = $2; |
---|
345 | 362 | |
---|
346 | | - if ((bits != 8) && (bits != 16) && |
---|
347 | | - (bits != 32) && (bits != 64)) { |
---|
| 363 | + switch (bits) { |
---|
| 364 | + case 8: type = TYPE_UINT8; break; |
---|
| 365 | + case 16: type = TYPE_UINT16; break; |
---|
| 366 | + case 32: type = TYPE_UINT32; break; |
---|
| 367 | + case 64: type = TYPE_UINT64; break; |
---|
| 368 | + default: |
---|
348 | 369 | ERROR(&@2, "Array elements must be" |
---|
349 | 370 | " 8, 16, 32 or 64-bits"); |
---|
350 | 371 | bits = 32; |
---|
351 | 372 | } |
---|
352 | 373 | |
---|
353 | | - $$.data = empty_data; |
---|
| 374 | + $$.data = data_add_marker(empty_data, type, NULL); |
---|
354 | 375 | $$.bits = bits; |
---|
355 | 376 | } |
---|
356 | 377 | | '<' |
---|
357 | 378 | { |
---|
358 | | - $$.data = empty_data; |
---|
| 379 | + $$.data = data_add_marker(empty_data, TYPE_UINT32, NULL); |
---|
359 | 380 | $$.bits = 32; |
---|
360 | 381 | } |
---|
361 | 382 | | arrayprefix integer_prim |
---|
.. | .. |
---|
377 | 398 | |
---|
378 | 399 | $$.data = data_append_integer($1.data, $2, $1.bits); |
---|
379 | 400 | } |
---|
380 | | - | arrayprefix DT_REF |
---|
| 401 | + | arrayprefix dt_ref |
---|
381 | 402 | { |
---|
382 | 403 | uint64_t val = ~0ULL >> (64 - $1.bits); |
---|
383 | 404 | |
---|
.. | .. |
---|
455 | 476 | ; |
---|
456 | 477 | |
---|
457 | 478 | integer_shift: |
---|
458 | | - integer_shift DT_LSHIFT integer_add { $$ = $1 << $3; } |
---|
459 | | - | integer_shift DT_RSHIFT integer_add { $$ = $1 >> $3; } |
---|
| 479 | + integer_shift DT_LSHIFT integer_add { $$ = ($3 < 64) ? ($1 << $3) : 0; } |
---|
| 480 | + | integer_shift DT_RSHIFT integer_add { $$ = ($3 < 64) ? ($1 >> $3) : 0; } |
---|
460 | 481 | | integer_add |
---|
461 | 482 | ; |
---|
462 | 483 | |
---|
.. | .. |
---|
499 | 520 | bytestring: |
---|
500 | 521 | /* empty */ |
---|
501 | 522 | { |
---|
502 | | - $$ = empty_data; |
---|
| 523 | + $$ = data_add_marker(empty_data, TYPE_UINT8, NULL); |
---|
503 | 524 | } |
---|
504 | 525 | | bytestring DT_BYTE |
---|
505 | 526 | { |
---|
.. | .. |
---|
534 | 555 | } |
---|
535 | 556 | | DT_DEL_NODE DT_PROPNODENAME ';' |
---|
536 | 557 | { |
---|
537 | | - $$ = name_node(build_node_delete(), $2); |
---|
| 558 | + $$ = name_node(build_node_delete(&@$), $2); |
---|
538 | 559 | } |
---|
539 | 560 | | DT_OMIT_NO_REF subnode |
---|
540 | 561 | { |
---|