Statistics
| Branch: | Revision:

root / hw / isa_mmio.c @ e7b43f7e

History | View | Annotate | Download (4 kB)

1 aef445bd pbrook
/*
2 aef445bd pbrook
 * Memory mapped access to ISA IO space.
3 aef445bd pbrook
 *
4 aef445bd pbrook
 * Copyright (c) 2006 Fabrice Bellard
5 5fafdf24 ths
 *
6 aef445bd pbrook
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 aef445bd pbrook
 * of this software and associated documentation files (the "Software"), to deal
8 aef445bd pbrook
 * in the Software without restriction, including without limitation the rights
9 aef445bd pbrook
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 aef445bd pbrook
 * copies of the Software, and to permit persons to whom the Software is
11 aef445bd pbrook
 * furnished to do so, subject to the following conditions:
12 aef445bd pbrook
 *
13 aef445bd pbrook
 * The above copyright notice and this permission notice shall be included in
14 aef445bd pbrook
 * all copies or substantial portions of the Software.
15 aef445bd pbrook
 *
16 aef445bd pbrook
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 aef445bd pbrook
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 aef445bd pbrook
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 aef445bd pbrook
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 aef445bd pbrook
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 aef445bd pbrook
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 aef445bd pbrook
 * THE SOFTWARE.
23 aef445bd pbrook
 */
24 aef445bd pbrook
25 87ecb68b pbrook
#include "hw.h"
26 87ecb68b pbrook
#include "isa.h"
27 aef445bd pbrook
28 c227f099 Anthony Liguori
static void isa_mmio_writeb (void *opaque, target_phys_addr_t addr,
29 aef445bd pbrook
                                  uint32_t val)
30 aef445bd pbrook
{
31 afcea8cb Blue Swirl
    cpu_outb(addr & IOPORTS_MASK, val);
32 aef445bd pbrook
}
33 aef445bd pbrook
34 84108e12 Blue Swirl
static void isa_mmio_writew_be(void *opaque, target_phys_addr_t addr,
35 84108e12 Blue Swirl
                               uint32_t val)
36 aef445bd pbrook
{
37 aef445bd pbrook
    val = bswap16(val);
38 afcea8cb Blue Swirl
    cpu_outw(addr & IOPORTS_MASK, val);
39 aef445bd pbrook
}
40 aef445bd pbrook
41 84108e12 Blue Swirl
static void isa_mmio_writew_le(void *opaque, target_phys_addr_t addr,
42 84108e12 Blue Swirl
                               uint32_t val)
43 84108e12 Blue Swirl
{
44 84108e12 Blue Swirl
    cpu_outw(addr & IOPORTS_MASK, val);
45 84108e12 Blue Swirl
}
46 84108e12 Blue Swirl
47 84108e12 Blue Swirl
static void isa_mmio_writel_be(void *opaque, target_phys_addr_t addr,
48 84108e12 Blue Swirl
                               uint32_t val)
49 aef445bd pbrook
{
50 aef445bd pbrook
    val = bswap32(val);
51 84108e12 Blue Swirl
    cpu_outl(addr & IOPORTS_MASK, val);
52 84108e12 Blue Swirl
}
53 84108e12 Blue Swirl
54 84108e12 Blue Swirl
static void isa_mmio_writel_le(void *opaque, target_phys_addr_t addr,
55 84108e12 Blue Swirl
                               uint32_t val)
56 84108e12 Blue Swirl
{
57 afcea8cb Blue Swirl
    cpu_outl(addr & IOPORTS_MASK, val);
58 aef445bd pbrook
}
59 aef445bd pbrook
60 c227f099 Anthony Liguori
static uint32_t isa_mmio_readb (void *opaque, target_phys_addr_t addr)
61 aef445bd pbrook
{
62 aef445bd pbrook
    uint32_t val;
63 aef445bd pbrook
64 afcea8cb Blue Swirl
    val = cpu_inb(addr & IOPORTS_MASK);
65 aef445bd pbrook
    return val;
66 aef445bd pbrook
}
67 aef445bd pbrook
68 84108e12 Blue Swirl
static uint32_t isa_mmio_readw_be(void *opaque, target_phys_addr_t addr)
69 aef445bd pbrook
{
70 aef445bd pbrook
    uint32_t val;
71 aef445bd pbrook
72 afcea8cb Blue Swirl
    val = cpu_inw(addr & IOPORTS_MASK);
73 aef445bd pbrook
    val = bswap16(val);
74 aef445bd pbrook
    return val;
75 aef445bd pbrook
}
76 aef445bd pbrook
77 84108e12 Blue Swirl
static uint32_t isa_mmio_readw_le(void *opaque, target_phys_addr_t addr)
78 84108e12 Blue Swirl
{
79 84108e12 Blue Swirl
    uint32_t val;
80 84108e12 Blue Swirl
81 84108e12 Blue Swirl
    val = cpu_inw(addr & IOPORTS_MASK);
82 84108e12 Blue Swirl
    return val;
83 84108e12 Blue Swirl
}
84 84108e12 Blue Swirl
85 84108e12 Blue Swirl
static uint32_t isa_mmio_readl_be(void *opaque, target_phys_addr_t addr)
86 aef445bd pbrook
{
87 aef445bd pbrook
    uint32_t val;
88 aef445bd pbrook
89 afcea8cb Blue Swirl
    val = cpu_inl(addr & IOPORTS_MASK);
90 aef445bd pbrook
    val = bswap32(val);
91 aef445bd pbrook
    return val;
92 aef445bd pbrook
}
93 aef445bd pbrook
94 84108e12 Blue Swirl
static uint32_t isa_mmio_readl_le(void *opaque, target_phys_addr_t addr)
95 84108e12 Blue Swirl
{
96 84108e12 Blue Swirl
    uint32_t val;
97 84108e12 Blue Swirl
98 84108e12 Blue Swirl
    val = cpu_inl(addr & IOPORTS_MASK);
99 84108e12 Blue Swirl
    return val;
100 84108e12 Blue Swirl
}
101 84108e12 Blue Swirl
102 84108e12 Blue Swirl
static CPUWriteMemoryFunc * const isa_mmio_write_be[] = {
103 84108e12 Blue Swirl
    &isa_mmio_writeb,
104 84108e12 Blue Swirl
    &isa_mmio_writew_be,
105 84108e12 Blue Swirl
    &isa_mmio_writel_be,
106 84108e12 Blue Swirl
};
107 84108e12 Blue Swirl
108 84108e12 Blue Swirl
static CPUReadMemoryFunc * const isa_mmio_read_be[] = {
109 84108e12 Blue Swirl
    &isa_mmio_readb,
110 84108e12 Blue Swirl
    &isa_mmio_readw_be,
111 84108e12 Blue Swirl
    &isa_mmio_readl_be,
112 84108e12 Blue Swirl
};
113 84108e12 Blue Swirl
114 84108e12 Blue Swirl
static CPUWriteMemoryFunc * const isa_mmio_write_le[] = {
115 aef445bd pbrook
    &isa_mmio_writeb,
116 84108e12 Blue Swirl
    &isa_mmio_writew_le,
117 84108e12 Blue Swirl
    &isa_mmio_writel_le,
118 aef445bd pbrook
};
119 aef445bd pbrook
120 84108e12 Blue Swirl
static CPUReadMemoryFunc * const isa_mmio_read_le[] = {
121 aef445bd pbrook
    &isa_mmio_readb,
122 84108e12 Blue Swirl
    &isa_mmio_readw_le,
123 84108e12 Blue Swirl
    &isa_mmio_readl_le,
124 aef445bd pbrook
};
125 aef445bd pbrook
126 aef445bd pbrook
static int isa_mmio_iomemtype = 0;
127 aef445bd pbrook
128 84108e12 Blue Swirl
void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size, int be)
129 aef445bd pbrook
{
130 aef445bd pbrook
    if (!isa_mmio_iomemtype) {
131 84108e12 Blue Swirl
        if (be) {
132 84108e12 Blue Swirl
            isa_mmio_iomemtype = cpu_register_io_memory(isa_mmio_read_be,
133 84108e12 Blue Swirl
                                                        isa_mmio_write_be,
134 84108e12 Blue Swirl
                                                        NULL);
135 84108e12 Blue Swirl
        } else {
136 84108e12 Blue Swirl
            isa_mmio_iomemtype = cpu_register_io_memory(isa_mmio_read_le,
137 84108e12 Blue Swirl
                                                        isa_mmio_write_le,
138 84108e12 Blue Swirl
                                                        NULL);
139 84108e12 Blue Swirl
        }
140 aef445bd pbrook
    }
141 aef445bd pbrook
    cpu_register_physical_memory(base, size, isa_mmio_iomemtype);
142 aef445bd pbrook
}