2
* QEMU IDE Emulation: mmio support (for embedded).
4
* Copyright (c) 2003 Fabrice Bellard
5
* Copyright (c) 2006 Openedhand Ltd.
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:
14
* The above copyright notice and this permission notice shall be included in
15
* all copies or substantial portions of the Software.
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
29
#include <hw/ide/internal.h>
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.
42
static void mmio_ide_reset(void *opaque)
44
MMIOState *s = opaque;
46
ide_bus_reset(&s->bus);
49
static uint32_t mmio_ide_read (void *opaque, target_phys_addr_t addr)
51
MMIOState *s = opaque;
54
return ide_ioport_read(&s->bus, addr);
56
return ide_data_readw(&s->bus, 0);
59
static void mmio_ide_write (void *opaque, target_phys_addr_t addr,
62
MMIOState *s = opaque;
65
ide_ioport_write(&s->bus, addr, val);
67
ide_data_writew(&s->bus, 0, val);
70
static CPUReadMemoryFunc * const mmio_ide_reads[] = {
76
static CPUWriteMemoryFunc * const mmio_ide_writes[] = {
82
static uint32_t mmio_ide_status_read (void *opaque, target_phys_addr_t addr)
85
return ide_status_read(&s->bus, 0);
88
static void mmio_ide_cmd_write (void *opaque, target_phys_addr_t addr,
91
MMIOState *s = opaque;
92
ide_cmd_write(&s->bus, 0, val);
95
static CPUReadMemoryFunc * const mmio_ide_status[] = {
101
static CPUWriteMemoryFunc * const mmio_ide_cmd[] = {
107
static const VMStateDescription vmstate_ide_mmio = {
110
.minimum_version_id = 0,
111
.minimum_version_id_old = 0,
112
.fields = (VMStateField []) {
113
VMSTATE_IDE_BUS(bus, MMIOState),
114
VMSTATE_IDE_DRIVES(bus.ifs, MMIOState),
115
VMSTATE_END_OF_LIST()
119
void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2,
120
qemu_irq irq, int shift,
121
DriveInfo *hd0, DriveInfo *hd1)
123
MMIOState *s = g_malloc0(sizeof(MMIOState));
126
ide_init2_with_non_qdev_drives(&s->bus, hd0, hd1, irq);
130
mem1 = cpu_register_io_memory(mmio_ide_reads, mmio_ide_writes, s,
131
DEVICE_NATIVE_ENDIAN);
132
mem2 = cpu_register_io_memory(mmio_ide_status, mmio_ide_cmd, s,
133
DEVICE_NATIVE_ENDIAN);
134
cpu_register_physical_memory(membase, 16 << shift, mem1);
135
cpu_register_physical_memory(membase2, 2 << shift, mem2);
136
vmstate_register(NULL, 0, &vmstate_ide_mmio, s);
137
qemu_register_reset(mmio_ide_reset, s);