1f9feecc1SToomas Soome /*
2199767f8SToomas Soome  * Copyright (c) 2013 The FreeBSD Foundation
3199767f8SToomas Soome  * All rights reserved.
4199767f8SToomas Soome  *
5199767f8SToomas Soome  * This software was developed by Benno Rice under sponsorship from
6199767f8SToomas Soome  * the FreeBSD Foundation.
7199767f8SToomas Soome  * Redistribution and use in source and binary forms, with or without
8199767f8SToomas Soome  * modification, are permitted provided that the following conditions
9199767f8SToomas Soome  * are met:
10199767f8SToomas Soome  * 1. Redistributions of source code must retain the above copyright
11199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer.
12199767f8SToomas Soome  * 2. Redistributions in binary form must reproduce the above copyright
13199767f8SToomas Soome  *    notice, this list of conditions and the following disclaimer in the
14199767f8SToomas Soome  *    documentation and/or other materials provided with the distribution.
15199767f8SToomas Soome  *
16199767f8SToomas Soome  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17199767f8SToomas Soome  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18199767f8SToomas Soome  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19199767f8SToomas Soome  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20199767f8SToomas Soome  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21199767f8SToomas Soome  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22199767f8SToomas Soome  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23199767f8SToomas Soome  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24199767f8SToomas Soome  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25199767f8SToomas Soome  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26199767f8SToomas Soome  * SUCH DAMAGE.
27199767f8SToomas Soome  */
28199767f8SToomas Soome 
29f9feecc1SToomas Soome #ifndef	_LOADER_EFI_H
30f9feecc1SToomas Soome #define	_LOADER_EFI_H
31199767f8SToomas Soome 
32199767f8SToomas Soome #include <stand.h>
33f9feecc1SToomas Soome #include <efi.h>
34f9feecc1SToomas Soome #include <efilib.h>
35f9feecc1SToomas Soome #include <sys/multiboot2.h>
36f9feecc1SToomas Soome #include <sys/queue.h>
37f9feecc1SToomas Soome #include <bootstrap.h>
38f9feecc1SToomas Soome 
39f9feecc1SToomas Soome struct chunk {
40f9feecc1SToomas Soome 	EFI_VIRTUAL_ADDRESS chunk_vaddr;
41f9feecc1SToomas Soome 	EFI_PHYSICAL_ADDRESS chunk_paddr;
4283b4671eSToomas Soome 	size_t chunk_size;
43f9feecc1SToomas Soome 	STAILQ_ENTRY(chunk) chunk_next;
44f9feecc1SToomas Soome };
45f9feecc1SToomas Soome 
46f9feecc1SToomas Soome STAILQ_HEAD(chunk_head, chunk);
47f9feecc1SToomas Soome 
48f9feecc1SToomas Soome struct relocator {
4983b4671eSToomas Soome 	vm_offset_t rel_stack;
5083b4671eSToomas Soome 	vm_offset_t rel_copy;
5183b4671eSToomas Soome 	vm_offset_t rel_memmove;
52f9feecc1SToomas Soome 	struct chunk_head rel_chunk_head;
53f9feecc1SToomas Soome 	struct chunk rel_chunklist[];
54f9feecc1SToomas Soome };
55199767f8SToomas Soome 
56199767f8SToomas Soome int	efi_autoload(void);
57199767f8SToomas Soome 
58f9feecc1SToomas Soome ssize_t	efi_copyin(const void *, vm_offset_t, const size_t);
59f9feecc1SToomas Soome ssize_t	efi_copyout(const vm_offset_t, void *, const size_t);
60f9feecc1SToomas Soome ssize_t	efi_readin(const int, vm_offset_t, const size_t);
6183b4671eSToomas Soome vm_offset_t efi_loadaddr(u_int, void *, vm_offset_t);
6283b4671eSToomas Soome void efi_free_loadaddr(vm_offset_t, size_t);
63f9feecc1SToomas Soome void * efi_translate(vm_offset_t);
64af8443c4SToomas Soome vm_offset_t efi_physaddr(multiboot_tag_module_t *, vm_offset_t,
655388916eSToomas Soome     EFI_MEMORY_DESCRIPTOR *, size_t, UINTN, vm_offset_t, size_t);
66d9256fffSToomas Soome void bi_isadir(void);
67199767f8SToomas Soome 
68f9feecc1SToomas Soome multiboot2_info_header_t *efi_copy_finish(struct relocator *);
69f9feecc1SToomas Soome void multiboot_tramp(uint32_t, struct relocator *, uint64_t);
70199767f8SToomas Soome 
71f9feecc1SToomas Soome void efi_addsmapdata(struct preloaded_file *);
72199767f8SToomas Soome 
73f9feecc1SToomas Soome #endif	/* _LOADER_EFI_H */
74