efi_stub.c revision 139738
11539Srgrimes/*-
21539Srgrimes * Copyright (c) 2003,2004 Marcel Moolenaar
31539Srgrimes * All rights reserved.
41539Srgrimes *
51539Srgrimes * Redistribution and use in source and binary forms, with or without
61539Srgrimes * modification, are permitted provided that the following conditions
71539Srgrimes * are met:
81539Srgrimes *
91539Srgrimes * 1. Redistributions of source code must retain the above copyright
101539Srgrimes *    notice, this list of conditions and the following disclaimer.
111539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
121539Srgrimes *    notice, this list of conditions and the following disclaimer in the
131539Srgrimes *    documentation and/or other materials provided with the distribution.
141539Srgrimes *
151539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
161539Srgrimes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
171539Srgrimes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
181539Srgrimes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
191539Srgrimes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
201539Srgrimes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
211539Srgrimes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
221539Srgrimes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
231539Srgrimes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
241539Srgrimes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
251539Srgrimes */
261539Srgrimes
271539Srgrimes#include <sys/cdefs.h>
281539Srgrimes__FBSDID("$FreeBSD: head/sys/boot/ia64/ski/efi_stub.c 139738 2005-01-05 22:16:58Z imp $");
291539Srgrimes
301539Srgrimes#include <sys/types.h>
311539Srgrimes#include <machine/bootinfo.h>
321539Srgrimes#include <machine/efi.h>
331539Srgrimes#include <stand.h>
341539Srgrimes#include "libski.h"
351539Srgrimes
361539Srgrimesextern void acpi_root;
371539Srgrimesextern void sal_systab;
381539Srgrimes
3990644Simpextern void acpi_stub_init(void);
401539Srgrimesextern void sal_stub_init(void);
411539Srgrimes
421539Srgrimesstruct efi_cfgtbl efi_cfgtab[] = {
431539Srgrimes	{ EFI_TABLE_ACPI20,	(intptr_t)&acpi_root },
441539Srgrimes	{ EFI_TABLE_SAL,	(intptr_t)&sal_systab }
451539Srgrimes};
461539Srgrimes
471539Srgrimesstatic efi_status GetTime(struct efi_tm *, struct efi_tmcap *);
482552Sgpalmerstatic efi_status SetTime(struct efi_tm *);
491539Srgrimesstatic efi_status GetWakeupTime(uint8_t *, uint8_t *, struct efi_tm *);
502552Sgpalmerstatic efi_status SetWakeupTime(uint8_t, struct efi_tm *);
511539Srgrimes
522552Sgpalmerstatic efi_status SetVirtualAddressMap(u_long, u_long, uint32_t,
531539Srgrimes    struct efi_md*);
541539Srgrimesstatic efi_status ConvertPointer(u_long, void **);
552552Sgpalmer
561539Srgrimesstatic efi_status GetVariable(efi_char *, struct uuid *, uint32_t *, u_long *,
572552Sgpalmer    void *);
581539Srgrimesstatic efi_status GetNextVariableName(u_long *, efi_char *, struct uuid *);
591539Srgrimesstatic efi_status SetVariable(efi_char *, struct uuid *, uint32_t, u_long,
601539Srgrimes    void *);
611539Srgrimes
621539Srgrimesstatic efi_status GetNextHighMonotonicCount(uint32_t *);
631539Srgrimesstatic efi_status ResetSystem(enum efi_reset, efi_status, u_long, efi_char *);
642915Swollman
6515267Swpaulstruct efi_rt efi_rttab = {
661539Srgrimes	/* Header. */
671539Srgrimes	{	0,			/* XXX Signature */
681539Srgrimes		0,			/* XXX Revision */
691539Srgrimes		0,			/* XXX HeaderSize */
701539Srgrimes		0,			/* XXX CRC32 */
711539Srgrimes	},
721539Srgrimes
731539Srgrimes	/* Time services */
741539Srgrimes	GetTime,
7542780Sdes	SetTime,
7642780Sdes	GetWakeupTime,
771539Srgrimes	SetWakeupTime,
781539Srgrimes
791539Srgrimes	/* Virtual memory services */
801539Srgrimes	SetVirtualAddressMap,
811539Srgrimes	ConvertPointer,
821539Srgrimes
832915Swollman	/* Variable services */
841539Srgrimes	GetVariable,
851539Srgrimes	GetNextVariableName,
862915Swollman	SetVariable,
872915Swollman
882915Swollman	/* Misc */
892915Swollman	GetNextHighMonotonicCount,
902915Swollman	ResetSystem
912915Swollman};
922915Swollman
932915Swollmanstruct efi_systbl efi_systab = {
942915Swollman	/* Header. */
952915Swollman	{	EFI_SYSTBL_SIG,
962915Swollman		0,			/* XXX Revision */
972915Swollman		0,			/* XXX HeaderSize */
982915Swollman		0,			/* XXX CRC32 */
991539Srgrimes	},
1001539Srgrimes
1011539Srgrimes	/* Firmware info. */
1021539Srgrimes	L"FreeBSD", 0, 0,
1031539Srgrimes
1041539Srgrimes	/* Console stuff. */
1051539Srgrimes	NULL, NULL,
1061539Srgrimes	NULL, NULL,
10732962Ssteve	NULL, NULL,
1081539Srgrimes
10990644Simp	/* Services (runtime first). */
1101539Srgrimes	(intptr_t)&efi_rttab,
1111539Srgrimes	NULL,
1121539Srgrimes
1131539Srgrimes	/* Configuration tables. */
114	sizeof(efi_cfgtab)/sizeof(struct efi_cfgtbl),
115	(intptr_t)efi_cfgtab
116};
117
118static efi_status
119unsupported(const char *func)
120{
121	printf("EFI: %s not supported\n", func);
122	return ((1UL << 63) + 3);
123}
124
125static efi_status
126GetTime(struct efi_tm *time, struct efi_tmcap *caps)
127{
128	uint32_t comps[8];
129
130	ssc((uint64_t)comps, 0, 0, 0, SSC_GET_RTC);
131	time->tm_year = comps[0] + 1900;
132	time->tm_mon = comps[1] + 1;
133	time->tm_mday = comps[2];
134	time->tm_hour = comps[3];
135	time->tm_min = comps[4];
136	time->tm_sec = comps[5];
137	time->__pad1 = time->__pad2 = 0;
138	time->tm_nsec = 0;
139	time->tm_tz = 0;
140	time->tm_dst = 0;
141	return (0);
142}
143
144static efi_status
145SetTime(struct efi_tm *time)
146{
147	return (0);
148}
149
150static efi_status
151GetWakeupTime(uint8_t *enabled, uint8_t *pending, struct efi_tm *time)
152{
153	return (unsupported(__func__));
154}
155
156static efi_status
157SetWakeupTime(uint8_t enable, struct efi_tm *time)
158{
159	return (unsupported(__func__));
160}
161
162static void
163Reloc(void *addr, uint64_t delta)
164{
165	uint64_t **fpp = addr;
166
167	*fpp[0] += delta;
168	*fpp[1] += delta;
169	*fpp += delta >> 3;
170}
171
172static efi_status
173SetVirtualAddressMap(u_long mapsz, u_long descsz, uint32_t version,
174    struct efi_md *memmap)
175{
176	uint64_t delta;
177
178	delta = (uintptr_t)memmap->md_virt - memmap->md_phys;
179	Reloc(&efi_rttab.rt_gettime, delta);
180	Reloc(&efi_rttab.rt_settime, delta);
181	return (0);		/* Hah... */
182}
183
184static efi_status
185ConvertPointer(u_long debug, void **addr)
186{
187	return (unsupported(__func__));
188}
189
190static efi_status
191GetVariable(efi_char *name, struct uuid *vendor, uint32_t *attrs,
192    u_long *datasz, void *data)
193{
194	return (unsupported(__func__));
195}
196
197static efi_status
198GetNextVariableName(u_long *namesz, efi_char *name, struct uuid *vendor)
199{
200	return (unsupported(__func__));
201}
202
203static efi_status
204SetVariable(efi_char *name, struct uuid *vendor, uint32_t attrs, u_long datasz,
205    void *data)
206{
207	return (unsupported(__func__));
208}
209
210static efi_status
211GetNextHighMonotonicCount(uint32_t *high)
212{
213	static uint32_t counter = 0;
214
215	*high = counter++;
216	return (0);
217}
218
219static efi_status
220ResetSystem(enum efi_reset type, efi_status status, u_long datasz,
221    efi_char *data)
222{
223	return (unsupported(__func__));
224}
225
226int
227ski_init_stubs(struct bootinfo *bi)
228{
229	struct efi_md *memp;
230
231	/* Describe the SKI memory map. */
232	bi->bi_memmap = (u_int64_t)(bi + 1);
233	bi->bi_memmap_size = 4 * sizeof(struct efi_md);
234	bi->bi_memdesc_size = sizeof(struct efi_md);
235	bi->bi_memdesc_version = 1;
236
237	memp = (struct efi_md *)bi->bi_memmap;
238
239	memp[0].md_type = EFI_MD_TYPE_PALCODE;
240	memp[0].md_phys = 0x100000;
241	memp[0].md_virt = NULL;
242	memp[0].md_pages = (4L*1024*1024)>>12;
243	memp[0].md_attr = EFI_MD_ATTR_WB | EFI_MD_ATTR_RT;
244
245	memp[1].md_type = EFI_MD_TYPE_FREE;
246	memp[1].md_phys = 5L*1024*1024;
247	memp[1].md_virt = NULL;
248	memp[1].md_pages = (128L*1024*1024)>>12;
249	memp[1].md_attr = EFI_MD_ATTR_WB;
250
251	memp[2].md_type = EFI_MD_TYPE_FREE;
252	memp[2].md_phys = 4L*1024*1024*1024;
253	memp[2].md_virt = NULL;
254	memp[2].md_pages = (64L*1024*1024)>>12;
255	memp[2].md_attr = EFI_MD_ATTR_WB;
256
257	memp[3].md_type = EFI_MD_TYPE_IOPORT;
258	memp[3].md_phys = 0xffffc000000;
259	memp[3].md_virt = NULL;
260	memp[3].md_pages = (64L*1024*1024)>>12;
261	memp[3].md_attr = EFI_MD_ATTR_UC;
262
263	bi->bi_systab = (u_int64_t)&efi_systab;
264
265	sal_stub_init();
266	acpi_stub_init();
267
268	return (0);
269}
270