]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/PrePi/FdtParser.c
2 * Copyright (c) 2015, Linaro Ltd. All rights reserved.
4 * SPDX-License-Identifier: BSD-2-Clause-Patent
8 #include <Include/libfdt.h>
12 IN VOID
*DeviceTreeBlob
,
13 OUT UINT64
*SystemMemoryBase
,
14 OUT UINT64
*SystemMemorySize
23 if (fdt_check_header (DeviceTreeBlob
) != 0) {
28 // Look for a node called "memory" at the lowest level of the tree
30 MemoryNode
= fdt_path_offset (DeviceTreeBlob
, "/memory");
31 if (MemoryNode
<= 0) {
36 // Retrieve the #address-cells and #size-cells properties
37 // from the root node, or use the default if not provided.
42 Prop
= fdt_getprop (DeviceTreeBlob
, 0, "#address-cells", &Length
);
44 AddressCells
= fdt32_to_cpu (*Prop
);
47 Prop
= fdt_getprop (DeviceTreeBlob
, 0, "#size-cells", &Length
);
49 SizeCells
= fdt32_to_cpu (*Prop
);
53 // Now find the 'reg' property of the /memory node, and read the first
56 Prop
= fdt_getprop (DeviceTreeBlob
, MemoryNode
, "reg", &Length
);
58 if (Length
< (AddressCells
+ SizeCells
) * sizeof (INT32
)) {
62 *SystemMemoryBase
= fdt32_to_cpu (Prop
[0]);
63 if (AddressCells
> 1) {
64 *SystemMemoryBase
= (*SystemMemoryBase
<< 32) | fdt32_to_cpu (Prop
[1]);
68 *SystemMemorySize
= fdt32_to_cpu (Prop
[0]);
70 *SystemMemorySize
= (*SystemMemorySize
<< 32) | fdt32_to_cpu (Prop
[1]);
83 CopyMem (FdtDest
, FdtSource
, fdt_totalsize (FdtSource
));