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