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