scsi.c revision 060711075893fd64c1eaaefe41f318d83011e4e3
/* $Id$ */
/** @file
* SCSI host adapter driver to boot from SCSI disks
*/
/*
* Copyright (C) 2004-2009 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/* The I/O port of the BusLogic SCSI adapter. */
#define BUSLOGIC_ISA_IO_PORT 0x330
/* The I/O port of the LsiLogic SCSI adapter. */
#define LSILOGIC_ISA_IO_PORT 0x340
#define VBOXSCSI_REGISTER_STATUS 0
#define VBOXSCSI_REGISTER_COMMAND 0
#define VBOXSCSI_REGISTER_DATA_IN 1
#define VBOXSCSI_REGISTER_IDENTIFY 2
#define VBOXSCSI_REGISTER_RESET 3
/* Command opcodes. */
#define SCSI_INQUIRY 0x12
#define SCSI_READ_CAPACITY 0x25
#define SCSI_READ_10 0x28
#define SCSI_WRITE_10 0x2a
/* Data transfer direction. */
#define SCSI_TXDIR_FROM_DEVICE 0
#define SCSI_TXDIR_TO_DEVICE 1
#define VBOXSCSI_BUSY (1 << 0)
//#define VBOX_SCSI_DEBUG 1 /* temporary */
#ifdef VBOX_SCSI_DEBUG
# define VBOXSCSI_DEBUG(a...) BX_INFO(a)
#else
# define VBOXSCSI_DEBUG(a...)
#endif
{
/* Check that the adapter is ready. */
Bit16u i;
do
{
} while (status & VBOXSCSI_BUSY);
/* Write target ID. */
/* Write transfer direction. */
/* Write the CDB size. */
/* Write buffer size. */
/* Write the CDB. */
for (i = 0; i < cbCDB; i++)
/* Now wait for the command to complete. */
do
{
} while (status & VBOXSCSI_BUSY);
#if 0
/* Get the read data. */
for (i = 0; i < cbBuffer; i++)
{
}
#else
#endif
return 0;
}
{
/* Check that the adapter is ready. */
Bit16u i;
do
{
} while (status & VBOXSCSI_BUSY);
/* Write target ID. */
/* Write transfer direction. */
/* Write the CDB size. */
/* Write buffer size. */
/* Write the CDB. */
for (i = 0; i < cbCDB; i++)
/* Write data to I/O port. */
for (i = 0; i < cbBuffer; i++)
{
}
/* Now wait for the command to complete. */
do
{
} while (status & VBOXSCSI_BUSY);
return 0;
}
/**
* Read sectors from an attached scsi device.
*
* @returns status code.
* @param device_id Id of the SCSI device to read from.
* @param count The number of sectors to read.
* @param lba The start sector to read from.
* @param segment The segment the buffer is in.
* @param offset The offset of the buffer.
*/
{
if (device_id > BX_MAX_SCSI_DEVICES)
// Reset count of transferred data
/* Prepare CDB */
if (!rc)
{
}
return rc;
}
/**
* Write sectors to an attached scsi device.
*
* @returns status code.
* @param device_id Id of the SCSI device to write to.
* @param count The number of sectors to write.
* @param lba The start sector to write to.
* @param segment The segment the buffer is in.
* @param offset The offset of the buffer.
*/
{
if (device_id > BX_MAX_SCSI_DEVICES)
// Reset count of transferred data
/* Prepare CDB */
if (!rc)
{
}
return rc;
}
/**
* Enumerate attached devices.
*
* @returns nothing.
* @param io_base The I/O base port of the controller.
*/
{
Bit8u i;
/* Go through target devices. */
for (i = 0; i < VBOXSCSI_MAX_DEVICES; i++)
{
Bit8u z;
if (rc != 0)
BX_PANIC("scsi_enumerate_attached_devices: SCSI_INQUIRY failed\n");
/* Check if there is a disk attached. */
if ( ((buffer[0] & 0xe0) == 0)
{
VBOXSCSI_DEBUG("scsi_enumerate_attached_devices: Disk detected at %d\n", i);
/* We add the disk only if the maximum is not reached yet. */
{
/* Issue a read capacity command now. */
if (rc != 0)
BX_PANIC("scsi_enumerate_attached_devices: SCSI_READ_CAPACITY failed\n");
/* Build sector number and size from the buffer. */
/* We only support the disk if sector size is 512 bytes. */
if (sector_size != 512)
{
/* Leave a log entry. */
continue;
}
/* We need to calculate the geometry for the disk. */
if (io_base == BUSLOGIC_ISA_IO_PORT)
{
/* This is from the BusLogic driver in the Linux kernel. */
{
heads = 255;
sectors_per_track = 63;
}
{
heads = 128;
sectors_per_track = 32;
}
else
{
heads = 64;
sectors_per_track = 32;
}
}
else if (io_base == LSILOGIC_ISA_IO_PORT)
{
/* This is from the BusLogic driver in the Linux kernel. */
{
heads = 255;
sectors_per_track = 63;
}
{
heads = 128;
sectors_per_track = 32;
}
else
{
heads = 64;
sectors_per_track = 32;
}
}
write_byte(ebda_seg, &EbdaData->scsi.devices[hdcount_scsi].device_info.translation, ATA_TRANSLATION_LBA);
/* Write lchs values. */
write_word(ebda_seg, &EbdaData->scsi.devices[hdcount_scsi].device_info.lchs.spt, sectors_per_track);
if (cylinders > 1024)
else
write_word(ebda_seg, &EbdaData->scsi.devices[hdcount_scsi].device_info.lchs.cylinders, (Bit16u)cylinders);
/* Write pchs values. */
write_word(ebda_seg, &EbdaData->scsi.devices[hdcount_scsi].device_info.pchs.spt, sectors_per_track);
if (cylinders > 1024)
else
write_word(ebda_seg, &EbdaData->scsi.devices[hdcount_scsi].device_info.pchs.cylinders, (Bit16u)cylinders);
/* Store the id of the disk in the ata hdidmap. */
hdcount++;
hdcount_scsi++;
}
else
{
/* We reached the maximum of SCSI disks we can boot from. We can quit detecting. */
break;
}
}
else
VBOXSCSI_DEBUG("scsi_enumerate_attached_devices: No disk detected at %d\n", i);
}
}
/**
* Init the SCSI driver and detect attached disks.
*/
void scsi_init( )
{
identifier = 0;
/* Detect BusLogic adapter. */
if (identifier == 0x55)
{
/* Detected - Enumerate attached devices. */
VBOXSCSI_DEBUG("scsi_init: BusLogic SCSI adapter detected\n");
}
else
{
VBOXSCSI_DEBUG("scsi_init: BusLogic SCSI adapter not detected\n");
}
/* Detect LsiLogic adapter. */
if (identifier == 0x55)
{
/* Detected - Enumerate attached devices. */
VBOXSCSI_DEBUG("scsi_init: LsiLogic SCSI adapter detected\n");
}
else
{
VBOXSCSI_DEBUG("scsi_init: LsiLogic SCSI adapter not detected\n");
}
}