Statistics
| Branch: | Revision:

root / hw / gt64xxx.c @ 17786d52

History | View | Annotate | Download (32.7 kB)

1 fde7d5bd ths
/*
2 fde7d5bd ths
 * QEMU GT64120 PCI host
3 fde7d5bd ths
 *
4 4de9b249 ths
 * Copyright (c) 2006,2007 Aurelien Jarno
5 5fafdf24 ths
 *
6 fde7d5bd ths
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 fde7d5bd ths
 * of this software and associated documentation files (the "Software"), to deal
8 fde7d5bd ths
 * in the Software without restriction, including without limitation the rights
9 fde7d5bd ths
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 fde7d5bd ths
 * copies of the Software, and to permit persons to whom the Software is
11 fde7d5bd ths
 * furnished to do so, subject to the following conditions:
12 fde7d5bd ths
 *
13 fde7d5bd ths
 * The above copyright notice and this permission notice shall be included in
14 fde7d5bd ths
 * all copies or substantial portions of the Software.
15 fde7d5bd ths
 *
16 fde7d5bd ths
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 fde7d5bd ths
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 fde7d5bd ths
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 fde7d5bd ths
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 fde7d5bd ths
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 fde7d5bd ths
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 fde7d5bd ths
 * THE SOFTWARE.
23 fde7d5bd ths
 */
24 fde7d5bd ths
25 87ecb68b pbrook
#include "hw.h"
26 87ecb68b pbrook
#include "mips.h"
27 87ecb68b pbrook
#include "pci.h"
28 fde7d5bd ths
#include "pci_host.h"
29 4f5e19e6 Isaku Yamahata
#include "pc.h"
30 fde7d5bd ths
31 05b4ff43 ths
//#define DEBUG
32 05b4ff43 ths
33 05b4ff43 ths
#ifdef DEBUG
34 d0f2c4c6 malc
#define DPRINTF(fmt, ...) fprintf(stderr, "%s: " fmt, __FUNCTION__, ##__VA_ARGS__)
35 05b4ff43 ths
#else
36 d0f2c4c6 malc
#define DPRINTF(fmt, ...)
37 05b4ff43 ths
#endif
38 05b4ff43 ths
39 fde7d5bd ths
#define GT_REGS                        (0x1000 >> 2)
40 fde7d5bd ths
41 fde7d5bd ths
/* CPU Configuration */
42 fde7d5bd ths
#define GT_CPU                    (0x000 >> 2)
43 fde7d5bd ths
#define GT_MULTI                    (0x120 >> 2)
44 fde7d5bd ths
45 fde7d5bd ths
/* CPU Address Decode */
46 fde7d5bd ths
#define GT_SCS10LD                    (0x008 >> 2)
47 fde7d5bd ths
#define GT_SCS10HD                    (0x010 >> 2)
48 fde7d5bd ths
#define GT_SCS32LD                    (0x018 >> 2)
49 fde7d5bd ths
#define GT_SCS32HD                    (0x020 >> 2)
50 fde7d5bd ths
#define GT_CS20LD                    (0x028 >> 2)
51 fde7d5bd ths
#define GT_CS20HD                    (0x030 >> 2)
52 fde7d5bd ths
#define GT_CS3BOOTLD            (0x038 >> 2)
53 fde7d5bd ths
#define GT_CS3BOOTHD            (0x040 >> 2)
54 fde7d5bd ths
#define GT_PCI0IOLD                    (0x048 >> 2)
55 fde7d5bd ths
#define GT_PCI0IOHD                    (0x050 >> 2)
56 fde7d5bd ths
#define GT_PCI0M0LD                    (0x058 >> 2)
57 fde7d5bd ths
#define GT_PCI0M0HD                    (0x060 >> 2)
58 fde7d5bd ths
#define GT_PCI0M1LD                    (0x080 >> 2)
59 fde7d5bd ths
#define GT_PCI0M1HD                    (0x088 >> 2)
60 fde7d5bd ths
#define GT_PCI1IOLD                    (0x090 >> 2)
61 fde7d5bd ths
#define GT_PCI1IOHD                    (0x098 >> 2)
62 fde7d5bd ths
#define GT_PCI1M0LD                    (0x0a0 >> 2)
63 fde7d5bd ths
#define GT_PCI1M0HD                    (0x0a8 >> 2)
64 fde7d5bd ths
#define GT_PCI1M1LD                    (0x0b0 >> 2)
65 fde7d5bd ths
#define GT_PCI1M1HD                    (0x0b8 >> 2)
66 05b4ff43 ths
#define GT_ISD                    (0x068 >> 2)
67 fde7d5bd ths
68 fde7d5bd ths
#define GT_SCS10AR                    (0x0d0 >> 2)
69 fde7d5bd ths
#define GT_SCS32AR                    (0x0d8 >> 2)
70 fde7d5bd ths
#define GT_CS20R                    (0x0e0 >> 2)
71 fde7d5bd ths
#define GT_CS3BOOTR                    (0x0e8 >> 2)
72 fde7d5bd ths
73 fde7d5bd ths
#define GT_PCI0IOREMAP            (0x0f0 >> 2)
74 fde7d5bd ths
#define GT_PCI0M0REMAP            (0x0f8 >> 2)
75 fde7d5bd ths
#define GT_PCI0M1REMAP            (0x100 >> 2)
76 fde7d5bd ths
#define GT_PCI1IOREMAP            (0x108 >> 2)
77 fde7d5bd ths
#define GT_PCI1M0REMAP            (0x110 >> 2)
78 fde7d5bd ths
#define GT_PCI1M1REMAP            (0x118 >> 2)
79 fde7d5bd ths
80 fde7d5bd ths
/* CPU Error Report */
81 fde7d5bd ths
#define GT_CPUERR_ADDRLO            (0x070 >> 2)
82 fde7d5bd ths
#define GT_CPUERR_ADDRHI            (0x078 >> 2)
83 fde7d5bd ths
#define GT_CPUERR_DATALO            (0x128 >> 2)                /* GT-64120A only  */
84 fde7d5bd ths
#define GT_CPUERR_DATAHI            (0x130 >> 2)                /* GT-64120A only  */
85 fde7d5bd ths
#define GT_CPUERR_PARITY            (0x138 >> 2)                /* GT-64120A only  */
86 fde7d5bd ths
87 fde7d5bd ths
/* CPU Sync Barrier */
88 fde7d5bd ths
#define GT_PCI0SYNC                    (0x0c0 >> 2)
89 fde7d5bd ths
#define GT_PCI1SYNC                    (0x0c8 >> 2)
90 fde7d5bd ths
91 fde7d5bd ths
/* SDRAM and Device Address Decode */
92 fde7d5bd ths
#define GT_SCS0LD                    (0x400 >> 2)
93 fde7d5bd ths
#define GT_SCS0HD                    (0x404 >> 2)
94 fde7d5bd ths
#define GT_SCS1LD                    (0x408 >> 2)
95 fde7d5bd ths
#define GT_SCS1HD                    (0x40c >> 2)
96 fde7d5bd ths
#define GT_SCS2LD                    (0x410 >> 2)
97 fde7d5bd ths
#define GT_SCS2HD                    (0x414 >> 2)
98 fde7d5bd ths
#define GT_SCS3LD                    (0x418 >> 2)
99 fde7d5bd ths
#define GT_SCS3HD                    (0x41c >> 2)
100 fde7d5bd ths
#define GT_CS0LD                    (0x420 >> 2)
101 fde7d5bd ths
#define GT_CS0HD                    (0x424 >> 2)
102 fde7d5bd ths
#define GT_CS1LD                    (0x428 >> 2)
103 fde7d5bd ths
#define GT_CS1HD                    (0x42c >> 2)
104 fde7d5bd ths
#define GT_CS2LD                    (0x430 >> 2)
105 fde7d5bd ths
#define GT_CS2HD                    (0x434 >> 2)
106 fde7d5bd ths
#define GT_CS3LD                    (0x438 >> 2)
107 fde7d5bd ths
#define GT_CS3HD                    (0x43c >> 2)
108 fde7d5bd ths
#define GT_BOOTLD                    (0x440 >> 2)
109 fde7d5bd ths
#define GT_BOOTHD                    (0x444 >> 2)
110 fde7d5bd ths
#define GT_ADERR                    (0x470 >> 2)
111 fde7d5bd ths
112 fde7d5bd ths
/* SDRAM Configuration */
113 fde7d5bd ths
#define GT_SDRAM_CFG            (0x448 >> 2)
114 fde7d5bd ths
#define GT_SDRAM_OPMODE            (0x474 >> 2)
115 fde7d5bd ths
#define GT_SDRAM_BM                    (0x478 >> 2)
116 fde7d5bd ths
#define GT_SDRAM_ADDRDECODE            (0x47c >> 2)
117 fde7d5bd ths
118 fde7d5bd ths
/* SDRAM Parameters */
119 fde7d5bd ths
#define GT_SDRAM_B0                    (0x44c >> 2)
120 fde7d5bd ths
#define GT_SDRAM_B1                    (0x450 >> 2)
121 fde7d5bd ths
#define GT_SDRAM_B2                    (0x454 >> 2)
122 fde7d5bd ths
#define GT_SDRAM_B3                    (0x458 >> 2)
123 fde7d5bd ths
124 fde7d5bd ths
/* Device Parameters */
125 fde7d5bd ths
#define GT_DEV_B0                    (0x45c >> 2)
126 fde7d5bd ths
#define GT_DEV_B1                    (0x460 >> 2)
127 fde7d5bd ths
#define GT_DEV_B2                    (0x464 >> 2)
128 fde7d5bd ths
#define GT_DEV_B3                    (0x468 >> 2)
129 fde7d5bd ths
#define GT_DEV_BOOT                    (0x46c >> 2)
130 fde7d5bd ths
131 fde7d5bd ths
/* ECC */
132 fde7d5bd ths
#define GT_ECC_ERRDATALO        (0x480 >> 2)                /* GT-64120A only  */
133 fde7d5bd ths
#define GT_ECC_ERRDATAHI        (0x484 >> 2)                /* GT-64120A only  */
134 fde7d5bd ths
#define GT_ECC_MEM                (0x488 >> 2)                /* GT-64120A only  */
135 fde7d5bd ths
#define GT_ECC_CALC                (0x48c >> 2)                /* GT-64120A only  */
136 fde7d5bd ths
#define GT_ECC_ERRADDR                (0x490 >> 2)                /* GT-64120A only  */
137 fde7d5bd ths
138 fde7d5bd ths
/* DMA Record */
139 fde7d5bd ths
#define GT_DMA0_CNT                    (0x800 >> 2)
140 fde7d5bd ths
#define GT_DMA1_CNT                    (0x804 >> 2)
141 fde7d5bd ths
#define GT_DMA2_CNT                    (0x808 >> 2)
142 fde7d5bd ths
#define GT_DMA3_CNT                    (0x80c >> 2)
143 fde7d5bd ths
#define GT_DMA0_SA                    (0x810 >> 2)
144 fde7d5bd ths
#define GT_DMA1_SA                    (0x814 >> 2)
145 fde7d5bd ths
#define GT_DMA2_SA                    (0x818 >> 2)
146 fde7d5bd ths
#define GT_DMA3_SA                    (0x81c >> 2)
147 fde7d5bd ths
#define GT_DMA0_DA                    (0x820 >> 2)
148 fde7d5bd ths
#define GT_DMA1_DA                    (0x824 >> 2)
149 fde7d5bd ths
#define GT_DMA2_DA                    (0x828 >> 2)
150 fde7d5bd ths
#define GT_DMA3_DA                    (0x82c >> 2)
151 fde7d5bd ths
#define GT_DMA0_NEXT            (0x830 >> 2)
152 fde7d5bd ths
#define GT_DMA1_NEXT            (0x834 >> 2)
153 fde7d5bd ths
#define GT_DMA2_NEXT            (0x838 >> 2)
154 fde7d5bd ths
#define GT_DMA3_NEXT            (0x83c >> 2)
155 fde7d5bd ths
#define GT_DMA0_CUR                    (0x870 >> 2)
156 fde7d5bd ths
#define GT_DMA1_CUR                    (0x874 >> 2)
157 fde7d5bd ths
#define GT_DMA2_CUR                    (0x878 >> 2)
158 fde7d5bd ths
#define GT_DMA3_CUR                    (0x87c >> 2)
159 fde7d5bd ths
160 fde7d5bd ths
/* DMA Channel Control */
161 fde7d5bd ths
#define GT_DMA0_CTRL            (0x840 >> 2)
162 fde7d5bd ths
#define GT_DMA1_CTRL            (0x844 >> 2)
163 fde7d5bd ths
#define GT_DMA2_CTRL            (0x848 >> 2)
164 fde7d5bd ths
#define GT_DMA3_CTRL            (0x84c >> 2)
165 fde7d5bd ths
166 fde7d5bd ths
/* DMA Arbiter */
167 fde7d5bd ths
#define GT_DMA_ARB                    (0x860 >> 2)
168 fde7d5bd ths
169 fde7d5bd ths
/* Timer/Counter */
170 fde7d5bd ths
#define GT_TC0                    (0x850 >> 2)
171 fde7d5bd ths
#define GT_TC1                    (0x854 >> 2)
172 fde7d5bd ths
#define GT_TC2                    (0x858 >> 2)
173 fde7d5bd ths
#define GT_TC3                    (0x85c >> 2)
174 fde7d5bd ths
#define GT_TC_CONTROL            (0x864 >> 2)
175 fde7d5bd ths
176 fde7d5bd ths
/* PCI Internal */
177 fde7d5bd ths
#define GT_PCI0_CMD                    (0xc00 >> 2)
178 fde7d5bd ths
#define GT_PCI0_TOR                    (0xc04 >> 2)
179 fde7d5bd ths
#define GT_PCI0_BS_SCS10            (0xc08 >> 2)
180 fde7d5bd ths
#define GT_PCI0_BS_SCS32            (0xc0c >> 2)
181 fde7d5bd ths
#define GT_PCI0_BS_CS20            (0xc10 >> 2)
182 fde7d5bd ths
#define GT_PCI0_BS_CS3BT            (0xc14 >> 2)
183 fde7d5bd ths
#define GT_PCI1_IACK            (0xc30 >> 2)
184 fde7d5bd ths
#define GT_PCI0_IACK            (0xc34 >> 2)
185 fde7d5bd ths
#define GT_PCI0_BARE            (0xc3c >> 2)
186 fde7d5bd ths
#define GT_PCI0_PREFMBR            (0xc40 >> 2)
187 fde7d5bd ths
#define GT_PCI0_SCS10_BAR            (0xc48 >> 2)
188 fde7d5bd ths
#define GT_PCI0_SCS32_BAR            (0xc4c >> 2)
189 fde7d5bd ths
#define GT_PCI0_CS20_BAR            (0xc50 >> 2)
190 fde7d5bd ths
#define GT_PCI0_CS3BT_BAR            (0xc54 >> 2)
191 fde7d5bd ths
#define GT_PCI0_SSCS10_BAR            (0xc58 >> 2)
192 fde7d5bd ths
#define GT_PCI0_SSCS32_BAR            (0xc5c >> 2)
193 fde7d5bd ths
#define GT_PCI0_SCS3BT_BAR            (0xc64 >> 2)
194 fde7d5bd ths
#define GT_PCI1_CMD                    (0xc80 >> 2)
195 fde7d5bd ths
#define GT_PCI1_TOR                    (0xc84 >> 2)
196 fde7d5bd ths
#define GT_PCI1_BS_SCS10            (0xc88 >> 2)
197 fde7d5bd ths
#define GT_PCI1_BS_SCS32            (0xc8c >> 2)
198 fde7d5bd ths
#define GT_PCI1_BS_CS20            (0xc90 >> 2)
199 fde7d5bd ths
#define GT_PCI1_BS_CS3BT            (0xc94 >> 2)
200 fde7d5bd ths
#define GT_PCI1_BARE            (0xcbc >> 2)
201 fde7d5bd ths
#define GT_PCI1_PREFMBR            (0xcc0 >> 2)
202 fde7d5bd ths
#define GT_PCI1_SCS10_BAR            (0xcc8 >> 2)
203 fde7d5bd ths
#define GT_PCI1_SCS32_BAR            (0xccc >> 2)
204 fde7d5bd ths
#define GT_PCI1_CS20_BAR            (0xcd0 >> 2)
205 fde7d5bd ths
#define GT_PCI1_CS3BT_BAR            (0xcd4 >> 2)
206 fde7d5bd ths
#define GT_PCI1_SSCS10_BAR            (0xcd8 >> 2)
207 fde7d5bd ths
#define GT_PCI1_SSCS32_BAR            (0xcdc >> 2)
208 fde7d5bd ths
#define GT_PCI1_SCS3BT_BAR            (0xce4 >> 2)
209 fde7d5bd ths
#define GT_PCI1_CFGADDR            (0xcf0 >> 2)
210 fde7d5bd ths
#define GT_PCI1_CFGDATA            (0xcf4 >> 2)
211 fde7d5bd ths
#define GT_PCI0_CFGADDR            (0xcf8 >> 2)
212 fde7d5bd ths
#define GT_PCI0_CFGDATA            (0xcfc >> 2)
213 fde7d5bd ths
214 fde7d5bd ths
/* Interrupts */
215 fde7d5bd ths
#define GT_INTRCAUSE            (0xc18 >> 2)
216 fde7d5bd ths
#define GT_INTRMASK                    (0xc1c >> 2)
217 fde7d5bd ths
#define GT_PCI0_ICMASK            (0xc24 >> 2)
218 fde7d5bd ths
#define GT_PCI0_SERR0MASK            (0xc28 >> 2)
219 fde7d5bd ths
#define GT_CPU_INTSEL            (0xc70 >> 2)
220 fde7d5bd ths
#define GT_PCI0_INTSEL            (0xc74 >> 2)
221 fde7d5bd ths
#define GT_HINTRCAUSE            (0xc98 >> 2)
222 fde7d5bd ths
#define GT_HINTRMASK            (0xc9c >> 2)
223 fde7d5bd ths
#define GT_PCI0_HICMASK            (0xca4 >> 2)
224 fde7d5bd ths
#define GT_PCI1_SERR1MASK            (0xca8 >> 2)
225 fde7d5bd ths
226 fde7d5bd ths
227 fde7d5bd ths
typedef PCIHostState GT64120PCIState;
228 fde7d5bd ths
229 a0a8793e ths
#define PCI_MAPPING_ENTRY(regname)            \
230 c227f099 Anthony Liguori
    target_phys_addr_t regname ##_start;      \
231 c227f099 Anthony Liguori
    target_phys_addr_t regname ##_length;     \
232 a0a8793e ths
    int regname ##_handle
233 a0a8793e ths
234 fde7d5bd ths
typedef struct GT64120State {
235 fde7d5bd ths
    GT64120PCIState *pci;
236 fde7d5bd ths
    uint32_t regs[GT_REGS];
237 a0a8793e ths
    PCI_MAPPING_ENTRY(PCI0IO);
238 a0a8793e ths
    PCI_MAPPING_ENTRY(ISD);
239 fde7d5bd ths
} GT64120State;
240 fde7d5bd ths
241 a0a8793e ths
/* Adjust range to avoid touching space which isn't mappable via PCI */
242 a0a8793e ths
/* XXX: Hardcoded values for Malta: 0x1e000000 - 0x1f100000
243 a0a8793e ths
                                    0x1fc00000 - 0x1fd00000  */
244 c227f099 Anthony Liguori
static void check_reserved_space (target_phys_addr_t *start,
245 c227f099 Anthony Liguori
                                  target_phys_addr_t *length)
246 a0a8793e ths
{
247 c227f099 Anthony Liguori
    target_phys_addr_t begin = *start;
248 c227f099 Anthony Liguori
    target_phys_addr_t end = *start + *length;
249 a0a8793e ths
250 a0a8793e ths
    if (end >= 0x1e000000LL && end < 0x1f100000LL)
251 a0a8793e ths
        end = 0x1e000000LL;
252 a0a8793e ths
    if (begin >= 0x1e000000LL && begin < 0x1f100000LL)
253 a0a8793e ths
        begin = 0x1f100000LL;
254 a0a8793e ths
    if (end >= 0x1fc00000LL && end < 0x1fd00000LL)
255 a0a8793e ths
        end = 0x1fc00000LL;
256 a0a8793e ths
    if (begin >= 0x1fc00000LL && begin < 0x1fd00000LL)
257 a0a8793e ths
        begin = 0x1fd00000LL;
258 a0a8793e ths
    /* XXX: This is broken when a reserved range splits the requested range */
259 a0a8793e ths
    if (end >= 0x1f100000LL && begin < 0x1e000000LL)
260 a0a8793e ths
        end = 0x1e000000LL;
261 a0a8793e ths
    if (end >= 0x1fd00000LL && begin < 0x1fc00000LL)
262 a0a8793e ths
        end = 0x1fc00000LL;
263 a0a8793e ths
264 a0a8793e ths
    *start = begin;
265 a0a8793e ths
    *length = end - begin;
266 a0a8793e ths
}
267 a0a8793e ths
268 a0a8793e ths
static void gt64120_isd_mapping(GT64120State *s)
269 a0a8793e ths
{
270 c227f099 Anthony Liguori
    target_phys_addr_t start = s->regs[GT_ISD] << 21;
271 c227f099 Anthony Liguori
    target_phys_addr_t length = 0x1000;
272 a0a8793e ths
273 a0a8793e ths
    if (s->ISD_length)
274 a0a8793e ths
        cpu_register_physical_memory(s->ISD_start, s->ISD_length,
275 a0a8793e ths
                                     IO_MEM_UNASSIGNED);
276 a0a8793e ths
    check_reserved_space(&start, &length);
277 a0a8793e ths
    length = 0x1000;
278 a0a8793e ths
    /* Map new address */
279 82f24fcc Riccardo Magliocchetti
    DPRINTF("ISD: "TARGET_FMT_plx"@"TARGET_FMT_plx" -> "TARGET_FMT_plx"@"TARGET_FMT_plx", %x\n", s->ISD_length, s->ISD_start,
280 a0a8793e ths
            length, start, s->ISD_handle);
281 a0a8793e ths
    s->ISD_start = start;
282 a0a8793e ths
    s->ISD_length = length;
283 a0a8793e ths
    cpu_register_physical_memory(s->ISD_start, s->ISD_length, s->ISD_handle);
284 a0a8793e ths
}
285 a0a8793e ths
286 9414cc6f ths
static void gt64120_pci_mapping(GT64120State *s)
287 2a1086d9 ths
{
288 9414cc6f ths
    /* Update IO mapping */
289 9414cc6f ths
    if ((s->regs[GT_PCI0IOLD] & 0x7f) <= s->regs[GT_PCI0IOHD])
290 9414cc6f ths
    {
291 3b46e624 ths
      /* Unmap old IO address */
292 9414cc6f ths
      if (s->PCI0IO_length)
293 9414cc6f ths
      {
294 3b46e624 ths
        cpu_register_physical_memory(s->PCI0IO_start, s->PCI0IO_length, IO_MEM_UNASSIGNED);
295 9414cc6f ths
      }
296 9414cc6f ths
      /* Map new IO address */
297 9414cc6f ths
      s->PCI0IO_start = s->regs[GT_PCI0IOLD] << 21;
298 9414cc6f ths
      s->PCI0IO_length = ((s->regs[GT_PCI0IOHD] + 1) - (s->regs[GT_PCI0IOLD] & 0x7f)) << 21;
299 9414cc6f ths
      isa_mem_base = s->PCI0IO_start;
300 84108e12 Blue Swirl
#ifdef TARGET_WORDS_BIGENDIAN
301 84108e12 Blue Swirl
      isa_mmio_init(s->PCI0IO_start, s->PCI0IO_length, 1);
302 84108e12 Blue Swirl
#else
303 84108e12 Blue Swirl
      isa_mmio_init(s->PCI0IO_start, s->PCI0IO_length, 0);
304 84108e12 Blue Swirl
#endif
305 9414cc6f ths
    }
306 2a1086d9 ths
}
307 2a1086d9 ths
308 c227f099 Anthony Liguori
static void gt64120_writel (void *opaque, target_phys_addr_t addr,
309 fde7d5bd ths
                            uint32_t val)
310 fde7d5bd ths
{
311 fde7d5bd ths
    GT64120State *s = opaque;
312 fde7d5bd ths
    uint32_t saddr;
313 fde7d5bd ths
314 c6c99c3f aurel32
    if (!(s->regs[GT_CPU] & 0x00001000))
315 1931e260 ths
        val = bswap32(val);
316 0da75eb1 ths
317 fde7d5bd ths
    saddr = (addr & 0xfff) >> 2;
318 fde7d5bd ths
    switch (saddr) {
319 0da75eb1 ths
320 0da75eb1 ths
    /* CPU Configuration */
321 fde7d5bd ths
    case GT_CPU:
322 fde7d5bd ths
        s->regs[GT_CPU] = val;
323 fde7d5bd ths
        break;
324 fde7d5bd ths
    case GT_MULTI:
325 0da75eb1 ths
        /* Read-only register as only one GT64xxx is present on the CPU bus */
326 fde7d5bd ths
        break;
327 fde7d5bd ths
328 fde7d5bd ths
    /* CPU Address Decode */
329 fde7d5bd ths
    case GT_PCI0IOLD:
330 fde7d5bd ths
        s->regs[GT_PCI0IOLD]    = val & 0x00007fff;
331 fde7d5bd ths
        s->regs[GT_PCI0IOREMAP] = val & 0x000007ff;
332 9414cc6f ths
        gt64120_pci_mapping(s);
333 fde7d5bd ths
        break;
334 fde7d5bd ths
    case GT_PCI0M0LD:
335 fde7d5bd ths
        s->regs[GT_PCI0M0LD]    = val & 0x00007fff;
336 fde7d5bd ths
        s->regs[GT_PCI0M0REMAP] = val & 0x000007ff;
337 fde7d5bd ths
        break;
338 fde7d5bd ths
    case GT_PCI0M1LD:
339 fde7d5bd ths
        s->regs[GT_PCI0M1LD]    = val & 0x00007fff;
340 fde7d5bd ths
        s->regs[GT_PCI0M1REMAP] = val & 0x000007ff;
341 fde7d5bd ths
        break;
342 fde7d5bd ths
    case GT_PCI1IOLD:
343 fde7d5bd ths
        s->regs[GT_PCI1IOLD]    = val & 0x00007fff;
344 fde7d5bd ths
        s->regs[GT_PCI1IOREMAP] = val & 0x000007ff;
345 fde7d5bd ths
        break;
346 fde7d5bd ths
    case GT_PCI1M0LD:
347 fde7d5bd ths
        s->regs[GT_PCI1M0LD]    = val & 0x00007fff;
348 fde7d5bd ths
        s->regs[GT_PCI1M0REMAP] = val & 0x000007ff;
349 fde7d5bd ths
        break;
350 fde7d5bd ths
    case GT_PCI1M1LD:
351 fde7d5bd ths
        s->regs[GT_PCI1M1LD]    = val & 0x00007fff;
352 fde7d5bd ths
        s->regs[GT_PCI1M1REMAP] = val & 0x000007ff;
353 fde7d5bd ths
        break;
354 fde7d5bd ths
    case GT_PCI0IOHD:
355 bb433bef ths
        s->regs[saddr] = val & 0x0000007f;
356 bb433bef ths
        gt64120_pci_mapping(s);
357 bb433bef ths
        break;
358 fde7d5bd ths
    case GT_PCI0M0HD:
359 fde7d5bd ths
    case GT_PCI0M1HD:
360 fde7d5bd ths
    case GT_PCI1IOHD:
361 fde7d5bd ths
    case GT_PCI1M0HD:
362 fde7d5bd ths
    case GT_PCI1M1HD:
363 fde7d5bd ths
        s->regs[saddr] = val & 0x0000007f;
364 fde7d5bd ths
        break;
365 a0a8793e ths
    case GT_ISD:
366 a0a8793e ths
        s->regs[saddr] = val & 0x00007fff;
367 a0a8793e ths
        gt64120_isd_mapping(s);
368 a0a8793e ths
        break;
369 a0a8793e ths
370 fde7d5bd ths
    case GT_PCI0IOREMAP:
371 fde7d5bd ths
    case GT_PCI0M0REMAP:
372 fde7d5bd ths
    case GT_PCI0M1REMAP:
373 fde7d5bd ths
    case GT_PCI1IOREMAP:
374 fde7d5bd ths
    case GT_PCI1M0REMAP:
375 fde7d5bd ths
    case GT_PCI1M1REMAP:
376 fde7d5bd ths
        s->regs[saddr] = val & 0x000007ff;
377 fde7d5bd ths
        break;
378 fde7d5bd ths
379 fde7d5bd ths
    /* CPU Error Report */
380 fde7d5bd ths
    case GT_CPUERR_ADDRLO:
381 fde7d5bd ths
    case GT_CPUERR_ADDRHI:
382 fde7d5bd ths
    case GT_CPUERR_DATALO:
383 fde7d5bd ths
    case GT_CPUERR_DATAHI:
384 fde7d5bd ths
    case GT_CPUERR_PARITY:
385 0da75eb1 ths
        /* Read-only registers, do nothing */
386 0da75eb1 ths
        break;
387 0da75eb1 ths
388 0da75eb1 ths
    /* CPU Sync Barrier */
389 0da75eb1 ths
    case GT_PCI0SYNC:
390 0da75eb1 ths
    case GT_PCI1SYNC:
391 0da75eb1 ths
        /* Read-only registers, do nothing */
392 fde7d5bd ths
        break;
393 fde7d5bd ths
394 05b4ff43 ths
    /* SDRAM and Device Address Decode */
395 05b4ff43 ths
    case GT_SCS0LD:
396 05b4ff43 ths
    case GT_SCS0HD:
397 05b4ff43 ths
    case GT_SCS1LD:
398 05b4ff43 ths
    case GT_SCS1HD:
399 05b4ff43 ths
    case GT_SCS2LD:
400 05b4ff43 ths
    case GT_SCS2HD:
401 05b4ff43 ths
    case GT_SCS3LD:
402 05b4ff43 ths
    case GT_SCS3HD:
403 05b4ff43 ths
    case GT_CS0LD:
404 05b4ff43 ths
    case GT_CS0HD:
405 05b4ff43 ths
    case GT_CS1LD:
406 05b4ff43 ths
    case GT_CS1HD:
407 05b4ff43 ths
    case GT_CS2LD:
408 05b4ff43 ths
    case GT_CS2HD:
409 05b4ff43 ths
    case GT_CS3LD:
410 05b4ff43 ths
    case GT_CS3HD:
411 05b4ff43 ths
    case GT_BOOTLD:
412 05b4ff43 ths
    case GT_BOOTHD:
413 05b4ff43 ths
    case GT_ADERR:
414 05b4ff43 ths
    /* SDRAM Configuration */
415 05b4ff43 ths
    case GT_SDRAM_CFG:
416 05b4ff43 ths
    case GT_SDRAM_OPMODE:
417 05b4ff43 ths
    case GT_SDRAM_BM:
418 05b4ff43 ths
    case GT_SDRAM_ADDRDECODE:
419 05b4ff43 ths
        /* Accept and ignore SDRAM interleave configuration */
420 05b4ff43 ths
        s->regs[saddr] = val;
421 05b4ff43 ths
        break;
422 05b4ff43 ths
423 05b4ff43 ths
    /* Device Parameters */
424 05b4ff43 ths
    case GT_DEV_B0:
425 05b4ff43 ths
    case GT_DEV_B1:
426 05b4ff43 ths
    case GT_DEV_B2:
427 05b4ff43 ths
    case GT_DEV_B3:
428 05b4ff43 ths
    case GT_DEV_BOOT:
429 05b4ff43 ths
        /* Not implemented */
430 d0f2c4c6 malc
        DPRINTF ("Unimplemented device register offset 0x%x\n", saddr << 2);
431 05b4ff43 ths
        break;
432 05b4ff43 ths
433 fde7d5bd ths
    /* ECC */
434 fde7d5bd ths
    case GT_ECC_ERRDATALO:
435 fde7d5bd ths
    case GT_ECC_ERRDATAHI:
436 fde7d5bd ths
    case GT_ECC_MEM:
437 fde7d5bd ths
    case GT_ECC_CALC:
438 fde7d5bd ths
    case GT_ECC_ERRADDR:
439 0da75eb1 ths
        /* Read-only registers, do nothing */
440 fde7d5bd ths
        break;
441 fde7d5bd ths
442 05b4ff43 ths
    /* DMA Record */
443 05b4ff43 ths
    case GT_DMA0_CNT:
444 05b4ff43 ths
    case GT_DMA1_CNT:
445 05b4ff43 ths
    case GT_DMA2_CNT:
446 05b4ff43 ths
    case GT_DMA3_CNT:
447 05b4ff43 ths
    case GT_DMA0_SA:
448 05b4ff43 ths
    case GT_DMA1_SA:
449 05b4ff43 ths
    case GT_DMA2_SA:
450 05b4ff43 ths
    case GT_DMA3_SA:
451 05b4ff43 ths
    case GT_DMA0_DA:
452 05b4ff43 ths
    case GT_DMA1_DA:
453 05b4ff43 ths
    case GT_DMA2_DA:
454 05b4ff43 ths
    case GT_DMA3_DA:
455 05b4ff43 ths
    case GT_DMA0_NEXT:
456 05b4ff43 ths
    case GT_DMA1_NEXT:
457 05b4ff43 ths
    case GT_DMA2_NEXT:
458 05b4ff43 ths
    case GT_DMA3_NEXT:
459 05b4ff43 ths
    case GT_DMA0_CUR:
460 05b4ff43 ths
    case GT_DMA1_CUR:
461 05b4ff43 ths
    case GT_DMA2_CUR:
462 05b4ff43 ths
    case GT_DMA3_CUR:
463 05b4ff43 ths
        /* Not implemented */
464 d0f2c4c6 malc
        DPRINTF ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
465 05b4ff43 ths
        break;
466 05b4ff43 ths
467 05b4ff43 ths
    /* DMA Channel Control */
468 05b4ff43 ths
    case GT_DMA0_CTRL:
469 05b4ff43 ths
    case GT_DMA1_CTRL:
470 05b4ff43 ths
    case GT_DMA2_CTRL:
471 05b4ff43 ths
    case GT_DMA3_CTRL:
472 05b4ff43 ths
        /* Not implemented */
473 d0f2c4c6 malc
        DPRINTF ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
474 05b4ff43 ths
        break;
475 05b4ff43 ths
476 05b4ff43 ths
    /* DMA Arbiter */
477 05b4ff43 ths
    case GT_DMA_ARB:
478 05b4ff43 ths
        /* Not implemented */
479 d0f2c4c6 malc
        DPRINTF ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
480 05b4ff43 ths
        break;
481 05b4ff43 ths
482 05b4ff43 ths
    /* Timer/Counter */
483 05b4ff43 ths
    case GT_TC0:
484 05b4ff43 ths
    case GT_TC1:
485 05b4ff43 ths
    case GT_TC2:
486 05b4ff43 ths
    case GT_TC3:
487 05b4ff43 ths
    case GT_TC_CONTROL:
488 05b4ff43 ths
        /* Not implemented */
489 d0f2c4c6 malc
        DPRINTF ("Unimplemented timer register offset 0x%x\n", saddr << 2);
490 05b4ff43 ths
        break;
491 05b4ff43 ths
492 fde7d5bd ths
    /* PCI Internal */
493 fde7d5bd ths
    case GT_PCI0_CMD:
494 fde7d5bd ths
    case GT_PCI1_CMD:
495 fde7d5bd ths
        s->regs[saddr] = val & 0x0401fc0f;
496 fde7d5bd ths
        break;
497 05b4ff43 ths
    case GT_PCI0_TOR:
498 05b4ff43 ths
    case GT_PCI0_BS_SCS10:
499 05b4ff43 ths
    case GT_PCI0_BS_SCS32:
500 05b4ff43 ths
    case GT_PCI0_BS_CS20:
501 05b4ff43 ths
    case GT_PCI0_BS_CS3BT:
502 05b4ff43 ths
    case GT_PCI1_IACK:
503 05b4ff43 ths
    case GT_PCI0_IACK:
504 05b4ff43 ths
    case GT_PCI0_BARE:
505 05b4ff43 ths
    case GT_PCI0_PREFMBR:
506 05b4ff43 ths
    case GT_PCI0_SCS10_BAR:
507 05b4ff43 ths
    case GT_PCI0_SCS32_BAR:
508 05b4ff43 ths
    case GT_PCI0_CS20_BAR:
509 05b4ff43 ths
    case GT_PCI0_CS3BT_BAR:
510 05b4ff43 ths
    case GT_PCI0_SSCS10_BAR:
511 05b4ff43 ths
    case GT_PCI0_SSCS32_BAR:
512 05b4ff43 ths
    case GT_PCI0_SCS3BT_BAR:
513 05b4ff43 ths
    case GT_PCI1_TOR:
514 05b4ff43 ths
    case GT_PCI1_BS_SCS10:
515 05b4ff43 ths
    case GT_PCI1_BS_SCS32:
516 05b4ff43 ths
    case GT_PCI1_BS_CS20:
517 05b4ff43 ths
    case GT_PCI1_BS_CS3BT:
518 05b4ff43 ths
    case GT_PCI1_BARE:
519 05b4ff43 ths
    case GT_PCI1_PREFMBR:
520 05b4ff43 ths
    case GT_PCI1_SCS10_BAR:
521 05b4ff43 ths
    case GT_PCI1_SCS32_BAR:
522 05b4ff43 ths
    case GT_PCI1_CS20_BAR:
523 05b4ff43 ths
    case GT_PCI1_CS3BT_BAR:
524 05b4ff43 ths
    case GT_PCI1_SSCS10_BAR:
525 05b4ff43 ths
    case GT_PCI1_SSCS32_BAR:
526 05b4ff43 ths
    case GT_PCI1_SCS3BT_BAR:
527 05b4ff43 ths
    case GT_PCI1_CFGADDR:
528 05b4ff43 ths
    case GT_PCI1_CFGDATA:
529 05b4ff43 ths
        /* not implemented */
530 05b4ff43 ths
        break;
531 fde7d5bd ths
    case GT_PCI0_CFGADDR:
532 fde7d5bd ths
        s->pci->config_reg = val & 0x80fffffc;
533 fde7d5bd ths
        break;
534 fde7d5bd ths
    case GT_PCI0_CFGDATA:
535 c6c99c3f aurel32
        if (!(s->regs[GT_PCI0_CMD] & 1) && (s->pci->config_reg & 0x00fff800))
536 c6c99c3f aurel32
            val = bswap32(val);
537 c6c99c3f aurel32
        if (s->pci->config_reg & (1u << 31))
538 c6c99c3f aurel32
            pci_data_write(s->pci->bus, s->pci->config_reg, val, 4);
539 05b4ff43 ths
        break;
540 05b4ff43 ths
541 05b4ff43 ths
    /* Interrupts */
542 05b4ff43 ths
    case GT_INTRCAUSE:
543 05b4ff43 ths
        /* not really implemented */
544 05b4ff43 ths
        s->regs[saddr] = ~(~(s->regs[saddr]) | ~(val & 0xfffffffe));
545 05b4ff43 ths
        s->regs[saddr] |= !!(s->regs[saddr] & 0xfffffffe);
546 d0f2c4c6 malc
        DPRINTF("INTRCAUSE %x\n", val);
547 05b4ff43 ths
        break;
548 05b4ff43 ths
    case GT_INTRMASK:
549 05b4ff43 ths
        s->regs[saddr] = val & 0x3c3ffffe;
550 d0f2c4c6 malc
        DPRINTF("INTRMASK %x\n", val);
551 05b4ff43 ths
        break;
552 05b4ff43 ths
    case GT_PCI0_ICMASK:
553 05b4ff43 ths
        s->regs[saddr] = val & 0x03fffffe;
554 d0f2c4c6 malc
        DPRINTF("ICMASK %x\n", val);
555 05b4ff43 ths
        break;
556 05b4ff43 ths
    case GT_PCI0_SERR0MASK:
557 05b4ff43 ths
        s->regs[saddr] = val & 0x0000003f;
558 d0f2c4c6 malc
        DPRINTF("SERR0MASK %x\n", val);
559 05b4ff43 ths
        break;
560 05b4ff43 ths
561 05b4ff43 ths
    /* Reserved when only PCI_0 is configured. */
562 05b4ff43 ths
    case GT_HINTRCAUSE:
563 05b4ff43 ths
    case GT_CPU_INTSEL:
564 05b4ff43 ths
    case GT_PCI0_INTSEL:
565 05b4ff43 ths
    case GT_HINTRMASK:
566 05b4ff43 ths
    case GT_PCI0_HICMASK:
567 05b4ff43 ths
    case GT_PCI1_SERR1MASK:
568 05b4ff43 ths
        /* not implemented */
569 fde7d5bd ths
        break;
570 fde7d5bd ths
571 0da75eb1 ths
    /* SDRAM Parameters */
572 0da75eb1 ths
    case GT_SDRAM_B0:
573 0da75eb1 ths
    case GT_SDRAM_B1:
574 0da75eb1 ths
    case GT_SDRAM_B2:
575 0da75eb1 ths
    case GT_SDRAM_B3:
576 0da75eb1 ths
        /* We don't simulate electrical parameters of the SDRAM.
577 0da75eb1 ths
           Accept, but ignore the values. */
578 0da75eb1 ths
        s->regs[saddr] = val;
579 0da75eb1 ths
        break;
580 0da75eb1 ths
581 fde7d5bd ths
    default:
582 d0f2c4c6 malc
        DPRINTF ("Bad register offset 0x%x\n", (int)addr);
583 fde7d5bd ths
        break;
584 fde7d5bd ths
    }
585 fde7d5bd ths
}
586 fde7d5bd ths
587 fde7d5bd ths
static uint32_t gt64120_readl (void *opaque,
588 c227f099 Anthony Liguori
                               target_phys_addr_t addr)
589 fde7d5bd ths
{
590 fde7d5bd ths
    GT64120State *s = opaque;
591 fde7d5bd ths
    uint32_t val;
592 fde7d5bd ths
    uint32_t saddr;
593 fde7d5bd ths
594 fde7d5bd ths
    saddr = (addr & 0xfff) >> 2;
595 fde7d5bd ths
    switch (saddr) {
596 fde7d5bd ths
597 0da75eb1 ths
    /* CPU Configuration */
598 0da75eb1 ths
    case GT_MULTI:
599 0da75eb1 ths
        /* Only one GT64xxx is present on the CPU bus, return
600 0da75eb1 ths
           the initial value */
601 0da75eb1 ths
        val = s->regs[saddr];
602 0da75eb1 ths
        break;
603 0da75eb1 ths
604 fde7d5bd ths
    /* CPU Error Report */
605 fde7d5bd ths
    case GT_CPUERR_ADDRLO:
606 fde7d5bd ths
    case GT_CPUERR_ADDRHI:
607 fde7d5bd ths
    case GT_CPUERR_DATALO:
608 fde7d5bd ths
    case GT_CPUERR_DATAHI:
609 fde7d5bd ths
    case GT_CPUERR_PARITY:
610 0da75eb1 ths
        /* Emulated memory has no error, always return the initial
611 5fafdf24 ths
           values */
612 0da75eb1 ths
        val = s->regs[saddr];
613 0da75eb1 ths
        break;
614 0da75eb1 ths
615 0da75eb1 ths
    /* CPU Sync Barrier */
616 0da75eb1 ths
    case GT_PCI0SYNC:
617 0da75eb1 ths
    case GT_PCI1SYNC:
618 0da75eb1 ths
        /* Reading those register should empty all FIFO on the PCI
619 0da75eb1 ths
           bus, which are not emulated. The return value should be
620 0da75eb1 ths
           a random value that should be ignored. */
621 5fafdf24 ths
        val = 0xc000ffee;
622 fde7d5bd ths
        break;
623 fde7d5bd ths
624 fde7d5bd ths
    /* ECC */
625 fde7d5bd ths
    case GT_ECC_ERRDATALO:
626 fde7d5bd ths
    case GT_ECC_ERRDATAHI:
627 fde7d5bd ths
    case GT_ECC_MEM:
628 fde7d5bd ths
    case GT_ECC_CALC:
629 fde7d5bd ths
    case GT_ECC_ERRADDR:
630 0da75eb1 ths
        /* Emulated memory has no error, always return the initial
631 5fafdf24 ths
           values */
632 0da75eb1 ths
        val = s->regs[saddr];
633 fde7d5bd ths
        break;
634 fde7d5bd ths
635 fde7d5bd ths
    case GT_CPU:
636 05b4ff43 ths
    case GT_SCS10LD:
637 05b4ff43 ths
    case GT_SCS10HD:
638 05b4ff43 ths
    case GT_SCS32LD:
639 05b4ff43 ths
    case GT_SCS32HD:
640 05b4ff43 ths
    case GT_CS20LD:
641 05b4ff43 ths
    case GT_CS20HD:
642 05b4ff43 ths
    case GT_CS3BOOTLD:
643 05b4ff43 ths
    case GT_CS3BOOTHD:
644 05b4ff43 ths
    case GT_SCS10AR:
645 05b4ff43 ths
    case GT_SCS32AR:
646 05b4ff43 ths
    case GT_CS20R:
647 05b4ff43 ths
    case GT_CS3BOOTR:
648 fde7d5bd ths
    case GT_PCI0IOLD:
649 fde7d5bd ths
    case GT_PCI0M0LD:
650 fde7d5bd ths
    case GT_PCI0M1LD:
651 fde7d5bd ths
    case GT_PCI1IOLD:
652 fde7d5bd ths
    case GT_PCI1M0LD:
653 fde7d5bd ths
    case GT_PCI1M1LD:
654 fde7d5bd ths
    case GT_PCI0IOHD:
655 fde7d5bd ths
    case GT_PCI0M0HD:
656 fde7d5bd ths
    case GT_PCI0M1HD:
657 fde7d5bd ths
    case GT_PCI1IOHD:
658 fde7d5bd ths
    case GT_PCI1M0HD:
659 fde7d5bd ths
    case GT_PCI1M1HD:
660 fde7d5bd ths
    case GT_PCI0IOREMAP:
661 fde7d5bd ths
    case GT_PCI0M0REMAP:
662 fde7d5bd ths
    case GT_PCI0M1REMAP:
663 fde7d5bd ths
    case GT_PCI1IOREMAP:
664 fde7d5bd ths
    case GT_PCI1M0REMAP:
665 fde7d5bd ths
    case GT_PCI1M1REMAP:
666 05b4ff43 ths
    case GT_ISD:
667 fde7d5bd ths
        val = s->regs[saddr];
668 fde7d5bd ths
        break;
669 fde7d5bd ths
    case GT_PCI0_IACK:
670 5fafdf24 ths
        /* Read the IRQ number */
671 4de9b249 ths
        val = pic_read_irq(isa_pic);
672 fde7d5bd ths
        break;
673 fde7d5bd ths
674 05b4ff43 ths
    /* SDRAM and Device Address Decode */
675 05b4ff43 ths
    case GT_SCS0LD:
676 05b4ff43 ths
    case GT_SCS0HD:
677 05b4ff43 ths
    case GT_SCS1LD:
678 05b4ff43 ths
    case GT_SCS1HD:
679 05b4ff43 ths
    case GT_SCS2LD:
680 05b4ff43 ths
    case GT_SCS2HD:
681 05b4ff43 ths
    case GT_SCS3LD:
682 05b4ff43 ths
    case GT_SCS3HD:
683 05b4ff43 ths
    case GT_CS0LD:
684 05b4ff43 ths
    case GT_CS0HD:
685 05b4ff43 ths
    case GT_CS1LD:
686 05b4ff43 ths
    case GT_CS1HD:
687 05b4ff43 ths
    case GT_CS2LD:
688 05b4ff43 ths
    case GT_CS2HD:
689 05b4ff43 ths
    case GT_CS3LD:
690 05b4ff43 ths
    case GT_CS3HD:
691 05b4ff43 ths
    case GT_BOOTLD:
692 05b4ff43 ths
    case GT_BOOTHD:
693 05b4ff43 ths
    case GT_ADERR:
694 05b4ff43 ths
        val = s->regs[saddr];
695 05b4ff43 ths
        break;
696 05b4ff43 ths
697 05b4ff43 ths
    /* SDRAM Configuration */
698 05b4ff43 ths
    case GT_SDRAM_CFG:
699 05b4ff43 ths
    case GT_SDRAM_OPMODE:
700 05b4ff43 ths
    case GT_SDRAM_BM:
701 05b4ff43 ths
    case GT_SDRAM_ADDRDECODE:
702 05b4ff43 ths
        val = s->regs[saddr];
703 05b4ff43 ths
        break;
704 05b4ff43 ths
705 0da75eb1 ths
    /* SDRAM Parameters */
706 0da75eb1 ths
    case GT_SDRAM_B0:
707 0da75eb1 ths
    case GT_SDRAM_B1:
708 0da75eb1 ths
    case GT_SDRAM_B2:
709 0da75eb1 ths
    case GT_SDRAM_B3:
710 0da75eb1 ths
        /* We don't simulate electrical parameters of the SDRAM.
711 0da75eb1 ths
           Just return the last written value. */
712 0da75eb1 ths
        val = s->regs[saddr];
713 0da75eb1 ths
        break;
714 0da75eb1 ths
715 05b4ff43 ths
    /* Device Parameters */
716 05b4ff43 ths
    case GT_DEV_B0:
717 05b4ff43 ths
    case GT_DEV_B1:
718 05b4ff43 ths
    case GT_DEV_B2:
719 05b4ff43 ths
    case GT_DEV_B3:
720 05b4ff43 ths
    case GT_DEV_BOOT:
721 05b4ff43 ths
        val = s->regs[saddr];
722 05b4ff43 ths
        break;
723 05b4ff43 ths
724 05b4ff43 ths
    /* DMA Record */
725 05b4ff43 ths
    case GT_DMA0_CNT:
726 05b4ff43 ths
    case GT_DMA1_CNT:
727 05b4ff43 ths
    case GT_DMA2_CNT:
728 05b4ff43 ths
    case GT_DMA3_CNT:
729 05b4ff43 ths
    case GT_DMA0_SA:
730 05b4ff43 ths
    case GT_DMA1_SA:
731 05b4ff43 ths
    case GT_DMA2_SA:
732 05b4ff43 ths
    case GT_DMA3_SA:
733 05b4ff43 ths
    case GT_DMA0_DA:
734 05b4ff43 ths
    case GT_DMA1_DA:
735 05b4ff43 ths
    case GT_DMA2_DA:
736 05b4ff43 ths
    case GT_DMA3_DA:
737 05b4ff43 ths
    case GT_DMA0_NEXT:
738 05b4ff43 ths
    case GT_DMA1_NEXT:
739 05b4ff43 ths
    case GT_DMA2_NEXT:
740 05b4ff43 ths
    case GT_DMA3_NEXT:
741 05b4ff43 ths
    case GT_DMA0_CUR:
742 05b4ff43 ths
    case GT_DMA1_CUR:
743 05b4ff43 ths
    case GT_DMA2_CUR:
744 05b4ff43 ths
    case GT_DMA3_CUR:
745 05b4ff43 ths
        val = s->regs[saddr];
746 05b4ff43 ths
        break;
747 05b4ff43 ths
748 05b4ff43 ths
    /* DMA Channel Control */
749 05b4ff43 ths
    case GT_DMA0_CTRL:
750 05b4ff43 ths
    case GT_DMA1_CTRL:
751 05b4ff43 ths
    case GT_DMA2_CTRL:
752 05b4ff43 ths
    case GT_DMA3_CTRL:
753 05b4ff43 ths
        val = s->regs[saddr];
754 05b4ff43 ths
        break;
755 05b4ff43 ths
756 05b4ff43 ths
    /* DMA Arbiter */
757 05b4ff43 ths
    case GT_DMA_ARB:
758 05b4ff43 ths
        val = s->regs[saddr];
759 05b4ff43 ths
        break;
760 05b4ff43 ths
761 05b4ff43 ths
    /* Timer/Counter */
762 05b4ff43 ths
    case GT_TC0:
763 05b4ff43 ths
    case GT_TC1:
764 05b4ff43 ths
    case GT_TC2:
765 05b4ff43 ths
    case GT_TC3:
766 05b4ff43 ths
    case GT_TC_CONTROL:
767 05b4ff43 ths
        val = s->regs[saddr];
768 05b4ff43 ths
        break;
769 05b4ff43 ths
770 fde7d5bd ths
    /* PCI Internal */
771 fde7d5bd ths
    case GT_PCI0_CFGADDR:
772 fde7d5bd ths
        val = s->pci->config_reg;
773 fde7d5bd ths
        break;
774 fde7d5bd ths
    case GT_PCI0_CFGDATA:
775 c6c99c3f aurel32
        if (!(s->pci->config_reg & (1 << 31)))
776 c6c99c3f aurel32
            val = 0xffffffff;
777 c6c99c3f aurel32
        else
778 c6c99c3f aurel32
            val = pci_data_read(s->pci->bus, s->pci->config_reg, 4);
779 c6c99c3f aurel32
        if (!(s->regs[GT_PCI0_CMD] & 1) && (s->pci->config_reg & 0x00fff800))
780 c6c99c3f aurel32
            val = bswap32(val);
781 05b4ff43 ths
        break;
782 05b4ff43 ths
783 05b4ff43 ths
    case GT_PCI0_CMD:
784 05b4ff43 ths
    case GT_PCI0_TOR:
785 05b4ff43 ths
    case GT_PCI0_BS_SCS10:
786 05b4ff43 ths
    case GT_PCI0_BS_SCS32:
787 05b4ff43 ths
    case GT_PCI0_BS_CS20:
788 05b4ff43 ths
    case GT_PCI0_BS_CS3BT:
789 05b4ff43 ths
    case GT_PCI1_IACK:
790 05b4ff43 ths
    case GT_PCI0_BARE:
791 05b4ff43 ths
    case GT_PCI0_PREFMBR:
792 05b4ff43 ths
    case GT_PCI0_SCS10_BAR:
793 05b4ff43 ths
    case GT_PCI0_SCS32_BAR:
794 05b4ff43 ths
    case GT_PCI0_CS20_BAR:
795 05b4ff43 ths
    case GT_PCI0_CS3BT_BAR:
796 05b4ff43 ths
    case GT_PCI0_SSCS10_BAR:
797 05b4ff43 ths
    case GT_PCI0_SSCS32_BAR:
798 05b4ff43 ths
    case GT_PCI0_SCS3BT_BAR:
799 05b4ff43 ths
    case GT_PCI1_CMD:
800 05b4ff43 ths
    case GT_PCI1_TOR:
801 05b4ff43 ths
    case GT_PCI1_BS_SCS10:
802 05b4ff43 ths
    case GT_PCI1_BS_SCS32:
803 05b4ff43 ths
    case GT_PCI1_BS_CS20:
804 05b4ff43 ths
    case GT_PCI1_BS_CS3BT:
805 05b4ff43 ths
    case GT_PCI1_BARE:
806 05b4ff43 ths
    case GT_PCI1_PREFMBR:
807 05b4ff43 ths
    case GT_PCI1_SCS10_BAR:
808 05b4ff43 ths
    case GT_PCI1_SCS32_BAR:
809 05b4ff43 ths
    case GT_PCI1_CS20_BAR:
810 05b4ff43 ths
    case GT_PCI1_CS3BT_BAR:
811 05b4ff43 ths
    case GT_PCI1_SSCS10_BAR:
812 05b4ff43 ths
    case GT_PCI1_SSCS32_BAR:
813 05b4ff43 ths
    case GT_PCI1_SCS3BT_BAR:
814 05b4ff43 ths
    case GT_PCI1_CFGADDR:
815 05b4ff43 ths
    case GT_PCI1_CFGDATA:
816 05b4ff43 ths
        val = s->regs[saddr];
817 05b4ff43 ths
        break;
818 05b4ff43 ths
819 05b4ff43 ths
    /* Interrupts */
820 05b4ff43 ths
    case GT_INTRCAUSE:
821 05b4ff43 ths
        val = s->regs[saddr];
822 d0f2c4c6 malc
        DPRINTF("INTRCAUSE %x\n", val);
823 05b4ff43 ths
        break;
824 05b4ff43 ths
    case GT_INTRMASK:
825 05b4ff43 ths
        val = s->regs[saddr];
826 d0f2c4c6 malc
        DPRINTF("INTRMASK %x\n", val);
827 05b4ff43 ths
        break;
828 05b4ff43 ths
    case GT_PCI0_ICMASK:
829 05b4ff43 ths
        val = s->regs[saddr];
830 d0f2c4c6 malc
        DPRINTF("ICMASK %x\n", val);
831 05b4ff43 ths
        break;
832 05b4ff43 ths
    case GT_PCI0_SERR0MASK:
833 05b4ff43 ths
        val = s->regs[saddr];
834 d0f2c4c6 malc
        DPRINTF("SERR0MASK %x\n", val);
835 05b4ff43 ths
        break;
836 05b4ff43 ths
837 05b4ff43 ths
    /* Reserved when only PCI_0 is configured. */
838 05b4ff43 ths
    case GT_HINTRCAUSE:
839 05b4ff43 ths
    case GT_CPU_INTSEL:
840 05b4ff43 ths
    case GT_PCI0_INTSEL:
841 05b4ff43 ths
    case GT_HINTRMASK:
842 05b4ff43 ths
    case GT_PCI0_HICMASK:
843 05b4ff43 ths
    case GT_PCI1_SERR1MASK:
844 05b4ff43 ths
        val = s->regs[saddr];
845 fde7d5bd ths
        break;
846 fde7d5bd ths
847 fde7d5bd ths
    default:
848 fde7d5bd ths
        val = s->regs[saddr];
849 d0f2c4c6 malc
        DPRINTF ("Bad register offset 0x%x\n", (int)addr);
850 fde7d5bd ths
        break;
851 fde7d5bd ths
    }
852 fde7d5bd ths
853 c6c99c3f aurel32
    if (!(s->regs[GT_CPU] & 0x00001000))
854 1931e260 ths
        val = bswap32(val);
855 1931e260 ths
856 05b4ff43 ths
    return val;
857 fde7d5bd ths
}
858 fde7d5bd ths
859 d60efc6b Blue Swirl
static CPUWriteMemoryFunc * const gt64120_write[] = {
860 fde7d5bd ths
    &gt64120_writel,
861 fde7d5bd ths
    &gt64120_writel,
862 fde7d5bd ths
    &gt64120_writel,
863 fde7d5bd ths
};
864 fde7d5bd ths
865 d60efc6b Blue Swirl
static CPUReadMemoryFunc * const gt64120_read[] = {
866 fde7d5bd ths
    &gt64120_readl,
867 fde7d5bd ths
    &gt64120_readl,
868 fde7d5bd ths
    &gt64120_readl,
869 fde7d5bd ths
};
870 fde7d5bd ths
871 fde7d5bd ths
static int pci_gt64120_map_irq(PCIDevice *pci_dev, int irq_num)
872 fde7d5bd ths
{
873 fde7d5bd ths
    int slot;
874 fde7d5bd ths
875 fde7d5bd ths
    slot = (pci_dev->devfn >> 3);
876 fde7d5bd ths
877 fde7d5bd ths
    switch (slot) {
878 fde7d5bd ths
      /* PIIX4 USB */
879 fde7d5bd ths
      case 10:
880 fde7d5bd ths
        return 3;
881 fde7d5bd ths
      /* AMD 79C973 Ethernet */
882 fde7d5bd ths
      case 11:
883 d4a4d056 ths
        return 1;
884 fde7d5bd ths
      /* Crystal 4281 Sound */
885 fde7d5bd ths
      case 12:
886 d4a4d056 ths
        return 2;
887 fde7d5bd ths
      /* PCI slot 1 to 4 */
888 fde7d5bd ths
      case 18 ... 21:
889 fde7d5bd ths
        return ((slot - 18) + irq_num) & 0x03;
890 fde7d5bd ths
      /* Unknown device, don't do any translation */
891 fde7d5bd ths
      default:
892 fde7d5bd ths
        return irq_num;
893 fde7d5bd ths
    }
894 fde7d5bd ths
}
895 fde7d5bd ths
896 fde7d5bd ths
static int pci_irq_levels[4];
897 fde7d5bd ths
898 5d4e84c8 Juan Quintela
static void pci_gt64120_set_irq(void *opaque, int irq_num, int level)
899 fde7d5bd ths
{
900 fde7d5bd ths
    int i, pic_irq, pic_level;
901 5d4e84c8 Juan Quintela
    qemu_irq *pic = opaque;
902 fde7d5bd ths
903 fde7d5bd ths
    pci_irq_levels[irq_num] = level;
904 fde7d5bd ths
905 fde7d5bd ths
    /* now we change the pic irq level according to the piix irq mappings */
906 fde7d5bd ths
    /* XXX: optimize */
907 fde7d5bd ths
    pic_irq = piix4_dev->config[0x60 + irq_num];
908 fde7d5bd ths
    if (pic_irq < 16) {
909 fde7d5bd ths
        /* The pic level is the logical OR of all the PCI irqs mapped
910 fde7d5bd ths
           to it */
911 fde7d5bd ths
        pic_level = 0;
912 fde7d5bd ths
        for (i = 0; i < 4; i++) {
913 fde7d5bd ths
            if (pic_irq == piix4_dev->config[0x60 + i])
914 fde7d5bd ths
                pic_level |= pci_irq_levels[i];
915 fde7d5bd ths
        }
916 d537cf6c pbrook
        qemu_set_irq(pic[pic_irq], pic_level);
917 fde7d5bd ths
    }
918 fde7d5bd ths
}
919 fde7d5bd ths
920 fde7d5bd ths
921 9596ebb7 pbrook
static void gt64120_reset(void *opaque)
922 fde7d5bd ths
{
923 fde7d5bd ths
    GT64120State *s = opaque;
924 fde7d5bd ths
925 30b6f3a8 ths
    /* FIXME: Malta specific hw assumptions ahead */
926 30b6f3a8 ths
927 fde7d5bd ths
    /* CPU Configuration */
928 fde7d5bd ths
#ifdef TARGET_WORDS_BIGENDIAN
929 fde7d5bd ths
    s->regs[GT_CPU]           = 0x00000000;
930 fde7d5bd ths
#else
931 bc687ec9 ths
    s->regs[GT_CPU]           = 0x00001000;
932 fde7d5bd ths
#endif
933 30b6f3a8 ths
    s->regs[GT_MULTI]         = 0x00000003;
934 30b6f3a8 ths
935 30b6f3a8 ths
    /* CPU Address decode */
936 30b6f3a8 ths
    s->regs[GT_SCS10LD]       = 0x00000000;
937 30b6f3a8 ths
    s->regs[GT_SCS10HD]       = 0x00000007;
938 30b6f3a8 ths
    s->regs[GT_SCS32LD]       = 0x00000008;
939 30b6f3a8 ths
    s->regs[GT_SCS32HD]       = 0x0000000f;
940 30b6f3a8 ths
    s->regs[GT_CS20LD]        = 0x000000e0;
941 30b6f3a8 ths
    s->regs[GT_CS20HD]        = 0x00000070;
942 30b6f3a8 ths
    s->regs[GT_CS3BOOTLD]     = 0x000000f8;
943 30b6f3a8 ths
    s->regs[GT_CS3BOOTHD]     = 0x0000007f;
944 fde7d5bd ths
945 fde7d5bd ths
    s->regs[GT_PCI0IOLD]      = 0x00000080;
946 fde7d5bd ths
    s->regs[GT_PCI0IOHD]      = 0x0000000f;
947 fde7d5bd ths
    s->regs[GT_PCI0M0LD]      = 0x00000090;
948 fde7d5bd ths
    s->regs[GT_PCI0M0HD]      = 0x0000001f;
949 30b6f3a8 ths
    s->regs[GT_ISD]           = 0x000000a0;
950 fde7d5bd ths
    s->regs[GT_PCI0M1LD]      = 0x00000790;
951 fde7d5bd ths
    s->regs[GT_PCI0M1HD]      = 0x0000001f;
952 fde7d5bd ths
    s->regs[GT_PCI1IOLD]      = 0x00000100;
953 fde7d5bd ths
    s->regs[GT_PCI1IOHD]      = 0x0000000f;
954 fde7d5bd ths
    s->regs[GT_PCI1M0LD]      = 0x00000110;
955 fde7d5bd ths
    s->regs[GT_PCI1M0HD]      = 0x0000001f;
956 fde7d5bd ths
    s->regs[GT_PCI1M1LD]      = 0x00000120;
957 fde7d5bd ths
    s->regs[GT_PCI1M1HD]      = 0x0000002f;
958 30b6f3a8 ths
959 30b6f3a8 ths
    s->regs[GT_SCS10AR]       = 0x00000000;
960 30b6f3a8 ths
    s->regs[GT_SCS32AR]       = 0x00000008;
961 30b6f3a8 ths
    s->regs[GT_CS20R]         = 0x000000e0;
962 30b6f3a8 ths
    s->regs[GT_CS3BOOTR]      = 0x000000f8;
963 30b6f3a8 ths
964 fde7d5bd ths
    s->regs[GT_PCI0IOREMAP]   = 0x00000080;
965 fde7d5bd ths
    s->regs[GT_PCI0M0REMAP]   = 0x00000090;
966 fde7d5bd ths
    s->regs[GT_PCI0M1REMAP]   = 0x00000790;
967 fde7d5bd ths
    s->regs[GT_PCI1IOREMAP]   = 0x00000100;
968 fde7d5bd ths
    s->regs[GT_PCI1M0REMAP]   = 0x00000110;
969 fde7d5bd ths
    s->regs[GT_PCI1M1REMAP]   = 0x00000120;
970 fde7d5bd ths
971 fde7d5bd ths
    /* CPU Error Report */
972 fde7d5bd ths
    s->regs[GT_CPUERR_ADDRLO] = 0x00000000;
973 fde7d5bd ths
    s->regs[GT_CPUERR_ADDRHI] = 0x00000000;
974 fde7d5bd ths
    s->regs[GT_CPUERR_DATALO] = 0xffffffff;
975 fde7d5bd ths
    s->regs[GT_CPUERR_DATAHI] = 0xffffffff;
976 fde7d5bd ths
    s->regs[GT_CPUERR_PARITY] = 0x000000ff;
977 fde7d5bd ths
978 30b6f3a8 ths
    /* CPU Sync Barrier */
979 30b6f3a8 ths
    s->regs[GT_PCI0SYNC]      = 0x00000000;
980 30b6f3a8 ths
    s->regs[GT_PCI1SYNC]      = 0x00000000;
981 30b6f3a8 ths
982 30b6f3a8 ths
    /* SDRAM and Device Address Decode */
983 30b6f3a8 ths
    s->regs[GT_SCS0LD]        = 0x00000000;
984 30b6f3a8 ths
    s->regs[GT_SCS0HD]        = 0x00000007;
985 30b6f3a8 ths
    s->regs[GT_SCS1LD]        = 0x00000008;
986 30b6f3a8 ths
    s->regs[GT_SCS1HD]        = 0x0000000f;
987 30b6f3a8 ths
    s->regs[GT_SCS2LD]        = 0x00000010;
988 30b6f3a8 ths
    s->regs[GT_SCS2HD]        = 0x00000017;
989 30b6f3a8 ths
    s->regs[GT_SCS3LD]        = 0x00000018;
990 30b6f3a8 ths
    s->regs[GT_SCS3HD]        = 0x0000001f;
991 30b6f3a8 ths
    s->regs[GT_CS0LD]         = 0x000000c0;
992 30b6f3a8 ths
    s->regs[GT_CS0HD]         = 0x000000c7;
993 30b6f3a8 ths
    s->regs[GT_CS1LD]         = 0x000000c8;
994 30b6f3a8 ths
    s->regs[GT_CS1HD]         = 0x000000cf;
995 30b6f3a8 ths
    s->regs[GT_CS2LD]         = 0x000000d0;
996 30b6f3a8 ths
    s->regs[GT_CS2HD]         = 0x000000df;
997 30b6f3a8 ths
    s->regs[GT_CS3LD]         = 0x000000f0;
998 30b6f3a8 ths
    s->regs[GT_CS3HD]         = 0x000000fb;
999 30b6f3a8 ths
    s->regs[GT_BOOTLD]        = 0x000000fc;
1000 30b6f3a8 ths
    s->regs[GT_BOOTHD]        = 0x000000ff;
1001 30b6f3a8 ths
    s->regs[GT_ADERR]         = 0xffffffff;
1002 30b6f3a8 ths
1003 30b6f3a8 ths
    /* SDRAM Configuration */
1004 30b6f3a8 ths
    s->regs[GT_SDRAM_CFG]     = 0x00000200;
1005 30b6f3a8 ths
    s->regs[GT_SDRAM_OPMODE]  = 0x00000000;
1006 30b6f3a8 ths
    s->regs[GT_SDRAM_BM]      = 0x00000007;
1007 30b6f3a8 ths
    s->regs[GT_SDRAM_ADDRDECODE] = 0x00000002;
1008 30b6f3a8 ths
1009 30b6f3a8 ths
    /* SDRAM Parameters */
1010 30b6f3a8 ths
    s->regs[GT_SDRAM_B0]      = 0x00000005;
1011 30b6f3a8 ths
    s->regs[GT_SDRAM_B1]      = 0x00000005;
1012 30b6f3a8 ths
    s->regs[GT_SDRAM_B2]      = 0x00000005;
1013 30b6f3a8 ths
    s->regs[GT_SDRAM_B3]      = 0x00000005;
1014 30b6f3a8 ths
1015 fde7d5bd ths
    /* ECC */
1016 fde7d5bd ths
    s->regs[GT_ECC_ERRDATALO] = 0x00000000;
1017 fde7d5bd ths
    s->regs[GT_ECC_ERRDATAHI] = 0x00000000;
1018 fde7d5bd ths
    s->regs[GT_ECC_MEM]       = 0x00000000;
1019 fde7d5bd ths
    s->regs[GT_ECC_CALC]      = 0x00000000;
1020 fde7d5bd ths
    s->regs[GT_ECC_ERRADDR]   = 0x00000000;
1021 fde7d5bd ths
1022 30b6f3a8 ths
    /* Device Parameters */
1023 30b6f3a8 ths
    s->regs[GT_DEV_B0]        = 0x386fffff;
1024 30b6f3a8 ths
    s->regs[GT_DEV_B1]        = 0x386fffff;
1025 30b6f3a8 ths
    s->regs[GT_DEV_B2]        = 0x386fffff;
1026 30b6f3a8 ths
    s->regs[GT_DEV_B3]        = 0x386fffff;
1027 30b6f3a8 ths
    s->regs[GT_DEV_BOOT]      = 0x146fffff;
1028 0da75eb1 ths
1029 30b6f3a8 ths
    /* DMA registers are all zeroed at reset */
1030 30b6f3a8 ths
1031 30b6f3a8 ths
    /* Timer/Counter */
1032 30b6f3a8 ths
    s->regs[GT_TC0]           = 0xffffffff;
1033 30b6f3a8 ths
    s->regs[GT_TC1]           = 0x00ffffff;
1034 30b6f3a8 ths
    s->regs[GT_TC2]           = 0x00ffffff;
1035 30b6f3a8 ths
    s->regs[GT_TC3]           = 0x00ffffff;
1036 30b6f3a8 ths
    s->regs[GT_TC_CONTROL]    = 0x00000000;
1037 30b6f3a8 ths
1038 30b6f3a8 ths
    /* PCI Internal */
1039 fde7d5bd ths
#ifdef TARGET_WORDS_BIGENDIAN
1040 fde7d5bd ths
    s->regs[GT_PCI0_CMD]      = 0x00000000;
1041 fde7d5bd ths
#else
1042 fde7d5bd ths
    s->regs[GT_PCI0_CMD]      = 0x00010001;
1043 fde7d5bd ths
#endif
1044 30b6f3a8 ths
    s->regs[GT_PCI0_TOR]      = 0x0000070f;
1045 30b6f3a8 ths
    s->regs[GT_PCI0_BS_SCS10] = 0x00fff000;
1046 30b6f3a8 ths
    s->regs[GT_PCI0_BS_SCS32] = 0x00fff000;
1047 30b6f3a8 ths
    s->regs[GT_PCI0_BS_CS20]  = 0x01fff000;
1048 30b6f3a8 ths
    s->regs[GT_PCI0_BS_CS3BT] = 0x00fff000;
1049 fde7d5bd ths
    s->regs[GT_PCI1_IACK]     = 0x00000000;
1050 30b6f3a8 ths
    s->regs[GT_PCI0_IACK]     = 0x00000000;
1051 30b6f3a8 ths
    s->regs[GT_PCI0_BARE]     = 0x0000000f;
1052 30b6f3a8 ths
    s->regs[GT_PCI0_PREFMBR]  = 0x00000040;
1053 30b6f3a8 ths
    s->regs[GT_PCI0_SCS10_BAR] = 0x00000000;
1054 30b6f3a8 ths
    s->regs[GT_PCI0_SCS32_BAR] = 0x01000000;
1055 30b6f3a8 ths
    s->regs[GT_PCI0_CS20_BAR] = 0x1c000000;
1056 30b6f3a8 ths
    s->regs[GT_PCI0_CS3BT_BAR] = 0x1f000000;
1057 30b6f3a8 ths
    s->regs[GT_PCI0_SSCS10_BAR] = 0x00000000;
1058 30b6f3a8 ths
    s->regs[GT_PCI0_SSCS32_BAR] = 0x01000000;
1059 30b6f3a8 ths
    s->regs[GT_PCI0_SCS3BT_BAR] = 0x1f000000;
1060 30b6f3a8 ths
#ifdef TARGET_WORDS_BIGENDIAN
1061 30b6f3a8 ths
    s->regs[GT_PCI1_CMD]      = 0x00000000;
1062 30b6f3a8 ths
#else
1063 30b6f3a8 ths
    s->regs[GT_PCI1_CMD]      = 0x00010001;
1064 30b6f3a8 ths
#endif
1065 30b6f3a8 ths
    s->regs[GT_PCI1_TOR]      = 0x0000070f;
1066 30b6f3a8 ths
    s->regs[GT_PCI1_BS_SCS10] = 0x00fff000;
1067 30b6f3a8 ths
    s->regs[GT_PCI1_BS_SCS32] = 0x00fff000;
1068 30b6f3a8 ths
    s->regs[GT_PCI1_BS_CS20]  = 0x01fff000;
1069 30b6f3a8 ths
    s->regs[GT_PCI1_BS_CS3BT] = 0x00fff000;
1070 30b6f3a8 ths
    s->regs[GT_PCI1_BARE]     = 0x0000000f;
1071 30b6f3a8 ths
    s->regs[GT_PCI1_PREFMBR]  = 0x00000040;
1072 30b6f3a8 ths
    s->regs[GT_PCI1_SCS10_BAR] = 0x00000000;
1073 30b6f3a8 ths
    s->regs[GT_PCI1_SCS32_BAR] = 0x01000000;
1074 30b6f3a8 ths
    s->regs[GT_PCI1_CS20_BAR] = 0x1c000000;
1075 30b6f3a8 ths
    s->regs[GT_PCI1_CS3BT_BAR] = 0x1f000000;
1076 30b6f3a8 ths
    s->regs[GT_PCI1_SSCS10_BAR] = 0x00000000;
1077 30b6f3a8 ths
    s->regs[GT_PCI1_SSCS32_BAR] = 0x01000000;
1078 30b6f3a8 ths
    s->regs[GT_PCI1_SCS3BT_BAR] = 0x1f000000;
1079 30b6f3a8 ths
    s->regs[GT_PCI1_CFGADDR]  = 0x00000000;
1080 30b6f3a8 ths
    s->regs[GT_PCI1_CFGDATA]  = 0x00000000;
1081 30b6f3a8 ths
    s->regs[GT_PCI0_CFGADDR]  = 0x00000000;
1082 30b6f3a8 ths
1083 30b6f3a8 ths
    /* Interrupt registers are all zeroed at reset */
1084 fde7d5bd ths
1085 a0a8793e ths
    gt64120_isd_mapping(s);
1086 9414cc6f ths
    gt64120_pci_mapping(s);
1087 fde7d5bd ths
}
1088 fde7d5bd ths
1089 1823082c ths
static void gt64120_save(QEMUFile* f, void *opaque)
1090 1823082c ths
{
1091 1823082c ths
    PCIDevice *d = opaque;
1092 1823082c ths
    pci_device_save(d, f);
1093 1823082c ths
}
1094 1823082c ths
1095 1823082c ths
static int gt64120_load(QEMUFile* f, void *opaque, int version_id)
1096 1823082c ths
{
1097 1823082c ths
    PCIDevice *d = opaque;
1098 1823082c ths
    int ret;
1099 1823082c ths
1100 1823082c ths
    if (version_id != 1)
1101 1823082c ths
        return -EINVAL;
1102 1823082c ths
    ret = pci_device_load(d, f);
1103 1823082c ths
    if (ret < 0)
1104 1823082c ths
        return ret;
1105 1823082c ths
    return 0;
1106 1823082c ths
}
1107 1823082c ths
1108 d537cf6c pbrook
PCIBus *pci_gt64120_init(qemu_irq *pic)
1109 fde7d5bd ths
{
1110 fde7d5bd ths
    GT64120State *s;
1111 fde7d5bd ths
    PCIDevice *d;
1112 fde7d5bd ths
1113 fde7d5bd ths
    s = qemu_mallocz(sizeof(GT64120State));
1114 fde7d5bd ths
    s->pci = qemu_mallocz(sizeof(GT64120PCIState));
1115 9414cc6f ths
1116 02e2da45 Paul Brook
    s->pci->bus = pci_register_bus(NULL, "pci",
1117 02e2da45 Paul Brook
                                   pci_gt64120_set_irq, pci_gt64120_map_irq,
1118 520128bd Isaku Yamahata
                                   pic, PCI_DEVFN(18, 0), 4);
1119 1eed09cb Avi Kivity
    s->ISD_handle = cpu_register_io_memory(gt64120_read, gt64120_write, s);
1120 fde7d5bd ths
    d = pci_register_device(s->pci->bus, "GT64120 PCI Bus", sizeof(PCIDevice),
1121 e0fe0204 Isaku Yamahata
                            0, NULL, NULL);
1122 fde7d5bd ths
1123 0f78cf0c ths
    /* FIXME: Malta specific hw assumptions ahead */
1124 0f78cf0c ths
1125 deb54399 aliguori
    pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_MARVELL);
1126 a770dc7e aliguori
    pci_config_set_device_id(d->config, PCI_DEVICE_ID_MARVELL_GT6412X);
1127 0f78cf0c ths
1128 0f78cf0c ths
    d->config[0x04] = 0x00;
1129 fde7d5bd ths
    d->config[0x05] = 0x00;
1130 fde7d5bd ths
    d->config[0x06] = 0x80;
1131 0f78cf0c ths
    d->config[0x07] = 0x02;
1132 0f78cf0c ths
1133 fde7d5bd ths
    d->config[0x08] = 0x10;
1134 fde7d5bd ths
    d->config[0x09] = 0x00;
1135 173a543b blueswir1
    pci_config_set_class(d->config, PCI_CLASS_BRIDGE_HOST);
1136 0f78cf0c ths
1137 0f78cf0c ths
    d->config[0x10] = 0x08;
1138 0f78cf0c ths
    d->config[0x14] = 0x08;
1139 0f78cf0c ths
    d->config[0x17] = 0x01;
1140 fde7d5bd ths
    d->config[0x1B] = 0x1c;
1141 fde7d5bd ths
    d->config[0x1F] = 0x1f;
1142 fde7d5bd ths
    d->config[0x23] = 0x14;
1143 0f78cf0c ths
    d->config[0x24] = 0x01;
1144 fde7d5bd ths
    d->config[0x27] = 0x14;
1145 fde7d5bd ths
    d->config[0x3D] = 0x01;
1146 fde7d5bd ths
1147 a0a8793e ths
    gt64120_reset(s);
1148 a0a8793e ths
1149 0be71e32 Alex Williamson
    register_savevm(&d->qdev, "GT64120 PCI Bus", 0, 1,
1150 0be71e32 Alex Williamson
                    gt64120_save, gt64120_load, d);
1151 1823082c ths
1152 fde7d5bd ths
    return s->pci->bus;
1153 fde7d5bd ths
}