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