isa_mmio.c 2.5 KB
Newer Older
P
pbrook 已提交
1 2 3 4
/*
 * Memory mapped access to ISA IO space.
 *
 * Copyright (c) 2006 Fabrice Bellard
5
 *
P
pbrook 已提交
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

25
#include "hw/hw.h"
P
Paolo Bonzini 已提交
26
#include "hw/isa/isa.h"
27
#include "exec/address-spaces.h"
P
pbrook 已提交
28

A
Avi Kivity 已提交
29
static void isa_mmio_writeb (void *opaque, hwaddr addr,
P
pbrook 已提交
30 31
                                  uint32_t val)
{
32
    cpu_outb(addr & IOPORTS_MASK, val);
P
pbrook 已提交
33 34
}

A
Avi Kivity 已提交
35
static void isa_mmio_writew(void *opaque, hwaddr addr,
B
Blue Swirl 已提交
36
                               uint32_t val)
P
pbrook 已提交
37
{
38
    cpu_outw(addr & IOPORTS_MASK, val);
P
pbrook 已提交
39 40
}

A
Avi Kivity 已提交
41
static void isa_mmio_writel(void *opaque, hwaddr addr,
B
Blue Swirl 已提交
42 43
                               uint32_t val)
{
44
    cpu_outl(addr & IOPORTS_MASK, val);
P
pbrook 已提交
45 46
}

A
Avi Kivity 已提交
47
static uint32_t isa_mmio_readb (void *opaque, hwaddr addr)
P
pbrook 已提交
48
{
49
    return cpu_inb(addr & IOPORTS_MASK);
P
pbrook 已提交
50 51
}

A
Avi Kivity 已提交
52
static uint32_t isa_mmio_readw(void *opaque, hwaddr addr)
P
pbrook 已提交
53
{
54
    return cpu_inw(addr & IOPORTS_MASK);
P
pbrook 已提交
55 56
}

A
Avi Kivity 已提交
57
static uint32_t isa_mmio_readl(void *opaque, hwaddr addr)
B
Blue Swirl 已提交
58
{
59
    return cpu_inl(addr & IOPORTS_MASK);
B
Blue Swirl 已提交
60 61
}

A
Avi Kivity 已提交
62 63 64 65 66 67
static const MemoryRegionOps isa_mmio_ops = {
    .old_mmio = {
        .write = { isa_mmio_writeb, isa_mmio_writew, isa_mmio_writel },
        .read = { isa_mmio_readb, isa_mmio_readw, isa_mmio_readl, },
    },
    .endianness = DEVICE_LITTLE_ENDIAN,
P
pbrook 已提交
68 69
};

A
Avi Kivity 已提交
70
void isa_mmio_setup(MemoryRegion *mr, hwaddr size)
A
Avi Kivity 已提交
71 72 73
{
    memory_region_init_io(mr, &isa_mmio_ops, NULL, "isa-mmio", size);
}
P
pbrook 已提交
74

A
Avi Kivity 已提交
75
void isa_mmio_init(hwaddr base, hwaddr size)
P
pbrook 已提交
76
{
77
    MemoryRegion *mr = g_malloc(sizeof(*mr));
78

A
Avi Kivity 已提交
79 80
    isa_mmio_setup(mr, size);
    memory_region_add_subregion(get_system_memory(), base, mr);
P
pbrook 已提交
81
}