VirtualBox

Changeset 81828 in vbox for trunk/src/VBox/Devices/Storage


Ignore:
Timestamp:
Nov 13, 2019 3:30:50 PM (5 years ago)
Author:
vboxsync
Message:

DevBusLogic.cpp: Converting it to the new PDM device style - Splitting up state structures. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Storage/DevBusLogic.cpp

    r81812 r81828  
    9595typedef struct BUSLOGICDEVICE
    9696{
    97     /** Pointer to the owning buslogic device instance. - R3 pointer */
    98     R3PTRTYPE(struct BUSLOGIC *)    pBusLogicR3;
    99     /** Pointer to the owning buslogic device instance. - R0 pointer */
    100     R0PTRTYPE(struct BUSLOGIC *)    pBusLogicR0;
    101     /** Pointer to the owning buslogic device instance. - RC pointer */
    102     RCPTRTYPE(struct BUSLOGIC *)    pBusLogicRC;
     97    /** The ring-3 device instance (for getting our bearings when arriving in an
     98     * interface method). */
     99    PPDMDEVINSR3                    pDevIns;
    103100
    104101    /** LUN of the device. */
    105102    uint32_t                        iLUN;
    106103
    107     /** Flag whether device is present. */
     104    /** Flag whether device is present.
     105     * @note This is mirrored in BUSLOGIC::afDevicePresent. */
    108106    bool                            fPresent;
    109     bool                            afAlignment[HC_ARCH_BITS == 64 ? 3 : 7];
     107    bool                            afAlignment[3];
    110108
    111109    /** Our base interface. */
     
    327325/**
    328326 * The shared BusLogic device emulation state.
    329  *
    330  * @implements  PDMILEDPORTS
    331327 */
    332328typedef struct BUSLOGIC
    333329{
    334     /** Pointer to the device instance - HC ptr */
    335     PPDMDEVINSR3                    pDevInsR3;
    336     /** Pointer to the device instance - R0 ptr */
    337     PPDMDEVINSR0                    pDevInsR0;
    338     /** Pointer to the device instance - RC ptr. */
    339     PPDMDEVINSRC                    pDevInsRC;
    340 
    341     /** Whether R0 is enabled. */
    342     bool                            fR0Enabled;
    343     /** Whether RC is enabled. */
    344     bool                            fGCEnabled;
    345     bool                            afPadding[2];
    346 
    347330    /** Status register - Readonly. */
    348331    volatile uint8_t                regStatus;
     
    354337    uint8_t                         uPendingIntr;
    355338
    356     /** Local RAM for the fetch hostadapter local RAM request.
    357      *  I don't know how big the buffer really is but the maximum
    358      *  seems to be 256 bytes because the offset and count field in the command request
    359      *  are only one byte big.
    360      */
    361     HostAdapterLocalRam             LocalRam;
    362 
    363339    /** Command code the guest issued. */
    364340    uint8_t                         uOperationCode;
    365     /** Buffer for the command parameters the adapter is currently receiving from the guest.
    366      *  Size of the largest command which is possible.
    367      */
    368     uint8_t                         aCommandBuffer[BUSLOGIC_COMMAND_SIZE_MAX]; /* Size of the biggest request. */
    369341    /** Current position in the command buffer. */
    370342    uint8_t                         iParameter;
    371343    /** Parameters left until the command is complete. */
    372344    uint8_t                         cbCommandParametersLeft;
    373 
    374     /** Whether we are using the RAM or reply buffer. */
    375     bool                            fUseLocalRam;
    376     /** Buffer to store reply data from the controller to the guest. */
    377     uint8_t                         aReplyBuffer[BUSLOGIC_REPLY_SIZE_MAX]; /* Size of the biggest reply. */
    378     /** Position in the buffer we are reading next. */
     345    /** Buffer for the command parameters the adapter is currently receiving from the guest.
     346     *  Size of the largest command which is possible.  */
     347    uint8_t                         aCommandBuffer[BUSLOGIC_COMMAND_SIZE_MAX]; /* Size of the biggest request. */
     348
     349    /** Only for LOG_ENABLED builds! */
     350    volatile uint32_t               cInMailboxesReadyIfLogEnabled;
     351
     352    /** Position in the buffer we are reading next.
     353     * @note aligned on 64 byte boundrary for cache-line mojo.  Means IOISABase
     354     *       is at offset 130. */
    379355    uint8_t                         iReply;
    380356    /** Bytes left until the reply buffer is empty. */
    381357    uint8_t                         cbReplyParametersLeft;
     358    /** Buffer to store reply data from the controller to the guest. */
     359    uint8_t                         aReplyBuffer[BUSLOGIC_REPLY_SIZE_MAX]; /* Size of the biggest reply. */
     360
     361    /** ISA I/O port base (disabled if zero). */
     362    RTIOPORT                        IOISABase;
     363    /** Default ISA I/O port base in FW-compatible format. */
     364    uint8_t                         uDefaultISABaseCode;
     365    /** Emulated device type. */
     366    uint8_t                         uDevType;
     367
     368    /** Signature index for Adaptec models. */
     369    uint8_t                         uAhaSigIdx;
     370
     371    /** Whether we are using the RAM or reply buffer. */
     372    bool                            fUseLocalRam;
    382373
    383374    /** Flag whether IRQs are enabled. */
     
    390381    uint8_t                         uIsaIrq;
    391382
    392     /** ISA I/O port base (disabled if zero). */
    393     RTIOPORT                        IOISABase;
    394     /** Default ISA I/O port base in FW-compatible format. */
    395     uint8_t                         uDefaultISABaseCode;
    396     /** Emulated device type. */
    397     uint8_t                         uDevType;
    398 
    399     /** Signature index for Adaptec models. */
    400     uint8_t                         uAhaSigIdx;
    401     uint8_t                         Alignment[7];
    402 
    403383    /** Number of mailboxes the guest set up. */
    404384    uint32_t                        cMailbox;
    405385
    406 #if HC_ARCH_BITS == 64
    407     uint32_t                        Alignment0;
    408 #endif
    409 
    410     /** Time when HBA reset was last initiated. */  /**< @todo does this need to be saved? */
    411     uint64_t                        u64ResetTime;
     386    /** Time when HBA reset was last initiated. */
     387    uint64_t                        u64ResetTime;   /**< @todo does this need to be saved? */
    412388    /** Physical base address of the outgoing mailboxes. */
    413389    RTGCPHYS                        GCPhysAddrMailboxOutgoingBase;
     
    419395    volatile bool                   fNotificationSent;
    420396
    421 #if HC_ARCH_BITS == 64
    422     uint32_t                        Alignment1;
    423 #endif
    424 
    425     /** Physical base address of the incoming mailboxes. */
    426     RTGCPHYS                        GCPhysAddrMailboxIncomingBase;
    427     /** Current incoming mailbox position. */
    428     uint32_t                        uMailboxIncomingPositionCurrent;
    429 
    430397    /** Whether strict round robin is enabled. */
    431398    bool                            fStrictRoundRobinMode;
    432399    /** Whether the extended LUN CCB format is enabled for 32 possible logical units. */
    433400    bool                            fExtendedLunCCBFormat;
    434     bool                            afAlignment2[2];
     401    bool                            fAlignment2;
     402
     403    /** Current incoming mailbox position. */
     404    uint32_t                        uMailboxIncomingPositionCurrent;
     405    /** Physical base address of the incoming mailboxes. */
     406    RTGCPHYS                        GCPhysAddrMailboxIncomingBase;
    435407
    436408    /** Critical section protecting access to the interrupt status register. */
    437409    PDMCRITSECT                     CritSectIntr;
     410
     411    /** Device presence indicators.
     412     * @note Copy of BUSLOGICDEVICE::fPresent accessible from ring-0. */
     413    bool                            afDevicePresent[BUSLOGIC_MAX_DEVICES];
     414
     415    /** The event semaphore the processing thread waits on. */
     416    SUPSEMEVENT                     hEvtProcess;
     417
     418    /** ISA compatibility I/O ports. */
     419    IOMIOPORTHANDLE                 hIoPortsIsa;
     420    /** BIOS I/O ports for booting, optional.   */
     421    IOMIOPORTHANDLE                 hIoPortsBios;
     422    /** PCI Region \#0: I/O ports. */
     423    IOMIOPORTHANDLE                 hIoPortsPci;
     424    /** PCI Region \#1: MMIO (32 bytes, but probably rounded up to 4KB). */
     425    IOMMMIOHANDLE                   hMmio;
     426
     427    /** Local RAM for the fetch hostadapter local RAM request.
     428     *  I don't know how big the buffer really is but the maximum
     429     *  seems to be 256 bytes because the offset and count field in the command request
     430     *  are only one byte big.
     431     */
     432    HostAdapterLocalRam             LocalRam;
     433} BUSLOGIC;
     434/** Pointer to the shared BusLogic device emulation state. */
     435typedef BUSLOGIC *PBUSLOGIC;
     436
     437
     438/**
     439 * The ring-3 BusLogic device emulation state.
     440 *
     441 * @implements  PDMILEDPORTS
     442 */
     443typedef struct BUSLOGICR3
     444{
     445    /** The device instance - only for getting our bearings in interface methods. */
     446    PPDMDEVINSR3                    pDevIns;
    438447
    439448    /** Device state for BIOS access. */
     
    453462    R3PTRTYPE(PPDMIMEDIANOTIFY)     pMediaNotify;
    454463
    455 #if HC_ARCH_BITS == 64
    456     uint32_t                        Alignment3;
    457 #endif
    458 
    459464    /** Indicates that PDMDevHlpAsyncNotificationCompleted should be called when
    460465     * a port is entering the idle state. */
     
    468473    /** Worker thread. */
    469474    R3PTRTYPE(PPDMTHREAD)           pThreadWrk;
    470     /** The event semaphore the processing thread waits on. */
    471     SUPSEMEVENT                     hEvtProcess;
    472475
    473476    /** Pointer to the array of addresses to redo. */
     
    475478    /** Number of addresses the redo array holds. */
    476479    uint32_t                        cReqsRedo;
    477 
    478 #ifdef LOG_ENABLED
    479     volatile uint32_t               cInMailboxesReady;
    480 #else
    481 # if HC_ARCH_BITS == 64
    482     uint32_t                        Alignment4;
    483 # endif
    484 #endif
    485 
    486     /** ISA compatibility I/O ports. */
    487     IOMIOPORTHANDLE                 hIoPortsIsa;
    488     /** BIOS I/O ports for booting, optional.   */
    489     IOMIOPORTHANDLE                 hIoPortsBios;
    490     /** PCI Region \#0: I/O ports. */
    491     IOMIOPORTHANDLE                 hIoPortsPci;
    492     /** PCI Region \#1: MMIO (32 bytes, but probably rounded up to 4KB). */
    493     IOMMMIOHANDLE                   hMmio;
    494 } BUSLOGIC;
    495 /** Pointer to the shared BusLogic device emulation state. */
    496 typedef BUSLOGIC *PBUSLOGIC;
     480} BUSLOGICR3;
     481/** Pointer to the ring-3 BusLogic device emulation state. */
     482typedef BUSLOGICR3 *PBUSLOGICR3;
     483
     484
     485/**
     486 * The ring-0 BusLogic device emulation state.
     487 */
     488typedef struct BUSLOGICR0
     489{
     490    uint64_t                        uUnused;
     491} BUSLOGICR0;
     492/** Pointer to the ring-0 BusLogic device emulation state. */
     493typedef BUSLOGICR0 *PBUSLOGICR0;
     494
     495
     496/**
     497 * The raw-mode BusLogic device emulation state.
     498 */
     499typedef struct BUSLOGICRC
     500{
     501    uint64_t                        uUnused;
     502} BUSLOGICRC;
     503/** Pointer to the raw-mode BusLogic device emulation state. */
     504typedef BUSLOGICRC *PBUSLOGICRC;
     505
     506
     507/** The current context BusLogic device emulation state. */
     508typedef CTX_SUFF(BUSLOGIC) BUSLOGICCC;
     509/** Pointer to the current context BusLogic device emulation state. */
     510typedef CTX_SUFF(PBUSLOGIC) PBUSLOGICCC;
    497511
    498512
     
    9911005 *
    9921006 * @returns nothing.
    993  * @param   pThis    The BusLogic controller instance.
    994  * @param   GCPhys   The guest physical address of the memory buffer.
    995  * @param   pSgBuf   The pointer to the host R3 S/G buffer.
    996  * @param   cbCopy   How many bytes to copy between the two buffers.
    997  * @param   pcbSkip  Initially contains the amount of bytes to skip
    998  *                   starting from the guest physical address before
    999  *                   accessing the S/G buffer and start copying data.
    1000  *                   On return this contains the remaining amount if
    1001  *                   cbCopy < *pcbSkip or 0 otherwise.
    1002  */
    1003 typedef DECLCALLBACK(void) BUSLOGICR3MEMCOPYCALLBACK(PBUSLOGIC pThis, RTGCPHYS GCPhys, PRTSGBUF pSgBuf, size_t cbCopy,
    1004                                                      size_t *pcbSkip);
     1007 * @param   pDevIns The device instance.
     1008 * @param   pThis   The BusLogic controller instance.
     1009 * @param   GCPhys  The guest physical address of the memory buffer.
     1010 * @param   pSgBuf  The pointer to the host R3 S/G buffer.
     1011 * @param   cbCopy  How many bytes to copy between the two buffers.
     1012 * @param   pcbSkip Initially contains the amount of bytes to skip
     1013 *                  starting from the guest physical address before
     1014 *                  accessing the S/G buffer and start copying data.
     1015 *                  On return this contains the remaining amount if
     1016 *                  cbCopy < *pcbSkip or 0 otherwise.
     1017 */
     1018typedef DECLCALLBACK(void) FNBUSLOGICR3MEMCOPYCALLBACK(PPDMDEVINS pDevIns, PBUSLOGIC pThis, RTGCPHYS GCPhys,
     1019                                                       PRTSGBUF pSgBuf, size_t cbCopy, size_t *pcbSkip);
    10051020/** Pointer to a memory copy buffer callback. */
    1006 typedef BUSLOGICR3MEMCOPYCALLBACK *PBUSLOGICR3MEMCOPYCALLBACK;
     1021typedef FNBUSLOGICR3MEMCOPYCALLBACK *PFNBUSLOGICR3MEMCOPYCALLBACK;
    10071022#endif
    10081023
     
    10221037 *
    10231038 * @returns nothing.
    1024  * @param   pBusLogic       Pointer to the BusLogic device instance.
     1039 * @param   pDevIns         The device instance.
     1040 * @param   pBusLogic       Pointer to the shared BusLogic instance data.
    10251041 * @param   fSuppressIrq    Flag to suppress IRQ generation regardless of fIRQEnabled
    10261042 * @param   uIrqType        Type of interrupt being generated.
    10271043 */
    1028 static void buslogicSetInterrupt(PBUSLOGIC pBusLogic, bool fSuppressIrq, uint8_t uIrqType)
     1044static void buslogicSetInterrupt(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, bool fSuppressIrq, uint8_t uIrqType)
    10291045{
    10301046    LogFlowFunc(("pBusLogic=%#p\n", pBusLogic));
     
    10511067    {
    10521068        if (!pBusLogic->uIsaIrq)
    1053             PDMDevHlpPCISetIrq(pBusLogic->CTX_SUFF(pDevIns), 0, 1);
     1069            PDMDevHlpPCISetIrq(pDevIns, 0, 1);
    10541070        else
    1055             PDMDevHlpISASetIrq(pBusLogic->CTX_SUFF(pDevIns), pBusLogic->uIsaIrq, 1);
     1071            PDMDevHlpISASetIrq(pDevIns, pBusLogic->uIsaIrq, 1);
    10561072    }
    10571073}
     
    10611077 *
    10621078 * @returns nothing.
    1063  * @param   pBusLogic  Pointer to the BusLogic device instance.
    1064  */
    1065 static void buslogicClearInterrupt(PBUSLOGIC pBusLogic)
     1079 * @param   pDevIns         The device instance.
     1080 * @param   pBusLogic       Pointer to the shared BusLogic instance data.
     1081 */
     1082static void buslogicClearInterrupt(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic)
    10661083{
    10671084    LogFlowFunc(("pBusLogic=%#p, clearing %#02x (pending %#02x)\n",
     
    10701087    pBusLogic->regStatus &= ~BL_STAT_CMDINV;
    10711088    if (!pBusLogic->uIsaIrq)
    1072         PDMDevHlpPCISetIrq(pBusLogic->CTX_SUFF(pDevIns), 0, 0);
     1089        PDMDevHlpPCISetIrq(pDevIns, 0, 0);
    10731090    else
    1074         PDMDevHlpISASetIrq(pBusLogic->CTX_SUFF(pDevIns), pBusLogic->uIsaIrq, 0);
     1091        PDMDevHlpISASetIrq(pDevIns, pBusLogic->uIsaIrq, 0);
    10751092    /* If there's another pending interrupt, report it now. */
    10761093    if (pBusLogic->uPendingIntr)
    10771094    {
    1078         buslogicSetInterrupt(pBusLogic, false, pBusLogic->uPendingIntr);
     1095        buslogicSetInterrupt(pDevIns, pBusLogic, false, pBusLogic->uPendingIntr);
    10791096        pBusLogic->uPendingIntr = 0;
    10801097    }
     
    11271144 *
    11281145 * @returns VBox status code.
    1129  * @param   pBusLogic Pointer to the BusLogic device instance.
    1130  * @param   fResetIO  Flag determining whether ISA I/O should be reset.
    1131  */
    1132 static int buslogicR3HwReset(PBUSLOGIC pBusLogic, bool fResetIO)
     1146 * @param   pDevIns     The device instance.
     1147 * @param   pBusLogic   Pointer to the shared BusLogic instance data.
     1148 * @param   pThisCC     Pointer to the ring-3 BusLogic instance data.
     1149 * @param   fResetIO    Flag determining whether ISA I/O should be reset.
     1150 */
     1151static int buslogicR3HwReset(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, PBUSLOGICCC pThisCC, bool fResetIO)
    11331152{
    11341153    LogFlowFunc(("pBusLogic=%#p\n", pBusLogic));
     
    11491168    /* Clear any active/pending interrupts. */
    11501169    pBusLogic->uPendingIntr = 0;
    1151     buslogicClearInterrupt(pBusLogic);
     1170    buslogicClearInterrupt(pDevIns, pBusLogic);
    11521171
    11531172    /* Guest-initiated HBA reset does not affect ISA port I/O. */
    11541173    if (fResetIO)
    1155         buslogicR3RegisterISARange(pBusLogic->CTX_SUFF(pDevIns), pBusLogic, pBusLogic->uDefaultISABaseCode);
     1174        buslogicR3RegisterISARange(pDevIns, pBusLogic, pBusLogic->uDefaultISABaseCode);
    11561175    buslogicR3InitializeLocalRam(pBusLogic);
    1157     vboxscsiInitialize(&pBusLogic->VBoxSCSI);
     1176    vboxscsiInitialize(&pThisCC->VBoxSCSI);
    11581177
    11591178    return VINF_SUCCESS;
     
    11661185 *
    11671186 * @returns nothing.
    1168  * @param   pBusLogic       Pointer to the BusLogic device instance
     1187 * @param   pDevIns         The device instance.
     1188 * @param   pBusLogic       Pointer to the shared BusLogic instance data.
    11691189 * @param   fSuppressIrq    Flag to suppress IRQ generation regardless of current state
    11701190 */
    1171 static void buslogicCommandComplete(PBUSLOGIC pBusLogic, bool fSuppressIrq)
     1191static void buslogicCommandComplete(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, bool fSuppressIrq)
    11721192{
    11731193    LogFlowFunc(("pBusLogic=%#p\n", pBusLogic));
     
    11831203        /* Notify that the command is complete. */
    11841204        pBusLogic->regStatus &= ~BL_STAT_DIRRDY;
    1185         buslogicSetInterrupt(pBusLogic, fSuppressIrq, BL_INTR_CMDC);
     1205        buslogicSetInterrupt(pDevIns, pBusLogic, fSuppressIrq, BL_INTR_CMDC);
    11861206    }
    11871207
     
    11941214 *
    11951215 * @returns nothing.
    1196  * @param   pThis       Pointer to the BusLogic device instance
     1216 * @param   pDevIns     The device instance.
     1217 * @param   pThis       Pointer to the shared BusLogic instance data.
    11971218 * @param   GCPhys      Guest physical memory address
    11981219 * @param   pvBuf       Host side buffer address
    11991220 * @param   cbWrite     Number of bytes to write
    12001221 */
    1201 static void blPhysWrite(PBUSLOGIC pThis, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
     1222static void blPhysWrite(PPDMDEVINS pDevIns, PBUSLOGIC pThis, RTGCPHYS GCPhys, const void *pvBuf, size_t cbWrite)
    12021223{
    12031224    if (!pThis->uIsaIrq)
    1204         PDMDevHlpPCIPhysWrite(pThis->CTX_SUFF(pDevIns), GCPhys, pvBuf, cbWrite);
     1225        PDMDevHlpPCIPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
    12051226    else
    1206         PDMDevHlpPhysWrite(pThis->CTX_SUFF(pDevIns), GCPhys, pvBuf, cbWrite);
     1227        PDMDevHlpPhysWrite(pDevIns, GCPhys, pvBuf, cbWrite);
    12071228}
    12081229
     
    12131234 *
    12141235 * @returns nothing
    1215  * @param   pBusLogic   Pointer to the BusLogic device instance.
     1236 * @param   pDevIns     The device instance.
     1237 * @param   pBusLogic   Pointer to the shared BusLogic instance data.
     1238 * @param   pThisCC     Pointer to the ring-3 BusLogic instance data.
    12161239 * @param   fHardReset  Flag initiating a hard (vs. soft) reset.
    12171240 */
    1218 static void buslogicR3InitiateReset(PBUSLOGIC pBusLogic, bool fHardReset)
     1241static void buslogicR3InitiateReset(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, PBUSLOGICCC pThisCC, bool fHardReset)
    12191242{
    12201243    LogFlowFunc(("pBusLogic=%#p fHardReset=%d\n", pBusLogic, fHardReset));
    12211244
    1222     buslogicR3HwReset(pBusLogic, false);
     1245    buslogicR3HwReset(pDevIns, pBusLogic, pThisCC, false);
    12231246
    12241247    if (fHardReset)
     
    12291252
    12301253        /* Remember when the guest initiated a reset (after we're done resetting). */
    1231         pBusLogic->u64ResetTime = PDMDevHlpTMTimeVirtGetNano(pBusLogic->CTX_SUFF(pDevIns));
     1254        pBusLogic->u64ResetTime = PDMDevHlpTMTimeVirtGetNano(pDevIns);
    12321255    }
    12331256}
     
    12381261 *
    12391262 * @returns nothing.
    1240  * @param   pBusLogic                 Pointer to the BusLogic device instance.
    1241  * @param   GCPhysAddrCCB             The physical guest address of the CCB the mailbox is for.
    1242  * @param   pCCBGuest                 The command control block.
    1243  * @param   uHostAdapterStatus        The host adapter status code to set.
    1244  * @param   uDeviceStatus             The target device status to set.
    1245  * @param   uMailboxCompletionCode    Completion status code to set in the mailbox.
    1246  */
    1247 static void buslogicR3SendIncomingMailbox(PBUSLOGIC pBusLogic, RTGCPHYS GCPhysAddrCCB,
     1263 * @param   pDevIns                 The device instance.
     1264 * @param   pBusLogic               Pointer to the shared BusLogic instance data.
     1265 * @param   GCPhysAddrCCB           The physical guest address of the CCB the mailbox is for.
     1266 * @param   pCCBGuest               The command control block.
     1267 * @param   uHostAdapterStatus      The host adapter status code to set.
     1268 * @param   uDeviceStatus           The target device status to set.
     1269 * @param   uMailboxCompletionCode  Completion status code to set in the mailbox.
     1270 */
     1271static void buslogicR3SendIncomingMailbox(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, RTGCPHYS GCPhysAddrCCB,
    12481272                                          PCCBU pCCBGuest, uint8_t uHostAdapterStatus,
    12491273                                          uint8_t uDeviceStatus, uint8_t uMailboxCompletionCode)
     
    12561280    MbxIn.u.in.uCompletionCode     = uMailboxCompletionCode;
    12571281
    1258     int rc = PDMDevHlpCritSectEnter(pBusLogic->CTX_SUFF(pDevIns), &pBusLogic->CritSectIntr, VINF_SUCCESS);
     1282    int rc = PDMDevHlpCritSectEnter(pDevIns, &pBusLogic->CritSectIntr, VINF_SUCCESS);
    12591283    AssertRC(rc);
    12601284
     
    12721296        pCCBGuest->c.uDeviceStatus      = uDeviceStatus;
    12731297        /* Rewrite CCB up to the CDB; perhaps more than necessary. */
    1274         blPhysWrite(pBusLogic, GCPhysAddrCCB, pCCBGuest, RT_UOFFSETOF(CCBC, abCDB));
     1298        blPhysWrite(pDevIns, pBusLogic, GCPhysAddrCCB, pCCBGuest, RT_UOFFSETOF(CCBC, abCDB));
    12751299    }
    12761300
     
    12781302    uint8_t     uCode;
    12791303    unsigned    uCodeOffs = pBusLogic->fMbxIs24Bit ? RT_OFFSETOF(Mailbox24, uCmdState) : RT_OFFSETOF(Mailbox32, u.out.uActionCode);
    1280     PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrMailboxIncoming + uCodeOffs, &uCode, sizeof(uCode));
     1304    PDMDevHlpPhysRead(pDevIns, GCPhysAddrMailboxIncoming + uCodeOffs, &uCode, sizeof(uCode));
    12811305    Assert(uCode == BUSLOGIC_MAILBOX_INCOMING_COMPLETION_FREE);
    12821306# endif
     
    12901314        U32_TO_ADDR(Mbx24.aPhysAddrCCB, MbxIn.u32PhysAddrCCB);
    12911315        Log(("24-bit mailbox: completion code=%u, CCB at %RGp\n", Mbx24.uCmdState, (RTGCPHYS)ADDR_TO_U32(Mbx24.aPhysAddrCCB)));
    1292         blPhysWrite(pBusLogic, GCPhysAddrMailboxIncoming, &Mbx24, sizeof(Mailbox24));
     1316        blPhysWrite(pDevIns, pBusLogic, GCPhysAddrMailboxIncoming, &Mbx24, sizeof(Mailbox24));
    12931317    }
    12941318    else
    12951319    {
    12961320        Log(("32-bit mailbox: completion code=%u, CCB at %RGp\n", MbxIn.u.in.uCompletionCode, GCPhysAddrCCB));
    1297         blPhysWrite(pBusLogic, GCPhysAddrMailboxIncoming, &MbxIn, sizeof(Mailbox32));
     1321        blPhysWrite(pDevIns, pBusLogic, GCPhysAddrMailboxIncoming, &MbxIn, sizeof(Mailbox32));
    12981322    }
    12991323
     
    13041328
    13051329# ifdef LOG_ENABLED
    1306     ASMAtomicIncU32(&pBusLogic->cInMailboxesReady);
     1330    ASMAtomicIncU32(&pBusLogic->cInMailboxesReadyIfLogEnabled);
    13071331# endif
    13081332
    1309     buslogicSetInterrupt(pBusLogic, false, BL_INTR_IMBL);
    1310 
    1311     PDMDevHlpCritSectLeave(pBusLogic->CTX_SUFF(pDevIns), &pBusLogic->CritSectIntr);
     1333    buslogicSetInterrupt(pDevIns, pBusLogic, false, BL_INTR_IMBL);
     1334
     1335    PDMDevHlpCritSectLeave(pDevIns, &pBusLogic->CritSectIntr);
    13121336}
    13131337
     
    14971521 * Copy from guest to host memory worker.
    14981522 *
    1499  * @copydoc BUSLOGICR3MEMCOPYCALLBACK
    1500  */
    1501 static DECLCALLBACK(void) buslogicR3CopyBufferFromGuestWorker(PBUSLOGIC pThis, RTGCPHYS GCPhys, PRTSGBUF pSgBuf,
    1502                                                               size_t cbCopy, size_t *pcbSkip)
    1503 {
     1523 * @copydoc FNBUSLOGICR3MEMCOPYCALLBACK
     1524 */
     1525static DECLCALLBACK(void) buslogicR3CopyBufferFromGuestWorker(PPDMDEVINS pDevIns, PBUSLOGIC pThis, RTGCPHYS GCPhys,
     1526                                                              PRTSGBUF pSgBuf, size_t cbCopy, size_t *pcbSkip)
     1527{
     1528    RT_NOREF(pThis);
     1529
    15041530    size_t cbSkipped = RT_MIN(cbCopy, *pcbSkip);
    15051531    cbCopy   -= cbSkipped;
     
    15131539
    15141540        AssertPtr(pvSeg);
    1515         PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCPhys, pvSeg, cbSeg);
     1541        PDMDevHlpPhysRead(pDevIns, GCPhys, pvSeg, cbSeg);
    15161542        GCPhys += cbSeg;
    15171543        cbCopy -= cbSeg;
     
    15221548 * Copy from host to guest memory worker.
    15231549 *
    1524  * @copydoc BUSLOGICR3MEMCOPYCALLBACK
    1525  */
    1526 static DECLCALLBACK(void) buslogicR3CopyBufferToGuestWorker(PBUSLOGIC pThis, RTGCPHYS GCPhys, PRTSGBUF pSgBuf,
    1527                                                             size_t cbCopy, size_t *pcbSkip)
     1550 * @copydoc FNBUSLOGICR3MEMCOPYCALLBACK
     1551 */
     1552static DECLCALLBACK(void) buslogicR3CopyBufferToGuestWorker(PPDMDEVINS pDevIns, PBUSLOGIC pThis, RTGCPHYS GCPhys,
     1553                                                            PRTSGBUF pSgBuf, size_t cbCopy, size_t *pcbSkip)
    15281554{
    15291555    size_t cbSkipped = RT_MIN(cbCopy, *pcbSkip);
     
    15381564
    15391565        AssertPtr(pvSeg);
    1540         blPhysWrite(pThis, GCPhys, pvSeg, cbSeg);
     1566        blPhysWrite(pDevIns, pThis, GCPhys, pvSeg, cbSeg);
    15411567        GCPhys += cbSeg;
    15421568        cbCopy -= cbSeg;
     
    15481574 *
    15491575 * @returns The amout of bytes actually copied.
    1550  * @param   pThis                  Pointer to the Buslogic device state.
    1551  * @param   pReq                   Pointe to the request state.
    1552  * @param   pfnCopyWorker          The copy method to apply for each guest buffer.
    1553  * @param   pSgBuf                 The host S/G buffer.
    1554  * @param   cbSkip                 How many bytes to skip in advance before starting to copy.
    1555  * @param   cbCopy                 How many bytes to copy.
    1556  */
    1557 static size_t buslogicR3SgBufWalker(PBUSLOGIC pThis, PBUSLOGICREQ pReq,
    1558                                     PBUSLOGICR3MEMCOPYCALLBACK pfnCopyWorker,
     1576 * @param   pDevIns         The device instance.
     1577 * @param   pThis           Pointer to the Buslogic device state.
     1578 * @param   pReq            Pointe to the request state.
     1579 * @param   pfnCopyWorker   The copy method to apply for each guest buffer.
     1580 * @param   pSgBuf          The host S/G buffer.
     1581 * @param   cbSkip          How many bytes to skip in advance before starting to copy.
     1582 * @param   cbCopy          How many bytes to copy.
     1583 */
     1584static size_t buslogicR3SgBufWalker(PPDMDEVINS pDevIns, PBUSLOGIC pThis, PBUSLOGICREQ pReq,
     1585                                    PFNBUSLOGICR3MEMCOPYCALLBACK pfnCopyWorker,
    15591586                                    PRTSGBUF pSgBuf, size_t cbSkip, size_t cbCopy)
    15601587{
    1561     PPDMDEVINS pDevIns = pThis->CTX_SUFF(pDevIns);
    15621588    uint32_t   cbDataCCB;
    15631589    uint32_t   u32PhysAddrCCB;
     
    16291655                    Log(("%s: GCPhysAddrDataBase=%RGp cbCopyThis=%zu\n", __FUNCTION__, GCPhysAddrDataBase, cbCopyThis));
    16301656
    1631                     pfnCopyWorker(pThis, GCPhysAddrDataBase, pSgBuf, cbCopyThis, &cbSkip);
     1657                    pfnCopyWorker(pDevIns, pThis, GCPhysAddrDataBase, pSgBuf, cbCopyThis, &cbSkip);
    16321658                    cbCopied += cbCopyThis;
    16331659                    cbCopy   -= cbCopyThis;
     
    16541680
    16551681            /* Copy the data into the guest memory. */
    1656             pfnCopyWorker(pThis, GCPhysAddrDataBase, pSgBuf, RT_MIN(cbDataCCB, cbCopy), &cbSkip);
     1682            pfnCopyWorker(pDevIns, pThis, GCPhysAddrDataBase, pSgBuf, RT_MIN(cbDataCCB, cbCopy), &cbSkip);
    16571683            cbCopied += RT_MIN(cbDataCCB, cbCopy);
    16581684        }
     
    16661692 *
    16671693 * @returns Amount of bytes copied to the guest.
    1668  * @param   pThis          The BusLogic controller device instance.
    1669  * @param   pReq           Request structure.
    1670  * @param   pSgBuf         The S/G buffer to copy from.
    1671  * @param   cbSkip         How many bytes to skip in advance before starting to copy.
    1672  * @param   cbCopy         How many bytes to copy.
    1673  */
    1674 static size_t buslogicR3CopySgBufToGuest(PBUSLOGIC pThis, PBUSLOGICREQ pReq, PRTSGBUF pSgBuf,
    1675                                          size_t cbSkip, size_t cbCopy)
    1676 {
    1677     return buslogicR3SgBufWalker(pThis, pReq, buslogicR3CopyBufferToGuestWorker,
    1678                                 pSgBuf, cbSkip, cbCopy);
     1694 * @param   pDevIns         The device instance.
     1695 * @param   pThis           Pointer to the shared BusLogic instance data.
     1696 * @param   pReq            Request structure.
     1697 * @param   pSgBuf          The S/G buffer to copy from.
     1698 * @param   cbSkip          How many bytes to skip in advance before starting to copy.
     1699 * @param   cbCopy          How many bytes to copy.
     1700 */
     1701static size_t buslogicR3CopySgBufToGuest(PPDMDEVINS pDevIns, PBUSLOGIC pThis, PBUSLOGICREQ pReq,
     1702                                         PRTSGBUF pSgBuf, size_t cbSkip, size_t cbCopy)
     1703{
     1704    return buslogicR3SgBufWalker(pDevIns, pThis, pReq, buslogicR3CopyBufferToGuestWorker, pSgBuf, cbSkip, cbCopy);
    16791705}
    16801706
     
    16831709 *
    16841710 * @returns Amount of bytes copied from the guest.
    1685  * @param   pThis          The BusLogic controller device instance.
    1686  * @param   pReq           Request structure.
    1687  * @param   pSgBuf         The S/G buffer to copy into.
    1688  * @param   cbSkip         How many bytes to skip in advance before starting to copy.
    1689  * @param   cbCopy         How many bytes to copy.
    1690  */
    1691 static size_t buslogicR3CopySgBufFromGuest(PBUSLOGIC pThis, PBUSLOGICREQ pReq, PRTSGBUF pSgBuf,
    1692                                            size_t cbSkip, size_t cbCopy)
    1693 {
    1694     return buslogicR3SgBufWalker(pThis, pReq, buslogicR3CopyBufferFromGuestWorker,
    1695                                 pSgBuf, cbSkip, cbCopy);
     1711 * @param   pDevIns         The device instance.
     1712 * @param   pThis           Pointer to the shared BusLogic instance data.
     1713 * @param   pReq            Request structure.
     1714 * @param   pSgBuf          The S/G buffer to copy into.
     1715 * @param   cbSkip          How many bytes to skip in advance before starting to copy.
     1716 * @param   cbCopy          How many bytes to copy.
     1717 */
     1718static size_t buslogicR3CopySgBufFromGuest(PPDMDEVINS pDevIns, PBUSLOGIC pThis, PBUSLOGICREQ pReq,
     1719                                           PRTSGBUF pSgBuf, size_t cbSkip, size_t cbCopy)
     1720{
     1721    return buslogicR3SgBufWalker(pDevIns, pThis, pReq, buslogicR3CopyBufferFromGuestWorker, pSgBuf, cbSkip, cbCopy);
    16961722}
    16971723
     
    17261752    if (fCopy && cbSenseBuffer)
    17271753    {
    1728         PBUSLOGIC   pThis = pReq->pTargetDevice->CTX_SUFF(pBusLogic);
     1754        PPDMDEVINS  pDevIns = pReq->pTargetDevice->pDevIns;
     1755        PBUSLOGIC   pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    17291756        RTGCPHYS    GCPhysAddrSenseBuffer;
    17301757
     
    17421769
    17431770        Log3(("%s: sense buffer: %.*Rhxs\n", __FUNCTION__, cbSenseBuffer, pReq->pbSenseBuffer));
    1744         blPhysWrite(pThis, GCPhysAddrSenseBuffer, pReq->pbSenseBuffer, cbSenseBuffer);
     1771        blPhysWrite(pDevIns, pThis, GCPhysAddrSenseBuffer, pReq->pbSenseBuffer, cbSenseBuffer);
    17451772    }
    17461773
     
    17771804 * @returns VBox status code.
    17781805 * @param   pDevIns     The PDM device instance.
    1779  * @param   pBusLogic   Pointer to the BusLogic device instance.
     1806 * @param   pBusLogic   Pointer to the shared BusLogic instance data.
    17801807 */
    17811808static int buslogicProcessCommand(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic)
     
    18191846#ifdef IN_RING3 /* We can do this from ring-0 now, but we'd like to see the LogRel, so we keep going back to ring-3 anyway. */
    18201847            Log(("ISA I/O for PCI (code %x)\n", pBusLogic->aCommandBuffer[0]));
    1821             buslogicR3RegisterISARange(pBusLogic->CTX_SUFF(pDevIns), pBusLogic, pBusLogic->aCommandBuffer[0]);
     1848            buslogicR3RegisterISARange(pDevIns, pBusLogic, pBusLogic->aCommandBuffer[0]);
    18221849            pBusLogic->cbReplyParametersLeft = 0;
    18231850            fSuppressIrq = true;
     
    21422169            for (int i = 0; i < 8; ++i)
    21432170            {
    2144                 if (pBusLogic->aDeviceStates[i].fPresent)
     2171                if (pBusLogic->afDevicePresent[i])
    21452172                    pBusLogic->aReplyBuffer[i] = 1;
    21462173            }
     
    21532180            for (int i = 0; i < 8; ++i)
    21542181            {
    2155                 if (pBusLogic->aDeviceStates[i + 8].fPresent)
     2182                if (pBusLogic->afDevicePresent[i + 8])
    21562183                    pBusLogic->aReplyBuffer[i] = 1;
    21572184            }
     
    21632190            uint16_t u16TargetsPresentMask = 0;
    21642191
    2165             for (uint8_t i = 0; i < RT_ELEMENTS(pBusLogic->aDeviceStates); i++)
     2192            for (uint8_t i = 0; i < RT_ELEMENTS(pBusLogic->afDevicePresent); i++)
    21662193            {
    2167                 if (pBusLogic->aDeviceStates[i].fPresent)
     2194                if (pBusLogic->afDevicePresent[i])
    21682195                    u16TargetsPresentMask |= (1 << i);
    21692196            }
     
    22612288            GCPhysFifoBuf = (RTGCPHYS)ADDR_TO_U32(addr);
    22622289            Log(("Write busmaster FIFO at: %04X\n", ADDR_TO_U32(addr)));
    2263             PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCPhysFifoBuf,
     2290            PDMDevHlpPhysRead(pDevIns, GCPhysFifoBuf,
    22642291                              &pBusLogic->LocalRam.u8View[64], 64);
    22652292            break;
     
    22762303            GCPhysFifoBuf = (RTGCPHYS)ADDR_TO_U32(addr);
    22772304            Log(("Read busmaster FIFO at: %04X\n", ADDR_TO_U32(addr)));
    2278             blPhysWrite(pBusLogic, GCPhysFifoBuf, &pBusLogic->LocalRam.u8View[64], 64);
     2305            blPhysWrite(pDevIns, pBusLogic, GCPhysFifoBuf, &pBusLogic->LocalRam.u8View[64], 64);
    22792306            break;
    22802307        }
     
    23102337        pBusLogic->regStatus |= BL_STAT_DIRRDY;
    23112338    else if (!pBusLogic->cbCommandParametersLeft)
    2312         buslogicCommandComplete(pBusLogic, fSuppressIrq);
     2339        buslogicCommandComplete(pDevIns, pBusLogic, fSuppressIrq);
    23132340
    23142341    return rc;
     
    23192346 *
    23202347 * @returns VBox status code.
    2321  * @param   pBusLogic    Pointer to the BusLogic instance data.
    2322  * @param   iRegister    The index of the register to read.
    2323  * @param   pu32         Where to store the register content.
    2324  */
    2325 static int buslogicRegisterRead(PBUSLOGIC pBusLogic, unsigned iRegister, uint32_t *pu32)
    2326 {
    2327     static const char achAhaSig[] = "ADAP";
     2348 * @param   pDevIns     The device instance.
     2349 * @param   pBusLogic   Pointer to the shared BusLogic instance data.
     2350 * @param   iRegister   The index of the register to read.
     2351 * @param   pu32        Where to store the register content.
     2352 */
     2353static int buslogicRegisterRead(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, unsigned iRegister, uint32_t *pu32)
     2354{
     2355    static const char s_szAhaSig[] = "ADAP";
    23282356    int rc = VINF_SUCCESS;
    23292357
     
    23432371            if (pBusLogic->regStatus & BL_STAT_DACT)
    23442372            {
    2345                 uint64_t    u64AccessTime = PDMDevHlpTMTimeVirtGetNano(pBusLogic->CTX_SUFF(pDevIns));
     2373                uint64_t    u64AccessTime = PDMDevHlpTMTimeVirtGetNano(pDevIns);
    23462374
    23472375                pBusLogic->regStatus &= ~BL_STAT_DACT;
     
    23792407                     */
    23802408                    if (pBusLogic->uOperationCode == BUSLOGICCOMMAND_FETCH_HOST_ADAPTER_LOCAL_RAM)
    2381                         buslogicCommandComplete(pBusLogic, true /* fSuppressIrq */);
     2409                        buslogicCommandComplete(pDevIns, pBusLogic, true /* fSuppressIrq */);
    23822410                    else
    2383                         buslogicCommandComplete(pBusLogic, false);
     2411                        buslogicCommandComplete(pDevIns, pBusLogic, false);
    23842412                }
    23852413            }
     
    23972425            if (pBusLogic->uDevType == DEV_AHA_1540B)
    23982426            {
    2399                 *pu32 = achAhaSig[pBusLogic->uAhaSigIdx];
    2400                 pBusLogic->uAhaSigIdx = (pBusLogic->uAhaSigIdx + 1) & 3;
     2427                uint8_t off = pBusLogic->uAhaSigIdx & 3;
     2428                *pu32 = s_szAhaSig[off];
     2429                pBusLogic->uAhaSigIdx = (off + 1) & 3;
    24012430            }
    24022431            else
     
    24192448 * @returns VBox status code.
    24202449 * @param   pDevIns     The PDM device instance.
    2421  * @param   pBusLogic   Pointer to the BusLogic instance data.
     2450 * @param   pBusLogic   Pointer to the shared BusLogic instance data.
    24222451 * @param   iRegister   The index of the register to read.
    24232452 * @param   uVal        The value to write.
     
    24372466
    24382467                LogRel(("BusLogic: %s reset\n", fHardReset ? "hard" : "soft"));
    2439                 buslogicR3InitiateReset(pBusLogic, fHardReset);
     2468                buslogicR3InitiateReset(pDevIns, pBusLogic, PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC), fHardReset);
    24402469#else
    24412470                rc = VINF_IOM_R3_IOPORT_WRITE;
     
    24492478
    24502479#ifdef LOG_ENABLED
    2451             uint32_t cMailboxesReady = ASMAtomicXchgU32(&pBusLogic->cInMailboxesReady, 0);
     2480            uint32_t cMailboxesReady = ASMAtomicXchgU32(&pBusLogic->cInMailboxesReadyIfLogEnabled, 0);
    24522481            Log(("%u incoming mailboxes were ready when this interrupt was cleared\n", cMailboxesReady));
    24532482#endif
    24542483
    24552484            if (uVal & BL_CTRL_RINT)
    2456                 buslogicClearInterrupt(pBusLogic);
     2485                buslogicClearInterrupt(pDevIns, pBusLogic);
    24572486
    24582487            PDMDevHlpCritSectLeave(pDevIns, &pBusLogic->CritSectIntr);
     
    26582687    ASSERT_GUEST(cb == 1);
    26592688
    2660     return buslogicRegisterRead(pBusLogic, iRegister, pu32);
     2689    return buslogicRegisterRead(pDevIns, pBusLogic, iRegister, pu32);
    26612690}
    26622691
     
    26832712#ifdef IN_RING3
    26842713
    2685 static int buslogicR3PrepareBIOSSCSIRequest(PBUSLOGIC pThis)
     2714static int buslogicR3PrepareBIOSSCSIRequest(PBUSLOGICCC pThisCC)
    26862715{
    26872716    uint32_t uTargetDevice;
     
    26912720    size_t cbBuf;
    26922721
    2693     int rc = vboxscsiSetupRequest(&pThis->VBoxSCSI, &uLun, &pbCdb, &cbCdb, &cbBuf, &uTargetDevice);
     2722    int rc = vboxscsiSetupRequest(&pThisCC->VBoxSCSI, &uLun, &pbCdb, &cbCdb, &cbBuf, &uTargetDevice);
    26942723    AssertMsgRCReturn(rc, ("Setting up SCSI request failed rc=%Rrc\n", rc), rc);
    26952724
    2696     if (   uTargetDevice < RT_ELEMENTS(pThis->aDeviceStates)
    2697         && pThis->aDeviceStates[uTargetDevice].pDrvBase)
    2698     {
    2699         PBUSLOGICDEVICE pTgtDev = &pThis->aDeviceStates[uTargetDevice];
     2725    if (   uTargetDevice < RT_ELEMENTS(pThisCC->aDeviceStates)
     2726        && pThisCC->aDeviceStates[uTargetDevice].pDrvBase)
     2727    {
     2728        PBUSLOGICDEVICE pTgtDev = &pThisCC->aDeviceStates[uTargetDevice];
    27002729        PDMMEDIAEXIOREQ hIoReq;
    27012730        PBUSLOGICREQ pReq;
     
    27182747            uint8_t u8ScsiSts = pReq->u8ScsiSts;
    27192748            pTgtDev->pDrvMediaEx->pfnIoReqFree(pTgtDev->pDrvMediaEx, pReq->hIoReq);
    2720             rc = vboxscsiRequestFinished(&pThis->VBoxSCSI, u8ScsiSts);
     2749            rc = vboxscsiRequestFinished(&pThisCC->VBoxSCSI, u8ScsiSts);
    27212750        }
    27222751        else if (rc == VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS)
     
    27362765    ScsiInquiryData.u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_NOT_CONNECTED_NOT_SUPPORTED;
    27372766
    2738     memcpy(pThis->VBoxSCSI.pbBuf, &ScsiInquiryData, 5);
    2739 
    2740     rc = vboxscsiRequestFinished(&pThis->VBoxSCSI, SCSI_STATUS_OK);
     2767    memcpy(pThisCC->VBoxSCSI.pbBuf, &ScsiInquiryData, 5);
     2768
     2769    rc = vboxscsiRequestFinished(&pThisCC->VBoxSCSI, SCSI_STATUS_OK);
    27412770    AssertMsgRCReturn(rc, ("Finishing BIOS SCSI request failed rc=%Rrc\n", rc), rc);
    27422771
     
    27512780buslogicR3BiosIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
    27522781{
    2753     PBUSLOGIC pBusLogic = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     2782    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
    27542783    RT_NOREF(pvUser, cb);
    27552784
    27562785    ASSERT_GUEST(cb == 1);
    27572786
    2758     int rc = vboxscsiReadRegister(&pBusLogic->VBoxSCSI, offPort, pu32);
     2787    int rc = vboxscsiReadRegister(&pThisCC->VBoxSCSI, offPort, pu32);
    27592788
    27602789    //Log2(("%s: pu32=%p:{%.*Rhxs} iRegister=%d rc=%Rrc\n", __FUNCTION__, pu32, 1, pu32, offPort, rc));
     
    27692798buslogicR3BiosIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
    27702799{
    2771     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     2800    PBUSLOGIC   pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     2801    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
    27722802    Log2(("#%d %s: pvUser=%#p cb=%d u32=%#x offPort=%#x\n", pDevIns->iInstance, __FUNCTION__, pvUser, cb, u32, offPort));
    27732803    RT_NOREF(pvUser, cb);
     
    27772807     * because it should not happen.
    27782808     */
    2779     if (ASMAtomicReadBool(&pThis->fBiosReqPending))
     2809    if (ASMAtomicReadBool(&pThisCC->fBiosReqPending))
    27802810        return VINF_SUCCESS;
    27812811
    27822812    ASSERT_GUEST(cb == 1);
    27832813
    2784     int rc = vboxscsiWriteRegister(&pThis->VBoxSCSI, offPort, (uint8_t)u32);
     2814    int rc = vboxscsiWriteRegister(&pThisCC->VBoxSCSI, offPort, (uint8_t)u32);
    27852815    if (rc == VERR_MORE_DATA)
    27862816    {
    2787         ASMAtomicXchgBool(&pThis->fBiosReqPending, true);
     2817        ASMAtomicXchgBool(&pThisCC->fBiosReqPending, true);
    27882818        /* Wake up the worker thread now that there are pending requests. */
    27892819        int rc2 = PDMDevHlpSUPSemEventSignal(pDevIns, pThis->hEvtProcess);
     
    28032833                                                               uint8_t const *pbSrc, uint32_t *pcTransfers, unsigned cb)
    28042834{
    2805     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     2835    PBUSLOGIC   pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     2836    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
    28062837    Log2(("#%d %s: pvUser=%#p cb=%d offPort=%#x\n", pDevIns->iInstance, __FUNCTION__, pvUser, cb, offPort));
    28072838    RT_NOREF(pvUser);
     
    28112842     * because it should not happen.
    28122843     */
    2813     if (ASMAtomicReadBool(&pThis->fBiosReqPending))
     2844    if (ASMAtomicReadBool(&pThisCC->fBiosReqPending))
    28142845        return VINF_SUCCESS;
    28152846
    2816     int rc = vboxscsiWriteString(pDevIns, &pThis->VBoxSCSI, offPort, pbSrc, pcTransfers, cb);
     2847    int rc = vboxscsiWriteString(pDevIns, &pThisCC->VBoxSCSI, offPort, pbSrc, pcTransfers, cb);
    28172848    if (rc == VERR_MORE_DATA)
    28182849    {
    2819         ASMAtomicXchgBool(&pThis->fBiosReqPending, true);
     2850        ASMAtomicXchgBool(&pThisCC->fBiosReqPending, true);
    28202851        /* Wake up the worker thread now taht there are pending requests. */
    28212852        int rc2 = PDMDevHlpSUPSemEventSignal(pDevIns, pThis->hEvtProcess);
     
    28342865                                                              uint8_t *pbDst, uint32_t *pcTransfers, unsigned cb)
    28352866{
    2836     PBUSLOGIC pBusLogic = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     2867    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
    28372868    LogFlowFunc(("#%d %s: pvUser=%#p cb=%d offPort=%#x\n", pDevIns->iInstance, __FUNCTION__, pvUser, cb, offPort));
    28382869    RT_NOREF(pvUser);
    28392870
    2840     return vboxscsiReadString(pDevIns, &pBusLogic->VBoxSCSI, offPort, pbDst, pcTransfers, cb);
     2871    return vboxscsiReadString(pDevIns, &pThisCC->VBoxSCSI, offPort, pbDst, pcTransfers, cb);
    28412872}
    28422873
     
    28462877 * @returns nothing.
    28472878 * @param   pDevIns         The device instance.
    2848  * @param   pBusLogic       Pointer to the BusLogic device instance.
     2879 * @param   pBusLogic       Pointer to the shared BusLogic instance data.
    28492880 * @param   uBaseCode       Encoded ISA I/O base; only low 3 bits are used.
    28502881 */
     
    29012932
    29022933
    2903 static int buslogicR3ReqComplete(PBUSLOGIC pThis, PBUSLOGICREQ pReq, int rcReq)
     2934static int buslogicR3ReqComplete(PPDMDEVINS pDevIns, PBUSLOGIC pThis, PBUSLOGICCC pThisCC, PBUSLOGICREQ pReq, int rcReq)
    29042935{
    29052936    RT_NOREF(rcReq);
     
    29142945        uint8_t u8ScsiSts = pReq->u8ScsiSts;
    29152946        pTgtDev->pDrvMediaEx->pfnIoReqFree(pTgtDev->pDrvMediaEx, pReq->hIoReq);
    2916         int rc = vboxscsiRequestFinished(&pThis->VBoxSCSI, u8ScsiSts);
     2947        int rc = vboxscsiRequestFinished(&pThisCC->VBoxSCSI, u8ScsiSts);
    29172948        AssertMsgRC(rc, ("Finishing BIOS SCSI request failed rc=%Rrc\n", rc));
    29182949    }
     
    29512982        pTgtDev->pDrvMediaEx->pfnIoReqFree(pTgtDev->pDrvMediaEx, pReq->hIoReq);
    29522983        if (u8ScsiSts == SCSI_STATUS_OK)
    2953             buslogicR3SendIncomingMailbox(pThis, GCPhysAddrCCB, &CCBGuest,
    2954                                         BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_CMD_COMPLETED,
    2955                                         BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
    2956                                         BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITHOUT_ERROR);
     2984            buslogicR3SendIncomingMailbox(pDevIns, pThis, GCPhysAddrCCB, &CCBGuest,
     2985                                          BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_CMD_COMPLETED,
     2986                                          BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
     2987                                          BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITHOUT_ERROR);
    29572988        else if (u8ScsiSts == SCSI_STATUS_CHECK_CONDITION)
    2958             buslogicR3SendIncomingMailbox(pThis, GCPhysAddrCCB, &CCBGuest,
    2959                                         BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_CMD_COMPLETED,
    2960                                         BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_CHECK_CONDITION,
    2961                                         BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITH_ERROR);
     2989            buslogicR3SendIncomingMailbox(pDevIns, pThis, GCPhysAddrCCB, &CCBGuest,
     2990                                          BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_CMD_COMPLETED,
     2991                                          BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_CHECK_CONDITION,
     2992                                          BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITH_ERROR);
    29622993        else
    29632994            AssertMsgFailed(("invalid completion status %u\n", u8ScsiSts));
     
    29682999    }
    29693000
    2970     if (pTgtDev->cOutstandingRequests == 0 && pThis->fSignalIdle)
    2971         PDMDevHlpAsyncNotificationCompleted(pThis->pDevInsR3);
     3001    if (pTgtDev->cOutstandingRequests == 0 && pThisCC->fSignalIdle)
     3002        PDMDevHlpAsyncNotificationCompleted(pDevIns);
    29723003
    29733004    return VINF_SUCCESS;
     
    29803011                                                       uint32_t *piInstance, uint32_t *piLUN)
    29813012{
    2982     PBUSLOGICDEVICE pBusLogicDevice = RT_FROM_MEMBER(pInterface, BUSLOGICDEVICE, IMediaPort);
    2983     PPDMDEVINS pDevIns = pBusLogicDevice->CTX_SUFF(pBusLogic)->CTX_SUFF(pDevIns);
     3013    PBUSLOGICDEVICE pTgtDev = RT_FROM_MEMBER(pInterface, BUSLOGICDEVICE, IMediaPort);
     3014    PPDMDEVINS      pDevIns = pTgtDev->pDevIns;
    29843015
    29853016    AssertPtrReturn(ppcszController, VERR_INVALID_POINTER);
     
    29893020    *ppcszController = pDevIns->pReg->szName;
    29903021    *piInstance = pDevIns->iInstance;
    2991     *piLUN = pBusLogicDevice->iLUN;
     3022    *piLUN = pTgtDev->iLUN;
    29923023
    29933024    return VINF_SUCCESS;
     
    30013032                                                    size_t cbCopy)
    30023033{
    3003     RT_NOREF1(hIoReq);
    30043034    PBUSLOGICDEVICE pTgtDev = RT_FROM_MEMBER(pInterface, BUSLOGICDEVICE, IMediaExPort);
    3005     PBUSLOGICREQ pReq = (PBUSLOGICREQ)pvIoReqAlloc;
     3035    PPDMDEVINS      pDevIns = pTgtDev->pDevIns;
     3036    PBUSLOGICREQ    pReq    = (PBUSLOGICREQ)pvIoReqAlloc;
     3037    RT_NOREF(hIoReq);
    30063038
    30073039    size_t cbCopied = 0;
    3008     if (RT_UNLIKELY(pReq->fBIOS))
    3009         cbCopied = vboxscsiCopyToBuf(&pTgtDev->CTX_SUFF(pBusLogic)->VBoxSCSI, pSgBuf, offDst, cbCopy);
     3040    if (RT_LIKELY(!pReq->fBIOS))
     3041        cbCopied = buslogicR3CopySgBufToGuest(pDevIns, PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC), pReq, pSgBuf, offDst, cbCopy);
    30103042    else
    3011         cbCopied = buslogicR3CopySgBufToGuest(pTgtDev->CTX_SUFF(pBusLogic), pReq, pSgBuf, offDst, cbCopy);
     3043    {
     3044        PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3045        cbCopied = vboxscsiCopyToBuf(&pThisCC->VBoxSCSI, pSgBuf, offDst, cbCopy);
     3046    }
    30123047    return cbCopied == cbCopy ? VINF_SUCCESS : VERR_PDM_MEDIAEX_IOBUF_OVERFLOW;
    30133048}
     
    30203055                                                  size_t cbCopy)
    30213056{
    3022     RT_NOREF1(hIoReq);
     3057    RT_NOREF(hIoReq);
    30233058    PBUSLOGICDEVICE pTgtDev = RT_FROM_MEMBER(pInterface, BUSLOGICDEVICE, IMediaExPort);
    3024     PBUSLOGICREQ pReq = (PBUSLOGICREQ)pvIoReqAlloc;
     3059    PPDMDEVINS      pDevIns = pTgtDev->pDevIns;
     3060    PBUSLOGICREQ    pReq    = (PBUSLOGICREQ)pvIoReqAlloc;
    30253061
    30263062    size_t cbCopied = 0;
    3027     if (RT_UNLIKELY(pReq->fBIOS))
    3028         cbCopied = vboxscsiCopyFromBuf(&pTgtDev->CTX_SUFF(pBusLogic)->VBoxSCSI, pSgBuf, offSrc, cbCopy);
     3063    if (RT_LIKELY(!pReq->fBIOS))
     3064        cbCopied = buslogicR3CopySgBufFromGuest(pDevIns, PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC), pReq, pSgBuf, offSrc, cbCopy);
    30293065    else
    3030         cbCopied = buslogicR3CopySgBufFromGuest(pTgtDev->CTX_SUFF(pBusLogic), pReq, pSgBuf, offSrc, cbCopy);
     3066    {
     3067        PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3068        cbCopied = vboxscsiCopyFromBuf(&pThisCC->VBoxSCSI, pSgBuf, offSrc, cbCopy);
     3069    }
    30313070    return cbCopied == cbCopy ? VINF_SUCCESS : VERR_PDM_MEDIAEX_IOBUF_UNDERRUN;
    30323071}
     
    30403079    RT_NOREF(hIoReq);
    30413080    PBUSLOGICDEVICE pTgtDev = RT_FROM_MEMBER(pInterface, BUSLOGICDEVICE, IMediaExPort);
    3042     buslogicR3ReqComplete(pTgtDev->CTX_SUFF(pBusLogic), (PBUSLOGICREQ)pvIoReqAlloc, rcReq);
     3081    PPDMDEVINS      pDevIns = pTgtDev->pDevIns;
     3082    buslogicR3ReqComplete(pDevIns, PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC), PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC),
     3083                          (PBUSLOGICREQ)pvIoReqAlloc, rcReq);
    30433084    return VINF_SUCCESS;
    30443085}
     
    30503091                                                      void *pvIoReqAlloc, PDMMEDIAEXIOREQSTATE enmState)
    30513092{
    3052     RT_NOREF3(hIoReq, pvIoReqAlloc, enmState);
     3093    RT_NOREF(hIoReq, pvIoReqAlloc, enmState);
    30533094    PBUSLOGICDEVICE pTgtDev = RT_FROM_MEMBER(pInterface, BUSLOGICDEVICE, IMediaExPort);
    30543095
     
    30573098        case PDMMEDIAEXIOREQSTATE_SUSPENDED:
    30583099        {
     3100            PPDMDEVINS  pDevIns = pTgtDev->pDevIns;
     3101            PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3102
    30593103            /* Make sure the request is not accounted for so the VM can suspend successfully. */
    30603104            uint32_t cTasksActive = ASMAtomicDecU32(&pTgtDev->cOutstandingRequests);
    3061             if (!cTasksActive && pTgtDev->CTX_SUFF(pBusLogic)->fSignalIdle)
    3062                 PDMDevHlpAsyncNotificationCompleted(pTgtDev->CTX_SUFF(pBusLogic)->pDevInsR3);
     3105            if (!cTasksActive && pThisCC->fSignalIdle)
     3106                PDMDevHlpAsyncNotificationCompleted(pDevIns);
    30633107            break;
    30643108        }
     
    30783122{
    30793123    PBUSLOGICDEVICE pTgtDev = RT_FROM_MEMBER(pInterface, BUSLOGICDEVICE, IMediaExPort);
    3080     PBUSLOGIC pThis = pTgtDev->CTX_SUFF(pBusLogic);
    3081 
    3082     if (pThis->pMediaNotify)
    3083     {
    3084         int rc = VMR3ReqCallNoWait(PDMDevHlpGetVM(pThis->CTX_SUFF(pDevIns)), VMCPUID_ANY,
    3085                                    (PFNRT)pThis->pMediaNotify->pfnEjected, 2,
    3086                                    pThis->pMediaNotify, pTgtDev->iLUN);
     3124    PPDMDEVINS      pDevIns = pTgtDev->pDevIns;
     3125    PBUSLOGICCC     pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3126
     3127    if (pThisCC->pMediaNotify)
     3128    {
     3129        int rc = VMR3ReqCallNoWait(PDMDevHlpGetVM(pDevIns), VMCPUID_ANY,
     3130                                   (PFNRT)pThisCC->pMediaNotify->pfnEjected, 2,
     3131                                   pThisCC->pMediaNotify, pTgtDev->iLUN);
    30873132        AssertRC(rc);
    30883133    }
    30893134}
    30903135
    3091 static int buslogicR3DeviceSCSIRequestSetup(PBUSLOGIC pBusLogic, RTGCPHYS GCPhysAddrCCB)
     3136static int buslogicR3DeviceSCSIRequestSetup(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, PBUSLOGICCC pThisCC, RTGCPHYS GCPhysAddrCCB)
    30923137{
    30933138    int rc = VINF_SUCCESS;
     
    30973142    /* Fetch the CCB from guest memory. */
    30983143    /** @todo How much do we really have to read? */
    3099     PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrCCB,
     3144    PDMDevHlpPhysRead(pDevIns, GCPhysAddrCCB,
    31003145                      &CCBGuest, sizeof(CCB32));
    31013146
    31023147    uTargetIdCCB = pBusLogic->fMbxIs24Bit ? CCBGuest.o.uTargetId : CCBGuest.n.uTargetId;
    3103     if (RT_LIKELY(uTargetIdCCB < RT_ELEMENTS(pBusLogic->aDeviceStates)))
    3104     {
    3105         PBUSLOGICDEVICE pTgtDev = &pBusLogic->aDeviceStates[uTargetIdCCB];
     3148    if (RT_LIKELY(uTargetIdCCB < RT_ELEMENTS(pThisCC->aDeviceStates)))
     3149    {
     3150        PBUSLOGICDEVICE pTgtDev = &pThisCC->aDeviceStates[uTargetIdCCB];
    31063151
    31073152#ifdef LOG_ENABLED
     
    31323177
    31333178                size_t cbBuf = 0;
    3134                 rc = buslogicR3QueryDataBufferSize(pBusLogic->CTX_SUFF(pDevIns), &pReq->CCBGuest, pReq->fIs24Bit, &cbBuf);
     3179                rc = buslogicR3QueryDataBufferSize(pDevIns, &pReq->CCBGuest, pReq->fIs24Bit, &cbBuf);
    31353180                AssertRC(rc);
    31363181
     
    31543199                                                               &pReq->u8ScsiSts, 30 * RT_MS_1SEC);
    31553200                if (rc != VINF_PDM_MEDIAEX_IOREQ_IN_PROGRESS)
    3156                     buslogicR3ReqComplete(pBusLogic, pReq, rc);
     3201                    buslogicR3ReqComplete(pDevIns, pBusLogic, pThisCC, pReq, rc);
    31573202            }
    31583203            else
    3159                 buslogicR3SendIncomingMailbox(pBusLogic, GCPhysAddrCCB, &CCBGuest,
     3204                buslogicR3SendIncomingMailbox(pDevIns, pBusLogic, GCPhysAddrCCB, &CCBGuest,
    31603205                                              BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_SCSI_SELECTION_TIMEOUT,
    31613206                                              BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
     
    31633208        }
    31643209        else
    3165             buslogicR3SendIncomingMailbox(pBusLogic, GCPhysAddrCCB, &CCBGuest,
     3210            buslogicR3SendIncomingMailbox(pDevIns, pBusLogic, GCPhysAddrCCB, &CCBGuest,
    31663211                                          BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_SCSI_SELECTION_TIMEOUT,
    31673212                                          BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
     
    31693214    }
    31703215    else
    3171         buslogicR3SendIncomingMailbox(pBusLogic, GCPhysAddrCCB, &CCBGuest,
     3216        buslogicR3SendIncomingMailbox(pDevIns, pBusLogic, GCPhysAddrCCB, &CCBGuest,
    31723217                                      BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_INVALID_COMMAND_PARAMETER,
    31733218                                      BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
     
    31773222}
    31783223
    3179 static int buslogicR3DeviceSCSIRequestAbort(PBUSLOGIC pBusLogic, RTGCPHYS GCPhysAddrCCB)
    3180 {
    3181     int      rc = VINF_SUCCESS;
     3224static int buslogicR3DeviceSCSIRequestAbort(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, RTGCPHYS GCPhysAddrCCB)
     3225{
    31823226    uint8_t  uTargetIdCCB;
    31833227    CCBU     CCBGuest;
    31843228
    3185     PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrCCB,
     3229    PDMDevHlpPhysRead(pDevIns, GCPhysAddrCCB,
    31863230                      &CCBGuest, sizeof(CCB32));
    31873231
    31883232    uTargetIdCCB = pBusLogic->fMbxIs24Bit ? CCBGuest.o.uTargetId : CCBGuest.n.uTargetId;
    3189     if (RT_LIKELY(uTargetIdCCB < RT_ELEMENTS(pBusLogic->aDeviceStates)))
    3190         buslogicR3SendIncomingMailbox(pBusLogic, GCPhysAddrCCB, &CCBGuest,
     3233    if (RT_LIKELY(uTargetIdCCB < RT_ELEMENTS(pBusLogic->afDevicePresent)))
     3234        buslogicR3SendIncomingMailbox(pDevIns, pBusLogic, GCPhysAddrCCB, &CCBGuest,
    31913235                                      BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_ABORT_QUEUE_GENERATED,
    31923236                                      BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
    31933237                                      BUSLOGIC_MAILBOX_INCOMING_COMPLETION_ABORTED_NOT_FOUND);
    31943238    else
    3195         buslogicR3SendIncomingMailbox(pBusLogic, GCPhysAddrCCB, &CCBGuest,
     3239        buslogicR3SendIncomingMailbox(pDevIns, pBusLogic, GCPhysAddrCCB, &CCBGuest,
    31963240                                      BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_INVALID_COMMAND_PARAMETER,
    31973241                                      BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
    31983242                                      BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITH_ERROR);
    31993243
    3200     return rc;
     3244    return VINF_SUCCESS;
    32013245}
    32023246
     
    32063250 *
    32073251 * @returns Mailbox guest physical address.
    3208  * @param   pBusLogic    Pointer to the BusLogic instance data.
     3252 * @param   pBusLogic    Pointer to the shared BusLogic instance data.
    32093253 * @param   pMbx         Pointer to the mailbox to read into.
    32103254 */
    3211 static RTGCPHYS buslogicR3ReadOutgoingMailbox(PBUSLOGIC pBusLogic, PMailbox32 pMbx)
     3255static RTGCPHYS buslogicR3ReadOutgoingMailbox(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, PMailbox32 pMbx)
    32123256{
    32133257    RTGCPHYS    GCMailbox;
     
    32183262
    32193263        GCMailbox = pBusLogic->GCPhysAddrMailboxOutgoingBase + (pBusLogic->uMailboxOutgoingPositionCurrent * sizeof(Mailbox24));
    3220         PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCMailbox, &Mbx24, sizeof(Mailbox24));
     3264        PDMDevHlpPhysRead(pDevIns, GCMailbox, &Mbx24, sizeof(Mailbox24));
    32213265        pMbx->u32PhysAddrCCB    = ADDR_TO_U32(Mbx24.aPhysAddrCCB);
    32223266        pMbx->u.out.uActionCode = Mbx24.uCmdState;
     
    32253269    {
    32263270        GCMailbox = pBusLogic->GCPhysAddrMailboxOutgoingBase + (pBusLogic->uMailboxOutgoingPositionCurrent * sizeof(Mailbox32));
    3227         PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCMailbox, pMbx, sizeof(Mailbox32));
     3271        PDMDevHlpPhysRead(pDevIns, GCMailbox, pMbx, sizeof(Mailbox32));
    32283272    }
    32293273
     
    32353279 *
    32363280 * @returns VBox status code.
    3237  * @param   pBusLogic    Pointer to the BusLogic instance data.
    3238  */
    3239 static int buslogicR3ProcessMailboxNext(PBUSLOGIC pBusLogic)
     3281 * @param   pDevIns         The device instance.
     3282 * @param   pBusLogic       Pointer to the shared BusLogic instance data.
     3283 * @param   pThisCC         Pointer to the ring-3 BusLogic instance data.
     3284 */
     3285static int buslogicR3ProcessMailboxNext(PPDMDEVINS pDevIns, PBUSLOGIC pBusLogic, PBUSLOGICCC pThisCC)
    32403286{
    32413287    RTGCPHYS     GCPhysAddrMailboxCurrent;
     
    32513297        {
    32523298            /* Fetch mailbox from guest memory. */
    3253             GCPhysAddrMailboxCurrent = buslogicR3ReadOutgoingMailbox(pBusLogic, &MailboxGuest);
     3299            GCPhysAddrMailboxCurrent = buslogicR3ReadOutgoingMailbox(pDevIns, pBusLogic, &MailboxGuest);
    32543300
    32553301            /* Check the next mailbox. */
     
    32613307    {
    32623308        /* Fetch mailbox from guest memory. */
    3263         GCPhysAddrMailboxCurrent = buslogicR3ReadOutgoingMailbox(pBusLogic, &MailboxGuest);
     3309        GCPhysAddrMailboxCurrent = buslogicR3ReadOutgoingMailbox(pDevIns, pBusLogic, &MailboxGuest);
    32643310    }
    32653311
     
    32843330    uint8_t uActionCode = BUSLOGIC_MAILBOX_OUTGOING_ACTION_FREE;
    32853331    unsigned uCodeOffs = pBusLogic->fMbxIs24Bit ? RT_OFFSETOF(Mailbox24, uCmdState) : RT_OFFSETOF(Mailbox32, u.out.uActionCode);
    3286     blPhysWrite(pBusLogic, GCPhysAddrMailboxCurrent + uCodeOffs, &uActionCode, sizeof(uActionCode));
     3332    blPhysWrite(pDevIns, pBusLogic, GCPhysAddrMailboxCurrent + uCodeOffs, &uActionCode, sizeof(uActionCode));
    32873333
    32883334    if (MailboxGuest.u.out.uActionCode == BUSLOGIC_MAILBOX_OUTGOING_ACTION_START_COMMAND)
    3289         rc = buslogicR3DeviceSCSIRequestSetup(pBusLogic, (RTGCPHYS)MailboxGuest.u32PhysAddrCCB);
     3335        rc = buslogicR3DeviceSCSIRequestSetup(pDevIns, pBusLogic, pThisCC, (RTGCPHYS)MailboxGuest.u32PhysAddrCCB);
    32903336    else if (MailboxGuest.u.out.uActionCode == BUSLOGIC_MAILBOX_OUTGOING_ACTION_ABORT_COMMAND)
    32913337    {
    32923338        LogFlow(("Aborting mailbox\n"));
    3293         rc = buslogicR3DeviceSCSIRequestAbort(pBusLogic, (RTGCPHYS)MailboxGuest.u32PhysAddrCCB);
     3339        rc = buslogicR3DeviceSCSIRequestAbort(pDevIns, pBusLogic, (RTGCPHYS)MailboxGuest.u32PhysAddrCCB);
    32943340    }
    32953341    else
     
    33083354static DECLCALLBACK(int) buslogicR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
    33093355{
     3356    PBUSLOGICCC     pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3357    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    33103358    RT_NOREF(uPass);
    3311     PBUSLOGIC       pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    3312     PCPDMDEVHLPR3   pHlp = pDevIns->pHlpR3;
    33133359
    33143360    /* Save the device config. */
    3315     for (unsigned i = 0; i < RT_ELEMENTS(pThis->aDeviceStates); i++)
    3316         pHlp->pfnSSMPutBool(pSSM, pThis->aDeviceStates[i].fPresent);
     3361    for (unsigned i = 0; i < RT_ELEMENTS(pThisCC->aDeviceStates); i++)
     3362        pHlp->pfnSSMPutBool(pSSM, pThisCC->aDeviceStates[i].fPresent);
    33173363
    33183364    return VINF_SSM_DONT_CALL_AGAIN;
     
    33223368static DECLCALLBACK(int) buslogicR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    33233369{
    3324     PBUSLOGIC       pBusLogic = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    3325     PCPDMDEVHLPR3   pHlp = pDevIns->pHlpR3;
     3370    PBUSLOGIC       pBusLogic      = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     3371    PBUSLOGICCC     pThisCC        = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3372    PCPDMDEVHLPR3   pHlp           = pDevIns->pHlpR3;
    33263373    uint32_t        cReqsSuspended = 0;
    33273374
    33283375    /* Every device first. */
    3329     for (unsigned i = 0; i < RT_ELEMENTS(pBusLogic->aDeviceStates); i++)
    3330     {
    3331         PBUSLOGICDEVICE pDevice = &pBusLogic->aDeviceStates[i];
     3376    for (unsigned i = 0; i < RT_ELEMENTS(pThisCC->aDeviceStates); i++)
     3377    {
     3378        PBUSLOGICDEVICE pDevice = &pThisCC->aDeviceStates[i];
    33323379
    33333380        AssertMsg(!pDevice->cOutstandingRequests,
     
    33653412    pHlp->pfnSSMPutBool  (pSSM, pBusLogic->fExtendedLunCCBFormat);
    33663413
    3367     vboxscsiR3SaveExec(pDevIns->pHlpR3, &pBusLogic->VBoxSCSI, pSSM);
     3414    vboxscsiR3SaveExec(pDevIns->pHlpR3, &pThisCC->VBoxSCSI, pSSM);
    33683415
    33693416    pHlp->pfnSSMPutU32(pSSM, cReqsSuspended);
    33703417
    33713418    /* Save the physical CCB address of all suspended requests. */
    3372     for (unsigned i = 0; i < RT_ELEMENTS(pBusLogic->aDeviceStates) && cReqsSuspended; i++)
    3373     {
    3374         PBUSLOGICDEVICE pDevice = &pBusLogic->aDeviceStates[i];
     3419    for (unsigned i = 0; i < RT_ELEMENTS(pThisCC->aDeviceStates) && cReqsSuspended; i++)
     3420    {
     3421        PBUSLOGICDEVICE pDevice = &pThisCC->aDeviceStates[i];
    33753422        if (pDevice->fPresent)
    33763423        {
     
    34083455static DECLCALLBACK(int) buslogicR3LoadDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    34093456{
     3457    PBUSLOGIC   pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     3458    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
    34103459    RT_NOREF(pSSM);
    3411     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    34123460
    34133461    buslogicR3RegisterISARange(pDevIns, pThis, pThis->uISABaseCode);
    34143462
    34153463    /* Kick of any requests we might need to redo. */
    3416     if (pThis->VBoxSCSI.fBusy)
     3464    if (pThisCC->VBoxSCSI.fBusy)
    34173465    {
    34183466
    34193467        /* The BIOS had a request active when we got suspended. Resume it. */
    3420         int rc = buslogicR3PrepareBIOSSCSIRequest(pThis);
     3468        int rc = buslogicR3PrepareBIOSSCSIRequest(pThisCC);
    34213469        AssertRC(rc);
    34223470    }
    3423     else if (pThis->cReqsRedo)
    3424     {
    3425         for (unsigned i = 0; i < pThis->cReqsRedo; i++)
    3426         {
    3427             int rc = buslogicR3DeviceSCSIRequestSetup(pThis, pThis->paGCPhysAddrCCBRedo[i]);
     3471    else if (pThisCC->cReqsRedo)
     3472    {
     3473        for (unsigned i = 0; i < pThisCC->cReqsRedo; i++)
     3474        {
     3475            int rc = buslogicR3DeviceSCSIRequestSetup(pDevIns, pThis, pThisCC, pThisCC->paGCPhysAddrCCBRedo[i]);
    34283476            AssertRC(rc);
    34293477        }
    34303478
    3431         RTMemFree(pThis->paGCPhysAddrCCBRedo);
    3432         pThis->paGCPhysAddrCCBRedo = NULL;
    3433         pThis->cReqsRedo = 0;
     3479        RTMemFree(pThisCC->paGCPhysAddrCCBRedo);
     3480        pThisCC->paGCPhysAddrCCBRedo = NULL;
     3481        pThisCC->cReqsRedo = 0;
    34343482    }
    34353483
     
    34413489{
    34423490    PBUSLOGIC       pBusLogic = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    3443     PCPDMDEVHLPR3   pHlp = pDevIns->pHlpR3;
    3444     int             rc = VINF_SUCCESS;
     3491    PBUSLOGICCC     pThisCC   = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3492    PCPDMDEVHLPR3   pHlp      = pDevIns->pHlpR3;
     3493    int             rc        = VINF_SUCCESS;
    34453494
    34463495    /* We support saved states only from this and older versions. */
     
    34493498
    34503499    /* Every device first. */
    3451     for (unsigned i = 0; i < RT_ELEMENTS(pBusLogic->aDeviceStates); i++)
    3452     {
    3453         PBUSLOGICDEVICE pDevice = &pBusLogic->aDeviceStates[i];
     3500    for (unsigned i = 0; i < RT_ELEMENTS(pThisCC->aDeviceStates); i++)
     3501    {
     3502        PBUSLOGICDEVICE pDevice = &pThisCC->aDeviceStates[i];
    34543503
    34553504        AssertMsg(!pDevice->cOutstandingRequests,
     
    34983547    pHlp->pfnSSMGetBool  (pSSM, &pBusLogic->fExtendedLunCCBFormat);
    34993548
    3500     rc = vboxscsiR3LoadExec(pDevIns->pHlpR3, &pBusLogic->VBoxSCSI, pSSM);
     3549    rc = vboxscsiR3LoadExec(pDevIns->pHlpR3, &pThisCC->VBoxSCSI, pSSM);
    35013550    if (RT_FAILURE(rc))
    35023551    {
    35033552        LogRel(("BusLogic: Failed to restore BIOS state: %Rrc.\n", rc));
    3504         return PDMDEV_SET_ERROR(pDevIns, rc,
    3505                                 N_("BusLogic: Failed to restore BIOS state\n"));
     3553        return PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic: Failed to restore BIOS state\n"));
    35063554    }
    35073555
     
    35153563        if (cTasks)
    35163564        {
    3517             pBusLogic->paGCPhysAddrCCBRedo = (PRTGCPHYS)RTMemAllocZ(cTasks * sizeof(RTGCPHYS));
    3518             if (RT_LIKELY(pBusLogic->paGCPhysAddrCCBRedo))
     3565            pThisCC->paGCPhysAddrCCBRedo = (PRTGCPHYS)RTMemAllocZ(cTasks * sizeof(RTGCPHYS));
     3566            if (RT_LIKELY(pThisCC->paGCPhysAddrCCBRedo))
    35193567            {
    3520                 pBusLogic->cReqsRedo = cTasks;
     3568                pThisCC->cReqsRedo = cTasks;
    35213569
    35223570                for (uint32_t i = 0; i < cTasks; i++)
     
    35253573
    35263574                    rc = pHlp->pfnSSMGetU32(pSSM, &u32PhysAddrCCB);
    3527                     if (RT_FAILURE(rc))
    3528                         break;
    3529 
    3530                     pBusLogic->paGCPhysAddrCCBRedo[i] = u32PhysAddrCCB;
     3575                    AssertRCBreak(rc);
     3576
     3577                    pThisCC->paGCPhysAddrCCBRedo[i] = u32PhysAddrCCB;
    35313578                }
    35323579            }
     
    35913638static DECLCALLBACK(int) buslogicR3StatusQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
    35923639{
    3593     PBUSLOGIC pBusLogic = RT_FROM_MEMBER(pInterface, BUSLOGIC, ILeds);
     3640    PBUSLOGICCC pThisCC = RT_FROM_MEMBER(pInterface, BUSLOGICCC, ILeds);
    35943641    if (iLUN < BUSLOGIC_MAX_DEVICES)
    35953642    {
    3596         *ppLed = &pBusLogic->aDeviceStates[iLUN].Led;
     3643        *ppLed = &pThisCC->aDeviceStates[iLUN].Led;
    35973644        Assert((*ppLed)->u32Magic == PDMLED_MAGIC);
    35983645        return VINF_SUCCESS;
     
    36063653static DECLCALLBACK(void *) buslogicR3StatusQueryInterface(PPDMIBASE pInterface, const char *pszIID)
    36073654{
    3608     PBUSLOGIC pThis = RT_FROM_MEMBER(pInterface, BUSLOGIC, IBase);
    3609     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
    3610     PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThis->ILeds);
     3655    PBUSLOGICCC pThisCC = RT_FROM_MEMBER(pInterface, BUSLOGICCC, IBase);
     3656    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThisCC->IBase);
     3657    PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThisCC->ILeds);
    36113658    return NULL;
    36123659}
    36133660
    36143661/**
    3615  * The worker thread processing requests from the guest.
    3616  *
    3617  * @returns VBox status code.
    3618  * @param   pDevIns         The device instance.
    3619  * @param   pThread         The thread structure.
     3662 * @callback_method_impl{FNPDMTHREADWAKEUPDEV}
    36203663 */
    36213664static DECLCALLBACK(int) buslogicR3Worker(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
    36223665{
    3623     RT_NOREF(pDevIns);
    3624     PBUSLOGIC pThis = (PBUSLOGIC)pThread->pvUser;
    3625     int rc = VINF_SUCCESS;
     3666    PBUSLOGIC   pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     3667    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
    36263668
    36273669    if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
     
    36303672    while (pThread->enmState == PDMTHREADSTATE_RUNNING)
    36313673    {
    3632         ASMAtomicWriteBool(&pThis->fWrkThreadSleeping, true);
     3674        int rc;
     3675
     3676        ASMAtomicWriteBool(&pThisCC->fWrkThreadSleeping, true);
    36333677        bool fNotificationSent = ASMAtomicXchgBool(&pThis->fNotificationSent, false);
    36343678        if (!fNotificationSent)
    36353679        {
    3636             Assert(ASMAtomicReadBool(&pThis->fWrkThreadSleeping));
     3680            Assert(ASMAtomicReadBool(&pThisCC->fWrkThreadSleeping));
    36373681            rc = PDMDevHlpSUPSemEventWaitNoResume(pDevIns, pThis->hEvtProcess, RT_INDEFINITE_WAIT);
    36383682            AssertLogRelMsgReturn(RT_SUCCESS(rc) || rc == VERR_INTERRUPTED, ("%Rrc\n", rc), rc);
     
    36433687        }
    36443688
    3645         ASMAtomicWriteBool(&pThis->fWrkThreadSleeping, false);
     3689        ASMAtomicWriteBool(&pThisCC->fWrkThreadSleeping, false);
    36463690
    36473691        /* Check whether there is a BIOS request pending and process it first. */
    3648         if (ASMAtomicReadBool(&pThis->fBiosReqPending))
    3649         {
    3650             rc = buslogicR3PrepareBIOSSCSIRequest(pThis);
     3692        if (ASMAtomicReadBool(&pThisCC->fBiosReqPending))
     3693        {
     3694            rc = buslogicR3PrepareBIOSSCSIRequest(pThisCC);
    36513695            AssertRC(rc);
    3652             ASMAtomicXchgBool(&pThis->fBiosReqPending, false);
     3696            ASMAtomicXchgBool(&pThisCC->fBiosReqPending, false);
    36533697        }
    36543698        else
     
    36593703            do
    36603704            {
    3661                 rc = buslogicR3ProcessMailboxNext(pThis);
     3705                rc = buslogicR3ProcessMailboxNext(pDevIns, pThis, pThisCC);
    36623706                AssertMsg(RT_SUCCESS(rc) || rc == VERR_NO_DATA, ("Processing mailbox failed rc=%Rrc\n", rc));
    36633707            } while (RT_SUCCESS(rc));
     
    36703714
    36713715/**
    3672  * Unblock the worker thread so it can respond to a state change.
    3673  *
    3674  * @returns VBox status code.
    3675  * @param   pDevIns     The device instance.
    3676  * @param   pThread     The send thread.
     3716 * @callback_method_impl{FNPDMTHREADWAKEUPDEV}
    36773717 */
    36783718static DECLCALLBACK(int) buslogicR3WorkerWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
     
    37153755                        PDMDevHlpMmioGetMappingAddress(pDevIns, pThis->hMmio),
    37163756                        PCIDevGetInterruptLine(pDevIns->apPciDevs[0]));
    3717     pHlp->pfnPrintf(pHlp, "GC=%RTbool R0=%RTbool\n",
    3718                     !!pThis->fGCEnabled, !!pThis->fR0Enabled);
     3757    pHlp->pfnPrintf(pHlp, "RC=%RTbool R0=%RTbool\n", pDevIns->fRCEnabled, pDevIns->fR0Enabled);
    37193758
    37203759    /* Print mailbox state. */
     
    37533792            for (i = 0; i < pThis->cMailbox; ++i)
    37543793            {
    3755                 PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCMailbox, &Mbx24, sizeof(Mailbox24));
     3794                PDMDevHlpPhysRead(pDevIns, GCMailbox, &Mbx24, sizeof(Mailbox24));
    37563795                pHlp->pfnPrintf(pHlp, "  slot %03d: CCB at %06X action code %02X", i, ADDR_TO_U32(Mbx24.aPhysAddrCCB), Mbx24.uCmdState);
    37573796                pHlp->pfnPrintf(pHlp, "%s\n", pThis->uMailboxOutgoingPositionCurrent == i ? " *" : "");
     
    37643803            for (i = 0; i < pThis->cMailbox; ++i)
    37653804            {
    3766                 PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCMailbox, &Mbx24, sizeof(Mailbox24));
     3805                PDMDevHlpPhysRead(pDevIns, GCMailbox, &Mbx24, sizeof(Mailbox24));
    37673806                pHlp->pfnPrintf(pHlp, "  slot %03d: CCB at %06X completion code %02X", i, ADDR_TO_U32(Mbx24.aPhysAddrCCB), Mbx24.uCmdState);
    37683807                pHlp->pfnPrintf(pHlp, "%s\n", pThis->uMailboxIncomingPositionCurrent == i ? " *" : "");
     
    37803819            for (i = 0; i < pThis->cMailbox; ++i)
    37813820            {
    3782                 PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCMailbox, &Mbx32, sizeof(Mailbox32));
     3821                PDMDevHlpPhysRead(pDevIns, GCMailbox, &Mbx32, sizeof(Mailbox32));
    37833822                pHlp->pfnPrintf(pHlp, "  slot %03d: CCB at %08X action code %02X", i, Mbx32.u32PhysAddrCCB, Mbx32.u.out.uActionCode);
    37843823                pHlp->pfnPrintf(pHlp, "%s\n", pThis->uMailboxOutgoingPositionCurrent == i ? " *" : "");
     
    37913830            for (i = 0; i < pThis->cMailbox; ++i)
    37923831            {
    3793                 PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCMailbox, &Mbx32, sizeof(Mailbox32));
     3832                PDMDevHlpPhysRead(pDevIns, GCMailbox, &Mbx32, sizeof(Mailbox32));
    37943833                pHlp->pfnPrintf(pHlp, "  slot %03d: CCB at %08X completion code %02X BTSTAT %02X SDSTAT %02X", i,
    37953834                                Mbx32.u32PhysAddrCCB, Mbx32.u.in.uCompletionCode, Mbx32.u.in.uHostAdapterStatus, Mbx32.u.in.uTargetDeviceStatus);
     
    38143853static bool buslogicR3AllAsyncIOIsFinished(PPDMDEVINS pDevIns)
    38153854{
    3816     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    3817 
    3818     for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aDeviceStates); i++)
    3819     {
    3820         PBUSLOGICDEVICE pThisDevice = &pThis->aDeviceStates[i];
     3855    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3856
     3857    for (uint32_t i = 0; i < RT_ELEMENTS(pThisCC->aDeviceStates); i++)
     3858    {
     3859        PBUSLOGICDEVICE pThisDevice = &pThisCC->aDeviceStates[i];
    38213860        if (pThisDevice->pDrvBase)
    38223861        {
     
    38403879        return false;
    38413880
    3842     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    3843     ASMAtomicWriteBool(&pThis->fSignalIdle, false);
     3881    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3882    ASMAtomicWriteBool(&pThisCC->fSignalIdle, false);
    38443883    return true;
    38453884}
     
    38503889static void buslogicR3SuspendOrPowerOff(PPDMDEVINS pDevIns)
    38513890{
    3852     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    3853 
    3854     ASMAtomicWriteBool(&pThis->fSignalIdle, true);
     3891    PBUSLOGIC   pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     3892    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3893
     3894    ASMAtomicWriteBool(&pThisCC->fSignalIdle, true);
    38553895    if (!buslogicR3AllAsyncIOIsFinished(pDevIns))
    38563896        PDMDevHlpSetAsyncNotification(pDevIns, buslogicR3IsAsyncSuspendOrPowerOffDone);
    38573897    else
    38583898    {
    3859         ASMAtomicWriteBool(&pThis->fSignalIdle, false);
     3899        ASMAtomicWriteBool(&pThisCC->fSignalIdle, false);
    38603900        AssertMsg(!pThis->fNotificationSent, ("The PDM Queue should be empty at this point\n"));
    3861     }
    3862 
    3863     for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aDeviceStates); i++)
    3864     {
    3865         PBUSLOGICDEVICE pThisDevice = &pThis->aDeviceStates[i];
     3901        RT_NOREF(pThis);
     3902    }
     3903
     3904    for (uint32_t i = 0; i < RT_ELEMENTS(pThisCC->aDeviceStates); i++)
     3905    {
     3906        PBUSLOGICDEVICE pThisDevice = &pThisCC->aDeviceStates[i];
    38663907        if (pThisDevice->pDrvMediaEx)
    38673908            pThisDevice->pDrvMediaEx->pfnNotifySuspend(pThisDevice->pDrvMediaEx);
     
    38923933static DECLCALLBACK(void) buslogicR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
    38933934{
     3935    PBUSLOGIC       pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     3936    PBUSLOGICCC     pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3937    PBUSLOGICDEVICE pDevice = &pThisCC->aDeviceStates[iLUN];
     3938    Log(("%s:\n", __FUNCTION__));
    38943939    RT_NOREF(fFlags);
    3895     PBUSLOGIC       pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    3896     PBUSLOGICDEVICE pDevice = &pThis->aDeviceStates[iLUN];
    3897 
    3898     Log(("%s:\n", __FUNCTION__));
     3940
    38993941
    39003942    AssertMsg(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
     
    39043946     * Zero some important members.
    39053947     */
     3948    pThis->afDevicePresent[iLUN] = false;
    39063949    pDevice->fPresent    = false;
    39073950    pDevice->pDrvBase    = NULL;
     
    39233966{
    39243967    PBUSLOGIC       pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    3925     PBUSLOGICDEVICE pDevice = &pThis->aDeviceStates[iLUN];
     3968    PBUSLOGICCC     pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     3969    PBUSLOGICDEVICE pDevice = &pThisCC->aDeviceStates[iLUN];
    39263970    int rc;
    39273971
     
    39594003                          rc);
    39604004
     4005        pThis->afDevicePresent[iLUN] = true;
    39614006        pDevice->fPresent = true;
    39624007    }
     
    39664011    if (RT_FAILURE(rc))
    39674012    {
     4013        pThis->afDevicePresent[iLUN] = false;
    39684014        pDevice->fPresent    = false;
    39694015        pDevice->pDrvBase    = NULL;
     
    39824028static DECLCALLBACK(bool) buslogicR3IsAsyncResetDone(PPDMDEVINS pDevIns)
    39834029{
    3984     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     4030    PBUSLOGIC   pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     4031    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
    39854032
    39864033    if (!buslogicR3AllAsyncIOIsFinished(pDevIns))
    39874034        return false;
    3988     ASMAtomicWriteBool(&pThis->fSignalIdle, false);
    3989 
    3990     buslogicR3HwReset(pThis, true);
     4035    ASMAtomicWriteBool(&pThisCC->fSignalIdle, false);
     4036
     4037    buslogicR3HwReset(pDevIns, pThis, pThisCC, true);
    39914038    return true;
    39924039}
     
    39974044static DECLCALLBACK(void) buslogicR3Reset(PPDMDEVINS pDevIns)
    39984045{
    3999     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    4000 
    4001     ASMAtomicWriteBool(&pThis->fSignalIdle, true);
     4046    PBUSLOGIC   pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     4047    PBUSLOGICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     4048
     4049    ASMAtomicWriteBool(&pThisCC->fSignalIdle, true);
    40024050    if (!buslogicR3AllAsyncIOIsFinished(pDevIns))
    40034051        PDMDevHlpSetAsyncNotification(pDevIns, buslogicR3IsAsyncResetDone);
    40044052    else
    40054053    {
    4006         ASMAtomicWriteBool(&pThis->fSignalIdle, false);
    4007         buslogicR3HwReset(pThis, true);
    4008     }
    4009 }
    4010 
    4011 static DECLCALLBACK(void) buslogicR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    4012 {
    4013     RT_NOREF(offDelta);
    4014     PBUSLOGIC pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    4015 
    4016     pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    4017 
    4018     for (uint32_t i = 0; i < BUSLOGIC_MAX_DEVICES; i++)
    4019     {
    4020         PBUSLOGICDEVICE pDevice = &pThis->aDeviceStates[i];
    4021 
    4022         pDevice->pBusLogicRC = PDMINS_2_DATA_RCPTR(pDevIns);
    4023     }
    4024 
     4054        ASMAtomicWriteBool(&pThisCC->fSignalIdle, false);
     4055        buslogicR3HwReset(pDevIns, pThis, pThisCC, true);
     4056    }
    40254057}
    40264058
     
    40664098{
    40674099    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    4068     PBUSLOGIC       pThis = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
    4069     PCPDMDEVHLPR3   pHlp = pDevIns->pHlpR3;
     4100    PBUSLOGIC       pThis   = PDMDEVINS_2_DATA(pDevIns, PBUSLOGIC);
     4101    PBUSLOGICCC     pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PBUSLOGICCC);
     4102    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    40704103
    40714104    /*
    40724105     * Init instance data (do early because of constructor).
    40734106     */
    4074     pThis->pDevInsR3 = pDevIns;
    4075     pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
    4076     pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
    4077     pThis->IBase.pfnQueryInterface = buslogicR3StatusQueryInterface;
    4078     pThis->ILeds.pfnQueryStatusLed = buslogicR3StatusQueryStatusLed;
     4107    pThisCC->pDevIns = pDevIns;
     4108    pThisCC->IBase.pfnQueryInterface = buslogicR3StatusQueryInterface;
     4109    pThisCC->ILeds.pfnQueryStatusLed = buslogicR3StatusQueryStatusLed;
    40794110
    40804111    PPDMPCIDEV pPciDev = pDevIns->apPciDevs[0];
     
    41004131    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "Bootable|AdapterType|ISACompat", "");
    41014132
    4102     pThis->fGCEnabled = pDevIns->fRCEnabled;
    4103     pThis->fR0Enabled = pDevIns->fR0Enabled;
    4104 
    41054133    bool fBootable = true;
    41064134    int rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "Bootable", &fBootable, true);
     
    42144242    RTStrPrintf(szDevTag, sizeof(szDevTag), "BUSLOGIC-%u", iInstance);
    42154243
    4216     rc = PDMDevHlpThreadCreate(pDevIns, &pThis->pThreadWrk, pThis, buslogicR3Worker,
     4244    rc = PDMDevHlpThreadCreate(pDevIns, &pThisCC->pThreadWrk, pThis, buslogicR3Worker,
    42174245                               buslogicR3WorkerWakeUp, 0, RTTHREADTYPE_IO, szDevTag);
    42184246    if (RT_FAILURE(rc))
     
    42214249
    42224250    /* Initialize per device state. */
    4223     for (unsigned i = 0; i < RT_ELEMENTS(pThis->aDeviceStates); i++)
    4224     {
    4225         PBUSLOGICDEVICE pDevice = &pThis->aDeviceStates[i];
     4251    for (unsigned i = 0; i < RT_ELEMENTS(pThisCC->aDeviceStates); i++)
     4252    {
     4253        PBUSLOGICDEVICE pDevice = &pThisCC->aDeviceStates[i];
    42264254
    42274255        /* Initialize static parts of the device. */
    42284256        pDevice->iLUN = i;
    4229         pDevice->pBusLogicR3 = pThis;
    4230         pDevice->pBusLogicR0 = PDMINS_2_DATA_R0PTR(pDevIns);
    4231         pDevice->pBusLogicRC = PDMINS_2_DATA_RCPTR(pDevIns);
     4257        pDevice->pDevIns = pDevIns;
    42324258        pDevice->Led.u32Magic = PDMLED_MAGIC;
    42334259        pDevice->IBase.pfnQueryInterface                 = buslogicR3DeviceQueryInterface;
     
    42654291                                           pDevice->iLUN);
    42664292
     4293            pThis->afDevicePresent[i] = true;
    42674294            pDevice->fPresent = true;
    42684295        }
    42694296        else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    42704297        {
     4298            pThis->afDevicePresent[i] = false;
    42714299            pDevice->fPresent    = false;
    42724300            pDevice->pDrvBase    = NULL;
     
    42874315     */
    42884316    PPDMIBASE pBase;
    4289     rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pBase, "Status Port");
     4317    rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThisCC->IBase, &pBase, "Status Port");
    42904318    if (RT_SUCCESS(rc))
    42914319    {
    4292         pThis->pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
    4293         pThis->pMediaNotify = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIANOTIFY);
    4294     }
    4295     else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
    4296     {
    4297         AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
    4298         return PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic cannot attach to status driver"));
    4299     }
     4320        pThisCC->pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
     4321        pThisCC->pMediaNotify = PDMIBASE_QUERY_INTERFACE(pBase, PDMIMEDIANOTIFY);
     4322    }
     4323    else
     4324        AssertMsgReturn(rc == VERR_PDM_NO_ATTACHED_DRIVER, ("Failed to attach to status driver. rc=%Rrc\n", rc),
     4325                        PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic cannot attach to status driver")));
    43004326
    43014327    rc = PDMDevHlpSSMRegisterEx(pDevIns, BUSLOGIC_SAVED_STATE_MINOR_VERSION, sizeof(*pThis), NULL,
     
    43134339    PDMDevHlpDBGFInfoRegister(pDevIns, szTmp, "BusLogic HBA info", buslogicR3Info);
    43144340
    4315     rc = buslogicR3HwReset(pThis, true);
     4341    rc = buslogicR3HwReset(pDevIns, pThis, pThisCC, true);
    43164342    AssertMsgRC(rc, ("hardware reset of BusLogic host adapter failed rc=%Rrc\n", rc));
    43174343
     
    43494375    /* .uReserved0 = */             0,
    43504376    /* .szName = */                 "buslogic",
    4351     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ |
    4352                                     PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION | PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION |
    4353                                     PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION,
     4377    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE
     4378                                    | PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION | PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION
     4379                                    | PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION,
    43544380    /* .fClass = */                 PDM_DEVREG_CLASS_STORAGE,
    43554381    /* .cMaxInstances = */          ~0U,
    43564382    /* .uSharedVersion = */         42,
    43574383    /* .cbInstanceShared = */       sizeof(BUSLOGIC),
    4358     /* .cbInstanceCC = */           0,
    4359     /* .cbInstanceRC = */           0,
     4384    /* .cbInstanceCC = */           sizeof(BUSLOGICCC),
     4385    /* .cbInstanceRC = */           sizeof(BUSLOGICRC),
    43604386    /* .cMaxPciDevices = */         1,
    43614387    /* .cMaxMsixVectors = */        0,
     
    43664392    /* .pfnConstruct = */           buslogicR3Construct,
    43674393    /* .pfnDestruct = */            buslogicR3Destruct,
    4368     /* .pfnRelocate = */            buslogicR3Relocate,
     4394    /* .pfnRelocate = */            NULL,
    43694395    /* .pfnMemSetup = */            NULL,
    43704396    /* .pfnPowerOn = */             NULL,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette