Deleted Added
full compact
efimd.c (139738) efimd.c (164010)
1/*-
1/*-
2 * Copyright (c) 2004 Marcel Moolenaar
2 * Copyright (c) 2004, 2006 Marcel Moolenaar
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/sys/boot/ia64/efi/efimd.c 139738 2005-01-05 22:16:58Z imp $");
28__FBSDID("$FreeBSD: head/sys/boot/ia64/efi/efimd.c 164010 2006-11-05 22:03:04Z marcel $");
29
29
30#include <stand.h>
31
30#include <efi.h>
31#include <efilib.h>
32
32#include <efi.h>
33#include <efilib.h>
34
33#include <machine/vmparam.h>
35#include <libia64.h>
34
36
35EFI_PHYSICAL_ADDRESS
36efimd_va2pa(EFI_VIRTUAL_ADDRESS va)
37#define EFI_INTEL_FPSWA \
38 {0xc41b6531,0x97b9,0x11d3,{0x9a,0x29,0x00,0x90,0x27,0x3f,0xc1,0x4d}}
39
40static EFI_GUID fpswa_guid = EFI_INTEL_FPSWA;
41
42/* DIG64 Headless Console & Debug Port Table. */
43#define HCDP_TABLE_GUID \
44 {0xf951938d,0x620b,0x42ef,{0x82,0x79,0xa8,0x4b,0x79,0x61,0x78,0x98}}
45
46static EFI_GUID hcdp_guid = HCDP_TABLE_GUID;
47
48static UINTN mapkey;
49
50uint64_t
51ldr_alloc(vm_offset_t va)
37{
38
52{
53
39 return (IA64_RR_MASK(va));
54 return (0);
40}
55}
56
57int
58ldr_bootinfo(struct bootinfo *bi, uint64_t *bi_addr)
59{
60 VOID *fpswa;
61 EFI_MEMORY_DESCRIPTOR *mm;
62 EFI_PHYSICAL_ADDRESS addr;
63 EFI_HANDLE handle;
64 EFI_STATUS status;
65 size_t bisz;
66 UINTN mmsz, pages, sz;
67 UINT32 mmver;
68
69 bi->bi_systab = (uint64_t)ST;
70 bi->bi_hcdp = (uint64_t)efi_get_table(&hcdp_guid);
71
72 sz = sizeof(EFI_HANDLE);
73 status = BS->LocateHandle(ByProtocol, &fpswa_guid, 0, &sz, &handle);
74 if (status == 0)
75 status = BS->HandleProtocol(handle, &fpswa_guid, &fpswa);
76 bi->bi_fpswa = (status == 0) ? (uint64_t)fpswa : 0;
77
78 bisz = (sizeof(struct bootinfo) + 0x0f) & ~0x0f;
79
80 /*
81 * Allocate enough pages to hold the bootinfo block and the memory
82 * map EFI will return to us. The memory map has an unknown size,
83 * so we have to determine that first. Note that the AllocatePages
84 * call can itself modify the memory map, so we have to take that
85 * into account as well. The changes to the memory map are caused
86 * by splitting a range of free memory into two (AFAICT), so that
87 * one is marked as being loader data.
88 */
89 sz = 0;
90 BS->GetMemoryMap(&sz, NULL, &mapkey, &mmsz, &mmver);
91 sz += mmsz;
92 sz = (sz + 15) & ~15;
93 pages = EFI_SIZE_TO_PAGES(sz + bisz);
94 status = BS->AllocatePages(AllocateAnyPages, EfiLoaderData, pages,
95 &addr);
96 if (EFI_ERROR(status)) {
97 printf("%s: AllocatePages() returned 0x%lx\n", __func__,
98 (long)status);
99 return (ENOMEM);
100 }
101
102 /*
103 * Read the memory map and stash it after bootinfo. Align the
104 * memory map on a 16-byte boundary (the bootinfo block is page
105 * aligned).
106 */
107 *bi_addr = addr;
108 mm = (void *)(addr + bisz);
109 sz = (EFI_PAGE_SIZE * pages) - bisz;
110 status = BS->GetMemoryMap(&sz, mm, &mapkey, &mmsz, &mmver);
111 if (EFI_ERROR(status)) {
112 printf("%s: GetMemoryMap() returned 0x%lx\n", __func__,
113 (long)status);
114 return (EINVAL);
115 }
116 bi->bi_memmap = (uint64_t)mm;
117 bi->bi_memmap_size = sz;
118 bi->bi_memdesc_size = mmsz;
119 bi->bi_memdesc_version = mmver;
120
121 bcopy(bi, (void *)(*bi_addr), sizeof(*bi));
122 return (0);
123}
124
125int
126ldr_enter(const char *kernel)
127{
128 EFI_STATUS status;
129
130 status = BS->ExitBootServices(IH, mapkey);
131 if (EFI_ERROR(status)) {
132 printf("%s: ExitBootServices() returned 0x%lx\n", __func__,
133 (long)status);
134 return (EINVAL);
135 }
136
137 return (0);
138}