efi_stub.c revision 110211
1/* 2 * Copyright (c) 2003 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. 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. 14 * 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. 25 * 26 * $FreeBSD: head/sys/boot/ia64/ski/efi_stub.c 110211 2003-02-01 22:50:09Z marcel $ 27 */ 28 29#include <sys/types.h> 30#include <machine/bootinfo.h> 31#include <efi.h> 32#include <stand.h> 33#include "libski.h" 34 35extern void acpi_root; 36extern void sal_systab; 37 38extern void acpi_stub_init(void); 39extern void sal_stub_init(void); 40 41EFI_CONFIGURATION_TABLE efi_cfgtab[] = { 42 { ACPI_20_TABLE_GUID, &acpi_root }, 43 { SAL_SYSTEM_TABLE_GUID, &sal_systab } 44}; 45 46 47static EFI_STATUS GetTime(EFI_TIME *, EFI_TIME_CAPABILITIES *); 48static EFI_STATUS SetTime(EFI_TIME *); 49static EFI_STATUS GetWakeupTime(BOOLEAN *, BOOLEAN *, EFI_TIME *); 50static EFI_STATUS SetWakeupTime(BOOLEAN, EFI_TIME *); 51 52static EFI_STATUS SetVirtualAddressMap(UINTN, UINTN, UINT32, 53 EFI_MEMORY_DESCRIPTOR*); 54static EFI_STATUS ConvertPointer(UINTN, VOID **); 55 56static EFI_STATUS GetVariable(CHAR16 *, EFI_GUID *, UINT32 *, UINTN *, VOID *); 57static EFI_STATUS GetNextVariableName(UINTN *, CHAR16 *, EFI_GUID *); 58static EFI_STATUS SetVariable(CHAR16 *, EFI_GUID *, UINT32, UINTN, VOID *); 59 60static EFI_STATUS GetNextHighMonotonicCount(UINT32 *); 61static EFI_STATUS ResetSystem(EFI_RESET_TYPE, EFI_STATUS, UINTN, CHAR16 *); 62 63EFI_RUNTIME_SERVICES efi_rttab = { 64 /* Header. */ 65 { EFI_RUNTIME_SERVICES_SIGNATURE, 66 EFI_RUNTIME_SERVICES_REVISION, 67 0, /* XXX HeaderSize */ 68 0, /* XXX CRC32 */ 69 }, 70 71 /* Time services */ 72 GetTime, 73 SetTime, 74 GetWakeupTime, 75 SetWakeupTime, 76 77 /* Virtual memory services */ 78 SetVirtualAddressMap, 79 ConvertPointer, 80 81 /* Variable services */ 82 GetVariable, 83 GetNextVariableName, 84 SetVariable, 85 86 /* Misc */ 87 GetNextHighMonotonicCount, 88 ResetSystem 89}; 90 91EFI_SYSTEM_TABLE efi_systab = { 92 /* Header. */ 93 { EFI_SYSTEM_TABLE_SIGNATURE, 94 EFI_SYSTEM_TABLE_REVISION, 95 0, /* XXX HeaderSize */ 96 0, /* XXX CRC32 */ 97 }, 98 99 /* Firmware info. */ 100 L"FreeBSD", 0, 101 102 /* Console stuff. */ 103 NULL, NULL, 104 NULL, NULL, 105 NULL, NULL, 106 107 /* Services (runtime first). */ 108 &efi_rttab, 109 NULL, 110 111 /* Configuration tables. */ 112 sizeof(efi_cfgtab)/sizeof(EFI_CONFIGURATION_TABLE), 113 efi_cfgtab 114}; 115 116static EFI_STATUS 117unsupported(const char *func) 118{ 119 printf("EFI: %s not supported\n", func); 120 return (EFI_UNSUPPORTED); 121} 122 123static EFI_STATUS 124GetTime(EFI_TIME *time, EFI_TIME_CAPABILITIES *caps) 125{ 126 UINT32 comps[8]; 127 128 ssc((UINT64)comps, 0, 0, 0, SSC_GET_RTC); 129 time->Year = comps[0] + 1900; 130 time->Month = comps[1] + 1; 131 time->Day = comps[2]; 132 time->Hour = comps[3]; 133 time->Minute = comps[4]; 134 time->Second = comps[5]; 135 time->Pad1 = time->Pad2 = 0; 136 time->Nanosecond = 0; 137 time->TimeZone = 0; 138 time->Daylight = 0; 139 return (EFI_SUCCESS); 140} 141 142static EFI_STATUS 143SetTime(EFI_TIME *time) 144{ 145 return (EFI_SUCCESS); 146} 147 148static EFI_STATUS 149GetWakeupTime(BOOLEAN *enabled, BOOLEAN *pending, EFI_TIME *time) 150{ 151 return (unsupported(__func__)); 152} 153 154static EFI_STATUS 155SetWakeupTime(BOOLEAN enable, EFI_TIME *time) 156{ 157 return (unsupported(__func__)); 158} 159 160static void 161Reloc(void *addr, UINT64 delta) 162{ 163 UINT64 **fpp = addr; 164 165 *fpp[0] += delta; 166 *fpp[1] += delta; 167 *fpp += delta >> 3; 168} 169 170static EFI_STATUS 171SetVirtualAddressMap(UINTN mapsz, UINTN descsz, UINT32 version, 172 EFI_MEMORY_DESCRIPTOR *memmap) 173{ 174 UINT64 delta; 175 176 delta = memmap->VirtualStart - memmap->PhysicalStart; 177 Reloc(&efi_rttab.GetTime, delta); 178 Reloc(&efi_rttab.SetTime, delta); 179 return (EFI_SUCCESS); /* Hah... */ 180} 181 182static EFI_STATUS 183ConvertPointer(UINTN debug, VOID **addr) 184{ 185 return (unsupported(__func__)); 186} 187 188static EFI_STATUS 189GetVariable(CHAR16 *name, EFI_GUID *vendor, UINT32 *attrs, UINTN *datasz, 190 VOID *data) 191{ 192 return (unsupported(__func__)); 193} 194 195static EFI_STATUS 196GetNextVariableName(UINTN *namesz, CHAR16 *name, EFI_GUID *vendor) 197{ 198 return (unsupported(__func__)); 199} 200 201static EFI_STATUS 202SetVariable(CHAR16 *name, EFI_GUID *vendor, UINT32 attrs, UINTN datasz, 203 VOID *data) 204{ 205 return (unsupported(__func__)); 206} 207 208static EFI_STATUS 209GetNextHighMonotonicCount(UINT32 *high) 210{ 211 static UINT32 counter = 0; 212 213 *high = counter++; 214 return (EFI_SUCCESS); 215} 216 217static EFI_STATUS 218ResetSystem(EFI_RESET_TYPE type, EFI_STATUS status, UINTN datasz, 219 CHAR16 *data) 220{ 221 return (unsupported(__func__)); 222} 223 224int 225ski_init_stubs(struct bootinfo *bi) 226{ 227 EFI_MEMORY_DESCRIPTOR *memp; 228 229 /* Describe the SKI memory map. */ 230 bi->bi_memmap = (u_int64_t)(bi + 1); 231 bi->bi_memmap_size = 4 * sizeof(EFI_MEMORY_DESCRIPTOR); 232 bi->bi_memdesc_size = sizeof(EFI_MEMORY_DESCRIPTOR); 233 bi->bi_memdesc_version = 1; 234 235 memp = (EFI_MEMORY_DESCRIPTOR *)bi->bi_memmap; 236 237 memp[0].Type = EfiPalCode; 238 memp[0].PhysicalStart = 0x100000; 239 memp[0].VirtualStart = 0; 240 memp[0].NumberOfPages = (4L*1024*1024)>>12; 241 memp[0].Attribute = EFI_MEMORY_WB | EFI_MEMORY_RUNTIME; 242 243 memp[1].Type = EfiConventionalMemory; 244 memp[1].PhysicalStart = 5L*1024*1024; 245 memp[1].VirtualStart = 0; 246 memp[1].NumberOfPages = (128L*1024*1024)>>12; 247 memp[1].Attribute = EFI_MEMORY_WB; 248 249 memp[2].Type = EfiConventionalMemory; 250 memp[2].PhysicalStart = 4L*1024*1024*1024; 251 memp[2].VirtualStart = 0; 252 memp[2].NumberOfPages = (64L*1024*1024)>>12; 253 memp[2].Attribute = EFI_MEMORY_WB; 254 255 memp[3].Type = EfiMemoryMappedIOPortSpace; 256 memp[3].PhysicalStart = 0xffffc000000; 257 memp[3].VirtualStart = 0; 258 memp[3].NumberOfPages = (64L*1024*1024)>>12; 259 memp[3].Attribute = EFI_MEMORY_UC; 260 261 bi->bi_systab = (u_int64_t)&efi_systab; 262 263 sal_stub_init(); 264 acpi_stub_init(); 265 266 return (0); 267} 268