blob: 66bc715fa49f78019ea06787bf649f1a176235ac [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;
aurel32563e3c62008-08-22 08:57:09 +0000132 int dir;
ths5867c882007-02-17 23:44:43 +0000133
134 /* Sometimes programs do several writes for timing purposes on old
135 HW. Take care not to waste time on writes that do nothing. */
136
137 s->last_read_offset = ~0U;
138
139 addr &= 7;
140 switch(addr) {
141 case PARA_REG_DATA:
142 if (s->dataw == val)
ths0fa7f152007-06-07 21:07:11 +0000143 return;
144 pdebug("wd%02x\n", val);
145 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_DATA, &parm);
146 s->dataw = val;
ths5867c882007-02-17 23:44:43 +0000147 break;
148 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000149 pdebug("ws%02x\n", val);
150 if (val & PARA_STS_TMOUT)
151 s->epp_timeout = 0;
152 break;
ths5867c882007-02-17 23:44:43 +0000153 case PARA_REG_CTR:
154 val |= 0xc0;
155 if (s->control == val)
ths0fa7f152007-06-07 21:07:11 +0000156 return;
157 pdebug("wc%02x\n", val);
aurel32563e3c62008-08-22 08:57:09 +0000158
159 if ((val & PARA_CTR_DIR) != (s->control & PARA_CTR_DIR)) {
160 if (val & PARA_CTR_DIR) {
161 dir = 1;
162 } else {
163 dir = 0;
164 }
165 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_DATA_DIR, &dir);
166 parm &= ~PARA_CTR_DIR;
167 }
168
ths0fa7f152007-06-07 21:07:11 +0000169 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm);
170 s->control = val;
ths5867c882007-02-17 23:44:43 +0000171 break;
172 case PARA_REG_EPP_ADDR:
ths0fa7f152007-06-07 21:07:11 +0000173 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
174 /* Controls not correct for EPP address cycle, so do nothing */
175 pdebug("wa%02x s\n", val);
176 else {
177 struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
178 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE_ADDR, &ioarg)) {
179 s->epp_timeout = 1;
180 pdebug("wa%02x t\n", val);
181 }
182 else
183 pdebug("wa%02x\n", val);
184 }
185 break;
ths5867c882007-02-17 23:44:43 +0000186 case PARA_REG_EPP_DATA:
ths0fa7f152007-06-07 21:07:11 +0000187 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
188 /* Controls not correct for EPP data cycle, so do nothing */
189 pdebug("we%02x s\n", val);
190 else {
191 struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
192 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg)) {
193 s->epp_timeout = 1;
194 pdebug("we%02x t\n", val);
195 }
196 else
197 pdebug("we%02x\n", val);
198 }
199 break;
ths5867c882007-02-17 23:44:43 +0000200 }
201}
202
203static void
204parallel_ioport_eppdata_write_hw2(void *opaque, uint32_t addr, uint32_t val)
205{
206 ParallelState *s = opaque;
207 uint16_t eppdata = cpu_to_le16(val);
208 int err;
209 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000210 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000211 };
212 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
ths0fa7f152007-06-07 21:07:11 +0000213 /* Controls not correct for EPP data cycle, so do nothing */
214 pdebug("we%04x s\n", val);
215 return;
ths5867c882007-02-17 23:44:43 +0000216 }
217 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
218 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000219 s->epp_timeout = 1;
220 pdebug("we%04x t\n", val);
ths5867c882007-02-17 23:44:43 +0000221 }
222 else
ths0fa7f152007-06-07 21:07:11 +0000223 pdebug("we%04x\n", val);
ths5867c882007-02-17 23:44:43 +0000224}
225
226static void
227parallel_ioport_eppdata_write_hw4(void *opaque, uint32_t addr, uint32_t val)
228{
229 ParallelState *s = opaque;
230 uint32_t eppdata = cpu_to_le32(val);
231 int err;
232 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000233 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000234 };
235 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
ths0fa7f152007-06-07 21:07:11 +0000236 /* Controls not correct for EPP data cycle, so do nothing */
237 pdebug("we%08x s\n", val);
238 return;
ths5867c882007-02-17 23:44:43 +0000239 }
240 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
241 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000242 s->epp_timeout = 1;
243 pdebug("we%08x t\n", val);
ths5867c882007-02-17 23:44:43 +0000244 }
245 else
ths0fa7f152007-06-07 21:07:11 +0000246 pdebug("we%08x\n", val);
ths5867c882007-02-17 23:44:43 +0000247}
248
249static uint32_t parallel_ioport_read_sw(void *opaque, uint32_t addr)
bellard6508fe52005-01-15 12:02:56 +0000250{
251 ParallelState *s = opaque;
252 uint32_t ret = 0xff;
253
254 addr &= 7;
255 switch(addr) {
ths5867c882007-02-17 23:44:43 +0000256 case PARA_REG_DATA:
ths0fa7f152007-06-07 21:07:11 +0000257 if (s->control & PARA_CTR_DIR)
258 ret = s->datar;
259 else
260 ret = s->dataw;
bellard6508fe52005-01-15 12:02:56 +0000261 break;
ths5867c882007-02-17 23:44:43 +0000262 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000263 ret = s->status;
264 s->irq_pending = 0;
265 if ((s->status & PARA_STS_BUSY) == 0 && (s->control & PARA_CTR_STROBE) == 0) {
266 /* XXX Fixme: wait 5 microseconds */
267 if (s->status & PARA_STS_ACK)
268 s->status &= ~PARA_STS_ACK;
269 else {
270 /* XXX Fixme: wait 5 microseconds */
271 s->status |= PARA_STS_ACK;
272 s->status |= PARA_STS_BUSY;
273 }
274 }
275 parallel_update_irq(s);
bellard6508fe52005-01-15 12:02:56 +0000276 break;
ths5867c882007-02-17 23:44:43 +0000277 case PARA_REG_CTR:
bellard6508fe52005-01-15 12:02:56 +0000278 ret = s->control;
279 break;
280 }
ths5867c882007-02-17 23:44:43 +0000281 pdebug("read addr=0x%02x val=0x%02x\n", addr, ret);
282 return ret;
283}
284
285static uint32_t parallel_ioport_read_hw(void *opaque, uint32_t addr)
286{
287 ParallelState *s = opaque;
288 uint8_t ret = 0xff;
289 addr &= 7;
290 switch(addr) {
291 case PARA_REG_DATA:
ths0fa7f152007-06-07 21:07:11 +0000292 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_DATA, &ret);
293 if (s->last_read_offset != addr || s->datar != ret)
294 pdebug("rd%02x\n", ret);
ths5867c882007-02-17 23:44:43 +0000295 s->datar = ret;
296 break;
297 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000298 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &ret);
299 ret &= ~PARA_STS_TMOUT;
300 if (s->epp_timeout)
301 ret |= PARA_STS_TMOUT;
302 if (s->last_read_offset != addr || s->status != ret)
303 pdebug("rs%02x\n", ret);
304 s->status = ret;
ths5867c882007-02-17 23:44:43 +0000305 break;
306 case PARA_REG_CTR:
307 /* s->control has some bits fixed to 1. It is zero only when
ths0fa7f152007-06-07 21:07:11 +0000308 it has not been yet written to. */
309 if (s->control == 0) {
310 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_CONTROL, &ret);
311 if (s->last_read_offset != addr)
312 pdebug("rc%02x\n", ret);
313 s->control = ret;
314 }
315 else {
316 ret = s->control;
317 if (s->last_read_offset != addr)
318 pdebug("rc%02x\n", ret);
319 }
ths5867c882007-02-17 23:44:43 +0000320 break;
321 case PARA_REG_EPP_ADDR:
ths0fa7f152007-06-07 21:07:11 +0000322 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
323 /* Controls not correct for EPP addr cycle, so do nothing */
324 pdebug("ra%02x s\n", ret);
325 else {
326 struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
327 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ_ADDR, &ioarg)) {
328 s->epp_timeout = 1;
329 pdebug("ra%02x t\n", ret);
330 }
331 else
332 pdebug("ra%02x\n", ret);
333 }
334 break;
ths5867c882007-02-17 23:44:43 +0000335 case PARA_REG_EPP_DATA:
ths0fa7f152007-06-07 21:07:11 +0000336 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
337 /* Controls not correct for EPP data cycle, so do nothing */
338 pdebug("re%02x s\n", ret);
339 else {
340 struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
341 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg)) {
342 s->epp_timeout = 1;
343 pdebug("re%02x t\n", ret);
344 }
345 else
346 pdebug("re%02x\n", ret);
347 }
348 break;
ths5867c882007-02-17 23:44:43 +0000349 }
350 s->last_read_offset = addr;
351 return ret;
352}
353
354static uint32_t
355parallel_ioport_eppdata_read_hw2(void *opaque, uint32_t addr)
356{
357 ParallelState *s = opaque;
358 uint32_t ret;
359 uint16_t eppdata = ~0;
360 int err;
361 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000362 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000363 };
364 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
ths0fa7f152007-06-07 21:07:11 +0000365 /* Controls not correct for EPP data cycle, so do nothing */
366 pdebug("re%04x s\n", eppdata);
367 return eppdata;
ths5867c882007-02-17 23:44:43 +0000368 }
369 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
370 ret = le16_to_cpu(eppdata);
371
372 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000373 s->epp_timeout = 1;
374 pdebug("re%04x t\n", ret);
ths5867c882007-02-17 23:44:43 +0000375 }
376 else
ths0fa7f152007-06-07 21:07:11 +0000377 pdebug("re%04x\n", ret);
ths5867c882007-02-17 23:44:43 +0000378 return ret;
379}
380
381static uint32_t
382parallel_ioport_eppdata_read_hw4(void *opaque, uint32_t addr)
383{
384 ParallelState *s = opaque;
385 uint32_t ret;
386 uint32_t eppdata = ~0U;
387 int err;
388 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000389 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000390 };
391 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
ths0fa7f152007-06-07 21:07:11 +0000392 /* Controls not correct for EPP data cycle, so do nothing */
393 pdebug("re%08x s\n", eppdata);
394 return eppdata;
ths5867c882007-02-17 23:44:43 +0000395 }
396 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
397 ret = le32_to_cpu(eppdata);
398
399 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000400 s->epp_timeout = 1;
401 pdebug("re%08x t\n", ret);
ths5867c882007-02-17 23:44:43 +0000402 }
403 else
ths0fa7f152007-06-07 21:07:11 +0000404 pdebug("re%08x\n", ret);
ths5867c882007-02-17 23:44:43 +0000405 return ret;
406}
407
408static void parallel_ioport_ecp_write(void *opaque, uint32_t addr, uint32_t val)
409{
410 addr &= 7;
411 pdebug("wecp%d=%02x\n", addr, val);
412}
413
414static uint32_t parallel_ioport_ecp_read(void *opaque, uint32_t addr)
415{
416 uint8_t ret = 0xff;
417 addr &= 7;
418 pdebug("recp%d:%02x\n", addr, ret);
bellard6508fe52005-01-15 12:02:56 +0000419 return ret;
420}
421
thsd60532c2007-06-18 18:55:46 +0000422static void parallel_reset(ParallelState *s, qemu_irq irq, CharDriverState *chr)
bellard6508fe52005-01-15 12:02:56 +0000423{
ths5867c882007-02-17 23:44:43 +0000424 s->datar = ~0;
425 s->dataw = ~0;
bellard6508fe52005-01-15 12:02:56 +0000426 s->status = PARA_STS_BUSY;
427 s->status |= PARA_STS_ACK;
428 s->status |= PARA_STS_ONLINE;
429 s->status |= PARA_STS_ERROR;
balrog52ccc5e2008-02-10 13:34:48 +0000430 s->status |= PARA_STS_TMOUT;
bellard6508fe52005-01-15 12:02:56 +0000431 s->control = PARA_CTR_SELECT;
432 s->control |= PARA_CTR_INIT;
balrog52ccc5e2008-02-10 13:34:48 +0000433 s->control |= 0xc0;
ths5867c882007-02-17 23:44:43 +0000434 s->irq = irq;
435 s->irq_pending = 0;
436 s->chr = chr;
437 s->hw_driver = 0;
438 s->epp_timeout = 0;
439 s->last_read_offset = ~0U;
thsd60532c2007-06-18 18:55:46 +0000440}
441
442/* If fd is zero, it means that the parallel device uses the console */
443ParallelState *parallel_init(int base, qemu_irq irq, CharDriverState *chr)
444{
445 ParallelState *s;
446 uint8_t dummy;
447
448 s = qemu_mallocz(sizeof(ParallelState));
449 if (!s)
450 return NULL;
451 parallel_reset(s, irq, chr);
bellard6508fe52005-01-15 12:02:56 +0000452
ths5867c882007-02-17 23:44:43 +0000453 if (qemu_chr_ioctl(chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) {
454 s->hw_driver = 1;
ths0fa7f152007-06-07 21:07:11 +0000455 s->status = dummy;
ths5867c882007-02-17 23:44:43 +0000456 }
457
458 if (s->hw_driver) {
ths0fa7f152007-06-07 21:07:11 +0000459 register_ioport_write(base, 8, 1, parallel_ioport_write_hw, s);
460 register_ioport_read(base, 8, 1, parallel_ioport_read_hw, s);
461 register_ioport_write(base+4, 1, 2, parallel_ioport_eppdata_write_hw2, s);
462 register_ioport_read(base+4, 1, 2, parallel_ioport_eppdata_read_hw2, s);
463 register_ioport_write(base+4, 1, 4, parallel_ioport_eppdata_write_hw4, s);
464 register_ioport_read(base+4, 1, 4, parallel_ioport_eppdata_read_hw4, s);
465 register_ioport_write(base+0x400, 8, 1, parallel_ioport_ecp_write, s);
466 register_ioport_read(base+0x400, 8, 1, parallel_ioport_ecp_read, s);
ths5867c882007-02-17 23:44:43 +0000467 }
468 else {
ths0fa7f152007-06-07 21:07:11 +0000469 register_ioport_write(base, 8, 1, parallel_ioport_write_sw, s);
470 register_ioport_read(base, 8, 1, parallel_ioport_read_sw, s);
ths5867c882007-02-17 23:44:43 +0000471 }
bellard6508fe52005-01-15 12:02:56 +0000472 return s;
473}
thsd60532c2007-06-18 18:55:46 +0000474
475/* Memory mapped interface */
pbrook9596ebb2007-11-18 01:44:38 +0000476static uint32_t parallel_mm_readb (void *opaque, target_phys_addr_t addr)
thsd60532c2007-06-18 18:55:46 +0000477{
478 ParallelState *s = opaque;
479
480 return parallel_ioport_read_sw(s, (addr - s->base) >> s->it_shift) & 0xFF;
481}
482
pbrook9596ebb2007-11-18 01:44:38 +0000483static void parallel_mm_writeb (void *opaque,
484 target_phys_addr_t addr, uint32_t value)
thsd60532c2007-06-18 18:55:46 +0000485{
486 ParallelState *s = opaque;
487
488 parallel_ioport_write_sw(s, (addr - s->base) >> s->it_shift, value & 0xFF);
489}
490
pbrook9596ebb2007-11-18 01:44:38 +0000491static uint32_t parallel_mm_readw (void *opaque, target_phys_addr_t addr)
thsd60532c2007-06-18 18:55:46 +0000492{
493 ParallelState *s = opaque;
494
495 return parallel_ioport_read_sw(s, (addr - s->base) >> s->it_shift) & 0xFFFF;
496}
497
pbrook9596ebb2007-11-18 01:44:38 +0000498static void parallel_mm_writew (void *opaque,
499 target_phys_addr_t addr, uint32_t value)
thsd60532c2007-06-18 18:55:46 +0000500{
501 ParallelState *s = opaque;
502
503 parallel_ioport_write_sw(s, (addr - s->base) >> s->it_shift, value & 0xFFFF);
504}
505
pbrook9596ebb2007-11-18 01:44:38 +0000506static uint32_t parallel_mm_readl (void *opaque, target_phys_addr_t addr)
thsd60532c2007-06-18 18:55:46 +0000507{
508 ParallelState *s = opaque;
509
510 return parallel_ioport_read_sw(s, (addr - s->base) >> s->it_shift);
511}
512
pbrook9596ebb2007-11-18 01:44:38 +0000513static void parallel_mm_writel (void *opaque,
514 target_phys_addr_t addr, uint32_t value)
thsd60532c2007-06-18 18:55:46 +0000515{
516 ParallelState *s = opaque;
517
518 parallel_ioport_write_sw(s, (addr - s->base) >> s->it_shift, value);
519}
520
521static CPUReadMemoryFunc *parallel_mm_read_sw[] = {
522 &parallel_mm_readb,
523 &parallel_mm_readw,
524 &parallel_mm_readl,
525};
526
527static CPUWriteMemoryFunc *parallel_mm_write_sw[] = {
528 &parallel_mm_writeb,
529 &parallel_mm_writew,
530 &parallel_mm_writel,
531};
532
533/* If fd is zero, it means that the parallel device uses the console */
534ParallelState *parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq, CharDriverState *chr)
535{
536 ParallelState *s;
537 int io_sw;
538
539 s = qemu_mallocz(sizeof(ParallelState));
540 if (!s)
541 return NULL;
542 parallel_reset(s, irq, chr);
543 s->base = base;
544 s->it_shift = it_shift;
545
546 io_sw = cpu_register_io_memory(0, parallel_mm_read_sw, parallel_mm_write_sw, s);
547 cpu_register_physical_memory(base, 8 << it_shift, io_sw);
548 return s;
549}