root / hw / slavio_misc.c @ 86cc1ce0
History | View | Annotate | Download (6.8 kB)
1 |
/*
|
---|---|
2 |
* QEMU Sparc SLAVIO aux io port emulation
|
3 |
*
|
4 |
* Copyright (c) 2005 Fabrice Bellard
|
5 |
*
|
6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 |
* of this software and associated documentation files (the "Software"), to deal
|
8 |
* in the Software without restriction, including without limitation the rights
|
9 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 |
* copies of the Software, and to permit persons to whom the Software is
|
11 |
* furnished to do so, subject to the following conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be included in
|
14 |
* all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 |
* THE SOFTWARE.
|
23 |
*/
|
24 |
#include "vl.h" |
25 |
/* debug misc */
|
26 |
//#define DEBUG_MISC
|
27 |
|
28 |
/*
|
29 |
* This is the auxio port, chip control and system control part of
|
30 |
* chip STP2001 (Slave I/O), also produced as NCR89C105. See
|
31 |
* http://www.ibiblio.org/pub/historic-linux/early-ports/Sparc/NCR/NCR89C105.txt
|
32 |
*
|
33 |
* This also includes the PMC CPU idle controller.
|
34 |
*/
|
35 |
|
36 |
#ifdef DEBUG_MISC
|
37 |
#define MISC_DPRINTF(fmt, args...) \
|
38 |
do { printf("MISC: " fmt , ##args); } while (0) |
39 |
#define pic_set_irq_new(intctl, irq, level) \
|
40 |
do { printf("MISC: set_irq(%d): %d\n", (irq), (level)); \ |
41 |
pic_set_irq_new((intctl), (irq),(level));} while (0) |
42 |
#else
|
43 |
#define MISC_DPRINTF(fmt, args...)
|
44 |
#endif
|
45 |
|
46 |
typedef struct MiscState { |
47 |
int irq;
|
48 |
uint8_t config; |
49 |
uint8_t aux1, aux2; |
50 |
uint8_t diag, mctrl, sysctrl; |
51 |
void *intctl;
|
52 |
} MiscState; |
53 |
|
54 |
#define MISC_MAXADDR 1 |
55 |
|
56 |
static void slavio_misc_update_irq(void *opaque) |
57 |
{ |
58 |
MiscState *s = opaque; |
59 |
|
60 |
if ((s->aux2 & 0x4) && (s->config & 0x8)) { |
61 |
pic_set_irq_new(s->intctl, s->irq, 1);
|
62 |
} else {
|
63 |
pic_set_irq_new(s->intctl, s->irq, 0);
|
64 |
} |
65 |
} |
66 |
|
67 |
static void slavio_misc_reset(void *opaque) |
68 |
{ |
69 |
MiscState *s = opaque; |
70 |
|
71 |
// Diagnostic and system control registers not cleared in reset
|
72 |
s->config = s->aux1 = s->aux2 = s->mctrl = 0;
|
73 |
} |
74 |
|
75 |
void slavio_set_power_fail(void *opaque, int power_failing) |
76 |
{ |
77 |
MiscState *s = opaque; |
78 |
|
79 |
MISC_DPRINTF("Power fail: %d, config: %d\n", power_failing, s->config);
|
80 |
if (power_failing && (s->config & 0x8)) { |
81 |
s->aux2 |= 0x4;
|
82 |
} else {
|
83 |
s->aux2 &= ~0x4;
|
84 |
} |
85 |
slavio_misc_update_irq(s); |
86 |
} |
87 |
|
88 |
static void slavio_misc_mem_writeb(void *opaque, target_phys_addr_t addr, uint32_t val) |
89 |
{ |
90 |
MiscState *s = opaque; |
91 |
|
92 |
switch (addr & 0xfff0000) { |
93 |
case 0x1800000: |
94 |
MISC_DPRINTF("Write config %2.2x\n", val & 0xff); |
95 |
s->config = val & 0xff;
|
96 |
slavio_misc_update_irq(s); |
97 |
break;
|
98 |
case 0x1900000: |
99 |
MISC_DPRINTF("Write aux1 %2.2x\n", val & 0xff); |
100 |
s->aux1 = val & 0xff;
|
101 |
break;
|
102 |
case 0x1910000: |
103 |
val &= 0x3;
|
104 |
MISC_DPRINTF("Write aux2 %2.2x\n", val);
|
105 |
val |= s->aux2 & 0x4;
|
106 |
if (val & 0x2) // Clear Power Fail int |
107 |
val &= 0x1;
|
108 |
s->aux2 = val; |
109 |
if (val & 1) |
110 |
qemu_system_shutdown_request(); |
111 |
slavio_misc_update_irq(s); |
112 |
break;
|
113 |
case 0x1a00000: |
114 |
MISC_DPRINTF("Write diag %2.2x\n", val & 0xff); |
115 |
s->diag = val & 0xff;
|
116 |
break;
|
117 |
case 0x1b00000: |
118 |
MISC_DPRINTF("Write modem control %2.2x\n", val & 0xff); |
119 |
s->mctrl = val & 0xff;
|
120 |
break;
|
121 |
case 0x1f00000: |
122 |
MISC_DPRINTF("Write system control %2.2x\n", val & 0xff); |
123 |
if (val & 1) { |
124 |
s->sysctrl = 0x2;
|
125 |
qemu_system_reset_request(); |
126 |
} |
127 |
break;
|
128 |
case 0xa000000: |
129 |
MISC_DPRINTF("Write power management %2.2x\n", val & 0xff); |
130 |
cpu_interrupt(cpu_single_env, CPU_INTERRUPT_HALT); |
131 |
break;
|
132 |
} |
133 |
} |
134 |
|
135 |
static uint32_t slavio_misc_mem_readb(void *opaque, target_phys_addr_t addr) |
136 |
{ |
137 |
MiscState *s = opaque; |
138 |
uint32_t ret = 0;
|
139 |
|
140 |
switch (addr & 0xfff0000) { |
141 |
case 0x1800000: |
142 |
ret = s->config; |
143 |
MISC_DPRINTF("Read config %2.2x\n", ret);
|
144 |
break;
|
145 |
case 0x1900000: |
146 |
ret = s->aux1; |
147 |
MISC_DPRINTF("Read aux1 %2.2x\n", ret);
|
148 |
break;
|
149 |
case 0x1910000: |
150 |
ret = s->aux2; |
151 |
MISC_DPRINTF("Read aux2 %2.2x\n", ret);
|
152 |
break;
|
153 |
case 0x1a00000: |
154 |
ret = s->diag; |
155 |
MISC_DPRINTF("Read diag %2.2x\n", ret);
|
156 |
break;
|
157 |
case 0x1b00000: |
158 |
ret = s->mctrl; |
159 |
MISC_DPRINTF("Read modem control %2.2x\n", ret);
|
160 |
break;
|
161 |
case 0x1f00000: |
162 |
MISC_DPRINTF("Read system control %2.2x\n", ret);
|
163 |
ret = s->sysctrl; |
164 |
break;
|
165 |
case 0xa000000: |
166 |
MISC_DPRINTF("Read power management %2.2x\n", ret);
|
167 |
break;
|
168 |
} |
169 |
return ret;
|
170 |
} |
171 |
|
172 |
static CPUReadMemoryFunc *slavio_misc_mem_read[3] = { |
173 |
slavio_misc_mem_readb, |
174 |
slavio_misc_mem_readb, |
175 |
slavio_misc_mem_readb, |
176 |
}; |
177 |
|
178 |
static CPUWriteMemoryFunc *slavio_misc_mem_write[3] = { |
179 |
slavio_misc_mem_writeb, |
180 |
slavio_misc_mem_writeb, |
181 |
slavio_misc_mem_writeb, |
182 |
}; |
183 |
|
184 |
static void slavio_misc_save(QEMUFile *f, void *opaque) |
185 |
{ |
186 |
MiscState *s = opaque; |
187 |
|
188 |
qemu_put_be32s(f, &s->irq); |
189 |
qemu_put_8s(f, &s->config); |
190 |
qemu_put_8s(f, &s->aux1); |
191 |
qemu_put_8s(f, &s->aux2); |
192 |
qemu_put_8s(f, &s->diag); |
193 |
qemu_put_8s(f, &s->mctrl); |
194 |
qemu_put_8s(f, &s->sysctrl); |
195 |
} |
196 |
|
197 |
static int slavio_misc_load(QEMUFile *f, void *opaque, int version_id) |
198 |
{ |
199 |
MiscState *s = opaque; |
200 |
|
201 |
if (version_id != 1) |
202 |
return -EINVAL;
|
203 |
|
204 |
qemu_get_be32s(f, &s->irq); |
205 |
qemu_get_8s(f, &s->config); |
206 |
qemu_get_8s(f, &s->aux1); |
207 |
qemu_get_8s(f, &s->aux2); |
208 |
qemu_get_8s(f, &s->diag); |
209 |
qemu_get_8s(f, &s->mctrl); |
210 |
qemu_get_8s(f, &s->sysctrl); |
211 |
return 0; |
212 |
} |
213 |
|
214 |
void *slavio_misc_init(uint32_t base, int irq, void *intctl) |
215 |
{ |
216 |
int slavio_misc_io_memory;
|
217 |
MiscState *s; |
218 |
|
219 |
s = qemu_mallocz(sizeof(MiscState));
|
220 |
if (!s)
|
221 |
return NULL; |
222 |
|
223 |
slavio_misc_io_memory = cpu_register_io_memory(0, slavio_misc_mem_read, slavio_misc_mem_write, s);
|
224 |
// Slavio control
|
225 |
cpu_register_physical_memory(base + 0x1800000, MISC_MAXADDR, slavio_misc_io_memory);
|
226 |
// AUX 1
|
227 |
cpu_register_physical_memory(base + 0x1900000, MISC_MAXADDR, slavio_misc_io_memory);
|
228 |
// AUX 2
|
229 |
cpu_register_physical_memory(base + 0x1910000, MISC_MAXADDR, slavio_misc_io_memory);
|
230 |
// Diagnostics
|
231 |
cpu_register_physical_memory(base + 0x1a00000, MISC_MAXADDR, slavio_misc_io_memory);
|
232 |
// Modem control
|
233 |
cpu_register_physical_memory(base + 0x1b00000, MISC_MAXADDR, slavio_misc_io_memory);
|
234 |
// System control
|
235 |
cpu_register_physical_memory(base + 0x1f00000, MISC_MAXADDR, slavio_misc_io_memory);
|
236 |
// Power management
|
237 |
cpu_register_physical_memory(base + 0xa000000, MISC_MAXADDR, slavio_misc_io_memory);
|
238 |
|
239 |
s->irq = irq; |
240 |
s->intctl = intctl; |
241 |
|
242 |
register_savevm("slavio_misc", base, 1, slavio_misc_save, slavio_misc_load, s); |
243 |
qemu_register_reset(slavio_misc_reset, s); |
244 |
slavio_misc_reset(s); |
245 |
return s;
|
246 |
} |