1 |
/* |
2 |
* PearPC |
3 |
* io.h |
4 |
* |
5 |
* Copyright (C) 2003 Sebastian Biallas (sb@biallas.net) |
6 |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License version 2 as |
9 |
* published by the Free Software Foundation. |
10 |
* |
11 |
* This program is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
* GNU General Public License for more details. |
15 |
* |
16 |
* You should have received a copy of the GNU General Public License |
17 |
* along with this program; if not, write to the Free Software |
18 |
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
*/ |
20 |
|
21 |
#ifndef __IO_IO_H__ |
22 |
#define __IO_IO_H__ |
23 |
|
24 |
#include "system/types.h" |
25 |
#include <stdlib.h> |
26 |
#include <string.h> |
27 |
#include "cpu/cpu.h" |
28 |
#include "cpu/debug.h" |
29 |
#include "cpu/mem.h" |
30 |
#include "io.h" |
31 |
#include "io/graphic/gcard.h" |
32 |
#include "io/pic/pic.h" |
33 |
#include "io/pci/pci.h" |
34 |
#include "io/cuda/cuda.h" |
35 |
#include "io/nvram/nvram.h" |
36 |
#include "debug/tracers.h" |
37 |
|
38 |
#define IO_MEM_ACCESS_OK 0 |
39 |
#define IO_MEM_ACCESS_EXC 1 |
40 |
#define IO_MEM_ACCESS_FATAL 2 |
41 |
|
42 |
static inline int io_mem_write(uint32 addr, uint32 data, int size) |
43 |
{ |
44 |
if (addr >= IO_GCARD_FRAMEBUFFER_PA_START && addr < IO_GCARD_FRAMEBUFFER_PA_END) { |
45 |
gcard_write(addr, data, size); |
46 |
return IO_MEM_ACCESS_OK; |
47 |
} |
48 |
if (addr >= IO_PCI_PA_START && addr < IO_PCI_PA_END) { |
49 |
pci_write(addr, data, size); |
50 |
return IO_MEM_ACCESS_OK; |
51 |
} |
52 |
if (addr >= IO_PIC_PA_START && addr < IO_PIC_PA_END) { |
53 |
pic_write(addr, data, size); |
54 |
return IO_MEM_ACCESS_OK; |
55 |
} |
56 |
if (addr >= IO_CUDA_PA_START && addr < IO_CUDA_PA_END) { |
57 |
cuda_write(addr, data, size); |
58 |
return IO_MEM_ACCESS_OK; |
59 |
} |
60 |
if (addr >= IO_NVRAM_PA_START && addr < IO_NVRAM_PA_END) { |
61 |
nvram_write(addr, data, size); |
62 |
return IO_MEM_ACCESS_OK; |
63 |
} |
64 |
// PCI and ISA must be checked at last |
65 |
if (addr >= IO_PCI_DEVICE_PA_START && addr < IO_PCI_DEVICE_PA_END) { |
66 |
pci_write_device(addr, data, size); |
67 |
return IO_MEM_ACCESS_OK; |
68 |
} |
69 |
if (addr >= IO_ISA_PA_START && addr < IO_ISA_PA_END) { |
70 |
/* |
71 |
* should raise exception here... |
72 |
* but linux dont like this |
73 |
*/ |
74 |
isa_write(addr, data, size); |
75 |
return IO_MEM_ACCESS_OK; |
76 |
/*if (isa_write(addr, data, size)) { |
77 |
return IO_MEM_ACCESS_OK; |
78 |
} else { |
79 |
ppc_exception(PPC_EXC_MACHINE_CHECK); |
80 |
return IO_MEM_ACCESS_EXC; |
81 |
}*/ |
82 |
} |
83 |
IO_CORE_WARN("no one is responsible for address %08x (write: %08x from %08x)\n", addr, data, ppc_cpu_get_pc(0)); |
84 |
SINGLESTEP(""); |
85 |
ppc_machine_check_exception(); |
86 |
return IO_MEM_ACCESS_EXC; |
87 |
} |
88 |
|
89 |
static inline int io_mem_read(uint32 addr, uint32 &data, int size) |
90 |
{ |
91 |
if (addr >= IO_GCARD_FRAMEBUFFER_PA_START && addr < IO_GCARD_FRAMEBUFFER_PA_END) { |
92 |
gcard_read(addr, data, size); |
93 |
return IO_MEM_ACCESS_OK; |
94 |
} |
95 |
if (addr >= IO_PCI_PA_START && addr < IO_PCI_PA_END) { |
96 |
pci_read(addr, data, size); |
97 |
return IO_MEM_ACCESS_OK; |
98 |
} |
99 |
if (addr >= IO_PIC_PA_START && addr < IO_PIC_PA_END) { |
100 |
pic_read(addr, data, size); |
101 |
return IO_MEM_ACCESS_OK; |
102 |
} |
103 |
if (addr >= IO_CUDA_PA_START && addr < IO_CUDA_PA_END) { |
104 |
cuda_read(addr, data, size); |
105 |
return IO_MEM_ACCESS_OK; |
106 |
} |
107 |
if (addr >= IO_NVRAM_PA_START && addr < IO_NVRAM_PA_END) { |
108 |
nvram_read(addr, data, size); |
109 |
return IO_MEM_ACCESS_OK; |
110 |
} |
111 |
if (addr == 0xff000004) { |
112 |
// wtf? |
113 |
data = 1; |
114 |
return IO_MEM_ACCESS_OK; |
115 |
} |
116 |
// PCI and ISA must be checked at last |
117 |
if (addr >= IO_PCI_DEVICE_PA_START && addr < IO_PCI_DEVICE_PA_END) { |
118 |
pci_read_device(addr, data, size); |
119 |
return IO_MEM_ACCESS_OK; |
120 |
} |
121 |
if (addr >= IO_ISA_PA_START && addr < IO_ISA_PA_END) { |
122 |
/* |
123 |
* should raise exception here... |
124 |
* but linux dont like this |
125 |
*/ |
126 |
isa_read(addr, data, size); |
127 |
return IO_MEM_ACCESS_OK; |
128 |
/*if (isa_read(addr, data, size)) { |
129 |
return IO_MEM_ACCESS_OK; |
130 |
} else { |
131 |
ppc_exception(PPC_EXC_MACHINE_CHECK); |
132 |
return IO_MEM_ACCESS_EXC; |
133 |
}*/ |
134 |
} |
135 |
IO_CORE_WARN("no one is responsible for address %08x (read from %08x)\n", addr, ppc_cpu_get_pc(0)); |
136 |
SINGLESTEP(""); |
137 |
ppc_machine_check_exception(); |
138 |
return IO_MEM_ACCESS_EXC; |
139 |
} |
140 |
|
141 |
static inline int io_mem_write64(uint32 addr, uint64 data) |
142 |
{ |
143 |
if ((addr >= IO_GCARD_FRAMEBUFFER_PA_START) && (addr < (IO_GCARD_FRAMEBUFFER_PA_END))) { |
144 |
gcard_write64(addr, data); |
145 |
return IO_MEM_ACCESS_OK; |
146 |
} |
147 |
IO_CORE_ERR("no one is responsible for address %08x (write64: %016q from %08x)\n", addr, &data, ppc_cpu_get_pc(0)); |
148 |
return IO_MEM_ACCESS_FATAL; |
149 |
} |
150 |
|
151 |
static inline int io_mem_read64(uint32 addr, uint64 &data) |
152 |
{ |
153 |
if ((addr >= IO_GCARD_FRAMEBUFFER_PA_START) && (addr < (IO_GCARD_FRAMEBUFFER_PA_END))) { |
154 |
gcard_read64(addr, data); |
155 |
return IO_MEM_ACCESS_OK; |
156 |
} |
157 |
IO_CORE_ERR("no one is responsible for address %08x (read64 from %08x)\n", addr, ppc_cpu_get_pc(0)); |
158 |
return IO_MEM_ACCESS_FATAL; |
159 |
} |
160 |
|
161 |
static inline int io_mem_write128(uint32 addr, uint128 *data) |
162 |
{ |
163 |
if ((addr >= IO_GCARD_FRAMEBUFFER_PA_START) && (addr < (IO_GCARD_FRAMEBUFFER_PA_END))) { |
164 |
gcard_write128(addr, data); |
165 |
return IO_MEM_ACCESS_OK; |
166 |
} |
167 |
IO_CORE_ERR("no one is responsible for address %08x (write128: %016q%016q from %08x)\n", addr, data->h, data->l, ppc_cpu_get_pc(0)); |
168 |
return IO_MEM_ACCESS_FATAL; |
169 |
} |
170 |
|
171 |
static inline int io_mem_write128_native(uint32 addr, uint128 *data) |
172 |
{ |
173 |
if ((addr >= IO_GCARD_FRAMEBUFFER_PA_START) && (addr < (IO_GCARD_FRAMEBUFFER_PA_END))) { |
174 |
gcard_write128_native(addr, data); |
175 |
return IO_MEM_ACCESS_OK; |
176 |
} |
177 |
IO_CORE_ERR("no one is responsible for address %08x (write128: %016q%016q from %08x)\n", addr, data->h, data->l, ppc_cpu_get_pc(0)); |
178 |
return IO_MEM_ACCESS_FATAL; |
179 |
} |
180 |
|
181 |
static inline int io_mem_read128(uint32 addr, uint128 *data) |
182 |
{ |
183 |
if ((addr >= IO_GCARD_FRAMEBUFFER_PA_START) && (addr < (IO_GCARD_FRAMEBUFFER_PA_END))) { |
184 |
gcard_read128(addr, data); |
185 |
return IO_MEM_ACCESS_OK; |
186 |
} |
187 |
IO_CORE_ERR("no one is responsible for address %08x (read128 from %08x)\n", addr, ppc_cpu_get_pc(0)); |
188 |
return IO_MEM_ACCESS_FATAL; |
189 |
} |
190 |
|
191 |
static inline int io_mem_read128_native(uint32 addr, uint128 *data) |
192 |
{ |
193 |
if ((addr >= IO_GCARD_FRAMEBUFFER_PA_START) && (addr < (IO_GCARD_FRAMEBUFFER_PA_END))) { |
194 |
gcard_read128_native(addr, data); |
195 |
return IO_MEM_ACCESS_OK; |
196 |
} |
197 |
IO_CORE_ERR("no one is responsible for address %08x (read128 from %08x)\n", addr, ppc_cpu_get_pc(0)); |
198 |
return IO_MEM_ACCESS_FATAL; |
199 |
} |
200 |
|
201 |
void io_init(); |
202 |
void io_done(); |
203 |
void io_init_config(); |
204 |
|
205 |
#endif |