File: scsi_gen_disk.c

package info (click to toggle)
faumachine 20100527-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 53,836 kB
  • ctags: 20,552
  • sloc: ansic: 179,550; asm: 3,645; makefile: 3,611; perl: 2,103; sh: 1,529; python: 600; xml: 563; lex: 210; vhdl: 204
file content (301 lines) | stat: -rw-r--r-- 5,742 bytes parent folder | download | duplicates (2)
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/*
 * $Id: scsi_gen_disk.c,v 1.91 2009-10-26 10:47:54 vrsieh Exp $ 
 *
 * Copyright (C) 2007-2009 FAUmachine Team <info@faumachine.org>.
 * This program is free software. You can redistribute it and/or modify it
 * under the terms of the GNU General Public License, either version 2 of
 * the License, or (at your option) any later version. See COPYING.
 */

#define INCLUDE
#include "system.h"

#include "arch_scsi_gen_disk.c"
#undef INCLUDE

#include "scsi_gen_disk.h"

struct cpssp {
	/* Ports */
	struct sig_boolean *sig_5V;
	struct sig_boolean *sig_12V;
	struct sig_scsi_bus *port_scsi_bus;

	/* Signals */

#define STATE
#define NAME		disk
#define	NAME_(x)	disk_ ## x
#define SNAME		"disk"
#include "arch_scsi_gen_disk.c"
#undef SNAME
#undef NAME_
#undef NAME
#undef STATE
};

static void
disk_phase_msg_out(struct cpssp *cpssp)
{
	sig_scsi_bus_phase_msg_out(cpssp->port_scsi_bus, cpssp);
}

static void
disk_phase_msg_in(struct cpssp *cpssp)
{
	sig_scsi_bus_phase_msg_in(cpssp->port_scsi_bus, cpssp);
}

static void
disk_phase_cmd(struct cpssp *cpssp)
{
	sig_scsi_bus_phase_command(cpssp->port_scsi_bus, cpssp);
}

static void
disk_phase_data_in(struct cpssp *cpssp)
{
	sig_scsi_bus_phase_data_in(cpssp->port_scsi_bus, cpssp);
}

static void
disk_phase_data_out(struct cpssp *cpssp)
{
	sig_scsi_bus_phase_data_out(cpssp->port_scsi_bus, cpssp);
}

static void
disk_phase_status(struct cpssp *cpssp)
{
	sig_scsi_bus_phase_status(cpssp->port_scsi_bus, cpssp);
}

static void
disk_phase_free(struct cpssp *cpssp)
{
	sig_scsi_bus_phase_free(cpssp->port_scsi_bus, cpssp);
}

static void
disk_want_recv(struct cpssp *cpssp, unsigned long count)
{
	sig_scsi_bus_want_recv(cpssp->port_scsi_bus, cpssp, count);
}

static void
disk_want_send(struct cpssp *cpssp, unsigned long count)
{
	sig_scsi_bus_want_send(cpssp->port_scsi_bus, cpssp, count);
}

#define BEHAVIOR
#define NAME		disk
#define	NAME_(x)	disk_ ## x
#define SNAME		"disk"
#include "arch_scsi_gen_disk.c"
#undef SNAME
#undef NAME_
#undef NAME
#undef BEHAVIOR

static void
scsi_gen_disk_power_set(void *_cpssp, unsigned int val)
{
	struct cpssp *cpssp = (struct cpssp *) _cpssp;

	disk_power_set(cpssp, val);
}

static int
scsi_gen_disk_phase_select(void *_cpssp, uint32_t id)
{
	struct cpssp *cpssp = (struct cpssp *) _cpssp;

	return disk_phase_select(cpssp, id);
}

static int
scsi_gen_disk_phase_reselect(void *_cpssp, uint32_t id)
{
	struct cpssp *cpssp = (struct cpssp *) _cpssp;

	return disk_phase_reselect(cpssp, id);
}

static void
scsi_gen_disk_phase_msg_out(void *_cpssp)
{
	/* Nothing to do... */
}

static void
scsi_gen_disk_phase_msg_in(void *_cpssp)
{
	/* Nothing to do... */
}

static void
scsi_gen_disk_phase_command(void *_cpssp)
{
	/* Nothing to do... */
}

static void
scsi_gen_disk_phase_data_out(void *_cpssp)
{
	/* Nothing to do... */
}

static void
scsi_gen_disk_phase_data_in(void *_cpssp)
{
	/* Nothing to do... */
}

static void
scsi_gen_disk_phase_status(void *_cpssp)
{
	/* Nothing to do... */
}


static void
scsi_gen_disk_phase_free(void *_cpssp)
{
	/* Nothing to do... */
}

static void
scsi_gen_disk_atn_set(void *_cpssp, unsigned int val)
{
	struct cpssp *cpssp = (struct cpssp *) _cpssp;

	return disk_atn_set(cpssp, val);
}

void
scsi_gen_disk_want_recv(
	void *_cpssp,
	unsigned long bufsize
)
{
	/* called always from the target ==> not relevant here! */
}

void
scsi_gen_disk_want_send(
	void *_cpssp,
	unsigned long bufsize
)
{
	/* called always from the target ==> not relevant here! */
}

static unsigned long
scsi_gen_disk_send(
	void *_cpssp,
	const uint8_t *buf,
	unsigned long bufsize
)
{
	struct cpssp *cpssp = (struct cpssp *) _cpssp;

	return disk_send(cpssp, buf, bufsize);
}

static unsigned long
scsi_gen_disk_recv(
	void *_cpssp,
	uint8_t *buf,
	unsigned long bufsize
)
{
	struct cpssp *cpssp = (struct cpssp *) _cpssp;

	return disk_recv(cpssp, buf, bufsize);
}

void *
scsi_gen_disk_create(
	const char *name,
	const char *image,
	const char *scsi_id,
	const char *size,
	struct sig_manage *port_manage,
	struct sig_power_device *port_power,
	struct sig_scsi_bus *port_scsi
)
{
	static const struct sig_boolean_funcs power_funcs = {
		.set = scsi_gen_disk_power_set,
	};
	static const struct sig_scsi_bus_funcs funcs = {
		.phase_select = scsi_gen_disk_phase_select,
		.phase_reselect = scsi_gen_disk_phase_reselect,
		.phase_msg_out = scsi_gen_disk_phase_msg_out,
		.phase_msg_in = scsi_gen_disk_phase_msg_in,
		.phase_command = scsi_gen_disk_phase_command,
		.phase_data_out = scsi_gen_disk_phase_data_out,
		.phase_data_in = scsi_gen_disk_phase_data_in,
		.phase_status = scsi_gen_disk_phase_status,
		.phase_free = scsi_gen_disk_phase_free,

		.atn_set = scsi_gen_disk_atn_set,

		.want_recv = scsi_gen_disk_want_recv,
		.want_send = scsi_gen_disk_want_send,

		.send = scsi_gen_disk_send,
		.recv = scsi_gen_disk_recv,
	};
	struct cpssp *cpssp;
	int id;
	unsigned long size_mb;
	char path[1024];

	system_name_push(name);

	cpssp = malloc(sizeof(*cpssp));
	assert(cpssp);

	/*
	 * Config
	 */
	id = strtoul(scsi_id, NULL, 0);
	assert(0 <= id && id < 7);
	size_mb = strtoul(size, NULL, 0);

	/*
	 * Components
	 */
	assert(strlen(system_path()) + strlen(".media") + 1 <= sizeof(path));
	sprintf(path, "%s.media", system_path());
	disk_create(cpssp, path, image, id, size_mb);
	disk_init(cpssp);

	/*
	 * Ports
	 */
	/* Call */
	cpssp->port_scsi_bus = port_scsi;
	sig_scsi_bus_connect(port_scsi, cpssp, &funcs);

	/* In */
	cpssp->sig_5V = port_power->power_5V;
	sig_boolean_connect_in(port_power->power_5V, cpssp, &power_funcs);
	cpssp->sig_12V = port_power->power_12V;

	system_name_pop();

	return cpssp;
}

void
scsi_gen_disk_destroy(void *_cpssp)
{
	struct cpssp *cpssp = _cpssp;

	disk_destroy(cpssp);

	free(cpssp);
}