blob: 5d99e7655b9068c1b426eaa8cd3847cc37d258b5 [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:
ths0fa7f152007-06-07 21:07:11 +0000104 if ((val & PARA_CTR_INIT) == 0 ) {
105 s->status = PARA_STS_BUSY;
106 s->status |= PARA_STS_ACK;
107 s->status |= PARA_STS_ONLINE;
108 s->status |= PARA_STS_ERROR;
109 }
110 else if (val & PARA_CTR_SELECT) {
111 if (val & PARA_CTR_STROBE) {
112 s->status &= ~PARA_STS_BUSY;
113 if ((s->control & PARA_CTR_STROBE) == 0)
114 qemu_chr_write(s->chr, &s->dataw, 1);
115 } else {
116 if (s->control & PARA_CTR_INTEN) {
117 s->irq_pending = 1;
118 }
119 }
120 }
121 parallel_update_irq(s);
122 s->control = val;
bellard6508fe52005-01-15 12:02:56 +0000123 break;
124 }
125}
126
ths5867c882007-02-17 23:44:43 +0000127static void parallel_ioport_write_hw(void *opaque, uint32_t addr, uint32_t val)
128{
129 ParallelState *s = opaque;
130 uint8_t parm = val;
131
132 /* Sometimes programs do several writes for timing purposes on old
133 HW. Take care not to waste time on writes that do nothing. */
134
135 s->last_read_offset = ~0U;
136
137 addr &= 7;
138 switch(addr) {
139 case PARA_REG_DATA:
140 if (s->dataw == val)
ths0fa7f152007-06-07 21:07:11 +0000141 return;
142 pdebug("wd%02x\n", val);
143 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_DATA, &parm);
144 s->dataw = val;
ths5867c882007-02-17 23:44:43 +0000145 break;
146 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000147 pdebug("ws%02x\n", val);
148 if (val & PARA_STS_TMOUT)
149 s->epp_timeout = 0;
150 break;
ths5867c882007-02-17 23:44:43 +0000151 case PARA_REG_CTR:
152 val |= 0xc0;
153 if (s->control == val)
ths0fa7f152007-06-07 21:07:11 +0000154 return;
155 pdebug("wc%02x\n", val);
156 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm);
157 s->control = val;
ths5867c882007-02-17 23:44:43 +0000158 break;
159 case PARA_REG_EPP_ADDR:
ths0fa7f152007-06-07 21:07:11 +0000160 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
161 /* Controls not correct for EPP address cycle, so do nothing */
162 pdebug("wa%02x s\n", val);
163 else {
164 struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
165 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE_ADDR, &ioarg)) {
166 s->epp_timeout = 1;
167 pdebug("wa%02x t\n", val);
168 }
169 else
170 pdebug("wa%02x\n", val);
171 }
172 break;
ths5867c882007-02-17 23:44:43 +0000173 case PARA_REG_EPP_DATA:
ths0fa7f152007-06-07 21:07:11 +0000174 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
175 /* Controls not correct for EPP data cycle, so do nothing */
176 pdebug("we%02x s\n", val);
177 else {
178 struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
179 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg)) {
180 s->epp_timeout = 1;
181 pdebug("we%02x t\n", val);
182 }
183 else
184 pdebug("we%02x\n", val);
185 }
186 break;
ths5867c882007-02-17 23:44:43 +0000187 }
188}
189
190static void
191parallel_ioport_eppdata_write_hw2(void *opaque, uint32_t addr, uint32_t val)
192{
193 ParallelState *s = opaque;
194 uint16_t eppdata = cpu_to_le16(val);
195 int err;
196 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000197 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000198 };
199 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
ths0fa7f152007-06-07 21:07:11 +0000200 /* Controls not correct for EPP data cycle, so do nothing */
201 pdebug("we%04x s\n", val);
202 return;
ths5867c882007-02-17 23:44:43 +0000203 }
204 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
205 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000206 s->epp_timeout = 1;
207 pdebug("we%04x t\n", val);
ths5867c882007-02-17 23:44:43 +0000208 }
209 else
ths0fa7f152007-06-07 21:07:11 +0000210 pdebug("we%04x\n", val);
ths5867c882007-02-17 23:44:43 +0000211}
212
213static void
214parallel_ioport_eppdata_write_hw4(void *opaque, uint32_t addr, uint32_t val)
215{
216 ParallelState *s = opaque;
217 uint32_t eppdata = cpu_to_le32(val);
218 int err;
219 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000220 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000221 };
222 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
ths0fa7f152007-06-07 21:07:11 +0000223 /* Controls not correct for EPP data cycle, so do nothing */
224 pdebug("we%08x s\n", val);
225 return;
ths5867c882007-02-17 23:44:43 +0000226 }
227 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
228 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000229 s->epp_timeout = 1;
230 pdebug("we%08x t\n", val);
ths5867c882007-02-17 23:44:43 +0000231 }
232 else
ths0fa7f152007-06-07 21:07:11 +0000233 pdebug("we%08x\n", val);
ths5867c882007-02-17 23:44:43 +0000234}
235
236static uint32_t parallel_ioport_read_sw(void *opaque, uint32_t addr)
bellard6508fe52005-01-15 12:02:56 +0000237{
238 ParallelState *s = opaque;
239 uint32_t ret = 0xff;
240
241 addr &= 7;
242 switch(addr) {
ths5867c882007-02-17 23:44:43 +0000243 case PARA_REG_DATA:
ths0fa7f152007-06-07 21:07:11 +0000244 if (s->control & PARA_CTR_DIR)
245 ret = s->datar;
246 else
247 ret = s->dataw;
bellard6508fe52005-01-15 12:02:56 +0000248 break;
ths5867c882007-02-17 23:44:43 +0000249 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000250 ret = s->status;
251 s->irq_pending = 0;
252 if ((s->status & PARA_STS_BUSY) == 0 && (s->control & PARA_CTR_STROBE) == 0) {
253 /* XXX Fixme: wait 5 microseconds */
254 if (s->status & PARA_STS_ACK)
255 s->status &= ~PARA_STS_ACK;
256 else {
257 /* XXX Fixme: wait 5 microseconds */
258 s->status |= PARA_STS_ACK;
259 s->status |= PARA_STS_BUSY;
260 }
261 }
262 parallel_update_irq(s);
bellard6508fe52005-01-15 12:02:56 +0000263 break;
ths5867c882007-02-17 23:44:43 +0000264 case PARA_REG_CTR:
bellard6508fe52005-01-15 12:02:56 +0000265 ret = s->control;
266 break;
267 }
ths5867c882007-02-17 23:44:43 +0000268 pdebug("read addr=0x%02x val=0x%02x\n", addr, ret);
269 return ret;
270}
271
272static uint32_t parallel_ioport_read_hw(void *opaque, uint32_t addr)
273{
274 ParallelState *s = opaque;
275 uint8_t ret = 0xff;
276 addr &= 7;
277 switch(addr) {
278 case PARA_REG_DATA:
ths0fa7f152007-06-07 21:07:11 +0000279 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_DATA, &ret);
280 if (s->last_read_offset != addr || s->datar != ret)
281 pdebug("rd%02x\n", ret);
ths5867c882007-02-17 23:44:43 +0000282 s->datar = ret;
283 break;
284 case PARA_REG_STS:
ths0fa7f152007-06-07 21:07:11 +0000285 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &ret);
286 ret &= ~PARA_STS_TMOUT;
287 if (s->epp_timeout)
288 ret |= PARA_STS_TMOUT;
289 if (s->last_read_offset != addr || s->status != ret)
290 pdebug("rs%02x\n", ret);
291 s->status = ret;
ths5867c882007-02-17 23:44:43 +0000292 break;
293 case PARA_REG_CTR:
294 /* s->control has some bits fixed to 1. It is zero only when
ths0fa7f152007-06-07 21:07:11 +0000295 it has not been yet written to. */
296 if (s->control == 0) {
297 qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_READ_CONTROL, &ret);
298 if (s->last_read_offset != addr)
299 pdebug("rc%02x\n", ret);
300 s->control = ret;
301 }
302 else {
303 ret = s->control;
304 if (s->last_read_offset != addr)
305 pdebug("rc%02x\n", ret);
306 }
ths5867c882007-02-17 23:44:43 +0000307 break;
308 case PARA_REG_EPP_ADDR:
ths0fa7f152007-06-07 21:07:11 +0000309 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
310 /* Controls not correct for EPP addr cycle, so do nothing */
311 pdebug("ra%02x s\n", ret);
312 else {
313 struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
314 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ_ADDR, &ioarg)) {
315 s->epp_timeout = 1;
316 pdebug("ra%02x t\n", ret);
317 }
318 else
319 pdebug("ra%02x\n", ret);
320 }
321 break;
ths5867c882007-02-17 23:44:43 +0000322 case PARA_REG_EPP_DATA:
ths0fa7f152007-06-07 21:07:11 +0000323 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
324 /* Controls not correct for EPP data cycle, so do nothing */
325 pdebug("re%02x s\n", ret);
326 else {
327 struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
328 if (qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg)) {
329 s->epp_timeout = 1;
330 pdebug("re%02x t\n", ret);
331 }
332 else
333 pdebug("re%02x\n", ret);
334 }
335 break;
ths5867c882007-02-17 23:44:43 +0000336 }
337 s->last_read_offset = addr;
338 return ret;
339}
340
341static uint32_t
342parallel_ioport_eppdata_read_hw2(void *opaque, uint32_t addr)
343{
344 ParallelState *s = opaque;
345 uint32_t ret;
346 uint16_t eppdata = ~0;
347 int err;
348 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000349 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000350 };
351 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
ths0fa7f152007-06-07 21:07:11 +0000352 /* Controls not correct for EPP data cycle, so do nothing */
353 pdebug("re%04x s\n", eppdata);
354 return eppdata;
ths5867c882007-02-17 23:44:43 +0000355 }
356 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
357 ret = le16_to_cpu(eppdata);
358
359 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000360 s->epp_timeout = 1;
361 pdebug("re%04x t\n", ret);
ths5867c882007-02-17 23:44:43 +0000362 }
363 else
ths0fa7f152007-06-07 21:07:11 +0000364 pdebug("re%04x\n", ret);
ths5867c882007-02-17 23:44:43 +0000365 return ret;
366}
367
368static uint32_t
369parallel_ioport_eppdata_read_hw4(void *opaque, uint32_t addr)
370{
371 ParallelState *s = opaque;
372 uint32_t ret;
373 uint32_t eppdata = ~0U;
374 int err;
375 struct ParallelIOArg ioarg = {
ths0fa7f152007-06-07 21:07:11 +0000376 .buffer = &eppdata, .count = sizeof(eppdata)
ths5867c882007-02-17 23:44:43 +0000377 };
378 if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
ths0fa7f152007-06-07 21:07:11 +0000379 /* Controls not correct for EPP data cycle, so do nothing */
380 pdebug("re%08x s\n", eppdata);
381 return eppdata;
ths5867c882007-02-17 23:44:43 +0000382 }
383 err = qemu_chr_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
384 ret = le32_to_cpu(eppdata);
385
386 if (err) {
ths0fa7f152007-06-07 21:07:11 +0000387 s->epp_timeout = 1;
388 pdebug("re%08x t\n", ret);
ths5867c882007-02-17 23:44:43 +0000389 }
390 else
ths0fa7f152007-06-07 21:07:11 +0000391 pdebug("re%08x\n", ret);
ths5867c882007-02-17 23:44:43 +0000392 return ret;
393}
394
395static void parallel_ioport_ecp_write(void *opaque, uint32_t addr, uint32_t val)
396{
397 addr &= 7;
398 pdebug("wecp%d=%02x\n", addr, val);
399}
400
401static uint32_t parallel_ioport_ecp_read(void *opaque, uint32_t addr)
402{
403 uint8_t ret = 0xff;
404 addr &= 7;
405 pdebug("recp%d:%02x\n", addr, ret);
bellard6508fe52005-01-15 12:02:56 +0000406 return ret;
407}
408
thsd60532c2007-06-18 18:55:46 +0000409static void parallel_reset(ParallelState *s, qemu_irq irq, CharDriverState *chr)
bellard6508fe52005-01-15 12:02:56 +0000410{
ths5867c882007-02-17 23:44:43 +0000411 s->datar = ~0;
412 s->dataw = ~0;
bellard6508fe52005-01-15 12:02:56 +0000413 s->status = PARA_STS_BUSY;
414 s->status |= PARA_STS_ACK;
415 s->status |= PARA_STS_ONLINE;
416 s->status |= PARA_STS_ERROR;
417 s->control = PARA_CTR_SELECT;
418 s->control |= PARA_CTR_INIT;
ths5867c882007-02-17 23:44:43 +0000419 s->irq = irq;
420 s->irq_pending = 0;
421 s->chr = chr;
422 s->hw_driver = 0;
423 s->epp_timeout = 0;
424 s->last_read_offset = ~0U;
thsd60532c2007-06-18 18:55:46 +0000425}
426
427/* If fd is zero, it means that the parallel device uses the console */
428ParallelState *parallel_init(int base, qemu_irq irq, CharDriverState *chr)
429{
430 ParallelState *s;
431 uint8_t dummy;
432
433 s = qemu_mallocz(sizeof(ParallelState));
434 if (!s)
435 return NULL;
436 parallel_reset(s, irq, chr);
bellard6508fe52005-01-15 12:02:56 +0000437
ths5867c882007-02-17 23:44:43 +0000438 if (qemu_chr_ioctl(chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) {
439 s->hw_driver = 1;
ths0fa7f152007-06-07 21:07:11 +0000440 s->status = dummy;
ths5867c882007-02-17 23:44:43 +0000441 }
442
443 if (s->hw_driver) {
ths0fa7f152007-06-07 21:07:11 +0000444 register_ioport_write(base, 8, 1, parallel_ioport_write_hw, s);
445 register_ioport_read(base, 8, 1, parallel_ioport_read_hw, s);
446 register_ioport_write(base+4, 1, 2, parallel_ioport_eppdata_write_hw2, s);
447 register_ioport_read(base+4, 1, 2, parallel_ioport_eppdata_read_hw2, s);
448 register_ioport_write(base+4, 1, 4, parallel_ioport_eppdata_write_hw4, s);
449 register_ioport_read(base+4, 1, 4, parallel_ioport_eppdata_read_hw4, s);
450 register_ioport_write(base+0x400, 8, 1, parallel_ioport_ecp_write, s);
451 register_ioport_read(base+0x400, 8, 1, parallel_ioport_ecp_read, s);
ths5867c882007-02-17 23:44:43 +0000452 }
453 else {
ths0fa7f152007-06-07 21:07:11 +0000454 register_ioport_write(base, 8, 1, parallel_ioport_write_sw, s);
455 register_ioport_read(base, 8, 1, parallel_ioport_read_sw, s);
ths5867c882007-02-17 23:44:43 +0000456 }
bellard6508fe52005-01-15 12:02:56 +0000457 return s;
458}
thsd60532c2007-06-18 18:55:46 +0000459
460/* Memory mapped interface */
pbrook9596ebb2007-11-18 01:44:38 +0000461static uint32_t parallel_mm_readb (void *opaque, target_phys_addr_t addr)
thsd60532c2007-06-18 18:55:46 +0000462{
463 ParallelState *s = opaque;
464
465 return parallel_ioport_read_sw(s, (addr - s->base) >> s->it_shift) & 0xFF;
466}
467
pbrook9596ebb2007-11-18 01:44:38 +0000468static void parallel_mm_writeb (void *opaque,
469 target_phys_addr_t addr, uint32_t value)
thsd60532c2007-06-18 18:55:46 +0000470{
471 ParallelState *s = opaque;
472
473 parallel_ioport_write_sw(s, (addr - s->base) >> s->it_shift, value & 0xFF);
474}
475
pbrook9596ebb2007-11-18 01:44:38 +0000476static uint32_t parallel_mm_readw (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) & 0xFFFF;
481}
482
pbrook9596ebb2007-11-18 01:44:38 +0000483static void parallel_mm_writew (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 & 0xFFFF);
489}
490
pbrook9596ebb2007-11-18 01:44:38 +0000491static uint32_t parallel_mm_readl (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);
496}
497
pbrook9596ebb2007-11-18 01:44:38 +0000498static void parallel_mm_writel (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);
504}
505
506static CPUReadMemoryFunc *parallel_mm_read_sw[] = {
507 &parallel_mm_readb,
508 &parallel_mm_readw,
509 &parallel_mm_readl,
510};
511
512static CPUWriteMemoryFunc *parallel_mm_write_sw[] = {
513 &parallel_mm_writeb,
514 &parallel_mm_writew,
515 &parallel_mm_writel,
516};
517
518/* If fd is zero, it means that the parallel device uses the console */
519ParallelState *parallel_mm_init(target_phys_addr_t base, int it_shift, qemu_irq irq, CharDriverState *chr)
520{
521 ParallelState *s;
522 int io_sw;
523
524 s = qemu_mallocz(sizeof(ParallelState));
525 if (!s)
526 return NULL;
527 parallel_reset(s, irq, chr);
528 s->base = base;
529 s->it_shift = it_shift;
530
531 io_sw = cpu_register_io_memory(0, parallel_mm_read_sw, parallel_mm_write_sw, s);
532 cpu_register_physical_memory(base, 8 << it_shift, io_sw);
533 return s;
534}