DevATA.cpp revision 954c328a44c68ccd408d540218239ff31973bace
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync * VBox storage devices: ATA/ATAPI controller device (disk and cdrom).
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Copyright (C) 2006-2008 Sun Microsystems, Inc.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * available from http://www.virtualbox.org. This file is free software;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * you can redistribute it and/or modify it under the terms of the GNU
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * General Public License (GPL) as published by the Free Software
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * additional information or have any questions.
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync/*******************************************************************************
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync* Defined Constants And Macros *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/** Temporary instrumentation for tracking down potential virtual disk
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * write performance issues. */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * The SSM saved state versions.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#define ATA_SAVED_STATE_VERSION_WITHOUT_FULL_SENSE 16
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync#define ATA_SAVED_STATE_VERSION_WITHOUT_EVENT_STATUS 17
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync/*******************************************************************************
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync* Header Files *
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync*******************************************************************************/
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync#endif /* IN_RING3 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync* Defined Constants And Macros *
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync*******************************************************************************/
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Maximum number of sectors to transfer in a READ/WRITE MULTIPLE request.
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync * Set to 1 to disable multi-sector read support. According to the ATA
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync * specification this must be a power of 2 and it must fit in an 8 bit
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync * value. Thus the only valid values are 1, 2, 4, 8, 16, 32, 64 and 128.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Fastest PIO mode supported by the drive.
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync * Fastest MDMA mode supported by the drive.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * Fastest UDMA mode supported by the drive.
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync/** ATAPI sense info size. */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync/** The maximum number of release log entries per device. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/* MediaEventStatus */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#define ATA_EVENT_STATUS_UNCHANGED 0 /**< medium event status not changed */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#define ATA_EVENT_STATUS_MEDIA_NEW 1 /**< new medium inserted */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync#define ATA_EVENT_STATUS_MEDIA_REMOVED 2 /**< medium removed */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync#define ATA_EVENT_STATUS_MEDIA_CHANGED 3 /**< medium was removed + new medium was inserted */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync/*******************************************************************************
0c94a8282c9042b02f022302a3d987746140eab9vboxsync* Structures and Typedefs *
0c94a8282c9042b02f022302a3d987746140eab9vboxsync*******************************************************************************/
0c94a8282c9042b02f022302a3d987746140eab9vboxsynctypedef struct ATADevState {
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Flag indicating whether the current command uses LBA48 mode. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Flag indicating whether this drive implements the ATAPI command set. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Set if this interface has asserted the IRQ. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Currently configured number of sectors in a multi-sector transfer. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** PCHS disk geometry. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Total number of sectors on this disk. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Number of sectors to transfer per IRQ. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 1: feature (write-only). */
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync /** ATA/ATAPI register 1: feature, high order byte. */
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync /** ATA/ATAPI register 1: error (read-only). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 2: sector count (read/write). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 2: sector count, high order byte. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 3: sector, high order byte. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 4: cylinder low (read/write). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 4: cylinder low, high order byte. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 5: cylinder high (read/write). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 5: cylinder high, high order byte. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 6: select drive/head (read/write). */
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync /** ATA/ATAPI register 7: status (read-only). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI register 7: command (write-only). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI drive control register (write-only). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Currently active transfer mode (MDMA/UDMA) and speed. */
f9cdd92d151d9c28eb0f1aed25863fc04f85691dvboxsync /** Current transfer direction. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Index of callback for begin transfer. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Index of callback for source/sink of data. */
f9cdd92d151d9c28eb0f1aed25863fc04f85691dvboxsync /** Flag indicating whether the current command transfers data in DMA mode. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Set to indicate that ATAPI transfer semantics must be used. */
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync /** Total ATA/ATAPI transfer size, shared PIO/DMA. */
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync /** Elementary ATA/ATAPI transfer size, shared PIO/DMA. */
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync /** Current read/write buffer position, shared PIO/DMA. */
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync /** First element beyond end of valid buffer content, shared PIO/DMA. */
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync /** ATA/ATAPI current PIO read/write transfer position. Not shared with DMA for safety reasons. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATA/ATAPI current PIO read/write transfer end. Not shared with DMA for safety reasons. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** ATAPI current LBA position. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** ATAPI current sector size. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** ATAPI current command. */
1969e98a26e5b56b67fbe3b6bfa007f8f09e86ebvboxsync /** ATAPI sense data. */
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync /** HACK: Countdown till we report a newly unmounted drive as mounted. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** The same for GET_EVENT_STATUS for mechanism */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** The status LED state for this drive. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Size of I/O buffer. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Pointer to the I/O buffer. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Pointer to the I/O buffer. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Pointer to the I/O buffer. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync RTRCPTR Aligmnent1; /**< Align the statistics at an 8-byte boundrary. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync * No data that is part of the saved state after this point!!!!!
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /* Release statistics: number of ATA DMA commands. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /* Release statistics: number of ATA PIO commands. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /* Release statistics: number of ATAPI PIO commands. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /* Release statistics: number of ATAPI PIO commands. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /* Release statistics: number of DMA sector writes and the time spent. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Statistics: number of read operations and the time spent reading. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Statistics: number of bytes read. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Statistics: number of write operations and the time spent writing. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Statistics: number of bytes written. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Statistics: number of flush operations and the time spend flushing. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Enable passing through commands directly to the ATAPI drive. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Number of errors we've reported to the release log.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * This is to prevent flooding caused by something going horribly wrong.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * this value against MAX_LOG_REL_ERRORS in places likely to cause floods
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * like the ones we currently seeing on the linux smoke tests (2006-11-10). */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** Timestamp of last started command. 0 if no command pending. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Pointer to the attached driver's base interface. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to the attached driver's block interface. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to the attached driver's block bios interface. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to the attached driver's mount interface.
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync * This is NULL if the driver isn't a removable unit. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** The base interface. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** The block port interface. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** The mount notify interface. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** The LUN #. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync RTUINT Alignment2; /**< Align pDevInsR3 correctly. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to device instance. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to controller instance. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to device instance. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to controller instance. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to device instance. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Pointer to controller instance. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** The serial numnber to use for IDENTIFY DEVICE commands. */
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync /** The firmware revision to use for IDENTIFY DEVICE commands. */
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync /** The model number to use for IDENTIFY DEVICE commands. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsynctypedef enum
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Begin a new transfer. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Continue a DMA transfer. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Continue a PIO transfer. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Reset the drives on current controller, stop all transfer activity. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** Reset the drives on current controller, resume operation. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /** Abort the current transfer of a particular drive. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsynctypedef struct ATARequest
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync /** The base of the first I/O Port range. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** The base of the second I/O Port range. (0 if none) */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** The assigned IRQ. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Access critical section */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Selected drive. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** The interface on which to handle async I/O. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** The state of the async I/O thread. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Flag indicating whether the next transfer is part of the current command. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Set when the reset processing is currently active on this controller. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Flag whether the current transfer needs to be redone. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Flag whether the redo suspend has been finished. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Flag whether the DMA operation to be redone is the final transfer. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** The BusMaster DMA state. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Pointer to first DMA descriptor. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Pointer to last DMA descriptor. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Pointer to current DMA buffer (for redo operations). */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** Size of current DMA buffer (for redo operations). */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** The ATA/ATAPI interfaces of this controller. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** Pointer to device instance. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** Pointer to device instance. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** Pointer to device instance. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /** Set when the destroying the device instance and the thread must exit. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /** The async I/O thread handle. NIL_RTTHREAD if no thread. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /** The event semaphore the thread is waiting on for requests. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /** The request queue for the AIO thread. One element is always unused. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /** The position at which to insert a new request for the AIO thread. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /** The position at which to get a new request for the AIO thread. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync uint8_t Alignment3[2]; /**< Explicit padding of the 2 byte gap. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** Magic delay before triggering interrupts in DMA mode. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** The mutex protecting the request queue. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync /** The event semaphore the thread is waiting on during suspended I/O. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#if 0 /*HC_ARCH_BITS == 32*/
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /* Statistics */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsynctypedef struct PCIATAState {
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** The controllers. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Pointer to device instance. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Status Port - Base interface. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Status Port - Leds interface. */
38745c55f37c31ba8b78cc728d2f08ea6eec38d6vboxsync /** Partner of ILeds. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Flag whether GC is enabled. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Flag whether R0 is enabled. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /** Flag indicating whether PIIX4 or PIIX3 is being emulated. */
0c94a8282c9042b02f022302a3d987746140eab9vboxsync bool Alignment0[HC_ARCH_BITS == 64 ? 5 : 1]; /**< Align the struct size. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define PDMIBASE_2_PCIATASTATE(pInterface) ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, IBase)) )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define PDMILEDPORTS_2_PCIATASTATE(pInterface) ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, ILeds)) )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define PDMIBLOCKPORT_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IPort)) )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define PDMIMOUNT_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMount)) )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define PDMIMOUNTNOTIFY_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMountNotify)) )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define PCIDEV_2_PCIATASTATE(pPciDev) ( (PCIATAState *)(pPciDev) )
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#define ATACONTROLLER_IDX(pController) ( (pController) - PDMINS_2_DATA(CONTROLLER_2_DEVINS(pController), PCIATAState *)->aCts )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define ATADEVSTATE_2_CONTROLLER(pIf) ( (pIf)->CTX_SUFF(pController) )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define ATADEVSTATE_2_DEVINS(pIf) ( (pIf)->CTX_SUFF(pDevIns) )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define CONTROLLER_2_DEVINS(pController) ( (pController)->CTX_SUFF(pDevIns) )
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync#define PDMIBASE_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IBase)) )
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync/*******************************************************************************
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync * Internal Functions *
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync ******************************************************************************/
66b58af085e22ee26be57f98127fb49ee2e91790vboxsyncPDMBOTHCBDECL(int) ataIOPortWrite1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsyncPDMBOTHCBDECL(int) ataIOPortRead1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *u32, unsigned cb);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsyncPDMBOTHCBDECL(int) ataIOPortWriteStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, PRTGCUINTREG pcTransfer, unsigned cb);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsyncPDMBOTHCBDECL(int) ataIOPortReadStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, PRTGCUINTREG pcTransfer, unsigned cb);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsyncPDMBOTHCBDECL(int) ataIOPortWrite2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsyncPDMBOTHCBDECL(int) ataIOPortRead2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *u32, unsigned cb);
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncPDMBOTHCBDECL(int) ataBMDMAIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncPDMBOTHCBDECL(int) ataBMDMAIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
f9cdd92d151d9c28eb0f1aed25863fc04f85691dvboxsyncDECLINLINE(void) ataSetStatusValue(ATADevState *s, uint8_t stat)
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /* Freeze status register contents while processing RESET. */
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncDECLINLINE(void) ataSetStatus(ATADevState *s, uint8_t stat)
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync /* Freeze status register contents while processing RESET. */
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
38745c55f37c31ba8b78cc728d2f08ea6eec38d6vboxsyncDECLINLINE(void) ataUnsetStatus(ATADevState *s, uint8_t stat)
38745c55f37c31ba8b78cc728d2f08ea6eec38d6vboxsync /* Freeze status register contents while processing RESET. */
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync Log2(("%s: LUN#%d status %#04x\n", __FUNCTION__, s->iLUN, s->uATARegStatus));
20f21077abf35d7b7b618acb159267933907407fvboxsyncstatic bool ataExecuteDeviceDiagnosticSS(ATADevState *);
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncstatic bool atapiGetEventStatusNotificationSS(ATADevState *);
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncstatic bool atapiModeSenseErrorRecoverySS(ATADevState *);
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncstatic bool atapiModeSenseCDStatusSS(ATADevState *);
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncstatic bool atapiReadDiscInformationSS(ATADevState *);
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsyncstatic bool atapiReadTrackInformationSS(ATADevState *);
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync * Begin of transfer function indexes for g_apfnBeginTransFuncs.
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync * Array of end transfer functions, the index is ATAFNET.
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync * Make sure ATAFNET and this array match!
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncstatic const PBeginTransferFunc g_apfnBeginTransFuncs[ATAFN_BT_MAX] =
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync * Source/sink function indexes for g_apfnSourceSinkFuncs.
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync * Array of source/sink functions, the index is ATAFNSS.
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync * Make sure ATAFNSS and this array match!
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsyncstatic const PSourceSinkFunc g_apfnSourceSinkFuncs[ATAFN_SS_MAX] =
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncstatic const ATARequest ataDMARequest = { ATA_AIO_DMA, };
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncstatic const ATARequest ataPIORequest = { ATA_AIO_PIO, };
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncstatic const ATARequest ataResetARequest = { ATA_AIO_RESET_ASSERTED, };
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsyncstatic const ATARequest ataResetCRequest = { ATA_AIO_RESET_CLEARED, };
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncstatic void ataAsyncIOClearRequests(PATACONTROLLER pCtl)
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncstatic void ataAsyncIOPutRequest(PATACONTROLLER pCtl, const ATARequest *pReq)
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync Assert((pCtl->AsyncIOReqHead + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests) != pCtl->AsyncIOReqTail);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync memcpy(&pCtl->aAsyncIORequests[pCtl->AsyncIOReqHead], pReq, sizeof(*pReq));
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync pCtl->AsyncIOReqHead %= RT_ELEMENTS(pCtl->aAsyncIORequests);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync LogBird(("ata: %x: signalling\n", pCtl->IOPortBase1));
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync rc = PDMR3CritSectScheduleExitEvent(&pCtl->lock, pCtl->AsyncIOSem);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync LogBird(("ata: %x: schedule failed, rc=%Rrc\n", pCtl->IOPortBase1, rc));
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsyncstatic const ATARequest *ataAsyncIOGetCurrentRequest(PATACONTROLLER pCtl)
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync pReq = &pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail];
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync * Remove the request with the given type, as it's finished. The request
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync * is not removed blindly, as this could mean a RESET request that is not
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync * yet processed (but has cleared the request queue) is lost.
20f21077abf35d7b7b618acb159267933907407fvboxsync * @param pCtl Controller for which to remove the request.
20f21077abf35d7b7b618acb159267933907407fvboxsync * @param ReqType Type of the request to remove.
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsyncstatic void ataAsyncIORemoveCurrentRequest(PATACONTROLLER pCtl, ATAAIO ReqType)
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync if (pCtl->AsyncIOReqHead != pCtl->AsyncIOReqTail && pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail].ReqType == ReqType)
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync pCtl->AsyncIOReqTail %= RT_ELEMENTS(pCtl->aAsyncIORequests);
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * Dump the request queue for a particular controller. First dump the queue
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync * contents, then the already processed entries, as long as they haven't been
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync * overwritten.
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync * @param pCtl Controller for which to dump the queue.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsyncstatic void ataAsyncIODumpRequests(PATACONTROLLER pCtl)
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync LogRel(("PIIX3 ATA: Ctl#%d: request queue dump (topmost is current):\n", ATACONTROLLER_IDX(pCtl)));
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync LogRel(("PIIX3 ATA: Ctl#%d: processed requests (topmost is oldest):\n", ATACONTROLLER_IDX(pCtl)));
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync 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));
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync LogRel(("abort request, iIf=%d fResetDrive=%d\n", pCtl->aAsyncIORequests[curr].u.a.iIf, pCtl->aAsyncIORequests[curr].u.a.fResetDrive));
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync LogRel(("unknown request %d\n", pCtl->aAsyncIORequests[curr].ReqType));
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync curr = (curr + 1) % RT_ELEMENTS(pCtl->aAsyncIORequests);
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * Checks whether the request queue for a particular controller is empty
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * or whether a particular controller is idle.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * @param pCtl Controller for which to check the queue.
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync * @param fStrict If set then the controller is checked to be idle.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsyncstatic bool ataAsyncIOIsIdle(PATACONTROLLER pCtl, bool fStrict)
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync rc = RTSemMutexRequest(pCtl->AsyncIORequestMutex, RT_INDEFINITE_WAIT);
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync fIdle = (pCtl->AsyncIOReqHead == pCtl->AsyncIOReqTail);
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * Send a transfer request to the async I/O thread.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * @param s Pointer to the ATA device state data.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * @param cbTotalTransfer Data transfer size.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * @param uTxDir Data transfer direction.
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync * @param iBeginTransfer Index of BeginTransfer callback.
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync * @param iSourceSink Index of SourceSink callback.
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync * @param fChainedTransfer Whether this is a transfer that is part of the previous command/transfer.
81614fc60e096e714022d10d38b70a36b9b21d48vboxsyncstatic void ataStartTransfer(ATADevState *s, uint32_t cbTotalTransfer, uint8_t uTxDir, ATAFNBT iBeginTransfer, ATAFNSS iSourceSink, bool fChainedTransfer)
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync /* Do not issue new requests while the RESET line is asserted. */
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync Log2(("%s: Ctl#%d: suppressed new request as RESET is active\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync /* If the controller is already doing something else right now, ignore
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync * the command that is being submitted. Some broken guests issue commands
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync * twice (e.g. the Linux kernel that comes with Acronis True Image 8). */
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync if (!fChainedTransfer && !ataAsyncIOIsIdle(pCtl, true))
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync Log(("%s: Ctl#%d: ignored command %#04x, controller state %d\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), s->uATARegCommand, pCtl->uAsyncIOState));
8865793e4f3435f5e2c728d9e6739cd24d08c0devboxsync LogRel(("PIIX3 IDE: guest issued command %#04x while controller busy\n", s->uATARegCommand));
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync * Kick the worker thread into action.
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync Log2(("%s: Ctl#%d: message to async I/O thread, new request\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Send an abort command request to the async I/O thread.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param s Pointer to the ATA device state data.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * @param fResetDrive Whether to reset the drive or just abort a command.
66b58af085e22ee26be57f98127fb49ee2e91790vboxsyncstatic void ataAbortCurrentCommand(ATADevState *s, bool fResetDrive)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Do not issue new requests while the RESET line is asserted. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Log2(("%s: Ctl#%d: suppressed aborting command as RESET is active\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync Log2(("%s: Ctl#%d: message to async I/O thread, abort command on LUN#%d\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), s->iLUN));
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync Log2(("%s: LUN#%d asserting IRQ\n", __FUNCTION__, s->iLUN));
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /* The BMDMA unit unconditionally sets BM_STATUS_INT if the interrupt
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync * line is asserted. It monitors the line for a rising edge. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /* Only actually set the IRQ line if updating the currently selected drive. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** @todo experiment with adaptive IRQ delivery: for reads it is
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync * better to wait for IRQ delivery, as it reduces latency. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync#endif /* IN_RING3 */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync Log2(("%s: LUN#%d deasserting IRQ\n", __FUNCTION__, s->iLUN));
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /* Only actually unset the IRQ line if updating the currently selected drive. */
66b58af085e22ee26be57f98127fb49ee2e91790vboxsyncstatic void ataPIOTransferStart(ATADevState *s, uint32_t start, uint32_t size)
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync Log2(("%s: LUN#%d start %d size %d\n", __FUNCTION__, s->iLUN, start, size));
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync s->uATARegNSector = (s->uATARegNSector & ~7) | ATAPI_INT_REASON_IO | ATAPI_INT_REASON_CD;
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync Log2(("%s: interrupt reason %#04x\n", __FUNCTION__, s->uATARegNSector));
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncstatic void ataPIOTransferLimitATAPI(ATADevState *s)
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /* Use maximum transfer size if the guest requested 0. Avoids a hang. */
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync Log2(("%s: byte count limit=%d\n", __FUNCTION__, cbLimit));
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync cbTransfer = RT_MIN(s->cbTotalTransfer, s->iIOBufferEnd - s->iIOBufferCur);
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync /* Byte count limit for clipping must be even in this case */
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsync /* 0 means either 256 (LBA28) or 65536 (LBA48) sectors. */
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsync return 65536;
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync return s->uATARegNSectorHOB << 8 | s->uATARegNSector;
66b58af085e22ee26be57f98127fb49ee2e91790vboxsync return 256;
c66c4413faa5a72ce047742f9acfa85e94dec8afvboxsyncstatic void ataPadString(uint8_t *pbDst, const char *pbSrc, uint32_t cbSize)
20f21077abf35d7b7b618acb159267933907407fvboxsyncstatic void ataSCSIPadStr(uint8_t *pbDst, const char *pbSrc, uint32_t cbSize)
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncDECLINLINE(void) ataH2BE_U16(uint8_t *pbBuf, uint16_t val)
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncDECLINLINE(void) ataH2BE_U24(uint8_t *pbBuf, uint32_t val)
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncDECLINLINE(void) ataH2BE_U32(uint8_t *pbBuf, uint32_t val)
661bfa5aae55ac2f94fa1cb131ea2323e5f6e633vboxsyncDECLINLINE(uint16_t) ataBE2H_U16(const uint8_t *pbBuf)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncDECLINLINE(uint32_t) ataBE2H_U24(const uint8_t *pbBuf)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return (pbBuf[0] << 16) | (pbBuf[1] << 8) | pbBuf[2];
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncDECLINLINE(uint32_t) ataBE2H_U32(const uint8_t *pbBuf)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return (pbBuf[0] << 24) | (pbBuf[1] << 16) | (pbBuf[2] << 8) | pbBuf[3];
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncDECLINLINE(void) ataLBA2MSF(uint8_t *pbBuf, uint32_t iATAPILBA)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncDECLINLINE(uint32_t) ataMSF2LBA(const uint8_t *pbBuf)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic void ataCmdOK(ATADevState *s, uint8_t status)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync s->uATARegError = 0; /* Not needed by ATA spec, but cannot hurt. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic void ataCmdError(ATADevState *s, uint8_t uErrorCode)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataSetStatusValue(s, ATA_STAT_READY | ATA_STAT_ERR);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[1] = RT_H2LE_U16(RT_MIN(s->PCHSGeometry.cCylinders, 16383));
8f7ee9e453c60b3b699799538a45950b35266665vboxsync /* Block size; obsolete, but required for the BIOS. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataPadString((uint8_t *)(p + 10), (const char *)s->abSerialNumber, 20); /* serial number */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[20] = RT_H2LE_U16(3); /* XXX: retired, cache type */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[21] = RT_H2LE_U16(512); /* XXX: retired, cache size in sectors */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataPadString((uint8_t *)(p + 23), (const char *)s->abFirmwareRevision, 8); /* firmware version */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataPadString((uint8_t *)(p + 27), (const char *)s->abModelNumber, 40); /* model */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[47] = RT_H2LE_U16(0x8000 | ATA_MAX_MULT_SECTORS);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[48] = RT_H2LE_U16(1); /* dword I/O, used by the BIOS */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[49] = RT_H2LE_U16(1 << 11 | 1 << 9 | 1 << 8); /* DMA and LBA supported */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[50] = RT_H2LE_U16(1 << 14); /* No drive specific standby timer minimum */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[53] = RT_H2LE_U16(1 | 1 << 1 | 1 << 2); /* words 54-58,64-70,88 valid */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[54] = RT_H2LE_U16(RT_MIN(s->PCHSGeometry.cCylinders, 16383));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[57] = RT_H2LE_U16( RT_MIN(s->PCHSGeometry.cCylinders, 16383)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[58] = RT_H2LE_U16( RT_MIN(s->PCHSGeometry.cCylinders, 16383)
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync /* Report maximum number of sectors possible with LBA28 */
8f7ee9e453c60b3b699799538a45950b35266665vboxsync p[63] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_MDMA, ATA_MDMA_MODE_MAX, s->uATATransferMode)); /* MDMA modes supported / mode enabled */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[64] = RT_H2LE_U16(ATA_PIO_MODE_MAX > 2 ? (1 << (ATA_PIO_MODE_MAX - 2)) - 1 : 0); /* PIO modes beyond PIO2 supported */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[65] = RT_H2LE_U16(120); /* minimum DMA multiword tx cycle time */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[66] = RT_H2LE_U16(120); /* recommended DMA multiword tx cycle time */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[67] = RT_H2LE_U16(120); /* minimum PIO cycle time without flow control */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[68] = RT_H2LE_U16(120); /* minimum PIO cycle time with IORDY flow control */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[80] = RT_H2LE_U16(0x7e); /* support everything up to ATA/ATAPI-6 */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[81] = RT_H2LE_U16(0x22); /* conforms to ATA/ATAPI-6 */
38745c55f37c31ba8b78cc728d2f08ea6eec38d6vboxsync p[82] = RT_H2LE_U16(1 << 3 | 1 << 5 | 1 << 6); /* supports power management, write cache and look-ahead */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[83] = RT_H2LE_U16(1 << 14 | 1 << 12); /* supports FLUSH CACHE */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[83] = RT_H2LE_U16(1 << 14 | 1 << 10 | 1 << 12 | 1 << 13); /* supports LBA48, FLUSH CACHE and FLUSH CACHE EXT */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[85] = RT_H2LE_U16(1 << 3 | 1 << 5 | 1 << 6); /* enabled power management, write cache and look-ahead */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[86] = RT_H2LE_U16(1 << 12); /* enabled FLUSH CACHE */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[86] = RT_H2LE_U16(1 << 10 | 1 << 12 | 1 << 13); /* enabled LBA48, FLUSH CACHE and FLUSH CACHE EXT */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[88] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_UDMA, ATA_UDMA_MODE_MAX, s->uATATransferMode)); /* UDMA modes supported / mode enabled */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync p[93] = RT_H2LE_U16((1 | 1 << 1) << ((s->iLUN & 1) == 0 ? 0 : 8) | 1 << 13 | 1 << 14);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync rc = s->pDrvBlock ? s->pDrvBlock->pfnGetUuid(s->pDrvBlock, &Uuid) : RTUuidClear(&Uuid);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Generate a predictable serial for drives which don't have a UUID. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RTStrPrintf(aSerial, sizeof(aSerial), "VB%x-%04x%04x",
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync RTStrPrintf(aSerial, sizeof(aSerial), "VB%08x-%08x", Uuid.au32[0], Uuid.au32[3]);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Removable CDROM, 50us response, 12 byte packets */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[0] = RT_H2LE_U16(2 << 14 | 5 << 8 | 1 << 7 | 2 << 5 | 0 << 0);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataPadString((uint8_t *)(p + 10), aSerial, 20); /* serial number */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[20] = RT_H2LE_U16(3); /* XXX: retired, cache type */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[21] = RT_H2LE_U16(512); /* XXX: retired, cache size in sectors */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataPadString((uint8_t *)(p + 23), "1.0", 8); /* firmware version */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataPadString((uint8_t *)(p + 27), "VBOX CD-ROM", 40); /* model */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[49] = RT_H2LE_U16(1 << 11 | 1 << 9 | 1 << 8); /* DMA and LBA supported */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[50] = RT_H2LE_U16(1 << 14); /* No drive specific standby timer minimum */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[53] = RT_H2LE_U16(1 << 1 | 1 << 2); /* words 64-70,88 are valid */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[63] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_MDMA, ATA_MDMA_MODE_MAX, s->uATATransferMode)); /* MDMA modes supported / mode enabled */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[64] = RT_H2LE_U16(ATA_PIO_MODE_MAX > 2 ? (1 << (ATA_PIO_MODE_MAX - 2)) - 1 : 0); /* PIO modes beyond PIO2 supported */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[65] = RT_H2LE_U16(120); /* minimum DMA multiword tx cycle time */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[66] = RT_H2LE_U16(120); /* recommended DMA multiword tx cycle time */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[67] = RT_H2LE_U16(120); /* minimum PIO cycle time without flow control */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[68] = RT_H2LE_U16(120); /* minimum PIO cycle time with IORDY flow control */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[73] = RT_H2LE_U16(0x003e); /* ATAPI CDROM major */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[80] = RT_H2LE_U16(0x7e); /* support everything up to ATA/ATAPI-6 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[81] = RT_H2LE_U16(0x22); /* conforms to ATA/ATAPI-6 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[82] = RT_H2LE_U16(1 << 4 | 1 << 9); /* supports packet command set and DEVICE RESET */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[85] = RT_H2LE_U16(1 << 4 | 1 << 9); /* enabled packet command set and DEVICE RESET */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[88] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_UDMA, ATA_UDMA_MODE_MAX, s->uATATransferMode)); /* UDMA modes supported / mode enabled */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync p[93] = RT_H2LE_U16((1 | 1 << 1) << ((s->iLUN & 1) == 0 ? 0 : 8) | 1 << 13 | 1 << 14);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* put signature */
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync /* any LBA variant */
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync /* LBA48 */
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync iLBA = ((s->uATARegSelect & 0x0f) << 24) | (s->uATARegHCyl << 16) |
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync iLBA = ((s->uATARegHCyl << 8) | s->uATARegLCyl) * s->PCHSGeometry.cHeads * s->PCHSGeometry.cSectors +
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync (s->uATARegSelect & 0x0f) * s->PCHSGeometry.cSectors +
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsyncstatic void ataSetSector(ATADevState *s, uint64_t iLBA)
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /* any LBA variant */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /* LBA48 */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync s->uATARegSelect = (s->uATARegSelect & 0xf0) | (iLBA >> 24);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync cyl = iLBA / (s->PCHSGeometry.cHeads * s->PCHSGeometry.cSectors);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync r = iLBA % (s->PCHSGeometry.cHeads * s->PCHSGeometry.cSectors);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync s->uATARegSelect = (s->uATARegSelect & 0xf0) | ((r / s->PCHSGeometry.cSectors) & 0x0f);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync s->uATARegSector = (r % s->PCHSGeometry.cSectors) + 1;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsyncstatic int ataReadSectors(ATADevState *s, uint64_t u64Sector, void *pvBuf, uint32_t cSectors)
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync s->Led.Asserted.s.fReading = s->Led.Actual.s.fReading = 1;
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync rc = s->pDrvBlock->pfnRead(s->pDrvBlock, u64Sector * 512, pvBuf, cSectors * 512);
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync STAM_REL_COUNTER_ADD(&s->StatBytesRead, cSectors * 512);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsyncstatic int ataWriteSectors(ATADevState *s, uint64_t u64Sector, const void *pvBuf, uint32_t cSectors)
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync s->Led.Asserted.s.fWriting = s->Led.Actual.s.fWriting = 1;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync rc = s->pDrvBlock->pfnWrite(s->pDrvBlock, u64Sector * 512, pvBuf, cSectors * 512);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync STAM_REL_COUNTER_ADD(&s->StatBytesWritten, cSectors * 512);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync false, "DevATA_DISKFULL",
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync N_("Host system reported disk full. VM execution is suspended. You can resume after freeing some space"));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsyncstatic void ataWarningFileTooBig(PPDMDEVINS pDevIns)
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync false, "DevATA_FILETOOBIG",
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync 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"));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync false, "DevATA_ISCSIDOWN",
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync N_("The iSCSI target has stopped responding. VM execution is suspended. You can resume when it is available again"));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync Log(("%s: %d sectors at LBA %d\n", __FUNCTION__, cSectors, iLBA));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync rc = ataReadSectors(s, iLBA, s->CTX_SUFF(pbIOBuffer), cSectors);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync return true;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync return true;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync if (rc == VERR_BROKEN_PIPE || rc == VERR_NET_CONNECTION_REFUSED)
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /* iSCSI connection abort (first error) or failure to reestablish
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync * connection (second error). Pause VM. On resume we'll retry. */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync return true;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync LogRel(("PIIX3 ATA: LUN#%d: disk read error (rc=%Rrc iSector=%#RX64 cSectors=%#RX32)\n",
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /** @todo implement redo for iSCSI */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync return false;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync Log(("%s: %d sectors at LBA %d\n", __FUNCTION__, cSectors, iLBA));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync rc = ataWriteSectors(s, iLBA, s->CTX_SUFF(pbIOBuffer), cSectors);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync return true;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync return true;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync if (rc == VERR_BROKEN_PIPE || rc == VERR_NET_CONNECTION_REFUSED)
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /* iSCSI connection abort (first error) or failure to reestablish
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync * connection (second error). Pause VM. On resume we'll retry. */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync return true;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync LogRel(("PIIX3 ATA: LUN#%d: disk write error (rc=%Rrc iSector=%#RX64 cSectors=%#RX32)\n",
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /** @todo implement redo for iSCSI */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync return false;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync | ((s->uTxDir != PDMBLOCKTXDIR_TO_DEVICE) ? ATAPI_INT_REASON_IO : 0)
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync Log2(("%s: interrupt reason %#04x\n", __FUNCTION__, s->uATARegNSector));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync memset(s->abATAPISense, '\0', sizeof(s->abATAPISense));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsyncstatic void atapiCmdError(ATADevState *s, const uint8_t *pabATAPISense, size_t cbATAPISense)
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync Log(("%s: sense=%#x (%s) asc=%#x ascq=%#x (%s)\n", __FUNCTION__, pabATAPISense[2] & 0x0f, SCSISenseText(pabATAPISense[2] & 0x0f),
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync pabATAPISense[12], pabATAPISense[13], SCSISenseExtText(pabATAPISense[12], pabATAPISense[13])));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync ataSetStatusValue(s, ATA_STAT_READY | ATA_STAT_ERR);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync s->uATARegNSector = (s->uATARegNSector & ~7) | ATAPI_INT_REASON_IO | ATAPI_INT_REASON_CD;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync Log2(("%s: interrupt reason %#04x\n", __FUNCTION__, s->uATARegNSector));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync memset(s->abATAPISense, '\0', sizeof(s->abATAPISense));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync memcpy(s->abATAPISense, pabATAPISense, RT_MIN(cbATAPISense, sizeof(s->abATAPISense)));
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync/** @todo deprecated function - doesn't provide enough info. Replace by direct
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync * calls to atapiCmdError() with full data. */
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsyncstatic void atapiCmdErrorSimple(ATADevState *s, uint8_t uATAPISenseKey, uint8_t uATAPIASC)
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync atapiCmdError(s, abATAPISense, sizeof(abATAPISense));
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync /* @todo implement an algorithm for correctly determining the read and
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync * write sector size without sending additional commands to the drive.
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync * This should be doable by saving processing the configuration requests
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync * and replies. */
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync if (cmd == SCSI_WRITE_10 || cmd == SCSI_WRITE_12 || cmd == SCSI_WRITE_AND_VERIFY_10)
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync aModeSenseCmd[1] = 0x08; /* disable block descriptor = 1 */
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync aModeSenseCmd[2] = (SCSI_PAGECONTROL_CURRENT << 6) | SCSI_MODEPAGE_WRITE_PARAMETER;
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, aModeSenseCmd, PDMBLOCKTXDIR_FROM_DEVICE, aModeSenseResult, &cbTransfer, &uDummySense, 500);
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync atapiCmdErrorSimple(s, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_NONE);
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync /* Select sector size based on the current data block type. */
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync Log2(("%s: sector size %d\n", __FUNCTION__, s->cbATAPISector));
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync cbTransfer = RT_MIN(s->cbTotalTransfer, s->cbIOBuffer);
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync Log(("%s: %d sectors at LBA %d\n", __FUNCTION__, cSectors, s->iATAPILBA));
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync s->Led.Asserted.s.fReading = s->Led.Actual.s.fReading = 1;
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync rc = s->pDrvBlock->pfnRead(s->pDrvBlock, (uint64_t)s->iATAPILBA * s->cbATAPISector, s->CTX_SUFF(pbIOBuffer), s->cbATAPISector * cSectors);
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync for (uint32_t i = s->iATAPILBA; i < s->iATAPILBA + cSectors; i++)
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync /* sync bytes */
e250515922582e0410c9bcb6d24b0f17bef083a0vboxsync rc = s->pDrvBlock->pfnRead(s->pDrvBlock, (uint64_t)i * 2048, pbBuf, 2048);
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync STAM_REL_COUNTER_ADD(&s->StatBytesRead, s->cbATAPISector * cSectors);
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync /* The initial buffer end value has been set up based on the total
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync * transfer size. But the I/O buffer size limits what can actually be
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync * done in one transfer, so set the actual value of the buffer end. */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync LogRel(("PIIX3 ATA: LUN#%d: CD-ROM read error, %d sectors at LBA %d\n", s->iLUN, cSectors, s->iATAPILBA));
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync atapiCmdErrorSimple(s, SCSI_SENSE_MEDIUM_ERROR, SCSI_ASC_READ_ERROR);
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync return false;
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync Log3(("ATAPI PT data write (%d): %.*Rhxs\n", cbTransfer, cbTransfer, s->CTX_SUFF(pbIOBuffer)));
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync /* Simple heuristics: if there is at least one sector of data
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync * to transfer, it's worth updating the LEDs. */
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync s->Led.Asserted.s.fReading = s->Led.Actual.s.fReading = 1;
fdb40b7d2efa84fc6f03b7a695cb4b2e035c30c7vboxsync s->Led.Asserted.s.fWriting = s->Led.Actual.s.fWriting = 1;
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync /* Linux accepts commands with up to 100KB of data, but expects
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync * us to handle commands with up to 128KB of data. The usual
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync * imbalance of powers. */
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync switch (s->aATAPICmd[0])
0c94a8282c9042b02f022302a3d987746140eab9vboxsync cSectors = ataBE2H_U24(s->aATAPICmd + 6) / s->cbATAPISector;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync cSectors = ataMSF2LBA(s->aATAPICmd + 6) - iATAPILBA;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync AssertMsgFailed(("Don't know how to split command %#04x\n", s->aATAPICmd[0]));
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync LogRel(("PIIX3 ATA: LUN#%d: CD-ROM passthrough split error\n", s->iLUN));
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync atapiCmdErrorSimple(s, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_ILLEGAL_OPCODE);
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync return false;
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync memcpy(aATAPICmd, s->aATAPICmd, ATAPI_PACKET_SIZE);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync for (uint32_t i = cSectors; i > 0; i -= cReqSectors)
0c94a8282c9042b02f022302a3d987746140eab9vboxsync switch (s->aATAPICmd[0])
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync ataLBA2MSF(aATAPICmd + 6, iATAPILBA + cReqSectors);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, aATAPICmd, (PDMBLOCKTXDIR)s->uTxDir, pbBuf, &cbCurrTX, abATAPISense, sizeof(abATAPISense), 30000 /**< @todo timeout */);
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, s->aATAPICmd, (PDMBLOCKTXDIR)s->uTxDir, s->CTX_SUFF(pbIOBuffer), &cbTransfer, abATAPISense, sizeof(abATAPISense), 30000 /**< @todo timeout */);
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync /* Update the LEDs and the read/write statistics. */
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync STAM_REL_COUNTER_ADD(&s->StatBytesRead, cbTransfer);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync STAM_REL_COUNTER_ADD(&s->StatBytesWritten, cbTransfer);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Reply with the same amount of data as the real drive. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* The initial buffer end value has been set up based on the total
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * transfer size. But the I/O buffer size limits what can actually be
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync * done in one transfer, so set the actual value of the buffer end. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Make sure that the real drive cannot be identified.
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * Motivation: changing the VM configuration should be as
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * invisible as possible to the guest. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync Log3(("ATAPI PT inquiry data before (%d): %.*Rhxs\n", cbTransfer, cbTransfer, s->CTX_SUFF(pbIOBuffer)));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataSCSIPadStr(s->CTX_SUFF(pbIOBuffer) + 8, "VBOX", 8);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataSCSIPadStr(s->CTX_SUFF(pbIOBuffer) + 16, "CD-ROM", 16);
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync ataSCSIPadStr(s->CTX_SUFF(pbIOBuffer) + 32, "1.0", 4);
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync Log3(("ATAPI PT data read (%d): %.*Rhxs\n", cbTransfer, cbTransfer, s->CTX_SUFF(pbIOBuffer)));
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync /* don't log superflous errors */
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync LogRel(("PIIX3 ATA: LUN#%d: CD-ROM passthrough cmd=%#04x sense=%d ASC=%#02x ASCQ=%#02x %Rrc\n",
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync s->iLUN, u8Cmd, abATAPISense[2] & 0x0f, abATAPISense[12], abATAPISense[13], rc));
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync } while (0);
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync atapiCmdError(s, abATAPISense, sizeof(abATAPISense));
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync return false;
88e56f700a3b8dfdf1646f96320f335e22339caavboxsyncstatic bool atapiReadSectors(ATADevState *s, uint32_t iATAPILBA, uint32_t cSectors, uint32_t cbSector)
49a6b09abb20015b0af3e618a1f92b7e26785e90vboxsync ataStartTransfer(s, cSectors * cbSector, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ, true);
88e56f700a3b8dfdf1646f96320f335e22339caavboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic bool atapiReadDiscInformationSS(ATADevState *s)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pbBuf[2] = (0 << 4) | (3 << 2) | (2 << 0); /* not erasable, complete session, complete disc */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pbBuf[5] = 1; /* first track number in last session (LSB) */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pbBuf[6] = 1; /* last track number in last session (LSB) */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync 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 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U32(pbBuf + 16, 0x00ffffff); /* last session lead-in start time is not available */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U32(pbBuf + 20, 0x00ffffff); /* last possible start time for lead-out is not available */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
38745c55f37c31ba8b78cc728d2f08ea6eec38d6vboxsyncstatic bool atapiReadTrackInformationSS(ATADevState *s)
5c4d7e2aae42bbf39793dfa686925f076a56b4d5vboxsync /* Accept address/number type of 1 only, and only track 1 exists. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync if ((s->aATAPICmd[1] & 0x03) != 1 || ataBE2H_U32(&s->aATAPICmd[2]) != 1)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync atapiCmdErrorSimple(s, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pbBuf[5] = (0 << 5) | (0 << 4) | (4 << 0); /* not damaged, primary copy, data track */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync 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 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pbBuf[7] = (0 << 1) | (0 << 0); /* last recorded address not valid, next recordable address not valid */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U32(pbBuf + 8, 0); /* track start address is 0 */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U32(pbBuf + 24, s->cTotalSectors); /* track size */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /* Accept valid request types only, and only starting feature 0. */
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync atapiCmdErrorSimple(s, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET);
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /** @todo implement switching between CD-ROM and DVD-ROM profile (the only
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * way to differentiate them right now is based on the image size). Also
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * implement signalling "no current profile" if no medium is loaded. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U16(pbBuf + 6, 0x08); /* current profile: read-only CD */
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync ataH2BE_U16(pbBuf + 8, 0); /* feature 0: list of profiles supported */
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync pbBuf[10] = (0 << 2) | (1 << 1) | (1 || 0); /* version 0, persistent, current */
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync /* The MMC-3 spec says that DVD-ROM read capability should be reported
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync * before CD-ROM read capability. */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U16(pbBuf + 12, 0x10); /* profile: read-only DVD */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync ataH2BE_U16(pbBuf + 16, 0x08); /* profile: read only CD */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* Other profiles we might want to add in the future: 0x40 (BD-ROM) and 0x50 (HDDVD-ROM) */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync return false;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsyncstatic bool atapiGetEventStatusNotificationSS(ATADevState *s)
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync /* no asynchronous operation supported */
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync atapiCmdErrorSimple(s, SCSI_SENSE_ILLEGAL_REQUEST, SCSI_ASC_INV_FIELD_IN_CMD_PACKET);
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync return false;
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync OldStatus = ASMAtomicReadU32(&s->MediaEventStatus);
19320d55d1417c39b3b5673a53aaa5ef177242c8vboxsync /* mount */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync /* umount */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync } while (!ASMAtomicCmpXchgU32(&s->MediaEventStatus, NewStatus, OldStatus));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync#if 1/*ndef VBOX*/ /** @todo implement MESN + AENC. (async notification on removal and stuff.) */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pbBuf[3] = 0x21; /* ATAPI-2 (XXX: put ATAPI-4 ?) */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync pbBuf[3] = 0x91; /* format 1, MESN=1, AENC=9 ??? */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsyncstatic bool atapiModeSenseErrorRecoverySS(ATADevState *s)
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsyncstatic bool atapiModeSenseCDStatusSS(ATADevState *s)
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync /* The following claims we support audio play. This is obviously false,
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync * but the Linux generic CDROM support makes many features depend on this
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync * capability. If it's not set, this causes many things to be disabled. */
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync pbBuf[12] = 0x71; /* multisession support, mode 2 form 1/2 support, audio play */
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync pbBuf[13] = 0x00; /* no subchannel reads supported */
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync pbBuf[14] = (1 << 0) | (1 << 3) | (1 << 5); /* lock supported, eject supported, tray type loading mechanism */
81614fc60e096e714022d10d38b70a36b9b21d48vboxsync pbBuf[15] = 0; /* no subchannel reads supported, no separate audio volume control, no changer etc. */
44372afb953dc9f1f1ec71943f5f561a607c0307vboxsync ataH2BE_U16(&pbBuf[16], 5632); /* (obsolete) claim 32x speed support */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U16(&pbBuf[18], 2); /* number of audio volume levels */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U16(&pbBuf[20], s->cbIOBuffer / _1K); /* buffer size supported in Kbyte */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U16(&pbBuf[22], 5632); /* (obsolete) current read speed 32x */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync pbBuf[25] = 0; /* reserved for digital audio (see idx 15) */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync ataH2BE_U16(&pbBuf[26], 0); /* (obsolete) maximum write speed */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync ataH2BE_U16(&pbBuf[28], 0); /* (obsolete) current write speed */
29099c2d04b11e614f1fa399fab9e9162f2788b9vboxsync ataH2BE_U16(&pbBuf[30], 0); /* copy management revision supported 0=no CSS */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U16(&pbBuf[36], 0); /* current write speed */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync ataH2BE_U16(&pbBuf[38], 0); /* number of write speed performance descriptors */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync memcpy(pbBuf, s->abATAPISense, RT_MIN(s->cbElementaryTransfer, sizeof(s->abATAPISense)));
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
0c94a8282c9042b02f022302a3d987746140eab9vboxsync /* no current LBA */
0c69348b58bb8eabb1bea8867ee932b667bd0d34vboxsync return false;
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 (pCfgNode)
char *pszCFGMValue;
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));
switch (rc)
case VERR_ACCESS_DENIED:
return rc;
s_apszDescs[i][j]);
return VINF_SUCCESS;
sizeof(PCIATAState),
NULL,
NULL,
NULL,
NULL,
NULL,