DevATA.cpp revision 3464a89069854bc3c36488c882ce2b28e211f818
5b281ba489ca18f0380d7efc7a5108b606cce449vboxsync * VBox storage devices:
4d6dcfe00aab559241d9ed05b89f803ab5ddf611vboxsync * ATA/ATAPI controller device (disk and cdrom).
4d6dcfe00aab559241d9ed05b89f803ab5ddf611vboxsync * Copyright (C) 2006 InnoTek Systemberatung GmbH
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * available from http://www.virtualbox.org. This file is free software;
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * you can redistribute it and/or modify it under the terms of the GNU
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * General Public License as published by the Free Software Foundation,
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * distribution. VirtualBox OSE is distributed in the hope that it will
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * be useful, but WITHOUT ANY WARRANTY of any kind.
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * If you received this file as part of a commercial VirtualBox
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * distribution, then only the terms of your commercial VirtualBox
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync * license agreement apply instead of the previous paragraph.
bd8e360cd1db83dcb2694ea9122ce3bc5bae678avboxsync/*******************************************************************************
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync* Header Files *
1c94c0a63ba68be1a7b2c640e70d7a06464e4fcavboxsync*******************************************************************************/
dccbafa70b5a9a6f933c5566e4542caf9f379b97vboxsync#endif /* IN_RING3 */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * Maximum number of sectors to transfer in a READ/WRITE MULTIPLE request.
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * Set to 1 to disable multi-sector read support. According to the ATA
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * specification this must be a power of 2 and it must fit in an 8 bit
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * value. Thus the only valid values are 1, 2, 4, 8, 16, 32, 64 and 128.
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * Fastest PIO mode supported by the drive.
ea6c70405e39fa563a55780ef25e0933d8c73a1avboxsync * Fastest MDMA mode supported by the drive.
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * Fastest UDMA mode supported by the drive.
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * The SSM saved state version.
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync/** The maximum number of release log entries per device. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsynctypedef struct ATADevState {
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Flag indicating whether the current command uses LBA48 mode. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Flag indicating whether this drive implements the ATAPI command set. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Set if this interface has asserted the IRQ. */
e0b01f0907f9ade6df65e65e86196fa09a11a245vboxsync /** Currently configured number of sectors in a multi-sector transfer. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** LCHS disk geometry. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Total number of sectors on this disk. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Number of sectors to transfer per IRQ. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 1: feature (write-only). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 1: feature, high order byte. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 1: error (read-only). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 2: sector count (read/write). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 2: sector count, high order byte. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 3: sector, high order byte. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 4: cylinder low (read/write). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 4: cylinder low, high order byte. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 5: cylinder high (read/write). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 5: cylinder high, high order byte. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 6: select drive/head (read/write). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 7: status (read-only). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI register 7: command (write-only). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** ATA/ATAPI drive control register (write-only). */
4d6dcfe00aab559241d9ed05b89f803ab5ddf611vboxsync /** Currently active transfer mode (MDMA/UDMA) and speed. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Current transfer direction. */
d618bed3882cd227cf8f5d0d2824f8db42fad415vboxsync /** Index of callback for begin transfer. */
dccbafa70b5a9a6f933c5566e4542caf9f379b97vboxsync /** Index of callback for source/sink of data. */
9735c8af814f4e79e0c2e4b63b2a61a30faa67bfvboxsync /** Flag indicating whether the current command transfers data in DMA mode. */
9735c8af814f4e79e0c2e4b63b2a61a30faa67bfvboxsync /** Set to indicate that ATAPI transfer semantics must be used. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Total ATA/ATAPI transfer size, shared PIO/DMA. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Elementary ATA/ATAPI transfer size, shared PIO/DMA. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Current read/write buffer position, shared PIO/DMA. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** First element beyond end of valid buffer content, shared PIO/DMA. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** ATA/ATAPI current PIO read/write transfer position. Not shared with DMA for safety reasons. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** ATA/ATAPI current PIO read/write transfer end. Not shared with DMA for safety reasons. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** ATAPI current LBA position. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** ATAPI current sector size. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** ATAPI current command. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** ATAPI sense key. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** ATAPI additional sense code. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** HACK: Countdown till we report a newly unmounted drive as mounted. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** The status LED state for this drive. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Size of I/O buffer. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Pointer to the I/O buffer. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Pointer to the I/O buffer. */
81587231c9c584851518872e197f6f02dffe68cavboxsync RTGCPTR Aligmnent0; /**< Align the statistics at an 8-byte boundrary. */
81587231c9c584851518872e197f6f02dffe68cavboxsync * No data that is part of the saved state after this point!!!!!
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Statistics: number of read operations and the time spent reading. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Statistics: number of bytes read. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Statistics: number of write operations and the time spent writing. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Statistics: number of bytes written. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Statistics: number of flush operations and the time spend flushing. */
dccbafa70b5a9a6f933c5566e4542caf9f379b97vboxsync /** Enable passing through commands directly to the ATAPI drive. */
da97b7ac000d0f02e86c31a4f2767a00d83c6167vboxsync /** Number of errors we've reported to the release log.
da97b7ac000d0f02e86c31a4f2767a00d83c6167vboxsync * This is to prevent flooding caused by something going horribly wrong.
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * this value against MAX_LOG_REL_ERRORS in places likely to cause floods
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * like the ones we currently seeing on the linux smoke tests (2006-11-10). */
14e0667f834cd0e2a8c365084cd2ad0a893109e8vboxsync /** Pointer to the attached driver's base interface. */
14e0667f834cd0e2a8c365084cd2ad0a893109e8vboxsync /** Pointer to the attached driver's block interface. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Pointer to the attached driver's block bios interface. */
d618bed3882cd227cf8f5d0d2824f8db42fad415vboxsync /** Pointer to the attached driver's mount interface.
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync * This is NULL if the driver isn't a removable unit. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** The base interface. */
da97b7ac000d0f02e86c31a4f2767a00d83c6167vboxsync /** The block port interface. */
da97b7ac000d0f02e86c31a4f2767a00d83c6167vboxsync /** The mount notify interface. */
ea6c70405e39fa563a55780ef25e0933d8c73a1avboxsync /** The LUN #. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync RTUINT Alignment2; /**< Align pDevInsHC correctly. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Pointer to device instance. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Pointer to controller instance. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Pointer to device instance. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Pointer to controller instance. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsynctypedef enum
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Begin a new transfer. */
d618bed3882cd227cf8f5d0d2824f8db42fad415vboxsync /** Continue a DMA transfer. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Continue a PIO transfer. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Reset the drives on current controller, stop all transfer activity. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Reset the drives on current controller, resume operation. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Abort the current transfer of a particular drive. */
d618bed3882cd227cf8f5d0d2824f8db42fad415vboxsynctypedef struct ATARequest
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** The base of the first I/O Port range. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** The base of the second I/O Port range. (0 if none) */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** The assigned IRQ. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Access critical section */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Selected drive. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** The interface on which to handle async I/O. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** The state of the async I/O thread. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Flag indicating whether the next transfer is part of the current command. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Set when the reset processing is currently active on this controller. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Flag whether the current transfer needs to be redone. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Flag whether the redo suspend has been finished. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Flag whether the DMA operation to be redone is the final transfer. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** The BusMaster DMA state. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Pointer to first DMA descriptor. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Pointer to last DMA descriptor. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** Pointer to current DMA buffer (for redo operations). */
d618bed3882cd227cf8f5d0d2824f8db42fad415vboxsync /** Size of current DMA buffer (for redo operations). */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /** The ATA/ATAPI interfaces of this controller. */
4d6dcfe00aab559241d9ed05b89f803ab5ddf611vboxsync /** Pointer to device instance. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Pointer to device instance. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Set when the destroying the device instance and the thread must exit. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** The async I/O thread handle. NIL_RTTHREAD if no thread. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** The event semaphore the thread is waiting on for requests. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** The request queue for the AIO thread. One element is always unused. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** The position at which to insert a new request for the AIO thread. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** The position at which to get a new request for the AIO thread. */
81587231c9c584851518872e197f6f02dffe68cavboxsync uint8_t Alignment3[2]; /** Explicit padding of the 2 byte gap. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** Magic delay before triggering interrupts in DMA mode. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** The mutex protecting the request queue. */
81587231c9c584851518872e197f6f02dffe68cavboxsync /** The event semaphore the thread is waiting on during suspended I/O. */
45e9c1c72518aeba6673332bdd4d70b59e1c11a4vboxsync /* Statistics */
14e0667f834cd0e2a8c365084cd2ad0a893109e8vboxsynctypedef struct PCIATAState {
ea6c70405e39fa563a55780ef25e0933d8c73a1avboxsync /** The controllers. */
4d6dcfe00aab559241d9ed05b89f803ab5ddf611vboxsync /** Pointer to device instance. */
bool fGCEnabled;
bool fR0Enabled;
} PCIATAState;
#define PDMIBASE_2_PCIATASTATE(pInterface) ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, IBase)) )
#define PDMILEDPORTS_2_PCIATASTATE(pInterface) ( (PCIATAState *)((uintptr_t)(pInterface) - RT_OFFSETOF(PCIATAState, ILeds)) )
#define PDMIBASE_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IBase)) )
#define PDMIBLOCKPORT_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IPort)) )
#define PDMIMOUNT_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMount)) )
#define PDMIMOUNTNOTIFY_2_ATASTATE(pInterface) ( (ATADevState *)((uintptr_t)(pInterface) - RT_OFFSETOF(ATADevState, IMountNotify)) )
#define ATACONTROLLER_IDX(pController) ( (pController) - PDMINS2DATA(CONTROLLER_2_DEVINS(pController), PCIATAState *)->aCts )
#ifndef VBOX_DEVICE_STRUCT_TESTCASE
PDMBOTHCBDECL(int) ataIOPortWrite1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
PDMBOTHCBDECL(int) ataIOPortRead1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *u32, unsigned cb);
PDMBOTHCBDECL(int) ataIOPortWriteStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, unsigned *pcTransfer, unsigned cb);
PDMBOTHCBDECL(int) ataIOPortReadStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrDst, unsigned *pcTransfer, unsigned cb);
PDMBOTHCBDECL(int) ataIOPortWrite2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
PDMBOTHCBDECL(int) ataIOPortRead2(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *u32, unsigned cb);
PDMBOTHCBDECL(int) ataBMDMAIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb);
PDMBOTHCBDECL(int) ataBMDMAIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb);
#ifdef IN_RING3
typedef enum ATAFNBT
ATAFN_BT_NULL = 0,
} ATAFNBT;
NULL,
typedef enum ATAFNSS
ATAFN_SS_NULL = 0,
} ATAFNSS;
NULL,
int rc;
int rc;
#ifdef __LINUX__
int rc;
return pReq;
int rc;
if (pCtl->AsyncIOReqHead != pCtl->AsyncIOReqTail && pCtl->aAsyncIORequests[pCtl->AsyncIOReqTail].ReqType == ReqType)
int rc;
case ATA_AIO_NEW:
LogRel(("new transfer request, iIf=%d iBeginTransfer=%d iSourceSink=%d cbTotalTransfer=%d uTxDir=%d\n", pCtl->aAsyncIORequests[curr].u.t.iIf, pCtl->aAsyncIORequests[curr].u.t.iBeginTransfer, pCtl->aAsyncIORequests[curr].u.t.iSourceSink, pCtl->aAsyncIORequests[curr].u.t.cbTotalTransfer, pCtl->aAsyncIORequests[curr].u.t.uTxDir));
case ATA_AIO_DMA:
case ATA_AIO_PIO:
case ATA_AIO_RESET_ASSERTED:
case ATA_AIO_RESET_CLEARED:
case ATA_AIO_ABORT:
LogRel(("abort request, iIf=%d fResetDrive=%d\n", pCtl->aAsyncIORequests[curr].u.a.iIf, pCtl->aAsyncIORequests[curr].u.a.fResetDrive));
int rc;
bool fIdle;
if (!fIdle)
if (fStrict)
return fIdle;
static void ataStartTransfer(ATADevState *s, uint32_t cbTotalTransfer, uint8_t uTxDir, ATAFNBT iBeginTransfer, ATAFNSS iSourceSink, bool fChainedTransfer)
Log2(("%s: Ctl#%d: suppressed new request as RESET is active\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Log(("%s: Ctl#%d: ignored command %#04x, controller state %d\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), s->uATARegCommand, pCtl->uAsyncIOState));
if (fChainedTransfer)
Log2(("%s: Ctl#%d: message to async I/O thread, new request\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Log2(("%s: Ctl#%d: suppressed aborting command as RESET is active\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl)));
Log2(("%s: Ctl#%d: message to async I/O thread, abort command on LUN#%d\n", __FUNCTION__, ATACONTROLLER_IDX(pCtl), s->iLUN));
if (!s->fIrqPending)
s->fIrqPending = true;
if (s->fIrqPending)
s->fIrqPending = false;
#ifdef IN_RING3
if (s->fATAPITransfer)
ataSetIRQ(s);
s->fATAPITransfer = false;
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
s->iIOBufferPIODataStart = 0;
s->iIOBufferPIODataEnd = 0;
cbLimit--;
cbLimit--;
if (s->fLBA48)
if (!s->uATARegNSector)
return s->uATARegNSector;
if (*pbSrc)
if (*pbSrc)
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
s->iIOBufferCur = 0;
s->iIOBufferEnd = 0;
uint16_t *p;
int rc;
if (s->cMultSectors)
p[63] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_MDMA, ATA_MDMA_MODE_MAX, s->uATATransferMode)); /* MDMA modes supported / mode enabled */
p[64] = RT_H2LE_U16(ATA_PIO_MODE_MAX > 2 ? (1 << (ATA_PIO_MODE_MAX - 2)) - 1 : 0); /* PIO modes beyond PIO2 supported */
p[82] = RT_H2LE_U16(1 << 3 | 1 << 5 | 1 << 6); /* supports power management, write cache and look-ahead */
p[83] = RT_H2LE_U16(1 << 14 | 1 << 10 | 1 << 12 | 1 << 13); /* supports LBA48, FLUSH CACHE and FLUSH CACHE EXT */
p[85] = RT_H2LE_U16(1 << 3 | 1 << 5 | 1 << 6); /* enabled power management, write cache and look-ahead */
p[86] = RT_H2LE_U16(1 << 10 | 1 << 12 | 1 << 13); /* enabled LBA48, FLUSH CACHE and FLUSH CACHE EXT */
p[88] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_UDMA, ATA_UDMA_MODE_MAX, s->uATATransferMode)); /* UDMA modes supported / mode enabled */
int rc;
ataCmdOK(s, 0);
uint16_t *p;
int rc;
p[63] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_MDMA, ATA_MDMA_MODE_MAX, s->uATATransferMode)); /* MDMA modes supported / mode enabled */
p[64] = RT_H2LE_U16(ATA_PIO_MODE_MAX > 2 ? (1 << (ATA_PIO_MODE_MAX - 2)) - 1 : 0); /* PIO modes beyond PIO2 supported */
p[88] = RT_H2LE_U16(ATA_TRANSFER_ID(ATA_MODE_UDMA, ATA_UDMA_MODE_MAX, s->uATATransferMode)); /* UDMA modes supported / mode enabled */
if (s->fATAPI)
else if (s->pDrvBlock)
s->uATARegLCyl = 0;
s->uATARegHCyl = 0;
if (s->fLBA48)
s->uATARegSector;
return iLBA;
if (s->fLBA48)
int rc;
return rc;
static int ataWriteSectors(ATADevState *s, uint64_t u64Sector, const void *pvBuf, uint32_t cSectors)
int rc;
return rc;
ataCmdOK(s, 0);
int rc;
N_("Host system reported disk full. VM execution is suspended. You can resume after freeing some space"));
int rc;
N_("The iSCSI target has stopped responding. VM execution is suspended. You can resume when it is available again"));
int rc;
int rc;
if (!s->cbTotalTransfer)
s->uATARegError = 0;
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
s->iIOBufferCur = 0;
s->iIOBufferEnd = 0;
s->fATAPITransfer = true;
atapiCmdOK(s);
int rc;
rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, aModeSenseCmd, PDMBLOCKTXDIR_FROM_DEVICE, aModeSenseResult, &cbTransfer, &uDummySense, 500);
s->cbATAPISector = 0;
if (s->cbTotalTransfer == 0)
atapiCmdBT(s);
switch (s->cbATAPISector)
rc = s->pDrvBlock->pfnRead(s->pDrvBlock, (uint64_t)s->iATAPILBA * s->cbATAPISector, s->CTXSUFF(pbIOBuffer), s->cbATAPISector * cSectors);
atapiCmdOK(s);
LogRel(("PIIX3 ATA: LUN#%d: CD-ROM read error, %d sectors at LBA %d\n", s->iLUN, cSectors, s->iATAPILBA));
switch (s->aATAPICmd[0])
case SCSI_READ_10:
case SCSI_WRITE_10:
case SCSI_WRITE_AND_VERIFY_10:
case SCSI_READ_12:
case SCSI_WRITE_12:
case SCSI_READ_CD:
case SCSI_READ_CD_MSF:
cReqSectors = 0;
cReqSectors = i;
switch (s->aATAPICmd[0])
case SCSI_READ_10:
case SCSI_WRITE_10:
case SCSI_WRITE_AND_VERIFY_10:
case SCSI_READ_12:
case SCSI_WRITE_12:
case SCSI_READ_CD:
case SCSI_READ_CD_MSF:
rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, aATAPICmd, (PDMBLOCKTXDIR)s->uTxDir, pbBuf, &cbCurrTX, &uATAPISenseKey, 30000 /**< @todo timeout */);
rc = s->pDrvBlock->pfnSendCmd(s->pDrvBlock, s->aATAPICmd, (PDMBLOCKTXDIR)s->uTxDir, s->CTXSUFF(pbIOBuffer), &cbTransfer, &uATAPISenseKey, 30000 /**< @todo timeout */);
Log3(("ATAPI PT inquiry data before (%d): %.*Vhxs\n", cbTransfer, cbTransfer, s->CTXSUFF(pbIOBuffer)));
if (cbTransfer)
atapiCmdOK(s);
LogRel(("PIIX3 ATA: LUN#%d: CD-ROM passthrough command (%#04x) error %d\n", s->iLUN, s->aATAPICmd[0], uATAPISenseKey));
static bool atapiReadSectors(ATADevState *s, uint32_t iATAPILBA, uint32_t cSectors, uint32_t cbSector)
ataStartTransfer(s, cSectors * cbSector, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ, true);
atapiCmdOK(s);
pbBuf[7] = (0 << 7) | (0 << 6) | (1 << 5) | (0 << 2) | (0 << 0); /* disc id not valid, disc bar code not valid, unrestricted use, not dirty, not RW medium */
atapiCmdOK(s);
pbBuf[6] = (0 << 7) | (0 << 6) | (0 << 5) | (0 << 6) | (1 << 0); /* not reserved track, not blank, not packet writing, not fixed packet, data mode 1 */
pbBuf[7] = (0 << 1) | (0 << 0); /* last recorded address not valid, next recordable address not valid */
atapiCmdOK(s);
atapiCmdOK(s);
atapiCmdOK(s);
atapiCmdOK(s);
pbBuf[14] = (1 << 0) | (1 << 3) | (1 << 5); /* lock supported, eject supported, tray type loading mechanism */
pbBuf[15] = 0; /* no subchannel reads supported, no separate audio volume control, no changer etc. */
atapiCmdOK(s);
atapiCmdOK(s);
atapiCmdOK(s);
bool fMSF;
if (fMSF)
ataLBA2MSF(q, 0);
ataH2BE_U32(q, 0);
if (fMSF)
atapiCmdOK(s);
bool fMSF;
/** @todo double-check this stuff against what a real drive says for a CD-ROM (not a CD-R) with only a single data session. Maybe solve the problem with "cdrdao read-toc" not being able to figure out whether numbers are in BCD or hex. */
if (fMSF)
atapiCmdOK(s);
bool fMSF;
if (fMSF)
if (fMSF)
ataLBA2MSF(q, 0);
ataH2BE_U32(q, 0);
atapiCmdOK(s);
switch (pbPacket[0])
case SCSI_TEST_UNIT_READY:
if (s->cNotifiedMediaChange > 0)
atapiCmdOK(s);
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-- ;
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-- ;
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);
case SCSI_SEEK_10:
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
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-- ;
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-- ;
ataStartTransfer(s, 8, PDMBLOCKTXDIR_FROM_DEVICE, ATAFN_BT_ATAPI_CMD, ATAFN_SS_ATAPI_READ_CAPACITY, true);
if (s->cNotifiedMediaChange > 0)
s->cNotifiedMediaChange-- ;
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-- ;
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;
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], g_apszSCSICmdNames[pbPacket[0]]));
Log2(("%s: limit=%#x packet: %.*Vhxs\n", __FUNCTION__, s->uATARegLCyl | (s->uATARegHCyl << 8), ATAPI_PACKET_SIZE, pbPacket));
if (s->fATAPIPassthrough)
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
atapiParseCmd(s);
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);
#ifdef DEBUG
s->fLBA48 = false;
s->fDMA = false;
switch (cmd)
case ATA_IDENTIFY_DEVICE:
if (s->fATAPI)
ataSetSignature(s);
case ATA_RECALIBRATE:
case ATA_SET_MULTIPLE_MODE:
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);
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)
#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;
if (!s->pDrvBlock)
val = 0;
ataUnsetIRQ(s);
#ifdef IN_RING3
val = 0;
return val;
#ifndef IN_RING3
#ifdef IN_RING3
#ifdef IN_RING3
return VINF_SUCCESS;
#ifdef IN_RING3
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)));
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
static int ataGuessDiskLCHS(ATADevState *s, uint32_t *pcCylinders, uint32_t *pcHeads, uint32_t *pcSectors)
int rc;
return VERR_INVALID_PARAMETER;
return rc;
return VERR_INVALID_PARAMETER;
return VINF_SUCCESS;
return VERR_INVALID_PARAMETER;
s->cbTotalTransfer = 0;
s->cbElementaryTransfer = 0;
bool fRedo;
bool fLastDesc = false;
if (cbBuffer == 0)
iIOBufferCur = 0;
LogRel(("PIIX3 ATA: Ctl#%d: ABORT DMA%s\n", ATACONTROLLER_IDX(pCtl), pCtl->fReset ? " due to RESET" : ""));
if (fLastDesc)
ATADevState *s;
LogRel(("PIIX3 ATA: LUN#%d: %s data in the middle of a PIO transfer - VERY SLOW\n", s->iLUN, s->uTxDir == PDMBLOCKTXDIR_FROM_DEVICE ? "storing" : "loading"));
bool fRedo;
s->iIOBufferCur = 0;
if (s->cbTotalTransfer)
if (s->fATAPITransfer)
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;
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);
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;
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, unsigned *pcTransfer, unsigned cb)
return rc;
#ifndef IN_RING3
#ifdef IN_GC
MMGCRamWriteNoTrapHandler((char *)GCDst + i, s->CTXSUFF(pbIOBuffer) + s->iIOBufferPIODataStart + i, cb);
rc = PGMPhysWriteGCPtrDirty(PDMDevHlpGetVM(pDevIns), GCDst, s->CTXSUFF(pbIOBuffer) + s->iIOBufferPIODataStart, cbTransfer);
if (cbTransfer)
Log3(("%s: addr=%#x val=%.*Vhxs\n", __FUNCTION__, Port, cbTransfer, s->CTXSUFF(pbIOBuffer) + s->iIOBufferPIODataStart));
#ifdef IN_RING3
return rc;
PDMBOTHCBDECL(int) ataIOPortWriteStr1(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, RTGCPTR *pGCPtrSrc, unsigned *pcTransfer, unsigned cb)
int rc;
return rc;
#ifndef IN_RING3
#ifdef IN_GC
MMGCRamReadNoTrapHandler(s->CTXSUFF(pbIOBuffer) + s->iIOBufferPIODataStart + i, (char *)GCSrc + i, cb);
rc = PGMPhysReadGCPtr(PDMDevHlpGetVM(pDevIns), s->CTXSUFF(pbIOBuffer) + s->iIOBufferPIODataStart, GCSrc, cbTransfer);
if (cbTransfer)
Log3(("%s: addr=%#x val=%.*Vhxs\n", __FUNCTION__, Port, cbTransfer, s->CTXSUFF(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)
return fAllIdle;
if (s->pbIOBufferHC)
int rc;
bool fAllDone;
fAllDone = true;
if ( fAllDone
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;
return VERR_NO_MEMORY;
rc = pIf->pDrvBlockBios->pfnGetGeometry(pIf->pDrvBlockBios, &pIf->cCHSCylinders, &pIf->cCHSHeads, &pIf->cCHSSectors);
pIf->pDrvBlockBios->pfnSetGeometry(pIf->pDrvBlockBios, pIf->cCHSCylinders, pIf->cCHSHeads, pIf->cCHSSectors);
LogRel(("PIIX3 ATA: LUN#%d: CD/DVD, total number of sectors %Ld, passthrough %s\n", pIf->iLUN, pIf->cTotalSectors, (pIf->fATAPIPassthrough ? "enabled" : "disabled")));
rc = pIf->pDrvBlockBios->pfnGetGeometry(pIf->pDrvBlockBios, &pIf->cCHSCylinders, &pIf->cCHSHeads, &pIf->cCHSSectors);
rc = pIf->pDrvBlockBios->pfnSetGeometry(pIf->pDrvBlockBios, pIf->cCHSCylinders, pIf->cCHSHeads, pIf->cCHSSectors);
rc = pIf->pDrvBlockBios->pfnSetGeometry(pIf->pDrvBlockBios, pIf->cCHSCylinders, pIf->cCHSHeads, pIf->cCHSSectors);
LogRel(("PIIX3 ATA: LUN#%d: disk, CHS=%d/%d/%d, total number of sectors %Ld\n", pIf->iLUN, pIf->cCHSCylinders, pIf->cCHSHeads, pIf->cCHSSectors, 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, &pData->aCts[i].aIfs[j].aATAPICmd, sizeof(pData->aCts[i].aIfs[j].aATAPICmd));
SSMR3PutMem(pSSMHandle, pData->aCts[i].aIfs[j].CTXSUFF(pbIOBuffer), pData->aCts[i].aIfs[j].cbIOBuffer);
static DECLCALLBACK(int) ataLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSMHandle, uint32_t u32Version)
int rc;
return rc;
SSMR3GetMem(pSSMHandle, &pData->aCts[i].aIfs[j].aATAPICmd, sizeof(pData->aCts[i].aIfs[j].aATAPICmd));
SSMR3GetMem(pSSMHandle, pData->aCts[i].aIfs[j].CTXSUFF(pbIOBuffer), pData->aCts[i].aIfs[j].cbIOBuffer);
return rc;
if (u32 != ~0U)
return rc;
return VINF_SUCCESS;
int rc;
bool fGCEnabled;
bool fR0Enabled;
fGCEnabled = true;
fR0Enabled = true;
DelayIRQMillies = 0;
if (fGCEnabled)
if (fR0Enabled)
if (fGCEnabled)
if (fR0Enabled)
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);
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);
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, &pData->aCts[i].StatAsyncOps, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_OCCURENCES, "The number of async operations.", "/Devices/ATA%d/Async/Operations", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pData->aCts[i].StatAsyncMinWait, STAMTYPE_U64_RESET, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, "Minimum wait in microseconds.", "/Devices/ATA%d/Async/MinWait", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pData->aCts[i].StatAsyncMaxWait, STAMTYPE_U64_RESET, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, "Maximum wait in microseconds.", "/Devices/ATA%d/Async/MaxWait", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pData->aCts[i].StatAsyncTimeUS, STAMTYPE_COUNTER, STAMVISIBILITY_ALWAYS, STAMUNIT_NONE, "Total time spent in microseconds.","/Devices/ATA%d/Async/TotalTimeUS", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pData->aCts[i].StatAsyncTime, STAMTYPE_PROFILE_ADV, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling of async operations.", "/Devices/ATA%d/Async/Time", i);
PDMDevHlpSTAMRegisterF(pDevIns, &pData->aCts[i].StatLockWait, STAMTYPE_PROFILE, STAMVISIBILITY_ALWAYS, STAMUNIT_TICKS_PER_CALL, "Profiling of locks.", "/Devices/ATA%d/Async/LockWait", i);
pData->pLedsConnector = (PDMILEDCONNECTORS *)pBase->pfnQueryInterface(pBase, PDMINTERFACE_LED_CONNECTORS);
rc = RTThreadCreate(&pCtl->AsyncIOThread, ataAsyncIOLoop, (void *)pCtl, 128*1024, RTTHREADTYPE_IO, 0, "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;
return VINF_SUCCESS;
PDM_DEVREG_FLAGS_HOST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GUEST_BITS_DEFAULT | PDM_DEVREG_FLAGS_GC | PDM_DEVREG_FLAGS_R0,
sizeof(PCIATAState),
NULL,
NULL,
NULL,
NULL,