summaryrefslogtreecommitdiff
path: root/DynamicTablesPkg/Library/FdtHwInfoParserLib/FdtUtility.h
blob: 2cf2d8ddec2f3cabe12becb0b9c52307ee8ce106 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
/** @file
  Flattened device tree utility.

  Copyright (c) 2021 - 2026, ARM Limited. All rights reserved.<BR>
  SPDX-License-Identifier: BSD-2-Clause-Patent

  @par Reference(s):
  - Device tree Specification - Release v0.3
  - linux/Documentation/devicetree/bindings/interrupt-controller/arm%2Cgic.yaml
  - linux//Documentation/devicetree/bindings/interrupt-controller/arm%2Cgic.yaml
**/

#pragma once

#include <Library/FdtLib.h>

/// Maximum string length for compatible names.
#define COMPATIBLE_STR_LEN  (32U)

/// Interrupt macros
#define PPI_OFFSET  (16U)
#define SPI_OFFSET  (32U)
#define DT_PPI_IRQ  (1U)
#define DT_SPI_IRQ  (0U)
#define DT_IRQ_IS_EDGE_TRIGGERED(x)  ((((x) & (BIT0 | BIT1)) != 0))
#define DT_IRQ_IS_ACTIVE_LOW(x)      ((((x) & (BIT1 | BIT3)) != 0))
#define IRQ_TYPE_OFFSET          (0U)
#define IRQ_NUMBER_OFFSET        (1U)
#define IRQ_FLAGS_OFFSET         (2U)
#define RISCV_IRQ_NUMBER_OFFSET  (0U)
#define RISCV_IRQ_FLAGS_OFFSET   (1U)

/** Get the interrupt Id of an interrupt described in a fdt.

  Data must describe a GIC interrupt. A GIC interrupt is on at least
  3 UINT32 cells.
  This function DOES NOT SUPPORT extended SPI range and extended PPI range.

  @param [in]  Data   Pointer to the first cell of an "interrupts" property.
  @param [in]  Size   Number of cells used to encode an interrupt.

  @retval  The interrupt id.
**/
UINT32
EFIAPI
FdtGetInterruptId (
  UINT32 CONST  *Data,
  UINT32        Size
  );

/** Get the ACPI interrupt flags of an interrupt described in a fdt.

  Data must describe a GIC interrupt. A GIC interrupt is on at least
  3 UINT32 cells.

  PPI interrupt cpu mask on bits [15:8] are ignored.

  @param [in]  Data   Pointer to the first cell of an "interrupts" property.
  @param [in]  Size   Number of cells used to encode an interrupt.

  @retval  The interrupt flags (for ACPI).
**/
UINT32
EFIAPI
FdtGetInterruptFlags (
  UINT32 CONST  *Data,
  UINT32        Size
  );

/** Parsed "interrupt-map" entry information.
*/
typedef struct {
  /// Child unit-address cells. Points into the FDT blob unless masked.
  CONST UINT32    *ChildAddress;
  /// Number of child unit-address cells.
  INT32           ChildAddressCells;
  /// Child interrupt specifier cells. Points into the FDT blob unless masked.
  CONST UINT32    *ChildInterrupt;
  /// Number of child interrupt specifier cells.
  INT32           ChildInterruptCells;
  /// "interrupt-parent" phandle cell from the map entry.
  CONST UINT32    *InterruptParent;
  /// Parent unit-address cells. Points into the FDT blob.
  CONST UINT32    *ParentAddress;
  /// Number of parent unit-address cells.
  INT32           ParentAddressCells;
  /// Parent interrupt specifier cells. Points into the FDT blob.
  CONST UINT32    *ParentInterrupt;
  /// Number of parent interrupt specifier cells.
  INT32           ParentInterruptCells;
  /// Storage for masked child unit-address cells when ApplyIntMask is TRUE.
  UINT32          MaskedChildAddress[FDT_MAX_NCELLS];
  /// Storage for masked child interrupt cells when ApplyIntMask is TRUE.
  UINT32          MaskedChildInterrupt[FDT_MAX_NCELLS];
} INTERRUPT_MAP_ENTRY_INFO;

/** A structure describing a compatibility string.
*/
typedef struct CompatStr {
  CONST CHAR8    CompatStr[COMPATIBLE_STR_LEN];
} COMPATIBILITY_STR;

/** Structure containing a list of compatible names and their count.
*/
typedef struct CompatibilityInfo {
  /// Count of entries in the NAME_TABLE.
  UINT32                     Count;

  /// Pointer to a table storing the names.
  CONST COMPATIBILITY_STR    *CompatTable;
} COMPATIBILITY_INFO;

/** Operate a check on a Device Tree node.

  @param [in]  Fdt          Pointer to a Flattened Device Tree.
  @param [in]  NodeOffset   Offset of the node to compare input string.
  @param [in]  Context      Context to operate the check on the node.

  @retval True    The check is correct.
  @retval FALSE   Otherwise, or error.
**/
typedef
BOOLEAN
(EFIAPI *NODE_CHECKER_FUNC)(
  IN  CONST VOID    *Fdt,
  IN        INT32     NodeOffset,
  IN  CONST VOID    *Context
  );

/** Iterate through the list of strings in the Context,
    and check whether at least one string is matching the
    "compatible" property of the node.

  @param [in]  Fdt          Pointer to a Flattened Device Tree.
  @param [in]  Node         Offset of the node to operate the check on.
  @param [in]  CompatInfo   COMPATIBILITY_INFO containing the list of compatible
                            strings to compare with the "compatible" property
                            of the node.

  @retval TRUE    At least one string matched, the node is compatible.
  @retval FALSE   Otherwise, or error.
**/
BOOLEAN
EFIAPI
FdtNodeIsCompatible (
  IN  CONST VOID   *Fdt,
  IN        INT32  Node,
  IN  CONST VOID   *CompatInfo
  );

/** Check whether a node has a property.

  @param [in]  Fdt          Pointer to a Flattened Device Tree.
  @param [in]  Node         Offset of the node to operate the check on.
  @param [in]  PropertyName Name of the property to search.
                            This is a NULL terminated string.

  @retval True    The node has the property.
  @retval FALSE   Otherwise, or error.
**/
BOOLEAN
EFIAPI
FdtNodeHasProperty (
  IN  CONST VOID   *Fdt,
  IN        INT32  Node,
  IN  CONST VOID   *PropertyName
  );

/** Get the next node in a branch having a matching name.

  The Device tree is traversed in a depth-first search, starting from Node.
  The input Node is skipped.

  @param [in]       Fdt         Pointer to a Flattened Device Tree.
  @param [in]       FdtBranch   Only search in the sub-nodes of this branch.
                                Write (-1) to search the whole tree.
  @param [in]       NodeName    The node name to search.
                                This is a NULL terminated string.
  @param [in, out]  Node        At entry: Node offset to start the search.
                                          This first node is skipped.
                                          Write (-1) to search the whole tree.
                                At exit:  If success, contains the offset of
                                          the next node in the branch
                                          having a matching name.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
  @retval EFI_NOT_FOUND           No matching node found.
**/
EFI_STATUS
EFIAPI
FdtGetNextNamedNodeInBranch (
  IN      CONST VOID   *Fdt,
  IN            INT32  FdtBranch,
  IN      CONST CHAR8  *NodeName,
  IN OUT        INT32  *Node
  );

/** Get the next node in a branch with at least one compatible property.

  The Device tree is traversed in a depth-first search, starting from Node.
  The input Node is skipped.

  @param [in]       Fdt         Pointer to a Flattened Device Tree.
  @param [in]       FdtBranch   Only search in the sub-nodes of this branch.
                                Write (-1) to search the whole tree.
  @param [in]  CompatNamesInfo  Table of compatible strings to compare with
                                the compatible property of the node.
  @param [in, out]  Node        At entry: Node offset to start the search.
                                          This first node is skipped.
                                          Write (-1) to search the whole tree.
                                At exit:  If success, contains the offset of
                                          the next node in the branch
                                          being compatible.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
  @retval EFI_NOT_FOUND           No matching node found.
**/
EFI_STATUS
EFIAPI
FdtGetNextCompatNodeInBranch (
  IN      CONST VOID                *Fdt,
  IN            INT32               FdtBranch,
  IN      CONST COMPATIBILITY_INFO  *CompatNamesInfo,
  IN OUT        INT32               *Node
  );

/** Get the next node in a branch having the PropName property.

  The Device tree is traversed in a depth-first search, starting from Node.
  The input Node is skipped.

  @param [in]       Fdt         Pointer to a Flattened Device Tree.
  @param [in]       FdtBranch   Only search in the sub-nodes of this branch.
                                Write (-1) to search the whole tree.
  @param [in]       PropName    Name of the property to search.
                                This is a NULL terminated string.
  @param [in, out]  Node        At entry: Node offset to start the search.
                                          This first node is skipped.
                                          Write (-1) to search the whole tree.
                                At exit:  If success, contains the offset of
                                          the next node in the branch
                                          being compatible.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
  @retval EFI_NOT_FOUND           No matching node found.
**/
EFI_STATUS
EFIAPI
FdtGetNextPropNodeInBranch (
  IN      CONST VOID   *Fdt,
  IN            INT32  FdtBranch,
  IN      CONST CHAR8  *PropName,
  IN OUT        INT32  *Node
  );

/** Count the number of nodes in a branch with the input name.

  @param [in]  Fdt              Pointer to a Flattened Device Tree.
  @param [in]  FdtBranch        Only search in the sub-nodes of this branch.
                                Write (-1) to search the whole tree.
  @param [in]  NodeName         Node name to search.
                                This is a NULL terminated string.
  @param [out] NodeCount        If success, contains the count of nodes
                                fulfilling the condition.
                                Can be 0.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtCountNamedNodeInBranch (
  IN  CONST VOID    *Fdt,
  IN        INT32   FdtBranch,
  IN  CONST CHAR8   *NodeName,
  OUT       UINT32  *NodeCount
  );

/** Count the number of nodes in a branch with at least
    one compatible property.

  @param [in]  Fdt              Pointer to a Flattened Device Tree.
  @param [in]  FdtBranch        Only search in the sub-nodes of this branch.
                                Write (-1) to search the whole tree.
  @param [in]  CompatibleTable  Table of compatible strings to
                                compare with the compatible property
                                of the node.
  @param [out] NodeCount        If success, contains the count of nodes
                                fulfilling the condition.
                                Can be 0.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtCountCompatNodeInBranch (
  IN  CONST VOID                *Fdt,
  IN        INT32               FdtBranch,
  IN  CONST COMPATIBILITY_INFO  *CompatNamesInfo,
  OUT       UINT32              *NodeCount
  );

/** Count the number of nodes in a branch having the PropName property.

  @param [in]  Fdt              Pointer to a Flattened Device Tree.
  @param [in]  FdtBranch        Only search in the sub-nodes of this branch.
                                Write (-1) to search the whole tree.
  @param [in]  PropName         Name of the property to search.
                                This is a NULL terminated string.
  @param [out] NodeCount        If success, contains the count of nodes
                                fulfilling the condition.
                                Can be 0.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtCountPropNodeInBranch (
  IN  CONST VOID    *Fdt,
  IN        INT32   FdtBranch,
  IN  CONST CHAR8   *PropName,
  OUT       UINT32  *NodeCount
  );

/** Get the interrupt domain parent node handling the interrupts of the input
    node.

  The interrupt domain parent must be one of the following:
  - an interrupt-controller
  - an interrupt nexus

  @param [in]  Fdt       Pointer to a Flattened Device Tree.
  @param [in]  Node      Offset of the node to start the search.
  @param [out] IntcNode  If success, contains the offset of the matching
                         interrupt domain node.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_NOT_FOUND           No interrupt domain node found.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtGetIntDomainNode (
  IN  CONST VOID   *Fdt,
  IN        INT32  Node,
  OUT       INT32  *IntcNode
  );

/** Get the interrupt-controller parent node handling the interrupts of the
    input node.

  The interrupt domain parent must be an interrupt-controller.

  @param [in]  Fdt       Pointer to a Flattened Device Tree.
  @param [in]  Node      Offset of the node to start the search.
  @param [out] IntcNode  If success, contains the offset of the matching
                         interrupt-controller node.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_NOT_FOUND           No interrupt-controller node found.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtGetIntControllerNode (
  IN  CONST VOID   *Fdt,
  IN        INT32  Node,
  OUT       INT32  *IntcNode
  );

/** Read up to two FDT cells as a UINT64 value.

  @param [in]  Data       Pointer to the first cell to read.
  @param [in]  CellCount  Number of cells to read.
  @param [out] Value      If success, contains the decoded value.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
  @retval EFI_UNSUPPORTED         Unsupported cell count.
**/
EFI_STATUS
EFIAPI
ReadFdtCells64 (
  IN  CONST UINT32  *Data,
  IN        INT32   CellCount,
  OUT       UINT64  *Value
  );

/** Get the number of cells used to encode an interrupt for a specific Node.

  @param [in]  Fdt                Pointer to a Flattened Device Tree (Fdt).
  @param [in]  Node               Offset of a node in the interrupt hierarchy.
  @param [in]  SearchInHierarchy  If TRUE, search from the parent node
                                  (i.e. get the parent #interrupt-cells).
                                  If FALSE, simply read the property directly from
                                  the input Node.
  @param [out] IntCells           If success, contains the "#interrupt-cells"
                                  property value relevant for Node.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtGetInterruptCellsInfo (
  IN  CONST VOID     *Fdt,
  IN        INT32    Node,
  IN        BOOLEAN  SearchInHierarchy,
  OUT       INT32    *IntCells
  );

/** Get one "interrupt-map" entry.

  This helper parses the "interrupt-map" property of a nexus node and returns
  the fully decoded entry identified by Index. The pointers stored in Entry
  point inside the FDT blob, except the child-side fields when ApplyIntMask is
  TRUE. In that case, the child-side fields point to masked copies stored in
  Entry.

  An "interrupt-map" is encoded as:
  <
    child-unit-address
    child-interrupt-specifier
    interrupt parent
    parent-unit-address
    parent-interrupt-specifier
  >

  @param [in]  Fdt        Pointer to a Flattened Device Tree (Fdt).
  @param [in]  NexusNode  Offset of the nexus node exposing "interrupt-map".
  @param [in]  Index      Zero-based interrupt-map entry index.
  @param [in]  ApplyIntMask  Whether to apply the "interrupt-map-mask" to the
                             child-side fields.
  @param [out] Entry      If success, contains the requested interrupt-map
                          entry.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
  @retval EFI_NOT_FOUND           The requested entry was not found.
**/
EFI_STATUS
EFIAPI
FdtGetInterruptMap (
  IN  CONST VOID                      *Fdt,
  IN        INT32                     NexusNode,
  IN        UINT32                    Index,
  IN        BOOLEAN                   ApplyIntMask,
  OUT       INTERRUPT_MAP_ENTRY_INFO  *Entry
  );

/** Resolve an interrupt specifier for a node through interrupt nexus nodes.

  If the interrupt parent domain of Node is already an interrupt-controller,
  the requested interrupt specifier is returned directly from the node
  "interrupts" property. Otherwise, the interrupt specifier is resolved
  recursively through one or more parent nexus "interrupt-map" properties
  until a final interrupt-controller is reached.

  @param [in]  Fdt             Pointer to a Flattened Device Tree (Fdt).
  @param [in]  Node            Node to get the interrupt from.
  @param [in]  Index           Index of the interrupt to get.
  @param [out] Interrupt       If success, contains the resolved interrupt
                               specifier.
  @param [out] InterruptCells  If success, contains the "#interrupt-cells"
                               value of the final interrupt-controller.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
  @retval EFI_NOT_FOUND           The requested interrupt was not found.
  @retval EFI_UNSUPPORTED         Unsupported interrupt-map format.
**/
EFI_STATUS
EFIAPI
FdtResolveInterrupt (
  IN  CONST VOID    *Fdt,
  IN        INT32   Node,
  IN        UINT32  Index,
  OUT CONST UINT32  **Interrupt,
  OUT       INT32   *InterruptCells
  );

/** Get the "#address-cells" and/or "#size-cells" property of the node.

  According to the Device Tree specification, s2.3.5 "#address-cells and
  #size-cells":
  "If missing, a client program should assume a default value of 2 for
  #address-cells, and a value of 1 for #size-cells."

  @param [in]  Fdt              Pointer to a Flattened Device Tree.
  @param [in]  Node             Offset of the node having to get the
                                "#address-cells" and "#size-cells"
                                properties from.
  @param [out] AddressCells     If success, number of address-cells.
                                If the property is not available,
                                default value is 2.
  @param [out] SizeCells        If success, number of size-cells.
                                If the property is not available,
                                default value is 1.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtGetAddressInfo (
  IN  CONST VOID *Fdt,
  IN        INT32 Node,
  OUT       INT32 *AddressCells, OPTIONAL
  OUT       INT32     *SizeCells       OPTIONAL
  );

/** Get the "#address-cells" and/or "#size-cells" property of the parent node.

  According to the Device Tree specification, s2.3.5 "#address-cells and
  #size-cells":
  "If missing, a client program should assume a default value of 2 for
  #address-cells, and a value of 1 for #size-cells."

  @param [in]  Fdt              Pointer to a Flattened Device Tree.
  @param [in]  Node             Offset of the node having to get the
                                "#address-cells" and "#size-cells"
                                properties from its parent.
  @param [out] AddressCells     If success, number of address-cells.
                                If the property is not available,
                                default value is 2.
  @param [out] SizeCells        If success, number of size-cells.
                                If the property is not available,
                                default value is 1.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtGetParentAddressInfo (
  IN  CONST VOID *Fdt,
  IN        INT32 Node,
  OUT       INT32 *AddressCells, OPTIONAL
  OUT       INT32     *SizeCells       OPTIONAL
  );

/** Get an address/size pair from a node "reg" property.

  The "reg" property stores addresses in the parent bus address space.
  This helper reads the requested entry without applying parent bus "ranges"
  translations.

  The helper supports address and size fields up to 64 bits.

  @param [in]  Fdt              Pointer to a Flattened Device Tree.
  @param [in]  Node             Offset of the node owning the "reg" property.
  @param [in]  Index            Index of the address/size pair to read.
  @param [out] BaseAddress      If success, contains the raw base address.
  @param [out] BaseAddressSize  If success, contains the size associated with
                                the raw base address. This parameter is
                                optional.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
  @retval EFI_NOT_FOUND           The requested "reg" entry was not found.
  @retval EFI_UNSUPPORTED         Unsupported address or size encoding.
**/
EFI_STATUS
EFIAPI
FdtGetReg (
  IN  CONST VOID    *Fdt,
  IN        INT32   Node,
  IN        UINT32  Index,
  OUT       UINT64  *BaseAddress,
  OUT       UINT64  *BaseAddressSize OPTIONAL
  );

/** Get a translated address/size pair from a node "reg" property.

  The "reg" property stores addresses in the parent bus address space.
  This helper reads the requested entry and resolves parent bus "ranges"
  mappings up to the root bus to return a CPU physical address.

  The helper supports address and size fields up to 64 bits.

  @param [in]  Fdt              Pointer to a Flattened Device Tree.
  @param [in]  Node             Offset of the node owning the "reg" property.
  @param [in]  Index            Index of the address/size pair to read.
  @param [out] BaseAddress      If success, contains the translated base
                                address.
  @param [out] BaseAddressSize  If success, contains the size associated with
                                the translated base address. This parameter is
                                optional.

  @retval EFI_SUCCESS             The function completed successfully.
  @retval EFI_ABORTED             An error occurred.
  @retval EFI_INVALID_PARAMETER   Invalid parameter.
  @retval EFI_NOT_FOUND           No matching "ranges" entry found.
  @retval EFI_UNSUPPORTED         Unsupported address or size encoding.
**/
EFI_STATUS
EFIAPI
FdtGetTranslatedReg (
  IN  CONST VOID    *Fdt,
  IN        INT32   Node,
  IN        UINT32  Index,
  OUT       UINT64  *BaseAddress,
  OUT       UINT64  *BaseAddressSize OPTIONAL
  );

/** For relevant architectures, get the "#address-cells" and/or "#size-cells"
    property of the node.

  According to the Device Tree specification, s2.3.5 "#address-cells and
  #size-cells":
  "If missing, a client program should assume a default value of 2 for
  #address-cells, and a value of 1 for #size-cells."

  @param [in]  Fdt              Pointer to a Flattened Device Tree.
  @param [in]  Node             Offset of the node having to get the
                                "#address-cells" and "#size-cells"
                                properties from.
  @param [out] AddressCells     If success, number of address-cells.
                                If the property is not available,
                                default value is 2.
  @param [out] SizeCells        If success, number of size-cells.
                                If the property is not available,
                                default value is 1.

  @retval EFI_INVALID_PARAMETER   Invalid parameter.
**/
EFI_STATUS
EFIAPI
FdtGetIntcAddressCells (
  IN  CONST VOID *Fdt,
  IN        INT32 Node,
  OUT       INT32 *AddressCells, OPTIONAL
  OUT       INT32     *SizeCells       OPTIONAL
  );

/** Convert the IRQ number in DT to ACPI GSI number

  In RISC-V, GSI space is divided among PLIC/APLICs. Hence, based
  on the parent interrupt controller, the IRQ number need to be
  converted into appropriate GSI number.

  @param [in]  ExtIntcNode    Parent interrupt controller node.
  @param [in]  Irq       Irq number to convert.

**/
UINT32
FdtConvertToGsi (
  IN INT32   ExtIntcNode,
  IN UINT32  Irq
  );

/** Create list of external interrupt controllers.

  In RISC-V, GSI space is divided among PLIC/APLICs. To convert
  the IRQ number in DT of a device to appropriate GSI number,
  create a list of external interrupt controllers.

  @param [in]  ExtIntcNode    External interrupt controller node.
  @param [in]  GsiBase        GSI base of the interrupt controller.

  @retval EFI_SUCCESS           External interrupt controller node is added in the list.
  @retval EFI_OUT_OF_RESOURCES  Failed to allocate memory for the list.
**/
EFI_STATUS
FdtCreateExtIntcList (
  INT32   ExtIntcNode,
  UINT32  GsiBase
  );