1 |
/* |
/* |
2 |
* Copyright (C) 2005-2006 Anders Gavare. All rights reserved. |
* Copyright (C) 2005-2007 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* $Id: dev_gc.c,v 1.8 2006/02/27 05:32:26 debug Exp $ |
* $Id: dev_openpic.c,v 1.14 2007/09/11 21:42:52 debug Exp $ |
28 |
* |
* |
29 |
* Grand Central Interrupt controller (used by MacPPC). |
* COMMENT: OpenPIC Interrupt controller (used by sandpoint ppc) |
30 |
|
* based on dev_gc.c |
31 |
*/ |
*/ |
32 |
|
|
33 |
#include <stdio.h> |
#include <stdio.h> |
36 |
|
|
37 |
#include "cpu.h" |
#include "cpu.h" |
38 |
#include "device.h" |
#include "device.h" |
|
#include "devices.h" |
|
39 |
#include "machine.h" |
#include "machine.h" |
40 |
#include "memory.h" |
#include "memory.h" |
41 |
#include "misc.h" |
#include "misc.h" |
42 |
|
|
43 |
|
|
44 |
DEVICE_ACCESS(gc) |
#define DEV_OPENPIC_LENGTH 0x40000 |
45 |
|
|
46 |
|
struct openpic_data { |
47 |
|
struct interrupt cpu_irq; |
48 |
|
|
49 |
|
uint32_t status_hi; |
50 |
|
uint32_t status_lo; |
51 |
|
uint32_t enable_hi; |
52 |
|
uint32_t enable_lo; |
53 |
|
}; |
54 |
|
|
55 |
|
|
56 |
|
void openpic_hi_interrupt_assert(struct interrupt *interrupt) |
57 |
{ |
{ |
58 |
struct gc_data *d = extra; |
struct openpic_data *d = interrupt->extra; |
59 |
|
d->status_hi |= interrupt->line; |
60 |
|
if (d->status_lo & d->enable_lo || d->status_hi & d->enable_hi) |
61 |
|
INTERRUPT_ASSERT(d->cpu_irq); |
62 |
|
} |
63 |
|
void openpic_hi_interrupt_deassert(struct interrupt *interrupt) |
64 |
|
{ |
65 |
|
struct openpic_data *d = interrupt->extra; |
66 |
|
d->status_hi &= ~interrupt->line; |
67 |
|
if (!(d->status_lo & d->enable_lo || d->status_hi & d->enable_hi)) |
68 |
|
INTERRUPT_DEASSERT(d->cpu_irq); |
69 |
|
} |
70 |
|
void openpic_lo_interrupt_assert(struct interrupt *interrupt) |
71 |
|
{ |
72 |
|
struct openpic_data *d = interrupt->extra; |
73 |
|
d->status_lo |= interrupt->line; |
74 |
|
if (d->status_lo & d->enable_lo || d->status_hi & d->enable_hi) |
75 |
|
INTERRUPT_ASSERT(d->cpu_irq); |
76 |
|
} |
77 |
|
void openpic_lo_interrupt_deassert(struct interrupt *interrupt) |
78 |
|
{ |
79 |
|
struct openpic_data *d = interrupt->extra; |
80 |
|
d->status_lo &= ~interrupt->line; |
81 |
|
if (!(d->status_lo & d->enable_lo || d->status_hi & d->enable_hi)) |
82 |
|
INTERRUPT_DEASSERT(d->cpu_irq); |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
|
DEVICE_ACCESS(openpic) |
87 |
|
{ |
88 |
|
// struct openpic_data *d = extra; |
89 |
uint64_t idata = 0, odata = 0; |
uint64_t idata = 0, odata = 0; |
90 |
|
|
91 |
if (writeflag == MEM_WRITE) |
if (writeflag == MEM_WRITE) |
93 |
|
|
94 |
switch (relative_addr) { |
switch (relative_addr) { |
95 |
|
|
96 |
|
case 0x00: |
97 |
|
if (writeflag == MEM_READ) |
98 |
|
// version 1.2 |
99 |
|
odata = 0x02000000; |
100 |
|
break; |
101 |
|
|
102 |
#if 0 |
#if 0 |
103 |
#define INT_STATE_REG_H (interrupt_reg + 0x00) |
#define INT_STATE_REG_H (interrupt_reg + 0x00) |
104 |
#define INT_ENABLE_REG_H (interrupt_reg + 0x04) |
#define INT_ENABLE_REG_H (interrupt_reg + 0x04) |
110 |
#define INT_LEVEL_REG_L (interrupt_reg + 0x1c) |
#define INT_LEVEL_REG_L (interrupt_reg + 0x1c) |
111 |
#endif |
#endif |
112 |
|
|
113 |
|
#if 0 |
114 |
case 0x10: |
case 0x10: |
115 |
if (writeflag == MEM_READ) |
if (writeflag == MEM_READ) |
116 |
odata = d->status_hi & d->enable_hi; |
odata = d->status_hi & d->enable_hi; |
120 |
if (writeflag == MEM_READ) |
if (writeflag == MEM_READ) |
121 |
odata = d->enable_hi; |
odata = d->enable_hi; |
122 |
else { |
else { |
123 |
uint32_t old_enable_hi = d->enable_hi; |
int old_assert = (d->status_lo & d->enable_lo |
124 |
|
|| d->status_hi & d->enable_hi); |
125 |
|
int new_assert; |
126 |
d->enable_hi = idata; |
d->enable_hi = idata; |
127 |
if (d->enable_hi != old_enable_hi) |
|
128 |
cpu_interrupt(cpu, d->reassert_irq); |
new_assert = (d->status_lo & d->enable_lo || |
129 |
|
d->status_hi & d->enable_hi); |
130 |
|
|
131 |
|
if (old_assert && !new_assert) |
132 |
|
INTERRUPT_DEASSERT(d->cpu_irq); |
133 |
|
else if (!old_assert && new_assert) |
134 |
|
INTERRUPT_ASSERT(d->cpu_irq); |
135 |
} |
} |
136 |
break; |
break; |
137 |
|
|
138 |
case 0x18: |
case 0x18: |
139 |
if (writeflag == MEM_WRITE) { |
if (writeflag == MEM_WRITE) { |
140 |
uint32_t old_status_hi = d->status_hi; |
int old_assert = (d->status_lo & d->enable_lo |
141 |
|
|| d->status_hi & d->enable_hi); |
142 |
|
int new_assert; |
143 |
d->status_hi &= ~idata; |
d->status_hi &= ~idata; |
144 |
if (d->status_hi != old_status_hi) |
|
145 |
cpu_interrupt(cpu, d->reassert_irq); |
new_assert = (d->status_lo & d->enable_lo || |
146 |
|
d->status_hi & d->enable_hi); |
147 |
|
|
148 |
|
if (old_assert && !new_assert) |
149 |
|
INTERRUPT_DEASSERT(d->cpu_irq); |
150 |
|
else if (!old_assert && new_assert) |
151 |
|
INTERRUPT_ASSERT(d->cpu_irq); |
152 |
} |
} |
153 |
break; |
break; |
154 |
|
|
161 |
if (writeflag == MEM_READ) |
if (writeflag == MEM_READ) |
162 |
odata = d->enable_lo; |
odata = d->enable_lo; |
163 |
else { |
else { |
164 |
uint32_t old_enable_lo = d->enable_lo; |
int old_assert = (d->status_lo & d->enable_lo |
165 |
|
|| d->status_hi & d->enable_hi); |
166 |
|
int new_assert; |
167 |
d->enable_lo = idata; |
d->enable_lo = idata; |
168 |
if (d->enable_lo != old_enable_lo) |
|
169 |
cpu_interrupt(cpu, d->reassert_irq); |
new_assert = (d->status_lo & d->enable_lo || |
170 |
|
d->status_hi & d->enable_hi); |
171 |
|
|
172 |
|
if (old_assert && !new_assert) |
173 |
|
INTERRUPT_DEASSERT(d->cpu_irq); |
174 |
|
else if (!old_assert && new_assert) |
175 |
|
INTERRUPT_ASSERT(d->cpu_irq); |
176 |
} |
} |
177 |
break; |
break; |
178 |
|
|
179 |
case 0x28: |
case 0x28: |
180 |
if (writeflag == MEM_WRITE) { |
if (writeflag == MEM_WRITE) { |
181 |
uint32_t old_status_lo = d->status_lo; |
int old_assert = (d->status_lo & d->enable_lo |
182 |
|
|| d->status_hi & d->enable_hi); |
183 |
|
int new_assert; |
184 |
d->status_lo &= ~idata; |
d->status_lo &= ~idata; |
185 |
if (d->status_lo != old_status_lo) |
|
186 |
cpu_interrupt(cpu, d->reassert_irq); |
new_assert = (d->status_lo & d->enable_lo || |
187 |
|
d->status_hi & d->enable_hi); |
188 |
|
|
189 |
|
if (old_assert && !new_assert) |
190 |
|
INTERRUPT_DEASSERT(d->cpu_irq); |
191 |
|
else if (!old_assert && new_assert) |
192 |
|
INTERRUPT_ASSERT(d->cpu_irq); |
193 |
} |
} |
194 |
break; |
break; |
195 |
|
|
196 |
|
case 0x1c: |
197 |
case 0x2c: |
case 0x2c: |
198 |
/* Avoir a debug message. */ |
/* Avoid a debug message. */ |
199 |
break; |
break; |
200 |
|
#endif |
201 |
default:if (writeflag == MEM_WRITE) { |
default:if (writeflag == MEM_WRITE) { |
202 |
fatal("[ gc: unimplemented write to " |
fatal("[ openpic: unimplemented write to " |
203 |
"offset 0x%x: data=0x%x ]\n", (int) |
"offset 0x%x: data=0x%x ]\n", (int) |
204 |
relative_addr, (int)idata); |
relative_addr, (int)idata); |
205 |
} else { |
} else { |
206 |
fatal("[ gc: unimplemented read from " |
fatal("[ openpic: unimplemented read from " |
207 |
"offset 0x%x ]\n", (int)relative_addr); |
"offset 0x%x ]\n", (int)relative_addr); |
208 |
} |
} |
209 |
} |
} |
215 |
} |
} |
216 |
|
|
217 |
|
|
218 |
/* |
DEVINIT(openpic) |
|
* dev_gc_init(): |
|
|
*/ |
|
|
struct gc_data *dev_gc_init(struct machine *machine, struct memory *mem, |
|
|
uint64_t addr, int reassert_irq) |
|
219 |
{ |
{ |
220 |
struct gc_data *d; |
struct openpic_data *d; |
221 |
|
int i; |
222 |
|
|
223 |
|
CHECK_ALLOCATION(d = malloc(sizeof(struct openpic_data))); |
224 |
|
memset(d, 0, sizeof(struct openpic_data)); |
225 |
|
|
226 |
d = malloc(sizeof(struct gc_data)); |
/* Connect to the CPU interrupt pin: */ |
227 |
if (d == NULL) { |
INTERRUPT_CONNECT(devinit->interrupt_path, d->cpu_irq); |
228 |
fprintf(stderr, "out of memory\n"); |
|
229 |
exit(1); |
/* |
230 |
|
* Register the 126 OpenPIC interrupts |
231 |
|
*/ |
232 |
|
for (i=0; i<126; i++) { |
233 |
|
struct interrupt template; |
234 |
|
char n[300]; |
235 |
|
snprintf(n, sizeof(n), "%s.openpic.%i", |
236 |
|
devinit->interrupt_path, i); |
237 |
|
memset(&template, 0, sizeof(template)); |
238 |
|
template.line = 1 << i; |
239 |
|
template.name = n; |
240 |
|
template.extra = d; |
241 |
|
template.interrupt_assert = openpic_lo_interrupt_assert; |
242 |
|
template.interrupt_deassert = openpic_lo_interrupt_deassert; |
243 |
|
interrupt_handler_register(&template); |
244 |
} |
} |
|
memset(d, 0, sizeof(struct gc_data)); |
|
|
d->reassert_irq = reassert_irq; |
|
245 |
|
|
246 |
memory_device_register(mem, "gc", addr, 0x100, |
memory_device_register(devinit->machine->memory, "openpic", |
247 |
dev_gc_access, d, DM_DEFAULT, NULL); |
devinit->addr, DEV_OPENPIC_LENGTH, dev_openpic_access, d, DM_DEFAULT, NULL); |
248 |
|
|
249 |
return d; |
return 1; |
250 |
} |
} |
251 |
|
|