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