-
Notifications
You must be signed in to change notification settings - Fork 1
/
SCSIDevice.cpp
227 lines (210 loc) · 6.22 KB
/
SCSIDevice.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* ES40 emulator.
* Copyright (C) 2007-2008 by the ES40 Emulator Project
*
* WWW : http://sourceforge.net/projects/es40
* E-mail : [email protected]
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Although this is not required, the author would appreciate being notified of,
* and receiving any modifications you may make to the source code that might serve
* the general public.
*/
/**
* \file
* Contains definitions for the SCSI device base class.
*
* $Id: SCSIDevice.cpp,v 1.1 2008/01/12 12:46:43 iamcamiel Exp $
*
* X-1.1 Camiel Vanderhoeven 12-JAN-2008
* Initial version in CVS.
**/
#include "StdAfx.h"
#include "SCSIDevice.h"
#include "SCSIBus.h"
/**
* \brief Constructor.
*
* Set this device as unregistered with any SCSI bus.
**/
CSCSIDevice::CSCSIDevice(void)
{
int i;
for (i=0;i<10;i++)
{
scsi_bus[i] = 0;
scsi_initiator_id[i] = -1;
}
}
/**
* \brief Destructor.
**/
CSCSIDevice::~CSCSIDevice(void)
{
}
/**
* \brief Register this device with a SCSI bus.
**/
void CSCSIDevice::scsi_register(int busno,class CSCSIBus * with, int target)
{
scsi_bus[busno] = with;
scsi_initiator_id[busno] = target;
scsi_bus[busno]->scsi_register(this, busno, target);
}
/**
* \brief Arbitrate for the SCSI bus.
*
* See CSCSIBus::arbitrate for a description.
**/
bool CSCSIDevice::scsi_arbitrate(int bus)
{
return scsi_bus[bus]->arbitrate(scsi_initiator_id[bus]);
}
/**
* \brief Select a target on the SCSI bus.
*
* See CSCSIBus::select for a description.
**/
bool CSCSIDevice::scsi_select(int bus, int target)
{
return scsi_bus[bus]->select(scsi_initiator_id[bus],target);
}
/**
* \brief Called when this device is selected.
*
* Override this to allow this device to be selected. Overrided
* functions should at least call scsi_set_phase to set
* the SCSI bus phase to a valid phase.
**/
void CSCSIDevice::scsi_select_me(int bus)
{
FAILURE("selected device doesn't implement scsi_select_me");
}
/**
* \brief Change the SCSI bus phase.
*
* See CSCSIBus::set_phase for a description.
**/
void CSCSIDevice::scsi_set_phase(int bus, int phase)
{
scsi_bus[bus]->set_phase(scsi_initiator_id[bus],phase);
}
/**
* \brief Get the current SCSI bus phase.
*
* See CSCSIBus::get_phase for a description.
**/
int CSCSIDevice::scsi_get_phase(int bus)
{
return scsi_bus[bus]->get_phase();
}
/**
* \brief Release the SCSI bus.
*
* See CSCSIBus::free_bus for a description.
**/
void CSCSIDevice::scsi_free(int bus)
{
return scsi_bus[bus]->free_bus(scsi_initiator_id[bus]);
}
/**
* \brief Return the number of bytes expected or available.
*
* Override this to return the number of bytes the device
* expects to receive from the initiator, or has available
* for the initiator, in the current SCSI phase.
*
* For an overview of data transfer during a SCSI bus phase,
* see SCSIDevice::scsi_xfer_ptr.
**/
size_t CSCSIDevice::scsi_expected_xfer_me(int bus)
{
FAILURE("selected device doesn't implement scsi_expected_xfer_me");
}
/**
* \brief Return the number of bytes expected or available.
*
* Returns the number of bytes the currently selected target
* expects to receive from the initiator, or has available
* for the initiator, in the current SCSI phase.
*
* For an overview of data transfer during a SCSI bus phase,
* see SCSIDevice::scsi_xfer_ptr.
**/
size_t CSCSIDevice::scsi_expected_xfer(int bus)
{
return scsi_bus[bus]->targets[scsi_bus[bus]->state.target]->scsi_expected_xfer_me(scsi_bus[bus]->target_bus_no[scsi_bus[bus]->state.target]);
}
/**
* \brief Return a pointer where the initiator can read or write data.
*
* Override this to return a pointer to where the initiator
* can read or write data in the current SCSI phase.
*
* For an overview of data transfer during a SCSI bus phase,
* see SCSIDevice::scsi_xfer_ptr.
**/
void * CSCSIDevice::scsi_xfer_ptr_me(int bus, size_t bytes)
{
FAILURE("selected device doesn't implement scsi_xfer_ptr_me");
}
/**
* \brief Return a pointer where target data can be read or written.
*
* Returns a pointer to where the initiator can read or
* write data from/to the currentlt selected target in
* the current SCSI phase.
*
* The initiator should do the following for each transfer:
* - Check the current phase using CSCSIDevice::scsi_get_phase.
* - Check the amount of data to transfer using
* CSCSIDevice::scsi_expected_xfer.
* - Signal intent to transfer data, and obtain a pointer
* using SCSIDevice::scsi_xfer_ptr.
* - Transfer data using the returned pointer.
* - Call CSCSIDevice::scsi_xfer_done to the the target
* process the data and/or transfer to a new phase.
* .
**/
void * CSCSIDevice::scsi_xfer_ptr(int bus, size_t bytes)
{
return scsi_bus[bus]->targets[scsi_bus[bus]->state.target]->scsi_xfer_ptr_me(scsi_bus[bus]->target_bus_no[scsi_bus[bus]->state.target],bytes);
}
/**
* \brief Process data written or read.
*
* Override this to process data read or written in
* the current SCSI phase.
*
* For an overview of data transfer during a SCSI bus phase,
* see SCSIDevice::scsi_xfer_ptr.
**/
void CSCSIDevice::scsi_xfer_done_me(int bus)
{
FAILURE("selected device doesn't implement scsi_xfer_done_me");
}
/**
* \brief Mark data transfer done.
*
* Let the target know that data has been transfered for the
* current SCSI phase.
*
* For an overview of data transfer during a SCSI bus phase,
* see SCSIDevice::scsi_xfer_ptr.
**/
void CSCSIDevice::scsi_xfer_done(int bus)
{
scsi_bus[bus]->targets[scsi_bus[bus]->state.target]->scsi_xfer_done_me(scsi_bus[bus]->target_bus_no[scsi_bus[bus]->state.target]);
}