xref: /freebsd/stand/i386/libi386/libi386.h (revision 388199e5bbac016b3d33b3c7a9e9250894dafc98)
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 
30ca987d46SWarner Losh /*
31ca987d46SWarner Losh  * i386 fully-qualified device descriptor.
32ca987d46SWarner Losh  * Note, this must match the 'struct devdesc' declaration
33ca987d46SWarner Losh  * in bootstrap.h and also with struct zfs_devdesc for zfs
34ca987d46SWarner Losh  * support.
35ca987d46SWarner Losh  */
36ca987d46SWarner Losh struct i386_devdesc
37ca987d46SWarner Losh {
38ca987d46SWarner Losh     struct devsw	*d_dev;
39ca987d46SWarner Losh     int			d_type;
40ca987d46SWarner Losh     int			d_unit;
41ca987d46SWarner Losh     union
42ca987d46SWarner Losh     {
43ca987d46SWarner Losh 	struct
44ca987d46SWarner Losh 	{
45ca987d46SWarner Losh 	    void	*data;
46ca987d46SWarner Losh 	    int		slice;
47ca987d46SWarner Losh 	    int		partition;
48ca987d46SWarner Losh 	    off_t	offset;
49ca987d46SWarner Losh 	} biosdisk;
50ca987d46SWarner Losh 	struct
51ca987d46SWarner Losh 	{
52ca987d46SWarner Losh 	    void	*data;
53ca987d46SWarner Losh 	} bioscd;
54ca987d46SWarner Losh 	struct
55ca987d46SWarner Losh 	{
56ca987d46SWarner Losh 	    void	*data;
57ca987d46SWarner Losh 	    uint64_t	pool_guid;
58ca987d46SWarner Losh 	    uint64_t	root_guid;
59ca987d46SWarner Losh 	} zfs;
60ca987d46SWarner Losh     } d_kind;
61ca987d46SWarner Losh };
62ca987d46SWarner Losh 
63ca987d46SWarner Losh /*
64ca987d46SWarner Losh  * relocater trampoline support.
65ca987d46SWarner Losh  */
66ca987d46SWarner Losh struct relocate_data {
67ca987d46SWarner Losh 	uint32_t	src;
68ca987d46SWarner Losh 	uint32_t	dest;
69ca987d46SWarner Losh 	uint32_t	size;
70ca987d46SWarner Losh };
71ca987d46SWarner Losh 
72ca987d46SWarner Losh extern void relocater(void);
73ca987d46SWarner Losh 
74ca987d46SWarner Losh /*
75ca987d46SWarner Losh  * The relocater_data[] is fixed size array allocated in relocater_tramp.S
76ca987d46SWarner Losh  */
77ca987d46SWarner Losh extern struct relocate_data relocater_data[];
78ca987d46SWarner Losh extern uint32_t relocater_size;
79ca987d46SWarner Losh 
80ca987d46SWarner Losh extern uint16_t relocator_ip;
81ca987d46SWarner Losh extern uint16_t relocator_cs;
82ca987d46SWarner Losh extern uint16_t relocator_ds;
83ca987d46SWarner Losh extern uint16_t relocator_es;
84ca987d46SWarner Losh extern uint16_t relocator_fs;
85ca987d46SWarner Losh extern uint16_t relocator_gs;
86ca987d46SWarner Losh extern uint16_t relocator_ss;
87ca987d46SWarner Losh extern uint16_t relocator_sp;
88ca987d46SWarner Losh extern uint32_t relocator_esi;
89ca987d46SWarner Losh extern uint32_t relocator_eax;
90ca987d46SWarner Losh extern uint32_t relocator_ebx;
91ca987d46SWarner Losh extern uint32_t relocator_edx;
92ca987d46SWarner Losh extern uint32_t relocator_ebp;
93ca987d46SWarner Losh extern uint16_t relocator_a20_enabled;
94ca987d46SWarner Losh 
95ca987d46SWarner Losh int	i386_getdev(void **vdev, const char *devspec, const char **path);
96ca987d46SWarner Losh char	*i386_fmtdev(void *vdev);
97ca987d46SWarner Losh int	i386_setcurrdev(struct env_var *ev, int flags, const void *value);
98ca987d46SWarner Losh 
99ca987d46SWarner Losh extern struct devdesc	currdev;	/* our current device */
100ca987d46SWarner Losh 
101ca987d46SWarner Losh #define MAXDEV		31		/* maximum number of distinct devices */
102ca987d46SWarner Losh #define MAXBDDEV	MAXDEV
103ca987d46SWarner Losh 
104ca987d46SWarner Losh /* exported devices XXX rename? */
105ca987d46SWarner Losh extern struct devsw bioscd;
106ca987d46SWarner Losh extern struct devsw biosdisk;
107ca987d46SWarner Losh extern struct devsw pxedisk;
108ca987d46SWarner Losh extern struct fs_ops pxe_fsops;
109ca987d46SWarner Losh 
110ca987d46SWarner Losh int	bc_add(int biosdev);		/* Register CD booted from. */
111ca987d46SWarner Losh int	bc_getdev(struct i386_devdesc *dev);	/* return dev_t for (dev) */
112ca987d46SWarner Losh int	bc_bios2unit(int biosdev);	/* xlate BIOS device -> bioscd unit */
113ca987d46SWarner Losh int	bc_unit2bios(int unit);		/* xlate bioscd unit -> BIOS device */
114ca987d46SWarner Losh uint32_t bd_getbigeom(int bunit);	/* return geometry in bootinfo format */
115ca987d46SWarner Losh int	bd_bios2unit(int biosdev);	/* xlate BIOS device -> biosdisk unit */
116ca987d46SWarner Losh int	bd_unit2bios(int unit);		/* xlate biosdisk unit -> BIOS device */
117ca987d46SWarner Losh int	bd_getdev(struct i386_devdesc *dev);	/* return dev_t for (dev) */
118ca987d46SWarner Losh 
119ca987d46SWarner Losh ssize_t	i386_copyin(const void *src, vm_offset_t dest, const size_t len);
120ca987d46SWarner Losh ssize_t	i386_copyout(const vm_offset_t src, void *dest, const size_t len);
121ca987d46SWarner Losh ssize_t	i386_readin(const int fd, vm_offset_t dest, const size_t len);
122ca987d46SWarner Losh 
123ca987d46SWarner Losh struct preloaded_file;
124ca987d46SWarner Losh void	bios_addsmapdata(struct preloaded_file *);
125ca987d46SWarner Losh void	bios_getsmap(void);
126ca987d46SWarner Losh 
127ca987d46SWarner Losh void	bios_getmem(void);
128ca987d46SWarner Losh extern uint32_t		bios_basemem;	/* base memory in bytes */
129ca987d46SWarner Losh extern uint32_t		bios_extmem;	/* extended memory in bytes */
130ca987d46SWarner Losh extern vm_offset_t	memtop;		/* last address of physical memory + 1 */
131ca987d46SWarner Losh extern vm_offset_t	memtop_copyin;	/* memtop less heap size for the cases */
132ca987d46SWarner Losh 					/*  when heap is at the top of         */
133ca987d46SWarner Losh 					/*  extended memory; for other cases   */
134ca987d46SWarner Losh 					/*  just the same as memtop            */
135ca987d46SWarner Losh extern uint32_t		high_heap_size;	/* extended memory region available */
136ca987d46SWarner Losh extern vm_offset_t	high_heap_base;	/* for use as the heap */
137ca987d46SWarner Losh 
138*388199e5SWarner Losh /*
139*388199e5SWarner Losh  * Values for width parameter to biospci_{read,write}_config
140*388199e5SWarner Losh  */
141*388199e5SWarner Losh #define BIOSPCI_8BITS	0
142*388199e5SWarner Losh #define BIOSPCI_16BITS	1
143*388199e5SWarner Losh #define BIOSPCI_32BITS	2
144*388199e5SWarner Losh 
145ca987d46SWarner Losh void	biospci_detect(void);
146ca987d46SWarner Losh int	biospci_find_devclass(uint32_t class, int index, uint32_t *locator);
147ca987d46SWarner Losh int	biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val);
148ca987d46SWarner Losh uint32_t biospci_locator(int8_t bus, uint8_t device, uint8_t function);
149ca987d46SWarner Losh int	biospci_write_config(uint32_t locator, int offset, int width, uint32_t val);
150ca987d46SWarner Losh 
151ca987d46SWarner Losh void	biosacpi_detect(void);
152ca987d46SWarner Losh 
153ca987d46SWarner Losh int	i386_autoload(void);
154ca987d46SWarner Losh 
155ca987d46SWarner Losh int	bi_getboothowto(char *kargs);
156ca987d46SWarner Losh void	bi_setboothowto(int howto);
157ca987d46SWarner Losh vm_offset_t	bi_copyenv(vm_offset_t addr);
158ca987d46SWarner Losh int	bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip,
159ca987d46SWarner Losh 	    vm_offset_t *modulep, vm_offset_t *kernend);
160ca987d46SWarner Losh int	bi_load64(char *args, vm_offset_t addr, vm_offset_t *modulep,
161ca987d46SWarner Losh 	    vm_offset_t *kernend, int add_smap);
162ca987d46SWarner Losh 
163ca987d46SWarner Losh void	pxe_enable(void *pxeinfo);
164