1 | /* $Id: VBoxSCSI.h 82667 2020-01-08 10:13:47Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox storage devices - Simple SCSI interface for BIOS access.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2019 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | */
|
---|
17 |
|
---|
18 | /** @page pg_drv_scsi Simple SCSI interface for BIOS access.
|
---|
19 | *
|
---|
20 | * This is a simple interface to access SCSI devices from the BIOS which is
|
---|
21 | * shared between the BusLogic and the LsiLogic SCSI host adapters to simplify
|
---|
22 | * the BIOS part.
|
---|
23 | *
|
---|
24 | * The first interface (if available) will be starting at port 0x430 and
|
---|
25 | * each will occupy 4 ports. The ports are used as described below:
|
---|
26 | *
|
---|
27 | * +--------+--------+----------+
|
---|
28 | * | Offset | Access | Purpose |
|
---|
29 | * +--------+--------+----------+
|
---|
30 | * | 0 | Write | Command |
|
---|
31 | * +--------+--------+----------+
|
---|
32 | * | 0 | Read | Status |
|
---|
33 | * +--------+--------+----------+
|
---|
34 | * | 1 | Write | Data in |
|
---|
35 | * +--------+--------+----------+
|
---|
36 | * | 1 | Read | Data out |
|
---|
37 | * +--------+--------+----------+
|
---|
38 | * | 2 | R/W | Detect |
|
---|
39 | * +--------+--------+----------+
|
---|
40 | * | 3 | Read | SCSI rc |
|
---|
41 | * +--------+--------+----------+
|
---|
42 | * | 3 | Write | Reset |
|
---|
43 | * +--------+--------+----------+
|
---|
44 | *
|
---|
45 | * The register at port 0 receives the SCSI CDB issued from the driver when
|
---|
46 | * writing to it but before writing the actual CDB the first write gives the
|
---|
47 | * size of the CDB in bytes.
|
---|
48 | *
|
---|
49 | * Reading the port at offset 0 gives status information about the adapter. If
|
---|
50 | * the busy bit is set the adapter is processing a previous issued request if it is
|
---|
51 | * cleared the command finished and the adapter can process another request.
|
---|
52 | * The driver has to poll this bit because the adapter will not assert an IRQ
|
---|
53 | * for simplicity reasons.
|
---|
54 | *
|
---|
55 | * The register at offset 2 is to detect if a host adapter is available. If the
|
---|
56 | * driver writes a value to this port and gets the same value after reading it
|
---|
57 | * again the adapter is available.
|
---|
58 | *
|
---|
59 | * Any write to the register at offset 3 causes the interface to be reset. A
|
---|
60 | * read returns the SCSI status code of the last operation.
|
---|
61 | *
|
---|
62 | * This part has no R0 or RC components.
|
---|
63 | */
|
---|
64 |
|
---|
65 | #ifndef VBOX_INCLUDED_SRC_Storage_VBoxSCSI_h
|
---|
66 | #define VBOX_INCLUDED_SRC_Storage_VBoxSCSI_h
|
---|
67 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
68 | # pragma once
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | /*******************************************************************************
|
---|
72 | * Header Files *
|
---|
73 | *******************************************************************************/
|
---|
74 | //#define DEBUG
|
---|
75 | #include <iprt/semaphore.h>
|
---|
76 | #include <VBox/vmm/pdmdev.h>
|
---|
77 | #include <VBox/vmm/pdmstorageifs.h>
|
---|
78 | #include <VBox/scsi.h>
|
---|
79 |
|
---|
80 | typedef enum VBOXSCSISTATE
|
---|
81 | {
|
---|
82 | VBOXSCSISTATE_NO_COMMAND = 0x00,
|
---|
83 | VBOXSCSISTATE_READ_TXDIR = 0x01,
|
---|
84 | VBOXSCSISTATE_READ_CDB_SIZE_BUFHI = 0x02,
|
---|
85 | VBOXSCSISTATE_READ_BUFFER_SIZE_LSB = 0x03,
|
---|
86 | VBOXSCSISTATE_READ_BUFFER_SIZE_MID = 0x04,
|
---|
87 | VBOXSCSISTATE_READ_COMMAND = 0x05,
|
---|
88 | VBOXSCSISTATE_COMMAND_READY = 0x06
|
---|
89 | } VBOXSCSISTATE;
|
---|
90 |
|
---|
91 | #define VBOXSCSI_TXDIR_FROM_DEVICE 0
|
---|
92 | #define VBOXSCSI_TXDIR_TO_DEVICE 1
|
---|
93 |
|
---|
94 | /** Maximum CDB size the BIOS driver sends. */
|
---|
95 | #define VBOXSCSI_CDB_SIZE_MAX 16
|
---|
96 |
|
---|
97 | typedef struct VBOXSCSI
|
---|
98 | {
|
---|
99 | /** The identify register. */
|
---|
100 | uint8_t regIdentify;
|
---|
101 | /** The target device. */
|
---|
102 | uint8_t uTargetDevice;
|
---|
103 | /** Transfer direction. */
|
---|
104 | uint8_t uTxDir;
|
---|
105 | /** The size of the CDB we are issuing. */
|
---|
106 | uint8_t cbCDB;
|
---|
107 | /** The command to issue. */
|
---|
108 | uint8_t abCDB[VBOXSCSI_CDB_SIZE_MAX + 4];
|
---|
109 | /** Current position in the array. */
|
---|
110 | uint8_t iCDB;
|
---|
111 |
|
---|
112 | #if HC_ARCH_BITS == 64
|
---|
113 | uint32_t Alignment0;
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | /** Pointer to the buffer holding the data. */
|
---|
117 | R3PTRTYPE(uint8_t *) pbBuf;
|
---|
118 | /** Size of the buffer in bytes. */
|
---|
119 | uint32_t cbBuf;
|
---|
120 | /** The number of bytes left to read/write in the
|
---|
121 | * buffer. It is decremented when the guest (BIOS) accesses
|
---|
122 | * the buffer data. */
|
---|
123 | uint32_t cbBufLeft;
|
---|
124 | /** Current position in the buffer (offBuf if you like). */
|
---|
125 | uint32_t iBuf;
|
---|
126 | /** The result code of last operation. */
|
---|
127 | int32_t rcCompletion;
|
---|
128 | /** Flag whether a request is pending. */
|
---|
129 | volatile bool fBusy;
|
---|
130 | /** The state we are in when fetching a command from the BIOS. */
|
---|
131 | VBOXSCSISTATE enmState;
|
---|
132 | /** Critical section protecting the device state. */
|
---|
133 | RTCRITSECT CritSect;
|
---|
134 | } VBOXSCSI, *PVBOXSCSI;
|
---|
135 |
|
---|
136 | #define VBOX_SCSI_BUSY RT_BIT(0)
|
---|
137 | #define VBOX_SCSI_ERROR RT_BIT(1)
|
---|
138 |
|
---|
139 | #ifdef IN_RING3
|
---|
140 | RT_C_DECLS_BEGIN
|
---|
141 | int vboxscsiInitialize(PVBOXSCSI pVBoxSCSI);
|
---|
142 | void vboxscsiDestroy(PVBOXSCSI pVBoxSCSI);
|
---|
143 | void vboxscsiHwReset(PVBOXSCSI pVBoxSCSI);
|
---|
144 | int vboxscsiReadRegister(PVBOXSCSI pVBoxSCSI, uint8_t iRegister, uint32_t *pu32Value);
|
---|
145 | int vboxscsiWriteRegister(PVBOXSCSI pVBoxSCSI, uint8_t iRegister, uint8_t uVal);
|
---|
146 | int vboxscsiSetupRequest(PVBOXSCSI pVBoxSCSI, uint32_t *puLun, uint8_t **ppbCdb, size_t *pcbCdb,
|
---|
147 | size_t *pcbBuf, uint32_t *puTargetDevice);
|
---|
148 | int vboxscsiRequestFinished(PVBOXSCSI pVBoxSCSI, int rcCompletion);
|
---|
149 | size_t vboxscsiCopyToBuf(PVBOXSCSI pVBoxSCSI, PRTSGBUF pSgBuf, size_t cbSkip, size_t cbCopy);
|
---|
150 | size_t vboxscsiCopyFromBuf(PVBOXSCSI pVBoxSCSI, PRTSGBUF pSgBuf, size_t cbSkip, size_t cbCopy);
|
---|
151 | void vboxscsiSetRequestRedo(PVBOXSCSI pVBoxSCSI);
|
---|
152 | int vboxscsiWriteString(PPDMDEVINS pDevIns, PVBOXSCSI pVBoxSCSI, uint8_t iRegister,
|
---|
153 | uint8_t const *pbSrc, uint32_t *pcTransfers, unsigned cb);
|
---|
154 | int vboxscsiReadString(PPDMDEVINS pDevIns, PVBOXSCSI pVBoxSCSI, uint8_t iRegister,
|
---|
155 | uint8_t *pbDst, uint32_t *pcTransfers, unsigned cb);
|
---|
156 |
|
---|
157 | DECLHIDDEN(int) vboxscsiR3LoadExec(PCPDMDEVHLPR3 pHlp, PVBOXSCSI pVBoxSCSI, PSSMHANDLE pSSM);
|
---|
158 | DECLHIDDEN(int) vboxscsiR3SaveExec(PCPDMDEVHLPR3 pHlp, PVBOXSCSI pVBoxSCSI, PSSMHANDLE pSSM);
|
---|
159 | RT_C_DECLS_END
|
---|
160 | #endif /* IN_RING3 */
|
---|
161 |
|
---|
162 | #endif /* !VBOX_INCLUDED_SRC_Storage_VBoxSCSI_h */
|
---|
163 |
|
---|