root / hw / slavio_misc.c @ be62a2eb
History | View | Annotate | Download (12.8 kB)
1 | 3475187d | bellard | /*
|
---|---|---|---|
2 | 3475187d | bellard | * QEMU Sparc SLAVIO aux io port emulation
|
3 | 5fafdf24 | ths | *
|
4 | 3475187d | bellard | * Copyright (c) 2005 Fabrice Bellard
|
5 | 5fafdf24 | ths | *
|
6 | 3475187d | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 3475187d | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 3475187d | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 3475187d | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 3475187d | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 3475187d | bellard | * furnished to do so, subject to the following conditions:
|
12 | 3475187d | bellard | *
|
13 | 3475187d | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 3475187d | bellard | * all copies or substantial portions of the Software.
|
15 | 3475187d | bellard | *
|
16 | 3475187d | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 3475187d | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 3475187d | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 3475187d | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 3475187d | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 3475187d | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 3475187d | bellard | * THE SOFTWARE.
|
23 | 3475187d | bellard | */
|
24 | 2582cfa0 | Blue Swirl | |
25 | 87ecb68b | pbrook | #include "sysemu.h" |
26 | 2582cfa0 | Blue Swirl | #include "sysbus.h" |
27 | 97bf4851 | Blue Swirl | #include "trace.h" |
28 | 3475187d | bellard | |
29 | 3475187d | bellard | /*
|
30 | 3475187d | bellard | * This is the auxio port, chip control and system control part of
|
31 | 3475187d | bellard | * chip STP2001 (Slave I/O), also produced as NCR89C105. See
|
32 | 3475187d | bellard | * http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
|
33 | 3475187d | bellard | *
|
34 | 3475187d | bellard | * This also includes the PMC CPU idle controller.
|
35 | 3475187d | bellard | */
|
36 | 3475187d | bellard | |
37 | 3475187d | bellard | typedef struct MiscState { |
38 | 2582cfa0 | Blue Swirl | SysBusDevice busdev; |
39 | dd703aae | Benoît Canet | MemoryRegion cfg_iomem; |
40 | 96891e59 | Benoît Canet | MemoryRegion diag_iomem; |
41 | 2e66ac3d | Benoît Canet | MemoryRegion mdm_iomem; |
42 | aca23c71 | Benoît Canet | MemoryRegion led_iomem; |
43 | cd64a524 | Benoît Canet | MemoryRegion sysctrl_iomem; |
44 | cccd43c5 | Benoît Canet | MemoryRegion aux1_iomem; |
45 | 40ce02fc | Benoît Canet | MemoryRegion aux2_iomem; |
46 | d537cf6c | pbrook | qemu_irq irq; |
47 | 97bbb109 | Blue Swirl | qemu_irq fdc_tc; |
48 | d37adb09 | Blue Swirl | uint32_t dummy; |
49 | 3475187d | bellard | uint8_t config; |
50 | 3475187d | bellard | uint8_t aux1, aux2; |
51 | bfa30a38 | blueswir1 | uint8_t diag, mctrl; |
52 | d37adb09 | Blue Swirl | uint8_t sysctrl; |
53 | 6a3b9cc9 | blueswir1 | uint16_t leds; |
54 | 3475187d | bellard | } MiscState; |
55 | 3475187d | bellard | |
56 | 2582cfa0 | Blue Swirl | typedef struct APCState { |
57 | 2582cfa0 | Blue Swirl | SysBusDevice busdev; |
58 | 9c48dee6 | Benoît Canet | MemoryRegion iomem; |
59 | 2582cfa0 | Blue Swirl | qemu_irq cpu_halt; |
60 | 2582cfa0 | Blue Swirl | } APCState; |
61 | 2582cfa0 | Blue Swirl | |
62 | 5aca8c3b | blueswir1 | #define MISC_SIZE 1 |
63 | a8f48dcc | blueswir1 | #define SYSCTRL_SIZE 4 |
64 | 3475187d | bellard | |
65 | 2be17ebd | blueswir1 | #define AUX1_TC 0x02 |
66 | 2be17ebd | blueswir1 | |
67 | 7debeb82 | blueswir1 | #define AUX2_PWROFF 0x01 |
68 | 7debeb82 | blueswir1 | #define AUX2_PWRINTCLR 0x02 |
69 | 7debeb82 | blueswir1 | #define AUX2_PWRFAIL 0x20 |
70 | 7debeb82 | blueswir1 | |
71 | 7debeb82 | blueswir1 | #define CFG_PWRINTEN 0x08 |
72 | 7debeb82 | blueswir1 | |
73 | 7debeb82 | blueswir1 | #define SYS_RESET 0x01 |
74 | 7debeb82 | blueswir1 | #define SYS_RESETSTAT 0x02 |
75 | 7debeb82 | blueswir1 | |
76 | 3475187d | bellard | static void slavio_misc_update_irq(void *opaque) |
77 | 3475187d | bellard | { |
78 | 3475187d | bellard | MiscState *s = opaque; |
79 | 3475187d | bellard | |
80 | 7debeb82 | blueswir1 | if ((s->aux2 & AUX2_PWRFAIL) && (s->config & CFG_PWRINTEN)) {
|
81 | 97bf4851 | Blue Swirl | trace_slavio_misc_update_irq_raise(); |
82 | d537cf6c | pbrook | qemu_irq_raise(s->irq); |
83 | 3475187d | bellard | } else {
|
84 | 97bf4851 | Blue Swirl | trace_slavio_misc_update_irq_lower(); |
85 | d537cf6c | pbrook | qemu_irq_lower(s->irq); |
86 | 3475187d | bellard | } |
87 | 3475187d | bellard | } |
88 | 3475187d | bellard | |
89 | 1795057a | Blue Swirl | static void slavio_misc_reset(DeviceState *d) |
90 | 3475187d | bellard | { |
91 | 1795057a | Blue Swirl | MiscState *s = container_of(d, MiscState, busdev.qdev); |
92 | 3475187d | bellard | |
93 | 4e3b1ea1 | bellard | // Diagnostic and system control registers not cleared in reset
|
94 | 3475187d | bellard | s->config = s->aux1 = s->aux2 = s->mctrl = 0;
|
95 | 3475187d | bellard | } |
96 | 3475187d | bellard | |
97 | b2b6f6ec | Blue Swirl | static void slavio_set_power_fail(void *opaque, int irq, int power_failing) |
98 | 3475187d | bellard | { |
99 | 3475187d | bellard | MiscState *s = opaque; |
100 | 3475187d | bellard | |
101 | 97bf4851 | Blue Swirl | trace_slavio_set_power_fail(power_failing, s->config); |
102 | 7debeb82 | blueswir1 | if (power_failing && (s->config & CFG_PWRINTEN)) {
|
103 | 7debeb82 | blueswir1 | s->aux2 |= AUX2_PWRFAIL; |
104 | 3475187d | bellard | } else {
|
105 | 7debeb82 | blueswir1 | s->aux2 &= ~AUX2_PWRFAIL; |
106 | 3475187d | bellard | } |
107 | 3475187d | bellard | slavio_misc_update_irq(s); |
108 | 3475187d | bellard | } |
109 | 3475187d | bellard | |
110 | c227f099 | Anthony Liguori | static void slavio_cfg_mem_writeb(void *opaque, target_phys_addr_t addr, |
111 | dd703aae | Benoît Canet | uint64_t val, unsigned size)
|
112 | a8f48dcc | blueswir1 | { |
113 | a8f48dcc | blueswir1 | MiscState *s = opaque; |
114 | a8f48dcc | blueswir1 | |
115 | 97bf4851 | Blue Swirl | trace_slavio_cfg_mem_writeb(val & 0xff);
|
116 | a8f48dcc | blueswir1 | s->config = val & 0xff;
|
117 | a8f48dcc | blueswir1 | slavio_misc_update_irq(s); |
118 | a8f48dcc | blueswir1 | } |
119 | a8f48dcc | blueswir1 | |
120 | dd703aae | Benoît Canet | static uint64_t slavio_cfg_mem_readb(void *opaque, target_phys_addr_t addr, |
121 | dd703aae | Benoît Canet | unsigned size)
|
122 | a8f48dcc | blueswir1 | { |
123 | a8f48dcc | blueswir1 | MiscState *s = opaque; |
124 | a8f48dcc | blueswir1 | uint32_t ret = 0;
|
125 | a8f48dcc | blueswir1 | |
126 | a8f48dcc | blueswir1 | ret = s->config; |
127 | 97bf4851 | Blue Swirl | trace_slavio_cfg_mem_readb(ret); |
128 | a8f48dcc | blueswir1 | return ret;
|
129 | a8f48dcc | blueswir1 | } |
130 | a8f48dcc | blueswir1 | |
131 | dd703aae | Benoît Canet | static const MemoryRegionOps slavio_cfg_mem_ops = { |
132 | dd703aae | Benoît Canet | .read = slavio_cfg_mem_readb, |
133 | dd703aae | Benoît Canet | .write = slavio_cfg_mem_writeb, |
134 | dd703aae | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
135 | dd703aae | Benoît Canet | .valid = { |
136 | dd703aae | Benoît Canet | .min_access_size = 1,
|
137 | dd703aae | Benoît Canet | .max_access_size = 1,
|
138 | dd703aae | Benoît Canet | }, |
139 | a8f48dcc | blueswir1 | }; |
140 | a8f48dcc | blueswir1 | |
141 | c227f099 | Anthony Liguori | static void slavio_diag_mem_writeb(void *opaque, target_phys_addr_t addr, |
142 | 96891e59 | Benoît Canet | uint64_t val, unsigned size)
|
143 | 3475187d | bellard | { |
144 | 3475187d | bellard | MiscState *s = opaque; |
145 | 3475187d | bellard | |
146 | 97bf4851 | Blue Swirl | trace_slavio_diag_mem_writeb(val & 0xff);
|
147 | a8f48dcc | blueswir1 | s->diag = val & 0xff;
|
148 | 3475187d | bellard | } |
149 | 3475187d | bellard | |
150 | 96891e59 | Benoît Canet | static uint64_t slavio_diag_mem_readb(void *opaque, target_phys_addr_t addr, |
151 | 96891e59 | Benoît Canet | unsigned size)
|
152 | 3475187d | bellard | { |
153 | 3475187d | bellard | MiscState *s = opaque; |
154 | 3475187d | bellard | uint32_t ret = 0;
|
155 | 3475187d | bellard | |
156 | a8f48dcc | blueswir1 | ret = s->diag; |
157 | 97bf4851 | Blue Swirl | trace_slavio_diag_mem_readb(ret); |
158 | a8f48dcc | blueswir1 | return ret;
|
159 | a8f48dcc | blueswir1 | } |
160 | a8f48dcc | blueswir1 | |
161 | 96891e59 | Benoît Canet | static const MemoryRegionOps slavio_diag_mem_ops = { |
162 | 96891e59 | Benoît Canet | .read = slavio_diag_mem_readb, |
163 | 96891e59 | Benoît Canet | .write = slavio_diag_mem_writeb, |
164 | 96891e59 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
165 | 96891e59 | Benoît Canet | .valid = { |
166 | 96891e59 | Benoît Canet | .min_access_size = 1,
|
167 | 96891e59 | Benoît Canet | .max_access_size = 1,
|
168 | 96891e59 | Benoît Canet | }, |
169 | a8f48dcc | blueswir1 | }; |
170 | a8f48dcc | blueswir1 | |
171 | c227f099 | Anthony Liguori | static void slavio_mdm_mem_writeb(void *opaque, target_phys_addr_t addr, |
172 | 2e66ac3d | Benoît Canet | uint64_t val, unsigned size)
|
173 | a8f48dcc | blueswir1 | { |
174 | a8f48dcc | blueswir1 | MiscState *s = opaque; |
175 | a8f48dcc | blueswir1 | |
176 | 97bf4851 | Blue Swirl | trace_slavio_mdm_mem_writeb(val & 0xff);
|
177 | a8f48dcc | blueswir1 | s->mctrl = val & 0xff;
|
178 | a8f48dcc | blueswir1 | } |
179 | a8f48dcc | blueswir1 | |
180 | 2e66ac3d | Benoît Canet | static uint64_t slavio_mdm_mem_readb(void *opaque, target_phys_addr_t addr, |
181 | 2e66ac3d | Benoît Canet | unsigned size)
|
182 | a8f48dcc | blueswir1 | { |
183 | a8f48dcc | blueswir1 | MiscState *s = opaque; |
184 | a8f48dcc | blueswir1 | uint32_t ret = 0;
|
185 | a8f48dcc | blueswir1 | |
186 | a8f48dcc | blueswir1 | ret = s->mctrl; |
187 | 97bf4851 | Blue Swirl | trace_slavio_mdm_mem_readb(ret); |
188 | 3475187d | bellard | return ret;
|
189 | 3475187d | bellard | } |
190 | 3475187d | bellard | |
191 | 2e66ac3d | Benoît Canet | static const MemoryRegionOps slavio_mdm_mem_ops = { |
192 | 2e66ac3d | Benoît Canet | .read = slavio_mdm_mem_readb, |
193 | 2e66ac3d | Benoît Canet | .write = slavio_mdm_mem_writeb, |
194 | 2e66ac3d | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
195 | 2e66ac3d | Benoît Canet | .valid = { |
196 | 2e66ac3d | Benoît Canet | .min_access_size = 1,
|
197 | 2e66ac3d | Benoît Canet | .max_access_size = 1,
|
198 | 2e66ac3d | Benoît Canet | }, |
199 | 3475187d | bellard | }; |
200 | 3475187d | bellard | |
201 | c227f099 | Anthony Liguori | static void slavio_aux1_mem_writeb(void *opaque, target_phys_addr_t addr, |
202 | cccd43c5 | Benoît Canet | uint64_t val, unsigned size)
|
203 | 0019ad53 | blueswir1 | { |
204 | 0019ad53 | blueswir1 | MiscState *s = opaque; |
205 | 0019ad53 | blueswir1 | |
206 | 97bf4851 | Blue Swirl | trace_slavio_aux1_mem_writeb(val & 0xff);
|
207 | 2be17ebd | blueswir1 | if (val & AUX1_TC) {
|
208 | 2be17ebd | blueswir1 | // Send a pulse to floppy terminal count line
|
209 | 2be17ebd | blueswir1 | if (s->fdc_tc) {
|
210 | 2be17ebd | blueswir1 | qemu_irq_raise(s->fdc_tc); |
211 | 2be17ebd | blueswir1 | qemu_irq_lower(s->fdc_tc); |
212 | 2be17ebd | blueswir1 | } |
213 | 2be17ebd | blueswir1 | val &= ~AUX1_TC; |
214 | 2be17ebd | blueswir1 | } |
215 | 0019ad53 | blueswir1 | s->aux1 = val & 0xff;
|
216 | 0019ad53 | blueswir1 | } |
217 | 0019ad53 | blueswir1 | |
218 | cccd43c5 | Benoît Canet | static uint64_t slavio_aux1_mem_readb(void *opaque, target_phys_addr_t addr, |
219 | cccd43c5 | Benoît Canet | unsigned size)
|
220 | 0019ad53 | blueswir1 | { |
221 | 0019ad53 | blueswir1 | MiscState *s = opaque; |
222 | 0019ad53 | blueswir1 | uint32_t ret = 0;
|
223 | 0019ad53 | blueswir1 | |
224 | 0019ad53 | blueswir1 | ret = s->aux1; |
225 | 97bf4851 | Blue Swirl | trace_slavio_aux1_mem_readb(ret); |
226 | 0019ad53 | blueswir1 | return ret;
|
227 | 0019ad53 | blueswir1 | } |
228 | 0019ad53 | blueswir1 | |
229 | cccd43c5 | Benoît Canet | static const MemoryRegionOps slavio_aux1_mem_ops = { |
230 | cccd43c5 | Benoît Canet | .read = slavio_aux1_mem_readb, |
231 | cccd43c5 | Benoît Canet | .write = slavio_aux1_mem_writeb, |
232 | cccd43c5 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
233 | cccd43c5 | Benoît Canet | .valid = { |
234 | cccd43c5 | Benoît Canet | .min_access_size = 1,
|
235 | cccd43c5 | Benoît Canet | .max_access_size = 1,
|
236 | cccd43c5 | Benoît Canet | }, |
237 | 0019ad53 | blueswir1 | }; |
238 | 0019ad53 | blueswir1 | |
239 | c227f099 | Anthony Liguori | static void slavio_aux2_mem_writeb(void *opaque, target_phys_addr_t addr, |
240 | 40ce02fc | Benoît Canet | uint64_t val, unsigned size)
|
241 | 0019ad53 | blueswir1 | { |
242 | 0019ad53 | blueswir1 | MiscState *s = opaque; |
243 | 0019ad53 | blueswir1 | |
244 | 0019ad53 | blueswir1 | val &= AUX2_PWRINTCLR | AUX2_PWROFF; |
245 | 97bf4851 | Blue Swirl | trace_slavio_aux2_mem_writeb(val & 0xff);
|
246 | 0019ad53 | blueswir1 | val |= s->aux2 & AUX2_PWRFAIL; |
247 | 0019ad53 | blueswir1 | if (val & AUX2_PWRINTCLR) // Clear Power Fail int |
248 | 0019ad53 | blueswir1 | val &= AUX2_PWROFF; |
249 | 0019ad53 | blueswir1 | s->aux2 = val; |
250 | 0019ad53 | blueswir1 | if (val & AUX2_PWROFF)
|
251 | 0019ad53 | blueswir1 | qemu_system_shutdown_request(); |
252 | 0019ad53 | blueswir1 | slavio_misc_update_irq(s); |
253 | 0019ad53 | blueswir1 | } |
254 | 0019ad53 | blueswir1 | |
255 | 40ce02fc | Benoît Canet | static uint64_t slavio_aux2_mem_readb(void *opaque, target_phys_addr_t addr, |
256 | 40ce02fc | Benoît Canet | unsigned size)
|
257 | 0019ad53 | blueswir1 | { |
258 | 0019ad53 | blueswir1 | MiscState *s = opaque; |
259 | 0019ad53 | blueswir1 | uint32_t ret = 0;
|
260 | 0019ad53 | blueswir1 | |
261 | 0019ad53 | blueswir1 | ret = s->aux2; |
262 | 97bf4851 | Blue Swirl | trace_slavio_aux2_mem_readb(ret); |
263 | 0019ad53 | blueswir1 | return ret;
|
264 | 0019ad53 | blueswir1 | } |
265 | 0019ad53 | blueswir1 | |
266 | 40ce02fc | Benoît Canet | static const MemoryRegionOps slavio_aux2_mem_ops = { |
267 | 40ce02fc | Benoît Canet | .read = slavio_aux2_mem_readb, |
268 | 40ce02fc | Benoît Canet | .write = slavio_aux2_mem_writeb, |
269 | 40ce02fc | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
270 | 40ce02fc | Benoît Canet | .valid = { |
271 | 40ce02fc | Benoît Canet | .min_access_size = 1,
|
272 | 40ce02fc | Benoît Canet | .max_access_size = 1,
|
273 | 40ce02fc | Benoît Canet | }, |
274 | 0019ad53 | blueswir1 | }; |
275 | 0019ad53 | blueswir1 | |
276 | 9c48dee6 | Benoît Canet | static void apc_mem_writeb(void *opaque, target_phys_addr_t addr, |
277 | 9c48dee6 | Benoît Canet | uint64_t val, unsigned size)
|
278 | 0019ad53 | blueswir1 | { |
279 | 2582cfa0 | Blue Swirl | APCState *s = opaque; |
280 | 0019ad53 | blueswir1 | |
281 | 97bf4851 | Blue Swirl | trace_apc_mem_writeb(val & 0xff);
|
282 | 6d0c293d | blueswir1 | qemu_irq_raise(s->cpu_halt); |
283 | 0019ad53 | blueswir1 | } |
284 | 0019ad53 | blueswir1 | |
285 | 9c48dee6 | Benoît Canet | static uint64_t apc_mem_readb(void *opaque, target_phys_addr_t addr, |
286 | 9c48dee6 | Benoît Canet | unsigned size)
|
287 | 0019ad53 | blueswir1 | { |
288 | 0019ad53 | blueswir1 | uint32_t ret = 0;
|
289 | 0019ad53 | blueswir1 | |
290 | 97bf4851 | Blue Swirl | trace_apc_mem_readb(ret); |
291 | 0019ad53 | blueswir1 | return ret;
|
292 | 0019ad53 | blueswir1 | } |
293 | 0019ad53 | blueswir1 | |
294 | 9c48dee6 | Benoît Canet | static const MemoryRegionOps apc_mem_ops = { |
295 | 9c48dee6 | Benoît Canet | .read = apc_mem_readb, |
296 | 9c48dee6 | Benoît Canet | .write = apc_mem_writeb, |
297 | 9c48dee6 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
298 | 9c48dee6 | Benoît Canet | .valid = { |
299 | 9c48dee6 | Benoît Canet | .min_access_size = 1,
|
300 | 9c48dee6 | Benoît Canet | .max_access_size = 1,
|
301 | 9c48dee6 | Benoît Canet | } |
302 | 0019ad53 | blueswir1 | }; |
303 | 0019ad53 | blueswir1 | |
304 | cd64a524 | Benoît Canet | static uint64_t slavio_sysctrl_mem_readl(void *opaque, target_phys_addr_t addr, |
305 | cd64a524 | Benoît Canet | unsigned size)
|
306 | bfa30a38 | blueswir1 | { |
307 | bfa30a38 | blueswir1 | MiscState *s = opaque; |
308 | a8f48dcc | blueswir1 | uint32_t ret = 0;
|
309 | bfa30a38 | blueswir1 | |
310 | a8f48dcc | blueswir1 | switch (addr) {
|
311 | bfa30a38 | blueswir1 | case 0: |
312 | bfa30a38 | blueswir1 | ret = s->sysctrl; |
313 | bfa30a38 | blueswir1 | break;
|
314 | bfa30a38 | blueswir1 | default:
|
315 | bfa30a38 | blueswir1 | break;
|
316 | bfa30a38 | blueswir1 | } |
317 | 97bf4851 | Blue Swirl | trace_slavio_sysctrl_mem_readl(ret); |
318 | bfa30a38 | blueswir1 | return ret;
|
319 | bfa30a38 | blueswir1 | } |
320 | bfa30a38 | blueswir1 | |
321 | c227f099 | Anthony Liguori | static void slavio_sysctrl_mem_writel(void *opaque, target_phys_addr_t addr, |
322 | cd64a524 | Benoît Canet | uint64_t val, unsigned size)
|
323 | bfa30a38 | blueswir1 | { |
324 | bfa30a38 | blueswir1 | MiscState *s = opaque; |
325 | bfa30a38 | blueswir1 | |
326 | 97bf4851 | Blue Swirl | trace_slavio_sysctrl_mem_writel(val); |
327 | a8f48dcc | blueswir1 | switch (addr) {
|
328 | bfa30a38 | blueswir1 | case 0: |
329 | 7debeb82 | blueswir1 | if (val & SYS_RESET) {
|
330 | 7debeb82 | blueswir1 | s->sysctrl = SYS_RESETSTAT; |
331 | bfa30a38 | blueswir1 | qemu_system_reset_request(); |
332 | bfa30a38 | blueswir1 | } |
333 | bfa30a38 | blueswir1 | break;
|
334 | bfa30a38 | blueswir1 | default:
|
335 | bfa30a38 | blueswir1 | break;
|
336 | bfa30a38 | blueswir1 | } |
337 | bfa30a38 | blueswir1 | } |
338 | bfa30a38 | blueswir1 | |
339 | cd64a524 | Benoît Canet | static const MemoryRegionOps slavio_sysctrl_mem_ops = { |
340 | cd64a524 | Benoît Canet | .read = slavio_sysctrl_mem_readl, |
341 | cd64a524 | Benoît Canet | .write = slavio_sysctrl_mem_writel, |
342 | cd64a524 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
343 | cd64a524 | Benoît Canet | .valid = { |
344 | cd64a524 | Benoît Canet | .min_access_size = 4,
|
345 | cd64a524 | Benoît Canet | .max_access_size = 4,
|
346 | cd64a524 | Benoît Canet | }, |
347 | bfa30a38 | blueswir1 | }; |
348 | bfa30a38 | blueswir1 | |
349 | aca23c71 | Benoît Canet | static uint64_t slavio_led_mem_readw(void *opaque, target_phys_addr_t addr, |
350 | aca23c71 | Benoît Canet | unsigned size)
|
351 | 6a3b9cc9 | blueswir1 | { |
352 | 6a3b9cc9 | blueswir1 | MiscState *s = opaque; |
353 | a8f48dcc | blueswir1 | uint32_t ret = 0;
|
354 | 6a3b9cc9 | blueswir1 | |
355 | a8f48dcc | blueswir1 | switch (addr) {
|
356 | 6a3b9cc9 | blueswir1 | case 0: |
357 | 6a3b9cc9 | blueswir1 | ret = s->leds; |
358 | 6a3b9cc9 | blueswir1 | break;
|
359 | 6a3b9cc9 | blueswir1 | default:
|
360 | 6a3b9cc9 | blueswir1 | break;
|
361 | 6a3b9cc9 | blueswir1 | } |
362 | 97bf4851 | Blue Swirl | trace_slavio_led_mem_readw(ret); |
363 | 6a3b9cc9 | blueswir1 | return ret;
|
364 | 6a3b9cc9 | blueswir1 | } |
365 | 6a3b9cc9 | blueswir1 | |
366 | c227f099 | Anthony Liguori | static void slavio_led_mem_writew(void *opaque, target_phys_addr_t addr, |
367 | aca23c71 | Benoît Canet | uint64_t val, unsigned size)
|
368 | 6a3b9cc9 | blueswir1 | { |
369 | 6a3b9cc9 | blueswir1 | MiscState *s = opaque; |
370 | 6a3b9cc9 | blueswir1 | |
371 | 97bf4851 | Blue Swirl | trace_slavio_led_mem_readw(val & 0xffff);
|
372 | a8f48dcc | blueswir1 | switch (addr) {
|
373 | 6a3b9cc9 | blueswir1 | case 0: |
374 | d5296cb5 | blueswir1 | s->leds = val; |
375 | 6a3b9cc9 | blueswir1 | break;
|
376 | 6a3b9cc9 | blueswir1 | default:
|
377 | 6a3b9cc9 | blueswir1 | break;
|
378 | 6a3b9cc9 | blueswir1 | } |
379 | 6a3b9cc9 | blueswir1 | } |
380 | 6a3b9cc9 | blueswir1 | |
381 | aca23c71 | Benoît Canet | static const MemoryRegionOps slavio_led_mem_ops = { |
382 | aca23c71 | Benoît Canet | .read = slavio_led_mem_readw, |
383 | aca23c71 | Benoît Canet | .write = slavio_led_mem_writew, |
384 | aca23c71 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
385 | aca23c71 | Benoît Canet | .valid = { |
386 | aca23c71 | Benoît Canet | .min_access_size = 2,
|
387 | aca23c71 | Benoît Canet | .max_access_size = 2,
|
388 | aca23c71 | Benoît Canet | }, |
389 | 6a3b9cc9 | blueswir1 | }; |
390 | 6a3b9cc9 | blueswir1 | |
391 | d37adb09 | Blue Swirl | static const VMStateDescription vmstate_misc = { |
392 | d37adb09 | Blue Swirl | .name ="slavio_misc",
|
393 | d37adb09 | Blue Swirl | .version_id = 1,
|
394 | d37adb09 | Blue Swirl | .minimum_version_id = 1,
|
395 | d37adb09 | Blue Swirl | .minimum_version_id_old = 1,
|
396 | d37adb09 | Blue Swirl | .fields = (VMStateField []) { |
397 | d37adb09 | Blue Swirl | VMSTATE_UINT32(dummy, MiscState), |
398 | d37adb09 | Blue Swirl | VMSTATE_UINT8(config, MiscState), |
399 | d37adb09 | Blue Swirl | VMSTATE_UINT8(aux1, MiscState), |
400 | d37adb09 | Blue Swirl | VMSTATE_UINT8(aux2, MiscState), |
401 | d37adb09 | Blue Swirl | VMSTATE_UINT8(diag, MiscState), |
402 | d37adb09 | Blue Swirl | VMSTATE_UINT8(mctrl, MiscState), |
403 | d37adb09 | Blue Swirl | VMSTATE_UINT8(sysctrl, MiscState), |
404 | d37adb09 | Blue Swirl | VMSTATE_END_OF_LIST() |
405 | d37adb09 | Blue Swirl | } |
406 | d37adb09 | Blue Swirl | }; |
407 | 3475187d | bellard | |
408 | 81a322d4 | Gerd Hoffmann | static int apc_init1(SysBusDevice *dev) |
409 | 2582cfa0 | Blue Swirl | { |
410 | 2582cfa0 | Blue Swirl | APCState *s = FROM_SYSBUS(APCState, dev); |
411 | 3475187d | bellard | |
412 | 2582cfa0 | Blue Swirl | sysbus_init_irq(dev, &s->cpu_halt); |
413 | 2582cfa0 | Blue Swirl | |
414 | 2582cfa0 | Blue Swirl | /* Power management (APC) XXX: not a Slavio device */
|
415 | 9c48dee6 | Benoît Canet | memory_region_init_io(&s->iomem, &apc_mem_ops, s, |
416 | 9c48dee6 | Benoît Canet | "apc", MISC_SIZE);
|
417 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->iomem); |
418 | 81a322d4 | Gerd Hoffmann | return 0; |
419 | 2582cfa0 | Blue Swirl | } |
420 | 2582cfa0 | Blue Swirl | |
421 | 81a322d4 | Gerd Hoffmann | static int slavio_misc_init1(SysBusDevice *dev) |
422 | 2582cfa0 | Blue Swirl | { |
423 | 2582cfa0 | Blue Swirl | MiscState *s = FROM_SYSBUS(MiscState, dev); |
424 | 2582cfa0 | Blue Swirl | |
425 | 2582cfa0 | Blue Swirl | sysbus_init_irq(dev, &s->irq); |
426 | 2582cfa0 | Blue Swirl | sysbus_init_irq(dev, &s->fdc_tc); |
427 | 2582cfa0 | Blue Swirl | |
428 | 2582cfa0 | Blue Swirl | /* 8 bit registers */
|
429 | 2582cfa0 | Blue Swirl | /* Slavio control */
|
430 | dd703aae | Benoît Canet | memory_region_init_io(&s->cfg_iomem, &slavio_cfg_mem_ops, s, |
431 | dd703aae | Benoît Canet | "configuration", MISC_SIZE);
|
432 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->cfg_iomem); |
433 | 2582cfa0 | Blue Swirl | |
434 | 2582cfa0 | Blue Swirl | /* Diagnostics */
|
435 | 96891e59 | Benoît Canet | memory_region_init_io(&s->diag_iomem, &slavio_diag_mem_ops, s, |
436 | 96891e59 | Benoît Canet | "diagnostic", MISC_SIZE);
|
437 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->diag_iomem); |
438 | 2582cfa0 | Blue Swirl | |
439 | 2582cfa0 | Blue Swirl | /* Modem control */
|
440 | 2e66ac3d | Benoît Canet | memory_region_init_io(&s->mdm_iomem, &slavio_mdm_mem_ops, s, |
441 | 2e66ac3d | Benoît Canet | "modem", MISC_SIZE);
|
442 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->mdm_iomem); |
443 | 2582cfa0 | Blue Swirl | |
444 | 2582cfa0 | Blue Swirl | /* 16 bit registers */
|
445 | 2582cfa0 | Blue Swirl | /* ss600mp diag LEDs */
|
446 | aca23c71 | Benoît Canet | memory_region_init_io(&s->led_iomem, &slavio_led_mem_ops, s, |
447 | aca23c71 | Benoît Canet | "leds", MISC_SIZE);
|
448 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->led_iomem); |
449 | 2582cfa0 | Blue Swirl | |
450 | 2582cfa0 | Blue Swirl | /* 32 bit registers */
|
451 | 2582cfa0 | Blue Swirl | /* System control */
|
452 | cd64a524 | Benoît Canet | memory_region_init_io(&s->sysctrl_iomem, &slavio_sysctrl_mem_ops, s, |
453 | cd64a524 | Benoît Canet | "system-control", MISC_SIZE);
|
454 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->sysctrl_iomem); |
455 | 2582cfa0 | Blue Swirl | |
456 | 2582cfa0 | Blue Swirl | /* AUX 1 (Misc System Functions) */
|
457 | cccd43c5 | Benoît Canet | memory_region_init_io(&s->aux1_iomem, &slavio_aux1_mem_ops, s, |
458 | cccd43c5 | Benoît Canet | "misc-system-functions", MISC_SIZE);
|
459 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->aux1_iomem); |
460 | 2582cfa0 | Blue Swirl | |
461 | 2582cfa0 | Blue Swirl | /* AUX 2 (Software Powerdown Control) */
|
462 | 40ce02fc | Benoît Canet | memory_region_init_io(&s->aux2_iomem, &slavio_aux2_mem_ops, s, |
463 | 40ce02fc | Benoît Canet | "software-powerdown-control", MISC_SIZE);
|
464 | 750ecd44 | Avi Kivity | sysbus_init_mmio(dev, &s->aux2_iomem); |
465 | 2582cfa0 | Blue Swirl | |
466 | b2b6f6ec | Blue Swirl | qdev_init_gpio_in(&dev->qdev, slavio_set_power_fail, 1);
|
467 | b2b6f6ec | Blue Swirl | |
468 | 81a322d4 | Gerd Hoffmann | return 0; |
469 | 2582cfa0 | Blue Swirl | } |
470 | 0019ad53 | blueswir1 | |
471 | 2582cfa0 | Blue Swirl | static SysBusDeviceInfo slavio_misc_info = {
|
472 | 2582cfa0 | Blue Swirl | .init = slavio_misc_init1, |
473 | 2582cfa0 | Blue Swirl | .qdev.name = "slavio_misc",
|
474 | 2582cfa0 | Blue Swirl | .qdev.size = sizeof(MiscState),
|
475 | 1795057a | Blue Swirl | .qdev.vmsd = &vmstate_misc, |
476 | 1795057a | Blue Swirl | .qdev.reset = slavio_misc_reset, |
477 | 2582cfa0 | Blue Swirl | }; |
478 | 2582cfa0 | Blue Swirl | |
479 | 2582cfa0 | Blue Swirl | static SysBusDeviceInfo apc_info = {
|
480 | 2582cfa0 | Blue Swirl | .init = apc_init1, |
481 | 2582cfa0 | Blue Swirl | .qdev.name = "apc",
|
482 | 2582cfa0 | Blue Swirl | .qdev.size = sizeof(MiscState),
|
483 | 2582cfa0 | Blue Swirl | }; |
484 | 2582cfa0 | Blue Swirl | |
485 | 2582cfa0 | Blue Swirl | static void slavio_misc_register_devices(void) |
486 | 2582cfa0 | Blue Swirl | { |
487 | 2582cfa0 | Blue Swirl | sysbus_register_withprop(&slavio_misc_info); |
488 | 2582cfa0 | Blue Swirl | sysbus_register_withprop(&apc_info); |
489 | 3475187d | bellard | } |
490 | 2582cfa0 | Blue Swirl | |
491 | 2582cfa0 | Blue Swirl | device_init(slavio_misc_register_devices) |