Statistics
| Branch: | Revision:

root / hw / gt64xxx.c @ d8c6d07f

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