2 * Copyright (c) 2003,2004 Marcel Moolenaar
5 * Redistribution and use in source and binary forms, with or without
6 * 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 ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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.
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
30 #include <sys/types.h>
31 #include <machine/bootinfo.h>
32 #include <machine/efi.h>
36 extern void acpi_root;
37 extern void sal_systab;
39 struct efi_cfgtbl efi_cfgtab[] = {
40 { EFI_TABLE_ACPI20, (intptr_t)&acpi_root },
41 { EFI_TABLE_SAL, (intptr_t)&sal_systab }
44 static efi_status GetTime(struct efi_tm *, struct efi_tmcap *);
45 static efi_status SetTime(struct efi_tm *);
46 static efi_status GetWakeupTime(uint8_t *, uint8_t *, struct efi_tm *);
47 static efi_status SetWakeupTime(uint8_t, struct efi_tm *);
49 static efi_status SetVirtualAddressMap(u_long, u_long, uint32_t,
51 static efi_status ConvertPointer(u_long, void **);
53 static efi_status GetVariable(efi_char *, struct uuid *, uint32_t *, u_long *,
55 static efi_status GetNextVariableName(u_long *, efi_char *, struct uuid *);
56 static efi_status SetVariable(efi_char *, struct uuid *, uint32_t, u_long,
59 static efi_status GetNextHighMonotonicCount(uint32_t *);
60 static efi_status ResetSystem(enum efi_reset, efi_status, u_long, efi_char *);
62 struct efi_rt efi_rttab = {
64 { 0, /* XXX Signature */
66 0, /* XXX HeaderSize */
76 /* Virtual memory services */
80 /* Variable services */
86 GetNextHighMonotonicCount,
90 struct efi_systbl efi_systab = {
94 0, /* XXX HeaderSize */
106 /* Services (runtime first). */
107 (intptr_t)&efi_rttab,
110 /* Configuration tables. */
111 sizeof(efi_cfgtab)/sizeof(struct efi_cfgtbl),
116 unsupported(const char *func)
118 printf("EFI: %s not supported\n", func);
119 return ((1UL << 63) + 3);
123 GetTime(struct efi_tm *time, struct efi_tmcap *caps)
127 ssc((uint64_t)comps, 0, 0, 0, SSC_GET_RTC);
128 time->tm_year = comps[0] + 1900;
129 time->tm_mon = comps[1] + 1;
130 time->tm_mday = comps[2];
131 time->tm_hour = comps[3];
132 time->tm_min = comps[4];
133 time->tm_sec = comps[5];
134 time->__pad1 = time->__pad2 = 0;
142 SetTime(struct efi_tm *time)
148 GetWakeupTime(uint8_t *enabled, uint8_t *pending, struct efi_tm *time)
150 return (unsupported(__func__));
154 SetWakeupTime(uint8_t enable, struct efi_tm *time)
156 return (unsupported(__func__));
160 Reloc(void *addr, uint64_t delta)
162 uint64_t **fpp = addr;
170 SetVirtualAddressMap(u_long mapsz, u_long descsz, uint32_t version,
171 struct efi_md *memmap)
175 delta = (uintptr_t)memmap->md_virt - memmap->md_phys;
176 Reloc(&efi_rttab.rt_gettime, delta);
177 Reloc(&efi_rttab.rt_settime, delta);
178 return (0); /* Hah... */
182 ConvertPointer(u_long debug, void **addr)
184 return (unsupported(__func__));
188 GetVariable(efi_char *name, struct uuid *vendor, uint32_t *attrs,
189 u_long *datasz, void *data)
191 return (unsupported(__func__));
195 GetNextVariableName(u_long *namesz, efi_char *name, struct uuid *vendor)
197 return (unsupported(__func__));
201 SetVariable(efi_char *name, struct uuid *vendor, uint32_t attrs, u_long datasz,
204 return (unsupported(__func__));
208 GetNextHighMonotonicCount(uint32_t *high)
210 static uint32_t counter = 0;
217 ResetSystem(enum efi_reset type, efi_status status, u_long datasz,
220 return (unsupported(__func__));
224 efi_stub_init(struct bootinfo *bi)
226 static struct efi_md memmap[4];
228 /* Describe the SKI memory map. */
229 bi->bi_memmap = (uintptr_t)(void *)memmap;
230 bi->bi_memmap_size = sizeof(memmap);
231 bi->bi_memdesc_size = sizeof(struct efi_md);
232 bi->bi_memdesc_version = 1;
234 memmap[0].md_type = EFI_MD_TYPE_PALCODE;
235 memmap[0].md_phys = 0x100000;
236 memmap[0].md_virt = NULL;
237 memmap[0].md_pages = (1L*1024*1024)>>12;
238 memmap[0].md_attr = EFI_MD_ATTR_WB | EFI_MD_ATTR_RT;
240 memmap[1].md_type = EFI_MD_TYPE_FREE;
241 memmap[1].md_phys = 4L*1024*1024;
242 memmap[1].md_virt = NULL;
243 memmap[1].md_pages = (128L*1024*1024)>>12;
244 memmap[1].md_attr = EFI_MD_ATTR_WB;
246 memmap[2].md_type = EFI_MD_TYPE_FREE;
247 memmap[2].md_phys = 4L*1024*1024*1024;
248 memmap[2].md_virt = NULL;
249 memmap[2].md_pages = (64L*1024*1024)>>12;
250 memmap[2].md_attr = EFI_MD_ATTR_WB;
252 memmap[3].md_type = EFI_MD_TYPE_IOPORT;
253 memmap[3].md_phys = 0xffffc000000;
254 memmap[3].md_virt = NULL;
255 memmap[3].md_pages = (64L*1024*1024)>>12;
256 memmap[3].md_attr = EFI_MD_ATTR_UC;
258 bi->bi_systab = (u_int64_t)&efi_systab;