ATAController.h revision ad8fb8c920c36650d5ead020ef8e05b681dd4375
/* $Id$ */
/** @file
*/
/*
* Copyright (C) 2006-2008 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.
*/
#ifndef ___Storage_ATAController_h
#define ___Storage_ATAController_h
/*******************************************************************************
* Header Files *
*******************************************************************************/
#ifdef IN_RING3
# include <iprt/semaphore.h>
#endif /* IN_RING3 */
#include <iprt/critsect.h>
#include "PIIX3ATABmDma.h"
#include "ide.h"
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/**
* Set to 1 to disable multi-sector read support. According to the ATA
* specification this must be a power of 2 and it must fit in an 8 bit
* value. Thus the only valid values are 1, 2, 4, 8, 16, 32, 64 and 128.
*/
#define ATA_MAX_MULT_SECTORS 128
/**
* Fastest PIO mode supported by the drive.
*/
#define ATA_PIO_MODE_MAX 4
/**
* Fastest MDMA mode supported by the drive.
*/
#define ATA_MDMA_MODE_MAX 2
/**
* Fastest UDMA mode supported by the drive.
*/
#define ATA_UDMA_MODE_MAX 6
/** ATAPI sense info size. */
#define ATAPI_SENSE_SIZE 64
/** The maximum number of release log entries per device. */
#define MAX_LOG_REL_ERRORS 1024
/* MediaEventStatus */
#define ATA_EVENT_STATUS_UNCHANGED 0 /**< medium event status not changed */
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct AHCIATADevState {
/** Flag indicating whether the current command uses LBA48 mode. */
bool fLBA48;
/** Flag indicating whether this drive implements the ATAPI command set. */
bool fATAPI;
/** Set if this interface has asserted the IRQ. */
bool fIrqPending;
/** Currently configured number of sectors in a multi-sector transfer. */
/** PCHS disk geometry. */
/** Total number of sectors on this disk. */
/** Number of sectors to transfer per IRQ. */
/** Current transfer direction. */
/** Index of callback for begin transfer. */
/** Flag indicating whether the current command transfers data in DMA mode. */
bool fDMA;
/** Set to indicate that ATAPI transfer semantics must be used. */
bool fATAPITransfer;
/** ATAPI current LBA position. */
/** ATAPI current sector size. */
/** ATAPI current command. */
/** ATAPI sense data. */
/** HACK: Countdown till we report a newly unmounted drive as mounted. */
/** The same for GET_EVENT_STATUS for mechanism */
volatile uint32_t MediaEventStatus;
/** The status LED state for this drive. */
#if HC_ARCH_BITS == 64
#endif
/** Size of I/O buffer. */
/** Pointer to the I/O buffer. */
/** Pointer to the I/O buffer. */
/** Pointer to the I/O buffer. */
/*
* No data that is part of the saved state after this point!!!!!
*/
/* Release statistics: number of ATA DMA commands. */
/* Release statistics: number of ATA PIO commands. */
/* Release statistics: number of ATAPI PIO commands. */
/* Release statistics: number of ATAPI PIO commands. */
#ifdef VBOX_INSTRUMENT_DMA_WRITES
/* Release statistics: number of DMA sector writes and the time spent. */
#endif
/** Statistics: number of read operations and the time spent reading. */
/** Statistics: number of bytes read. */
#if HC_ARCH_BITS == 64
#endif
/** Statistics: number of write operations and the time spent writing. */
/** Statistics: number of bytes written. */
#if HC_ARCH_BITS == 64
#endif
/** Statistics: number of flush operations and the time spend flushing. */
/** Enable passing through commands directly to the ATAPI drive. */
bool fATAPIPassthrough;
/** Number of errors we've reported to the release log.
* This is to prevent flooding caused by something going horribly wrong.
* this value against MAX_LOG_REL_ERRORS in places likely to cause floods
* like the ones we currently seeing on the linux smoke tests (2006-11-10). */
/** Timestamp of last started command. 0 if no command pending. */
/** Pointer to the attached driver's base interface. */
/** Pointer to the attached driver's block interface. */
/** Pointer to the attached driver's block bios interface. */
/** Pointer to the attached driver's mount interface.
* This is NULL if the driver isn't a removable unit. */
/** The base interface. */
/** The block port interface. */
/** The mount notify interface. */
/** The LUN #. */
#if HC_ARCH_BITS == 64
#endif
/** Pointer to device instance. */
/** Pointer to controller instance. */
/** Pointer to device instance. */
/** Pointer to controller instance. */
/** Pointer to device instance. */
/** Pointer to controller instance. */
typedef struct AHCIATATransferRequest
{
typedef struct AHCIATAAbortRequest
{
bool fResetDrive;
typedef enum
{
/** Begin a new transfer. */
AHCIATA_AIO_NEW = 0,
/** Continue a DMA transfer. */
/** Continue a PIO transfer. */
/** Reset the drives on current controller, stop all transfer activity. */
/** Reset the drives on current controller, resume operation. */
/** Abort the current transfer of a particular drive. */
} AHCIATAAIO;
typedef struct AHCIATARequest
{
union
{
} u;
typedef struct AHCIATACONTROLLER
{
/** The base of the first I/O Port range. */
/** The base of the second I/O Port range. (0 if none) */
/** The assigned IRQ. */
/** Access critical section */
/** Selected drive. */
/** The interface on which to handle async I/O. */
/** The state of the async I/O thread. */
/** Flag indicating whether the next transfer is part of the current command. */
bool fChainedTransfer;
/** Set when the reset processing is currently active on this controller. */
bool fReset;
/** Flag whether the current transfer needs to be redone. */
bool fRedo;
/** Flag whether the redo suspend has been finished. */
bool fRedoIdle;
/** Flag whether the DMA operation to be redone is the final transfer. */
bool fRedoDMALastDesc;
/** The BusMaster DMA state. */
/** Pointer to first DMA descriptor. */
/** Pointer to last DMA descriptor. */
/** Pointer to current DMA buffer (for redo operations). */
/** Size of current DMA buffer (for redo operations). */
/** Pointer to device instance. */
/** Pointer to device instance. */
/** Pointer to device instance. */
/** Set when the destroying the device instance and the thread must exit. */
/** The async I/O thread handle. NIL_RTTHREAD if no thread. */
/** The event semaphore the thread is waiting on for requests. */
/** The request queue for the AIO thread. One element is always unused. */
/** The position at which to insert a new request for the AIO thread. */
/** The position at which to get a new request for the AIO thread. */
/** Whether to call RTThreadUserSignal when idle.
* Before setting this, call RTThreadUserReset. */
bool volatile fSignalIdle;
/** Magic delay before triggering interrupts in DMA mode. */
/** The mutex protecting the request queue. */
/** The event semaphore the thread is waiting on during suspended I/O. */
#if 0 /*HC_ARCH_BITS == 32*/
#endif
/* Statistics */
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
#define PDMIBASE_2_ATASTATE(pInterface) ( (AHCIATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(AHCIATADevState, IBase)) )
/*******************************************************************************
* Internal Functions *
******************************************************************************/
int ataControllerIOPortWriteStr1(PAHCIATACONTROLLER pCtl, RTIOPORT Port, RTGCPTR *pGCPtrSrc, PRTGCUINTREG pcTransfer, unsigned cb);
int ataControllerIOPortReadStr1(PAHCIATACONTROLLER pCtl, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfer, unsigned cb);
int ataControllerBMDMAIOPortRead(PAHCIATACONTROLLER pCtl, RTIOPORT Port, uint32_t *pu32, unsigned cb);
int ataControllerBMDMAIOPortWrite(PAHCIATACONTROLLER pCtl, RTIOPORT Port, uint32_t u32, unsigned cb);
#ifdef IN_RING3
/**
* Initialize a controller state.
*
* @returns VBox status code.
* @param pDevIns Pointer to the device instance which creates a controller.
* @param pCtl Pointer to the unitialized ATA controller structure.
* @param pDrvBaseMaster Pointer to the base driver interface which acts as the master.
* @param pDrvBaseSlave Pointer to the base driver interface which acts as the slave.
* @param szName Name of the controller (Used to initialize the critical section).
*/
int ataControllerInit(PPDMDEVINS pDevIns, PAHCIATACONTROLLER pCtl, PPDMIBASE pDrvBaseMaster, PPDMIBASE pDrvBaseSlave,
uint32_t *pcbSSMState, const char *szName, PPDMLED pLed, PSTAMCOUNTER pStatBytesRead, PSTAMCOUNTER pStatBytesWritten);
/**
* Free all allocated resources for one controller instance.
*
* @returns VBox status code.
* @param pCtl The controller instance.
*/
/**
* Power off a controller.
*
* @returns nothing.
* @param pCtl the controller instance.
*/
/**
* Reset a controller instance to an initial state.
*
* @returns VBox status code.
* @param pCtl Pointer to the controller.
*/
/**
* Suspend operation of an controller.
*
* @returns nothing
* @param pCtl The controller instance.
*/
/**
* Resume operation of an controller.
*
* @returns nothing
* @param pCtl The controller instance.
*/
/**
* Relocate neccessary pointers.
*
* @returns nothing.
* @param pCtl The controller instance.
* @param offDelta The relocation delta relative to the old location.
*/
/**
* Execute state save operation.
*
* @returns VBox status code.
* @param pCtl The controller instance.
* @param pSSM SSM operation handle.
*/
/**
* Prepare state save operation.
*
* @returns VBox status code.
* @param pCtl The controller instance.
* @param pSSM SSM operation handle.
*/
/**
* Excute state load operation.
*
* @returns VBox status code.
* @param pCtl The controller instance.
* @param pSSM SSM operation handle.
*/
/**
* Prepare state load operation.
*
* @returns VBox status code.
* @param pCtl The controller instance.
* @param pSSM SSM operation handle.
*/
#endif /* IN_RING3 */
#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
#endif /* !___Storage_ATAController_h */