blob: 8402eadf9b1b79825d28f4c05c94295c04aca738 [file] [log] [blame]
bellard6508fe52005-01-15 12:02:56 +00001/*
2 * QEMU Parallel PORT emulation
ths5fafdf22007-09-16 21:08:06 +00003 *
bellarde57a8c02005-11-10 23:58:52 +00004 * Copyright (c) 2003-2005 Fabrice Bellard
ths5867c882007-02-17 23:44:43 +00005 * Copyright (c) 2007 Marko Kohtala
ths5fafdf22007-09-16 21:08:06 +00006 *
bellard6508fe52005-01-15 12:02:56 +00007 * 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 */
pbrook87ecb682007-11-17 17:14:51 +000025#include "hw.h"
26#include "qemu-char.h"
27#include "isa.h"
28#include "pc.h"
bellard6508fe52005-01-15 12:02:56 +000029
30//#define DEBUG_PARALLEL
31
ths5867c882007-02-17 23:44:43 +000032#ifdef DEBUG_PARALLEL
33#define pdebug(fmt, arg...) printf("pp: " fmt, ##arg)
34#else
35#define pdebug(fmt, arg...) ((void)0)
36#endif
37
38#define PARA_REG_DATA 0
39#define PARA_REG_STS 1
40#define PARA_REG_CTR 2
41#define PARA_REG_EPP_ADDR 3
42#define PARA_REG_EPP_DATA 4
43
bellard6508fe52005-01-15 12:02:56 +000044/*
45 * These are the definitions for the Printer Status Register
46 */
47#define PARA_STS_BUSY 0x80 /* Busy complement */
48#define PARA_STS_ACK 0x40 /* Acknowledge */
49#define PARA_STS_PAPER 0x20 /* Out of paper */
50#define PARA_STS_ONLINE 0x10 /* Online */
51#define PARA_STS_ERROR 0x08 /* Error complement */
ths5867c882007-02-17 23:44:43 +000052#define PARA_STS_TMOUT 0x01 /* EPP timeout */
bellard6508fe52005-01-15 12:02:56 +000053
54/*
55 * These are the definitions for the Printer Control Register
56 */
ths5867c882007-02-17 23:44:43 +000057#define PARA_CTR_DIR 0x20 /* Direction (1=read, 0=write) */
bellard6508fe52005-01-15 12:02:56 +000058#define PARA_CTR_INTEN 0x10 /* IRQ Enable */
59#define PARA_CTR_SELECT 0x08 /* Select In complement */
60#define PARA_CTR_INIT 0x04 /* Initialize Printer complement */
61#define PARA_CTR_AUTOLF 0x02 /* Auto linefeed complement */
62#define PARA_CTR_STROBE 0x01 /* Strobe complement */
63
ths5867c882007-02-17 23:44:43 +000064#define PARA_CTR_SIGNAL (PARA_CTR_SELECT|PARA_CTR_INIT|PARA_CTR_AUTOLF|PARA_CTR_STROBE)
65
bellard6508fe52005-01-15 12:02:56 +000066struct ParallelState {
ths5867c882007-02-17 23:44:43 +000067 uint8_t dataw;
68 uint8_t datar;
69 uint8_t status;
bellard6508fe52005-01-15 12:02:56 +000070 uint8_t control;
pbrookd537cf62007-04-07 18:14:41 +000071 qemu_irq irq;
bellard6508fe52005-01-15 12:02:56 +000072 int irq_pending;
73 CharDriverState *chr;
bellarde57a8c02005-11-10 23:58:52 +000074 int hw_driver;
ths5867c882007-02-17 23:44:43 +000075 int epp_timeout;
76 uint32_t last_read_offset; /* For debugging */
thsd60532c2007-06-18 18:55:46 +000077 /* Memory-mapped interface */
78 target_phys_addr_t base;
79 int it_shift;
bellard6508fe52005-01-15 12:02:56 +000080};
81
82static void parallel_update_irq(ParallelState *s)
83{
84 if (s->irq_pending)
pbrookd537cf62007-04-07 18:14:41 +000085 qemu_irq_raise(s->irq);
bellard6508fe52005-01-15 12:02:56 +000086 else
pbrookd537cf62007-04-07 18:14:41 +000087 qemu_irq_lower(s->irq);
bellard6508fe52005-01-15 12:02:56 +000088}
89
ths5867c882007-02-17 23:44:43 +000090static void
91parallel_ioport_write_sw(void *opaque, uint32_t addr, uint32_t val)
bellard6508fe52005-01-15 12:02:56 +000092{
93 ParallelState *s = opaque;
ths3b46e622007-09-17 08:09:54 +000094
ths5867c882007-02-17 23:44:43 +000095 pdebug("write addr=0x%02x val=0x%02x\n", addr, val);
96
bellard6508fe52005-01-15 12:02:56 +000097 addr &= 7;
bellard6508fe52005-01-15 12:02:56 +000098 switch(addr) {
ths5867c882007-02-17 23:44:43 +000099 case PARA_REG_DATA:
ths0fa7f152007-06-07 21:07:11 +0000100 s->dataw = val;
101 parallel_update_irq(s);
bellard6508fe52005-01-15 12:02:56 +0000102 break;
ths5867c882007-02-17 23:44:43 +0000103 case PARA_REG_CTR:
balrog52ccc5e2008-02-10 13:34:48 +0000104 val |= 0xc0;
ths0fa7f152007-06-07 21:07:11 +0000105 if ((val & PARA_CTR_INIT) == 0 ) {
106 s->status = PARA_STS_BUSY;
107 s->status |= PARA_STS_ACK;
108 s->status |= PARA_STS_ONLINE;
109 s->status |= PARA_STS_ERROR;
110 }
111 else if (val & PARA_CTR_SELECT) {
112 if (val & PARA_CTR_STROBE) {
113 s->status &= ~PARA_STS_BUSY;
114 if ((s->control & PARA_CTR_STROBE) == 0)
115 qemu_chr_write(s->chr, &s->dataw, 1);
116 } else {
117 if (s->control & PARA_CTR_INTEN) {
118 s->irq_pending = 1;
119 }
120 }
121 }
122 parallel_update_irq(s);
123 s->control = val;
bellard6508fe52005-01-15 12:02:56 +0000124 break;
125 }
126}
127
ths5867c882007-02-17 23:44:43 +0000128static void parallel_ioport_write_hw(void *opaque, uint32_t addr, uint32_t val)
129{
130 ParallelState *s = opaque;
131 uint8_t parm = val;
132
133 /* Sometimes programs do several writes for timing purposes on old
134 HW. Take care not to waste time on writes that do nothing. */
135
136 s->last_read_offset = ~0U;
137
138 addr &= 7;
139 switch(addr) {
140 case PARA_REG_DATA:
141 if (s->dataw == val)
ths0fa7f152007-06-07 21:07:11 +0000142 return;
143 pdebug("wd%02x\n", val);
144 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_DATA, &parm);
145 s->dataw = val;
ths5867c882007-02-17 23:44:43 +0000146 break;
147 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000148 pdebug("ws%02x\n", val);
149 if (val & PARA_STS_TMOUT)
150 s->epp_timeout = 0;
151 break;
ths5867c882007-02-17 23:44:43 +0000152 case PARA_REG_CTR:
153 val |= 0xc0;
154 if (s->control == val)
ths0fa7f152007-06-07 21:07:11 +0000155 return;
156 pdebug("wc%02x\n", val);
157 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm);
158 s->control = val;
ths5867c882007-02-17 23:44:43 +0000159 break;
160 case PARA_REG_EPP_ADDR:
ths0fa7f152007-06-07 21:07:11 +0000161 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
162 /* Controls not correct for EPP address cycle, so do nothing */
163 pdebug("wa%02x s\n", val);
164 else {
165 struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
166 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE_ADDR, &ioarg)) {
167 s->epp_timeout = 1;
168 pdebug("wa%02x t\n", val);
169 }
170 else
171 pdebug("wa%02x\n", val);
172 }
173 break;
ths5867c882007-02-17 23:44:43 +0000174 case PARA_REG_EPP_DATA:
ths0fa7f152007-06-07 21:07:11 +0000175 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
176 /* Controls not correct for EPP data cycle, so do nothing */
177 pdebug("we%02x s\n", val);
178 else {
179 struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
180 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg)) {
181 s->epp_timeout = 1;
182 pdebug("we%02x t\n", val);
183 }
184 else
185 pdebug("we%02x\n", val);
186 }
187 break;
ths5867c882007-02-17 23:44:43 +0000188 }
189}
190
191static void
192parallel_ioport_eppdata_write_hw2(void *opaque, uint32_t addr, uint32_t val)
193{
194 ParallelState *s = opaque;
195 uint16_t eppdata = cpu_to_le16(val);
196 int err;
197 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000198 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000199 };
200 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
ths0fa7f152007-06-07 21:07:11 +0000201 /* Controls not correct for EPP data cycle, so do nothing */
202 pdebug("we%04x s\n", val);
203 return;
ths5867c882007-02-17 23:44:43 +0000204 }
205 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
206 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000207 s->epp_timeout = 1;
208 pdebug("we%04x t\n", val);
ths5867c882007-02-17 23:44:43 +0000209 }
210 else
ths0fa7f152007-06-07 21:07:11 +0000211 pdebug("we%04x\n", val);
ths5867c882007-02-17 23:44:43 +0000212}
213
214static void
215parallel_ioport_eppdata_write_hw4(void *opaque, uint32_t addr, uint32_t val)
216{
217 ParallelState *s = opaque;
218 uint32_t eppdata = cpu_to_le32(val);
219 int err;
220 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000221 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000222 };
223 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
ths0fa7f152007-06-07 21:07:11 +0000224 /* Controls not correct for EPP data cycle, so do nothing */
225 pdebug("we%08x s\n", val);
226 return;
ths5867c882007-02-17 23:44:43 +0000227 }
228 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
229 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000230 s->epp_timeout = 1;
231 pdebug("we%08x t\n", val);
ths5867c882007-02-17 23:44:43 +0000232 }
233 else
ths0fa7f152007-06-07 21:07:11 +0000234 pdebug("we%08x\n", val);
ths5867c882007-02-17 23:44:43 +0000235}
236
237static uint32_t parallel_ioport_read_sw(void *opaque, uint32_t addr)
bellard6508fe52005-01-15 12:02:56 +0000238{
239 ParallelState *s = opaque;
240 uint32_t ret = 0xff;
241
242 addr &= 7;
243 switch(addr) {
ths5867c882007-02-17 23:44:43 +0000244 case PARA_REG_DATA:
ths0fa7f152007-06-07 21:07:11 +0000245 if (s->control & PARA_CTR_DIR)
246 ret = s->datar;
247 else
248 ret = s->dataw;
bellard6508fe52005-01-15 12:02:56 +0000249 break;
ths5867c882007-02-17 23:44:43 +0000250 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000251 ret = s->status;
252 s->irq_pending = 0;
253 if ((s->status & PARA_STS_BUSY) == 0 && (s->control & PARA_CTR_STROBE) == 0) {
254 /* XXX Fixme: wait 5 microseconds */
255 if (s->status & PARA_STS_ACK)
256 s->status &= ~PARA_STS_ACK;
257 else {
258 /* XXX Fixme: wait 5 microseconds */
259 s->status |= PARA_STS_ACK;
260 s->status |= PARA_STS_BUSY;
261 }
262 }
263 parallel_update_irq(s);
bellard6508fe52005-01-15 12:02:56 +0000264 break;
ths5867c882007-02-17 23:44:43 +0000265 case PARA_REG_CTR:
bellard6508fe52005-01-15 12:02:56 +0000266 ret = s->control;
267 break;
268 }
ths5867c882007-02-17 23:44:43 +0000269 pdebug("read addr=0x%02x val=0x%02x\n", addr, ret);
270 return ret;
271}
272
273static uint32_t parallel_ioport_read_hw(void *opaque, uint32_t addr)
274{
275 ParallelState *s = opaque;
276 uint8_t ret = 0xff;
277 addr &= 7;
278 switch(addr) {
279 case PARA_REG_DATA:
ths0fa7f152007-06-07 21:07:11 +0000280 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_DATA, &ret);
281 if (s->last_read_offset != addr || s->datar != ret)
282 pdebug("rd%02x\n", ret);
ths5867c882007-02-17 23:44:43 +0000283 s->datar = ret;
284 break;
285 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000286 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &ret);
287 ret &= ~PARA_STS_TMOUT;
288 if (s->epp_timeout)
289 ret |= PARA_STS_TMOUT;
290 if (s->last_read_offset != addr || s->status != ret)
291 pdebug("rs%02x\n", ret);
292 s->status = ret;
ths5867c882007-02-17 23:44:43 +0000293 break;
294 case PARA_REG_CTR:
295 /* s->control has some bits fixed to 1. It is zero only when
ths0fa7f152007-06-07 21:07:11 +0000296 it has not been yet written to. */
297 if (s->control == 0) {
298 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_CONTROL, &ret);
299 if (s->last_read_offset != addr)
300 pdebug("rc%02x\n", ret);
301 s->control = ret;
302 }
303 else {
304 ret = s->control;
305 if (s->last_read_offset != addr)
306 pdebug("rc%02x\n", ret);
307 }
ths5867c882007-02-17 23:44:43 +0000308 break;
309 case PARA_REG_EPP_ADDR:
ths0fa7f152007-06-07 21:07:11 +0000310 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
311 /* Controls not correct for EPP addr cycle, so do nothing */
312 pdebug("ra%02x s\n", ret);
313 else {
314 struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
315 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ_ADDR, &ioarg)) {
316 s->epp_timeout = 1;
317 pdebug("ra%02x t\n", ret);
318 }
319 else
320 pdebug("ra%02x\n", ret);
321 }
322 break;
ths5867c882007-02-17 23:44:43 +0000323 case PARA_REG_EPP_DATA:
ths0fa7f152007-06-07 21:07:11 +0000324 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
325 /* Controls not correct for EPP data cycle, so do nothing */
326 pdebug("re%02x s\n", ret);
327 else {
328 struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
329 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg)) {
330 s->epp_timeout = 1;
331 pdebug("re%02x t\n", ret);
332 }
333 else
334 pdebug("re%02x\n", ret);
335 }
336 break;
ths5867c882007-02-17 23:44:43 +0000337 }
338 s->last_read_offset = addr;
339 return ret;
340}
341
342static uint32_t
343parallel_ioport_eppdata_read_hw2(void *opaque, uint32_t addr)
344{
345 ParallelState *s = opaque;
346 uint32_t ret;
347 uint16_t eppdata = ~0;
348 int err;
349 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000350 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000351 };
352 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
ths0fa7f152007-06-07 21:07:11 +0000353 /* Controls not correct for EPP data cycle, so do nothing */
354 pdebug("re%04x s\n", eppdata);
355 return eppdata;
ths5867c882007-02-17 23:44:43 +0000356 }
357 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
358 ret = le16_to_cpu(eppdata);
359
360 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000361 s->epp_timeout = 1;
362 pdebug("re%04x t\n", ret);
ths5867c882007-02-17 23:44:43 +0000363 }
364 else
ths0fa7f152007-06-07 21:07:11 +0000365 pdebug("re%04x\n", ret);
ths5867c882007-02-17 23:44:43 +0000366 return ret;
367}
368
369static uint32_t
370parallel_ioport_eppdata_read_hw4(void *opaque, uint32_t addr)
371{
372 ParallelState *s = opaque;
373 uint32_t ret;
374 uint32_t eppdata = ~0U;
375 int err;
376 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000377 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000378 };
379 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
ths0fa7f152007-06-07 21:07:11 +0000380 /* Controls not correct for EPP data cycle, so do nothing */
381 pdebug("re%08x s\n", eppdata);
382 return eppdata;
ths5867c882007-02-17 23:44:43 +0000383 }
384 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
385 ret = le32_to_cpu(eppdata);
386
387 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000388 s->epp_timeout = 1;
389 pdebug("re%08x t\n", ret);
ths5867c882007-02-17 23:44:43 +0000390 }
391 else
ths0fa7f152007-06-07 21:07:11 +0000392 pdebug("re%08x\n", ret);
ths5867c882007-02-17 23:44:43 +0000393 return ret;
394}
395
396static void parallel_ioport_ecp_write(void *opaque, uint32_t addr, uint32_t val)
397{
398 addr &= 7;
399 pdebug("wecp%d=%02x\n", addr, val);
400}
401
402static uint32_t parallel_ioport_ecp_read(void *opaque, uint32_t addr)
403{
404 uint8_t ret = 0xff;
405 addr &= 7;
406 pdebug("recp%d:%02x\n", addr, ret);
bellard6508fe52005-01-15 12:02:56 +0000407 return ret;
408}
409
thsd60532c2007-06-18 18:55:46 +0000410static void parallel_reset(ParallelState *s, qemu_irq irq, CharDriverState *chr)
bellard6508fe52005-01-15 12:02:56 +0000411{
ths5867c882007-02-17 23:44:43 +0000412 s->datar = ~0;
413 s->dataw = ~0;
bellard6508fe52005-01-15 12:02:56 +0000414 s->status = PARA_STS_BUSY;
415 s->status |= PARA_STS_ACK;
416 s->status |= PARA_STS_ONLINE;
417 s->status |= PARA_STS_ERROR;
balrog52ccc5e2008-02-10 13:34:48 +0000418 s->status |= PARA_STS_TMOUT;
bellard6508fe52005-01-15 12:02:56 +0000419 s->control = PARA_CTR_SELECT;
420 s->control |= PARA_CTR_INIT;
balrog52ccc5e2008-02-10 13:34:48 +0000421 s->control |= 0xc0;
ths5867c882007-02-17 23:44:43 +0000422 s->irq = irq;
423 s->irq_pending = 0;
424 s->chr = chr;
425 s->hw_driver = 0;
426 s->epp_timeout = 0;
427 s->last_read_offset = ~0U;
thsd60532c2007-06-18 18:55:46 +0000428}
429
430/* If fd is zero, it means that the parallel device uses the console */
431ParallelState *parallel_init(int base, qemu_irq irq, CharDriverState *chr)
432{
433 ParallelState *s;
434 uint8_t dummy;
435
436 s = qemu_mallocz(sizeof(ParallelState));
437 if (!s)
438 return NULL;
439 parallel_reset(s, irq, chr);
bellard6508fe52005-01-15 12:02:56 +0000440
ths5867c882007-02-17 23:44:43 +0000441 if (qemu_chr_ioctl(chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) {
442 s->hw_driver = 1;
ths0fa7f152007-06-07 21:07:11 +0000443 s->status = dummy;
ths5867c882007-02-17 23:44:43 +0000444 }
445
446 if (s->hw_driver) {
ths0fa7f152007-06-07 21:07:11 +0000447 register_ioport_write(base, 8, 1, parallel_ioport_write_hw, s);
448 register_ioport_read(base, 8, 1, parallel_ioport_read_hw, s);
449 register_ioport_write(base+4, 1, 2, parallel_ioport_eppdata_write_hw2, s);
450 register_ioport_read(base+4, 1, 2, parallel_ioport_eppdata_read_hw2, s);
451 register_ioport_write(base+4, 1, 4, parallel_ioport_eppdata_write_hw4, s);
452 register_ioport_read(base+4, 1, 4, parallel_ioport_eppdata_read_hw4, s);
453 register_ioport_write(base+0x400, 8, 1, parallel_ioport_ecp_write, s);
454 register_ioport_read(base+0x400, 8, 1, parallel_ioport_ecp_read, s);
ths5867c882007-02-17 23:44:43 +0000455 }
456 else {
ths0fa7f152007-06-07 21:07:11 +0000457 register_ioport_write(base, 8, 1, parallel_ioport_write_sw, s);
458 register_ioport_read(base, 8, 1, parallel_ioport_read_sw, s);
ths5867c882007-02-17 23:44:43 +0000459 }
bellard6508fe52005-01-15 12:02:56 +0000460 return s;
461}
thsd60532c2007-06-18 18:55:46 +0000462
463/* Memory mapped interface */
pbrook9596ebb2007-11-18 01:44:38 +0000464static uint32_t parallel_mm_readb (void *opaque, target_phys_addr_t addr)
thsd60532c2007-06-18 18:55:46 +0000465{
466 ParallelState *s = opaque;
467
468 return parallel_ioport_read_sw(s, (addr - s->base) >> s->it_shift) & 0xFF;
469}
470
pbrook9596ebb2007-11-18 01:44:38 +0000471static void parallel_mm_writeb (void *opaque,
472 target_phys_addr_t addr, uint32_t value)
thsd60532c2007-06-18 18:55:46 +0000473{
474 ParallelState *s = opaque;
475
476 parallel_ioport_write_sw(s, (addr - s->base) >> s->it_shift, value & 0xFF);
477}
478
pbrook9596ebb2007-11-18 01:44:38 +0000479static uint32_t parallel_mm_readw (void *opaque, target_phys_addr_t addr)
thsd60532c2007-06-18 18:55:46 +0000480{
481 ParallelState *s = opaque;
482
483 return parallel_ioport_read_sw(s, (addr - s->base) >> s->it_shift) & 0xFFFF;
484}
485
pbrook9596ebb2007-11-18 01:44:38 +0000486static void parallel_mm_writew (void *opaque,
487 target_phys_addr_t addr, uint32_t value)
thsd60532c2007-06-18 18:55:46 +0000488{
489 ParallelState *s = opaque;
490
491 parallel_ioport_write_sw(s, (addr - s->base) >> s->it_shift, value & 0xFFFF);
492}
493
pbrook9596ebb2007-11-18 01:44:38 +0000494static uint32_t parallel_mm_readl (void *opaque, target_phys_addr_t addr)
thsd60532c2007-06-18 18:55:46 +0000495{
496 ParallelState *s = opaque;
497
498 return parallel_ioport_read_sw(s, (addr - s->base) >> s->it_shift);
499}
500
pbrook9596ebb2007-11-18 01:44:38 +0000501static void parallel_mm_writel (void *opaque,
502 target_phys_addr_t addr, uint32_t value)
thsd60532c2007-06-18 18:55:46 +0000503{
504 ParallelState *s = opaque;
505
506 parallel_ioport_write_sw(s, (addr - s->base) >> s->it_shift, value);
507}
508
509static CPUReadMemoryFunc *parallel_mm_read_sw[] = {
510 &parallel_mm_readb,
511 &parallel_mm_readw,
512 &parallel_mm_readl,
513};
514
515static CPUWriteMemoryFunc *parallel_mm_write_sw[] = {
516 &parallel_mm_writeb,
517 &parallel_mm_writew,
518 &parallel_mm_writel,
519};
520
521/* If fd is zero, it means that the parallel device uses the console */
522ParallelState *parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq, CharDriverState *chr)
523{
524 ParallelState *s;
525 int io_sw;
526
527 s = qemu_mallocz(sizeof(ParallelState));
528 if (!s)
529 return NULL;
530 parallel_reset(s, irq, chr);
531 s->base = base;
532 s->it_shift = it_shift;
533
534 io_sw = cpu_register_io_memory(0, parallel_mm_read_sw, parallel_mm_write_sw, s);
535 cpu_register_physical_memory(base, 8 << it_shift, io_sw);
536 return s;
537}