]>
Commit | Line | Data |
---|---|---|
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 | |
10 | BOOLEAN\r | |
11 | FindMemnode (\r | |
12 | IN VOID *DeviceTreeBlob,\r | |
13 | OUT UINT64 *SystemMemoryBase,\r | |
14 | OUT UINT64 *SystemMemorySize\r | |
15 | )\r | |
16 | {\r | |
17 | INT32 MemoryNode;\r | |
18 | INT32 AddressCells;\r | |
19 | INT32 SizeCells;\r | |
20 | INT32 Length;\r | |
21 | CONST INT32 *Prop;\r | |
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 | |
40 | SizeCells = 1;\r | |
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 | |
66 | Prop += AddressCells;\r | |
67 | \r | |
68 | *SystemMemorySize = fdt32_to_cpu (Prop[0]);\r | |
69 | if (SizeCells > 1) {\r | |
70 | *SystemMemorySize = (*SystemMemorySize << 32) | fdt32_to_cpu (Prop[1]);\r | |
71 | }\r | |
72 | \r | |
73 | return TRUE;\r | |
74 | }\r | |
75 | \r | |
76 | VOID\r | |
77 | CopyFdt (\r | |
78 | IN VOID *FdtDest,\r | |
79 | IN VOID *FdtSource\r | |
80 | )\r | |
81 | {\r | |
82 | fdt_pack(FdtSource);\r | |
83 | CopyMem (FdtDest, FdtSource, fdt_totalsize (FdtSource));\r | |
84 | }\r |