scsi.c revision 367dfc76faea958fa6765efde770d4cc30f51295
/* $Id$ */
/** @file
* SCSI host adapter driver to boot from SCSI disks
*/
/*
* Copyright (C) 2004-2011 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"
//#define VBOX_SCSI_DEBUG 1 /* temporary */
#ifdef VBOX_SCSI_DEBUG
#else
# define VBSCSI_DEBUG(...)
#endif
#define VBSCSI_BUSY (1 << 0)
/* The I/O port of the BusLogic SCSI adapter. */
#define BUSLOGIC_BIOS_IO_PORT 0x330
/* The I/O port of the LsiLogic SCSI adapter. */
#define LSILOGIC_BIOS_IO_PORT 0x340
/* The I/O port of the LsiLogic SAS adapter. */
#define LSILOGIC_SAS_BIOS_IO_PORT 0x350
#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
/* 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()
{
/* Check that the adapter is ready. */
uint16_t i;
do
{
} while (status & VBSCSI_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 & VBSCSI_BUSY);
/* Get the read data. */
return 0;
}
{
/* Check that the adapter is ready. */
uint16_t i;
do
{
} while (status & VBSCSI_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. */
/* 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;
}
/**
* 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)
BX_PANIC("scsi_enumerate_attached_devices: SCSI_INQUIRY failed\n");
/* Check if there is a disk attached. */
if ( ((buffer[0] & 0xe0) == 0)
{
VBSCSI_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. */
aCDB[0] = SCSI_READ_CAPACITY;
if (rc != 0)
BX_PANIC("scsi_enumerate_attached_devices: SCSI_READ_CAPACITY failed\n");
/* 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;
}
/* We need to calculate the geometry for the disk. 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;
}
/* 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++;
hdcount_scsi++;
}
else
{
/* We reached the maximum of SCSI disks we can boot from. We can quit detecting. */
break;
}
}
else
VBSCSI_DEBUG("scsi_enumerate_attached_devices: No disk detected at %d\n", i);
}
}
/**
* Init the SCSI driver and detect attached disks.
*/
{
bios_dsk->scsi_hdcount = 0;
identifier = 0;
/* Detect BusLogic adapter. */
if (identifier == 0x55)
{
/* Detected - Enumerate attached devices. */
VBSCSI_DEBUG("scsi_init: BusLogic SCSI adapter detected\n");
}
else
{
VBSCSI_DEBUG("scsi_init: BusLogic SCSI adapter not detected\n");
}
/* Detect LsiLogic adapter. */
if (identifier == 0x55)
{
/* Detected - Enumerate attached devices. */
VBSCSI_DEBUG("scsi_init: LSI Logic SCSI adapter detected\n");
}
else
{
VBSCSI_DEBUG("scsi_init: LSI Logic SCSI adapter not detected\n");
}
/* Detect LsiLogic SAS adapter. */
if (identifier == 0x55)
{
/* Detected - Enumerate attached devices. */
VBSCSI_DEBUG("scsi_init: LSI Logic SAS adapter detected\n");
}
else
{
VBSCSI_DEBUG("scsi_init: LSI Logic SAS adapter not detected\n");
}
}