]>
git.proxmox.com Git - mirror_edk2.git/blob - ArmVirtPkg/PrePi/FdtParser.c
2 * Copyright (c) 2015, Linaro Ltd. All rights reserved.
4 * This program and the accompanying materials
5 * are licensed and made available under the terms and conditions of the BSD License
6 * which accompanies this distribution. The full text of the license may be found at
7 * http://opensource.org/licenses/bsd-license.php
9 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include <Include/libfdt.h>
18 IN VOID
*DeviceTreeBlob
,
19 OUT UINT64
*SystemMemoryBase
,
20 OUT UINT64
*SystemMemorySize
29 if (fdt_check_header (DeviceTreeBlob
) != 0) {
34 // Look for a node called "memory" at the lowest level of the tree
36 MemoryNode
= fdt_path_offset (DeviceTreeBlob
, "/memory");
37 if (MemoryNode
<= 0) {
42 // Retrieve the #address-cells and #size-cells properties
43 // from the root node, or use the default if not provided.
48 Prop
= fdt_getprop (DeviceTreeBlob
, 0, "#address-cells", &Length
);
50 AddressCells
= fdt32_to_cpu (*Prop
);
53 Prop
= fdt_getprop (DeviceTreeBlob
, 0, "#size-cells", &Length
);
55 SizeCells
= fdt32_to_cpu (*Prop
);
59 // Now find the 'reg' property of the /memory node, and read the first
62 Prop
= fdt_getprop (DeviceTreeBlob
, MemoryNode
, "reg", &Length
);
64 if (Length
< (AddressCells
+ SizeCells
) * sizeof (INT32
)) {
68 *SystemMemoryBase
= fdt32_to_cpu (Prop
[0]);
69 if (AddressCells
> 1) {
70 *SystemMemoryBase
= (*SystemMemoryBase
<< 32) | fdt32_to_cpu (Prop
[1]);
74 *SystemMemorySize
= fdt32_to_cpu (Prop
[0]);
76 *SystemMemorySize
= (*SystemMemorySize
<< 32) | fdt32_to_cpu (Prop
[1]);
89 CopyMem (FdtDest
, FdtSource
, fdt_totalsize (FdtSource
));