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.14 2007/09/11 21:42:52 debug Exp $ |
* $Id: dev_openpic.c,v 1.14 2007/09/11 21:42:52 debug Exp $ |
28 |
* |
* |
29 |
* COMMENT: Grand Central Interrupt controller (used by MacPPC) |
* COMMENT: OpenPIC Interrupt controller (used by sandpoint ppc) |
30 |
|
* based on dev_openpic.c |
31 |
*/ |
*/ |
32 |
|
|
33 |
#include <stdio.h> |
#include <stdio.h> |
41 |
#include "misc.h" |
#include "misc.h" |
42 |
|
|
43 |
|
|
44 |
#define DEV_GC_LENGTH 0x100 |
#define DEV_OPENPIC_LENGTH 0x40000 |
45 |
|
|
46 |
struct gc_data { |
struct openpic_data { |
47 |
struct interrupt cpu_irq; |
struct interrupt cpu_irq; |
48 |
|
|
49 |
uint32_t status_hi; |
uint32_t status_hi; |
53 |
}; |
}; |
54 |
|
|
55 |
|
|
56 |
void gc_hi_interrupt_assert(struct interrupt *interrupt) |
void openpic_hi_interrupt_assert(struct interrupt *interrupt) |
57 |
{ |
{ |
58 |
struct gc_data *d = interrupt->extra; |
struct openpic_data *d = interrupt->extra; |
59 |
d->status_hi |= interrupt->line; |
d->status_hi |= interrupt->line; |
60 |
if (d->status_lo & d->enable_lo || d->status_hi & d->enable_hi) |
if (d->status_lo & d->enable_lo || d->status_hi & d->enable_hi) |
61 |
INTERRUPT_ASSERT(d->cpu_irq); |
INTERRUPT_ASSERT(d->cpu_irq); |
62 |
} |
} |
63 |
void gc_hi_interrupt_deassert(struct interrupt *interrupt) |
void openpic_hi_interrupt_deassert(struct interrupt *interrupt) |
64 |
{ |
{ |
65 |
struct gc_data *d = interrupt->extra; |
struct openpic_data *d = interrupt->extra; |
66 |
d->status_hi &= ~interrupt->line; |
d->status_hi &= ~interrupt->line; |
67 |
if (!(d->status_lo & d->enable_lo || d->status_hi & d->enable_hi)) |
if (!(d->status_lo & d->enable_lo || d->status_hi & d->enable_hi)) |
68 |
INTERRUPT_DEASSERT(d->cpu_irq); |
INTERRUPT_DEASSERT(d->cpu_irq); |
69 |
} |
} |
70 |
void gc_lo_interrupt_assert(struct interrupt *interrupt) |
void openpic_lo_interrupt_assert(struct interrupt *interrupt) |
71 |
{ |
{ |
72 |
struct gc_data *d = interrupt->extra; |
struct openpic_data *d = interrupt->extra; |
73 |
d->status_lo |= interrupt->line; |
d->status_lo |= interrupt->line; |
74 |
if (d->status_lo & d->enable_lo || d->status_hi & d->enable_hi) |
if (d->status_lo & d->enable_lo || d->status_hi & d->enable_hi) |
75 |
INTERRUPT_ASSERT(d->cpu_irq); |
INTERRUPT_ASSERT(d->cpu_irq); |
76 |
} |
} |
77 |
void gc_lo_interrupt_deassert(struct interrupt *interrupt) |
void openpic_lo_interrupt_deassert(struct interrupt *interrupt) |
78 |
{ |
{ |
79 |
struct gc_data *d = interrupt->extra; |
struct openpic_data *d = interrupt->extra; |
80 |
d->status_lo &= ~interrupt->line; |
d->status_lo &= ~interrupt->line; |
81 |
if (!(d->status_lo & d->enable_lo || d->status_hi & d->enable_hi)) |
if (!(d->status_lo & d->enable_lo || d->status_hi & d->enable_hi)) |
82 |
INTERRUPT_DEASSERT(d->cpu_irq); |
INTERRUPT_DEASSERT(d->cpu_irq); |
83 |
} |
} |
84 |
|
|
85 |
|
|
86 |
DEVICE_ACCESS(gc) |
DEVICE_ACCESS(openpic) |
87 |
{ |
{ |
88 |
struct gc_data *d = extra; |
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) |
192 |
break; |
break; |
193 |
|
|
194 |
default:if (writeflag == MEM_WRITE) { |
default:if (writeflag == MEM_WRITE) { |
195 |
fatal("[ gc: unimplemented write to " |
fatal("[ openpic: unimplemented write to " |
196 |
"offset 0x%x: data=0x%x ]\n", (int) |
"offset 0x%x: data=0x%x ]\n", (int) |
197 |
relative_addr, (int)idata); |
relative_addr, (int)idata); |
198 |
} else { |
} else { |
199 |
fatal("[ gc: unimplemented read from " |
fatal("[ openpic: unimplemented read from " |
200 |
"offset 0x%x ]\n", (int)relative_addr); |
"offset 0x%x ]\n", (int)relative_addr); |
201 |
} |
} |
202 |
} |
} |
208 |
} |
} |
209 |
|
|
210 |
|
|
211 |
DEVINIT(gc) |
DEVINIT(openpic) |
212 |
{ |
{ |
213 |
struct gc_data *d; |
struct openpic_data *d; |
214 |
int i; |
int i; |
215 |
|
|
216 |
CHECK_ALLOCATION(d = malloc(sizeof(struct gc_data))); |
CHECK_ALLOCATION(d = malloc(sizeof(struct openpic_data))); |
217 |
memset(d, 0, sizeof(struct gc_data)); |
memset(d, 0, sizeof(struct openpic_data)); |
218 |
|
|
219 |
/* Connect to the CPU interrupt pin: */ |
/* Connect to the CPU interrupt pin: */ |
220 |
INTERRUPT_CONNECT(devinit->interrupt_path, d->cpu_irq); |
INTERRUPT_CONNECT(devinit->interrupt_path, d->cpu_irq); |
225 |
for (i=0; i<32; i++) { |
for (i=0; i<32; i++) { |
226 |
struct interrupt template; |
struct interrupt template; |
227 |
char n[300]; |
char n[300]; |
228 |
snprintf(n, sizeof(n), "%s.gc.lo.%i", |
snprintf(n, sizeof(n), "%s.openpic.lo.%i", |
229 |
devinit->interrupt_path, i); |
devinit->interrupt_path, i); |
230 |
memset(&template, 0, sizeof(template)); |
memset(&template, 0, sizeof(template)); |
231 |
template.line = 1 << i; |
template.line = 1 << i; |
232 |
template.name = n; |
template.name = n; |
233 |
template.extra = d; |
template.extra = d; |
234 |
template.interrupt_assert = gc_lo_interrupt_assert; |
template.interrupt_assert = openpic_lo_interrupt_assert; |
235 |
template.interrupt_deassert = gc_lo_interrupt_deassert; |
template.interrupt_deassert = openpic_lo_interrupt_deassert; |
236 |
interrupt_handler_register(&template); |
interrupt_handler_register(&template); |
237 |
|
|
238 |
snprintf(n, sizeof(n), "%s.gc.hi.%i", |
snprintf(n, sizeof(n), "%s.openpic.hi.%i", |
239 |
devinit->interrupt_path, i); |
devinit->interrupt_path, i); |
240 |
memset(&template, 0, sizeof(template)); |
memset(&template, 0, sizeof(template)); |
241 |
template.line = 1 << i; |
template.line = 1 << i; |
242 |
template.name = n; |
template.name = n; |
243 |
template.extra = d; |
template.extra = d; |
244 |
template.interrupt_assert = gc_hi_interrupt_assert; |
template.interrupt_assert = openpic_hi_interrupt_assert; |
245 |
template.interrupt_deassert = gc_hi_interrupt_deassert; |
template.interrupt_deassert = openpic_hi_interrupt_deassert; |
246 |
interrupt_handler_register(&template); |
interrupt_handler_register(&template); |
247 |
} |
} |
248 |
|
|
249 |
memory_device_register(devinit->machine->memory, "gc", |
memory_device_register(devinit->machine->memory, "openpic", |
250 |
devinit->addr, DEV_GC_LENGTH, dev_gc_access, d, DM_DEFAULT, NULL); |
devinit->addr, DEV_OPENPIC_LENGTH, dev_openpic_access, d, DM_DEFAULT, NULL); |
251 |
|
|
252 |
return 1; |
return 1; |
253 |
} |
} |