2 * Copyright (c) 2004 Marcel Moolenaar
3 * Copyright (c) 2001 Doug Rabson
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
33 #include <machine/bootinfo.h>
34 #include <machine/efi.h>
35 #include <machine/sal.h>
39 extern uint64_t ia64_call_efi_physical(uint64_t, uint64_t, uint64_t, uint64_t,
42 static struct efi_systbl *efi_systbl;
43 static struct efi_cfgtbl *efi_cfgtbl;
44 static struct efi_rt *efi_runtime;
46 static int efi_status2err[25] = {
48 ENOEXEC, /* EFI_LOAD_ERROR */
49 EINVAL, /* EFI_INVALID_PARAMETER */
50 ENOSYS, /* EFI_UNSUPPORTED */
51 EMSGSIZE, /* EFI_BAD_BUFFER_SIZE */
52 EOVERFLOW, /* EFI_BUFFER_TOO_SMALL */
53 EBUSY, /* EFI_NOT_READY */
54 EIO, /* EFI_DEVICE_ERROR */
55 EROFS, /* EFI_WRITE_PROTECTED */
56 EAGAIN, /* EFI_OUT_OF_RESOURCES */
57 EIO, /* EFI_VOLUME_CORRUPTED */
58 ENOSPC, /* EFI_VOLUME_FULL */
59 ENXIO, /* EFI_NO_MEDIA */
60 ESTALE, /* EFI_MEDIA_CHANGED */
61 ENOENT, /* EFI_NOT_FOUND */
62 EACCES, /* EFI_ACCESS_DENIED */
63 ETIMEDOUT, /* EFI_NO_RESPONSE */
64 EADDRNOTAVAIL, /* EFI_NO_MAPPING */
65 ETIMEDOUT, /* EFI_TIMEOUT */
66 EDOOFUS, /* EFI_NOT_STARTED */
67 EALREADY, /* EFI_ALREADY_STARTED */
68 ECANCELED, /* EFI_ABORTED */
69 EPROTO, /* EFI_ICMP_ERROR */
70 EPROTO, /* EFI_TFTP_ERROR */
71 EPROTO /* EFI_PROTOCOL_ERROR */
75 efi_status_to_errno(efi_status status)
80 code = status & 0x3ffffffffffffffful;
81 error = (code < 25) ? efi_status2err[code] : EDOOFUS;
91 * Collect the entry points for PAL and SAL. Be extra careful about NULL
92 * pointer values. We're running pre-console, so it's better to return
93 * error values than to cause panics, machine checks and other traps and
94 * faults. Keep this minimal...
97 efi_boot_minimal(uint64_t systbl)
104 efi_systbl = (struct efi_systbl *)IA64_PHYS_TO_RR7(systbl);
105 if (efi_systbl->st_hdr.th_sig != EFI_SYSTBL_SIG) {
109 efi_cfgtbl = (efi_systbl->st_cfgtbl == 0) ? NULL :
110 (struct efi_cfgtbl *)IA64_PHYS_TO_RR7(efi_systbl->st_cfgtbl);
111 if (efi_cfgtbl == NULL)
113 efi_runtime = (efi_systbl->st_rt == 0) ? NULL :
114 (struct efi_rt *)IA64_PHYS_TO_RR7(efi_systbl->st_rt);
115 if (efi_runtime == NULL)
119 * Relocate runtime memory segments for firmware.
123 if (md->md_attr & EFI_MD_ATTR_RT) {
124 if (md->md_attr & EFI_MD_ATTR_WB)
126 (void *)IA64_PHYS_TO_RR7(md->md_phys);
127 else if (md->md_attr & EFI_MD_ATTR_UC)
128 md->md_virt = pmap_mapdev(md->md_phys,
129 md->md_pages * EFI_PAGE_SIZE);
131 md = efi_md_next(md);
133 status = ia64_call_efi_physical((uint64_t)efi_runtime->rt_setvirtual,
134 bootinfo.bi_memmap_size, bootinfo.bi_memdesc_size,
135 bootinfo.bi_memdesc_version, bootinfo.bi_memmap, 0);
136 return ((status < 0) ? EFAULT : 0);
140 efi_get_table(struct uuid *uuid)
142 struct efi_cfgtbl *ct;
145 if (efi_cfgtbl == NULL)
147 count = efi_systbl->st_entries;
150 if (!bcmp(&ct->ct_uuid, uuid, sizeof(*uuid)))
151 return ((void *)IA64_PHYS_TO_RR7(ct->ct_data));
158 efi_get_time(struct efi_tm *tm)
161 efi_runtime->rt_gettime(tm, NULL);
168 if (bootinfo.bi_memmap == 0)
170 return ((struct efi_md *)IA64_PHYS_TO_RR7(bootinfo.bi_memmap));
174 efi_md_next(struct efi_md *md)
178 plim = IA64_PHYS_TO_RR7(bootinfo.bi_memmap + bootinfo.bi_memmap_size);
179 md = (struct efi_md *)((uintptr_t)md + bootinfo.bi_memdesc_size);
180 return ((md >= (struct efi_md *)plim) ? NULL : md);
184 efi_reset_system(void)
187 if (efi_runtime != NULL)
188 efi_runtime->rt_reset(EFI_RESET_WARM, 0, 0, NULL);
189 panic("%s: unable to reset the machine", __func__);
193 efi_set_time(struct efi_tm *tm)
196 return (efi_status_to_errno(efi_runtime->rt_settime(tm)));
200 efi_var_get(efi_char *name, struct uuid *vendor, uint32_t *attrib,
201 size_t *datasize, void *data)
205 status = efi_runtime->rt_getvar(name, vendor, attrib, datasize, data);
206 return (efi_status_to_errno(status));
210 efi_var_nextname(size_t *namesize, efi_char *name, struct uuid *vendor)
214 status = efi_runtime->rt_scanvar(namesize, name, vendor);
215 return (efi_status_to_errno(status));
219 efi_var_set(efi_char *name, struct uuid *vendor, uint32_t attrib,
220 size_t datasize, void *data)
224 status = efi_runtime->rt_setvar(name, vendor, attrib, datasize, data);
225 return (efi_status_to_errno(status));