From owner-svn-src-projects@FreeBSD.ORG Mon Feb 4 23:12:38 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 66EA2C65; Mon, 4 Feb 2013 23:12:38 +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 41D4A839; Mon, 4 Feb 2013 23:12:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r14NCcvC028095; Mon, 4 Feb 2013 23:12:38 GMT (envelope-from benno@svn.freebsd.org) Received: (from benno@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r14NCbO6028092; Mon, 4 Feb 2013 23:12:37 GMT (envelope-from benno@svn.freebsd.org) Message-Id: <201302042312.r14NCbO6028092@svn.freebsd.org> From: Benno Rice Date: Mon, 4 Feb 2013 23:12:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r246335 - in projects/uefi/sys: amd64/include boot/i386/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: Mon, 04 Feb 2013 23:12:38 -0000 Author: benno Date: Mon Feb 4 23:12:37 2013 New Revision: 246335 URL: http://svnweb.freebsd.org/changeset/base/246335 Log: Grab the EFI memory map and store it as module metadata on the kernel. This is the same approach used to provide the BIOS SMAP to the kernel. There's a lot of functional overlap between the bootinfo64.c and efimd.c files that should be addressed later. Sponsored by: FreeBSD Foundation Modified: projects/uefi/sys/amd64/include/metadata.h projects/uefi/sys/boot/i386/efi/bootinfo64.c projects/uefi/sys/boot/i386/efi/efimd.c Modified: projects/uefi/sys/amd64/include/metadata.h ============================================================================== --- projects/uefi/sys/amd64/include/metadata.h Mon Feb 4 22:15:36 2013 (r246334) +++ projects/uefi/sys/amd64/include/metadata.h Mon Feb 4 23:12:37 2013 (r246335) @@ -31,5 +31,6 @@ #define MODINFOMD_SMAP 0x1001 #define MODINFOMD_SMAP_XATTR 0x1002 +#define MODINFOMD_EFI 0x1003 #endif /* !_MACHINE_METADATA_H_ */ Modified: projects/uefi/sys/boot/i386/efi/bootinfo64.c ============================================================================== --- projects/uefi/sys/boot/i386/efi/bootinfo64.c Mon Feb 4 22:15:36 2013 (r246334) +++ projects/uefi/sys/boot/i386/efi/bootinfo64.c Mon Feb 4 23:12:37 2013 (r246335) @@ -37,7 +37,6 @@ __FBSDID("$FreeBSD$"); #include #include "bootstrap.h" #include "libi386.h" -#include "btxv86.h" /* * Copy module-related data into the load area, where it can be @@ -126,6 +125,8 @@ bi_copymodules64(vm_offset_t addr) return(addr); } +extern int ldr_bootinfo(struct preloaded_file *kfp); + /* * Load the information expected by an amd64 kernel. * @@ -190,7 +191,7 @@ bi_load64(char *args, vm_offset_t *modul file_addmetadata(kfp, MODINFOMD_HOWTO, sizeof howto, &howto); file_addmetadata(kfp, MODINFOMD_ENVP, sizeof envp, &envp); file_addmetadata(kfp, MODINFOMD_KERNEND, sizeof kernend, &kernend); - /*bios_addsmapdata(kfp);*/ + ldr_bootinfo(kfp); /* Figure out the size and location of the metadata */ *modulep = addr; Modified: projects/uefi/sys/boot/i386/efi/efimd.c ============================================================================== --- projects/uefi/sys/boot/i386/efi/efimd.c Mon Feb 4 22:15:36 2013 (r246334) +++ projects/uefi/sys/boot/i386/efi/efimd.c Mon Feb 4 23:12:37 2013 (r246335) @@ -32,19 +32,11 @@ __FBSDID("$FreeBSD$"); #include #include -#include #include +#include +#include -#define EFI_INTEL_FPSWA \ - {0xc41b6531,0x97b9,0x11d3,{0x9a,0x29,0x00,0x90,0x27,0x3f,0xc1,0x4d}} - -static EFI_GUID fpswa_guid = EFI_INTEL_FPSWA; - -/* DIG64 Headless Console & Debug Port Table. */ -#define HCDP_TABLE_GUID \ - {0xf951938d,0x620b,0x42ef,{0x82,0x79,0xa8,0x4b,0x79,0x61,0x78,0x98}} - -static EFI_GUID hcdp_guid = HCDP_TABLE_GUID; +#include "bootstrap.h" static UINTN mapkey; @@ -56,27 +48,17 @@ ldr_alloc(vm_offset_t va) } int -ldr_bootinfo(struct bootinfo *bi, uint64_t *bi_addr) +ldr_bootinfo(struct preloaded_file *kfp) { - VOID *fpswa; EFI_MEMORY_DESCRIPTOR *mm; EFI_PHYSICAL_ADDRESS addr; - EFI_HANDLE handle; EFI_STATUS status; - size_t bisz; + size_t efisz; UINTN mmsz, pages, sz; UINT32 mmver; + struct efi_header *efihdr; - bi->bi_systab = (uint64_t)ST; - bi->bi_hcdp = (uint64_t)efi_get_table(&hcdp_guid); - - sz = sizeof(EFI_HANDLE); - status = BS->LocateHandle(ByProtocol, &fpswa_guid, 0, &sz, &handle); - if (status == 0) - status = BS->HandleProtocol(handle, &fpswa_guid, &fpswa); - bi->bi_fpswa = (status == 0) ? (uint64_t)fpswa : 0; - - bisz = (sizeof(struct bootinfo) + 0x0f) & ~0x0f; + efisz = (sizeof(struct efi_header) + 0xf) & ~0xf; /* * Allocate enough pages to hold the bootinfo block and the memory @@ -90,8 +72,8 @@ ldr_bootinfo(struct bootinfo *bi, uint64 sz = 0; BS->GetMemoryMap(&sz, NULL, &mapkey, &mmsz, &mmver); sz += mmsz; - sz = (sz + 15) & ~15; - pages = EFI_SIZE_TO_PAGES(sz + bisz); + sz = (sz + 0xf) & ~0xf; + pages = EFI_SIZE_TO_PAGES(sz + efisz); status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages, &addr); if (EFI_ERROR(status)) { @@ -105,21 +87,22 @@ ldr_bootinfo(struct bootinfo *bi, uint64 * memory map on a 16-byte boundary (the bootinfo block is page * aligned). */ - *bi_addr = addr; - mm = (void *)(addr + bisz); - sz = (EFI_PAGE_SIZE * pages) - bisz; + efihdr = (struct efi_header *)addr; + mm = (void *)((uint8_t *)efihdr + efisz); + sz = (EFI_PAGE_SIZE * pages) - efisz; status = BS->GetMemoryMap(&sz, mm, &mapkey, &mmsz, &mmver); if (EFI_ERROR(status)) { printf("%s: GetMemoryMap() returned 0x%lx\n", __func__, (long)status); return (EINVAL); } - bi->bi_memmap = (uint64_t)mm; - bi->bi_memmap_size = sz; - bi->bi_memdesc_size = mmsz; - bi->bi_memdesc_version = mmver; - bcopy(bi, (void *)(*bi_addr), sizeof(*bi)); + efihdr->memory_size = sz; + efihdr->descriptor_size = mmsz; + efihdr->descriptor_version = mmver; + + file_addmetadata(kfp, MODINFOMD_EFI, efisz + sz, efihdr); + return (0); }