]> git.proxmox.com Git - mirror_qemu.git/blame - hw/dma/i8257.c
migration: Move the VMStateDescription typedef to typedefs.h
[mirror_qemu.git] / hw / dma / i8257.c
CommitLineData
27503323
FB
1/*
2 * QEMU DMA emulation
85571bc7
FB
3 *
4 * Copyright (c) 2003-2004 Vassili Karpov (malc)
5 *
27503323
FB
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
0b8fa32f 24
b6a0aa05 25#include "qemu/osdep.h"
83c9f4ca 26#include "hw/hw.h"
0d09e41a 27#include "hw/isa/isa.h"
55f613ac 28#include "hw/dma/i8257.h"
1de7afc9 29#include "qemu/main-loop.h"
0b8fa32f 30#include "qemu/module.h"
c1a00ff8 31#include "qemu/log.h"
7dbb4c49 32#include "trace.h"
27503323 33
340e19eb
HP
34#define I8257(obj) \
35 OBJECT_CHECK(I8257State, (obj), TYPE_I8257)
36
85571bc7 37/* #define DEBUG_DMA */
7ebb5e41 38
85571bc7 39#define dolog(...) fprintf (stderr, "dma: " __VA_ARGS__)
27503323 40#ifdef DEBUG_DMA
27503323
FB
41#define linfo(...) fprintf (stderr, "dma: " __VA_ARGS__)
42#define ldebug(...) fprintf (stderr, "dma: " __VA_ARGS__)
43#else
27503323
FB
44#define linfo(...)
45#define ldebug(...)
46#endif
47
27503323
FB
48#define ADDR 0
49#define COUNT 1
50
27503323 51enum {
e875c40a
FB
52 CMD_MEMORY_TO_MEMORY = 0x01,
53 CMD_FIXED_ADDRESS = 0x02,
54 CMD_BLOCK_CONTROLLER = 0x04,
55 CMD_COMPRESSED_TIME = 0x08,
56 CMD_CYCLIC_PRIORITY = 0x10,
57 CMD_EXTENDED_WRITE = 0x20,
58 CMD_LOW_DREQ = 0x40,
59 CMD_LOW_DACK = 0x80,
60 CMD_NOT_SUPPORTED = CMD_MEMORY_TO_MEMORY | CMD_FIXED_ADDRESS
61 | CMD_COMPRESSED_TIME | CMD_CYCLIC_PRIORITY | CMD_EXTENDED_WRITE
62 | CMD_LOW_DREQ | CMD_LOW_DACK
27503323
FB
63
64};
65
b9ebd28c 66static void i8257_dma_run(void *opaque);
492c30af 67
8d3c4c81 68static const int channels[8] = {-1, 2, 3, 1, -1, -1, -1, 0};
9eb153f1 69
74c47de0 70static void i8257_write_page(void *opaque, uint32_t nport, uint32_t data)
27503323 71{
6a128b13 72 I8257State *d = opaque;
27503323 73 int ichan;
27503323 74
9eb153f1 75 ichan = channels[nport & 7];
27503323 76 if (-1 == ichan) {
85571bc7 77 dolog ("invalid channel %#x %#x\n", nport, data);
27503323
FB
78 return;
79 }
9eb153f1
FB
80 d->regs[ichan].page = data;
81}
82
74c47de0 83static void i8257_write_pageh(void *opaque, uint32_t nport, uint32_t data)
9eb153f1 84{
6a128b13 85 I8257State *d = opaque;
9eb153f1 86 int ichan;
27503323 87
9eb153f1 88 ichan = channels[nport & 7];
b0bda528 89 if (-1 == ichan) {
85571bc7 90 dolog ("invalid channel %#x %#x\n", nport, data);
b0bda528
FB
91 return;
92 }
93 d->regs[ichan].pageh = data;
94}
9eb153f1 95
74c47de0 96static uint32_t i8257_read_page(void *opaque, uint32_t nport)
b0bda528 97{
6a128b13 98 I8257State *d = opaque;
b0bda528
FB
99 int ichan;
100
101 ichan = channels[nport & 7];
9eb153f1 102 if (-1 == ichan) {
85571bc7 103 dolog ("invalid channel read %#x\n", nport);
9eb153f1
FB
104 return 0;
105 }
106 return d->regs[ichan].page;
27503323
FB
107}
108
74c47de0 109static uint32_t i8257_read_pageh(void *opaque, uint32_t nport)
b0bda528 110{
6a128b13 111 I8257State *d = opaque;
b0bda528
FB
112 int ichan;
113
114 ichan = channels[nport & 7];
115 if (-1 == ichan) {
85571bc7 116 dolog ("invalid channel read %#x\n", nport);
b0bda528
FB
117 return 0;
118 }
119 return d->regs[ichan].pageh;
120}
121
74c47de0 122static inline void i8257_init_chan(I8257State *d, int ichan)
27503323 123{
0eee6d62 124 I8257Regs *r;
27503323 125
9eb153f1 126 r = d->regs + ichan;
85571bc7 127 r->now[ADDR] = r->base[ADDR] << d->dshift;
27503323
FB
128 r->now[COUNT] = 0;
129}
130
74c47de0 131static inline int i8257_getff(I8257State *d)
27503323
FB
132{
133 int ff;
134
9eb153f1
FB
135 ff = d->flip_flop;
136 d->flip_flop = !ff;
27503323
FB
137 return ff;
138}
139
74c47de0 140static uint64_t i8257_read_chan(void *opaque, hwaddr nport, unsigned size)
27503323 141{
6a128b13 142 I8257State *d = opaque;
85571bc7 143 int ichan, nreg, iport, ff, val, dir;
0eee6d62 144 I8257Regs *r;
27503323 145
9eb153f1
FB
146 iport = (nport >> d->dshift) & 0x0f;
147 ichan = iport >> 1;
148 nreg = iport & 1;
149 r = d->regs + ichan;
27503323 150
85571bc7 151 dir = ((r->mode >> 5) & 1) ? -1 : 1;
74c47de0 152 ff = i8257_getff(d);
27503323 153 if (nreg)
9eb153f1 154 val = (r->base[COUNT] << d->dshift) - r->now[COUNT];
27503323 155 else
85571bc7 156 val = r->now[ADDR] + r->now[COUNT] * dir;
27503323 157
85571bc7 158 ldebug ("read_chan %#x -> %d\n", iport, val);
9eb153f1 159 return (val >> (d->dshift + (ff << 3))) & 0xff;
27503323
FB
160}
161
74c47de0
HP
162static void i8257_write_chan(void *opaque, hwaddr nport, uint64_t data,
163 unsigned int size)
27503323 164{
6a128b13 165 I8257State *d = opaque;
9eb153f1 166 int iport, ichan, nreg;
0eee6d62 167 I8257Regs *r;
27503323 168
9eb153f1
FB
169 iport = (nport >> d->dshift) & 0x0f;
170 ichan = iport >> 1;
171 nreg = iport & 1;
172 r = d->regs + ichan;
74c47de0 173 if (i8257_getff(d)) {
3504fe17 174 r->base[nreg] = (r->base[nreg] & 0xff) | ((data << 8) & 0xff00);
74c47de0 175 i8257_init_chan(d, ichan);
3504fe17
FB
176 } else {
177 r->base[nreg] = (r->base[nreg] & 0xff00) | (data & 0xff);
27503323 178 }
27503323
FB
179}
180
74c47de0
HP
181static void i8257_write_cont(void *opaque, hwaddr nport, uint64_t data,
182 unsigned int size)
27503323 183{
6a128b13 184 I8257State *d = opaque;
85571bc7 185 int iport, ichan = 0;
27503323 186
9eb153f1 187 iport = (nport >> d->dshift) & 0x0f;
27503323 188 switch (iport) {
ecd584b8 189 case 0x00: /* command */
df475d18 190 if ((data != 0) && (data & CMD_NOT_SUPPORTED)) {
c1a00ff8
PMD
191 qemu_log_mask(LOG_UNIMP, "%s: cmd 0x%02"PRIx64" not supported\n",
192 __func__, data);
df475d18 193 return;
27503323
FB
194 }
195 d->command = data;
196 break;
197
ecd584b8 198 case 0x01:
27503323
FB
199 ichan = data & 3;
200 if (data & 4) {
201 d->status |= 1 << (ichan + 4);
202 }
203 else {
204 d->status &= ~(1 << (ichan + 4));
205 }
206 d->status &= ~(1 << ichan);
b9ebd28c 207 i8257_dma_run(d);
27503323
FB
208 break;
209
ecd584b8 210 case 0x02: /* single mask */
27503323
FB
211 if (data & 4)
212 d->mask |= 1 << (data & 3);
213 else
214 d->mask &= ~(1 << (data & 3));
b9ebd28c 215 i8257_dma_run(d);
27503323
FB
216 break;
217
ecd584b8 218 case 0x03: /* mode */
27503323 219 {
16d17fdb
FB
220 ichan = data & 3;
221#ifdef DEBUG_DMA
85571bc7
FB
222 {
223 int op, ai, dir, opmode;
e875c40a
FB
224 op = (data >> 2) & 3;
225 ai = (data >> 4) & 1;
226 dir = (data >> 5) & 1;
227 opmode = (data >> 6) & 3;
27503323 228
e875c40a
FB
229 linfo ("ichan %d, op %d, ai %d, dir %d, opmode %d\n",
230 ichan, op, ai, dir, opmode);
85571bc7 231 }
27503323 232#endif
27503323
FB
233 d->regs[ichan].mode = data;
234 break;
235 }
236
ecd584b8 237 case 0x04: /* clear flip flop */
27503323
FB
238 d->flip_flop = 0;
239 break;
240
ecd584b8 241 case 0x05: /* reset */
27503323
FB
242 d->flip_flop = 0;
243 d->mask = ~0;
244 d->status = 0;
245 d->command = 0;
246 break;
247
ecd584b8 248 case 0x06: /* clear mask for all channels */
27503323 249 d->mask = 0;
b9ebd28c 250 i8257_dma_run(d);
27503323
FB
251 break;
252
ecd584b8 253 case 0x07: /* write mask for all channels */
27503323 254 d->mask = data;
b9ebd28c 255 i8257_dma_run(d);
27503323
FB
256 break;
257
258 default:
85571bc7 259 dolog ("unknown iport %#x\n", iport);
df475d18 260 break;
27503323
FB
261 }
262
16d17fdb 263#ifdef DEBUG_DMA
27503323 264 if (0xc != iport) {
85571bc7 265 linfo ("write_cont: nport %#06x, ichan % 2d, val %#06x\n",
9eb153f1 266 nport, ichan, data);
27503323
FB
267 }
268#endif
27503323
FB
269}
270
74c47de0 271static uint64_t i8257_read_cont(void *opaque, hwaddr nport, unsigned size)
9eb153f1 272{
6a128b13 273 I8257State *d = opaque;
9eb153f1 274 int iport, val;
85571bc7 275
9eb153f1
FB
276 iport = (nport >> d->dshift) & 0x0f;
277 switch (iport) {
ecd584b8 278 case 0x00: /* status */
9eb153f1
FB
279 val = d->status;
280 d->status &= 0xf0;
281 break;
ecd584b8 282 case 0x01: /* mask */
9eb153f1
FB
283 val = d->mask;
284 break;
285 default:
286 val = 0;
287 break;
288 }
85571bc7
FB
289
290 ldebug ("read_cont: nport %#06x, iport %#04x val %#x\n", nport, iport, val);
9eb153f1
FB
291 return val;
292}
293
16ffe363
HP
294static IsaDmaTransferMode i8257_dma_get_transfer_mode(IsaDma *obj, int nchan)
295{
296 I8257State *d = I8257(obj);
297 return (d->regs[nchan & 3].mode >> 2) & 3;
298}
299
300static bool i8257_dma_has_autoinitialization(IsaDma *obj, int nchan)
27503323 301{
16ffe363
HP
302 I8257State *d = I8257(obj);
303 return (d->regs[nchan & 3].mode >> 4) & 1;
27503323
FB
304}
305
16ffe363 306static void i8257_dma_hold_DREQ(IsaDma *obj, int nchan)
27503323 307{
16ffe363
HP
308 I8257State *d = I8257(obj);
309 int ichan;
27503323 310
27503323 311 ichan = nchan & 3;
16ffe363
HP
312 d->status |= 1 << (ichan + 4);
313 i8257_dma_run(d);
27503323
FB
314}
315
16ffe363 316static void i8257_dma_release_DREQ(IsaDma *obj, int nchan)
27503323 317{
16ffe363
HP
318 I8257State *d = I8257(obj);
319 int ichan;
27503323 320
27503323 321 ichan = nchan & 3;
16ffe363
HP
322 d->status &= ~(1 << (ichan + 4));
323 i8257_dma_run(d);
27503323
FB
324}
325
b9ebd28c 326static void i8257_channel_run(I8257State *d, int ichan)
27503323 327{
b9ebd28c 328 int ncont = d->dshift;
27503323 329 int n;
b9ebd28c 330 I8257Regs *r = &d->regs[ichan];
85571bc7
FB
331#ifdef DEBUG_DMA
332 int dir, opmode;
27503323 333
85571bc7
FB
334 dir = (r->mode >> 5) & 1;
335 opmode = (r->mode >> 6) & 3;
27503323 336
85571bc7
FB
337 if (dir) {
338 dolog ("DMA in address decrement mode\n");
339 }
340 if (opmode != 1) {
341 dolog ("DMA not in single mode select %#x\n", opmode);
342 }
343#endif
27503323 344
85571bc7
FB
345 n = r->transfer_handler (r->opaque, ichan + (ncont << 2),
346 r->now[COUNT], (r->base[COUNT] + 1) << ncont);
347 r->now[COUNT] = n;
348 ldebug ("dma_pos %d size %d\n", n, (r->base[COUNT] + 1) << ncont);
bb8f32c0
HP
349 if (n == (r->base[COUNT] + 1) << ncont) {
350 ldebug("transfer done\n");
351 d->status |= (1 << ichan);
352 }
27503323
FB
353}
354
b9ebd28c 355static void i8257_dma_run(void *opaque)
27503323 356{
b9ebd28c
HP
357 I8257State *d = opaque;
358 int ichan;
492c30af 359 int rearm = 0;
acae6f1c 360
b9ebd28c 361 if (d->running) {
acae6f1c
KW
362 rearm = 1;
363 goto out;
364 } else {
b9ebd28c 365 d->running = 1;
acae6f1c 366 }
27503323 367
b9ebd28c
HP
368 for (ichan = 0; ichan < 4; ichan++) {
369 int mask;
27503323 370
b9ebd28c 371 mask = 1 << ichan;
27503323 372
b9ebd28c
HP
373 if ((0 == (d->mask & mask)) && (0 != (d->status & (mask << 4)))) {
374 i8257_channel_run(d, ichan);
375 rearm = 1;
27503323
FB
376 }
377 }
492c30af 378
b9ebd28c 379 d->running = 0;
acae6f1c 380out:
19d2b5e6 381 if (rearm) {
b9ebd28c
HP
382 qemu_bh_schedule_idle(d->dma_bh);
383 d->dma_bh_scheduled = true;
19d2b5e6 384 }
492c30af
AL
385}
386
16ffe363 387static void i8257_dma_register_channel(IsaDma *obj, int nchan,
bd36a618 388 IsaDmaTransferHandler transfer_handler,
16ffe363 389 void *opaque)
27503323 390{
16ffe363 391 I8257State *d = I8257(obj);
0eee6d62 392 I8257Regs *r;
16ffe363 393 int ichan;
27503323 394
27503323
FB
395 ichan = nchan & 3;
396
16ffe363 397 r = d->regs + ichan;
16f62432
FB
398 r->transfer_handler = transfer_handler;
399 r->opaque = opaque;
400}
401
16ffe363
HP
402static int i8257_dma_read_memory(IsaDma *obj, int nchan, void *buf, int pos,
403 int len)
85571bc7 404{
16ffe363
HP
405 I8257State *d = I8257(obj);
406 I8257Regs *r = &d->regs[nchan & 3];
a8170e5e 407 hwaddr addr = ((r->pageh & 0x7f) << 24) | (r->page << 16) | r->now[ADDR];
85571bc7
FB
408
409 if (r->mode & 0x20) {
410 int i;
411 uint8_t *p = buf;
412
413 cpu_physical_memory_read (addr - pos - len, buf, len);
414 /* What about 16bit transfers? */
415 for (i = 0; i < len >> 1; i++) {
416 uint8_t b = p[len - i - 1];
417 p[i] = b;
418 }
419 }
420 else
421 cpu_physical_memory_read (addr + pos, buf, len);
422
423 return len;
424}
425
16ffe363
HP
426static int i8257_dma_write_memory(IsaDma *obj, int nchan, void *buf, int pos,
427 int len)
85571bc7 428{
16ffe363
HP
429 I8257State *s = I8257(obj);
430 I8257Regs *r = &s->regs[nchan & 3];
a8170e5e 431 hwaddr addr = ((r->pageh & 0x7f) << 24) | (r->page << 16) | r->now[ADDR];
85571bc7
FB
432
433 if (r->mode & 0x20) {
434 int i;
435 uint8_t *p = buf;
436
437 cpu_physical_memory_write (addr - pos - len, buf, len);
438 /* What about 16bit transfers? */
439 for (i = 0; i < len; i++) {
440 uint8_t b = p[len - i - 1];
441 p[i] = b;
442 }
443 }
444 else
445 cpu_physical_memory_write (addr + pos, buf, len);
446
447 return len;
448}
449
19d2b5e6
PB
450/* request the emulator to transfer a new DMA memory block ASAP (even
451 * if the idle bottom half would not have exited the iothread yet).
452 */
16ffe363 453static void i8257_dma_schedule(IsaDma *obj)
16f62432 454{
16ffe363
HP
455 I8257State *d = I8257(obj);
456 if (d->dma_bh_scheduled) {
19d2b5e6
PB
457 qemu_notify_event();
458 }
27503323
FB
459}
460
340e19eb 461static void i8257_reset(DeviceState *dev)
d7d02e3c 462{
340e19eb 463 I8257State *d = I8257(dev);
74c47de0 464 i8257_write_cont(d, (0x05 << d->dshift), 0, 1);
d7d02e3c
FB
465}
466
74c47de0
HP
467static int i8257_phony_handler(void *opaque, int nchan, int dma_pos,
468 int dma_len)
ca9cc28c 469{
7dbb4c49 470 trace_i8257_unregistered_dma(nchan, dma_pos, dma_len);
ca9cc28c
AZ
471 return dma_pos;
472}
473
58229933
JG
474
475static const MemoryRegionOps channel_io_ops = {
74c47de0
HP
476 .read = i8257_read_chan,
477 .write = i8257_write_chan,
58229933
JG
478 .endianness = DEVICE_NATIVE_ENDIAN,
479 .impl = {
480 .min_access_size = 1,
481 .max_access_size = 1,
482 },
483};
484
485/* IOport from page_base */
486static const MemoryRegionPortio page_portio_list[] = {
74c47de0
HP
487 { 0x01, 3, 1, .write = i8257_write_page, .read = i8257_read_page, },
488 { 0x07, 1, 1, .write = i8257_write_page, .read = i8257_read_page, },
58229933
JG
489 PORTIO_END_OF_LIST(),
490};
491
492/* IOport from pageh_base */
493static const MemoryRegionPortio pageh_portio_list[] = {
74c47de0
HP
494 { 0x01, 3, 1, .write = i8257_write_pageh, .read = i8257_read_pageh, },
495 { 0x07, 3, 1, .write = i8257_write_pageh, .read = i8257_read_pageh, },
58229933
JG
496 PORTIO_END_OF_LIST(),
497};
498
499static const MemoryRegionOps cont_io_ops = {
74c47de0
HP
500 .read = i8257_read_cont,
501 .write = i8257_write_cont,
58229933
JG
502 .endianness = DEVICE_NATIVE_ENDIAN,
503 .impl = {
504 .min_access_size = 1,
505 .max_access_size = 1,
506 },
507};
508
0eee6d62 509static const VMStateDescription vmstate_i8257_regs = {
7b5045c5
JQ
510 .name = "dma_regs",
511 .version_id = 1,
512 .minimum_version_id = 1,
d49805ae 513 .fields = (VMStateField[]) {
0eee6d62
HP
514 VMSTATE_INT32_ARRAY(now, I8257Regs, 2),
515 VMSTATE_UINT16_ARRAY(base, I8257Regs, 2),
516 VMSTATE_UINT8(mode, I8257Regs),
517 VMSTATE_UINT8(page, I8257Regs),
518 VMSTATE_UINT8(pageh, I8257Regs),
519 VMSTATE_UINT8(dack, I8257Regs),
520 VMSTATE_UINT8(eop, I8257Regs),
7b5045c5 521 VMSTATE_END_OF_LIST()
85571bc7 522 }
7b5045c5 523};
85571bc7 524
74c47de0 525static int i8257_post_load(void *opaque, int version_id)
85571bc7 526{
b9ebd28c
HP
527 I8257State *d = opaque;
528 i8257_dma_run(d);
492c30af 529
85571bc7
FB
530 return 0;
531}
532
340e19eb 533static const VMStateDescription vmstate_i8257 = {
7b5045c5
JQ
534 .name = "dma",
535 .version_id = 1,
536 .minimum_version_id = 1,
74c47de0 537 .post_load = i8257_post_load,
d49805ae 538 .fields = (VMStateField[]) {
6a128b13
HP
539 VMSTATE_UINT8(command, I8257State),
540 VMSTATE_UINT8(mask, I8257State),
541 VMSTATE_UINT8(flip_flop, I8257State),
542 VMSTATE_INT32(dshift, I8257State),
0eee6d62
HP
543 VMSTATE_STRUCT_ARRAY(regs, I8257State, 4, 1, vmstate_i8257_regs,
544 I8257Regs),
7b5045c5
JQ
545 VMSTATE_END_OF_LIST()
546 }
547};
548
340e19eb
HP
549static void i8257_realize(DeviceState *dev, Error **errp)
550{
551 ISADevice *isa = ISA_DEVICE(dev);
552 I8257State *d = I8257(dev);
553 int i;
554
555 memory_region_init_io(&d->channel_io, NULL, &channel_io_ops, d,
556 "dma-chan", 8 << d->dshift);
557 memory_region_add_subregion(isa_address_space_io(isa),
558 d->base, &d->channel_io);
559
e305a165
MAL
560 isa_register_portio_list(isa, &d->portio_page,
561 d->page_base, page_portio_list, d,
340e19eb
HP
562 "dma-page");
563 if (d->pageh_base >= 0) {
e305a165
MAL
564 isa_register_portio_list(isa, &d->portio_pageh,
565 d->pageh_base, pageh_portio_list, d,
340e19eb
HP
566 "dma-pageh");
567 }
568
569 memory_region_init_io(&d->cont_io, OBJECT(isa), &cont_io_ops, d,
570 "dma-cont", 8 << d->dshift);
571 memory_region_add_subregion(isa_address_space_io(isa),
572 d->base + (8 << d->dshift), &d->cont_io);
573
574 for (i = 0; i < ARRAY_SIZE(d->regs); ++i) {
575 d->regs[i].transfer_handler = i8257_phony_handler;
576 }
577
578 d->dma_bh = qemu_bh_new(i8257_dma_run, d);
579}
580
581static Property i8257_properties[] = {
582 DEFINE_PROP_INT32("base", I8257State, base, 0x00),
583 DEFINE_PROP_INT32("page-base", I8257State, page_base, 0x80),
584 DEFINE_PROP_INT32("pageh-base", I8257State, pageh_base, 0x480),
585 DEFINE_PROP_INT32("dshift", I8257State, dshift, 0),
586 DEFINE_PROP_END_OF_LIST()
587};
588
589static void i8257_class_init(ObjectClass *klass, void *data)
590{
591 DeviceClass *dc = DEVICE_CLASS(klass);
16ffe363 592 IsaDmaClass *idc = ISADMA_CLASS(klass);
340e19eb
HP
593
594 dc->realize = i8257_realize;
595 dc->reset = i8257_reset;
596 dc->vmsd = &vmstate_i8257;
597 dc->props = i8257_properties;
16ffe363
HP
598
599 idc->get_transfer_mode = i8257_dma_get_transfer_mode;
600 idc->has_autoinitialization = i8257_dma_has_autoinitialization;
601 idc->read_memory = i8257_dma_read_memory;
602 idc->write_memory = i8257_dma_write_memory;
603 idc->hold_DREQ = i8257_dma_hold_DREQ;
604 idc->release_DREQ = i8257_dma_release_DREQ;
605 idc->schedule = i8257_dma_schedule;
606 idc->register_channel = i8257_dma_register_channel;
a952c186 607 /* Reason: needs to be wired up by isa_bus_dma() to work */
e90f2a8c 608 dc->user_creatable = false;
16ffe363
HP
609}
610
340e19eb
HP
611static const TypeInfo i8257_info = {
612 .name = TYPE_I8257,
613 .parent = TYPE_ISA_DEVICE,
614 .instance_size = sizeof(I8257State),
615 .class_init = i8257_class_init,
16ffe363
HP
616 .interfaces = (InterfaceInfo[]) {
617 { TYPE_ISADMA },
618 { }
619 }
340e19eb
HP
620};
621
622static void i8257_register_types(void)
623{
624 type_register_static(&i8257_info);
625}
626
627type_init(i8257_register_types)
628
55f613ac 629void i8257_dma_init(ISABus *bus, bool high_page_enable)
9eb153f1 630{
340e19eb
HP
631 ISADevice *isa1, *isa2;
632 DeviceState *d;
633
634 isa1 = isa_create(bus, TYPE_I8257);
635 d = DEVICE(isa1);
636 qdev_prop_set_int32(d, "base", 0x00);
637 qdev_prop_set_int32(d, "page-base", 0x80);
638 qdev_prop_set_int32(d, "pageh-base", high_page_enable ? 0x480 : -1);
639 qdev_prop_set_int32(d, "dshift", 0);
640 qdev_init_nofail(d);
340e19eb
HP
641
642 isa2 = isa_create(bus, TYPE_I8257);
643 d = DEVICE(isa2);
644 qdev_prop_set_int32(d, "base", 0xc0);
645 qdev_prop_set_int32(d, "page-base", 0x88);
646 qdev_prop_set_int32(d, "pageh-base", high_page_enable ? 0x488 : -1);
647 qdev_prop_set_int32(d, "dshift", 1);
648 qdev_init_nofail(d);
16ffe363
HP
649
650 isa_bus_dma(bus, ISADMA(isa1), ISADMA(isa2));
27503323 651}