]> git.proxmox.com Git - mirror_qemu.git/blame - hw/char/parallel.c
Merge remote-tracking branch 'remotes/mwalle/tags/lm32-queue/20160620' into staging
[mirror_qemu.git] / hw / char / parallel.c
CommitLineData
6508fe59
FB
1/*
2 * QEMU Parallel PORT emulation
5fafdf24 3 *
e57a8c0e 4 * Copyright (c) 2003-2005 Fabrice Bellard
5867c88a 5 * Copyright (c) 2007 Marko Kohtala
5fafdf24 6 *
6508fe59
FB
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
b6a0aa05 25#include "qemu/osdep.h"
da34e65c 26#include "qapi/error.h"
83c9f4ca 27#include "hw/hw.h"
dccfcd0e 28#include "sysemu/char.h"
0d09e41a
PB
29#include "hw/isa/isa.h"
30#include "hw/i386/pc.h"
9c17d615 31#include "sysemu/sysemu.h"
6508fe59
FB
32
33//#define DEBUG_PARALLEL
34
5867c88a 35#ifdef DEBUG_PARALLEL
001faf32 36#define pdebug(fmt, ...) printf("pp: " fmt, ## __VA_ARGS__)
5867c88a 37#else
001faf32 38#define pdebug(fmt, ...) ((void)0)
5867c88a
TS
39#endif
40
41#define PARA_REG_DATA 0
42#define PARA_REG_STS 1
43#define PARA_REG_CTR 2
44#define PARA_REG_EPP_ADDR 3
45#define PARA_REG_EPP_DATA 4
46
6508fe59
FB
47/*
48 * These are the definitions for the Printer Status Register
49 */
50#define PARA_STS_BUSY 0x80 /* Busy complement */
51#define PARA_STS_ACK 0x40 /* Acknowledge */
52#define PARA_STS_PAPER 0x20 /* Out of paper */
53#define PARA_STS_ONLINE 0x10 /* Online */
54#define PARA_STS_ERROR 0x08 /* Error complement */
5867c88a 55#define PARA_STS_TMOUT 0x01 /* EPP timeout */
6508fe59
FB
56
57/*
58 * These are the definitions for the Printer Control Register
59 */
5867c88a 60#define PARA_CTR_DIR 0x20 /* Direction (1=read, 0=write) */
6508fe59
FB
61#define PARA_CTR_INTEN 0x10 /* IRQ Enable */
62#define PARA_CTR_SELECT 0x08 /* Select In complement */
63#define PARA_CTR_INIT 0x04 /* Initialize Printer complement */
64#define PARA_CTR_AUTOLF 0x02 /* Auto linefeed complement */
65#define PARA_CTR_STROBE 0x01 /* Strobe complement */
66
5867c88a
TS
67#define PARA_CTR_SIGNAL (PARA_CTR_SELECT|PARA_CTR_INIT|PARA_CTR_AUTOLF|PARA_CTR_STROBE)
68
defdb20e 69typedef struct ParallelState {
63858cd9 70 MemoryRegion iomem;
5867c88a
TS
71 uint8_t dataw;
72 uint8_t datar;
73 uint8_t status;
6508fe59 74 uint8_t control;
d537cf6c 75 qemu_irq irq;
6508fe59
FB
76 int irq_pending;
77 CharDriverState *chr;
e57a8c0e 78 int hw_driver;
5867c88a
TS
79 int epp_timeout;
80 uint32_t last_read_offset; /* For debugging */
d60532ca 81 /* Memory-mapped interface */
d60532ca 82 int it_shift;
defdb20e 83} ParallelState;
6508fe59 84
b0dc5ee6
AF
85#define TYPE_ISA_PARALLEL "isa-parallel"
86#define ISA_PARALLEL(obj) \
87 OBJECT_CHECK(ISAParallelState, (obj), TYPE_ISA_PARALLEL)
88
021f0674 89typedef struct ISAParallelState {
b0dc5ee6
AF
90 ISADevice parent_obj;
91
e8ee28fb 92 uint32_t index;
021f0674
GH
93 uint32_t iobase;
94 uint32_t isairq;
95 ParallelState state;
96} ISAParallelState;
97
6508fe59
FB
98static void parallel_update_irq(ParallelState *s)
99{
100 if (s->irq_pending)
d537cf6c 101 qemu_irq_raise(s->irq);
6508fe59 102 else
d537cf6c 103 qemu_irq_lower(s->irq);
6508fe59
FB
104}
105
5867c88a
TS
106static void
107parallel_ioport_write_sw(void *opaque, uint32_t addr, uint32_t val)
6508fe59
FB
108{
109 ParallelState *s = opaque;
3b46e624 110
5867c88a
TS
111 pdebug("write addr=0x%02x val=0x%02x\n", addr, val);
112
113 addr &= 7;
114 switch(addr) {
115 case PARA_REG_DATA:
0fa7f157
TS
116 s->dataw = val;
117 parallel_update_irq(s);
5867c88a
TS
118 break;
119 case PARA_REG_CTR:
52ccc5e0 120 val |= 0xc0;
0fa7f157
TS
121 if ((val & PARA_CTR_INIT) == 0 ) {
122 s->status = PARA_STS_BUSY;
123 s->status |= PARA_STS_ACK;
124 s->status |= PARA_STS_ONLINE;
125 s->status |= PARA_STS_ERROR;
126 }
127 else if (val & PARA_CTR_SELECT) {
128 if (val & PARA_CTR_STROBE) {
129 s->status &= ~PARA_STS_BUSY;
130 if ((s->control & PARA_CTR_STROBE) == 0)
2cc6e0a1 131 qemu_chr_fe_write(s->chr, &s->dataw, 1);
0fa7f157
TS
132 } else {
133 if (s->control & PARA_CTR_INTEN) {
134 s->irq_pending = 1;
135 }
136 }
137 }
138 parallel_update_irq(s);
139 s->control = val;
5867c88a
TS
140 break;
141 }
142}
143
144static void parallel_ioport_write_hw(void *opaque, uint32_t addr, uint32_t val)
145{
146 ParallelState *s = opaque;
147 uint8_t parm = val;
563e3c6e 148 int dir;
5867c88a
TS
149
150 /* Sometimes programs do several writes for timing purposes on old
151 HW. Take care not to waste time on writes that do nothing. */
152
153 s->last_read_offset = ~0U;
154
6508fe59 155 addr &= 7;
6508fe59 156 switch(addr) {
5867c88a
TS
157 case PARA_REG_DATA:
158 if (s->dataw == val)
0fa7f157
TS
159 return;
160 pdebug("wd%02x\n", val);
41084f1b 161 qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_WRITE_DATA, &parm);
0fa7f157 162 s->dataw = val;
6508fe59 163 break;
5867c88a 164 case PARA_REG_STS:
0fa7f157
TS
165 pdebug("ws%02x\n", val);
166 if (val & PARA_STS_TMOUT)
167 s->epp_timeout = 0;
168 break;
5867c88a
TS
169 case PARA_REG_CTR:
170 val |= 0xc0;
171 if (s->control == val)
0fa7f157
TS
172 return;
173 pdebug("wc%02x\n", val);
563e3c6e
AJ
174
175 if ((val & PARA_CTR_DIR) != (s->control & PARA_CTR_DIR)) {
176 if (val & PARA_CTR_DIR) {
177 dir = 1;
178 } else {
179 dir = 0;
180 }
41084f1b 181 qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_DATA_DIR, &dir);
563e3c6e
AJ
182 parm &= ~PARA_CTR_DIR;
183 }
184
41084f1b 185 qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm);
0fa7f157 186 s->control = val;
6508fe59 187 break;
5867c88a 188 case PARA_REG_EPP_ADDR:
0fa7f157
TS
189 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
190 /* Controls not correct for EPP address cycle, so do nothing */
191 pdebug("wa%02x s\n", val);
192 else {
193 struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
41084f1b 194 if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE_ADDR, &ioarg)) {
0fa7f157
TS
195 s->epp_timeout = 1;
196 pdebug("wa%02x t\n", val);
197 }
198 else
199 pdebug("wa%02x\n", val);
200 }
201 break;
5867c88a 202 case PARA_REG_EPP_DATA:
0fa7f157
TS
203 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
204 /* Controls not correct for EPP data cycle, so do nothing */
205 pdebug("we%02x s\n", val);
206 else {
207 struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
41084f1b 208 if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg)) {
0fa7f157
TS
209 s->epp_timeout = 1;
210 pdebug("we%02x t\n", val);
211 }
212 else
213 pdebug("we%02x\n", val);
214 }
215 break;
5867c88a
TS
216 }
217}
218
219static void
220parallel_ioport_eppdata_write_hw2(void *opaque, uint32_t addr, uint32_t val)
221{
222 ParallelState *s = opaque;
223 uint16_t eppdata = cpu_to_le16(val);
224 int err;
225 struct ParallelIOArg ioarg = {
0fa7f157 226 .buffer = &eppdata, .count = sizeof(eppdata)
5867c88a
TS
227 };
228 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
0fa7f157
TS
229 /* Controls not correct for EPP data cycle, so do nothing */
230 pdebug("we%04x s\n", val);
231 return;
5867c88a 232 }
41084f1b 233 err = qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
5867c88a 234 if (err) {
0fa7f157
TS
235 s->epp_timeout = 1;
236 pdebug("we%04x t\n", val);
5867c88a
TS
237 }
238 else
0fa7f157 239 pdebug("we%04x\n", val);
5867c88a
TS
240}
241
242static void
243parallel_ioport_eppdata_write_hw4(void *opaque, uint32_t addr, uint32_t val)
244{
245 ParallelState *s = opaque;
246 uint32_t eppdata = cpu_to_le32(val);
247 int err;
248 struct ParallelIOArg ioarg = {
0fa7f157 249 .buffer = &eppdata, .count = sizeof(eppdata)
5867c88a
TS
250 };
251 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
0fa7f157
TS
252 /* Controls not correct for EPP data cycle, so do nothing */
253 pdebug("we%08x s\n", val);
254 return;
5867c88a 255 }
41084f1b 256 err = qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
5867c88a 257 if (err) {
0fa7f157
TS
258 s->epp_timeout = 1;
259 pdebug("we%08x t\n", val);
6508fe59 260 }
5867c88a 261 else
0fa7f157 262 pdebug("we%08x\n", val);
6508fe59
FB
263}
264
5867c88a 265static uint32_t parallel_ioport_read_sw(void *opaque, uint32_t addr)
6508fe59
FB
266{
267 ParallelState *s = opaque;
268 uint32_t ret = 0xff;
269
270 addr &= 7;
271 switch(addr) {
5867c88a 272 case PARA_REG_DATA:
0fa7f157
TS
273 if (s->control & PARA_CTR_DIR)
274 ret = s->datar;
275 else
276 ret = s->dataw;
6508fe59 277 break;
5867c88a 278 case PARA_REG_STS:
0fa7f157
TS
279 ret = s->status;
280 s->irq_pending = 0;
281 if ((s->status & PARA_STS_BUSY) == 0 && (s->control & PARA_CTR_STROBE) == 0) {
282 /* XXX Fixme: wait 5 microseconds */
283 if (s->status & PARA_STS_ACK)
284 s->status &= ~PARA_STS_ACK;
285 else {
286 /* XXX Fixme: wait 5 microseconds */
287 s->status |= PARA_STS_ACK;
288 s->status |= PARA_STS_BUSY;
289 }
290 }
291 parallel_update_irq(s);
6508fe59 292 break;
5867c88a 293 case PARA_REG_CTR:
6508fe59
FB
294 ret = s->control;
295 break;
296 }
5867c88a
TS
297 pdebug("read addr=0x%02x val=0x%02x\n", addr, ret);
298 return ret;
299}
300
301static uint32_t parallel_ioport_read_hw(void *opaque, uint32_t addr)
302{
303 ParallelState *s = opaque;
304 uint8_t ret = 0xff;
305 addr &= 7;
306 switch(addr) {
307 case PARA_REG_DATA:
41084f1b 308 qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_DATA, &ret);
0fa7f157
TS
309 if (s->last_read_offset != addr || s->datar != ret)
310 pdebug("rd%02x\n", ret);
5867c88a
TS
311 s->datar = ret;
312 break;
313 case PARA_REG_STS:
41084f1b 314 qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &ret);
0fa7f157
TS
315 ret &= ~PARA_STS_TMOUT;
316 if (s->epp_timeout)
317 ret |= PARA_STS_TMOUT;
318 if (s->last_read_offset != addr || s->status != ret)
319 pdebug("rs%02x\n", ret);
320 s->status = ret;
5867c88a
TS
321 break;
322 case PARA_REG_CTR:
323 /* s->control has some bits fixed to 1. It is zero only when
0fa7f157
TS
324 it has not been yet written to. */
325 if (s->control == 0) {
41084f1b 326 qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_CONTROL, &ret);
0fa7f157
TS
327 if (s->last_read_offset != addr)
328 pdebug("rc%02x\n", ret);
329 s->control = ret;
330 }
331 else {
332 ret = s->control;
333 if (s->last_read_offset != addr)
334 pdebug("rc%02x\n", ret);
335 }
5867c88a
TS
336 break;
337 case PARA_REG_EPP_ADDR:
0fa7f157
TS
338 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
339 /* Controls not correct for EPP addr cycle, so do nothing */
340 pdebug("ra%02x s\n", ret);
341 else {
342 struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
41084f1b 343 if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ_ADDR, &ioarg)) {
0fa7f157
TS
344 s->epp_timeout = 1;
345 pdebug("ra%02x t\n", ret);
346 }
347 else
348 pdebug("ra%02x\n", ret);
349 }
350 break;
5867c88a 351 case PARA_REG_EPP_DATA:
0fa7f157
TS
352 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
353 /* Controls not correct for EPP data cycle, so do nothing */
354 pdebug("re%02x s\n", ret);
355 else {
356 struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
41084f1b 357 if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg)) {
0fa7f157
TS
358 s->epp_timeout = 1;
359 pdebug("re%02x t\n", ret);
360 }
361 else
362 pdebug("re%02x\n", ret);
363 }
364 break;
5867c88a
TS
365 }
366 s->last_read_offset = addr;
367 return ret;
368}
369
370static uint32_t
371parallel_ioport_eppdata_read_hw2(void *opaque, uint32_t addr)
372{
373 ParallelState *s = opaque;
374 uint32_t ret;
375 uint16_t eppdata = ~0;
376 int err;
377 struct ParallelIOArg ioarg = {
0fa7f157 378 .buffer = &eppdata, .count = sizeof(eppdata)
5867c88a
TS
379 };
380 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
0fa7f157
TS
381 /* Controls not correct for EPP data cycle, so do nothing */
382 pdebug("re%04x s\n", eppdata);
383 return eppdata;
5867c88a 384 }
41084f1b 385 err = qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
5867c88a
TS
386 ret = le16_to_cpu(eppdata);
387
388 if (err) {
0fa7f157
TS
389 s->epp_timeout = 1;
390 pdebug("re%04x t\n", ret);
5867c88a
TS
391 }
392 else
0fa7f157 393 pdebug("re%04x\n", ret);
5867c88a
TS
394 return ret;
395}
396
397static uint32_t
398parallel_ioport_eppdata_read_hw4(void *opaque, uint32_t addr)
399{
400 ParallelState *s = opaque;
401 uint32_t ret;
402 uint32_t eppdata = ~0U;
403 int err;
404 struct ParallelIOArg ioarg = {
0fa7f157 405 .buffer = &eppdata, .count = sizeof(eppdata)
5867c88a
TS
406 };
407 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
0fa7f157
TS
408 /* Controls not correct for EPP data cycle, so do nothing */
409 pdebug("re%08x s\n", eppdata);
410 return eppdata;
5867c88a 411 }
41084f1b 412 err = qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
5867c88a
TS
413 ret = le32_to_cpu(eppdata);
414
415 if (err) {
0fa7f157
TS
416 s->epp_timeout = 1;
417 pdebug("re%08x t\n", ret);
5867c88a
TS
418 }
419 else
0fa7f157 420 pdebug("re%08x\n", ret);
5867c88a
TS
421 return ret;
422}
423
424static void parallel_ioport_ecp_write(void *opaque, uint32_t addr, uint32_t val)
425{
7f5b7d3e 426 pdebug("wecp%d=%02x\n", addr & 7, val);
5867c88a
TS
427}
428
429static uint32_t parallel_ioport_ecp_read(void *opaque, uint32_t addr)
430{
431 uint8_t ret = 0xff;
7f5b7d3e
BS
432
433 pdebug("recp%d:%02x\n", addr & 7, ret);
6508fe59
FB
434 return ret;
435}
436
33093a0a 437static void parallel_reset(void *opaque)
6508fe59 438{
33093a0a
AJ
439 ParallelState *s = opaque;
440
5867c88a
TS
441 s->datar = ~0;
442 s->dataw = ~0;
6508fe59
FB
443 s->status = PARA_STS_BUSY;
444 s->status |= PARA_STS_ACK;
445 s->status |= PARA_STS_ONLINE;
446 s->status |= PARA_STS_ERROR;
52ccc5e0 447 s->status |= PARA_STS_TMOUT;
6508fe59
FB
448 s->control = PARA_CTR_SELECT;
449 s->control |= PARA_CTR_INIT;
52ccc5e0 450 s->control |= 0xc0;
5867c88a 451 s->irq_pending = 0;
5867c88a
TS
452 s->hw_driver = 0;
453 s->epp_timeout = 0;
454 s->last_read_offset = ~0U;
d60532ca
TS
455}
456
e8ee28fb
GH
457static const int isa_parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
458
1922abd0
RH
459static const MemoryRegionPortio isa_parallel_portio_hw_list[] = {
460 { 0, 8, 1,
461 .read = parallel_ioport_read_hw,
462 .write = parallel_ioport_write_hw },
463 { 4, 1, 2,
464 .read = parallel_ioport_eppdata_read_hw2,
465 .write = parallel_ioport_eppdata_write_hw2 },
466 { 4, 1, 4,
467 .read = parallel_ioport_eppdata_read_hw4,
468 .write = parallel_ioport_eppdata_write_hw4 },
469 { 0x400, 8, 1,
470 .read = parallel_ioport_ecp_read,
471 .write = parallel_ioport_ecp_write },
472 PORTIO_END_OF_LIST(),
473};
474
475static const MemoryRegionPortio isa_parallel_portio_sw_list[] = {
476 { 0, 8, 1,
477 .read = parallel_ioport_read_sw,
478 .write = parallel_ioport_write_sw },
479 PORTIO_END_OF_LIST(),
480};
481
461a2753
PD
482
483static const VMStateDescription vmstate_parallel_isa = {
484 .name = "parallel_isa",
485 .version_id = 1,
486 .minimum_version_id = 1,
487 .fields = (VMStateField[]) {
488 VMSTATE_UINT8(state.dataw, ISAParallelState),
489 VMSTATE_UINT8(state.datar, ISAParallelState),
490 VMSTATE_UINT8(state.status, ISAParallelState),
491 VMSTATE_UINT8(state.control, ISAParallelState),
492 VMSTATE_INT32(state.irq_pending, ISAParallelState),
493 VMSTATE_INT32(state.epp_timeout, ISAParallelState),
494 VMSTATE_END_OF_LIST()
495 }
496};
497
498
db895a1e 499static void parallel_isa_realizefn(DeviceState *dev, Error **errp)
d60532ca 500{
e8ee28fb 501 static int index;
db895a1e 502 ISADevice *isadev = ISA_DEVICE(dev);
b0dc5ee6 503 ISAParallelState *isa = ISA_PARALLEL(dev);
021f0674 504 ParallelState *s = &isa->state;
e8ee28fb 505 int base;
d60532ca
TS
506 uint8_t dummy;
507
021f0674 508 if (!s->chr) {
db895a1e
AF
509 error_setg(errp, "Can't create parallel device, empty char device");
510 return;
021f0674
GH
511 }
512
db895a1e 513 if (isa->index == -1) {
e8ee28fb 514 isa->index = index;
db895a1e
AF
515 }
516 if (isa->index >= MAX_PARALLEL_PORTS) {
517 error_setg(errp, "Max. supported number of parallel ports is %d.",
518 MAX_PARALLEL_PORTS);
519 return;
520 }
521 if (isa->iobase == -1) {
e8ee28fb 522 isa->iobase = isa_parallel_io[isa->index];
db895a1e 523 }
e8ee28fb
GH
524 index++;
525
526 base = isa->iobase;
db895a1e 527 isa_init_irq(isadev, &s->irq, isa->isairq);
a08d4367 528 qemu_register_reset(parallel_reset, s);
6508fe59 529
41084f1b 530 if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) {
5867c88a 531 s->hw_driver = 1;
0fa7f157 532 s->status = dummy;
5867c88a
TS
533 }
534
db895a1e 535 isa_register_portio_list(isadev, base,
1922abd0
RH
536 (s->hw_driver
537 ? &isa_parallel_portio_hw_list[0]
538 : &isa_parallel_portio_sw_list[0]),
539 s, "parallel");
021f0674
GH
540}
541
d60532ca 542/* Memory mapped interface */
a8170e5e 543static uint32_t parallel_mm_readb (void *opaque, hwaddr addr)
d60532ca
TS
544{
545 ParallelState *s = opaque;
546
8da3ff18 547 return parallel_ioport_read_sw(s, addr >> s->it_shift) & 0xFF;
d60532ca
TS
548}
549
9596ebb7 550static void parallel_mm_writeb (void *opaque,
a8170e5e 551 hwaddr addr, uint32_t value)
d60532ca
TS
552{
553 ParallelState *s = opaque;
554
8da3ff18 555 parallel_ioport_write_sw(s, addr >> s->it_shift, value & 0xFF);
d60532ca
TS
556}
557
a8170e5e 558static uint32_t parallel_mm_readw (void *opaque, hwaddr addr)
d60532ca
TS
559{
560 ParallelState *s = opaque;
561
8da3ff18 562 return parallel_ioport_read_sw(s, addr >> s->it_shift) & 0xFFFF;
d60532ca
TS
563}
564
9596ebb7 565static void parallel_mm_writew (void *opaque,
a8170e5e 566 hwaddr addr, uint32_t value)
d60532ca
TS
567{
568 ParallelState *s = opaque;
569
8da3ff18 570 parallel_ioport_write_sw(s, addr >> s->it_shift, value & 0xFFFF);
d60532ca
TS
571}
572
a8170e5e 573static uint32_t parallel_mm_readl (void *opaque, hwaddr addr)
d60532ca
TS
574{
575 ParallelState *s = opaque;
576
8da3ff18 577 return parallel_ioport_read_sw(s, addr >> s->it_shift);
d60532ca
TS
578}
579
9596ebb7 580static void parallel_mm_writel (void *opaque,
a8170e5e 581 hwaddr addr, uint32_t value)
d60532ca
TS
582{
583 ParallelState *s = opaque;
584
8da3ff18 585 parallel_ioport_write_sw(s, addr >> s->it_shift, value);
d60532ca
TS
586}
587
63858cd9
AK
588static const MemoryRegionOps parallel_mm_ops = {
589 .old_mmio = {
590 .read = { parallel_mm_readb, parallel_mm_readw, parallel_mm_readl },
591 .write = { parallel_mm_writeb, parallel_mm_writew, parallel_mm_writel },
592 },
593 .endianness = DEVICE_NATIVE_ENDIAN,
d60532ca
TS
594};
595
596/* If fd is zero, it means that the parallel device uses the console */
63858cd9 597bool parallel_mm_init(MemoryRegion *address_space,
a8170e5e 598 hwaddr base, int it_shift, qemu_irq irq,
defdb20e 599 CharDriverState *chr)
d60532ca
TS
600{
601 ParallelState *s;
d60532ca 602
7267c094 603 s = g_malloc0(sizeof(ParallelState));
33093a0a
AJ
604 s->irq = irq;
605 s->chr = chr;
d60532ca 606 s->it_shift = it_shift;
a08d4367 607 qemu_register_reset(parallel_reset, s);
d60532ca 608
2c9b15ca 609 memory_region_init_io(&s->iomem, NULL, &parallel_mm_ops, s,
63858cd9
AK
610 "parallel", 8 << it_shift);
611 memory_region_add_subregion(address_space, base, &s->iomem);
defdb20e 612 return true;
d60532ca 613}
021f0674 614
39bffca2
AL
615static Property parallel_isa_properties[] = {
616 DEFINE_PROP_UINT32("index", ISAParallelState, index, -1),
c7bcc85d 617 DEFINE_PROP_UINT32("iobase", ISAParallelState, iobase, -1),
39bffca2
AL
618 DEFINE_PROP_UINT32("irq", ISAParallelState, isairq, 7),
619 DEFINE_PROP_CHR("chardev", ISAParallelState, state.chr),
620 DEFINE_PROP_END_OF_LIST(),
621};
622
8f04ee08
AL
623static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
624{
39bffca2 625 DeviceClass *dc = DEVICE_CLASS(klass);
db895a1e
AF
626
627 dc->realize = parallel_isa_realizefn;
461a2753 628 dc->vmsd = &vmstate_parallel_isa;
39bffca2 629 dc->props = parallel_isa_properties;
125ee0ed 630 set_bit(DEVICE_CATEGORY_INPUT, dc->categories);
8f04ee08
AL
631}
632
8c43a6f0 633static const TypeInfo parallel_isa_info = {
b0dc5ee6 634 .name = TYPE_ISA_PARALLEL,
39bffca2
AL
635 .parent = TYPE_ISA_DEVICE,
636 .instance_size = sizeof(ISAParallelState),
637 .class_init = parallel_isa_class_initfn,
021f0674
GH
638};
639
83f7d43a 640static void parallel_register_types(void)
021f0674 641{
39bffca2 642 type_register_static(&parallel_isa_info);
021f0674
GH
643}
644
83f7d43a 645type_init(parallel_register_types)