10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*5084Sjohnlev * Common Development and Distribution License (the "License"). 6*5084Sjohnlev * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*5084Sjohnlev * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/param.h> 300Sstevel@tonic-gate #include <sys/controlregs.h> 310Sstevel@tonic-gate #include <sys/bootconf.h> 320Sstevel@tonic-gate #include <sys/bootvfs.h> 330Sstevel@tonic-gate #include <sys/bootregs.h> 340Sstevel@tonic-gate #include <sys/bootconf.h> 350Sstevel@tonic-gate #include <sys/conf.h> 360Sstevel@tonic-gate #include <sys/promif.h> 370Sstevel@tonic-gate #include <sys/ddi.h> 380Sstevel@tonic-gate #include <sys/sunddi.h> 390Sstevel@tonic-gate #include <sys/sunndi.h> 400Sstevel@tonic-gate #include <sys/biosdisk.h> 410Sstevel@tonic-gate #include <sys/psw.h> 42*5084Sjohnlev #if defined(__xpv) 43*5084Sjohnlev #include <sys/hypervisor.h> 44*5084Sjohnlev #endif 450Sstevel@tonic-gate 460Sstevel@tonic-gate 470Sstevel@tonic-gate /* hard code realmode memory address for now */ 480Sstevel@tonic-gate #define BIOS_RES_BUFFER_ADDR 0x7000 490Sstevel@tonic-gate 500Sstevel@tonic-gate #define BIOSDEV_NUM 8 510Sstevel@tonic-gate #define STARTING_DRVNUM 0x80 520Sstevel@tonic-gate #define FP_OFF(fp) (((uintptr_t)(fp)) & 0xFFFF) 530Sstevel@tonic-gate #define FP_SEG(fp) ((((uintptr_t)(fp)) >> 16) & 0xFFFF) 540Sstevel@tonic-gate 550Sstevel@tonic-gate #ifdef DEBUG 560Sstevel@tonic-gate int biosdebug = 0; 570Sstevel@tonic-gate #define dprintf(fmt) \ 580Sstevel@tonic-gate if (biosdebug) \ 590Sstevel@tonic-gate prom_printf fmt 600Sstevel@tonic-gate #else 610Sstevel@tonic-gate #define dprintf(fmt) 620Sstevel@tonic-gate #endif 630Sstevel@tonic-gate 640Sstevel@tonic-gate biosdev_data_t biosdev_info[BIOSDEV_NUM]; /* from 0x80 to 0x87 */ 650Sstevel@tonic-gate int dobiosdev = 1; 660Sstevel@tonic-gate 670Sstevel@tonic-gate 680Sstevel@tonic-gate static int bios_check_extension_present(uchar_t); 690Sstevel@tonic-gate static int get_dev_params(uchar_t); 700Sstevel@tonic-gate static int read_firstblock(uchar_t drivenum); 710Sstevel@tonic-gate static int drive_present(uchar_t drivenum); 720Sstevel@tonic-gate static void reset_disk(uchar_t drivenum); 730Sstevel@tonic-gate 740Sstevel@tonic-gate 750Sstevel@tonic-gate void 760Sstevel@tonic-gate startup_bios_disk() 770Sstevel@tonic-gate { 780Sstevel@tonic-gate uchar_t drivenum; 790Sstevel@tonic-gate int got_devparams = 0; 800Sstevel@tonic-gate int got_first_block = 0; 810Sstevel@tonic-gate uchar_t name[20]; 820Sstevel@tonic-gate dev_info_t *devi; 830Sstevel@tonic-gate 84*5084Sjohnlev #if defined(__xpv) 85*5084Sjohnlev if (!DOMAIN_IS_INITDOMAIN(xen_info)) 86*5084Sjohnlev return; 87*5084Sjohnlev #endif 88*5084Sjohnlev 890Sstevel@tonic-gate if (dobiosdev == 0) 900Sstevel@tonic-gate return; 910Sstevel@tonic-gate 920Sstevel@tonic-gate for (drivenum = 0x80; drivenum < (0x80 + BIOSDEV_NUM); drivenum++) { 930Sstevel@tonic-gate 940Sstevel@tonic-gate if (!drive_present(drivenum)) 950Sstevel@tonic-gate continue; 960Sstevel@tonic-gate 970Sstevel@tonic-gate got_devparams = get_dev_params(drivenum); 980Sstevel@tonic-gate 990Sstevel@tonic-gate if ((got_first_block = read_firstblock(drivenum)) == 0) { 1000Sstevel@tonic-gate /* retry */ 1010Sstevel@tonic-gate got_first_block = read_firstblock(drivenum); 1020Sstevel@tonic-gate } 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate if (got_devparams || got_first_block) { 1050Sstevel@tonic-gate (void) sprintf((char *)name, "biosdev-0x%x", drivenum); 1060Sstevel@tonic-gate devi = ddi_root_node(); 1070Sstevel@tonic-gate (void) e_ddi_prop_update_byte_array(DDI_DEV_T_NONE, 1080Sstevel@tonic-gate devi, (char *)name, 1090Sstevel@tonic-gate (uchar_t *)&biosdev_info[drivenum - 0x80], 1100Sstevel@tonic-gate sizeof (biosdev_data_t)); 1110Sstevel@tonic-gate } 1120Sstevel@tonic-gate } 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate static int 1160Sstevel@tonic-gate bios_check_extension_present(uchar_t drivenum) 1170Sstevel@tonic-gate { 1180Sstevel@tonic-gate struct bop_regs rp = {0}; 1190Sstevel@tonic-gate extern struct bootops *bootops; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate rp.eax.word.ax = 0x4100; 1220Sstevel@tonic-gate rp.ebx.word.bx = 0x55AA; 1230Sstevel@tonic-gate rp.edx.word.dx = drivenum; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* make sure we have extension support */ 1260Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate if (((rp.eflags & PS_C) != 0) || (rp.ebx.word.bx != 0xAA55)) { 1290Sstevel@tonic-gate dprintf(("bios_check_extension_present int13 fn 41 " 1300Sstevel@tonic-gate "failed %d bx = %x\n", rp.eflags, rp.ebx.word.bx)); 1310Sstevel@tonic-gate return (0); 1320Sstevel@tonic-gate } 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate if ((rp.ecx.word.cx & 0x7) == 0) { 1350Sstevel@tonic-gate dprintf(("bios_check_extension_present get device parameters " 1360Sstevel@tonic-gate "not supported cx = %x\n", rp.ecx.word.cx)); 1370Sstevel@tonic-gate return (0); 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate return (1); 1410Sstevel@tonic-gate } 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate static int 1440Sstevel@tonic-gate get_dev_params(uchar_t drivenum) 1450Sstevel@tonic-gate { 1460Sstevel@tonic-gate struct bop_regs rp = {0}; 1470Sstevel@tonic-gate fn48_t *bufp; 1480Sstevel@tonic-gate extern struct bootops *bootops; 1490Sstevel@tonic-gate int i; 1500Sstevel@tonic-gate int index; 151175Sjg uchar_t *tmp; 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate dprintf(("In get_dev_params\n")); 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate if (bios_check_extension_present(drivenum) == 0) 1560Sstevel@tonic-gate return (0); 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate bufp = (fn48_t *)BIOS_RES_BUFFER_ADDR; 1590Sstevel@tonic-gate 160175Sjg /* 161175Sjg * We cannot use bzero here as we're initializing data 162175Sjg * at an address below kernel base. 163175Sjg */ 1640Sstevel@tonic-gate for (i = 0; i < sizeof (*bufp); i++) 1650Sstevel@tonic-gate ((uchar_t *)bufp)[i] = 0; 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate bufp->buflen = sizeof (*bufp); 1680Sstevel@tonic-gate rp.eax.word.ax = 0x4800; 1690Sstevel@tonic-gate rp.edx.byte.dl = drivenum; 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate rp.esi.word.si = (uint16_t)FP_OFF((uint_t)(uintptr_t)bufp); 1720Sstevel@tonic-gate rp.ds = FP_SEG((uint_t)(uintptr_t)bufp); 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate if ((rp.eflags & PS_C) != 0) { 1770Sstevel@tonic-gate dprintf(("EDD FAILED on drive eflag = %x ah= %x\n", 1780Sstevel@tonic-gate rp.eflags, rp.eax.byte.ah)); 1790Sstevel@tonic-gate return (0); 1800Sstevel@tonic-gate } 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate index = drivenum - 0x80; 1830Sstevel@tonic-gate biosdev_info[index].edd_valid = 1; 184175Sjg 185175Sjg /* 186175Sjg * Some compilers turn a structure copy into a call 187175Sjg * to memcpy. Since we are copying data below kernel 188175Sjg * base intentionally, and memcpy asserts that's not 189175Sjg * the case, we do the copy manually here. 190175Sjg */ 191175Sjg tmp = (uchar_t *)&biosdev_info[index].fn48_dev_params; 192175Sjg for (i = 0; i < sizeof (*bufp); i++) 193175Sjg tmp[i] = ((uchar_t *)bufp)[i]; 1940Sstevel@tonic-gate 1950Sstevel@tonic-gate return (1); 1960Sstevel@tonic-gate } 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate static int 1990Sstevel@tonic-gate drive_present(uchar_t drivenum) 2000Sstevel@tonic-gate { 2010Sstevel@tonic-gate struct bop_regs rp = {0}; 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate rp.eax.byte.ah = 0x8; /* get params */ 2040Sstevel@tonic-gate rp.edx.byte.dl = drivenum; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate if (((rp.eflags & PS_C) != 0) || rp.eax.byte.ah != 0) { 2090Sstevel@tonic-gate dprintf(("drive not present drivenum %x eflag %x ah %x\n", 210*5084Sjohnlev drivenum, rp.eflags, rp.eax.byte.ah)); 2110Sstevel@tonic-gate return (0); 2120Sstevel@tonic-gate } 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate dprintf(("drive-present %x\n", drivenum)); 2150Sstevel@tonic-gate return (1); 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate } 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate static void 2200Sstevel@tonic-gate reset_disk(uchar_t drivenum) 2210Sstevel@tonic-gate { 2220Sstevel@tonic-gate struct bop_regs rp = {0}; 2230Sstevel@tonic-gate int status; 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate rp.eax.byte.ah = 0x0; /* reset disk */ 2260Sstevel@tonic-gate rp.edx.byte.dl = drivenum; 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate status = rp.eax.byte.ah; 2310Sstevel@tonic-gate 2320Sstevel@tonic-gate if (((rp.eflags & PS_C) != 0) || status != 0) 2330Sstevel@tonic-gate dprintf(("Bad disk reset driv %x, status %x\n", drivenum, 2340Sstevel@tonic-gate status)); 2350Sstevel@tonic-gate } 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate /* Get first block */ 2380Sstevel@tonic-gate static int 2390Sstevel@tonic-gate read_firstblock(uchar_t drivenum) 2400Sstevel@tonic-gate { 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate struct bop_regs rp = {0}; 2430Sstevel@tonic-gate caddr_t bufp; 2440Sstevel@tonic-gate uchar_t status; 2450Sstevel@tonic-gate int i, index; 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate reset_disk(drivenum); 2490Sstevel@tonic-gate bufp = (caddr_t)BIOS_RES_BUFFER_ADDR; 2500Sstevel@tonic-gate 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate rp.eax.byte.ah = 0x2; /* Read disk */ 2530Sstevel@tonic-gate rp.eax.byte.al = 1; /* nsect */ 2540Sstevel@tonic-gate rp.ecx.byte.ch = 0; /* cyl & 0xff */ 2550Sstevel@tonic-gate rp.ecx.byte.cl = 1; /* cyl >> 2 & 0xc0 (sector number) */ 2560Sstevel@tonic-gate rp.edx.byte.dh = 0; /* head */ 2570Sstevel@tonic-gate rp.edx.byte.dl = drivenum; /* drivenum */ 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate /* es:bx is buf address */ 2600Sstevel@tonic-gate rp.ebx.word.bx = (uint16_t)FP_OFF((uint_t)(uintptr_t)bufp); 2610Sstevel@tonic-gate rp.es = FP_SEG((uint_t)(uintptr_t)bufp); 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate BOP_DOINT(bootops, 0x13, &rp); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate status = rp.eax.byte.ah; 2660Sstevel@tonic-gate if (((rp.eflags & PS_C) != 0) || status != 0) { 2670Sstevel@tonic-gate dprintf(("read_firstblock AH not clear %x \n", status)); 2680Sstevel@tonic-gate return (0); 2690Sstevel@tonic-gate } 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate dprintf(("drivenum %x uid at 0x1b8 is %x\n", drivenum, 2720Sstevel@tonic-gate *(uint32_t *)(bufp +0x1b8))); 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate index = drivenum - 0x80; 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate biosdev_info[index].first_block_valid = 1; 2770Sstevel@tonic-gate for (i = 0; i < 512; i++) 2780Sstevel@tonic-gate biosdev_info[index].first_block[i] = *((uchar_t *)bufp + i); 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate return (1); 2810Sstevel@tonic-gate } 282