]> git.proxmox.com Git - qemu.git/blame - hw/ide/mmio.c
softmmu: move include files to include/sysemu/
[qemu.git] / hw / ide / mmio.c
CommitLineData
3d2bf4a1
GH
1/*
2 * QEMU IDE Emulation: mmio support (for embedded).
3 *
4 * Copyright (c) 2003 Fabrice Bellard
5 * Copyright (c) 2006 Openedhand Ltd.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
24 */
59f2a787 25#include <hw/hw.h>
737e150e 26#include "block/block.h"
9c17d615 27#include "sysemu/dma.h"
59f2a787
GH
28
29#include <hw/ide/internal.h>
3d2bf4a1
GH
30
31/***********************************************************/
32/* MMIO based ide port
33 * This emulates IDE device connected directly to the CPU bus without
34 * dedicated ide controller, which is often seen on embedded boards.
35 */
36
37typedef struct {
0ce51e92 38 IDEBus bus;
3d2bf4a1 39 int shift;
9d7f1b9a 40 MemoryRegion iomem1, iomem2;
3d2bf4a1
GH
41} MMIOState;
42
4a643563
BS
43static void mmio_ide_reset(void *opaque)
44{
45 MMIOState *s = opaque;
46
47 ide_bus_reset(&s->bus);
48}
49
a8170e5e 50static uint64_t mmio_ide_read(void *opaque, hwaddr addr,
9d7f1b9a 51 unsigned size)
3d2bf4a1 52{
18c0fb30 53 MMIOState *s = opaque;
3d2bf4a1
GH
54 addr >>= s->shift;
55 if (addr & 7)
0ce51e92 56 return ide_ioport_read(&s->bus, addr);
3d2bf4a1 57 else
0ce51e92 58 return ide_data_readw(&s->bus, 0);
3d2bf4a1
GH
59}
60
a8170e5e 61static void mmio_ide_write(void *opaque, hwaddr addr,
9d7f1b9a 62 uint64_t val, unsigned size)
3d2bf4a1 63{
18c0fb30 64 MMIOState *s = opaque;
3d2bf4a1
GH
65 addr >>= s->shift;
66 if (addr & 7)
0ce51e92 67 ide_ioport_write(&s->bus, addr, val);
3d2bf4a1 68 else
0ce51e92 69 ide_data_writew(&s->bus, 0, val);
3d2bf4a1
GH
70}
71
9d7f1b9a
AK
72static const MemoryRegionOps mmio_ide_ops = {
73 .read = mmio_ide_read,
74 .write = mmio_ide_write,
75 .endianness = DEVICE_NATIVE_ENDIAN,
3d2bf4a1
GH
76};
77
a8170e5e 78static uint64_t mmio_ide_status_read(void *opaque, hwaddr addr,
9d7f1b9a 79 unsigned size)
3d2bf4a1 80{
18c0fb30 81 MMIOState *s= opaque;
0ce51e92 82 return ide_status_read(&s->bus, 0);
3d2bf4a1
GH
83}
84
a8170e5e 85static void mmio_ide_cmd_write(void *opaque, hwaddr addr,
9d7f1b9a 86 uint64_t val, unsigned size)
3d2bf4a1 87{
18c0fb30 88 MMIOState *s = opaque;
0ce51e92 89 ide_cmd_write(&s->bus, 0, val);
3d2bf4a1
GH
90}
91
9d7f1b9a
AK
92static const MemoryRegionOps mmio_ide_cs_ops = {
93 .read = mmio_ide_status_read,
94 .write = mmio_ide_cmd_write,
95 .endianness = DEVICE_NATIVE_ENDIAN,
3d2bf4a1
GH
96};
97
24daf35c
JQ
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};
2bcbf7e4 109
a8170e5e 110void mmio_ide_init (hwaddr membase, hwaddr membase2,
9d7f1b9a 111 MemoryRegion *address_space,
3d2bf4a1 112 qemu_irq irq, int shift,
f455e98c 113 DriveInfo *hd0, DriveInfo *hd1)
3d2bf4a1 114{
7267c094 115 MMIOState *s = g_malloc0(sizeof(MMIOState));
3d2bf4a1 116
57234ee4 117 ide_init2_with_non_qdev_drives(&s->bus, hd0, hd1, irq);
3d2bf4a1 118
3d2bf4a1
GH
119 s->shift = shift;
120
9d7f1b9a
AK
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);
0be71e32 127 vmstate_register(NULL, 0, &vmstate_ide_mmio, s);
4a643563 128 qemu_register_reset(mmio_ide_reset, s);
3d2bf4a1
GH
129}
130