1a7db759eSPhilippe Mathieu-Daudé /*
2a7db759eSPhilippe Mathieu-Daudé * QEMU GT64120 PCI host
3a7db759eSPhilippe Mathieu-Daudé *
450a24291SPhilippe Mathieu-Daudé * (Datasheet GT-64120 Rev 1.4 from Sep 14, 1999)
550a24291SPhilippe Mathieu-Daudé *
6a7db759eSPhilippe Mathieu-Daudé * Copyright (c) 2006,2007 Aurelien Jarno
7a7db759eSPhilippe Mathieu-Daudé *
8a7db759eSPhilippe Mathieu-Daudé * Permission is hereby granted, free of charge, to any person obtaining a copy
9a7db759eSPhilippe Mathieu-Daudé * of this software and associated documentation files (the "Software"), to deal
10a7db759eSPhilippe Mathieu-Daudé * in the Software without restriction, including without limitation the rights
11a7db759eSPhilippe Mathieu-Daudé * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12a7db759eSPhilippe Mathieu-Daudé * copies of the Software, and to permit persons to whom the Software is
13a7db759eSPhilippe Mathieu-Daudé * furnished to do so, subject to the following conditions:
14a7db759eSPhilippe Mathieu-Daudé *
15a7db759eSPhilippe Mathieu-Daudé * The above copyright notice and this permission notice shall be included in
16a7db759eSPhilippe Mathieu-Daudé * all copies or substantial portions of the Software.
17a7db759eSPhilippe Mathieu-Daudé *
18a7db759eSPhilippe Mathieu-Daudé * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19a7db759eSPhilippe Mathieu-Daudé * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20a7db759eSPhilippe Mathieu-Daudé * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21a7db759eSPhilippe Mathieu-Daudé * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22a7db759eSPhilippe Mathieu-Daudé * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23a7db759eSPhilippe Mathieu-Daudé * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24a7db759eSPhilippe Mathieu-Daudé * THE SOFTWARE.
25a7db759eSPhilippe Mathieu-Daudé */
26a7db759eSPhilippe Mathieu-Daudé
27a7db759eSPhilippe Mathieu-Daudé #include "qemu/osdep.h"
28a7db759eSPhilippe Mathieu-Daudé #include "qapi/error.h"
29a7db759eSPhilippe Mathieu-Daudé #include "qemu/units.h"
30a7db759eSPhilippe Mathieu-Daudé #include "qemu/log.h"
31a7db759eSPhilippe Mathieu-Daudé #include "hw/qdev-properties.h"
32a7db759eSPhilippe Mathieu-Daudé #include "hw/registerfields.h"
33a7db759eSPhilippe Mathieu-Daudé #include "hw/pci/pci_device.h"
34a7db759eSPhilippe Mathieu-Daudé #include "hw/pci/pci_host.h"
35a7db759eSPhilippe Mathieu-Daudé #include "hw/misc/empty_slot.h"
36a7db759eSPhilippe Mathieu-Daudé #include "migration/vmstate.h"
37a7db759eSPhilippe Mathieu-Daudé #include "hw/intc/i8259.h"
38a7db759eSPhilippe Mathieu-Daudé #include "hw/irq.h"
39a7db759eSPhilippe Mathieu-Daudé #include "trace.h"
40a7db759eSPhilippe Mathieu-Daudé #include "qom/object.h"
41a7db759eSPhilippe Mathieu-Daudé
42a7db759eSPhilippe Mathieu-Daudé #define GT_REGS (0x1000 >> 2)
43a7db759eSPhilippe Mathieu-Daudé
44a7db759eSPhilippe Mathieu-Daudé /* CPU Configuration */
45a7db759eSPhilippe Mathieu-Daudé #define GT_CPU (0x000 >> 2)
46a7db759eSPhilippe Mathieu-Daudé #define GT_MULTI (0x120 >> 2)
47a7db759eSPhilippe Mathieu-Daudé
48a7db759eSPhilippe Mathieu-Daudé REG32(GT_CPU, 0x000)
49a7db759eSPhilippe Mathieu-Daudé FIELD(GT_CPU, Endianness, 12, 1)
50a7db759eSPhilippe Mathieu-Daudé
51a7db759eSPhilippe Mathieu-Daudé /* CPU Address Decode */
52a7db759eSPhilippe Mathieu-Daudé #define GT_SCS10LD (0x008 >> 2)
53a7db759eSPhilippe Mathieu-Daudé #define GT_SCS10HD (0x010 >> 2)
54a7db759eSPhilippe Mathieu-Daudé #define GT_SCS32LD (0x018 >> 2)
55a7db759eSPhilippe Mathieu-Daudé #define GT_SCS32HD (0x020 >> 2)
56a7db759eSPhilippe Mathieu-Daudé #define GT_CS20LD (0x028 >> 2)
57a7db759eSPhilippe Mathieu-Daudé #define GT_CS20HD (0x030 >> 2)
58a7db759eSPhilippe Mathieu-Daudé #define GT_CS3BOOTLD (0x038 >> 2)
59a7db759eSPhilippe Mathieu-Daudé #define GT_CS3BOOTHD (0x040 >> 2)
60a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0IOLD (0x048 >> 2)
61a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0IOHD (0x050 >> 2)
62a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0M0LD (0x058 >> 2)
63a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0M0HD (0x060 >> 2)
64a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0M1LD (0x080 >> 2)
65a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0M1HD (0x088 >> 2)
66a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1IOLD (0x090 >> 2)
67a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1IOHD (0x098 >> 2)
68a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1M0LD (0x0a0 >> 2)
69a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1M0HD (0x0a8 >> 2)
70a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1M1LD (0x0b0 >> 2)
71a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1M1HD (0x0b8 >> 2)
72a7db759eSPhilippe Mathieu-Daudé #define GT_ISD (0x068 >> 2)
73a7db759eSPhilippe Mathieu-Daudé
74a7db759eSPhilippe Mathieu-Daudé #define GT_SCS10AR (0x0d0 >> 2)
75a7db759eSPhilippe Mathieu-Daudé #define GT_SCS32AR (0x0d8 >> 2)
76a7db759eSPhilippe Mathieu-Daudé #define GT_CS20R (0x0e0 >> 2)
77a7db759eSPhilippe Mathieu-Daudé #define GT_CS3BOOTR (0x0e8 >> 2)
78a7db759eSPhilippe Mathieu-Daudé
79a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0IOREMAP (0x0f0 >> 2)
80a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0M0REMAP (0x0f8 >> 2)
81a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0M1REMAP (0x100 >> 2)
82a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1IOREMAP (0x108 >> 2)
83a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1M0REMAP (0x110 >> 2)
84a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1M1REMAP (0x118 >> 2)
85a7db759eSPhilippe Mathieu-Daudé
86a7db759eSPhilippe Mathieu-Daudé /* CPU Error Report */
87a7db759eSPhilippe Mathieu-Daudé #define GT_CPUERR_ADDRLO (0x070 >> 2)
88a7db759eSPhilippe Mathieu-Daudé #define GT_CPUERR_ADDRHI (0x078 >> 2)
89a7db759eSPhilippe Mathieu-Daudé #define GT_CPUERR_DATALO (0x128 >> 2) /* GT-64120A only */
90a7db759eSPhilippe Mathieu-Daudé #define GT_CPUERR_DATAHI (0x130 >> 2) /* GT-64120A only */
91a7db759eSPhilippe Mathieu-Daudé #define GT_CPUERR_PARITY (0x138 >> 2) /* GT-64120A only */
92a7db759eSPhilippe Mathieu-Daudé
93a7db759eSPhilippe Mathieu-Daudé /* CPU Sync Barrier */
94a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0SYNC (0x0c0 >> 2)
95a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1SYNC (0x0c8 >> 2)
96a7db759eSPhilippe Mathieu-Daudé
97a7db759eSPhilippe Mathieu-Daudé /* SDRAM and Device Address Decode */
98a7db759eSPhilippe Mathieu-Daudé #define GT_SCS0LD (0x400 >> 2)
99a7db759eSPhilippe Mathieu-Daudé #define GT_SCS0HD (0x404 >> 2)
100a7db759eSPhilippe Mathieu-Daudé #define GT_SCS1LD (0x408 >> 2)
101a7db759eSPhilippe Mathieu-Daudé #define GT_SCS1HD (0x40c >> 2)
102a7db759eSPhilippe Mathieu-Daudé #define GT_SCS2LD (0x410 >> 2)
103a7db759eSPhilippe Mathieu-Daudé #define GT_SCS2HD (0x414 >> 2)
104a7db759eSPhilippe Mathieu-Daudé #define GT_SCS3LD (0x418 >> 2)
105a7db759eSPhilippe Mathieu-Daudé #define GT_SCS3HD (0x41c >> 2)
106a7db759eSPhilippe Mathieu-Daudé #define GT_CS0LD (0x420 >> 2)
107a7db759eSPhilippe Mathieu-Daudé #define GT_CS0HD (0x424 >> 2)
108a7db759eSPhilippe Mathieu-Daudé #define GT_CS1LD (0x428 >> 2)
109a7db759eSPhilippe Mathieu-Daudé #define GT_CS1HD (0x42c >> 2)
110a7db759eSPhilippe Mathieu-Daudé #define GT_CS2LD (0x430 >> 2)
111a7db759eSPhilippe Mathieu-Daudé #define GT_CS2HD (0x434 >> 2)
112a7db759eSPhilippe Mathieu-Daudé #define GT_CS3LD (0x438 >> 2)
113a7db759eSPhilippe Mathieu-Daudé #define GT_CS3HD (0x43c >> 2)
114a7db759eSPhilippe Mathieu-Daudé #define GT_BOOTLD (0x440 >> 2)
115a7db759eSPhilippe Mathieu-Daudé #define GT_BOOTHD (0x444 >> 2)
116a7db759eSPhilippe Mathieu-Daudé #define GT_ADERR (0x470 >> 2)
117a7db759eSPhilippe Mathieu-Daudé
118a7db759eSPhilippe Mathieu-Daudé /* SDRAM Configuration */
119a7db759eSPhilippe Mathieu-Daudé #define GT_SDRAM_CFG (0x448 >> 2)
120a7db759eSPhilippe Mathieu-Daudé #define GT_SDRAM_OPMODE (0x474 >> 2)
121a7db759eSPhilippe Mathieu-Daudé #define GT_SDRAM_BM (0x478 >> 2)
122a7db759eSPhilippe Mathieu-Daudé #define GT_SDRAM_ADDRDECODE (0x47c >> 2)
123a7db759eSPhilippe Mathieu-Daudé
124a7db759eSPhilippe Mathieu-Daudé /* SDRAM Parameters */
125a7db759eSPhilippe Mathieu-Daudé #define GT_SDRAM_B0 (0x44c >> 2)
126a7db759eSPhilippe Mathieu-Daudé #define GT_SDRAM_B1 (0x450 >> 2)
127a7db759eSPhilippe Mathieu-Daudé #define GT_SDRAM_B2 (0x454 >> 2)
128a7db759eSPhilippe Mathieu-Daudé #define GT_SDRAM_B3 (0x458 >> 2)
129a7db759eSPhilippe Mathieu-Daudé
130a7db759eSPhilippe Mathieu-Daudé /* Device Parameters */
131a7db759eSPhilippe Mathieu-Daudé #define GT_DEV_B0 (0x45c >> 2)
132a7db759eSPhilippe Mathieu-Daudé #define GT_DEV_B1 (0x460 >> 2)
133a7db759eSPhilippe Mathieu-Daudé #define GT_DEV_B2 (0x464 >> 2)
134a7db759eSPhilippe Mathieu-Daudé #define GT_DEV_B3 (0x468 >> 2)
135a7db759eSPhilippe Mathieu-Daudé #define GT_DEV_BOOT (0x46c >> 2)
136a7db759eSPhilippe Mathieu-Daudé
137a7db759eSPhilippe Mathieu-Daudé /* ECC */
138a7db759eSPhilippe Mathieu-Daudé #define GT_ECC_ERRDATALO (0x480 >> 2) /* GT-64120A only */
139a7db759eSPhilippe Mathieu-Daudé #define GT_ECC_ERRDATAHI (0x484 >> 2) /* GT-64120A only */
140a7db759eSPhilippe Mathieu-Daudé #define GT_ECC_MEM (0x488 >> 2) /* GT-64120A only */
141a7db759eSPhilippe Mathieu-Daudé #define GT_ECC_CALC (0x48c >> 2) /* GT-64120A only */
142a7db759eSPhilippe Mathieu-Daudé #define GT_ECC_ERRADDR (0x490 >> 2) /* GT-64120A only */
143a7db759eSPhilippe Mathieu-Daudé
144a7db759eSPhilippe Mathieu-Daudé /* DMA Record */
145a7db759eSPhilippe Mathieu-Daudé #define GT_DMA0_CNT (0x800 >> 2)
146a7db759eSPhilippe Mathieu-Daudé #define GT_DMA1_CNT (0x804 >> 2)
147a7db759eSPhilippe Mathieu-Daudé #define GT_DMA2_CNT (0x808 >> 2)
148a7db759eSPhilippe Mathieu-Daudé #define GT_DMA3_CNT (0x80c >> 2)
149a7db759eSPhilippe Mathieu-Daudé #define GT_DMA0_SA (0x810 >> 2)
150a7db759eSPhilippe Mathieu-Daudé #define GT_DMA1_SA (0x814 >> 2)
151a7db759eSPhilippe Mathieu-Daudé #define GT_DMA2_SA (0x818 >> 2)
152a7db759eSPhilippe Mathieu-Daudé #define GT_DMA3_SA (0x81c >> 2)
153a7db759eSPhilippe Mathieu-Daudé #define GT_DMA0_DA (0x820 >> 2)
154a7db759eSPhilippe Mathieu-Daudé #define GT_DMA1_DA (0x824 >> 2)
155a7db759eSPhilippe Mathieu-Daudé #define GT_DMA2_DA (0x828 >> 2)
156a7db759eSPhilippe Mathieu-Daudé #define GT_DMA3_DA (0x82c >> 2)
157a7db759eSPhilippe Mathieu-Daudé #define GT_DMA0_NEXT (0x830 >> 2)
158a7db759eSPhilippe Mathieu-Daudé #define GT_DMA1_NEXT (0x834 >> 2)
159a7db759eSPhilippe Mathieu-Daudé #define GT_DMA2_NEXT (0x838 >> 2)
160a7db759eSPhilippe Mathieu-Daudé #define GT_DMA3_NEXT (0x83c >> 2)
161a7db759eSPhilippe Mathieu-Daudé #define GT_DMA0_CUR (0x870 >> 2)
162a7db759eSPhilippe Mathieu-Daudé #define GT_DMA1_CUR (0x874 >> 2)
163a7db759eSPhilippe Mathieu-Daudé #define GT_DMA2_CUR (0x878 >> 2)
164a7db759eSPhilippe Mathieu-Daudé #define GT_DMA3_CUR (0x87c >> 2)
165a7db759eSPhilippe Mathieu-Daudé
166a7db759eSPhilippe Mathieu-Daudé /* DMA Channel Control */
167a7db759eSPhilippe Mathieu-Daudé #define GT_DMA0_CTRL (0x840 >> 2)
168a7db759eSPhilippe Mathieu-Daudé #define GT_DMA1_CTRL (0x844 >> 2)
169a7db759eSPhilippe Mathieu-Daudé #define GT_DMA2_CTRL (0x848 >> 2)
170a7db759eSPhilippe Mathieu-Daudé #define GT_DMA3_CTRL (0x84c >> 2)
171a7db759eSPhilippe Mathieu-Daudé
172a7db759eSPhilippe Mathieu-Daudé /* DMA Arbiter */
173a7db759eSPhilippe Mathieu-Daudé #define GT_DMA_ARB (0x860 >> 2)
174a7db759eSPhilippe Mathieu-Daudé
175a7db759eSPhilippe Mathieu-Daudé /* Timer/Counter */
176a7db759eSPhilippe Mathieu-Daudé #define GT_TC0 (0x850 >> 2)
177a7db759eSPhilippe Mathieu-Daudé #define GT_TC1 (0x854 >> 2)
178a7db759eSPhilippe Mathieu-Daudé #define GT_TC2 (0x858 >> 2)
179a7db759eSPhilippe Mathieu-Daudé #define GT_TC3 (0x85c >> 2)
180a7db759eSPhilippe Mathieu-Daudé #define GT_TC_CONTROL (0x864 >> 2)
181a7db759eSPhilippe Mathieu-Daudé
182a7db759eSPhilippe Mathieu-Daudé /* PCI Internal */
183a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_CMD (0xc00 >> 2)
184a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_TOR (0xc04 >> 2)
185a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_BS_SCS10 (0xc08 >> 2)
186a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_BS_SCS32 (0xc0c >> 2)
187a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_BS_CS20 (0xc10 >> 2)
188a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_BS_CS3BT (0xc14 >> 2)
189a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_IACK (0xc30 >> 2)
190a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_IACK (0xc34 >> 2)
191a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_BARE (0xc3c >> 2)
192a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_PREFMBR (0xc40 >> 2)
193a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_SCS10_BAR (0xc48 >> 2)
194a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_SCS32_BAR (0xc4c >> 2)
195a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_CS20_BAR (0xc50 >> 2)
196a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_CS3BT_BAR (0xc54 >> 2)
197a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_SSCS10_BAR (0xc58 >> 2)
198a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_SSCS32_BAR (0xc5c >> 2)
199a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_SCS3BT_BAR (0xc64 >> 2)
200a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_CMD (0xc80 >> 2)
201a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_TOR (0xc84 >> 2)
202a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_BS_SCS10 (0xc88 >> 2)
203a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_BS_SCS32 (0xc8c >> 2)
204a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_BS_CS20 (0xc90 >> 2)
205a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_BS_CS3BT (0xc94 >> 2)
206a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_BARE (0xcbc >> 2)
207a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_PREFMBR (0xcc0 >> 2)
208a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_SCS10_BAR (0xcc8 >> 2)
209a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_SCS32_BAR (0xccc >> 2)
210a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_CS20_BAR (0xcd0 >> 2)
211a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_CS3BT_BAR (0xcd4 >> 2)
212a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_SSCS10_BAR (0xcd8 >> 2)
213a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_SSCS32_BAR (0xcdc >> 2)
214a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_SCS3BT_BAR (0xce4 >> 2)
215a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_CFGADDR (0xcf0 >> 2)
216a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_CFGDATA (0xcf4 >> 2)
217a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_CFGADDR (0xcf8 >> 2)
218a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_CFGDATA (0xcfc >> 2)
219a7db759eSPhilippe Mathieu-Daudé
220a7db759eSPhilippe Mathieu-Daudé REG32(GT_PCI0_CMD, 0xc00)
221a7db759eSPhilippe Mathieu-Daudé FIELD(GT_PCI0_CMD, MByteSwap, 0, 1)
222a7db759eSPhilippe Mathieu-Daudé FIELD(GT_PCI0_CMD, SByteSwap, 16, 1)
223a7db759eSPhilippe Mathieu-Daudé #define R_GT_PCI0_CMD_ByteSwap_MASK \
224a7db759eSPhilippe Mathieu-Daudé (R_GT_PCI0_CMD_MByteSwap_MASK | R_GT_PCI0_CMD_SByteSwap_MASK)
225a7db759eSPhilippe Mathieu-Daudé REG32(GT_PCI1_CMD, 0xc80)
226a7db759eSPhilippe Mathieu-Daudé FIELD(GT_PCI1_CMD, MByteSwap, 0, 1)
227a7db759eSPhilippe Mathieu-Daudé FIELD(GT_PCI1_CMD, SByteSwap, 16, 1)
228a7db759eSPhilippe Mathieu-Daudé #define R_GT_PCI1_CMD_ByteSwap_MASK \
229a7db759eSPhilippe Mathieu-Daudé (R_GT_PCI1_CMD_MByteSwap_MASK | R_GT_PCI1_CMD_SByteSwap_MASK)
230a7db759eSPhilippe Mathieu-Daudé
231a7db759eSPhilippe Mathieu-Daudé /* Interrupts */
232a7db759eSPhilippe Mathieu-Daudé #define GT_INTRCAUSE (0xc18 >> 2)
233a7db759eSPhilippe Mathieu-Daudé #define GT_INTRMASK (0xc1c >> 2)
234a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_ICMASK (0xc24 >> 2)
235a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_SERR0MASK (0xc28 >> 2)
236a7db759eSPhilippe Mathieu-Daudé #define GT_CPU_INTSEL (0xc70 >> 2)
237a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_INTSEL (0xc74 >> 2)
238a7db759eSPhilippe Mathieu-Daudé #define GT_HINTRCAUSE (0xc98 >> 2)
239a7db759eSPhilippe Mathieu-Daudé #define GT_HINTRMASK (0xc9c >> 2)
240a7db759eSPhilippe Mathieu-Daudé #define GT_PCI0_HICMASK (0xca4 >> 2)
241a7db759eSPhilippe Mathieu-Daudé #define GT_PCI1_SERR1MASK (0xca8 >> 2)
242a7db759eSPhilippe Mathieu-Daudé
243a7db759eSPhilippe Mathieu-Daudé #define PCI_MAPPING_ENTRY(regname) \
244a7db759eSPhilippe Mathieu-Daudé hwaddr regname ##_start; \
245a7db759eSPhilippe Mathieu-Daudé hwaddr regname ##_length; \
246a7db759eSPhilippe Mathieu-Daudé MemoryRegion regname ##_mem
247a7db759eSPhilippe Mathieu-Daudé
248a7db759eSPhilippe Mathieu-Daudé #define TYPE_GT64120_PCI_HOST_BRIDGE "gt64120"
249a7db759eSPhilippe Mathieu-Daudé
250a7db759eSPhilippe Mathieu-Daudé OBJECT_DECLARE_SIMPLE_TYPE(GT64120State, GT64120_PCI_HOST_BRIDGE)
251a7db759eSPhilippe Mathieu-Daudé
252a7db759eSPhilippe Mathieu-Daudé struct GT64120State {
253a7db759eSPhilippe Mathieu-Daudé PCIHostState parent_obj;
254a7db759eSPhilippe Mathieu-Daudé
255a7db759eSPhilippe Mathieu-Daudé uint32_t regs[GT_REGS];
256a7db759eSPhilippe Mathieu-Daudé PCI_MAPPING_ENTRY(PCI0IO);
257a7db759eSPhilippe Mathieu-Daudé PCI_MAPPING_ENTRY(PCI0M0);
258a7db759eSPhilippe Mathieu-Daudé PCI_MAPPING_ENTRY(PCI0M1);
259a7db759eSPhilippe Mathieu-Daudé PCI_MAPPING_ENTRY(ISD);
260a7db759eSPhilippe Mathieu-Daudé MemoryRegion pci0_mem;
261a7db759eSPhilippe Mathieu-Daudé AddressSpace pci0_mem_as;
262a7db759eSPhilippe Mathieu-Daudé
263a7db759eSPhilippe Mathieu-Daudé /* properties */
264a7db759eSPhilippe Mathieu-Daudé bool cpu_little_endian;
265a7db759eSPhilippe Mathieu-Daudé };
266a7db759eSPhilippe Mathieu-Daudé
267a7db759eSPhilippe Mathieu-Daudé /* Adjust range to avoid touching space which isn't mappable via PCI */
268a7db759eSPhilippe Mathieu-Daudé /*
269a7db759eSPhilippe Mathieu-Daudé * XXX: Hardcoded values for Malta: 0x1e000000 - 0x1f100000
270a7db759eSPhilippe Mathieu-Daudé * 0x1fc00000 - 0x1fd00000
271a7db759eSPhilippe Mathieu-Daudé */
check_reserved_space(hwaddr * start,hwaddr * length)272a7db759eSPhilippe Mathieu-Daudé static void check_reserved_space(hwaddr *start, hwaddr *length)
273a7db759eSPhilippe Mathieu-Daudé {
274a7db759eSPhilippe Mathieu-Daudé hwaddr begin = *start;
275a7db759eSPhilippe Mathieu-Daudé hwaddr end = *start + *length;
276a7db759eSPhilippe Mathieu-Daudé
277a7db759eSPhilippe Mathieu-Daudé if (end >= 0x1e000000LL && end < 0x1f100000LL) {
278a7db759eSPhilippe Mathieu-Daudé end = 0x1e000000LL;
279a7db759eSPhilippe Mathieu-Daudé }
280a7db759eSPhilippe Mathieu-Daudé if (begin >= 0x1e000000LL && begin < 0x1f100000LL) {
281a7db759eSPhilippe Mathieu-Daudé begin = 0x1f100000LL;
282a7db759eSPhilippe Mathieu-Daudé }
283a7db759eSPhilippe Mathieu-Daudé if (end >= 0x1fc00000LL && end < 0x1fd00000LL) {
284a7db759eSPhilippe Mathieu-Daudé end = 0x1fc00000LL;
285a7db759eSPhilippe Mathieu-Daudé }
286a7db759eSPhilippe Mathieu-Daudé if (begin >= 0x1fc00000LL && begin < 0x1fd00000LL) {
287a7db759eSPhilippe Mathieu-Daudé begin = 0x1fd00000LL;
288a7db759eSPhilippe Mathieu-Daudé }
289a7db759eSPhilippe Mathieu-Daudé /* XXX: This is broken when a reserved range splits the requested range */
290a7db759eSPhilippe Mathieu-Daudé if (end >= 0x1f100000LL && begin < 0x1e000000LL) {
291a7db759eSPhilippe Mathieu-Daudé end = 0x1e000000LL;
292a7db759eSPhilippe Mathieu-Daudé }
293a7db759eSPhilippe Mathieu-Daudé if (end >= 0x1fd00000LL && begin < 0x1fc00000LL) {
294a7db759eSPhilippe Mathieu-Daudé end = 0x1fc00000LL;
295a7db759eSPhilippe Mathieu-Daudé }
296a7db759eSPhilippe Mathieu-Daudé
297a7db759eSPhilippe Mathieu-Daudé *start = begin;
298a7db759eSPhilippe Mathieu-Daudé *length = end - begin;
299a7db759eSPhilippe Mathieu-Daudé }
300a7db759eSPhilippe Mathieu-Daudé
gt64120_isd_mapping(GT64120State * s)301a7db759eSPhilippe Mathieu-Daudé static void gt64120_isd_mapping(GT64120State *s)
302a7db759eSPhilippe Mathieu-Daudé {
303a7db759eSPhilippe Mathieu-Daudé /* Bits 14:0 of ISD map to bits 35:21 of the start address. */
304a7db759eSPhilippe Mathieu-Daudé hwaddr start = ((hwaddr)s->regs[GT_ISD] << 21) & 0xFFFE00000ull;
305a7db759eSPhilippe Mathieu-Daudé hwaddr length = 0x1000;
306a7db759eSPhilippe Mathieu-Daudé
307a7db759eSPhilippe Mathieu-Daudé memory_region_transaction_begin();
308a7db759eSPhilippe Mathieu-Daudé
309a7db759eSPhilippe Mathieu-Daudé if (s->ISD_length) {
310a7db759eSPhilippe Mathieu-Daudé memory_region_del_subregion(get_system_memory(), &s->ISD_mem);
311a7db759eSPhilippe Mathieu-Daudé }
312a7db759eSPhilippe Mathieu-Daudé check_reserved_space(&start, &length);
313a7db759eSPhilippe Mathieu-Daudé length = 0x1000;
314a7db759eSPhilippe Mathieu-Daudé /* Map new address */
315a7db759eSPhilippe Mathieu-Daudé trace_gt64120_isd_remap(s->ISD_length, s->ISD_start, length, start);
316a7db759eSPhilippe Mathieu-Daudé s->ISD_start = start;
317a7db759eSPhilippe Mathieu-Daudé s->ISD_length = length;
318a7db759eSPhilippe Mathieu-Daudé memory_region_add_subregion(get_system_memory(), s->ISD_start, &s->ISD_mem);
319a7db759eSPhilippe Mathieu-Daudé
320a7db759eSPhilippe Mathieu-Daudé memory_region_transaction_commit();
321a7db759eSPhilippe Mathieu-Daudé }
322a7db759eSPhilippe Mathieu-Daudé
gt64120_update_pci_cfgdata_mapping(GT64120State * s)323a7db759eSPhilippe Mathieu-Daudé static void gt64120_update_pci_cfgdata_mapping(GT64120State *s)
324a7db759eSPhilippe Mathieu-Daudé {
325a7db759eSPhilippe Mathieu-Daudé /* Indexed on MByteSwap bit, see Table 158: PCI_0 Command, Offset: 0xc00 */
326a7db759eSPhilippe Mathieu-Daudé static const MemoryRegionOps *pci_host_data_ops[] = {
327a7db759eSPhilippe Mathieu-Daudé &pci_host_data_be_ops, &pci_host_data_le_ops
328a7db759eSPhilippe Mathieu-Daudé };
329a7db759eSPhilippe Mathieu-Daudé PCIHostState *phb = PCI_HOST_BRIDGE(s);
330a7db759eSPhilippe Mathieu-Daudé
331a7db759eSPhilippe Mathieu-Daudé memory_region_transaction_begin();
332a7db759eSPhilippe Mathieu-Daudé
333a7db759eSPhilippe Mathieu-Daudé /*
334a7db759eSPhilippe Mathieu-Daudé * The setting of the MByteSwap bit and MWordSwap bit in the PCI Internal
335a7db759eSPhilippe Mathieu-Daudé * Command Register determines how data transactions from the CPU to/from
336f1c0cff8SMichael Tokarev * PCI are handled along with the setting of the Endianness bit in the CPU
337a7db759eSPhilippe Mathieu-Daudé * Configuration Register. See:
338f1c0cff8SMichael Tokarev * - Table 16: 32-bit PCI Transaction Endianness
339a7db759eSPhilippe Mathieu-Daudé * - Table 158: PCI_0 Command, Offset: 0xc00
340a7db759eSPhilippe Mathieu-Daudé */
341a7db759eSPhilippe Mathieu-Daudé
342a7db759eSPhilippe Mathieu-Daudé if (memory_region_is_mapped(&phb->data_mem)) {
343a7db759eSPhilippe Mathieu-Daudé memory_region_del_subregion(&s->ISD_mem, &phb->data_mem);
344a7db759eSPhilippe Mathieu-Daudé object_unparent(OBJECT(&phb->data_mem));
345a7db759eSPhilippe Mathieu-Daudé }
346a7db759eSPhilippe Mathieu-Daudé memory_region_init_io(&phb->data_mem, OBJECT(phb),
347a7db759eSPhilippe Mathieu-Daudé pci_host_data_ops[s->regs[GT_PCI0_CMD] & 1],
348a7db759eSPhilippe Mathieu-Daudé s, "pci-conf-data", 4);
349a7db759eSPhilippe Mathieu-Daudé memory_region_add_subregion_overlap(&s->ISD_mem, GT_PCI0_CFGDATA << 2,
350a7db759eSPhilippe Mathieu-Daudé &phb->data_mem, 1);
351a7db759eSPhilippe Mathieu-Daudé
352a7db759eSPhilippe Mathieu-Daudé memory_region_transaction_commit();
353a7db759eSPhilippe Mathieu-Daudé }
354a7db759eSPhilippe Mathieu-Daudé
gt64120_pci_mapping(GT64120State * s)355a7db759eSPhilippe Mathieu-Daudé static void gt64120_pci_mapping(GT64120State *s)
356a7db759eSPhilippe Mathieu-Daudé {
357a7db759eSPhilippe Mathieu-Daudé memory_region_transaction_begin();
358a7db759eSPhilippe Mathieu-Daudé
359a7db759eSPhilippe Mathieu-Daudé /* Update PCI0IO mapping */
360a7db759eSPhilippe Mathieu-Daudé if ((s->regs[GT_PCI0IOLD] & 0x7f) <= s->regs[GT_PCI0IOHD]) {
361a7db759eSPhilippe Mathieu-Daudé /* Unmap old IO address */
362a7db759eSPhilippe Mathieu-Daudé if (s->PCI0IO_length) {
363a7db759eSPhilippe Mathieu-Daudé memory_region_del_subregion(get_system_memory(), &s->PCI0IO_mem);
364a7db759eSPhilippe Mathieu-Daudé object_unparent(OBJECT(&s->PCI0IO_mem));
365a7db759eSPhilippe Mathieu-Daudé }
366a7db759eSPhilippe Mathieu-Daudé /* Map new IO address */
367a7db759eSPhilippe Mathieu-Daudé s->PCI0IO_start = s->regs[GT_PCI0IOLD] << 21;
368a7db759eSPhilippe Mathieu-Daudé s->PCI0IO_length = ((s->regs[GT_PCI0IOHD] + 1) -
369a7db759eSPhilippe Mathieu-Daudé (s->regs[GT_PCI0IOLD] & 0x7f)) << 21;
370a7db759eSPhilippe Mathieu-Daudé if (s->PCI0IO_length) {
371a7db759eSPhilippe Mathieu-Daudé memory_region_init_alias(&s->PCI0IO_mem, OBJECT(s), "pci0-io",
372a7db759eSPhilippe Mathieu-Daudé get_system_io(), 0, s->PCI0IO_length);
373a7db759eSPhilippe Mathieu-Daudé memory_region_add_subregion(get_system_memory(), s->PCI0IO_start,
374a7db759eSPhilippe Mathieu-Daudé &s->PCI0IO_mem);
375a7db759eSPhilippe Mathieu-Daudé }
376a7db759eSPhilippe Mathieu-Daudé }
377a7db759eSPhilippe Mathieu-Daudé
378a7db759eSPhilippe Mathieu-Daudé /* Update PCI0M0 mapping */
379a7db759eSPhilippe Mathieu-Daudé if ((s->regs[GT_PCI0M0LD] & 0x7f) <= s->regs[GT_PCI0M0HD]) {
380a7db759eSPhilippe Mathieu-Daudé /* Unmap old MEM address */
381a7db759eSPhilippe Mathieu-Daudé if (s->PCI0M0_length) {
382a7db759eSPhilippe Mathieu-Daudé memory_region_del_subregion(get_system_memory(), &s->PCI0M0_mem);
383a7db759eSPhilippe Mathieu-Daudé object_unparent(OBJECT(&s->PCI0M0_mem));
384a7db759eSPhilippe Mathieu-Daudé }
385a7db759eSPhilippe Mathieu-Daudé /* Map new mem address */
386a7db759eSPhilippe Mathieu-Daudé s->PCI0M0_start = s->regs[GT_PCI0M0LD] << 21;
387a7db759eSPhilippe Mathieu-Daudé s->PCI0M0_length = ((s->regs[GT_PCI0M0HD] + 1) -
388a7db759eSPhilippe Mathieu-Daudé (s->regs[GT_PCI0M0LD] & 0x7f)) << 21;
389a7db759eSPhilippe Mathieu-Daudé if (s->PCI0M0_length) {
390a7db759eSPhilippe Mathieu-Daudé memory_region_init_alias(&s->PCI0M0_mem, OBJECT(s), "pci0-mem0",
391a7db759eSPhilippe Mathieu-Daudé &s->pci0_mem, s->PCI0M0_start,
392a7db759eSPhilippe Mathieu-Daudé s->PCI0M0_length);
393a7db759eSPhilippe Mathieu-Daudé memory_region_add_subregion(get_system_memory(), s->PCI0M0_start,
394a7db759eSPhilippe Mathieu-Daudé &s->PCI0M0_mem);
395a7db759eSPhilippe Mathieu-Daudé }
396a7db759eSPhilippe Mathieu-Daudé }
397a7db759eSPhilippe Mathieu-Daudé
398a7db759eSPhilippe Mathieu-Daudé /* Update PCI0M1 mapping */
399a7db759eSPhilippe Mathieu-Daudé if ((s->regs[GT_PCI0M1LD] & 0x7f) <= s->regs[GT_PCI0M1HD]) {
400a7db759eSPhilippe Mathieu-Daudé /* Unmap old MEM address */
401a7db759eSPhilippe Mathieu-Daudé if (s->PCI0M1_length) {
402a7db759eSPhilippe Mathieu-Daudé memory_region_del_subregion(get_system_memory(), &s->PCI0M1_mem);
403a7db759eSPhilippe Mathieu-Daudé object_unparent(OBJECT(&s->PCI0M1_mem));
404a7db759eSPhilippe Mathieu-Daudé }
405a7db759eSPhilippe Mathieu-Daudé /* Map new mem address */
406a7db759eSPhilippe Mathieu-Daudé s->PCI0M1_start = s->regs[GT_PCI0M1LD] << 21;
407a7db759eSPhilippe Mathieu-Daudé s->PCI0M1_length = ((s->regs[GT_PCI0M1HD] + 1) -
408a7db759eSPhilippe Mathieu-Daudé (s->regs[GT_PCI0M1LD] & 0x7f)) << 21;
409a7db759eSPhilippe Mathieu-Daudé if (s->PCI0M1_length) {
410a7db759eSPhilippe Mathieu-Daudé memory_region_init_alias(&s->PCI0M1_mem, OBJECT(s), "pci0-mem1",
411a7db759eSPhilippe Mathieu-Daudé &s->pci0_mem, s->PCI0M1_start,
412a7db759eSPhilippe Mathieu-Daudé s->PCI0M1_length);
413a7db759eSPhilippe Mathieu-Daudé memory_region_add_subregion(get_system_memory(), s->PCI0M1_start,
414a7db759eSPhilippe Mathieu-Daudé &s->PCI0M1_mem);
415a7db759eSPhilippe Mathieu-Daudé }
416a7db759eSPhilippe Mathieu-Daudé }
417a7db759eSPhilippe Mathieu-Daudé
418a7db759eSPhilippe Mathieu-Daudé memory_region_transaction_commit();
419a7db759eSPhilippe Mathieu-Daudé }
420a7db759eSPhilippe Mathieu-Daudé
gt64120_post_load(void * opaque,int version_id)421a7db759eSPhilippe Mathieu-Daudé static int gt64120_post_load(void *opaque, int version_id)
422a7db759eSPhilippe Mathieu-Daudé {
423a7db759eSPhilippe Mathieu-Daudé GT64120State *s = opaque;
424a7db759eSPhilippe Mathieu-Daudé
425a7db759eSPhilippe Mathieu-Daudé gt64120_isd_mapping(s);
426a7db759eSPhilippe Mathieu-Daudé gt64120_pci_mapping(s);
427a7db759eSPhilippe Mathieu-Daudé
428a7db759eSPhilippe Mathieu-Daudé return 0;
429a7db759eSPhilippe Mathieu-Daudé }
430a7db759eSPhilippe Mathieu-Daudé
431a7db759eSPhilippe Mathieu-Daudé static const VMStateDescription vmstate_gt64120 = {
432a7db759eSPhilippe Mathieu-Daudé .name = "gt64120",
433a7db759eSPhilippe Mathieu-Daudé .version_id = 1,
434a7db759eSPhilippe Mathieu-Daudé .minimum_version_id = 1,
435a7db759eSPhilippe Mathieu-Daudé .post_load = gt64120_post_load,
436e2bd53a3SRichard Henderson .fields = (const VMStateField[]) {
437a7db759eSPhilippe Mathieu-Daudé VMSTATE_UINT32_ARRAY(regs, GT64120State, GT_REGS),
438a7db759eSPhilippe Mathieu-Daudé VMSTATE_END_OF_LIST()
439a7db759eSPhilippe Mathieu-Daudé }
440a7db759eSPhilippe Mathieu-Daudé };
441a7db759eSPhilippe Mathieu-Daudé
gt64120_writel(void * opaque,hwaddr addr,uint64_t val,unsigned size)442a7db759eSPhilippe Mathieu-Daudé static void gt64120_writel(void *opaque, hwaddr addr,
443a7db759eSPhilippe Mathieu-Daudé uint64_t val, unsigned size)
444a7db759eSPhilippe Mathieu-Daudé {
445a7db759eSPhilippe Mathieu-Daudé GT64120State *s = opaque;
446a7db759eSPhilippe Mathieu-Daudé uint32_t saddr = addr >> 2;
447a7db759eSPhilippe Mathieu-Daudé
448a7db759eSPhilippe Mathieu-Daudé trace_gt64120_write(addr, val);
449a7db759eSPhilippe Mathieu-Daudé if (!(s->regs[GT_CPU] & 0x00001000)) {
450a7db759eSPhilippe Mathieu-Daudé val = bswap32(val);
451a7db759eSPhilippe Mathieu-Daudé }
452a7db759eSPhilippe Mathieu-Daudé
453a7db759eSPhilippe Mathieu-Daudé switch (saddr) {
454a7db759eSPhilippe Mathieu-Daudé
455a7db759eSPhilippe Mathieu-Daudé /* CPU Configuration */
456a7db759eSPhilippe Mathieu-Daudé case GT_CPU:
457a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CPU] = val;
458a7db759eSPhilippe Mathieu-Daudé break;
459a7db759eSPhilippe Mathieu-Daudé case GT_MULTI:
460a7db759eSPhilippe Mathieu-Daudé /* Read-only register as only one GT64xxx is present on the CPU bus */
461a7db759eSPhilippe Mathieu-Daudé break;
462a7db759eSPhilippe Mathieu-Daudé
463a7db759eSPhilippe Mathieu-Daudé /* CPU Address Decode */
464a7db759eSPhilippe Mathieu-Daudé case GT_PCI0IOLD:
465a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0IOLD] = val & 0x00007fff;
466a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0IOREMAP] = val & 0x000007ff;
467a7db759eSPhilippe Mathieu-Daudé gt64120_pci_mapping(s);
468a7db759eSPhilippe Mathieu-Daudé break;
469a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M0LD:
470a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M0LD] = val & 0x00007fff;
471a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M0REMAP] = val & 0x000007ff;
472a7db759eSPhilippe Mathieu-Daudé gt64120_pci_mapping(s);
473a7db759eSPhilippe Mathieu-Daudé break;
474a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M1LD:
475a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M1LD] = val & 0x00007fff;
476a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M1REMAP] = val & 0x000007ff;
477a7db759eSPhilippe Mathieu-Daudé gt64120_pci_mapping(s);
478a7db759eSPhilippe Mathieu-Daudé break;
479a7db759eSPhilippe Mathieu-Daudé case GT_PCI1IOLD:
480a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1IOLD] = val & 0x00007fff;
481a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1IOREMAP] = val & 0x000007ff;
482a7db759eSPhilippe Mathieu-Daudé break;
483a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M0LD:
484a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M0LD] = val & 0x00007fff;
485a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M0REMAP] = val & 0x000007ff;
486a7db759eSPhilippe Mathieu-Daudé break;
487a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M1LD:
488a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M1LD] = val & 0x00007fff;
489a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M1REMAP] = val & 0x000007ff;
490a7db759eSPhilippe Mathieu-Daudé break;
491a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M0HD:
492a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M1HD:
493a7db759eSPhilippe Mathieu-Daudé case GT_PCI0IOHD:
494a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val & 0x0000007f;
495a7db759eSPhilippe Mathieu-Daudé gt64120_pci_mapping(s);
496a7db759eSPhilippe Mathieu-Daudé break;
497a7db759eSPhilippe Mathieu-Daudé case GT_PCI1IOHD:
498a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M0HD:
499a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M1HD:
500a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val & 0x0000007f;
501a7db759eSPhilippe Mathieu-Daudé break;
502a7db759eSPhilippe Mathieu-Daudé case GT_ISD:
503a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val & 0x00007fff;
504a7db759eSPhilippe Mathieu-Daudé gt64120_isd_mapping(s);
505a7db759eSPhilippe Mathieu-Daudé break;
506a7db759eSPhilippe Mathieu-Daudé
507a7db759eSPhilippe Mathieu-Daudé case GT_PCI0IOREMAP:
508a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M0REMAP:
509a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M1REMAP:
510a7db759eSPhilippe Mathieu-Daudé case GT_PCI1IOREMAP:
511a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M0REMAP:
512a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M1REMAP:
513a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val & 0x000007ff;
514a7db759eSPhilippe Mathieu-Daudé break;
515a7db759eSPhilippe Mathieu-Daudé
516a7db759eSPhilippe Mathieu-Daudé /* CPU Error Report */
517a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_ADDRLO:
518a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_ADDRHI:
519a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_DATALO:
520a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_DATAHI:
521a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_PARITY:
522a7db759eSPhilippe Mathieu-Daudé /* Read-only registers, do nothing */
523a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_GUEST_ERROR,
524a7db759eSPhilippe Mathieu-Daudé "gt64120: Read-only register write "
525a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*" PRIx64 "\n",
526a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
527a7db759eSPhilippe Mathieu-Daudé break;
528a7db759eSPhilippe Mathieu-Daudé
529a7db759eSPhilippe Mathieu-Daudé /* CPU Sync Barrier */
530a7db759eSPhilippe Mathieu-Daudé case GT_PCI0SYNC:
531a7db759eSPhilippe Mathieu-Daudé case GT_PCI1SYNC:
532a7db759eSPhilippe Mathieu-Daudé /* Read-only registers, do nothing */
533a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_GUEST_ERROR,
534a7db759eSPhilippe Mathieu-Daudé "gt64120: Read-only register write "
535a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*" PRIx64 "\n",
536a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
537a7db759eSPhilippe Mathieu-Daudé break;
538a7db759eSPhilippe Mathieu-Daudé
539a7db759eSPhilippe Mathieu-Daudé /* SDRAM and Device Address Decode */
540a7db759eSPhilippe Mathieu-Daudé case GT_SCS0LD:
541a7db759eSPhilippe Mathieu-Daudé case GT_SCS0HD:
542a7db759eSPhilippe Mathieu-Daudé case GT_SCS1LD:
543a7db759eSPhilippe Mathieu-Daudé case GT_SCS1HD:
544a7db759eSPhilippe Mathieu-Daudé case GT_SCS2LD:
545a7db759eSPhilippe Mathieu-Daudé case GT_SCS2HD:
546a7db759eSPhilippe Mathieu-Daudé case GT_SCS3LD:
547a7db759eSPhilippe Mathieu-Daudé case GT_SCS3HD:
548a7db759eSPhilippe Mathieu-Daudé case GT_CS0LD:
549a7db759eSPhilippe Mathieu-Daudé case GT_CS0HD:
550a7db759eSPhilippe Mathieu-Daudé case GT_CS1LD:
551a7db759eSPhilippe Mathieu-Daudé case GT_CS1HD:
552a7db759eSPhilippe Mathieu-Daudé case GT_CS2LD:
553a7db759eSPhilippe Mathieu-Daudé case GT_CS2HD:
554a7db759eSPhilippe Mathieu-Daudé case GT_CS3LD:
555a7db759eSPhilippe Mathieu-Daudé case GT_CS3HD:
556a7db759eSPhilippe Mathieu-Daudé case GT_BOOTLD:
557a7db759eSPhilippe Mathieu-Daudé case GT_BOOTHD:
558a7db759eSPhilippe Mathieu-Daudé case GT_ADERR:
559a7db759eSPhilippe Mathieu-Daudé /* SDRAM Configuration */
560a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_CFG:
561a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_OPMODE:
562a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_BM:
563a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_ADDRDECODE:
564a7db759eSPhilippe Mathieu-Daudé /* Accept and ignore SDRAM interleave configuration */
565a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val;
566a7db759eSPhilippe Mathieu-Daudé break;
567a7db759eSPhilippe Mathieu-Daudé
568a7db759eSPhilippe Mathieu-Daudé /* Device Parameters */
569a7db759eSPhilippe Mathieu-Daudé case GT_DEV_B0:
570a7db759eSPhilippe Mathieu-Daudé case GT_DEV_B1:
571a7db759eSPhilippe Mathieu-Daudé case GT_DEV_B2:
572a7db759eSPhilippe Mathieu-Daudé case GT_DEV_B3:
573a7db759eSPhilippe Mathieu-Daudé case GT_DEV_BOOT:
574a7db759eSPhilippe Mathieu-Daudé /* Not implemented */
575a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_UNIMP,
576a7db759eSPhilippe Mathieu-Daudé "gt64120: Unimplemented device register write "
577a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*" PRIx64 "\n",
578a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
579a7db759eSPhilippe Mathieu-Daudé break;
580a7db759eSPhilippe Mathieu-Daudé
581a7db759eSPhilippe Mathieu-Daudé /* ECC */
582a7db759eSPhilippe Mathieu-Daudé case GT_ECC_ERRDATALO:
583a7db759eSPhilippe Mathieu-Daudé case GT_ECC_ERRDATAHI:
584a7db759eSPhilippe Mathieu-Daudé case GT_ECC_MEM:
585a7db759eSPhilippe Mathieu-Daudé case GT_ECC_CALC:
586a7db759eSPhilippe Mathieu-Daudé case GT_ECC_ERRADDR:
587a7db759eSPhilippe Mathieu-Daudé /* Read-only registers, do nothing */
588a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_GUEST_ERROR,
589a7db759eSPhilippe Mathieu-Daudé "gt64120: Read-only register write "
590a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*" PRIx64 "\n",
591a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
592a7db759eSPhilippe Mathieu-Daudé break;
593a7db759eSPhilippe Mathieu-Daudé
594a7db759eSPhilippe Mathieu-Daudé /* DMA Record */
595a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_CNT:
596a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_CNT:
597a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_CNT:
598a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_CNT:
599a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_SA:
600a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_SA:
601a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_SA:
602a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_SA:
603a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_DA:
604a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_DA:
605a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_DA:
606a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_DA:
607a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_NEXT:
608a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_NEXT:
609a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_NEXT:
610a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_NEXT:
611a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_CUR:
612a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_CUR:
613a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_CUR:
614a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_CUR:
615a7db759eSPhilippe Mathieu-Daudé
616a7db759eSPhilippe Mathieu-Daudé /* DMA Channel Control */
617a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_CTRL:
618a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_CTRL:
619a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_CTRL:
620a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_CTRL:
621a7db759eSPhilippe Mathieu-Daudé
622a7db759eSPhilippe Mathieu-Daudé /* DMA Arbiter */
623a7db759eSPhilippe Mathieu-Daudé case GT_DMA_ARB:
624a7db759eSPhilippe Mathieu-Daudé /* Not implemented */
625a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_UNIMP,
626a7db759eSPhilippe Mathieu-Daudé "gt64120: Unimplemented DMA register write "
627a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*" PRIx64 "\n",
628a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
629a7db759eSPhilippe Mathieu-Daudé break;
630a7db759eSPhilippe Mathieu-Daudé
631a7db759eSPhilippe Mathieu-Daudé /* Timer/Counter */
632a7db759eSPhilippe Mathieu-Daudé case GT_TC0:
633a7db759eSPhilippe Mathieu-Daudé case GT_TC1:
634a7db759eSPhilippe Mathieu-Daudé case GT_TC2:
635a7db759eSPhilippe Mathieu-Daudé case GT_TC3:
636a7db759eSPhilippe Mathieu-Daudé case GT_TC_CONTROL:
637a7db759eSPhilippe Mathieu-Daudé /* Not implemented */
638a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_UNIMP,
639a7db759eSPhilippe Mathieu-Daudé "gt64120: Unimplemented timer register write "
640a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*" PRIx64 "\n",
641a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
642a7db759eSPhilippe Mathieu-Daudé break;
643a7db759eSPhilippe Mathieu-Daudé
644a7db759eSPhilippe Mathieu-Daudé /* PCI Internal */
645a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CMD:
646a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CMD:
647a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val & 0x0401fc0f;
648a7db759eSPhilippe Mathieu-Daudé gt64120_update_pci_cfgdata_mapping(s);
649a7db759eSPhilippe Mathieu-Daudé break;
650a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_TOR:
651a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BS_SCS10:
652a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BS_SCS32:
653a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BS_CS20:
654a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BS_CS3BT:
655a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_IACK:
656a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_IACK:
657a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BARE:
658a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_PREFMBR:
659a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SCS10_BAR:
660a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SCS32_BAR:
661a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CS20_BAR:
662a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CS3BT_BAR:
663a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SSCS10_BAR:
664a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SSCS32_BAR:
665a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SCS3BT_BAR:
666a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_TOR:
667a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BS_SCS10:
668a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BS_SCS32:
669a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BS_CS20:
670a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BS_CS3BT:
671a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BARE:
672a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_PREFMBR:
673a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SCS10_BAR:
674a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SCS32_BAR:
675a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CS20_BAR:
676a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CS3BT_BAR:
677a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SSCS10_BAR:
678a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SSCS32_BAR:
679a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SCS3BT_BAR:
680a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CFGADDR:
681a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CFGDATA:
682a7db759eSPhilippe Mathieu-Daudé /* not implemented */
683a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_UNIMP,
684a7db759eSPhilippe Mathieu-Daudé "gt64120: Unimplemented PCI register write "
685a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*" PRIx64 "\n",
686a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
687a7db759eSPhilippe Mathieu-Daudé break;
688a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CFGADDR:
689a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CFGDATA:
690a7db759eSPhilippe Mathieu-Daudé /* Mapped via in gt64120_pci_mapping() */
691a7db759eSPhilippe Mathieu-Daudé g_assert_not_reached();
692a7db759eSPhilippe Mathieu-Daudé
693a7db759eSPhilippe Mathieu-Daudé /* Interrupts */
694a7db759eSPhilippe Mathieu-Daudé case GT_INTRCAUSE:
695a7db759eSPhilippe Mathieu-Daudé /* not really implemented */
696a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = ~(~(s->regs[saddr]) | ~(val & 0xfffffffe));
697a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] |= !!(s->regs[saddr] & 0xfffffffe);
698a7db759eSPhilippe Mathieu-Daudé trace_gt64120_write_intreg("INTRCAUSE", size, val);
699a7db759eSPhilippe Mathieu-Daudé break;
700a7db759eSPhilippe Mathieu-Daudé case GT_INTRMASK:
701a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val & 0x3c3ffffe;
702a7db759eSPhilippe Mathieu-Daudé trace_gt64120_write_intreg("INTRMASK", size, val);
703a7db759eSPhilippe Mathieu-Daudé break;
704a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_ICMASK:
705a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val & 0x03fffffe;
706a7db759eSPhilippe Mathieu-Daudé trace_gt64120_write_intreg("ICMASK", size, val);
707a7db759eSPhilippe Mathieu-Daudé break;
708a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SERR0MASK:
709a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val & 0x0000003f;
710a7db759eSPhilippe Mathieu-Daudé trace_gt64120_write_intreg("SERR0MASK", size, val);
711a7db759eSPhilippe Mathieu-Daudé break;
712a7db759eSPhilippe Mathieu-Daudé
713a7db759eSPhilippe Mathieu-Daudé /* Reserved when only PCI_0 is configured. */
714a7db759eSPhilippe Mathieu-Daudé case GT_HINTRCAUSE:
715a7db759eSPhilippe Mathieu-Daudé case GT_CPU_INTSEL:
716a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_INTSEL:
717a7db759eSPhilippe Mathieu-Daudé case GT_HINTRMASK:
718a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_HICMASK:
719a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SERR1MASK:
720a7db759eSPhilippe Mathieu-Daudé /* not implemented */
721a7db759eSPhilippe Mathieu-Daudé break;
722a7db759eSPhilippe Mathieu-Daudé
723a7db759eSPhilippe Mathieu-Daudé /* SDRAM Parameters */
724a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_B0:
725a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_B1:
726a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_B2:
727a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_B3:
728a7db759eSPhilippe Mathieu-Daudé /*
729a7db759eSPhilippe Mathieu-Daudé * We don't simulate electrical parameters of the SDRAM.
730a7db759eSPhilippe Mathieu-Daudé * Accept, but ignore the values.
731a7db759eSPhilippe Mathieu-Daudé */
732a7db759eSPhilippe Mathieu-Daudé s->regs[saddr] = val;
733a7db759eSPhilippe Mathieu-Daudé break;
734a7db759eSPhilippe Mathieu-Daudé
735a7db759eSPhilippe Mathieu-Daudé default:
736a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_GUEST_ERROR,
737a7db759eSPhilippe Mathieu-Daudé "gt64120: Illegal register write "
738a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*" PRIx64 "\n",
739a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
740a7db759eSPhilippe Mathieu-Daudé break;
741a7db759eSPhilippe Mathieu-Daudé }
742a7db759eSPhilippe Mathieu-Daudé }
743a7db759eSPhilippe Mathieu-Daudé
gt64120_readl(void * opaque,hwaddr addr,unsigned size)744a7db759eSPhilippe Mathieu-Daudé static uint64_t gt64120_readl(void *opaque,
745a7db759eSPhilippe Mathieu-Daudé hwaddr addr, unsigned size)
746a7db759eSPhilippe Mathieu-Daudé {
747a7db759eSPhilippe Mathieu-Daudé GT64120State *s = opaque;
748a7db759eSPhilippe Mathieu-Daudé uint32_t val;
749a7db759eSPhilippe Mathieu-Daudé uint32_t saddr = addr >> 2;
750a7db759eSPhilippe Mathieu-Daudé
751a7db759eSPhilippe Mathieu-Daudé switch (saddr) {
752a7db759eSPhilippe Mathieu-Daudé
753a7db759eSPhilippe Mathieu-Daudé /* CPU Configuration */
754a7db759eSPhilippe Mathieu-Daudé case GT_MULTI:
755a7db759eSPhilippe Mathieu-Daudé /*
756a7db759eSPhilippe Mathieu-Daudé * Only one GT64xxx is present on the CPU bus, return
757a7db759eSPhilippe Mathieu-Daudé * the initial value.
758a7db759eSPhilippe Mathieu-Daudé */
759a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
760a7db759eSPhilippe Mathieu-Daudé break;
761a7db759eSPhilippe Mathieu-Daudé
762a7db759eSPhilippe Mathieu-Daudé /* CPU Error Report */
763a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_ADDRLO:
764a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_ADDRHI:
765a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_DATALO:
766a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_DATAHI:
767a7db759eSPhilippe Mathieu-Daudé case GT_CPUERR_PARITY:
768a7db759eSPhilippe Mathieu-Daudé /* Emulated memory has no error, always return the initial values. */
769a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
770a7db759eSPhilippe Mathieu-Daudé break;
771a7db759eSPhilippe Mathieu-Daudé
772a7db759eSPhilippe Mathieu-Daudé /* CPU Sync Barrier */
773a7db759eSPhilippe Mathieu-Daudé case GT_PCI0SYNC:
774a7db759eSPhilippe Mathieu-Daudé case GT_PCI1SYNC:
775a7db759eSPhilippe Mathieu-Daudé /*
776a7db759eSPhilippe Mathieu-Daudé * Reading those register should empty all FIFO on the PCI
777a7db759eSPhilippe Mathieu-Daudé * bus, which are not emulated. The return value should be
778a7db759eSPhilippe Mathieu-Daudé * a random value that should be ignored.
779a7db759eSPhilippe Mathieu-Daudé */
780a7db759eSPhilippe Mathieu-Daudé val = 0xc000ffee;
781a7db759eSPhilippe Mathieu-Daudé break;
782a7db759eSPhilippe Mathieu-Daudé
783a7db759eSPhilippe Mathieu-Daudé /* ECC */
784a7db759eSPhilippe Mathieu-Daudé case GT_ECC_ERRDATALO:
785a7db759eSPhilippe Mathieu-Daudé case GT_ECC_ERRDATAHI:
786a7db759eSPhilippe Mathieu-Daudé case GT_ECC_MEM:
787a7db759eSPhilippe Mathieu-Daudé case GT_ECC_CALC:
788a7db759eSPhilippe Mathieu-Daudé case GT_ECC_ERRADDR:
789a7db759eSPhilippe Mathieu-Daudé /* Emulated memory has no error, always return the initial values. */
790a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
791a7db759eSPhilippe Mathieu-Daudé break;
792a7db759eSPhilippe Mathieu-Daudé
793a7db759eSPhilippe Mathieu-Daudé case GT_CPU:
794a7db759eSPhilippe Mathieu-Daudé case GT_SCS10LD:
795a7db759eSPhilippe Mathieu-Daudé case GT_SCS10HD:
796a7db759eSPhilippe Mathieu-Daudé case GT_SCS32LD:
797a7db759eSPhilippe Mathieu-Daudé case GT_SCS32HD:
798a7db759eSPhilippe Mathieu-Daudé case GT_CS20LD:
799a7db759eSPhilippe Mathieu-Daudé case GT_CS20HD:
800a7db759eSPhilippe Mathieu-Daudé case GT_CS3BOOTLD:
801a7db759eSPhilippe Mathieu-Daudé case GT_CS3BOOTHD:
802a7db759eSPhilippe Mathieu-Daudé case GT_SCS10AR:
803a7db759eSPhilippe Mathieu-Daudé case GT_SCS32AR:
804a7db759eSPhilippe Mathieu-Daudé case GT_CS20R:
805a7db759eSPhilippe Mathieu-Daudé case GT_CS3BOOTR:
806a7db759eSPhilippe Mathieu-Daudé case GT_PCI0IOLD:
807a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M0LD:
808a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M1LD:
809a7db759eSPhilippe Mathieu-Daudé case GT_PCI1IOLD:
810a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M0LD:
811a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M1LD:
812a7db759eSPhilippe Mathieu-Daudé case GT_PCI0IOHD:
813a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M0HD:
814a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M1HD:
815a7db759eSPhilippe Mathieu-Daudé case GT_PCI1IOHD:
816a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M0HD:
817a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M1HD:
818a7db759eSPhilippe Mathieu-Daudé case GT_PCI0IOREMAP:
819a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M0REMAP:
820a7db759eSPhilippe Mathieu-Daudé case GT_PCI0M1REMAP:
821a7db759eSPhilippe Mathieu-Daudé case GT_PCI1IOREMAP:
822a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M0REMAP:
823a7db759eSPhilippe Mathieu-Daudé case GT_PCI1M1REMAP:
824a7db759eSPhilippe Mathieu-Daudé case GT_ISD:
825a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
826a7db759eSPhilippe Mathieu-Daudé break;
827a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_IACK:
828a7db759eSPhilippe Mathieu-Daudé /* Read the IRQ number */
829a7db759eSPhilippe Mathieu-Daudé val = pic_read_irq(isa_pic);
830a7db759eSPhilippe Mathieu-Daudé break;
831a7db759eSPhilippe Mathieu-Daudé
832a7db759eSPhilippe Mathieu-Daudé /* SDRAM and Device Address Decode */
833a7db759eSPhilippe Mathieu-Daudé case GT_SCS0LD:
834a7db759eSPhilippe Mathieu-Daudé case GT_SCS0HD:
835a7db759eSPhilippe Mathieu-Daudé case GT_SCS1LD:
836a7db759eSPhilippe Mathieu-Daudé case GT_SCS1HD:
837a7db759eSPhilippe Mathieu-Daudé case GT_SCS2LD:
838a7db759eSPhilippe Mathieu-Daudé case GT_SCS2HD:
839a7db759eSPhilippe Mathieu-Daudé case GT_SCS3LD:
840a7db759eSPhilippe Mathieu-Daudé case GT_SCS3HD:
841a7db759eSPhilippe Mathieu-Daudé case GT_CS0LD:
842a7db759eSPhilippe Mathieu-Daudé case GT_CS0HD:
843a7db759eSPhilippe Mathieu-Daudé case GT_CS1LD:
844a7db759eSPhilippe Mathieu-Daudé case GT_CS1HD:
845a7db759eSPhilippe Mathieu-Daudé case GT_CS2LD:
846a7db759eSPhilippe Mathieu-Daudé case GT_CS2HD:
847a7db759eSPhilippe Mathieu-Daudé case GT_CS3LD:
848a7db759eSPhilippe Mathieu-Daudé case GT_CS3HD:
849a7db759eSPhilippe Mathieu-Daudé case GT_BOOTLD:
850a7db759eSPhilippe Mathieu-Daudé case GT_BOOTHD:
851a7db759eSPhilippe Mathieu-Daudé case GT_ADERR:
852a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
853a7db759eSPhilippe Mathieu-Daudé break;
854a7db759eSPhilippe Mathieu-Daudé
855a7db759eSPhilippe Mathieu-Daudé /* SDRAM Configuration */
856a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_CFG:
857a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_OPMODE:
858a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_BM:
859a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_ADDRDECODE:
860a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
861a7db759eSPhilippe Mathieu-Daudé break;
862a7db759eSPhilippe Mathieu-Daudé
863a7db759eSPhilippe Mathieu-Daudé /* SDRAM Parameters */
864a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_B0:
865a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_B1:
866a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_B2:
867a7db759eSPhilippe Mathieu-Daudé case GT_SDRAM_B3:
868a7db759eSPhilippe Mathieu-Daudé /*
869a7db759eSPhilippe Mathieu-Daudé * We don't simulate electrical parameters of the SDRAM.
870a7db759eSPhilippe Mathieu-Daudé * Just return the last written value.
871a7db759eSPhilippe Mathieu-Daudé */
872a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
873a7db759eSPhilippe Mathieu-Daudé break;
874a7db759eSPhilippe Mathieu-Daudé
875a7db759eSPhilippe Mathieu-Daudé /* Device Parameters */
876a7db759eSPhilippe Mathieu-Daudé case GT_DEV_B0:
877a7db759eSPhilippe Mathieu-Daudé case GT_DEV_B1:
878a7db759eSPhilippe Mathieu-Daudé case GT_DEV_B2:
879a7db759eSPhilippe Mathieu-Daudé case GT_DEV_B3:
880a7db759eSPhilippe Mathieu-Daudé case GT_DEV_BOOT:
881a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
882a7db759eSPhilippe Mathieu-Daudé break;
883a7db759eSPhilippe Mathieu-Daudé
884a7db759eSPhilippe Mathieu-Daudé /* DMA Record */
885a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_CNT:
886a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_CNT:
887a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_CNT:
888a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_CNT:
889a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_SA:
890a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_SA:
891a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_SA:
892a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_SA:
893a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_DA:
894a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_DA:
895a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_DA:
896a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_DA:
897a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_NEXT:
898a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_NEXT:
899a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_NEXT:
900a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_NEXT:
901a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_CUR:
902a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_CUR:
903a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_CUR:
904a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_CUR:
905a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
906a7db759eSPhilippe Mathieu-Daudé break;
907a7db759eSPhilippe Mathieu-Daudé
908a7db759eSPhilippe Mathieu-Daudé /* DMA Channel Control */
909a7db759eSPhilippe Mathieu-Daudé case GT_DMA0_CTRL:
910a7db759eSPhilippe Mathieu-Daudé case GT_DMA1_CTRL:
911a7db759eSPhilippe Mathieu-Daudé case GT_DMA2_CTRL:
912a7db759eSPhilippe Mathieu-Daudé case GT_DMA3_CTRL:
913a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
914a7db759eSPhilippe Mathieu-Daudé break;
915a7db759eSPhilippe Mathieu-Daudé
916a7db759eSPhilippe Mathieu-Daudé /* DMA Arbiter */
917a7db759eSPhilippe Mathieu-Daudé case GT_DMA_ARB:
918a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
919a7db759eSPhilippe Mathieu-Daudé break;
920a7db759eSPhilippe Mathieu-Daudé
921a7db759eSPhilippe Mathieu-Daudé /* Timer/Counter */
922a7db759eSPhilippe Mathieu-Daudé case GT_TC0:
923a7db759eSPhilippe Mathieu-Daudé case GT_TC1:
924a7db759eSPhilippe Mathieu-Daudé case GT_TC2:
925a7db759eSPhilippe Mathieu-Daudé case GT_TC3:
926a7db759eSPhilippe Mathieu-Daudé case GT_TC_CONTROL:
927a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
928a7db759eSPhilippe Mathieu-Daudé break;
929a7db759eSPhilippe Mathieu-Daudé
930a7db759eSPhilippe Mathieu-Daudé /* PCI Internal */
931a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CFGADDR:
932a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CFGDATA:
933a7db759eSPhilippe Mathieu-Daudé /* Mapped via in gt64120_pci_mapping() */
934a7db759eSPhilippe Mathieu-Daudé g_assert_not_reached();
935a7db759eSPhilippe Mathieu-Daudé
936a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CMD:
937a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_TOR:
938a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BS_SCS10:
939a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BS_SCS32:
940a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BS_CS20:
941a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BS_CS3BT:
942a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_IACK:
943a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_BARE:
944a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_PREFMBR:
945a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SCS10_BAR:
946a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SCS32_BAR:
947a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CS20_BAR:
948a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_CS3BT_BAR:
949a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SSCS10_BAR:
950a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SSCS32_BAR:
951a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SCS3BT_BAR:
952a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CMD:
953a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_TOR:
954a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BS_SCS10:
955a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BS_SCS32:
956a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BS_CS20:
957a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BS_CS3BT:
958a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_BARE:
959a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_PREFMBR:
960a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SCS10_BAR:
961a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SCS32_BAR:
962a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CS20_BAR:
963a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CS3BT_BAR:
964a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SSCS10_BAR:
965a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SSCS32_BAR:
966a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SCS3BT_BAR:
967a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CFGADDR:
968a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_CFGDATA:
969a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
970a7db759eSPhilippe Mathieu-Daudé break;
971a7db759eSPhilippe Mathieu-Daudé
972a7db759eSPhilippe Mathieu-Daudé /* Interrupts */
973a7db759eSPhilippe Mathieu-Daudé case GT_INTRCAUSE:
974a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
975a7db759eSPhilippe Mathieu-Daudé trace_gt64120_read_intreg("INTRCAUSE", size, val);
976a7db759eSPhilippe Mathieu-Daudé break;
977a7db759eSPhilippe Mathieu-Daudé case GT_INTRMASK:
978a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
979a7db759eSPhilippe Mathieu-Daudé trace_gt64120_read_intreg("INTRMASK", size, val);
980a7db759eSPhilippe Mathieu-Daudé break;
981a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_ICMASK:
982a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
983a7db759eSPhilippe Mathieu-Daudé trace_gt64120_read_intreg("ICMASK", size, val);
984a7db759eSPhilippe Mathieu-Daudé break;
985a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_SERR0MASK:
986a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
987a7db759eSPhilippe Mathieu-Daudé trace_gt64120_read_intreg("SERR0MASK", size, val);
988a7db759eSPhilippe Mathieu-Daudé break;
989a7db759eSPhilippe Mathieu-Daudé
990a7db759eSPhilippe Mathieu-Daudé /* Reserved when only PCI_0 is configured. */
991a7db759eSPhilippe Mathieu-Daudé case GT_HINTRCAUSE:
992a7db759eSPhilippe Mathieu-Daudé case GT_CPU_INTSEL:
993a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_INTSEL:
994a7db759eSPhilippe Mathieu-Daudé case GT_HINTRMASK:
995a7db759eSPhilippe Mathieu-Daudé case GT_PCI0_HICMASK:
996a7db759eSPhilippe Mathieu-Daudé case GT_PCI1_SERR1MASK:
997a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
998a7db759eSPhilippe Mathieu-Daudé break;
999a7db759eSPhilippe Mathieu-Daudé
1000a7db759eSPhilippe Mathieu-Daudé default:
1001a7db759eSPhilippe Mathieu-Daudé val = s->regs[saddr];
1002a7db759eSPhilippe Mathieu-Daudé qemu_log_mask(LOG_GUEST_ERROR,
1003a7db759eSPhilippe Mathieu-Daudé "gt64120: Illegal register read "
1004a7db759eSPhilippe Mathieu-Daudé "reg:0x%03x size:%u value:0x%0*x\n",
1005a7db759eSPhilippe Mathieu-Daudé saddr << 2, size, size << 1, val);
1006a7db759eSPhilippe Mathieu-Daudé break;
1007a7db759eSPhilippe Mathieu-Daudé }
1008a7db759eSPhilippe Mathieu-Daudé
1009a7db759eSPhilippe Mathieu-Daudé if (!(s->regs[GT_CPU] & 0x00001000)) {
1010a7db759eSPhilippe Mathieu-Daudé val = bswap32(val);
1011a7db759eSPhilippe Mathieu-Daudé }
1012a7db759eSPhilippe Mathieu-Daudé trace_gt64120_read(addr, val);
1013a7db759eSPhilippe Mathieu-Daudé
1014a7db759eSPhilippe Mathieu-Daudé return val;
1015a7db759eSPhilippe Mathieu-Daudé }
1016a7db759eSPhilippe Mathieu-Daudé
1017a7db759eSPhilippe Mathieu-Daudé static const MemoryRegionOps isd_mem_ops = {
1018a7db759eSPhilippe Mathieu-Daudé .read = gt64120_readl,
1019a7db759eSPhilippe Mathieu-Daudé .write = gt64120_writel,
1020a7db759eSPhilippe Mathieu-Daudé .endianness = DEVICE_NATIVE_ENDIAN,
1021a7db759eSPhilippe Mathieu-Daudé .impl = {
1022a7db759eSPhilippe Mathieu-Daudé .min_access_size = 4,
1023a7db759eSPhilippe Mathieu-Daudé .max_access_size = 4,
1024a7db759eSPhilippe Mathieu-Daudé },
1025a7db759eSPhilippe Mathieu-Daudé };
1026a7db759eSPhilippe Mathieu-Daudé
gt64120_reset(DeviceState * dev)1027a7db759eSPhilippe Mathieu-Daudé static void gt64120_reset(DeviceState *dev)
1028a7db759eSPhilippe Mathieu-Daudé {
1029a7db759eSPhilippe Mathieu-Daudé GT64120State *s = GT64120_PCI_HOST_BRIDGE(dev);
1030a7db759eSPhilippe Mathieu-Daudé
1031a7db759eSPhilippe Mathieu-Daudé /* FIXME: Malta specific hw assumptions ahead */
1032a7db759eSPhilippe Mathieu-Daudé
1033a7db759eSPhilippe Mathieu-Daudé /* CPU Configuration */
1034a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CPU] = s->cpu_little_endian ? R_GT_CPU_Endianness_MASK : 0;
1035a7db759eSPhilippe Mathieu-Daudé s->regs[GT_MULTI] = 0x00000003;
1036a7db759eSPhilippe Mathieu-Daudé
1037a7db759eSPhilippe Mathieu-Daudé /* CPU Address decode */
1038a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS10LD] = 0x00000000;
1039a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS10HD] = 0x00000007;
1040a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS32LD] = 0x00000008;
1041a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS32HD] = 0x0000000f;
1042a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS20LD] = 0x000000e0;
1043a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS20HD] = 0x00000070;
1044a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS3BOOTLD] = 0x000000f8;
1045a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS3BOOTHD] = 0x0000007f;
1046a7db759eSPhilippe Mathieu-Daudé
1047a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0IOLD] = 0x00000080;
1048a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0IOHD] = 0x0000000f;
1049a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M0LD] = 0x00000090;
1050a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M0HD] = 0x0000001f;
1051a7db759eSPhilippe Mathieu-Daudé s->regs[GT_ISD] = 0x000000a0;
1052a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M1LD] = 0x00000790;
1053a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M1HD] = 0x0000001f;
1054a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1IOLD] = 0x00000100;
1055a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1IOHD] = 0x0000000f;
1056a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M0LD] = 0x00000110;
1057a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M0HD] = 0x0000001f;
1058a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M1LD] = 0x00000120;
1059a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M1HD] = 0x0000002f;
1060a7db759eSPhilippe Mathieu-Daudé
1061a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS10AR] = 0x00000000;
1062a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS32AR] = 0x00000008;
1063a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS20R] = 0x000000e0;
1064a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS3BOOTR] = 0x000000f8;
1065a7db759eSPhilippe Mathieu-Daudé
1066a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0IOREMAP] = 0x00000080;
1067a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M0REMAP] = 0x00000090;
1068a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0M1REMAP] = 0x00000790;
1069a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1IOREMAP] = 0x00000100;
1070a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M0REMAP] = 0x00000110;
1071a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1M1REMAP] = 0x00000120;
1072a7db759eSPhilippe Mathieu-Daudé
1073a7db759eSPhilippe Mathieu-Daudé /* CPU Error Report */
1074a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CPUERR_ADDRLO] = 0x00000000;
1075a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CPUERR_ADDRHI] = 0x00000000;
1076a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CPUERR_DATALO] = 0xffffffff;
1077a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CPUERR_DATAHI] = 0xffffffff;
1078a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CPUERR_PARITY] = 0x000000ff;
1079a7db759eSPhilippe Mathieu-Daudé
1080a7db759eSPhilippe Mathieu-Daudé /* CPU Sync Barrier */
1081a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0SYNC] = 0x00000000;
1082a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1SYNC] = 0x00000000;
1083a7db759eSPhilippe Mathieu-Daudé
1084a7db759eSPhilippe Mathieu-Daudé /* SDRAM and Device Address Decode */
1085a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS0LD] = 0x00000000;
1086a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS0HD] = 0x00000007;
1087a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS1LD] = 0x00000008;
1088a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS1HD] = 0x0000000f;
1089a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS2LD] = 0x00000010;
1090a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS2HD] = 0x00000017;
1091a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS3LD] = 0x00000018;
1092a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SCS3HD] = 0x0000001f;
1093a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS0LD] = 0x000000c0;
1094a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS0HD] = 0x000000c7;
1095a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS1LD] = 0x000000c8;
1096a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS1HD] = 0x000000cf;
1097a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS2LD] = 0x000000d0;
1098a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS2HD] = 0x000000df;
1099a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS3LD] = 0x000000f0;
1100a7db759eSPhilippe Mathieu-Daudé s->regs[GT_CS3HD] = 0x000000fb;
1101a7db759eSPhilippe Mathieu-Daudé s->regs[GT_BOOTLD] = 0x000000fc;
1102a7db759eSPhilippe Mathieu-Daudé s->regs[GT_BOOTHD] = 0x000000ff;
1103a7db759eSPhilippe Mathieu-Daudé s->regs[GT_ADERR] = 0xffffffff;
1104a7db759eSPhilippe Mathieu-Daudé
1105a7db759eSPhilippe Mathieu-Daudé /* SDRAM Configuration */
1106a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SDRAM_CFG] = 0x00000200;
1107a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SDRAM_OPMODE] = 0x00000000;
1108a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SDRAM_BM] = 0x00000007;
1109a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SDRAM_ADDRDECODE] = 0x00000002;
1110a7db759eSPhilippe Mathieu-Daudé
1111a7db759eSPhilippe Mathieu-Daudé /* SDRAM Parameters */
1112a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SDRAM_B0] = 0x00000005;
1113a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SDRAM_B1] = 0x00000005;
1114a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SDRAM_B2] = 0x00000005;
1115a7db759eSPhilippe Mathieu-Daudé s->regs[GT_SDRAM_B3] = 0x00000005;
1116a7db759eSPhilippe Mathieu-Daudé
1117a7db759eSPhilippe Mathieu-Daudé /* ECC */
1118a7db759eSPhilippe Mathieu-Daudé s->regs[GT_ECC_ERRDATALO] = 0x00000000;
1119a7db759eSPhilippe Mathieu-Daudé s->regs[GT_ECC_ERRDATAHI] = 0x00000000;
1120a7db759eSPhilippe Mathieu-Daudé s->regs[GT_ECC_MEM] = 0x00000000;
1121a7db759eSPhilippe Mathieu-Daudé s->regs[GT_ECC_CALC] = 0x00000000;
1122a7db759eSPhilippe Mathieu-Daudé s->regs[GT_ECC_ERRADDR] = 0x00000000;
1123a7db759eSPhilippe Mathieu-Daudé
1124a7db759eSPhilippe Mathieu-Daudé /* Device Parameters */
1125a7db759eSPhilippe Mathieu-Daudé s->regs[GT_DEV_B0] = 0x386fffff;
1126a7db759eSPhilippe Mathieu-Daudé s->regs[GT_DEV_B1] = 0x386fffff;
1127a7db759eSPhilippe Mathieu-Daudé s->regs[GT_DEV_B2] = 0x386fffff;
1128a7db759eSPhilippe Mathieu-Daudé s->regs[GT_DEV_B3] = 0x386fffff;
1129a7db759eSPhilippe Mathieu-Daudé s->regs[GT_DEV_BOOT] = 0x146fffff;
1130a7db759eSPhilippe Mathieu-Daudé
1131a7db759eSPhilippe Mathieu-Daudé /* DMA registers are all zeroed at reset */
1132a7db759eSPhilippe Mathieu-Daudé
1133a7db759eSPhilippe Mathieu-Daudé /* Timer/Counter */
1134a7db759eSPhilippe Mathieu-Daudé s->regs[GT_TC0] = 0xffffffff;
1135a7db759eSPhilippe Mathieu-Daudé s->regs[GT_TC1] = 0x00ffffff;
1136a7db759eSPhilippe Mathieu-Daudé s->regs[GT_TC2] = 0x00ffffff;
1137a7db759eSPhilippe Mathieu-Daudé s->regs[GT_TC3] = 0x00ffffff;
1138a7db759eSPhilippe Mathieu-Daudé s->regs[GT_TC_CONTROL] = 0x00000000;
1139a7db759eSPhilippe Mathieu-Daudé
1140a7db759eSPhilippe Mathieu-Daudé /* PCI Internal */
1141a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_CMD] = s->cpu_little_endian ? R_GT_PCI0_CMD_ByteSwap_MASK : 0;
1142a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_TOR] = 0x0000070f;
1143a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_BS_SCS10] = 0x00fff000;
1144a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_BS_SCS32] = 0x00fff000;
1145a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_BS_CS20] = 0x01fff000;
1146a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_BS_CS3BT] = 0x00fff000;
1147a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_IACK] = 0x00000000;
1148a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_IACK] = 0x00000000;
1149a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_BARE] = 0x0000000f;
1150a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_PREFMBR] = 0x00000040;
1151a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_SCS10_BAR] = 0x00000000;
1152a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_SCS32_BAR] = 0x01000000;
1153a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_CS20_BAR] = 0x1c000000;
1154a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_CS3BT_BAR] = 0x1f000000;
1155a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_SSCS10_BAR] = 0x00000000;
1156a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_SSCS32_BAR] = 0x01000000;
1157a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_SCS3BT_BAR] = 0x1f000000;
1158a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_CMD] = s->cpu_little_endian ? R_GT_PCI1_CMD_ByteSwap_MASK : 0;
1159a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_TOR] = 0x0000070f;
1160a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_BS_SCS10] = 0x00fff000;
1161a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_BS_SCS32] = 0x00fff000;
1162a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_BS_CS20] = 0x01fff000;
1163a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_BS_CS3BT] = 0x00fff000;
1164a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_BARE] = 0x0000000f;
1165a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_PREFMBR] = 0x00000040;
1166a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_SCS10_BAR] = 0x00000000;
1167a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_SCS32_BAR] = 0x01000000;
1168a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_CS20_BAR] = 0x1c000000;
1169a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_CS3BT_BAR] = 0x1f000000;
1170a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_SSCS10_BAR] = 0x00000000;
1171a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_SSCS32_BAR] = 0x01000000;
1172a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_SCS3BT_BAR] = 0x1f000000;
1173a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_CFGADDR] = 0x00000000;
1174a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI1_CFGDATA] = 0x00000000;
1175a7db759eSPhilippe Mathieu-Daudé s->regs[GT_PCI0_CFGADDR] = 0x00000000;
1176a7db759eSPhilippe Mathieu-Daudé
1177a7db759eSPhilippe Mathieu-Daudé /* Interrupt registers are all zeroed at reset */
1178a7db759eSPhilippe Mathieu-Daudé
1179a7db759eSPhilippe Mathieu-Daudé gt64120_isd_mapping(s);
1180a7db759eSPhilippe Mathieu-Daudé gt64120_pci_mapping(s);
1181a7db759eSPhilippe Mathieu-Daudé gt64120_update_pci_cfgdata_mapping(s);
1182a7db759eSPhilippe Mathieu-Daudé }
1183a7db759eSPhilippe Mathieu-Daudé
gt64120_realize(DeviceState * dev,Error ** errp)1184a7db759eSPhilippe Mathieu-Daudé static void gt64120_realize(DeviceState *dev, Error **errp)
1185a7db759eSPhilippe Mathieu-Daudé {
1186a7db759eSPhilippe Mathieu-Daudé GT64120State *s = GT64120_PCI_HOST_BRIDGE(dev);
1187a7db759eSPhilippe Mathieu-Daudé PCIHostState *phb = PCI_HOST_BRIDGE(dev);
1188a7db759eSPhilippe Mathieu-Daudé
1189a7db759eSPhilippe Mathieu-Daudé memory_region_init_io(&s->ISD_mem, OBJECT(dev), &isd_mem_ops, s,
1190a7db759eSPhilippe Mathieu-Daudé "gt64120-isd", 0x1000);
1191a7db759eSPhilippe Mathieu-Daudé memory_region_init(&s->pci0_mem, OBJECT(dev), "pci0-mem", 4 * GiB);
1192a7db759eSPhilippe Mathieu-Daudé address_space_init(&s->pci0_mem_as, &s->pci0_mem, "pci0-mem");
1193a7db759eSPhilippe Mathieu-Daudé phb->bus = pci_root_bus_new(dev, "pci",
1194a7db759eSPhilippe Mathieu-Daudé &s->pci0_mem,
1195a7db759eSPhilippe Mathieu-Daudé get_system_io(),
1196a7db759eSPhilippe Mathieu-Daudé PCI_DEVFN(18, 0), TYPE_PCI_BUS);
1197a7db759eSPhilippe Mathieu-Daudé
1198a7db759eSPhilippe Mathieu-Daudé pci_create_simple(phb->bus, PCI_DEVFN(0, 0), "gt64120_pci");
11993d85c7c1SJiaxun Yang memory_region_init_io(&phb->conf_mem, OBJECT(phb),
12003d85c7c1SJiaxun Yang &pci_host_conf_le_ops,
12013d85c7c1SJiaxun Yang s, "pci-conf-idx", 4);
12023d85c7c1SJiaxun Yang memory_region_add_subregion_overlap(&s->ISD_mem, GT_PCI0_CFGADDR << 2,
12033d85c7c1SJiaxun Yang &phb->conf_mem, 1);
12043d85c7c1SJiaxun Yang
1205a7db759eSPhilippe Mathieu-Daudé
1206a7db759eSPhilippe Mathieu-Daudé /*
1207a7db759eSPhilippe Mathieu-Daudé * The whole address space decoded by the GT-64120A doesn't generate
1208a7db759eSPhilippe Mathieu-Daudé * exception when accessing invalid memory. Create an empty slot to
1209a7db759eSPhilippe Mathieu-Daudé * emulate this feature.
1210a7db759eSPhilippe Mathieu-Daudé */
1211a7db759eSPhilippe Mathieu-Daudé empty_slot_init("GT64120", 0, 0x20000000);
1212a7db759eSPhilippe Mathieu-Daudé }
1213a7db759eSPhilippe Mathieu-Daudé
gt64120_pci_realize(PCIDevice * d,Error ** errp)1214a7db759eSPhilippe Mathieu-Daudé static void gt64120_pci_realize(PCIDevice *d, Error **errp)
1215a7db759eSPhilippe Mathieu-Daudé {
121650a24291SPhilippe Mathieu-Daudé /* Values from chapter 17.16 "PCI Configuration" */
121750a24291SPhilippe Mathieu-Daudé
121850a24291SPhilippe Mathieu-Daudé pci_set_long(d->wmask + PCI_BASE_ADDRESS_0, 0xfffff008); /* SCS[1:0] */
121950a24291SPhilippe Mathieu-Daudé pci_set_long(d->wmask + PCI_BASE_ADDRESS_1, 0xfffff008); /* SCS[3:2] */
122050a24291SPhilippe Mathieu-Daudé pci_set_long(d->wmask + PCI_BASE_ADDRESS_2, 0xfffff008); /* CS[2:0] */
122150a24291SPhilippe Mathieu-Daudé pci_set_long(d->wmask + PCI_BASE_ADDRESS_3, 0xfffff008); /* CS[3], BootCS */
122250a24291SPhilippe Mathieu-Daudé pci_set_long(d->wmask + PCI_BASE_ADDRESS_4, 0xfffff000); /* ISD MMIO */
122350a24291SPhilippe Mathieu-Daudé pci_set_long(d->wmask + PCI_BASE_ADDRESS_5, 0xfffff001); /* ISD I/O */
1224ec70b773SPhilippe Mathieu-Daudé }
1225ec70b773SPhilippe Mathieu-Daudé
gt64120_pci_reset_hold(Object * obj,ResetType type)1226ec70b773SPhilippe Mathieu-Daudé static void gt64120_pci_reset_hold(Object *obj, ResetType type)
1227ec70b773SPhilippe Mathieu-Daudé {
1228ec70b773SPhilippe Mathieu-Daudé PCIDevice *d = PCI_DEVICE(obj);
1229ec70b773SPhilippe Mathieu-Daudé
1230ec70b773SPhilippe Mathieu-Daudé /* Values from chapter 17.16 "PCI Configuration" */
1231ec70b773SPhilippe Mathieu-Daudé
1232ec70b773SPhilippe Mathieu-Daudé pci_set_word(d->config + PCI_COMMAND, 0);
1233ec70b773SPhilippe Mathieu-Daudé pci_set_word(d->config + PCI_STATUS,
1234ec70b773SPhilippe Mathieu-Daudé PCI_STATUS_FAST_BACK | PCI_STATUS_DEVSEL_MEDIUM);
1235ec70b773SPhilippe Mathieu-Daudé pci_config_set_prog_interface(d->config, 0);
123650a24291SPhilippe Mathieu-Daudé
1237a7db759eSPhilippe Mathieu-Daudé pci_set_long(d->config + PCI_BASE_ADDRESS_0, 0x00000008);
1238a7db759eSPhilippe Mathieu-Daudé pci_set_long(d->config + PCI_BASE_ADDRESS_1, 0x01000008);
1239a7db759eSPhilippe Mathieu-Daudé pci_set_long(d->config + PCI_BASE_ADDRESS_2, 0x1c000000);
1240a7db759eSPhilippe Mathieu-Daudé pci_set_long(d->config + PCI_BASE_ADDRESS_3, 0x1f000000);
1241a7db759eSPhilippe Mathieu-Daudé pci_set_long(d->config + PCI_BASE_ADDRESS_4, 0x14000000);
1242a7db759eSPhilippe Mathieu-Daudé pci_set_long(d->config + PCI_BASE_ADDRESS_5, 0x14000001);
124350a24291SPhilippe Mathieu-Daudé
1244a7db759eSPhilippe Mathieu-Daudé pci_set_byte(d->config + 0x3d, 0x01);
1245a7db759eSPhilippe Mathieu-Daudé }
1246a7db759eSPhilippe Mathieu-Daudé
gt64120_pci_class_init(ObjectClass * klass,void * data)1247a7db759eSPhilippe Mathieu-Daudé static void gt64120_pci_class_init(ObjectClass *klass, void *data)
1248a7db759eSPhilippe Mathieu-Daudé {
1249a7db759eSPhilippe Mathieu-Daudé PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
1250a7db759eSPhilippe Mathieu-Daudé DeviceClass *dc = DEVICE_CLASS(klass);
1251ec70b773SPhilippe Mathieu-Daudé ResettableClass *rc = RESETTABLE_CLASS(klass);
1252a7db759eSPhilippe Mathieu-Daudé
1253ec70b773SPhilippe Mathieu-Daudé rc->phases.hold = gt64120_pci_reset_hold;
1254a7db759eSPhilippe Mathieu-Daudé k->realize = gt64120_pci_realize;
1255a7db759eSPhilippe Mathieu-Daudé k->vendor_id = PCI_VENDOR_ID_MARVELL;
1256a7db759eSPhilippe Mathieu-Daudé k->device_id = PCI_DEVICE_ID_MARVELL_GT6412X;
1257a7db759eSPhilippe Mathieu-Daudé k->revision = 0x10;
1258a7db759eSPhilippe Mathieu-Daudé k->class_id = PCI_CLASS_BRIDGE_HOST;
1259a7db759eSPhilippe Mathieu-Daudé /*
1260a7db759eSPhilippe Mathieu-Daudé * PCI-facing part of the host bridge, not usable without the
1261a7db759eSPhilippe Mathieu-Daudé * host-facing part, which can't be device_add'ed, yet.
1262a7db759eSPhilippe Mathieu-Daudé */
1263a7db759eSPhilippe Mathieu-Daudé dc->user_creatable = false;
1264a7db759eSPhilippe Mathieu-Daudé }
1265a7db759eSPhilippe Mathieu-Daudé
1266a7db759eSPhilippe Mathieu-Daudé static const TypeInfo gt64120_pci_info = {
1267a7db759eSPhilippe Mathieu-Daudé .name = "gt64120_pci",
1268a7db759eSPhilippe Mathieu-Daudé .parent = TYPE_PCI_DEVICE,
1269a7db759eSPhilippe Mathieu-Daudé .instance_size = sizeof(PCIDevice),
1270a7db759eSPhilippe Mathieu-Daudé .class_init = gt64120_pci_class_init,
1271a7db759eSPhilippe Mathieu-Daudé .interfaces = (InterfaceInfo[]) {
1272a7db759eSPhilippe Mathieu-Daudé { INTERFACE_CONVENTIONAL_PCI_DEVICE },
1273a7db759eSPhilippe Mathieu-Daudé { },
1274a7db759eSPhilippe Mathieu-Daudé },
1275a7db759eSPhilippe Mathieu-Daudé };
1276a7db759eSPhilippe Mathieu-Daudé
1277a7db759eSPhilippe Mathieu-Daudé static Property gt64120_properties[] = {
1278a7db759eSPhilippe Mathieu-Daudé DEFINE_PROP_BOOL("cpu-little-endian", GT64120State,
1279a7db759eSPhilippe Mathieu-Daudé cpu_little_endian, false),
1280a7db759eSPhilippe Mathieu-Daudé DEFINE_PROP_END_OF_LIST(),
1281a7db759eSPhilippe Mathieu-Daudé };
1282a7db759eSPhilippe Mathieu-Daudé
gt64120_class_init(ObjectClass * klass,void * data)1283a7db759eSPhilippe Mathieu-Daudé static void gt64120_class_init(ObjectClass *klass, void *data)
1284a7db759eSPhilippe Mathieu-Daudé {
1285a7db759eSPhilippe Mathieu-Daudé DeviceClass *dc = DEVICE_CLASS(klass);
1286a7db759eSPhilippe Mathieu-Daudé
1287a7db759eSPhilippe Mathieu-Daudé set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
1288a7db759eSPhilippe Mathieu-Daudé device_class_set_props(dc, gt64120_properties);
1289a7db759eSPhilippe Mathieu-Daudé dc->realize = gt64120_realize;
1290*e3d08143SPeter Maydell device_class_set_legacy_reset(dc, gt64120_reset);
1291a7db759eSPhilippe Mathieu-Daudé dc->vmsd = &vmstate_gt64120;
1292a7db759eSPhilippe Mathieu-Daudé }
1293a7db759eSPhilippe Mathieu-Daudé
1294a7db759eSPhilippe Mathieu-Daudé static const TypeInfo gt64120_info = {
1295a7db759eSPhilippe Mathieu-Daudé .name = TYPE_GT64120_PCI_HOST_BRIDGE,
1296a7db759eSPhilippe Mathieu-Daudé .parent = TYPE_PCI_HOST_BRIDGE,
1297a7db759eSPhilippe Mathieu-Daudé .instance_size = sizeof(GT64120State),
1298a7db759eSPhilippe Mathieu-Daudé .class_init = gt64120_class_init,
1299a7db759eSPhilippe Mathieu-Daudé };
1300a7db759eSPhilippe Mathieu-Daudé
gt64120_pci_register_types(void)1301a7db759eSPhilippe Mathieu-Daudé static void gt64120_pci_register_types(void)
1302a7db759eSPhilippe Mathieu-Daudé {
1303a7db759eSPhilippe Mathieu-Daudé type_register_static(>64120_info);
1304a7db759eSPhilippe Mathieu-Daudé type_register_static(>64120_pci_info);
1305a7db759eSPhilippe Mathieu-Daudé }
1306a7db759eSPhilippe Mathieu-Daudé
1307a7db759eSPhilippe Mathieu-Daudé type_init(gt64120_pci_register_types)
1308