Home | History | Annotate | Line # | Download | only in efiboot
efifdt.c revision 1.27
      1  1.27  jmcneill /* $NetBSD: efifdt.c,v 1.27 2020/10/22 09:28:30 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.25  jmcneill #include "efiacpi.h"
     34   1.1  jmcneill 
     35   1.1  jmcneill #include <libfdt.h>
     36   1.1  jmcneill 
     37   1.1  jmcneill #define FDT_TABLE_GUID	\
     38   1.1  jmcneill 	{ 0xb1b621d5, 0xf19c, 0x41a5, { 0x83, 0x0b, 0xd9, 0x15, 0x2c, 0x69, 0xaa, 0xe0 } }
     39   1.1  jmcneill static EFI_GUID FdtTableGuid = FDT_TABLE_GUID;
     40   1.1  jmcneill 
     41   1.1  jmcneill #define	FDT_MEMORY_NODE_PATH	"/memory"
     42   1.1  jmcneill #define	FDT_MEMORY_NODE_NAME	"memory"
     43   1.1  jmcneill #define	FDT_CHOSEN_NODE_PATH	"/chosen"
     44   1.3  jmcneill #define	FDT_CHOSEN_NODE_NAME	"chosen"
     45   1.1  jmcneill 
     46   1.1  jmcneill #define	FDT_MEMORY_USABLE(_md)	\
     47   1.1  jmcneill 	((_md)->Type == EfiLoaderCode || (_md)->Type == EfiLoaderData || \
     48   1.1  jmcneill 	 (_md)->Type == EfiBootServicesCode || (_md)->Type == EfiBootServicesData || \
     49   1.1  jmcneill 	 (_md)->Type == EfiConventionalMemory)
     50   1.1  jmcneill 
     51  1.21     skrll #ifdef _LP64
     52  1.21     skrll #define PRIdUINTN "ld"
     53  1.21     skrll #define PRIxUINTN "lx"
     54  1.21     skrll #else
     55  1.21     skrll #define PRIdUINTN "d"
     56  1.21     skrll #define PRIxUINTN "x"
     57  1.21     skrll #endif
     58   1.1  jmcneill static void *fdt_data = NULL;
     59  1.25  jmcneill static size_t fdt_data_size = 512*1024;
     60   1.1  jmcneill 
     61   1.1  jmcneill int
     62   1.1  jmcneill efi_fdt_probe(void)
     63   1.1  jmcneill {
     64   1.1  jmcneill 	EFI_STATUS status;
     65   1.1  jmcneill 
     66   1.1  jmcneill 	status = LibGetSystemConfigurationTable(&FdtTableGuid, &fdt_data);
     67   1.1  jmcneill 	if (EFI_ERROR(status))
     68   1.1  jmcneill 		return EIO;
     69   1.1  jmcneill 
     70   1.1  jmcneill 	if (fdt_check_header(fdt_data) != 0) {
     71   1.1  jmcneill 		fdt_data = NULL;
     72   1.1  jmcneill 		return EINVAL;
     73   1.1  jmcneill 	}
     74   1.1  jmcneill 
     75   1.1  jmcneill 	return 0;
     76   1.1  jmcneill }
     77   1.1  jmcneill 
     78   1.9  jmcneill int
     79   1.9  jmcneill efi_fdt_set_data(void *data)
     80   1.9  jmcneill {
     81  1.25  jmcneill 	int err;
     82  1.25  jmcneill 
     83   1.9  jmcneill 	if (fdt_check_header(data) != 0)
     84   1.9  jmcneill 		return EINVAL;
     85   1.9  jmcneill 
     86  1.25  jmcneill 	fdt_data = alloc(fdt_data_size);
     87  1.25  jmcneill 	if (fdt_data == NULL)
     88  1.25  jmcneill 		return ENOMEM;
     89  1.25  jmcneill 	memset(fdt_data, 0, fdt_data_size);
     90  1.25  jmcneill 
     91  1.25  jmcneill 	err = fdt_open_into(data, fdt_data, fdt_data_size);
     92  1.25  jmcneill 	if (err != 0) {
     93  1.25  jmcneill 		dealloc(fdt_data, fdt_data_size);
     94  1.25  jmcneill 		fdt_data = NULL;
     95  1.25  jmcneill 		return ENXIO;
     96  1.25  jmcneill 	}
     97  1.25  jmcneill 
     98   1.9  jmcneill 	return 0;
     99   1.9  jmcneill }
    100   1.9  jmcneill 
    101   1.1  jmcneill void *
    102   1.1  jmcneill efi_fdt_data(void)
    103   1.1  jmcneill {
    104   1.1  jmcneill 	return fdt_data;
    105   1.1  jmcneill }
    106   1.1  jmcneill 
    107   1.1  jmcneill int
    108   1.1  jmcneill efi_fdt_size(void)
    109   1.1  jmcneill {
    110   1.1  jmcneill 	return fdt_data == NULL ? 0 : fdt_totalsize(fdt_data);
    111   1.1  jmcneill }
    112   1.1  jmcneill 
    113  1.15   thorpej bool
    114  1.15   thorpej efi_fdt_overlay_is_compatible(void *dtbo)
    115  1.15   thorpej {
    116  1.15   thorpej 	const int system_root = fdt_path_offset(fdt_data, "/");
    117  1.15   thorpej 	const int overlay_root = fdt_path_offset(dtbo, "/");
    118  1.15   thorpej 
    119  1.15   thorpej 	if (system_root < 0 || overlay_root < 0)
    120  1.15   thorpej 		return false;
    121  1.15   thorpej 
    122  1.15   thorpej 	const int system_ncompat = fdt_stringlist_count(fdt_data, system_root,
    123  1.15   thorpej 	    "compatible");
    124  1.15   thorpej 	const int overlay_ncompat = fdt_stringlist_count(dtbo, overlay_root,
    125  1.15   thorpej 	    "compatible");
    126  1.15   thorpej 
    127  1.15   thorpej 	if (system_ncompat <= 0 || overlay_ncompat <= 0)
    128  1.15   thorpej 		return false;
    129  1.15   thorpej 
    130  1.15   thorpej 	const char *system_compatible, *overlay_compatible;
    131  1.15   thorpej 	int si, oi;
    132  1.15   thorpej 
    133  1.15   thorpej 	for (si = 0; si < system_ncompat; si++) {
    134  1.15   thorpej 		system_compatible = fdt_stringlist_get(fdt_data,
    135  1.15   thorpej 		    system_root, "compatible", si, NULL);
    136  1.15   thorpej 		if (system_compatible == NULL)
    137  1.15   thorpej 			continue;
    138  1.15   thorpej 		for (oi = 0; oi < overlay_ncompat; oi++) {
    139  1.15   thorpej 			overlay_compatible = fdt_stringlist_get(dtbo,
    140  1.15   thorpej 			    overlay_root, "compatible", oi, NULL);
    141  1.15   thorpej 			if (overlay_compatible == NULL)
    142  1.15   thorpej 				continue;
    143  1.15   thorpej 			if (strcmp(system_compatible, overlay_compatible) == 0)
    144  1.15   thorpej 				return true;
    145  1.15   thorpej 		}
    146  1.15   thorpej 	}
    147  1.15   thorpej 
    148  1.15   thorpej 	return false;
    149  1.15   thorpej }
    150  1.15   thorpej 
    151  1.15   thorpej int
    152  1.15   thorpej efi_fdt_overlay_apply(void *dtbo, int *fdterr)
    153  1.15   thorpej {
    154  1.15   thorpej 	int err = fdt_overlay_apply(fdt_data, dtbo);
    155  1.15   thorpej 	if (fdterr)
    156  1.15   thorpej 		*fdterr = err;
    157  1.15   thorpej 	return err == 0 ? 0 : EIO;
    158  1.15   thorpej }
    159  1.15   thorpej 
    160   1.1  jmcneill void
    161   1.8  jmcneill efi_fdt_init(u_long addr, u_long len)
    162   1.8  jmcneill {
    163   1.8  jmcneill 	int error;
    164   1.8  jmcneill 
    165   1.8  jmcneill 	error = fdt_open_into(fdt_data, (void *)addr, len);
    166   1.8  jmcneill 	if (error < 0)
    167   1.8  jmcneill 		panic("fdt_open_into failed: %d", error);
    168   1.8  jmcneill 
    169   1.8  jmcneill 	fdt_data = (void *)addr;
    170   1.8  jmcneill }
    171   1.8  jmcneill 
    172   1.8  jmcneill void
    173   1.8  jmcneill efi_fdt_fini(void)
    174   1.8  jmcneill {
    175   1.8  jmcneill 	int error;
    176   1.8  jmcneill 
    177   1.8  jmcneill 	error = fdt_pack(fdt_data);
    178   1.8  jmcneill 	if (error < 0)
    179   1.8  jmcneill 		panic("fdt_pack failed: %d", error);
    180   1.8  jmcneill }
    181   1.8  jmcneill 
    182   1.8  jmcneill void
    183   1.7  jmcneill efi_fdt_show(void)
    184   1.7  jmcneill {
    185   1.7  jmcneill 	const char *model, *compat;
    186   1.7  jmcneill 	int n, ncompat;
    187   1.7  jmcneill 
    188   1.7  jmcneill 	if (fdt_data == NULL)
    189   1.7  jmcneill 		return;
    190   1.7  jmcneill 
    191   1.7  jmcneill 	model = fdt_getprop(fdt_data, fdt_path_offset(fdt_data, "/"), "model", NULL);
    192   1.7  jmcneill 	if (model)
    193   1.7  jmcneill 		printf("FDT: %s [", model);
    194   1.7  jmcneill 	ncompat = fdt_stringlist_count(fdt_data, fdt_path_offset(fdt_data, "/"), "compatible");
    195   1.7  jmcneill 	for (n = 0; n < ncompat; n++) {
    196   1.7  jmcneill 		compat = fdt_stringlist_get(fdt_data, fdt_path_offset(fdt_data, "/"),
    197   1.7  jmcneill 		    "compatible", n, NULL);
    198   1.7  jmcneill 		printf("%s%s", n == 0 ? "" : ", ", compat);
    199   1.7  jmcneill 	}
    200   1.7  jmcneill 	printf("]\n");
    201   1.7  jmcneill }
    202   1.7  jmcneill 
    203  1.23  riastrad static int
    204  1.23  riastrad efi_fdt_chosen(void)
    205  1.23  riastrad {
    206  1.23  riastrad 	int chosen;
    207  1.23  riastrad 
    208  1.23  riastrad 	chosen = fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH);
    209  1.23  riastrad 	if (chosen < 0)
    210  1.23  riastrad 		chosen = fdt_add_subnode(fdt_data,
    211  1.23  riastrad 		    fdt_path_offset(fdt_data, "/"),
    212  1.23  riastrad 		    FDT_CHOSEN_NODE_NAME);
    213  1.23  riastrad 	if (chosen < 0)
    214  1.23  riastrad 		panic("FDT: Failed to create " FDT_CHOSEN_NODE_PATH " node");
    215  1.23  riastrad 
    216  1.23  riastrad 	return chosen;
    217  1.23  riastrad }
    218  1.23  riastrad 
    219   1.7  jmcneill void
    220  1.25  jmcneill efi_fdt_system_table(void)
    221  1.25  jmcneill {
    222  1.25  jmcneill #ifdef EFIBOOT_RUNTIME_ADDRESS
    223  1.25  jmcneill 	int chosen;
    224  1.25  jmcneill 
    225  1.25  jmcneill 	chosen = efi_fdt_chosen();
    226  1.25  jmcneill 
    227  1.25  jmcneill 	fdt_setprop_u64(fdt_data, chosen, "netbsd,uefi-system-table", (uint64_t)(uintptr_t)ST);
    228  1.25  jmcneill #endif
    229  1.25  jmcneill }
    230  1.25  jmcneill 
    231  1.25  jmcneill void
    232   1.1  jmcneill efi_fdt_memory_map(void)
    233   1.1  jmcneill {
    234   1.1  jmcneill 	UINTN nentries = 0, mapkey, descsize;
    235   1.2  jmcneill 	EFI_MEMORY_DESCRIPTOR *md, *memmap;
    236   1.1  jmcneill 	UINT32 descver;
    237   1.2  jmcneill 	UINT64 phys_start, phys_size;
    238  1.16  jmcneill 	int n, memory, chosen;
    239   1.1  jmcneill 
    240   1.1  jmcneill 	memory = fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH);
    241   1.1  jmcneill 	if (memory < 0)
    242   1.1  jmcneill 		memory = fdt_add_subnode(fdt_data, fdt_path_offset(fdt_data, "/"), FDT_MEMORY_NODE_NAME);
    243   1.1  jmcneill 	if (memory < 0)
    244   1.1  jmcneill 		panic("FDT: Failed to create " FDT_MEMORY_NODE_PATH " node");
    245   1.1  jmcneill 
    246  1.23  riastrad 	chosen = efi_fdt_chosen();
    247  1.16  jmcneill 
    248   1.1  jmcneill 	fdt_delprop(fdt_data, memory, "reg");
    249   1.1  jmcneill 
    250   1.1  jmcneill 	const int address_cells = fdt_address_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
    251   1.1  jmcneill 	const int size_cells = fdt_size_cells(fdt_data, fdt_path_offset(fdt_data, "/"));
    252   1.1  jmcneill 
    253   1.2  jmcneill 	memmap = LibMemoryMap(&nentries, &mapkey, &descsize, &descver);
    254   1.2  jmcneill 	for (n = 0, md = memmap; n < nentries; n++, md = NextMemoryDescriptor(md, descsize)) {
    255  1.18  jmcneill 		fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Type);
    256  1.18  jmcneill 		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->PhysicalStart);
    257  1.18  jmcneill 		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->NumberOfPages);
    258  1.18  jmcneill 		fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_CHOSEN_NODE_PATH), "netbsd,uefi-memmap", md->Attribute);
    259  1.18  jmcneill 
    260  1.11  jmcneill 		if ((md->Attribute & EFI_MEMORY_RUNTIME) != 0)
    261  1.11  jmcneill 			continue;
    262  1.16  jmcneill 
    263   1.1  jmcneill 		if ((md->Attribute & EFI_MEMORY_WB) == 0)
    264   1.1  jmcneill 			continue;
    265   1.1  jmcneill 		if (!FDT_MEMORY_USABLE(md))
    266   1.1  jmcneill 			continue;
    267   1.2  jmcneill 		if ((address_cells == 1 || size_cells == 1) && md->PhysicalStart + (md->NumberOfPages * EFI_PAGE_SIZE) > 0xffffffff)
    268   1.2  jmcneill 			continue;
    269   1.2  jmcneill 		if (md->NumberOfPages <= 1)
    270   1.2  jmcneill 			continue;
    271   1.2  jmcneill 
    272   1.2  jmcneill 		phys_start = md->PhysicalStart;
    273   1.2  jmcneill 		phys_size = md->NumberOfPages * EFI_PAGE_SIZE;
    274   1.2  jmcneill 
    275   1.2  jmcneill 		if (phys_start & EFI_PAGE_MASK) {
    276   1.2  jmcneill 			/* UEFI spec says these should be 4KB aligned, but U-Boot doesn't always.. */
    277   1.2  jmcneill 			phys_start = (phys_start + EFI_PAGE_SIZE) & ~EFI_PAGE_MASK;
    278   1.2  jmcneill 			phys_size -= (EFI_PAGE_SIZE * 2);
    279   1.2  jmcneill 			if (phys_size == 0)
    280   1.2  jmcneill 				continue;
    281   1.2  jmcneill 		}
    282   1.1  jmcneill 
    283   1.1  jmcneill 		if (address_cells == 1)
    284   1.1  jmcneill 			fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
    285   1.2  jmcneill 			    "reg", (uint32_t)phys_start);
    286   1.1  jmcneill 		else
    287   1.1  jmcneill 			fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
    288   1.2  jmcneill 			    "reg", phys_start);
    289   1.1  jmcneill 
    290   1.1  jmcneill 		if (size_cells == 1)
    291   1.1  jmcneill 			fdt_appendprop_u32(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
    292   1.2  jmcneill 			    "reg", (uint32_t)phys_size);
    293   1.1  jmcneill 		else
    294   1.1  jmcneill 			fdt_appendprop_u64(fdt_data, fdt_path_offset(fdt_data, FDT_MEMORY_NODE_PATH),
    295   1.2  jmcneill 			    "reg", phys_size);
    296   1.1  jmcneill 	}
    297   1.1  jmcneill }
    298   1.1  jmcneill 
    299   1.1  jmcneill void
    300  1.16  jmcneill efi_fdt_gop(void)
    301  1.16  jmcneill {
    302  1.16  jmcneill 	EFI_STATUS status;
    303  1.16  jmcneill 	EFI_GRAPHICS_OUTPUT_PROTOCOL *gop;
    304  1.16  jmcneill 	EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE *mode;
    305  1.16  jmcneill 	EFI_HANDLE *gop_handle;
    306  1.16  jmcneill 	UINTN ngop_handle, n;
    307  1.16  jmcneill 	char buf[48];
    308  1.25  jmcneill 	int fb, chosen;
    309  1.16  jmcneill 
    310  1.16  jmcneill 	status = LibLocateHandle(ByProtocol, &GraphicsOutputProtocol, NULL, &ngop_handle, &gop_handle);
    311  1.16  jmcneill 	if (EFI_ERROR(status) || ngop_handle == 0)
    312  1.16  jmcneill 		return;
    313  1.16  jmcneill 
    314  1.16  jmcneill 	for (n = 0; n < ngop_handle; n++) {
    315  1.16  jmcneill 		status = uefi_call_wrapper(BS->HandleProtocol, 3, gop_handle[n], &GraphicsOutputProtocol, (void **)&gop);
    316  1.16  jmcneill 		if (EFI_ERROR(status))
    317  1.16  jmcneill 			continue;
    318  1.16  jmcneill 
    319  1.16  jmcneill 		mode = gop->Mode;
    320  1.16  jmcneill 		if (mode == NULL)
    321  1.16  jmcneill 			continue;
    322  1.16  jmcneill 
    323  1.16  jmcneill #ifdef EFIBOOT_DEBUG
    324  1.21     skrll 		printf("GOP: FB @ 0x%" PRIx64 " size 0x%" PRIxUINTN "\n", mode->FrameBufferBase, mode->FrameBufferSize);
    325  1.16  jmcneill 		printf("GOP: Version %d\n", mode->Info->Version);
    326  1.16  jmcneill 		printf("GOP: HRes %d VRes %d\n", mode->Info->HorizontalResolution, mode->Info->VerticalResolution);
    327  1.16  jmcneill 		printf("GOP: PixelFormat %d\n", mode->Info->PixelFormat);
    328  1.16  jmcneill 		printf("GOP: PixelBitmask R 0x%x G 0x%x B 0x%x Res 0x%x\n",
    329  1.16  jmcneill 		    mode->Info->PixelInformation.RedMask,
    330  1.16  jmcneill 		    mode->Info->PixelInformation.GreenMask,
    331  1.16  jmcneill 		    mode->Info->PixelInformation.BlueMask,
    332  1.16  jmcneill 		    mode->Info->PixelInformation.ReservedMask);
    333  1.16  jmcneill 		printf("GOP: Pixels per scanline %d\n", mode->Info->PixelsPerScanLine);
    334  1.16  jmcneill #endif
    335  1.16  jmcneill 
    336  1.16  jmcneill 		if (mode->Info->PixelFormat == PixelBltOnly) {
    337  1.16  jmcneill 			printf("GOP: PixelBltOnly pixel format not supported\n");
    338  1.16  jmcneill 			continue;
    339  1.16  jmcneill 		}
    340  1.16  jmcneill 
    341  1.25  jmcneill 		chosen = efi_fdt_chosen();
    342  1.25  jmcneill 		fdt_setprop_u32(fdt_data, chosen, "#address-cells", 2);
    343  1.25  jmcneill 		fdt_setprop_u32(fdt_data, chosen, "#size-cells", 2);
    344  1.25  jmcneill 		fdt_setprop_empty(fdt_data, chosen, "ranges");
    345  1.19  jmcneill 
    346  1.27  jmcneill 		snprintf(buf, sizeof(buf), "framebuffer@%" PRIx64, mode->FrameBufferBase);
    347  1.25  jmcneill 		fb = fdt_add_subnode(fdt_data, chosen, buf);
    348  1.27  jmcneill 		if (fb < 0) {
    349  1.27  jmcneill 			/* Framebuffer node already exists. No need to create a new one! */
    350  1.27  jmcneill 			return;
    351  1.27  jmcneill 		}
    352  1.16  jmcneill 
    353  1.16  jmcneill 		fdt_appendprop_string(fdt_data, fb, "compatible", "simple-framebuffer");
    354  1.16  jmcneill 		fdt_appendprop_string(fdt_data, fb, "status", "okay");
    355  1.16  jmcneill 		fdt_appendprop_u64(fdt_data, fb, "reg", mode->FrameBufferBase);
    356  1.16  jmcneill 		fdt_appendprop_u64(fdt_data, fb, "reg", mode->FrameBufferSize);
    357  1.16  jmcneill 		fdt_appendprop_u32(fdt_data, fb, "width", mode->Info->HorizontalResolution);
    358  1.16  jmcneill 		fdt_appendprop_u32(fdt_data, fb, "height", mode->Info->VerticalResolution);
    359  1.16  jmcneill 		fdt_appendprop_u32(fdt_data, fb, "stride", mode->Info->PixelsPerScanLine * 4);	/* XXX */
    360  1.16  jmcneill 		fdt_appendprop_string(fdt_data, fb, "format", "a8b8g8r8");
    361  1.16  jmcneill 
    362  1.25  jmcneill 		/*
    363  1.25  jmcneill 		 * In ACPI mode, use GOP as console.
    364  1.25  jmcneill 		 */
    365  1.25  jmcneill 		if (efi_acpi_available()) {
    366  1.25  jmcneill 			snprintf(buf, sizeof(buf), "/chosen/framebuffer@%" PRIx64, mode->FrameBufferBase);
    367  1.25  jmcneill 			fdt_setprop_string(fdt_data, chosen, "stdout-path", buf);
    368  1.25  jmcneill 		}
    369  1.16  jmcneill 
    370  1.16  jmcneill 		return;
    371  1.16  jmcneill 	}
    372  1.16  jmcneill }
    373  1.16  jmcneill 
    374  1.16  jmcneill void
    375   1.1  jmcneill efi_fdt_bootargs(const char *bootargs)
    376   1.1  jmcneill {
    377   1.3  jmcneill 	struct efi_block_part *bpart = efi_block_boot_part();
    378  1.14  jmcneill 	uint8_t macaddr[6];
    379   1.3  jmcneill 	int chosen;
    380   1.3  jmcneill 
    381  1.23  riastrad 	chosen = efi_fdt_chosen();
    382   1.3  jmcneill 
    383   1.3  jmcneill 	if (*bootargs)
    384   1.3  jmcneill 		fdt_setprop_string(fdt_data, chosen, "bootargs", bootargs);
    385   1.3  jmcneill 
    386   1.3  jmcneill 	if (bpart) {
    387   1.3  jmcneill 		switch (bpart->type) {
    388   1.3  jmcneill 		case EFI_BLOCK_PART_DISKLABEL:
    389   1.3  jmcneill 			fdt_setprop(fdt_data, chosen, "netbsd,mbr",
    390   1.3  jmcneill 			    bpart->hash, sizeof(bpart->hash));
    391   1.3  jmcneill 			fdt_setprop_u32(fdt_data, chosen, "netbsd,partition",
    392   1.3  jmcneill 			    bpart->index);
    393   1.3  jmcneill 			break;
    394  1.12  jmcneill 		case EFI_BLOCK_PART_GPT:
    395  1.12  jmcneill 			if (bpart->gpt.ent.ent_name[0] == 0x0000) {
    396  1.12  jmcneill 				fdt_setprop(fdt_data, chosen, "netbsd,gpt-guid",
    397  1.12  jmcneill 				    bpart->hash, sizeof(bpart->hash));
    398  1.12  jmcneill 			} else {
    399  1.12  jmcneill 				char *label = NULL;
    400  1.12  jmcneill 				int rv = ucs2_to_utf8(bpart->gpt.ent.ent_name, &label);
    401  1.12  jmcneill 				if (rv == 0) {
    402  1.12  jmcneill 					fdt_setprop_string(fdt_data, chosen, "netbsd,gpt-label", label);
    403  1.12  jmcneill 					FreePool(label);
    404  1.12  jmcneill 				}
    405  1.12  jmcneill 			}
    406  1.12  jmcneill 			break;
    407   1.3  jmcneill 		default:
    408   1.3  jmcneill 			break;
    409   1.3  jmcneill 		}
    410  1.14  jmcneill 	} else if (efi_net_get_booted_macaddr(macaddr) == 0) {
    411  1.14  jmcneill 		fdt_setprop(fdt_data, chosen, "netbsd,booted-mac-address", macaddr, sizeof(macaddr));
    412   1.3  jmcneill 	}
    413   1.1  jmcneill }
    414   1.8  jmcneill 
    415   1.8  jmcneill void
    416   1.8  jmcneill efi_fdt_initrd(u_long initrd_addr, u_long initrd_size)
    417   1.8  jmcneill {
    418   1.8  jmcneill 	int chosen;
    419   1.8  jmcneill 
    420   1.8  jmcneill 	if (initrd_size == 0)
    421   1.8  jmcneill 		return;
    422   1.8  jmcneill 
    423  1.23  riastrad 	chosen = efi_fdt_chosen();
    424   1.8  jmcneill 	fdt_setprop_u64(fdt_data, chosen, "linux,initrd-start", initrd_addr);
    425   1.8  jmcneill 	fdt_setprop_u64(fdt_data, chosen, "linux,initrd-end", initrd_addr + initrd_size);
    426   1.8  jmcneill }
    427  1.20  riastrad 
    428  1.22  riastrad /* pass in the NetBSD on-disk random seed */
    429  1.20  riastrad void
    430  1.20  riastrad efi_fdt_rndseed(u_long rndseed_addr, u_long rndseed_size)
    431  1.20  riastrad {
    432  1.20  riastrad 	int chosen;
    433  1.20  riastrad 
    434  1.20  riastrad 	if (rndseed_size == 0)
    435  1.20  riastrad 		return;
    436  1.20  riastrad 
    437  1.23  riastrad 	chosen = efi_fdt_chosen();
    438  1.20  riastrad 	fdt_setprop_u64(fdt_data, chosen, "netbsd,rndseed-start",
    439  1.20  riastrad 	    rndseed_addr);
    440  1.20  riastrad 	fdt_setprop_u64(fdt_data, chosen, "netbsd,rndseed-end",
    441  1.20  riastrad 	    rndseed_addr + rndseed_size);
    442  1.20  riastrad }
    443  1.22  riastrad 
    444  1.22  riastrad /* pass in output from the EFI firmware's RNG from some unknown source */
    445  1.22  riastrad void
    446  1.22  riastrad efi_fdt_efirng(u_long efirng_addr, u_long efirng_size)
    447  1.22  riastrad {
    448  1.22  riastrad 	int chosen;
    449  1.22  riastrad 
    450  1.22  riastrad 	if (efirng_size == 0)
    451  1.22  riastrad 		return;
    452  1.22  riastrad 
    453  1.23  riastrad 	chosen = efi_fdt_chosen();
    454  1.22  riastrad 	fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-start",
    455  1.22  riastrad 	    efirng_addr);
    456  1.22  riastrad 	fdt_setprop_u64(fdt_data, chosen, "netbsd,efirng-end",
    457  1.22  riastrad 	    efirng_addr + efirng_size);
    458  1.22  riastrad }
    459  1.24  jmcneill 
    460  1.24  jmcneill /* pass in module information */
    461  1.24  jmcneill void
    462  1.24  jmcneill efi_fdt_module(const char *module_name, u_long module_addr, u_long module_size)
    463  1.24  jmcneill {
    464  1.24  jmcneill 	int chosen;
    465  1.24  jmcneill 
    466  1.24  jmcneill 	if (module_size == 0)
    467  1.24  jmcneill 		return;
    468  1.24  jmcneill 
    469  1.24  jmcneill 	chosen = efi_fdt_chosen();
    470  1.24  jmcneill 	fdt_appendprop_string(fdt_data, chosen, "netbsd,module-names", module_name);
    471  1.24  jmcneill 	fdt_appendprop_u64(fdt_data, chosen, "netbsd,modules", module_addr);
    472  1.24  jmcneill 	fdt_appendprop_u64(fdt_data, chosen, "netbsd,modules", module_size);
    473  1.24  jmcneill }
    474