1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/types.h> 30*0Sstevel@tonic-gate #include <sys/param.h> 31*0Sstevel@tonic-gate #include <sys/controlregs.h> 32*0Sstevel@tonic-gate #include <sys/bootconf.h> 33*0Sstevel@tonic-gate #include <sys/bootvfs.h> 34*0Sstevel@tonic-gate #include <sys/bootregs.h> 35*0Sstevel@tonic-gate #include <sys/bootconf.h> 36*0Sstevel@tonic-gate #include <sys/conf.h> 37*0Sstevel@tonic-gate #include <sys/promif.h> 38*0Sstevel@tonic-gate #include <sys/ddi.h> 39*0Sstevel@tonic-gate #include <sys/sunddi.h> 40*0Sstevel@tonic-gate #include <sys/sunndi.h> 41*0Sstevel@tonic-gate #include <sys/biosdisk.h> 42*0Sstevel@tonic-gate #include <sys/psw.h> 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate 45*0Sstevel@tonic-gate /* hard code realmode memory address for now */ 46*0Sstevel@tonic-gate #define BIOS_RES_BUFFER_ADDR 0x7000 47*0Sstevel@tonic-gate 48*0Sstevel@tonic-gate #define BIOSDEV_NUM 8 49*0Sstevel@tonic-gate #define STARTING_DRVNUM 0x80 50*0Sstevel@tonic-gate #define FP_OFF(fp) (((uintptr_t)(fp)) & 0xFFFF) 51*0Sstevel@tonic-gate #define FP_SEG(fp) ((((uintptr_t)(fp)) >> 16) & 0xFFFF) 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate #ifdef DEBUG 54*0Sstevel@tonic-gate int biosdebug = 0; 55*0Sstevel@tonic-gate #define dprintf(fmt) \ 56*0Sstevel@tonic-gate if (biosdebug) \ 57*0Sstevel@tonic-gate prom_printf fmt 58*0Sstevel@tonic-gate #else 59*0Sstevel@tonic-gate #define dprintf(fmt) 60*0Sstevel@tonic-gate #endif 61*0Sstevel@tonic-gate 62*0Sstevel@tonic-gate biosdev_data_t biosdev_info[BIOSDEV_NUM]; /* from 0x80 to 0x87 */ 63*0Sstevel@tonic-gate int dobiosdev = 1; 64*0Sstevel@tonic-gate 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate static int bios_check_extension_present(uchar_t); 67*0Sstevel@tonic-gate static int get_dev_params(uchar_t); 68*0Sstevel@tonic-gate static int read_firstblock(uchar_t drivenum); 69*0Sstevel@tonic-gate static int drive_present(uchar_t drivenum); 70*0Sstevel@tonic-gate static void reset_disk(uchar_t drivenum); 71*0Sstevel@tonic-gate 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate void 74*0Sstevel@tonic-gate startup_bios_disk() 75*0Sstevel@tonic-gate { 76*0Sstevel@tonic-gate uchar_t drivenum; 77*0Sstevel@tonic-gate int got_devparams = 0; 78*0Sstevel@tonic-gate int got_first_block = 0; 79*0Sstevel@tonic-gate uchar_t name[20]; 80*0Sstevel@tonic-gate dev_info_t *devi; 81*0Sstevel@tonic-gate 82*0Sstevel@tonic-gate if (dobiosdev == 0) 83*0Sstevel@tonic-gate return; 84*0Sstevel@tonic-gate 85*0Sstevel@tonic-gate for (drivenum = 0x80; drivenum < (0x80 + BIOSDEV_NUM); drivenum++) { 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate if (!drive_present(drivenum)) 88*0Sstevel@tonic-gate continue; 89*0Sstevel@tonic-gate 90*0Sstevel@tonic-gate got_devparams = get_dev_params(drivenum); 91*0Sstevel@tonic-gate 92*0Sstevel@tonic-gate if ((got_first_block = read_firstblock(drivenum)) == 0) { 93*0Sstevel@tonic-gate /* retry */ 94*0Sstevel@tonic-gate got_first_block = read_firstblock(drivenum); 95*0Sstevel@tonic-gate } 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate if (got_devparams || got_first_block) { 98*0Sstevel@tonic-gate (void) sprintf((char *)name, "biosdev-0x%x", drivenum); 99*0Sstevel@tonic-gate devi = ddi_root_node(); 100*0Sstevel@tonic-gate (void) e_ddi_prop_update_byte_array(DDI_DEV_T_NONE, 101*0Sstevel@tonic-gate devi, (char *)name, 102*0Sstevel@tonic-gate (uchar_t *)&biosdev_info[drivenum - 0x80], 103*0Sstevel@tonic-gate sizeof (biosdev_data_t)); 104*0Sstevel@tonic-gate } 105*0Sstevel@tonic-gate } 106*0Sstevel@tonic-gate } 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate static int 109*0Sstevel@tonic-gate bios_check_extension_present(uchar_t drivenum) 110*0Sstevel@tonic-gate { 111*0Sstevel@tonic-gate struct bop_regs rp = {0}; 112*0Sstevel@tonic-gate extern struct bootops *bootops; 113*0Sstevel@tonic-gate 114*0Sstevel@tonic-gate rp.eax.word.ax = 0x4100; 115*0Sstevel@tonic-gate rp.ebx.word.bx = 0x55AA; 116*0Sstevel@tonic-gate rp.edx.word.dx = drivenum; 117*0Sstevel@tonic-gate 118*0Sstevel@tonic-gate /* make sure we have extension support */ 119*0Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 120*0Sstevel@tonic-gate 121*0Sstevel@tonic-gate if (((rp.eflags & PS_C) != 0) || (rp.ebx.word.bx != 0xAA55)) { 122*0Sstevel@tonic-gate dprintf(("bios_check_extension_present int13 fn 41 " 123*0Sstevel@tonic-gate "failed %d bx = %x\n", rp.eflags, rp.ebx.word.bx)); 124*0Sstevel@tonic-gate return (0); 125*0Sstevel@tonic-gate } 126*0Sstevel@tonic-gate 127*0Sstevel@tonic-gate if ((rp.ecx.word.cx & 0x7) == 0) { 128*0Sstevel@tonic-gate dprintf(("bios_check_extension_present get device parameters " 129*0Sstevel@tonic-gate "not supported cx = %x\n", rp.ecx.word.cx)); 130*0Sstevel@tonic-gate return (0); 131*0Sstevel@tonic-gate } 132*0Sstevel@tonic-gate 133*0Sstevel@tonic-gate return (1); 134*0Sstevel@tonic-gate } 135*0Sstevel@tonic-gate 136*0Sstevel@tonic-gate static int 137*0Sstevel@tonic-gate get_dev_params(uchar_t drivenum) 138*0Sstevel@tonic-gate { 139*0Sstevel@tonic-gate struct bop_regs rp = {0}; 140*0Sstevel@tonic-gate fn48_t *bufp; 141*0Sstevel@tonic-gate extern struct bootops *bootops; 142*0Sstevel@tonic-gate int i; 143*0Sstevel@tonic-gate int index; 144*0Sstevel@tonic-gate 145*0Sstevel@tonic-gate dprintf(("In get_dev_params\n")); 146*0Sstevel@tonic-gate 147*0Sstevel@tonic-gate if (bios_check_extension_present(drivenum) == 0) 148*0Sstevel@tonic-gate return (0); 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate bufp = (fn48_t *)BIOS_RES_BUFFER_ADDR; 151*0Sstevel@tonic-gate 152*0Sstevel@tonic-gate for (i = 0; i < sizeof (*bufp); i++) 153*0Sstevel@tonic-gate ((uchar_t *)bufp)[i] = 0; 154*0Sstevel@tonic-gate 155*0Sstevel@tonic-gate bufp->buflen = sizeof (*bufp); 156*0Sstevel@tonic-gate rp.eax.word.ax = 0x4800; 157*0Sstevel@tonic-gate rp.edx.byte.dl = drivenum; 158*0Sstevel@tonic-gate 159*0Sstevel@tonic-gate rp.esi.word.si = (uint16_t)FP_OFF((uint_t)(uintptr_t)bufp); 160*0Sstevel@tonic-gate rp.ds = FP_SEG((uint_t)(uintptr_t)bufp); 161*0Sstevel@tonic-gate 162*0Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate if ((rp.eflags & PS_C) != 0) { 165*0Sstevel@tonic-gate dprintf(("EDD FAILED on drive eflag = %x ah= %x\n", 166*0Sstevel@tonic-gate rp.eflags, rp.eax.byte.ah)); 167*0Sstevel@tonic-gate return (0); 168*0Sstevel@tonic-gate } 169*0Sstevel@tonic-gate 170*0Sstevel@tonic-gate index = drivenum - 0x80; 171*0Sstevel@tonic-gate biosdev_info[index].edd_valid = 1; 172*0Sstevel@tonic-gate biosdev_info[index].fn48_dev_params = *bufp; 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate return (1); 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate } 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate static int 179*0Sstevel@tonic-gate drive_present(uchar_t drivenum) 180*0Sstevel@tonic-gate { 181*0Sstevel@tonic-gate struct bop_regs rp = {0}; 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate rp.eax.byte.ah = 0x8; /* get params */ 184*0Sstevel@tonic-gate rp.edx.byte.dl = drivenum; 185*0Sstevel@tonic-gate 186*0Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 187*0Sstevel@tonic-gate 188*0Sstevel@tonic-gate if (((rp.eflags & PS_C) != 0) || rp.eax.byte.ah != 0) { 189*0Sstevel@tonic-gate dprintf(("drive not present drivenum %x eflag %x ah %x\n", 190*0Sstevel@tonic-gate drivenum, rp.eflags, rp.eax.byte.ah)); 191*0Sstevel@tonic-gate return (0); 192*0Sstevel@tonic-gate } 193*0Sstevel@tonic-gate 194*0Sstevel@tonic-gate dprintf(("drive-present %x\n", drivenum)); 195*0Sstevel@tonic-gate return (1); 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate } 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate static void 200*0Sstevel@tonic-gate reset_disk(uchar_t drivenum) 201*0Sstevel@tonic-gate { 202*0Sstevel@tonic-gate struct bop_regs rp = {0}; 203*0Sstevel@tonic-gate int status; 204*0Sstevel@tonic-gate 205*0Sstevel@tonic-gate rp.eax.byte.ah = 0x0; /* reset disk */ 206*0Sstevel@tonic-gate rp.edx.byte.dl = drivenum; 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 209*0Sstevel@tonic-gate 210*0Sstevel@tonic-gate status = rp.eax.byte.ah; 211*0Sstevel@tonic-gate 212*0Sstevel@tonic-gate if (((rp.eflags & PS_C) != 0) || status != 0) 213*0Sstevel@tonic-gate dprintf(("Bad disk reset driv %x, status %x\n", drivenum, 214*0Sstevel@tonic-gate status)); 215*0Sstevel@tonic-gate } 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gate /* Get first block */ 218*0Sstevel@tonic-gate static int 219*0Sstevel@tonic-gate read_firstblock(uchar_t drivenum) 220*0Sstevel@tonic-gate { 221*0Sstevel@tonic-gate 222*0Sstevel@tonic-gate struct bop_regs rp = {0}; 223*0Sstevel@tonic-gate caddr_t bufp; 224*0Sstevel@tonic-gate uchar_t status; 225*0Sstevel@tonic-gate int i, index; 226*0Sstevel@tonic-gate 227*0Sstevel@tonic-gate 228*0Sstevel@tonic-gate reset_disk(drivenum); 229*0Sstevel@tonic-gate bufp = (caddr_t)BIOS_RES_BUFFER_ADDR; 230*0Sstevel@tonic-gate 231*0Sstevel@tonic-gate 232*0Sstevel@tonic-gate rp.eax.byte.ah = 0x2; /* Read disk */ 233*0Sstevel@tonic-gate rp.eax.byte.al = 1; /* nsect */ 234*0Sstevel@tonic-gate rp.ecx.byte.ch = 0; /* cyl & 0xff */ 235*0Sstevel@tonic-gate rp.ecx.byte.cl = 1; /* cyl >> 2 & 0xc0 (sector number) */ 236*0Sstevel@tonic-gate rp.edx.byte.dh = 0; /* head */ 237*0Sstevel@tonic-gate rp.edx.byte.dl = drivenum; /* drivenum */ 238*0Sstevel@tonic-gate 239*0Sstevel@tonic-gate /* es:bx is buf address */ 240*0Sstevel@tonic-gate rp.ebx.word.bx = (uint16_t)FP_OFF((uint_t)(uintptr_t)bufp); 241*0Sstevel@tonic-gate rp.es = FP_SEG((uint_t)(uintptr_t)bufp); 242*0Sstevel@tonic-gate 243*0Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 244*0Sstevel@tonic-gate 245*0Sstevel@tonic-gate status = rp.eax.byte.ah; 246*0Sstevel@tonic-gate if (((rp.eflags & PS_C) != 0) || status != 0) { 247*0Sstevel@tonic-gate dprintf(("read_firstblock AH not clear %x \n", status)); 248*0Sstevel@tonic-gate return (0); 249*0Sstevel@tonic-gate } 250*0Sstevel@tonic-gate 251*0Sstevel@tonic-gate dprintf(("drivenum %x uid at 0x1b8 is %x\n", drivenum, 252*0Sstevel@tonic-gate *(uint32_t *)(bufp +0x1b8))); 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate index = drivenum - 0x80; 255*0Sstevel@tonic-gate 256*0Sstevel@tonic-gate biosdev_info[index].first_block_valid = 1; 257*0Sstevel@tonic-gate for (i = 0; i < 512; i++) 258*0Sstevel@tonic-gate biosdev_info[index].first_block[i] = *((uchar_t *)bufp + i); 259*0Sstevel@tonic-gate 260*0Sstevel@tonic-gate return (1); 261*0Sstevel@tonic-gate } 262