1*58a2b000SEvgeniy Ivanov /* $NetBSD: biosdisk_ll.h,v 1.15 2007/12/25 18:33:34 perry Exp $ */ 2*58a2b000SEvgeniy Ivanov 3*58a2b000SEvgeniy Ivanov /* 4*58a2b000SEvgeniy Ivanov * Copyright (c) 1996 5*58a2b000SEvgeniy Ivanov * Matthias Drochner. All rights reserved. 6*58a2b000SEvgeniy Ivanov * Copyright (c) 1996 7*58a2b000SEvgeniy Ivanov * Perry E. Metzger. All rights reserved. 8*58a2b000SEvgeniy Ivanov * 9*58a2b000SEvgeniy Ivanov * Redistribution and use in source and binary forms, with or without 10*58a2b000SEvgeniy Ivanov * modification, are permitted provided that the following conditions 11*58a2b000SEvgeniy Ivanov * are met: 12*58a2b000SEvgeniy Ivanov * 1. Redistributions of source code must retain the above copyright 13*58a2b000SEvgeniy Ivanov * notice, this list of conditions and the following disclaimer. 14*58a2b000SEvgeniy Ivanov * 2. Redistributions in binary form must reproduce the above copyright 15*58a2b000SEvgeniy Ivanov * notice, this list of conditions and the following disclaimer in the 16*58a2b000SEvgeniy Ivanov * documentation and/or other materials provided with the distribution. 17*58a2b000SEvgeniy Ivanov * 3. All advertising materials mentioning features or use of this software 18*58a2b000SEvgeniy Ivanov * must display the following acknowledgements: 19*58a2b000SEvgeniy Ivanov * This product includes software developed for the NetBSD Project 20*58a2b000SEvgeniy Ivanov * by Matthias Drochner. 21*58a2b000SEvgeniy Ivanov * This product includes software developed for the NetBSD Project 22*58a2b000SEvgeniy Ivanov * by Perry E. Metzger. 23*58a2b000SEvgeniy Ivanov * 4. The names of the authors may not be used to endorse or promote products 24*58a2b000SEvgeniy Ivanov * derived from this software without specific prior written permission. 25*58a2b000SEvgeniy Ivanov * 26*58a2b000SEvgeniy Ivanov * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 27*58a2b000SEvgeniy Ivanov * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 28*58a2b000SEvgeniy Ivanov * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 29*58a2b000SEvgeniy Ivanov * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 30*58a2b000SEvgeniy Ivanov * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31*58a2b000SEvgeniy Ivanov * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32*58a2b000SEvgeniy Ivanov * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33*58a2b000SEvgeniy Ivanov * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34*58a2b000SEvgeniy Ivanov * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 35*58a2b000SEvgeniy Ivanov * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36*58a2b000SEvgeniy Ivanov */ 37*58a2b000SEvgeniy Ivanov 38*58a2b000SEvgeniy Ivanov /* 39*58a2b000SEvgeniy Ivanov * shared by bootsector startup (bootsectmain) and biosdisk.c needs lowlevel 40*58a2b000SEvgeniy Ivanov * parts from bios_disk.S 41*58a2b000SEvgeniy Ivanov */ 42*58a2b000SEvgeniy Ivanov 43*58a2b000SEvgeniy Ivanov /* 44*58a2b000SEvgeniy Ivanov * Beware that bios_disk.S relies on the offsets of the structure 45*58a2b000SEvgeniy Ivanov * members. 46*58a2b000SEvgeniy Ivanov */ 47*58a2b000SEvgeniy Ivanov struct biosdisk_ll { 48*58a2b000SEvgeniy Ivanov int dev; /* BIOS device number */ 49*58a2b000SEvgeniy Ivanov int type; /* device type; see below */ 50*58a2b000SEvgeniy Ivanov int sec, head, cyl; /* geometry */ 51*58a2b000SEvgeniy Ivanov int flags; /* see below */ 52*58a2b000SEvgeniy Ivanov int chs_sectors; /* # of sectors addressable by CHS */ 53*58a2b000SEvgeniy Ivanov int secsize; /* bytes per sector */ 54*58a2b000SEvgeniy Ivanov }; 55*58a2b000SEvgeniy Ivanov #define BIOSDISK_INT13EXT 1 /* BIOS supports int13 extension */ 56*58a2b000SEvgeniy Ivanov 57*58a2b000SEvgeniy Ivanov #define BIOSDISK_TYPE_FD 0 58*58a2b000SEvgeniy Ivanov #define BIOSDISK_TYPE_HD 1 59*58a2b000SEvgeniy Ivanov #define BIOSDISK_TYPE_CD 2 60*58a2b000SEvgeniy Ivanov 61*58a2b000SEvgeniy Ivanov /* 62*58a2b000SEvgeniy Ivanov * Version 1.x drive parameters from int13 extensions 63*58a2b000SEvgeniy Ivanov * - should be supported by every BIOS that supports the extensions. 64*58a2b000SEvgeniy Ivanov * Version 3.x parameters allow the drives to be matched properly 65*58a2b000SEvgeniy Ivanov * - but are much less likely to be supported. 66*58a2b000SEvgeniy Ivanov */ 67*58a2b000SEvgeniy Ivanov 68*58a2b000SEvgeniy Ivanov struct biosdisk_extinfo { 69*58a2b000SEvgeniy Ivanov uint16_t size; /* size of buffer, set on call */ 70*58a2b000SEvgeniy Ivanov uint16_t flags; /* flags, see below */ 71*58a2b000SEvgeniy Ivanov uint32_t cyl; /* # of physical cylinders */ 72*58a2b000SEvgeniy Ivanov uint32_t head; /* # of physical heads */ 73*58a2b000SEvgeniy Ivanov uint32_t sec; /* # of physical sectors per track */ 74*58a2b000SEvgeniy Ivanov uint64_t totsec; /* total number of sectors */ 75*58a2b000SEvgeniy Ivanov uint16_t sbytes; /* # of bytes per sector */ 76*58a2b000SEvgeniy Ivanov #if defined(BIOSDISK_EXTINFO_V2) || defined(BIOSDISK_EXTINFO_V3) 77*58a2b000SEvgeniy Ivanov /* v2.0 extensions */ 78*58a2b000SEvgeniy Ivanov uint32_t edd_cfg; /* EDD configuration parameters */ 79*58a2b000SEvgeniy Ivanov #if defined(BIOSDISK_EXTINFO_V3) 80*58a2b000SEvgeniy Ivanov /* v3.0 extensions */ 81*58a2b000SEvgeniy Ivanov uint16_t devpath_sig; /* 0xbedd if path info present */ 82*58a2b000SEvgeniy Ivanov #define EXTINFO_DEVPATH_SIGNATURE 0xbedd 83*58a2b000SEvgeniy Ivanov uint8_t devpath_len; /* length from devpath_sig */ 84*58a2b000SEvgeniy Ivanov uint8_t fill21[3]; 85*58a2b000SEvgeniy Ivanov char host_bus[4]; /* Probably "ISA" or "PCI" */ 86*58a2b000SEvgeniy Ivanov char iface_type[8]; /* "ATA", "ATAPI", "SCSI" etc */ 87*58a2b000SEvgeniy Ivanov union { 88*58a2b000SEvgeniy Ivanov uint8_t ip_8[8]; 89*58a2b000SEvgeniy Ivanov uint16_t ip_16[4]; 90*58a2b000SEvgeniy Ivanov uint32_t ip_32[2]; 91*58a2b000SEvgeniy Ivanov uint64_t ip_64[1]; 92*58a2b000SEvgeniy Ivanov } interface_path; 93*58a2b000SEvgeniy Ivanov #define ip_isa_iobase ip_16[0]; /* iobase for ISA bus */ 94*58a2b000SEvgeniy Ivanov #define ip_pci_bus ip_8[0]; /* PCI bus number */ 95*58a2b000SEvgeniy Ivanov #define ip_pci_device ip_8[1]; /* PCI device number */ 96*58a2b000SEvgeniy Ivanov #define ip_pci_function ip_8[2]; /* PCI function number */ 97*58a2b000SEvgeniy Ivanov union { 98*58a2b000SEvgeniy Ivanov uint8_t dp_8[8]; 99*58a2b000SEvgeniy Ivanov uint16_t dp_16[4]; 100*58a2b000SEvgeniy Ivanov uint32_t dp_32[2]; 101*58a2b000SEvgeniy Ivanov uint64_t dp_64[1]; 102*58a2b000SEvgeniy Ivanov } device_path; 103*58a2b000SEvgeniy Ivanov #define dp_ata_slave dp_8[0]; 104*58a2b000SEvgeniy Ivanov #define dp_atapi_slave dp_8[0]; 105*58a2b000SEvgeniy Ivanov #define dp_atapi_lun dp_8[1]; 106*58a2b000SEvgeniy Ivanov #define dp_scsi_lun dp_8[0]; 107*58a2b000SEvgeniy Ivanov #define dp_firewire_guid dp_64[0]; 108*58a2b000SEvgeniy Ivanov #define dp_fibrechnl_wwn dp_64[0]; 109*58a2b000SEvgeniy Ivanov uint8_t fill40[1]; 110*58a2b000SEvgeniy Ivanov uint8_t checksum; /* byte sum from dev_path_sig is 0 */ 111*58a2b000SEvgeniy Ivanov #endif /* BIOSDISK_EXTINFO_V3 */ 112*58a2b000SEvgeniy Ivanov #endif /* BIOSDISK_EXTINFO_V2 */ 113*58a2b000SEvgeniy Ivanov } __packed; 114*58a2b000SEvgeniy Ivanov 115*58a2b000SEvgeniy Ivanov #define EXTINFO_DMA_TRANS 0x0001 /* transparent DMA boundary errors */ 116*58a2b000SEvgeniy Ivanov #define EXTINFO_GEOM_VALID 0x0002 /* geometry in c/h/s in struct valid */ 117*58a2b000SEvgeniy Ivanov #define EXTINFO_REMOVABLE 0x0004 /* removable device */ 118*58a2b000SEvgeniy Ivanov #define EXTINFO_WRITEVERF 0x0008 /* supports write with verify */ 119*58a2b000SEvgeniy Ivanov #define EXTINFO_CHANGELINE 0x0010 /* changeline support */ 120*58a2b000SEvgeniy Ivanov #define EXTINFO_LOCKABLE 0x0020 /* device is lockable */ 121*58a2b000SEvgeniy Ivanov #define EXTINFO_MAXGEOM 0x0040 /* geometry set to max; no media */ 122*58a2b000SEvgeniy Ivanov 123*58a2b000SEvgeniy Ivanov #define BIOSDISK_DEFAULT_SECSIZE 512 124*58a2b000SEvgeniy Ivanov 125*58a2b000SEvgeniy Ivanov int set_geometry(struct biosdisk_ll *, struct biosdisk_extinfo *); 126*58a2b000SEvgeniy Ivanov int readsects(struct biosdisk_ll *, daddr_t, int, char *, int); 127