xref: /freebsd/stand/i386/libi386/libi386.h (revision e0c4386e7e71d93b0edc0c8fa156263fc4a8b0b6)
1 /*-
2  * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
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  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  */
26 
27 
28 #include "disk.h"
29 #ifdef LOADER_ZFS_SUPPORT
30 #include "libzfs.h"
31 #endif
32 /*
33  * i386 fully-qualified device descriptor.
34  */
35 struct i386_devdesc
36 {
37 	union
38 	{
39 		struct devdesc dd;
40 		struct disk_devdesc disk;
41 #ifdef LOADER_ZFS_SUPPORT
42 		struct zfs_devdesc zfs;
43 #endif
44 	};
45 };
46 
47 /*
48  * relocater trampoline support.
49  */
50 struct relocate_data {
51 	uint32_t	src;
52 	uint32_t	dest;
53 	uint32_t	size;
54 };
55 
56 extern void relocater(void);
57 
58 /*
59  * The relocater_data[] is fixed size array allocated in relocater_tramp.S
60  */
61 extern struct relocate_data relocater_data[];
62 extern uint32_t relocater_size;
63 
64 extern uint16_t relocator_ip;
65 extern uint16_t relocator_cs;
66 extern uint16_t relocator_ds;
67 extern uint16_t relocator_es;
68 extern uint16_t relocator_fs;
69 extern uint16_t relocator_gs;
70 extern uint16_t relocator_ss;
71 extern uint16_t relocator_sp;
72 extern uint32_t relocator_esi;
73 extern uint32_t relocator_eax;
74 extern uint32_t relocator_ebx;
75 extern uint32_t relocator_edx;
76 extern uint32_t relocator_ebp;
77 extern uint16_t relocator_a20_enabled;
78 
79 int	i386_getdev(void **vdev, const char *devspec, const char **path);
80 char	*i386_fmtdev(void *vdev);
81 
82 extern struct devdesc	currdev;	/* our current device */
83 
84 #define MAXDEV		31		/* maximum number of distinct devices */
85 #define MAXBDDEV	MAXDEV
86 
87 #include <readin.h>
88 
89 /* exported devices XXX rename? */
90 extern struct devsw bioscd;
91 extern struct devsw biosfd;
92 extern struct devsw bioshd;
93 extern struct devsw pxedisk;
94 extern struct fs_ops pxe_fsops;
95 
96 int	bc_add(int biosdev);		/* Register CD booted from. */
97 uint32_t bd_getbigeom(int bunit);	/* return geometry in bootinfo format */
98 int	bd_bios2unit(int biosdev);	/* xlate BIOS device -> biosdisk unit */
99 int	bd_unit2bios(struct i386_devdesc *); /* xlate biosdisk -> BIOS device */
100 int	bd_getdev(struct i386_devdesc *dev);	/* return dev_t for (dev) */
101 
102 ssize_t	i386_copyin(const void *src, vm_offset_t dest, const size_t len);
103 ssize_t	i386_copyout(const vm_offset_t src, void *dest, const size_t len);
104 ssize_t	i386_readin(readin_handle_t fd, vm_offset_t dest, const size_t len);
105 
106 struct preloaded_file;
107 void	bios_addsmapdata(struct preloaded_file *);
108 void	bios_getsmap(void);
109 
110 void	bios_getmem(void);
111 extern uint32_t		bios_basemem;	/* base memory in bytes */
112 extern uint32_t		bios_extmem;	/* extended memory in bytes */
113 extern vm_offset_t	memtop;		/* last address of physical memory + 1 */
114 extern vm_offset_t	memtop_copyin;	/* memtop less heap size for the cases */
115 					/*  when heap is at the top of         */
116 					/*  extended memory; for other cases   */
117 					/*  just the same as memtop            */
118 extern uint32_t		high_heap_size;	/* extended memory region available */
119 extern vm_offset_t	high_heap_base;	/* for use as the heap */
120 
121 /* 16KB buffer space for real mode data transfers. */
122 #define	BIO_BUFFER_SIZE 0x4000
123 void *bio_alloc(size_t size);
124 void bio_free(void *ptr, size_t size);
125 
126 /*
127  * Values for width parameter to biospci_{read,write}_config
128  */
129 #define BIOSPCI_8BITS	0
130 #define BIOSPCI_16BITS	1
131 #define BIOSPCI_32BITS	2
132 
133 void	biospci_detect(void);
134 int	biospci_find_devclass(uint32_t class, int index, uint32_t *locator);
135 int	biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val);
136 uint32_t biospci_locator(int8_t bus, uint8_t device, uint8_t function);
137 int	biospci_write_config(uint32_t locator, int offset, int width, uint32_t val);
138 
139 void	biosacpi_detect(void);
140 
141 int	i386_autoload(void);
142 
143 void	bi_load_vbe_data(struct preloaded_file *kfp);
144 int	bi_getboothowto(char *kargs);
145 void	bi_setboothowto(int howto);
146 int	bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip,
147 	    vm_offset_t *modulep, vm_offset_t *kernend);
148 int	bi_load64(char *args, vm_offset_t *modulep,
149 	    vm_offset_t *kernend, int add_smap);
150 
151 void	pxe_enable(void *pxeinfo);
152