root / hw / isa_mmio.c @ 8f40c388
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 | aef445bd | pbrook | *
|
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 | aef445bd | pbrook | #include "vl.h" |
26 | aef445bd | pbrook | |
27 | aef445bd | pbrook | static void isa_mmio_writeb (void *opaque, target_phys_addr_t addr, |
28 | aef445bd | pbrook | uint32_t val) |
29 | aef445bd | pbrook | { |
30 | aef445bd | pbrook | cpu_outb(NULL, addr & 0xffff, val); |
31 | aef445bd | pbrook | } |
32 | aef445bd | pbrook | |
33 | aef445bd | pbrook | static void isa_mmio_writew (void *opaque, target_phys_addr_t addr, |
34 | aef445bd | pbrook | uint32_t val) |
35 | aef445bd | pbrook | { |
36 | aef445bd | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
37 | aef445bd | pbrook | val = bswap16(val); |
38 | aef445bd | pbrook | #endif
|
39 | aef445bd | pbrook | cpu_outw(NULL, addr & 0xffff, val); |
40 | aef445bd | pbrook | } |
41 | aef445bd | pbrook | |
42 | aef445bd | pbrook | static void isa_mmio_writel (void *opaque, target_phys_addr_t addr, |
43 | aef445bd | pbrook | uint32_t val) |
44 | aef445bd | pbrook | { |
45 | aef445bd | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
46 | aef445bd | pbrook | val = bswap32(val); |
47 | aef445bd | pbrook | #endif
|
48 | aef445bd | pbrook | cpu_outl(NULL, addr & 0xffff, val); |
49 | aef445bd | pbrook | } |
50 | aef445bd | pbrook | |
51 | aef445bd | pbrook | static uint32_t isa_mmio_readb (void *opaque, target_phys_addr_t addr) |
52 | aef445bd | pbrook | { |
53 | aef445bd | pbrook | uint32_t val; |
54 | aef445bd | pbrook | |
55 | aef445bd | pbrook | val = cpu_inb(NULL, addr & 0xffff); |
56 | aef445bd | pbrook | return val;
|
57 | aef445bd | pbrook | } |
58 | aef445bd | pbrook | |
59 | aef445bd | pbrook | static uint32_t isa_mmio_readw (void *opaque, target_phys_addr_t addr) |
60 | aef445bd | pbrook | { |
61 | aef445bd | pbrook | uint32_t val; |
62 | aef445bd | pbrook | |
63 | aef445bd | pbrook | val = cpu_inw(NULL, addr & 0xffff); |
64 | aef445bd | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
65 | aef445bd | pbrook | val = bswap16(val); |
66 | aef445bd | pbrook | #endif
|
67 | aef445bd | pbrook | return val;
|
68 | aef445bd | pbrook | } |
69 | aef445bd | pbrook | |
70 | aef445bd | pbrook | static uint32_t isa_mmio_readl (void *opaque, target_phys_addr_t addr) |
71 | aef445bd | pbrook | { |
72 | aef445bd | pbrook | uint32_t val; |
73 | aef445bd | pbrook | |
74 | aef445bd | pbrook | val = cpu_inl(NULL, addr & 0xffff); |
75 | aef445bd | pbrook | #ifdef TARGET_WORDS_BIGENDIAN
|
76 | aef445bd | pbrook | val = bswap32(val); |
77 | aef445bd | pbrook | #endif
|
78 | aef445bd | pbrook | return val;
|
79 | aef445bd | pbrook | } |
80 | aef445bd | pbrook | |
81 | aef445bd | pbrook | static CPUWriteMemoryFunc *isa_mmio_write[] = {
|
82 | aef445bd | pbrook | &isa_mmio_writeb, |
83 | aef445bd | pbrook | &isa_mmio_writew, |
84 | aef445bd | pbrook | &isa_mmio_writel, |
85 | aef445bd | pbrook | }; |
86 | aef445bd | pbrook | |
87 | aef445bd | pbrook | static CPUReadMemoryFunc *isa_mmio_read[] = {
|
88 | aef445bd | pbrook | &isa_mmio_readb, |
89 | aef445bd | pbrook | &isa_mmio_readw, |
90 | aef445bd | pbrook | &isa_mmio_readl, |
91 | aef445bd | pbrook | }; |
92 | aef445bd | pbrook | |
93 | aef445bd | pbrook | static int isa_mmio_iomemtype = 0; |
94 | aef445bd | pbrook | |
95 | aef445bd | pbrook | void isa_mmio_init(target_phys_addr_t base, target_phys_addr_t size)
|
96 | aef445bd | pbrook | { |
97 | aef445bd | pbrook | if (!isa_mmio_iomemtype) {
|
98 | aef445bd | pbrook | isa_mmio_iomemtype = cpu_register_io_memory(0, isa_mmio_read,
|
99 | aef445bd | pbrook | isa_mmio_write, NULL);
|
100 | aef445bd | pbrook | } |
101 | aef445bd | pbrook | cpu_register_physical_memory(base, size, isa_mmio_iomemtype); |
102 | aef445bd | pbrook | } |