Date: Thu, 28 Feb 2013 10:54:20 +0000 (UTC) From: Benno Rice <benno@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r247457 - projects/uefi/sys/boot/amd64/efi Message-ID: <201302281054.r1SAsKxU058435@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: benno Date: Thu Feb 28 10:54:19 2013 New Revision: 247457 URL: http://svnweb.freebsd.org/changeset/base/247457 Log: Split efimd.c up and place parts into bootinfo.c and parts into elf64_freebsd.c Deleted: projects/uefi/sys/boot/amd64/efi/efimd.c Modified: projects/uefi/sys/boot/amd64/efi/Makefile projects/uefi/sys/boot/amd64/efi/bootinfo.c projects/uefi/sys/boot/amd64/efi/elf64_freebsd.c projects/uefi/sys/boot/amd64/efi/x86_efi.h Modified: projects/uefi/sys/boot/amd64/efi/Makefile ============================================================================== --- projects/uefi/sys/boot/amd64/efi/Makefile Thu Feb 28 10:50:09 2013 (r247456) +++ projects/uefi/sys/boot/amd64/efi/Makefile Thu Feb 28 10:54:19 2013 (r247457) @@ -11,7 +11,7 @@ INTERNALPROG= # architecture-specific loader code SRCS= main.c conf.c vers.c reloc.c elf64_freebsd.c -SRCS+= copy.c bootinfo.c autoload.c devicename.c efimd.c +SRCS+= copy.c bootinfo.c autoload.c devicename.c SRCS+= framebuffer.c amd64_tramp.S start.S CFLAGS+= -fPIC Modified: projects/uefi/sys/boot/amd64/efi/bootinfo.c ============================================================================== --- projects/uefi/sys/boot/amd64/efi/bootinfo.c Thu Feb 28 10:50:09 2013 (r247456) +++ projects/uefi/sys/boot/amd64/efi/bootinfo.c Thu Feb 28 10:54:19 2013 (r247457) @@ -1,5 +1,6 @@ /*- * Copyright (c) 1998 Michael Smith <msmith@freebsd.org> + * Copyright (c) 2004, 2006 Marcel Moolenaar * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,6 +34,8 @@ __FBSDID("$FreeBSD$"); #include <sys/reboot.h> #include <sys/linker.h> #include <machine/cpufunc.h> +#include <machine/efi.h> +#include <machine/metadata.h> #include <machine/psl.h> #include <machine/specialreg.h> @@ -40,8 +43,11 @@ __FBSDID("$FreeBSD$"); #include <efilib.h> #include "bootstrap.h" +#include "framebuffer.h" #include "x86_efi.h" +UINTN x86_efi_mapkey; + /* * Return a 'boothowto' value corresponding to the kernel arguments in * (kargs) and any relevant environment variables. @@ -229,7 +235,66 @@ bi_copymodules64(vm_offset_t addr) return(addr); } -extern int ldr_bootinfo(struct preloaded_file *kfp); +static int +ldr_bootinfo(struct preloaded_file *kfp) +{ + EFI_MEMORY_DESCRIPTOR *mm; + EFI_PHYSICAL_ADDRESS addr; + EFI_STATUS status; + size_t efisz; + UINTN mmsz, pages, sz; + UINT32 mmver; + struct efi_header *efihdr; + + efisz = (sizeof(struct efi_header) + 0xf) & ~0xf; + + /* + * Allocate enough pages to hold the bootinfo block and the memory + * map EFI will return to us. The memory map has an unknown size, + * so we have to determine that first. Note that the AllocatePages + * call can itself modify the memory map, so we have to take that + * into account as well. The changes to the memory map are caused + * by splitting a range of free memory into two (AFAICT), so that + * one is marked as being loader data. + */ + sz = 0; + BS->GetMemoryMap(&sz, NULL, &x86_efi_mapkey, &mmsz, &mmver); + sz += mmsz; + sz = (sz + 0xf) & ~0xf; + pages = EFI_SIZE_TO_PAGES(sz + efisz); + status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages, + &addr); + if (EFI_ERROR(status)) { + printf("%s: AllocatePages() returned 0x%lx\n", __func__, + (long)status); + return (ENOMEM); + } + + /* + * Read the memory map and stash it after bootinfo. Align the + * memory map on a 16-byte boundary (the bootinfo block is page + * aligned). + */ + efihdr = (struct efi_header *)addr; + mm = (void *)((uint8_t *)efihdr + efisz); + sz = (EFI_PAGE_SIZE * pages) - efisz; + status = BS->GetMemoryMap(&sz, mm, &x86_efi_mapkey, &mmsz, &mmver); + if (EFI_ERROR(status)) { + printf("%s: GetMemoryMap() returned 0x%lx\n", __func__, + (long)status); + return (EINVAL); + } + + efihdr->memory_size = sz; + efihdr->descriptor_size = mmsz; + efihdr->descriptor_version = mmver; + + efi_find_framebuffer(efihdr); + + file_addmetadata(kfp, MODINFOMD_EFI, efisz + sz, efihdr); + + return (0); +} /* * Load the information expected by an amd64 kernel. Modified: projects/uefi/sys/boot/amd64/efi/elf64_freebsd.c ============================================================================== --- projects/uefi/sys/boot/amd64/efi/elf64_freebsd.c Thu Feb 28 10:50:09 2013 (r247456) +++ projects/uefi/sys/boot/amd64/efi/elf64_freebsd.c Thu Feb 28 10:54:19 2013 (r247457) @@ -93,6 +93,7 @@ elf64_exec(struct preloaded_file *fp) ACPI_TABLE_RSDP *rsdp; char buf[24]; int revision; + EFI_STATUS status; rsdp = efi_get_table(&acpi20_guid); if (rsdp == NULL) { @@ -164,7 +165,12 @@ elf64_exec(struct preloaded_file *fp) printf("Start @ 0x%lx ...\n", ehdr->e_entry); - ldr_enter(fp->f_name); + status = BS->ExitBootServices(IH, x86_efi_mapkey); + if (EFI_ERROR(status)) { + printf("%s: ExitBootServices() returned 0x%lx\n", __func__, + (long)status); + return (EINVAL); + } dev_cleanup(); Modified: projects/uefi/sys/boot/amd64/efi/x86_efi.h ============================================================================== --- projects/uefi/sys/boot/amd64/efi/x86_efi.h Thu Feb 28 10:50:09 2013 (r247456) +++ projects/uefi/sys/boot/amd64/efi/x86_efi.h Thu Feb 28 10:54:19 2013 (r247457) @@ -44,4 +44,6 @@ ssize_t x86_efi_copyin(const void *src, ssize_t x86_efi_copyout(const vm_offset_t src, void *dest, const size_t len); ssize_t x86_efi_readin(const int fd, vm_offset_t dest, const size_t len); +extern UINTN x86_efi_mapkey; + #endif /* _X86_EFI_COPY_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201302281054.r1SAsKxU058435>