root / hw / bonito.c @ 0ef654e3
History | View | Annotate | Download (24.3 kB)
1 | d0f7453d | Huacai Chen | /*
|
---|---|---|---|
2 | d0f7453d | Huacai Chen | * bonito north bridge support
|
3 | d0f7453d | Huacai Chen | *
|
4 | d0f7453d | Huacai Chen | * Copyright (c) 2008 yajin (yajin@vm-kernel.org)
|
5 | d0f7453d | Huacai Chen | * Copyright (c) 2010 Huacai Chen (zltjiangshi@gmail.com)
|
6 | d0f7453d | Huacai Chen | *
|
7 | d0f7453d | Huacai Chen | * This code is licensed under the GNU GPL v2.
|
8 | 6b620ca3 | Paolo Bonzini | *
|
9 | 6b620ca3 | Paolo Bonzini | * Contributions after 2012-01-13 are licensed under the terms of the
|
10 | 6b620ca3 | Paolo Bonzini | * GNU GPL, version 2 or (at your option) any later version.
|
11 | d0f7453d | Huacai Chen | */
|
12 | d0f7453d | Huacai Chen | |
13 | d0f7453d | Huacai Chen | /*
|
14 | d0f7453d | Huacai Chen | * fulong 2e mini pc has a bonito north bridge.
|
15 | d0f7453d | Huacai Chen | */
|
16 | d0f7453d | Huacai Chen | |
17 | d0f7453d | Huacai Chen | /* what is the meaning of devfn in qemu and IDSEL in bonito northbridge?
|
18 | d0f7453d | Huacai Chen | *
|
19 | d0f7453d | Huacai Chen | * devfn pci_slot<<3 + funno
|
20 | d0f7453d | Huacai Chen | * one pci bus can have 32 devices and each device can have 8 functions.
|
21 | d0f7453d | Huacai Chen | *
|
22 | d0f7453d | Huacai Chen | * In bonito north bridge, pci slot = IDSEL bit - 12.
|
23 | d0f7453d | Huacai Chen | * For example, PCI_IDSEL_VIA686B = 17,
|
24 | d0f7453d | Huacai Chen | * pci slot = 17-12=5
|
25 | d0f7453d | Huacai Chen | *
|
26 | d0f7453d | Huacai Chen | * so
|
27 | d0f7453d | Huacai Chen | * VT686B_FUN0's devfn = (5<<3)+0
|
28 | d0f7453d | Huacai Chen | * VT686B_FUN1's devfn = (5<<3)+1
|
29 | d0f7453d | Huacai Chen | *
|
30 | d0f7453d | Huacai Chen | * qemu also uses pci address for north bridge to access pci config register.
|
31 | d0f7453d | Huacai Chen | * bus_no [23:16]
|
32 | d0f7453d | Huacai Chen | * dev_no [15:11]
|
33 | d0f7453d | Huacai Chen | * fun_no [10:8]
|
34 | d0f7453d | Huacai Chen | * reg_no [7:2]
|
35 | d0f7453d | Huacai Chen | *
|
36 | d0f7453d | Huacai Chen | * so function bonito_sbridge_pciaddr for the translation from
|
37 | d0f7453d | Huacai Chen | * north bridge address to pci address.
|
38 | d0f7453d | Huacai Chen | */
|
39 | d0f7453d | Huacai Chen | |
40 | d0f7453d | Huacai Chen | #include <assert.h> |
41 | d0f7453d | Huacai Chen | |
42 | d0f7453d | Huacai Chen | #include "hw.h" |
43 | d0f7453d | Huacai Chen | #include "pci.h" |
44 | d0f7453d | Huacai Chen | #include "pc.h" |
45 | d0f7453d | Huacai Chen | #include "mips.h" |
46 | d0f7453d | Huacai Chen | #include "pci_host.h" |
47 | d0f7453d | Huacai Chen | #include "sysemu.h" |
48 | 1e39101c | Avi Kivity | #include "exec-memory.h" |
49 | d0f7453d | Huacai Chen | |
50 | d0f7453d | Huacai Chen | //#define DEBUG_BONITO
|
51 | d0f7453d | Huacai Chen | |
52 | d0f7453d | Huacai Chen | #ifdef DEBUG_BONITO
|
53 | d0f7453d | Huacai Chen | #define DPRINTF(fmt, ...) fprintf(stderr, "%s: " fmt, __FUNCTION__, ##__VA_ARGS__) |
54 | d0f7453d | Huacai Chen | #else
|
55 | d0f7453d | Huacai Chen | #define DPRINTF(fmt, ...)
|
56 | d0f7453d | Huacai Chen | #endif
|
57 | d0f7453d | Huacai Chen | |
58 | d0f7453d | Huacai Chen | /* from linux soure code. include/asm-mips/mips-boards/bonito64.h*/
|
59 | d0f7453d | Huacai Chen | #define BONITO_BOOT_BASE 0x1fc00000 |
60 | d0f7453d | Huacai Chen | #define BONITO_BOOT_SIZE 0x00100000 |
61 | d0f7453d | Huacai Chen | #define BONITO_BOOT_TOP (BONITO_BOOT_BASE+BONITO_BOOT_SIZE-1) |
62 | d0f7453d | Huacai Chen | #define BONITO_FLASH_BASE 0x1c000000 |
63 | d0f7453d | Huacai Chen | #define BONITO_FLASH_SIZE 0x03000000 |
64 | d0f7453d | Huacai Chen | #define BONITO_FLASH_TOP (BONITO_FLASH_BASE+BONITO_FLASH_SIZE-1) |
65 | d0f7453d | Huacai Chen | #define BONITO_SOCKET_BASE 0x1f800000 |
66 | d0f7453d | Huacai Chen | #define BONITO_SOCKET_SIZE 0x00400000 |
67 | d0f7453d | Huacai Chen | #define BONITO_SOCKET_TOP (BONITO_SOCKET_BASE+BONITO_SOCKET_SIZE-1) |
68 | d0f7453d | Huacai Chen | #define BONITO_REG_BASE 0x1fe00000 |
69 | d0f7453d | Huacai Chen | #define BONITO_REG_SIZE 0x00040000 |
70 | d0f7453d | Huacai Chen | #define BONITO_REG_TOP (BONITO_REG_BASE+BONITO_REG_SIZE-1) |
71 | d0f7453d | Huacai Chen | #define BONITO_DEV_BASE 0x1ff00000 |
72 | d0f7453d | Huacai Chen | #define BONITO_DEV_SIZE 0x00100000 |
73 | d0f7453d | Huacai Chen | #define BONITO_DEV_TOP (BONITO_DEV_BASE+BONITO_DEV_SIZE-1) |
74 | d0f7453d | Huacai Chen | #define BONITO_PCILO_BASE 0x10000000 |
75 | d0f7453d | Huacai Chen | #define BONITO_PCILO_BASE_VA 0xb0000000 |
76 | d0f7453d | Huacai Chen | #define BONITO_PCILO_SIZE 0x0c000000 |
77 | d0f7453d | Huacai Chen | #define BONITO_PCILO_TOP (BONITO_PCILO_BASE+BONITO_PCILO_SIZE-1) |
78 | d0f7453d | Huacai Chen | #define BONITO_PCILO0_BASE 0x10000000 |
79 | d0f7453d | Huacai Chen | #define BONITO_PCILO1_BASE 0x14000000 |
80 | d0f7453d | Huacai Chen | #define BONITO_PCILO2_BASE 0x18000000 |
81 | d0f7453d | Huacai Chen | #define BONITO_PCIHI_BASE 0x20000000 |
82 | d0f7453d | Huacai Chen | #define BONITO_PCIHI_SIZE 0x20000000 |
83 | d0f7453d | Huacai Chen | #define BONITO_PCIHI_TOP (BONITO_PCIHI_BASE+BONITO_PCIHI_SIZE-1) |
84 | d0f7453d | Huacai Chen | #define BONITO_PCIIO_BASE 0x1fd00000 |
85 | d0f7453d | Huacai Chen | #define BONITO_PCIIO_BASE_VA 0xbfd00000 |
86 | d0f7453d | Huacai Chen | #define BONITO_PCIIO_SIZE 0x00010000 |
87 | d0f7453d | Huacai Chen | #define BONITO_PCIIO_TOP (BONITO_PCIIO_BASE+BONITO_PCIIO_SIZE-1) |
88 | d0f7453d | Huacai Chen | #define BONITO_PCICFG_BASE 0x1fe80000 |
89 | d0f7453d | Huacai Chen | #define BONITO_PCICFG_SIZE 0x00080000 |
90 | d0f7453d | Huacai Chen | #define BONITO_PCICFG_TOP (BONITO_PCICFG_BASE+BONITO_PCICFG_SIZE-1) |
91 | d0f7453d | Huacai Chen | |
92 | d0f7453d | Huacai Chen | |
93 | d0f7453d | Huacai Chen | #define BONITO_PCICONFIGBASE 0x00 |
94 | d0f7453d | Huacai Chen | #define BONITO_REGBASE 0x100 |
95 | d0f7453d | Huacai Chen | |
96 | d0f7453d | Huacai Chen | #define BONITO_PCICONFIG_BASE (BONITO_PCICONFIGBASE+BONITO_REG_BASE)
|
97 | d0f7453d | Huacai Chen | #define BONITO_PCICONFIG_SIZE (0x100) |
98 | d0f7453d | Huacai Chen | |
99 | d0f7453d | Huacai Chen | #define BONITO_INTERNAL_REG_BASE (BONITO_REGBASE+BONITO_REG_BASE)
|
100 | d0f7453d | Huacai Chen | #define BONITO_INTERNAL_REG_SIZE (0x70) |
101 | d0f7453d | Huacai Chen | |
102 | d0f7453d | Huacai Chen | #define BONITO_SPCICONFIG_BASE (BONITO_PCICFG_BASE)
|
103 | d0f7453d | Huacai Chen | #define BONITO_SPCICONFIG_SIZE (BONITO_PCICFG_SIZE)
|
104 | d0f7453d | Huacai Chen | |
105 | d0f7453d | Huacai Chen | |
106 | d0f7453d | Huacai Chen | |
107 | d0f7453d | Huacai Chen | /* 1. Bonito h/w Configuration */
|
108 | d0f7453d | Huacai Chen | /* Power on register */
|
109 | d0f7453d | Huacai Chen | |
110 | d0f7453d | Huacai Chen | #define BONITO_BONPONCFG (0x00 >> 2) /* 0x100 */ |
111 | d0f7453d | Huacai Chen | #define BONITO_BONGENCFG_OFFSET 0x4 |
112 | d0f7453d | Huacai Chen | #define BONITO_BONGENCFG (BONITO_BONGENCFG_OFFSET>>2) /*0x104 */ |
113 | d0f7453d | Huacai Chen | |
114 | d0f7453d | Huacai Chen | /* 2. IO & IDE configuration */
|
115 | d0f7453d | Huacai Chen | #define BONITO_IODEVCFG (0x08 >> 2) /* 0x108 */ |
116 | d0f7453d | Huacai Chen | |
117 | d0f7453d | Huacai Chen | /* 3. IO & IDE configuration */
|
118 | d0f7453d | Huacai Chen | #define BONITO_SDCFG (0x0c >> 2) /* 0x10c */ |
119 | d0f7453d | Huacai Chen | |
120 | d0f7453d | Huacai Chen | /* 4. PCI address map control */
|
121 | d0f7453d | Huacai Chen | #define BONITO_PCIMAP (0x10 >> 2) /* 0x110 */ |
122 | d0f7453d | Huacai Chen | #define BONITO_PCIMEMBASECFG (0x14 >> 2) /* 0x114 */ |
123 | d0f7453d | Huacai Chen | #define BONITO_PCIMAP_CFG (0x18 >> 2) /* 0x118 */ |
124 | d0f7453d | Huacai Chen | |
125 | d0f7453d | Huacai Chen | /* 5. ICU & GPIO regs */
|
126 | d0f7453d | Huacai Chen | /* GPIO Regs - r/w */
|
127 | d0f7453d | Huacai Chen | #define BONITO_GPIODATA_OFFSET 0x1c |
128 | d0f7453d | Huacai Chen | #define BONITO_GPIODATA (BONITO_GPIODATA_OFFSET >> 2) /* 0x11c */ |
129 | d0f7453d | Huacai Chen | #define BONITO_GPIOIE (0x20 >> 2) /* 0x120 */ |
130 | d0f7453d | Huacai Chen | |
131 | d0f7453d | Huacai Chen | /* ICU Configuration Regs - r/w */
|
132 | d0f7453d | Huacai Chen | #define BONITO_INTEDGE (0x24 >> 2) /* 0x124 */ |
133 | d0f7453d | Huacai Chen | #define BONITO_INTSTEER (0x28 >> 2) /* 0x128 */ |
134 | d0f7453d | Huacai Chen | #define BONITO_INTPOL (0x2c >> 2) /* 0x12c */ |
135 | d0f7453d | Huacai Chen | |
136 | d0f7453d | Huacai Chen | /* ICU Enable Regs - IntEn & IntISR are r/o. */
|
137 | d0f7453d | Huacai Chen | #define BONITO_INTENSET (0x30 >> 2) /* 0x130 */ |
138 | d0f7453d | Huacai Chen | #define BONITO_INTENCLR (0x34 >> 2) /* 0x134 */ |
139 | d0f7453d | Huacai Chen | #define BONITO_INTEN (0x38 >> 2) /* 0x138 */ |
140 | d0f7453d | Huacai Chen | #define BONITO_INTISR (0x3c >> 2) /* 0x13c */ |
141 | d0f7453d | Huacai Chen | |
142 | d0f7453d | Huacai Chen | /* PCI mail boxes */
|
143 | d0f7453d | Huacai Chen | #define BONITO_PCIMAIL0_OFFSET 0x40 |
144 | d0f7453d | Huacai Chen | #define BONITO_PCIMAIL1_OFFSET 0x44 |
145 | d0f7453d | Huacai Chen | #define BONITO_PCIMAIL2_OFFSET 0x48 |
146 | d0f7453d | Huacai Chen | #define BONITO_PCIMAIL3_OFFSET 0x4c |
147 | d0f7453d | Huacai Chen | #define BONITO_PCIMAIL0 (0x40 >> 2) /* 0x140 */ |
148 | d0f7453d | Huacai Chen | #define BONITO_PCIMAIL1 (0x44 >> 2) /* 0x144 */ |
149 | d0f7453d | Huacai Chen | #define BONITO_PCIMAIL2 (0x48 >> 2) /* 0x148 */ |
150 | d0f7453d | Huacai Chen | #define BONITO_PCIMAIL3 (0x4c >> 2) /* 0x14c */ |
151 | d0f7453d | Huacai Chen | |
152 | d0f7453d | Huacai Chen | /* 6. PCI cache */
|
153 | d0f7453d | Huacai Chen | #define BONITO_PCICACHECTRL (0x50 >> 2) /* 0x150 */ |
154 | d0f7453d | Huacai Chen | #define BONITO_PCICACHETAG (0x54 >> 2) /* 0x154 */ |
155 | d0f7453d | Huacai Chen | #define BONITO_PCIBADADDR (0x58 >> 2) /* 0x158 */ |
156 | d0f7453d | Huacai Chen | #define BONITO_PCIMSTAT (0x5c >> 2) /* 0x15c */ |
157 | d0f7453d | Huacai Chen | |
158 | d0f7453d | Huacai Chen | /* 7. other*/
|
159 | d0f7453d | Huacai Chen | #define BONITO_TIMECFG (0x60 >> 2) /* 0x160 */ |
160 | d0f7453d | Huacai Chen | #define BONITO_CPUCFG (0x64 >> 2) /* 0x164 */ |
161 | d0f7453d | Huacai Chen | #define BONITO_DQCFG (0x68 >> 2) /* 0x168 */ |
162 | d0f7453d | Huacai Chen | #define BONITO_MEMSIZE (0x6C >> 2) /* 0x16c */ |
163 | d0f7453d | Huacai Chen | |
164 | d0f7453d | Huacai Chen | #define BONITO_REGS (0x70 >> 2) |
165 | d0f7453d | Huacai Chen | |
166 | d0f7453d | Huacai Chen | /* PCI config for south bridge. type 0 */
|
167 | d0f7453d | Huacai Chen | #define BONITO_PCICONF_IDSEL_MASK 0xfffff800 /* [31:11] */ |
168 | d0f7453d | Huacai Chen | #define BONITO_PCICONF_IDSEL_OFFSET 11 |
169 | d0f7453d | Huacai Chen | #define BONITO_PCICONF_FUN_MASK 0x700 /* [10:8] */ |
170 | d0f7453d | Huacai Chen | #define BONITO_PCICONF_FUN_OFFSET 8 |
171 | d0f7453d | Huacai Chen | #define BONITO_PCICONF_REG_MASK 0xFC |
172 | d0f7453d | Huacai Chen | #define BONITO_PCICONF_REG_OFFSET 0 |
173 | d0f7453d | Huacai Chen | |
174 | d0f7453d | Huacai Chen | |
175 | d0f7453d | Huacai Chen | /* idsel BIT = pci slot number +12 */
|
176 | d0f7453d | Huacai Chen | #define PCI_SLOT_BASE 12 |
177 | d0f7453d | Huacai Chen | #define PCI_IDSEL_VIA686B_BIT (17) |
178 | d0f7453d | Huacai Chen | #define PCI_IDSEL_VIA686B (1<<PCI_IDSEL_VIA686B_BIT) |
179 | d0f7453d | Huacai Chen | |
180 | d0f7453d | Huacai Chen | #define PCI_ADDR(busno,devno,funno,regno) \
|
181 | d0f7453d | Huacai Chen | ((((busno)<<16)&0xff0000) + (((devno)<<11)&0xf800) + (((funno)<<8)&0x700) + (regno)) |
182 | d0f7453d | Huacai Chen | |
183 | d0f7453d | Huacai Chen | typedef PCIHostState BonitoState;
|
184 | d0f7453d | Huacai Chen | |
185 | d0f7453d | Huacai Chen | typedef struct PCIBonitoState |
186 | d0f7453d | Huacai Chen | { |
187 | d0f7453d | Huacai Chen | PCIDevice dev; |
188 | d0f7453d | Huacai Chen | BonitoState *pcihost; |
189 | d0f7453d | Huacai Chen | uint32_t regs[BONITO_REGS]; |
190 | d0f7453d | Huacai Chen | |
191 | d0f7453d | Huacai Chen | struct bonldma {
|
192 | d0f7453d | Huacai Chen | uint32_t ldmactrl; |
193 | d0f7453d | Huacai Chen | uint32_t ldmastat; |
194 | d0f7453d | Huacai Chen | uint32_t ldmaaddr; |
195 | d0f7453d | Huacai Chen | uint32_t ldmago; |
196 | d0f7453d | Huacai Chen | } bonldma; |
197 | d0f7453d | Huacai Chen | |
198 | d0f7453d | Huacai Chen | /* Based at 1fe00300, bonito Copier */
|
199 | d0f7453d | Huacai Chen | struct boncop {
|
200 | d0f7453d | Huacai Chen | uint32_t copctrl; |
201 | d0f7453d | Huacai Chen | uint32_t copstat; |
202 | d0f7453d | Huacai Chen | uint32_t coppaddr; |
203 | d0f7453d | Huacai Chen | uint32_t copgo; |
204 | d0f7453d | Huacai Chen | } boncop; |
205 | d0f7453d | Huacai Chen | |
206 | d0f7453d | Huacai Chen | /* Bonito registers */
|
207 | 89200979 | Benoît Canet | MemoryRegion iomem; |
208 | def344a6 | Benoît Canet | MemoryRegion iomem_ldma; |
209 | 9a542a48 | Benoît Canet | MemoryRegion iomem_cop; |
210 | d0f7453d | Huacai Chen | |
211 | d0f7453d | Huacai Chen | target_phys_addr_t bonito_pciio_start; |
212 | d0f7453d | Huacai Chen | target_phys_addr_t bonito_pciio_length; |
213 | d0f7453d | Huacai Chen | int bonito_pciio_handle;
|
214 | d0f7453d | Huacai Chen | |
215 | d0f7453d | Huacai Chen | target_phys_addr_t bonito_localio_start; |
216 | d0f7453d | Huacai Chen | target_phys_addr_t bonito_localio_length; |
217 | d0f7453d | Huacai Chen | int bonito_localio_handle;
|
218 | d0f7453d | Huacai Chen | |
219 | d0f7453d | Huacai Chen | } PCIBonitoState; |
220 | d0f7453d | Huacai Chen | |
221 | d0f7453d | Huacai Chen | PCIBonitoState * bonito_state; |
222 | d0f7453d | Huacai Chen | |
223 | 89200979 | Benoît Canet | static void bonito_writel(void *opaque, target_phys_addr_t addr, |
224 | 89200979 | Benoît Canet | uint64_t val, unsigned size)
|
225 | d0f7453d | Huacai Chen | { |
226 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
227 | d0f7453d | Huacai Chen | uint32_t saddr; |
228 | d0f7453d | Huacai Chen | int reset = 0; |
229 | d0f7453d | Huacai Chen | |
230 | d0f7453d | Huacai Chen | saddr = (addr - BONITO_REGBASE) >> 2;
|
231 | d0f7453d | Huacai Chen | |
232 | b2bedb21 | Stefan Weil | DPRINTF("bonito_writel "TARGET_FMT_plx" val %x saddr %x\n", addr, val, saddr); |
233 | d0f7453d | Huacai Chen | switch (saddr) {
|
234 | d0f7453d | Huacai Chen | case BONITO_BONPONCFG:
|
235 | d0f7453d | Huacai Chen | case BONITO_IODEVCFG:
|
236 | d0f7453d | Huacai Chen | case BONITO_SDCFG:
|
237 | d0f7453d | Huacai Chen | case BONITO_PCIMAP:
|
238 | d0f7453d | Huacai Chen | case BONITO_PCIMEMBASECFG:
|
239 | d0f7453d | Huacai Chen | case BONITO_PCIMAP_CFG:
|
240 | d0f7453d | Huacai Chen | case BONITO_GPIODATA:
|
241 | d0f7453d | Huacai Chen | case BONITO_GPIOIE:
|
242 | d0f7453d | Huacai Chen | case BONITO_INTEDGE:
|
243 | d0f7453d | Huacai Chen | case BONITO_INTSTEER:
|
244 | d0f7453d | Huacai Chen | case BONITO_INTPOL:
|
245 | d0f7453d | Huacai Chen | case BONITO_PCIMAIL0:
|
246 | d0f7453d | Huacai Chen | case BONITO_PCIMAIL1:
|
247 | d0f7453d | Huacai Chen | case BONITO_PCIMAIL2:
|
248 | d0f7453d | Huacai Chen | case BONITO_PCIMAIL3:
|
249 | d0f7453d | Huacai Chen | case BONITO_PCICACHECTRL:
|
250 | d0f7453d | Huacai Chen | case BONITO_PCICACHETAG:
|
251 | d0f7453d | Huacai Chen | case BONITO_PCIBADADDR:
|
252 | d0f7453d | Huacai Chen | case BONITO_PCIMSTAT:
|
253 | d0f7453d | Huacai Chen | case BONITO_TIMECFG:
|
254 | d0f7453d | Huacai Chen | case BONITO_CPUCFG:
|
255 | d0f7453d | Huacai Chen | case BONITO_DQCFG:
|
256 | d0f7453d | Huacai Chen | case BONITO_MEMSIZE:
|
257 | d0f7453d | Huacai Chen | s->regs[saddr] = val; |
258 | d0f7453d | Huacai Chen | break;
|
259 | d0f7453d | Huacai Chen | case BONITO_BONGENCFG:
|
260 | d0f7453d | Huacai Chen | if (!(s->regs[saddr] & 0x04) && (val & 0x04)) { |
261 | d0f7453d | Huacai Chen | reset = 1; /* bit 2 jump from 0 to 1 cause reset */ |
262 | d0f7453d | Huacai Chen | } |
263 | d0f7453d | Huacai Chen | s->regs[saddr] = val; |
264 | d0f7453d | Huacai Chen | if (reset) {
|
265 | d0f7453d | Huacai Chen | qemu_system_reset_request(); |
266 | d0f7453d | Huacai Chen | } |
267 | d0f7453d | Huacai Chen | break;
|
268 | d0f7453d | Huacai Chen | case BONITO_INTENSET:
|
269 | d0f7453d | Huacai Chen | s->regs[BONITO_INTENSET] = val; |
270 | d0f7453d | Huacai Chen | s->regs[BONITO_INTEN] |= val; |
271 | d0f7453d | Huacai Chen | break;
|
272 | d0f7453d | Huacai Chen | case BONITO_INTENCLR:
|
273 | d0f7453d | Huacai Chen | s->regs[BONITO_INTENCLR] = val; |
274 | d0f7453d | Huacai Chen | s->regs[BONITO_INTEN] &= ~val; |
275 | d0f7453d | Huacai Chen | break;
|
276 | d0f7453d | Huacai Chen | case BONITO_INTEN:
|
277 | d0f7453d | Huacai Chen | case BONITO_INTISR:
|
278 | b2bedb21 | Stefan Weil | DPRINTF("write to readonly bonito register %x\n", saddr);
|
279 | d0f7453d | Huacai Chen | break;
|
280 | d0f7453d | Huacai Chen | default:
|
281 | b2bedb21 | Stefan Weil | DPRINTF("write to unknown bonito register %x\n", saddr);
|
282 | d0f7453d | Huacai Chen | break;
|
283 | d0f7453d | Huacai Chen | } |
284 | d0f7453d | Huacai Chen | } |
285 | d0f7453d | Huacai Chen | |
286 | 89200979 | Benoît Canet | static uint64_t bonito_readl(void *opaque, target_phys_addr_t addr, |
287 | 89200979 | Benoît Canet | unsigned size)
|
288 | d0f7453d | Huacai Chen | { |
289 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
290 | d0f7453d | Huacai Chen | uint32_t saddr; |
291 | d0f7453d | Huacai Chen | |
292 | d0f7453d | Huacai Chen | saddr = (addr - BONITO_REGBASE) >> 2;
|
293 | d0f7453d | Huacai Chen | |
294 | b2bedb21 | Stefan Weil | DPRINTF("bonito_readl "TARGET_FMT_plx"\n", addr); |
295 | d0f7453d | Huacai Chen | switch (saddr) {
|
296 | d0f7453d | Huacai Chen | case BONITO_INTISR:
|
297 | d0f7453d | Huacai Chen | return s->regs[saddr];
|
298 | d0f7453d | Huacai Chen | default:
|
299 | d0f7453d | Huacai Chen | return s->regs[saddr];
|
300 | d0f7453d | Huacai Chen | } |
301 | d0f7453d | Huacai Chen | } |
302 | d0f7453d | Huacai Chen | |
303 | 89200979 | Benoît Canet | static const MemoryRegionOps bonito_ops = { |
304 | 89200979 | Benoît Canet | .read = bonito_readl, |
305 | 89200979 | Benoît Canet | .write = bonito_writel, |
306 | 89200979 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
307 | 89200979 | Benoît Canet | .valid = { |
308 | 89200979 | Benoît Canet | .min_access_size = 4,
|
309 | 89200979 | Benoît Canet | .max_access_size = 4,
|
310 | 89200979 | Benoît Canet | }, |
311 | d0f7453d | Huacai Chen | }; |
312 | d0f7453d | Huacai Chen | |
313 | d0f7453d | Huacai Chen | static void bonito_pciconf_writel(void *opaque, target_phys_addr_t addr, |
314 | 183e1d40 | Benoît Canet | uint64_t val, unsigned size)
|
315 | d0f7453d | Huacai Chen | { |
316 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
317 | d0f7453d | Huacai Chen | |
318 | b2bedb21 | Stefan Weil | DPRINTF("bonito_pciconf_writel "TARGET_FMT_plx" val %x\n", addr, val); |
319 | d0f7453d | Huacai Chen | s->dev.config_write(&s->dev, addr, val, 4);
|
320 | d0f7453d | Huacai Chen | } |
321 | d0f7453d | Huacai Chen | |
322 | 183e1d40 | Benoît Canet | static uint64_t bonito_pciconf_readl(void *opaque, target_phys_addr_t addr, |
323 | 183e1d40 | Benoît Canet | unsigned size)
|
324 | d0f7453d | Huacai Chen | { |
325 | d0f7453d | Huacai Chen | |
326 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
327 | d0f7453d | Huacai Chen | |
328 | d0f7453d | Huacai Chen | DPRINTF("bonito_pciconf_readl "TARGET_FMT_plx"\n", addr); |
329 | d0f7453d | Huacai Chen | return s->dev.config_read(&s->dev, addr, 4); |
330 | d0f7453d | Huacai Chen | } |
331 | d0f7453d | Huacai Chen | |
332 | d0f7453d | Huacai Chen | /* north bridge PCI configure space. 0x1fe0 0000 - 0x1fe0 00ff */
|
333 | d0f7453d | Huacai Chen | |
334 | 183e1d40 | Benoît Canet | static const MemoryRegionOps bonito_pciconf_ops = { |
335 | 183e1d40 | Benoît Canet | .read = bonito_pciconf_readl, |
336 | 183e1d40 | Benoît Canet | .write = bonito_pciconf_writel, |
337 | 183e1d40 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
338 | 183e1d40 | Benoît Canet | .valid = { |
339 | 183e1d40 | Benoît Canet | .min_access_size = 4,
|
340 | 183e1d40 | Benoît Canet | .max_access_size = 4,
|
341 | 183e1d40 | Benoît Canet | }, |
342 | d0f7453d | Huacai Chen | }; |
343 | d0f7453d | Huacai Chen | |
344 | def344a6 | Benoît Canet | static uint64_t bonito_ldma_readl(void *opaque, target_phys_addr_t addr, |
345 | def344a6 | Benoît Canet | unsigned size)
|
346 | d0f7453d | Huacai Chen | { |
347 | d0f7453d | Huacai Chen | uint32_t val; |
348 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
349 | d0f7453d | Huacai Chen | |
350 | d0f7453d | Huacai Chen | val = ((uint32_t *)(&s->bonldma))[addr/sizeof(uint32_t)];
|
351 | d0f7453d | Huacai Chen | |
352 | d0f7453d | Huacai Chen | return val;
|
353 | d0f7453d | Huacai Chen | } |
354 | d0f7453d | Huacai Chen | |
355 | d0f7453d | Huacai Chen | static void bonito_ldma_writel(void *opaque, target_phys_addr_t addr, |
356 | def344a6 | Benoît Canet | uint64_t val, unsigned size)
|
357 | d0f7453d | Huacai Chen | { |
358 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
359 | d0f7453d | Huacai Chen | |
360 | d0f7453d | Huacai Chen | ((uint32_t *)(&s->bonldma))[addr/sizeof(uint32_t)] = val & 0xffffffff; |
361 | d0f7453d | Huacai Chen | } |
362 | d0f7453d | Huacai Chen | |
363 | def344a6 | Benoît Canet | static const MemoryRegionOps bonito_ldma_ops = { |
364 | def344a6 | Benoît Canet | .read = bonito_ldma_readl, |
365 | def344a6 | Benoît Canet | .write = bonito_ldma_writel, |
366 | def344a6 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
367 | def344a6 | Benoît Canet | .valid = { |
368 | def344a6 | Benoît Canet | .min_access_size = 4,
|
369 | def344a6 | Benoît Canet | .max_access_size = 4,
|
370 | def344a6 | Benoît Canet | }, |
371 | d0f7453d | Huacai Chen | }; |
372 | d0f7453d | Huacai Chen | |
373 | 9a542a48 | Benoît Canet | static uint64_t bonito_cop_readl(void *opaque, target_phys_addr_t addr, |
374 | 9a542a48 | Benoît Canet | unsigned size)
|
375 | d0f7453d | Huacai Chen | { |
376 | d0f7453d | Huacai Chen | uint32_t val; |
377 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
378 | d0f7453d | Huacai Chen | |
379 | d0f7453d | Huacai Chen | val = ((uint32_t *)(&s->boncop))[addr/sizeof(uint32_t)];
|
380 | d0f7453d | Huacai Chen | |
381 | d0f7453d | Huacai Chen | return val;
|
382 | d0f7453d | Huacai Chen | } |
383 | d0f7453d | Huacai Chen | |
384 | d0f7453d | Huacai Chen | static void bonito_cop_writel(void *opaque, target_phys_addr_t addr, |
385 | 9a542a48 | Benoît Canet | uint64_t val, unsigned size)
|
386 | d0f7453d | Huacai Chen | { |
387 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
388 | d0f7453d | Huacai Chen | |
389 | d0f7453d | Huacai Chen | ((uint32_t *)(&s->boncop))[addr/sizeof(uint32_t)] = val & 0xffffffff; |
390 | d0f7453d | Huacai Chen | } |
391 | d0f7453d | Huacai Chen | |
392 | 9a542a48 | Benoît Canet | static const MemoryRegionOps bonito_cop_ops = { |
393 | 9a542a48 | Benoît Canet | .read = bonito_cop_readl, |
394 | 9a542a48 | Benoît Canet | .write = bonito_cop_writel, |
395 | 9a542a48 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
396 | 9a542a48 | Benoît Canet | .valid = { |
397 | 9a542a48 | Benoît Canet | .min_access_size = 4,
|
398 | 9a542a48 | Benoît Canet | .max_access_size = 4,
|
399 | 9a542a48 | Benoît Canet | }, |
400 | d0f7453d | Huacai Chen | }; |
401 | d0f7453d | Huacai Chen | |
402 | d0f7453d | Huacai Chen | static uint32_t bonito_sbridge_pciaddr(void *opaque, target_phys_addr_t addr) |
403 | d0f7453d | Huacai Chen | { |
404 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
405 | d0f7453d | Huacai Chen | uint32_t cfgaddr; |
406 | d0f7453d | Huacai Chen | uint32_t idsel; |
407 | d0f7453d | Huacai Chen | uint32_t devno; |
408 | d0f7453d | Huacai Chen | uint32_t funno; |
409 | d0f7453d | Huacai Chen | uint32_t regno; |
410 | d0f7453d | Huacai Chen | uint32_t pciaddr; |
411 | d0f7453d | Huacai Chen | |
412 | d0f7453d | Huacai Chen | /* support type0 pci config */
|
413 | d0f7453d | Huacai Chen | if ((s->regs[BONITO_PCIMAP_CFG] & 0x10000) != 0x0) { |
414 | d0f7453d | Huacai Chen | return 0xffffffff; |
415 | d0f7453d | Huacai Chen | } |
416 | d0f7453d | Huacai Chen | |
417 | d0f7453d | Huacai Chen | cfgaddr = addr & 0xffff;
|
418 | d0f7453d | Huacai Chen | cfgaddr |= (s->regs[BONITO_PCIMAP_CFG] & 0xffff) << 16; |
419 | d0f7453d | Huacai Chen | |
420 | d0f7453d | Huacai Chen | idsel = (cfgaddr & BONITO_PCICONF_IDSEL_MASK) >> BONITO_PCICONF_IDSEL_OFFSET; |
421 | d0f7453d | Huacai Chen | devno = ffs(idsel) - 1;
|
422 | d0f7453d | Huacai Chen | funno = (cfgaddr & BONITO_PCICONF_FUN_MASK) >> BONITO_PCICONF_FUN_OFFSET; |
423 | d0f7453d | Huacai Chen | regno = (cfgaddr & BONITO_PCICONF_REG_MASK) >> BONITO_PCICONF_REG_OFFSET; |
424 | d0f7453d | Huacai Chen | |
425 | d0f7453d | Huacai Chen | if (idsel == 0) { |
426 | d0f7453d | Huacai Chen | fprintf(stderr, "error in bonito pci config address" TARGET_FMT_plx
|
427 | d0f7453d | Huacai Chen | ",pcimap_cfg=%x\n", addr, s->regs[BONITO_PCIMAP_CFG]);
|
428 | d0f7453d | Huacai Chen | exit(1);
|
429 | d0f7453d | Huacai Chen | } |
430 | d0f7453d | Huacai Chen | pciaddr = PCI_ADDR(pci_bus_num(s->pcihost->bus), devno, funno, regno); |
431 | b2bedb21 | Stefan Weil | DPRINTF("cfgaddr %x pciaddr %x busno %x devno %d funno %d regno %d\n",
|
432 | d0f7453d | Huacai Chen | cfgaddr, pciaddr, pci_bus_num(s->pcihost->bus), devno, funno, regno); |
433 | d0f7453d | Huacai Chen | |
434 | d0f7453d | Huacai Chen | return pciaddr;
|
435 | d0f7453d | Huacai Chen | } |
436 | d0f7453d | Huacai Chen | |
437 | d0f7453d | Huacai Chen | static void bonito_spciconf_writeb(void *opaque, target_phys_addr_t addr, |
438 | d0f7453d | Huacai Chen | uint32_t val) |
439 | d0f7453d | Huacai Chen | { |
440 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
441 | d0f7453d | Huacai Chen | uint32_t pciaddr; |
442 | d0f7453d | Huacai Chen | uint16_t status; |
443 | d0f7453d | Huacai Chen | |
444 | b2bedb21 | Stefan Weil | DPRINTF("bonito_spciconf_writeb "TARGET_FMT_plx" val %x\n", addr, val); |
445 | d0f7453d | Huacai Chen | pciaddr = bonito_sbridge_pciaddr(s, addr); |
446 | d0f7453d | Huacai Chen | |
447 | d0f7453d | Huacai Chen | if (pciaddr == 0xffffffff) { |
448 | d0f7453d | Huacai Chen | return;
|
449 | d0f7453d | Huacai Chen | } |
450 | d0f7453d | Huacai Chen | |
451 | d0f7453d | Huacai Chen | /* set the pci address in s->config_reg */
|
452 | d0f7453d | Huacai Chen | s->pcihost->config_reg = (pciaddr) | (1u << 31); |
453 | d0f7453d | Huacai Chen | pci_data_write(s->pcihost->bus, s->pcihost->config_reg, val & 0xff, 1); |
454 | d0f7453d | Huacai Chen | |
455 | d0f7453d | Huacai Chen | /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */
|
456 | d0f7453d | Huacai Chen | status = pci_get_word(s->dev.config + PCI_STATUS); |
457 | d0f7453d | Huacai Chen | status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); |
458 | d0f7453d | Huacai Chen | pci_set_word(s->dev.config + PCI_STATUS, status); |
459 | d0f7453d | Huacai Chen | } |
460 | d0f7453d | Huacai Chen | |
461 | d0f7453d | Huacai Chen | static void bonito_spciconf_writew(void *opaque, target_phys_addr_t addr, |
462 | d0f7453d | Huacai Chen | uint32_t val) |
463 | d0f7453d | Huacai Chen | { |
464 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
465 | d0f7453d | Huacai Chen | uint32_t pciaddr; |
466 | d0f7453d | Huacai Chen | uint16_t status; |
467 | d0f7453d | Huacai Chen | |
468 | b2bedb21 | Stefan Weil | DPRINTF("bonito_spciconf_writew "TARGET_FMT_plx" val %x\n", addr, val); |
469 | d0f7453d | Huacai Chen | assert((addr&0x1)==0); |
470 | d0f7453d | Huacai Chen | |
471 | d0f7453d | Huacai Chen | pciaddr = bonito_sbridge_pciaddr(s, addr); |
472 | d0f7453d | Huacai Chen | |
473 | d0f7453d | Huacai Chen | if (pciaddr == 0xffffffff) { |
474 | d0f7453d | Huacai Chen | return;
|
475 | d0f7453d | Huacai Chen | } |
476 | d0f7453d | Huacai Chen | |
477 | d0f7453d | Huacai Chen | /* set the pci address in s->config_reg */
|
478 | d0f7453d | Huacai Chen | s->pcihost->config_reg = (pciaddr) | (1u << 31); |
479 | d0f7453d | Huacai Chen | pci_data_write(s->pcihost->bus, s->pcihost->config_reg, val, 2);
|
480 | d0f7453d | Huacai Chen | |
481 | d0f7453d | Huacai Chen | /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */
|
482 | d0f7453d | Huacai Chen | status = pci_get_word(s->dev.config + PCI_STATUS); |
483 | d0f7453d | Huacai Chen | status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); |
484 | d0f7453d | Huacai Chen | pci_set_word(s->dev.config + PCI_STATUS, status); |
485 | d0f7453d | Huacai Chen | } |
486 | d0f7453d | Huacai Chen | |
487 | d0f7453d | Huacai Chen | static void bonito_spciconf_writel(void *opaque, target_phys_addr_t addr, |
488 | d0f7453d | Huacai Chen | uint32_t val) |
489 | d0f7453d | Huacai Chen | { |
490 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
491 | d0f7453d | Huacai Chen | uint32_t pciaddr; |
492 | d0f7453d | Huacai Chen | uint16_t status; |
493 | d0f7453d | Huacai Chen | |
494 | b2bedb21 | Stefan Weil | DPRINTF("bonito_spciconf_writel "TARGET_FMT_plx" val %x\n", addr, val); |
495 | d0f7453d | Huacai Chen | assert((addr&0x3)==0); |
496 | d0f7453d | Huacai Chen | |
497 | d0f7453d | Huacai Chen | pciaddr = bonito_sbridge_pciaddr(s, addr); |
498 | d0f7453d | Huacai Chen | |
499 | d0f7453d | Huacai Chen | if (pciaddr == 0xffffffff) { |
500 | d0f7453d | Huacai Chen | return;
|
501 | d0f7453d | Huacai Chen | } |
502 | d0f7453d | Huacai Chen | |
503 | d0f7453d | Huacai Chen | /* set the pci address in s->config_reg */
|
504 | d0f7453d | Huacai Chen | s->pcihost->config_reg = (pciaddr) | (1u << 31); |
505 | d0f7453d | Huacai Chen | pci_data_write(s->pcihost->bus, s->pcihost->config_reg, val, 4);
|
506 | d0f7453d | Huacai Chen | |
507 | d0f7453d | Huacai Chen | /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */
|
508 | d0f7453d | Huacai Chen | status = pci_get_word(s->dev.config + PCI_STATUS); |
509 | d0f7453d | Huacai Chen | status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); |
510 | d0f7453d | Huacai Chen | pci_set_word(s->dev.config + PCI_STATUS, status); |
511 | d0f7453d | Huacai Chen | } |
512 | d0f7453d | Huacai Chen | |
513 | d0f7453d | Huacai Chen | static uint32_t bonito_spciconf_readb(void *opaque, target_phys_addr_t addr) |
514 | d0f7453d | Huacai Chen | { |
515 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
516 | d0f7453d | Huacai Chen | uint32_t pciaddr; |
517 | d0f7453d | Huacai Chen | uint16_t status; |
518 | d0f7453d | Huacai Chen | |
519 | b2bedb21 | Stefan Weil | DPRINTF("bonito_spciconf_readb "TARGET_FMT_plx"\n", addr); |
520 | d0f7453d | Huacai Chen | pciaddr = bonito_sbridge_pciaddr(s, addr); |
521 | d0f7453d | Huacai Chen | |
522 | d0f7453d | Huacai Chen | if (pciaddr == 0xffffffff) { |
523 | d0f7453d | Huacai Chen | return 0xff; |
524 | d0f7453d | Huacai Chen | } |
525 | d0f7453d | Huacai Chen | |
526 | d0f7453d | Huacai Chen | /* set the pci address in s->config_reg */
|
527 | d0f7453d | Huacai Chen | s->pcihost->config_reg = (pciaddr) | (1u << 31); |
528 | d0f7453d | Huacai Chen | |
529 | d0f7453d | Huacai Chen | /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */
|
530 | d0f7453d | Huacai Chen | status = pci_get_word(s->dev.config + PCI_STATUS); |
531 | d0f7453d | Huacai Chen | status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); |
532 | d0f7453d | Huacai Chen | pci_set_word(s->dev.config + PCI_STATUS, status); |
533 | d0f7453d | Huacai Chen | |
534 | d0f7453d | Huacai Chen | return pci_data_read(s->pcihost->bus, s->pcihost->config_reg, 1); |
535 | d0f7453d | Huacai Chen | } |
536 | d0f7453d | Huacai Chen | |
537 | d0f7453d | Huacai Chen | static uint32_t bonito_spciconf_readw(void *opaque, target_phys_addr_t addr) |
538 | d0f7453d | Huacai Chen | { |
539 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
540 | d0f7453d | Huacai Chen | uint32_t pciaddr; |
541 | d0f7453d | Huacai Chen | uint16_t status; |
542 | d0f7453d | Huacai Chen | |
543 | b2bedb21 | Stefan Weil | DPRINTF("bonito_spciconf_readw "TARGET_FMT_plx"\n", addr); |
544 | d0f7453d | Huacai Chen | assert((addr&0x1)==0); |
545 | d0f7453d | Huacai Chen | |
546 | d0f7453d | Huacai Chen | pciaddr = bonito_sbridge_pciaddr(s, addr); |
547 | d0f7453d | Huacai Chen | |
548 | d0f7453d | Huacai Chen | if (pciaddr == 0xffffffff) { |
549 | d0f7453d | Huacai Chen | return 0xffff; |
550 | d0f7453d | Huacai Chen | } |
551 | d0f7453d | Huacai Chen | |
552 | d0f7453d | Huacai Chen | /* set the pci address in s->config_reg */
|
553 | d0f7453d | Huacai Chen | s->pcihost->config_reg = (pciaddr) | (1u << 31); |
554 | d0f7453d | Huacai Chen | |
555 | d0f7453d | Huacai Chen | /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */
|
556 | d0f7453d | Huacai Chen | status = pci_get_word(s->dev.config + PCI_STATUS); |
557 | d0f7453d | Huacai Chen | status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); |
558 | d0f7453d | Huacai Chen | pci_set_word(s->dev.config + PCI_STATUS, status); |
559 | d0f7453d | Huacai Chen | |
560 | d0f7453d | Huacai Chen | return pci_data_read(s->pcihost->bus, s->pcihost->config_reg, 2); |
561 | d0f7453d | Huacai Chen | } |
562 | d0f7453d | Huacai Chen | |
563 | d0f7453d | Huacai Chen | static uint32_t bonito_spciconf_readl(void *opaque, target_phys_addr_t addr) |
564 | d0f7453d | Huacai Chen | { |
565 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
566 | d0f7453d | Huacai Chen | uint32_t pciaddr; |
567 | d0f7453d | Huacai Chen | uint16_t status; |
568 | d0f7453d | Huacai Chen | |
569 | b2bedb21 | Stefan Weil | DPRINTF("bonito_spciconf_readl "TARGET_FMT_plx"\n", addr); |
570 | d0f7453d | Huacai Chen | assert((addr&0x3) == 0); |
571 | d0f7453d | Huacai Chen | |
572 | d0f7453d | Huacai Chen | pciaddr = bonito_sbridge_pciaddr(s, addr); |
573 | d0f7453d | Huacai Chen | |
574 | d0f7453d | Huacai Chen | if (pciaddr == 0xffffffff) { |
575 | d0f7453d | Huacai Chen | return 0xffffffff; |
576 | d0f7453d | Huacai Chen | } |
577 | d0f7453d | Huacai Chen | |
578 | d0f7453d | Huacai Chen | /* set the pci address in s->config_reg */
|
579 | d0f7453d | Huacai Chen | s->pcihost->config_reg = (pciaddr) | (1u << 31); |
580 | d0f7453d | Huacai Chen | |
581 | d0f7453d | Huacai Chen | /* clear PCI_STATUS_REC_MASTER_ABORT and PCI_STATUS_REC_TARGET_ABORT */
|
582 | d0f7453d | Huacai Chen | status = pci_get_word(s->dev.config + PCI_STATUS); |
583 | d0f7453d | Huacai Chen | status &= ~(PCI_STATUS_REC_MASTER_ABORT | PCI_STATUS_REC_TARGET_ABORT); |
584 | d0f7453d | Huacai Chen | pci_set_word(s->dev.config + PCI_STATUS, status); |
585 | d0f7453d | Huacai Chen | |
586 | d0f7453d | Huacai Chen | return pci_data_read(s->pcihost->bus, s->pcihost->config_reg, 4); |
587 | d0f7453d | Huacai Chen | } |
588 | d0f7453d | Huacai Chen | |
589 | d0f7453d | Huacai Chen | /* south bridge PCI configure space. 0x1fe8 0000 - 0x1fef ffff */
|
590 | 845cbeb8 | Benoît Canet | static const MemoryRegionOps bonito_spciconf_ops = { |
591 | 845cbeb8 | Benoît Canet | .old_mmio = { |
592 | 845cbeb8 | Benoît Canet | .read = { |
593 | 845cbeb8 | Benoît Canet | bonito_spciconf_readb, |
594 | 845cbeb8 | Benoît Canet | bonito_spciconf_readw, |
595 | 845cbeb8 | Benoît Canet | bonito_spciconf_readl, |
596 | 845cbeb8 | Benoît Canet | }, |
597 | 845cbeb8 | Benoît Canet | .write = { |
598 | 845cbeb8 | Benoît Canet | bonito_spciconf_writeb, |
599 | 845cbeb8 | Benoît Canet | bonito_spciconf_writew, |
600 | 845cbeb8 | Benoît Canet | bonito_spciconf_writel, |
601 | 845cbeb8 | Benoît Canet | }, |
602 | 845cbeb8 | Benoît Canet | }, |
603 | 845cbeb8 | Benoît Canet | .endianness = DEVICE_NATIVE_ENDIAN, |
604 | d0f7453d | Huacai Chen | }; |
605 | d0f7453d | Huacai Chen | |
606 | d0f7453d | Huacai Chen | #define BONITO_IRQ_BASE 32 |
607 | d0f7453d | Huacai Chen | |
608 | d0f7453d | Huacai Chen | static void pci_bonito_set_irq(void *opaque, int irq_num, int level) |
609 | d0f7453d | Huacai Chen | { |
610 | d0f7453d | Huacai Chen | qemu_irq *pic = opaque; |
611 | d0f7453d | Huacai Chen | int internal_irq = irq_num - BONITO_IRQ_BASE;
|
612 | d0f7453d | Huacai Chen | |
613 | d0f7453d | Huacai Chen | if (bonito_state->regs[BONITO_INTEDGE] & (1<<internal_irq)) { |
614 | d0f7453d | Huacai Chen | qemu_irq_pulse(*pic); |
615 | d0f7453d | Huacai Chen | } else { /* level triggered */ |
616 | d0f7453d | Huacai Chen | if (bonito_state->regs[BONITO_INTPOL] & (1<<internal_irq)) { |
617 | d0f7453d | Huacai Chen | qemu_irq_raise(*pic); |
618 | d0f7453d | Huacai Chen | } else {
|
619 | d0f7453d | Huacai Chen | qemu_irq_lower(*pic); |
620 | d0f7453d | Huacai Chen | } |
621 | d0f7453d | Huacai Chen | } |
622 | d0f7453d | Huacai Chen | } |
623 | d0f7453d | Huacai Chen | |
624 | d0f7453d | Huacai Chen | /* map the original irq (0~3) to bonito irq (16~47, but 16~31 are unused) */
|
625 | d0f7453d | Huacai Chen | static int pci_bonito_map_irq(PCIDevice * pci_dev, int irq_num) |
626 | d0f7453d | Huacai Chen | { |
627 | d0f7453d | Huacai Chen | int slot;
|
628 | d0f7453d | Huacai Chen | |
629 | d0f7453d | Huacai Chen | slot = (pci_dev->devfn >> 3);
|
630 | d0f7453d | Huacai Chen | |
631 | d0f7453d | Huacai Chen | switch (slot) {
|
632 | d0f7453d | Huacai Chen | case 5: /* FULONG2E_VIA_SLOT, SouthBridge, IDE, USB, ACPI, AC97, MC97 */ |
633 | d0f7453d | Huacai Chen | return irq_num % 4 + BONITO_IRQ_BASE; |
634 | d0f7453d | Huacai Chen | case 6: /* FULONG2E_ATI_SLOT, VGA */ |
635 | d0f7453d | Huacai Chen | return 4 + BONITO_IRQ_BASE; |
636 | d0f7453d | Huacai Chen | case 7: /* FULONG2E_RTL_SLOT, RTL8139 */ |
637 | d0f7453d | Huacai Chen | return 5 + BONITO_IRQ_BASE; |
638 | d0f7453d | Huacai Chen | case 8 ... 12: /* PCI slot 1 to 4 */ |
639 | d0f7453d | Huacai Chen | return (slot - 8 + irq_num) + 6 + BONITO_IRQ_BASE; |
640 | d0f7453d | Huacai Chen | default: /* Unknown device, don't do any translation */ |
641 | d0f7453d | Huacai Chen | return irq_num;
|
642 | d0f7453d | Huacai Chen | } |
643 | d0f7453d | Huacai Chen | } |
644 | d0f7453d | Huacai Chen | |
645 | d0f7453d | Huacai Chen | static void bonito_reset(void *opaque) |
646 | d0f7453d | Huacai Chen | { |
647 | d0f7453d | Huacai Chen | PCIBonitoState *s = opaque; |
648 | d0f7453d | Huacai Chen | |
649 | d0f7453d | Huacai Chen | /* set the default value of north bridge registers */
|
650 | d0f7453d | Huacai Chen | |
651 | d0f7453d | Huacai Chen | s->regs[BONITO_BONPONCFG] = 0xc40;
|
652 | d0f7453d | Huacai Chen | s->regs[BONITO_BONGENCFG] = 0x1384;
|
653 | d0f7453d | Huacai Chen | s->regs[BONITO_IODEVCFG] = 0x2bff8010;
|
654 | d0f7453d | Huacai Chen | s->regs[BONITO_SDCFG] = 0x255e0091;
|
655 | d0f7453d | Huacai Chen | |
656 | d0f7453d | Huacai Chen | s->regs[BONITO_GPIODATA] = 0x1ff;
|
657 | d0f7453d | Huacai Chen | s->regs[BONITO_GPIOIE] = 0x1ff;
|
658 | d0f7453d | Huacai Chen | s->regs[BONITO_DQCFG] = 0x8;
|
659 | d0f7453d | Huacai Chen | s->regs[BONITO_MEMSIZE] = 0x10000000;
|
660 | d0f7453d | Huacai Chen | s->regs[BONITO_PCIMAP] = 0x6140;
|
661 | d0f7453d | Huacai Chen | } |
662 | d0f7453d | Huacai Chen | |
663 | d0f7453d | Huacai Chen | static const VMStateDescription vmstate_bonito = { |
664 | d0f7453d | Huacai Chen | .name = "Bonito",
|
665 | d0f7453d | Huacai Chen | .version_id = 1,
|
666 | d0f7453d | Huacai Chen | .minimum_version_id = 1,
|
667 | d0f7453d | Huacai Chen | .minimum_version_id_old = 1,
|
668 | d0f7453d | Huacai Chen | .fields = (VMStateField []) { |
669 | d0f7453d | Huacai Chen | VMSTATE_PCI_DEVICE(dev, PCIBonitoState), |
670 | d0f7453d | Huacai Chen | VMSTATE_END_OF_LIST() |
671 | d0f7453d | Huacai Chen | } |
672 | d0f7453d | Huacai Chen | }; |
673 | d0f7453d | Huacai Chen | |
674 | d0f7453d | Huacai Chen | static int bonito_pcihost_initfn(SysBusDevice *dev) |
675 | d0f7453d | Huacai Chen | { |
676 | d0f7453d | Huacai Chen | return 0; |
677 | d0f7453d | Huacai Chen | } |
678 | d0f7453d | Huacai Chen | |
679 | d0f7453d | Huacai Chen | static int bonito_initfn(PCIDevice *dev) |
680 | d0f7453d | Huacai Chen | { |
681 | d0f7453d | Huacai Chen | PCIBonitoState *s = DO_UPCAST(PCIBonitoState, dev, dev); |
682 | 89200979 | Benoît Canet | SysBusDevice *sysbus = &s->pcihost->busdev; |
683 | d0f7453d | Huacai Chen | |
684 | d0f7453d | Huacai Chen | /* Bonito North Bridge, built on FPGA, VENDOR_ID/DEVICE_ID are "undefined" */
|
685 | d0f7453d | Huacai Chen | pci_config_set_prog_interface(dev->config, 0x00);
|
686 | d0f7453d | Huacai Chen | |
687 | d0f7453d | Huacai Chen | /* set the north bridge register mapping */
|
688 | 89200979 | Benoît Canet | memory_region_init_io(&s->iomem, &bonito_ops, s, |
689 | 89200979 | Benoît Canet | "north-bridge-register", BONITO_INTERNAL_REG_SIZE);
|
690 | 750ecd44 | Avi Kivity | sysbus_init_mmio(sysbus, &s->iomem); |
691 | 89200979 | Benoît Canet | sysbus_mmio_map(sysbus, 0, BONITO_INTERNAL_REG_BASE);
|
692 | d0f7453d | Huacai Chen | |
693 | d0f7453d | Huacai Chen | /* set the north bridge pci configure mapping */
|
694 | 183e1d40 | Benoît Canet | memory_region_init_io(&s->pcihost->conf_mem, &bonito_pciconf_ops, s, |
695 | 183e1d40 | Benoît Canet | "north-bridge-pci-config", BONITO_PCICONFIG_SIZE);
|
696 | 750ecd44 | Avi Kivity | sysbus_init_mmio(sysbus, &s->pcihost->conf_mem); |
697 | 183e1d40 | Benoît Canet | sysbus_mmio_map(sysbus, 1, BONITO_PCICONFIG_BASE);
|
698 | d0f7453d | Huacai Chen | |
699 | d0f7453d | Huacai Chen | /* set the south bridge pci configure mapping */
|
700 | 845cbeb8 | Benoît Canet | memory_region_init_io(&s->pcihost->data_mem, &bonito_spciconf_ops, s, |
701 | 845cbeb8 | Benoît Canet | "south-bridge-pci-config", BONITO_SPCICONFIG_SIZE);
|
702 | 750ecd44 | Avi Kivity | sysbus_init_mmio(sysbus, &s->pcihost->data_mem); |
703 | 845cbeb8 | Benoît Canet | sysbus_mmio_map(sysbus, 2, BONITO_SPCICONFIG_BASE);
|
704 | d0f7453d | Huacai Chen | |
705 | def344a6 | Benoît Canet | memory_region_init_io(&s->iomem_ldma, &bonito_ldma_ops, s, |
706 | def344a6 | Benoît Canet | "ldma", 0x100); |
707 | 750ecd44 | Avi Kivity | sysbus_init_mmio(sysbus, &s->iomem_ldma); |
708 | def344a6 | Benoît Canet | sysbus_mmio_map(sysbus, 3, 0xbfe00200); |
709 | d0f7453d | Huacai Chen | |
710 | 9a542a48 | Benoît Canet | memory_region_init_io(&s->iomem_cop, &bonito_cop_ops, s, |
711 | 9a542a48 | Benoît Canet | "cop", 0x100); |
712 | 750ecd44 | Avi Kivity | sysbus_init_mmio(sysbus, &s->iomem_cop); |
713 | 9a542a48 | Benoît Canet | sysbus_mmio_map(sysbus, 4, 0xbfe00300); |
714 | d0f7453d | Huacai Chen | |
715 | d0f7453d | Huacai Chen | /* Map PCI IO Space 0x1fd0 0000 - 0x1fd1 0000 */
|
716 | d0f7453d | Huacai Chen | s->bonito_pciio_start = BONITO_PCIIO_BASE; |
717 | d0f7453d | Huacai Chen | s->bonito_pciio_length = BONITO_PCIIO_SIZE; |
718 | d0f7453d | Huacai Chen | isa_mem_base = s->bonito_pciio_start; |
719 | 968d683c | Alexander Graf | isa_mmio_init(s->bonito_pciio_start, s->bonito_pciio_length); |
720 | d0f7453d | Huacai Chen | |
721 | d0f7453d | Huacai Chen | /* add pci local io mapping */
|
722 | d0f7453d | Huacai Chen | s->bonito_localio_start = BONITO_DEV_BASE; |
723 | d0f7453d | Huacai Chen | s->bonito_localio_length = BONITO_DEV_SIZE; |
724 | 968d683c | Alexander Graf | isa_mmio_init(s->bonito_localio_start, s->bonito_localio_length); |
725 | d0f7453d | Huacai Chen | |
726 | d0f7453d | Huacai Chen | /* set the default value of north bridge pci config */
|
727 | d0f7453d | Huacai Chen | pci_set_word(dev->config + PCI_COMMAND, 0x0000);
|
728 | d0f7453d | Huacai Chen | pci_set_word(dev->config + PCI_STATUS, 0x0000);
|
729 | d0f7453d | Huacai Chen | pci_set_word(dev->config + PCI_SUBSYSTEM_VENDOR_ID, 0x0000);
|
730 | d0f7453d | Huacai Chen | pci_set_word(dev->config + PCI_SUBSYSTEM_ID, 0x0000);
|
731 | d0f7453d | Huacai Chen | |
732 | d0f7453d | Huacai Chen | pci_set_byte(dev->config + PCI_INTERRUPT_LINE, 0x00);
|
733 | d0f7453d | Huacai Chen | pci_set_byte(dev->config + PCI_INTERRUPT_PIN, 0x01);
|
734 | d0f7453d | Huacai Chen | pci_set_byte(dev->config + PCI_MIN_GNT, 0x3c);
|
735 | d0f7453d | Huacai Chen | pci_set_byte(dev->config + PCI_MAX_LAT, 0x00);
|
736 | d0f7453d | Huacai Chen | |
737 | d0f7453d | Huacai Chen | qemu_register_reset(bonito_reset, s); |
738 | d0f7453d | Huacai Chen | |
739 | d0f7453d | Huacai Chen | return 0; |
740 | d0f7453d | Huacai Chen | } |
741 | d0f7453d | Huacai Chen | |
742 | d0f7453d | Huacai Chen | PCIBus *bonito_init(qemu_irq *pic) |
743 | d0f7453d | Huacai Chen | { |
744 | d0f7453d | Huacai Chen | DeviceState *dev; |
745 | d0f7453d | Huacai Chen | PCIBus *b; |
746 | d0f7453d | Huacai Chen | BonitoState *pcihost; |
747 | d0f7453d | Huacai Chen | PCIBonitoState *s; |
748 | d0f7453d | Huacai Chen | PCIDevice *d; |
749 | d0f7453d | Huacai Chen | |
750 | d0f7453d | Huacai Chen | dev = qdev_create(NULL, "Bonito-pcihost"); |
751 | d0f7453d | Huacai Chen | pcihost = FROM_SYSBUS(BonitoState, sysbus_from_qdev(dev)); |
752 | d0f7453d | Huacai Chen | b = pci_register_bus(&pcihost->busdev.qdev, "pci", pci_bonito_set_irq,
|
753 | 1e39101c | Avi Kivity | pci_bonito_map_irq, pic, get_system_memory(), |
754 | aee97b84 | Avi Kivity | get_system_io(), |
755 | 1e39101c | Avi Kivity | 0x28, 32); |
756 | d0f7453d | Huacai Chen | pcihost->bus = b; |
757 | d0f7453d | Huacai Chen | qdev_init_nofail(dev); |
758 | d0f7453d | Huacai Chen | |
759 | 89200979 | Benoît Canet | /* set the pcihost pointer before bonito_initfn is called */
|
760 | 89200979 | Benoît Canet | d = pci_create(b, PCI_DEVFN(0, 0), "Bonito"); |
761 | d0f7453d | Huacai Chen | s = DO_UPCAST(PCIBonitoState, dev, d); |
762 | d0f7453d | Huacai Chen | s->pcihost = pcihost; |
763 | d0f7453d | Huacai Chen | bonito_state = s; |
764 | 89200979 | Benoît Canet | qdev_init_nofail(&d->qdev); |
765 | d0f7453d | Huacai Chen | |
766 | d0f7453d | Huacai Chen | return b;
|
767 | d0f7453d | Huacai Chen | } |
768 | d0f7453d | Huacai Chen | |
769 | 40021f08 | Anthony Liguori | static void bonito_class_init(ObjectClass *klass, void *data) |
770 | 40021f08 | Anthony Liguori | { |
771 | 40021f08 | Anthony Liguori | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
772 | 40021f08 | Anthony Liguori | |
773 | 40021f08 | Anthony Liguori | k->init = bonito_initfn; |
774 | 40021f08 | Anthony Liguori | k->vendor_id = 0xdf53;
|
775 | 40021f08 | Anthony Liguori | k->device_id = 0x00d5;
|
776 | 40021f08 | Anthony Liguori | k->revision = 0x01;
|
777 | 40021f08 | Anthony Liguori | k->class_id = PCI_CLASS_BRIDGE_HOST; |
778 | 40021f08 | Anthony Liguori | } |
779 | 40021f08 | Anthony Liguori | |
780 | 40021f08 | Anthony Liguori | static DeviceInfo bonito_info = {
|
781 | 40021f08 | Anthony Liguori | .name = "Bonito",
|
782 | 40021f08 | Anthony Liguori | .desc = "Host bridge",
|
783 | 40021f08 | Anthony Liguori | .size = sizeof(PCIBonitoState),
|
784 | 40021f08 | Anthony Liguori | .vmsd = &vmstate_bonito, |
785 | 40021f08 | Anthony Liguori | .no_user = 1,
|
786 | 40021f08 | Anthony Liguori | .class_init = bonito_class_init, |
787 | d0f7453d | Huacai Chen | }; |
788 | d0f7453d | Huacai Chen | |
789 | 999e12bb | Anthony Liguori | static void bonito_pcihost_class_init(ObjectClass *klass, void *data) |
790 | 999e12bb | Anthony Liguori | { |
791 | 999e12bb | Anthony Liguori | SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); |
792 | 999e12bb | Anthony Liguori | |
793 | 999e12bb | Anthony Liguori | k->init = bonito_pcihost_initfn; |
794 | 999e12bb | Anthony Liguori | } |
795 | 999e12bb | Anthony Liguori | |
796 | 999e12bb | Anthony Liguori | static DeviceInfo bonito_pcihost_info = {
|
797 | 999e12bb | Anthony Liguori | .name = "Bonito-pcihost",
|
798 | 999e12bb | Anthony Liguori | .size = sizeof(BonitoState),
|
799 | 999e12bb | Anthony Liguori | .no_user = 1,
|
800 | 999e12bb | Anthony Liguori | .class_init = bonito_pcihost_class_init, |
801 | d0f7453d | Huacai Chen | }; |
802 | d0f7453d | Huacai Chen | |
803 | d0f7453d | Huacai Chen | static void bonito_register(void) |
804 | d0f7453d | Huacai Chen | { |
805 | d0f7453d | Huacai Chen | sysbus_register_withprop(&bonito_pcihost_info); |
806 | d0f7453d | Huacai Chen | pci_qdev_register(&bonito_info); |
807 | d0f7453d | Huacai Chen | } |
808 | d0f7453d | Huacai Chen | device_init(bonito_register); |