scsi.c revision 8a2c7cae7578acfb7c77a510f12fabee2670e31c
/* $Id$ */
/** @file
* SCSI host adapter driver to boot from SCSI disks
*/
/*
* Copyright (C) 2004-2012 Oracle Corporation
*
* 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.
*/
#include <stdint.h>
#include <string.h>
#include "biosint.h"
#include "inlines.h"
#include "ebda.h"
#if DEBUG_SCSI
#else
# define DBG_SCSI(...)
#endif
#define VBSCSI_BUSY (1 << 0)
/* The I/O port of the BusLogic SCSI adapter. */
#define BUSLOGIC_BIOS_IO_PORT 0x430
/* The I/O port of the LsiLogic SCSI adapter. */
#define LSILOGIC_BIOS_IO_PORT 0x434
/* The I/O port of the LsiLogic SAS adapter. */
#define LSILOGIC_SAS_BIOS_IO_PORT 0x438
#define VBSCSI_REGISTER_STATUS 0
#define VBSCSI_REGISTER_COMMAND 0
#define VBSCSI_REGISTER_DATA_IN 1
#define VBSCSI_REGISTER_IDENTIFY 2
#define VBSCSI_REGISTER_RESET 3
#define VBSCSI_REGISTER_DEVSTAT 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
#pragma pack(1)
typedef struct {
} cdb_rw10;
#pragma pack()
#pragma aux insb_discard = \
".286" \
"again:" \
"in al,dx" \
"loop again" \
{
/* Check that the adapter is ready. */
uint16_t i;
do
while (status & VBSCSI_BUSY);
outb(io_base + VBSCSI_REGISTER_COMMAND, SCSI_TXDIR_FROM_DEVICE); /* Write the transfer direction. */
for (i = 0; i < cbCDB; i++) /* Write the CDB. */
/* Now wait for the command to complete. */
do
while (status & VBSCSI_BUSY);
/* Read in the data. The transfer length may be exactly 64K or more,
* which needs a bit of care when we're using 16-bit 'rep ins'.
*/
while (length > 32768) {
length -= 32768;
}
return 0;
}
{
/* Check that the adapter is ready. */
uint16_t i;
do
while (status & VBSCSI_BUSY);
for (i = 0; i < cbCDB; i++) /* Write the CDB. */
/* Write out the data. The transfer length may be exactly 64K or more,
* which needs a bit of care when we're using 16-bit 'rep outs'.
*/
while (length > 32768) {
length -= 32768;
}
/* Now wait for the command to complete. */
do
while (status & VBSCSI_BUSY);
return 0;
}
/**
* Read sectors from an attached SCSI device.
*
* @returns status code.
* @param bios_dsk Pointer to disk request packet (in the
* EBDA).
*/
{
if (device_id > BX_MAX_SCSI_DEVICES)
/* Prepare a CDB. */
if (!rc)
{
}
return rc;
}
/**
* Write sectors to an attached SCSI device.
*
* @returns status code.
* @param bios_dsk Pointer to disk request packet (in the
* EBDA).
*/
{
if (device_id > BX_MAX_SCSI_DEVICES)
/* Prepare a CDB. */
if (!rc)
{
}
return rc;
}
//@todo: move
#define ATA_DATA_NO 0x00
#define ATA_DATA_IN 0x01
#define ATA_DATA_OUT 0x02
/**
* Perform a "packet style" read with supplied CDB.
*
* @returns status code.
* @param bios_dsk Pointer to disk request packet (in the
* EBDA).
*/
{
uint16_t i;
/* Data out is currently not supported. */
if (inout == ATA_DATA_OUT) {
return 1;
}
/* Convert to SCSI specific device number. */
/* Wait until the adapter is ready. */
do
while (status & VBSCSI_BUSY);
/* On the SCSI level, we have to transfer whole sectors. */
/* NB: With proper residual length support, this should not be necessary; we should
* be able to avoid transferring the 'after' part of the sector.
*/
outb(io_base + VBSCSI_REGISTER_COMMAND, SCSI_TXDIR_FROM_DEVICE); /* Write the transfer direction. */
for (i = 0; i < cmdlen; i++) /* Write the CDB. */
/* Now wait for the command to complete. */
do
while (status & VBSCSI_BUSY);
/* If any error occurred, inform the caller and don't bother reading the data. */
if (status & VBSCSI_ERROR) {
return 3;
}
/* Transfer the data read from the device. */
if (before) /* If necessary, throw away data which needs to be skipped. */
/* The requested length may be exactly 64K or more, which needs
* a bit of care when we're using 16-bit 'rep ins'.
*/
while (length > 32768) {
length -= 32768;
}
return 0;
}
/**
* Enumerate attached devices.
*
* @returns nothing.
* @param io_base The I/O base port of the controller.
*/
{
int i;
/* Go through target devices. */
for (i = 0; i < VBSCSI_MAX_DEVICES; i++)
{
aCDB[0] = SCSI_INQUIRY;
aCDB[1] = 0;
aCDB[2] = 0;
aCDB[3] = 0;
aCDB[5] = 0;
if (rc != 0)
/* Check the attached device. */
if ( ((buffer[0] & 0xe0) == 0)
{
/* We add the disk only if the maximum is not reached yet. */
{
/* Issue a read capacity command now. */
aCDB[0] = SCSI_READ_CAPACITY;
if (rc != 0)
/* Build sector number and size from the buffer. */
//@todo: byte swapping for dword sized items should be farmed out...
/* We only support the disk if sector size is 512 bytes. */
if (sector_size != 512)
{
/* Leave a log entry. */
continue;
}
/* Get logical CHS geometry. */
switch (devcount_scsi)
{
case 0:
cmos_base = 0x90;
break;
case 1:
cmos_base = 0x98;
break;
case 2:
cmos_base = 0xA0;
break;
case 3:
cmos_base = 0xA8;
break;
default:
cmos_base = 0;
}
{
/* If provided, grab the logical geometry from CMOS. */
}
else
{
/* Calculate default logical geometry. NB: Very different
*/
{
heads = 255;
sectors_per_track = 63;
}
{
heads = 128;
sectors_per_track = 32;
}
else
{
heads = 64;
sectors_per_track = 32;
}
}
/* Calculate index into the generic disk table. */
/* Write LCHS values. */
if (cylinders > 1024)
else
/* Write PCHS values. */
if (cylinders > 1024)
else
/* Store the id of the disk in the ata hdidmap. */
hdcount++;
/* Update hdcount in the BDA. */
hdcount++;
}
else
{
/* We reached the maximum of SCSI disks we can boot from. We can quit detecting. */
break;
}
}
else if ( ((buffer[0] & 0xe0) == 0)
{
/* Calculate index into the generic device table. */
/* Store the ID of the device in the BIOS cdidmap. */
cdcount++;
}
else
}
}
/**
* Init the SCSI driver and detect attached disks.
*/
{
bios_dsk->scsi_devcount = 0;
identifier = 0;
/* Detect the BusLogic adapter. */
if (identifier == 0x55)
{
/* Detected - Enumerate attached devices. */
}
else
{
}
/* Detect the LSI Logic parallel SCSI adapter. */
if (identifier == 0x55)
{
/* Detected - Enumerate attached devices. */
}
else
{
}
/* Detect the LSI Logic SAS adapter. */
if (identifier == 0x55)
{
/* Detected - Enumerate attached devices. */
}
else
{
}
}