efifdt.c revision 1.19 1 1.19 jmcneill /* $NetBSD: efifdt.c,v 1.19 2019/08/30 00:01:33 jmcneill Exp $ */
2 1.1 jmcneill
3 1.1 jmcneill /*-
4 1.15 thorpej * Copyright (c) 2019 Jason R. Thorpe
5 1.1 jmcneill * Copyright (c) 2018 Jared McNeill <jmcneill (at) invisible.ca>
6 1.1 jmcneill * All rights reserved.
7 1.1 jmcneill *
8 1.1 jmcneill * Redistribution and use in source and binary forms, with or without
9 1.1 jmcneill * modification, are permitted provided that the following conditions
10 1.1 jmcneill * are met:
11 1.1 jmcneill * 1. Redistributions of source code must retain the above copyright
12 1.1 jmcneill * notice, this list of conditions and the following disclaimer.
13 1.1 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 jmcneill * notice, this list of conditions and the following disclaimer in the
15 1.1 jmcneill * documentation and/or other materials provided with the distribution.
16 1.1 jmcneill *
17 1.1 jmcneill * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 1.1 jmcneill * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 1.1 jmcneill * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 1.1 jmcneill * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 1.1 jmcneill * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 1.1 jmcneill * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 1.1 jmcneill * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 1.1 jmcneill * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 1.1 jmcneill * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 1.1 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 1.1 jmcneill * SUCH DAMAGE.
28 1.1 jmcneill */
29 1.1 jmcneill
30 1.1 jmcneill #include "efiboot.h"
31 1.1 jmcneill #include "efifdt.h"
32 1.3 jmcneill #include "efiblock.h"
33 1.1 jmcneill
34 1.1 jmcneill #include <libfdt.h>
35 1.1 jmcneill
36 1.1 jmcneill #define FDT_TABLE_GUID \
37 1.1 jmcneill { 0xb1b621d5, 0xf19c, 0x41a5, { 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 } }
38 1.1 jmcneill static EFI_GUID FdtTableGuid = FDT_TABLE_GUID;
39 1.1 jmcneill
40 1.1 jmcneill #define FDT_MEMORY_NODE_PATH "/memory"
41 1.1 jmcneill #define FDT_MEMORY_NODE_NAME "memory"
42 1.1 jmcneill #define FDT_CHOSEN_NODE_PATH "/chosen"
43 1.3 jmcneill #define FDT_CHOSEN_NODE_NAME "chosen"
44 1.1 jmcneill
45 1.1 jmcneill #define FDT_MEMORY_USABLE(_md) \
46 1.1 jmcneill ((_md)->Type == EfiLoaderCode || (_md)->Type == EfiLoaderData || \
47 1.1 jmcneill (_md)->Type == EfiBootServicesCode || (_md)->Type == EfiBootServicesData || \
48 1.1 jmcneill (_md)->Type == EfiConventionalMemory)
49 1.1 jmcneill
50 1.1 jmcneill static void *fdt_data = NULL;
51 1.1 jmcneill
52 1.1 jmcneill int
53 1.1 jmcneill efi_fdt_probe(void)
54 1.1 jmcneill {
55 1.1 jmcneill EFI_STATUS status;
56 1.1 jmcneill
57 1.1 jmcneill status = LibGetSystemConfigurationTable(&FdtTableGuid, &fdt_data);
58 1.1 jmcneill if (EFI_ERROR(status))
59 1.1 jmcneill return EIO;
60 1.1 jmcneill
61 1.1 jmcneill if (fdt_check_header(fdt_data) != 0) {
62 1.1 jmcneill fdt_data = NULL;
63 1.1 jmcneill return EINVAL;
64 1.1 jmcneill }
65 1.1 jmcneill
66 1.1 jmcneill return 0;
67 1.1 jmcneill }
68 1.1 jmcneill
69 1.9 jmcneill int
70 1.9 jmcneill efi_fdt_set_data(void *data)
71 1.9 jmcneill {
72 1.9 jmcneill if (fdt_check_header(data) != 0)
73 1.9 jmcneill return EINVAL;
74 1.9 jmcneill
75 1.9 jmcneill fdt_data = data;
76 1.9 jmcneill return 0;
77 1.9 jmcneill }
78 1.9 jmcneill
79 1.1 jmcneill void *
80 1.1 jmcneill efi_fdt_data(void)
81 1.1 jmcneill {
82 1.1 jmcneill return fdt_data;
83 1.1 jmcneill }
84 1.1 jmcneill
85 1.1 jmcneill int
86 1.1 jmcneill efi_fdt_size(void)
87 1.1 jmcneill {
88 1.1 jmcneill return fdt_data == NULL ? 0 : fdt_totalsize(fdt_data);
89 1.1 jmcneill }
90 1.1 jmcneill
91 1.15 thorpej bool
92 1.15 thorpej efi_fdt_overlay_is_compatible(void *dtbo)
93 1.15 thorpej {
94 1.15 thorpej const int system_root = fdt_path_offset(fdt_data, "/");
95 1.15 thorpej const int overlay_root = fdt_path_offset(dtbo, "/");
96 1.15 thorpej
97 1.15 thorpej if (system_root < 0 || overlay_root < 0)
98 1.15 thorpej return false;
99 1.15 thorpej
100 1.15 thorpej const int system_ncompat = fdt_stringlist_count(fdt_data, system_root,
101 1.15 thorpej "compatible");
102 1.15 thorpej const int overlay_ncompat = fdt_stringlist_count(dtbo, overlay_root,
103 1.15 thorpej "compatible");
104 1.15 thorpej
105 1.15 thorpej if (system_ncompat <= 0 || overlay_ncompat <= 0)
106 1.15 thorpej return false;
107 1.15 thorpej
108 1.15 thorpej const char *system_compatible, *overlay_compatible;
109 1.15 thorpej int si, oi;
110 1.15 thorpej
111 1.15 thorpej for (si = 0; si < system_ncompat; si++) {
112 1.15 thorpej system_compatible = fdt_stringlist_get(fdt_data,
113 1.15 thorpej system_root, "compatible", si, NULL);
114 1.15 thorpej if (system_compatible == NULL)
115 1.15 thorpej continue;
116 1.15 thorpej for (oi = 0; oi < overlay_ncompat; oi++) {
117 1.15 thorpej overlay_compatible = fdt_stringlist_get(dtbo,
118 1.15 thorpej overlay_root, "compatible", oi, NULL);
119 1.15 thorpej if (overlay_compatible == NULL)
120 1.15 thorpej continue;
121 1.15 thorpej if (strcmp(system_compatible, overlay_compatible) == 0)
122 1.15 thorpej return true;
123 1.15 thorpej }
124 1.15 thorpej }
125 1.15 thorpej
126 1.15 thorpej return false;
127 1.15 thorpej }
128 1.15 thorpej
129 1.15 thorpej int
130 1.15 thorpej efi_fdt_overlay_apply(void *dtbo, int *fdterr)
131 1.15 thorpej {
132 1.15 thorpej int err = fdt_overlay_apply(fdt_data, dtbo);
133 1.15 thorpej if (fdterr)
134 1.15 thorpej *fdterr = err;
135 1.15 thorpej return err == 0 ? 0 : EIO;
136 1.15 thorpej }
137 1.15 thorpej
138 1.1 jmcneill void
139 1.8 jmcneill efi_fdt_init(u_long addr, u_long len)
140 1.8 jmcneill {
141 1.8 jmcneill int error;
142 1.8 jmcneill
143 1.8 jmcneill error = fdt_open_into(fdt_data, (void *)addr, len);
144 1.8 jmcneill if (error < 0)
145 1.8 jmcneill panic("fdt_open_into failed: %d", error);
146 1.8 jmcneill
147 1.8 jmcneill fdt_data = (void *)addr;
148 1.8 jmcneill }
149 1.8 jmcneill
150 1.8 jmcneill void
151 1.8 jmcneill efi_fdt_fini(void)
152 1.8 jmcneill {
153 1.8 jmcneill int error;
154 1.8 jmcneill
155 1.8 jmcneill error = fdt_pack(fdt_data);
156 1.8 jmcneill if (error < 0)
157 1.8 jmcneill panic("fdt_pack failed: %d", error);
158 1.8 jmcneill }
159 1.8 jmcneill
160 1.8 jmcneill void
161 1.7 jmcneill efi_fdt_show(void)
162 1.7 jmcneill {
163 1.7 jmcneill const char *model, *compat;
164 1.7 jmcneill int n, ncompat;
165 1.7 jmcneill
166 1.7 jmcneill if (fdt_data == NULL)
167 1.7 jmcneill return;
168 1.7 jmcneill
169 1.7 jmcneill model = fdt_getprop(fdt_data, fdt_path_offset(fdt_data, "/"), "model", NULL);
170 1.7 jmcneill if (model)
171 1.7 jmcneill printf("FDT: %s [", model);
172 1.7 jmcneill ncompat = fdt_stringlist_count(fdt_data, fdt_path_offset(fdt_data, "/"), "compatible");
173 1.7 jmcneill for (n = 0; n < ncompat; n++) {
174 1.7 jmcneill compat = fdt_stringlist_get(fdt_data, fdt_path_offset(fdt_data, "/"),
175 1.7 jmcneill "compatible", n, NULL);
176 1.7 jmcneill printf("%s%s", n == 0 ? "" : ", ", compat);
177 1.7 jmcneill }
178 1.7 jmcneill printf("]\n");
179 1.7 jmcneill }
180 1.7 jmcneill
181 1.7 jmcneill void
182 1.1 jmcneill efi_fdt_memory_map(void)
183 1.1 jmcneill {
184 1.1 jmcneill UINTN nentries = 0, mapkey, descsize;
185 1.2 jmcneill EFI_MEMORY_DESCRIPTOR *md, *memmap;
186 1.1 jmcneill UINT32 descver;
187 1.2 jmcneill UINT64 phys_start, phys_size;
188 1.16 jmcneill int n, memory, chosen;
189 1.1 jmcneill
190 1.1 jmcneill memory = fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH);
191 1.1 jmcneill if (memory < 0)
192 1.1 jmcneill memory = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_MEMORY_NODE_NAME);
193 1.1 jmcneill if (memory < 0)
194 1.1 jmcneill panic("FDT: Failed to create " FDT_MEMORY_NODE_PATH " node");
195 1.1 jmcneill
196 1.16 jmcneill chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
197 1.16 jmcneill if (chosen < 0)
198 1.16 jmcneill chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
199 1.16 jmcneill if (chosen < 0)
200 1.16 jmcneill panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
201 1.16 jmcneill
202 1.1 jmcneill fdt_delprop(fdt_data, memory, "reg");
203 1.1 jmcneill
204 1.1 jmcneill const int address_cells = fdt_address_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
205 1.1 jmcneill const int size_cells = fdt_size_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
206 1.1 jmcneill
207 1.2 jmcneill memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
208 1.2 jmcneill for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
209 1.18 jmcneill fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Type);
210 1.18 jmcneill fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->PhysicalStart);
211 1.18 jmcneill fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->NumberOfPages);
212 1.18 jmcneill fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Attribute);
213 1.18 jmcneill
214 1.11 jmcneill if ((md->Attribute & EFI_MEMORY_RUNTIME) != 0)
215 1.11 jmcneill continue;
216 1.16 jmcneill
217 1.1 jmcneill if ((md->Attribute & EFI_MEMORY_WB) == 0)
218 1.1 jmcneill continue;
219 1.1 jmcneill if (!FDT_MEMORY_USABLE(md))
220 1.1 jmcneill continue;
221 1.2 jmcneill if ((address_cells == 1 || size_cells == 1) && md->PhysicalStart + (md->NumberOfPages * EFI_PAGE_SIZE) > 0xffffffff)
222 1.2 jmcneill continue;
223 1.2 jmcneill if (md->NumberOfPages <= 1)
224 1.2 jmcneill continue;
225 1.2 jmcneill
226 1.2 jmcneill phys_start = md->PhysicalStart;
227 1.2 jmcneill phys_size = md->NumberOfPages * EFI_PAGE_SIZE;
228 1.2 jmcneill
229 1.2 jmcneill if (phys_start & EFI_PAGE_MASK) {
230 1.2 jmcneill /* UEFI spec says these should be 4KB aligned, but U-Boot doesn't always.. */
231 1.2 jmcneill phys_start = (phys_start + EFI_PAGE_SIZE) & ~EFI_PAGE_MASK;
232 1.2 jmcneill phys_size -= (EFI_PAGE_SIZE * 2);
233 1.2 jmcneill if (phys_size == 0)
234 1.2 jmcneill continue;
235 1.2 jmcneill }
236 1.1 jmcneill
237 1.1 jmcneill if (address_cells == 1)
238 1.1 jmcneill fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
239 1.2 jmcneill "reg", (uint32_t)phys_start);
240 1.1 jmcneill else
241 1.1 jmcneill fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
242 1.2 jmcneill "reg", phys_start);
243 1.1 jmcneill
244 1.1 jmcneill if (size_cells == 1)
245 1.1 jmcneill fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
246 1.2 jmcneill "reg", (uint32_t)phys_size);
247 1.1 jmcneill else
248 1.1 jmcneill fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
249 1.2 jmcneill "reg", phys_size);
250 1.1 jmcneill }
251 1.1 jmcneill }
252 1.1 jmcneill
253 1.1 jmcneill void
254 1.16 jmcneill efi_fdt_gop(void)
255 1.16 jmcneill {
256 1.16 jmcneill EFI_STATUS status;
257 1.16 jmcneill EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
258 1.16 jmcneill EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *mode;
259 1.16 jmcneill EFI_HANDLE *gop_handle;
260 1.16 jmcneill UINTN ngop_handle, n;
261 1.16 jmcneill char buf[48];
262 1.16 jmcneill int fb;
263 1.16 jmcneill
264 1.16 jmcneill status = LibLocateHandle(ByProtocol, &GraphicsOutputProtocol, NULL, &ngop_handle, &gop_handle);
265 1.16 jmcneill if (EFI_ERROR(status) || ngop_handle == 0)
266 1.16 jmcneill return;
267 1.16 jmcneill
268 1.16 jmcneill for (n = 0; n < ngop_handle; n++) {
269 1.16 jmcneill status = uefi_call_wrapper(BS->HandleProtocol, 3, gop_handle[n], &GraphicsOutputProtocol, (void **)&gop);
270 1.16 jmcneill if (EFI_ERROR(status))
271 1.16 jmcneill continue;
272 1.16 jmcneill
273 1.16 jmcneill mode = gop->Mode;
274 1.16 jmcneill if (mode == NULL)
275 1.16 jmcneill continue;
276 1.16 jmcneill
277 1.16 jmcneill #ifdef EFIBOOT_DEBUG
278 1.16 jmcneill printf("GOP: FB @ 0x%lx size 0x%lx\n", mode->FrameBufferBase, mode->FrameBufferSize);
279 1.16 jmcneill printf("GOP: Version %d\n", mode->Info->Version);
280 1.16 jmcneill printf("GOP: HRes %d VRes %d\n", mode->Info->HorizontalResolution, mode->Info->VerticalResolution);
281 1.16 jmcneill printf("GOP: PixelFormat %d\n", mode->Info->PixelFormat);
282 1.16 jmcneill printf("GOP: PixelBitmask R 0x%x G 0x%x B 0x%x Res 0x%x\n",
283 1.16 jmcneill mode->Info->PixelInformation.RedMask,
284 1.16 jmcneill mode->Info->PixelInformation.GreenMask,
285 1.16 jmcneill mode->Info->PixelInformation.BlueMask,
286 1.16 jmcneill mode->Info->PixelInformation.ReservedMask);
287 1.16 jmcneill printf("GOP: Pixels per scanline %d\n", mode->Info->PixelsPerScanLine);
288 1.16 jmcneill #endif
289 1.16 jmcneill
290 1.16 jmcneill if (mode->Info->PixelFormat == PixelBltOnly) {
291 1.16 jmcneill printf("GOP: PixelBltOnly pixel format not supported\n");
292 1.16 jmcneill continue;
293 1.16 jmcneill }
294 1.16 jmcneill
295 1.19 jmcneill fdt_setprop_u32(fdt_data,
296 1.19 jmcneill fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "#address-cells", 2);
297 1.19 jmcneill fdt_setprop_u32(fdt_data,
298 1.19 jmcneill fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "#size-cells", 2);
299 1.19 jmcneill fdt_setprop_empty(fdt_data,
300 1.19 jmcneill fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "ranges");
301 1.19 jmcneill
302 1.17 skrll snprintf(buf, sizeof(buf), "framebuffer@%" PRIx64, mode->FrameBufferBase);
303 1.19 jmcneill fb = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), buf);
304 1.16 jmcneill if (fb < 0)
305 1.16 jmcneill panic("FDT: Failed to create framebuffer node");
306 1.16 jmcneill
307 1.16 jmcneill fdt_appendprop_string(fdt_data, fb, "compatible", "simple-framebuffer");
308 1.16 jmcneill fdt_appendprop_string(fdt_data, fb, "status", "okay");
309 1.16 jmcneill fdt_appendprop_u64(fdt_data, fb, "reg", mode->FrameBufferBase);
310 1.16 jmcneill fdt_appendprop_u64(fdt_data, fb, "reg", mode->FrameBufferSize);
311 1.16 jmcneill fdt_appendprop_u32(fdt_data, fb, "width", mode->Info->HorizontalResolution);
312 1.16 jmcneill fdt_appendprop_u32(fdt_data, fb, "height", mode->Info->VerticalResolution);
313 1.16 jmcneill fdt_appendprop_u32(fdt_data, fb, "stride", mode->Info->PixelsPerScanLine * 4); /* XXX */
314 1.16 jmcneill fdt_appendprop_string(fdt_data, fb, "format", "a8b8g8r8");
315 1.16 jmcneill
316 1.17 skrll snprintf(buf, sizeof(buf), "/chosen/framebuffer@%" PRIx64, mode->FrameBufferBase);
317 1.16 jmcneill fdt_setprop_string(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH),
318 1.16 jmcneill "stdout-path", buf);
319 1.16 jmcneill
320 1.16 jmcneill return;
321 1.16 jmcneill }
322 1.16 jmcneill }
323 1.16 jmcneill
324 1.16 jmcneill void
325 1.1 jmcneill efi_fdt_bootargs(const char *bootargs)
326 1.1 jmcneill {
327 1.3 jmcneill struct efi_block_part *bpart = efi_block_boot_part();
328 1.14 jmcneill uint8_t macaddr[6];
329 1.3 jmcneill int chosen;
330 1.3 jmcneill
331 1.3 jmcneill chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
332 1.3 jmcneill if (chosen < 0)
333 1.3 jmcneill chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
334 1.3 jmcneill if (chosen < 0)
335 1.4 alnsn panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
336 1.3 jmcneill
337 1.3 jmcneill if (*bootargs)
338 1.3 jmcneill fdt_setprop_string(fdt_data, chosen, "bootargs", bootargs);
339 1.3 jmcneill
340 1.3 jmcneill if (bpart) {
341 1.3 jmcneill switch (bpart->type) {
342 1.3 jmcneill case EFI_BLOCK_PART_DISKLABEL:
343 1.3 jmcneill fdt_setprop(fdt_data, chosen, "netbsd,mbr",
344 1.3 jmcneill bpart->hash, sizeof(bpart->hash));
345 1.3 jmcneill fdt_setprop_u32(fdt_data, chosen, "netbsd,partition",
346 1.3 jmcneill bpart->index);
347 1.3 jmcneill break;
348 1.12 jmcneill case EFI_BLOCK_PART_GPT:
349 1.12 jmcneill if (bpart->gpt.ent.ent_name[0] == 0x0000) {
350 1.12 jmcneill fdt_setprop(fdt_data, chosen, "netbsd,gpt-guid",
351 1.12 jmcneill bpart->hash, sizeof(bpart->hash));
352 1.12 jmcneill } else {
353 1.12 jmcneill char *label = NULL;
354 1.12 jmcneill int rv = ucs2_to_utf8(bpart->gpt.ent.ent_name, &label);
355 1.12 jmcneill if (rv == 0) {
356 1.12 jmcneill fdt_setprop_string(fdt_data, chosen, "netbsd,gpt-label", label);
357 1.12 jmcneill FreePool(label);
358 1.12 jmcneill }
359 1.12 jmcneill }
360 1.12 jmcneill break;
361 1.3 jmcneill default:
362 1.3 jmcneill break;
363 1.3 jmcneill }
364 1.14 jmcneill } else if (efi_net_get_booted_macaddr(macaddr) == 0) {
365 1.14 jmcneill fdt_setprop(fdt_data, chosen, "netbsd,booted-mac-address", macaddr, sizeof(macaddr));
366 1.3 jmcneill }
367 1.1 jmcneill }
368 1.8 jmcneill
369 1.8 jmcneill void
370 1.8 jmcneill efi_fdt_initrd(u_long initrd_addr, u_long initrd_size)
371 1.8 jmcneill {
372 1.8 jmcneill int chosen;
373 1.8 jmcneill
374 1.8 jmcneill if (initrd_size == 0)
375 1.8 jmcneill return;
376 1.8 jmcneill
377 1.8 jmcneill chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
378 1.8 jmcneill if (chosen < 0)
379 1.8 jmcneill chosen = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_CHOSEN_NODE_NAME);
380 1.8 jmcneill if (chosen < 0)
381 1.8 jmcneill panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
382 1.8 jmcneill
383 1.8 jmcneill fdt_setprop_u64(fdt_data, chosen, "linux,initrd-start", initrd_addr);
384 1.8 jmcneill fdt_setprop_u64(fdt_data, chosen, "linux,initrd-end", initrd_addr + initrd_size);
385 1.8 jmcneill }
386