DevATA.cpp revision 1a52e1a951d21e8f7c5a2e69032c744d7f8265c5
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * VBox storage devices: ATA/ATAPI controller device (disk and cdrom).
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * Copyright (C) 2006-2008 Sun Microsystems, Inc.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * available from http://www.virtualbox.org. This file is free software;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * you can redistribute it and/or modify it under the terms of the GNU
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * General Public License (GPL) as published by the Free Software
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * additional information or have any questions.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Defined Constants And Macros *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync*******************************************************************************/
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** Temporary instrumentation for tracking down potential virtual disk
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * write performance issues. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** @name The SSM saved state versions.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/** The current saved state version. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** The saved state version used by VirtualBox 3.0.
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * This lacks the config part and has the type at the and. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define ATA_SAVED_STATE_VERSION_WITHOUT_FULL_SENSE 16
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define ATA_SAVED_STATE_VERSION_WITHOUT_EVENT_STATUS 17
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync/*******************************************************************************
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync* Header Files *
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync*******************************************************************************/
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#endif /* IN_RING3 */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Defined Constants And Macros *
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync*******************************************************************************/
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Maximum number of sectors to transfer in a READ/WRITE MULTIPLE request.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Set to 1 to disable multi-sector read support. According to the ATA
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * specification this must be a power of 2 and it must fit in an 8 bit
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * value. Thus the only valid values are 1, 2, 4, 8, 16, 32, 64 and 128.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Fastest PIO mode supported by the drive.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * Fastest MDMA mode supported by the drive.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Fastest UDMA mode supported by the drive.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/** ATAPI sense info size. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync/** The maximum number of release log entries per device. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync/* MediaEventStatus */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define ATA_EVENT_STATUS_UNCHANGED 0 /**< medium event status not changed */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define ATA_EVENT_STATUS_MEDIA_NEW 1 /**< new medium inserted */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#define ATA_EVENT_STATUS_MEDIA_REMOVED 2 /**< medium removed */
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync#define ATA_EVENT_STATUS_MEDIA_CHANGED 3 /**< medium was removed + new medium was inserted */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Length of the configurable VPD data (without termination)
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync/*******************************************************************************
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync* Structures and Typedefs *
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync*******************************************************************************/
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * The state of an ATA device.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @implements PDMIBASE
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @implements PDMIBLOCKPORT
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @implements PDMIMOUNTNOTIFY
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsynctypedef struct ATADevState
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Flag indicating whether the current command uses LBA48 mode. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /** Flag indicating whether this drive implements the ATAPI command set. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /** Set if this interface has asserted the IRQ. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /** Currently configured number of sectors in a multi-sector transfer. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** PCHS disk geometry. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Total number of sectors on this disk. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Number of sectors to transfer per IRQ. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** ATA/ATAPI register 1: feature (write-only). */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** ATA/ATAPI register 1: feature, high order byte. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 1: error (read-only). */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 2: sector count (read/write). */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 2: sector count, high order byte. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 3: sector, high order byte. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 4: cylinder low (read/write). */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 4: cylinder low, high order byte. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 5: cylinder high (read/write). */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 5: cylinder high, high order byte. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 6: select drive/head (read/write). */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 7: status (read-only). */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI register 7: command (write-only). */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI drive control register (write-only). */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Currently active transfer mode (MDMA/UDMA) and speed. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Current transfer direction. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Index of callback for begin transfer. */
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync /** Index of callback for source/sink of data. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Flag indicating whether the current command transfers data in DMA mode. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Set to indicate that ATAPI transfer semantics must be used. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Total ATA/ATAPI transfer size, shared PIO/DMA. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Elementary ATA/ATAPI transfer size, shared PIO/DMA. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Current read/write buffer position, shared PIO/DMA. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** First element beyond end of valid buffer content, shared PIO/DMA. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** ATA/ATAPI current PIO read/write transfer position. Not shared with DMA for safety reasons. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATA/ATAPI current PIO read/write transfer end. Not shared with DMA for safety reasons. */
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync /** ATAPI current LBA position. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATAPI current sector size. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATAPI current command. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** ATAPI sense data. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** HACK: Countdown till we report a newly unmounted drive as mounted. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** The same for GET_EVENT_STATUS for mechanism */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** The status LED state for this drive. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Size of I/O buffer. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Pointer to the I/O buffer. */
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync /** Pointer to the I/O buffer. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Pointer to the I/O buffer. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync RTRCPTR Aligmnent1; /**< Align the statistics at an 8-byte boundrary. */
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * No data that is part of the saved state after this point!!!!!
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /* Release statistics: number of ATA DMA commands. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /* Release statistics: number of ATA PIO commands. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /* Release statistics: number of ATAPI PIO commands. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /* Release statistics: number of ATAPI PIO commands. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /* Release statistics: number of DMA sector writes and the time spent. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /** Statistics: number of read operations and the time spent reading. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /** Statistics: number of bytes read. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Statistics: number of write operations and the time spent writing. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Statistics: number of bytes written. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Statistics: number of flush operations and the time spend flushing. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Enable passing through commands directly to the ATAPI drive. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /** Number of errors we've reported to the release log.
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * This is to prevent flooding caused by something going horribly wrong.
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync * this value against MAX_LOG_REL_ERRORS in places likely to cause floods
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * like the ones we currently seeing on the linux smoke tests (2006-11-10). */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Timestamp of last started command. 0 if no command pending. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Pointer to the attached driver's base interface. */
a9f41cb889f53e8407561a6155052c441eb0fc5fvboxsync /** Pointer to the attached driver's block interface. */
d5ea45cc92d7f1d3ade8189944531f665bfe8ed5vboxsync /** Pointer to the attached driver's block bios interface. */
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync /** Pointer to the attached driver's mount interface.
0dd6dfbebcda0af90da4413aaea5f3b9d1817556vboxsync * This is NULL if the driver isn't a removable unit. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** The base interface. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** The block port interface. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The mount notify interface. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** The LUN #. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync RTUINT Alignment2; /**< Align pDevInsR3 correctly. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** Pointer to device instance. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** Pointer to controller instance. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** Pointer to device instance. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** Pointer to controller instance. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** Pointer to device instance. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** Pointer to controller instance. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** The serial number to use for IDENTIFY DEVICE commands. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** The firmware revision to use for IDENTIFY DEVICE commands. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync char szFirmwareRevision[ATA_FIRMWARE_REVISION_LENGTH+1];
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** The model number to use for IDENTIFY DEVICE commands. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** The vendor identification string for SCSI INQUIRY commands. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync char szInquiryVendorId[ATAPI_INQUIRY_VENDOR_ID_LENGTH+1];
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** The product identification string for SCSI INQUIRY commands. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync char szInquiryProductId[ATAPI_INQUIRY_PRODUCT_ID_LENGTH+1];
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync /** The revision string for SCSI INQUIRY commands. */
fc78e01f665145ab3641c5f8095e9ae984ddcb84vboxsync char szInquiryRevision[ATAPI_INQUIRY_REVISION_LENGTH+1];
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncAssertCompileMemberAlignment(ATADevState, cTotalSectors, 8);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncAssertCompileMemberAlignment(ATADevState, StatATADMA, 8);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncAssertCompileMemberAlignment(ATADevState, u64CmdTS, 8);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncAssertCompileMemberAlignment(ATADevState, pDevInsR3, 8);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncAssertCompileMemberAlignment(ATADevState, szSerialNumber, 8);
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsynctypedef enum
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /** Begin a new transfer. */
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync /** Continue a DMA transfer. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Continue a PIO transfer. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Reset the drives on current controller, stop all transfer activity. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Reset the drives on current controller, resume operation. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /** Abort the current transfer of a particular drive. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsynctypedef struct ATARequest
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The base of the first I/O Port range. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The base of the second I/O Port range. (0 if none) */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The assigned IRQ. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Access critical section */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Selected drive. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The interface on which to handle async I/O. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The state of the async I/O thread. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Flag indicating whether the next transfer is part of the current command. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Set when the reset processing is currently active on this controller. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Flag whether the current transfer needs to be redone. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Flag whether the redo suspend has been finished. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Flag whether the DMA operation to be redone is the final transfer. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** The BusMaster DMA state. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Pointer to first DMA descriptor. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Pointer to last DMA descriptor. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Pointer to current DMA buffer (for redo operations). */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Size of current DMA buffer (for redo operations). */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The ATA/ATAPI interfaces of this controller. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Pointer to device instance. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Pointer to device instance. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Pointer to device instance. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Set when the destroying the device instance and the thread must exit. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** The async I/O thread handle. NIL_RTTHREAD if no thread. */
d7125f3a1b435761c393f9ec406e85a73ae2a3e7vboxsync /** The event semaphore the thread is waiting on for requests. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** The request queue for the AIO thread. One element is always unused. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** The position at which to insert a new request for the AIO thread. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** The position at which to get a new request for the AIO thread. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Whether to call PDMDevHlpAsyncNotificationCompleted when idle. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync bool volatile fSignalIdle;
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync uint8_t Alignment3[1]; /**< Explicit padding of the 1 byte gap. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** Magic delay before triggering interrupts in DMA mode. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The mutex protecting the request queue. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** The event semaphore the thread is waiting on during suspended I/O. */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync#if 0 /*HC_ARCH_BITS == 32*/
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /** Timestamp we started the reset. */
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync /* Statistics */
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncAssertCompileMemberAlignment(ATACONTROLLER, lock, 8);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncAssertCompileMemberAlignment(ATACONTROLLER, aIfs, 8);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncAssertCompileMemberAlignment(ATACONTROLLER, u64ResetTime, 8);
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsyncAssertCompileMemberAlignment(ATACONTROLLER, StatAsyncOps, 8);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync /** PIIX3 chipset, must be 0 for saved state compatibility */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /** PIIX4 chipset, must be 1 for saved state compatibility */
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync /** ICH6 chipset */
a39ea3668b7019c23a68936259545f9b71bce1aavboxsync * The state of the ATA PCI device.
da3503c04ce76e653401396fe2795a9bc2427a1dvboxsync * @extends PCIDEVICE
ea779b55cc87f3e3fadddca4672c6697c82606edvboxsync * @implements PDMILEDPORTS
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsynctypedef struct PCIATAState
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync /** The controllers. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /** Pointer to device instance. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Status LUN: Base interface. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Status LUN: Leds interface. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /** Status LUN: Partner of ILeds. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /** Flag whether GC is enabled. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /** Flag whether R0 is enabled. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync /** Flag indicating chipset being emulated. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync bool Alignment0[HC_ARCH_BITS == 64 ? 5 : 1 ]; /**< Align the struct size. */
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync#define PDMIBASE_2_PCIATASTATE(pInterface) ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, IBase)) )
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync#define PDMILEDPORTS_2_PCIATASTATE(pInterface) ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, ILeds)) )
0c4004948fca34f2db87e7b38013137e9472c306vboxsync#define PDMIBLOCKPORT_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IPort)) )
0c4004948fca34f2db87e7b38013137e9472c306vboxsync#define PDMIMOUNT_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMount)) )
0c4004948fca34f2db87e7b38013137e9472c306vboxsync#define PDMIMOUNTNOTIFY_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMountNotify)) )
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync#define PCIDEV_2_PCIATASTATE(pPciDev) ( (PCIATAState *)(pPciDev) )
0c4004948fca34f2db87e7b38013137e9472c306vboxsync#define ATACONTROLLER_IDX(pController) ( (pController) - PDMINS_2_DATA(CONTROLLER_2_DEVINS(pController), PCIATAState *)->aCts )
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync#define ATADEVSTATE_2_CONTROLLER(pIf) ( (pIf)->CTX_SUFF(pController) )
0c4004948fca34f2db87e7b38013137e9472c306vboxsync#define ATADEVSTATE_2_DEVINS(pIf) ( (pIf)->CTX_SUFF(pDevIns) )
0c4004948fca34f2db87e7b38013137e9472c306vboxsync#define CONTROLLER_2_DEVINS(pController) ( (pController)->CTX_SUFF(pDevIns) )
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsync#define PDMIBASE_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IBase)) )
0c4004948fca34f2db87e7b38013137e9472c306vboxsync/*******************************************************************************
0c4004948fca34f2db87e7b38013137e9472c306vboxsync * Internal Functions *
0c4004948fca34f2db87e7b38013137e9472c306vboxsync ******************************************************************************/
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncPDMBOTHCBDECL(int) ataIOPortWrite1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncPDMBOTHCBDECL(int) ataIOPortRead1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *u32, unsigned cb);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsyncPDMBOTHCBDECL(int) ataIOPortWriteStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, PRTGCUINTREG pcTransfer, unsigned cb);
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncPDMBOTHCBDECL(int) ataIOPortReadStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfer, unsigned cb);
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncPDMBOTHCBDECL(int) ataIOPortWrite2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncPDMBOTHCBDECL(int) ataIOPortRead2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *u32, unsigned cb);
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncPDMBOTHCBDECL(int) ataBMDMAIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
0c4004948fca34f2db87e7b38013137e9472c306vboxsyncPDMBOTHCBDECL(int) ataBMDMAIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
d4e9ccea0ea1ed303b5708ff94f6c202755f0dc6vboxsyncDECLINLINE(void) ataSetStatusValue(ATADevState *s, uint8_t stat)
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync /* Freeze status register contents while processing RESET. */
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsyncDECLINLINE(void) ataSetStatus(ATADevState *s, uint8_t stat)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /* Freeze status register contents while processing RESET. */
0c4004948fca34f2db87e7b38013137e9472c306vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsyncDECLINLINE(void) ataUnsetStatus(ATADevState *s, uint8_t stat)
0c4004948fca34f2db87e7b38013137e9472c306vboxsync /* Freeze status register contents while processing RESET. */
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic bool ataExecuteDeviceDiagnosticSS(ATADevState *);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic bool atapiGetEventStatusNotificationSS(ATADevState *);
8cd2f2e64725096acb682f34a5568b7fb816eda7vboxsyncstatic bool atapiModeSenseErrorRecoverySS(ATADevState *);
e74eef731a813e4e06680c587a6759b9974b29c9vboxsyncstatic bool atapiModeSenseCDStatusSS(ATADevState *);
26947320577c481b4afefdb0afbb855181e5b2e8vboxsyncstatic bool atapiReadDiscInformationSS(ATADevState *);
26947320577c481b4afefdb0afbb855181e5b2e8vboxsyncstatic bool atapiReadTrackInformationSS(ATADevState *);
26947320577c481b4afefdb0afbb855181e5b2e8vboxsync * Begin of transfer function indexes for g_apfnBeginTransFuncs.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Array of end transfer functions, the index is ATAFNET.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Make sure ATAFNET and this array match!
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic const PBeginTransferFunc g_apfnBeginTransFuncs[ATAFN_BT_MAX] =
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Source/sink function indexes for g_apfnSourceSinkFuncs.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Array of source/sink functions, the index is ATAFNSS.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * Make sure ATAFNSS and this array match!
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic const PSourceSinkFunc g_apfnSourceSinkFuncs[ATAFN_SS_MAX] =
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsyncstatic const ATARequest g_ataDMARequest = { ATA_AIO_DMA, };
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsyncstatic const ATARequest g_ataPIORequest = { ATA_AIO_PIO, };
9b789c281103a2489742bf32f6ab500e38b2ecd5vboxsyncstatic const ATARequest g_ataResetARequest = { ATA_AIO_RESET_ASSERTED, };
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic const ATARequest g_ataResetCRequest = { ATA_AIO_RESET_CLEARED, };
c91345f92b829d3fba05ce7a97206d83c5183ce0vboxsyncstatic void ataAsyncIOClearRequests(PATACONTROLLER pCtl)
44a2ecaf2d0fc196ab76cab13b3f909299e386d1vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic void ataAsyncIOPutRequest(PATACONTROLLER pCtl, const ATARequest *pReq)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync Assert((pCtl->AsyncIOReqHead + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests) != pCtl->AsyncIOReqTail);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync memcpy(&pCtl->aAsyncIORequests[pCtl->AsyncIOReqHead], pReq, sizeof(*pReq));
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pCtl->AsyncIOReqHead %= RT_ELEMENTS(pCtl->aAsyncIORequests);
ad77e3ec3cde24263bc7537575f5cae442bee3b1vboxsync rc = PDMR3CritSectScheduleExitEvent(&pCtl->lock, pCtl->AsyncIOSem);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic const ATARequest *ataAsyncIOGetCurrentRequest(PATACONTROLLER pCtl)
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync pReq = &pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail];
8f0fc87a72dee210b62acc9dd859a4bebf8bfb33vboxsync * Remove the request with the given type, as it's finished. The request
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * is not removed blindly, as this could mean a RESET request that is not
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * yet processed (but has cleared the request queue) is lost.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync * @param pCtl Controller for which to remove the request.
cba6719bd64ec749967bbe931230452664109857vboxsync * @param ReqType Type of the request to remove.
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsyncstatic void ataAsyncIORemoveCurrentRequest(PATACONTROLLER pCtl, ATAAIO ReqType)
cba6719bd64ec749967bbe931230452664109857vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
9dca051a5f8ff457ef1692990f6ecfa280daf265vboxsync if (pCtl->AsyncIOReqHead != pCtl->AsyncIOReqTail && pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail].ReqType == ReqType)
int rc;
case ATA_AIO_NEW:
LogRel(("new transfer request, iIf=%d iBeginTransfer=%d iSourceSink=%d cbTotalTransfer=%d uTxDir=%d\n", pCtl->aAsyncIORequests[curr].u.t.iIf, pCtl->aAsyncIORequests[curr].u.t.iBeginTransfer, pCtl->aAsyncIORequests[curr].u.t.iSourceSink, pCtl->aAsyncIORequests[curr].u.t.cbTotalTransfer, pCtl->aAsyncIORequests[curr].u.t.uTxDir));
case ATA_AIO_DMA:
case ATA_AIO_PIO:
case ATA_AIO_RESET_ASSERTED:
case ATA_AIO_RESET_CLEARED:
case ATA_AIO_ABORT:
LogRel(("abort request, iIf=%d fResetDrive=%d\n", pCtl->aAsyncIORequests[curr].u.a.iIf, pCtl->aAsyncIORequests[curr].u.a.fResetDrive));
int rc;
bool fIdle;
if (!fIdle)
if (fStrict)
return fIdle;
static void ataStartTransfer(ATADevState *s, uint32_t cbTotalTransfer, uint8_t uTxDir, ATAFNBT iBeginTransfer, ATAFNSS iSourceSink, bool fChainedTransfer)
Log2(("%s: Ctl#%d: suppressed new request as RESET is active\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Log(("%s: Ctl#%d: ignored command %#04x, controller state %d\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), s->uATARegCommand, pCtl->uAsyncIOState));
if (fChainedTransfer)
Log2(("%s: Ctl#%d: message to async I/O thread, new request\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Log2(("%s: Ctl#%d: suppressed aborting command as RESET is active\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Log2(("%s: Ctl#%d: message to async I/O thread, abort command on LUN#%d\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), s->iLUN));
if (!s->fIrqPending)
s->fIrqPending = true;
s->fIrqPending = false;
#ifdef IN_RING3
if (s->fATAPITransfer)
ataSetIRQ(s);
s->fATAPITransfer = false;
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
s->iIOBufferPIODataStart = 0;
s->iIOBufferPIODataEnd = 0;
if (cbLimit == 0)
cbLimit--;
cbLimit--;
if (s->fLBA48)
if (!s->uATARegNSector)
return s->uATARegNSector;
if (*pbSrc)
if (*pbSrc)
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
s->iIOBufferCur = 0;
s->iIOBufferEnd = 0;
size_t i;
for (i = 0; i < count; i++)
count--;
uint16_t *p;
ataPadString((uint8_t *)(p + 23), s->szFirmwareRevision, ATA_FIRMWARE_REVISION_LENGTH); /* firmware version */
if (s->cMultSectors)
p[63] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_MDMA, ATA_MDMA_MODE_MAX, s->uATATransferMode)); /* MDMA modes supported / mode enabled */
p[64] = RT_H2LE_U16(ATA_PIO_MODE_MAX > 2 ? (1 << (ATA_PIO_MODE_MAX - 2)) - 1 : 0); /* PIO modes beyond PIO2 supported */
p[82] = RT_H2LE_U16(1 << 3 | 1 << 5 | 1 << 6); /* supports power management, write cache and look-ahead */
p[83] = RT_H2LE_U16(1 << 14 | 1 << 10 | 1 << 12 | 1 << 13); /* supports LBA48, FLUSH CACHE and FLUSH CACHE EXT */
p[85] = RT_H2LE_U16(1 << 3 | 1 << 5 | 1 << 6); /* enabled power management, write cache and look-ahead */
p[86] = RT_H2LE_U16(1 << 10 | 1 << 12 | 1 << 13); /* enabled LBA48, FLUSH CACHE and FLUSH CACHE EXT */
p[88] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_UDMA, ATA_UDMA_MODE_MAX, s->uATATransferMode)); /* UDMA modes supported / mode enabled */
int rc;
ataCmdOK(s, 0);
uint16_t *p;
ataPadString((uint8_t *)(p + 23), s->szFirmwareRevision, ATA_FIRMWARE_REVISION_LENGTH); /* firmware version */
p[63] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_MDMA, ATA_MDMA_MODE_MAX, s->uATATransferMode)); /* MDMA modes supported / mode enabled */
p[64] = RT_H2LE_U16(ATA_PIO_MODE_MAX > 2 ? (1 << (ATA_PIO_MODE_MAX - 2)) - 1 : 0); /* PIO modes beyond PIO2 supported */
p[88] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_UDMA, ATA_UDMA_MODE_MAX, s->uATATransferMode)); /* UDMA modes supported / mode enabled */
if (s->fATAPI)
else if (s->pDrvBlock)
s->uATARegLCyl = 0;
s->uATARegHCyl = 0;
if (s->fLBA48)
s->uATARegSector;
iLBA = ((s->uATARegHCyl << 8) | s->uATARegLCyl) * s->PCHSGeometry.cHeads * s->PCHSGeometry.cSectors +
return iLBA;
if (s->fLBA48)
int rc;
N_("Host system reported disk full. VM execution is suspended. You can resume after freeing some space"));
int rc;
N_("Host system reported that the file size limit of the host file system has been exceeded. VM execution is suspended. You need to move your virtual hard disk to a filesystem which allows bigger files"));
int rc;
N_("The iSCSI target has stopped responding. VM execution is suspended. You can resume when it is available again"));
int rc;
static int ataReadSectors(ATADevState *s, uint64_t u64Sector, void *pvBuf, uint32_t cSectors, bool *fRedo)
int rc;
*fRedo = false;
return rc;
static int ataWriteSectors(ATADevState *s, uint64_t u64Sector, const void *pvBuf, uint32_t cSectors, bool *fRedo)
int rc;
#ifdef VBOX_INSTRUMENT_DMA_WRITES
if (s->fDMA)
#ifdef VBOX_INSTRUMENT_DMA_WRITES
if (s->fDMA)
*fRedo = false;
return rc;
ataCmdOK(s, 0);
int rc;
bool fRedo;
if (fRedo)
return fRedo;
int rc;
bool fRedo;
if (!s->cbTotalTransfer)
if (fRedo)
return fRedo;
s->uATARegError = 0;
Log(("%s: sense=%#x (%s) asc=%#x ascq=%#x (%s)\n", __FUNCTION__, pabATAPISense[2] & 0x0f, SCSISenseText(pabATAPISense[2] & 0x0f),
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
s->iIOBufferCur = 0;
s->iIOBufferEnd = 0;
s->fATAPITransfer = true;
atapiCmdOK(s);
int rc;
rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, aModeSenseCmd, PDMBLOCKTXDIR_FROM_DEVICE, aModeSenseResult, &cbTransfer, &uDummySense, 500);
s->cbATAPISector = 0;
if (s->cbTotalTransfer == 0)
atapiCmdBT(s);
switch (s->cbATAPISector)
rc = s->pDrvBlock->pfnRead(s->pDrvBlock, (uint64_t)s->iATAPILBA * s->cbATAPISector, s->CTX_SUFF(pbIOBuffer), s->cbATAPISector * cSectors);
atapiCmdOK(s);
LogRel(("PIIX3 ATA: LUN#%d: CD-ROM read error, %d sectors at LBA %d\n", s->iLUN, cSectors, s->iATAPILBA));
switch (s->aATAPICmd[0])
case SCSI_READ_10:
case SCSI_WRITE_10:
case SCSI_WRITE_AND_VERIFY_10:
case SCSI_READ_12:
case SCSI_WRITE_12:
case SCSI_READ_CD:
case SCSI_READ_CD_MSF:
cReqSectors = 0;
cReqSectors = i;
switch (s->aATAPICmd[0])
case SCSI_READ_10:
case SCSI_WRITE_10:
case SCSI_WRITE_AND_VERIFY_10:
case SCSI_READ_12:
case SCSI_WRITE_12:
case SCSI_READ_CD:
case SCSI_READ_CD_MSF:
rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, aATAPICmd, (PDMBLOCKTXDIR)s->uTxDir, pbBuf, &cbCurrTX, abATAPISense, sizeof(abATAPISense), 30000 /**< @todo timeout */);
rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, s->aATAPICmd, (PDMBLOCKTXDIR)s->uTxDir, s->CTX_SUFF(pbIOBuffer), &cbTransfer, abATAPISense, sizeof(abATAPISense), 30000 /**< @todo timeout */);
Log3(("ATAPI PT inquiry data before (%d): %.*Rhxs\n", cbTransfer, cbTransfer, s->CTX_SUFF(pbIOBuffer)));
if (cbTransfer)
atapiCmdOK(s);
s->cErrors++;
switch (format) {
if (media == 0)
switch (format)
if (layer != 0)
if (total_sectors == 0)
if (uASC < 0)
atapiCmdOK(s);
static bool atapiReadSectors(ATADevState *s, uint32_t iATAPILBA, uint32_t cSectors, uint32_t cbSector)
ataStartTransfer(s, cSectors * cbSector, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ, true);
atapiCmdOK(s);
pbBuf[7] = (0 << 7) | (0 << 6) | (1 << 5) | (0 << 2) | (0 << 0); /* disc id not valid, disc bar code not valid, unrestricted use, not dirty, not RW medium */
atapiCmdOK(s);
pbBuf[6] = (0 << 7) | (0 << 6) | (0 << 5) | (0 << 6) | (1 << 0); /* not reserved track, not blank, not packet writing, not fixed packet, data mode 1 */
pbBuf[7] = (0 << 1) | (0 << 0); /* last recorded address not valid, next recordable address not valid */
atapiCmdOK(s);
atapiCmdOK(s);
switch (OldStatus)
atapiCmdOK(s);
atapiCmdOK(s);
atapiCmdOK(s);
pbBuf[14] = (1 << 0) | (1 << 3) | (1 << 5); /* lock supported, eject supported, tray type loading mechanism */
pbBuf[15] = 0; /* no subchannel reads supported, no separate audio volume control, no changer etc. */
atapiCmdOK(s);
atapiCmdOK(s);
atapiCmdOK(s);
bool fMSF;
if (fMSF)
ataLBA2MSF(q, 0);
ataH2BE_U32(q, 0);
if (fMSF)
atapiCmdOK(s);
bool fMSF;
/** @todo double-check this stuff against what a real drive says for a CD-ROM (not a CD-R) with only a single data session. Maybe solve the problem with "cdrdao read-toc" not being able to figure out whether numbers are in BCD or hex. */
if (fMSF)
atapiCmdOK(s);
bool fMSF;
if (fMSF)
if (fMSF)
ataLBA2MSF(q, 0);
ataH2BE_U32(q, 0);
atapiCmdOK(s);
switch (pbPacket[0])
case SCSI_TEST_UNIT_READY:
if (s->cNotifiedMediaChange > 0)
atapiCmdErrorSimple(s, SCSI_SENSE_UNIT_ATTENTION, SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED); /* media changed */
atapiCmdOK(s);
ataStartTransfer(s, RT_MIN(cbMax, 8), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_EVENT_STATUS_NOTIFICATION, true);
case SCSI_MODE_SENSE_10:
switch (uPageControl)
case SCSI_PAGECONTROL_CURRENT:
switch (uPageCode)
ataStartTransfer(s, RT_MIN(cbMax, 16), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MODE_SENSE_ERROR_RECOVERY, true);
case SCSI_MODEPAGE_CD_STATUS:
ataStartTransfer(s, RT_MIN(cbMax, 40), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MODE_SENSE_CD_STATUS, true);
goto error_cmd;
goto error_cmd;
case SCSI_PAGECONTROL_DEFAULT:
goto error_cmd;
case SCSI_PAGECONTROL_SAVED:
case SCSI_REQUEST_SENSE:
ataStartTransfer(s, RT_MIN(cbMax, 18), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_REQUEST_SENSE, true);
atapiCmdOK(s);
case SCSI_READ_10:
case SCSI_READ_12:
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
atapiCmdErrorSimple(s, SCSI_SENSE_UNIT_ATTENTION, SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED); /* media changed */
if (cSectors == 0)
atapiCmdOK(s);
LogRel(("PIIX3 ATA: LUN#%d: CD-ROM block number %Ld invalid (READ)\n", s->iLUN, (uint64_t)iATAPILBA + cSectors));
case SCSI_READ_CD:
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
atapiCmdErrorSimple(s, SCSI_SENSE_UNIT_ATTENTION, SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED); /* media changed */
if (cSectors == 0)
atapiCmdOK(s);
LogRel(("PIIX3 ATA: LUN#%d: CD-ROM block number %Ld invalid (READ CD)\n", s->iLUN, (uint64_t)iATAPILBA + cSectors));
atapiCmdOK(s);
LogRel(("PIIX3 ATA: LUN#%d: CD-ROM sector format not supported (%#x)\n", s->iLUN, pbPacket[9] & 0xf8));
case SCSI_SEEK_10:
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
atapiCmdErrorSimple(s, SCSI_SENSE_UNIT_ATTENTION, SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED); /* media changed */
LogRel(("PIIX3 ATA: LUN#%d: CD-ROM block number %Ld invalid (SEEK)\n", s->iLUN, (uint64_t)iATAPILBA));
atapiCmdOK(s);
case SCSI_START_STOP_UNIT:
atapiCmdOK(s);
case SCSI_MECHANISM_STATUS:
ataStartTransfer(s, RT_MIN(cbMax, 8), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_MECHANISM_STATUS, true);
case SCSI_READ_TOC_PMA_ATIP:
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
atapiCmdErrorSimple(s, SCSI_SENSE_UNIT_ATTENTION, SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED); /* media changed */
switch (format)
ataStartTransfer(s, cbMax, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_NORMAL, true);
ataStartTransfer(s, RT_MIN(cbMax, 12), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_MULTI, true);
ataStartTransfer(s, cbMax, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TOC_RAW, true);
case SCSI_READ_CAPACITY:
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
atapiCmdErrorSimple(s, SCSI_SENSE_UNIT_ATTENTION, SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED); /* media changed */
ataStartTransfer(s, 8, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_CAPACITY, true);
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
atapiCmdErrorSimple(s, SCSI_SENSE_UNIT_ATTENTION, SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED); /* media changed */
ataStartTransfer(s, RT_MIN(cbMax, 34), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_DISC_INFORMATION, true);
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
atapiCmdErrorSimple(s, SCSI_SENSE_UNIT_ATTENTION, SCSI_ASC_MEDIUM_MAY_HAVE_CHANGED); /* media changed */
ataStartTransfer(s, RT_MIN(cbMax, 36), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_TRACK_INFORMATION, true);
case SCSI_GET_CONFIGURATION:
ataStartTransfer(s, RT_MIN(cbMax, 32), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_CONFIGURATION, true);
case SCSI_INQUIRY:
ataStartTransfer(s, RT_MIN(cbMax, 36), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_INQUIRY, true);
case SCSI_READ_DVD_STRUCTURE:
ataStartTransfer(s, RT_MIN(cbMax, 4), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_DVD_STRUCTURE, true);
switch (pbPacket[0])
case SCSI_BLANK:
goto sendcmd;
case SCSI_CLOSE_TRACK_SESSION:
goto sendcmd;
case SCSI_ERASE_10:
goto sendcmd;
case SCSI_FORMAT_UNIT:
goto sendcmd;
case SCSI_GET_CONFIGURATION:
goto sendcmd;
ataStartTransfer(s, RT_MIN(cbTransfer, 8), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_GET_EVENT_STATUS_NOTIFICATION, true);
goto sendcmd;
case SCSI_GET_PERFORMANCE:
goto sendcmd;
case SCSI_INQUIRY:
goto sendcmd;
case SCSI_LOAD_UNLOAD_MEDIUM:
goto sendcmd;
case SCSI_MECHANISM_STATUS:
goto sendcmd;
case SCSI_MODE_SELECT_10:
goto sendcmd;
case SCSI_MODE_SENSE_10:
goto sendcmd;
case SCSI_PAUSE_RESUME:
goto sendcmd;
case SCSI_PLAY_AUDIO_10:
goto sendcmd;
case SCSI_PLAY_AUDIO_12:
goto sendcmd;
case SCSI_PLAY_AUDIO_MSF:
goto sendcmd;
goto sendcmd;
case SCSI_READ_10:
goto sendcmd;
case SCSI_READ_12:
goto sendcmd;
case SCSI_READ_BUFFER:
goto sendcmd;
goto sendcmd;
case SCSI_READ_CAPACITY:
goto sendcmd;
case SCSI_READ_CD:
goto sendcmd;
case SCSI_READ_CD_MSF:
cSectors = 32; /* Limit transfer size to 64~74K. Safety first. In any case this can only harm software doing CDDA extraction. */
goto sendcmd;
goto sendcmd;
case SCSI_READ_DVD_STRUCTURE:
goto sendcmd;
goto sendcmd;
case SCSI_READ_SUBCHANNEL:
goto sendcmd;
case SCSI_READ_TOC_PMA_ATIP:
goto sendcmd;
goto sendcmd;
case SCSI_REPAIR_TRACK:
goto sendcmd;
case SCSI_REPORT_KEY:
goto sendcmd;
case SCSI_REQUEST_SENSE:
ataStartTransfer(s, RT_MIN(cbTransfer, 18), PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_REQUEST_SENSE, true);
goto sendcmd;
case SCSI_RESERVE_TRACK:
goto sendcmd;
case SCSI_SCAN:
goto sendcmd;
case SCSI_SEEK_10:
goto sendcmd;
case SCSI_SEND_CUE_SHEET:
goto sendcmd;
case SCSI_SEND_DVD_STRUCTURE:
goto sendcmd;
case SCSI_SEND_EVENT:
goto sendcmd;
case SCSI_SEND_KEY:
goto sendcmd;
goto sendcmd;
case SCSI_SET_CD_SPEED:
goto sendcmd;
case SCSI_SET_READ_AHEAD:
goto sendcmd;
case SCSI_SET_STREAMING:
goto sendcmd;
case SCSI_START_STOP_UNIT:
goto sendcmd;
case SCSI_STOP_PLAY_SCAN:
goto sendcmd;
case SCSI_SYNCHRONIZE_CACHE:
goto sendcmd;
case SCSI_TEST_UNIT_READY:
goto sendcmd;
case SCSI_VERIFY_10:
goto sendcmd;
case SCSI_WRITE_10:
s->cbATAPISector = 0;
goto sendcmd;
case SCSI_WRITE_12:
s->cbATAPISector = 0;
goto sendcmd;
case SCSI_WRITE_AND_VERIFY_10:
s->cbATAPISector = 0;
goto sendcmd;
case SCSI_WRITE_BUFFER:
LogRel(("PIIX3 ATA: LUN#%d: CD-ROM passthrough command attempted to update firmware, blocked\n", s->iLUN));
goto sendcmd;
goto sendcmd;
case SCSI_REZERO_UNIT:
if (cbTransfer == 0)
ataStartTransfer(s, cbTransfer, uTxDir, ATAFN_BT_ATAPI_PASSTHROUGH_CMD, ATAFN_SS_ATAPI_PASSTHROUGH, true);
#ifdef DEBUG
Log(("%s: LUN#%d DMA=%d CMD=%#04x \"%s\"\n", __FUNCTION__, s->iLUN, s->fDMA, pbPacket[0], SCSICmdText(pbPacket[0])));
Log2(("%s: limit=%#x packet: %.*Rhxs\n", __FUNCTION__, s->uATARegLCyl | (s->uATARegHCyl << 8), ATAPI_PACKET_SIZE, pbPacket));
if (s->fATAPIPassthrough)
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
atapiParseCmd(s);
switch (OldStatus)
LogRel(("PIIX3 ATA: LUN#%d: CD/DVD, total number of sectors %Ld, passthrough unchanged\n", pIf->iLUN, pIf->cTotalSectors));
s->cNotifiedMediaChange = 0;
ataUnsetIRQ(s);
ataSetSignature(s);
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
s->iIOBufferPIODataStart = 0;
s->iIOBufferPIODataEnd = 0;
s->fDMA = false;
s->fATAPITransfer = false;
s->uATARegFeature = 0;
ataSetSignature(s);
if (s->fATAPI)
#ifdef DEBUG
s->fLBA48 = false;
s->fDMA = false;
if (s->u64CmdTS)
switch (cmd)
case ATA_IDENTIFY_DEVICE:
if (s->fATAPI)
ataSetSignature(s);
case ATA_RECALIBRATE:
case ATA_SET_MULTIPLE_MODE:
if ( s->uATARegNSector != 0
ataCmdOK(s, 0);
s->fLBA48 = true;
case ATA_READ_VERIFY_SECTORS:
ataCmdOK(s, 0);
case ATA_READ_SECTORS_EXT:
s->fLBA48 = true;
case ATA_READ_SECTORS:
if (!s->pDrvBlock)
goto abort_cmd;
ataStartTransfer(s, ataGetNSectors(s) * 512, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
case ATA_WRITE_SECTORS_EXT:
s->fLBA48 = true;
case ATA_WRITE_SECTORS:
ataStartTransfer(s, ataGetNSectors(s) * 512, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
case ATA_READ_MULTIPLE_EXT:
s->fLBA48 = true;
case ATA_READ_MULTIPLE:
if (!s->cMultSectors)
goto abort_cmd;
ataStartTransfer(s, ataGetNSectors(s) * 512, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
case ATA_WRITE_MULTIPLE_EXT:
s->fLBA48 = true;
case ATA_WRITE_MULTIPLE:
if (!s->cMultSectors)
goto abort_cmd;
ataStartTransfer(s, ataGetNSectors(s) * 512, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
case ATA_READ_DMA_EXT:
s->fLBA48 = true;
case ATA_READ_DMA:
if (!s->pDrvBlock)
goto abort_cmd;
s->fDMA = true;
ataStartTransfer(s, ataGetNSectors(s) * 512, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_READ_SECTORS, false);
case ATA_WRITE_DMA_EXT:
s->fLBA48 = true;
case ATA_WRITE_DMA:
if (!s->pDrvBlock)
goto abort_cmd;
s->fDMA = true;
ataStartTransfer(s, ataGetNSectors(s) * 512, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_READ_WRITE_SECTORS, ATAFN_SS_WRITE_SECTORS, false);
s->fLBA48 = true;
ataCmdOK(s, 0);
ataCmdOK(s, 0);
ataCmdOK(s, 0);
case ATA_CHECK_POWER_MODE:
ataCmdOK(s, 0);
case ATA_SET_FEATURES:
if (!s->pDrvBlock)
goto abort_cmd;
switch (s->uATARegFeature)
s->uATATransferMode = (s->uATARegNSector & 0xf8) | RT_MIN(s->uATARegNSector & 0x07, ATA_MDMA_MODE_MAX);
s->uATATransferMode = (s->uATARegNSector & 0xf8) | RT_MIN(s->uATARegNSector & 0x07, ATA_UDMA_MODE_MAX);
goto abort_cmd;
goto abort_cmd;
s->uATARegFeature = 0;
case ATA_FLUSH_CACHE_EXT:
case ATA_FLUSH_CACHE:
goto abort_cmd;
case ATA_STANDBY_IMMEDIATE:
ataCmdOK(s, 0);
case ATA_IDLE_IMMEDIATE:
ataAbortCurrentCommand(s, false);
if (s->fATAPI)
ataStartTransfer(s, 0, PDMBLOCKTXDIR_NONE, ATAFN_BT_NULL, ATAFN_SS_EXECUTE_DEVICE_DIAGNOSTIC, false);
case ATA_DEVICE_RESET:
if (!s->fATAPI)
goto abort_cmd;
ataAbortCurrentCommand(s, true);
case ATA_PACKET:
if (!s->fATAPI)
goto abort_cmd;
goto abort_cmd;
ataStartTransfer(s, ATAPI_PACKET_SIZE, PDMBLOCKTXDIR_TO_DEVICE, ATAFN_BT_PACKET, ATAFN_SS_PACKET, false);
switch (addr)
Log2(("%s: LUN#%d asserting IRQ (drive select change)\n", __FUNCTION__, pCtl->aIfs[pCtl->iSelectedIf].iLUN));
Log2(("%s: LUN#%d deasserting IRQ (drive select change)\n", __FUNCTION__, pCtl->aIfs[pCtl->iSelectedIf].iLUN));
#ifndef IN_RING3
return VINF_IOM_HC_IOPORT_WRITE;
return VINF_SUCCESS;
bool fHOB;
if (!s->pDrvBlock)
val = 0;
if (!s->pDrvBlock)
val = 0;
else if (fHOB)
if (!s->pDrvBlock)
val = 0;
else if (fHOB)
if (!s->pDrvBlock)
val = 0;
else if (fHOB)
if (!s->pDrvBlock)
val = 0;
else if (fHOB)
val = 0;
static unsigned cBusy = 0;
if (!s->pDrvBlock)
val = 0;
#ifdef IN_RING3
cBusy = 0;
#ifndef RT_OS_WINDOWS
cBusy = 0;
return VINF_IOM_HC_IOPORT_READ;
cBusy = 0;
ataUnsetIRQ(s);
return VINF_SUCCESS;
val = 0;
return val;
#ifndef IN_RING3
#ifdef IN_RING3
LogRel(("PIIX3 ATA: Ctl#%d: RESET, DevSel=%d AIOIf=%d CmdIf0=%#04x (%d usec ago) CmdIf1=%#04x (%d usec ago)\n",
#ifdef IN_RING3
Log2(("%s: LUN#%d asserting IRQ (interrupt disable change)\n", __FUNCTION__, pCtl->aIfs[pCtl->iSelectedIf].iLUN));
Log2(("%s: LUN#%d deasserting IRQ (interrupt disable change)\n", __FUNCTION__, pCtl->aIfs[pCtl->iSelectedIf].iLUN));
return VINF_SUCCESS;
#ifdef IN_RING3
ATADevState *s;
LogRel(("PIIX3 ATA: LUN#%d: %s data in the middle of a PIO transfer - VERY SLOW\n", s->iLUN, s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE ? "loading" : "storing"));
bool fRedo;
s->iIOBufferCur = 0;
if (s->cbTotalTransfer)
if (s->fATAPITransfer)
Log2(("%s: Ctl#%d: suppressed continuing PIO transfer as RESET is active\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Log2(("%s: Ctl#%d: message to async I/O thread, continuing PIO transfer\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
if (s->cbTotalTransfer)
ataSetIRQ(s);
Log2(("%s: Ctl#%d: skipping message to async I/O thread, ending PIO transfer\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
uint8_t *p;
#ifndef IN_RING3
return VINF_IOM_HC_IOPORT_WRITE;
return VINF_SUCCESS;
uint8_t *p;
#ifndef IN_RING3
return VINF_IOM_HC_IOPORT_READ;
return VINF_SUCCESS;
#ifdef IN_RING3
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
bool fRedo;
bool fLastDesc = false;
if (cbBuffer == 0)
iIOBufferCur = 0;
LogRel(("PIIX3 ATA: Ctl#%d: ABORT DMA%s\n", ATACONTROLLER_IDX(pCtl), pCtl->fReset ? " due to RESET" : ""));
if (fLastDesc)
ATADevState *s;
Log2(("%s: Ctl#%d: state=%d, req=%d\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), pCtl->uAsyncIOState, ReqType));
AssertReleaseMsg(ReqType == ATA_AIO_RESET_ASSERTED || ReqType == ATA_AIO_RESET_CLEARED || ReqType == ATA_AIO_ABORT || pCtl->uAsyncIOState == ReqType, ("I/O state inconsistent: state=%d request=%d\n", pCtl->uAsyncIOState, ReqType));
switch (ReqType)
case ATA_AIO_NEW:
s->iIOBufferEnd = 0;
if (s->fATAPI)
if (s->fDMA)
if (s->fDMA)
s->iIOBufferCur = 0;
bool fRedo;
ataCmdOK(s, 0);
if (s->fDMA)
if (s->cbTotalTransfer)
Log2(("%s: Ctl#%d: message to async I/O thread, continuing DMA transfer immediately\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Assert(s->uTxDir == PDMBLOCKTXDIR_NONE); /* Any transfer which has an initial transfer size of 0 must be marked as such. */
ataSetIRQ(s);
if (s->cbTotalTransfer)
ataSetIRQ(s);
Assert(s->uTxDir == PDMBLOCKTXDIR_NONE); /* Any transfer which has an initial transfer size of 0 must be marked as such. */
if (!s->fATAPITransfer)
ataSetIRQ(s);
case ATA_AIO_DMA:
s = &pCtl->aIfs[pCtl->iAIOIf]; /* Do not remove or there's an instant crash after loading the saved state */
ATAFNSS iOriginalSourceSink = (ATAFNSS)s->iSourceSink; /* Used by the hack below, but gets reset by then. */
&& s->cbTotalTransfer == 0
if (s->fATAPITransfer)
Log2(("%s: Ctl#%d: interrupt reason %#04x\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), s->uATARegNSector));
s->fATAPITransfer = false;
ataSetIRQ(s);
case ATA_AIO_PIO:
s = &pCtl->aIfs[pCtl->iAIOIf]; /* Do not remove or there's an instant crash after loading the saved state */
bool fRedo;
s->iIOBufferCur = 0;
if (s->cbTotalTransfer)
ataSetIRQ(s);
&& !s->fATAPITransfer
ataSetIRQ(s);
case ATA_AIO_RESET_ASSERTED:
case ATA_AIO_RESET_CLEARED:
case ATA_AIO_ABORT:
ataResetDevice(s);
s->fDMA = false;
ataSetIRQ(s);
Log(("%s: Ctl#%d: LUN#%d finished I/O transaction in %d microseconds\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), pCtl->aIfs[pCtl->iAIOIf].iLUN, (uint32_t)(uWait)));
LogRel(("PIIX3 ATA: execution time for ATA command %#04x was %d seconds\n", pCtl->aIfs[pCtl->iAIOIf].uATARegCommand, uWait / (1000 * 1000)));
LogRel(("PIIX3 ATA: execution time for ATAPI command %#04x was %d seconds\n", pCtl->aIfs[pCtl->iAIOIf].aATAPICmd[0], uWait / (1000 * 1000)));
return rc;
return val;
#ifdef IN_RING3
Log2(("%s: Ctl#%d: suppressed continuing DMA transfer as RESET is active\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Log2(("%s: Ctl#%d: message to async I/O thread, continuing DMA transfer\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
return val;
return val;
PDMBOTHCBDECL(int) ataBMDMAIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
int rc;
return rc;
return VERR_IOM_IOPORT_UNUSED;
return rc;
PDMBOTHCBDECL(int) ataBMDMAIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
int rc;
return rc;
#ifndef IN_RING3
default: AssertMsgFailed(("%s: Unsupported write to port %x size=%d val=%x\n", __FUNCTION__, Port, cb, u32)); break;
return rc;
#ifdef IN_RING3
static DECLCALLBACK(int) ataBMDMAIORangeMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion, RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
AssertMsg(RT_ALIGN(GCPhysAddress, 8) == GCPhysAddress, ("Expected 8 byte alignment. GCPhysAddress=%#x\n", GCPhysAddress));
return rc;
return NULL;
static DECLCALLBACK(int) ataStatus_QueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
switch (iLUN)
return VINF_SUCCESS;
return VERR_PDM_LUN_NOT_FOUND;
return NULL;
PDMBOTHCBDECL(int) ataIOPortWrite1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
return rc;
return rc;
PDMBOTHCBDECL(int) ataIOPortRead1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
return rc;
return rc;
PDMBOTHCBDECL(int) ataIOPortReadStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfer, unsigned cb)
return rc;
#ifndef IN_RING3
/* Deal with the unlikely case where no data (or not enough for the read length operation) is available; go back to ring 3. */
if (!cTransAvailable)
return VINF_IOM_HC_IOPORT_READ;
rc = PGMPhysSimpleDirtyWriteGCPtr(PDMDevHlpGetVMCPU(pDevIns), GCDst, s->CTX_SUFF(pbIOBuffer) + s->iIOBufferPIODataStart, cbTransfer);
if (cbTransfer)
Log3(("%s: addr=%#x val=%.*Rhxs\n", __FUNCTION__, Port, cbTransfer, s->CTX_SUFF(pbIOBuffer) + s->iIOBufferPIODataStart));
#ifdef IN_RING3
return rc;
PDMBOTHCBDECL(int) ataIOPortWriteStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, PRTGCUINTREG pcTransfer, unsigned cb)
int rc;
return rc;
#ifndef IN_RING3
/* Deal with the unlikely case where no data (or not enough for the read length operation) is available; go back to ring 3. */
if (!cTransAvailable)
return VINF_IOM_HC_IOPORT_WRITE;
rc = PGMPhysSimpleReadGCPtr(PDMDevHlpGetVMCPU(pDevIns), s->CTX_SUFF(pbIOBuffer) + s->iIOBufferPIODataStart, GCSrc, cbTransfer);
if (cbTransfer)
Log3(("%s: addr=%#x val=%.*Rhxs\n", __FUNCTION__, Port, cbTransfer, s->CTX_SUFF(pbIOBuffer) + s->iIOBufferPIODataStart));
#ifdef IN_RING3
return rc;
PDMBOTHCBDECL(int) ataIOPortWrite2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
int rc;
return VINF_SUCCESS;
return rc;
return rc;
PDMBOTHCBDECL(int) ataIOPortRead2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
int rc;
return VERR_IOM_IOPORT_UNUSED;
return rc;
return VINF_SUCCESS;
#ifdef IN_RING3
if (s->pbIOBufferR3)
int rc;
LogRel(("PIIX3 ATA Dtor: Ctl#%u is still executing, DevSel=%d AIOIf=%d CmdIf0=%#04x CmdIf1=%#04x rc=%Rrc\n",
return VINF_SUCCESS;
unsigned iController;
unsigned iInterface;
AssertReleaseMsg(iController < RT_ELEMENTS(pThis->aCts), ("iController=%d iLUN=%d\n", iController, iLUN));
return VERR_PDM_MISSING_INTERFACE;
return VERR_PDM_MISSING_INTERFACE;
AssertMsgFailed(("Configuration error: LUN#%d isn't a disk or cd/dvd-rom. enmType=%d\n", pIf->iLUN, enmType));
return VERR_PDM_UNSUPPORTED_BLOCK_TYPE;
return VERR_INTERNAL_ERROR;
rc = MMR3HyperAllocOnceNoRel(pVM, pIf->cbIOBuffer, 0, MM_TAG_PDM_DEVICE_USER, (void **)&pIf->pbIOBufferR3);
return VERR_NO_MEMORY;
LogRel(("PIIX3 ATA: LUN#%d: CD/DVD, total number of sectors %Ld, passthrough %s\n", pIf->iLUN, pIf->cTotalSectors, (pIf->fATAPIPassthrough ? "enabled" : "disabled")));
LogRel(("PIIX3 ATA: LUN#%d: disk, PCHS=%u/%u/%u, total number of sectors %Ld\n", pIf->iLUN, pIf->PCHSGeometry.cCylinders, pIf->PCHSGeometry.cHeads, pIf->PCHSGeometry.cSectors, pIf->cTotalSectors));
return rc;
int rc;
unsigned iController;
unsigned iInterface;
AssertReleaseMsg(iController < RT_ELEMENTS(pThis->aCts), ("iController=%d iLUN=%d\n", iController, iLUN));
return rc;
int rc;
if (!fRc)
if (!fRc)
if (!fConstruct)
return rcRet;
return VINF_SUCCESS;
return VINF_SSM_DONT_CALL_AGAIN;
SSMR3PutMem(pSSM, &pThis->aCts[i].aIfs[j].abATAPISense, sizeof(pThis->aCts[i].aIfs[j].abATAPISense));
switch (iLun)
static DECLCALLBACK(int) ataLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
int rc;
return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Config mismatch: u8Type - saved=%u config=%u"), u8Type, pThis->u8Type);
bool fEnabled;
if (!fEnabled)
bool fInUse;
N_("The %s VM is missing a %s device. Please make sure the source and target VMs have compatible storage configurations"),
return VINF_SUCCESS;
return VERR_INTERNAL_ERROR_4;
SSMR3GetMem(pSSM, pThis->aCts[i].aIfs[j].abATAPISense, sizeof(pThis->aCts[i].aIfs[j].abATAPISense));
while (cbLeft-- > 0)
return rc;
if (u32 != ~0U)
return rc;
return VINF_SUCCESS;
szType);
return rc;
int rc;
bool fGCEnabled;
bool fR0Enabled;
return rc;
case CHIPSET_ICH6:
* See www.intel.com/Assets/PDF/manual/298600.pdf p. 30
case CHIPSET_PIIX4:
case CHIPSET_PIIX3:
PCIDevSetCommand( &pThis->dev, PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS | PCI_COMMAND_BUSMASTER);
PCIDevSetClassProg( &pThis->dev, 0x8a); /* programming interface = PCI_IDE bus master is supported */
if (fGCEnabled)
if (fR0Enabled)
if (fGCEnabled)
if (fR0Enabled)
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatATADMA, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatATAPIO, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatATAPIDMA, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatATAPIPIO, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatReads, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatBytesRead, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,
#ifdef VBOX_INSTRUMENT_DMA_WRITES
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatInstrVDWrites,STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
"Profiling of the VD DMA write operations.", "/Devices/IDE%d/ATA%d/Unit%d/InstrVDWrites", iInstance, i, j);
#ifdef VBOX_WITH_STATISTICS
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatWrites, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatBytesWritten, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES,
#ifdef VBOX_WITH_STATISTICS
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatFlushes, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncOps, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES,
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncMinWait, STAMTYPE_U64_RESET, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncMaxWait, STAMTYPE_U64_RESET, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncTimeUS, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE,
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncTime, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatLockWait, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL,
Assert(pCtl->AsyncIOThread != NIL_RTTHREAD && pCtl->AsyncIOSem != NIL_RTSEMEVENT && pCtl->SuspendIOSem != NIL_RTSEMEVENT && pCtl->AsyncIORequestMutex != NIL_RTSEMMUTEX);
Log(("%s: controller %d AIO thread id %#x; sem %p susp_sem %p mutex %p\n", __FUNCTION__, i, pCtl->AsyncIOThread, pCtl->AsyncIOSem, pCtl->SuspendIOSem, pCtl->AsyncIORequestMutex));
rc = CFGMR3QueryStringDef(pCfgNode, "SerialNumber", pIf->szSerialNumber, sizeof(pIf->szSerialNumber),
szSerial);
rc = CFGMR3QueryStringDef(pCfgNode, "FirmwareRevision", pIf->szFirmwareRevision, sizeof(pIf->szFirmwareRevision),
rc = CFGMR3QueryStringDef(pCfgNode, "ATAPIVendorId", pIf->szInquiryVendorId, sizeof(pIf->szInquiryVendorId),
rc = CFGMR3QueryStringDef(pCfgNode, "ATAPIProductId", pIf->szInquiryProductId, sizeof(pIf->szInquiryProductId),
rc = CFGMR3QueryStringDef(pCfgNode, "ATAPIRevision", pIf->szInquiryRevision, sizeof(pIf->szInquiryRevision),
switch (rc)
case VERR_ACCESS_DENIED:
return rc;
s_apszDescs[i][j]);
sizeof(PCIATAState),
NULL,
NULL,
NULL,
NULL,
NULL,