VirtualBox

source: vbox/trunk/src/VBox/Devices/Storage/DevBusLogic.cpp@ 62956

Last change on this file since 62956 was 62632, checked in by vboxsync, 8 years ago

Devices: unused parameter warnings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 167.0 KB
Line 
1/* $Id: DevBusLogic.cpp 62632 2016-07-28 15:58:14Z vboxsync $ */
2/** @file
3 * VBox storage devices - BusLogic SCSI host adapter BT-958.
4 *
5 * Based on the Multi-Master Ultra SCSI Systems Technical Reference Manual.
6 */
7
8/*
9 * Copyright (C) 2006-2016 Oracle Corporation
10 *
11 * This file is part of VirtualBox Open Source Edition (OSE), as
12 * available from http://www.virtualbox.org. This file is free software;
13 * you can redistribute it and/or modify it under the terms of the GNU
14 * General Public License (GPL) as published by the Free Software
15 * Foundation, in version 2 as it comes in the "COPYING" file of the
16 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
18 */
19
20
21/*********************************************************************************************************************************
22* Header Files *
23*********************************************************************************************************************************/
24#define LOG_GROUP LOG_GROUP_DEV_BUSLOGIC
25#include <VBox/vmm/pdmdev.h>
26#include <VBox/vmm/pdmstorageifs.h>
27#include <VBox/vmm/pdmcritsect.h>
28#include <VBox/scsi.h>
29#include <iprt/asm.h>
30#include <iprt/assert.h>
31#include <iprt/string.h>
32#include <iprt/log.h>
33#ifdef IN_RING3
34# include <iprt/alloc.h>
35# include <iprt/memcache.h>
36# include <iprt/param.h>
37# include <iprt/uuid.h>
38#endif
39
40#include "VBoxSCSI.h"
41#include "VBoxDD.h"
42
43
44/*********************************************************************************************************************************
45* Defined Constants And Macros *
46*********************************************************************************************************************************/
47/** Maximum number of attached devices the adapter can handle. */
48#define BUSLOGIC_MAX_DEVICES 16
49
50/** Maximum number of scatter gather elements this device can handle. */
51#define BUSLOGIC_MAX_SCATTER_GATHER_LIST_SIZE 128
52
53/** Size of the command buffer. */
54#define BUSLOGIC_COMMAND_SIZE_MAX 53
55
56/** Size of the reply buffer. */
57#define BUSLOGIC_REPLY_SIZE_MAX 64
58
59/** Custom fixed I/O ports for BIOS controller access.
60 * Note that these should not be in the ISA range (below 400h) to avoid
61 * conflicts with ISA device probing. Addresses in the 300h-340h range should be
62 * especially avoided.
63 */
64#define BUSLOGIC_BIOS_IO_PORT 0x430
65
66/** State saved version. */
67#define BUSLOGIC_SAVED_STATE_MINOR_VERSION 4
68
69/** Saved state version before the suspend on error feature was implemented. */
70#define BUSLOGIC_SAVED_STATE_MINOR_PRE_ERROR_HANDLING 1
71/** Saved state version before 24-bit mailbox support was implemented. */
72#define BUSLOGIC_SAVED_STATE_MINOR_PRE_24BIT_MBOX 2
73/** Saved state version before command buffer size was raised. */
74#define BUSLOGIC_SAVED_STATE_MINOR_PRE_CMDBUF_RESIZE 3
75
76/** Command buffer size in old saved states. */
77#define BUSLOGIC_COMMAND_SIZE_OLD 5
78
79/** The duration of software-initiated reset (in nano seconds).
80 * Not documented, set to 50 ms. */
81#define BUSLOGIC_RESET_DURATION_NS UINT64_C(50000000)
82
83
84/*********************************************************************************************************************************
85* Structures and Typedefs *
86*********************************************************************************************************************************/
87/**
88 * State of a device attached to the buslogic host adapter.
89 *
90 * @implements PDMIBASE
91 * @implements PDMISCSIPORT
92 * @implements PDMILEDPORTS
93 */
94typedef struct BUSLOGICDEVICE
95{
96 /** Pointer to the owning buslogic device instance. - R3 pointer */
97 R3PTRTYPE(struct BUSLOGIC *) pBusLogicR3;
98 /** Pointer to the owning buslogic device instance. - R0 pointer */
99 R0PTRTYPE(struct BUSLOGIC *) pBusLogicR0;
100 /** Pointer to the owning buslogic device instance. - RC pointer */
101 RCPTRTYPE(struct BUSLOGIC *) pBusLogicRC;
102
103 /** Flag whether device is present. */
104 bool fPresent;
105 /** LUN of the device. */
106 RTUINT iLUN;
107
108#if HC_ARCH_BITS == 64
109 uint32_t Alignment0;
110#endif
111
112 /** Our base interface. */
113 PDMIBASE IBase;
114 /** SCSI port interface. */
115 PDMISCSIPORT ISCSIPort;
116 /** Led interface. */
117 PDMILEDPORTS ILed;
118 /** Pointer to the attached driver's base interface. */
119 R3PTRTYPE(PPDMIBASE) pDrvBase;
120 /** Pointer to the underlying SCSI connector interface. */
121 R3PTRTYPE(PPDMISCSICONNECTOR) pDrvSCSIConnector;
122 /** The status LED state for this device. */
123 PDMLED Led;
124
125#if HC_ARCH_BITS == 64
126 uint32_t Alignment1;
127#endif
128
129 /** Number of outstanding tasks on the port. */
130 volatile uint32_t cOutstandingRequests;
131
132} BUSLOGICDEVICE, *PBUSLOGICDEVICE;
133
134/**
135 * Commands the BusLogic adapter supports.
136 */
137enum BUSLOGICCOMMAND
138{
139 BUSLOGICCOMMAND_TEST_CMDC_INTERRUPT = 0x00,
140 BUSLOGICCOMMAND_INITIALIZE_MAILBOX = 0x01,
141 BUSLOGICCOMMAND_EXECUTE_MAILBOX_COMMAND = 0x02,
142 BUSLOGICCOMMAND_EXECUTE_BIOS_COMMAND = 0x03,
143 BUSLOGICCOMMAND_INQUIRE_BOARD_ID = 0x04,
144 BUSLOGICCOMMAND_ENABLE_OUTGOING_MAILBOX_AVAILABLE_INTERRUPT = 0x05,
145 BUSLOGICCOMMAND_SET_SCSI_SELECTION_TIMEOUT = 0x06,
146 BUSLOGICCOMMAND_SET_PREEMPT_TIME_ON_BUS = 0x07,
147 BUSLOGICCOMMAND_SET_TIME_OFF_BUS = 0x08,
148 BUSLOGICCOMMAND_SET_BUS_TRANSFER_RATE = 0x09,
149 BUSLOGICCOMMAND_INQUIRE_INSTALLED_DEVICES_ID_0_TO_7 = 0x0a,
150 BUSLOGICCOMMAND_INQUIRE_CONFIGURATION = 0x0b,
151 BUSLOGICCOMMAND_ENABLE_TARGET_MODE = 0x0c,
152 BUSLOGICCOMMAND_INQUIRE_SETUP_INFORMATION = 0x0d,
153 BUSLOGICCOMMAND_WRITE_ADAPTER_LOCAL_RAM = 0x1a,
154 BUSLOGICCOMMAND_READ_ADAPTER_LOCAL_RAM = 0x1b,
155 BUSLOGICCOMMAND_WRITE_BUSMASTER_CHIP_FIFO = 0x1c,
156 BUSLOGICCOMMAND_READ_BUSMASTER_CHIP_FIFO = 0x1d,
157 BUSLOGICCOMMAND_ECHO_COMMAND_DATA = 0x1f,
158 BUSLOGICCOMMAND_HOST_ADAPTER_DIAGNOSTIC = 0x20,
159 BUSLOGICCOMMAND_SET_ADAPTER_OPTIONS = 0x21,
160 BUSLOGICCOMMAND_INQUIRE_INSTALLED_DEVICES_ID_8_TO_15 = 0x23,
161 BUSLOGICCOMMAND_INQUIRE_TARGET_DEVICES = 0x24,
162 BUSLOGICCOMMAND_DISABLE_HOST_ADAPTER_INTERRUPT = 0x25,
163 BUSLOGICCOMMAND_EXT_BIOS_INFO = 0x28,
164 BUSLOGICCOMMAND_UNLOCK_MAILBOX = 0x29,
165 BUSLOGICCOMMAND_INITIALIZE_EXTENDED_MAILBOX = 0x81,
166 BUSLOGICCOMMAND_EXECUTE_SCSI_COMMAND = 0x83,
167 BUSLOGICCOMMAND_INQUIRE_FIRMWARE_VERSION_3RD_LETTER = 0x84,
168 BUSLOGICCOMMAND_INQUIRE_FIRMWARE_VERSION_LETTER = 0x85,
169 BUSLOGICCOMMAND_INQUIRE_PCI_HOST_ADAPTER_INFORMATION = 0x86,
170 BUSLOGICCOMMAND_INQUIRE_HOST_ADAPTER_MODEL_NUMBER = 0x8b,
171 BUSLOGICCOMMAND_INQUIRE_SYNCHRONOUS_PERIOD = 0x8c,
172 BUSLOGICCOMMAND_INQUIRE_EXTENDED_SETUP_INFORMATION = 0x8d,
173 BUSLOGICCOMMAND_ENABLE_STRICT_ROUND_ROBIN_MODE = 0x8f,
174 BUSLOGICCOMMAND_STORE_HOST_ADAPTER_LOCAL_RAM = 0x90,
175 BUSLOGICCOMMAND_FETCH_HOST_ADAPTER_LOCAL_RAM = 0x91,
176 BUSLOGICCOMMAND_STORE_LOCAL_DATA_IN_EEPROM = 0x92,
177 BUSLOGICCOMMAND_UPLOAD_AUTO_SCSI_CODE = 0x94,
178 BUSLOGICCOMMAND_MODIFY_IO_ADDRESS = 0x95,
179 BUSLOGICCOMMAND_SET_CCB_FORMAT = 0x96,
180 BUSLOGICCOMMAND_WRITE_INQUIRY_BUFFER = 0x9a,
181 BUSLOGICCOMMAND_READ_INQUIRY_BUFFER = 0x9b,
182 BUSLOGICCOMMAND_FLASH_ROM_UPLOAD_DOWNLOAD = 0xa7,
183 BUSLOGICCOMMAND_READ_SCAM_DATA = 0xa8,
184 BUSLOGICCOMMAND_WRITE_SCAM_DATA = 0xa9
185} BUSLOGICCOMMAND;
186
187#pragma pack(1)
188/**
189 * Auto SCSI structure which is located
190 * in host adapter RAM and contains several
191 * configuration parameters.
192 */
193typedef struct AutoSCSIRam
194{
195 uint8_t aInternalSignature[2];
196 uint8_t cbInformation;
197 uint8_t aHostAdaptertype[6];
198 uint8_t uReserved1;
199 bool fFloppyEnabled : 1;
200 bool fFloppySecondary : 1;
201 bool fLevelSensitiveInterrupt : 1;
202 unsigned char uReserved2 : 2;
203 unsigned char uSystemRAMAreForBIOS : 3;
204 unsigned char uDMAChannel : 7;
205 bool fDMAAutoConfiguration : 1;
206 unsigned char uIrqChannel : 7;
207 bool fIrqAutoConfiguration : 1;
208 uint8_t uDMATransferRate;
209 uint8_t uSCSIId;
210 bool fLowByteTerminated : 1;
211 bool fParityCheckingEnabled : 1;
212 bool fHighByteTerminated : 1;
213 bool fNoisyCablingEnvironment : 1;
214 bool fFastSynchronousNeogtiation : 1;
215 bool fBusResetEnabled : 1;
216 bool fReserved3 : 1;
217 bool fActiveNegotiationEnabled : 1;
218 uint8_t uBusOnDelay;
219 uint8_t uBusOffDelay;
220 bool fHostAdapterBIOSEnabled : 1;
221 bool fBIOSRedirectionOfInt19 : 1;
222 bool fExtendedTranslation : 1;
223 bool fMapRemovableAsFixed : 1;
224 bool fReserved4 : 1;
225 bool fBIOSSupportsMoreThan2Drives : 1;
226 bool fBIOSInterruptMode : 1;
227 bool fFlopticalSupport : 1;
228 uint16_t u16DeviceEnabledMask;
229 uint16_t u16WidePermittedMask;
230 uint16_t u16FastPermittedMask;
231 uint16_t u16SynchronousPermittedMask;
232 uint16_t u16DisconnectPermittedMask;
233 uint16_t u16SendStartUnitCommandMask;
234 uint16_t u16IgnoreInBIOSScanMask;
235 unsigned char uPCIInterruptPin : 2;
236 unsigned char uHostAdapterIoPortAddress : 2;
237 bool fStrictRoundRobinMode : 1;
238 bool fVesaBusSpeedGreaterThan33MHz : 1;
239 bool fVesaBurstWrite : 1;
240 bool fVesaBurstRead : 1;
241 uint16_t u16UltraPermittedMask;
242 uint32_t uReserved5;
243 uint8_t uReserved6;
244 uint8_t uAutoSCSIMaximumLUN;
245 bool fReserved7 : 1;
246 bool fSCAMDominant : 1;
247 bool fSCAMenabled : 1;
248 bool fSCAMLevel2 : 1;
249 unsigned char uReserved8 : 4;
250 bool fInt13Extension : 1;
251 bool fReserved9 : 1;
252 bool fCDROMBoot : 1;
253 unsigned char uReserved10 : 5;
254 unsigned char uBootTargetId : 4;
255 unsigned char uBootChannel : 4;
256 bool fForceBusDeviceScanningOrder : 1;
257 unsigned char uReserved11 : 7;
258 uint16_t u16NonTaggedToAlternateLunPermittedMask;
259 uint16_t u16RenegotiateSyncAfterCheckConditionMask;
260 uint8_t aReserved12[10];
261 uint8_t aManufacturingDiagnostic[2];
262 uint16_t u16Checksum;
263} AutoSCSIRam, *PAutoSCSIRam;
264AssertCompileSize(AutoSCSIRam, 64);
265#pragma pack()
266
267/**
268 * The local Ram.
269 */
270typedef union HostAdapterLocalRam
271{
272 /** Byte view. */
273 uint8_t u8View[256];
274 /** Structured view. */
275 struct
276 {
277 /** Offset 0 - 63 is for BIOS. */
278 uint8_t u8Bios[64];
279 /** Auto SCSI structure. */
280 AutoSCSIRam autoSCSIData;
281 } structured;
282} HostAdapterLocalRam, *PHostAdapterLocalRam;
283AssertCompileSize(HostAdapterLocalRam, 256);
284
285
286/** Ugly 24-bit big-endian addressing. */
287typedef struct
288{
289 uint8_t hi;
290 uint8_t mid;
291 uint8_t lo;
292} Addr24, Len24;
293AssertCompileSize(Addr24, 3);
294
295#define ADDR_TO_U32(x) (((x).hi << 16) | ((x).mid << 8) | (x).lo)
296#define LEN_TO_U32 ADDR_TO_U32
297#define U32_TO_ADDR(a, x) do {(a).hi = (x) >> 16; (a).mid = (x) >> 8; (a).lo = (x);} while(0)
298#define U32_TO_LEN U32_TO_ADDR
299
300/** @name Compatible ISA base I/O port addresses. Disabled if zero.
301 * @{ */
302#define NUM_ISA_BASES 8
303#define MAX_ISA_BASE (NUM_ISA_BASES - 1)
304#define ISA_BASE_DISABLED 6
305
306static uint16_t const g_aISABases[NUM_ISA_BASES] =
307{
308 0x330, 0x334, 0x230, 0x234, 0x130, 0x134, 0, 0
309};
310/** @} */
311
312/** Pointer to a task state structure. */
313typedef struct BUSLOGICTASKSTATE *PBUSLOGICTASKSTATE;
314
315/**
316 * Main BusLogic device state.
317 *
318 * @extends PCIDEVICE
319 * @implements PDMILEDPORTS
320 */
321typedef struct BUSLOGIC
322{
323 /** The PCI device structure. */
324 PCIDEVICE dev;
325 /** Pointer to the device instance - HC ptr */
326 PPDMDEVINSR3 pDevInsR3;
327 /** Pointer to the device instance - R0 ptr */
328 PPDMDEVINSR0 pDevInsR0;
329 /** Pointer to the device instance - RC ptr. */
330 PPDMDEVINSRC pDevInsRC;
331
332 /** Whether R0 is enabled. */
333 bool fR0Enabled;
334 /** Whether RC is enabled. */
335 bool fGCEnabled;
336
337 /** Base address of the I/O ports. */
338 RTIOPORT IOPortBase;
339 /** Base address of the memory mapping. */
340 RTGCPHYS MMIOBase;
341 /** Status register - Readonly. */
342 volatile uint8_t regStatus;
343 /** Interrupt register - Readonly. */
344 volatile uint8_t regInterrupt;
345 /** Geometry register - Readonly. */
346 volatile uint8_t regGeometry;
347 /** Pending (delayed) interrupt. */
348 uint8_t uPendingIntr;
349
350 /** Local RAM for the fetch hostadapter local RAM request.
351 * I don't know how big the buffer really is but the maximum
352 * seems to be 256 bytes because the offset and count field in the command request
353 * are only one byte big.
354 */
355 HostAdapterLocalRam LocalRam;
356
357 /** Command code the guest issued. */
358 uint8_t uOperationCode;
359 /** Buffer for the command parameters the adapter is currently receiving from the guest.
360 * Size of the largest command which is possible.
361 */
362 uint8_t aCommandBuffer[BUSLOGIC_COMMAND_SIZE_MAX]; /* Size of the biggest request. */
363 /** Current position in the command buffer. */
364 uint8_t iParameter;
365 /** Parameters left until the command is complete. */
366 uint8_t cbCommandParametersLeft;
367
368 /** Whether we are using the RAM or reply buffer. */
369 bool fUseLocalRam;
370 /** Buffer to store reply data from the controller to the guest. */
371 uint8_t aReplyBuffer[BUSLOGIC_REPLY_SIZE_MAX]; /* Size of the biggest reply. */
372 /** Position in the buffer we are reading next. */
373 uint8_t iReply;
374 /** Bytes left until the reply buffer is empty. */
375 uint8_t cbReplyParametersLeft;
376
377 /** Flag whether IRQs are enabled. */
378 bool fIRQEnabled;
379 /** Flag whether the ISA I/O port range is disabled
380 * to prevent the BIOS to access the device. */
381 bool fISAEnabled; /**< @todo unused, to be removed */
382 /** Flag whether 24-bit mailboxes are in use (default is 32-bit). */
383 bool fMbxIs24Bit;
384 /** ISA I/O port base (encoded in FW-compatible format). */
385 uint8_t uISABaseCode;
386
387 /** ISA I/O port base (disabled if zero). */
388 RTIOPORT IOISABase;
389 /** Default ISA I/O port base in FW-compatible format. */
390 uint8_t uDefaultISABaseCode;
391
392 /** Number of mailboxes the guest set up. */
393 uint32_t cMailbox;
394
395#if HC_ARCH_BITS == 64
396 uint32_t Alignment0;
397#endif
398
399 /** Time when HBA reset was last initiated. */ /**< @todo does this need to be saved? */
400 uint64_t u64ResetTime;
401 /** Physical base address of the outgoing mailboxes. */
402 RTGCPHYS GCPhysAddrMailboxOutgoingBase;
403 /** Current outgoing mailbox position. */
404 uint32_t uMailboxOutgoingPositionCurrent;
405 /** Number of mailboxes ready. */
406 volatile uint32_t cMailboxesReady;
407 /** Whether a notification to R3 was sent. */
408 volatile bool fNotificationSent;
409
410#if HC_ARCH_BITS == 64
411 uint32_t Alignment1;
412#endif
413
414 /** Physical base address of the incoming mailboxes. */
415 RTGCPHYS GCPhysAddrMailboxIncomingBase;
416 /** Current incoming mailbox position. */
417 uint32_t uMailboxIncomingPositionCurrent;
418
419 /** Whether strict round robin is enabled. */
420 bool fStrictRoundRobinMode;
421 /** Whether the extended LUN CCB format is enabled for 32 possible logical units. */
422 bool fExtendedLunCCBFormat;
423
424 /** Queue to send tasks to R3. - HC ptr */
425 R3PTRTYPE(PPDMQUEUE) pNotifierQueueR3;
426 /** Queue to send tasks to R3. - HC ptr */
427 R0PTRTYPE(PPDMQUEUE) pNotifierQueueR0;
428 /** Queue to send tasks to R3. - RC ptr */
429 RCPTRTYPE(PPDMQUEUE) pNotifierQueueRC;
430
431 uint32_t Alignment2;
432
433 /** Critical section protecting access to the interrupt status register. */
434 PDMCRITSECT CritSectIntr;
435
436 /** Cache for task states. */
437 R3PTRTYPE(RTMEMCACHE) hTaskCache;
438
439 /** Device state for BIOS access. */
440 VBOXSCSI VBoxSCSI;
441
442 /** BusLogic device states. */
443 BUSLOGICDEVICE aDeviceStates[BUSLOGIC_MAX_DEVICES];
444
445 /** The base interface.
446 * @todo use PDMDEVINS::IBase */
447 PDMIBASE IBase;
448 /** Status Port - Leds interface. */
449 PDMILEDPORTS ILeds;
450 /** Partner of ILeds. */
451 R3PTRTYPE(PPDMILEDCONNECTORS) pLedsConnector;
452
453#if HC_ARCH_BITS == 64
454 uint32_t Alignment3;
455#endif
456
457 /** Indicates that PDMDevHlpAsyncNotificationCompleted should be called when
458 * a port is entering the idle state. */
459 bool volatile fSignalIdle;
460 /** Flag whether we have tasks which need to be processed again. */
461 bool volatile fRedo;
462 /** Flag whether the worker thread is sleeping. */
463 volatile bool fWrkThreadSleeping;
464 /** Flag whether a request from the BIOS is pending which the
465 * worker thread needs to process. */
466 volatile bool fBiosReqPending;
467 /** List of tasks which can be redone. */
468 R3PTRTYPE(volatile PBUSLOGICTASKSTATE) pTasksRedoHead;
469
470 /** The support driver session handle. */
471 R3R0PTRTYPE(PSUPDRVSESSION) pSupDrvSession;
472 /** Worker thread. */
473 R3PTRTYPE(PPDMTHREAD) pThreadWrk;
474 /** The event semaphore the processing thread waits on. */
475 SUPSEMEVENT hEvtProcess;
476
477#ifdef LOG_ENABLED
478# if HC_ARCH_BITS == 64
479 uint32_t Alignment4;
480# endif
481
482 volatile uint32_t cInMailboxesReady;
483#endif
484
485} BUSLOGIC, *PBUSLOGIC;
486
487/** Register offsets in the I/O port space. */
488#define BUSLOGIC_REGISTER_CONTROL 0 /**< Writeonly */
489/** Fields for the control register. */
490# define BL_CTRL_RSBUS RT_BIT(4) /* Reset SCSI Bus. */
491# define BL_CTRL_RINT RT_BIT(5) /* Reset Interrupt. */
492# define BL_CTRL_RSOFT RT_BIT(6) /* Soft Reset. */
493# define BL_CTRL_RHARD RT_BIT(7) /* Hard Reset. */
494
495#define BUSLOGIC_REGISTER_STATUS 0 /**< Readonly */
496/** Fields for the status register. */
497# define BL_STAT_CMDINV RT_BIT(0) /* Command Invalid. */
498# define BL_STAT_DIRRDY RT_BIT(2) /* Data In Register Ready. */
499# define BL_STAT_CPRBSY RT_BIT(3) /* Command/Parameter Out Register Busy. */
500# define BL_STAT_HARDY RT_BIT(4) /* Host Adapter Ready. */
501# define BL_STAT_INREQ RT_BIT(5) /* Initialization Required. */
502# define BL_STAT_DFAIL RT_BIT(6) /* Diagnostic Failure. */
503# define BL_STAT_DACT RT_BIT(7) /* Diagnistic Active. */
504
505#define BUSLOGIC_REGISTER_COMMAND 1 /**< Writeonly */
506#define BUSLOGIC_REGISTER_DATAIN 1 /**< Readonly */
507#define BUSLOGIC_REGISTER_INTERRUPT 2 /**< Readonly */
508/** Fields for the interrupt register. */
509# define BL_INTR_IMBL RT_BIT(0) /* Incoming Mailbox Loaded. */
510# define BL_INTR_OMBR RT_BIT(1) /* Outgoing Mailbox Available. */
511# define BL_INTR_CMDC RT_BIT(2) /* Command Complete. */
512# define BL_INTR_RSTS RT_BIT(3) /* SCSI Bus Reset State. */
513# define BL_INTR_INTV RT_BIT(7) /* Interrupt Valid. */
514
515#define BUSLOGIC_REGISTER_GEOMETRY 3 /* Readonly */
516# define BL_GEOM_XLATEN RT_BIT(7) /* Extended geometry translation enabled. */
517
518/** Structure for the INQUIRE_PCI_HOST_ADAPTER_INFORMATION reply. */
519typedef struct ReplyInquirePCIHostAdapterInformation
520{
521 uint8_t IsaIOPort;
522 uint8_t IRQ;
523 unsigned char LowByteTerminated : 1;
524 unsigned char HighByteTerminated : 1;
525 unsigned char uReserved : 2; /* Reserved. */
526 unsigned char JP1 : 1; /* Whatever that means. */
527 unsigned char JP2 : 1; /* Whatever that means. */
528 unsigned char JP3 : 1; /* Whatever that means. */
529 /** Whether the provided info is valid. */
530 unsigned char InformationIsValid: 1;
531 uint8_t uReserved2; /* Reserved. */
532} ReplyInquirePCIHostAdapterInformation, *PReplyInquirePCIHostAdapterInformation;
533AssertCompileSize(ReplyInquirePCIHostAdapterInformation, 4);
534
535/** Structure for the INQUIRE_CONFIGURATION reply. */
536typedef struct ReplyInquireConfiguration
537{
538 unsigned char uReserved1 : 5;
539 bool fDmaChannel5 : 1;
540 bool fDmaChannel6 : 1;
541 bool fDmaChannel7 : 1;
542 bool fIrqChannel9 : 1;
543 bool fIrqChannel10 : 1;
544 bool fIrqChannel11 : 1;
545 bool fIrqChannel12 : 1;
546 unsigned char uReserved2 : 1;
547 bool fIrqChannel14 : 1;
548 bool fIrqChannel15 : 1;
549 unsigned char uReserved3 : 1;
550 unsigned char uHostAdapterId : 4;
551 unsigned char uReserved4 : 4;
552} ReplyInquireConfiguration, *PReplyInquireConfiguration;
553AssertCompileSize(ReplyInquireConfiguration, 3);
554
555/** Structure for the INQUIRE_SETUP_INFORMATION reply. */
556typedef struct ReplyInquireSetupInformationSynchronousValue
557{
558 unsigned char uOffset : 4;
559 unsigned char uTransferPeriod : 3;
560 bool fSynchronous : 1;
561}ReplyInquireSetupInformationSynchronousValue, *PReplyInquireSetupInformationSynchronousValue;
562AssertCompileSize(ReplyInquireSetupInformationSynchronousValue, 1);
563
564typedef struct ReplyInquireSetupInformation
565{
566 bool fSynchronousInitiationEnabled : 1;
567 bool fParityCheckingEnabled : 1;
568 unsigned char uReserved1 : 6;
569 uint8_t uBusTransferRate;
570 uint8_t uPreemptTimeOnBus;
571 uint8_t uTimeOffBus;
572 uint8_t cMailbox;
573 Addr24 MailboxAddress;
574 ReplyInquireSetupInformationSynchronousValue SynchronousValuesId0To7[8];
575 uint8_t uDisconnectPermittedId0To7;
576 uint8_t uSignature;
577 uint8_t uCharacterD;
578 uint8_t uHostBusType;
579 uint8_t uWideTransferPermittedId0To7;
580 uint8_t uWideTransfersActiveId0To7;
581 ReplyInquireSetupInformationSynchronousValue SynchronousValuesId8To15[8];
582 uint8_t uDisconnectPermittedId8To15;
583 uint8_t uReserved2;
584 uint8_t uWideTransferPermittedId8To15;
585 uint8_t uWideTransfersActiveId8To15;
586} ReplyInquireSetupInformation, *PReplyInquireSetupInformation;
587AssertCompileSize(ReplyInquireSetupInformation, 34);
588
589/** Structure for the INQUIRE_EXTENDED_SETUP_INFORMATION. */
590#pragma pack(1)
591typedef struct ReplyInquireExtendedSetupInformation
592{
593 uint8_t uBusType;
594 uint8_t uBiosAddress;
595 uint16_t u16ScatterGatherLimit;
596 uint8_t cMailbox;
597 uint32_t uMailboxAddressBase;
598 unsigned char uReserved1 : 2;
599 bool fFastEISA : 1;
600 unsigned char uReserved2 : 3;
601 bool fLevelSensitiveInterrupt : 1;
602 unsigned char uReserved3 : 1;
603 unsigned char aFirmwareRevision[3];
604 bool fHostWideSCSI : 1;
605 bool fHostDifferentialSCSI : 1;
606 bool fHostSupportsSCAM : 1;
607 bool fHostUltraSCSI : 1;
608 bool fHostSmartTermination : 1;
609 unsigned char uReserved4 : 3;
610} ReplyInquireExtendedSetupInformation, *PReplyInquireExtendedSetupInformation;
611AssertCompileSize(ReplyInquireExtendedSetupInformation, 14);
612#pragma pack()
613
614/** Structure for the INITIALIZE EXTENDED MAILBOX request. */
615#pragma pack(1)
616typedef struct RequestInitializeExtendedMailbox
617{
618 /** Number of mailboxes in guest memory. */
619 uint8_t cMailbox;
620 /** Physical address of the first mailbox. */
621 uint32_t uMailboxBaseAddress;
622} RequestInitializeExtendedMailbox, *PRequestInitializeExtendedMailbox;
623AssertCompileSize(RequestInitializeExtendedMailbox, 5);
624#pragma pack()
625
626/** Structure for the INITIALIZE MAILBOX request. */
627typedef struct
628{
629 /** Number of mailboxes to set up. */
630 uint8_t cMailbox;
631 /** Physical address of the first mailbox. */
632 Addr24 aMailboxBaseAddr;
633} RequestInitMbx, *PRequestInitMbx;
634AssertCompileSize(RequestInitMbx, 4);
635
636/**
637 * Structure of a mailbox in guest memory.
638 * The incoming and outgoing mailbox have the same size
639 * but the incoming one has some more fields defined which
640 * are marked as reserved in the outgoing one.
641 * The last field is also different from the type.
642 * For outgoing mailboxes it is the action and
643 * for incoming ones the completion status code for the task.
644 * We use one structure for both types.
645 */
646typedef struct Mailbox32
647{
648 /** Physical address of the CCB structure in the guest memory. */
649 uint32_t u32PhysAddrCCB;
650 /** Type specific data. */
651 union
652 {
653 /** For outgoing mailboxes. */
654 struct
655 {
656 /** Reserved */
657 uint8_t uReserved[3];
658 /** Action code. */
659 uint8_t uActionCode;
660 } out;
661 /** For incoming mailboxes. */
662 struct
663 {
664 /** The host adapter status after finishing the request. */
665 uint8_t uHostAdapterStatus;
666 /** The status of the device which executed the request after executing it. */
667 uint8_t uTargetDeviceStatus;
668 /** Reserved. */
669 uint8_t uReserved;
670 /** The completion status code of the request. */
671 uint8_t uCompletionCode;
672 } in;
673 } u;
674} Mailbox32, *PMailbox32;
675AssertCompileSize(Mailbox32, 8);
676
677/** Old style 24-bit mailbox entry. */
678typedef struct Mailbox24
679{
680 /** Mailbox command (incoming) or state (outgoing). */
681 uint8_t uCmdState;
682 /** Physical address of the CCB structure in the guest memory. */
683 Addr24 aPhysAddrCCB;
684} Mailbox24, *PMailbox24;
685AssertCompileSize(Mailbox24, 4);
686
687/**
688 * Action codes for outgoing mailboxes.
689 */
690enum BUSLOGIC_MAILBOX_OUTGOING_ACTION
691{
692 BUSLOGIC_MAILBOX_OUTGOING_ACTION_FREE = 0x00,
693 BUSLOGIC_MAILBOX_OUTGOING_ACTION_START_COMMAND = 0x01,
694 BUSLOGIC_MAILBOX_OUTGOING_ACTION_ABORT_COMMAND = 0x02
695};
696
697/**
698 * Completion codes for incoming mailboxes.
699 */
700enum BUSLOGIC_MAILBOX_INCOMING_COMPLETION
701{
702 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_FREE = 0x00,
703 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITHOUT_ERROR = 0x01,
704 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_ABORTED = 0x02,
705 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_ABORTED_NOT_FOUND = 0x03,
706 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITH_ERROR = 0x04,
707 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_INVALID_CCB = 0x05
708};
709
710/**
711 * Host adapter status for incoming mailboxes.
712 */
713enum BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS
714{
715 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_CMD_COMPLETED = 0x00,
716 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_LINKED_CMD_COMPLETED = 0x0a,
717 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_LINKED_CMD_COMPLETED_WITH_FLAG = 0x0b,
718 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_DATA_UNDERUN = 0x0c,
719 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_SCSI_SELECTION_TIMEOUT = 0x11,
720 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_DATA_OVERRUN = 0x12,
721 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_UNEXPECTED_BUS_FREE = 0x13,
722 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_INVALID_BUS_PHASE_REQUESTED = 0x14,
723 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_INVALID_OUTGOING_MAILBOX_ACTION_CODE = 0x15,
724 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_INVALID_COMMAND_OPERATION_CODE = 0x16,
725 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_LINKED_CCB_HAS_INVALID_LUN = 0x17,
726 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_INVALID_COMMAND_PARAMETER = 0x1a,
727 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_AUTO_REQUEST_SENSE_FAILED = 0x1b,
728 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_TAGGED_QUEUING_MESSAGE_REJECTED = 0x1c,
729 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_UNSUPPORTED_MESSAGE_RECEIVED = 0x1d,
730 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_HOST_ADAPTER_HARDWARE_FAILED = 0x20,
731 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_TARGET_FAILED_RESPONSE_TO_ATN = 0x21,
732 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_HOST_ADAPTER_ASSERTED_RST = 0x22,
733 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_OTHER_DEVICE_ASSERTED_RST = 0x23,
734 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_TARGET_DEVICE_RECONNECTED_IMPROPERLY = 0x24,
735 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_HOST_ADAPTER_ASSERTED_BUS_DEVICE_RESET = 0x25,
736 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_ABORT_QUEUE_GENERATED = 0x26,
737 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_HOST_ADAPTER_SOFTWARE_ERROR = 0x27,
738 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_HOST_ADAPTER_HARDWARE_TIMEOUT_ERROR = 0x30,
739 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_SCSI_PARITY_ERROR_DETECTED = 0x34
740};
741
742/**
743 * Device status codes for incoming mailboxes.
744 */
745enum BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS
746{
747 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD = 0x00,
748 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_CHECK_CONDITION = 0x02,
749 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_DEVICE_BUSY = 0x08
750};
751
752/**
753 * Opcode types for CCB.
754 */
755enum BUSLOGIC_CCB_OPCODE
756{
757 BUSLOGIC_CCB_OPCODE_INITIATOR_CCB = 0x00,
758 BUSLOGIC_CCB_OPCODE_TARGET_CCB = 0x01,
759 BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_SCATTER_GATHER = 0x02,
760 BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_RESIDUAL_DATA_LENGTH = 0x03,
761 BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_RESIDUAL_SCATTER_GATHER = 0x04,
762 BUSLOGIC_CCB_OPCODE_BUS_DEVICE_RESET = 0x81
763};
764
765/**
766 * Data transfer direction.
767 */
768enum BUSLOGIC_CCB_DIRECTION
769{
770 BUSLOGIC_CCB_DIRECTION_UNKNOWN = 0x00,
771 BUSLOGIC_CCB_DIRECTION_IN = 0x01,
772 BUSLOGIC_CCB_DIRECTION_OUT = 0x02,
773 BUSLOGIC_CCB_DIRECTION_NO_DATA = 0x03
774};
775
776/**
777 * The command control block for a SCSI request.
778 */
779typedef struct CCB32
780{
781 /** Opcode. */
782 uint8_t uOpcode;
783 /** Reserved */
784 unsigned char uReserved1 : 3;
785 /** Data direction for the request. */
786 unsigned char uDataDirection : 2;
787 /** Whether the request is tag queued. */
788 bool fTagQueued : 1;
789 /** Queue tag mode. */
790 unsigned char uQueueTag : 2;
791 /** Length of the SCSI CDB. */
792 uint8_t cbCDB;
793 /** Sense data length. */
794 uint8_t cbSenseData;
795 /** Data length. */
796 uint32_t cbData;
797 /** Data pointer.
798 * This points to the data region or a scatter gather list based on the opcode.
799 */
800 uint32_t u32PhysAddrData;
801 /** Reserved. */
802 uint8_t uReserved2[2];
803 /** Host adapter status. */
804 uint8_t uHostAdapterStatus;
805 /** Device adapter status. */
806 uint8_t uDeviceStatus;
807 /** The device the request is sent to. */
808 uint8_t uTargetId;
809 /**The LUN in the device. */
810 unsigned char uLogicalUnit : 5;
811 /** Legacy tag. */
812 bool fLegacyTagEnable : 1;
813 /** Legacy queue tag. */
814 unsigned char uLegacyQueueTag : 2;
815 /** The SCSI CDB. (A CDB can be 12 bytes long.) */
816 uint8_t abCDB[12];
817 /** Reserved. */
818 uint8_t uReserved3[6];
819 /** Sense data pointer. */
820 uint32_t u32PhysAddrSenseData;
821} CCB32, *PCCB32;
822AssertCompileSize(CCB32, 40);
823
824
825/**
826 * The 24-bit command control block.
827 */
828typedef struct CCB24
829{
830 /** Opcode. */
831 uint8_t uOpcode;
832 /** The LUN in the device. */
833 unsigned char uLogicalUnit : 3;
834 /** Data direction for the request. */
835 unsigned char uDataDirection : 2;
836 /** The target device ID. */
837 unsigned char uTargetId : 3;
838 /** Length of the SCSI CDB. */
839 uint8_t cbCDB;
840 /** Sense data length. */
841 uint8_t cbSenseData;
842 /** Data length. */
843 Len24 acbData;
844 /** Data pointer.
845 * This points to the data region or a scatter gather list based on the opc
846 */
847 Addr24 aPhysAddrData;
848 /** Pointer to next CCB for linked commands. */
849 Addr24 aPhysAddrLink;
850 /** Command linking identifier. */
851 uint8_t uLinkId;
852 /** Host adapter status. */
853 uint8_t uHostAdapterStatus;
854 /** Device adapter status. */
855 uint8_t uDeviceStatus;
856 /** Two unused bytes. */
857 uint8_t aReserved[2];
858 /** The SCSI CDB. (A CDB can be 12 bytes long.) */
859 uint8_t abCDB[12];
860} CCB24, *PCCB24;
861AssertCompileSize(CCB24, 30);
862
863/**
864 * The common 24-bit/32-bit command control block. The 32-bit CCB is laid out
865 * such that many fields are in the same location as in the older 24-bit CCB.
866 */
867typedef struct CCBC
868{
869 /** Opcode. */
870 uint8_t uOpcode;
871 /** The LUN in the device. */
872 unsigned char uPad1 : 3;
873 /** Data direction for the request. */
874 unsigned char uDataDirection : 2;
875 /** The target device ID. */
876 unsigned char uPad2 : 3;
877 /** Length of the SCSI CDB. */
878 uint8_t cbCDB;
879 /** Sense data length. */
880 uint8_t cbSenseData;
881 uint8_t aPad1[10];
882 /** Host adapter status. */
883 uint8_t uHostAdapterStatus;
884 /** Device adapter status. */
885 uint8_t uDeviceStatus;
886 uint8_t aPad2[2];
887 /** The SCSI CDB (up to 12 bytes). */
888 uint8_t abCDB[12];
889} CCBC, *PCCBC;
890AssertCompileSize(CCBC, 30);
891
892/* Make sure that the 24-bit/32-bit/common CCB offsets match. */
893AssertCompileMemberOffset(CCBC, cbCDB, 2);
894AssertCompileMemberOffset(CCB24, cbCDB, 2);
895AssertCompileMemberOffset(CCB32, cbCDB, 2);
896AssertCompileMemberOffset(CCBC, uHostAdapterStatus, 14);
897AssertCompileMemberOffset(CCB24, uHostAdapterStatus, 14);
898AssertCompileMemberOffset(CCB32, uHostAdapterStatus, 14);
899AssertCompileMemberOffset(CCBC, abCDB, 18);
900AssertCompileMemberOffset(CCB24, abCDB, 18);
901AssertCompileMemberOffset(CCB32, abCDB, 18);
902
903/** A union of all CCB types (24-bit/32-bit/common). */
904typedef union CCBU
905{
906 CCB32 n; /**< New 32-bit CCB. */
907 CCB24 o; /**< Old 24-bit CCB. */
908 CCBC c; /**< Common CCB subset. */
909} CCBU, *PCCBU;
910
911/** 32-bit scatter-gather list entry. */
912typedef struct SGE32
913{
914 uint32_t cbSegment;
915 uint32_t u32PhysAddrSegmentBase;
916} SGE32, *PSGE32;
917AssertCompileSize(SGE32, 8);
918
919/** 24-bit scatter-gather list entry. */
920typedef struct SGE24
921{
922 Len24 acbSegment;
923 Addr24 aPhysAddrSegmentBase;
924} SGE24, *PSGE24;
925AssertCompileSize(SGE24, 6);
926
927/**
928 * The structure for the "Execute SCSI Command" command.
929 */
930typedef struct ESCMD
931{
932 /** Data length. */
933 uint32_t cbData;
934 /** Data pointer. */
935 uint32_t u32PhysAddrData;
936 /** The device the request is sent to. */
937 uint8_t uTargetId;
938 /** The LUN in the device. */
939 uint8_t uLogicalUnit;
940 /** Reserved */
941 unsigned char uReserved1 : 3;
942 /** Data direction for the request. */
943 unsigned char uDataDirection : 2;
944 /** Reserved */
945 unsigned char uReserved2 : 3;
946 /** Length of the SCSI CDB. */
947 uint8_t cbCDB;
948 /** The SCSI CDB. (A CDB can be 12 bytes long.) */
949 uint8_t abCDB[12];
950} ESCMD, *PESCMD;
951AssertCompileSize(ESCMD, 24);
952
953/**
954 * Task state for a CCB request.
955 */
956typedef struct BUSLOGICTASKSTATE
957{
958 /** Next in the redo list. */
959 PBUSLOGICTASKSTATE pRedoNext;
960 /** Device this task is assigned to. */
961 R3PTRTYPE(PBUSLOGICDEVICE) pTargetDeviceR3;
962 /** The command control block from the guest. */
963 CCBU CommandControlBlockGuest;
964 /** Mailbox read from guest memory. */
965 Mailbox32 MailboxGuest;
966 /** The SCSI request we pass to the underlying SCSI engine. */
967 PDMSCSIREQUEST PDMScsiRequest;
968 /** Data buffer segment */
969 RTSGSEG DataSeg;
970 /** Pointer to the R3 sense buffer. */
971 uint8_t *pbSenseBuffer;
972 /** Flag whether this is a request from the BIOS. */
973 bool fBIOS;
974 /** 24-bit request flag (default is 32-bit). */
975 bool fIs24Bit;
976 /** S/G entry size (depends on the above flag). */
977 uint8_t cbSGEntry;
978} BUSLOGICTASKSTATE;
979
980#ifndef VBOX_DEVICE_STRUCT_TESTCASE
981
982#define PDMIBASE_2_PBUSLOGICDEVICE(pInterface) ( (PBUSLOGICDEVICE)((uintptr_t)(pInterface) - RT_OFFSETOF(BUSLOGICDEVICE, IBase)) )
983#define PDMISCSIPORT_2_PBUSLOGICDEVICE(pInterface) ( (PBUSLOGICDEVICE)((uintptr_t)(pInterface) - RT_OFFSETOF(BUSLOGICDEVICE, ISCSIPort)) )
984#define PDMILEDPORTS_2_PBUSLOGICDEVICE(pInterface) ( (PBUSLOGICDEVICE)((uintptr_t)(pInterface) - RT_OFFSETOF(BUSLOGICDEVICE, ILed)) )
985#define PDMIBASE_2_PBUSLOGIC(pInterface) ( (PBUSLOGIC)((uintptr_t)(pInterface) - RT_OFFSETOF(BUSLOGIC, IBase)) )
986#define PDMILEDPORTS_2_PBUSLOGIC(pInterface) ( (PBUSLOGIC)((uintptr_t)(pInterface) - RT_OFFSETOF(BUSLOGIC, ILeds)) )
987
988
989/*********************************************************************************************************************************
990* Internal Functions *
991*********************************************************************************************************************************/
992static int buslogicR3RegisterISARange(PBUSLOGIC pBusLogic, uint8_t uBaseCode);
993
994
995/**
996 * Assert IRQ line of the BusLogic adapter.
997 *
998 * @returns nothing.
999 * @param pBusLogic Pointer to the BusLogic device instance.
1000 * @param fSuppressIrq Flag to suppress IRQ generation regardless of fIRQEnabled
1001 * @param uFlag Type of interrupt being generated.
1002 */
1003static void buslogicSetInterrupt(PBUSLOGIC pBusLogic, bool fSuppressIrq, uint8_t uIrqType)
1004{
1005 LogFlowFunc(("pBusLogic=%#p\n", pBusLogic));
1006
1007 /* The CMDC interrupt has priority over IMBL and OMBR. */
1008 if (uIrqType & (BL_INTR_IMBL | BL_INTR_OMBR))
1009 {
1010 if (!(pBusLogic->regInterrupt & BL_INTR_CMDC))
1011 pBusLogic->regInterrupt |= uIrqType; /* Report now. */
1012 else
1013 pBusLogic->uPendingIntr |= uIrqType; /* Report later. */
1014 }
1015 else if (uIrqType & BL_INTR_CMDC)
1016 {
1017 AssertMsg(pBusLogic->regInterrupt == 0 || pBusLogic->regInterrupt == (BL_INTR_INTV | BL_INTR_CMDC),
1018 ("regInterrupt=%02X\n", pBusLogic->regInterrupt));
1019 pBusLogic->regInterrupt |= uIrqType;
1020 }
1021 else
1022 AssertMsgFailed(("Invalid interrupt state!\n"));
1023
1024 pBusLogic->regInterrupt |= BL_INTR_INTV;
1025 if (pBusLogic->fIRQEnabled && !fSuppressIrq)
1026 PDMDevHlpPCISetIrq(pBusLogic->CTX_SUFF(pDevIns), 0, 1);
1027}
1028
1029/**
1030 * Deasserts the interrupt line of the BusLogic adapter.
1031 *
1032 * @returns nothing
1033 * @param pBuslogic Pointer to the BusLogic device instance.
1034 */
1035static void buslogicClearInterrupt(PBUSLOGIC pBusLogic)
1036{
1037 LogFlowFunc(("pBusLogic=%#p, clearing %#02x (pending %#02x)\n",
1038 pBusLogic, pBusLogic->regInterrupt, pBusLogic->uPendingIntr));
1039 pBusLogic->regInterrupt = 0;
1040 PDMDevHlpPCISetIrq(pBusLogic->CTX_SUFF(pDevIns), 0, 0);
1041 /* If there's another pending interrupt, report it now. */
1042 if (pBusLogic->uPendingIntr)
1043 {
1044 buslogicSetInterrupt(pBusLogic, false, pBusLogic->uPendingIntr);
1045 pBusLogic->uPendingIntr = 0;
1046 }
1047}
1048
1049#if defined(IN_RING3)
1050
1051/**
1052 * Advances the mailbox pointer to the next slot.
1053 */
1054DECLINLINE(void) buslogicR3OutgoingMailboxAdvance(PBUSLOGIC pBusLogic)
1055{
1056 pBusLogic->uMailboxOutgoingPositionCurrent = (pBusLogic->uMailboxOutgoingPositionCurrent + 1) % pBusLogic->cMailbox;
1057}
1058
1059/**
1060 * Initialize local RAM of host adapter with default values.
1061 *
1062 * @returns nothing.
1063 * @param pBusLogic.
1064 */
1065static void buslogicR3InitializeLocalRam(PBUSLOGIC pBusLogic)
1066{
1067 /*
1068 * These values are mostly from what I think is right
1069 * looking at the dmesg output from a Linux guest inside
1070 * a VMware server VM.
1071 *
1072 * So they don't have to be right :)
1073 */
1074 memset(pBusLogic->LocalRam.u8View, 0, sizeof(HostAdapterLocalRam));
1075 pBusLogic->LocalRam.structured.autoSCSIData.fLevelSensitiveInterrupt = true;
1076 pBusLogic->LocalRam.structured.autoSCSIData.fParityCheckingEnabled = true;
1077 pBusLogic->LocalRam.structured.autoSCSIData.fExtendedTranslation = true; /* Same as in geometry register. */
1078 pBusLogic->LocalRam.structured.autoSCSIData.u16DeviceEnabledMask = ~0; /* All enabled. Maybe mask out non present devices? */
1079 pBusLogic->LocalRam.structured.autoSCSIData.u16WidePermittedMask = ~0;
1080 pBusLogic->LocalRam.structured.autoSCSIData.u16FastPermittedMask = ~0;
1081 pBusLogic->LocalRam.structured.autoSCSIData.u16SynchronousPermittedMask = ~0;
1082 pBusLogic->LocalRam.structured.autoSCSIData.u16DisconnectPermittedMask = ~0;
1083 pBusLogic->LocalRam.structured.autoSCSIData.fStrictRoundRobinMode = pBusLogic->fStrictRoundRobinMode;
1084 pBusLogic->LocalRam.structured.autoSCSIData.u16UltraPermittedMask = ~0;
1085 /** @todo calculate checksum? */
1086}
1087
1088/**
1089 * Do a hardware reset of the buslogic adapter.
1090 *
1091 * @returns VBox status code.
1092 * @param pBusLogic Pointer to the BusLogic device instance.
1093 * @param fResetIO Flag determining whether ISA I/O should be reset.
1094 */
1095static int buslogicR3HwReset(PBUSLOGIC pBusLogic, bool fResetIO)
1096{
1097 LogFlowFunc(("pBusLogic=%#p\n", pBusLogic));
1098
1099 /* Reset registers to default values. */
1100 pBusLogic->regStatus = BL_STAT_HARDY | BL_STAT_INREQ;
1101 pBusLogic->regGeometry = BL_GEOM_XLATEN;
1102 pBusLogic->uOperationCode = 0xff; /* No command executing. */
1103 pBusLogic->iParameter = 0;
1104 pBusLogic->cbCommandParametersLeft = 0;
1105 pBusLogic->fIRQEnabled = true;
1106 pBusLogic->fStrictRoundRobinMode = false;
1107 pBusLogic->fExtendedLunCCBFormat = false;
1108 pBusLogic->uMailboxOutgoingPositionCurrent = 0;
1109 pBusLogic->uMailboxIncomingPositionCurrent = 0;
1110
1111 /* Clear any active/pending interrupts. */
1112 pBusLogic->uPendingIntr = 0;
1113 buslogicClearInterrupt(pBusLogic);
1114
1115 /* Guest-initiated HBA reset does not affect ISA port I/O. */
1116 if (fResetIO)
1117 {
1118 buslogicR3RegisterISARange(pBusLogic, pBusLogic->uDefaultISABaseCode);
1119 }
1120 buslogicR3InitializeLocalRam(pBusLogic);
1121 vboxscsiInitialize(&pBusLogic->VBoxSCSI);
1122
1123 return VINF_SUCCESS;
1124}
1125
1126#endif /* IN_RING3 */
1127
1128/**
1129 * Resets the command state machine for the next command and notifies the guest.
1130 *
1131 * @returns nothing.
1132 * @param pBusLogic Pointer to the BusLogic device instance
1133 * @param fSuppressIrq Flag to suppress IRQ generation regardless of current state
1134 */
1135static void buslogicCommandComplete(PBUSLOGIC pBusLogic, bool fSuppressIrq)
1136{
1137 LogFlowFunc(("pBusLogic=%#p\n", pBusLogic));
1138
1139 pBusLogic->fUseLocalRam = false;
1140 pBusLogic->regStatus |= BL_STAT_HARDY;
1141 pBusLogic->iReply = 0;
1142
1143 /* Modify I/O address does not generate an interrupt. */
1144 if (pBusLogic->uOperationCode != BUSLOGICCOMMAND_EXECUTE_MAILBOX_COMMAND)
1145 {
1146 /* Notify that the command is complete. */
1147 pBusLogic->regStatus &= ~BL_STAT_DIRRDY;
1148 buslogicSetInterrupt(pBusLogic, fSuppressIrq, BL_INTR_CMDC);
1149 }
1150
1151 pBusLogic->uOperationCode = 0xff;
1152 pBusLogic->iParameter = 0;
1153}
1154
1155#if defined(IN_RING3)
1156
1157/**
1158 * Initiates a hard reset which was issued from the guest.
1159 *
1160 * @returns nothing
1161 * @param pBusLogic Pointer to the BusLogic device instance.
1162 * @param fHardReset Flag initiating a hard (vs. soft) reset.
1163 */
1164static void buslogicR3InitiateReset(PBUSLOGIC pBusLogic, bool fHardReset)
1165{
1166 LogFlowFunc(("pBusLogic=%#p fHardReset=%d\n", pBusLogic, fHardReset));
1167
1168 buslogicR3HwReset(pBusLogic, false);
1169
1170 if (fHardReset)
1171 {
1172 /* Set the diagnostic active bit in the status register and clear the ready state. */
1173 pBusLogic->regStatus |= BL_STAT_DACT;
1174 pBusLogic->regStatus &= ~BL_STAT_HARDY;
1175
1176 /* Remember when the guest initiated a reset (after we're done resetting). */
1177 pBusLogic->u64ResetTime = PDMDevHlpTMTimeVirtGetNano(pBusLogic->CTX_SUFF(pDevIns));
1178 }
1179}
1180
1181/**
1182 * Send a mailbox with set status codes to the guest.
1183 *
1184 * @returns nothing.
1185 * @param pBusLogic Pointer to the BusLogic device instance.
1186 * @param pTaskState Pointer to the task state with the mailbox to send.
1187 * @param uHostAdapterStatus The host adapter status code to set.
1188 * @param uDeviceStatus The target device status to set.
1189 * @param uMailboxCompletionCode Completion status code to set in the mailbox.
1190 */
1191static void buslogicR3SendIncomingMailbox(PBUSLOGIC pBusLogic, PBUSLOGICTASKSTATE pTaskState,
1192 uint8_t uHostAdapterStatus, uint8_t uDeviceStatus,
1193 uint8_t uMailboxCompletionCode)
1194{
1195 pTaskState->MailboxGuest.u.in.uHostAdapterStatus = uHostAdapterStatus;
1196 pTaskState->MailboxGuest.u.in.uTargetDeviceStatus = uDeviceStatus;
1197 pTaskState->MailboxGuest.u.in.uCompletionCode = uMailboxCompletionCode;
1198
1199 int rc = PDMCritSectEnter(&pBusLogic->CritSectIntr, VINF_SUCCESS);
1200 AssertRC(rc);
1201
1202 RTGCPHYS GCPhysAddrMailboxIncoming = pBusLogic->GCPhysAddrMailboxIncomingBase
1203 + ( pBusLogic->uMailboxIncomingPositionCurrent
1204 * (pTaskState->fIs24Bit ? sizeof(Mailbox24) : sizeof(Mailbox32)) );
1205
1206 if (uMailboxCompletionCode != BUSLOGIC_MAILBOX_INCOMING_COMPLETION_ABORTED_NOT_FOUND)
1207 {
1208 RTGCPHYS GCPhysAddrCCB = pTaskState->MailboxGuest.u32PhysAddrCCB;
1209 LogFlowFunc(("Completing CCB %RGp hstat=%u, dstat=%u, outgoing mailbox at %RGp\n", GCPhysAddrCCB,
1210 uHostAdapterStatus, uDeviceStatus, GCPhysAddrMailboxIncoming));
1211
1212 /* Update CCB. */
1213 pTaskState->CommandControlBlockGuest.c.uHostAdapterStatus = uHostAdapterStatus;
1214 pTaskState->CommandControlBlockGuest.c.uDeviceStatus = uDeviceStatus;
1215 /* Rewrite CCB up to the CDB; perhaps more than necessary. */
1216 PDMDevHlpPCIPhysWrite(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrCCB,
1217 &pTaskState->CommandControlBlockGuest, RT_OFFSETOF(CCBC, abCDB));
1218 }
1219
1220# ifdef RT_STRICT
1221 uint8_t uCode;
1222 unsigned uCodeOffs = pTaskState->fIs24Bit ? RT_OFFSETOF(Mailbox24, uCmdState) : RT_OFFSETOF(Mailbox32, u.out.uActionCode);
1223 PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrMailboxIncoming + uCodeOffs, &uCode, sizeof(uCode));
1224 Assert(uCode == BUSLOGIC_MAILBOX_INCOMING_COMPLETION_FREE);
1225# endif
1226
1227 /* Update mailbox. */
1228 if (pTaskState->fIs24Bit)
1229 {
1230 Mailbox24 Mbx24;
1231
1232 Mbx24.uCmdState = pTaskState->MailboxGuest.u.in.uCompletionCode;
1233 U32_TO_ADDR(Mbx24.aPhysAddrCCB, pTaskState->MailboxGuest.u32PhysAddrCCB);
1234 Log(("24-bit mailbox: completion code=%u, CCB at %RGp\n", Mbx24.uCmdState, (RTGCPHYS)ADDR_TO_U32(Mbx24.aPhysAddrCCB)));
1235 PDMDevHlpPCIPhysWrite(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrMailboxIncoming, &Mbx24, sizeof(Mailbox24));
1236 }
1237 else
1238 {
1239 Log(("32-bit mailbox: completion code=%u, CCB at %RGp\n", pTaskState->MailboxGuest.u.in.uCompletionCode, (RTGCPHYS)pTaskState->MailboxGuest.u32PhysAddrCCB));
1240 PDMDevHlpPCIPhysWrite(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrMailboxIncoming,
1241 &pTaskState->MailboxGuest, sizeof(Mailbox32));
1242 }
1243
1244 /* Advance to next mailbox position. */
1245 pBusLogic->uMailboxIncomingPositionCurrent++;
1246 if (pBusLogic->uMailboxIncomingPositionCurrent >= pBusLogic->cMailbox)
1247 pBusLogic->uMailboxIncomingPositionCurrent = 0;
1248
1249# ifdef LOG_ENABLED
1250 ASMAtomicIncU32(&pBusLogic->cInMailboxesReady);
1251# endif
1252
1253 buslogicSetInterrupt(pBusLogic, false, BL_INTR_IMBL);
1254
1255 PDMCritSectLeave(&pBusLogic->CritSectIntr);
1256}
1257
1258# ifdef LOG_ENABLED
1259
1260/**
1261 * Dumps the content of a mailbox for debugging purposes.
1262 *
1263 * @return nothing
1264 * @param pMailbox The mailbox to dump.
1265 * @param fOutgoing true if dumping the outgoing state.
1266 * false if dumping the incoming state.
1267 */
1268static void buslogicR3DumpMailboxInfo(PMailbox32 pMailbox, bool fOutgoing)
1269{
1270 Log(("%s: Dump for %s mailbox:\n", __FUNCTION__, fOutgoing ? "outgoing" : "incoming"));
1271 Log(("%s: u32PhysAddrCCB=%#x\n", __FUNCTION__, pMailbox->u32PhysAddrCCB));
1272 if (fOutgoing)
1273 {
1274 Log(("%s: uActionCode=%u\n", __FUNCTION__, pMailbox->u.out.uActionCode));
1275 }
1276 else
1277 {
1278 Log(("%s: uHostAdapterStatus=%u\n", __FUNCTION__, pMailbox->u.in.uHostAdapterStatus));
1279 Log(("%s: uTargetDeviceStatus=%u\n", __FUNCTION__, pMailbox->u.in.uTargetDeviceStatus));
1280 Log(("%s: uCompletionCode=%u\n", __FUNCTION__, pMailbox->u.in.uCompletionCode));
1281 }
1282}
1283
1284/**
1285 * Dumps the content of a command control block for debugging purposes.
1286 *
1287 * @returns nothing.
1288 * @param pCCB Pointer to the command control block to dump.
1289 * @param fIs24BitCCB Flag to determine CCB format.
1290 */
1291static void buslogicR3DumpCCBInfo(PCCBU pCCB, bool fIs24BitCCB)
1292{
1293 Log(("%s: Dump for %s Command Control Block:\n", __FUNCTION__, fIs24BitCCB ? "24-bit" : "32-bit"));
1294 Log(("%s: uOpCode=%#x\n", __FUNCTION__, pCCB->c.uOpcode));
1295 Log(("%s: uDataDirection=%u\n", __FUNCTION__, pCCB->c.uDataDirection));
1296 Log(("%s: cbCDB=%u\n", __FUNCTION__, pCCB->c.cbCDB));
1297 Log(("%s: cbSenseData=%u\n", __FUNCTION__, pCCB->c.cbSenseData));
1298 Log(("%s: uHostAdapterStatus=%u\n", __FUNCTION__, pCCB->c.uHostAdapterStatus));
1299 Log(("%s: uDeviceStatus=%u\n", __FUNCTION__, pCCB->c.uDeviceStatus));
1300 if (fIs24BitCCB)
1301 {
1302 Log(("%s: cbData=%u\n", __FUNCTION__, LEN_TO_U32(pCCB->o.acbData)));
1303 Log(("%s: PhysAddrData=%#x\n", __FUNCTION__, ADDR_TO_U32(pCCB->o.aPhysAddrData)));
1304 Log(("%s: uTargetId=%u\n", __FUNCTION__, pCCB->o.uTargetId));
1305 Log(("%s: uLogicalUnit=%u\n", __FUNCTION__, pCCB->o.uLogicalUnit));
1306 }
1307 else
1308 {
1309 Log(("%s: cbData=%u\n", __FUNCTION__, pCCB->n.cbData));
1310 Log(("%s: PhysAddrData=%#x\n", __FUNCTION__, pCCB->n.u32PhysAddrData));
1311 Log(("%s: uTargetId=%u\n", __FUNCTION__, pCCB->n.uTargetId));
1312 Log(("%s: uLogicalUnit=%u\n", __FUNCTION__, pCCB->n.uLogicalUnit));
1313 Log(("%s: fTagQueued=%d\n", __FUNCTION__, pCCB->n.fTagQueued));
1314 Log(("%s: uQueueTag=%u\n", __FUNCTION__, pCCB->n.uQueueTag));
1315 Log(("%s: fLegacyTagEnable=%u\n", __FUNCTION__, pCCB->n.fLegacyTagEnable));
1316 Log(("%s: uLegacyQueueTag=%u\n", __FUNCTION__, pCCB->n.uLegacyQueueTag));
1317 Log(("%s: PhysAddrSenseData=%#x\n", __FUNCTION__, pCCB->n.u32PhysAddrSenseData));
1318 }
1319 Log(("%s: uCDB[0]=%#x\n", __FUNCTION__, pCCB->c.abCDB[0]));
1320 for (int i = 1; i < pCCB->c.cbCDB; i++)
1321 Log(("%s: uCDB[%d]=%u\n", __FUNCTION__, i, pCCB->c.abCDB[i]));
1322}
1323
1324# endif /* LOG_ENABLED */
1325
1326/**
1327 * Allocate data buffer.
1328 *
1329 * @param pTaskState Pointer to the task state.
1330 * @param GCSGList Guest physical address of S/G list.
1331 * @param cEntries Number of list entries to read.
1332 * @param pSGEList Pointer to 32-bit S/G list storage.
1333 */
1334static void buslogicR3ReadSGEntries(PBUSLOGICTASKSTATE pTaskState, RTGCPHYS GCSGList, uint32_t cEntries, SGE32 *pSGEList)
1335{
1336 PPDMDEVINS pDevIns = pTaskState->CTX_SUFF(pTargetDevice)->CTX_SUFF(pBusLogic)->CTX_SUFF(pDevIns);
1337 SGE24 aSGE24[32];
1338 Assert(cEntries <= RT_ELEMENTS(aSGE24));
1339
1340 /* Read the S/G entries. Convert 24-bit entries to 32-bit format. */
1341 if (pTaskState->fIs24Bit)
1342 {
1343 Log2(("Converting %u 24-bit S/G entries to 32-bit\n", cEntries));
1344 PDMDevHlpPhysRead(pDevIns, GCSGList, &aSGE24, cEntries * sizeof(SGE24));
1345 for (uint32_t i = 0; i < cEntries; ++i)
1346 {
1347 pSGEList[i].cbSegment = LEN_TO_U32(aSGE24[i].acbSegment);
1348 pSGEList[i].u32PhysAddrSegmentBase = ADDR_TO_U32(aSGE24[i].aPhysAddrSegmentBase);
1349 }
1350 }
1351 else
1352 PDMDevHlpPhysRead(pDevIns, GCSGList, pSGEList, cEntries * sizeof(SGE32));
1353}
1354
1355/**
1356 * Allocate data buffer.
1357 *
1358 * @returns VBox status code.
1359 * @param pTaskState Pointer to the task state.
1360 */
1361static int buslogicR3DataBufferAlloc(PBUSLOGICTASKSTATE pTaskState)
1362{
1363 PPDMDEVINS pDevIns = pTaskState->CTX_SUFF(pTargetDevice)->CTX_SUFF(pBusLogic)->CTX_SUFF(pDevIns);
1364 uint32_t cbDataCCB;
1365 uint32_t u32PhysAddrCCB;
1366
1367 /* Extract the data length and physical address from the CCB. */
1368 if (pTaskState->fIs24Bit)
1369 {
1370 u32PhysAddrCCB = ADDR_TO_U32(pTaskState->CommandControlBlockGuest.o.aPhysAddrData);
1371 cbDataCCB = LEN_TO_U32(pTaskState->CommandControlBlockGuest.o.acbData);
1372 }
1373 else
1374 {
1375 u32PhysAddrCCB = pTaskState->CommandControlBlockGuest.n.u32PhysAddrData;
1376 cbDataCCB = pTaskState->CommandControlBlockGuest.n.cbData;
1377 }
1378
1379 if ( (pTaskState->CommandControlBlockGuest.c.uDataDirection != BUSLOGIC_CCB_DIRECTION_NO_DATA)
1380 && cbDataCCB)
1381 {
1382 /** @todo Check following assumption and what residual means. */
1383 /*
1384 * The BusLogic adapter can handle two different data buffer formats.
1385 * The first one is that the data pointer entry in the CCB points to
1386 * the buffer directly. In second mode the data pointer points to a
1387 * scatter gather list which describes the buffer.
1388 */
1389 if ( (pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_SCATTER_GATHER)
1390 || (pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_RESIDUAL_SCATTER_GATHER))
1391 {
1392 uint32_t cScatterGatherGCRead;
1393 uint32_t iScatterGatherEntry;
1394 SGE32 aScatterGatherReadGC[32]; /* A buffer for scatter gather list entries read from guest memory. */
1395 uint32_t cScatterGatherGCLeft = cbDataCCB / pTaskState->cbSGEntry;
1396 RTGCPHYS GCPhysAddrScatterGatherCurrent = u32PhysAddrCCB;
1397 size_t cbDataToTransfer = 0;
1398
1399 /* Count number of bytes to transfer. */
1400 do
1401 {
1402 cScatterGatherGCRead = (cScatterGatherGCLeft < RT_ELEMENTS(aScatterGatherReadGC))
1403 ? cScatterGatherGCLeft
1404 : RT_ELEMENTS(aScatterGatherReadGC);
1405 cScatterGatherGCLeft -= cScatterGatherGCRead;
1406
1407 buslogicR3ReadSGEntries(pTaskState, GCPhysAddrScatterGatherCurrent, cScatterGatherGCRead, aScatterGatherReadGC);
1408
1409 for (iScatterGatherEntry = 0; iScatterGatherEntry < cScatterGatherGCRead; iScatterGatherEntry++)
1410 {
1411 RTGCPHYS GCPhysAddrDataBase;
1412
1413 Log(("%s: iScatterGatherEntry=%u\n", __FUNCTION__, iScatterGatherEntry));
1414
1415 GCPhysAddrDataBase = (RTGCPHYS)aScatterGatherReadGC[iScatterGatherEntry].u32PhysAddrSegmentBase;
1416 cbDataToTransfer += aScatterGatherReadGC[iScatterGatherEntry].cbSegment;
1417
1418 Log(("%s: GCPhysAddrDataBase=%RGp cbDataToTransfer=%u\n",
1419 __FUNCTION__, GCPhysAddrDataBase,
1420 aScatterGatherReadGC[iScatterGatherEntry].cbSegment));
1421 }
1422
1423 /* Set address to the next entries to read. */
1424 GCPhysAddrScatterGatherCurrent += cScatterGatherGCRead * pTaskState->cbSGEntry;
1425 } while (cScatterGatherGCLeft > 0);
1426
1427 Log(("%s: cbDataToTransfer=%d\n", __FUNCTION__, cbDataToTransfer));
1428
1429 /* Allocate buffer */
1430 pTaskState->DataSeg.cbSeg = cbDataToTransfer;
1431 pTaskState->DataSeg.pvSeg = RTMemAlloc(pTaskState->DataSeg.cbSeg);
1432 if (!pTaskState->DataSeg.pvSeg)
1433 return VERR_NO_MEMORY;
1434
1435 /* Copy the data if needed */
1436 if ( (pTaskState->CommandControlBlockGuest.c.uDataDirection == BUSLOGIC_CCB_DIRECTION_OUT)
1437 || (pTaskState->CommandControlBlockGuest.c.uDataDirection == BUSLOGIC_CCB_DIRECTION_UNKNOWN))
1438 {
1439 cScatterGatherGCLeft = cbDataCCB / pTaskState->cbSGEntry;
1440 GCPhysAddrScatterGatherCurrent = u32PhysAddrCCB;
1441 uint8_t *pbData = (uint8_t *)pTaskState->DataSeg.pvSeg;
1442
1443 do
1444 {
1445 cScatterGatherGCRead = (cScatterGatherGCLeft < RT_ELEMENTS(aScatterGatherReadGC))
1446 ? cScatterGatherGCLeft
1447 : RT_ELEMENTS(aScatterGatherReadGC);
1448 cScatterGatherGCLeft -= cScatterGatherGCRead;
1449
1450 buslogicR3ReadSGEntries(pTaskState, GCPhysAddrScatterGatherCurrent, cScatterGatherGCRead, aScatterGatherReadGC);
1451
1452 for (iScatterGatherEntry = 0; iScatterGatherEntry < cScatterGatherGCRead; iScatterGatherEntry++)
1453 {
1454 RTGCPHYS GCPhysAddrDataBase;
1455
1456 Log(("%s: iScatterGatherEntry=%u\n", __FUNCTION__, iScatterGatherEntry));
1457
1458 GCPhysAddrDataBase = (RTGCPHYS)aScatterGatherReadGC[iScatterGatherEntry].u32PhysAddrSegmentBase;
1459 cbDataToTransfer = aScatterGatherReadGC[iScatterGatherEntry].cbSegment;
1460
1461 Log(("%s: GCPhysAddrDataBase=%RGp cbDataToTransfer=%u\n", __FUNCTION__, GCPhysAddrDataBase, cbDataToTransfer));
1462
1463 PDMDevHlpPhysRead(pDevIns, GCPhysAddrDataBase, pbData, cbDataToTransfer);
1464 pbData += cbDataToTransfer;
1465 }
1466
1467 /* Set address to the next entries to read. */
1468 GCPhysAddrScatterGatherCurrent += cScatterGatherGCRead * pTaskState->cbSGEntry;
1469 } while (cScatterGatherGCLeft > 0);
1470 }
1471
1472 }
1473 else if ( pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB
1474 || pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_RESIDUAL_DATA_LENGTH)
1475 {
1476 /* The buffer is not scattered. */
1477 RTGCPHYS GCPhysAddrDataBase = u32PhysAddrCCB;
1478
1479 AssertMsg(GCPhysAddrDataBase != 0, ("Physical address is 0\n"));
1480
1481 pTaskState->DataSeg.cbSeg = cbDataCCB;
1482 pTaskState->DataSeg.pvSeg = RTMemAlloc(pTaskState->DataSeg.cbSeg);
1483 if (!pTaskState->DataSeg.pvSeg)
1484 return VERR_NO_MEMORY;
1485
1486 Log(("Non scattered buffer:\n"));
1487 Log(("u32PhysAddrData=%#x\n", u32PhysAddrCCB));
1488 Log(("cbData=%u\n", cbDataCCB));
1489 Log(("GCPhysAddrDataBase=0x%RGp\n", GCPhysAddrDataBase));
1490
1491 /* Copy the data into the buffer. */
1492 PDMDevHlpPhysRead(pDevIns, GCPhysAddrDataBase, pTaskState->DataSeg.pvSeg, pTaskState->DataSeg.cbSeg);
1493 }
1494 }
1495
1496 return VINF_SUCCESS;
1497}
1498
1499/**
1500 * Free allocated resources used for the scatter gather list.
1501 *
1502 * @returns nothing.
1503 * @param pTaskState Pointer to the task state.
1504 */
1505static void buslogicR3DataBufferFree(PBUSLOGICTASKSTATE pTaskState)
1506{
1507 PPDMDEVINS pDevIns = pTaskState->CTX_SUFF(pTargetDevice)->CTX_SUFF(pBusLogic)->CTX_SUFF(pDevIns);
1508 uint32_t cbDataCCB;
1509 uint32_t u32PhysAddrCCB;
1510
1511 /* Extract the data length and physical address from the CCB. */
1512 if (pTaskState->fIs24Bit)
1513 {
1514 u32PhysAddrCCB = ADDR_TO_U32(pTaskState->CommandControlBlockGuest.o.aPhysAddrData);
1515 cbDataCCB = LEN_TO_U32(pTaskState->CommandControlBlockGuest.o.acbData);
1516 }
1517 else
1518 {
1519 u32PhysAddrCCB = pTaskState->CommandControlBlockGuest.n.u32PhysAddrData;
1520 cbDataCCB = pTaskState->CommandControlBlockGuest.n.cbData;
1521 }
1522
1523#if 1
1524 /* Hack for NT 10/91: A CCB describes a 2K buffer, but TEST UNIT READY is executed. This command
1525 * returns no data, hence the buffer must be left alone!
1526 */
1527 if (pTaskState->CommandControlBlockGuest.c.abCDB[0] == 0)
1528 cbDataCCB = 0;
1529#endif
1530
1531 LogFlowFunc(("pTaskState=%#p cbDataCCB=%u direction=%u cbSeg=%u\n", pTaskState, cbDataCCB,
1532 pTaskState->CommandControlBlockGuest.c.uDataDirection, pTaskState->DataSeg.cbSeg));
1533
1534 if ( (cbDataCCB > 0)
1535 && ( (pTaskState->CommandControlBlockGuest.c.uDataDirection == BUSLOGIC_CCB_DIRECTION_IN)
1536 || (pTaskState->CommandControlBlockGuest.c.uDataDirection == BUSLOGIC_CCB_DIRECTION_UNKNOWN)))
1537 {
1538 if ( (pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_SCATTER_GATHER)
1539 || (pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_RESIDUAL_SCATTER_GATHER))
1540 {
1541 uint32_t cScatterGatherGCRead;
1542 uint32_t iScatterGatherEntry;
1543 SGE32 aScatterGatherReadGC[32]; /* Number of scatter gather list entries read from guest memory. */
1544 uint32_t cScatterGatherGCLeft = cbDataCCB / pTaskState->cbSGEntry;
1545 RTGCPHYS GCPhysAddrScatterGatherCurrent = u32PhysAddrCCB;
1546 uint8_t *pbData = (uint8_t *)pTaskState->DataSeg.pvSeg;
1547
1548 do
1549 {
1550 cScatterGatherGCRead = (cScatterGatherGCLeft < RT_ELEMENTS(aScatterGatherReadGC))
1551 ? cScatterGatherGCLeft
1552 : RT_ELEMENTS(aScatterGatherReadGC);
1553 cScatterGatherGCLeft -= cScatterGatherGCRead;
1554
1555 buslogicR3ReadSGEntries(pTaskState, GCPhysAddrScatterGatherCurrent, cScatterGatherGCRead, aScatterGatherReadGC);
1556
1557 for (iScatterGatherEntry = 0; iScatterGatherEntry < cScatterGatherGCRead; iScatterGatherEntry++)
1558 {
1559 RTGCPHYS GCPhysAddrDataBase;
1560 size_t cbDataToTransfer;
1561
1562 Log(("%s: iScatterGatherEntry=%u\n", __FUNCTION__, iScatterGatherEntry));
1563
1564 GCPhysAddrDataBase = (RTGCPHYS)aScatterGatherReadGC[iScatterGatherEntry].u32PhysAddrSegmentBase;
1565 cbDataToTransfer = aScatterGatherReadGC[iScatterGatherEntry].cbSegment;
1566
1567 Log(("%s: GCPhysAddrDataBase=%RGp cbDataToTransfer=%u\n", __FUNCTION__, GCPhysAddrDataBase, cbDataToTransfer));
1568
1569 PDMDevHlpPCIPhysWrite(pDevIns, GCPhysAddrDataBase, pbData, cbDataToTransfer);
1570 pbData += cbDataToTransfer;
1571 }
1572
1573 /* Set address to the next entries to read. */
1574 GCPhysAddrScatterGatherCurrent += cScatterGatherGCRead * pTaskState->cbSGEntry;
1575 } while (cScatterGatherGCLeft > 0);
1576
1577 }
1578 else if ( pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB
1579 || pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_RESIDUAL_DATA_LENGTH)
1580 {
1581 /* The buffer is not scattered. */
1582 RTGCPHYS GCPhysAddrDataBase = u32PhysAddrCCB;
1583
1584 AssertMsg(GCPhysAddrDataBase != 0, ("Physical address is 0\n"));
1585
1586 Log(("Non-scattered buffer:\n"));
1587 Log(("u32PhysAddrData=%#x\n", u32PhysAddrCCB));
1588 Log(("cbData=%u\n", cbDataCCB));
1589 Log(("GCPhysAddrDataBase=0x%RGp\n", GCPhysAddrDataBase));
1590
1591 /* Copy the data into the guest memory. */
1592 PDMDevHlpPCIPhysWrite(pDevIns, GCPhysAddrDataBase, pTaskState->DataSeg.pvSeg, pTaskState->DataSeg.cbSeg);
1593 }
1594
1595 }
1596 /* Update residual data length. */
1597 if ( (pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_RESIDUAL_DATA_LENGTH)
1598 || (pTaskState->CommandControlBlockGuest.c.uOpcode == BUSLOGIC_CCB_OPCODE_INITIATOR_CCB_RESIDUAL_SCATTER_GATHER))
1599 {
1600 uint32_t cbResidual;
1601
1602 /** @todo we need to get the actual transfer length from the VSCSI layer?! */
1603 cbResidual = 0; //LEN_TO_U32(pTaskState->CCBGuest.acbData) - ???;
1604 if (pTaskState->fIs24Bit)
1605 U32_TO_LEN(pTaskState->CommandControlBlockGuest.o.acbData, cbResidual);
1606 else
1607 pTaskState->CommandControlBlockGuest.n.cbData = cbResidual;
1608 }
1609
1610 RTMemFree(pTaskState->DataSeg.pvSeg);
1611 pTaskState->DataSeg.pvSeg = NULL;
1612 pTaskState->DataSeg.cbSeg = 0;
1613}
1614
1615/** Convert sense buffer length taking into account shortcut values. */
1616static uint32_t buslogicR3ConvertSenseBufferLength(uint32_t cbSense)
1617{
1618 /* Convert special sense buffer length values. */
1619 if (cbSense == 0)
1620 cbSense = 14; /* 0 means standard 14-byte buffer. */
1621 else if (cbSense == 1)
1622 cbSense = 0; /* 1 means no sense data. */
1623 else if (cbSense < 8)
1624 AssertMsgFailed(("Reserved cbSense value of %d used!\n", cbSense));
1625
1626 return cbSense;
1627}
1628
1629/**
1630 * Free the sense buffer.
1631 *
1632 * @returns nothing.
1633 * @param pTaskState Pointer to the task state.
1634 * @param fCopy If sense data should be copied to guest memory.
1635 */
1636static void buslogicR3SenseBufferFree(PBUSLOGICTASKSTATE pTaskState, bool fCopy)
1637{
1638 uint32_t cbSenseBuffer;
1639
1640 cbSenseBuffer = buslogicR3ConvertSenseBufferLength(pTaskState->CommandControlBlockGuest.c.cbSenseData);
1641
1642 /* Copy the sense buffer into guest memory if requested. */
1643 if (fCopy && cbSenseBuffer)
1644 {
1645 PPDMDEVINS pDevIns = pTaskState->CTX_SUFF(pTargetDevice)->CTX_SUFF(pBusLogic)->CTX_SUFF(pDevIns);
1646 RTGCPHYS GCPhysAddrSenseBuffer;
1647
1648 /* With 32-bit CCBs, the (optional) sense buffer physical address is provided separately.
1649 * On the other hand, with 24-bit CCBs, the sense buffer is simply located at the end of
1650 * the CCB, right after the variable-length CDB.
1651 */
1652 if (pTaskState->fIs24Bit)
1653 {
1654 GCPhysAddrSenseBuffer = pTaskState->MailboxGuest.u32PhysAddrCCB;
1655 GCPhysAddrSenseBuffer += pTaskState->CommandControlBlockGuest.c.cbCDB + RT_OFFSETOF(CCB24, abCDB);
1656 }
1657 else
1658 GCPhysAddrSenseBuffer = pTaskState->CommandControlBlockGuest.n.u32PhysAddrSenseData;
1659
1660 Log3(("%s: sense buffer: %.*Rhxs\n", __FUNCTION__, cbSenseBuffer, pTaskState->pbSenseBuffer));
1661 PDMDevHlpPCIPhysWrite(pDevIns, GCPhysAddrSenseBuffer, pTaskState->pbSenseBuffer, cbSenseBuffer);
1662 }
1663
1664 RTMemFree(pTaskState->pbSenseBuffer);
1665 pTaskState->pbSenseBuffer = NULL;
1666}
1667
1668/**
1669 * Alloc the sense buffer.
1670 *
1671 * @returns VBox status code.
1672 * @param pTaskState Pointer to the task state.
1673 * @note Current assumption is that the sense buffer is not scattered and does not cross a page boundary.
1674 */
1675static int buslogicR3SenseBufferAlloc(PBUSLOGICTASKSTATE pTaskState)
1676{
1677 PPDMDEVINS pDevIns = pTaskState->CTX_SUFF(pTargetDevice)->CTX_SUFF(pBusLogic)->CTX_SUFF(pDevIns);
1678 uint32_t cbSenseBuffer;
1679
1680 pTaskState->pbSenseBuffer = NULL;
1681
1682 cbSenseBuffer = buslogicR3ConvertSenseBufferLength(pTaskState->CommandControlBlockGuest.c.cbSenseData);
1683 if (cbSenseBuffer)
1684 {
1685 pTaskState->pbSenseBuffer = (uint8_t *)RTMemAllocZ(cbSenseBuffer);
1686 if (!pTaskState->pbSenseBuffer)
1687 return VERR_NO_MEMORY;
1688 }
1689
1690 return VINF_SUCCESS;
1691}
1692
1693#endif /* IN_RING3 */
1694
1695/**
1696 * Parses the command buffer and executes it.
1697 *
1698 * @returns VBox status code.
1699 * @param pBusLogic Pointer to the BusLogic device instance.
1700 */
1701static int buslogicProcessCommand(PBUSLOGIC pBusLogic)
1702{
1703 int rc = VINF_SUCCESS;
1704 bool fSuppressIrq = false;
1705
1706 LogFlowFunc(("pBusLogic=%#p\n", pBusLogic));
1707 AssertMsg(pBusLogic->uOperationCode != 0xff, ("There is no command to execute\n"));
1708
1709 switch (pBusLogic->uOperationCode)
1710 {
1711 case BUSLOGICCOMMAND_TEST_CMDC_INTERRUPT:
1712 /* Valid command, no reply. */
1713 pBusLogic->cbReplyParametersLeft = 0;
1714 break;
1715 case BUSLOGICCOMMAND_INQUIRE_PCI_HOST_ADAPTER_INFORMATION:
1716 {
1717 PReplyInquirePCIHostAdapterInformation pReply = (PReplyInquirePCIHostAdapterInformation)pBusLogic->aReplyBuffer;
1718 memset(pReply, 0, sizeof(ReplyInquirePCIHostAdapterInformation));
1719
1720 /* It seems VMware does not provide valid information here too, lets do the same :) */
1721 pReply->InformationIsValid = 0;
1722 pReply->IsaIOPort = pBusLogic->uISABaseCode;
1723 pReply->IRQ = PCIDevGetInterruptLine(&pBusLogic->dev);
1724 pBusLogic->cbReplyParametersLeft = sizeof(ReplyInquirePCIHostAdapterInformation);
1725 break;
1726 }
1727 case BUSLOGICCOMMAND_SET_SCSI_SELECTION_TIMEOUT:
1728 {
1729 /* no-op */
1730 pBusLogic->cbReplyParametersLeft = 0;
1731 break;
1732 }
1733 case BUSLOGICCOMMAND_MODIFY_IO_ADDRESS:
1734 {
1735 /* Modify the ISA-compatible I/O port base. Note that this technically
1736 * violates the PCI spec, as this address is not reported through PCI.
1737 * However, it is required for compatibility with old drivers.
1738 */
1739#ifdef IN_RING3
1740 Log(("ISA I/O for PCI (code %x)\n", pBusLogic->aCommandBuffer[0]));
1741 buslogicR3RegisterISARange(pBusLogic, pBusLogic->aCommandBuffer[0]);
1742 pBusLogic->cbReplyParametersLeft = 0;
1743 fSuppressIrq = true;
1744 break;
1745#else
1746 AssertMsgFailed(("Must never get here!\n"));
1747#endif
1748 }
1749 case BUSLOGICCOMMAND_INQUIRE_BOARD_ID:
1750 {
1751 /* The special option byte is important: If it is '0' or 'B', Windows NT drivers
1752 * for Adaptec AHA-154x may claim the adapter. The BusLogic drivers will claim
1753 * the adapter only when the byte is *not* '0' or 'B'.
1754 */
1755 pBusLogic->aReplyBuffer[0] = 'A'; /* Firmware option bytes */
1756 pBusLogic->aReplyBuffer[1] = 'A'; /* Special option byte */
1757
1758 /* We report version 5.07B. This reply will provide the first two digits. */
1759 pBusLogic->aReplyBuffer[2] = '5'; /* Major version 5 */
1760 pBusLogic->aReplyBuffer[3] = '0'; /* Minor version 0 */
1761 pBusLogic->cbReplyParametersLeft = 4; /* Reply is 4 bytes long */
1762 break;
1763 }
1764 case BUSLOGICCOMMAND_INQUIRE_FIRMWARE_VERSION_3RD_LETTER:
1765 {
1766 pBusLogic->aReplyBuffer[0] = '7';
1767 pBusLogic->cbReplyParametersLeft = 1;
1768 break;
1769 }
1770 case BUSLOGICCOMMAND_INQUIRE_FIRMWARE_VERSION_LETTER:
1771 {
1772 pBusLogic->aReplyBuffer[0] = 'B';
1773 pBusLogic->cbReplyParametersLeft = 1;
1774 break;
1775 }
1776 case BUSLOGICCOMMAND_SET_ADAPTER_OPTIONS:
1777 /* The parameter list length is determined by the first byte of the command buffer. */
1778 if (pBusLogic->iParameter == 1)
1779 {
1780 /* First pass - set the number of following parameter bytes. */
1781 pBusLogic->cbCommandParametersLeft = pBusLogic->aCommandBuffer[0];
1782 Log(("Set HA options: %u bytes follow\n", pBusLogic->cbCommandParametersLeft));
1783 }
1784 else
1785 {
1786 /* Second pass - process received data. */
1787 Log(("Set HA options: received %u bytes\n", pBusLogic->aCommandBuffer[0]));
1788 /* We ignore the data - it only concerns the SCSI hardware protocol. */
1789 }
1790 pBusLogic->cbReplyParametersLeft = 0;
1791 break;
1792
1793 case BUSLOGICCOMMAND_EXECUTE_SCSI_COMMAND:
1794 /* The parameter list length is at least 12 bytes; the 12th byte determines
1795 * the number of additional CDB bytes that will follow.
1796 */
1797 if (pBusLogic->iParameter == 12)
1798 {
1799 /* First pass - set the number of following CDB bytes. */
1800 pBusLogic->cbCommandParametersLeft = pBusLogic->aCommandBuffer[11];
1801 Log(("Execute SCSI cmd: %u more bytes follow\n", pBusLogic->cbCommandParametersLeft));
1802 }
1803 else
1804 {
1805 PESCMD pCmd;
1806
1807 /* Second pass - process received data. */
1808 Log(("Execute SCSI cmd: received %u bytes\n", pBusLogic->aCommandBuffer[0]));
1809
1810 pCmd = (PESCMD)pBusLogic->aCommandBuffer;
1811 Log(("Addr %08X, cbData %08X, cbCDB=%u\n", pCmd->u32PhysAddrData, pCmd->cbData, pCmd->cbCDB));
1812 }
1813 // This is currently a dummy - just fails every command.
1814 pBusLogic->cbReplyParametersLeft = 4;
1815 pBusLogic->aReplyBuffer[0] = pBusLogic->aReplyBuffer[1] = 0;
1816 pBusLogic->aReplyBuffer[2] = 0x11; /* HBA status (timeout). */
1817 pBusLogic->aReplyBuffer[3] = 0; /* Device status. */
1818 break;
1819
1820 case BUSLOGICCOMMAND_INQUIRE_HOST_ADAPTER_MODEL_NUMBER:
1821 {
1822 /* The reply length is set by the guest and is found in the first byte of the command buffer. */
1823 pBusLogic->cbReplyParametersLeft = pBusLogic->aCommandBuffer[0];
1824 memset(pBusLogic->aReplyBuffer, 0, pBusLogic->cbReplyParametersLeft);
1825 const char aModelName[] = "958D "; /* Trailing \0 is fine, that's the filler anyway. */
1826 int cCharsToTransfer = pBusLogic->cbReplyParametersLeft <= sizeof(aModelName)
1827 ? pBusLogic->cbReplyParametersLeft
1828 : sizeof(aModelName);
1829
1830 for (int i = 0; i < cCharsToTransfer; i++)
1831 pBusLogic->aReplyBuffer[i] = aModelName[i];
1832
1833 break;
1834 }
1835 case BUSLOGICCOMMAND_INQUIRE_CONFIGURATION:
1836 {
1837 uint8_t uPciIrq = PCIDevGetInterruptLine(&pBusLogic->dev);
1838
1839 pBusLogic->cbReplyParametersLeft = sizeof(ReplyInquireConfiguration);
1840 PReplyInquireConfiguration pReply = (PReplyInquireConfiguration)pBusLogic->aReplyBuffer;
1841 memset(pReply, 0, sizeof(ReplyInquireConfiguration));
1842
1843 pReply->uHostAdapterId = 7; /* The controller has always 7 as ID. */
1844 pReply->fDmaChannel6 = 1; /* DMA channel 6 is a good default. */
1845 /* The PCI IRQ is not necessarily representable in this structure.
1846 * If that is the case, the guest likely won't function correctly,
1847 * therefore we log a warning.
1848 */
1849 switch (uPciIrq)
1850 {
1851 case 9: pReply->fIrqChannel9 = 1; break;
1852 case 10: pReply->fIrqChannel10 = 1; break;
1853 case 11: pReply->fIrqChannel11 = 1; break;
1854 case 12: pReply->fIrqChannel12 = 1; break;
1855 case 14: pReply->fIrqChannel14 = 1; break;
1856 case 15: pReply->fIrqChannel15 = 1; break;
1857 default:
1858 LogRel(("Warning: PCI IRQ %d cannot be represented as ISA!\n", uPciIrq));
1859 break;
1860 }
1861 break;
1862 }
1863 case BUSLOGICCOMMAND_INQUIRE_EXTENDED_SETUP_INFORMATION:
1864 {
1865 /* Some Adaptec AHA-154x drivers (e.g. OS/2) execute this command and expect
1866 * it to fail. If it succeeds, the drivers refuse to load. However, some newer
1867 * Adaptec 154x models supposedly support it too??
1868 */
1869
1870 /* The reply length is set by the guest and is found in the first byte of the command buffer. */
1871 pBusLogic->cbReplyParametersLeft = pBusLogic->aCommandBuffer[0];
1872 PReplyInquireExtendedSetupInformation pReply = (PReplyInquireExtendedSetupInformation)pBusLogic->aReplyBuffer;
1873 memset(pReply, 0, sizeof(ReplyInquireExtendedSetupInformation));
1874
1875 /** @todo should this reflect the RAM contents (AutoSCSIRam)? */
1876 pReply->uBusType = 'E'; /* EISA style */
1877 pReply->u16ScatterGatherLimit = 8192;
1878 pReply->cMailbox = pBusLogic->cMailbox;
1879 pReply->uMailboxAddressBase = (uint32_t)pBusLogic->GCPhysAddrMailboxOutgoingBase;
1880 pReply->fLevelSensitiveInterrupt = true;
1881 pReply->fHostWideSCSI = true;
1882 pReply->fHostUltraSCSI = true;
1883 memcpy(pReply->aFirmwareRevision, "07B", sizeof(pReply->aFirmwareRevision));
1884
1885 break;
1886 }
1887 case BUSLOGICCOMMAND_INQUIRE_SETUP_INFORMATION:
1888 {
1889 /* The reply length is set by the guest and is found in the first byte of the command buffer. */
1890 pBusLogic->cbReplyParametersLeft = pBusLogic->aCommandBuffer[0];
1891 PReplyInquireSetupInformation pReply = (PReplyInquireSetupInformation)pBusLogic->aReplyBuffer;
1892 memset(pReply, 0, sizeof(ReplyInquireSetupInformation));
1893 pReply->fSynchronousInitiationEnabled = true;
1894 pReply->fParityCheckingEnabled = true;
1895 pReply->cMailbox = pBusLogic->cMailbox;
1896 U32_TO_ADDR(pReply->MailboxAddress, pBusLogic->GCPhysAddrMailboxOutgoingBase);
1897 pReply->uSignature = 'B';
1898 /* The 'D' signature prevents Adaptec's OS/2 drivers from getting too
1899 * friendly with BusLogic hardware and upsetting the HBA state.
1900 */
1901 pReply->uCharacterD = 'D'; /* BusLogic model. */
1902 pReply->uHostBusType = 'F'; /* PCI bus. */
1903 break;
1904 }
1905 case BUSLOGICCOMMAND_FETCH_HOST_ADAPTER_LOCAL_RAM:
1906 {
1907 /*
1908 * First element in the command buffer contains start offset to read from
1909 * and second one the number of bytes to read.
1910 */
1911 uint8_t uOffset = pBusLogic->aCommandBuffer[0];
1912 pBusLogic->cbReplyParametersLeft = pBusLogic->aCommandBuffer[1];
1913
1914 pBusLogic->fUseLocalRam = true;
1915 pBusLogic->iReply = uOffset;
1916 break;
1917 }
1918 case BUSLOGICCOMMAND_INITIALIZE_MAILBOX:
1919 {
1920 PRequestInitMbx pRequest = (PRequestInitMbx)pBusLogic->aCommandBuffer;
1921
1922 pBusLogic->fMbxIs24Bit = true;
1923 pBusLogic->cMailbox = pRequest->cMailbox;
1924 pBusLogic->GCPhysAddrMailboxOutgoingBase = (RTGCPHYS)ADDR_TO_U32(pRequest->aMailboxBaseAddr);
1925 /* The area for incoming mailboxes is right after the last entry of outgoing mailboxes. */
1926 pBusLogic->GCPhysAddrMailboxIncomingBase = pBusLogic->GCPhysAddrMailboxOutgoingBase + (pBusLogic->cMailbox * sizeof(Mailbox24));
1927
1928 Log(("GCPhysAddrMailboxOutgoingBase=%RGp\n", pBusLogic->GCPhysAddrMailboxOutgoingBase));
1929 Log(("GCPhysAddrMailboxIncomingBase=%RGp\n", pBusLogic->GCPhysAddrMailboxIncomingBase));
1930 Log(("cMailboxes=%u (24-bit mode)\n", pBusLogic->cMailbox));
1931 LogRel(("Initialized 24-bit mailbox, %d entries at %08x\n", pRequest->cMailbox, ADDR_TO_U32(pRequest->aMailboxBaseAddr)));
1932
1933 pBusLogic->regStatus &= ~BL_STAT_INREQ;
1934 pBusLogic->cbReplyParametersLeft = 0;
1935 break;
1936 }
1937 case BUSLOGICCOMMAND_INITIALIZE_EXTENDED_MAILBOX:
1938 {
1939 PRequestInitializeExtendedMailbox pRequest = (PRequestInitializeExtendedMailbox)pBusLogic->aCommandBuffer;
1940
1941 pBusLogic->fMbxIs24Bit = false;
1942 pBusLogic->cMailbox = pRequest->cMailbox;
1943 pBusLogic->GCPhysAddrMailboxOutgoingBase = (RTGCPHYS)pRequest->uMailboxBaseAddress;
1944 /* The area for incoming mailboxes is right after the last entry of outgoing mailboxes. */
1945 pBusLogic->GCPhysAddrMailboxIncomingBase = (RTGCPHYS)pRequest->uMailboxBaseAddress + (pBusLogic->cMailbox * sizeof(Mailbox32));
1946
1947 Log(("GCPhysAddrMailboxOutgoingBase=%RGp\n", pBusLogic->GCPhysAddrMailboxOutgoingBase));
1948 Log(("GCPhysAddrMailboxIncomingBase=%RGp\n", pBusLogic->GCPhysAddrMailboxIncomingBase));
1949 Log(("cMailboxes=%u (32-bit mode)\n", pBusLogic->cMailbox));
1950 LogRel(("Initialized 32-bit mailbox, %d entries at %08x\n", pRequest->cMailbox, pRequest->uMailboxBaseAddress));
1951
1952 pBusLogic->regStatus &= ~BL_STAT_INREQ;
1953 pBusLogic->cbReplyParametersLeft = 0;
1954 break;
1955 }
1956 case BUSLOGICCOMMAND_ENABLE_STRICT_ROUND_ROBIN_MODE:
1957 {
1958 if (pBusLogic->aCommandBuffer[0] == 0)
1959 pBusLogic->fStrictRoundRobinMode = false;
1960 else if (pBusLogic->aCommandBuffer[0] == 1)
1961 pBusLogic->fStrictRoundRobinMode = true;
1962 else
1963 AssertMsgFailed(("Invalid round robin mode %d\n", pBusLogic->aCommandBuffer[0]));
1964
1965 pBusLogic->cbReplyParametersLeft = 0;
1966 break;
1967 }
1968 case BUSLOGICCOMMAND_SET_CCB_FORMAT:
1969 {
1970 if (pBusLogic->aCommandBuffer[0] == 0)
1971 pBusLogic->fExtendedLunCCBFormat = false;
1972 else if (pBusLogic->aCommandBuffer[0] == 1)
1973 pBusLogic->fExtendedLunCCBFormat = true;
1974 else
1975 AssertMsgFailed(("Invalid CCB format %d\n", pBusLogic->aCommandBuffer[0]));
1976
1977 pBusLogic->cbReplyParametersLeft = 0;
1978 break;
1979 }
1980 case BUSLOGICCOMMAND_INQUIRE_INSTALLED_DEVICES_ID_0_TO_7:
1981 /* This is supposed to send TEST UNIT READY to each target/LUN.
1982 * We cheat and skip that, since we already know what's attached
1983 */
1984 memset(pBusLogic->aReplyBuffer, 0, 8);
1985 for (int i = 0; i < 8; ++i)
1986 {
1987 if (pBusLogic->aDeviceStates[i].fPresent)
1988 pBusLogic->aReplyBuffer[i] = 1;
1989 }
1990 pBusLogic->aReplyBuffer[7] = 0; /* HA hardcoded at ID 7. */
1991 pBusLogic->cbReplyParametersLeft = 8;
1992 break;
1993 case BUSLOGICCOMMAND_INQUIRE_INSTALLED_DEVICES_ID_8_TO_15:
1994 /* See note about cheating above. */
1995 memset(pBusLogic->aReplyBuffer, 0, 8);
1996 for (int i = 0; i < 8; ++i)
1997 {
1998 if (pBusLogic->aDeviceStates[i + 8].fPresent)
1999 pBusLogic->aReplyBuffer[i] = 1;
2000 }
2001 pBusLogic->cbReplyParametersLeft = 8;
2002 break;
2003 case BUSLOGICCOMMAND_INQUIRE_TARGET_DEVICES:
2004 {
2005 /* Each bit which is set in the 16bit wide variable means a present device. */
2006 uint16_t u16TargetsPresentMask = 0;
2007
2008 for (uint8_t i = 0; i < RT_ELEMENTS(pBusLogic->aDeviceStates); i++)
2009 {
2010 if (pBusLogic->aDeviceStates[i].fPresent)
2011 u16TargetsPresentMask |= (1 << i);
2012 }
2013 pBusLogic->aReplyBuffer[0] = (uint8_t)u16TargetsPresentMask;
2014 pBusLogic->aReplyBuffer[1] = (uint8_t)(u16TargetsPresentMask >> 8);
2015 pBusLogic->cbReplyParametersLeft = 2;
2016 break;
2017 }
2018 case BUSLOGICCOMMAND_INQUIRE_SYNCHRONOUS_PERIOD:
2019 {
2020 pBusLogic->cbReplyParametersLeft = pBusLogic->aCommandBuffer[0];
2021
2022 for (uint8_t i = 0; i < pBusLogic->cbReplyParametersLeft; i++)
2023 pBusLogic->aReplyBuffer[i] = 0; /** @todo Figure if we need something other here. It's not needed for the linux driver */
2024
2025 break;
2026 }
2027 case BUSLOGICCOMMAND_DISABLE_HOST_ADAPTER_INTERRUPT:
2028 {
2029 if (pBusLogic->aCommandBuffer[0] == 0)
2030 pBusLogic->fIRQEnabled = false;
2031 else
2032 pBusLogic->fIRQEnabled = true;
2033 /* No interrupt signaled regardless of enable/disable. */
2034 fSuppressIrq = true;
2035 break;
2036 }
2037 case BUSLOGICCOMMAND_ECHO_COMMAND_DATA:
2038 {
2039 pBusLogic->aReplyBuffer[0] = pBusLogic->aCommandBuffer[0];
2040 pBusLogic->cbReplyParametersLeft = 1;
2041 break;
2042 }
2043 case BUSLOGICCOMMAND_SET_PREEMPT_TIME_ON_BUS:
2044 {
2045 pBusLogic->cbReplyParametersLeft = 0;
2046 pBusLogic->LocalRam.structured.autoSCSIData.uBusOnDelay = pBusLogic->aCommandBuffer[0];
2047 Log(("Bus-on time: %d\n", pBusLogic->aCommandBuffer[0]));
2048 break;
2049 }
2050 case BUSLOGICCOMMAND_SET_TIME_OFF_BUS:
2051 {
2052 pBusLogic->cbReplyParametersLeft = 0;
2053 pBusLogic->LocalRam.structured.autoSCSIData.uBusOffDelay = pBusLogic->aCommandBuffer[0];
2054 Log(("Bus-off time: %d\n", pBusLogic->aCommandBuffer[0]));
2055 break;
2056 }
2057 case BUSLOGICCOMMAND_SET_BUS_TRANSFER_RATE:
2058 {
2059 pBusLogic->cbReplyParametersLeft = 0;
2060 pBusLogic->LocalRam.structured.autoSCSIData.uDMATransferRate = pBusLogic->aCommandBuffer[0];
2061 Log(("Bus transfer rate: %02X\n", pBusLogic->aCommandBuffer[0]));
2062 break;
2063 }
2064 case BUSLOGICCOMMAND_WRITE_BUSMASTER_CHIP_FIFO:
2065 {
2066 RTGCPHYS GCPhysFifoBuf;
2067 Addr24 addr;
2068
2069 pBusLogic->cbReplyParametersLeft = 0;
2070 addr.hi = pBusLogic->aCommandBuffer[0];
2071 addr.mid = pBusLogic->aCommandBuffer[1];
2072 addr.lo = pBusLogic->aCommandBuffer[2];
2073 GCPhysFifoBuf = (RTGCPHYS)ADDR_TO_U32(addr);
2074 Log(("Write busmaster FIFO at: %04X\n", ADDR_TO_U32(addr)));
2075 PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCPhysFifoBuf,
2076 &pBusLogic->LocalRam.u8View[64], 64);
2077 break;
2078 }
2079 case BUSLOGICCOMMAND_READ_BUSMASTER_CHIP_FIFO:
2080 {
2081 RTGCPHYS GCPhysFifoBuf;
2082 Addr24 addr;
2083
2084 pBusLogic->cbReplyParametersLeft = 0;
2085 addr.hi = pBusLogic->aCommandBuffer[0];
2086 addr.mid = pBusLogic->aCommandBuffer[1];
2087 addr.lo = pBusLogic->aCommandBuffer[2];
2088 GCPhysFifoBuf = (RTGCPHYS)ADDR_TO_U32(addr);
2089 Log(("Read busmaster FIFO at: %04X\n", ADDR_TO_U32(addr)));
2090 PDMDevHlpPCIPhysWrite(pBusLogic->CTX_SUFF(pDevIns), GCPhysFifoBuf,
2091 &pBusLogic->LocalRam.u8View[64], 64);
2092 break;
2093 }
2094 default:
2095 AssertMsgFailed(("Invalid command %#x\n", pBusLogic->uOperationCode));
2096 case BUSLOGICCOMMAND_EXT_BIOS_INFO:
2097 case BUSLOGICCOMMAND_UNLOCK_MAILBOX:
2098 /* Commands valid for Adaptec 154xC which we don't handle since
2099 * we pretend being 154xB compatible. Just mark the command as invalid.
2100 */
2101 Log(("Command %#x not valid for this adapter\n", pBusLogic->uOperationCode));
2102 pBusLogic->cbReplyParametersLeft = 0;
2103 pBusLogic->regStatus |= BL_STAT_CMDINV;
2104 break;
2105 case BUSLOGICCOMMAND_EXECUTE_MAILBOX_COMMAND: /* Should be handled already. */
2106 AssertMsgFailed(("Invalid mailbox execute state!\n"));
2107 }
2108
2109 Log(("uOperationCode=%#x, cbReplyParametersLeft=%d\n", pBusLogic->uOperationCode, pBusLogic->cbReplyParametersLeft));
2110
2111 /* Set the data in ready bit in the status register in case the command has a reply. */
2112 if (pBusLogic->cbReplyParametersLeft)
2113 pBusLogic->regStatus |= BL_STAT_DIRRDY;
2114 else if (!pBusLogic->cbCommandParametersLeft)
2115 buslogicCommandComplete(pBusLogic, fSuppressIrq);
2116
2117 return rc;
2118}
2119
2120/**
2121 * Read a register from the BusLogic adapter.
2122 *
2123 * @returns VBox status code.
2124 * @param pBusLogic Pointer to the BusLogic instance data.
2125 * @param iRegister The index of the register to read.
2126 * @param pu32 Where to store the register content.
2127 */
2128static int buslogicRegisterRead(PBUSLOGIC pBusLogic, unsigned iRegister, uint32_t *pu32)
2129{
2130 int rc = VINF_SUCCESS;
2131
2132 switch (iRegister)
2133 {
2134 case BUSLOGIC_REGISTER_STATUS:
2135 {
2136 *pu32 = pBusLogic->regStatus;
2137
2138 /* If the diagnostic active bit is set, we are in a guest-initiated
2139 * hard reset. If the guest reads the status register and waits for
2140 * the host adapter ready bit to be set, we terminate the reset right
2141 * away. However, guests may also expect the reset condition to clear
2142 * automatically after a period of time, in which case we can't show
2143 * the DIAG bit at all.
2144 */
2145 if (pBusLogic->regStatus & BL_STAT_DACT)
2146 {
2147 uint64_t u64AccessTime = PDMDevHlpTMTimeVirtGetNano(pBusLogic->CTX_SUFF(pDevIns));
2148
2149 pBusLogic->regStatus &= ~BL_STAT_DACT;
2150 pBusLogic->regStatus |= BL_STAT_HARDY;
2151
2152 if (u64AccessTime - pBusLogic->u64ResetTime > BUSLOGIC_RESET_DURATION_NS)
2153 {
2154 /* If reset already expired, let the guest see that right away. */
2155 *pu32 = pBusLogic->regStatus;
2156 pBusLogic->u64ResetTime = 0;
2157 }
2158 }
2159 break;
2160 }
2161 case BUSLOGIC_REGISTER_DATAIN:
2162 {
2163 if (pBusLogic->fUseLocalRam)
2164 *pu32 = pBusLogic->LocalRam.u8View[pBusLogic->iReply];
2165 else
2166 *pu32 = pBusLogic->aReplyBuffer[pBusLogic->iReply];
2167
2168 /* Careful about underflow - guest can read data register even if
2169 * no data is available.
2170 */
2171 if (pBusLogic->cbReplyParametersLeft)
2172 {
2173 pBusLogic->iReply++;
2174 pBusLogic->cbReplyParametersLeft--;
2175 if (!pBusLogic->cbReplyParametersLeft)
2176 {
2177 /*
2178 * Reply finished, set command complete bit, unset data-in ready bit and
2179 * interrupt the guest if enabled.
2180 */
2181 buslogicCommandComplete(pBusLogic, false);
2182 }
2183 }
2184 LogFlowFunc(("data=%02x, iReply=%d, cbReplyParametersLeft=%u\n", *pu32,
2185 pBusLogic->iReply, pBusLogic->cbReplyParametersLeft));
2186 break;
2187 }
2188 case BUSLOGIC_REGISTER_INTERRUPT:
2189 {
2190 *pu32 = pBusLogic->regInterrupt;
2191 break;
2192 }
2193 case BUSLOGIC_REGISTER_GEOMETRY:
2194 {
2195 *pu32 = pBusLogic->regGeometry;
2196 break;
2197 }
2198 default:
2199 *pu32 = UINT32_C(0xffffffff);
2200 }
2201
2202 Log2(("%s: pu32=%p:{%.*Rhxs} iRegister=%d rc=%Rrc\n",
2203 __FUNCTION__, pu32, 1, pu32, iRegister, rc));
2204
2205 return rc;
2206}
2207
2208/**
2209 * Write a value to a register.
2210 *
2211 * @returns VBox status code.
2212 * @param pBusLogic Pointer to the BusLogic instance data.
2213 * @param iRegister The index of the register to read.
2214 * @param uVal The value to write.
2215 */
2216static int buslogicRegisterWrite(PBUSLOGIC pBusLogic, unsigned iRegister, uint8_t uVal)
2217{
2218 int rc = VINF_SUCCESS;
2219
2220 switch (iRegister)
2221 {
2222 case BUSLOGIC_REGISTER_CONTROL:
2223 {
2224 if ((uVal & BL_CTRL_RHARD) || (uVal & BL_CTRL_RSOFT))
2225 {
2226#ifdef IN_RING3
2227 bool fHardReset = !!(uVal & BL_CTRL_RHARD);
2228
2229 LogRel(("BusLogic: %s reset\n", fHardReset ? "hard" : "soft"));
2230 buslogicR3InitiateReset(pBusLogic, fHardReset);
2231#else
2232 rc = VINF_IOM_R3_IOPORT_WRITE;
2233#endif
2234 break;
2235 }
2236
2237 rc = PDMCritSectEnter(&pBusLogic->CritSectIntr, VINF_IOM_R3_IOPORT_WRITE);
2238 if (rc != VINF_SUCCESS)
2239 return rc;
2240
2241#ifdef LOG_ENABLED
2242 uint32_t cMailboxesReady = ASMAtomicXchgU32(&pBusLogic->cInMailboxesReady, 0);
2243 Log(("%u incoming mailboxes were ready when this interrupt was cleared\n", cMailboxesReady));
2244#endif
2245
2246 if (uVal & BL_CTRL_RINT)
2247 buslogicClearInterrupt(pBusLogic);
2248
2249 PDMCritSectLeave(&pBusLogic->CritSectIntr);
2250
2251 break;
2252 }
2253 case BUSLOGIC_REGISTER_COMMAND:
2254 {
2255 /* Fast path for mailbox execution command. */
2256 if ((uVal == BUSLOGICCOMMAND_EXECUTE_MAILBOX_COMMAND) && (pBusLogic->uOperationCode == 0xff))
2257 {
2258 /* If there are no mailboxes configured, don't even try to do anything. */
2259 if (pBusLogic->cMailbox)
2260 {
2261 ASMAtomicIncU32(&pBusLogic->cMailboxesReady);
2262 if (!ASMAtomicXchgBool(&pBusLogic->fNotificationSent, true))
2263 {
2264 /* Send new notification to the queue. */
2265 PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pBusLogic->CTX_SUFF(pNotifierQueue));
2266 AssertMsg(pItem, ("Allocating item for queue failed\n"));
2267 PDMQueueInsert(pBusLogic->CTX_SUFF(pNotifierQueue), (PPDMQUEUEITEMCORE)pItem);
2268 }
2269 }
2270
2271 return rc;
2272 }
2273
2274 /*
2275 * Check if we are already fetch command parameters from the guest.
2276 * If not we initialize executing a new command.
2277 */
2278 if (pBusLogic->uOperationCode == 0xff)
2279 {
2280 pBusLogic->uOperationCode = uVal;
2281 pBusLogic->iParameter = 0;
2282
2283 /* Mark host adapter as busy and clear the invalid status bit. */
2284 pBusLogic->regStatus &= ~(BL_STAT_HARDY | BL_STAT_CMDINV);
2285
2286 /* Get the number of bytes for parameters from the command code. */
2287 switch (pBusLogic->uOperationCode)
2288 {
2289 case BUSLOGICCOMMAND_TEST_CMDC_INTERRUPT:
2290 case BUSLOGICCOMMAND_INQUIRE_FIRMWARE_VERSION_LETTER:
2291 case BUSLOGICCOMMAND_INQUIRE_BOARD_ID:
2292 case BUSLOGICCOMMAND_INQUIRE_FIRMWARE_VERSION_3RD_LETTER:
2293 case BUSLOGICCOMMAND_INQUIRE_PCI_HOST_ADAPTER_INFORMATION:
2294 case BUSLOGICCOMMAND_INQUIRE_CONFIGURATION:
2295 case BUSLOGICCOMMAND_INQUIRE_INSTALLED_DEVICES_ID_0_TO_7:
2296 case BUSLOGICCOMMAND_INQUIRE_INSTALLED_DEVICES_ID_8_TO_15:
2297 case BUSLOGICCOMMAND_INQUIRE_TARGET_DEVICES:
2298 pBusLogic->cbCommandParametersLeft = 0;
2299 break;
2300 case BUSLOGICCOMMAND_MODIFY_IO_ADDRESS:
2301 case BUSLOGICCOMMAND_INQUIRE_EXTENDED_SETUP_INFORMATION:
2302 case BUSLOGICCOMMAND_INQUIRE_SETUP_INFORMATION:
2303 case BUSLOGICCOMMAND_INQUIRE_HOST_ADAPTER_MODEL_NUMBER:
2304 case BUSLOGICCOMMAND_ENABLE_STRICT_ROUND_ROBIN_MODE:
2305 case BUSLOGICCOMMAND_SET_CCB_FORMAT:
2306 case BUSLOGICCOMMAND_INQUIRE_SYNCHRONOUS_PERIOD:
2307 case BUSLOGICCOMMAND_DISABLE_HOST_ADAPTER_INTERRUPT:
2308 case BUSLOGICCOMMAND_ECHO_COMMAND_DATA:
2309 case BUSLOGICCOMMAND_SET_PREEMPT_TIME_ON_BUS:
2310 case BUSLOGICCOMMAND_SET_TIME_OFF_BUS:
2311 case BUSLOGICCOMMAND_SET_BUS_TRANSFER_RATE:
2312 pBusLogic->cbCommandParametersLeft = 1;
2313 break;
2314 case BUSLOGICCOMMAND_FETCH_HOST_ADAPTER_LOCAL_RAM:
2315 pBusLogic->cbCommandParametersLeft = 2;
2316 break;
2317 case BUSLOGICCOMMAND_READ_BUSMASTER_CHIP_FIFO:
2318 case BUSLOGICCOMMAND_WRITE_BUSMASTER_CHIP_FIFO:
2319 pBusLogic->cbCommandParametersLeft = 3;
2320 break;
2321 case BUSLOGICCOMMAND_SET_SCSI_SELECTION_TIMEOUT:
2322 pBusLogic->cbCommandParametersLeft = 4;
2323 break;
2324 case BUSLOGICCOMMAND_INITIALIZE_MAILBOX:
2325 pBusLogic->cbCommandParametersLeft = sizeof(RequestInitMbx);
2326 break;
2327 case BUSLOGICCOMMAND_INITIALIZE_EXTENDED_MAILBOX:
2328 pBusLogic->cbCommandParametersLeft = sizeof(RequestInitializeExtendedMailbox);
2329 break;
2330 case BUSLOGICCOMMAND_SET_ADAPTER_OPTIONS:
2331 /* There must be at least one byte following this command. */
2332 pBusLogic->cbCommandParametersLeft = 1;
2333 break;
2334 case BUSLOGICCOMMAND_EXECUTE_SCSI_COMMAND:
2335 /* 12 bytes + variable-length CDB. */
2336 pBusLogic->cbCommandParametersLeft = 12;
2337 break;
2338 case BUSLOGICCOMMAND_EXT_BIOS_INFO:
2339 case BUSLOGICCOMMAND_UNLOCK_MAILBOX:
2340 /* Invalid commands. */
2341 pBusLogic->cbCommandParametersLeft = 0;
2342 break;
2343 case BUSLOGICCOMMAND_EXECUTE_MAILBOX_COMMAND: /* Should not come here anymore. */
2344 default:
2345 AssertMsgFailed(("Invalid operation code %#x\n", uVal));
2346 }
2347 }
2348 else
2349 {
2350#ifndef IN_RING3
2351 /* This command must be executed in R3 as it rehooks the ISA I/O port. */
2352 if (pBusLogic->uOperationCode == BUSLOGICCOMMAND_MODIFY_IO_ADDRESS)
2353 {
2354 rc = VINF_IOM_R3_IOPORT_WRITE;
2355 break;
2356 }
2357#endif
2358 /*
2359 * The real adapter would set the Command register busy bit in the status register.
2360 * The guest has to wait until it is unset.
2361 * We don't need to do it because the guest does not continue execution while we are in this
2362 * function.
2363 */
2364 pBusLogic->aCommandBuffer[pBusLogic->iParameter] = uVal;
2365 pBusLogic->iParameter++;
2366 pBusLogic->cbCommandParametersLeft--;
2367 }
2368
2369 /* Start execution of command if there are no parameters left. */
2370 if (!pBusLogic->cbCommandParametersLeft)
2371 {
2372 rc = buslogicProcessCommand(pBusLogic);
2373 AssertMsgRC(rc, ("Processing command failed rc=%Rrc\n", rc));
2374 }
2375 break;
2376 }
2377
2378 /* On BusLogic adapters, the interrupt and geometry registers are R/W.
2379 * That is different from Adaptec 154x where those are read only.
2380 */
2381 case BUSLOGIC_REGISTER_INTERRUPT:
2382 pBusLogic->regInterrupt = uVal;
2383 break;
2384
2385 case BUSLOGIC_REGISTER_GEOMETRY:
2386 pBusLogic->regGeometry = uVal;
2387 break;
2388
2389 default:
2390 AssertMsgFailed(("Register not available\n"));
2391 rc = VERR_IOM_IOPORT_UNUSED;
2392 }
2393
2394 return rc;
2395}
2396
2397/**
2398 * Memory mapped I/O Handler for read operations.
2399 *
2400 * @returns VBox status code.
2401 *
2402 * @param pDevIns The device instance.
2403 * @param pvUser User argument.
2404 * @param GCPhysAddr Physical address (in GC) where the read starts.
2405 * @param pv Where to store the result.
2406 * @param cb Number of bytes read.
2407 */
2408PDMBOTHCBDECL(int) buslogicMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
2409{
2410 RT_NOREF_PV(pDevIns); RT_NOREF_PV(pvUser); RT_NOREF_PV(GCPhysAddr); RT_NOREF_PV(pv); RT_NOREF_PV(cb);
2411
2412 /* the linux driver does not make use of the MMIO area. */
2413 AssertMsgFailed(("MMIO Read\n"));
2414 return VINF_SUCCESS;
2415}
2416
2417/**
2418 * Memory mapped I/O Handler for write operations.
2419 *
2420 * @returns VBox status code.
2421 *
2422 * @param pDevIns The device instance.
2423 * @param pvUser User argument.
2424 * @param GCPhysAddr Physical address (in GC) where the read starts.
2425 * @param pv Where to fetch the result.
2426 * @param cb Number of bytes to write.
2427 */
2428PDMBOTHCBDECL(int) buslogicMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
2429{
2430 RT_NOREF_PV(pDevIns); RT_NOREF_PV(pvUser); RT_NOREF_PV(GCPhysAddr); RT_NOREF_PV(pv); RT_NOREF_PV(cb);
2431
2432 /* the linux driver does not make use of the MMIO area. */
2433 AssertMsgFailed(("MMIO Write\n"));
2434 return VINF_SUCCESS;
2435}
2436
2437/**
2438 * Port I/O Handler for IN operations.
2439 *
2440 * @returns VBox status code.
2441 *
2442 * @param pDevIns The device instance.
2443 * @param pvUser User argument.
2444 * @param uPort Port number used for the IN operation.
2445 * @param pu32 Where to store the result.
2446 * @param cb Number of bytes read.
2447 */
2448PDMBOTHCBDECL(int) buslogicIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
2449{
2450 PBUSLOGIC pBusLogic = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
2451 unsigned iRegister = Port % 4;
2452 RT_NOREF_PV(pvUser); RT_NOREF_PV(cb);
2453
2454 Assert(cb == 1);
2455
2456 return buslogicRegisterRead(pBusLogic, iRegister, pu32);
2457}
2458
2459/**
2460 * Port I/O Handler for OUT operations.
2461 *
2462 * @returns VBox status code.
2463 *
2464 * @param pDevIns The device instance.
2465 * @param pvUser User argument.
2466 * @param uPort Port number used for the IN operation.
2467 * @param u32 The value to output.
2468 * @param cb The value size in bytes.
2469 */
2470PDMBOTHCBDECL(int) buslogicIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
2471{
2472 PBUSLOGIC pBusLogic = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
2473 unsigned iRegister = Port % 4;
2474 uint8_t uVal = (uint8_t)u32;
2475 RT_NOREF2(pvUser, cb);
2476
2477 Assert(cb == 1);
2478
2479 int rc = buslogicRegisterWrite(pBusLogic, iRegister, (uint8_t)uVal);
2480
2481 Log2(("#%d %s: pvUser=%#p cb=%d u32=%#x Port=%#x rc=%Rrc\n",
2482 pDevIns->iInstance, __FUNCTION__, pvUser, cb, u32, Port, rc));
2483
2484 return rc;
2485}
2486
2487#ifdef IN_RING3
2488
2489static int buslogicR3PrepareBIOSSCSIRequest(PBUSLOGIC pBusLogic)
2490{
2491 int rc;
2492 PBUSLOGICTASKSTATE pTaskState;
2493 uint32_t uTargetDevice;
2494
2495 rc = RTMemCacheAllocEx(pBusLogic->hTaskCache, (void **)&pTaskState);
2496 AssertMsgRCReturn(rc, ("Getting task from cache failed rc=%Rrc\n", rc), rc);
2497
2498 pTaskState->fBIOS = true;
2499
2500 rc = vboxscsiSetupRequest(&pBusLogic->VBoxSCSI, &pTaskState->PDMScsiRequest, &uTargetDevice);
2501 AssertMsgRCReturn(rc, ("Setting up SCSI request failed rc=%Rrc\n", rc), rc);
2502
2503 pTaskState->PDMScsiRequest.pvUser = pTaskState;
2504
2505 pTaskState->CTX_SUFF(pTargetDevice) = &pBusLogic->aDeviceStates[uTargetDevice];
2506
2507 if (!pTaskState->CTX_SUFF(pTargetDevice)->fPresent)
2508 {
2509 /* Device is not present. */
2510 AssertMsg(pTaskState->PDMScsiRequest.pbCDB[0] == SCSI_INQUIRY,
2511 ("Device is not present but command is not inquiry\n"));
2512
2513 SCSIINQUIRYDATA ScsiInquiryData;
2514
2515 memset(&ScsiInquiryData, 0, sizeof(SCSIINQUIRYDATA));
2516 ScsiInquiryData.u5PeripheralDeviceType = SCSI_INQUIRY_DATA_PERIPHERAL_DEVICE_TYPE_UNKNOWN;
2517 ScsiInquiryData.u3PeripheralQualifier = SCSI_INQUIRY_DATA_PERIPHERAL_QUALIFIER_NOT_CONNECTED_NOT_SUPPORTED;
2518
2519 memcpy(pBusLogic->VBoxSCSI.pbBuf, &ScsiInquiryData, 5);
2520
2521 rc = vboxscsiRequestFinished(&pBusLogic->VBoxSCSI, &pTaskState->PDMScsiRequest, SCSI_STATUS_OK);
2522 AssertMsgRCReturn(rc, ("Finishing BIOS SCSI request failed rc=%Rrc\n", rc), rc);
2523
2524 RTMemCacheFree(pBusLogic->hTaskCache, pTaskState);
2525 }
2526 else
2527 {
2528 LogFlowFunc(("before increment %u\n", pTaskState->CTX_SUFF(pTargetDevice)->cOutstandingRequests));
2529 ASMAtomicIncU32(&pTaskState->CTX_SUFF(pTargetDevice)->cOutstandingRequests);
2530 LogFlowFunc(("after increment %u\n", pTaskState->CTX_SUFF(pTargetDevice)->cOutstandingRequests));
2531
2532 rc = pTaskState->CTX_SUFF(pTargetDevice)->pDrvSCSIConnector->pfnSCSIRequestSend(pTaskState->CTX_SUFF(pTargetDevice)->pDrvSCSIConnector,
2533 &pTaskState->PDMScsiRequest);
2534 AssertMsgRC(rc, ("Sending request to SCSI layer failed rc=%Rrc\n", rc));
2535 }
2536
2537 return rc;
2538}
2539
2540
2541/**
2542 * Port I/O Handler for IN operations - BIOS port.
2543 *
2544 * @returns VBox status code.
2545 *
2546 * @param pDevIns The device instance.
2547 * @param pvUser User argument.
2548 * @param uPort Port number used for the IN operation.
2549 * @param pu32 Where to store the result.
2550 * @param cb Number of bytes read.
2551 */
2552static DECLCALLBACK(int) buslogicR3BiosIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
2553{
2554 int rc;
2555 PBUSLOGIC pBusLogic = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
2556
2557 Assert(cb == 1);
2558
2559 rc = vboxscsiReadRegister(&pBusLogic->VBoxSCSI, (Port - BUSLOGIC_BIOS_IO_PORT), pu32);
2560
2561 //Log2(("%s: pu32=%p:{%.*Rhxs} iRegister=%d rc=%Rrc\n",
2562 // __FUNCTION__, pu32, 1, pu32, (Port - BUSLOGIC_BIOS_IO_PORT), rc));
2563
2564 return rc;
2565}
2566
2567/**
2568 * Port I/O Handler for OUT operations - BIOS port.
2569 *
2570 * @returns VBox status code.
2571 *
2572 * @param pDevIns The device instance.
2573 * @param pvUser User argument.
2574 * @param uPort Port number used for the IN operation.
2575 * @param u32 The value to output.
2576 * @param cb The value size in bytes.
2577 */
2578static DECLCALLBACK(int) buslogicR3BiosIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
2579{
2580 int rc;
2581 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
2582
2583 Log2(("#%d %s: pvUser=%#p cb=%d u32=%#x Port=%#x\n",
2584 pDevIns->iInstance, __FUNCTION__, pvUser, cb, u32, Port));
2585
2586 /*
2587 * If there is already a request form the BIOS pending ignore this write
2588 * because it should not happen.
2589 */
2590 if (ASMAtomicReadBool(&pThis->fBiosReqPending))
2591 return VINF_SUCCESS;
2592
2593 Assert(cb == 1);
2594
2595 rc = vboxscsiWriteRegister(&pThis->VBoxSCSI, (Port - BUSLOGIC_BIOS_IO_PORT), (uint8_t)u32);
2596 if (rc == VERR_MORE_DATA)
2597 {
2598 ASMAtomicXchgBool(&pThis->fBiosReqPending, true);
2599 /* Send a notifier to the PDM queue that there are pending requests. */
2600 PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pThis->CTX_SUFF(pNotifierQueue));
2601 AssertMsg(pItem, ("Allocating item for queue failed\n"));
2602 PDMQueueInsert(pThis->CTX_SUFF(pNotifierQueue), (PPDMQUEUEITEMCORE)pItem);
2603 rc = VINF_SUCCESS;
2604 }
2605 else if (RT_FAILURE(rc))
2606 AssertMsgFailed(("Writing BIOS register failed %Rrc\n", rc));
2607
2608 return VINF_SUCCESS;
2609}
2610
2611/**
2612 * Port I/O Handler for primary port range OUT string operations.
2613 * @see FNIOMIOPORTOUTSTRING for details.
2614 */
2615static DECLCALLBACK(int) buslogicR3BiosIoPortWriteStr(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port,
2616 uint8_t const *pbSrc, uint32_t *pcTransfers, unsigned cb)
2617{
2618 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
2619 Log2(("#%d %s: pvUser=%#p cb=%d Port=%#x\n", pDevIns->iInstance, __FUNCTION__, pvUser, cb, Port));
2620
2621 /*
2622 * If there is already a request form the BIOS pending ignore this write
2623 * because it should not happen.
2624 */
2625 if (ASMAtomicReadBool(&pThis->fBiosReqPending))
2626 return VINF_SUCCESS;
2627
2628 int rc = vboxscsiWriteString(pDevIns, &pThis->VBoxSCSI, (Port - BUSLOGIC_BIOS_IO_PORT), pbSrc, pcTransfers, cb);
2629 if (rc == VERR_MORE_DATA)
2630 {
2631 ASMAtomicXchgBool(&pThis->fBiosReqPending, true);
2632 /* Send a notifier to the PDM queue that there are pending requests. */
2633 PPDMQUEUEITEMCORE pItem = PDMQueueAlloc(pThis->CTX_SUFF(pNotifierQueue));
2634 AssertMsg(pItem, ("Allocating item for queue failed\n"));
2635 PDMQueueInsert(pThis->CTX_SUFF(pNotifierQueue), (PPDMQUEUEITEMCORE)pItem);
2636 }
2637 else if (RT_FAILURE(rc))
2638 AssertMsgFailed(("Writing BIOS register failed %Rrc\n", rc));
2639
2640 return VINF_SUCCESS;
2641}
2642
2643/**
2644 * Port I/O Handler for primary port range IN string operations.
2645 * @see FNIOMIOPORTINSTRING for details.
2646 */
2647static DECLCALLBACK(int) buslogicR3BiosIoPortReadStr(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port,
2648 uint8_t *pbDst, uint32_t *pcTransfers, unsigned cb)
2649{
2650 PBUSLOGIC pBusLogic = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
2651 LogFlowFunc(("#%d %s: pvUser=%#p cb=%d Port=%#x\n", pDevIns->iInstance, __FUNCTION__, pvUser, cb, Port));
2652
2653 return vboxscsiReadString(pDevIns, &pBusLogic->VBoxSCSI, (Port - BUSLOGIC_BIOS_IO_PORT),
2654 pbDst, pcTransfers, cb);
2655}
2656
2657/**
2658 * Update the ISA I/O range.
2659 *
2660 * @returns nothing.
2661 * @param pBusLogic Pointer to the BusLogic device instance.
2662 * @param uBaseCode Encoded ISA I/O base; only low 3 bits are used.
2663 */
2664static int buslogicR3RegisterISARange(PBUSLOGIC pBusLogic, uint8_t uBaseCode)
2665{
2666 uint8_t uCode = uBaseCode & MAX_ISA_BASE;
2667 uint16_t uNewBase = g_aISABases[uCode];
2668 int rc = VINF_SUCCESS;
2669
2670 LogFlowFunc(("ISA I/O code %02X, new base %X\n", uBaseCode, uNewBase));
2671
2672 /* Check if the same port range is already registered. */
2673 if (uNewBase != pBusLogic->IOISABase)
2674 {
2675 /* Unregister the old range, if any. */
2676 if (pBusLogic->IOISABase)
2677 rc = PDMDevHlpIOPortDeregister(pBusLogic->CTX_SUFF(pDevIns), pBusLogic->IOISABase, 4);
2678
2679 if (RT_SUCCESS(rc))
2680 {
2681 pBusLogic->IOISABase = 0; /* First mark as unregistered. */
2682 pBusLogic->uISABaseCode = ISA_BASE_DISABLED;
2683
2684 if (uNewBase)
2685 {
2686 /* Register the new range if requested. */
2687 rc = PDMDevHlpIOPortRegister(pBusLogic->CTX_SUFF(pDevIns), uNewBase, 4, NULL,
2688 buslogicIOPortWrite, buslogicIOPortRead,
2689 NULL, NULL,
2690 "BusLogic ISA");
2691 if (RT_SUCCESS(rc))
2692 {
2693 pBusLogic->IOISABase = uNewBase;
2694 pBusLogic->uISABaseCode = uCode;
2695 }
2696 }
2697 }
2698 if (RT_SUCCESS(rc))
2699 {
2700 if (uNewBase)
2701 {
2702 Log(("ISA I/O base: %x\n", uNewBase));
2703 LogRel(("BusLogic: ISA I/O base: %x\n", uNewBase));
2704 }
2705 else
2706 {
2707 Log(("Disabling ISA I/O ports.\n"));
2708 LogRel(("BusLogic: ISA I/O disabled\n"));
2709 }
2710 }
2711
2712 }
2713 return rc;
2714}
2715
2716static void buslogicR3WarningDiskFull(PPDMDEVINS pDevIns)
2717{
2718 int rc;
2719 LogRel(("BusLogic#%d: Host disk full\n", pDevIns->iInstance));
2720 rc = PDMDevHlpVMSetRuntimeError(pDevIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DevBusLogic_DISKFULL",
2721 N_("Host system reported disk full. VM execution is suspended. You can resume after freeing some space"));
2722 AssertRC(rc);
2723}
2724
2725static void buslogicR3WarningFileTooBig(PPDMDEVINS pDevIns)
2726{
2727 int rc;
2728 LogRel(("BusLogic#%d: File too big\n", pDevIns->iInstance));
2729 rc = PDMDevHlpVMSetRuntimeError(pDevIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DevBusLogic_FILETOOBIG",
2730 N_("Host system reported that the file size limit of the host file system has been exceeded. VM execution is suspended. You need to move your virtual hard disk to a filesystem which allows bigger files"));
2731 AssertRC(rc);
2732}
2733
2734static void buslogicR3WarningISCSI(PPDMDEVINS pDevIns)
2735{
2736 int rc;
2737 LogRel(("BusLogic#%d: iSCSI target unavailable\n", pDevIns->iInstance));
2738 rc = PDMDevHlpVMSetRuntimeError(pDevIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DevBusLogic_ISCSIDOWN",
2739 N_("The iSCSI target has stopped responding. VM execution is suspended. You can resume when it is available again"));
2740 AssertRC(rc);
2741}
2742
2743static void buslogicR3WarningUnknown(PPDMDEVINS pDevIns, int rc)
2744{
2745 int rc2;
2746 LogRel(("BusLogic#%d: Unknown but recoverable error has occurred (rc=%Rrc)\n", pDevIns->iInstance, rc));
2747 rc2 = PDMDevHlpVMSetRuntimeError(pDevIns, VMSETRTERR_FLAGS_SUSPEND | VMSETRTERR_FLAGS_NO_WAIT, "DevBusLogic_UNKNOWN",
2748 N_("An unknown but recoverable I/O error has occurred (rc=%Rrc). VM execution is suspended. You can resume when the error is fixed"), rc);
2749 AssertRC(rc2);
2750}
2751
2752static void buslogicR3RedoSetWarning(PBUSLOGIC pThis, int rc)
2753{
2754 if (rc == VERR_DISK_FULL)
2755 buslogicR3WarningDiskFull(pThis->CTX_SUFF(pDevIns));
2756 else if (rc == VERR_FILE_TOO_BIG)
2757 buslogicR3WarningFileTooBig(pThis->CTX_SUFF(pDevIns));
2758 else if (rc == VERR_BROKEN_PIPE || rc == VERR_NET_CONNECTION_REFUSED)
2759 {
2760 /* iSCSI connection abort (first error) or failure to reestablish
2761 * connection (second error). Pause VM. On resume we'll retry. */
2762 buslogicR3WarningISCSI(pThis->CTX_SUFF(pDevIns));
2763 }
2764 else if (rc != VERR_VD_DEK_MISSING)
2765 buslogicR3WarningUnknown(pThis->CTX_SUFF(pDevIns), rc);
2766}
2767
2768
2769static DECLCALLBACK(int) buslogicR3MmioMap(PPCIDEVICE pPciDev, /*unsigned*/ int iRegion,
2770 RTGCPHYS GCPhysAddress, uint32_t cb, PCIADDRESSSPACE enmType)
2771{
2772 PPDMDEVINS pDevIns = pPciDev->pDevIns;
2773 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
2774 int rc = VINF_SUCCESS;
2775
2776 Log2(("%s: registering MMIO area at GCPhysAddr=%RGp cb=%u\n", __FUNCTION__, GCPhysAddress, cb));
2777
2778 Assert(cb >= 32);
2779
2780 if (enmType == PCI_ADDRESS_SPACE_MEM)
2781 {
2782 /* We use the assigned size here, because we currently only support page aligned MMIO ranges. */
2783 rc = PDMDevHlpMMIORegister(pDevIns, GCPhysAddress, cb, NULL /*pvUser*/,
2784 IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
2785 buslogicMMIOWrite, buslogicMMIORead, "BusLogic MMIO");
2786 if (RT_FAILURE(rc))
2787 return rc;
2788
2789 if (pThis->fR0Enabled)
2790 {
2791 rc = PDMDevHlpMMIORegisterR0(pDevIns, GCPhysAddress, cb, NIL_RTR0PTR /*pvUser*/,
2792 "buslogicMMIOWrite", "buslogicMMIORead");
2793 if (RT_FAILURE(rc))
2794 return rc;
2795 }
2796
2797 if (pThis->fGCEnabled)
2798 {
2799 rc = PDMDevHlpMMIORegisterRC(pDevIns, GCPhysAddress, cb, NIL_RTRCPTR /*pvUser*/,
2800 "buslogicMMIOWrite", "buslogicMMIORead");
2801 if (RT_FAILURE(rc))
2802 return rc;
2803 }
2804
2805 pThis->MMIOBase = GCPhysAddress;
2806 }
2807 else if (enmType == PCI_ADDRESS_SPACE_IO)
2808 {
2809 rc = PDMDevHlpIOPortRegister(pDevIns, (RTIOPORT)GCPhysAddress, 32,
2810 NULL, buslogicIOPortWrite, buslogicIOPortRead, NULL, NULL, "BusLogic PCI");
2811 if (RT_FAILURE(rc))
2812 return rc;
2813
2814 if (pThis->fR0Enabled)
2815 {
2816 rc = PDMDevHlpIOPortRegisterR0(pDevIns, (RTIOPORT)GCPhysAddress, 32,
2817 0, "buslogicIOPortWrite", "buslogicIOPortRead", NULL, NULL, "BusLogic PCI");
2818 if (RT_FAILURE(rc))
2819 return rc;
2820 }
2821
2822 if (pThis->fGCEnabled)
2823 {
2824 rc = PDMDevHlpIOPortRegisterRC(pDevIns, (RTIOPORT)GCPhysAddress, 32,
2825 0, "buslogicIOPortWrite", "buslogicIOPortRead", NULL, NULL, "BusLogic PCI");
2826 if (RT_FAILURE(rc))
2827 return rc;
2828 }
2829
2830 pThis->IOPortBase = (RTIOPORT)GCPhysAddress;
2831 }
2832 else
2833 AssertMsgFailed(("Invalid enmType=%d\n", enmType));
2834
2835 return rc;
2836}
2837
2838static DECLCALLBACK(int) buslogicR3DeviceSCSIRequestCompleted(PPDMISCSIPORT pInterface, PPDMSCSIREQUEST pSCSIRequest,
2839 int rcCompletion, bool fRedo, int rcReq)
2840{
2841 int rc;
2842 PBUSLOGICTASKSTATE pTaskState = (PBUSLOGICTASKSTATE)pSCSIRequest->pvUser;
2843 PBUSLOGICDEVICE pBusLogicDevice = pTaskState->CTX_SUFF(pTargetDevice);
2844 PBUSLOGIC pBusLogic = pBusLogicDevice->CTX_SUFF(pBusLogic);
2845
2846 LogFlowFunc(("before decrement %u\n", pBusLogicDevice->cOutstandingRequests));
2847 ASMAtomicDecU32(&pBusLogicDevice->cOutstandingRequests);
2848 LogFlowFunc(("after decrement %u\n", pBusLogicDevice->cOutstandingRequests));
2849
2850 if (fRedo)
2851 {
2852 if (!pTaskState->fBIOS)
2853 {
2854 buslogicR3DataBufferFree(pTaskState);
2855
2856 if (pTaskState->pbSenseBuffer)
2857 buslogicR3SenseBufferFree(pTaskState, false /* fCopy */);
2858 }
2859
2860 /* Add to the list. */
2861 do
2862 {
2863 pTaskState->pRedoNext = ASMAtomicReadPtrT(&pBusLogic->pTasksRedoHead, PBUSLOGICTASKSTATE);
2864 } while (!ASMAtomicCmpXchgPtr(&pBusLogic->pTasksRedoHead, pTaskState, pTaskState->pRedoNext));
2865
2866 /* Suspend the VM if not done already. */
2867 if (!ASMAtomicXchgBool(&pBusLogic->fRedo, true))
2868 buslogicR3RedoSetWarning(pBusLogic, rcReq);
2869 }
2870 else
2871 {
2872 if (pTaskState->fBIOS)
2873 {
2874 rc = vboxscsiRequestFinished(&pBusLogic->VBoxSCSI, pSCSIRequest, rcCompletion);
2875 AssertMsgRC(rc, ("Finishing BIOS SCSI request failed rc=%Rrc\n", rc));
2876 }
2877 else
2878 {
2879 buslogicR3DataBufferFree(pTaskState);
2880
2881 if (pTaskState->pbSenseBuffer)
2882 buslogicR3SenseBufferFree(pTaskState, (rcCompletion != SCSI_STATUS_OK));
2883
2884 if (rcCompletion == SCSI_STATUS_OK)
2885 buslogicR3SendIncomingMailbox(pBusLogic, pTaskState,
2886 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_CMD_COMPLETED,
2887 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
2888 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITHOUT_ERROR);
2889 else if (rcCompletion == SCSI_STATUS_CHECK_CONDITION)
2890 buslogicR3SendIncomingMailbox(pBusLogic, pTaskState,
2891 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_CMD_COMPLETED,
2892 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_CHECK_CONDITION,
2893 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITH_ERROR);
2894 else
2895 AssertMsgFailed(("invalid completion status %d\n", rcCompletion));
2896 }
2897#ifdef LOG_ENABLED
2898 buslogicR3DumpCCBInfo(&pTaskState->CommandControlBlockGuest, pTaskState->fIs24Bit);
2899#endif
2900
2901 /* Remove task from the cache. */
2902 RTMemCacheFree(pBusLogic->hTaskCache, pTaskState);
2903 }
2904
2905 if (pBusLogicDevice->cOutstandingRequests == 0 && pBusLogic->fSignalIdle)
2906 PDMDevHlpAsyncNotificationCompleted(pBusLogic->pDevInsR3);
2907
2908 return VINF_SUCCESS;
2909}
2910
2911static DECLCALLBACK(int) buslogicR3QueryDeviceLocation(PPDMISCSIPORT pInterface, const char **ppcszController,
2912 uint32_t *piInstance, uint32_t *piLUN)
2913{
2914 PBUSLOGICDEVICE pBusLogicDevice = PDMISCSIPORT_2_PBUSLOGICDEVICE(pInterface);
2915 PPDMDEVINS pDevIns = pBusLogicDevice->CTX_SUFF(pBusLogic)->CTX_SUFF(pDevIns);
2916
2917 AssertPtrReturn(ppcszController, VERR_INVALID_POINTER);
2918 AssertPtrReturn(piInstance, VERR_INVALID_POINTER);
2919 AssertPtrReturn(piLUN, VERR_INVALID_POINTER);
2920
2921 *ppcszController = pDevIns->pReg->szName;
2922 *piInstance = pDevIns->iInstance;
2923 *piLUN = pBusLogicDevice->iLUN;
2924
2925 return VINF_SUCCESS;
2926}
2927
2928static int buslogicR3DeviceSCSIRequestSetup(PBUSLOGIC pBusLogic, PBUSLOGICTASKSTATE pTaskState)
2929{
2930 int rc = VINF_SUCCESS;
2931 uint8_t uTargetIdCCB;
2932 PBUSLOGICDEVICE pTargetDevice;
2933
2934 /* Fetch the CCB from guest memory. */
2935 /** @todo How much do we really have to read? */
2936 RTGCPHYS GCPhysAddrCCB = (RTGCPHYS)pTaskState->MailboxGuest.u32PhysAddrCCB;
2937 PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrCCB,
2938 &pTaskState->CommandControlBlockGuest, sizeof(CCB32));
2939
2940 uTargetIdCCB = pTaskState->fIs24Bit ? pTaskState->CommandControlBlockGuest.o.uTargetId : pTaskState->CommandControlBlockGuest.n.uTargetId;
2941 if (RT_LIKELY(uTargetIdCCB < RT_ELEMENTS(pBusLogic->aDeviceStates)))
2942 {
2943 pTargetDevice = &pBusLogic->aDeviceStates[uTargetIdCCB];
2944 pTaskState->CTX_SUFF(pTargetDevice) = pTargetDevice;
2945
2946#ifdef LOG_ENABLED
2947 buslogicR3DumpCCBInfo(&pTaskState->CommandControlBlockGuest, pTaskState->fIs24Bit);
2948#endif
2949
2950 /* Alloc required buffers. */
2951 rc = buslogicR3DataBufferAlloc(pTaskState);
2952 AssertMsgRC(rc, ("Alloc failed rc=%Rrc\n", rc));
2953
2954 rc = buslogicR3SenseBufferAlloc(pTaskState);
2955 AssertMsgRC(rc, ("Mapping sense buffer failed rc=%Rrc\n", rc));
2956
2957 /* Check if device is present on bus. If not return error immediately and don't process this further. */
2958 if (!pBusLogic->aDeviceStates[uTargetIdCCB].fPresent)
2959 {
2960 buslogicR3DataBufferFree(pTaskState);
2961
2962 if (pTaskState->pbSenseBuffer)
2963 buslogicR3SenseBufferFree(pTaskState, true);
2964
2965 buslogicR3SendIncomingMailbox(pBusLogic, pTaskState,
2966 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_SCSI_SELECTION_TIMEOUT,
2967 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
2968 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITH_ERROR);
2969
2970 RTMemCacheFree(pBusLogic->hTaskCache, pTaskState);
2971 }
2972 else
2973 {
2974 /* Setup SCSI request. */
2975 pTaskState->PDMScsiRequest.uLogicalUnit = pTaskState->fIs24Bit ? pTaskState->CommandControlBlockGuest.o.uLogicalUnit
2976 : pTaskState->CommandControlBlockGuest.n.uLogicalUnit;
2977
2978 if (pTaskState->CommandControlBlockGuest.c.uDataDirection == BUSLOGIC_CCB_DIRECTION_UNKNOWN)
2979 pTaskState->PDMScsiRequest.uDataDirection = PDMSCSIREQUESTTXDIR_UNKNOWN;
2980 else if (pTaskState->CommandControlBlockGuest.c.uDataDirection == BUSLOGIC_CCB_DIRECTION_IN)
2981 pTaskState->PDMScsiRequest.uDataDirection = PDMSCSIREQUESTTXDIR_FROM_DEVICE;
2982 else if (pTaskState->CommandControlBlockGuest.c.uDataDirection == BUSLOGIC_CCB_DIRECTION_OUT)
2983 pTaskState->PDMScsiRequest.uDataDirection = PDMSCSIREQUESTTXDIR_TO_DEVICE;
2984 else if (pTaskState->CommandControlBlockGuest.c.uDataDirection == BUSLOGIC_CCB_DIRECTION_NO_DATA)
2985 pTaskState->PDMScsiRequest.uDataDirection = PDMSCSIREQUESTTXDIR_NONE;
2986 else
2987 AssertMsgFailed(("Invalid data direction type %d\n", pTaskState->CommandControlBlockGuest.c.uDataDirection));
2988
2989 pTaskState->PDMScsiRequest.cbCDB = pTaskState->CommandControlBlockGuest.c.cbCDB;
2990 pTaskState->PDMScsiRequest.pbCDB = pTaskState->CommandControlBlockGuest.c.abCDB;
2991 if (pTaskState->DataSeg.cbSeg)
2992 {
2993 pTaskState->PDMScsiRequest.cbScatterGather = pTaskState->DataSeg.cbSeg;
2994 pTaskState->PDMScsiRequest.cScatterGatherEntries = 1;
2995 pTaskState->PDMScsiRequest.paScatterGatherHead = &pTaskState->DataSeg;
2996 }
2997 else
2998 {
2999 pTaskState->PDMScsiRequest.cbScatterGather = 0;
3000 pTaskState->PDMScsiRequest.cScatterGatherEntries = 0;
3001 pTaskState->PDMScsiRequest.paScatterGatherHead = NULL;
3002 }
3003 pTaskState->PDMScsiRequest.cbSenseBuffer = buslogicR3ConvertSenseBufferLength(pTaskState->CommandControlBlockGuest.c.cbSenseData);
3004 pTaskState->PDMScsiRequest.pbSenseBuffer = pTaskState->pbSenseBuffer;
3005 pTaskState->PDMScsiRequest.pvUser = pTaskState;
3006
3007 ASMAtomicIncU32(&pTargetDevice->cOutstandingRequests);
3008 rc = pTargetDevice->pDrvSCSIConnector->pfnSCSIRequestSend(pTargetDevice->pDrvSCSIConnector, &pTaskState->PDMScsiRequest);
3009 AssertMsgRC(rc, ("Sending request to SCSI layer failed rc=%Rrc\n", rc));
3010 }
3011 }
3012 else
3013 {
3014 RTMemCacheFree(pBusLogic->hTaskCache, pTaskState);
3015
3016 buslogicR3SendIncomingMailbox(pBusLogic, pTaskState,
3017 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_INVALID_COMMAND_PARAMETER,
3018 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
3019 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITH_ERROR);
3020 }
3021
3022 return rc;
3023}
3024
3025static int buslogicR3DeviceSCSIRequestAbort(PBUSLOGIC pBusLogic, PBUSLOGICTASKSTATE pTaskState)
3026{
3027 int rc = VINF_SUCCESS;
3028 uint8_t uTargetIdCCB;
3029 PBUSLOGICDEVICE pTargetDevice;
3030 RTGCPHYS GCPhysAddrCCB = (RTGCPHYS)pTaskState->MailboxGuest.u32PhysAddrCCB;
3031
3032 PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrCCB,
3033 &pTaskState->CommandControlBlockGuest, sizeof(CCB32));
3034
3035 uTargetIdCCB = pTaskState->fIs24Bit ? pTaskState->CommandControlBlockGuest.o.uTargetId : pTaskState->CommandControlBlockGuest.n.uTargetId;
3036 if (RT_LIKELY(uTargetIdCCB < RT_ELEMENTS(pBusLogic->aDeviceStates)))
3037 {
3038 pTargetDevice = &pBusLogic->aDeviceStates[uTargetIdCCB];
3039 pTaskState->CTX_SUFF(pTargetDevice) = pTargetDevice;
3040
3041 buslogicR3SendIncomingMailbox(pBusLogic, pTaskState,
3042 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_ABORT_QUEUE_GENERATED,
3043 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
3044 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_ABORTED_NOT_FOUND);
3045
3046 RTMemCacheFree(pBusLogic->hTaskCache, pTaskState);
3047 }
3048 else
3049 {
3050 RTMemCacheFree(pBusLogic->hTaskCache, pTaskState);
3051
3052 buslogicR3SendIncomingMailbox(pBusLogic, pTaskState,
3053 BUSLOGIC_MAILBOX_INCOMING_ADAPTER_STATUS_INVALID_COMMAND_PARAMETER,
3054 BUSLOGIC_MAILBOX_INCOMING_DEVICE_STATUS_OPERATION_GOOD,
3055 BUSLOGIC_MAILBOX_INCOMING_COMPLETION_WITH_ERROR);
3056 }
3057
3058 return rc;
3059}
3060
3061/**
3062 * Read a mailbox from guest memory. Convert 24-bit mailboxes to
3063 * 32-bit format.
3064 *
3065 * @returns Mailbox guest physical address.
3066 * @param pBusLogic Pointer to the BusLogic instance data.
3067 * @param pTaskStat Pointer to the task state being set up.
3068 */
3069static RTGCPHYS buslogicR3ReadOutgoingMailbox(PBUSLOGIC pBusLogic, PBUSLOGICTASKSTATE pTaskState)
3070{
3071 RTGCPHYS GCMailbox;
3072
3073 if (pBusLogic->fMbxIs24Bit)
3074 {
3075 Mailbox24 Mbx24;
3076
3077 GCMailbox = pBusLogic->GCPhysAddrMailboxOutgoingBase + (pBusLogic->uMailboxOutgoingPositionCurrent * sizeof(Mailbox24));
3078 PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCMailbox, &Mbx24, sizeof(Mailbox24));
3079 pTaskState->MailboxGuest.u32PhysAddrCCB = ADDR_TO_U32(Mbx24.aPhysAddrCCB);
3080 pTaskState->MailboxGuest.u.out.uActionCode = Mbx24.uCmdState;
3081 }
3082 else
3083 {
3084 GCMailbox = pBusLogic->GCPhysAddrMailboxOutgoingBase + (pBusLogic->uMailboxOutgoingPositionCurrent * sizeof(Mailbox32));
3085 PDMDevHlpPhysRead(pBusLogic->CTX_SUFF(pDevIns), GCMailbox, &pTaskState->MailboxGuest, sizeof(Mailbox32));
3086 }
3087
3088 return GCMailbox;
3089}
3090
3091/**
3092 * Read mailbox from the guest and execute command.
3093 *
3094 * @returns VBox status code.
3095 * @param pBusLogic Pointer to the BusLogic instance data.
3096 */
3097static int buslogicR3ProcessMailboxNext(PBUSLOGIC pBusLogic)
3098{
3099 PBUSLOGICTASKSTATE pTaskState = NULL;
3100 RTGCPHYS GCPhysAddrMailboxCurrent;
3101 int rc;
3102
3103 rc = RTMemCacheAllocEx(pBusLogic->hTaskCache, (void **)&pTaskState);
3104 AssertMsgReturn(RT_SUCCESS(rc) && (pTaskState != NULL), ("Failed to get task state from cache\n"), rc);
3105
3106 pTaskState->fBIOS = false;
3107 pTaskState->fIs24Bit = pBusLogic->fMbxIs24Bit;
3108 pTaskState->cbSGEntry = pBusLogic->fMbxIs24Bit ? sizeof(SGE24) : sizeof(SGE32);
3109
3110 if (!pBusLogic->fStrictRoundRobinMode)
3111 {
3112 /* Search for a filled mailbox - stop if we have scanned all mailboxes. */
3113 uint8_t uMailboxPosCur = pBusLogic->uMailboxOutgoingPositionCurrent;
3114
3115 do
3116 {
3117 /* Fetch mailbox from guest memory. */
3118 GCPhysAddrMailboxCurrent = buslogicR3ReadOutgoingMailbox(pBusLogic,pTaskState);
3119
3120 /* Check the next mailbox. */
3121 buslogicR3OutgoingMailboxAdvance(pBusLogic);
3122 } while ( pTaskState->MailboxGuest.u.out.uActionCode == BUSLOGIC_MAILBOX_OUTGOING_ACTION_FREE
3123 && uMailboxPosCur != pBusLogic->uMailboxOutgoingPositionCurrent);
3124 }
3125 else
3126 {
3127 /* Fetch mailbox from guest memory. */
3128 GCPhysAddrMailboxCurrent = buslogicR3ReadOutgoingMailbox(pBusLogic,pTaskState);
3129 }
3130
3131 /*
3132 * Check if the mailbox is actually loaded.
3133 * It might be possible that the guest notified us without
3134 * a loaded mailbox. Do nothing in that case but leave a
3135 * log entry.
3136 */
3137 if (pTaskState->MailboxGuest.u.out.uActionCode == BUSLOGIC_MAILBOX_OUTGOING_ACTION_FREE)
3138 {
3139 Log(("No loaded mailbox left\n"));
3140 RTMemCacheFree(pBusLogic->hTaskCache, pTaskState);
3141 return VERR_NO_DATA;
3142 }
3143
3144 LogFlow(("Got loaded mailbox at slot %u, CCB phys %RGp\n", pBusLogic->uMailboxOutgoingPositionCurrent, (RTGCPHYS)pTaskState->MailboxGuest.u32PhysAddrCCB));
3145#ifdef LOG_ENABLED
3146 buslogicR3DumpMailboxInfo(&pTaskState->MailboxGuest, true);
3147#endif
3148
3149 /* We got the mailbox, mark it as free in the guest. */
3150 uint8_t uActionCode = BUSLOGIC_MAILBOX_OUTGOING_ACTION_FREE;
3151 unsigned uCodeOffs = pTaskState->fIs24Bit ? RT_OFFSETOF(Mailbox24, uCmdState) : RT_OFFSETOF(Mailbox32, u.out.uActionCode);
3152 PDMDevHlpPCIPhysWrite(pBusLogic->CTX_SUFF(pDevIns), GCPhysAddrMailboxCurrent + uCodeOffs, &uActionCode, sizeof(uActionCode));
3153
3154 if (pTaskState->MailboxGuest.u.out.uActionCode == BUSLOGIC_MAILBOX_OUTGOING_ACTION_START_COMMAND)
3155 rc = buslogicR3DeviceSCSIRequestSetup(pBusLogic, pTaskState);
3156 else if (pTaskState->MailboxGuest.u.out.uActionCode == BUSLOGIC_MAILBOX_OUTGOING_ACTION_ABORT_COMMAND)
3157 {
3158 LogFlow(("Aborting mailbox\n"));
3159 rc = buslogicR3DeviceSCSIRequestAbort(pBusLogic, pTaskState);
3160 }
3161 else
3162 AssertMsgFailed(("Invalid outgoing mailbox action code %u\n", pTaskState->MailboxGuest.u.out.uActionCode));
3163
3164 AssertRC(rc);
3165
3166 /* Advance to the next mailbox. */
3167 if (pBusLogic->fStrictRoundRobinMode)
3168 buslogicR3OutgoingMailboxAdvance(pBusLogic);
3169
3170 return rc;
3171}
3172
3173/**
3174 * Transmit queue consumer
3175 * Queue a new async task.
3176 *
3177 * @returns Success indicator.
3178 * If false the item will not be removed and the flushing will stop.
3179 * @param pDevIns The device instance.
3180 * @param pItem The item to consume. Upon return this item will be freed.
3181 */
3182static DECLCALLBACK(bool) buslogicR3NotifyQueueConsumer(PPDMDEVINS pDevIns, PPDMQUEUEITEMCORE pItem)
3183{
3184 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3185
3186 int rc = SUPSemEventSignal(pThis->pSupDrvSession, pThis->hEvtProcess);
3187 AssertRC(rc);
3188
3189 return true;
3190}
3191
3192/**
3193 * Kicks the controller to process pending tasks after the VM was resumed
3194 * or loaded from a saved state.
3195 *
3196 * @returns nothing.
3197 * @param pThis The BusLogic device instance.
3198 */
3199static void buslogicR3Kick(PBUSLOGIC pThis)
3200{
3201 if (pThis->fRedo)
3202 {
3203 pThis->fRedo = false;
3204 if (pThis->VBoxSCSI.fBusy)
3205 {
3206
3207 /* The BIOS had a request active when we got suspended. Resume it. */
3208 int rc = buslogicR3PrepareBIOSSCSIRequest(pThis);
3209 AssertRC(rc);
3210 }
3211 else
3212 {
3213 /* Queue all pending tasks again. */
3214 PBUSLOGICTASKSTATE pTaskState = pThis->pTasksRedoHead;
3215
3216 pThis->pTasksRedoHead = NULL;
3217
3218 while (pTaskState)
3219 {
3220 PBUSLOGICTASKSTATE pCur = pTaskState;
3221
3222 int rc = buslogicR3DeviceSCSIRequestSetup(pThis, pCur);
3223 AssertRC(rc);
3224
3225 pTaskState = pTaskState->pRedoNext;
3226 }
3227 }
3228 }
3229}
3230
3231/** @callback_method_impl{FNSSMDEVLIVEEXEC} */
3232static DECLCALLBACK(int) buslogicR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
3233{
3234 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3235
3236 /* Save the device config. */
3237 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aDeviceStates); i++)
3238 SSMR3PutBool(pSSM, pThis->aDeviceStates[i].fPresent);
3239
3240 return VINF_SSM_DONT_CALL_AGAIN;
3241}
3242
3243/** @callback_method_impl{FNSSMDEVSAVEEXEC} */
3244static DECLCALLBACK(int) buslogicR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
3245{
3246 PBUSLOGIC pBusLogic = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3247
3248 /* Every device first. */
3249 for (unsigned i = 0; i < RT_ELEMENTS(pBusLogic->aDeviceStates); i++)
3250 {
3251 PBUSLOGICDEVICE pDevice = &pBusLogic->aDeviceStates[i];
3252
3253 AssertMsg(!pDevice->cOutstandingRequests,
3254 ("There are still outstanding requests on this device\n"));
3255 SSMR3PutBool(pSSM, pDevice->fPresent);
3256 SSMR3PutU32(pSSM, pDevice->cOutstandingRequests);
3257 }
3258 /* Now the main device state. */
3259 SSMR3PutU8 (pSSM, pBusLogic->regStatus);
3260 SSMR3PutU8 (pSSM, pBusLogic->regInterrupt);
3261 SSMR3PutU8 (pSSM, pBusLogic->regGeometry);
3262 SSMR3PutMem (pSSM, &pBusLogic->LocalRam, sizeof(pBusLogic->LocalRam));
3263 SSMR3PutU8 (pSSM, pBusLogic->uOperationCode);
3264 SSMR3PutMem (pSSM, &pBusLogic->aCommandBuffer, sizeof(pBusLogic->aCommandBuffer));
3265 SSMR3PutU8 (pSSM, pBusLogic->iParameter);
3266 SSMR3PutU8 (pSSM, pBusLogic->cbCommandParametersLeft);
3267 SSMR3PutBool (pSSM, pBusLogic->fUseLocalRam);
3268 SSMR3PutMem (pSSM, pBusLogic->aReplyBuffer, sizeof(pBusLogic->aReplyBuffer));
3269 SSMR3PutU8 (pSSM, pBusLogic->iReply);
3270 SSMR3PutU8 (pSSM, pBusLogic->cbReplyParametersLeft);
3271 SSMR3PutBool (pSSM, pBusLogic->fIRQEnabled);
3272 SSMR3PutU8 (pSSM, pBusLogic->uISABaseCode);
3273 SSMR3PutU32 (pSSM, pBusLogic->cMailbox);
3274 SSMR3PutBool (pSSM, pBusLogic->fMbxIs24Bit);
3275 SSMR3PutGCPhys(pSSM, pBusLogic->GCPhysAddrMailboxOutgoingBase);
3276 SSMR3PutU32 (pSSM, pBusLogic->uMailboxOutgoingPositionCurrent);
3277 SSMR3PutU32 (pSSM, pBusLogic->cMailboxesReady);
3278 SSMR3PutBool (pSSM, pBusLogic->fNotificationSent);
3279 SSMR3PutGCPhys(pSSM, pBusLogic->GCPhysAddrMailboxIncomingBase);
3280 SSMR3PutU32 (pSSM, pBusLogic->uMailboxIncomingPositionCurrent);
3281 SSMR3PutBool (pSSM, pBusLogic->fStrictRoundRobinMode);
3282 SSMR3PutBool (pSSM, pBusLogic->fExtendedLunCCBFormat);
3283
3284 vboxscsiR3SaveExec(&pBusLogic->VBoxSCSI, pSSM);
3285
3286 /*
3287 * Save the physical addresses of the command control blocks of still pending tasks.
3288 * They are processed again on resume.
3289 *
3290 * The number of pending tasks needs to be determined first.
3291 */
3292 uint32_t cTasks = 0;
3293
3294 PBUSLOGICTASKSTATE pTaskState = pBusLogic->pTasksRedoHead;
3295 if (pBusLogic->fRedo)
3296 {
3297 while (pTaskState)
3298 {
3299 cTasks++;
3300 pTaskState = pTaskState->pRedoNext;
3301 }
3302 }
3303 SSMR3PutU32(pSSM, cTasks);
3304
3305 /* Write the address of every task now. */
3306 pTaskState = pBusLogic->pTasksRedoHead;
3307 while (pTaskState)
3308 {
3309 SSMR3PutU32(pSSM, pTaskState->MailboxGuest.u32PhysAddrCCB);
3310 pTaskState = pTaskState->pRedoNext;
3311 }
3312
3313 return SSMR3PutU32(pSSM, ~0);
3314}
3315
3316/** @callback_method_impl{FNSSMDEVLOADDONE} */
3317static DECLCALLBACK(int) buslogicR3LoadDone(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
3318{
3319 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3320
3321 buslogicR3RegisterISARange(pThis, pThis->uISABaseCode);
3322 buslogicR3Kick(pThis);
3323 return VINF_SUCCESS;
3324}
3325
3326/** @callback_method_impl{FNSSMDEVLOADEXEC} */
3327static DECLCALLBACK(int) buslogicR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
3328{
3329 PBUSLOGIC pBusLogic = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3330 int rc = VINF_SUCCESS;
3331
3332 /* We support saved states only from this and older versions. */
3333 if (uVersion > BUSLOGIC_SAVED_STATE_MINOR_VERSION)
3334 return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
3335
3336 /* Every device first. */
3337 for (unsigned i = 0; i < RT_ELEMENTS(pBusLogic->aDeviceStates); i++)
3338 {
3339 PBUSLOGICDEVICE pDevice = &pBusLogic->aDeviceStates[i];
3340
3341 AssertMsg(!pDevice->cOutstandingRequests,
3342 ("There are still outstanding requests on this device\n"));
3343 bool fPresent;
3344 rc = SSMR3GetBool(pSSM, &fPresent);
3345 AssertRCReturn(rc, rc);
3346 if (pDevice->fPresent != fPresent)
3347 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Target %u config mismatch: config=%RTbool state=%RTbool"), i, pDevice->fPresent, fPresent);
3348
3349 if (uPass == SSM_PASS_FINAL)
3350 SSMR3GetU32(pSSM, (uint32_t *)&pDevice->cOutstandingRequests);
3351 }
3352
3353 if (uPass != SSM_PASS_FINAL)
3354 return VINF_SUCCESS;
3355
3356 /* Now the main device state. */
3357 SSMR3GetU8 (pSSM, (uint8_t *)&pBusLogic->regStatus);
3358 SSMR3GetU8 (pSSM, (uint8_t *)&pBusLogic->regInterrupt);
3359 SSMR3GetU8 (pSSM, (uint8_t *)&pBusLogic->regGeometry);
3360 SSMR3GetMem (pSSM, &pBusLogic->LocalRam, sizeof(pBusLogic->LocalRam));
3361 SSMR3GetU8 (pSSM, &pBusLogic->uOperationCode);
3362 if (uVersion > BUSLOGIC_SAVED_STATE_MINOR_PRE_CMDBUF_RESIZE)
3363 SSMR3GetMem (pSSM, &pBusLogic->aCommandBuffer, sizeof(pBusLogic->aCommandBuffer));
3364 else
3365 SSMR3GetMem (pSSM, &pBusLogic->aCommandBuffer, BUSLOGIC_COMMAND_SIZE_OLD);
3366 SSMR3GetU8 (pSSM, &pBusLogic->iParameter);
3367 SSMR3GetU8 (pSSM, &pBusLogic->cbCommandParametersLeft);
3368 SSMR3GetBool (pSSM, &pBusLogic->fUseLocalRam);
3369 SSMR3GetMem (pSSM, pBusLogic->aReplyBuffer, sizeof(pBusLogic->aReplyBuffer));
3370 SSMR3GetU8 (pSSM, &pBusLogic->iReply);
3371 SSMR3GetU8 (pSSM, &pBusLogic->cbReplyParametersLeft);
3372 SSMR3GetBool (pSSM, &pBusLogic->fIRQEnabled);
3373 SSMR3GetU8 (pSSM, &pBusLogic->uISABaseCode);
3374 SSMR3GetU32 (pSSM, &pBusLogic->cMailbox);
3375 if (uVersion > BUSLOGIC_SAVED_STATE_MINOR_PRE_24BIT_MBOX)
3376 SSMR3GetBool (pSSM, &pBusLogic->fMbxIs24Bit);
3377 SSMR3GetGCPhys(pSSM, &pBusLogic->GCPhysAddrMailboxOutgoingBase);
3378 SSMR3GetU32 (pSSM, &pBusLogic->uMailboxOutgoingPositionCurrent);
3379 SSMR3GetU32 (pSSM, (uint32_t *)&pBusLogic->cMailboxesReady);
3380 SSMR3GetBool (pSSM, (bool *)&pBusLogic->fNotificationSent);
3381 SSMR3GetGCPhys(pSSM, &pBusLogic->GCPhysAddrMailboxIncomingBase);
3382 SSMR3GetU32 (pSSM, &pBusLogic->uMailboxIncomingPositionCurrent);
3383 SSMR3GetBool (pSSM, &pBusLogic->fStrictRoundRobinMode);
3384 SSMR3GetBool (pSSM, &pBusLogic->fExtendedLunCCBFormat);
3385
3386 rc = vboxscsiR3LoadExec(&pBusLogic->VBoxSCSI, pSSM);
3387 if (RT_FAILURE(rc))
3388 {
3389 LogRel(("BusLogic: Failed to restore BIOS state: %Rrc.\n", rc));
3390 return PDMDEV_SET_ERROR(pDevIns, rc,
3391 N_("BusLogic: Failed to restore BIOS state\n"));
3392 }
3393
3394 if (pBusLogic->VBoxSCSI.fBusy)
3395 pBusLogic->fRedo = true;
3396
3397 if (uVersion > BUSLOGIC_SAVED_STATE_MINOR_PRE_ERROR_HANDLING)
3398 {
3399 /* Check if there are pending tasks saved. */
3400 uint32_t cTasks = 0;
3401
3402 SSMR3GetU32(pSSM, &cTasks);
3403
3404 if (cTasks)
3405 pBusLogic->fRedo = true;
3406
3407 for (uint32_t i = 0; i < cTasks; i++)
3408 {
3409 PBUSLOGICTASKSTATE pTaskState = (PBUSLOGICTASKSTATE)RTMemCacheAlloc(pBusLogic->hTaskCache);
3410 if (!pTaskState)
3411 {
3412 rc = VERR_NO_MEMORY;
3413 break;
3414 }
3415
3416 rc = SSMR3GetU32(pSSM, &pTaskState->MailboxGuest.u32PhysAddrCCB);
3417 if (RT_FAILURE(rc))
3418 {
3419 RTMemCacheFree(pBusLogic->hTaskCache, pTaskState);
3420 break;
3421 }
3422
3423 /* Link into the list. */
3424 pTaskState->pRedoNext = pBusLogic->pTasksRedoHead;
3425 pBusLogic->pTasksRedoHead = pTaskState;
3426 }
3427 }
3428
3429 if (RT_SUCCESS(rc))
3430 {
3431 uint32_t u32;
3432 rc = SSMR3GetU32(pSSM, &u32);
3433 if (RT_SUCCESS(rc))
3434 AssertMsgReturn(u32 == ~0U, ("%#x\n", u32), VERR_SSM_DATA_UNIT_FORMAT_CHANGED);
3435 }
3436
3437 return rc;
3438}
3439
3440/**
3441 * Gets the pointer to the status LED of a device - called from the SCSI driver.
3442 *
3443 * @returns VBox status code.
3444 * @param pInterface Pointer to the interface structure containing the called function pointer.
3445 * @param iLUN The unit which status LED we desire. Always 0 here as the driver
3446 * doesn't know about other LUN's.
3447 * @param ppLed Where to store the LED pointer.
3448 */
3449static DECLCALLBACK(int) buslogicR3DeviceQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
3450{
3451 PBUSLOGICDEVICE pDevice = PDMILEDPORTS_2_PBUSLOGICDEVICE(pInterface);
3452 if (iLUN == 0)
3453 {
3454 *ppLed = &pDevice->Led;
3455 Assert((*ppLed)->u32Magic == PDMLED_MAGIC);
3456 return VINF_SUCCESS;
3457 }
3458 return VERR_PDM_LUN_NOT_FOUND;
3459}
3460
3461/**
3462 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
3463 */
3464static DECLCALLBACK(void *) buslogicR3DeviceQueryInterface(PPDMIBASE pInterface, const char *pszIID)
3465{
3466 PBUSLOGICDEVICE pDevice = PDMIBASE_2_PBUSLOGICDEVICE(pInterface);
3467 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDevice->IBase);
3468 PDMIBASE_RETURN_INTERFACE(pszIID, PDMISCSIPORT, &pDevice->ISCSIPort);
3469 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pDevice->ILed);
3470 return NULL;
3471}
3472
3473/**
3474 * Gets the pointer to the status LED of a unit.
3475 *
3476 * @returns VBox status code.
3477 * @param pInterface Pointer to the interface structure containing the called function pointer.
3478 * @param iLUN The unit which status LED we desire.
3479 * @param ppLed Where to store the LED pointer.
3480 */
3481static DECLCALLBACK(int) buslogicR3StatusQueryStatusLed(PPDMILEDPORTS pInterface, unsigned iLUN, PPDMLED *ppLed)
3482{
3483 PBUSLOGIC pBusLogic = PDMILEDPORTS_2_PBUSLOGIC(pInterface);
3484 if (iLUN < BUSLOGIC_MAX_DEVICES)
3485 {
3486 *ppLed = &pBusLogic->aDeviceStates[iLUN].Led;
3487 Assert((*ppLed)->u32Magic == PDMLED_MAGIC);
3488 return VINF_SUCCESS;
3489 }
3490 return VERR_PDM_LUN_NOT_FOUND;
3491}
3492
3493/**
3494 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
3495 */
3496static DECLCALLBACK(void *) buslogicR3StatusQueryInterface(PPDMIBASE pInterface, const char *pszIID)
3497{
3498 PBUSLOGIC pThis = PDMIBASE_2_PBUSLOGIC(pInterface);
3499 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->IBase);
3500 PDMIBASE_RETURN_INTERFACE(pszIID, PDMILEDPORTS, &pThis->ILeds);
3501 return NULL;
3502}
3503
3504/**
3505 * The worker thread processing requests from the guest.
3506 *
3507 * @returns VBox status code.
3508 * @param pDevIns The device instance.
3509 * @param pThread The thread structure.
3510 */
3511static DECLCALLBACK(int) buslogicR3Worker(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
3512{
3513 PBUSLOGIC pThis = (PBUSLOGIC)pThread->pvUser;
3514 int rc = VINF_SUCCESS;
3515
3516 if (pThread->enmState == PDMTHREADSTATE_INITIALIZING)
3517 return VINF_SUCCESS;
3518
3519 while (pThread->enmState == PDMTHREADSTATE_RUNNING)
3520 {
3521 ASMAtomicWriteBool(&pThis->fWrkThreadSleeping, true);
3522 bool fNotificationSent = ASMAtomicXchgBool(&pThis->fNotificationSent, false);
3523 if (!fNotificationSent)
3524 {
3525 Assert(ASMAtomicReadBool(&pThis->fWrkThreadSleeping));
3526 rc = SUPSemEventWaitNoResume(pThis->pSupDrvSession, pThis->hEvtProcess, RT_INDEFINITE_WAIT);
3527 AssertLogRelMsgReturn(RT_SUCCESS(rc) || rc == VERR_INTERRUPTED, ("%Rrc\n", rc), rc);
3528 if (RT_UNLIKELY(pThread->enmState != PDMTHREADSTATE_RUNNING))
3529 break;
3530 LogFlowFunc(("Woken up with rc=%Rrc\n", rc));
3531 ASMAtomicWriteBool(&pThis->fNotificationSent, false);
3532 }
3533
3534 ASMAtomicWriteBool(&pThis->fWrkThreadSleeping, false);
3535
3536 /* Check whether there is a BIOS request pending and process it first. */
3537 if (ASMAtomicReadBool(&pThis->fBiosReqPending))
3538 {
3539 rc = buslogicR3PrepareBIOSSCSIRequest(pThis);
3540 AssertRC(rc);
3541 ASMAtomicXchgBool(&pThis->fBiosReqPending, false);
3542 }
3543 else
3544 {
3545 ASMAtomicXchgU32(&pThis->cMailboxesReady, 0); /** @todo Actually not required anymore but to stay compatible with older saved states. */
3546
3547 /* Process mailboxes. */
3548 do
3549 {
3550 rc = buslogicR3ProcessMailboxNext(pThis);
3551 AssertMsg(RT_SUCCESS(rc) || rc == VERR_NO_DATA, ("Processing mailbox failed rc=%Rrc\n", rc));
3552 } while (RT_SUCCESS(rc));
3553 }
3554 } /* While running */
3555
3556 return VINF_SUCCESS;
3557}
3558
3559
3560/**
3561 * Unblock the worker thread so it can respond to a state change.
3562 *
3563 * @returns VBox status code.
3564 * @param pDevIns The device instance.
3565 * @param pThread The send thread.
3566 */
3567static DECLCALLBACK(int) buslogicR3WorkerWakeUp(PPDMDEVINS pDevIns, PPDMTHREAD pThread)
3568{
3569 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3570 return SUPSemEventSignal(pThis->pSupDrvSession, pThis->hEvtProcess);
3571}
3572
3573/**
3574 * BusLogic debugger info callback.
3575 *
3576 * @param pDevIns The device instance.
3577 * @param pHlp The output helpers.
3578 * @param pszArgs The arguments.
3579 */
3580static DECLCALLBACK(void) buslogicR3Info(PPDMDEVINS pDevIns, PCDBGFINFOHLP pHlp, const char *pszArgs)
3581{
3582 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3583 unsigned i;
3584 bool fVerbose = false;
3585
3586 /* Parse arguments. */
3587 if (pszArgs)
3588 fVerbose = strstr(pszArgs, "verbose") != NULL;
3589
3590 /* Show basic information. */
3591 pHlp->pfnPrintf(pHlp,
3592 "%s#%d: PCI I/O=%RTiop ISA I/O=%RTiop MMIO=%RGp IRQ=%u GC=%RTbool R0=%RTbool\n",
3593 pDevIns->pReg->szName,
3594 pDevIns->iInstance,
3595 pThis->IOPortBase, pThis->IOISABase, pThis->MMIOBase,
3596 PCIDevGetInterruptLine(&pThis->dev),
3597 !!pThis->fGCEnabled, !!pThis->fR0Enabled);
3598
3599 /* Print mailbox state. */
3600 if (pThis->regStatus & BL_STAT_INREQ)
3601 pHlp->pfnPrintf(pHlp, "Mailbox not initialized\n");
3602 else
3603 pHlp->pfnPrintf(pHlp, "%u-bit mailbox with %u entries at %RGp (%d LUN CCBs)\n",
3604 pThis->fMbxIs24Bit ? 24 : 32, pThis->cMailbox,
3605 pThis->GCPhysAddrMailboxOutgoingBase,
3606 pThis->fMbxIs24Bit ? 8 : pThis->fExtendedLunCCBFormat ? 64 : 8);
3607
3608 /* Print register contents. */
3609 pHlp->pfnPrintf(pHlp, "Registers: STAT=%02x INTR=%02x GEOM=%02x\n",
3610 pThis->regStatus, pThis->regInterrupt, pThis->regGeometry);
3611
3612 /* Print miscellaneous state. */
3613 pHlp->pfnPrintf(pHlp, "HAC interrupts: %s\n",
3614 pThis->fIRQEnabled ? "on" : "off");
3615
3616 /* Print the current command, if any. */
3617 if (pThis->uOperationCode != 0xff )
3618 pHlp->pfnPrintf(pHlp, "Current command: %02X\n", pThis->uOperationCode);
3619
3620 if (fVerbose && (pThis->regStatus & BL_STAT_INREQ) == 0)
3621 {
3622 RTGCPHYS GCMailbox;
3623
3624 /* Dump the mailbox contents. */
3625 if (pThis->fMbxIs24Bit)
3626 {
3627 Mailbox24 Mbx24;
3628
3629 /* Outgoing mailbox, 24-bit format. */
3630 GCMailbox = pThis->GCPhysAddrMailboxOutgoingBase;
3631 pHlp->pfnPrintf(pHlp, " Outgoing mailbox entries (24-bit) at %06X:\n", GCMailbox);
3632 for (i = 0; i < pThis->cMailbox; ++i)
3633 {
3634 PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCMailbox, &Mbx24, sizeof(Mailbox24));
3635 pHlp->pfnPrintf(pHlp, " slot %03d: CCB at %06X action code %02X", i, ADDR_TO_U32(Mbx24.aPhysAddrCCB), Mbx24.uCmdState);
3636 pHlp->pfnPrintf(pHlp, "%s\n", pThis->uMailboxOutgoingPositionCurrent == i ? " *" : "");
3637 GCMailbox += sizeof(Mailbox24);
3638 }
3639
3640 /* Incoming mailbox, 24-bit format. */
3641 GCMailbox = pThis->GCPhysAddrMailboxOutgoingBase + (pThis->cMailbox * sizeof(Mailbox24));
3642 pHlp->pfnPrintf(pHlp, " Incoming mailbox entries (24-bit) at %06X:\n", GCMailbox);
3643 for (i = 0; i < pThis->cMailbox; ++i)
3644 {
3645 PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCMailbox, &Mbx24, sizeof(Mailbox24));
3646 pHlp->pfnPrintf(pHlp, " slot %03d: CCB at %06X completion code %02X", i, ADDR_TO_U32(Mbx24.aPhysAddrCCB), Mbx24.uCmdState);
3647 pHlp->pfnPrintf(pHlp, "%s\n", pThis->uMailboxIncomingPositionCurrent == i ? " *" : "");
3648 GCMailbox += sizeof(Mailbox24);
3649 }
3650
3651 }
3652 else
3653 {
3654 Mailbox32 Mbx32;
3655
3656 /* Outgoing mailbox, 32-bit format. */
3657 GCMailbox = pThis->GCPhysAddrMailboxOutgoingBase;
3658 pHlp->pfnPrintf(pHlp, " Outgoing mailbox entries (32-bit) at %08X:\n", (uint32_t)GCMailbox);
3659 for (i = 0; i < pThis->cMailbox; ++i)
3660 {
3661 PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCMailbox, &Mbx32, sizeof(Mailbox32));
3662 pHlp->pfnPrintf(pHlp, " slot %03d: CCB at %08X action code %02X", i, Mbx32.u32PhysAddrCCB, Mbx32.u.out.uActionCode);
3663 pHlp->pfnPrintf(pHlp, "%s\n", pThis->uMailboxOutgoingPositionCurrent == i ? " *" : "");
3664 GCMailbox += sizeof(Mailbox32);
3665 }
3666
3667 /* Incoming mailbox, 32-bit format. */
3668 GCMailbox = pThis->GCPhysAddrMailboxOutgoingBase + (pThis->cMailbox * sizeof(Mailbox32));
3669 pHlp->pfnPrintf(pHlp, " Outgoing mailbox entries (32-bit) at %08X:\n", (uint32_t)GCMailbox);
3670 for (i = 0; i < pThis->cMailbox; ++i)
3671 {
3672 PDMDevHlpPhysRead(pThis->CTX_SUFF(pDevIns), GCMailbox, &Mbx32, sizeof(Mailbox32));
3673 pHlp->pfnPrintf(pHlp, " slot %03d: CCB at %08X completion code %02X BTSTAT %02X SDSTAT %02X", i,
3674 Mbx32.u32PhysAddrCCB, Mbx32.u.in.uCompletionCode, Mbx32.u.in.uHostAdapterStatus, Mbx32.u.in.uTargetDeviceStatus);
3675 pHlp->pfnPrintf(pHlp, "%s\n", pThis->uMailboxOutgoingPositionCurrent == i ? " *" : "");
3676 GCMailbox += sizeof(Mailbox32);
3677 }
3678
3679 }
3680 }
3681}
3682
3683/* -=-=-=-=- Helper -=-=-=-=- */
3684
3685 /**
3686 * Checks if all asynchronous I/O is finished.
3687 *
3688 * Used by buslogicR3Reset, buslogicR3Suspend and buslogicR3PowerOff.
3689 *
3690 * @returns true if quiesced, false if busy.
3691 * @param pDevIns The device instance.
3692 */
3693static bool buslogicR3AllAsyncIOIsFinished(PPDMDEVINS pDevIns)
3694{
3695 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3696
3697 for (uint32_t i = 0; i < RT_ELEMENTS(pThis->aDeviceStates); i++)
3698 {
3699 PBUSLOGICDEVICE pThisDevice = &pThis->aDeviceStates[i];
3700 if (pThisDevice->pDrvBase)
3701 {
3702 if (pThisDevice->cOutstandingRequests != 0)
3703 return false;
3704 }
3705 }
3706
3707 return true;
3708}
3709
3710/**
3711 * Callback employed by buslogicR3Suspend and buslogicR3PowerOff..
3712 *
3713 * @returns true if we've quiesced, false if we're still working.
3714 * @param pDevIns The device instance.
3715 */
3716static DECLCALLBACK(bool) buslogicR3IsAsyncSuspendOrPowerOffDone(PPDMDEVINS pDevIns)
3717{
3718 if (!buslogicR3AllAsyncIOIsFinished(pDevIns))
3719 return false;
3720
3721 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3722 ASMAtomicWriteBool(&pThis->fSignalIdle, false);
3723 return true;
3724}
3725
3726/**
3727 * Common worker for ahciR3Suspend and ahciR3PowerOff.
3728 */
3729static void buslogicR3SuspendOrPowerOff(PPDMDEVINS pDevIns, bool fPowerOff)
3730{
3731 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3732
3733 ASMAtomicWriteBool(&pThis->fSignalIdle, true);
3734 if (!buslogicR3AllAsyncIOIsFinished(pDevIns))
3735 PDMDevHlpSetAsyncNotification(pDevIns, buslogicR3IsAsyncSuspendOrPowerOffDone);
3736 else
3737 {
3738 ASMAtomicWriteBool(&pThis->fSignalIdle, false);
3739
3740 AssertMsg(!pThis->fNotificationSent, ("The PDM Queue should be empty at this point\n"));
3741
3742 if (pThis->fRedo)
3743 {
3744 if (fPowerOff)
3745 {
3746 /* Free tasks which would have been queued again on resume. */
3747 PBUSLOGICTASKSTATE pTaskState = pThis->pTasksRedoHead;
3748
3749 pThis->pTasksRedoHead = NULL;
3750
3751 while (pTaskState)
3752 {
3753 PBUSLOGICTASKSTATE pFree;
3754
3755 pFree = pTaskState;
3756 pTaskState = pTaskState->pRedoNext;
3757
3758 RTMemCacheFree(pThis->hTaskCache, pFree);
3759 }
3760 pThis->fRedo = false;
3761 }
3762 else if (pThis->VBoxSCSI.fBusy)
3763 {
3764 /* Destroy the task because the BIOS interface has all necessary information. */
3765 Assert(pThis->pTasksRedoHead->fBIOS);
3766 Assert(!pThis->pTasksRedoHead->pRedoNext);
3767
3768 RTMemCacheFree(pThis->hTaskCache, pThis->pTasksRedoHead);
3769 pThis->pTasksRedoHead = NULL;
3770 }
3771 }
3772 }
3773}
3774
3775/**
3776 * Suspend notification.
3777 *
3778 * @param pDevIns The device instance data.
3779 */
3780static DECLCALLBACK(void) buslogicR3Suspend(PPDMDEVINS pDevIns)
3781{
3782 Log(("buslogicR3Suspend\n"));
3783 buslogicR3SuspendOrPowerOff(pDevIns, false /* fPoweroff */);
3784}
3785
3786/**
3787 * Resume notification.
3788 *
3789 * @param pDevIns The device instance data.
3790 */
3791static DECLCALLBACK(void) buslogicR3Resume(PPDMDEVINS pDevIns)
3792{
3793 Log(("buslogicR3Resume\n"));
3794 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3795 buslogicR3Kick(pThis);
3796}
3797
3798
3799/**
3800 * Detach notification.
3801 *
3802 * One harddisk at one port has been unplugged.
3803 * The VM is suspended at this point.
3804 *
3805 * @param pDevIns The device instance.
3806 * @param iLUN The logical unit which is being detached.
3807 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
3808 */
3809static DECLCALLBACK(void) buslogicR3Detach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
3810{
3811 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3812 PBUSLOGICDEVICE pDevice = &pThis->aDeviceStates[iLUN];
3813
3814 Log(("%s:\n", __FUNCTION__));
3815
3816 AssertMsg(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
3817 ("BusLogic: Device does not support hotplugging\n"));
3818
3819 /*
3820 * Zero some important members.
3821 */
3822 pDevice->pDrvBase = NULL;
3823 pDevice->fPresent = false;
3824 pDevice->pDrvSCSIConnector = NULL;
3825}
3826
3827/**
3828 * Attach command.
3829 *
3830 * This is called when we change block driver.
3831 *
3832 * @returns VBox status code.
3833 * @param pDevIns The device instance.
3834 * @param iLUN The logical unit which is being detached.
3835 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines.
3836 */
3837static DECLCALLBACK(int) buslogicR3Attach(PPDMDEVINS pDevIns, unsigned iLUN, uint32_t fFlags)
3838{
3839 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3840 PBUSLOGICDEVICE pDevice = &pThis->aDeviceStates[iLUN];
3841 int rc;
3842
3843 AssertMsgReturn(fFlags & PDM_TACH_FLAGS_NOT_HOT_PLUG,
3844 ("BusLogic: Device does not support hotplugging\n"),
3845 VERR_INVALID_PARAMETER);
3846
3847 /* the usual paranoia */
3848 AssertRelease(!pDevice->pDrvBase);
3849 AssertRelease(!pDevice->pDrvSCSIConnector);
3850 Assert(pDevice->iLUN == iLUN);
3851
3852 /*
3853 * Try attach the block device and get the interfaces,
3854 * required as well as optional.
3855 */
3856 rc = PDMDevHlpDriverAttach(pDevIns, pDevice->iLUN, &pDevice->IBase, &pDevice->pDrvBase, NULL);
3857 if (RT_SUCCESS(rc))
3858 {
3859 /* Get SCSI connector interface. */
3860 pDevice->pDrvSCSIConnector = PDMIBASE_QUERY_INTERFACE(pDevice->pDrvBase, PDMISCSICONNECTOR);
3861 AssertMsgReturn(pDevice->pDrvSCSIConnector, ("Missing SCSI interface below\n"), VERR_PDM_MISSING_INTERFACE);
3862 pDevice->fPresent = true;
3863 }
3864 else
3865 AssertMsgFailed(("Failed to attach LUN#%d. rc=%Rrc\n", pDevice->iLUN, rc));
3866
3867 if (RT_FAILURE(rc))
3868 {
3869 pDevice->pDrvBase = NULL;
3870 pDevice->pDrvSCSIConnector = NULL;
3871 }
3872 return rc;
3873}
3874
3875/**
3876 * Callback employed by buslogicR3Reset.
3877 *
3878 * @returns true if we've quiesced, false if we're still working.
3879 * @param pDevIns The device instance.
3880 */
3881static DECLCALLBACK(bool) buslogicR3IsAsyncResetDone(PPDMDEVINS pDevIns)
3882{
3883 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3884
3885 if (!buslogicR3AllAsyncIOIsFinished(pDevIns))
3886 return false;
3887 ASMAtomicWriteBool(&pThis->fSignalIdle, false);
3888
3889 buslogicR3HwReset(pThis, true);
3890 return true;
3891}
3892
3893/**
3894 * @copydoc FNPDMDEVRESET
3895 */
3896static DECLCALLBACK(void) buslogicR3Reset(PPDMDEVINS pDevIns)
3897{
3898 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3899
3900 ASMAtomicWriteBool(&pThis->fSignalIdle, true);
3901 if (!buslogicR3AllAsyncIOIsFinished(pDevIns))
3902 PDMDevHlpSetAsyncNotification(pDevIns, buslogicR3IsAsyncResetDone);
3903 else
3904 {
3905 ASMAtomicWriteBool(&pThis->fSignalIdle, false);
3906 buslogicR3HwReset(pThis, true);
3907 }
3908}
3909
3910static DECLCALLBACK(void) buslogicR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
3911{
3912 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3913
3914 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
3915 pThis->pNotifierQueueRC = PDMQueueRCPtr(pThis->pNotifierQueueR3);
3916
3917 for (uint32_t i = 0; i < BUSLOGIC_MAX_DEVICES; i++)
3918 {
3919 PBUSLOGICDEVICE pDevice = &pThis->aDeviceStates[i];
3920
3921 pDevice->pBusLogicRC = PDMINS_2_DATA_RCPTR(pDevIns);
3922 }
3923
3924}
3925
3926/**
3927 * Poweroff notification.
3928 *
3929 * @param pDevIns Pointer to the device instance
3930 */
3931static DECLCALLBACK(void) buslogicR3PowerOff(PPDMDEVINS pDevIns)
3932{
3933 Log(("buslogicR3PowerOff\n"));
3934 buslogicR3SuspendOrPowerOff(pDevIns, true /* fPoweroff */);
3935}
3936
3937/**
3938 * Destroy a driver instance.
3939 *
3940 * Most VM resources are freed by the VM. This callback is provided so that any non-VM
3941 * resources can be freed correctly.
3942 *
3943 * @param pDevIns The device instance data.
3944 */
3945static DECLCALLBACK(int) buslogicR3Destruct(PPDMDEVINS pDevIns)
3946{
3947 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3948 PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
3949
3950 PDMR3CritSectDelete(&pThis->CritSectIntr);
3951
3952 /*
3953 * Free all tasks which are still hanging around
3954 * (Power off after the VM was suspended).
3955 */
3956 if (pThis->fRedo)
3957 {
3958 /* Free tasks which would have been queued again on resume. */
3959 PBUSLOGICTASKSTATE pTaskState = pThis->pTasksRedoHead;
3960
3961 pThis->pTasksRedoHead = NULL;
3962
3963 while (pTaskState)
3964 {
3965 PBUSLOGICTASKSTATE pFree;
3966
3967 pFree = pTaskState;
3968 pTaskState = pTaskState->pRedoNext;
3969
3970 RTMemCacheFree(pThis->hTaskCache, pFree);
3971 }
3972 pThis->fRedo = false;
3973 }
3974
3975 if (pThis->hEvtProcess != NIL_SUPSEMEVENT)
3976 {
3977 SUPSemEventClose(pThis->pSupDrvSession, pThis->hEvtProcess);
3978 pThis->hEvtProcess = NIL_SUPSEMEVENT;
3979 }
3980
3981 int rc = RTMemCacheDestroy(pThis->hTaskCache);
3982 AssertMsgRC(rc, ("Destroying task cache failed rc=%Rrc\n", rc));
3983
3984 return rc;
3985}
3986
3987/**
3988 * @interface_method_impl{PDMDEVREG,pfnConstruct}
3989 */
3990static DECLCALLBACK(int) buslogicR3Construct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
3991{
3992 PBUSLOGIC pThis = PDMINS_2_DATA(pDevIns, PBUSLOGIC);
3993 int rc = VINF_SUCCESS;
3994 bool fBootable = true;
3995 char achISACompat[16];
3996 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
3997
3998 /*
3999 * Init instance data (do early because of constructor).
4000 */
4001 pThis->hTaskCache = NIL_RTMEMCACHE;
4002 pThis->pDevInsR3 = pDevIns;
4003 pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
4004 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
4005 pThis->IBase.pfnQueryInterface = buslogicR3StatusQueryInterface;
4006 pThis->ILeds.pfnQueryStatusLed = buslogicR3StatusQueryStatusLed;
4007
4008 PCIDevSetVendorId (&pThis->dev, 0x104b); /* BusLogic */
4009 PCIDevSetDeviceId (&pThis->dev, 0x1040); /* BT-958 */
4010 PCIDevSetCommand (&pThis->dev, 0x0003);
4011 PCIDevSetRevisionId (&pThis->dev, 0x01);
4012 PCIDevSetClassProg (&pThis->dev, 0x00); /* SCSI */
4013 PCIDevSetClassSub (&pThis->dev, 0x00); /* SCSI */
4014 PCIDevSetClassBase (&pThis->dev, 0x01); /* Mass storage */
4015 PCIDevSetBaseAddress (&pThis->dev, 0, true /*IO*/, false /*Pref*/, false /*64-bit*/, 0x00000000);
4016 PCIDevSetBaseAddress (&pThis->dev, 1, false /*IO*/, false /*Pref*/, false /*64-bit*/, 0x00000000);
4017 PCIDevSetSubSystemVendorId(&pThis->dev, 0x104b);
4018 PCIDevSetSubSystemId (&pThis->dev, 0x1040);
4019 PCIDevSetInterruptLine (&pThis->dev, 0x00);
4020 PCIDevSetInterruptPin (&pThis->dev, 0x01);
4021
4022 /*
4023 * Validate and read configuration.
4024 */
4025 if (!CFGMR3AreValuesValid(pCfg,
4026 "GCEnabled\0"
4027 "R0Enabled\0"
4028 "Bootable\0"
4029 "ISACompat\0"))
4030 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
4031 N_("BusLogic configuration error: unknown option specified"));
4032
4033 rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &pThis->fGCEnabled, true);
4034 if (RT_FAILURE(rc))
4035 return PDMDEV_SET_ERROR(pDevIns, rc,
4036 N_("BusLogic configuration error: failed to read GCEnabled as boolean"));
4037 Log(("%s: fGCEnabled=%d\n", __FUNCTION__, pThis->fGCEnabled));
4038
4039 rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &pThis->fR0Enabled, true);
4040 if (RT_FAILURE(rc))
4041 return PDMDEV_SET_ERROR(pDevIns, rc,
4042 N_("BusLogic configuration error: failed to read R0Enabled as boolean"));
4043 Log(("%s: fR0Enabled=%d\n", __FUNCTION__, pThis->fR0Enabled));
4044 rc = CFGMR3QueryBoolDef(pCfg, "Bootable", &fBootable, true);
4045 if (RT_FAILURE(rc))
4046 return PDMDEV_SET_ERROR(pDevIns, rc,
4047 N_("BusLogic configuration error: failed to read Bootable as boolean"));
4048 Log(("%s: fBootable=%RTbool\n", __FUNCTION__, fBootable));
4049
4050 /* Only the first instance defaults to having the ISA compatibility ports enabled. */
4051 if (iInstance == 0)
4052 rc = CFGMR3QueryStringDef(pCfg, "ISACompat", achISACompat, sizeof(achISACompat), "Alternate");
4053 else
4054 rc = CFGMR3QueryStringDef(pCfg, "ISACompat", achISACompat, sizeof(achISACompat), "Disabled");
4055 if (RT_FAILURE(rc))
4056 return PDMDEV_SET_ERROR(pDevIns, rc,
4057 N_("BusLogic configuration error: failed to read ISACompat as string"));
4058 Log(("%s: ISACompat=%s\n", __FUNCTION__, achISACompat));
4059
4060 /* Grok the ISACompat setting. */
4061 if (!strcmp(achISACompat, "Disabled"))
4062 pThis->uDefaultISABaseCode = ISA_BASE_DISABLED;
4063 else if (!strcmp(achISACompat, "Primary"))
4064 pThis->uDefaultISABaseCode = 0; /* I/O base at 330h. */
4065 else if (!strcmp(achISACompat, "Alternate"))
4066 pThis->uDefaultISABaseCode = 1; /* I/O base at 334h. */
4067 else
4068 return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
4069 N_("BusLogic configuration error: invalid ISACompat setting"));
4070
4071 /*
4072 * Register the PCI device and its I/O regions.
4073 */
4074 rc = PDMDevHlpPCIRegister(pDevIns, &pThis->dev);
4075 if (RT_FAILURE(rc))
4076 return rc;
4077
4078 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 0, 32, PCI_ADDRESS_SPACE_IO, buslogicR3MmioMap);
4079 if (RT_FAILURE(rc))
4080 return rc;
4081
4082 rc = PDMDevHlpPCIIORegionRegister(pDevIns, 1, 32, PCI_ADDRESS_SPACE_MEM, buslogicR3MmioMap);
4083 if (RT_FAILURE(rc))
4084 return rc;
4085
4086 if (fBootable)
4087 {
4088 /* Register I/O port space for BIOS access. */
4089 rc = PDMDevHlpIOPortRegister(pDevIns, BUSLOGIC_BIOS_IO_PORT, 4, NULL,
4090 buslogicR3BiosIoPortWrite, buslogicR3BiosIoPortRead,
4091 buslogicR3BiosIoPortWriteStr, buslogicR3BiosIoPortReadStr,
4092 "BusLogic BIOS");
4093 if (RT_FAILURE(rc))
4094 return PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic cannot register BIOS I/O handlers"));
4095 }
4096
4097 /* Set up the compatibility I/O range. */
4098 rc = buslogicR3RegisterISARange(pThis, pThis->uDefaultISABaseCode);
4099 if (RT_FAILURE(rc))
4100 return PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic cannot register ISA I/O handlers"));
4101
4102 /* Initialize task cache. */
4103 rc = RTMemCacheCreate(&pThis->hTaskCache, sizeof(BUSLOGICTASKSTATE), 0, UINT32_MAX,
4104 NULL, NULL, NULL, 0);
4105 if (RT_FAILURE(rc))
4106 return PDMDEV_SET_ERROR(pDevIns, rc,
4107 N_("BusLogic: Failed to initialize task cache\n"));
4108
4109 /* Initialize task queue. */
4110 rc = PDMDevHlpQueueCreate(pDevIns, sizeof(PDMQUEUEITEMCORE), 5, 0,
4111 buslogicR3NotifyQueueConsumer, true, "BusLogicTask", &pThis->pNotifierQueueR3);
4112 if (RT_FAILURE(rc))
4113 return rc;
4114 pThis->pNotifierQueueR0 = PDMQueueR0Ptr(pThis->pNotifierQueueR3);
4115 pThis->pNotifierQueueRC = PDMQueueRCPtr(pThis->pNotifierQueueR3);
4116
4117 rc = PDMDevHlpCritSectInit(pDevIns, &pThis->CritSectIntr, RT_SRC_POS, "BusLogic-Intr#%u", pDevIns->iInstance);
4118 if (RT_FAILURE(rc))
4119 return PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic: cannot create critical section"));
4120
4121 /*
4122 * Create event semaphore and worker thread.
4123 */
4124 rc = SUPSemEventCreate(pThis->pSupDrvSession, &pThis->hEvtProcess);
4125 if (RT_FAILURE(rc))
4126 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
4127 N_("BusLogic: Failed to create SUP event semaphore"));
4128
4129 char szDevTag[20];
4130 RTStrPrintf(szDevTag, sizeof(szDevTag), "BUSLOGIC-%u", iInstance);
4131
4132 rc = PDMDevHlpThreadCreate(pDevIns, &pThis->pThreadWrk, pThis, buslogicR3Worker,
4133 buslogicR3WorkerWakeUp, 0, RTTHREADTYPE_IO, szDevTag);
4134 if (RT_FAILURE(rc))
4135 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
4136 N_("BusLogic: Failed to create worker thread %s"), szDevTag);
4137
4138 /* Initialize per device state. */
4139 for (unsigned i = 0; i < RT_ELEMENTS(pThis->aDeviceStates); i++)
4140 {
4141 char szName[24];
4142 PBUSLOGICDEVICE pDevice = &pThis->aDeviceStates[i];
4143
4144 RTStrPrintf(szName, sizeof(szName), "Device%u", i);
4145
4146 /* Initialize static parts of the device. */
4147 pDevice->iLUN = i;
4148 pDevice->pBusLogicR3 = pThis;
4149 pDevice->pBusLogicR0 = PDMINS_2_DATA_R0PTR(pDevIns);
4150 pDevice->pBusLogicRC = PDMINS_2_DATA_RCPTR(pDevIns);
4151 pDevice->Led.u32Magic = PDMLED_MAGIC;
4152 pDevice->IBase.pfnQueryInterface = buslogicR3DeviceQueryInterface;
4153 pDevice->ISCSIPort.pfnSCSIRequestCompleted = buslogicR3DeviceSCSIRequestCompleted;
4154 pDevice->ISCSIPort.pfnQueryDeviceLocation = buslogicR3QueryDeviceLocation;
4155 pDevice->ILed.pfnQueryStatusLed = buslogicR3DeviceQueryStatusLed;
4156
4157 /* Attach SCSI driver. */
4158 rc = PDMDevHlpDriverAttach(pDevIns, pDevice->iLUN, &pDevice->IBase, &pDevice->pDrvBase, szName);
4159 if (RT_SUCCESS(rc))
4160 {
4161 /* Get SCSI connector interface. */
4162 pDevice->pDrvSCSIConnector = PDMIBASE_QUERY_INTERFACE(pDevice->pDrvBase, PDMISCSICONNECTOR);
4163 AssertMsgReturn(pDevice->pDrvSCSIConnector, ("Missing SCSI interface below\n"), VERR_PDM_MISSING_INTERFACE);
4164
4165 pDevice->fPresent = true;
4166 }
4167 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
4168 {
4169 pDevice->pDrvBase = NULL;
4170 pDevice->fPresent = false;
4171 rc = VINF_SUCCESS;
4172 Log(("BusLogic: no driver attached to device %s\n", szName));
4173 }
4174 else
4175 {
4176 AssertLogRelMsgFailed(("BusLogic: Failed to attach %s\n", szName));
4177 return rc;
4178 }
4179 }
4180
4181 /*
4182 * Attach status driver (optional).
4183 */
4184 PPDMIBASE pBase;
4185 rc = PDMDevHlpDriverAttach(pDevIns, PDM_STATUS_LUN, &pThis->IBase, &pBase, "Status Port");
4186 if (RT_SUCCESS(rc))
4187 pThis->pLedsConnector = PDMIBASE_QUERY_INTERFACE(pBase, PDMILEDCONNECTORS);
4188 else if (rc != VERR_PDM_NO_ATTACHED_DRIVER)
4189 {
4190 AssertMsgFailed(("Failed to attach to status driver. rc=%Rrc\n", rc));
4191 return PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic cannot attach to status driver"));
4192 }
4193
4194 rc = PDMDevHlpSSMRegisterEx(pDevIns, BUSLOGIC_SAVED_STATE_MINOR_VERSION, sizeof(*pThis), NULL,
4195 NULL, buslogicR3LiveExec, NULL,
4196 NULL, buslogicR3SaveExec, NULL,
4197 NULL, buslogicR3LoadExec, buslogicR3LoadDone);
4198 if (RT_FAILURE(rc))
4199 return PDMDEV_SET_ERROR(pDevIns, rc, N_("BusLogic cannot register save state handlers"));
4200
4201 /*
4202 * Register the debugger info callback.
4203 */
4204 char szTmp[128];
4205 RTStrPrintf(szTmp, sizeof(szTmp), "%s%d", pDevIns->pReg->szName, pDevIns->iInstance);
4206 PDMDevHlpDBGFInfoRegister(pDevIns, szTmp, "BusLogic HBA info", buslogicR3Info);
4207
4208 rc = buslogicR3HwReset(pThis, true);
4209 AssertMsgRC(rc, ("hardware reset of BusLogic host adapter failed rc=%Rrc\n", rc));
4210
4211 return rc;
4212}
4213
4214/**
4215 * The device registration structure.
4216 */
4217const PDMDEVREG g_DeviceBusLogic =
4218{
4219 /* u32Version */
4220 PDM_DEVREG_VERSION,
4221 /* szName */
4222 "buslogic",
4223 /* szRCMod */
4224 "VBoxDDRC.rc",
4225 /* szR0Mod */
4226 "VBoxDDR0.r0",
4227 /* pszDescription */
4228 "BusLogic BT-958 SCSI host adapter.\n",
4229 /* fFlags */
4230 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0 |
4231 PDM_DEVREG_FLAGS_FIRST_SUSPEND_NOTIFICATION | PDM_DEVREG_FLAGS_FIRST_POWEROFF_NOTIFICATION |
4232 PDM_DEVREG_FLAGS_FIRST_RESET_NOTIFICATION,
4233 /* fClass */
4234 PDM_DEVREG_CLASS_STORAGE,
4235 /* cMaxInstances */
4236 ~0U,
4237 /* cbInstance */
4238 sizeof(BUSLOGIC),
4239 /* pfnConstruct */
4240 buslogicR3Construct,
4241 /* pfnDestruct */
4242 buslogicR3Destruct,
4243 /* pfnRelocate */
4244 buslogicR3Relocate,
4245 /* pfnMemSetup */
4246 NULL,
4247 /* pfnPowerOn */
4248 NULL,
4249 /* pfnReset */
4250 buslogicR3Reset,
4251 /* pfnSuspend */
4252 buslogicR3Suspend,
4253 /* pfnResume */
4254 buslogicR3Resume,
4255 /* pfnAttach */
4256 buslogicR3Attach,
4257 /* pfnDetach */
4258 buslogicR3Detach,
4259 /* pfnQueryInterface. */
4260 NULL,
4261 /* pfnInitComplete */
4262 NULL,
4263 /* pfnPowerOff */
4264 buslogicR3PowerOff,
4265 /* pfnSoftReset */
4266 NULL,
4267 /* u32VersionEnd */
4268 PDM_DEVREG_VERSION
4269};
4270
4271#endif /* IN_RING3 */
4272#endif /* !VBOX_DEVICE_STRUCT_TESTCASE */
Note: See TracBrowser for help on using the repository browser.

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