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 27ca987d46SWarner Losh 28*f197c0bfSWarner Losh #include "disk.h" 29*f197c0bfSWarner Losh #ifdef LOADER_ZFS_SUPPORT 30*f197c0bfSWarner Losh #include "libzfs.h" 31*f197c0bfSWarner Losh #endif 32ca987d46SWarner Losh /* 33ca987d46SWarner Losh * i386 fully-qualified device descriptor. 34ca987d46SWarner Losh */ 35*f197c0bfSWarner Losh struct i386_devdesc 36*f197c0bfSWarner Losh { 37ca987d46SWarner Losh union 38ca987d46SWarner Losh { 39*f197c0bfSWarner Losh struct devdesc dd; 40*f197c0bfSWarner Losh struct disk_devdesc disk; 41*f197c0bfSWarner Losh #ifdef LOADER_ZFS_SUPPORT 42*f197c0bfSWarner Losh struct zfs_devdesc zfs; 43*f197c0bfSWarner Losh #endif 44*f197c0bfSWarner Losh }; 45ca987d46SWarner Losh }; 46ca987d46SWarner Losh 47ca987d46SWarner Losh /* 48ca987d46SWarner Losh * relocater trampoline support. 49ca987d46SWarner Losh */ 50ca987d46SWarner Losh struct relocate_data { 51ca987d46SWarner Losh uint32_t src; 52ca987d46SWarner Losh uint32_t dest; 53ca987d46SWarner Losh uint32_t size; 54ca987d46SWarner Losh }; 55ca987d46SWarner Losh 56ca987d46SWarner Losh extern void relocater(void); 57ca987d46SWarner Losh 58ca987d46SWarner Losh /* 59ca987d46SWarner Losh * The relocater_data[] is fixed size array allocated in relocater_tramp.S 60ca987d46SWarner Losh */ 61ca987d46SWarner Losh extern struct relocate_data relocater_data[]; 62ca987d46SWarner Losh extern uint32_t relocater_size; 63ca987d46SWarner Losh 64ca987d46SWarner Losh extern uint16_t relocator_ip; 65ca987d46SWarner Losh extern uint16_t relocator_cs; 66ca987d46SWarner Losh extern uint16_t relocator_ds; 67ca987d46SWarner Losh extern uint16_t relocator_es; 68ca987d46SWarner Losh extern uint16_t relocator_fs; 69ca987d46SWarner Losh extern uint16_t relocator_gs; 70ca987d46SWarner Losh extern uint16_t relocator_ss; 71ca987d46SWarner Losh extern uint16_t relocator_sp; 72ca987d46SWarner Losh extern uint32_t relocator_esi; 73ca987d46SWarner Losh extern uint32_t relocator_eax; 74ca987d46SWarner Losh extern uint32_t relocator_ebx; 75ca987d46SWarner Losh extern uint32_t relocator_edx; 76ca987d46SWarner Losh extern uint32_t relocator_ebp; 77ca987d46SWarner Losh extern uint16_t relocator_a20_enabled; 78ca987d46SWarner Losh 79ca987d46SWarner Losh int i386_getdev(void **vdev, const char *devspec, const char **path); 80ca987d46SWarner Losh char *i386_fmtdev(void *vdev); 81ca987d46SWarner Losh 82ca987d46SWarner Losh extern struct devdesc currdev; /* our current device */ 83ca987d46SWarner Losh 84ca987d46SWarner Losh #define MAXDEV 31 /* maximum number of distinct devices */ 85ca987d46SWarner Losh #define MAXBDDEV MAXDEV 86ca987d46SWarner Losh 87afc571b1SSimon J. Gerraty #include <readin.h> 88afc571b1SSimon J. Gerraty 89ca987d46SWarner Losh /* exported devices XXX rename? */ 90ca987d46SWarner Losh extern struct devsw bioscd; 91cdff1036SToomas Soome extern struct devsw biosfd; 92cdff1036SToomas Soome extern struct devsw bioshd; 93ca987d46SWarner Losh extern struct devsw pxedisk; 94ca987d46SWarner Losh extern struct fs_ops pxe_fsops; 95ca987d46SWarner Losh 96ca987d46SWarner Losh int bc_add(int biosdev); /* Register CD booted from. */ 97ca987d46SWarner Losh uint32_t bd_getbigeom(int bunit); /* return geometry in bootinfo format */ 98ca987d46SWarner Losh int bd_bios2unit(int biosdev); /* xlate BIOS device -> biosdisk unit */ 99cdff1036SToomas Soome int bd_unit2bios(struct i386_devdesc *); /* xlate biosdisk -> BIOS device */ 100ca987d46SWarner Losh int bd_getdev(struct i386_devdesc *dev); /* return dev_t for (dev) */ 101ca987d46SWarner Losh 102ca987d46SWarner Losh ssize_t i386_copyin(const void *src, vm_offset_t dest, const size_t len); 103ca987d46SWarner Losh ssize_t i386_copyout(const vm_offset_t src, void *dest, const size_t len); 104afc571b1SSimon J. Gerraty ssize_t i386_readin(readin_handle_t fd, vm_offset_t dest, const size_t len); 105ca987d46SWarner Losh 106ca987d46SWarner Losh struct preloaded_file; 107ca987d46SWarner Losh void bios_addsmapdata(struct preloaded_file *); 108ca987d46SWarner Losh void bios_getsmap(void); 109ca987d46SWarner Losh 110ca987d46SWarner Losh void bios_getmem(void); 111ca987d46SWarner Losh extern uint32_t bios_basemem; /* base memory in bytes */ 112ca987d46SWarner Losh extern uint32_t bios_extmem; /* extended memory in bytes */ 113ca987d46SWarner Losh extern vm_offset_t memtop; /* last address of physical memory + 1 */ 114ca987d46SWarner Losh extern vm_offset_t memtop_copyin; /* memtop less heap size for the cases */ 115ca987d46SWarner Losh /* when heap is at the top of */ 116ca987d46SWarner Losh /* extended memory; for other cases */ 117ca987d46SWarner Losh /* just the same as memtop */ 118ca987d46SWarner Losh extern uint32_t high_heap_size; /* extended memory region available */ 119ca987d46SWarner Losh extern vm_offset_t high_heap_base; /* for use as the heap */ 120ca987d46SWarner Losh 12175772fa2SToomas Soome /* 16KB buffer space for real mode data transfers. */ 12275772fa2SToomas Soome #define BIO_BUFFER_SIZE 0x4000 12375772fa2SToomas Soome void *bio_alloc(size_t size); 12475772fa2SToomas Soome void bio_free(void *ptr, size_t size); 12575772fa2SToomas Soome 126388199e5SWarner Losh /* 127388199e5SWarner Losh * Values for width parameter to biospci_{read,write}_config 128388199e5SWarner Losh */ 129388199e5SWarner Losh #define BIOSPCI_8BITS 0 130388199e5SWarner Losh #define BIOSPCI_16BITS 1 131388199e5SWarner Losh #define BIOSPCI_32BITS 2 132388199e5SWarner Losh 133ca987d46SWarner Losh void biospci_detect(void); 134ca987d46SWarner Losh int biospci_find_devclass(uint32_t class, int index, uint32_t *locator); 135ca987d46SWarner Losh int biospci_read_config(uint32_t locator, int offset, int width, uint32_t *val); 136ca987d46SWarner Losh uint32_t biospci_locator(int8_t bus, uint8_t device, uint8_t function); 137ca987d46SWarner Losh int biospci_write_config(uint32_t locator, int offset, int width, uint32_t val); 138ca987d46SWarner Losh 139ca987d46SWarner Losh void biosacpi_detect(void); 140ca987d46SWarner Losh 141ca987d46SWarner Losh int i386_autoload(void); 142ca987d46SWarner Losh 1433630506bSToomas Soome void bi_load_vbe_data(struct preloaded_file *kfp); 144ca987d46SWarner Losh int bi_getboothowto(char *kargs); 145ca987d46SWarner Losh void bi_setboothowto(int howto); 146ca987d46SWarner Losh int bi_load32(char *args, int *howtop, int *bootdevp, vm_offset_t *bip, 147ca987d46SWarner Losh vm_offset_t *modulep, vm_offset_t *kernend); 14845ecda8eSRoger Pau Monné int bi_load64(char *args, vm_offset_t *modulep, 149ca987d46SWarner Losh vm_offset_t *kernend, int add_smap); 150ca987d46SWarner Losh 151ca987d46SWarner Losh void pxe_enable(void *pxeinfo); 152