Statistics
| Branch: | Revision:

root / hw / gt64xxx.c @ 05b4ff43

History | View | Annotate | Download (26.9 kB)

1 fde7d5bd ths
/*
2 fde7d5bd ths
 * QEMU GT64120 PCI host
3 fde7d5bd ths
 *
4 4de9b249 ths
 * Copyright (c) 2006,2007 Aurelien Jarno
5 fde7d5bd 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 fde7d5bd ths
#include "vl.h"
26 05b4ff43 ths
27 fde7d5bd ths
typedef target_phys_addr_t pci_addr_t;
28 fde7d5bd ths
#include "pci_host.h"
29 fde7d5bd ths
30 05b4ff43 ths
//#define DEBUG
31 05b4ff43 ths
32 05b4ff43 ths
#ifdef DEBUG
33 05b4ff43 ths
#define dprintf(fmt, ...) fprintf(stderr, "%s: " fmt, __FUNCTION__, ##__VA_ARGS__)
34 05b4ff43 ths
#else
35 05b4ff43 ths
#define dprintf(fmt, ...)
36 05b4ff43 ths
#endif
37 05b4ff43 ths
38 fde7d5bd ths
#define GT_REGS                        (0x1000 >> 2)
39 fde7d5bd ths
40 fde7d5bd ths
/* CPU Configuration */
41 fde7d5bd ths
#define GT_CPU                    (0x000 >> 2)
42 fde7d5bd ths
#define GT_MULTI                    (0x120 >> 2)
43 fde7d5bd ths
44 fde7d5bd ths
/* CPU Address Decode */
45 fde7d5bd ths
#define GT_SCS10LD                    (0x008 >> 2)
46 fde7d5bd ths
#define GT_SCS10HD                    (0x010 >> 2)
47 fde7d5bd ths
#define GT_SCS32LD                    (0x018 >> 2)
48 fde7d5bd ths
#define GT_SCS32HD                    (0x020 >> 2)
49 fde7d5bd ths
#define GT_CS20LD                    (0x028 >> 2)
50 fde7d5bd ths
#define GT_CS20HD                    (0x030 >> 2)
51 fde7d5bd ths
#define GT_CS3BOOTLD            (0x038 >> 2)
52 fde7d5bd ths
#define GT_CS3BOOTHD            (0x040 >> 2)
53 fde7d5bd ths
#define GT_PCI0IOLD                    (0x048 >> 2)
54 fde7d5bd ths
#define GT_PCI0IOHD                    (0x050 >> 2)
55 fde7d5bd ths
#define GT_PCI0M0LD                    (0x058 >> 2)
56 fde7d5bd ths
#define GT_PCI0M0HD                    (0x060 >> 2)
57 fde7d5bd ths
#define GT_PCI0M1LD                    (0x080 >> 2)
58 fde7d5bd ths
#define GT_PCI0M1HD                    (0x088 >> 2)
59 fde7d5bd ths
#define GT_PCI1IOLD                    (0x090 >> 2)
60 fde7d5bd ths
#define GT_PCI1IOHD                    (0x098 >> 2)
61 fde7d5bd ths
#define GT_PCI1M0LD                    (0x0a0 >> 2)
62 fde7d5bd ths
#define GT_PCI1M0HD                    (0x0a8 >> 2)
63 fde7d5bd ths
#define GT_PCI1M1LD                    (0x0b0 >> 2)
64 fde7d5bd ths
#define GT_PCI1M1HD                    (0x0b8 >> 2)
65 05b4ff43 ths
#define GT_ISD                    (0x068 >> 2)
66 fde7d5bd ths
67 fde7d5bd ths
#define GT_SCS10AR                    (0x0d0 >> 2)
68 fde7d5bd ths
#define GT_SCS32AR                    (0x0d8 >> 2)
69 fde7d5bd ths
#define GT_CS20R                    (0x0e0 >> 2)
70 fde7d5bd ths
#define GT_CS3BOOTR                    (0x0e8 >> 2)
71 fde7d5bd ths
72 fde7d5bd ths
#define GT_PCI0IOREMAP            (0x0f0 >> 2)
73 fde7d5bd ths
#define GT_PCI0M0REMAP            (0x0f8 >> 2)
74 fde7d5bd ths
#define GT_PCI0M1REMAP            (0x100 >> 2)
75 fde7d5bd ths
#define GT_PCI1IOREMAP            (0x108 >> 2)
76 fde7d5bd ths
#define GT_PCI1M0REMAP            (0x110 >> 2)
77 fde7d5bd ths
#define GT_PCI1M1REMAP            (0x118 >> 2)
78 fde7d5bd ths
79 fde7d5bd ths
/* CPU Error Report */
80 fde7d5bd ths
#define GT_CPUERR_ADDRLO            (0x070 >> 2)
81 fde7d5bd ths
#define GT_CPUERR_ADDRHI            (0x078 >> 2)
82 fde7d5bd ths
#define GT_CPUERR_DATALO            (0x128 >> 2)                /* GT-64120A only  */
83 fde7d5bd ths
#define GT_CPUERR_DATAHI            (0x130 >> 2)                /* GT-64120A only  */
84 fde7d5bd ths
#define GT_CPUERR_PARITY            (0x138 >> 2)                /* GT-64120A only  */
85 fde7d5bd ths
86 fde7d5bd ths
/* CPU Sync Barrier */
87 fde7d5bd ths
#define GT_PCI0SYNC                    (0x0c0 >> 2)
88 fde7d5bd ths
#define GT_PCI1SYNC                    (0x0c8 >> 2)
89 fde7d5bd ths
90 fde7d5bd ths
/* SDRAM and Device Address Decode */
91 fde7d5bd ths
#define GT_SCS0LD                    (0x400 >> 2)
92 fde7d5bd ths
#define GT_SCS0HD                    (0x404 >> 2)
93 fde7d5bd ths
#define GT_SCS1LD                    (0x408 >> 2)
94 fde7d5bd ths
#define GT_SCS1HD                    (0x40c >> 2)
95 fde7d5bd ths
#define GT_SCS2LD                    (0x410 >> 2)
96 fde7d5bd ths
#define GT_SCS2HD                    (0x414 >> 2)
97 fde7d5bd ths
#define GT_SCS3LD                    (0x418 >> 2)
98 fde7d5bd ths
#define GT_SCS3HD                    (0x41c >> 2)
99 fde7d5bd ths
#define GT_CS0LD                    (0x420 >> 2)
100 fde7d5bd ths
#define GT_CS0HD                    (0x424 >> 2)
101 fde7d5bd ths
#define GT_CS1LD                    (0x428 >> 2)
102 fde7d5bd ths
#define GT_CS1HD                    (0x42c >> 2)
103 fde7d5bd ths
#define GT_CS2LD                    (0x430 >> 2)
104 fde7d5bd ths
#define GT_CS2HD                    (0x434 >> 2)
105 fde7d5bd ths
#define GT_CS3LD                    (0x438 >> 2)
106 fde7d5bd ths
#define GT_CS3HD                    (0x43c >> 2)
107 fde7d5bd ths
#define GT_BOOTLD                    (0x440 >> 2)
108 fde7d5bd ths
#define GT_BOOTHD                    (0x444 >> 2)
109 fde7d5bd ths
#define GT_ADERR                    (0x470 >> 2)
110 fde7d5bd ths
111 fde7d5bd ths
/* SDRAM Configuration */
112 fde7d5bd ths
#define GT_SDRAM_CFG            (0x448 >> 2)
113 fde7d5bd ths
#define GT_SDRAM_OPMODE            (0x474 >> 2)
114 fde7d5bd ths
#define GT_SDRAM_BM                    (0x478 >> 2)
115 fde7d5bd ths
#define GT_SDRAM_ADDRDECODE            (0x47c >> 2)
116 fde7d5bd ths
117 fde7d5bd ths
/* SDRAM Parameters */
118 fde7d5bd ths
#define GT_SDRAM_B0                    (0x44c >> 2)
119 fde7d5bd ths
#define GT_SDRAM_B1                    (0x450 >> 2)
120 fde7d5bd ths
#define GT_SDRAM_B2                    (0x454 >> 2)
121 fde7d5bd ths
#define GT_SDRAM_B3                    (0x458 >> 2)
122 fde7d5bd ths
123 fde7d5bd ths
/* Device Parameters */
124 fde7d5bd ths
#define GT_DEV_B0                    (0x45c >> 2)
125 fde7d5bd ths
#define GT_DEV_B1                    (0x460 >> 2)
126 fde7d5bd ths
#define GT_DEV_B2                    (0x464 >> 2)
127 fde7d5bd ths
#define GT_DEV_B3                    (0x468 >> 2)
128 fde7d5bd ths
#define GT_DEV_BOOT                    (0x46c >> 2)
129 fde7d5bd ths
130 fde7d5bd ths
/* ECC */
131 fde7d5bd ths
#define GT_ECC_ERRDATALO        (0x480 >> 2)                /* GT-64120A only  */
132 fde7d5bd ths
#define GT_ECC_ERRDATAHI        (0x484 >> 2)                /* GT-64120A only  */
133 fde7d5bd ths
#define GT_ECC_MEM                (0x488 >> 2)                /* GT-64120A only  */
134 fde7d5bd ths
#define GT_ECC_CALC                (0x48c >> 2)                /* GT-64120A only  */
135 fde7d5bd ths
#define GT_ECC_ERRADDR                (0x490 >> 2)                /* GT-64120A only  */
136 fde7d5bd ths
137 fde7d5bd ths
/* DMA Record */
138 fde7d5bd ths
#define GT_DMA0_CNT                    (0x800 >> 2)
139 fde7d5bd ths
#define GT_DMA1_CNT                    (0x804 >> 2)
140 fde7d5bd ths
#define GT_DMA2_CNT                    (0x808 >> 2)
141 fde7d5bd ths
#define GT_DMA3_CNT                    (0x80c >> 2)
142 fde7d5bd ths
#define GT_DMA0_SA                    (0x810 >> 2)
143 fde7d5bd ths
#define GT_DMA1_SA                    (0x814 >> 2)
144 fde7d5bd ths
#define GT_DMA2_SA                    (0x818 >> 2)
145 fde7d5bd ths
#define GT_DMA3_SA                    (0x81c >> 2)
146 fde7d5bd ths
#define GT_DMA0_DA                    (0x820 >> 2)
147 fde7d5bd ths
#define GT_DMA1_DA                    (0x824 >> 2)
148 fde7d5bd ths
#define GT_DMA2_DA                    (0x828 >> 2)
149 fde7d5bd ths
#define GT_DMA3_DA                    (0x82c >> 2)
150 fde7d5bd ths
#define GT_DMA0_NEXT            (0x830 >> 2)
151 fde7d5bd ths
#define GT_DMA1_NEXT            (0x834 >> 2)
152 fde7d5bd ths
#define GT_DMA2_NEXT            (0x838 >> 2)
153 fde7d5bd ths
#define GT_DMA3_NEXT            (0x83c >> 2)
154 fde7d5bd ths
#define GT_DMA0_CUR                    (0x870 >> 2)
155 fde7d5bd ths
#define GT_DMA1_CUR                    (0x874 >> 2)
156 fde7d5bd ths
#define GT_DMA2_CUR                    (0x878 >> 2)
157 fde7d5bd ths
#define GT_DMA3_CUR                    (0x87c >> 2)
158 fde7d5bd ths
159 fde7d5bd ths
/* DMA Channel Control */
160 fde7d5bd ths
#define GT_DMA0_CTRL            (0x840 >> 2)
161 fde7d5bd ths
#define GT_DMA1_CTRL            (0x844 >> 2)
162 fde7d5bd ths
#define GT_DMA2_CTRL            (0x848 >> 2)
163 fde7d5bd ths
#define GT_DMA3_CTRL            (0x84c >> 2)
164 fde7d5bd ths
165 fde7d5bd ths
/* DMA Arbiter */
166 fde7d5bd ths
#define GT_DMA_ARB                    (0x860 >> 2)
167 fde7d5bd ths
168 fde7d5bd ths
/* Timer/Counter */
169 fde7d5bd ths
#define GT_TC0                    (0x850 >> 2)
170 fde7d5bd ths
#define GT_TC1                    (0x854 >> 2)
171 fde7d5bd ths
#define GT_TC2                    (0x858 >> 2)
172 fde7d5bd ths
#define GT_TC3                    (0x85c >> 2)
173 fde7d5bd ths
#define GT_TC_CONTROL            (0x864 >> 2)
174 fde7d5bd ths
175 fde7d5bd ths
/* PCI Internal */
176 fde7d5bd ths
#define GT_PCI0_CMD                    (0xc00 >> 2)
177 fde7d5bd ths
#define GT_PCI0_TOR                    (0xc04 >> 2)
178 fde7d5bd ths
#define GT_PCI0_BS_SCS10            (0xc08 >> 2)
179 fde7d5bd ths
#define GT_PCI0_BS_SCS32            (0xc0c >> 2)
180 fde7d5bd ths
#define GT_PCI0_BS_CS20            (0xc10 >> 2)
181 fde7d5bd ths
#define GT_PCI0_BS_CS3BT            (0xc14 >> 2)
182 fde7d5bd ths
#define GT_PCI1_IACK            (0xc30 >> 2)
183 fde7d5bd ths
#define GT_PCI0_IACK            (0xc34 >> 2)
184 fde7d5bd ths
#define GT_PCI0_BARE            (0xc3c >> 2)
185 fde7d5bd ths
#define GT_PCI0_PREFMBR            (0xc40 >> 2)
186 fde7d5bd ths
#define GT_PCI0_SCS10_BAR            (0xc48 >> 2)
187 fde7d5bd ths
#define GT_PCI0_SCS32_BAR            (0xc4c >> 2)
188 fde7d5bd ths
#define GT_PCI0_CS20_BAR            (0xc50 >> 2)
189 fde7d5bd ths
#define GT_PCI0_CS3BT_BAR            (0xc54 >> 2)
190 fde7d5bd ths
#define GT_PCI0_SSCS10_BAR            (0xc58 >> 2)
191 fde7d5bd ths
#define GT_PCI0_SSCS32_BAR            (0xc5c >> 2)
192 fde7d5bd ths
#define GT_PCI0_SCS3BT_BAR            (0xc64 >> 2)
193 fde7d5bd ths
#define GT_PCI1_CMD                    (0xc80 >> 2)
194 fde7d5bd ths
#define GT_PCI1_TOR                    (0xc84 >> 2)
195 fde7d5bd ths
#define GT_PCI1_BS_SCS10            (0xc88 >> 2)
196 fde7d5bd ths
#define GT_PCI1_BS_SCS32            (0xc8c >> 2)
197 fde7d5bd ths
#define GT_PCI1_BS_CS20            (0xc90 >> 2)
198 fde7d5bd ths
#define GT_PCI1_BS_CS3BT            (0xc94 >> 2)
199 fde7d5bd ths
#define GT_PCI1_BARE            (0xcbc >> 2)
200 fde7d5bd ths
#define GT_PCI1_PREFMBR            (0xcc0 >> 2)
201 fde7d5bd ths
#define GT_PCI1_SCS10_BAR            (0xcc8 >> 2)
202 fde7d5bd ths
#define GT_PCI1_SCS32_BAR            (0xccc >> 2)
203 fde7d5bd ths
#define GT_PCI1_CS20_BAR            (0xcd0 >> 2)
204 fde7d5bd ths
#define GT_PCI1_CS3BT_BAR            (0xcd4 >> 2)
205 fde7d5bd ths
#define GT_PCI1_SSCS10_BAR            (0xcd8 >> 2)
206 fde7d5bd ths
#define GT_PCI1_SSCS32_BAR            (0xcdc >> 2)
207 fde7d5bd ths
#define GT_PCI1_SCS3BT_BAR            (0xce4 >> 2)
208 fde7d5bd ths
#define GT_PCI1_CFGADDR            (0xcf0 >> 2)
209 fde7d5bd ths
#define GT_PCI1_CFGDATA            (0xcf4 >> 2)
210 fde7d5bd ths
#define GT_PCI0_CFGADDR            (0xcf8 >> 2)
211 fde7d5bd ths
#define GT_PCI0_CFGDATA            (0xcfc >> 2)
212 fde7d5bd ths
213 fde7d5bd ths
/* Interrupts */
214 fde7d5bd ths
#define GT_INTRCAUSE            (0xc18 >> 2)
215 fde7d5bd ths
#define GT_INTRMASK                    (0xc1c >> 2)
216 fde7d5bd ths
#define GT_PCI0_ICMASK            (0xc24 >> 2)
217 fde7d5bd ths
#define GT_PCI0_SERR0MASK            (0xc28 >> 2)
218 fde7d5bd ths
#define GT_CPU_INTSEL            (0xc70 >> 2)
219 fde7d5bd ths
#define GT_PCI0_INTSEL            (0xc74 >> 2)
220 fde7d5bd ths
#define GT_HINTRCAUSE            (0xc98 >> 2)
221 fde7d5bd ths
#define GT_HINTRMASK            (0xc9c >> 2)
222 fde7d5bd ths
#define GT_PCI0_HICMASK            (0xca4 >> 2)
223 fde7d5bd ths
#define GT_PCI1_SERR1MASK            (0xca8 >> 2)
224 fde7d5bd ths
225 fde7d5bd ths
226 fde7d5bd ths
typedef PCIHostState GT64120PCIState;
227 fde7d5bd ths
228 fde7d5bd ths
typedef struct GT64120State {
229 fde7d5bd ths
    GT64120PCIState *pci;
230 fde7d5bd ths
    uint32_t regs[GT_REGS];
231 35f1de31 ths
    target_phys_addr_t PCI0IO_start;
232 35f1de31 ths
    target_phys_addr_t PCI0IO_length;
233 fde7d5bd ths
} GT64120State;
234 fde7d5bd ths
235 fde7d5bd ths
static void gt64120_pci_mapping(GT64120State *s)
236 fde7d5bd ths
{
237 fde7d5bd ths
    /* Update IO mapping */
238 90e950d1 ths
    if ((s->regs[GT_PCI0IOLD] & 0x7f) <= s->regs[GT_PCI0IOHD])
239 90e950d1 ths
    {
240 35f1de31 ths
      /* Unmap old IO address */            
241 35f1de31 ths
      if (s->PCI0IO_length)
242 35f1de31 ths
      {
243 35f1de31 ths
        cpu_register_physical_memory(s->PCI0IO_start, s->PCI0IO_length, IO_MEM_UNASSIGNED);             
244 35f1de31 ths
      }
245 35f1de31 ths
      /* Map new IO address */
246 35f1de31 ths
      s->PCI0IO_start = s->regs[GT_PCI0IOLD] << 21;
247 35f1de31 ths
      s->PCI0IO_length = ((s->regs[GT_PCI0IOHD] + 1) - (s->regs[GT_PCI0IOLD] & 0x7f)) << 21;
248 11f29511 ths
      isa_mem_base = s->PCI0IO_start;
249 35f1de31 ths
      isa_mmio_init(s->PCI0IO_start, s->PCI0IO_length);
250 90e950d1 ths
    }
251 fde7d5bd ths
}
252 fde7d5bd ths
253 fde7d5bd ths
static void gt64120_writel (void *opaque, target_phys_addr_t addr,
254 fde7d5bd ths
                            uint32_t val)
255 fde7d5bd ths
{
256 fde7d5bd ths
    GT64120State *s = opaque;
257 fde7d5bd ths
    uint32_t saddr;
258 fde7d5bd ths
259 0da75eb1 ths
#ifdef TARGET_WORDS_BIGENDIAN
260 0da75eb1 ths
    val = bswap32(val);
261 0da75eb1 ths
#endif
262 0da75eb1 ths
263 fde7d5bd ths
    saddr = (addr & 0xfff) >> 2;
264 fde7d5bd ths
    switch (saddr) {
265 0da75eb1 ths
266 0da75eb1 ths
    /* CPU Configuration */
267 fde7d5bd ths
    case GT_CPU:
268 fde7d5bd ths
        s->regs[GT_CPU] = val;
269 fde7d5bd ths
        break;
270 fde7d5bd ths
    case GT_MULTI:
271 0da75eb1 ths
        /* Read-only register as only one GT64xxx is present on the CPU bus */
272 fde7d5bd ths
        break;
273 fde7d5bd ths
274 fde7d5bd ths
    /* CPU Address Decode */
275 fde7d5bd ths
    case GT_PCI0IOLD:
276 fde7d5bd ths
        s->regs[GT_PCI0IOLD]    = val & 0x00007fff;
277 fde7d5bd ths
        s->regs[GT_PCI0IOREMAP] = val & 0x000007ff;
278 fde7d5bd ths
        gt64120_pci_mapping(s);
279 fde7d5bd ths
        break;
280 fde7d5bd ths
    case GT_PCI0M0LD:
281 fde7d5bd ths
        s->regs[GT_PCI0M0LD]    = val & 0x00007fff;
282 fde7d5bd ths
        s->regs[GT_PCI0M0REMAP] = val & 0x000007ff;
283 fde7d5bd ths
        gt64120_pci_mapping(s);
284 fde7d5bd ths
        break;
285 fde7d5bd ths
    case GT_PCI0M1LD:
286 fde7d5bd ths
        s->regs[GT_PCI0M1LD]    = val & 0x00007fff;
287 fde7d5bd ths
        s->regs[GT_PCI0M1REMAP] = val & 0x000007ff;
288 fde7d5bd ths
        gt64120_pci_mapping(s);
289 fde7d5bd ths
        break;
290 fde7d5bd ths
    case GT_PCI1IOLD:
291 fde7d5bd ths
        s->regs[GT_PCI1IOLD]    = val & 0x00007fff;
292 fde7d5bd ths
        s->regs[GT_PCI1IOREMAP] = val & 0x000007ff;
293 fde7d5bd ths
        gt64120_pci_mapping(s);
294 fde7d5bd ths
        break;
295 fde7d5bd ths
    case GT_PCI1M0LD:
296 fde7d5bd ths
        s->regs[GT_PCI1M0LD]    = val & 0x00007fff;
297 fde7d5bd ths
        s->regs[GT_PCI1M0REMAP] = val & 0x000007ff;
298 fde7d5bd ths
        gt64120_pci_mapping(s);
299 fde7d5bd ths
        break;
300 fde7d5bd ths
    case GT_PCI1M1LD:
301 fde7d5bd ths
        s->regs[GT_PCI1M1LD]    = val & 0x00007fff;
302 fde7d5bd ths
        s->regs[GT_PCI1M1REMAP] = val & 0x000007ff;
303 fde7d5bd ths
        gt64120_pci_mapping(s);
304 fde7d5bd ths
        break;
305 fde7d5bd ths
    case GT_PCI0IOHD:
306 fde7d5bd ths
    case GT_PCI0M0HD:
307 fde7d5bd ths
    case GT_PCI0M1HD:
308 fde7d5bd ths
    case GT_PCI1IOHD:
309 fde7d5bd ths
    case GT_PCI1M0HD:
310 fde7d5bd ths
    case GT_PCI1M1HD:
311 fde7d5bd ths
        s->regs[saddr] = val & 0x0000007f;
312 fde7d5bd ths
        gt64120_pci_mapping(s);
313 fde7d5bd ths
        break;
314 fde7d5bd ths
    case GT_PCI0IOREMAP:
315 fde7d5bd ths
    case GT_PCI0M0REMAP:
316 fde7d5bd ths
    case GT_PCI0M1REMAP:
317 fde7d5bd ths
    case GT_PCI1IOREMAP:
318 fde7d5bd ths
    case GT_PCI1M0REMAP:
319 fde7d5bd ths
    case GT_PCI1M1REMAP:
320 fde7d5bd ths
        s->regs[saddr] = val & 0x000007ff;
321 fde7d5bd ths
        gt64120_pci_mapping(s);
322 fde7d5bd ths
        break;
323 fde7d5bd ths
324 fde7d5bd ths
    /* CPU Error Report */
325 fde7d5bd ths
    case GT_CPUERR_ADDRLO:
326 fde7d5bd ths
    case GT_CPUERR_ADDRHI:
327 fde7d5bd ths
    case GT_CPUERR_DATALO:
328 fde7d5bd ths
    case GT_CPUERR_DATAHI:
329 fde7d5bd ths
    case GT_CPUERR_PARITY:
330 0da75eb1 ths
        /* Read-only registers, do nothing */
331 0da75eb1 ths
        break;
332 0da75eb1 ths
333 0da75eb1 ths
    /* CPU Sync Barrier */
334 0da75eb1 ths
    case GT_PCI0SYNC:
335 0da75eb1 ths
    case GT_PCI1SYNC:
336 0da75eb1 ths
        /* Read-only registers, do nothing */
337 fde7d5bd ths
        break;
338 fde7d5bd ths
339 05b4ff43 ths
    /* SDRAM and Device Address Decode */
340 05b4ff43 ths
    case GT_SCS0LD:
341 05b4ff43 ths
    case GT_SCS0HD:
342 05b4ff43 ths
    case GT_SCS1LD:
343 05b4ff43 ths
    case GT_SCS1HD:
344 05b4ff43 ths
    case GT_SCS2LD:
345 05b4ff43 ths
    case GT_SCS2HD:
346 05b4ff43 ths
    case GT_SCS3LD:
347 05b4ff43 ths
    case GT_SCS3HD:
348 05b4ff43 ths
    case GT_CS0LD:
349 05b4ff43 ths
    case GT_CS0HD:
350 05b4ff43 ths
    case GT_CS1LD:
351 05b4ff43 ths
    case GT_CS1HD:
352 05b4ff43 ths
    case GT_CS2LD:
353 05b4ff43 ths
    case GT_CS2HD:
354 05b4ff43 ths
    case GT_CS3LD:
355 05b4ff43 ths
    case GT_CS3HD:
356 05b4ff43 ths
    case GT_BOOTLD:
357 05b4ff43 ths
    case GT_BOOTHD:
358 05b4ff43 ths
    case GT_ADERR:
359 05b4ff43 ths
    /* SDRAM Configuration */
360 05b4ff43 ths
    case GT_SDRAM_CFG:
361 05b4ff43 ths
    case GT_SDRAM_OPMODE:
362 05b4ff43 ths
    case GT_SDRAM_BM:
363 05b4ff43 ths
    case GT_SDRAM_ADDRDECODE:
364 05b4ff43 ths
        /* Accept and ignore SDRAM interleave configuration */
365 05b4ff43 ths
        s->regs[saddr] = val;
366 05b4ff43 ths
        break;
367 05b4ff43 ths
368 05b4ff43 ths
    /* Device Parameters */
369 05b4ff43 ths
    case GT_DEV_B0:
370 05b4ff43 ths
    case GT_DEV_B1:
371 05b4ff43 ths
    case GT_DEV_B2:
372 05b4ff43 ths
    case GT_DEV_B3:
373 05b4ff43 ths
    case GT_DEV_BOOT:
374 05b4ff43 ths
        /* Not implemented */
375 05b4ff43 ths
        dprintf ("Unimplemented device register offset 0x%x\n", saddr << 2);
376 05b4ff43 ths
        break;
377 05b4ff43 ths
378 fde7d5bd ths
    /* ECC */
379 fde7d5bd ths
    case GT_ECC_ERRDATALO:
380 fde7d5bd ths
    case GT_ECC_ERRDATAHI:
381 fde7d5bd ths
    case GT_ECC_MEM:
382 fde7d5bd ths
    case GT_ECC_CALC:
383 fde7d5bd ths
    case GT_ECC_ERRADDR:
384 0da75eb1 ths
        /* Read-only registers, do nothing */
385 fde7d5bd ths
        break;
386 fde7d5bd ths
387 05b4ff43 ths
    /* DMA Record */
388 05b4ff43 ths
    case GT_DMA0_CNT:
389 05b4ff43 ths
    case GT_DMA1_CNT:
390 05b4ff43 ths
    case GT_DMA2_CNT:
391 05b4ff43 ths
    case GT_DMA3_CNT:
392 05b4ff43 ths
    case GT_DMA0_SA:
393 05b4ff43 ths
    case GT_DMA1_SA:
394 05b4ff43 ths
    case GT_DMA2_SA:
395 05b4ff43 ths
    case GT_DMA3_SA:
396 05b4ff43 ths
    case GT_DMA0_DA:
397 05b4ff43 ths
    case GT_DMA1_DA:
398 05b4ff43 ths
    case GT_DMA2_DA:
399 05b4ff43 ths
    case GT_DMA3_DA:
400 05b4ff43 ths
    case GT_DMA0_NEXT:
401 05b4ff43 ths
    case GT_DMA1_NEXT:
402 05b4ff43 ths
    case GT_DMA2_NEXT:
403 05b4ff43 ths
    case GT_DMA3_NEXT:
404 05b4ff43 ths
    case GT_DMA0_CUR:
405 05b4ff43 ths
    case GT_DMA1_CUR:
406 05b4ff43 ths
    case GT_DMA2_CUR:
407 05b4ff43 ths
    case GT_DMA3_CUR:
408 05b4ff43 ths
        /* Not implemented */
409 05b4ff43 ths
        dprintf ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
410 05b4ff43 ths
        break;
411 05b4ff43 ths
412 05b4ff43 ths
    /* DMA Channel Control */
413 05b4ff43 ths
    case GT_DMA0_CTRL:
414 05b4ff43 ths
    case GT_DMA1_CTRL:
415 05b4ff43 ths
    case GT_DMA2_CTRL:
416 05b4ff43 ths
    case GT_DMA3_CTRL:
417 05b4ff43 ths
        /* Not implemented */
418 05b4ff43 ths
        dprintf ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
419 05b4ff43 ths
        break;
420 05b4ff43 ths
421 05b4ff43 ths
    /* DMA Arbiter */
422 05b4ff43 ths
    case GT_DMA_ARB:
423 05b4ff43 ths
        /* Not implemented */
424 05b4ff43 ths
        dprintf ("Unimplemented DMA register offset 0x%x\n", saddr << 2);
425 05b4ff43 ths
        break;
426 05b4ff43 ths
427 05b4ff43 ths
    /* Timer/Counter */
428 05b4ff43 ths
    case GT_TC0:
429 05b4ff43 ths
    case GT_TC1:
430 05b4ff43 ths
    case GT_TC2:
431 05b4ff43 ths
    case GT_TC3:
432 05b4ff43 ths
    case GT_TC_CONTROL:
433 05b4ff43 ths
        /* Not implemented */
434 05b4ff43 ths
        dprintf ("Unimplemented timer register offset 0x%x\n", saddr << 2);
435 05b4ff43 ths
        break;
436 05b4ff43 ths
437 fde7d5bd ths
    /* PCI Internal */
438 fde7d5bd ths
    case GT_PCI0_CMD:
439 fde7d5bd ths
    case GT_PCI1_CMD:
440 fde7d5bd ths
        s->regs[saddr] = val & 0x0401fc0f;
441 fde7d5bd ths
        break;
442 05b4ff43 ths
    case GT_PCI0_TOR:
443 05b4ff43 ths
    case GT_PCI0_BS_SCS10:
444 05b4ff43 ths
    case GT_PCI0_BS_SCS32:
445 05b4ff43 ths
    case GT_PCI0_BS_CS20:
446 05b4ff43 ths
    case GT_PCI0_BS_CS3BT:
447 05b4ff43 ths
    case GT_PCI1_IACK:
448 05b4ff43 ths
    case GT_PCI0_IACK:
449 05b4ff43 ths
    case GT_PCI0_BARE:
450 05b4ff43 ths
    case GT_PCI0_PREFMBR:
451 05b4ff43 ths
    case GT_PCI0_SCS10_BAR:
452 05b4ff43 ths
    case GT_PCI0_SCS32_BAR:
453 05b4ff43 ths
    case GT_PCI0_CS20_BAR:
454 05b4ff43 ths
    case GT_PCI0_CS3BT_BAR:
455 05b4ff43 ths
    case GT_PCI0_SSCS10_BAR:
456 05b4ff43 ths
    case GT_PCI0_SSCS32_BAR:
457 05b4ff43 ths
    case GT_PCI0_SCS3BT_BAR:
458 05b4ff43 ths
    case GT_PCI1_TOR:
459 05b4ff43 ths
    case GT_PCI1_BS_SCS10:
460 05b4ff43 ths
    case GT_PCI1_BS_SCS32:
461 05b4ff43 ths
    case GT_PCI1_BS_CS20:
462 05b4ff43 ths
    case GT_PCI1_BS_CS3BT:
463 05b4ff43 ths
    case GT_PCI1_BARE:
464 05b4ff43 ths
    case GT_PCI1_PREFMBR:
465 05b4ff43 ths
    case GT_PCI1_SCS10_BAR:
466 05b4ff43 ths
    case GT_PCI1_SCS32_BAR:
467 05b4ff43 ths
    case GT_PCI1_CS20_BAR:
468 05b4ff43 ths
    case GT_PCI1_CS3BT_BAR:
469 05b4ff43 ths
    case GT_PCI1_SSCS10_BAR:
470 05b4ff43 ths
    case GT_PCI1_SSCS32_BAR:
471 05b4ff43 ths
    case GT_PCI1_SCS3BT_BAR:
472 05b4ff43 ths
    case GT_PCI1_CFGADDR:
473 05b4ff43 ths
    case GT_PCI1_CFGDATA:
474 05b4ff43 ths
        /* not implemented */
475 05b4ff43 ths
        break;
476 fde7d5bd ths
    case GT_PCI0_CFGADDR:
477 fde7d5bd ths
        s->pci->config_reg = val & 0x80fffffc;
478 fde7d5bd ths
        break;
479 fde7d5bd ths
    case GT_PCI0_CFGDATA:
480 05b4ff43 ths
        if (s->pci->config_reg & (1u << 31))
481 05b4ff43 ths
            pci_host_data_writel(s->pci, 0, val);
482 05b4ff43 ths
        break;
483 05b4ff43 ths
484 05b4ff43 ths
    /* Interrupts */
485 05b4ff43 ths
    case GT_INTRCAUSE:
486 05b4ff43 ths
        /* not really implemented */
487 05b4ff43 ths
        s->regs[saddr] = ~(~(s->regs[saddr]) | ~(val & 0xfffffffe));
488 05b4ff43 ths
        s->regs[saddr] |= !!(s->regs[saddr] & 0xfffffffe);
489 05b4ff43 ths
        dprintf("INTRCAUSE %x\n", val);
490 05b4ff43 ths
        break;
491 05b4ff43 ths
    case GT_INTRMASK:
492 05b4ff43 ths
        s->regs[saddr] = val & 0x3c3ffffe;
493 05b4ff43 ths
        dprintf("INTRMASK %x\n", val);
494 05b4ff43 ths
        break;
495 05b4ff43 ths
    case GT_PCI0_ICMASK:
496 05b4ff43 ths
        s->regs[saddr] = val & 0x03fffffe;
497 05b4ff43 ths
        dprintf("ICMASK %x\n", val);
498 05b4ff43 ths
        break;
499 05b4ff43 ths
    case GT_PCI0_SERR0MASK:
500 05b4ff43 ths
        s->regs[saddr] = val & 0x0000003f;
501 05b4ff43 ths
        dprintf("SERR0MASK %x\n", val);
502 05b4ff43 ths
        break;
503 05b4ff43 ths
504 05b4ff43 ths
    /* Reserved when only PCI_0 is configured. */
505 05b4ff43 ths
    case GT_HINTRCAUSE:
506 05b4ff43 ths
    case GT_CPU_INTSEL:
507 05b4ff43 ths
    case GT_PCI0_INTSEL:
508 05b4ff43 ths
    case GT_HINTRMASK:
509 05b4ff43 ths
    case GT_PCI0_HICMASK:
510 05b4ff43 ths
    case GT_PCI1_SERR1MASK:
511 05b4ff43 ths
        /* not implemented */
512 fde7d5bd ths
        break;
513 fde7d5bd ths
514 0da75eb1 ths
    /* SDRAM Parameters */
515 0da75eb1 ths
    case GT_SDRAM_B0:
516 0da75eb1 ths
    case GT_SDRAM_B1:
517 0da75eb1 ths
    case GT_SDRAM_B2:
518 0da75eb1 ths
    case GT_SDRAM_B3:
519 0da75eb1 ths
        /* We don't simulate electrical parameters of the SDRAM.
520 0da75eb1 ths
           Accept, but ignore the values. */
521 0da75eb1 ths
        s->regs[saddr] = val;
522 0da75eb1 ths
        break;
523 0da75eb1 ths
524 fde7d5bd ths
    default:
525 05b4ff43 ths
        dprintf ("Bad register offset 0x%x\n", (int)addr);
526 fde7d5bd ths
        break;
527 fde7d5bd ths
    }
528 fde7d5bd ths
}
529 fde7d5bd ths
530 fde7d5bd ths
static uint32_t gt64120_readl (void *opaque,
531 fde7d5bd ths
                               target_phys_addr_t addr)
532 fde7d5bd ths
{
533 fde7d5bd ths
    GT64120State *s = opaque;
534 fde7d5bd ths
    uint32_t val;
535 fde7d5bd ths
    uint32_t saddr;
536 fde7d5bd ths
537 fde7d5bd ths
    val = 0;
538 fde7d5bd ths
    saddr = (addr & 0xfff) >> 2;
539 fde7d5bd ths
540 fde7d5bd ths
    switch (saddr) {
541 fde7d5bd ths
542 0da75eb1 ths
    /* CPU Configuration */
543 0da75eb1 ths
    case GT_MULTI:
544 0da75eb1 ths
        /* Only one GT64xxx is present on the CPU bus, return
545 0da75eb1 ths
           the initial value */
546 0da75eb1 ths
        val = s->regs[saddr];
547 0da75eb1 ths
        break;
548 0da75eb1 ths
549 fde7d5bd ths
    /* CPU Error Report */
550 fde7d5bd ths
    case GT_CPUERR_ADDRLO:
551 fde7d5bd ths
    case GT_CPUERR_ADDRHI:
552 fde7d5bd ths
    case GT_CPUERR_DATALO:
553 fde7d5bd ths
    case GT_CPUERR_DATAHI:
554 fde7d5bd ths
    case GT_CPUERR_PARITY:
555 0da75eb1 ths
        /* Emulated memory has no error, always return the initial
556 0da75eb1 ths
           values */ 
557 0da75eb1 ths
        val = s->regs[saddr];
558 0da75eb1 ths
        break;
559 0da75eb1 ths
560 0da75eb1 ths
    /* CPU Sync Barrier */
561 0da75eb1 ths
    case GT_PCI0SYNC:
562 0da75eb1 ths
    case GT_PCI1SYNC:
563 0da75eb1 ths
        /* Reading those register should empty all FIFO on the PCI
564 0da75eb1 ths
           bus, which are not emulated. The return value should be
565 0da75eb1 ths
           a random value that should be ignored. */
566 0da75eb1 ths
        val = 0xc000ffee; 
567 fde7d5bd ths
        break;
568 fde7d5bd ths
569 fde7d5bd ths
    /* ECC */
570 fde7d5bd ths
    case GT_ECC_ERRDATALO:
571 fde7d5bd ths
    case GT_ECC_ERRDATAHI:
572 fde7d5bd ths
    case GT_ECC_MEM:
573 fde7d5bd ths
    case GT_ECC_CALC:
574 fde7d5bd ths
    case GT_ECC_ERRADDR:
575 0da75eb1 ths
        /* Emulated memory has no error, always return the initial
576 0da75eb1 ths
           values */ 
577 0da75eb1 ths
        val = s->regs[saddr];
578 fde7d5bd ths
        break;
579 fde7d5bd ths
580 fde7d5bd ths
    case GT_CPU:
581 05b4ff43 ths
    case GT_SCS10LD:
582 05b4ff43 ths
    case GT_SCS10HD:
583 05b4ff43 ths
    case GT_SCS32LD:
584 05b4ff43 ths
    case GT_SCS32HD:
585 05b4ff43 ths
    case GT_CS20LD:
586 05b4ff43 ths
    case GT_CS20HD:
587 05b4ff43 ths
    case GT_CS3BOOTLD:
588 05b4ff43 ths
    case GT_CS3BOOTHD:
589 05b4ff43 ths
    case GT_SCS10AR:
590 05b4ff43 ths
    case GT_SCS32AR:
591 05b4ff43 ths
    case GT_CS20R:
592 05b4ff43 ths
    case GT_CS3BOOTR:
593 fde7d5bd ths
    case GT_PCI0IOLD:
594 fde7d5bd ths
    case GT_PCI0M0LD:
595 fde7d5bd ths
    case GT_PCI0M1LD:
596 fde7d5bd ths
    case GT_PCI1IOLD:
597 fde7d5bd ths
    case GT_PCI1M0LD:
598 fde7d5bd ths
    case GT_PCI1M1LD:
599 fde7d5bd ths
    case GT_PCI0IOHD:
600 fde7d5bd ths
    case GT_PCI0M0HD:
601 fde7d5bd ths
    case GT_PCI0M1HD:
602 fde7d5bd ths
    case GT_PCI1IOHD:
603 fde7d5bd ths
    case GT_PCI1M0HD:
604 fde7d5bd ths
    case GT_PCI1M1HD:
605 fde7d5bd ths
    case GT_PCI0IOREMAP:
606 fde7d5bd ths
    case GT_PCI0M0REMAP:
607 fde7d5bd ths
    case GT_PCI0M1REMAP:
608 fde7d5bd ths
    case GT_PCI1IOREMAP:
609 fde7d5bd ths
    case GT_PCI1M0REMAP:
610 fde7d5bd ths
    case GT_PCI1M1REMAP:
611 05b4ff43 ths
    case GT_ISD:
612 fde7d5bd ths
        val = s->regs[saddr];
613 fde7d5bd ths
        break;
614 fde7d5bd ths
    case GT_PCI0_IACK:
615 4de9b249 ths
        /* Read the IRQ number */ 
616 4de9b249 ths
        val = pic_read_irq(isa_pic);
617 fde7d5bd ths
        break;
618 fde7d5bd ths
619 05b4ff43 ths
    /* SDRAM and Device Address Decode */
620 05b4ff43 ths
    case GT_SCS0LD:
621 05b4ff43 ths
    case GT_SCS0HD:
622 05b4ff43 ths
    case GT_SCS1LD:
623 05b4ff43 ths
    case GT_SCS1HD:
624 05b4ff43 ths
    case GT_SCS2LD:
625 05b4ff43 ths
    case GT_SCS2HD:
626 05b4ff43 ths
    case GT_SCS3LD:
627 05b4ff43 ths
    case GT_SCS3HD:
628 05b4ff43 ths
    case GT_CS0LD:
629 05b4ff43 ths
    case GT_CS0HD:
630 05b4ff43 ths
    case GT_CS1LD:
631 05b4ff43 ths
    case GT_CS1HD:
632 05b4ff43 ths
    case GT_CS2LD:
633 05b4ff43 ths
    case GT_CS2HD:
634 05b4ff43 ths
    case GT_CS3LD:
635 05b4ff43 ths
    case GT_CS3HD:
636 05b4ff43 ths
    case GT_BOOTLD:
637 05b4ff43 ths
    case GT_BOOTHD:
638 05b4ff43 ths
    case GT_ADERR:
639 05b4ff43 ths
        val = s->regs[saddr];
640 05b4ff43 ths
        break;
641 05b4ff43 ths
642 05b4ff43 ths
    /* SDRAM Configuration */
643 05b4ff43 ths
    case GT_SDRAM_CFG:
644 05b4ff43 ths
    case GT_SDRAM_OPMODE:
645 05b4ff43 ths
    case GT_SDRAM_BM:
646 05b4ff43 ths
    case GT_SDRAM_ADDRDECODE:
647 05b4ff43 ths
        val = s->regs[saddr];
648 05b4ff43 ths
        break;
649 05b4ff43 ths
650 0da75eb1 ths
    /* SDRAM Parameters */
651 0da75eb1 ths
    case GT_SDRAM_B0:
652 0da75eb1 ths
    case GT_SDRAM_B1:
653 0da75eb1 ths
    case GT_SDRAM_B2:
654 0da75eb1 ths
    case GT_SDRAM_B3:
655 0da75eb1 ths
        /* We don't simulate electrical parameters of the SDRAM.
656 0da75eb1 ths
           Just return the last written value. */
657 0da75eb1 ths
        val = s->regs[saddr];
658 0da75eb1 ths
        break;
659 0da75eb1 ths
660 05b4ff43 ths
    /* Device Parameters */
661 05b4ff43 ths
    case GT_DEV_B0:
662 05b4ff43 ths
    case GT_DEV_B1:
663 05b4ff43 ths
    case GT_DEV_B2:
664 05b4ff43 ths
    case GT_DEV_B3:
665 05b4ff43 ths
    case GT_DEV_BOOT:
666 05b4ff43 ths
        val = s->regs[saddr];
667 05b4ff43 ths
        break;
668 05b4ff43 ths
669 05b4ff43 ths
    /* DMA Record */
670 05b4ff43 ths
    case GT_DMA0_CNT:
671 05b4ff43 ths
    case GT_DMA1_CNT:
672 05b4ff43 ths
    case GT_DMA2_CNT:
673 05b4ff43 ths
    case GT_DMA3_CNT:
674 05b4ff43 ths
    case GT_DMA0_SA:
675 05b4ff43 ths
    case GT_DMA1_SA:
676 05b4ff43 ths
    case GT_DMA2_SA:
677 05b4ff43 ths
    case GT_DMA3_SA:
678 05b4ff43 ths
    case GT_DMA0_DA:
679 05b4ff43 ths
    case GT_DMA1_DA:
680 05b4ff43 ths
    case GT_DMA2_DA:
681 05b4ff43 ths
    case GT_DMA3_DA:
682 05b4ff43 ths
    case GT_DMA0_NEXT:
683 05b4ff43 ths
    case GT_DMA1_NEXT:
684 05b4ff43 ths
    case GT_DMA2_NEXT:
685 05b4ff43 ths
    case GT_DMA3_NEXT:
686 05b4ff43 ths
    case GT_DMA0_CUR:
687 05b4ff43 ths
    case GT_DMA1_CUR:
688 05b4ff43 ths
    case GT_DMA2_CUR:
689 05b4ff43 ths
    case GT_DMA3_CUR:
690 05b4ff43 ths
        val = s->regs[saddr];
691 05b4ff43 ths
        break;
692 05b4ff43 ths
693 05b4ff43 ths
    /* DMA Channel Control */
694 05b4ff43 ths
    case GT_DMA0_CTRL:
695 05b4ff43 ths
    case GT_DMA1_CTRL:
696 05b4ff43 ths
    case GT_DMA2_CTRL:
697 05b4ff43 ths
    case GT_DMA3_CTRL:
698 05b4ff43 ths
        val = s->regs[saddr];
699 05b4ff43 ths
        break;
700 05b4ff43 ths
701 05b4ff43 ths
    /* DMA Arbiter */
702 05b4ff43 ths
    case GT_DMA_ARB:
703 05b4ff43 ths
        val = s->regs[saddr];
704 05b4ff43 ths
        break;
705 05b4ff43 ths
706 05b4ff43 ths
    /* Timer/Counter */
707 05b4ff43 ths
    case GT_TC0:
708 05b4ff43 ths
    case GT_TC1:
709 05b4ff43 ths
    case GT_TC2:
710 05b4ff43 ths
    case GT_TC3:
711 05b4ff43 ths
    case GT_TC_CONTROL:
712 05b4ff43 ths
        val = s->regs[saddr];
713 05b4ff43 ths
        break;
714 05b4ff43 ths
715 fde7d5bd ths
    /* PCI Internal */
716 fde7d5bd ths
    case GT_PCI0_CFGADDR:
717 fde7d5bd ths
        val = s->pci->config_reg;
718 fde7d5bd ths
        break;
719 fde7d5bd ths
    case GT_PCI0_CFGDATA:
720 05b4ff43 ths
        if (!(s->pci->config_reg & (1u << 31)))
721 05b4ff43 ths
            val = 0xffffffff;
722 05b4ff43 ths
        else
723 05b4ff43 ths
            val = pci_data_read(s->pci->bus, s->pci->config_reg, 4);
724 05b4ff43 ths
        break;
725 05b4ff43 ths
726 05b4ff43 ths
    case GT_PCI0_CMD:
727 05b4ff43 ths
    case GT_PCI0_TOR:
728 05b4ff43 ths
    case GT_PCI0_BS_SCS10:
729 05b4ff43 ths
    case GT_PCI0_BS_SCS32:
730 05b4ff43 ths
    case GT_PCI0_BS_CS20:
731 05b4ff43 ths
    case GT_PCI0_BS_CS3BT:
732 05b4ff43 ths
    case GT_PCI1_IACK:
733 05b4ff43 ths
    case GT_PCI0_BARE:
734 05b4ff43 ths
    case GT_PCI0_PREFMBR:
735 05b4ff43 ths
    case GT_PCI0_SCS10_BAR:
736 05b4ff43 ths
    case GT_PCI0_SCS32_BAR:
737 05b4ff43 ths
    case GT_PCI0_CS20_BAR:
738 05b4ff43 ths
    case GT_PCI0_CS3BT_BAR:
739 05b4ff43 ths
    case GT_PCI0_SSCS10_BAR:
740 05b4ff43 ths
    case GT_PCI0_SSCS32_BAR:
741 05b4ff43 ths
    case GT_PCI0_SCS3BT_BAR:
742 05b4ff43 ths
    case GT_PCI1_CMD:
743 05b4ff43 ths
    case GT_PCI1_TOR:
744 05b4ff43 ths
    case GT_PCI1_BS_SCS10:
745 05b4ff43 ths
    case GT_PCI1_BS_SCS32:
746 05b4ff43 ths
    case GT_PCI1_BS_CS20:
747 05b4ff43 ths
    case GT_PCI1_BS_CS3BT:
748 05b4ff43 ths
    case GT_PCI1_BARE:
749 05b4ff43 ths
    case GT_PCI1_PREFMBR:
750 05b4ff43 ths
    case GT_PCI1_SCS10_BAR:
751 05b4ff43 ths
    case GT_PCI1_SCS32_BAR:
752 05b4ff43 ths
    case GT_PCI1_CS20_BAR:
753 05b4ff43 ths
    case GT_PCI1_CS3BT_BAR:
754 05b4ff43 ths
    case GT_PCI1_SSCS10_BAR:
755 05b4ff43 ths
    case GT_PCI1_SSCS32_BAR:
756 05b4ff43 ths
    case GT_PCI1_SCS3BT_BAR:
757 05b4ff43 ths
    case GT_PCI1_CFGADDR:
758 05b4ff43 ths
    case GT_PCI1_CFGDATA:
759 05b4ff43 ths
        val = s->regs[saddr];
760 05b4ff43 ths
        break;
761 05b4ff43 ths
762 05b4ff43 ths
    /* Interrupts */
763 05b4ff43 ths
    case GT_INTRCAUSE:
764 05b4ff43 ths
        val = s->regs[saddr];
765 05b4ff43 ths
        dprintf("INTRCAUSE %x\n", val);
766 05b4ff43 ths
        break;
767 05b4ff43 ths
    case GT_INTRMASK:
768 05b4ff43 ths
        val = s->regs[saddr];
769 05b4ff43 ths
        dprintf("INTRMASK %x\n", val);
770 05b4ff43 ths
        break;
771 05b4ff43 ths
    case GT_PCI0_ICMASK:
772 05b4ff43 ths
        val = s->regs[saddr];
773 05b4ff43 ths
        dprintf("ICMASK %x\n", val);
774 05b4ff43 ths
        break;
775 05b4ff43 ths
    case GT_PCI0_SERR0MASK:
776 05b4ff43 ths
        val = s->regs[saddr];
777 05b4ff43 ths
        dprintf("SERR0MASK %x\n", val);
778 05b4ff43 ths
        break;
779 05b4ff43 ths
780 05b4ff43 ths
    /* Reserved when only PCI_0 is configured. */
781 05b4ff43 ths
    case GT_HINTRCAUSE:
782 05b4ff43 ths
    case GT_CPU_INTSEL:
783 05b4ff43 ths
    case GT_PCI0_INTSEL:
784 05b4ff43 ths
    case GT_HINTRMASK:
785 05b4ff43 ths
    case GT_PCI0_HICMASK:
786 05b4ff43 ths
    case GT_PCI1_SERR1MASK:
787 05b4ff43 ths
        val = s->regs[saddr];
788 fde7d5bd ths
        break;
789 fde7d5bd ths
790 fde7d5bd ths
    default:
791 fde7d5bd ths
        val = s->regs[saddr];
792 05b4ff43 ths
        dprintf ("Bad register offset 0x%x\n", (int)addr);
793 fde7d5bd ths
        break;
794 fde7d5bd ths
    }
795 fde7d5bd ths
796 0da75eb1 ths
#ifdef TARGET_WORDS_BIGENDIAN
797 05b4ff43 ths
    val = bswap32(val);
798 0da75eb1 ths
#endif
799 05b4ff43 ths
    return val;
800 fde7d5bd ths
}
801 fde7d5bd ths
802 fde7d5bd ths
static CPUWriteMemoryFunc *gt64120_write[] = {
803 fde7d5bd ths
    &gt64120_writel,
804 fde7d5bd ths
    &gt64120_writel,
805 fde7d5bd ths
    &gt64120_writel,
806 fde7d5bd ths
};
807 fde7d5bd ths
808 fde7d5bd ths
static CPUReadMemoryFunc *gt64120_read[] = {
809 fde7d5bd ths
    &gt64120_readl,
810 fde7d5bd ths
    &gt64120_readl,
811 fde7d5bd ths
    &gt64120_readl,
812 fde7d5bd ths
};
813 fde7d5bd ths
814 fde7d5bd ths
static int pci_gt64120_map_irq(PCIDevice *pci_dev, int irq_num)
815 fde7d5bd ths
{
816 fde7d5bd ths
    int slot;
817 fde7d5bd ths
818 fde7d5bd ths
    slot = (pci_dev->devfn >> 3);
819 fde7d5bd ths
820 fde7d5bd ths
    switch (slot) {
821 fde7d5bd ths
      /* PIIX4 USB */
822 fde7d5bd ths
      case 10:
823 fde7d5bd ths
        return 3;
824 fde7d5bd ths
      /* AMD 79C973 Ethernet */
825 fde7d5bd ths
      case 11:
826 d4a4d056 ths
        return 1;
827 fde7d5bd ths
      /* Crystal 4281 Sound */
828 fde7d5bd ths
      case 12:
829 d4a4d056 ths
        return 2;
830 fde7d5bd ths
      /* PCI slot 1 to 4 */
831 fde7d5bd ths
      case 18 ... 21:
832 fde7d5bd ths
        return ((slot - 18) + irq_num) & 0x03;
833 fde7d5bd ths
      /* Unknown device, don't do any translation */
834 fde7d5bd ths
      default:
835 fde7d5bd ths
        return irq_num;
836 fde7d5bd ths
    }
837 fde7d5bd ths
}
838 fde7d5bd ths
839 fde7d5bd ths
extern PCIDevice *piix4_dev;
840 fde7d5bd ths
static int pci_irq_levels[4];
841 fde7d5bd ths
842 d537cf6c pbrook
static void pci_gt64120_set_irq(qemu_irq *pic, int irq_num, int level)
843 fde7d5bd ths
{
844 fde7d5bd ths
    int i, pic_irq, pic_level;
845 fde7d5bd ths
846 fde7d5bd ths
    pci_irq_levels[irq_num] = level;
847 fde7d5bd ths
848 fde7d5bd ths
    /* now we change the pic irq level according to the piix irq mappings */
849 fde7d5bd ths
    /* XXX: optimize */
850 fde7d5bd ths
    pic_irq = piix4_dev->config[0x60 + irq_num];
851 fde7d5bd ths
    if (pic_irq < 16) {
852 fde7d5bd ths
        /* The pic level is the logical OR of all the PCI irqs mapped
853 fde7d5bd ths
           to it */
854 fde7d5bd ths
        pic_level = 0;
855 fde7d5bd ths
        for (i = 0; i < 4; i++) {
856 fde7d5bd ths
            if (pic_irq == piix4_dev->config[0x60 + i])
857 fde7d5bd ths
                pic_level |= pci_irq_levels[i];
858 fde7d5bd ths
        }
859 d537cf6c pbrook
        qemu_set_irq(pic[pic_irq], pic_level);
860 fde7d5bd ths
    }
861 fde7d5bd ths
}
862 fde7d5bd ths
863 fde7d5bd ths
864 fde7d5bd ths
void gt64120_reset(void *opaque)
865 fde7d5bd ths
{
866 fde7d5bd ths
    GT64120State *s = opaque;
867 fde7d5bd ths
868 fde7d5bd ths
    /* CPU Configuration */
869 fde7d5bd ths
#ifdef TARGET_WORDS_BIGENDIAN
870 fde7d5bd ths
    s->regs[GT_CPU]           = 0x00000000;
871 fde7d5bd ths
#else
872 bc687ec9 ths
    s->regs[GT_CPU]           = 0x00001000;
873 fde7d5bd ths
#endif
874 fde7d5bd ths
    s->regs[GT_MULTI]         = 0x00000000;
875 fde7d5bd ths
876 fde7d5bd ths
    /* CPU Address decode FIXME: not complete*/
877 fde7d5bd ths
    s->regs[GT_PCI0IOLD]      = 0x00000080;
878 fde7d5bd ths
    s->regs[GT_PCI0IOHD]      = 0x0000000f;
879 fde7d5bd ths
    s->regs[GT_PCI0M0LD]      = 0x00000090;
880 fde7d5bd ths
    s->regs[GT_PCI0M0HD]      = 0x0000001f;
881 fde7d5bd ths
    s->regs[GT_PCI0M1LD]      = 0x00000790;
882 fde7d5bd ths
    s->regs[GT_PCI0M1HD]      = 0x0000001f;
883 fde7d5bd ths
    s->regs[GT_PCI1IOLD]      = 0x00000100;
884 fde7d5bd ths
    s->regs[GT_PCI1IOHD]      = 0x0000000f;
885 fde7d5bd ths
    s->regs[GT_PCI1M0LD]      = 0x00000110;
886 fde7d5bd ths
    s->regs[GT_PCI1M0HD]      = 0x0000001f;
887 fde7d5bd ths
    s->regs[GT_PCI1M1LD]      = 0x00000120;
888 fde7d5bd ths
    s->regs[GT_PCI1M1HD]      = 0x0000002f;
889 fde7d5bd ths
    s->regs[GT_PCI0IOREMAP]   = 0x00000080;
890 fde7d5bd ths
    s->regs[GT_PCI0M0REMAP]   = 0x00000090;
891 fde7d5bd ths
    s->regs[GT_PCI0M1REMAP]   = 0x00000790;
892 fde7d5bd ths
    s->regs[GT_PCI1IOREMAP]   = 0x00000100;
893 fde7d5bd ths
    s->regs[GT_PCI1M0REMAP]   = 0x00000110;
894 fde7d5bd ths
    s->regs[GT_PCI1M1REMAP]   = 0x00000120;
895 fde7d5bd ths
896 fde7d5bd ths
    /* CPU Error Report */
897 fde7d5bd ths
    s->regs[GT_CPUERR_ADDRLO] = 0x00000000;
898 fde7d5bd ths
    s->regs[GT_CPUERR_ADDRHI] = 0x00000000;
899 fde7d5bd ths
    s->regs[GT_CPUERR_DATALO] = 0xffffffff;
900 fde7d5bd ths
    s->regs[GT_CPUERR_DATAHI] = 0xffffffff;
901 fde7d5bd ths
    s->regs[GT_CPUERR_PARITY] = 0x000000ff;
902 fde7d5bd ths
903 fde7d5bd ths
    /* ECC */
904 fde7d5bd ths
    s->regs[GT_ECC_ERRDATALO] = 0x00000000;
905 fde7d5bd ths
    s->regs[GT_ECC_ERRDATAHI] = 0x00000000;
906 fde7d5bd ths
    s->regs[GT_ECC_MEM]       = 0x00000000;
907 fde7d5bd ths
    s->regs[GT_ECC_CALC]      = 0x00000000;
908 fde7d5bd ths
    s->regs[GT_ECC_ERRADDR]   = 0x00000000;
909 fde7d5bd ths
910 0da75eb1 ths
    /* SDRAM Parameters */
911 0da75eb1 ths
    s->regs[GT_SDRAM_B0]      = 0x00000005;    
912 0da75eb1 ths
    s->regs[GT_SDRAM_B1]      = 0x00000005;    
913 0da75eb1 ths
    s->regs[GT_SDRAM_B2]      = 0x00000005;    
914 0da75eb1 ths
    s->regs[GT_SDRAM_B3]      = 0x00000005;    
915 0da75eb1 ths
916 fde7d5bd ths
    /* PCI Internal FIXME: not complete*/
917 fde7d5bd ths
#ifdef TARGET_WORDS_BIGENDIAN
918 fde7d5bd ths
    s->regs[GT_PCI0_CMD]      = 0x00000000;
919 fde7d5bd ths
    s->regs[GT_PCI1_CMD]      = 0x00000000;
920 fde7d5bd ths
#else
921 fde7d5bd ths
    s->regs[GT_PCI0_CMD]      = 0x00010001;
922 fde7d5bd ths
    s->regs[GT_PCI1_CMD]      = 0x00010001;
923 fde7d5bd ths
#endif
924 fde7d5bd ths
    s->regs[GT_PCI0_IACK]     = 0x00000000;
925 fde7d5bd ths
    s->regs[GT_PCI1_IACK]     = 0x00000000;
926 fde7d5bd ths
927 fde7d5bd ths
    gt64120_pci_mapping(s);
928 fde7d5bd ths
}
929 fde7d5bd ths
930 bc687ec9 ths
static uint32_t gt64120_read_config(PCIDevice *d, uint32_t address, int len)
931 bc687ec9 ths
{
932 bc687ec9 ths
    uint32_t val = pci_default_read_config(d, address, len);
933 bc687ec9 ths
#ifdef TARGET_WORDS_BIGENDIAN
934 bc687ec9 ths
    val = bswap32(val);
935 bc687ec9 ths
#endif
936 bc687ec9 ths
    return val;
937 bc687ec9 ths
}
938 bc687ec9 ths
939 bc687ec9 ths
static void gt64120_write_config(PCIDevice *d, uint32_t address, uint32_t val,
940 bc687ec9 ths
                                 int len)
941 bc687ec9 ths
{
942 bc687ec9 ths
#ifdef TARGET_WORDS_BIGENDIAN
943 bc687ec9 ths
    val = bswap32(val);
944 bc687ec9 ths
#endif
945 bc687ec9 ths
    pci_default_write_config(d, address, val, len);
946 bc687ec9 ths
}
947 bc687ec9 ths
948 d537cf6c pbrook
PCIBus *pci_gt64120_init(qemu_irq *pic)
949 fde7d5bd ths
{
950 fde7d5bd ths
    GT64120State *s;
951 fde7d5bd ths
    PCIDevice *d;
952 fde7d5bd ths
    int gt64120;
953 fde7d5bd ths
954 fde7d5bd ths
    s = qemu_mallocz(sizeof(GT64120State));
955 fde7d5bd ths
    s->pci = qemu_mallocz(sizeof(GT64120PCIState));
956 fde7d5bd ths
    gt64120_reset(s);
957 fde7d5bd ths
958 fde7d5bd ths
    s->pci->bus = pci_register_bus(pci_gt64120_set_irq, pci_gt64120_map_irq,
959 fde7d5bd ths
                                   pic, 144, 4);
960 fde7d5bd ths
961 fde7d5bd ths
    gt64120 = cpu_register_io_memory(0, gt64120_read,
962 fde7d5bd ths
                                     gt64120_write, s);
963 fde7d5bd ths
    cpu_register_physical_memory(0x1be00000LL, 0x1000, gt64120);
964 fde7d5bd ths
965 fde7d5bd ths
    d = pci_register_device(s->pci->bus, "GT64120 PCI Bus", sizeof(PCIDevice),
966 bc687ec9 ths
                            0, gt64120_read_config, gt64120_write_config);
967 fde7d5bd ths
968 fde7d5bd ths
    d->config[0x00] = 0xab; // vendor_id
969 fde7d5bd ths
    d->config[0x01] = 0x11;
970 bc687ec9 ths
    d->config[0x02] = 0x20; // device_id
971 bc687ec9 ths
    d->config[0x03] = 0x46;
972 fde7d5bd ths
    d->config[0x04] = 0x06;
973 fde7d5bd ths
    d->config[0x05] = 0x00;
974 fde7d5bd ths
    d->config[0x06] = 0x80;
975 fde7d5bd ths
    d->config[0x07] = 0xa2;
976 fde7d5bd ths
    d->config[0x08] = 0x10;
977 fde7d5bd ths
    d->config[0x09] = 0x00;
978 fde7d5bd ths
    d->config[0x0A] = 0x80;
979 fde7d5bd ths
    d->config[0x0B] = 0x05;
980 fde7d5bd ths
    d->config[0x0C] = 0x08;
981 fde7d5bd ths
    d->config[0x0D] = 0x40;
982 fde7d5bd ths
    d->config[0x0E] = 0x00;
983 fde7d5bd ths
    d->config[0x0F] = 0x00;
984 fde7d5bd ths
    d->config[0x17] = 0x08;
985 fde7d5bd ths
    d->config[0x1B] = 0x1c;
986 fde7d5bd ths
    d->config[0x1F] = 0x1f;
987 fde7d5bd ths
    d->config[0x23] = 0x14;
988 fde7d5bd ths
    d->config[0x27] = 0x14;
989 fde7d5bd ths
    d->config[0x3D] = 0x01;
990 fde7d5bd ths
991 fde7d5bd ths
    return s->pci->bus;
992 fde7d5bd ths
}