root / hw / ppc405_uc.c @ c75a823c
History | View | Annotate | Download (78.1 kB)
1 | 8ecc7913 | j_mayer | /*
|
---|---|---|---|
2 | 8ecc7913 | j_mayer | * QEMU PowerPC 405 embedded processors emulation
|
3 | 5fafdf24 | ths | *
|
4 | 8ecc7913 | j_mayer | * Copyright (c) 2007 Jocelyn Mayer
|
5 | 5fafdf24 | ths | *
|
6 | 8ecc7913 | j_mayer | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 8ecc7913 | j_mayer | * of this software and associated documentation files (the "Software"), to deal
|
8 | 8ecc7913 | j_mayer | * in the Software without restriction, including without limitation the rights
|
9 | 8ecc7913 | j_mayer | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 8ecc7913 | j_mayer | * copies of the Software, and to permit persons to whom the Software is
|
11 | 8ecc7913 | j_mayer | * furnished to do so, subject to the following conditions:
|
12 | 8ecc7913 | j_mayer | *
|
13 | 8ecc7913 | j_mayer | * The above copyright notice and this permission notice shall be included in
|
14 | 8ecc7913 | j_mayer | * all copies or substantial portions of the Software.
|
15 | 8ecc7913 | j_mayer | *
|
16 | 8ecc7913 | j_mayer | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 8ecc7913 | j_mayer | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 8ecc7913 | j_mayer | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 8ecc7913 | j_mayer | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 8ecc7913 | j_mayer | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 8ecc7913 | j_mayer | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 8ecc7913 | j_mayer | * THE SOFTWARE.
|
23 | 8ecc7913 | j_mayer | */
|
24 | 87ecb68b | pbrook | #include "hw.h" |
25 | 87ecb68b | pbrook | #include "ppc.h" |
26 | 04f20795 | j_mayer | #include "ppc405.h" |
27 | 87ecb68b | pbrook | #include "pc.h" |
28 | 87ecb68b | pbrook | #include "qemu-timer.h" |
29 | 87ecb68b | pbrook | #include "sysemu.h" |
30 | 8ecc7913 | j_mayer | |
31 | 8ecc7913 | j_mayer | extern int loglevel; |
32 | 8ecc7913 | j_mayer | extern FILE *logfile;
|
33 | 8ecc7913 | j_mayer | |
34 | 8ecc7913 | j_mayer | #define DEBUG_OPBA
|
35 | 8ecc7913 | j_mayer | #define DEBUG_SDRAM
|
36 | 8ecc7913 | j_mayer | #define DEBUG_GPIO
|
37 | 8ecc7913 | j_mayer | #define DEBUG_SERIAL
|
38 | 8ecc7913 | j_mayer | #define DEBUG_OCM
|
39 | 9c02f1a2 | j_mayer | //#define DEBUG_I2C
|
40 | 9c02f1a2 | j_mayer | #define DEBUG_GPT
|
41 | 9c02f1a2 | j_mayer | #define DEBUG_MAL
|
42 | 8ecc7913 | j_mayer | #define DEBUG_CLOCKS
|
43 | aae9366a | j_mayer | //#define DEBUG_CLOCKS_LL
|
44 | 8ecc7913 | j_mayer | |
45 | b8d3f5d1 | j_mayer | ram_addr_t ppc405_set_bootinfo (CPUState *env, ppc4xx_bd_info_t *bd, |
46 | b8d3f5d1 | j_mayer | uint32_t flags) |
47 | 04f20795 | j_mayer | { |
48 | 04f20795 | j_mayer | ram_addr_t bdloc; |
49 | 04f20795 | j_mayer | int i, n;
|
50 | 04f20795 | j_mayer | |
51 | 04f20795 | j_mayer | /* We put the bd structure at the top of memory */
|
52 | be58fc7c | j_mayer | if (bd->bi_memsize >= 0x01000000UL) |
53 | be58fc7c | j_mayer | bdloc = 0x01000000UL - sizeof(struct ppc4xx_bd_info_t); |
54 | be58fc7c | j_mayer | else
|
55 | be58fc7c | j_mayer | bdloc = bd->bi_memsize - sizeof(struct ppc4xx_bd_info_t); |
56 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x00, bd->bi_memstart);
|
57 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x04, bd->bi_memsize);
|
58 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x08, bd->bi_flashstart);
|
59 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x0C, bd->bi_flashsize);
|
60 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x10, bd->bi_flashoffset);
|
61 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x14, bd->bi_sramstart);
|
62 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x18, bd->bi_sramsize);
|
63 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x1C, bd->bi_bootflags);
|
64 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x20, bd->bi_ipaddr);
|
65 | 04f20795 | j_mayer | for (i = 0; i < 6; i++) |
66 | 04f20795 | j_mayer | stb_raw(phys_ram_base + bdloc + 0x24 + i, bd->bi_enetaddr[i]);
|
67 | 04f20795 | j_mayer | stw_raw(phys_ram_base + bdloc + 0x2A, bd->bi_ethspeed);
|
68 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x2C, bd->bi_intfreq);
|
69 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x30, bd->bi_busfreq);
|
70 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x34, bd->bi_baudrate);
|
71 | 04f20795 | j_mayer | for (i = 0; i < 4; i++) |
72 | 04f20795 | j_mayer | stb_raw(phys_ram_base + bdloc + 0x38 + i, bd->bi_s_version[i]);
|
73 | 04f20795 | j_mayer | for (i = 0; i < 32; i++) |
74 | 04f20795 | j_mayer | stb_raw(phys_ram_base + bdloc + 0x3C + i, bd->bi_s_version[i]);
|
75 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x5C, bd->bi_plb_busfreq);
|
76 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + 0x60, bd->bi_pci_busfreq);
|
77 | 04f20795 | j_mayer | for (i = 0; i < 6; i++) |
78 | 04f20795 | j_mayer | stb_raw(phys_ram_base + bdloc + 0x64 + i, bd->bi_pci_enetaddr[i]);
|
79 | 04f20795 | j_mayer | n = 0x6A;
|
80 | b8d3f5d1 | j_mayer | if (flags & 0x00000001) { |
81 | 04f20795 | j_mayer | for (i = 0; i < 6; i++) |
82 | 04f20795 | j_mayer | stb_raw(phys_ram_base + bdloc + n++, bd->bi_pci_enetaddr2[i]); |
83 | 04f20795 | j_mayer | } |
84 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + n, bd->bi_opbfreq); |
85 | 04f20795 | j_mayer | n += 4;
|
86 | 04f20795 | j_mayer | for (i = 0; i < 2; i++) { |
87 | 04f20795 | j_mayer | stl_raw(phys_ram_base + bdloc + n, bd->bi_iic_fast[i]); |
88 | 04f20795 | j_mayer | n += 4;
|
89 | 04f20795 | j_mayer | } |
90 | 04f20795 | j_mayer | |
91 | 04f20795 | j_mayer | return bdloc;
|
92 | 04f20795 | j_mayer | } |
93 | 04f20795 | j_mayer | |
94 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
95 | 8ecc7913 | j_mayer | /* Shared peripherals */
|
96 | 8ecc7913 | j_mayer | |
97 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
98 | 8ecc7913 | j_mayer | /* Peripheral local bus arbitrer */
|
99 | 8ecc7913 | j_mayer | enum {
|
100 | 8ecc7913 | j_mayer | PLB0_BESR = 0x084,
|
101 | 8ecc7913 | j_mayer | PLB0_BEAR = 0x086,
|
102 | 8ecc7913 | j_mayer | PLB0_ACR = 0x087,
|
103 | 8ecc7913 | j_mayer | }; |
104 | 8ecc7913 | j_mayer | |
105 | 8ecc7913 | j_mayer | typedef struct ppc4xx_plb_t ppc4xx_plb_t; |
106 | 8ecc7913 | j_mayer | struct ppc4xx_plb_t {
|
107 | 8ecc7913 | j_mayer | uint32_t acr; |
108 | 8ecc7913 | j_mayer | uint32_t bear; |
109 | 8ecc7913 | j_mayer | uint32_t besr; |
110 | 8ecc7913 | j_mayer | }; |
111 | 8ecc7913 | j_mayer | |
112 | 8ecc7913 | j_mayer | static target_ulong dcr_read_plb (void *opaque, int dcrn) |
113 | 8ecc7913 | j_mayer | { |
114 | 8ecc7913 | j_mayer | ppc4xx_plb_t *plb; |
115 | 8ecc7913 | j_mayer | target_ulong ret; |
116 | 8ecc7913 | j_mayer | |
117 | 8ecc7913 | j_mayer | plb = opaque; |
118 | 8ecc7913 | j_mayer | switch (dcrn) {
|
119 | 8ecc7913 | j_mayer | case PLB0_ACR:
|
120 | 8ecc7913 | j_mayer | ret = plb->acr; |
121 | 8ecc7913 | j_mayer | break;
|
122 | 8ecc7913 | j_mayer | case PLB0_BEAR:
|
123 | 8ecc7913 | j_mayer | ret = plb->bear; |
124 | 8ecc7913 | j_mayer | break;
|
125 | 8ecc7913 | j_mayer | case PLB0_BESR:
|
126 | 8ecc7913 | j_mayer | ret = plb->besr; |
127 | 8ecc7913 | j_mayer | break;
|
128 | 8ecc7913 | j_mayer | default:
|
129 | 8ecc7913 | j_mayer | /* Avoid gcc warning */
|
130 | 8ecc7913 | j_mayer | ret = 0;
|
131 | 8ecc7913 | j_mayer | break;
|
132 | 8ecc7913 | j_mayer | } |
133 | 8ecc7913 | j_mayer | |
134 | 8ecc7913 | j_mayer | return ret;
|
135 | 8ecc7913 | j_mayer | } |
136 | 8ecc7913 | j_mayer | |
137 | 8ecc7913 | j_mayer | static void dcr_write_plb (void *opaque, int dcrn, target_ulong val) |
138 | 8ecc7913 | j_mayer | { |
139 | 8ecc7913 | j_mayer | ppc4xx_plb_t *plb; |
140 | 8ecc7913 | j_mayer | |
141 | 8ecc7913 | j_mayer | plb = opaque; |
142 | 8ecc7913 | j_mayer | switch (dcrn) {
|
143 | 8ecc7913 | j_mayer | case PLB0_ACR:
|
144 | 9c02f1a2 | j_mayer | /* We don't care about the actual parameters written as
|
145 | 9c02f1a2 | j_mayer | * we don't manage any priorities on the bus
|
146 | 9c02f1a2 | j_mayer | */
|
147 | 9c02f1a2 | j_mayer | plb->acr = val & 0xF8000000;
|
148 | 8ecc7913 | j_mayer | break;
|
149 | 8ecc7913 | j_mayer | case PLB0_BEAR:
|
150 | 8ecc7913 | j_mayer | /* Read only */
|
151 | 8ecc7913 | j_mayer | break;
|
152 | 8ecc7913 | j_mayer | case PLB0_BESR:
|
153 | 8ecc7913 | j_mayer | /* Write-clear */
|
154 | 8ecc7913 | j_mayer | plb->besr &= ~val; |
155 | 8ecc7913 | j_mayer | break;
|
156 | 8ecc7913 | j_mayer | } |
157 | 8ecc7913 | j_mayer | } |
158 | 8ecc7913 | j_mayer | |
159 | 8ecc7913 | j_mayer | static void ppc4xx_plb_reset (void *opaque) |
160 | 8ecc7913 | j_mayer | { |
161 | 8ecc7913 | j_mayer | ppc4xx_plb_t *plb; |
162 | 8ecc7913 | j_mayer | |
163 | 8ecc7913 | j_mayer | plb = opaque; |
164 | 8ecc7913 | j_mayer | plb->acr = 0x00000000;
|
165 | 8ecc7913 | j_mayer | plb->bear = 0x00000000;
|
166 | 8ecc7913 | j_mayer | plb->besr = 0x00000000;
|
167 | 8ecc7913 | j_mayer | } |
168 | 8ecc7913 | j_mayer | |
169 | 8ecc7913 | j_mayer | void ppc4xx_plb_init (CPUState *env)
|
170 | 8ecc7913 | j_mayer | { |
171 | 8ecc7913 | j_mayer | ppc4xx_plb_t *plb; |
172 | 8ecc7913 | j_mayer | |
173 | 8ecc7913 | j_mayer | plb = qemu_mallocz(sizeof(ppc4xx_plb_t));
|
174 | 8ecc7913 | j_mayer | if (plb != NULL) { |
175 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PLB0_ACR, plb, &dcr_read_plb, &dcr_write_plb); |
176 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PLB0_BEAR, plb, &dcr_read_plb, &dcr_write_plb); |
177 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PLB0_BESR, plb, &dcr_read_plb, &dcr_write_plb); |
178 | 8ecc7913 | j_mayer | ppc4xx_plb_reset(plb); |
179 | 8ecc7913 | j_mayer | qemu_register_reset(ppc4xx_plb_reset, plb); |
180 | 8ecc7913 | j_mayer | } |
181 | 8ecc7913 | j_mayer | } |
182 | 8ecc7913 | j_mayer | |
183 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
184 | 8ecc7913 | j_mayer | /* PLB to OPB bridge */
|
185 | 8ecc7913 | j_mayer | enum {
|
186 | 8ecc7913 | j_mayer | POB0_BESR0 = 0x0A0,
|
187 | 8ecc7913 | j_mayer | POB0_BESR1 = 0x0A2,
|
188 | 8ecc7913 | j_mayer | POB0_BEAR = 0x0A4,
|
189 | 8ecc7913 | j_mayer | }; |
190 | 8ecc7913 | j_mayer | |
191 | 8ecc7913 | j_mayer | typedef struct ppc4xx_pob_t ppc4xx_pob_t; |
192 | 8ecc7913 | j_mayer | struct ppc4xx_pob_t {
|
193 | 8ecc7913 | j_mayer | uint32_t bear; |
194 | 8ecc7913 | j_mayer | uint32_t besr[2];
|
195 | 8ecc7913 | j_mayer | }; |
196 | 8ecc7913 | j_mayer | |
197 | 8ecc7913 | j_mayer | static target_ulong dcr_read_pob (void *opaque, int dcrn) |
198 | 8ecc7913 | j_mayer | { |
199 | 8ecc7913 | j_mayer | ppc4xx_pob_t *pob; |
200 | 8ecc7913 | j_mayer | target_ulong ret; |
201 | 8ecc7913 | j_mayer | |
202 | 8ecc7913 | j_mayer | pob = opaque; |
203 | 8ecc7913 | j_mayer | switch (dcrn) {
|
204 | 8ecc7913 | j_mayer | case POB0_BEAR:
|
205 | 8ecc7913 | j_mayer | ret = pob->bear; |
206 | 8ecc7913 | j_mayer | break;
|
207 | 8ecc7913 | j_mayer | case POB0_BESR0:
|
208 | 8ecc7913 | j_mayer | case POB0_BESR1:
|
209 | 8ecc7913 | j_mayer | ret = pob->besr[dcrn - POB0_BESR0]; |
210 | 8ecc7913 | j_mayer | break;
|
211 | 8ecc7913 | j_mayer | default:
|
212 | 8ecc7913 | j_mayer | /* Avoid gcc warning */
|
213 | 8ecc7913 | j_mayer | ret = 0;
|
214 | 8ecc7913 | j_mayer | break;
|
215 | 8ecc7913 | j_mayer | } |
216 | 8ecc7913 | j_mayer | |
217 | 8ecc7913 | j_mayer | return ret;
|
218 | 8ecc7913 | j_mayer | } |
219 | 8ecc7913 | j_mayer | |
220 | 8ecc7913 | j_mayer | static void dcr_write_pob (void *opaque, int dcrn, target_ulong val) |
221 | 8ecc7913 | j_mayer | { |
222 | 8ecc7913 | j_mayer | ppc4xx_pob_t *pob; |
223 | 8ecc7913 | j_mayer | |
224 | 8ecc7913 | j_mayer | pob = opaque; |
225 | 8ecc7913 | j_mayer | switch (dcrn) {
|
226 | 8ecc7913 | j_mayer | case POB0_BEAR:
|
227 | 8ecc7913 | j_mayer | /* Read only */
|
228 | 8ecc7913 | j_mayer | break;
|
229 | 8ecc7913 | j_mayer | case POB0_BESR0:
|
230 | 8ecc7913 | j_mayer | case POB0_BESR1:
|
231 | 8ecc7913 | j_mayer | /* Write-clear */
|
232 | 8ecc7913 | j_mayer | pob->besr[dcrn - POB0_BESR0] &= ~val; |
233 | 8ecc7913 | j_mayer | break;
|
234 | 8ecc7913 | j_mayer | } |
235 | 8ecc7913 | j_mayer | } |
236 | 8ecc7913 | j_mayer | |
237 | 8ecc7913 | j_mayer | static void ppc4xx_pob_reset (void *opaque) |
238 | 8ecc7913 | j_mayer | { |
239 | 8ecc7913 | j_mayer | ppc4xx_pob_t *pob; |
240 | 8ecc7913 | j_mayer | |
241 | 8ecc7913 | j_mayer | pob = opaque; |
242 | 8ecc7913 | j_mayer | /* No error */
|
243 | 8ecc7913 | j_mayer | pob->bear = 0x00000000;
|
244 | 8ecc7913 | j_mayer | pob->besr[0] = 0x0000000; |
245 | 8ecc7913 | j_mayer | pob->besr[1] = 0x0000000; |
246 | 8ecc7913 | j_mayer | } |
247 | 8ecc7913 | j_mayer | |
248 | 8ecc7913 | j_mayer | void ppc4xx_pob_init (CPUState *env)
|
249 | 8ecc7913 | j_mayer | { |
250 | 8ecc7913 | j_mayer | ppc4xx_pob_t *pob; |
251 | 8ecc7913 | j_mayer | |
252 | 8ecc7913 | j_mayer | pob = qemu_mallocz(sizeof(ppc4xx_pob_t));
|
253 | 8ecc7913 | j_mayer | if (pob != NULL) { |
254 | 8ecc7913 | j_mayer | ppc_dcr_register(env, POB0_BEAR, pob, &dcr_read_pob, &dcr_write_pob); |
255 | 8ecc7913 | j_mayer | ppc_dcr_register(env, POB0_BESR0, pob, &dcr_read_pob, &dcr_write_pob); |
256 | 8ecc7913 | j_mayer | ppc_dcr_register(env, POB0_BESR1, pob, &dcr_read_pob, &dcr_write_pob); |
257 | 8ecc7913 | j_mayer | qemu_register_reset(ppc4xx_pob_reset, pob); |
258 | 8ecc7913 | j_mayer | ppc4xx_pob_reset(env); |
259 | 8ecc7913 | j_mayer | } |
260 | 8ecc7913 | j_mayer | } |
261 | 8ecc7913 | j_mayer | |
262 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
263 | 8ecc7913 | j_mayer | /* OPB arbitrer */
|
264 | 8ecc7913 | j_mayer | typedef struct ppc4xx_opba_t ppc4xx_opba_t; |
265 | 8ecc7913 | j_mayer | struct ppc4xx_opba_t {
|
266 | 9c02f1a2 | j_mayer | target_phys_addr_t base; |
267 | 8ecc7913 | j_mayer | uint8_t cr; |
268 | 8ecc7913 | j_mayer | uint8_t pr; |
269 | 8ecc7913 | j_mayer | }; |
270 | 8ecc7913 | j_mayer | |
271 | 8ecc7913 | j_mayer | static uint32_t opba_readb (void *opaque, target_phys_addr_t addr) |
272 | 8ecc7913 | j_mayer | { |
273 | 8ecc7913 | j_mayer | ppc4xx_opba_t *opba; |
274 | 8ecc7913 | j_mayer | uint32_t ret; |
275 | 8ecc7913 | j_mayer | |
276 | 8ecc7913 | j_mayer | #ifdef DEBUG_OPBA
|
277 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
278 | 8ecc7913 | j_mayer | #endif
|
279 | 8ecc7913 | j_mayer | opba = opaque; |
280 | 8ecc7913 | j_mayer | switch (addr - opba->base) {
|
281 | 8ecc7913 | j_mayer | case 0x00: |
282 | 8ecc7913 | j_mayer | ret = opba->cr; |
283 | 8ecc7913 | j_mayer | break;
|
284 | 8ecc7913 | j_mayer | case 0x01: |
285 | 8ecc7913 | j_mayer | ret = opba->pr; |
286 | 8ecc7913 | j_mayer | break;
|
287 | 8ecc7913 | j_mayer | default:
|
288 | 8ecc7913 | j_mayer | ret = 0x00;
|
289 | 8ecc7913 | j_mayer | break;
|
290 | 8ecc7913 | j_mayer | } |
291 | 8ecc7913 | j_mayer | |
292 | 8ecc7913 | j_mayer | return ret;
|
293 | 8ecc7913 | j_mayer | } |
294 | 8ecc7913 | j_mayer | |
295 | 8ecc7913 | j_mayer | static void opba_writeb (void *opaque, |
296 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
297 | 8ecc7913 | j_mayer | { |
298 | 8ecc7913 | j_mayer | ppc4xx_opba_t *opba; |
299 | 8ecc7913 | j_mayer | |
300 | 8ecc7913 | j_mayer | #ifdef DEBUG_OPBA
|
301 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
302 | 8ecc7913 | j_mayer | #endif
|
303 | 8ecc7913 | j_mayer | opba = opaque; |
304 | 8ecc7913 | j_mayer | switch (addr - opba->base) {
|
305 | 8ecc7913 | j_mayer | case 0x00: |
306 | 8ecc7913 | j_mayer | opba->cr = value & 0xF8;
|
307 | 8ecc7913 | j_mayer | break;
|
308 | 8ecc7913 | j_mayer | case 0x01: |
309 | 8ecc7913 | j_mayer | opba->pr = value & 0xFF;
|
310 | 8ecc7913 | j_mayer | break;
|
311 | 8ecc7913 | j_mayer | default:
|
312 | 8ecc7913 | j_mayer | break;
|
313 | 8ecc7913 | j_mayer | } |
314 | 8ecc7913 | j_mayer | } |
315 | 8ecc7913 | j_mayer | |
316 | 8ecc7913 | j_mayer | static uint32_t opba_readw (void *opaque, target_phys_addr_t addr) |
317 | 8ecc7913 | j_mayer | { |
318 | 8ecc7913 | j_mayer | uint32_t ret; |
319 | 8ecc7913 | j_mayer | |
320 | 8ecc7913 | j_mayer | #ifdef DEBUG_OPBA
|
321 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
322 | 8ecc7913 | j_mayer | #endif
|
323 | 8ecc7913 | j_mayer | ret = opba_readb(opaque, addr) << 8;
|
324 | 8ecc7913 | j_mayer | ret |= opba_readb(opaque, addr + 1);
|
325 | 8ecc7913 | j_mayer | |
326 | 8ecc7913 | j_mayer | return ret;
|
327 | 8ecc7913 | j_mayer | } |
328 | 8ecc7913 | j_mayer | |
329 | 8ecc7913 | j_mayer | static void opba_writew (void *opaque, |
330 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
331 | 8ecc7913 | j_mayer | { |
332 | 8ecc7913 | j_mayer | #ifdef DEBUG_OPBA
|
333 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
334 | 8ecc7913 | j_mayer | #endif
|
335 | 8ecc7913 | j_mayer | opba_writeb(opaque, addr, value >> 8);
|
336 | 8ecc7913 | j_mayer | opba_writeb(opaque, addr + 1, value);
|
337 | 8ecc7913 | j_mayer | } |
338 | 8ecc7913 | j_mayer | |
339 | 8ecc7913 | j_mayer | static uint32_t opba_readl (void *opaque, target_phys_addr_t addr) |
340 | 8ecc7913 | j_mayer | { |
341 | 8ecc7913 | j_mayer | uint32_t ret; |
342 | 8ecc7913 | j_mayer | |
343 | 8ecc7913 | j_mayer | #ifdef DEBUG_OPBA
|
344 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
345 | 8ecc7913 | j_mayer | #endif
|
346 | 8ecc7913 | j_mayer | ret = opba_readb(opaque, addr) << 24;
|
347 | 8ecc7913 | j_mayer | ret |= opba_readb(opaque, addr + 1) << 16; |
348 | 8ecc7913 | j_mayer | |
349 | 8ecc7913 | j_mayer | return ret;
|
350 | 8ecc7913 | j_mayer | } |
351 | 8ecc7913 | j_mayer | |
352 | 8ecc7913 | j_mayer | static void opba_writel (void *opaque, |
353 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
354 | 8ecc7913 | j_mayer | { |
355 | 8ecc7913 | j_mayer | #ifdef DEBUG_OPBA
|
356 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
357 | 8ecc7913 | j_mayer | #endif
|
358 | 8ecc7913 | j_mayer | opba_writeb(opaque, addr, value >> 24);
|
359 | 8ecc7913 | j_mayer | opba_writeb(opaque, addr + 1, value >> 16); |
360 | 8ecc7913 | j_mayer | } |
361 | 8ecc7913 | j_mayer | |
362 | 8ecc7913 | j_mayer | static CPUReadMemoryFunc *opba_read[] = {
|
363 | 8ecc7913 | j_mayer | &opba_readb, |
364 | 8ecc7913 | j_mayer | &opba_readw, |
365 | 8ecc7913 | j_mayer | &opba_readl, |
366 | 8ecc7913 | j_mayer | }; |
367 | 8ecc7913 | j_mayer | |
368 | 8ecc7913 | j_mayer | static CPUWriteMemoryFunc *opba_write[] = {
|
369 | 8ecc7913 | j_mayer | &opba_writeb, |
370 | 8ecc7913 | j_mayer | &opba_writew, |
371 | 8ecc7913 | j_mayer | &opba_writel, |
372 | 8ecc7913 | j_mayer | }; |
373 | 8ecc7913 | j_mayer | |
374 | 8ecc7913 | j_mayer | static void ppc4xx_opba_reset (void *opaque) |
375 | 8ecc7913 | j_mayer | { |
376 | 8ecc7913 | j_mayer | ppc4xx_opba_t *opba; |
377 | 8ecc7913 | j_mayer | |
378 | 8ecc7913 | j_mayer | opba = opaque; |
379 | 8ecc7913 | j_mayer | opba->cr = 0x00; /* No dynamic priorities - park disabled */ |
380 | 8ecc7913 | j_mayer | opba->pr = 0x11;
|
381 | 8ecc7913 | j_mayer | } |
382 | 8ecc7913 | j_mayer | |
383 | 9c02f1a2 | j_mayer | void ppc4xx_opba_init (CPUState *env, ppc4xx_mmio_t *mmio,
|
384 | 9c02f1a2 | j_mayer | target_phys_addr_t offset) |
385 | 8ecc7913 | j_mayer | { |
386 | 8ecc7913 | j_mayer | ppc4xx_opba_t *opba; |
387 | 8ecc7913 | j_mayer | |
388 | 8ecc7913 | j_mayer | opba = qemu_mallocz(sizeof(ppc4xx_opba_t));
|
389 | 8ecc7913 | j_mayer | if (opba != NULL) { |
390 | 9c02f1a2 | j_mayer | opba->base = offset; |
391 | 8ecc7913 | j_mayer | #ifdef DEBUG_OPBA
|
392 | aae9366a | j_mayer | printf("%s: offset " PADDRX "\n", __func__, offset); |
393 | 8ecc7913 | j_mayer | #endif
|
394 | 8ecc7913 | j_mayer | ppc4xx_mmio_register(env, mmio, offset, 0x002,
|
395 | 8ecc7913 | j_mayer | opba_read, opba_write, opba); |
396 | 8ecc7913 | j_mayer | qemu_register_reset(ppc4xx_opba_reset, opba); |
397 | 8ecc7913 | j_mayer | ppc4xx_opba_reset(opba); |
398 | 8ecc7913 | j_mayer | } |
399 | 8ecc7913 | j_mayer | } |
400 | 8ecc7913 | j_mayer | |
401 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
402 | 8ecc7913 | j_mayer | /* Code decompression controller */
|
403 | 8ecc7913 | j_mayer | /* XXX: TODO */
|
404 | 8ecc7913 | j_mayer | |
405 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
406 | 8ecc7913 | j_mayer | /* SDRAM controller */
|
407 | 8ecc7913 | j_mayer | typedef struct ppc4xx_sdram_t ppc4xx_sdram_t; |
408 | 8ecc7913 | j_mayer | struct ppc4xx_sdram_t {
|
409 | 8ecc7913 | j_mayer | uint32_t addr; |
410 | 8ecc7913 | j_mayer | int nbanks;
|
411 | 71db710f | blueswir1 | target_phys_addr_t ram_bases[4];
|
412 | 71db710f | blueswir1 | target_phys_addr_t ram_sizes[4];
|
413 | 8ecc7913 | j_mayer | uint32_t besr0; |
414 | 8ecc7913 | j_mayer | uint32_t besr1; |
415 | 8ecc7913 | j_mayer | uint32_t bear; |
416 | 8ecc7913 | j_mayer | uint32_t cfg; |
417 | 8ecc7913 | j_mayer | uint32_t status; |
418 | 8ecc7913 | j_mayer | uint32_t rtr; |
419 | 8ecc7913 | j_mayer | uint32_t pmit; |
420 | 8ecc7913 | j_mayer | uint32_t bcr[4];
|
421 | 8ecc7913 | j_mayer | uint32_t tr; |
422 | 8ecc7913 | j_mayer | uint32_t ecccfg; |
423 | 8ecc7913 | j_mayer | uint32_t eccesr; |
424 | 8ecc7913 | j_mayer | qemu_irq irq; |
425 | 8ecc7913 | j_mayer | }; |
426 | 8ecc7913 | j_mayer | |
427 | 8ecc7913 | j_mayer | enum {
|
428 | 8ecc7913 | j_mayer | SDRAM0_CFGADDR = 0x010,
|
429 | 8ecc7913 | j_mayer | SDRAM0_CFGDATA = 0x011,
|
430 | 8ecc7913 | j_mayer | }; |
431 | 8ecc7913 | j_mayer | |
432 | aae9366a | j_mayer | /* XXX: TOFIX: some patches have made this code become inconsistent:
|
433 | aae9366a | j_mayer | * there are type inconsistencies, mixing target_phys_addr_t, target_ulong
|
434 | aae9366a | j_mayer | * and uint32_t
|
435 | aae9366a | j_mayer | */
|
436 | 36081602 | j_mayer | static uint32_t sdram_bcr (target_phys_addr_t ram_base,
|
437 | 36081602 | j_mayer | target_phys_addr_t ram_size) |
438 | 8ecc7913 | j_mayer | { |
439 | 8ecc7913 | j_mayer | uint32_t bcr; |
440 | 8ecc7913 | j_mayer | |
441 | 8ecc7913 | j_mayer | switch (ram_size) {
|
442 | 8ecc7913 | j_mayer | case (4 * 1024 * 1024): |
443 | 8ecc7913 | j_mayer | bcr = 0x00000000;
|
444 | 8ecc7913 | j_mayer | break;
|
445 | 8ecc7913 | j_mayer | case (8 * 1024 * 1024): |
446 | 8ecc7913 | j_mayer | bcr = 0x00020000;
|
447 | 8ecc7913 | j_mayer | break;
|
448 | 8ecc7913 | j_mayer | case (16 * 1024 * 1024): |
449 | 8ecc7913 | j_mayer | bcr = 0x00040000;
|
450 | 8ecc7913 | j_mayer | break;
|
451 | 8ecc7913 | j_mayer | case (32 * 1024 * 1024): |
452 | 8ecc7913 | j_mayer | bcr = 0x00060000;
|
453 | 8ecc7913 | j_mayer | break;
|
454 | 8ecc7913 | j_mayer | case (64 * 1024 * 1024): |
455 | 8ecc7913 | j_mayer | bcr = 0x00080000;
|
456 | 8ecc7913 | j_mayer | break;
|
457 | 8ecc7913 | j_mayer | case (128 * 1024 * 1024): |
458 | 8ecc7913 | j_mayer | bcr = 0x000A0000;
|
459 | 8ecc7913 | j_mayer | break;
|
460 | 8ecc7913 | j_mayer | case (256 * 1024 * 1024): |
461 | 8ecc7913 | j_mayer | bcr = 0x000C0000;
|
462 | 8ecc7913 | j_mayer | break;
|
463 | 8ecc7913 | j_mayer | default:
|
464 | aae9366a | j_mayer | printf("%s: invalid RAM size " PADDRX "\n", __func__, ram_size); |
465 | 8ecc7913 | j_mayer | return 0x00000000; |
466 | 8ecc7913 | j_mayer | } |
467 | 8ecc7913 | j_mayer | bcr |= ram_base & 0xFF800000;
|
468 | 8ecc7913 | j_mayer | bcr |= 1;
|
469 | 8ecc7913 | j_mayer | |
470 | 8ecc7913 | j_mayer | return bcr;
|
471 | 8ecc7913 | j_mayer | } |
472 | 8ecc7913 | j_mayer | |
473 | b068d6a7 | j_mayer | static always_inline target_phys_addr_t sdram_base (uint32_t bcr)
|
474 | 8ecc7913 | j_mayer | { |
475 | 8ecc7913 | j_mayer | return bcr & 0xFF800000; |
476 | 8ecc7913 | j_mayer | } |
477 | 8ecc7913 | j_mayer | |
478 | 8ecc7913 | j_mayer | static target_ulong sdram_size (uint32_t bcr)
|
479 | 8ecc7913 | j_mayer | { |
480 | 8ecc7913 | j_mayer | target_ulong size; |
481 | 8ecc7913 | j_mayer | int sh;
|
482 | 8ecc7913 | j_mayer | |
483 | 8ecc7913 | j_mayer | sh = (bcr >> 17) & 0x7; |
484 | 8ecc7913 | j_mayer | if (sh == 7) |
485 | 8ecc7913 | j_mayer | size = -1;
|
486 | 8ecc7913 | j_mayer | else
|
487 | 8ecc7913 | j_mayer | size = (4 * 1024 * 1024) << sh; |
488 | 8ecc7913 | j_mayer | |
489 | 8ecc7913 | j_mayer | return size;
|
490 | 8ecc7913 | j_mayer | } |
491 | 8ecc7913 | j_mayer | |
492 | 8ecc7913 | j_mayer | static void sdram_set_bcr (uint32_t *bcrp, uint32_t bcr, int enabled) |
493 | 8ecc7913 | j_mayer | { |
494 | 8ecc7913 | j_mayer | if (*bcrp & 0x00000001) { |
495 | 8ecc7913 | j_mayer | /* Unmap RAM */
|
496 | 8ecc7913 | j_mayer | #ifdef DEBUG_SDRAM
|
497 | aae9366a | j_mayer | printf("%s: unmap RAM area " PADDRX " " ADDRX "\n", |
498 | be58fc7c | j_mayer | __func__, sdram_base(*bcrp), sdram_size(*bcrp)); |
499 | 8ecc7913 | j_mayer | #endif
|
500 | 8ecc7913 | j_mayer | cpu_register_physical_memory(sdram_base(*bcrp), sdram_size(*bcrp), |
501 | 8ecc7913 | j_mayer | IO_MEM_UNASSIGNED); |
502 | 8ecc7913 | j_mayer | } |
503 | 8ecc7913 | j_mayer | *bcrp = bcr & 0xFFDEE001;
|
504 | 8ecc7913 | j_mayer | if (enabled && (bcr & 0x00000001)) { |
505 | 8ecc7913 | j_mayer | #ifdef DEBUG_SDRAM
|
506 | aae9366a | j_mayer | printf("%s: Map RAM area " PADDRX " " ADDRX "\n", |
507 | be58fc7c | j_mayer | __func__, sdram_base(bcr), sdram_size(bcr)); |
508 | 8ecc7913 | j_mayer | #endif
|
509 | 8ecc7913 | j_mayer | cpu_register_physical_memory(sdram_base(bcr), sdram_size(bcr), |
510 | 8ecc7913 | j_mayer | sdram_base(bcr) | IO_MEM_RAM); |
511 | 8ecc7913 | j_mayer | } |
512 | 8ecc7913 | j_mayer | } |
513 | 8ecc7913 | j_mayer | |
514 | 8ecc7913 | j_mayer | static void sdram_map_bcr (ppc4xx_sdram_t *sdram) |
515 | 8ecc7913 | j_mayer | { |
516 | 8ecc7913 | j_mayer | int i;
|
517 | 8ecc7913 | j_mayer | |
518 | 8ecc7913 | j_mayer | for (i = 0; i < sdram->nbanks; i++) { |
519 | 8ecc7913 | j_mayer | if (sdram->ram_sizes[i] != 0) { |
520 | 8ecc7913 | j_mayer | sdram_set_bcr(&sdram->bcr[i], |
521 | 8ecc7913 | j_mayer | sdram_bcr(sdram->ram_bases[i], sdram->ram_sizes[i]), |
522 | 8ecc7913 | j_mayer | 1);
|
523 | 8ecc7913 | j_mayer | } else {
|
524 | 8ecc7913 | j_mayer | sdram_set_bcr(&sdram->bcr[i], 0x00000000, 0); |
525 | 8ecc7913 | j_mayer | } |
526 | 8ecc7913 | j_mayer | } |
527 | 8ecc7913 | j_mayer | } |
528 | 8ecc7913 | j_mayer | |
529 | 8ecc7913 | j_mayer | static void sdram_unmap_bcr (ppc4xx_sdram_t *sdram) |
530 | 8ecc7913 | j_mayer | { |
531 | 8ecc7913 | j_mayer | int i;
|
532 | 8ecc7913 | j_mayer | |
533 | 8ecc7913 | j_mayer | for (i = 0; i < sdram->nbanks; i++) { |
534 | 04f20795 | j_mayer | #ifdef DEBUG_SDRAM
|
535 | aae9366a | j_mayer | printf("%s: Unmap RAM area " PADDRX " " ADDRX "\n", |
536 | be58fc7c | j_mayer | __func__, sdram_base(sdram->bcr[i]), sdram_size(sdram->bcr[i])); |
537 | 04f20795 | j_mayer | #endif
|
538 | 8ecc7913 | j_mayer | cpu_register_physical_memory(sdram_base(sdram->bcr[i]), |
539 | 8ecc7913 | j_mayer | sdram_size(sdram->bcr[i]), |
540 | 8ecc7913 | j_mayer | IO_MEM_UNASSIGNED); |
541 | 8ecc7913 | j_mayer | } |
542 | 8ecc7913 | j_mayer | } |
543 | 8ecc7913 | j_mayer | |
544 | 8ecc7913 | j_mayer | static target_ulong dcr_read_sdram (void *opaque, int dcrn) |
545 | 8ecc7913 | j_mayer | { |
546 | 8ecc7913 | j_mayer | ppc4xx_sdram_t *sdram; |
547 | 8ecc7913 | j_mayer | target_ulong ret; |
548 | 8ecc7913 | j_mayer | |
549 | 8ecc7913 | j_mayer | sdram = opaque; |
550 | 8ecc7913 | j_mayer | switch (dcrn) {
|
551 | 8ecc7913 | j_mayer | case SDRAM0_CFGADDR:
|
552 | 8ecc7913 | j_mayer | ret = sdram->addr; |
553 | 8ecc7913 | j_mayer | break;
|
554 | 8ecc7913 | j_mayer | case SDRAM0_CFGDATA:
|
555 | 8ecc7913 | j_mayer | switch (sdram->addr) {
|
556 | 8ecc7913 | j_mayer | case 0x00: /* SDRAM_BESR0 */ |
557 | 8ecc7913 | j_mayer | ret = sdram->besr0; |
558 | 8ecc7913 | j_mayer | break;
|
559 | 8ecc7913 | j_mayer | case 0x08: /* SDRAM_BESR1 */ |
560 | 8ecc7913 | j_mayer | ret = sdram->besr1; |
561 | 8ecc7913 | j_mayer | break;
|
562 | 8ecc7913 | j_mayer | case 0x10: /* SDRAM_BEAR */ |
563 | 8ecc7913 | j_mayer | ret = sdram->bear; |
564 | 8ecc7913 | j_mayer | break;
|
565 | 8ecc7913 | j_mayer | case 0x20: /* SDRAM_CFG */ |
566 | 8ecc7913 | j_mayer | ret = sdram->cfg; |
567 | 8ecc7913 | j_mayer | break;
|
568 | 8ecc7913 | j_mayer | case 0x24: /* SDRAM_STATUS */ |
569 | 8ecc7913 | j_mayer | ret = sdram->status; |
570 | 8ecc7913 | j_mayer | break;
|
571 | 8ecc7913 | j_mayer | case 0x30: /* SDRAM_RTR */ |
572 | 8ecc7913 | j_mayer | ret = sdram->rtr; |
573 | 8ecc7913 | j_mayer | break;
|
574 | 8ecc7913 | j_mayer | case 0x34: /* SDRAM_PMIT */ |
575 | 8ecc7913 | j_mayer | ret = sdram->pmit; |
576 | 8ecc7913 | j_mayer | break;
|
577 | 8ecc7913 | j_mayer | case 0x40: /* SDRAM_B0CR */ |
578 | 8ecc7913 | j_mayer | ret = sdram->bcr[0];
|
579 | 8ecc7913 | j_mayer | break;
|
580 | 8ecc7913 | j_mayer | case 0x44: /* SDRAM_B1CR */ |
581 | 8ecc7913 | j_mayer | ret = sdram->bcr[1];
|
582 | 8ecc7913 | j_mayer | break;
|
583 | 8ecc7913 | j_mayer | case 0x48: /* SDRAM_B2CR */ |
584 | 8ecc7913 | j_mayer | ret = sdram->bcr[2];
|
585 | 8ecc7913 | j_mayer | break;
|
586 | 8ecc7913 | j_mayer | case 0x4C: /* SDRAM_B3CR */ |
587 | 8ecc7913 | j_mayer | ret = sdram->bcr[3];
|
588 | 8ecc7913 | j_mayer | break;
|
589 | 8ecc7913 | j_mayer | case 0x80: /* SDRAM_TR */ |
590 | 8ecc7913 | j_mayer | ret = -1; /* ? */ |
591 | 8ecc7913 | j_mayer | break;
|
592 | 8ecc7913 | j_mayer | case 0x94: /* SDRAM_ECCCFG */ |
593 | 8ecc7913 | j_mayer | ret = sdram->ecccfg; |
594 | 8ecc7913 | j_mayer | break;
|
595 | 8ecc7913 | j_mayer | case 0x98: /* SDRAM_ECCESR */ |
596 | 8ecc7913 | j_mayer | ret = sdram->eccesr; |
597 | 8ecc7913 | j_mayer | break;
|
598 | 8ecc7913 | j_mayer | default: /* Error */ |
599 | 8ecc7913 | j_mayer | ret = -1;
|
600 | 8ecc7913 | j_mayer | break;
|
601 | 8ecc7913 | j_mayer | } |
602 | 8ecc7913 | j_mayer | break;
|
603 | 8ecc7913 | j_mayer | default:
|
604 | 8ecc7913 | j_mayer | /* Avoid gcc warning */
|
605 | 8ecc7913 | j_mayer | ret = 0x00000000;
|
606 | 8ecc7913 | j_mayer | break;
|
607 | 8ecc7913 | j_mayer | } |
608 | 8ecc7913 | j_mayer | |
609 | 8ecc7913 | j_mayer | return ret;
|
610 | 8ecc7913 | j_mayer | } |
611 | 8ecc7913 | j_mayer | |
612 | 8ecc7913 | j_mayer | static void dcr_write_sdram (void *opaque, int dcrn, target_ulong val) |
613 | 8ecc7913 | j_mayer | { |
614 | 8ecc7913 | j_mayer | ppc4xx_sdram_t *sdram; |
615 | 8ecc7913 | j_mayer | |
616 | 8ecc7913 | j_mayer | sdram = opaque; |
617 | 8ecc7913 | j_mayer | switch (dcrn) {
|
618 | 8ecc7913 | j_mayer | case SDRAM0_CFGADDR:
|
619 | 8ecc7913 | j_mayer | sdram->addr = val; |
620 | 8ecc7913 | j_mayer | break;
|
621 | 8ecc7913 | j_mayer | case SDRAM0_CFGDATA:
|
622 | 8ecc7913 | j_mayer | switch (sdram->addr) {
|
623 | 8ecc7913 | j_mayer | case 0x00: /* SDRAM_BESR0 */ |
624 | 8ecc7913 | j_mayer | sdram->besr0 &= ~val; |
625 | 8ecc7913 | j_mayer | break;
|
626 | 8ecc7913 | j_mayer | case 0x08: /* SDRAM_BESR1 */ |
627 | 8ecc7913 | j_mayer | sdram->besr1 &= ~val; |
628 | 8ecc7913 | j_mayer | break;
|
629 | 8ecc7913 | j_mayer | case 0x10: /* SDRAM_BEAR */ |
630 | 8ecc7913 | j_mayer | sdram->bear = val; |
631 | 8ecc7913 | j_mayer | break;
|
632 | 8ecc7913 | j_mayer | case 0x20: /* SDRAM_CFG */ |
633 | 8ecc7913 | j_mayer | val &= 0xFFE00000;
|
634 | 8ecc7913 | j_mayer | if (!(sdram->cfg & 0x80000000) && (val & 0x80000000)) { |
635 | 8ecc7913 | j_mayer | #ifdef DEBUG_SDRAM
|
636 | 8ecc7913 | j_mayer | printf("%s: enable SDRAM controller\n", __func__);
|
637 | 8ecc7913 | j_mayer | #endif
|
638 | 8ecc7913 | j_mayer | /* validate all RAM mappings */
|
639 | 8ecc7913 | j_mayer | sdram_map_bcr(sdram); |
640 | 8ecc7913 | j_mayer | sdram->status &= ~0x80000000;
|
641 | 8ecc7913 | j_mayer | } else if ((sdram->cfg & 0x80000000) && !(val & 0x80000000)) { |
642 | 8ecc7913 | j_mayer | #ifdef DEBUG_SDRAM
|
643 | 8ecc7913 | j_mayer | printf("%s: disable SDRAM controller\n", __func__);
|
644 | 8ecc7913 | j_mayer | #endif
|
645 | 8ecc7913 | j_mayer | /* invalidate all RAM mappings */
|
646 | 8ecc7913 | j_mayer | sdram_unmap_bcr(sdram); |
647 | 8ecc7913 | j_mayer | sdram->status |= 0x80000000;
|
648 | 8ecc7913 | j_mayer | } |
649 | 8ecc7913 | j_mayer | if (!(sdram->cfg & 0x40000000) && (val & 0x40000000)) |
650 | 8ecc7913 | j_mayer | sdram->status |= 0x40000000;
|
651 | 8ecc7913 | j_mayer | else if ((sdram->cfg & 0x40000000) && !(val & 0x40000000)) |
652 | 8ecc7913 | j_mayer | sdram->status &= ~0x40000000;
|
653 | 8ecc7913 | j_mayer | sdram->cfg = val; |
654 | 8ecc7913 | j_mayer | break;
|
655 | 8ecc7913 | j_mayer | case 0x24: /* SDRAM_STATUS */ |
656 | 8ecc7913 | j_mayer | /* Read-only register */
|
657 | 8ecc7913 | j_mayer | break;
|
658 | 8ecc7913 | j_mayer | case 0x30: /* SDRAM_RTR */ |
659 | 8ecc7913 | j_mayer | sdram->rtr = val & 0x3FF80000;
|
660 | 8ecc7913 | j_mayer | break;
|
661 | 8ecc7913 | j_mayer | case 0x34: /* SDRAM_PMIT */ |
662 | 8ecc7913 | j_mayer | sdram->pmit = (val & 0xF8000000) | 0x07C00000; |
663 | 8ecc7913 | j_mayer | break;
|
664 | 8ecc7913 | j_mayer | case 0x40: /* SDRAM_B0CR */ |
665 | 8ecc7913 | j_mayer | sdram_set_bcr(&sdram->bcr[0], val, sdram->cfg & 0x80000000); |
666 | 8ecc7913 | j_mayer | break;
|
667 | 8ecc7913 | j_mayer | case 0x44: /* SDRAM_B1CR */ |
668 | 8ecc7913 | j_mayer | sdram_set_bcr(&sdram->bcr[1], val, sdram->cfg & 0x80000000); |
669 | 8ecc7913 | j_mayer | break;
|
670 | 8ecc7913 | j_mayer | case 0x48: /* SDRAM_B2CR */ |
671 | 8ecc7913 | j_mayer | sdram_set_bcr(&sdram->bcr[2], val, sdram->cfg & 0x80000000); |
672 | 8ecc7913 | j_mayer | break;
|
673 | 8ecc7913 | j_mayer | case 0x4C: /* SDRAM_B3CR */ |
674 | 8ecc7913 | j_mayer | sdram_set_bcr(&sdram->bcr[3], val, sdram->cfg & 0x80000000); |
675 | 8ecc7913 | j_mayer | break;
|
676 | 8ecc7913 | j_mayer | case 0x80: /* SDRAM_TR */ |
677 | 8ecc7913 | j_mayer | sdram->tr = val & 0x018FC01F;
|
678 | 8ecc7913 | j_mayer | break;
|
679 | 8ecc7913 | j_mayer | case 0x94: /* SDRAM_ECCCFG */ |
680 | 8ecc7913 | j_mayer | sdram->ecccfg = val & 0x00F00000;
|
681 | 8ecc7913 | j_mayer | break;
|
682 | 8ecc7913 | j_mayer | case 0x98: /* SDRAM_ECCESR */ |
683 | 8ecc7913 | j_mayer | val &= 0xFFF0F000;
|
684 | 8ecc7913 | j_mayer | if (sdram->eccesr == 0 && val != 0) |
685 | 8ecc7913 | j_mayer | qemu_irq_raise(sdram->irq); |
686 | 8ecc7913 | j_mayer | else if (sdram->eccesr != 0 && val == 0) |
687 | 8ecc7913 | j_mayer | qemu_irq_lower(sdram->irq); |
688 | 8ecc7913 | j_mayer | sdram->eccesr = val; |
689 | 8ecc7913 | j_mayer | break;
|
690 | 8ecc7913 | j_mayer | default: /* Error */ |
691 | 8ecc7913 | j_mayer | break;
|
692 | 8ecc7913 | j_mayer | } |
693 | 8ecc7913 | j_mayer | break;
|
694 | 8ecc7913 | j_mayer | } |
695 | 8ecc7913 | j_mayer | } |
696 | 8ecc7913 | j_mayer | |
697 | 8ecc7913 | j_mayer | static void sdram_reset (void *opaque) |
698 | 8ecc7913 | j_mayer | { |
699 | 8ecc7913 | j_mayer | ppc4xx_sdram_t *sdram; |
700 | 8ecc7913 | j_mayer | |
701 | 8ecc7913 | j_mayer | sdram = opaque; |
702 | 8ecc7913 | j_mayer | sdram->addr = 0x00000000;
|
703 | 8ecc7913 | j_mayer | sdram->bear = 0x00000000;
|
704 | 8ecc7913 | j_mayer | sdram->besr0 = 0x00000000; /* No error */ |
705 | 8ecc7913 | j_mayer | sdram->besr1 = 0x00000000; /* No error */ |
706 | 8ecc7913 | j_mayer | sdram->cfg = 0x00000000;
|
707 | 8ecc7913 | j_mayer | sdram->ecccfg = 0x00000000; /* No ECC */ |
708 | 8ecc7913 | j_mayer | sdram->eccesr = 0x00000000; /* No error */ |
709 | 8ecc7913 | j_mayer | sdram->pmit = 0x07C00000;
|
710 | 8ecc7913 | j_mayer | sdram->rtr = 0x05F00000;
|
711 | 8ecc7913 | j_mayer | sdram->tr = 0x00854009;
|
712 | 8ecc7913 | j_mayer | /* We pre-initialize RAM banks */
|
713 | 8ecc7913 | j_mayer | sdram->status = 0x00000000;
|
714 | 8ecc7913 | j_mayer | sdram->cfg = 0x00800000;
|
715 | 8ecc7913 | j_mayer | sdram_unmap_bcr(sdram); |
716 | 8ecc7913 | j_mayer | } |
717 | 8ecc7913 | j_mayer | |
718 | 8ecc7913 | j_mayer | void ppc405_sdram_init (CPUState *env, qemu_irq irq, int nbanks, |
719 | 71db710f | blueswir1 | target_phys_addr_t *ram_bases, |
720 | 71db710f | blueswir1 | target_phys_addr_t *ram_sizes, |
721 | 04f20795 | j_mayer | int do_init)
|
722 | 8ecc7913 | j_mayer | { |
723 | 8ecc7913 | j_mayer | ppc4xx_sdram_t *sdram; |
724 | 8ecc7913 | j_mayer | |
725 | 8ecc7913 | j_mayer | sdram = qemu_mallocz(sizeof(ppc4xx_sdram_t));
|
726 | 8ecc7913 | j_mayer | if (sdram != NULL) { |
727 | 8ecc7913 | j_mayer | sdram->irq = irq; |
728 | 8ecc7913 | j_mayer | sdram->nbanks = nbanks; |
729 | 71db710f | blueswir1 | memset(sdram->ram_bases, 0, 4 * sizeof(target_phys_addr_t)); |
730 | 36081602 | j_mayer | memcpy(sdram->ram_bases, ram_bases, |
731 | 36081602 | j_mayer | nbanks * sizeof(target_phys_addr_t));
|
732 | 71db710f | blueswir1 | memset(sdram->ram_sizes, 0, 4 * sizeof(target_phys_addr_t)); |
733 | 36081602 | j_mayer | memcpy(sdram->ram_sizes, ram_sizes, |
734 | 36081602 | j_mayer | nbanks * sizeof(target_phys_addr_t));
|
735 | 8ecc7913 | j_mayer | sdram_reset(sdram); |
736 | 8ecc7913 | j_mayer | qemu_register_reset(&sdram_reset, sdram); |
737 | 8ecc7913 | j_mayer | ppc_dcr_register(env, SDRAM0_CFGADDR, |
738 | 8ecc7913 | j_mayer | sdram, &dcr_read_sdram, &dcr_write_sdram); |
739 | 8ecc7913 | j_mayer | ppc_dcr_register(env, SDRAM0_CFGDATA, |
740 | 8ecc7913 | j_mayer | sdram, &dcr_read_sdram, &dcr_write_sdram); |
741 | 04f20795 | j_mayer | if (do_init)
|
742 | 04f20795 | j_mayer | sdram_map_bcr(sdram); |
743 | 8ecc7913 | j_mayer | } |
744 | 8ecc7913 | j_mayer | } |
745 | 8ecc7913 | j_mayer | |
746 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
747 | 8ecc7913 | j_mayer | /* Peripheral controller */
|
748 | 8ecc7913 | j_mayer | typedef struct ppc4xx_ebc_t ppc4xx_ebc_t; |
749 | 8ecc7913 | j_mayer | struct ppc4xx_ebc_t {
|
750 | 8ecc7913 | j_mayer | uint32_t addr; |
751 | 8ecc7913 | j_mayer | uint32_t bcr[8];
|
752 | 8ecc7913 | j_mayer | uint32_t bap[8];
|
753 | 8ecc7913 | j_mayer | uint32_t bear; |
754 | 8ecc7913 | j_mayer | uint32_t besr0; |
755 | 8ecc7913 | j_mayer | uint32_t besr1; |
756 | 8ecc7913 | j_mayer | uint32_t cfg; |
757 | 8ecc7913 | j_mayer | }; |
758 | 8ecc7913 | j_mayer | |
759 | 8ecc7913 | j_mayer | enum {
|
760 | 8ecc7913 | j_mayer | EBC0_CFGADDR = 0x012,
|
761 | 8ecc7913 | j_mayer | EBC0_CFGDATA = 0x013,
|
762 | 8ecc7913 | j_mayer | }; |
763 | 8ecc7913 | j_mayer | |
764 | 8ecc7913 | j_mayer | static target_ulong dcr_read_ebc (void *opaque, int dcrn) |
765 | 8ecc7913 | j_mayer | { |
766 | 8ecc7913 | j_mayer | ppc4xx_ebc_t *ebc; |
767 | 8ecc7913 | j_mayer | target_ulong ret; |
768 | 8ecc7913 | j_mayer | |
769 | 8ecc7913 | j_mayer | ebc = opaque; |
770 | 8ecc7913 | j_mayer | switch (dcrn) {
|
771 | 8ecc7913 | j_mayer | case EBC0_CFGADDR:
|
772 | 8ecc7913 | j_mayer | ret = ebc->addr; |
773 | 8ecc7913 | j_mayer | break;
|
774 | 8ecc7913 | j_mayer | case EBC0_CFGDATA:
|
775 | 8ecc7913 | j_mayer | switch (ebc->addr) {
|
776 | 8ecc7913 | j_mayer | case 0x00: /* B0CR */ |
777 | 8ecc7913 | j_mayer | ret = ebc->bcr[0];
|
778 | 8ecc7913 | j_mayer | break;
|
779 | 8ecc7913 | j_mayer | case 0x01: /* B1CR */ |
780 | 8ecc7913 | j_mayer | ret = ebc->bcr[1];
|
781 | 8ecc7913 | j_mayer | break;
|
782 | 8ecc7913 | j_mayer | case 0x02: /* B2CR */ |
783 | 8ecc7913 | j_mayer | ret = ebc->bcr[2];
|
784 | 8ecc7913 | j_mayer | break;
|
785 | 8ecc7913 | j_mayer | case 0x03: /* B3CR */ |
786 | 8ecc7913 | j_mayer | ret = ebc->bcr[3];
|
787 | 8ecc7913 | j_mayer | break;
|
788 | 8ecc7913 | j_mayer | case 0x04: /* B4CR */ |
789 | 8ecc7913 | j_mayer | ret = ebc->bcr[4];
|
790 | 8ecc7913 | j_mayer | break;
|
791 | 8ecc7913 | j_mayer | case 0x05: /* B5CR */ |
792 | 8ecc7913 | j_mayer | ret = ebc->bcr[5];
|
793 | 8ecc7913 | j_mayer | break;
|
794 | 8ecc7913 | j_mayer | case 0x06: /* B6CR */ |
795 | 8ecc7913 | j_mayer | ret = ebc->bcr[6];
|
796 | 8ecc7913 | j_mayer | break;
|
797 | 8ecc7913 | j_mayer | case 0x07: /* B7CR */ |
798 | 8ecc7913 | j_mayer | ret = ebc->bcr[7];
|
799 | 8ecc7913 | j_mayer | break;
|
800 | 8ecc7913 | j_mayer | case 0x10: /* B0AP */ |
801 | 8ecc7913 | j_mayer | ret = ebc->bap[0];
|
802 | 8ecc7913 | j_mayer | break;
|
803 | 8ecc7913 | j_mayer | case 0x11: /* B1AP */ |
804 | 8ecc7913 | j_mayer | ret = ebc->bap[1];
|
805 | 8ecc7913 | j_mayer | break;
|
806 | 8ecc7913 | j_mayer | case 0x12: /* B2AP */ |
807 | 8ecc7913 | j_mayer | ret = ebc->bap[2];
|
808 | 8ecc7913 | j_mayer | break;
|
809 | 8ecc7913 | j_mayer | case 0x13: /* B3AP */ |
810 | 8ecc7913 | j_mayer | ret = ebc->bap[3];
|
811 | 8ecc7913 | j_mayer | break;
|
812 | 8ecc7913 | j_mayer | case 0x14: /* B4AP */ |
813 | 8ecc7913 | j_mayer | ret = ebc->bap[4];
|
814 | 8ecc7913 | j_mayer | break;
|
815 | 8ecc7913 | j_mayer | case 0x15: /* B5AP */ |
816 | 8ecc7913 | j_mayer | ret = ebc->bap[5];
|
817 | 8ecc7913 | j_mayer | break;
|
818 | 8ecc7913 | j_mayer | case 0x16: /* B6AP */ |
819 | 8ecc7913 | j_mayer | ret = ebc->bap[6];
|
820 | 8ecc7913 | j_mayer | break;
|
821 | 8ecc7913 | j_mayer | case 0x17: /* B7AP */ |
822 | 8ecc7913 | j_mayer | ret = ebc->bap[7];
|
823 | 8ecc7913 | j_mayer | break;
|
824 | 8ecc7913 | j_mayer | case 0x20: /* BEAR */ |
825 | 8ecc7913 | j_mayer | ret = ebc->bear; |
826 | 8ecc7913 | j_mayer | break;
|
827 | 8ecc7913 | j_mayer | case 0x21: /* BESR0 */ |
828 | 8ecc7913 | j_mayer | ret = ebc->besr0; |
829 | 8ecc7913 | j_mayer | break;
|
830 | 8ecc7913 | j_mayer | case 0x22: /* BESR1 */ |
831 | 8ecc7913 | j_mayer | ret = ebc->besr1; |
832 | 8ecc7913 | j_mayer | break;
|
833 | 8ecc7913 | j_mayer | case 0x23: /* CFG */ |
834 | 8ecc7913 | j_mayer | ret = ebc->cfg; |
835 | 8ecc7913 | j_mayer | break;
|
836 | 8ecc7913 | j_mayer | default:
|
837 | 8ecc7913 | j_mayer | ret = 0x00000000;
|
838 | 8ecc7913 | j_mayer | break;
|
839 | 8ecc7913 | j_mayer | } |
840 | 8ecc7913 | j_mayer | default:
|
841 | 8ecc7913 | j_mayer | ret = 0x00000000;
|
842 | 8ecc7913 | j_mayer | break;
|
843 | 8ecc7913 | j_mayer | } |
844 | 8ecc7913 | j_mayer | |
845 | 8ecc7913 | j_mayer | return ret;
|
846 | 8ecc7913 | j_mayer | } |
847 | 8ecc7913 | j_mayer | |
848 | 8ecc7913 | j_mayer | static void dcr_write_ebc (void *opaque, int dcrn, target_ulong val) |
849 | 8ecc7913 | j_mayer | { |
850 | 8ecc7913 | j_mayer | ppc4xx_ebc_t *ebc; |
851 | 8ecc7913 | j_mayer | |
852 | 8ecc7913 | j_mayer | ebc = opaque; |
853 | 8ecc7913 | j_mayer | switch (dcrn) {
|
854 | 8ecc7913 | j_mayer | case EBC0_CFGADDR:
|
855 | 8ecc7913 | j_mayer | ebc->addr = val; |
856 | 8ecc7913 | j_mayer | break;
|
857 | 8ecc7913 | j_mayer | case EBC0_CFGDATA:
|
858 | 8ecc7913 | j_mayer | switch (ebc->addr) {
|
859 | 8ecc7913 | j_mayer | case 0x00: /* B0CR */ |
860 | 8ecc7913 | j_mayer | break;
|
861 | 8ecc7913 | j_mayer | case 0x01: /* B1CR */ |
862 | 8ecc7913 | j_mayer | break;
|
863 | 8ecc7913 | j_mayer | case 0x02: /* B2CR */ |
864 | 8ecc7913 | j_mayer | break;
|
865 | 8ecc7913 | j_mayer | case 0x03: /* B3CR */ |
866 | 8ecc7913 | j_mayer | break;
|
867 | 8ecc7913 | j_mayer | case 0x04: /* B4CR */ |
868 | 8ecc7913 | j_mayer | break;
|
869 | 8ecc7913 | j_mayer | case 0x05: /* B5CR */ |
870 | 8ecc7913 | j_mayer | break;
|
871 | 8ecc7913 | j_mayer | case 0x06: /* B6CR */ |
872 | 8ecc7913 | j_mayer | break;
|
873 | 8ecc7913 | j_mayer | case 0x07: /* B7CR */ |
874 | 8ecc7913 | j_mayer | break;
|
875 | 8ecc7913 | j_mayer | case 0x10: /* B0AP */ |
876 | 8ecc7913 | j_mayer | break;
|
877 | 8ecc7913 | j_mayer | case 0x11: /* B1AP */ |
878 | 8ecc7913 | j_mayer | break;
|
879 | 8ecc7913 | j_mayer | case 0x12: /* B2AP */ |
880 | 8ecc7913 | j_mayer | break;
|
881 | 8ecc7913 | j_mayer | case 0x13: /* B3AP */ |
882 | 8ecc7913 | j_mayer | break;
|
883 | 8ecc7913 | j_mayer | case 0x14: /* B4AP */ |
884 | 8ecc7913 | j_mayer | break;
|
885 | 8ecc7913 | j_mayer | case 0x15: /* B5AP */ |
886 | 8ecc7913 | j_mayer | break;
|
887 | 8ecc7913 | j_mayer | case 0x16: /* B6AP */ |
888 | 8ecc7913 | j_mayer | break;
|
889 | 8ecc7913 | j_mayer | case 0x17: /* B7AP */ |
890 | 8ecc7913 | j_mayer | break;
|
891 | 8ecc7913 | j_mayer | case 0x20: /* BEAR */ |
892 | 8ecc7913 | j_mayer | break;
|
893 | 8ecc7913 | j_mayer | case 0x21: /* BESR0 */ |
894 | 8ecc7913 | j_mayer | break;
|
895 | 8ecc7913 | j_mayer | case 0x22: /* BESR1 */ |
896 | 8ecc7913 | j_mayer | break;
|
897 | 8ecc7913 | j_mayer | case 0x23: /* CFG */ |
898 | 8ecc7913 | j_mayer | break;
|
899 | 8ecc7913 | j_mayer | default:
|
900 | 8ecc7913 | j_mayer | break;
|
901 | 8ecc7913 | j_mayer | } |
902 | 8ecc7913 | j_mayer | break;
|
903 | 8ecc7913 | j_mayer | default:
|
904 | 8ecc7913 | j_mayer | break;
|
905 | 8ecc7913 | j_mayer | } |
906 | 8ecc7913 | j_mayer | } |
907 | 8ecc7913 | j_mayer | |
908 | 8ecc7913 | j_mayer | static void ebc_reset (void *opaque) |
909 | 8ecc7913 | j_mayer | { |
910 | 8ecc7913 | j_mayer | ppc4xx_ebc_t *ebc; |
911 | 8ecc7913 | j_mayer | int i;
|
912 | 8ecc7913 | j_mayer | |
913 | 8ecc7913 | j_mayer | ebc = opaque; |
914 | 8ecc7913 | j_mayer | ebc->addr = 0x00000000;
|
915 | 8ecc7913 | j_mayer | ebc->bap[0] = 0x7F8FFE80; |
916 | 8ecc7913 | j_mayer | ebc->bcr[0] = 0xFFE28000; |
917 | 8ecc7913 | j_mayer | for (i = 0; i < 8; i++) { |
918 | 8ecc7913 | j_mayer | ebc->bap[i] = 0x00000000;
|
919 | 8ecc7913 | j_mayer | ebc->bcr[i] = 0x00000000;
|
920 | 8ecc7913 | j_mayer | } |
921 | 8ecc7913 | j_mayer | ebc->besr0 = 0x00000000;
|
922 | 8ecc7913 | j_mayer | ebc->besr1 = 0x00000000;
|
923 | 9c02f1a2 | j_mayer | ebc->cfg = 0x80400000;
|
924 | 8ecc7913 | j_mayer | } |
925 | 8ecc7913 | j_mayer | |
926 | 8ecc7913 | j_mayer | void ppc405_ebc_init (CPUState *env)
|
927 | 8ecc7913 | j_mayer | { |
928 | 8ecc7913 | j_mayer | ppc4xx_ebc_t *ebc; |
929 | 8ecc7913 | j_mayer | |
930 | 8ecc7913 | j_mayer | ebc = qemu_mallocz(sizeof(ppc4xx_ebc_t));
|
931 | 8ecc7913 | j_mayer | if (ebc != NULL) { |
932 | 8ecc7913 | j_mayer | ebc_reset(ebc); |
933 | 8ecc7913 | j_mayer | qemu_register_reset(&ebc_reset, ebc); |
934 | 8ecc7913 | j_mayer | ppc_dcr_register(env, EBC0_CFGADDR, |
935 | 8ecc7913 | j_mayer | ebc, &dcr_read_ebc, &dcr_write_ebc); |
936 | 8ecc7913 | j_mayer | ppc_dcr_register(env, EBC0_CFGDATA, |
937 | 8ecc7913 | j_mayer | ebc, &dcr_read_ebc, &dcr_write_ebc); |
938 | 8ecc7913 | j_mayer | } |
939 | 8ecc7913 | j_mayer | } |
940 | 8ecc7913 | j_mayer | |
941 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
942 | 8ecc7913 | j_mayer | /* DMA controller */
|
943 | 8ecc7913 | j_mayer | enum {
|
944 | 8ecc7913 | j_mayer | DMA0_CR0 = 0x100,
|
945 | 8ecc7913 | j_mayer | DMA0_CT0 = 0x101,
|
946 | 8ecc7913 | j_mayer | DMA0_DA0 = 0x102,
|
947 | 8ecc7913 | j_mayer | DMA0_SA0 = 0x103,
|
948 | 8ecc7913 | j_mayer | DMA0_SG0 = 0x104,
|
949 | 8ecc7913 | j_mayer | DMA0_CR1 = 0x108,
|
950 | 8ecc7913 | j_mayer | DMA0_CT1 = 0x109,
|
951 | 8ecc7913 | j_mayer | DMA0_DA1 = 0x10A,
|
952 | 8ecc7913 | j_mayer | DMA0_SA1 = 0x10B,
|
953 | 8ecc7913 | j_mayer | DMA0_SG1 = 0x10C,
|
954 | 8ecc7913 | j_mayer | DMA0_CR2 = 0x110,
|
955 | 8ecc7913 | j_mayer | DMA0_CT2 = 0x111,
|
956 | 8ecc7913 | j_mayer | DMA0_DA2 = 0x112,
|
957 | 8ecc7913 | j_mayer | DMA0_SA2 = 0x113,
|
958 | 8ecc7913 | j_mayer | DMA0_SG2 = 0x114,
|
959 | 8ecc7913 | j_mayer | DMA0_CR3 = 0x118,
|
960 | 8ecc7913 | j_mayer | DMA0_CT3 = 0x119,
|
961 | 8ecc7913 | j_mayer | DMA0_DA3 = 0x11A,
|
962 | 8ecc7913 | j_mayer | DMA0_SA3 = 0x11B,
|
963 | 8ecc7913 | j_mayer | DMA0_SG3 = 0x11C,
|
964 | 8ecc7913 | j_mayer | DMA0_SR = 0x120,
|
965 | 8ecc7913 | j_mayer | DMA0_SGC = 0x123,
|
966 | 8ecc7913 | j_mayer | DMA0_SLP = 0x125,
|
967 | 8ecc7913 | j_mayer | DMA0_POL = 0x126,
|
968 | 8ecc7913 | j_mayer | }; |
969 | 8ecc7913 | j_mayer | |
970 | 8ecc7913 | j_mayer | typedef struct ppc405_dma_t ppc405_dma_t; |
971 | 8ecc7913 | j_mayer | struct ppc405_dma_t {
|
972 | 8ecc7913 | j_mayer | qemu_irq irqs[4];
|
973 | 8ecc7913 | j_mayer | uint32_t cr[4];
|
974 | 8ecc7913 | j_mayer | uint32_t ct[4];
|
975 | 8ecc7913 | j_mayer | uint32_t da[4];
|
976 | 8ecc7913 | j_mayer | uint32_t sa[4];
|
977 | 8ecc7913 | j_mayer | uint32_t sg[4];
|
978 | 8ecc7913 | j_mayer | uint32_t sr; |
979 | 8ecc7913 | j_mayer | uint32_t sgc; |
980 | 8ecc7913 | j_mayer | uint32_t slp; |
981 | 8ecc7913 | j_mayer | uint32_t pol; |
982 | 8ecc7913 | j_mayer | }; |
983 | 8ecc7913 | j_mayer | |
984 | 8ecc7913 | j_mayer | static target_ulong dcr_read_dma (void *opaque, int dcrn) |
985 | 8ecc7913 | j_mayer | { |
986 | 8ecc7913 | j_mayer | ppc405_dma_t *dma; |
987 | 8ecc7913 | j_mayer | |
988 | 8ecc7913 | j_mayer | dma = opaque; |
989 | 8ecc7913 | j_mayer | |
990 | 8ecc7913 | j_mayer | return 0; |
991 | 8ecc7913 | j_mayer | } |
992 | 8ecc7913 | j_mayer | |
993 | 8ecc7913 | j_mayer | static void dcr_write_dma (void *opaque, int dcrn, target_ulong val) |
994 | 8ecc7913 | j_mayer | { |
995 | 8ecc7913 | j_mayer | ppc405_dma_t *dma; |
996 | 8ecc7913 | j_mayer | |
997 | 8ecc7913 | j_mayer | dma = opaque; |
998 | 8ecc7913 | j_mayer | } |
999 | 8ecc7913 | j_mayer | |
1000 | 8ecc7913 | j_mayer | static void ppc405_dma_reset (void *opaque) |
1001 | 8ecc7913 | j_mayer | { |
1002 | 8ecc7913 | j_mayer | ppc405_dma_t *dma; |
1003 | 8ecc7913 | j_mayer | int i;
|
1004 | 8ecc7913 | j_mayer | |
1005 | 8ecc7913 | j_mayer | dma = opaque; |
1006 | 8ecc7913 | j_mayer | for (i = 0; i < 4; i++) { |
1007 | 8ecc7913 | j_mayer | dma->cr[i] = 0x00000000;
|
1008 | 8ecc7913 | j_mayer | dma->ct[i] = 0x00000000;
|
1009 | 8ecc7913 | j_mayer | dma->da[i] = 0x00000000;
|
1010 | 8ecc7913 | j_mayer | dma->sa[i] = 0x00000000;
|
1011 | 8ecc7913 | j_mayer | dma->sg[i] = 0x00000000;
|
1012 | 8ecc7913 | j_mayer | } |
1013 | 8ecc7913 | j_mayer | dma->sr = 0x00000000;
|
1014 | 8ecc7913 | j_mayer | dma->sgc = 0x00000000;
|
1015 | 8ecc7913 | j_mayer | dma->slp = 0x7C000000;
|
1016 | 8ecc7913 | j_mayer | dma->pol = 0x00000000;
|
1017 | 8ecc7913 | j_mayer | } |
1018 | 8ecc7913 | j_mayer | |
1019 | 8ecc7913 | j_mayer | void ppc405_dma_init (CPUState *env, qemu_irq irqs[4]) |
1020 | 8ecc7913 | j_mayer | { |
1021 | 8ecc7913 | j_mayer | ppc405_dma_t *dma; |
1022 | 8ecc7913 | j_mayer | |
1023 | 8ecc7913 | j_mayer | dma = qemu_mallocz(sizeof(ppc405_dma_t));
|
1024 | 8ecc7913 | j_mayer | if (dma != NULL) { |
1025 | 8ecc7913 | j_mayer | memcpy(dma->irqs, irqs, 4 * sizeof(qemu_irq)); |
1026 | 8ecc7913 | j_mayer | ppc405_dma_reset(dma); |
1027 | 8ecc7913 | j_mayer | qemu_register_reset(&ppc405_dma_reset, dma); |
1028 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_CR0, |
1029 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1030 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_CT0, |
1031 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1032 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_DA0, |
1033 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1034 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SA0, |
1035 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1036 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SG0, |
1037 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1038 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_CR1, |
1039 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1040 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_CT1, |
1041 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1042 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_DA1, |
1043 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1044 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SA1, |
1045 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1046 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SG1, |
1047 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1048 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_CR2, |
1049 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1050 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_CT2, |
1051 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1052 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_DA2, |
1053 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1054 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SA2, |
1055 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1056 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SG2, |
1057 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1058 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_CR3, |
1059 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1060 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_CT3, |
1061 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1062 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_DA3, |
1063 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1064 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SA3, |
1065 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1066 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SG3, |
1067 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1068 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SR, |
1069 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1070 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SGC, |
1071 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1072 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_SLP, |
1073 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1074 | 8ecc7913 | j_mayer | ppc_dcr_register(env, DMA0_POL, |
1075 | 8ecc7913 | j_mayer | dma, &dcr_read_dma, &dcr_write_dma); |
1076 | 8ecc7913 | j_mayer | } |
1077 | 8ecc7913 | j_mayer | } |
1078 | 8ecc7913 | j_mayer | |
1079 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
1080 | 8ecc7913 | j_mayer | /* GPIO */
|
1081 | 8ecc7913 | j_mayer | typedef struct ppc405_gpio_t ppc405_gpio_t; |
1082 | 8ecc7913 | j_mayer | struct ppc405_gpio_t {
|
1083 | 9c02f1a2 | j_mayer | target_phys_addr_t base; |
1084 | 8ecc7913 | j_mayer | uint32_t or; |
1085 | 8ecc7913 | j_mayer | uint32_t tcr; |
1086 | 8ecc7913 | j_mayer | uint32_t osrh; |
1087 | 8ecc7913 | j_mayer | uint32_t osrl; |
1088 | 8ecc7913 | j_mayer | uint32_t tsrh; |
1089 | 8ecc7913 | j_mayer | uint32_t tsrl; |
1090 | 8ecc7913 | j_mayer | uint32_t odr; |
1091 | 8ecc7913 | j_mayer | uint32_t ir; |
1092 | 8ecc7913 | j_mayer | uint32_t rr1; |
1093 | 8ecc7913 | j_mayer | uint32_t isr1h; |
1094 | 8ecc7913 | j_mayer | uint32_t isr1l; |
1095 | 8ecc7913 | j_mayer | }; |
1096 | 8ecc7913 | j_mayer | |
1097 | 8ecc7913 | j_mayer | static uint32_t ppc405_gpio_readb (void *opaque, target_phys_addr_t addr) |
1098 | 8ecc7913 | j_mayer | { |
1099 | 8ecc7913 | j_mayer | ppc405_gpio_t *gpio; |
1100 | 8ecc7913 | j_mayer | |
1101 | 8ecc7913 | j_mayer | gpio = opaque; |
1102 | 8ecc7913 | j_mayer | #ifdef DEBUG_GPIO
|
1103 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1104 | 8ecc7913 | j_mayer | #endif
|
1105 | 8ecc7913 | j_mayer | |
1106 | 8ecc7913 | j_mayer | return 0; |
1107 | 8ecc7913 | j_mayer | } |
1108 | 8ecc7913 | j_mayer | |
1109 | 8ecc7913 | j_mayer | static void ppc405_gpio_writeb (void *opaque, |
1110 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1111 | 8ecc7913 | j_mayer | { |
1112 | 8ecc7913 | j_mayer | ppc405_gpio_t *gpio; |
1113 | 8ecc7913 | j_mayer | |
1114 | 8ecc7913 | j_mayer | gpio = opaque; |
1115 | 8ecc7913 | j_mayer | #ifdef DEBUG_GPIO
|
1116 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1117 | 8ecc7913 | j_mayer | #endif
|
1118 | 8ecc7913 | j_mayer | } |
1119 | 8ecc7913 | j_mayer | |
1120 | 8ecc7913 | j_mayer | static uint32_t ppc405_gpio_readw (void *opaque, target_phys_addr_t addr) |
1121 | 8ecc7913 | j_mayer | { |
1122 | 8ecc7913 | j_mayer | ppc405_gpio_t *gpio; |
1123 | 8ecc7913 | j_mayer | |
1124 | 8ecc7913 | j_mayer | gpio = opaque; |
1125 | 8ecc7913 | j_mayer | #ifdef DEBUG_GPIO
|
1126 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1127 | 8ecc7913 | j_mayer | #endif
|
1128 | 8ecc7913 | j_mayer | |
1129 | 8ecc7913 | j_mayer | return 0; |
1130 | 8ecc7913 | j_mayer | } |
1131 | 8ecc7913 | j_mayer | |
1132 | 8ecc7913 | j_mayer | static void ppc405_gpio_writew (void *opaque, |
1133 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1134 | 8ecc7913 | j_mayer | { |
1135 | 8ecc7913 | j_mayer | ppc405_gpio_t *gpio; |
1136 | 8ecc7913 | j_mayer | |
1137 | 8ecc7913 | j_mayer | gpio = opaque; |
1138 | 8ecc7913 | j_mayer | #ifdef DEBUG_GPIO
|
1139 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1140 | 8ecc7913 | j_mayer | #endif
|
1141 | 8ecc7913 | j_mayer | } |
1142 | 8ecc7913 | j_mayer | |
1143 | 8ecc7913 | j_mayer | static uint32_t ppc405_gpio_readl (void *opaque, target_phys_addr_t addr) |
1144 | 8ecc7913 | j_mayer | { |
1145 | 8ecc7913 | j_mayer | ppc405_gpio_t *gpio; |
1146 | 8ecc7913 | j_mayer | |
1147 | 8ecc7913 | j_mayer | gpio = opaque; |
1148 | 8ecc7913 | j_mayer | #ifdef DEBUG_GPIO
|
1149 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1150 | 8ecc7913 | j_mayer | #endif
|
1151 | 8ecc7913 | j_mayer | |
1152 | 8ecc7913 | j_mayer | return 0; |
1153 | 8ecc7913 | j_mayer | } |
1154 | 8ecc7913 | j_mayer | |
1155 | 8ecc7913 | j_mayer | static void ppc405_gpio_writel (void *opaque, |
1156 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1157 | 8ecc7913 | j_mayer | { |
1158 | 8ecc7913 | j_mayer | ppc405_gpio_t *gpio; |
1159 | 8ecc7913 | j_mayer | |
1160 | 8ecc7913 | j_mayer | gpio = opaque; |
1161 | 8ecc7913 | j_mayer | #ifdef DEBUG_GPIO
|
1162 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1163 | 8ecc7913 | j_mayer | #endif
|
1164 | 8ecc7913 | j_mayer | } |
1165 | 8ecc7913 | j_mayer | |
1166 | 8ecc7913 | j_mayer | static CPUReadMemoryFunc *ppc405_gpio_read[] = {
|
1167 | 8ecc7913 | j_mayer | &ppc405_gpio_readb, |
1168 | 8ecc7913 | j_mayer | &ppc405_gpio_readw, |
1169 | 8ecc7913 | j_mayer | &ppc405_gpio_readl, |
1170 | 8ecc7913 | j_mayer | }; |
1171 | 8ecc7913 | j_mayer | |
1172 | 8ecc7913 | j_mayer | static CPUWriteMemoryFunc *ppc405_gpio_write[] = {
|
1173 | 8ecc7913 | j_mayer | &ppc405_gpio_writeb, |
1174 | 8ecc7913 | j_mayer | &ppc405_gpio_writew, |
1175 | 8ecc7913 | j_mayer | &ppc405_gpio_writel, |
1176 | 8ecc7913 | j_mayer | }; |
1177 | 8ecc7913 | j_mayer | |
1178 | 8ecc7913 | j_mayer | static void ppc405_gpio_reset (void *opaque) |
1179 | 8ecc7913 | j_mayer | { |
1180 | 8ecc7913 | j_mayer | ppc405_gpio_t *gpio; |
1181 | 8ecc7913 | j_mayer | |
1182 | 8ecc7913 | j_mayer | gpio = opaque; |
1183 | 8ecc7913 | j_mayer | } |
1184 | 8ecc7913 | j_mayer | |
1185 | 9c02f1a2 | j_mayer | void ppc405_gpio_init (CPUState *env, ppc4xx_mmio_t *mmio,
|
1186 | 9c02f1a2 | j_mayer | target_phys_addr_t offset) |
1187 | 8ecc7913 | j_mayer | { |
1188 | 8ecc7913 | j_mayer | ppc405_gpio_t *gpio; |
1189 | 8ecc7913 | j_mayer | |
1190 | 8ecc7913 | j_mayer | gpio = qemu_mallocz(sizeof(ppc405_gpio_t));
|
1191 | 8ecc7913 | j_mayer | if (gpio != NULL) { |
1192 | 9c02f1a2 | j_mayer | gpio->base = offset; |
1193 | 8ecc7913 | j_mayer | ppc405_gpio_reset(gpio); |
1194 | 8ecc7913 | j_mayer | qemu_register_reset(&ppc405_gpio_reset, gpio); |
1195 | 8ecc7913 | j_mayer | #ifdef DEBUG_GPIO
|
1196 | aae9366a | j_mayer | printf("%s: offset " PADDRX "\n", __func__, offset); |
1197 | 8ecc7913 | j_mayer | #endif
|
1198 | 8ecc7913 | j_mayer | ppc4xx_mmio_register(env, mmio, offset, 0x038,
|
1199 | 8ecc7913 | j_mayer | ppc405_gpio_read, ppc405_gpio_write, gpio); |
1200 | 8ecc7913 | j_mayer | } |
1201 | 8ecc7913 | j_mayer | } |
1202 | 8ecc7913 | j_mayer | |
1203 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
1204 | 8ecc7913 | j_mayer | /* Serial ports */
|
1205 | 8ecc7913 | j_mayer | static CPUReadMemoryFunc *serial_mm_read[] = {
|
1206 | 8ecc7913 | j_mayer | &serial_mm_readb, |
1207 | 8ecc7913 | j_mayer | &serial_mm_readw, |
1208 | 8ecc7913 | j_mayer | &serial_mm_readl, |
1209 | 8ecc7913 | j_mayer | }; |
1210 | 8ecc7913 | j_mayer | |
1211 | 8ecc7913 | j_mayer | static CPUWriteMemoryFunc *serial_mm_write[] = {
|
1212 | 8ecc7913 | j_mayer | &serial_mm_writeb, |
1213 | 8ecc7913 | j_mayer | &serial_mm_writew, |
1214 | 8ecc7913 | j_mayer | &serial_mm_writel, |
1215 | 8ecc7913 | j_mayer | }; |
1216 | 8ecc7913 | j_mayer | |
1217 | 8ecc7913 | j_mayer | void ppc405_serial_init (CPUState *env, ppc4xx_mmio_t *mmio,
|
1218 | 9c02f1a2 | j_mayer | target_phys_addr_t offset, qemu_irq irq, |
1219 | 8ecc7913 | j_mayer | CharDriverState *chr) |
1220 | 8ecc7913 | j_mayer | { |
1221 | 8ecc7913 | j_mayer | void *serial;
|
1222 | 8ecc7913 | j_mayer | |
1223 | 8ecc7913 | j_mayer | #ifdef DEBUG_SERIAL
|
1224 | aae9366a | j_mayer | printf("%s: offset " PADDRX "\n", __func__, offset); |
1225 | 8ecc7913 | j_mayer | #endif
|
1226 | 9c02f1a2 | j_mayer | serial = serial_mm_init(offset, 0, irq, chr, 0); |
1227 | 8ecc7913 | j_mayer | ppc4xx_mmio_register(env, mmio, offset, 0x008,
|
1228 | 8ecc7913 | j_mayer | serial_mm_read, serial_mm_write, serial); |
1229 | 8ecc7913 | j_mayer | } |
1230 | 8ecc7913 | j_mayer | |
1231 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
1232 | 8ecc7913 | j_mayer | /* On Chip Memory */
|
1233 | 8ecc7913 | j_mayer | enum {
|
1234 | 8ecc7913 | j_mayer | OCM0_ISARC = 0x018,
|
1235 | 8ecc7913 | j_mayer | OCM0_ISACNTL = 0x019,
|
1236 | 8ecc7913 | j_mayer | OCM0_DSARC = 0x01A,
|
1237 | 8ecc7913 | j_mayer | OCM0_DSACNTL = 0x01B,
|
1238 | 8ecc7913 | j_mayer | }; |
1239 | 8ecc7913 | j_mayer | |
1240 | 8ecc7913 | j_mayer | typedef struct ppc405_ocm_t ppc405_ocm_t; |
1241 | 8ecc7913 | j_mayer | struct ppc405_ocm_t {
|
1242 | 8ecc7913 | j_mayer | target_ulong offset; |
1243 | 8ecc7913 | j_mayer | uint32_t isarc; |
1244 | 8ecc7913 | j_mayer | uint32_t isacntl; |
1245 | 8ecc7913 | j_mayer | uint32_t dsarc; |
1246 | 8ecc7913 | j_mayer | uint32_t dsacntl; |
1247 | 8ecc7913 | j_mayer | }; |
1248 | 8ecc7913 | j_mayer | |
1249 | 8ecc7913 | j_mayer | static void ocm_update_mappings (ppc405_ocm_t *ocm, |
1250 | 8ecc7913 | j_mayer | uint32_t isarc, uint32_t isacntl, |
1251 | 8ecc7913 | j_mayer | uint32_t dsarc, uint32_t dsacntl) |
1252 | 8ecc7913 | j_mayer | { |
1253 | 8ecc7913 | j_mayer | #ifdef DEBUG_OCM
|
1254 | aae9366a | j_mayer | printf("OCM update ISA %08" PRIx32 " %08" PRIx32 " (%08" PRIx32 |
1255 | aae9366a | j_mayer | " %08" PRIx32 ") DSA %08" PRIx32 " %08" PRIx32 |
1256 | aae9366a | j_mayer | " (%08" PRIx32 " %08" PRIx32 ")\n", |
1257 | 8ecc7913 | j_mayer | isarc, isacntl, dsarc, dsacntl, |
1258 | 8ecc7913 | j_mayer | ocm->isarc, ocm->isacntl, ocm->dsarc, ocm->dsacntl); |
1259 | 8ecc7913 | j_mayer | #endif
|
1260 | 8ecc7913 | j_mayer | if (ocm->isarc != isarc ||
|
1261 | 8ecc7913 | j_mayer | (ocm->isacntl & 0x80000000) != (isacntl & 0x80000000)) { |
1262 | 8ecc7913 | j_mayer | if (ocm->isacntl & 0x80000000) { |
1263 | 8ecc7913 | j_mayer | /* Unmap previously assigned memory region */
|
1264 | aae9366a | j_mayer | printf("OCM unmap ISA %08" PRIx32 "\n", ocm->isarc); |
1265 | 8ecc7913 | j_mayer | cpu_register_physical_memory(ocm->isarc, 0x04000000,
|
1266 | 8ecc7913 | j_mayer | IO_MEM_UNASSIGNED); |
1267 | 8ecc7913 | j_mayer | } |
1268 | 8ecc7913 | j_mayer | if (isacntl & 0x80000000) { |
1269 | 8ecc7913 | j_mayer | /* Map new instruction memory region */
|
1270 | 8ecc7913 | j_mayer | #ifdef DEBUG_OCM
|
1271 | aae9366a | j_mayer | printf("OCM map ISA %08" PRIx32 "\n", isarc); |
1272 | 8ecc7913 | j_mayer | #endif
|
1273 | 8ecc7913 | j_mayer | cpu_register_physical_memory(isarc, 0x04000000,
|
1274 | 8ecc7913 | j_mayer | ocm->offset | IO_MEM_RAM); |
1275 | 8ecc7913 | j_mayer | } |
1276 | 8ecc7913 | j_mayer | } |
1277 | 8ecc7913 | j_mayer | if (ocm->dsarc != dsarc ||
|
1278 | 8ecc7913 | j_mayer | (ocm->dsacntl & 0x80000000) != (dsacntl & 0x80000000)) { |
1279 | 8ecc7913 | j_mayer | if (ocm->dsacntl & 0x80000000) { |
1280 | 8ecc7913 | j_mayer | /* Beware not to unmap the region we just mapped */
|
1281 | 8ecc7913 | j_mayer | if (!(isacntl & 0x80000000) || ocm->dsarc != isarc) { |
1282 | 8ecc7913 | j_mayer | /* Unmap previously assigned memory region */
|
1283 | 8ecc7913 | j_mayer | #ifdef DEBUG_OCM
|
1284 | aae9366a | j_mayer | printf("OCM unmap DSA %08" PRIx32 "\n", ocm->dsarc); |
1285 | 8ecc7913 | j_mayer | #endif
|
1286 | 8ecc7913 | j_mayer | cpu_register_physical_memory(ocm->dsarc, 0x04000000,
|
1287 | 8ecc7913 | j_mayer | IO_MEM_UNASSIGNED); |
1288 | 8ecc7913 | j_mayer | } |
1289 | 8ecc7913 | j_mayer | } |
1290 | 8ecc7913 | j_mayer | if (dsacntl & 0x80000000) { |
1291 | 8ecc7913 | j_mayer | /* Beware not to remap the region we just mapped */
|
1292 | 8ecc7913 | j_mayer | if (!(isacntl & 0x80000000) || dsarc != isarc) { |
1293 | 8ecc7913 | j_mayer | /* Map new data memory region */
|
1294 | 8ecc7913 | j_mayer | #ifdef DEBUG_OCM
|
1295 | aae9366a | j_mayer | printf("OCM map DSA %08" PRIx32 "\n", dsarc); |
1296 | 8ecc7913 | j_mayer | #endif
|
1297 | 8ecc7913 | j_mayer | cpu_register_physical_memory(dsarc, 0x04000000,
|
1298 | 8ecc7913 | j_mayer | ocm->offset | IO_MEM_RAM); |
1299 | 8ecc7913 | j_mayer | } |
1300 | 8ecc7913 | j_mayer | } |
1301 | 8ecc7913 | j_mayer | } |
1302 | 8ecc7913 | j_mayer | } |
1303 | 8ecc7913 | j_mayer | |
1304 | 8ecc7913 | j_mayer | static target_ulong dcr_read_ocm (void *opaque, int dcrn) |
1305 | 8ecc7913 | j_mayer | { |
1306 | 8ecc7913 | j_mayer | ppc405_ocm_t *ocm; |
1307 | 8ecc7913 | j_mayer | target_ulong ret; |
1308 | 8ecc7913 | j_mayer | |
1309 | 8ecc7913 | j_mayer | ocm = opaque; |
1310 | 8ecc7913 | j_mayer | switch (dcrn) {
|
1311 | 8ecc7913 | j_mayer | case OCM0_ISARC:
|
1312 | 8ecc7913 | j_mayer | ret = ocm->isarc; |
1313 | 8ecc7913 | j_mayer | break;
|
1314 | 8ecc7913 | j_mayer | case OCM0_ISACNTL:
|
1315 | 8ecc7913 | j_mayer | ret = ocm->isacntl; |
1316 | 8ecc7913 | j_mayer | break;
|
1317 | 8ecc7913 | j_mayer | case OCM0_DSARC:
|
1318 | 8ecc7913 | j_mayer | ret = ocm->dsarc; |
1319 | 8ecc7913 | j_mayer | break;
|
1320 | 8ecc7913 | j_mayer | case OCM0_DSACNTL:
|
1321 | 8ecc7913 | j_mayer | ret = ocm->dsacntl; |
1322 | 8ecc7913 | j_mayer | break;
|
1323 | 8ecc7913 | j_mayer | default:
|
1324 | 8ecc7913 | j_mayer | ret = 0;
|
1325 | 8ecc7913 | j_mayer | break;
|
1326 | 8ecc7913 | j_mayer | } |
1327 | 8ecc7913 | j_mayer | |
1328 | 8ecc7913 | j_mayer | return ret;
|
1329 | 8ecc7913 | j_mayer | } |
1330 | 8ecc7913 | j_mayer | |
1331 | 8ecc7913 | j_mayer | static void dcr_write_ocm (void *opaque, int dcrn, target_ulong val) |
1332 | 8ecc7913 | j_mayer | { |
1333 | 8ecc7913 | j_mayer | ppc405_ocm_t *ocm; |
1334 | 8ecc7913 | j_mayer | uint32_t isarc, dsarc, isacntl, dsacntl; |
1335 | 8ecc7913 | j_mayer | |
1336 | 8ecc7913 | j_mayer | ocm = opaque; |
1337 | 8ecc7913 | j_mayer | isarc = ocm->isarc; |
1338 | 8ecc7913 | j_mayer | dsarc = ocm->dsarc; |
1339 | 8ecc7913 | j_mayer | isacntl = ocm->isacntl; |
1340 | 8ecc7913 | j_mayer | dsacntl = ocm->dsacntl; |
1341 | 8ecc7913 | j_mayer | switch (dcrn) {
|
1342 | 8ecc7913 | j_mayer | case OCM0_ISARC:
|
1343 | 8ecc7913 | j_mayer | isarc = val & 0xFC000000;
|
1344 | 8ecc7913 | j_mayer | break;
|
1345 | 8ecc7913 | j_mayer | case OCM0_ISACNTL:
|
1346 | 8ecc7913 | j_mayer | isacntl = val & 0xC0000000;
|
1347 | 8ecc7913 | j_mayer | break;
|
1348 | 8ecc7913 | j_mayer | case OCM0_DSARC:
|
1349 | 8ecc7913 | j_mayer | isarc = val & 0xFC000000;
|
1350 | 8ecc7913 | j_mayer | break;
|
1351 | 8ecc7913 | j_mayer | case OCM0_DSACNTL:
|
1352 | 8ecc7913 | j_mayer | isacntl = val & 0xC0000000;
|
1353 | 8ecc7913 | j_mayer | break;
|
1354 | 8ecc7913 | j_mayer | } |
1355 | 8ecc7913 | j_mayer | ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl); |
1356 | 8ecc7913 | j_mayer | ocm->isarc = isarc; |
1357 | 8ecc7913 | j_mayer | ocm->dsarc = dsarc; |
1358 | 8ecc7913 | j_mayer | ocm->isacntl = isacntl; |
1359 | 8ecc7913 | j_mayer | ocm->dsacntl = dsacntl; |
1360 | 8ecc7913 | j_mayer | } |
1361 | 8ecc7913 | j_mayer | |
1362 | 8ecc7913 | j_mayer | static void ocm_reset (void *opaque) |
1363 | 8ecc7913 | j_mayer | { |
1364 | 8ecc7913 | j_mayer | ppc405_ocm_t *ocm; |
1365 | 8ecc7913 | j_mayer | uint32_t isarc, dsarc, isacntl, dsacntl; |
1366 | 8ecc7913 | j_mayer | |
1367 | 8ecc7913 | j_mayer | ocm = opaque; |
1368 | 8ecc7913 | j_mayer | isarc = 0x00000000;
|
1369 | 8ecc7913 | j_mayer | isacntl = 0x00000000;
|
1370 | 8ecc7913 | j_mayer | dsarc = 0x00000000;
|
1371 | 8ecc7913 | j_mayer | dsacntl = 0x00000000;
|
1372 | 8ecc7913 | j_mayer | ocm_update_mappings(ocm, isarc, isacntl, dsarc, dsacntl); |
1373 | 8ecc7913 | j_mayer | ocm->isarc = isarc; |
1374 | 8ecc7913 | j_mayer | ocm->dsarc = dsarc; |
1375 | 8ecc7913 | j_mayer | ocm->isacntl = isacntl; |
1376 | 8ecc7913 | j_mayer | ocm->dsacntl = dsacntl; |
1377 | 8ecc7913 | j_mayer | } |
1378 | 8ecc7913 | j_mayer | |
1379 | 8ecc7913 | j_mayer | void ppc405_ocm_init (CPUState *env, unsigned long offset) |
1380 | 8ecc7913 | j_mayer | { |
1381 | 8ecc7913 | j_mayer | ppc405_ocm_t *ocm; |
1382 | 8ecc7913 | j_mayer | |
1383 | 8ecc7913 | j_mayer | ocm = qemu_mallocz(sizeof(ppc405_ocm_t));
|
1384 | 8ecc7913 | j_mayer | if (ocm != NULL) { |
1385 | 8ecc7913 | j_mayer | ocm->offset = offset; |
1386 | 8ecc7913 | j_mayer | ocm_reset(ocm); |
1387 | 8ecc7913 | j_mayer | qemu_register_reset(&ocm_reset, ocm); |
1388 | 8ecc7913 | j_mayer | ppc_dcr_register(env, OCM0_ISARC, |
1389 | 8ecc7913 | j_mayer | ocm, &dcr_read_ocm, &dcr_write_ocm); |
1390 | 8ecc7913 | j_mayer | ppc_dcr_register(env, OCM0_ISACNTL, |
1391 | 8ecc7913 | j_mayer | ocm, &dcr_read_ocm, &dcr_write_ocm); |
1392 | 8ecc7913 | j_mayer | ppc_dcr_register(env, OCM0_DSARC, |
1393 | 8ecc7913 | j_mayer | ocm, &dcr_read_ocm, &dcr_write_ocm); |
1394 | 8ecc7913 | j_mayer | ppc_dcr_register(env, OCM0_DSACNTL, |
1395 | 8ecc7913 | j_mayer | ocm, &dcr_read_ocm, &dcr_write_ocm); |
1396 | 8ecc7913 | j_mayer | } |
1397 | 8ecc7913 | j_mayer | } |
1398 | 8ecc7913 | j_mayer | |
1399 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
1400 | 8ecc7913 | j_mayer | /* I2C controller */
|
1401 | 8ecc7913 | j_mayer | typedef struct ppc4xx_i2c_t ppc4xx_i2c_t; |
1402 | 8ecc7913 | j_mayer | struct ppc4xx_i2c_t {
|
1403 | 9c02f1a2 | j_mayer | target_phys_addr_t base; |
1404 | 9c02f1a2 | j_mayer | qemu_irq irq; |
1405 | 8ecc7913 | j_mayer | uint8_t mdata; |
1406 | 8ecc7913 | j_mayer | uint8_t lmadr; |
1407 | 8ecc7913 | j_mayer | uint8_t hmadr; |
1408 | 8ecc7913 | j_mayer | uint8_t cntl; |
1409 | 8ecc7913 | j_mayer | uint8_t mdcntl; |
1410 | 8ecc7913 | j_mayer | uint8_t sts; |
1411 | 8ecc7913 | j_mayer | uint8_t extsts; |
1412 | 8ecc7913 | j_mayer | uint8_t sdata; |
1413 | 8ecc7913 | j_mayer | uint8_t lsadr; |
1414 | 8ecc7913 | j_mayer | uint8_t hsadr; |
1415 | 8ecc7913 | j_mayer | uint8_t clkdiv; |
1416 | 8ecc7913 | j_mayer | uint8_t intrmsk; |
1417 | 8ecc7913 | j_mayer | uint8_t xfrcnt; |
1418 | 8ecc7913 | j_mayer | uint8_t xtcntlss; |
1419 | 8ecc7913 | j_mayer | uint8_t directcntl; |
1420 | 8ecc7913 | j_mayer | }; |
1421 | 8ecc7913 | j_mayer | |
1422 | 8ecc7913 | j_mayer | static uint32_t ppc4xx_i2c_readb (void *opaque, target_phys_addr_t addr) |
1423 | 8ecc7913 | j_mayer | { |
1424 | 8ecc7913 | j_mayer | ppc4xx_i2c_t *i2c; |
1425 | 8ecc7913 | j_mayer | uint32_t ret; |
1426 | 8ecc7913 | j_mayer | |
1427 | 8ecc7913 | j_mayer | #ifdef DEBUG_I2C
|
1428 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1429 | 8ecc7913 | j_mayer | #endif
|
1430 | 8ecc7913 | j_mayer | i2c = opaque; |
1431 | 8ecc7913 | j_mayer | switch (addr - i2c->base) {
|
1432 | 8ecc7913 | j_mayer | case 0x00: |
1433 | 8ecc7913 | j_mayer | // i2c_readbyte(&i2c->mdata);
|
1434 | 8ecc7913 | j_mayer | ret = i2c->mdata; |
1435 | 8ecc7913 | j_mayer | break;
|
1436 | 8ecc7913 | j_mayer | case 0x02: |
1437 | 8ecc7913 | j_mayer | ret = i2c->sdata; |
1438 | 8ecc7913 | j_mayer | break;
|
1439 | 8ecc7913 | j_mayer | case 0x04: |
1440 | 8ecc7913 | j_mayer | ret = i2c->lmadr; |
1441 | 8ecc7913 | j_mayer | break;
|
1442 | 8ecc7913 | j_mayer | case 0x05: |
1443 | 8ecc7913 | j_mayer | ret = i2c->hmadr; |
1444 | 8ecc7913 | j_mayer | break;
|
1445 | 8ecc7913 | j_mayer | case 0x06: |
1446 | 8ecc7913 | j_mayer | ret = i2c->cntl; |
1447 | 8ecc7913 | j_mayer | break;
|
1448 | 8ecc7913 | j_mayer | case 0x07: |
1449 | 8ecc7913 | j_mayer | ret = i2c->mdcntl; |
1450 | 8ecc7913 | j_mayer | break;
|
1451 | 8ecc7913 | j_mayer | case 0x08: |
1452 | 8ecc7913 | j_mayer | ret = i2c->sts; |
1453 | 8ecc7913 | j_mayer | break;
|
1454 | 8ecc7913 | j_mayer | case 0x09: |
1455 | 8ecc7913 | j_mayer | ret = i2c->extsts; |
1456 | 8ecc7913 | j_mayer | break;
|
1457 | 8ecc7913 | j_mayer | case 0x0A: |
1458 | 8ecc7913 | j_mayer | ret = i2c->lsadr; |
1459 | 8ecc7913 | j_mayer | break;
|
1460 | 8ecc7913 | j_mayer | case 0x0B: |
1461 | 8ecc7913 | j_mayer | ret = i2c->hsadr; |
1462 | 8ecc7913 | j_mayer | break;
|
1463 | 8ecc7913 | j_mayer | case 0x0C: |
1464 | 8ecc7913 | j_mayer | ret = i2c->clkdiv; |
1465 | 8ecc7913 | j_mayer | break;
|
1466 | 8ecc7913 | j_mayer | case 0x0D: |
1467 | 8ecc7913 | j_mayer | ret = i2c->intrmsk; |
1468 | 8ecc7913 | j_mayer | break;
|
1469 | 8ecc7913 | j_mayer | case 0x0E: |
1470 | 8ecc7913 | j_mayer | ret = i2c->xfrcnt; |
1471 | 8ecc7913 | j_mayer | break;
|
1472 | 8ecc7913 | j_mayer | case 0x0F: |
1473 | 8ecc7913 | j_mayer | ret = i2c->xtcntlss; |
1474 | 8ecc7913 | j_mayer | break;
|
1475 | 8ecc7913 | j_mayer | case 0x10: |
1476 | 8ecc7913 | j_mayer | ret = i2c->directcntl; |
1477 | 8ecc7913 | j_mayer | break;
|
1478 | 8ecc7913 | j_mayer | default:
|
1479 | 8ecc7913 | j_mayer | ret = 0x00;
|
1480 | 8ecc7913 | j_mayer | break;
|
1481 | 8ecc7913 | j_mayer | } |
1482 | 8ecc7913 | j_mayer | #ifdef DEBUG_I2C
|
1483 | aae9366a | j_mayer | printf("%s: addr " PADDRX " %02" PRIx32 "\n", __func__, addr, ret); |
1484 | 8ecc7913 | j_mayer | #endif
|
1485 | 8ecc7913 | j_mayer | |
1486 | 8ecc7913 | j_mayer | return ret;
|
1487 | 8ecc7913 | j_mayer | } |
1488 | 8ecc7913 | j_mayer | |
1489 | 8ecc7913 | j_mayer | static void ppc4xx_i2c_writeb (void *opaque, |
1490 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1491 | 8ecc7913 | j_mayer | { |
1492 | 8ecc7913 | j_mayer | ppc4xx_i2c_t *i2c; |
1493 | 8ecc7913 | j_mayer | |
1494 | 8ecc7913 | j_mayer | #ifdef DEBUG_I2C
|
1495 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1496 | 8ecc7913 | j_mayer | #endif
|
1497 | 8ecc7913 | j_mayer | i2c = opaque; |
1498 | 8ecc7913 | j_mayer | switch (addr - i2c->base) {
|
1499 | 8ecc7913 | j_mayer | case 0x00: |
1500 | 8ecc7913 | j_mayer | i2c->mdata = value; |
1501 | 8ecc7913 | j_mayer | // i2c_sendbyte(&i2c->mdata);
|
1502 | 8ecc7913 | j_mayer | break;
|
1503 | 8ecc7913 | j_mayer | case 0x02: |
1504 | 8ecc7913 | j_mayer | i2c->sdata = value; |
1505 | 8ecc7913 | j_mayer | break;
|
1506 | 8ecc7913 | j_mayer | case 0x04: |
1507 | 8ecc7913 | j_mayer | i2c->lmadr = value; |
1508 | 8ecc7913 | j_mayer | break;
|
1509 | 8ecc7913 | j_mayer | case 0x05: |
1510 | 8ecc7913 | j_mayer | i2c->hmadr = value; |
1511 | 8ecc7913 | j_mayer | break;
|
1512 | 8ecc7913 | j_mayer | case 0x06: |
1513 | 8ecc7913 | j_mayer | i2c->cntl = value; |
1514 | 8ecc7913 | j_mayer | break;
|
1515 | 8ecc7913 | j_mayer | case 0x07: |
1516 | 8ecc7913 | j_mayer | i2c->mdcntl = value & 0xDF;
|
1517 | 8ecc7913 | j_mayer | break;
|
1518 | 8ecc7913 | j_mayer | case 0x08: |
1519 | 8ecc7913 | j_mayer | i2c->sts &= ~(value & 0x0A);
|
1520 | 8ecc7913 | j_mayer | break;
|
1521 | 8ecc7913 | j_mayer | case 0x09: |
1522 | 8ecc7913 | j_mayer | i2c->extsts &= ~(value & 0x8F);
|
1523 | 8ecc7913 | j_mayer | break;
|
1524 | 8ecc7913 | j_mayer | case 0x0A: |
1525 | 8ecc7913 | j_mayer | i2c->lsadr = value; |
1526 | 8ecc7913 | j_mayer | break;
|
1527 | 8ecc7913 | j_mayer | case 0x0B: |
1528 | 8ecc7913 | j_mayer | i2c->hsadr = value; |
1529 | 8ecc7913 | j_mayer | break;
|
1530 | 8ecc7913 | j_mayer | case 0x0C: |
1531 | 8ecc7913 | j_mayer | i2c->clkdiv = value; |
1532 | 8ecc7913 | j_mayer | break;
|
1533 | 8ecc7913 | j_mayer | case 0x0D: |
1534 | 8ecc7913 | j_mayer | i2c->intrmsk = value; |
1535 | 8ecc7913 | j_mayer | break;
|
1536 | 8ecc7913 | j_mayer | case 0x0E: |
1537 | 8ecc7913 | j_mayer | i2c->xfrcnt = value & 0x77;
|
1538 | 8ecc7913 | j_mayer | break;
|
1539 | 8ecc7913 | j_mayer | case 0x0F: |
1540 | 8ecc7913 | j_mayer | i2c->xtcntlss = value; |
1541 | 8ecc7913 | j_mayer | break;
|
1542 | 8ecc7913 | j_mayer | case 0x10: |
1543 | 8ecc7913 | j_mayer | i2c->directcntl = value & 0x7;
|
1544 | 8ecc7913 | j_mayer | break;
|
1545 | 8ecc7913 | j_mayer | } |
1546 | 8ecc7913 | j_mayer | } |
1547 | 8ecc7913 | j_mayer | |
1548 | 8ecc7913 | j_mayer | static uint32_t ppc4xx_i2c_readw (void *opaque, target_phys_addr_t addr) |
1549 | 8ecc7913 | j_mayer | { |
1550 | 8ecc7913 | j_mayer | uint32_t ret; |
1551 | 8ecc7913 | j_mayer | |
1552 | 8ecc7913 | j_mayer | #ifdef DEBUG_I2C
|
1553 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1554 | 8ecc7913 | j_mayer | #endif
|
1555 | 8ecc7913 | j_mayer | ret = ppc4xx_i2c_readb(opaque, addr) << 8;
|
1556 | 8ecc7913 | j_mayer | ret |= ppc4xx_i2c_readb(opaque, addr + 1);
|
1557 | 8ecc7913 | j_mayer | |
1558 | 8ecc7913 | j_mayer | return ret;
|
1559 | 8ecc7913 | j_mayer | } |
1560 | 8ecc7913 | j_mayer | |
1561 | 8ecc7913 | j_mayer | static void ppc4xx_i2c_writew (void *opaque, |
1562 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1563 | 8ecc7913 | j_mayer | { |
1564 | 8ecc7913 | j_mayer | #ifdef DEBUG_I2C
|
1565 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1566 | 8ecc7913 | j_mayer | #endif
|
1567 | 8ecc7913 | j_mayer | ppc4xx_i2c_writeb(opaque, addr, value >> 8);
|
1568 | 8ecc7913 | j_mayer | ppc4xx_i2c_writeb(opaque, addr + 1, value);
|
1569 | 8ecc7913 | j_mayer | } |
1570 | 8ecc7913 | j_mayer | |
1571 | 8ecc7913 | j_mayer | static uint32_t ppc4xx_i2c_readl (void *opaque, target_phys_addr_t addr) |
1572 | 8ecc7913 | j_mayer | { |
1573 | 8ecc7913 | j_mayer | uint32_t ret; |
1574 | 8ecc7913 | j_mayer | |
1575 | 8ecc7913 | j_mayer | #ifdef DEBUG_I2C
|
1576 | 8ecc7913 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1577 | 8ecc7913 | j_mayer | #endif
|
1578 | 8ecc7913 | j_mayer | ret = ppc4xx_i2c_readb(opaque, addr) << 24;
|
1579 | 8ecc7913 | j_mayer | ret |= ppc4xx_i2c_readb(opaque, addr + 1) << 16; |
1580 | 8ecc7913 | j_mayer | ret |= ppc4xx_i2c_readb(opaque, addr + 2) << 8; |
1581 | 8ecc7913 | j_mayer | ret |= ppc4xx_i2c_readb(opaque, addr + 3);
|
1582 | 8ecc7913 | j_mayer | |
1583 | 8ecc7913 | j_mayer | return ret;
|
1584 | 8ecc7913 | j_mayer | } |
1585 | 8ecc7913 | j_mayer | |
1586 | 8ecc7913 | j_mayer | static void ppc4xx_i2c_writel (void *opaque, |
1587 | 8ecc7913 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1588 | 8ecc7913 | j_mayer | { |
1589 | 8ecc7913 | j_mayer | #ifdef DEBUG_I2C
|
1590 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1591 | 8ecc7913 | j_mayer | #endif
|
1592 | 8ecc7913 | j_mayer | ppc4xx_i2c_writeb(opaque, addr, value >> 24);
|
1593 | 8ecc7913 | j_mayer | ppc4xx_i2c_writeb(opaque, addr + 1, value >> 16); |
1594 | 8ecc7913 | j_mayer | ppc4xx_i2c_writeb(opaque, addr + 2, value >> 8); |
1595 | 8ecc7913 | j_mayer | ppc4xx_i2c_writeb(opaque, addr + 3, value);
|
1596 | 8ecc7913 | j_mayer | } |
1597 | 8ecc7913 | j_mayer | |
1598 | 8ecc7913 | j_mayer | static CPUReadMemoryFunc *i2c_read[] = {
|
1599 | 8ecc7913 | j_mayer | &ppc4xx_i2c_readb, |
1600 | 8ecc7913 | j_mayer | &ppc4xx_i2c_readw, |
1601 | 8ecc7913 | j_mayer | &ppc4xx_i2c_readl, |
1602 | 8ecc7913 | j_mayer | }; |
1603 | 8ecc7913 | j_mayer | |
1604 | 8ecc7913 | j_mayer | static CPUWriteMemoryFunc *i2c_write[] = {
|
1605 | 8ecc7913 | j_mayer | &ppc4xx_i2c_writeb, |
1606 | 8ecc7913 | j_mayer | &ppc4xx_i2c_writew, |
1607 | 8ecc7913 | j_mayer | &ppc4xx_i2c_writel, |
1608 | 8ecc7913 | j_mayer | }; |
1609 | 8ecc7913 | j_mayer | |
1610 | 8ecc7913 | j_mayer | static void ppc4xx_i2c_reset (void *opaque) |
1611 | 8ecc7913 | j_mayer | { |
1612 | 8ecc7913 | j_mayer | ppc4xx_i2c_t *i2c; |
1613 | 8ecc7913 | j_mayer | |
1614 | 8ecc7913 | j_mayer | i2c = opaque; |
1615 | 8ecc7913 | j_mayer | i2c->mdata = 0x00;
|
1616 | 8ecc7913 | j_mayer | i2c->sdata = 0x00;
|
1617 | 8ecc7913 | j_mayer | i2c->cntl = 0x00;
|
1618 | 8ecc7913 | j_mayer | i2c->mdcntl = 0x00;
|
1619 | 8ecc7913 | j_mayer | i2c->sts = 0x00;
|
1620 | 8ecc7913 | j_mayer | i2c->extsts = 0x00;
|
1621 | 8ecc7913 | j_mayer | i2c->clkdiv = 0x00;
|
1622 | 8ecc7913 | j_mayer | i2c->xfrcnt = 0x00;
|
1623 | 8ecc7913 | j_mayer | i2c->directcntl = 0x0F;
|
1624 | 8ecc7913 | j_mayer | } |
1625 | 8ecc7913 | j_mayer | |
1626 | 9c02f1a2 | j_mayer | void ppc405_i2c_init (CPUState *env, ppc4xx_mmio_t *mmio,
|
1627 | 9c02f1a2 | j_mayer | target_phys_addr_t offset, qemu_irq irq) |
1628 | 8ecc7913 | j_mayer | { |
1629 | 8ecc7913 | j_mayer | ppc4xx_i2c_t *i2c; |
1630 | 8ecc7913 | j_mayer | |
1631 | 8ecc7913 | j_mayer | i2c = qemu_mallocz(sizeof(ppc4xx_i2c_t));
|
1632 | 8ecc7913 | j_mayer | if (i2c != NULL) { |
1633 | 9c02f1a2 | j_mayer | i2c->base = offset; |
1634 | 9c02f1a2 | j_mayer | i2c->irq = irq; |
1635 | 8ecc7913 | j_mayer | ppc4xx_i2c_reset(i2c); |
1636 | 8ecc7913 | j_mayer | #ifdef DEBUG_I2C
|
1637 | aae9366a | j_mayer | printf("%s: offset " PADDRX "\n", __func__, offset); |
1638 | 8ecc7913 | j_mayer | #endif
|
1639 | 8ecc7913 | j_mayer | ppc4xx_mmio_register(env, mmio, offset, 0x011,
|
1640 | 8ecc7913 | j_mayer | i2c_read, i2c_write, i2c); |
1641 | 8ecc7913 | j_mayer | qemu_register_reset(ppc4xx_i2c_reset, i2c); |
1642 | 8ecc7913 | j_mayer | } |
1643 | 8ecc7913 | j_mayer | } |
1644 | 8ecc7913 | j_mayer | |
1645 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
1646 | 9c02f1a2 | j_mayer | /* General purpose timers */
|
1647 | 9c02f1a2 | j_mayer | typedef struct ppc4xx_gpt_t ppc4xx_gpt_t; |
1648 | 9c02f1a2 | j_mayer | struct ppc4xx_gpt_t {
|
1649 | 9c02f1a2 | j_mayer | target_phys_addr_t base; |
1650 | 9c02f1a2 | j_mayer | int64_t tb_offset; |
1651 | 9c02f1a2 | j_mayer | uint32_t tb_freq; |
1652 | 9c02f1a2 | j_mayer | struct QEMUTimer *timer;
|
1653 | 9c02f1a2 | j_mayer | qemu_irq irqs[5];
|
1654 | 9c02f1a2 | j_mayer | uint32_t oe; |
1655 | 9c02f1a2 | j_mayer | uint32_t ol; |
1656 | 9c02f1a2 | j_mayer | uint32_t im; |
1657 | 9c02f1a2 | j_mayer | uint32_t is; |
1658 | 9c02f1a2 | j_mayer | uint32_t ie; |
1659 | 9c02f1a2 | j_mayer | uint32_t comp[5];
|
1660 | 9c02f1a2 | j_mayer | uint32_t mask[5];
|
1661 | 9c02f1a2 | j_mayer | }; |
1662 | 9c02f1a2 | j_mayer | |
1663 | 9c02f1a2 | j_mayer | static uint32_t ppc4xx_gpt_readb (void *opaque, target_phys_addr_t addr) |
1664 | 9c02f1a2 | j_mayer | { |
1665 | 9c02f1a2 | j_mayer | #ifdef DEBUG_GPT
|
1666 | 9c02f1a2 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1667 | 9c02f1a2 | j_mayer | #endif
|
1668 | 9c02f1a2 | j_mayer | /* XXX: generate a bus fault */
|
1669 | 9c02f1a2 | j_mayer | return -1; |
1670 | 9c02f1a2 | j_mayer | } |
1671 | 9c02f1a2 | j_mayer | |
1672 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_writeb (void *opaque, |
1673 | 9c02f1a2 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1674 | 9c02f1a2 | j_mayer | { |
1675 | 9c02f1a2 | j_mayer | #ifdef DEBUG_I2C
|
1676 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1677 | 9c02f1a2 | j_mayer | #endif
|
1678 | 9c02f1a2 | j_mayer | /* XXX: generate a bus fault */
|
1679 | 9c02f1a2 | j_mayer | } |
1680 | 9c02f1a2 | j_mayer | |
1681 | 9c02f1a2 | j_mayer | static uint32_t ppc4xx_gpt_readw (void *opaque, target_phys_addr_t addr) |
1682 | 9c02f1a2 | j_mayer | { |
1683 | 9c02f1a2 | j_mayer | #ifdef DEBUG_GPT
|
1684 | 9c02f1a2 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1685 | 9c02f1a2 | j_mayer | #endif
|
1686 | 9c02f1a2 | j_mayer | /* XXX: generate a bus fault */
|
1687 | 9c02f1a2 | j_mayer | return -1; |
1688 | 9c02f1a2 | j_mayer | } |
1689 | 9c02f1a2 | j_mayer | |
1690 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_writew (void *opaque, |
1691 | 9c02f1a2 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1692 | 9c02f1a2 | j_mayer | { |
1693 | 9c02f1a2 | j_mayer | #ifdef DEBUG_I2C
|
1694 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1695 | 9c02f1a2 | j_mayer | #endif
|
1696 | 9c02f1a2 | j_mayer | /* XXX: generate a bus fault */
|
1697 | 9c02f1a2 | j_mayer | } |
1698 | 9c02f1a2 | j_mayer | |
1699 | 9c02f1a2 | j_mayer | static int ppc4xx_gpt_compare (ppc4xx_gpt_t *gpt, int n) |
1700 | 9c02f1a2 | j_mayer | { |
1701 | 9c02f1a2 | j_mayer | /* XXX: TODO */
|
1702 | 9c02f1a2 | j_mayer | return 0; |
1703 | 9c02f1a2 | j_mayer | } |
1704 | 9c02f1a2 | j_mayer | |
1705 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_set_output (ppc4xx_gpt_t *gpt, int n, int level) |
1706 | 9c02f1a2 | j_mayer | { |
1707 | 9c02f1a2 | j_mayer | /* XXX: TODO */
|
1708 | 9c02f1a2 | j_mayer | } |
1709 | 9c02f1a2 | j_mayer | |
1710 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_set_outputs (ppc4xx_gpt_t *gpt) |
1711 | 9c02f1a2 | j_mayer | { |
1712 | 9c02f1a2 | j_mayer | uint32_t mask; |
1713 | 9c02f1a2 | j_mayer | int i;
|
1714 | 9c02f1a2 | j_mayer | |
1715 | 9c02f1a2 | j_mayer | mask = 0x80000000;
|
1716 | 9c02f1a2 | j_mayer | for (i = 0; i < 5; i++) { |
1717 | 9c02f1a2 | j_mayer | if (gpt->oe & mask) {
|
1718 | 9c02f1a2 | j_mayer | /* Output is enabled */
|
1719 | 9c02f1a2 | j_mayer | if (ppc4xx_gpt_compare(gpt, i)) {
|
1720 | 9c02f1a2 | j_mayer | /* Comparison is OK */
|
1721 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask); |
1722 | 9c02f1a2 | j_mayer | } else {
|
1723 | 9c02f1a2 | j_mayer | /* Comparison is KO */
|
1724 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_output(gpt, i, gpt->ol & mask ? 0 : 1); |
1725 | 9c02f1a2 | j_mayer | } |
1726 | 9c02f1a2 | j_mayer | } |
1727 | 9c02f1a2 | j_mayer | mask = mask >> 1;
|
1728 | 9c02f1a2 | j_mayer | } |
1729 | 9c02f1a2 | j_mayer | } |
1730 | 9c02f1a2 | j_mayer | |
1731 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_set_irqs (ppc4xx_gpt_t *gpt) |
1732 | 9c02f1a2 | j_mayer | { |
1733 | 9c02f1a2 | j_mayer | uint32_t mask; |
1734 | 9c02f1a2 | j_mayer | int i;
|
1735 | 9c02f1a2 | j_mayer | |
1736 | 9c02f1a2 | j_mayer | mask = 0x00008000;
|
1737 | 9c02f1a2 | j_mayer | for (i = 0; i < 5; i++) { |
1738 | 9c02f1a2 | j_mayer | if (gpt->is & gpt->im & mask)
|
1739 | 9c02f1a2 | j_mayer | qemu_irq_raise(gpt->irqs[i]); |
1740 | 9c02f1a2 | j_mayer | else
|
1741 | 9c02f1a2 | j_mayer | qemu_irq_lower(gpt->irqs[i]); |
1742 | 9c02f1a2 | j_mayer | mask = mask >> 1;
|
1743 | 9c02f1a2 | j_mayer | } |
1744 | 9c02f1a2 | j_mayer | } |
1745 | 9c02f1a2 | j_mayer | |
1746 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_compute_timer (ppc4xx_gpt_t *gpt) |
1747 | 9c02f1a2 | j_mayer | { |
1748 | 9c02f1a2 | j_mayer | /* XXX: TODO */
|
1749 | 9c02f1a2 | j_mayer | } |
1750 | 9c02f1a2 | j_mayer | |
1751 | 9c02f1a2 | j_mayer | static uint32_t ppc4xx_gpt_readl (void *opaque, target_phys_addr_t addr) |
1752 | 9c02f1a2 | j_mayer | { |
1753 | 9c02f1a2 | j_mayer | ppc4xx_gpt_t *gpt; |
1754 | 9c02f1a2 | j_mayer | uint32_t ret; |
1755 | 9c02f1a2 | j_mayer | int idx;
|
1756 | 9c02f1a2 | j_mayer | |
1757 | 9c02f1a2 | j_mayer | #ifdef DEBUG_GPT
|
1758 | 9c02f1a2 | j_mayer | printf("%s: addr " PADDRX "\n", __func__, addr); |
1759 | 9c02f1a2 | j_mayer | #endif
|
1760 | 9c02f1a2 | j_mayer | gpt = opaque; |
1761 | 9c02f1a2 | j_mayer | switch (addr - gpt->base) {
|
1762 | 9c02f1a2 | j_mayer | case 0x00: |
1763 | 9c02f1a2 | j_mayer | /* Time base counter */
|
1764 | 9c02f1a2 | j_mayer | ret = muldiv64(qemu_get_clock(vm_clock) + gpt->tb_offset, |
1765 | 9c02f1a2 | j_mayer | gpt->tb_freq, ticks_per_sec); |
1766 | 9c02f1a2 | j_mayer | break;
|
1767 | 9c02f1a2 | j_mayer | case 0x10: |
1768 | 9c02f1a2 | j_mayer | /* Output enable */
|
1769 | 9c02f1a2 | j_mayer | ret = gpt->oe; |
1770 | 9c02f1a2 | j_mayer | break;
|
1771 | 9c02f1a2 | j_mayer | case 0x14: |
1772 | 9c02f1a2 | j_mayer | /* Output level */
|
1773 | 9c02f1a2 | j_mayer | ret = gpt->ol; |
1774 | 9c02f1a2 | j_mayer | break;
|
1775 | 9c02f1a2 | j_mayer | case 0x18: |
1776 | 9c02f1a2 | j_mayer | /* Interrupt mask */
|
1777 | 9c02f1a2 | j_mayer | ret = gpt->im; |
1778 | 9c02f1a2 | j_mayer | break;
|
1779 | 9c02f1a2 | j_mayer | case 0x1C: |
1780 | 9c02f1a2 | j_mayer | case 0x20: |
1781 | 9c02f1a2 | j_mayer | /* Interrupt status */
|
1782 | 9c02f1a2 | j_mayer | ret = gpt->is; |
1783 | 9c02f1a2 | j_mayer | break;
|
1784 | 9c02f1a2 | j_mayer | case 0x24: |
1785 | 9c02f1a2 | j_mayer | /* Interrupt enable */
|
1786 | 9c02f1a2 | j_mayer | ret = gpt->ie; |
1787 | 9c02f1a2 | j_mayer | break;
|
1788 | 9c02f1a2 | j_mayer | case 0x80 ... 0x90: |
1789 | 9c02f1a2 | j_mayer | /* Compare timer */
|
1790 | 9c02f1a2 | j_mayer | idx = ((addr - gpt->base) - 0x80) >> 2; |
1791 | 9c02f1a2 | j_mayer | ret = gpt->comp[idx]; |
1792 | 9c02f1a2 | j_mayer | break;
|
1793 | 9c02f1a2 | j_mayer | case 0xC0 ... 0xD0: |
1794 | 9c02f1a2 | j_mayer | /* Compare mask */
|
1795 | 9c02f1a2 | j_mayer | idx = ((addr - gpt->base) - 0xC0) >> 2; |
1796 | 9c02f1a2 | j_mayer | ret = gpt->mask[idx]; |
1797 | 9c02f1a2 | j_mayer | break;
|
1798 | 9c02f1a2 | j_mayer | default:
|
1799 | 9c02f1a2 | j_mayer | ret = -1;
|
1800 | 9c02f1a2 | j_mayer | break;
|
1801 | 9c02f1a2 | j_mayer | } |
1802 | 9c02f1a2 | j_mayer | |
1803 | 9c02f1a2 | j_mayer | return ret;
|
1804 | 9c02f1a2 | j_mayer | } |
1805 | 9c02f1a2 | j_mayer | |
1806 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_writel (void *opaque, |
1807 | 9c02f1a2 | j_mayer | target_phys_addr_t addr, uint32_t value) |
1808 | 9c02f1a2 | j_mayer | { |
1809 | 9c02f1a2 | j_mayer | ppc4xx_gpt_t *gpt; |
1810 | 9c02f1a2 | j_mayer | int idx;
|
1811 | 9c02f1a2 | j_mayer | |
1812 | 9c02f1a2 | j_mayer | #ifdef DEBUG_I2C
|
1813 | aae9366a | j_mayer | printf("%s: addr " PADDRX " val %08" PRIx32 "\n", __func__, addr, value); |
1814 | 9c02f1a2 | j_mayer | #endif
|
1815 | 9c02f1a2 | j_mayer | gpt = opaque; |
1816 | 9c02f1a2 | j_mayer | switch (addr - gpt->base) {
|
1817 | 9c02f1a2 | j_mayer | case 0x00: |
1818 | 9c02f1a2 | j_mayer | /* Time base counter */
|
1819 | 9c02f1a2 | j_mayer | gpt->tb_offset = muldiv64(value, ticks_per_sec, gpt->tb_freq) |
1820 | 9c02f1a2 | j_mayer | - qemu_get_clock(vm_clock); |
1821 | 9c02f1a2 | j_mayer | ppc4xx_gpt_compute_timer(gpt); |
1822 | 9c02f1a2 | j_mayer | break;
|
1823 | 9c02f1a2 | j_mayer | case 0x10: |
1824 | 9c02f1a2 | j_mayer | /* Output enable */
|
1825 | 9c02f1a2 | j_mayer | gpt->oe = value & 0xF8000000;
|
1826 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_outputs(gpt); |
1827 | 9c02f1a2 | j_mayer | break;
|
1828 | 9c02f1a2 | j_mayer | case 0x14: |
1829 | 9c02f1a2 | j_mayer | /* Output level */
|
1830 | 9c02f1a2 | j_mayer | gpt->ol = value & 0xF8000000;
|
1831 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_outputs(gpt); |
1832 | 9c02f1a2 | j_mayer | break;
|
1833 | 9c02f1a2 | j_mayer | case 0x18: |
1834 | 9c02f1a2 | j_mayer | /* Interrupt mask */
|
1835 | 9c02f1a2 | j_mayer | gpt->im = value & 0x0000F800;
|
1836 | 9c02f1a2 | j_mayer | break;
|
1837 | 9c02f1a2 | j_mayer | case 0x1C: |
1838 | 9c02f1a2 | j_mayer | /* Interrupt status set */
|
1839 | 9c02f1a2 | j_mayer | gpt->is |= value & 0x0000F800;
|
1840 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_irqs(gpt); |
1841 | 9c02f1a2 | j_mayer | break;
|
1842 | 9c02f1a2 | j_mayer | case 0x20: |
1843 | 9c02f1a2 | j_mayer | /* Interrupt status clear */
|
1844 | 9c02f1a2 | j_mayer | gpt->is &= ~(value & 0x0000F800);
|
1845 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_irqs(gpt); |
1846 | 9c02f1a2 | j_mayer | break;
|
1847 | 9c02f1a2 | j_mayer | case 0x24: |
1848 | 9c02f1a2 | j_mayer | /* Interrupt enable */
|
1849 | 9c02f1a2 | j_mayer | gpt->ie = value & 0x0000F800;
|
1850 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_irqs(gpt); |
1851 | 9c02f1a2 | j_mayer | break;
|
1852 | 9c02f1a2 | j_mayer | case 0x80 ... 0x90: |
1853 | 9c02f1a2 | j_mayer | /* Compare timer */
|
1854 | 9c02f1a2 | j_mayer | idx = ((addr - gpt->base) - 0x80) >> 2; |
1855 | 9c02f1a2 | j_mayer | gpt->comp[idx] = value & 0xF8000000;
|
1856 | 9c02f1a2 | j_mayer | ppc4xx_gpt_compute_timer(gpt); |
1857 | 9c02f1a2 | j_mayer | break;
|
1858 | 9c02f1a2 | j_mayer | case 0xC0 ... 0xD0: |
1859 | 9c02f1a2 | j_mayer | /* Compare mask */
|
1860 | 9c02f1a2 | j_mayer | idx = ((addr - gpt->base) - 0xC0) >> 2; |
1861 | 9c02f1a2 | j_mayer | gpt->mask[idx] = value & 0xF8000000;
|
1862 | 9c02f1a2 | j_mayer | ppc4xx_gpt_compute_timer(gpt); |
1863 | 9c02f1a2 | j_mayer | break;
|
1864 | 9c02f1a2 | j_mayer | } |
1865 | 9c02f1a2 | j_mayer | } |
1866 | 9c02f1a2 | j_mayer | |
1867 | 9c02f1a2 | j_mayer | static CPUReadMemoryFunc *gpt_read[] = {
|
1868 | 9c02f1a2 | j_mayer | &ppc4xx_gpt_readb, |
1869 | 9c02f1a2 | j_mayer | &ppc4xx_gpt_readw, |
1870 | 9c02f1a2 | j_mayer | &ppc4xx_gpt_readl, |
1871 | 9c02f1a2 | j_mayer | }; |
1872 | 9c02f1a2 | j_mayer | |
1873 | 9c02f1a2 | j_mayer | static CPUWriteMemoryFunc *gpt_write[] = {
|
1874 | 9c02f1a2 | j_mayer | &ppc4xx_gpt_writeb, |
1875 | 9c02f1a2 | j_mayer | &ppc4xx_gpt_writew, |
1876 | 9c02f1a2 | j_mayer | &ppc4xx_gpt_writel, |
1877 | 9c02f1a2 | j_mayer | }; |
1878 | 9c02f1a2 | j_mayer | |
1879 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_cb (void *opaque) |
1880 | 9c02f1a2 | j_mayer | { |
1881 | 9c02f1a2 | j_mayer | ppc4xx_gpt_t *gpt; |
1882 | 9c02f1a2 | j_mayer | |
1883 | 9c02f1a2 | j_mayer | gpt = opaque; |
1884 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_irqs(gpt); |
1885 | 9c02f1a2 | j_mayer | ppc4xx_gpt_set_outputs(gpt); |
1886 | 9c02f1a2 | j_mayer | ppc4xx_gpt_compute_timer(gpt); |
1887 | 9c02f1a2 | j_mayer | } |
1888 | 9c02f1a2 | j_mayer | |
1889 | 9c02f1a2 | j_mayer | static void ppc4xx_gpt_reset (void *opaque) |
1890 | 9c02f1a2 | j_mayer | { |
1891 | 9c02f1a2 | j_mayer | ppc4xx_gpt_t *gpt; |
1892 | 9c02f1a2 | j_mayer | int i;
|
1893 | 9c02f1a2 | j_mayer | |
1894 | 9c02f1a2 | j_mayer | gpt = opaque; |
1895 | 9c02f1a2 | j_mayer | qemu_del_timer(gpt->timer); |
1896 | 9c02f1a2 | j_mayer | gpt->oe = 0x00000000;
|
1897 | 9c02f1a2 | j_mayer | gpt->ol = 0x00000000;
|
1898 | 9c02f1a2 | j_mayer | gpt->im = 0x00000000;
|
1899 | 9c02f1a2 | j_mayer | gpt->is = 0x00000000;
|
1900 | 9c02f1a2 | j_mayer | gpt->ie = 0x00000000;
|
1901 | 9c02f1a2 | j_mayer | for (i = 0; i < 5; i++) { |
1902 | 9c02f1a2 | j_mayer | gpt->comp[i] = 0x00000000;
|
1903 | 9c02f1a2 | j_mayer | gpt->mask[i] = 0x00000000;
|
1904 | 9c02f1a2 | j_mayer | } |
1905 | 9c02f1a2 | j_mayer | } |
1906 | 9c02f1a2 | j_mayer | |
1907 | 9c02f1a2 | j_mayer | void ppc4xx_gpt_init (CPUState *env, ppc4xx_mmio_t *mmio,
|
1908 | 9c02f1a2 | j_mayer | target_phys_addr_t offset, qemu_irq irqs[5])
|
1909 | 9c02f1a2 | j_mayer | { |
1910 | 9c02f1a2 | j_mayer | ppc4xx_gpt_t *gpt; |
1911 | 9c02f1a2 | j_mayer | int i;
|
1912 | 9c02f1a2 | j_mayer | |
1913 | 9c02f1a2 | j_mayer | gpt = qemu_mallocz(sizeof(ppc4xx_gpt_t));
|
1914 | 9c02f1a2 | j_mayer | if (gpt != NULL) { |
1915 | 9c02f1a2 | j_mayer | gpt->base = offset; |
1916 | 9c02f1a2 | j_mayer | for (i = 0; i < 5; i++) |
1917 | 9c02f1a2 | j_mayer | gpt->irqs[i] = irqs[i]; |
1918 | 9c02f1a2 | j_mayer | gpt->timer = qemu_new_timer(vm_clock, &ppc4xx_gpt_cb, gpt); |
1919 | 9c02f1a2 | j_mayer | ppc4xx_gpt_reset(gpt); |
1920 | 9c02f1a2 | j_mayer | #ifdef DEBUG_GPT
|
1921 | aae9366a | j_mayer | printf("%s: offset " PADDRX "\n", __func__, offset); |
1922 | 9c02f1a2 | j_mayer | #endif
|
1923 | 9c02f1a2 | j_mayer | ppc4xx_mmio_register(env, mmio, offset, 0x0D4,
|
1924 | 9c02f1a2 | j_mayer | gpt_read, gpt_write, gpt); |
1925 | 9c02f1a2 | j_mayer | qemu_register_reset(ppc4xx_gpt_reset, gpt); |
1926 | 9c02f1a2 | j_mayer | } |
1927 | 9c02f1a2 | j_mayer | } |
1928 | 9c02f1a2 | j_mayer | |
1929 | 9c02f1a2 | j_mayer | /*****************************************************************************/
|
1930 | 9c02f1a2 | j_mayer | /* MAL */
|
1931 | 9c02f1a2 | j_mayer | enum {
|
1932 | 9c02f1a2 | j_mayer | MAL0_CFG = 0x180,
|
1933 | 9c02f1a2 | j_mayer | MAL0_ESR = 0x181,
|
1934 | 9c02f1a2 | j_mayer | MAL0_IER = 0x182,
|
1935 | 9c02f1a2 | j_mayer | MAL0_TXCASR = 0x184,
|
1936 | 9c02f1a2 | j_mayer | MAL0_TXCARR = 0x185,
|
1937 | 9c02f1a2 | j_mayer | MAL0_TXEOBISR = 0x186,
|
1938 | 9c02f1a2 | j_mayer | MAL0_TXDEIR = 0x187,
|
1939 | 9c02f1a2 | j_mayer | MAL0_RXCASR = 0x190,
|
1940 | 9c02f1a2 | j_mayer | MAL0_RXCARR = 0x191,
|
1941 | 9c02f1a2 | j_mayer | MAL0_RXEOBISR = 0x192,
|
1942 | 9c02f1a2 | j_mayer | MAL0_RXDEIR = 0x193,
|
1943 | 9c02f1a2 | j_mayer | MAL0_TXCTP0R = 0x1A0,
|
1944 | 9c02f1a2 | j_mayer | MAL0_TXCTP1R = 0x1A1,
|
1945 | 9c02f1a2 | j_mayer | MAL0_TXCTP2R = 0x1A2,
|
1946 | 9c02f1a2 | j_mayer | MAL0_TXCTP3R = 0x1A3,
|
1947 | 9c02f1a2 | j_mayer | MAL0_RXCTP0R = 0x1C0,
|
1948 | 9c02f1a2 | j_mayer | MAL0_RXCTP1R = 0x1C1,
|
1949 | 9c02f1a2 | j_mayer | MAL0_RCBS0 = 0x1E0,
|
1950 | 9c02f1a2 | j_mayer | MAL0_RCBS1 = 0x1E1,
|
1951 | 9c02f1a2 | j_mayer | }; |
1952 | 9c02f1a2 | j_mayer | |
1953 | 9c02f1a2 | j_mayer | typedef struct ppc40x_mal_t ppc40x_mal_t; |
1954 | 9c02f1a2 | j_mayer | struct ppc40x_mal_t {
|
1955 | 9c02f1a2 | j_mayer | qemu_irq irqs[4];
|
1956 | 9c02f1a2 | j_mayer | uint32_t cfg; |
1957 | 9c02f1a2 | j_mayer | uint32_t esr; |
1958 | 9c02f1a2 | j_mayer | uint32_t ier; |
1959 | 9c02f1a2 | j_mayer | uint32_t txcasr; |
1960 | 9c02f1a2 | j_mayer | uint32_t txcarr; |
1961 | 9c02f1a2 | j_mayer | uint32_t txeobisr; |
1962 | 9c02f1a2 | j_mayer | uint32_t txdeir; |
1963 | 9c02f1a2 | j_mayer | uint32_t rxcasr; |
1964 | 9c02f1a2 | j_mayer | uint32_t rxcarr; |
1965 | 9c02f1a2 | j_mayer | uint32_t rxeobisr; |
1966 | 9c02f1a2 | j_mayer | uint32_t rxdeir; |
1967 | 9c02f1a2 | j_mayer | uint32_t txctpr[4];
|
1968 | 9c02f1a2 | j_mayer | uint32_t rxctpr[2];
|
1969 | 9c02f1a2 | j_mayer | uint32_t rcbs[2];
|
1970 | 9c02f1a2 | j_mayer | }; |
1971 | 9c02f1a2 | j_mayer | |
1972 | 9c02f1a2 | j_mayer | static void ppc40x_mal_reset (void *opaque); |
1973 | 9c02f1a2 | j_mayer | |
1974 | 9c02f1a2 | j_mayer | static target_ulong dcr_read_mal (void *opaque, int dcrn) |
1975 | 9c02f1a2 | j_mayer | { |
1976 | 9c02f1a2 | j_mayer | ppc40x_mal_t *mal; |
1977 | 9c02f1a2 | j_mayer | target_ulong ret; |
1978 | 9c02f1a2 | j_mayer | |
1979 | 9c02f1a2 | j_mayer | mal = opaque; |
1980 | 9c02f1a2 | j_mayer | switch (dcrn) {
|
1981 | 9c02f1a2 | j_mayer | case MAL0_CFG:
|
1982 | 9c02f1a2 | j_mayer | ret = mal->cfg; |
1983 | 9c02f1a2 | j_mayer | break;
|
1984 | 9c02f1a2 | j_mayer | case MAL0_ESR:
|
1985 | 9c02f1a2 | j_mayer | ret = mal->esr; |
1986 | 9c02f1a2 | j_mayer | break;
|
1987 | 9c02f1a2 | j_mayer | case MAL0_IER:
|
1988 | 9c02f1a2 | j_mayer | ret = mal->ier; |
1989 | 9c02f1a2 | j_mayer | break;
|
1990 | 9c02f1a2 | j_mayer | case MAL0_TXCASR:
|
1991 | 9c02f1a2 | j_mayer | ret = mal->txcasr; |
1992 | 9c02f1a2 | j_mayer | break;
|
1993 | 9c02f1a2 | j_mayer | case MAL0_TXCARR:
|
1994 | 9c02f1a2 | j_mayer | ret = mal->txcarr; |
1995 | 9c02f1a2 | j_mayer | break;
|
1996 | 9c02f1a2 | j_mayer | case MAL0_TXEOBISR:
|
1997 | 9c02f1a2 | j_mayer | ret = mal->txeobisr; |
1998 | 9c02f1a2 | j_mayer | break;
|
1999 | 9c02f1a2 | j_mayer | case MAL0_TXDEIR:
|
2000 | 9c02f1a2 | j_mayer | ret = mal->txdeir; |
2001 | 9c02f1a2 | j_mayer | break;
|
2002 | 9c02f1a2 | j_mayer | case MAL0_RXCASR:
|
2003 | 9c02f1a2 | j_mayer | ret = mal->rxcasr; |
2004 | 9c02f1a2 | j_mayer | break;
|
2005 | 9c02f1a2 | j_mayer | case MAL0_RXCARR:
|
2006 | 9c02f1a2 | j_mayer | ret = mal->rxcarr; |
2007 | 9c02f1a2 | j_mayer | break;
|
2008 | 9c02f1a2 | j_mayer | case MAL0_RXEOBISR:
|
2009 | 9c02f1a2 | j_mayer | ret = mal->rxeobisr; |
2010 | 9c02f1a2 | j_mayer | break;
|
2011 | 9c02f1a2 | j_mayer | case MAL0_RXDEIR:
|
2012 | 9c02f1a2 | j_mayer | ret = mal->rxdeir; |
2013 | 9c02f1a2 | j_mayer | break;
|
2014 | 9c02f1a2 | j_mayer | case MAL0_TXCTP0R:
|
2015 | 9c02f1a2 | j_mayer | ret = mal->txctpr[0];
|
2016 | 9c02f1a2 | j_mayer | break;
|
2017 | 9c02f1a2 | j_mayer | case MAL0_TXCTP1R:
|
2018 | 9c02f1a2 | j_mayer | ret = mal->txctpr[1];
|
2019 | 9c02f1a2 | j_mayer | break;
|
2020 | 9c02f1a2 | j_mayer | case MAL0_TXCTP2R:
|
2021 | 9c02f1a2 | j_mayer | ret = mal->txctpr[2];
|
2022 | 9c02f1a2 | j_mayer | break;
|
2023 | 9c02f1a2 | j_mayer | case MAL0_TXCTP3R:
|
2024 | 9c02f1a2 | j_mayer | ret = mal->txctpr[3];
|
2025 | 9c02f1a2 | j_mayer | break;
|
2026 | 9c02f1a2 | j_mayer | case MAL0_RXCTP0R:
|
2027 | 9c02f1a2 | j_mayer | ret = mal->rxctpr[0];
|
2028 | 9c02f1a2 | j_mayer | break;
|
2029 | 9c02f1a2 | j_mayer | case MAL0_RXCTP1R:
|
2030 | 9c02f1a2 | j_mayer | ret = mal->rxctpr[1];
|
2031 | 9c02f1a2 | j_mayer | break;
|
2032 | 9c02f1a2 | j_mayer | case MAL0_RCBS0:
|
2033 | 9c02f1a2 | j_mayer | ret = mal->rcbs[0];
|
2034 | 9c02f1a2 | j_mayer | break;
|
2035 | 9c02f1a2 | j_mayer | case MAL0_RCBS1:
|
2036 | 9c02f1a2 | j_mayer | ret = mal->rcbs[1];
|
2037 | 9c02f1a2 | j_mayer | break;
|
2038 | 9c02f1a2 | j_mayer | default:
|
2039 | 9c02f1a2 | j_mayer | ret = 0;
|
2040 | 9c02f1a2 | j_mayer | break;
|
2041 | 9c02f1a2 | j_mayer | } |
2042 | 9c02f1a2 | j_mayer | |
2043 | 9c02f1a2 | j_mayer | return ret;
|
2044 | 9c02f1a2 | j_mayer | } |
2045 | 9c02f1a2 | j_mayer | |
2046 | 9c02f1a2 | j_mayer | static void dcr_write_mal (void *opaque, int dcrn, target_ulong val) |
2047 | 9c02f1a2 | j_mayer | { |
2048 | 9c02f1a2 | j_mayer | ppc40x_mal_t *mal; |
2049 | 9c02f1a2 | j_mayer | int idx;
|
2050 | 9c02f1a2 | j_mayer | |
2051 | 9c02f1a2 | j_mayer | mal = opaque; |
2052 | 9c02f1a2 | j_mayer | switch (dcrn) {
|
2053 | 9c02f1a2 | j_mayer | case MAL0_CFG:
|
2054 | 9c02f1a2 | j_mayer | if (val & 0x80000000) |
2055 | 9c02f1a2 | j_mayer | ppc40x_mal_reset(mal); |
2056 | 9c02f1a2 | j_mayer | mal->cfg = val & 0x00FFC087;
|
2057 | 9c02f1a2 | j_mayer | break;
|
2058 | 9c02f1a2 | j_mayer | case MAL0_ESR:
|
2059 | 9c02f1a2 | j_mayer | /* Read/clear */
|
2060 | 9c02f1a2 | j_mayer | mal->esr &= ~val; |
2061 | 9c02f1a2 | j_mayer | break;
|
2062 | 9c02f1a2 | j_mayer | case MAL0_IER:
|
2063 | 9c02f1a2 | j_mayer | mal->ier = val & 0x0000001F;
|
2064 | 9c02f1a2 | j_mayer | break;
|
2065 | 9c02f1a2 | j_mayer | case MAL0_TXCASR:
|
2066 | 9c02f1a2 | j_mayer | mal->txcasr = val & 0xF0000000;
|
2067 | 9c02f1a2 | j_mayer | break;
|
2068 | 9c02f1a2 | j_mayer | case MAL0_TXCARR:
|
2069 | 9c02f1a2 | j_mayer | mal->txcarr = val & 0xF0000000;
|
2070 | 9c02f1a2 | j_mayer | break;
|
2071 | 9c02f1a2 | j_mayer | case MAL0_TXEOBISR:
|
2072 | 9c02f1a2 | j_mayer | /* Read/clear */
|
2073 | 9c02f1a2 | j_mayer | mal->txeobisr &= ~val; |
2074 | 9c02f1a2 | j_mayer | break;
|
2075 | 9c02f1a2 | j_mayer | case MAL0_TXDEIR:
|
2076 | 9c02f1a2 | j_mayer | /* Read/clear */
|
2077 | 9c02f1a2 | j_mayer | mal->txdeir &= ~val; |
2078 | 9c02f1a2 | j_mayer | break;
|
2079 | 9c02f1a2 | j_mayer | case MAL0_RXCASR:
|
2080 | 9c02f1a2 | j_mayer | mal->rxcasr = val & 0xC0000000;
|
2081 | 9c02f1a2 | j_mayer | break;
|
2082 | 9c02f1a2 | j_mayer | case MAL0_RXCARR:
|
2083 | 9c02f1a2 | j_mayer | mal->rxcarr = val & 0xC0000000;
|
2084 | 9c02f1a2 | j_mayer | break;
|
2085 | 9c02f1a2 | j_mayer | case MAL0_RXEOBISR:
|
2086 | 9c02f1a2 | j_mayer | /* Read/clear */
|
2087 | 9c02f1a2 | j_mayer | mal->rxeobisr &= ~val; |
2088 | 9c02f1a2 | j_mayer | break;
|
2089 | 9c02f1a2 | j_mayer | case MAL0_RXDEIR:
|
2090 | 9c02f1a2 | j_mayer | /* Read/clear */
|
2091 | 9c02f1a2 | j_mayer | mal->rxdeir &= ~val; |
2092 | 9c02f1a2 | j_mayer | break;
|
2093 | 9c02f1a2 | j_mayer | case MAL0_TXCTP0R:
|
2094 | 9c02f1a2 | j_mayer | idx = 0;
|
2095 | 9c02f1a2 | j_mayer | goto update_tx_ptr;
|
2096 | 9c02f1a2 | j_mayer | case MAL0_TXCTP1R:
|
2097 | 9c02f1a2 | j_mayer | idx = 1;
|
2098 | 9c02f1a2 | j_mayer | goto update_tx_ptr;
|
2099 | 9c02f1a2 | j_mayer | case MAL0_TXCTP2R:
|
2100 | 9c02f1a2 | j_mayer | idx = 2;
|
2101 | 9c02f1a2 | j_mayer | goto update_tx_ptr;
|
2102 | 9c02f1a2 | j_mayer | case MAL0_TXCTP3R:
|
2103 | 9c02f1a2 | j_mayer | idx = 3;
|
2104 | 9c02f1a2 | j_mayer | update_tx_ptr:
|
2105 | 9c02f1a2 | j_mayer | mal->txctpr[idx] = val; |
2106 | 9c02f1a2 | j_mayer | break;
|
2107 | 9c02f1a2 | j_mayer | case MAL0_RXCTP0R:
|
2108 | 9c02f1a2 | j_mayer | idx = 0;
|
2109 | 9c02f1a2 | j_mayer | goto update_rx_ptr;
|
2110 | 9c02f1a2 | j_mayer | case MAL0_RXCTP1R:
|
2111 | 9c02f1a2 | j_mayer | idx = 1;
|
2112 | 9c02f1a2 | j_mayer | update_rx_ptr:
|
2113 | 9c02f1a2 | j_mayer | mal->rxctpr[idx] = val; |
2114 | 9c02f1a2 | j_mayer | break;
|
2115 | 9c02f1a2 | j_mayer | case MAL0_RCBS0:
|
2116 | 9c02f1a2 | j_mayer | idx = 0;
|
2117 | 9c02f1a2 | j_mayer | goto update_rx_size;
|
2118 | 9c02f1a2 | j_mayer | case MAL0_RCBS1:
|
2119 | 9c02f1a2 | j_mayer | idx = 1;
|
2120 | 9c02f1a2 | j_mayer | update_rx_size:
|
2121 | 9c02f1a2 | j_mayer | mal->rcbs[idx] = val & 0x000000FF;
|
2122 | 9c02f1a2 | j_mayer | break;
|
2123 | 9c02f1a2 | j_mayer | } |
2124 | 9c02f1a2 | j_mayer | } |
2125 | 9c02f1a2 | j_mayer | |
2126 | 9c02f1a2 | j_mayer | static void ppc40x_mal_reset (void *opaque) |
2127 | 9c02f1a2 | j_mayer | { |
2128 | 9c02f1a2 | j_mayer | ppc40x_mal_t *mal; |
2129 | 9c02f1a2 | j_mayer | |
2130 | 9c02f1a2 | j_mayer | mal = opaque; |
2131 | 9c02f1a2 | j_mayer | mal->cfg = 0x0007C000;
|
2132 | 9c02f1a2 | j_mayer | mal->esr = 0x00000000;
|
2133 | 9c02f1a2 | j_mayer | mal->ier = 0x00000000;
|
2134 | 9c02f1a2 | j_mayer | mal->rxcasr = 0x00000000;
|
2135 | 9c02f1a2 | j_mayer | mal->rxdeir = 0x00000000;
|
2136 | 9c02f1a2 | j_mayer | mal->rxeobisr = 0x00000000;
|
2137 | 9c02f1a2 | j_mayer | mal->txcasr = 0x00000000;
|
2138 | 9c02f1a2 | j_mayer | mal->txdeir = 0x00000000;
|
2139 | 9c02f1a2 | j_mayer | mal->txeobisr = 0x00000000;
|
2140 | 9c02f1a2 | j_mayer | } |
2141 | 9c02f1a2 | j_mayer | |
2142 | 9c02f1a2 | j_mayer | void ppc405_mal_init (CPUState *env, qemu_irq irqs[4]) |
2143 | 9c02f1a2 | j_mayer | { |
2144 | 9c02f1a2 | j_mayer | ppc40x_mal_t *mal; |
2145 | 9c02f1a2 | j_mayer | int i;
|
2146 | 9c02f1a2 | j_mayer | |
2147 | 9c02f1a2 | j_mayer | mal = qemu_mallocz(sizeof(ppc40x_mal_t));
|
2148 | 9c02f1a2 | j_mayer | if (mal != NULL) { |
2149 | 9c02f1a2 | j_mayer | for (i = 0; i < 4; i++) |
2150 | 9c02f1a2 | j_mayer | mal->irqs[i] = irqs[i]; |
2151 | 9c02f1a2 | j_mayer | ppc40x_mal_reset(mal); |
2152 | 9c02f1a2 | j_mayer | qemu_register_reset(&ppc40x_mal_reset, mal); |
2153 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_CFG, |
2154 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2155 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_ESR, |
2156 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2157 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_IER, |
2158 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2159 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_TXCASR, |
2160 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2161 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_TXCARR, |
2162 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2163 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_TXEOBISR, |
2164 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2165 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_TXDEIR, |
2166 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2167 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_RXCASR, |
2168 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2169 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_RXCARR, |
2170 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2171 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_RXEOBISR, |
2172 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2173 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_RXDEIR, |
2174 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2175 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_TXCTP0R, |
2176 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2177 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_TXCTP1R, |
2178 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2179 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_TXCTP2R, |
2180 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2181 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_TXCTP3R, |
2182 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2183 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_RXCTP0R, |
2184 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2185 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_RXCTP1R, |
2186 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2187 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_RCBS0, |
2188 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2189 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, MAL0_RCBS1, |
2190 | 9c02f1a2 | j_mayer | mal, &dcr_read_mal, &dcr_write_mal); |
2191 | 9c02f1a2 | j_mayer | } |
2192 | 9c02f1a2 | j_mayer | } |
2193 | 9c02f1a2 | j_mayer | |
2194 | 9c02f1a2 | j_mayer | /*****************************************************************************/
|
2195 | 8ecc7913 | j_mayer | /* SPR */
|
2196 | 8ecc7913 | j_mayer | void ppc40x_core_reset (CPUState *env)
|
2197 | 8ecc7913 | j_mayer | { |
2198 | 8ecc7913 | j_mayer | target_ulong dbsr; |
2199 | 8ecc7913 | j_mayer | |
2200 | 8ecc7913 | j_mayer | printf("Reset PowerPC core\n");
|
2201 | ef397e88 | j_mayer | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
2202 | ef397e88 | j_mayer | /* XXX: TOFIX */
|
2203 | ef397e88 | j_mayer | #if 0
|
2204 | 8ecc7913 | j_mayer | cpu_ppc_reset(env);
|
2205 | ef397e88 | j_mayer | #else
|
2206 | ef397e88 | j_mayer | qemu_system_reset_request(); |
2207 | ef397e88 | j_mayer | #endif
|
2208 | 8ecc7913 | j_mayer | dbsr = env->spr[SPR_40x_DBSR]; |
2209 | 8ecc7913 | j_mayer | dbsr &= ~0x00000300;
|
2210 | 8ecc7913 | j_mayer | dbsr |= 0x00000100;
|
2211 | 8ecc7913 | j_mayer | env->spr[SPR_40x_DBSR] = dbsr; |
2212 | 8ecc7913 | j_mayer | } |
2213 | 8ecc7913 | j_mayer | |
2214 | 8ecc7913 | j_mayer | void ppc40x_chip_reset (CPUState *env)
|
2215 | 8ecc7913 | j_mayer | { |
2216 | 8ecc7913 | j_mayer | target_ulong dbsr; |
2217 | 8ecc7913 | j_mayer | |
2218 | 8ecc7913 | j_mayer | printf("Reset PowerPC chip\n");
|
2219 | ef397e88 | j_mayer | env->interrupt_request |= CPU_INTERRUPT_EXITTB; |
2220 | ef397e88 | j_mayer | /* XXX: TOFIX */
|
2221 | ef397e88 | j_mayer | #if 0
|
2222 | 8ecc7913 | j_mayer | cpu_ppc_reset(env);
|
2223 | ef397e88 | j_mayer | #else
|
2224 | ef397e88 | j_mayer | qemu_system_reset_request(); |
2225 | ef397e88 | j_mayer | #endif
|
2226 | 8ecc7913 | j_mayer | /* XXX: TODO reset all internal peripherals */
|
2227 | 8ecc7913 | j_mayer | dbsr = env->spr[SPR_40x_DBSR]; |
2228 | 8ecc7913 | j_mayer | dbsr &= ~0x00000300;
|
2229 | 04f20795 | j_mayer | dbsr |= 0x00000200;
|
2230 | 8ecc7913 | j_mayer | env->spr[SPR_40x_DBSR] = dbsr; |
2231 | 8ecc7913 | j_mayer | } |
2232 | 8ecc7913 | j_mayer | |
2233 | 8ecc7913 | j_mayer | void ppc40x_system_reset (CPUState *env)
|
2234 | 8ecc7913 | j_mayer | { |
2235 | 8ecc7913 | j_mayer | printf("Reset PowerPC system\n");
|
2236 | 8ecc7913 | j_mayer | qemu_system_reset_request(); |
2237 | 8ecc7913 | j_mayer | } |
2238 | 8ecc7913 | j_mayer | |
2239 | 8ecc7913 | j_mayer | void store_40x_dbcr0 (CPUState *env, uint32_t val)
|
2240 | 8ecc7913 | j_mayer | { |
2241 | 8ecc7913 | j_mayer | switch ((val >> 28) & 0x3) { |
2242 | 8ecc7913 | j_mayer | case 0x0: |
2243 | 8ecc7913 | j_mayer | /* No action */
|
2244 | 8ecc7913 | j_mayer | break;
|
2245 | 8ecc7913 | j_mayer | case 0x1: |
2246 | 8ecc7913 | j_mayer | /* Core reset */
|
2247 | 8ecc7913 | j_mayer | ppc40x_core_reset(env); |
2248 | 8ecc7913 | j_mayer | break;
|
2249 | 8ecc7913 | j_mayer | case 0x2: |
2250 | 8ecc7913 | j_mayer | /* Chip reset */
|
2251 | 8ecc7913 | j_mayer | ppc40x_chip_reset(env); |
2252 | 8ecc7913 | j_mayer | break;
|
2253 | 8ecc7913 | j_mayer | case 0x3: |
2254 | 8ecc7913 | j_mayer | /* System reset */
|
2255 | 8ecc7913 | j_mayer | ppc40x_system_reset(env); |
2256 | 8ecc7913 | j_mayer | break;
|
2257 | 8ecc7913 | j_mayer | } |
2258 | 8ecc7913 | j_mayer | } |
2259 | 8ecc7913 | j_mayer | |
2260 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
2261 | 8ecc7913 | j_mayer | /* PowerPC 405CR */
|
2262 | 8ecc7913 | j_mayer | enum {
|
2263 | 8ecc7913 | j_mayer | PPC405CR_CPC0_PLLMR = 0x0B0,
|
2264 | 8ecc7913 | j_mayer | PPC405CR_CPC0_CR0 = 0x0B1,
|
2265 | 8ecc7913 | j_mayer | PPC405CR_CPC0_CR1 = 0x0B2,
|
2266 | 8ecc7913 | j_mayer | PPC405CR_CPC0_PSR = 0x0B4,
|
2267 | 8ecc7913 | j_mayer | PPC405CR_CPC0_JTAGID = 0x0B5,
|
2268 | 8ecc7913 | j_mayer | PPC405CR_CPC0_ER = 0x0B9,
|
2269 | 8ecc7913 | j_mayer | PPC405CR_CPC0_FR = 0x0BA,
|
2270 | 8ecc7913 | j_mayer | PPC405CR_CPC0_SR = 0x0BB,
|
2271 | 8ecc7913 | j_mayer | }; |
2272 | 8ecc7913 | j_mayer | |
2273 | 04f20795 | j_mayer | enum {
|
2274 | 04f20795 | j_mayer | PPC405CR_CPU_CLK = 0,
|
2275 | 04f20795 | j_mayer | PPC405CR_TMR_CLK = 1,
|
2276 | 04f20795 | j_mayer | PPC405CR_PLB_CLK = 2,
|
2277 | 04f20795 | j_mayer | PPC405CR_SDRAM_CLK = 3,
|
2278 | 04f20795 | j_mayer | PPC405CR_OPB_CLK = 4,
|
2279 | 04f20795 | j_mayer | PPC405CR_EXT_CLK = 5,
|
2280 | 04f20795 | j_mayer | PPC405CR_UART_CLK = 6,
|
2281 | 04f20795 | j_mayer | PPC405CR_CLK_NB = 7,
|
2282 | 04f20795 | j_mayer | }; |
2283 | 04f20795 | j_mayer | |
2284 | 8ecc7913 | j_mayer | typedef struct ppc405cr_cpc_t ppc405cr_cpc_t; |
2285 | 8ecc7913 | j_mayer | struct ppc405cr_cpc_t {
|
2286 | 04f20795 | j_mayer | clk_setup_t clk_setup[PPC405CR_CLK_NB]; |
2287 | 8ecc7913 | j_mayer | uint32_t sysclk; |
2288 | 8ecc7913 | j_mayer | uint32_t psr; |
2289 | 8ecc7913 | j_mayer | uint32_t cr0; |
2290 | 8ecc7913 | j_mayer | uint32_t cr1; |
2291 | 8ecc7913 | j_mayer | uint32_t jtagid; |
2292 | 8ecc7913 | j_mayer | uint32_t pllmr; |
2293 | 8ecc7913 | j_mayer | uint32_t er; |
2294 | 8ecc7913 | j_mayer | uint32_t fr; |
2295 | 8ecc7913 | j_mayer | }; |
2296 | 8ecc7913 | j_mayer | |
2297 | 8ecc7913 | j_mayer | static void ppc405cr_clk_setup (ppc405cr_cpc_t *cpc) |
2298 | 8ecc7913 | j_mayer | { |
2299 | 8ecc7913 | j_mayer | uint64_t VCO_out, PLL_out; |
2300 | 8ecc7913 | j_mayer | uint32_t CPU_clk, TMR_clk, SDRAM_clk, PLB_clk, OPB_clk, EXT_clk, UART_clk; |
2301 | 8ecc7913 | j_mayer | int M, D0, D1, D2;
|
2302 | 8ecc7913 | j_mayer | |
2303 | 8ecc7913 | j_mayer | D0 = ((cpc->pllmr >> 26) & 0x3) + 1; /* CBDV */ |
2304 | 8ecc7913 | j_mayer | if (cpc->pllmr & 0x80000000) { |
2305 | 8ecc7913 | j_mayer | D1 = (((cpc->pllmr >> 20) - 1) & 0xF) + 1; /* FBDV */ |
2306 | 8ecc7913 | j_mayer | D2 = 8 - ((cpc->pllmr >> 16) & 0x7); /* FWDVA */ |
2307 | 8ecc7913 | j_mayer | M = D0 * D1 * D2; |
2308 | 8ecc7913 | j_mayer | VCO_out = cpc->sysclk * M; |
2309 | 8ecc7913 | j_mayer | if (VCO_out < 400000000 || VCO_out > 800000000) { |
2310 | 8ecc7913 | j_mayer | /* PLL cannot lock */
|
2311 | 8ecc7913 | j_mayer | cpc->pllmr &= ~0x80000000;
|
2312 | 8ecc7913 | j_mayer | goto bypass_pll;
|
2313 | 8ecc7913 | j_mayer | } |
2314 | 8ecc7913 | j_mayer | PLL_out = VCO_out / D2; |
2315 | 8ecc7913 | j_mayer | } else {
|
2316 | 8ecc7913 | j_mayer | /* Bypass PLL */
|
2317 | 8ecc7913 | j_mayer | bypass_pll:
|
2318 | 8ecc7913 | j_mayer | M = D0; |
2319 | 8ecc7913 | j_mayer | PLL_out = cpc->sysclk * M; |
2320 | 8ecc7913 | j_mayer | } |
2321 | 8ecc7913 | j_mayer | CPU_clk = PLL_out; |
2322 | 8ecc7913 | j_mayer | if (cpc->cr1 & 0x00800000) |
2323 | 8ecc7913 | j_mayer | TMR_clk = cpc->sysclk; /* Should have a separate clock */
|
2324 | 8ecc7913 | j_mayer | else
|
2325 | 8ecc7913 | j_mayer | TMR_clk = CPU_clk; |
2326 | 8ecc7913 | j_mayer | PLB_clk = CPU_clk / D0; |
2327 | 8ecc7913 | j_mayer | SDRAM_clk = PLB_clk; |
2328 | 8ecc7913 | j_mayer | D0 = ((cpc->pllmr >> 10) & 0x3) + 1; |
2329 | 8ecc7913 | j_mayer | OPB_clk = PLB_clk / D0; |
2330 | 8ecc7913 | j_mayer | D0 = ((cpc->pllmr >> 24) & 0x3) + 2; |
2331 | 8ecc7913 | j_mayer | EXT_clk = PLB_clk / D0; |
2332 | 8ecc7913 | j_mayer | D0 = ((cpc->cr0 >> 1) & 0x1F) + 1; |
2333 | 8ecc7913 | j_mayer | UART_clk = CPU_clk / D0; |
2334 | 8ecc7913 | j_mayer | /* Setup CPU clocks */
|
2335 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405CR_CPU_CLK], CPU_clk); |
2336 | 8ecc7913 | j_mayer | /* Setup time-base clock */
|
2337 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405CR_TMR_CLK], TMR_clk); |
2338 | 8ecc7913 | j_mayer | /* Setup PLB clock */
|
2339 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405CR_PLB_CLK], PLB_clk); |
2340 | 8ecc7913 | j_mayer | /* Setup SDRAM clock */
|
2341 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405CR_SDRAM_CLK], SDRAM_clk); |
2342 | 8ecc7913 | j_mayer | /* Setup OPB clock */
|
2343 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405CR_OPB_CLK], OPB_clk); |
2344 | 8ecc7913 | j_mayer | /* Setup external clock */
|
2345 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405CR_EXT_CLK], EXT_clk); |
2346 | 8ecc7913 | j_mayer | /* Setup UART clock */
|
2347 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405CR_UART_CLK], UART_clk); |
2348 | 8ecc7913 | j_mayer | } |
2349 | 8ecc7913 | j_mayer | |
2350 | 8ecc7913 | j_mayer | static target_ulong dcr_read_crcpc (void *opaque, int dcrn) |
2351 | 8ecc7913 | j_mayer | { |
2352 | 8ecc7913 | j_mayer | ppc405cr_cpc_t *cpc; |
2353 | 8ecc7913 | j_mayer | target_ulong ret; |
2354 | 8ecc7913 | j_mayer | |
2355 | 8ecc7913 | j_mayer | cpc = opaque; |
2356 | 8ecc7913 | j_mayer | switch (dcrn) {
|
2357 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_PLLMR:
|
2358 | 8ecc7913 | j_mayer | ret = cpc->pllmr; |
2359 | 8ecc7913 | j_mayer | break;
|
2360 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_CR0:
|
2361 | 8ecc7913 | j_mayer | ret = cpc->cr0; |
2362 | 8ecc7913 | j_mayer | break;
|
2363 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_CR1:
|
2364 | 8ecc7913 | j_mayer | ret = cpc->cr1; |
2365 | 8ecc7913 | j_mayer | break;
|
2366 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_PSR:
|
2367 | 8ecc7913 | j_mayer | ret = cpc->psr; |
2368 | 8ecc7913 | j_mayer | break;
|
2369 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_JTAGID:
|
2370 | 8ecc7913 | j_mayer | ret = cpc->jtagid; |
2371 | 8ecc7913 | j_mayer | break;
|
2372 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_ER:
|
2373 | 8ecc7913 | j_mayer | ret = cpc->er; |
2374 | 8ecc7913 | j_mayer | break;
|
2375 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_FR:
|
2376 | 8ecc7913 | j_mayer | ret = cpc->fr; |
2377 | 8ecc7913 | j_mayer | break;
|
2378 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_SR:
|
2379 | 8ecc7913 | j_mayer | ret = ~(cpc->er | cpc->fr) & 0xFFFF0000;
|
2380 | 8ecc7913 | j_mayer | break;
|
2381 | 8ecc7913 | j_mayer | default:
|
2382 | 8ecc7913 | j_mayer | /* Avoid gcc warning */
|
2383 | 8ecc7913 | j_mayer | ret = 0;
|
2384 | 8ecc7913 | j_mayer | break;
|
2385 | 8ecc7913 | j_mayer | } |
2386 | 8ecc7913 | j_mayer | |
2387 | 8ecc7913 | j_mayer | return ret;
|
2388 | 8ecc7913 | j_mayer | } |
2389 | 8ecc7913 | j_mayer | |
2390 | 8ecc7913 | j_mayer | static void dcr_write_crcpc (void *opaque, int dcrn, target_ulong val) |
2391 | 8ecc7913 | j_mayer | { |
2392 | 8ecc7913 | j_mayer | ppc405cr_cpc_t *cpc; |
2393 | 8ecc7913 | j_mayer | |
2394 | 8ecc7913 | j_mayer | cpc = opaque; |
2395 | 8ecc7913 | j_mayer | switch (dcrn) {
|
2396 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_PLLMR:
|
2397 | 8ecc7913 | j_mayer | cpc->pllmr = val & 0xFFF77C3F;
|
2398 | 8ecc7913 | j_mayer | break;
|
2399 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_CR0:
|
2400 | 8ecc7913 | j_mayer | cpc->cr0 = val & 0x0FFFFFFE;
|
2401 | 8ecc7913 | j_mayer | break;
|
2402 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_CR1:
|
2403 | 8ecc7913 | j_mayer | cpc->cr1 = val & 0x00800000;
|
2404 | 8ecc7913 | j_mayer | break;
|
2405 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_PSR:
|
2406 | 8ecc7913 | j_mayer | /* Read-only */
|
2407 | 8ecc7913 | j_mayer | break;
|
2408 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_JTAGID:
|
2409 | 8ecc7913 | j_mayer | /* Read-only */
|
2410 | 8ecc7913 | j_mayer | break;
|
2411 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_ER:
|
2412 | 8ecc7913 | j_mayer | cpc->er = val & 0xBFFC0000;
|
2413 | 8ecc7913 | j_mayer | break;
|
2414 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_FR:
|
2415 | 8ecc7913 | j_mayer | cpc->fr = val & 0xBFFC0000;
|
2416 | 8ecc7913 | j_mayer | break;
|
2417 | 8ecc7913 | j_mayer | case PPC405CR_CPC0_SR:
|
2418 | 8ecc7913 | j_mayer | /* Read-only */
|
2419 | 8ecc7913 | j_mayer | break;
|
2420 | 8ecc7913 | j_mayer | } |
2421 | 8ecc7913 | j_mayer | } |
2422 | 8ecc7913 | j_mayer | |
2423 | 8ecc7913 | j_mayer | static void ppc405cr_cpc_reset (void *opaque) |
2424 | 8ecc7913 | j_mayer | { |
2425 | 8ecc7913 | j_mayer | ppc405cr_cpc_t *cpc; |
2426 | 8ecc7913 | j_mayer | int D;
|
2427 | 8ecc7913 | j_mayer | |
2428 | 8ecc7913 | j_mayer | cpc = opaque; |
2429 | 8ecc7913 | j_mayer | /* Compute PLLMR value from PSR settings */
|
2430 | 8ecc7913 | j_mayer | cpc->pllmr = 0x80000000;
|
2431 | 8ecc7913 | j_mayer | /* PFWD */
|
2432 | 8ecc7913 | j_mayer | switch ((cpc->psr >> 30) & 3) { |
2433 | 8ecc7913 | j_mayer | case 0: |
2434 | 8ecc7913 | j_mayer | /* Bypass */
|
2435 | 8ecc7913 | j_mayer | cpc->pllmr &= ~0x80000000;
|
2436 | 8ecc7913 | j_mayer | break;
|
2437 | 8ecc7913 | j_mayer | case 1: |
2438 | 8ecc7913 | j_mayer | /* Divide by 3 */
|
2439 | 8ecc7913 | j_mayer | cpc->pllmr |= 5 << 16; |
2440 | 8ecc7913 | j_mayer | break;
|
2441 | 8ecc7913 | j_mayer | case 2: |
2442 | 8ecc7913 | j_mayer | /* Divide by 4 */
|
2443 | 8ecc7913 | j_mayer | cpc->pllmr |= 4 << 16; |
2444 | 8ecc7913 | j_mayer | break;
|
2445 | 8ecc7913 | j_mayer | case 3: |
2446 | 8ecc7913 | j_mayer | /* Divide by 6 */
|
2447 | 8ecc7913 | j_mayer | cpc->pllmr |= 2 << 16; |
2448 | 8ecc7913 | j_mayer | break;
|
2449 | 8ecc7913 | j_mayer | } |
2450 | 8ecc7913 | j_mayer | /* PFBD */
|
2451 | 8ecc7913 | j_mayer | D = (cpc->psr >> 28) & 3; |
2452 | 8ecc7913 | j_mayer | cpc->pllmr |= (D + 1) << 20; |
2453 | 8ecc7913 | j_mayer | /* PT */
|
2454 | 8ecc7913 | j_mayer | D = (cpc->psr >> 25) & 7; |
2455 | 8ecc7913 | j_mayer | switch (D) {
|
2456 | 8ecc7913 | j_mayer | case 0x2: |
2457 | 8ecc7913 | j_mayer | cpc->pllmr |= 0x13;
|
2458 | 8ecc7913 | j_mayer | break;
|
2459 | 8ecc7913 | j_mayer | case 0x4: |
2460 | 8ecc7913 | j_mayer | cpc->pllmr |= 0x15;
|
2461 | 8ecc7913 | j_mayer | break;
|
2462 | 8ecc7913 | j_mayer | case 0x5: |
2463 | 8ecc7913 | j_mayer | cpc->pllmr |= 0x16;
|
2464 | 8ecc7913 | j_mayer | break;
|
2465 | 8ecc7913 | j_mayer | default:
|
2466 | 8ecc7913 | j_mayer | break;
|
2467 | 8ecc7913 | j_mayer | } |
2468 | 8ecc7913 | j_mayer | /* PDC */
|
2469 | 8ecc7913 | j_mayer | D = (cpc->psr >> 23) & 3; |
2470 | 8ecc7913 | j_mayer | cpc->pllmr |= D << 26;
|
2471 | 8ecc7913 | j_mayer | /* ODP */
|
2472 | 8ecc7913 | j_mayer | D = (cpc->psr >> 21) & 3; |
2473 | 8ecc7913 | j_mayer | cpc->pllmr |= D << 10;
|
2474 | 8ecc7913 | j_mayer | /* EBPD */
|
2475 | 8ecc7913 | j_mayer | D = (cpc->psr >> 17) & 3; |
2476 | 8ecc7913 | j_mayer | cpc->pllmr |= D << 24;
|
2477 | 8ecc7913 | j_mayer | cpc->cr0 = 0x0000003C;
|
2478 | 8ecc7913 | j_mayer | cpc->cr1 = 0x2B0D8800;
|
2479 | 8ecc7913 | j_mayer | cpc->er = 0x00000000;
|
2480 | 8ecc7913 | j_mayer | cpc->fr = 0x00000000;
|
2481 | 8ecc7913 | j_mayer | ppc405cr_clk_setup(cpc); |
2482 | 8ecc7913 | j_mayer | } |
2483 | 8ecc7913 | j_mayer | |
2484 | 8ecc7913 | j_mayer | static void ppc405cr_clk_init (ppc405cr_cpc_t *cpc) |
2485 | 8ecc7913 | j_mayer | { |
2486 | 8ecc7913 | j_mayer | int D;
|
2487 | 8ecc7913 | j_mayer | |
2488 | 8ecc7913 | j_mayer | /* XXX: this should be read from IO pins */
|
2489 | 8ecc7913 | j_mayer | cpc->psr = 0x00000000; /* 8 bits ROM */ |
2490 | 8ecc7913 | j_mayer | /* PFWD */
|
2491 | 8ecc7913 | j_mayer | D = 0x2; /* Divide by 4 */ |
2492 | 8ecc7913 | j_mayer | cpc->psr |= D << 30;
|
2493 | 8ecc7913 | j_mayer | /* PFBD */
|
2494 | 8ecc7913 | j_mayer | D = 0x1; /* Divide by 2 */ |
2495 | 8ecc7913 | j_mayer | cpc->psr |= D << 28;
|
2496 | 8ecc7913 | j_mayer | /* PDC */
|
2497 | 8ecc7913 | j_mayer | D = 0x1; /* Divide by 2 */ |
2498 | 8ecc7913 | j_mayer | cpc->psr |= D << 23;
|
2499 | 8ecc7913 | j_mayer | /* PT */
|
2500 | 8ecc7913 | j_mayer | D = 0x5; /* M = 16 */ |
2501 | 8ecc7913 | j_mayer | cpc->psr |= D << 25;
|
2502 | 8ecc7913 | j_mayer | /* ODP */
|
2503 | 8ecc7913 | j_mayer | D = 0x1; /* Divide by 2 */ |
2504 | 8ecc7913 | j_mayer | cpc->psr |= D << 21;
|
2505 | 8ecc7913 | j_mayer | /* EBDP */
|
2506 | 8ecc7913 | j_mayer | D = 0x2; /* Divide by 4 */ |
2507 | 8ecc7913 | j_mayer | cpc->psr |= D << 17;
|
2508 | 8ecc7913 | j_mayer | } |
2509 | 8ecc7913 | j_mayer | |
2510 | 8ecc7913 | j_mayer | static void ppc405cr_cpc_init (CPUState *env, clk_setup_t clk_setup[7], |
2511 | 8ecc7913 | j_mayer | uint32_t sysclk) |
2512 | 8ecc7913 | j_mayer | { |
2513 | 8ecc7913 | j_mayer | ppc405cr_cpc_t *cpc; |
2514 | 8ecc7913 | j_mayer | |
2515 | 8ecc7913 | j_mayer | cpc = qemu_mallocz(sizeof(ppc405cr_cpc_t));
|
2516 | 8ecc7913 | j_mayer | if (cpc != NULL) { |
2517 | 04f20795 | j_mayer | memcpy(cpc->clk_setup, clk_setup, |
2518 | 04f20795 | j_mayer | PPC405CR_CLK_NB * sizeof(clk_setup_t));
|
2519 | 8ecc7913 | j_mayer | cpc->sysclk = sysclk; |
2520 | 8ecc7913 | j_mayer | cpc->jtagid = 0x42051049;
|
2521 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405CR_CPC0_PSR, cpc, |
2522 | 8ecc7913 | j_mayer | &dcr_read_crcpc, &dcr_write_crcpc); |
2523 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405CR_CPC0_CR0, cpc, |
2524 | 8ecc7913 | j_mayer | &dcr_read_crcpc, &dcr_write_crcpc); |
2525 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405CR_CPC0_CR1, cpc, |
2526 | 8ecc7913 | j_mayer | &dcr_read_crcpc, &dcr_write_crcpc); |
2527 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405CR_CPC0_JTAGID, cpc, |
2528 | 8ecc7913 | j_mayer | &dcr_read_crcpc, &dcr_write_crcpc); |
2529 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405CR_CPC0_PLLMR, cpc, |
2530 | 8ecc7913 | j_mayer | &dcr_read_crcpc, &dcr_write_crcpc); |
2531 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405CR_CPC0_ER, cpc, |
2532 | 8ecc7913 | j_mayer | &dcr_read_crcpc, &dcr_write_crcpc); |
2533 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405CR_CPC0_FR, cpc, |
2534 | 8ecc7913 | j_mayer | &dcr_read_crcpc, &dcr_write_crcpc); |
2535 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405CR_CPC0_SR, cpc, |
2536 | 8ecc7913 | j_mayer | &dcr_read_crcpc, &dcr_write_crcpc); |
2537 | 8ecc7913 | j_mayer | ppc405cr_clk_init(cpc); |
2538 | 8ecc7913 | j_mayer | qemu_register_reset(ppc405cr_cpc_reset, cpc); |
2539 | 8ecc7913 | j_mayer | ppc405cr_cpc_reset(cpc); |
2540 | 8ecc7913 | j_mayer | } |
2541 | 8ecc7913 | j_mayer | } |
2542 | 8ecc7913 | j_mayer | |
2543 | 71db710f | blueswir1 | CPUState *ppc405cr_init (target_phys_addr_t ram_bases[4],
|
2544 | 71db710f | blueswir1 | target_phys_addr_t ram_sizes[4],
|
2545 | 8ecc7913 | j_mayer | uint32_t sysclk, qemu_irq **picp, |
2546 | 04f20795 | j_mayer | ram_addr_t *offsetp, int do_init)
|
2547 | 8ecc7913 | j_mayer | { |
2548 | 04f20795 | j_mayer | clk_setup_t clk_setup[PPC405CR_CLK_NB]; |
2549 | 8ecc7913 | j_mayer | qemu_irq dma_irqs[4];
|
2550 | 8ecc7913 | j_mayer | CPUState *env; |
2551 | 8ecc7913 | j_mayer | ppc4xx_mmio_t *mmio; |
2552 | 8ecc7913 | j_mayer | qemu_irq *pic, *irqs; |
2553 | 8ecc7913 | j_mayer | ram_addr_t offset; |
2554 | 8ecc7913 | j_mayer | int i;
|
2555 | 8ecc7913 | j_mayer | |
2556 | 8ecc7913 | j_mayer | memset(clk_setup, 0, sizeof(clk_setup)); |
2557 | 008ff9d7 | j_mayer | env = ppc4xx_init("405cr", &clk_setup[PPC405CR_CPU_CLK],
|
2558 | 04f20795 | j_mayer | &clk_setup[PPC405CR_TMR_CLK], sysclk); |
2559 | 8ecc7913 | j_mayer | /* Memory mapped devices registers */
|
2560 | 8ecc7913 | j_mayer | mmio = ppc4xx_mmio_init(env, 0xEF600000);
|
2561 | 8ecc7913 | j_mayer | /* PLB arbitrer */
|
2562 | 8ecc7913 | j_mayer | ppc4xx_plb_init(env); |
2563 | 8ecc7913 | j_mayer | /* PLB to OPB bridge */
|
2564 | 8ecc7913 | j_mayer | ppc4xx_pob_init(env); |
2565 | 8ecc7913 | j_mayer | /* OBP arbitrer */
|
2566 | 8ecc7913 | j_mayer | ppc4xx_opba_init(env, mmio, 0x600);
|
2567 | 8ecc7913 | j_mayer | /* Universal interrupt controller */
|
2568 | 8ecc7913 | j_mayer | irqs = qemu_mallocz(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
|
2569 | 8ecc7913 | j_mayer | irqs[PPCUIC_OUTPUT_INT] = |
2570 | b48d7d69 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; |
2571 | 8ecc7913 | j_mayer | irqs[PPCUIC_OUTPUT_CINT] = |
2572 | b48d7d69 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT]; |
2573 | 8ecc7913 | j_mayer | pic = ppcuic_init(env, irqs, 0x0C0, 0, 1); |
2574 | 8ecc7913 | j_mayer | *picp = pic; |
2575 | 8ecc7913 | j_mayer | /* SDRAM controller */
|
2576 | 04f20795 | j_mayer | ppc405_sdram_init(env, pic[14], 1, ram_bases, ram_sizes, do_init); |
2577 | 8ecc7913 | j_mayer | offset = 0;
|
2578 | 8ecc7913 | j_mayer | for (i = 0; i < 4; i++) |
2579 | 8ecc7913 | j_mayer | offset += ram_sizes[i]; |
2580 | 8ecc7913 | j_mayer | /* External bus controller */
|
2581 | 8ecc7913 | j_mayer | ppc405_ebc_init(env); |
2582 | 8ecc7913 | j_mayer | /* DMA controller */
|
2583 | 04f20795 | j_mayer | dma_irqs[0] = pic[26]; |
2584 | 04f20795 | j_mayer | dma_irqs[1] = pic[25]; |
2585 | 04f20795 | j_mayer | dma_irqs[2] = pic[24]; |
2586 | 04f20795 | j_mayer | dma_irqs[3] = pic[23]; |
2587 | 8ecc7913 | j_mayer | ppc405_dma_init(env, dma_irqs); |
2588 | 8ecc7913 | j_mayer | /* Serial ports */
|
2589 | 8ecc7913 | j_mayer | if (serial_hds[0] != NULL) { |
2590 | 923e5e33 | aurel32 | ppc405_serial_init(env, mmio, 0x300, pic[0], serial_hds[0]); |
2591 | 8ecc7913 | j_mayer | } |
2592 | 8ecc7913 | j_mayer | if (serial_hds[1] != NULL) { |
2593 | 923e5e33 | aurel32 | ppc405_serial_init(env, mmio, 0x400, pic[1], serial_hds[1]); |
2594 | 8ecc7913 | j_mayer | } |
2595 | 8ecc7913 | j_mayer | /* IIC controller */
|
2596 | 923e5e33 | aurel32 | ppc405_i2c_init(env, mmio, 0x500, pic[2]); |
2597 | 8ecc7913 | j_mayer | /* GPIO */
|
2598 | 8ecc7913 | j_mayer | ppc405_gpio_init(env, mmio, 0x700);
|
2599 | 8ecc7913 | j_mayer | /* CPU control */
|
2600 | 8ecc7913 | j_mayer | ppc405cr_cpc_init(env, clk_setup, sysclk); |
2601 | 8ecc7913 | j_mayer | *offsetp = offset; |
2602 | 8ecc7913 | j_mayer | |
2603 | 8ecc7913 | j_mayer | return env;
|
2604 | 8ecc7913 | j_mayer | } |
2605 | 8ecc7913 | j_mayer | |
2606 | 8ecc7913 | j_mayer | /*****************************************************************************/
|
2607 | 8ecc7913 | j_mayer | /* PowerPC 405EP */
|
2608 | 8ecc7913 | j_mayer | /* CPU control */
|
2609 | 8ecc7913 | j_mayer | enum {
|
2610 | 8ecc7913 | j_mayer | PPC405EP_CPC0_PLLMR0 = 0x0F0,
|
2611 | 8ecc7913 | j_mayer | PPC405EP_CPC0_BOOT = 0x0F1,
|
2612 | 8ecc7913 | j_mayer | PPC405EP_CPC0_EPCTL = 0x0F3,
|
2613 | 8ecc7913 | j_mayer | PPC405EP_CPC0_PLLMR1 = 0x0F4,
|
2614 | 8ecc7913 | j_mayer | PPC405EP_CPC0_UCR = 0x0F5,
|
2615 | 8ecc7913 | j_mayer | PPC405EP_CPC0_SRR = 0x0F6,
|
2616 | 8ecc7913 | j_mayer | PPC405EP_CPC0_JTAGID = 0x0F7,
|
2617 | 8ecc7913 | j_mayer | PPC405EP_CPC0_PCI = 0x0F9,
|
2618 | 9c02f1a2 | j_mayer | #if 0
|
2619 | 9c02f1a2 | j_mayer | PPC405EP_CPC0_ER = xxx,
|
2620 | 9c02f1a2 | j_mayer | PPC405EP_CPC0_FR = xxx,
|
2621 | 9c02f1a2 | j_mayer | PPC405EP_CPC0_SR = xxx,
|
2622 | 9c02f1a2 | j_mayer | #endif
|
2623 | 8ecc7913 | j_mayer | }; |
2624 | 8ecc7913 | j_mayer | |
2625 | 04f20795 | j_mayer | enum {
|
2626 | 04f20795 | j_mayer | PPC405EP_CPU_CLK = 0,
|
2627 | 04f20795 | j_mayer | PPC405EP_PLB_CLK = 1,
|
2628 | 04f20795 | j_mayer | PPC405EP_OPB_CLK = 2,
|
2629 | 04f20795 | j_mayer | PPC405EP_EBC_CLK = 3,
|
2630 | 04f20795 | j_mayer | PPC405EP_MAL_CLK = 4,
|
2631 | 04f20795 | j_mayer | PPC405EP_PCI_CLK = 5,
|
2632 | 04f20795 | j_mayer | PPC405EP_UART0_CLK = 6,
|
2633 | 04f20795 | j_mayer | PPC405EP_UART1_CLK = 7,
|
2634 | 04f20795 | j_mayer | PPC405EP_CLK_NB = 8,
|
2635 | 04f20795 | j_mayer | }; |
2636 | 04f20795 | j_mayer | |
2637 | 8ecc7913 | j_mayer | typedef struct ppc405ep_cpc_t ppc405ep_cpc_t; |
2638 | 8ecc7913 | j_mayer | struct ppc405ep_cpc_t {
|
2639 | 8ecc7913 | j_mayer | uint32_t sysclk; |
2640 | 04f20795 | j_mayer | clk_setup_t clk_setup[PPC405EP_CLK_NB]; |
2641 | 8ecc7913 | j_mayer | uint32_t boot; |
2642 | 8ecc7913 | j_mayer | uint32_t epctl; |
2643 | 8ecc7913 | j_mayer | uint32_t pllmr[2];
|
2644 | 8ecc7913 | j_mayer | uint32_t ucr; |
2645 | 8ecc7913 | j_mayer | uint32_t srr; |
2646 | 8ecc7913 | j_mayer | uint32_t jtagid; |
2647 | 8ecc7913 | j_mayer | uint32_t pci; |
2648 | 9c02f1a2 | j_mayer | /* Clock and power management */
|
2649 | 9c02f1a2 | j_mayer | uint32_t er; |
2650 | 9c02f1a2 | j_mayer | uint32_t fr; |
2651 | 9c02f1a2 | j_mayer | uint32_t sr; |
2652 | 8ecc7913 | j_mayer | }; |
2653 | 8ecc7913 | j_mayer | |
2654 | 8ecc7913 | j_mayer | static void ppc405ep_compute_clocks (ppc405ep_cpc_t *cpc) |
2655 | 8ecc7913 | j_mayer | { |
2656 | 8ecc7913 | j_mayer | uint32_t CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk; |
2657 | 8ecc7913 | j_mayer | uint32_t UART0_clk, UART1_clk; |
2658 | 8ecc7913 | j_mayer | uint64_t VCO_out, PLL_out; |
2659 | 8ecc7913 | j_mayer | int M, D;
|
2660 | 8ecc7913 | j_mayer | |
2661 | 8ecc7913 | j_mayer | VCO_out = 0;
|
2662 | 8ecc7913 | j_mayer | if ((cpc->pllmr[1] & 0x80000000) && !(cpc->pllmr[1] & 0x40000000)) { |
2663 | 8ecc7913 | j_mayer | M = (((cpc->pllmr[1] >> 20) - 1) & 0xF) + 1; /* FBMUL */ |
2664 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2665 | aae9366a | j_mayer | printf("FBMUL %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 20) & 0xF, M); |
2666 | aae9366a | j_mayer | #endif
|
2667 | 8ecc7913 | j_mayer | D = 8 - ((cpc->pllmr[1] >> 16) & 0x7); /* FWDA */ |
2668 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2669 | aae9366a | j_mayer | printf("FWDA %01" PRIx32 " %d\n", (cpc->pllmr[1] >> 16) & 0x7, D); |
2670 | aae9366a | j_mayer | #endif
|
2671 | 8ecc7913 | j_mayer | VCO_out = cpc->sysclk * M * D; |
2672 | 8ecc7913 | j_mayer | if (VCO_out < 500000000UL || VCO_out > 1000000000UL) { |
2673 | 8ecc7913 | j_mayer | /* Error - unlock the PLL */
|
2674 | 8ecc7913 | j_mayer | printf("VCO out of range %" PRIu64 "\n", VCO_out); |
2675 | 8ecc7913 | j_mayer | #if 0
|
2676 | 8ecc7913 | j_mayer | cpc->pllmr[1] &= ~0x80000000;
|
2677 | 8ecc7913 | j_mayer | goto pll_bypass;
|
2678 | 8ecc7913 | j_mayer | #endif
|
2679 | 8ecc7913 | j_mayer | } |
2680 | 8ecc7913 | j_mayer | PLL_out = VCO_out / D; |
2681 | 9c02f1a2 | j_mayer | /* Pretend the PLL is locked */
|
2682 | 9c02f1a2 | j_mayer | cpc->boot |= 0x00000001;
|
2683 | 8ecc7913 | j_mayer | } else {
|
2684 | 8ecc7913 | j_mayer | #if 0
|
2685 | 8ecc7913 | j_mayer | pll_bypass:
|
2686 | 8ecc7913 | j_mayer | #endif
|
2687 | 8ecc7913 | j_mayer | PLL_out = cpc->sysclk; |
2688 | 9c02f1a2 | j_mayer | if (cpc->pllmr[1] & 0x40000000) { |
2689 | 9c02f1a2 | j_mayer | /* Pretend the PLL is not locked */
|
2690 | 9c02f1a2 | j_mayer | cpc->boot &= ~0x00000001;
|
2691 | 9c02f1a2 | j_mayer | } |
2692 | 8ecc7913 | j_mayer | } |
2693 | 8ecc7913 | j_mayer | /* Now, compute all other clocks */
|
2694 | 8ecc7913 | j_mayer | D = ((cpc->pllmr[0] >> 20) & 0x3) + 1; /* CCDV */ |
2695 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2696 | aae9366a | j_mayer | printf("CCDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 20) & 0x3, D); |
2697 | 8ecc7913 | j_mayer | #endif
|
2698 | 8ecc7913 | j_mayer | CPU_clk = PLL_out / D; |
2699 | 8ecc7913 | j_mayer | D = ((cpc->pllmr[0] >> 16) & 0x3) + 1; /* CBDV */ |
2700 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2701 | aae9366a | j_mayer | printf("CBDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 16) & 0x3, D); |
2702 | 8ecc7913 | j_mayer | #endif
|
2703 | 8ecc7913 | j_mayer | PLB_clk = CPU_clk / D; |
2704 | 8ecc7913 | j_mayer | D = ((cpc->pllmr[0] >> 12) & 0x3) + 1; /* OPDV */ |
2705 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2706 | aae9366a | j_mayer | printf("OPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 12) & 0x3, D); |
2707 | 8ecc7913 | j_mayer | #endif
|
2708 | 8ecc7913 | j_mayer | OPB_clk = PLB_clk / D; |
2709 | 8ecc7913 | j_mayer | D = ((cpc->pllmr[0] >> 8) & 0x3) + 2; /* EPDV */ |
2710 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2711 | aae9366a | j_mayer | printf("EPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 8) & 0x3, D); |
2712 | 8ecc7913 | j_mayer | #endif
|
2713 | 8ecc7913 | j_mayer | EBC_clk = PLB_clk / D; |
2714 | 8ecc7913 | j_mayer | D = ((cpc->pllmr[0] >> 4) & 0x3) + 1; /* MPDV */ |
2715 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2716 | aae9366a | j_mayer | printf("MPDV %01" PRIx32 " %d\n", (cpc->pllmr[0] >> 4) & 0x3, D); |
2717 | 8ecc7913 | j_mayer | #endif
|
2718 | 8ecc7913 | j_mayer | MAL_clk = PLB_clk / D; |
2719 | 8ecc7913 | j_mayer | D = (cpc->pllmr[0] & 0x3) + 1; /* PPDV */ |
2720 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2721 | aae9366a | j_mayer | printf("PPDV %01" PRIx32 " %d\n", cpc->pllmr[0] & 0x3, D); |
2722 | 8ecc7913 | j_mayer | #endif
|
2723 | 8ecc7913 | j_mayer | PCI_clk = PLB_clk / D; |
2724 | 8ecc7913 | j_mayer | D = ((cpc->ucr - 1) & 0x7F) + 1; /* U0DIV */ |
2725 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2726 | aae9366a | j_mayer | printf("U0DIV %01" PRIx32 " %d\n", cpc->ucr & 0x7F, D); |
2727 | 8ecc7913 | j_mayer | #endif
|
2728 | 8ecc7913 | j_mayer | UART0_clk = PLL_out / D; |
2729 | 8ecc7913 | j_mayer | D = (((cpc->ucr >> 8) - 1) & 0x7F) + 1; /* U1DIV */ |
2730 | aae9366a | j_mayer | #ifdef DEBUG_CLOCKS_LL
|
2731 | aae9366a | j_mayer | printf("U1DIV %01" PRIx32 " %d\n", (cpc->ucr >> 8) & 0x7F, D); |
2732 | 8ecc7913 | j_mayer | #endif
|
2733 | 8ecc7913 | j_mayer | UART1_clk = PLL_out / D; |
2734 | 8ecc7913 | j_mayer | #ifdef DEBUG_CLOCKS
|
2735 | aae9366a | j_mayer | printf("Setup PPC405EP clocks - sysclk %" PRIu32 " VCO %" PRIu64 |
2736 | 8ecc7913 | j_mayer | " PLL out %" PRIu64 " Hz\n", cpc->sysclk, VCO_out, PLL_out); |
2737 | aae9366a | j_mayer | printf("CPU %" PRIu32 " PLB %" PRIu32 " OPB %" PRIu32 " EBC %" PRIu32 |
2738 | aae9366a | j_mayer | " MAL %" PRIu32 " PCI %" PRIu32 " UART0 %" PRIu32 |
2739 | aae9366a | j_mayer | " UART1 %" PRIu32 "\n", |
2740 | 8ecc7913 | j_mayer | CPU_clk, PLB_clk, OPB_clk, EBC_clk, MAL_clk, PCI_clk, |
2741 | 8ecc7913 | j_mayer | UART0_clk, UART1_clk); |
2742 | 8ecc7913 | j_mayer | #endif
|
2743 | 8ecc7913 | j_mayer | /* Setup CPU clocks */
|
2744 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405EP_CPU_CLK], CPU_clk); |
2745 | 8ecc7913 | j_mayer | /* Setup PLB clock */
|
2746 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405EP_PLB_CLK], PLB_clk); |
2747 | 8ecc7913 | j_mayer | /* Setup OPB clock */
|
2748 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405EP_OPB_CLK], OPB_clk); |
2749 | 8ecc7913 | j_mayer | /* Setup external clock */
|
2750 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405EP_EBC_CLK], EBC_clk); |
2751 | 8ecc7913 | j_mayer | /* Setup MAL clock */
|
2752 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405EP_MAL_CLK], MAL_clk); |
2753 | 8ecc7913 | j_mayer | /* Setup PCI clock */
|
2754 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405EP_PCI_CLK], PCI_clk); |
2755 | 8ecc7913 | j_mayer | /* Setup UART0 clock */
|
2756 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405EP_UART0_CLK], UART0_clk); |
2757 | 8ecc7913 | j_mayer | /* Setup UART1 clock */
|
2758 | 04f20795 | j_mayer | clk_setup(&cpc->clk_setup[PPC405EP_UART1_CLK], UART1_clk); |
2759 | 8ecc7913 | j_mayer | } |
2760 | 8ecc7913 | j_mayer | |
2761 | 8ecc7913 | j_mayer | static target_ulong dcr_read_epcpc (void *opaque, int dcrn) |
2762 | 8ecc7913 | j_mayer | { |
2763 | 8ecc7913 | j_mayer | ppc405ep_cpc_t *cpc; |
2764 | 8ecc7913 | j_mayer | target_ulong ret; |
2765 | 8ecc7913 | j_mayer | |
2766 | 8ecc7913 | j_mayer | cpc = opaque; |
2767 | 8ecc7913 | j_mayer | switch (dcrn) {
|
2768 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_BOOT:
|
2769 | 8ecc7913 | j_mayer | ret = cpc->boot; |
2770 | 8ecc7913 | j_mayer | break;
|
2771 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_EPCTL:
|
2772 | 8ecc7913 | j_mayer | ret = cpc->epctl; |
2773 | 8ecc7913 | j_mayer | break;
|
2774 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_PLLMR0:
|
2775 | 8ecc7913 | j_mayer | ret = cpc->pllmr[0];
|
2776 | 8ecc7913 | j_mayer | break;
|
2777 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_PLLMR1:
|
2778 | 8ecc7913 | j_mayer | ret = cpc->pllmr[1];
|
2779 | 8ecc7913 | j_mayer | break;
|
2780 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_UCR:
|
2781 | 8ecc7913 | j_mayer | ret = cpc->ucr; |
2782 | 8ecc7913 | j_mayer | break;
|
2783 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_SRR:
|
2784 | 8ecc7913 | j_mayer | ret = cpc->srr; |
2785 | 8ecc7913 | j_mayer | break;
|
2786 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_JTAGID:
|
2787 | 8ecc7913 | j_mayer | ret = cpc->jtagid; |
2788 | 8ecc7913 | j_mayer | break;
|
2789 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_PCI:
|
2790 | 8ecc7913 | j_mayer | ret = cpc->pci; |
2791 | 8ecc7913 | j_mayer | break;
|
2792 | 8ecc7913 | j_mayer | default:
|
2793 | 8ecc7913 | j_mayer | /* Avoid gcc warning */
|
2794 | 8ecc7913 | j_mayer | ret = 0;
|
2795 | 8ecc7913 | j_mayer | break;
|
2796 | 8ecc7913 | j_mayer | } |
2797 | 8ecc7913 | j_mayer | |
2798 | 8ecc7913 | j_mayer | return ret;
|
2799 | 8ecc7913 | j_mayer | } |
2800 | 8ecc7913 | j_mayer | |
2801 | 8ecc7913 | j_mayer | static void dcr_write_epcpc (void *opaque, int dcrn, target_ulong val) |
2802 | 8ecc7913 | j_mayer | { |
2803 | 8ecc7913 | j_mayer | ppc405ep_cpc_t *cpc; |
2804 | 8ecc7913 | j_mayer | |
2805 | 8ecc7913 | j_mayer | cpc = opaque; |
2806 | 8ecc7913 | j_mayer | switch (dcrn) {
|
2807 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_BOOT:
|
2808 | 8ecc7913 | j_mayer | /* Read-only register */
|
2809 | 8ecc7913 | j_mayer | break;
|
2810 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_EPCTL:
|
2811 | 8ecc7913 | j_mayer | /* Don't care for now */
|
2812 | 8ecc7913 | j_mayer | cpc->epctl = val & 0xC00000F3;
|
2813 | 8ecc7913 | j_mayer | break;
|
2814 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_PLLMR0:
|
2815 | 8ecc7913 | j_mayer | cpc->pllmr[0] = val & 0x00633333; |
2816 | 8ecc7913 | j_mayer | ppc405ep_compute_clocks(cpc); |
2817 | 8ecc7913 | j_mayer | break;
|
2818 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_PLLMR1:
|
2819 | 8ecc7913 | j_mayer | cpc->pllmr[1] = val & 0xC0F73FFF; |
2820 | 8ecc7913 | j_mayer | ppc405ep_compute_clocks(cpc); |
2821 | 8ecc7913 | j_mayer | break;
|
2822 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_UCR:
|
2823 | 8ecc7913 | j_mayer | /* UART control - don't care for now */
|
2824 | 8ecc7913 | j_mayer | cpc->ucr = val & 0x003F7F7F;
|
2825 | 8ecc7913 | j_mayer | break;
|
2826 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_SRR:
|
2827 | 8ecc7913 | j_mayer | cpc->srr = val; |
2828 | 8ecc7913 | j_mayer | break;
|
2829 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_JTAGID:
|
2830 | 8ecc7913 | j_mayer | /* Read-only */
|
2831 | 8ecc7913 | j_mayer | break;
|
2832 | 8ecc7913 | j_mayer | case PPC405EP_CPC0_PCI:
|
2833 | 8ecc7913 | j_mayer | cpc->pci = val; |
2834 | 8ecc7913 | j_mayer | break;
|
2835 | 8ecc7913 | j_mayer | } |
2836 | 8ecc7913 | j_mayer | } |
2837 | 8ecc7913 | j_mayer | |
2838 | 8ecc7913 | j_mayer | static void ppc405ep_cpc_reset (void *opaque) |
2839 | 8ecc7913 | j_mayer | { |
2840 | 8ecc7913 | j_mayer | ppc405ep_cpc_t *cpc = opaque; |
2841 | 8ecc7913 | j_mayer | |
2842 | 8ecc7913 | j_mayer | cpc->boot = 0x00000010; /* Boot from PCI - IIC EEPROM disabled */ |
2843 | 8ecc7913 | j_mayer | cpc->epctl = 0x00000000;
|
2844 | 8ecc7913 | j_mayer | cpc->pllmr[0] = 0x00011010; |
2845 | 8ecc7913 | j_mayer | cpc->pllmr[1] = 0x40000000; |
2846 | 8ecc7913 | j_mayer | cpc->ucr = 0x00000000;
|
2847 | 8ecc7913 | j_mayer | cpc->srr = 0x00040000;
|
2848 | 8ecc7913 | j_mayer | cpc->pci = 0x00000000;
|
2849 | 9c02f1a2 | j_mayer | cpc->er = 0x00000000;
|
2850 | 9c02f1a2 | j_mayer | cpc->fr = 0x00000000;
|
2851 | 9c02f1a2 | j_mayer | cpc->sr = 0x00000000;
|
2852 | 8ecc7913 | j_mayer | ppc405ep_compute_clocks(cpc); |
2853 | 8ecc7913 | j_mayer | } |
2854 | 8ecc7913 | j_mayer | |
2855 | 8ecc7913 | j_mayer | /* XXX: sysclk should be between 25 and 100 MHz */
|
2856 | 8ecc7913 | j_mayer | static void ppc405ep_cpc_init (CPUState *env, clk_setup_t clk_setup[8], |
2857 | 8ecc7913 | j_mayer | uint32_t sysclk) |
2858 | 8ecc7913 | j_mayer | { |
2859 | 8ecc7913 | j_mayer | ppc405ep_cpc_t *cpc; |
2860 | 8ecc7913 | j_mayer | |
2861 | 8ecc7913 | j_mayer | cpc = qemu_mallocz(sizeof(ppc405ep_cpc_t));
|
2862 | 8ecc7913 | j_mayer | if (cpc != NULL) { |
2863 | 04f20795 | j_mayer | memcpy(cpc->clk_setup, clk_setup, |
2864 | 04f20795 | j_mayer | PPC405EP_CLK_NB * sizeof(clk_setup_t));
|
2865 | 8ecc7913 | j_mayer | cpc->jtagid = 0x20267049;
|
2866 | 8ecc7913 | j_mayer | cpc->sysclk = sysclk; |
2867 | 8ecc7913 | j_mayer | ppc405ep_cpc_reset(cpc); |
2868 | 8ecc7913 | j_mayer | qemu_register_reset(&ppc405ep_cpc_reset, cpc); |
2869 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_BOOT, cpc, |
2870 | 8ecc7913 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc); |
2871 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_EPCTL, cpc, |
2872 | 8ecc7913 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc); |
2873 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_PLLMR0, cpc, |
2874 | 8ecc7913 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc); |
2875 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_PLLMR1, cpc, |
2876 | 8ecc7913 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc); |
2877 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_UCR, cpc, |
2878 | 8ecc7913 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc); |
2879 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_SRR, cpc, |
2880 | 8ecc7913 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc); |
2881 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_JTAGID, cpc, |
2882 | 8ecc7913 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc); |
2883 | 8ecc7913 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_PCI, cpc, |
2884 | 8ecc7913 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc); |
2885 | 9c02f1a2 | j_mayer | #if 0
|
2886 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_ER, cpc,
|
2887 | 9c02f1a2 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc);
|
2888 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_FR, cpc,
|
2889 | 9c02f1a2 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc);
|
2890 | 9c02f1a2 | j_mayer | ppc_dcr_register(env, PPC405EP_CPC0_SR, cpc,
|
2891 | 9c02f1a2 | j_mayer | &dcr_read_epcpc, &dcr_write_epcpc);
|
2892 | 9c02f1a2 | j_mayer | #endif
|
2893 | 8ecc7913 | j_mayer | } |
2894 | 8ecc7913 | j_mayer | } |
2895 | 8ecc7913 | j_mayer | |
2896 | 71db710f | blueswir1 | CPUState *ppc405ep_init (target_phys_addr_t ram_bases[2],
|
2897 | 71db710f | blueswir1 | target_phys_addr_t ram_sizes[2],
|
2898 | 8ecc7913 | j_mayer | uint32_t sysclk, qemu_irq **picp, |
2899 | 04f20795 | j_mayer | ram_addr_t *offsetp, int do_init)
|
2900 | 8ecc7913 | j_mayer | { |
2901 | 9c02f1a2 | j_mayer | clk_setup_t clk_setup[PPC405EP_CLK_NB], tlb_clk_setup; |
2902 | 9c02f1a2 | j_mayer | qemu_irq dma_irqs[4], gpt_irqs[5], mal_irqs[4]; |
2903 | 8ecc7913 | j_mayer | CPUState *env; |
2904 | 8ecc7913 | j_mayer | ppc4xx_mmio_t *mmio; |
2905 | 8ecc7913 | j_mayer | qemu_irq *pic, *irqs; |
2906 | 8ecc7913 | j_mayer | ram_addr_t offset; |
2907 | 8ecc7913 | j_mayer | int i;
|
2908 | 8ecc7913 | j_mayer | |
2909 | 8ecc7913 | j_mayer | memset(clk_setup, 0, sizeof(clk_setup)); |
2910 | 8ecc7913 | j_mayer | /* init CPUs */
|
2911 | 008ff9d7 | j_mayer | env = ppc4xx_init("405ep", &clk_setup[PPC405EP_CPU_CLK],
|
2912 | 9c02f1a2 | j_mayer | &tlb_clk_setup, sysclk); |
2913 | 9c02f1a2 | j_mayer | clk_setup[PPC405EP_CPU_CLK].cb = tlb_clk_setup.cb; |
2914 | 9c02f1a2 | j_mayer | clk_setup[PPC405EP_CPU_CLK].opaque = tlb_clk_setup.opaque; |
2915 | 8ecc7913 | j_mayer | /* Internal devices init */
|
2916 | 8ecc7913 | j_mayer | /* Memory mapped devices registers */
|
2917 | 8ecc7913 | j_mayer | mmio = ppc4xx_mmio_init(env, 0xEF600000);
|
2918 | 8ecc7913 | j_mayer | /* PLB arbitrer */
|
2919 | 8ecc7913 | j_mayer | ppc4xx_plb_init(env); |
2920 | 8ecc7913 | j_mayer | /* PLB to OPB bridge */
|
2921 | 8ecc7913 | j_mayer | ppc4xx_pob_init(env); |
2922 | 8ecc7913 | j_mayer | /* OBP arbitrer */
|
2923 | 8ecc7913 | j_mayer | ppc4xx_opba_init(env, mmio, 0x600);
|
2924 | 8ecc7913 | j_mayer | /* Universal interrupt controller */
|
2925 | 8ecc7913 | j_mayer | irqs = qemu_mallocz(sizeof(qemu_irq) * PPCUIC_OUTPUT_NB);
|
2926 | 8ecc7913 | j_mayer | irqs[PPCUIC_OUTPUT_INT] = |
2927 | b48d7d69 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT]; |
2928 | 8ecc7913 | j_mayer | irqs[PPCUIC_OUTPUT_CINT] = |
2929 | b48d7d69 | j_mayer | ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT]; |
2930 | 8ecc7913 | j_mayer | pic = ppcuic_init(env, irqs, 0x0C0, 0, 1); |
2931 | 8ecc7913 | j_mayer | *picp = pic; |
2932 | 8ecc7913 | j_mayer | /* SDRAM controller */
|
2933 | 923e5e33 | aurel32 | /* XXX 405EP has no ECC interrupt */
|
2934 | 923e5e33 | aurel32 | ppc405_sdram_init(env, pic[17], 2, ram_bases, ram_sizes, do_init); |
2935 | 8ecc7913 | j_mayer | offset = 0;
|
2936 | 8ecc7913 | j_mayer | for (i = 0; i < 2; i++) |
2937 | 8ecc7913 | j_mayer | offset += ram_sizes[i]; |
2938 | 8ecc7913 | j_mayer | /* External bus controller */
|
2939 | 8ecc7913 | j_mayer | ppc405_ebc_init(env); |
2940 | 8ecc7913 | j_mayer | /* DMA controller */
|
2941 | 923e5e33 | aurel32 | dma_irqs[0] = pic[5]; |
2942 | 923e5e33 | aurel32 | dma_irqs[1] = pic[6]; |
2943 | 923e5e33 | aurel32 | dma_irqs[2] = pic[7]; |
2944 | 923e5e33 | aurel32 | dma_irqs[3] = pic[8]; |
2945 | 8ecc7913 | j_mayer | ppc405_dma_init(env, dma_irqs); |
2946 | 8ecc7913 | j_mayer | /* IIC controller */
|
2947 | 923e5e33 | aurel32 | ppc405_i2c_init(env, mmio, 0x500, pic[2]); |
2948 | 8ecc7913 | j_mayer | /* GPIO */
|
2949 | 8ecc7913 | j_mayer | ppc405_gpio_init(env, mmio, 0x700);
|
2950 | 8ecc7913 | j_mayer | /* Serial ports */
|
2951 | 8ecc7913 | j_mayer | if (serial_hds[0] != NULL) { |
2952 | 923e5e33 | aurel32 | ppc405_serial_init(env, mmio, 0x300, pic[0], serial_hds[0]); |
2953 | 8ecc7913 | j_mayer | } |
2954 | 8ecc7913 | j_mayer | if (serial_hds[1] != NULL) { |
2955 | 923e5e33 | aurel32 | ppc405_serial_init(env, mmio, 0x400, pic[1], serial_hds[1]); |
2956 | 8ecc7913 | j_mayer | } |
2957 | 8ecc7913 | j_mayer | /* OCM */
|
2958 | 8ecc7913 | j_mayer | ppc405_ocm_init(env, ram_sizes[0] + ram_sizes[1]); |
2959 | 8ecc7913 | j_mayer | offset += 4096;
|
2960 | 9c02f1a2 | j_mayer | /* GPT */
|
2961 | 923e5e33 | aurel32 | gpt_irqs[0] = pic[19]; |
2962 | 923e5e33 | aurel32 | gpt_irqs[1] = pic[20]; |
2963 | 923e5e33 | aurel32 | gpt_irqs[2] = pic[21]; |
2964 | 923e5e33 | aurel32 | gpt_irqs[3] = pic[22]; |
2965 | 923e5e33 | aurel32 | gpt_irqs[4] = pic[23]; |
2966 | 9c02f1a2 | j_mayer | ppc4xx_gpt_init(env, mmio, 0x000, gpt_irqs);
|
2967 | 8ecc7913 | j_mayer | /* PCI */
|
2968 | 923e5e33 | aurel32 | /* Uses pic[3], pic[16], pic[18] */
|
2969 | 9c02f1a2 | j_mayer | /* MAL */
|
2970 | 923e5e33 | aurel32 | mal_irqs[0] = pic[11]; |
2971 | 923e5e33 | aurel32 | mal_irqs[1] = pic[12]; |
2972 | 923e5e33 | aurel32 | mal_irqs[2] = pic[13]; |
2973 | 923e5e33 | aurel32 | mal_irqs[3] = pic[14]; |
2974 | 9c02f1a2 | j_mayer | ppc405_mal_init(env, mal_irqs); |
2975 | 9c02f1a2 | j_mayer | /* Ethernet */
|
2976 | 923e5e33 | aurel32 | /* Uses pic[9], pic[15], pic[17] */
|
2977 | 8ecc7913 | j_mayer | /* CPU control */
|
2978 | 8ecc7913 | j_mayer | ppc405ep_cpc_init(env, clk_setup, sysclk); |
2979 | 8ecc7913 | j_mayer | *offsetp = offset; |
2980 | 8ecc7913 | j_mayer | |
2981 | 8ecc7913 | j_mayer | return env;
|
2982 | 8ecc7913 | j_mayer | } |