]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/PrePi/FdtParser.c
ArmVirtPkg: Apply uncrustify changes
[mirror_edk2.git] / ArmVirtPkg / PrePi / FdtParser.c
CommitLineData
83270956
AB
1/*\r
2 * Copyright (c) 2015, Linaro Ltd. All rights reserved.\r
3 *\r
9792fb0e 4 * SPDX-License-Identifier: BSD-2-Clause-Patent\r
83270956
AB
5 */\r
6\r
7#include <Uefi.h>\r
8#include <Include/libfdt.h>\r
9\r
10BOOLEAN\r
11FindMemnode (\r
12 IN VOID *DeviceTreeBlob,\r
13 OUT UINT64 *SystemMemoryBase,\r
14 OUT UINT64 *SystemMemorySize\r
15 )\r
16{\r
2b16a4fb
MK
17 INT32 MemoryNode;\r
18 INT32 AddressCells;\r
19 INT32 SizeCells;\r
20 INT32 Length;\r
21 CONST INT32 *Prop;\r
83270956
AB
22\r
23 if (fdt_check_header (DeviceTreeBlob) != 0) {\r
24 return FALSE;\r
25 }\r
26\r
27 //\r
28 // Look for a node called "memory" at the lowest level of the tree\r
29 //\r
30 MemoryNode = fdt_path_offset (DeviceTreeBlob, "/memory");\r
31 if (MemoryNode <= 0) {\r
32 return FALSE;\r
33 }\r
34\r
35 //\r
36 // Retrieve the #address-cells and #size-cells properties\r
37 // from the root node, or use the default if not provided.\r
38 //\r
39 AddressCells = 1;\r
2b16a4fb 40 SizeCells = 1;\r
83270956
AB
41\r
42 Prop = fdt_getprop (DeviceTreeBlob, 0, "#address-cells", &Length);\r
43 if (Length == 4) {\r
44 AddressCells = fdt32_to_cpu (*Prop);\r
45 }\r
46\r
47 Prop = fdt_getprop (DeviceTreeBlob, 0, "#size-cells", &Length);\r
48 if (Length == 4) {\r
49 SizeCells = fdt32_to_cpu (*Prop);\r
50 }\r
51\r
52 //\r
53 // Now find the 'reg' property of the /memory node, and read the first\r
54 // range listed.\r
55 //\r
56 Prop = fdt_getprop (DeviceTreeBlob, MemoryNode, "reg", &Length);\r
57\r
58 if (Length < (AddressCells + SizeCells) * sizeof (INT32)) {\r
59 return FALSE;\r
60 }\r
61\r
62 *SystemMemoryBase = fdt32_to_cpu (Prop[0]);\r
63 if (AddressCells > 1) {\r
64 *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);\r
65 }\r
2b16a4fb 66\r
83270956
AB
67 Prop += AddressCells;\r
68\r
69 *SystemMemorySize = fdt32_to_cpu (Prop[0]);\r
70 if (SizeCells > 1) {\r
71 *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);\r
72 }\r
73\r
74 return TRUE;\r
75}\r
76\r
77VOID\r
78CopyFdt (\r
2b16a4fb
MK
79 IN VOID *FdtDest,\r
80 IN VOID *FdtSource\r
83270956
AB
81 )\r
82{\r
2b16a4fb 83 fdt_pack (FdtSource);\r
83270956
AB
84 CopyMem (FdtDest, FdtSource, fdt_totalsize (FdtSource));\r
85}\r