1 |
/* |
2 |
* Copyright (C) 2003-2007 Anders Gavare. All rights reserved. |
3 |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
6 |
* |
7 |
* 1. Redistributions of source code must retain the above copyright |
8 |
* notice, this list of conditions and the following disclaimer. |
9 |
* 2. Redistributions in binary form must reproduce the above copyright |
10 |
* notice, this list of conditions and the following disclaimer in the |
11 |
* documentation and/or other materials provided with the distribution. |
12 |
* 3. The name of the author may not be used to endorse or promote products |
13 |
* derived from this software without specific prior written permission. |
14 |
* |
15 |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
16 |
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 |
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
19 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
20 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
21 |
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
22 |
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
23 |
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
24 |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
25 |
* SUCH DAMAGE. |
26 |
* |
27 |
* |
28 |
* $Id: dev_kn230.c,v 1.19 2007/06/15 19:11:15 debug Exp $ |
29 |
* |
30 |
* COMMENT: DEC KN230 (MIPSMATE 5100) stuff |
31 |
*/ |
32 |
|
33 |
#include <stdio.h> |
34 |
#include <stdlib.h> |
35 |
#include <string.h> |
36 |
|
37 |
#include "device.h" |
38 |
#include "interrupt.h" |
39 |
#include "machine.h" |
40 |
#include "memory.h" |
41 |
#include "misc.h" |
42 |
|
43 |
#include "dec_5100.h" |
44 |
|
45 |
|
46 |
#define DEV_KN230_LENGTH 0x1c00000 |
47 |
|
48 |
struct kn230_data { |
49 |
struct interrupt mips_irq_2; |
50 |
struct interrupt mips_irq_3; |
51 |
|
52 |
uint32_t csr; |
53 |
}; |
54 |
|
55 |
|
56 |
/* |
57 |
* kn230_interrupt_assert(): |
58 |
* kn230_interrupt_deassert(): |
59 |
* |
60 |
* Called whenever a KN230 interrupt is asserted/deasserted. |
61 |
*/ |
62 |
void kn230_interrupt_assert(struct interrupt *interrupt) |
63 |
{ |
64 |
struct kn230_data *d = interrupt->extra; |
65 |
int assert2 = 0, assert3 = 0; |
66 |
|
67 |
d->csr |= interrupt->line; |
68 |
if (d->csr & (KN230_CSR_INTR_SII | KN230_CSR_INTR_LANCE)) |
69 |
assert3 = 1; |
70 |
if (d->csr & (KN230_CSR_INTR_DZ0 | |
71 |
KN230_CSR_INTR_OPT0 | KN230_CSR_INTR_OPT1)) |
72 |
assert2 = 1; |
73 |
|
74 |
if (assert2) |
75 |
INTERRUPT_ASSERT(d->mips_irq_2); |
76 |
if (assert3) |
77 |
INTERRUPT_ASSERT(d->mips_irq_2); |
78 |
} |
79 |
void kn230_interrupt_deassert(struct interrupt *interrupt) |
80 |
{ |
81 |
struct kn230_data *d = interrupt->extra; |
82 |
int assert2 = 0, assert3 = 0; |
83 |
|
84 |
d->csr &= ~interrupt->line; |
85 |
if (d->csr & (KN230_CSR_INTR_SII | KN230_CSR_INTR_LANCE)) |
86 |
assert3 = 1; |
87 |
if (d->csr & (KN230_CSR_INTR_DZ0 | |
88 |
KN230_CSR_INTR_OPT0 | KN230_CSR_INTR_OPT1)) |
89 |
assert2 = 1; |
90 |
|
91 |
if (!assert2) |
92 |
INTERRUPT_DEASSERT(d->mips_irq_2); |
93 |
if (!assert3) |
94 |
INTERRUPT_DEASSERT(d->mips_irq_2); |
95 |
} |
96 |
|
97 |
|
98 |
DEVICE_ACCESS(kn230) |
99 |
{ |
100 |
struct kn230_data *d = extra; |
101 |
uint64_t idata = 0, odata = 0; |
102 |
|
103 |
if (writeflag == MEM_WRITE) |
104 |
idata = memory_readmax64(cpu, data, len); |
105 |
|
106 |
switch (relative_addr) { |
107 |
case 0: |
108 |
if (writeflag==MEM_READ) { |
109 |
odata = d->csr; |
110 |
/* debug("[ kn230: read from CSR: 0x%08x ]\n", |
111 |
(int)odata); */ |
112 |
} else { |
113 |
/* debug("[ kn230: write to CSR: 0x%08x ]\n", |
114 |
(int)idata); */ |
115 |
} |
116 |
break; |
117 |
default: |
118 |
if (writeflag==MEM_READ) { |
119 |
debug("[ kn230: read from 0x%08lx ]\n", |
120 |
(long)relative_addr); |
121 |
} else { |
122 |
debug("[ kn230: write to 0x%08lx: 0x%08x ]\n", |
123 |
(long)relative_addr, (int)idata); |
124 |
} |
125 |
} |
126 |
|
127 |
if (writeflag == MEM_READ) |
128 |
memory_writemax64(cpu, data, len, odata); |
129 |
|
130 |
return 1; |
131 |
} |
132 |
|
133 |
|
134 |
DEVINIT(kn230) |
135 |
{ |
136 |
struct kn230_data *d; |
137 |
char tmpstr[300]; |
138 |
int i; |
139 |
|
140 |
CHECK_ALLOCATION(d = malloc(sizeof(struct kn230_data))); |
141 |
memset(d, 0, sizeof(struct kn230_data)); |
142 |
|
143 |
/* |
144 |
* devinit->interrupt_path points to the MIPS cpu itself. |
145 |
* The KN230 interrupt controller interrupts at MIPS interrupts |
146 |
* 2 and 3, depending on which KN230 is asserted. |
147 |
*/ |
148 |
snprintf(tmpstr, sizeof(tmpstr), "%s.2", devinit->interrupt_path); |
149 |
INTERRUPT_CONNECT(tmpstr, d->mips_irq_2); |
150 |
snprintf(tmpstr, sizeof(tmpstr), "%s.3", devinit->interrupt_path); |
151 |
INTERRUPT_CONNECT(tmpstr, d->mips_irq_3); |
152 |
|
153 |
/* Register KN230 interrupts 8..15: */ |
154 |
for (i=8; i<=15; i++) { |
155 |
struct interrupt template; |
156 |
char tmpstr[300]; |
157 |
snprintf(tmpstr, sizeof(tmpstr), "%s.kn230.0x%x", |
158 |
devinit->interrupt_path, 1 << i); |
159 |
memset(&template, 0, sizeof(template)); |
160 |
template.line = 1 << i; |
161 |
template.name = tmpstr; |
162 |
template.extra = d; |
163 |
template.interrupt_assert = kn230_interrupt_assert; |
164 |
template.interrupt_deassert = kn230_interrupt_deassert; |
165 |
interrupt_handler_register(&template); |
166 |
} |
167 |
|
168 |
memory_device_register(devinit->machine->memory, devinit->name, |
169 |
devinit->addr, DEV_KN230_LENGTH, dev_kn230_access, d, |
170 |
DM_DEFAULT, NULL); |
171 |
|
172 |
devinit->return_ptr = d; |
173 |
|
174 |
return 1; |
175 |
} |
176 |
|