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