root / hw / isa_mmio.c @ 3ced9f7a
History | View | Annotate | Download (2.9 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 | c227f099 | Anthony Liguori | static void isa_mmio_writew (void *opaque, target_phys_addr_t addr, |
35 | aef445bd | pbrook | uint32_t val) |
36 | aef445bd | pbrook | { |
37 | aef445bd | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
38 | aef445bd | pbrook | val = bswap16(val); |
39 | aef445bd | pbrook | #endif
|
40 | afcea8cb | Blue Swirl | cpu_outw(addr & IOPORTS_MASK, val); |
41 | aef445bd | pbrook | } |
42 | aef445bd | pbrook | |
43 | c227f099 | Anthony Liguori | static void isa_mmio_writel (void *opaque, target_phys_addr_t addr, |
44 | aef445bd | pbrook | uint32_t val) |
45 | aef445bd | pbrook | { |
46 | aef445bd | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
47 | aef445bd | pbrook | val = bswap32(val); |
48 | aef445bd | pbrook | #endif
|
49 | afcea8cb | Blue Swirl | cpu_outl(addr & IOPORTS_MASK, val); |
50 | aef445bd | pbrook | } |
51 | aef445bd | pbrook | |
52 | c227f099 | Anthony Liguori | static uint32_t isa_mmio_readb (void *opaque, target_phys_addr_t addr) |
53 | aef445bd | pbrook | { |
54 | aef445bd | pbrook | uint32_t val; |
55 | aef445bd | pbrook | |
56 | afcea8cb | Blue Swirl | val = cpu_inb(addr & IOPORTS_MASK); |
57 | aef445bd | pbrook | return val;
|
58 | aef445bd | pbrook | } |
59 | aef445bd | pbrook | |
60 | c227f099 | Anthony Liguori | static uint32_t isa_mmio_readw (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_inw(addr & IOPORTS_MASK); |
65 | aef445bd | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
66 | aef445bd | pbrook | val = bswap16(val); |
67 | aef445bd | pbrook | #endif
|
68 | aef445bd | pbrook | return val;
|
69 | aef445bd | pbrook | } |
70 | aef445bd | pbrook | |
71 | c227f099 | Anthony Liguori | static uint32_t isa_mmio_readl (void *opaque, target_phys_addr_t addr) |
72 | aef445bd | pbrook | { |
73 | aef445bd | pbrook | uint32_t val; |
74 | aef445bd | pbrook | |
75 | afcea8cb | Blue Swirl | val = cpu_inl(addr & IOPORTS_MASK); |
76 | aef445bd | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
77 | aef445bd | pbrook | val = bswap32(val); |
78 | aef445bd | pbrook | #endif
|
79 | aef445bd | pbrook | return val;
|
80 | aef445bd | pbrook | } |
81 | aef445bd | pbrook | |
82 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const isa_mmio_write[] = { |
83 | aef445bd | pbrook | &isa_mmio_writeb, |
84 | aef445bd | pbrook | &isa_mmio_writew, |
85 | aef445bd | pbrook | &isa_mmio_writel, |
86 | aef445bd | pbrook | }; |
87 | aef445bd | pbrook | |
88 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const isa_mmio_read[] = { |
89 | aef445bd | pbrook | &isa_mmio_readb, |
90 | aef445bd | pbrook | &isa_mmio_readw, |
91 | aef445bd | pbrook | &isa_mmio_readl, |
92 | aef445bd | pbrook | }; |
93 | aef445bd | pbrook | |
94 | aef445bd | pbrook | static int isa_mmio_iomemtype = 0; |
95 | aef445bd | pbrook | |
96 | c227f099 | Anthony Liguori | void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size)
|
97 | aef445bd | pbrook | { |
98 | aef445bd | pbrook | if (!isa_mmio_iomemtype) {
|
99 | 1eed09cb | Avi Kivity | isa_mmio_iomemtype = cpu_register_io_memory(isa_mmio_read, |
100 | aef445bd | pbrook | isa_mmio_write, NULL);
|
101 | aef445bd | pbrook | } |
102 | aef445bd | pbrook | cpu_register_physical_memory(base, size, isa_mmio_iomemtype); |
103 | aef445bd | pbrook | } |