DevATA.cpp revision ae2c86459198976fb5203a35c7c593b8b58d11c2
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * VBox storage devices: ATA/ATAPI controller device (disk and cdrom).
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Copyright (C) 2006-2008 Sun Microsystems, Inc.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * available from http://www.virtualbox.org. This file is free software;
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * you can redistribute it and/or modify it under the terms of the GNU
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * General Public License (GPL) as published by the Free Software
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * additional information or have any questions.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*******************************************************************************
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync* Defined Constants And Macros *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync*******************************************************************************/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** Temporary instrumentation for tracking down potential virtual disk
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * write performance issues. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * The SSM saved state versions.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATA_SAVED_STATE_VERSION_WITHOUT_FULL_SENSE 16
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATA_SAVED_STATE_VERSION_WITHOUT_EVENT_STATUS 17
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*******************************************************************************
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync* Header Files *
628ddfbd43ad5365d69fddda4007598242956577vboxsync*******************************************************************************/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#endif /* IN_RING3 */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*******************************************************************************
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync* Defined Constants And Macros *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync*******************************************************************************/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Maximum number of sectors to transfer in a READ/WRITE MULTIPLE request.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Set to 1 to disable multi-sector read support. According to the ATA
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * specification this must be a power of 2 and it must fit in an 8 bit
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * value. Thus the only valid values are 1, 2, 4, 8, 16, 32, 64 and 128.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Fastest PIO mode supported by the drive.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Fastest MDMA mode supported by the drive.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Fastest UDMA mode supported by the drive.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** ATAPI sense info size. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/** The maximum number of release log entries per device. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/* MediaEventStatus */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATA_EVENT_STATUS_UNCHANGED 0 /**< medium event status not changed */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATA_EVENT_STATUS_MEDIA_NEW 1 /**< new medium inserted */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATA_EVENT_STATUS_MEDIA_REMOVED 2 /**< medium removed */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATA_EVENT_STATUS_MEDIA_CHANGED 3 /**< medium was removed + new medium was inserted */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Length of the configurable VPD data (without termination)
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync/*******************************************************************************
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync* Structures and Typedefs *
54d3b0107d9bf326fe6e0de92e012c791dbb1587vboxsync*******************************************************************************/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsynctypedef struct ATADevState {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag indicating whether the current command uses LBA48 mode. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag indicating whether this drive implements the ATAPI command set. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Set if this interface has asserted the IRQ. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Currently configured number of sectors in a multi-sector transfer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** PCHS disk geometry. */
1330d766d6c411e4937f22e4e6aee1732a4873b0vboxsync /** Total number of sectors on this disk. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Number of sectors to transfer per IRQ. */
23c03b3208f2fe46af3705791f6f38cdb2642f19vboxsync /** ATA/ATAPI register 1: feature (write-only). */
23c03b3208f2fe46af3705791f6f38cdb2642f19vboxsync /** ATA/ATAPI register 1: feature, high order byte. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 1: error (read-only). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 2: sector count (read/write). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 2: sector count, high order byte. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 3: sector, high order byte. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 4: cylinder low (read/write). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 4: cylinder low, high order byte. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 5: cylinder high (read/write). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 5: cylinder high, high order byte. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 6: select drive/head (read/write). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI register 7: status (read-only). */
cd0318d4ff9c5a7539bea1672f9bcbbf57e59095vboxsync /** ATA/ATAPI register 7: command (write-only). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI drive control register (write-only). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Currently active transfer mode (MDMA/UDMA) and speed. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Current transfer direction. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Index of callback for begin transfer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Index of callback for source/sink of data. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag indicating whether the current command transfers data in DMA mode. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Set to indicate that ATAPI transfer semantics must be used. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Total ATA/ATAPI transfer size, shared PIO/DMA. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Elementary ATA/ATAPI transfer size, shared PIO/DMA. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Current read/write buffer position, shared PIO/DMA. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** First element beyond end of valid buffer content, shared PIO/DMA. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI current PIO read/write transfer position. Not shared with DMA for safety reasons. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATA/ATAPI current PIO read/write transfer end. Not shared with DMA for safety reasons. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATAPI current LBA position. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATAPI current sector size. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATAPI current command. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** ATAPI sense data. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** HACK: Countdown till we report a newly unmounted drive as mounted. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The same for GET_EVENT_STATUS for mechanism */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The status LED state for this drive. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Size of I/O buffer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to the I/O buffer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to the I/O buffer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to the I/O buffer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTRCPTR Aligmnent1; /**< Align the statistics at an 8-byte boundrary. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * No data that is part of the saved state after this point!!!!!
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Release statistics: number of ATA DMA commands. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Release statistics: number of ATA PIO commands. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Release statistics: number of ATAPI PIO commands. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Release statistics: number of ATAPI PIO commands. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Release statistics: number of DMA sector writes and the time spent. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Statistics: number of read operations and the time spent reading. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Statistics: number of bytes read. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Statistics: number of write operations and the time spent writing. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Statistics: number of bytes written. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Statistics: number of flush operations and the time spend flushing. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Enable passing through commands directly to the ATAPI drive. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Number of errors we've reported to the release log.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This is to prevent flooding caused by something going horribly wrong.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * this value against MAX_LOG_REL_ERRORS in places likely to cause floods
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * like the ones we currently seeing on the linux smoke tests (2006-11-10). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Timestamp of last started command. 0 if no command pending. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to the attached driver's base interface. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to the attached driver's block interface. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to the attached driver's block bios interface. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to the attached driver's mount interface.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * This is NULL if the driver isn't a removable unit. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The base interface. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The block port interface. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The mount notify interface. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The LUN #. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync RTUINT Alignment2; /**< Align pDevInsR3 correctly. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to device instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to controller instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to device instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to controller instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to device instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to controller instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The serial numnber to use for IDENTIFY DEVICE commands. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The firmware revision to use for IDENTIFY DEVICE commands. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync char achFirmwareRevision[ATA_FIRMWARE_REVISION_LENGTH+1];
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The model number to use for IDENTIFY DEVICE commands. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsynctypedef enum
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Begin a new transfer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Continue a DMA transfer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Continue a PIO transfer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Reset the drives on current controller, stop all transfer activity. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Reset the drives on current controller, resume operation. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Abort the current transfer of a particular drive. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsynctypedef struct ATARequest
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The base of the first I/O Port range. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The base of the second I/O Port range. (0 if none) */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The assigned IRQ. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Access critical section */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Selected drive. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The interface on which to handle async I/O. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The state of the async I/O thread. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag indicating whether the next transfer is part of the current command. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Set when the reset processing is currently active on this controller. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag whether the current transfer needs to be redone. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag whether the redo suspend has been finished. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag whether the DMA operation to be redone is the final transfer. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The BusMaster DMA state. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to first DMA descriptor. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to last DMA descriptor. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to current DMA buffer (for redo operations). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Size of current DMA buffer (for redo operations). */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The ATA/ATAPI interfaces of this controller. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to device instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to device instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to device instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Set when the destroying the device instance and the thread must exit. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The async I/O thread handle. NIL_RTTHREAD if no thread. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The event semaphore the thread is waiting on for requests. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The request queue for the AIO thread. One element is always unused. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The position at which to insert a new request for the AIO thread. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The position at which to get a new request for the AIO thread. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync uint8_t Alignment3[2]; /**< Explicit padding of the 2 byte gap. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Magic delay before triggering interrupts in DMA mode. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The mutex protecting the request queue. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The event semaphore the thread is waiting on during suspended I/O. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#if 0 /*HC_ARCH_BITS == 32*/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Statistics */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsynctypedef struct PCIATAState {
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** The controllers. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Pointer to device instance. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Status Port - Base interface. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Status Port - Leds interface. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Partner of ILeds. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag whether GC is enabled. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag whether R0 is enabled. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /** Flag indicating whether PIIX4 or PIIX3 is being emulated. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync bool Alignment0[HC_ARCH_BITS == 64 ? 5 : 1]; /**< Align the struct size. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define PDMIBASE_2_PCIATASTATE(pInterface) ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, IBase)) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define PDMILEDPORTS_2_PCIATASTATE(pInterface) ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, ILeds)) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define PDMIBLOCKPORT_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IPort)) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define PDMIMOUNT_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMount)) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define PDMIMOUNTNOTIFY_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMountNotify)) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define PCIDEV_2_PCIATASTATE(pPciDev) ( (PCIATAState *)(pPciDev) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATACONTROLLER_IDX(pController) ( (pController) - PDMINS_2_DATA(CONTROLLER_2_DEVINS(pController), PCIATAState *)->aCts )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATADEVSTATE_2_CONTROLLER(pIf) ( (pIf)->CTX_SUFF(pController) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define ATADEVSTATE_2_DEVINS(pIf) ( (pIf)->CTX_SUFF(pDevIns) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define CONTROLLER_2_DEVINS(pController) ( (pController)->CTX_SUFF(pDevIns) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync#define PDMIBASE_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IBase)) )
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync/*******************************************************************************
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Internal Functions *
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync ******************************************************************************/
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPDMBOTHCBDECL(int) ataIOPortWrite1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPDMBOTHCBDECL(int) ataIOPortRead1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *u32, unsigned cb);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPDMBOTHCBDECL(int) ataIOPortWriteStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, PRTGCUINTREG pcTransfer, unsigned cb);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPDMBOTHCBDECL(int) ataIOPortReadStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfer, unsigned cb);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPDMBOTHCBDECL(int) ataIOPortWrite2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPDMBOTHCBDECL(int) ataIOPortRead2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *u32, unsigned cb);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPDMBOTHCBDECL(int) ataBMDMAIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncPDMBOTHCBDECL(int) ataBMDMAIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncDECLINLINE(void) ataSetStatusValue(ATADevState *s, uint8_t stat)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Freeze status register contents while processing RESET. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncDECLINLINE(void) ataSetStatus(ATADevState *s, uint8_t stat)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Freeze status register contents while processing RESET. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncDECLINLINE(void) ataUnsetStatus(ATADevState *s, uint8_t stat)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync /* Freeze status register contents while processing RESET. */
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic bool ataExecuteDeviceDiagnosticSS(ATADevState *);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic bool atapiGetEventStatusNotificationSS(ATADevState *);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic bool atapiModeSenseErrorRecoverySS(ATADevState *);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic bool atapiModeSenseCDStatusSS(ATADevState *);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic bool atapiReadDiscInformationSS(ATADevState *);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic bool atapiReadTrackInformationSS(ATADevState *);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Begin of transfer function indexes for g_apfnBeginTransFuncs.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Array of end transfer functions, the index is ATAFNET.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Make sure ATAFNET and this array match!
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic const PBeginTransferFunc g_apfnBeginTransFuncs[ATAFN_BT_MAX] =
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Source/sink function indexes for g_apfnSourceSinkFuncs.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Array of source/sink functions, the index is ATAFNSS.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Make sure ATAFNSS and this array match!
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic const PSourceSinkFunc g_apfnSourceSinkFuncs[ATAFN_SS_MAX] =
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic const ATARequest ataDMARequest = { ATA_AIO_DMA, };
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic const ATARequest ataPIORequest = { ATA_AIO_PIO, };
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic const ATARequest ataResetARequest = { ATA_AIO_RESET_ASSERTED, };
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic const ATARequest ataResetCRequest = { ATA_AIO_RESET_CLEARED, };
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic void ataAsyncIOClearRequests(PATACONTROLLER pCtl)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic void ataAsyncIOPutRequest(PATACONTROLLER pCtl, const ATARequest *pReq)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync Assert((pCtl->AsyncIOReqHead + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests) != pCtl->AsyncIOReqTail);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync memcpy(&pCtl->aAsyncIORequests[pCtl->AsyncIOReqHead], pReq, sizeof(*pReq));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pCtl->AsyncIOReqHead %= RT_ELEMENTS(pCtl->aAsyncIORequests);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogBird(("ata: %x: signalling\n", pCtl->IOPortBase1));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = PDMR3CritSectScheduleExitEvent(&pCtl->lock, pCtl->AsyncIOSem);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogBird(("ata: %x: schedule failed, rc=%Rrc\n", pCtl->IOPortBase1, rc));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic const ATARequest *ataAsyncIOGetCurrentRequest(PATACONTROLLER pCtl)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pReq = &pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail];
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Remove the request with the given type, as it's finished. The request
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * is not removed blindly, as this could mean a RESET request that is not
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * yet processed (but has cleared the request queue) is lost.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pCtl Controller for which to remove the request.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param ReqType Type of the request to remove.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic void ataAsyncIORemoveCurrentRequest(PATACONTROLLER pCtl, ATAAIO ReqType)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync if (pCtl->AsyncIOReqHead != pCtl->AsyncIOReqTail && pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail].ReqType == ReqType)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync pCtl->AsyncIOReqTail %= RT_ELEMENTS(pCtl->aAsyncIORequests);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Dump the request queue for a particular controller. First dump the queue
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * contents, then the already processed entries, as long as they haven't been
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * overwritten.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pCtl Controller for which to dump the queue.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic void ataAsyncIODumpRequests(PATACONTROLLER pCtl)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogRel(("PIIX3 ATA: Ctl#%d: request queue dump (topmost is current):\n", ATACONTROLLER_IDX(pCtl)));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogRel(("PIIX3 ATA: Ctl#%d: processed requests (topmost is oldest):\n", ATACONTROLLER_IDX(pCtl)));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync 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));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogRel(("abort request, iIf=%d fResetDrive=%d\n", pCtl->aAsyncIORequests[curr].u.a.iIf, pCtl->aAsyncIORequests[curr].u.a.fResetDrive));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync LogRel(("unknown request %d\n", pCtl->aAsyncIORequests[curr].ReqType));
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync curr = (curr + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Checks whether the request queue for a particular controller is empty
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * or whether a particular controller is idle.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param pCtl Controller for which to check the queue.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param fStrict If set then the controller is checked to be idle.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic bool ataAsyncIOIsIdle(PATACONTROLLER pCtl, bool fStrict)
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync fIdle = (pCtl->AsyncIOReqHead == pCtl->AsyncIOReqTail);
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * Send a transfer request to the async I/O thread.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param s Pointer to the ATA device state data.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param cbTotalTransfer Data transfer size.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param uTxDir Data transfer direction.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param iBeginTransfer Index of BeginTransfer callback.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param iSourceSink Index of SourceSink callback.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsync * @param fChainedTransfer Whether this is a transfer that is part of the previous command/transfer.
1c2c968fd241148110002d75b2c0fdeddc211e14vboxsyncstatic 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;
uint16_t *p;
ataPadString((uint8_t *)(p + 10), s->achSerialNumber, ATA_SERIAL_NUMBER_LENGTH); /* serial number */
ataPadString((uint8_t *)(p + 23), s->achFirmwareRevision, 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 + 10), s->achSerialNumber, ATA_SERIAL_NUMBER_LENGTH); /* serial number */
ataPadString((uint8_t *)(p + 23), s->achFirmwareRevision, 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;
return rc;
static int ataWriteSectors(ATADevState *s, uint64_t u64Sector, const void *pvBuf, uint32_t cSectors)
int rc;
#ifdef VBOX_INSTRUMENT_DMA_WRITES
if (s->fDMA)
#ifdef VBOX_INSTRUMENT_DMA_WRITES
if (s->fDMA)
return rc;
ataCmdOK(s, 0);
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;
int rc;
if (!s->cbTotalTransfer)
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++;
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);
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)
s->cNotifiedMediaChange = 0;
ataUnsetIRQ(s);
ataSetSignature(s);
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
s->iIOBufferPIODataStart = 0;
s->iIOBufferPIODataEnd = 0;
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;
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)
int rc;
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);
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;
N_("The IDE async I/O thread remained busy after a reset, usually a host filesystem performance problem\n"));
static DECLCALLBACK(void *) ataStatus_QueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
switch (enmInterface)
case PDMINTERFACE_BASE:
case PDMINTERFACE_LED_PORTS:
return NULL;
static DECLCALLBACK(int) ataStatus_QueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
switch (iLUN)
return VINF_SUCCESS;
return VERR_PDM_LUN_NOT_FOUND;
switch (enmInterface)
case PDMINTERFACE_BASE:
case PDMINTERFACE_BLOCK_PORT:
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;
#ifndef IN_RING0
PDMBOTHCBDECL(int) ataIOPortReadStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfer, unsigned cb)
return rc;
#ifndef IN_RING3
#ifdef IN_RC
MMGCRamWriteNoTrapHandler((char *)GCDst + i, s->CTX_SUFF(pbIOBuffer) + s->iIOBufferPIODataStart + i, cb);
rc = PGMPhysSimpleDirtyWriteGCPtr(PDMDevHlpGetVM(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
#ifdef IN_RC
MMGCRamReadNoTrapHandler(s->CTX_SUFF(pbIOBuffer) + s->iIOBufferPIODataStart + i, (char *)GCSrc + i, cb);
rc = PGMPhysSimpleReadGCPtr(PDMDevHlpGetVM(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
bool fVMLocked;
bool fAllIdle = false;
if (fVMLocked)
fAllIdle = true;
if (!fAllIdle)
if ( fAllIdle
if (fVMLocked)
if (!fAllIdle)
return fAllIdle;
if (s->pbIOBufferR3)
int rc;
return VINF_SUCCESS;
unsigned iController;
unsigned iInterface;
AssertReleaseMsg(iController < RT_ELEMENTS(pThis->aCts), ("iController=%d iLUN=%d\n", iController, iLUN));
int rc;
return VERR_PDM_MISSING_INTERFACE;
pIf->pDrvBlockBios = (PDMIBLOCKBIOS *)pIf->pDrvBase->pfnQueryInterface(pIf->pDrvBase, PDMINTERFACE_BLOCK_BIOS);
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 VINF_SUCCESS;
int rc;
unsigned iController;
unsigned iInterface;
AssertReleaseMsg(iController < RT_ELEMENTS(pThis->aCts), ("iController=%d iLUN=%d\n", iController, iLUN));
return rc;
int rc;
return VERR_SSM_IDE_ASYNC_TIMEOUT;
return VINF_SUCCESS;
SSMR3PutMem(pSSMHandle, &pThis->aCts[i].aIfs[j].aATAPICmd, sizeof(pThis->aCts[i].aIfs[j].aATAPICmd));
SSMR3PutMem(pSSMHandle, &pThis->aCts[i].aIfs[j].abATAPISense, sizeof(pThis->aCts[i].aIfs[j].abATAPISense));
SSMR3PutMem(pSSMHandle, pThis->aCts[i].aIfs[j].CTX_SUFF(pbIOBuffer), pThis->aCts[i].aIfs[j].cbIOBuffer);
static DECLCALLBACK(int) ataLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t u32Version)
int rc;
return rc;
SSMR3GetMem(pSSMHandle, &pThis->aCts[i].aIfs[j].aATAPICmd, sizeof(pThis->aCts[i].aIfs[j].aATAPICmd));
SSMR3GetMem(pSSMHandle, pThis->aCts[i].aIfs[j].abATAPISense, sizeof(pThis->aCts[i].aIfs[j].abATAPISense));
SSMR3GetMem(pSSMHandle, pThis->aCts[i].aIfs[j].CTX_SUFF(pbIOBuffer), pThis->aCts[i].aIfs[j].cbIOBuffer);
return VERR_SSM_LOAD_CONFIG_MISMATCH;
while (cbLeft-- > 0)
return rc;
if (u32 != ~0U)
return rc;
return VINF_SUCCESS;
int rc;
bool fGCEnabled;
bool fR0Enabled;
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, "Number of ATA DMA transfers.", "/Devices/ATA%d/Unit%d/DMA", i, j);
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatATAPIO, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of ATA PIO transfers.", "/Devices/ATA%d/Unit%d/PIO", i, j);
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatATAPIDMA, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of ATAPI DMA transfers.", "/Devices/ATA%d/Unit%d/AtapiDMA", i, j);
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatATAPIPIO, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "Number of ATAPI PIO transfers.", "/Devices/ATA%d/Unit%d/AtapiPIO", i, j);
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatReads, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling of the read operations.", "/Devices/ATA%d/Unit%d/Reads", i, j);
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatBytesRead, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Amount of data read.", "/Devices/ATA%d/Unit%d/ReadBytes", i, j);
#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/ATA%d/Unit%d/InstrVDWrites", i, j);
#ifdef VBOX_WITH_STATISTICS
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatWrites, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling of the write operations.","/Devices/ATA%d/Unit%d/Writes", i, j);
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatBytesWritten, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_BYTES, "Amount of data written.", "/Devices/ATA%d/Unit%d/WrittenBytes", i, j);
#ifdef VBOX_WITH_STATISTICS
PDMDevHlpSTAMRegisterF(pDevIns, &pIf->StatFlushes, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling of the flush operations.","/Devices/ATA%d/Unit%d/Flushes", i, j);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncOps, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "The number of async operations.", "/Devices/ATA%d/Async/Operations", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncMinWait, STAMTYPE_U64_RESET, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, "Minimum wait in microseconds.", "/Devices/ATA%d/Async/MinWait", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncMaxWait, STAMTYPE_U64_RESET, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, "Maximum wait in microseconds.", "/Devices/ATA%d/Async/MaxWait", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncTimeUS, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, "Total time spent in microseconds.","/Devices/ATA%d/Async/TotalTimeUS", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatAsyncTime, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling of async operations.", "/Devices/ATA%d/Async/Time", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pThis->aCts[i].StatLockWait, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling of locks.", "/Devices/ATA%d/Async/LockWait", i);
pThis->pLedsConnector = (PDMILEDCONNECTORS *)pBase->pfnQueryInterface(pBase, PDMINTERFACE_LED_CONNECTORS);
rc = RTThreadCreate(&pCtl->AsyncIOThread, ataAsyncIOLoop, (void *)pCtl, 128*1024, RTTHREADTYPE_IO, RTTHREADFLAGS_WAITABLE, "ATA");
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));
if (pCfgNode)
rc = CFGMR3QueryString(pCfgNode, "SerialNumber", pIf->achSerialNumber, sizeof(pIf->achSerialNumber));
rc = CFGMR3QueryString(pCfgNode, "FirmwareRevision", pIf->achFirmwareRevision, sizeof(pIf->achFirmwareRevision));
switch (rc)
case VERR_ACCESS_DENIED:
return rc;
s_apszDescs[i][j]);
return VINF_SUCCESS;
sizeof(PCIATAState),
NULL,
NULL,
NULL,
NULL,
NULL,