From owner-svn-src-projects@FreeBSD.ORG Thu Feb 28 10:54:21 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id 1013E62A; Thu, 28 Feb 2013 10:54:21 +0000 (UTC) (envelope-from benno@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id E7B7F1AEA; Thu, 28 Feb 2013 10:54:20 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r1SAsKPA058439; Thu, 28 Feb 2013 10:54:20 GMT (envelope-from benno@svn.freebsd.org) Received: (from benno@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r1SAsKxU058435; Thu, 28 Feb 2013 10:54:20 GMT (envelope-from benno@svn.freebsd.org) Message-Id: <201302281054.r1SAsKxU058435@svn.freebsd.org> From: Benno Rice Date: Thu, 28 Feb 2013 10:54:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r247457 - projects/uefi/sys/boot/amd64/efi X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 28 Feb 2013 10:54:21 -0000 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 + * 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 #include #include +#include +#include #include #include @@ -40,8 +43,11 @@ __FBSDID("$FreeBSD$"); #include #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_ */