1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <hw/hw.h>
26#include "block.h"
27#include "dma.h"
28
29#include <hw/ide/internal.h>
30
31
32
33
34
35
36
37typedef struct {
38 IDEBus bus;
39 int shift;
40 MemoryRegion iomem1, iomem2;
41} MMIOState;
42
43static void mmio_ide_reset(void *opaque)
44{
45 MMIOState *s = opaque;
46
47 ide_bus_reset(&s->bus);
48}
49
50static uint64_t mmio_ide_read(void *opaque, target_phys_addr_t addr,
51 unsigned size)
52{
53 MMIOState *s = opaque;
54 addr >>= s->shift;
55 if (addr & 7)
56 return ide_ioport_read(&s->bus, addr);
57 else
58 return ide_data_readw(&s->bus, 0);
59}
60
61static void mmio_ide_write(void *opaque, target_phys_addr_t addr,
62 uint64_t val, unsigned size)
63{
64 MMIOState *s = opaque;
65 addr >>= s->shift;
66 if (addr & 7)
67 ide_ioport_write(&s->bus, addr, val);
68 else
69 ide_data_writew(&s->bus, 0, val);
70}
71
72static const MemoryRegionOps mmio_ide_ops = {
73 .read = mmio_ide_read,
74 .write = mmio_ide_write,
75 .endianness = DEVICE_NATIVE_ENDIAN,
76};
77
78static uint64_t mmio_ide_status_read(void *opaque, target_phys_addr_t addr,
79 unsigned size)
80{
81 MMIOState *s= opaque;
82 return ide_status_read(&s->bus, 0);
83}
84
85static void mmio_ide_cmd_write(void *opaque, target_phys_addr_t addr,
86 uint64_t val, unsigned size)
87{
88 MMIOState *s = opaque;
89 ide_cmd_write(&s->bus, 0, val);
90}
91
92static const MemoryRegionOps mmio_ide_cs_ops = {
93 .read = mmio_ide_status_read,
94 .write = mmio_ide_cmd_write,
95 .endianness = DEVICE_NATIVE_ENDIAN,
96};
97
98static const VMStateDescription vmstate_ide_mmio = {
99 .name = "mmio-ide",
100 .version_id = 3,
101 .minimum_version_id = 0,
102 .minimum_version_id_old = 0,
103 .fields = (VMStateField []) {
104 VMSTATE_IDE_BUS(bus, MMIOState),
105 VMSTATE_IDE_DRIVES(bus.ifs, MMIOState),
106 VMSTATE_END_OF_LIST()
107 }
108};
109
110void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2,
111 MemoryRegion *address_space,
112 qemu_irq irq, int shift,
113 DriveInfo *hd0, DriveInfo *hd1)
114{
115 MMIOState *s = g_malloc0(sizeof(MMIOState));
116
117 ide_init2_with_non_qdev_drives(&s->bus, hd0, hd1, irq);
118
119 s->shift = shift;
120
121 memory_region_init_io(&s->iomem1, &mmio_ide_ops, s,
122 "ide-mmio.1", 16 << shift);
123 memory_region_init_io(&s->iomem2, &mmio_ide_cs_ops, s,
124 "ide-mmio.2", 2 << shift);
125 memory_region_add_subregion(address_space, membase, &s->iomem1);
126 memory_region_add_subregion(address_space, membase2, &s->iomem2);
127 vmstate_register(NULL, 0, &vmstate_ide_mmio, s);
128 qemu_register_reset(mmio_ide_reset, s);
129}
130
131