]> git.proxmox.com Git - mirror_edk2.git/blame - ArmVirtPkg/Library/ArmXenRelocatablePlatformLib/FdtParser.c
ArmVirtPkg/FdtParser: avoid unaligned accesses with the MMU off
[mirror_edk2.git] / ArmVirtPkg / Library / ArmXenRelocatablePlatformLib / FdtParser.c
CommitLineData
03b6bed1
AB
1/*\r
2 * Copyright (c) 2015, Linaro Ltd. All rights reserved.\r
3 *\r
4 * This program and the accompanying materials\r
5 * are licensed and made available under the terms and conditions of the BSD License\r
6 * which accompanies this distribution. The full text of the license may be found at\r
7 * http://opensource.org/licenses/bsd-license.php\r
8 *\r
9 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11 */\r
12\r
13#include <Uefi.h>\r
14#include <Include/libfdt.h>\r
15\r
16BOOLEAN\r
17FindMemnode (\r
18 IN VOID *DeviceTreeBlob,\r
19 OUT UINT64 *SystemMemoryBase,\r
20 OUT UINT64 *SystemMemorySize\r
21 )\r
22{\r
23 INT32 MemoryNode;\r
24 INT32 AddressCells;\r
25 INT32 SizeCells;\r
26 INT32 Length;\r
27 CONST INT32 *Prop;\r
28\r
29 if (fdt_check_header (DeviceTreeBlob) != 0) {\r
30 return FALSE;\r
31 }\r
32\r
33 //\r
34 // Look for a node called "memory" at the lowest level of the tree\r
35 //\r
36 MemoryNode = fdt_path_offset (DeviceTreeBlob, "/memory");\r
37 if (MemoryNode <= 0) {\r
38 return FALSE;\r
39 }\r
40\r
41 //\r
42 // Retrieve the #address-cells and #size-cells properties\r
43 // from the root node, or use the default if not provided.\r
44 //\r
45 AddressCells = 1;\r
46 SizeCells = 1;\r
47\r
48 Prop = fdt_getprop (DeviceTreeBlob, 0, "#address-cells", &Length);\r
49 if (Length == 4) {\r
50 AddressCells = fdt32_to_cpu (*Prop);\r
51 }\r
52\r
53 Prop = fdt_getprop (DeviceTreeBlob, 0, "#size-cells", &Length);\r
54 if (Length == 4) {\r
55 SizeCells = fdt32_to_cpu (*Prop);\r
56 }\r
57\r
58 //\r
59 // Now find the 'reg' property of the /memory node, and read the first\r
60 // range listed.\r
61 //\r
62 Prop = fdt_getprop (DeviceTreeBlob, MemoryNode, "reg", &Length);\r
63\r
64 if (Length < (AddressCells + SizeCells) * sizeof (INT32)) {\r
65 return FALSE;\r
66 }\r
67\r
94a3845b
AB
68 *SystemMemoryBase = fdt32_to_cpu (Prop[0]);\r
69 if (AddressCells > 1) {\r
70 *SystemMemoryBase = (*SystemMemoryBase << 32) | fdt32_to_cpu (Prop[1]);\r
03b6bed1
AB
71 }\r
72 Prop += AddressCells;\r
73\r
94a3845b
AB
74 *SystemMemorySize = fdt32_to_cpu (Prop[0]);\r
75 if (SizeCells > 1) {\r
76 *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);\r
03b6bed1
AB
77 }\r
78\r
79 return TRUE;\r
80}\r
81\r
82VOID\r
83CopyFdt (\r
84 IN VOID *FdtDest,\r
85 IN VOID *FdtSource\r
86 )\r
87{\r
88 CopyMem (FdtDest, FdtSource, fdt_totalsize (FdtSource));\r
89}\r