xref: /freebsd/stand/i386/libi386/libi386.h (revision 3630506b9daec9167a89bc4525638ea45a00769e)
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  */
33b3a2aad1SWarner Losh struct i386_devdesc {
349f6fd839SIan Lepore     struct devdesc	dd;		/* Must be first. */
35ca987d46SWarner Losh     union
36ca987d46SWarner Losh     {
37ca987d46SWarner Losh 	struct
38ca987d46SWarner Losh 	{
39ca987d46SWarner Losh 	    int		slice;
40ca987d46SWarner Losh 	    int		partition;
41ca987d46SWarner Losh 	    off_t	offset;
42ca987d46SWarner Losh 	} biosdisk;
43ca987d46SWarner Losh 	struct
44ca987d46SWarner Losh 	{
45ca987d46SWarner Losh 	    uint64_t	pool_guid;
46ca987d46SWarner Losh 	    uint64_t	root_guid;
47ca987d46SWarner Losh 	} zfs;
48ca987d46SWarner Losh     } d_kind;
49ca987d46SWarner Losh };
50ca987d46SWarner Losh 
51ca987d46SWarner Losh /*
52ca987d46SWarner Losh  * relocater trampoline support.
53ca987d46SWarner Losh  */
54ca987d46SWarner Losh struct relocate_data {
55ca987d46SWarner Losh 	uint32_t	src;
56ca987d46SWarner Losh 	uint32_t	dest;
57ca987d46SWarner Losh 	uint32_t	size;
58ca987d46SWarner Losh };
59ca987d46SWarner Losh 
60ca987d46SWarner Losh extern void relocater(void);
61ca987d46SWarner Losh 
62ca987d46SWarner Losh /*
63ca987d46SWarner Losh  * The relocater_data[] is fixed size array allocated in relocater_tramp.S
64ca987d46SWarner Losh  */
65ca987d46SWarner Losh extern struct relocate_data relocater_data[];
66ca987d46SWarner Losh extern uint32_t relocater_size;
67ca987d46SWarner Losh 
68ca987d46SWarner Losh extern uint16_t relocator_ip;
69ca987d46SWarner Losh extern uint16_t relocator_cs;
70ca987d46SWarner Losh extern uint16_t relocator_ds;
71ca987d46SWarner Losh extern uint16_t relocator_es;
72ca987d46SWarner Losh extern uint16_t relocator_fs;
73ca987d46SWarner Losh extern uint16_t relocator_gs;
74ca987d46SWarner Losh extern uint16_t relocator_ss;
75ca987d46SWarner Losh extern uint16_t relocator_sp;
76ca987d46SWarner Losh extern uint32_t relocator_esi;
77ca987d46SWarner Losh extern uint32_t relocator_eax;
78ca987d46SWarner Losh extern uint32_t relocator_ebx;
79ca987d46SWarner Losh extern uint32_t relocator_edx;
80ca987d46SWarner Losh extern uint32_t relocator_ebp;
81ca987d46SWarner Losh extern uint16_t relocator_a20_enabled;
82ca987d46SWarner Losh 
83ca987d46SWarner Losh int	i386_getdev(void **vdev, const char *devspec, const char **path);
84ca987d46SWarner Losh char	*i386_fmtdev(void *vdev);
85ca987d46SWarner Losh int	i386_setcurrdev(struct env_var *ev, int flags, const void *value);
86ca987d46SWarner Losh 
87ca987d46SWarner Losh extern struct devdesc	currdev;	/* our current device */
88ca987d46SWarner Losh 
89ca987d46SWarner Losh #define MAXDEV		31		/* maximum number of distinct devices */
90ca987d46SWarner Losh #define MAXBDDEV	MAXDEV
91ca987d46SWarner Losh 
92afc571b1SSimon J. Gerraty #include <readin.h>
93afc571b1SSimon J. Gerraty 
94ca987d46SWarner Losh /* exported devices XXX rename? */
95ca987d46SWarner Losh extern struct devsw bioscd;
96cdff1036SToomas Soome extern struct devsw biosfd;
97cdff1036SToomas Soome extern struct devsw bioshd;
98ca987d46SWarner Losh extern struct devsw pxedisk;
99ca987d46SWarner Losh extern struct fs_ops pxe_fsops;
100ca987d46SWarner Losh 
101ca987d46SWarner Losh int	bc_add(int biosdev);		/* Register CD booted from. */
102ca987d46SWarner Losh uint32_t bd_getbigeom(int bunit);	/* return geometry in bootinfo format */
103ca987d46SWarner Losh int	bd_bios2unit(int biosdev);	/* xlate BIOS device -> biosdisk unit */
104cdff1036SToomas Soome int	bd_unit2bios(struct i386_devdesc *); /* xlate biosdisk -> BIOS device */
105ca987d46SWarner Losh int	bd_getdev(struct i386_devdesc *dev);	/* return dev_t for (dev) */
106ca987d46SWarner Losh 
107ca987d46SWarner Losh ssize_t	i386_copyin(const void *src, vm_offset_t dest, const size_t len);
108ca987d46SWarner Losh ssize_t	i386_copyout(const vm_offset_t src, void *dest, const size_t len);
109afc571b1SSimon J. Gerraty ssize_t	i386_readin(readin_handle_t fd, vm_offset_t dest, const size_t len);
110ca987d46SWarner Losh 
111ca987d46SWarner Losh struct preloaded_file;
112ca987d46SWarner Losh void	bios_addsmapdata(struct preloaded_file *);
113ca987d46SWarner Losh void	bios_getsmap(void);
114ca987d46SWarner Losh 
115ca987d46SWarner Losh void	bios_getmem(void);
116ca987d46SWarner Losh extern uint32_t		bios_basemem;	/* base memory in bytes */
117ca987d46SWarner Losh extern uint32_t		bios_extmem;	/* extended memory in bytes */
118ca987d46SWarner Losh extern vm_offset_t	memtop;		/* last address of physical memory + 1 */
119ca987d46SWarner Losh extern vm_offset_t	memtop_copyin;	/* memtop less heap size for the cases */
120ca987d46SWarner Losh 					/*  when heap is at the top of         */
121ca987d46SWarner Losh 					/*  extended memory; for other cases   */
122ca987d46SWarner Losh 					/*  just the same as memtop            */
123ca987d46SWarner Losh extern uint32_t		high_heap_size;	/* extended memory region available */
124ca987d46SWarner Losh extern vm_offset_t	high_heap_base;	/* for use as the heap */
125ca987d46SWarner Losh 
12675772fa2SToomas Soome /* 16KB buffer space for real mode data transfers. */
12775772fa2SToomas Soome #define	BIO_BUFFER_SIZE 0x4000
12875772fa2SToomas Soome void *bio_alloc(size_t size);
12975772fa2SToomas Soome void bio_free(void *ptr, size_t size);
13075772fa2SToomas Soome 
131388199e5SWarner Losh /*
132388199e5SWarner Losh  * Values for width parameter to biospci_{read,write}_config
133388199e5SWarner Losh  */
134388199e5SWarner Losh #define BIOSPCI_8BITS	0
135388199e5SWarner Losh #define BIOSPCI_16BITS	1
136388199e5SWarner Losh #define BIOSPCI_32BITS	2
137388199e5SWarner Losh 
138ca987d46SWarner Losh void	biospci_detect(void);
139ca987d46SWarner Losh int	biospci_find_devclass(uint32_t class, int index, uint32_t *locator);
140ca987d46SWarner Losh int	biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val);
141ca987d46SWarner Losh uint32_t biospci_locator(int8_t bus, uint8_t device, uint8_t function);
142ca987d46SWarner Losh int	biospci_write_config(uint32_t locator, int offset, int width, uint32_t val);
143ca987d46SWarner Losh 
144ca987d46SWarner Losh void	biosacpi_detect(void);
145ca987d46SWarner Losh 
146ca987d46SWarner Losh int	i386_autoload(void);
147ca987d46SWarner Losh 
148*3630506bSToomas Soome void	bi_load_vbe_data(struct preloaded_file *kfp);
149ca987d46SWarner Losh int	bi_getboothowto(char *kargs);
150ca987d46SWarner Losh void	bi_setboothowto(int howto);
151ca987d46SWarner Losh vm_offset_t	bi_copyenv(vm_offset_t addr);
152ca987d46SWarner Losh int	bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip,
153ca987d46SWarner Losh 	    vm_offset_t *modulep, vm_offset_t *kernend);
154ca987d46SWarner Losh int	bi_load64(char *args, vm_offset_t addr, vm_offset_t *modulep,
155ca987d46SWarner Losh 	    vm_offset_t *kernend, int add_smap);
156ca987d46SWarner Losh 
157ca987d46SWarner Losh void	pxe_enable(void *pxeinfo);
158