2 * DMA device simulation in PKUnity SoC
4 * Copyright (C) 2010-2012 Guan Xuetao
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation, or any later version.
9 * See the COPYING file in the top-level directory.
12 #include "hw/sysbus.h"
17 #define PUV3_DMA_CH_NR (6)
18 #define PUV3_DMA_CH_MASK (0xff)
19 #define PUV3_DMA_CH(offset) ((offset) >> 8)
24 uint32_t reg_CFG
[PUV3_DMA_CH_NR
];
27 static uint64_t puv3_dma_read(void *opaque
, hwaddr offset
,
30 PUV3DMAState
*s
= opaque
;
33 assert(PUV3_DMA_CH(offset
) < PUV3_DMA_CH_NR
);
35 switch (offset
& PUV3_DMA_CH_MASK
) {
37 ret
= s
->reg_CFG
[PUV3_DMA_CH(offset
)];
40 DPRINTF("Bad offset 0x%x\n", offset
);
42 DPRINTF("offset 0x%x, value 0x%x\n", offset
, ret
);
47 static void puv3_dma_write(void *opaque
, hwaddr offset
,
48 uint64_t value
, unsigned size
)
50 PUV3DMAState
*s
= opaque
;
52 assert(PUV3_DMA_CH(offset
) < PUV3_DMA_CH_NR
);
54 switch (offset
& PUV3_DMA_CH_MASK
) {
56 s
->reg_CFG
[PUV3_DMA_CH(offset
)] = value
;
59 DPRINTF("Bad offset 0x%x\n", offset
);
61 DPRINTF("offset 0x%x, value 0x%x\n", offset
, value
);
64 static const MemoryRegionOps puv3_dma_ops
= {
65 .read
= puv3_dma_read
,
66 .write
= puv3_dma_write
,
71 .endianness
= DEVICE_NATIVE_ENDIAN
,
74 static int puv3_dma_init(SysBusDevice
*dev
)
76 PUV3DMAState
*s
= FROM_SYSBUS(PUV3DMAState
, dev
);
79 for (i
= 0; i
< PUV3_DMA_CH_NR
; i
++) {
83 memory_region_init_io(&s
->iomem
, &puv3_dma_ops
, s
, "puv3_dma",
85 sysbus_init_mmio(dev
, &s
->iomem
);
90 static void puv3_dma_class_init(ObjectClass
*klass
, void *data
)
92 SysBusDeviceClass
*sdc
= SYS_BUS_DEVICE_CLASS(klass
);
94 sdc
->init
= puv3_dma_init
;
97 static const TypeInfo puv3_dma_info
= {
99 .parent
= TYPE_SYS_BUS_DEVICE
,
100 .instance_size
= sizeof(PUV3DMAState
),
101 .class_init
= puv3_dma_class_init
,
104 static void puv3_dma_register_type(void)
106 type_register_static(&puv3_dma_info
);
109 type_init(puv3_dma_register_type
)