File: pata_disk_template.c

package info (click to toggle)
faumachine 20180503-4
  • links: PTS
  • area: main
  • in suites: buster
  • size: 61,272 kB
  • sloc: ansic: 272,290; makefile: 6,199; asm: 4,251; sh: 3,022; perl: 886; xml: 563; pascal: 311; lex: 214; vhdl: 204
file content (316 lines) | stat: -rw-r--r-- 6,201 bytes parent folder | download
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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
 * Copyright (C) 2013 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.
 */

/* Debugging Options */
#define DEBUG_CONTROL_FLOW	0
#define DEBUG_INTERRUPT		0
#define DEBUG_OPCODES		0

#define RESERVED_SECTORS		20
#define RESERVED_SECTORS_THRESHOLD	1

#include "config.h"

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "conv_gen.h"
#include "glue.h"
#include "std-ide.h"

#include "sig_boolean.h"
#include "sig_integer.h"

#define STATE

struct cpssp {
	struct sig_ide_bus *port_ide;

	struct {
		unsigned int unit;

		volatile uint8_t error;   /* error reg    (read only)  */
		volatile uint8_t features;/* features reg (write only) */
		volatile uint8_t nsector; /* sector count reg */
		volatile uint8_t sector;  /* sector reg */
		volatile uint16_t cyl;    /* cylinder reg */
		volatile uint8_t select;  /* select reg */
		volatile uint8_t command; /* command reg */
		uint8_t control;          /* device control reg */
	} common;

#define NAME		core
#define NAME_(x)	core_ ## x
#define SNAME		"core"
#include "arch_ata_disk.c"
#undef NAME
#undef NAME_
#undef SNAME

#define NAME		iface
#define NAME_(x)	iface_ ## x
#define SNAME		"iface"
#include "arch_pata_ata.c"
#undef NAME
#undef NAME_
#undef SNAME
};

#undef STATE

#define BEHAVIOR

static void
iface_dmarq_out_set(struct cpssp *cpssp, unsigned int val)
{
	sig_ide_bus_dmarq_set(cpssp->port_ide, val);
}

static void
iface_irqrq_out_set(struct cpssp *cpssp, unsigned int val)
{
	sig_ide_bus_irq(cpssp->port_ide, cpssp, val);
}

/*forward*/ static void
iface_dma_in(struct cpssp *cpssp, unsigned int count);
/*forward*/ static void
iface_dma_out(struct cpssp *cpssp, unsigned int count);
/*forward*/ static void
iface_pio_in(struct cpssp *cpssp, unsigned int count, int irq);
/*forward*/ static void
iface_pio_out(struct cpssp *cpssp, unsigned int count, int irq);
/*forward*/ static void
iface_done_io(struct cpssp *cpssp);
/*forward*/ static void
iface_done_cmd(struct cpssp *cpssp, int irq);

/*forward*/ static void
core_data_in(struct cpssp *cpssp, uint16_t *valp);
/*forward*/ static void
core_data_out(struct cpssp *cpssp, uint16_t val);
/*forward*/ static void
core_command(struct cpssp *cpssp);
/*forward*/ static void
core_soft_reset(struct cpssp *cpssp);

static void
core_dma_in(struct cpssp *cpssp, unsigned int count)
{
	iface_dma_in(cpssp, count);
}

static void
core_dma_out(struct cpssp *cpssp, unsigned int count)
{
	iface_dma_out(cpssp, count);
}

static void
core_pio_in(struct cpssp *cpssp, unsigned int count, int irq)
{
	iface_pio_in(cpssp, count, irq);
}

static void
core_pio_out(struct cpssp *cpssp, unsigned int count, int irq)
{
	iface_pio_out(cpssp, count, irq);
}

static void
core_done_io(struct cpssp *cpssp)
{
	iface_done_io(cpssp);
}

static void
core_done_cmd(struct cpssp *cpssp, int irq)
{
	iface_done_cmd(cpssp, irq);
}

static void
iface_data_in(struct cpssp *cpssp, uint16_t *valp)
{
	core_data_in(cpssp, valp);
}

static void
iface_data_out(struct cpssp *cpssp, uint16_t val)
{
	core_data_out(cpssp, val);
}

static void
iface_command(struct cpssp *cpssp)
{
	core_command(cpssp);
}

static void
iface_soft_reset(struct cpssp *cpssp)
{
	core_soft_reset(cpssp);
}

#define NAME		core
#define NAME_(x)	core_ ## x
#define SNAME		"core"
#include "arch_ata_disk.c"
#undef NAME
#undef NAME_
#undef SNAME

#define DEBUG			0
#define PACKET_INTERFACE	0
#define NAME		iface
#define NAME_(x)	iface_ ## x
#define SNAME		"iface"
#include "arch_pata_ata.c"
#undef NAME
#undef NAME_
#undef SNAME
#undef PACKET_INTERFACE
#undef DEBUG

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

	core_power_set(cpssp, val);
	iface_power_set(cpssp, val);
}

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

	core_reset_set(cpssp, val);
	iface_reset_set(cpssp, val);
}

static int
COMP_(inw)(void *_cpssp, unsigned short port, uint16_t *valp)
{
	struct cpssp *cpssp = _cpssp;

	return iface_inw(cpssp, port, valp);
}

static void
COMP_(outw)(void *_cpssp, unsigned short port, uint16_t val)
{
	struct cpssp *cpssp = _cpssp;

	iface_outw(cpssp, port, val);
}

static int
COMP_(dmainw)(void *_cpssp, uint16_t *valp)
{
	struct cpssp *cpssp = _cpssp;

	return iface_dmainw(cpssp, valp);
}

static void
COMP_(dmaoutw)(void *_cpssp, uint16_t val)
{
	struct cpssp *cpssp = _cpssp;

	iface_dmaoutw(cpssp, val);
}

void *
COMP_(create)(
	const char *name,
	const char *image,
#ifndef CYLINDERS
	const char *cylinders,
	const char *heads,
	const char *sectors,
	const char *size,
#endif
	const char *unit,
	struct sig_manage *port_manage,
	struct sig_molex_ide_power_conn *port_power,
	struct sig_ide_bus *port_ide
)
{
	static const struct sig_std_logic_funcs power_funcs = {
		.boolean_or_set = COMP_(power_set),
	};
	static const struct sig_ide_bus_funcs ide_funcs = {
		.reset = COMP_(reset),
		.inw = COMP_(inw),
		.outw = COMP_(outw),
		.dmainw = COMP_(dmainw),
		.dmaoutw = COMP_(dmaoutw),
	};
	struct cpssp *cpssp;

	assert(unit);

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

	cpssp->common.unit = strtoul(unit, NULL, 0);

	core_create(cpssp, name, image,
#ifndef CYLINDERS
			cylinders, heads, sectors, size,
#endif
			port_manage);
	iface_create(cpssp);

	/* Call */
	cpssp->port_ide = port_ide;
	sig_ide_bus_connect(port_ide, cpssp, &ide_funcs);

	/* In */
	sig_std_logic_connect_in(port_power->_plus_5V, cpssp, &power_funcs);

	return cpssp;
}

void
COMP_(destroy)(void *_cpssp)
{
	struct cpssp *cpssp = _cpssp;

	core_destroy(cpssp);
	iface_destroy(cpssp);

	shm_free(cpssp);
}

void
COMP_(suspend)(void *_cpssp, FILE *fp)
{
	struct cpssp *cpssp = _cpssp;

	generic_suspend(&cpssp->common, sizeof(cpssp->common), fp);
	core_suspend(cpssp, fp);
	iface_suspend(cpssp, fp);
}

void
COMP_(resume)(void *_cpssp, FILE *fp)
{
	struct cpssp *cpssp = _cpssp;

	generic_resume(&cpssp->common, sizeof(cpssp->common), fp);
	core_resume(cpssp, fp);
	iface_resume(cpssp, fp);
}

#undef BEHAVIOR