root / hw / ppc4xx_pci.c @ f6dc18df
History | View | Annotate | Download (10.5 kB)
1 | 825bb581 | aurel32 | /*
|
---|---|---|---|
2 | 825bb581 | aurel32 | * This program is free software; you can redistribute it and/or modify
|
3 | 825bb581 | aurel32 | * it under the terms of the GNU General Public License, version 2, as
|
4 | 825bb581 | aurel32 | * published by the Free Software Foundation.
|
5 | 825bb581 | aurel32 | *
|
6 | 825bb581 | aurel32 | * This program is distributed in the hope that it will be useful,
|
7 | 825bb581 | aurel32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
8 | 825bb581 | aurel32 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
9 | 825bb581 | aurel32 | * GNU General Public License for more details.
|
10 | 825bb581 | aurel32 | *
|
11 | 825bb581 | aurel32 | * You should have received a copy of the GNU General Public License
|
12 | 8167ee88 | Blue Swirl | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
13 | 825bb581 | aurel32 | *
|
14 | 825bb581 | aurel32 | * Copyright IBM Corp. 2008
|
15 | 825bb581 | aurel32 | *
|
16 | 825bb581 | aurel32 | * Authors: Hollis Blanchard <hollisb@us.ibm.com>
|
17 | 825bb581 | aurel32 | */
|
18 | 825bb581 | aurel32 | |
19 | 825bb581 | aurel32 | /* This file implements emulation of the 32-bit PCI controller found in some
|
20 | 825bb581 | aurel32 | * 4xx SoCs, such as the 440EP. */
|
21 | 825bb581 | aurel32 | |
22 | 825bb581 | aurel32 | #include "hw.h" |
23 | 0c34a5d7 | aurel32 | #include "ppc.h" |
24 | 0c34a5d7 | aurel32 | #include "ppc4xx.h" |
25 | 825bb581 | aurel32 | #include "pci.h" |
26 | 825bb581 | aurel32 | #include "pci_host.h" |
27 | 825bb581 | aurel32 | #include "bswap.h" |
28 | 825bb581 | aurel32 | |
29 | 825bb581 | aurel32 | #undef DEBUG
|
30 | 825bb581 | aurel32 | #ifdef DEBUG
|
31 | 825bb581 | aurel32 | #define DPRINTF(fmt, ...) do { printf(fmt, ## __VA_ARGS__); } while (0) |
32 | 825bb581 | aurel32 | #else
|
33 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...)
|
34 | 825bb581 | aurel32 | #endif /* DEBUG */ |
35 | 825bb581 | aurel32 | |
36 | 825bb581 | aurel32 | struct PCIMasterMap {
|
37 | 825bb581 | aurel32 | uint32_t la; |
38 | 825bb581 | aurel32 | uint32_t ma; |
39 | 825bb581 | aurel32 | uint32_t pcila; |
40 | 825bb581 | aurel32 | uint32_t pciha; |
41 | 825bb581 | aurel32 | }; |
42 | 825bb581 | aurel32 | |
43 | 825bb581 | aurel32 | struct PCITargetMap {
|
44 | 825bb581 | aurel32 | uint32_t ms; |
45 | 825bb581 | aurel32 | uint32_t la; |
46 | 825bb581 | aurel32 | }; |
47 | 825bb581 | aurel32 | |
48 | 825bb581 | aurel32 | #define PPC4xx_PCI_NR_PMMS 3 |
49 | 825bb581 | aurel32 | #define PPC4xx_PCI_NR_PTMS 2 |
50 | 825bb581 | aurel32 | |
51 | 825bb581 | aurel32 | struct PPC4xxPCIState {
|
52 | 825bb581 | aurel32 | struct PCIMasterMap pmm[PPC4xx_PCI_NR_PMMS];
|
53 | 825bb581 | aurel32 | struct PCITargetMap ptm[PPC4xx_PCI_NR_PTMS];
|
54 | 825bb581 | aurel32 | |
55 | 825bb581 | aurel32 | PCIHostState pci_state; |
56 | 825bb581 | aurel32 | PCIDevice *pci_dev; |
57 | 825bb581 | aurel32 | }; |
58 | 825bb581 | aurel32 | typedef struct PPC4xxPCIState PPC4xxPCIState; |
59 | 825bb581 | aurel32 | |
60 | 825bb581 | aurel32 | #define PCIC0_CFGADDR 0x0 |
61 | 825bb581 | aurel32 | #define PCIC0_CFGDATA 0x4 |
62 | 825bb581 | aurel32 | |
63 | 825bb581 | aurel32 | /* PLB Memory Map (PMM) registers specify which PLB addresses are translated to
|
64 | 825bb581 | aurel32 | * PCI accesses. */
|
65 | 825bb581 | aurel32 | #define PCIL0_PMM0LA 0x0 |
66 | 825bb581 | aurel32 | #define PCIL0_PMM0MA 0x4 |
67 | 825bb581 | aurel32 | #define PCIL0_PMM0PCILA 0x8 |
68 | 825bb581 | aurel32 | #define PCIL0_PMM0PCIHA 0xc |
69 | 825bb581 | aurel32 | #define PCIL0_PMM1LA 0x10 |
70 | 825bb581 | aurel32 | #define PCIL0_PMM1MA 0x14 |
71 | 825bb581 | aurel32 | #define PCIL0_PMM1PCILA 0x18 |
72 | 825bb581 | aurel32 | #define PCIL0_PMM1PCIHA 0x1c |
73 | 825bb581 | aurel32 | #define PCIL0_PMM2LA 0x20 |
74 | 825bb581 | aurel32 | #define PCIL0_PMM2MA 0x24 |
75 | 825bb581 | aurel32 | #define PCIL0_PMM2PCILA 0x28 |
76 | 825bb581 | aurel32 | #define PCIL0_PMM2PCIHA 0x2c |
77 | 825bb581 | aurel32 | |
78 | 825bb581 | aurel32 | /* PCI Target Map (PTM) registers specify which PCI addresses are translated to
|
79 | 825bb581 | aurel32 | * PLB accesses. */
|
80 | 825bb581 | aurel32 | #define PCIL0_PTM1MS 0x30 |
81 | 825bb581 | aurel32 | #define PCIL0_PTM1LA 0x34 |
82 | 825bb581 | aurel32 | #define PCIL0_PTM2MS 0x38 |
83 | 825bb581 | aurel32 | #define PCIL0_PTM2LA 0x3c |
84 | 825bb581 | aurel32 | #define PCI_REG_SIZE 0x40 |
85 | 825bb581 | aurel32 | |
86 | 825bb581 | aurel32 | |
87 | c227f099 | Anthony Liguori | static uint32_t pci4xx_cfgaddr_readl(void *opaque, target_phys_addr_t addr) |
88 | 825bb581 | aurel32 | { |
89 | 825bb581 | aurel32 | PPC4xxPCIState *ppc4xx_pci = opaque; |
90 | 825bb581 | aurel32 | |
91 | 825bb581 | aurel32 | return ppc4xx_pci->pci_state.config_reg;
|
92 | 825bb581 | aurel32 | } |
93 | 825bb581 | aurel32 | |
94 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pci4xx_cfgaddr_read[] = { |
95 | 825bb581 | aurel32 | &pci4xx_cfgaddr_readl, |
96 | 825bb581 | aurel32 | &pci4xx_cfgaddr_readl, |
97 | 825bb581 | aurel32 | &pci4xx_cfgaddr_readl, |
98 | 825bb581 | aurel32 | }; |
99 | 825bb581 | aurel32 | |
100 | c227f099 | Anthony Liguori | static void pci4xx_cfgaddr_writel(void *opaque, target_phys_addr_t addr, |
101 | 825bb581 | aurel32 | uint32_t value) |
102 | 825bb581 | aurel32 | { |
103 | 825bb581 | aurel32 | PPC4xxPCIState *ppc4xx_pci = opaque; |
104 | 825bb581 | aurel32 | |
105 | 825bb581 | aurel32 | #ifdef TARGET_WORDS_BIGENDIAN
|
106 | 825bb581 | aurel32 | value = bswap32(value); |
107 | 825bb581 | aurel32 | #endif
|
108 | 825bb581 | aurel32 | |
109 | 825bb581 | aurel32 | ppc4xx_pci->pci_state.config_reg = value & ~0x3;
|
110 | 825bb581 | aurel32 | } |
111 | 825bb581 | aurel32 | |
112 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pci4xx_cfgaddr_write[] = { |
113 | 825bb581 | aurel32 | &pci4xx_cfgaddr_writel, |
114 | 825bb581 | aurel32 | &pci4xx_cfgaddr_writel, |
115 | 825bb581 | aurel32 | &pci4xx_cfgaddr_writel, |
116 | 825bb581 | aurel32 | }; |
117 | 825bb581 | aurel32 | |
118 | c227f099 | Anthony Liguori | static void ppc4xx_pci_reg_write4(void *opaque, target_phys_addr_t offset, |
119 | 825bb581 | aurel32 | uint32_t value) |
120 | 825bb581 | aurel32 | { |
121 | 825bb581 | aurel32 | struct PPC4xxPCIState *pci = opaque;
|
122 | 825bb581 | aurel32 | |
123 | 825bb581 | aurel32 | #ifdef TARGET_WORDS_BIGENDIAN
|
124 | 825bb581 | aurel32 | value = bswap32(value); |
125 | 825bb581 | aurel32 | #endif
|
126 | 825bb581 | aurel32 | |
127 | 825bb581 | aurel32 | /* We ignore all target attempts at PCI configuration, effectively
|
128 | 825bb581 | aurel32 | * assuming a bidirectional 1:1 mapping of PLB and PCI space. */
|
129 | 825bb581 | aurel32 | |
130 | 825bb581 | aurel32 | switch (offset) {
|
131 | 825bb581 | aurel32 | case PCIL0_PMM0LA:
|
132 | 825bb581 | aurel32 | pci->pmm[0].la = value;
|
133 | 825bb581 | aurel32 | break;
|
134 | 825bb581 | aurel32 | case PCIL0_PMM0MA:
|
135 | 825bb581 | aurel32 | pci->pmm[0].ma = value;
|
136 | 825bb581 | aurel32 | break;
|
137 | 825bb581 | aurel32 | case PCIL0_PMM0PCIHA:
|
138 | 825bb581 | aurel32 | pci->pmm[0].pciha = value;
|
139 | 825bb581 | aurel32 | break;
|
140 | 825bb581 | aurel32 | case PCIL0_PMM0PCILA:
|
141 | 825bb581 | aurel32 | pci->pmm[0].pcila = value;
|
142 | 825bb581 | aurel32 | break;
|
143 | 825bb581 | aurel32 | |
144 | 825bb581 | aurel32 | case PCIL0_PMM1LA:
|
145 | 825bb581 | aurel32 | pci->pmm[1].la = value;
|
146 | 825bb581 | aurel32 | break;
|
147 | 825bb581 | aurel32 | case PCIL0_PMM1MA:
|
148 | 825bb581 | aurel32 | pci->pmm[1].ma = value;
|
149 | 825bb581 | aurel32 | break;
|
150 | 825bb581 | aurel32 | case PCIL0_PMM1PCIHA:
|
151 | 825bb581 | aurel32 | pci->pmm[1].pciha = value;
|
152 | 825bb581 | aurel32 | break;
|
153 | 825bb581 | aurel32 | case PCIL0_PMM1PCILA:
|
154 | 825bb581 | aurel32 | pci->pmm[1].pcila = value;
|
155 | 825bb581 | aurel32 | break;
|
156 | 825bb581 | aurel32 | |
157 | 825bb581 | aurel32 | case PCIL0_PMM2LA:
|
158 | 825bb581 | aurel32 | pci->pmm[2].la = value;
|
159 | 825bb581 | aurel32 | break;
|
160 | 825bb581 | aurel32 | case PCIL0_PMM2MA:
|
161 | 825bb581 | aurel32 | pci->pmm[2].ma = value;
|
162 | 825bb581 | aurel32 | break;
|
163 | 825bb581 | aurel32 | case PCIL0_PMM2PCIHA:
|
164 | 825bb581 | aurel32 | pci->pmm[2].pciha = value;
|
165 | 825bb581 | aurel32 | break;
|
166 | 825bb581 | aurel32 | case PCIL0_PMM2PCILA:
|
167 | 825bb581 | aurel32 | pci->pmm[2].pcila = value;
|
168 | 825bb581 | aurel32 | break;
|
169 | 825bb581 | aurel32 | |
170 | 825bb581 | aurel32 | case PCIL0_PTM1MS:
|
171 | 825bb581 | aurel32 | pci->ptm[0].ms = value;
|
172 | 825bb581 | aurel32 | break;
|
173 | 825bb581 | aurel32 | case PCIL0_PTM1LA:
|
174 | 825bb581 | aurel32 | pci->ptm[0].la = value;
|
175 | 825bb581 | aurel32 | break;
|
176 | 825bb581 | aurel32 | case PCIL0_PTM2MS:
|
177 | 825bb581 | aurel32 | pci->ptm[1].ms = value;
|
178 | 825bb581 | aurel32 | break;
|
179 | 825bb581 | aurel32 | case PCIL0_PTM2LA:
|
180 | 825bb581 | aurel32 | pci->ptm[1].la = value;
|
181 | 825bb581 | aurel32 | break;
|
182 | 825bb581 | aurel32 | |
183 | 825bb581 | aurel32 | default:
|
184 | 825bb581 | aurel32 | printf("%s: unhandled PCI internal register 0x%lx\n", __func__,
|
185 | 825bb581 | aurel32 | (unsigned long)offset); |
186 | 825bb581 | aurel32 | break;
|
187 | 825bb581 | aurel32 | } |
188 | 825bb581 | aurel32 | } |
189 | 825bb581 | aurel32 | |
190 | c227f099 | Anthony Liguori | static uint32_t ppc4xx_pci_reg_read4(void *opaque, target_phys_addr_t offset) |
191 | 825bb581 | aurel32 | { |
192 | 825bb581 | aurel32 | struct PPC4xxPCIState *pci = opaque;
|
193 | 825bb581 | aurel32 | uint32_t value; |
194 | 825bb581 | aurel32 | |
195 | 825bb581 | aurel32 | switch (offset) {
|
196 | 825bb581 | aurel32 | case PCIL0_PMM0LA:
|
197 | 825bb581 | aurel32 | value = pci->pmm[0].la;
|
198 | 825bb581 | aurel32 | break;
|
199 | 825bb581 | aurel32 | case PCIL0_PMM0MA:
|
200 | 825bb581 | aurel32 | value = pci->pmm[0].ma;
|
201 | 825bb581 | aurel32 | break;
|
202 | 825bb581 | aurel32 | case PCIL0_PMM0PCIHA:
|
203 | 825bb581 | aurel32 | value = pci->pmm[0].pciha;
|
204 | 825bb581 | aurel32 | break;
|
205 | 825bb581 | aurel32 | case PCIL0_PMM0PCILA:
|
206 | 825bb581 | aurel32 | value = pci->pmm[0].pcila;
|
207 | 825bb581 | aurel32 | break;
|
208 | 825bb581 | aurel32 | |
209 | 825bb581 | aurel32 | case PCIL0_PMM1LA:
|
210 | 825bb581 | aurel32 | value = pci->pmm[1].la;
|
211 | 825bb581 | aurel32 | break;
|
212 | 825bb581 | aurel32 | case PCIL0_PMM1MA:
|
213 | 825bb581 | aurel32 | value = pci->pmm[1].ma;
|
214 | 825bb581 | aurel32 | break;
|
215 | 825bb581 | aurel32 | case PCIL0_PMM1PCIHA:
|
216 | 825bb581 | aurel32 | value = pci->pmm[1].pciha;
|
217 | 825bb581 | aurel32 | break;
|
218 | 825bb581 | aurel32 | case PCIL0_PMM1PCILA:
|
219 | 825bb581 | aurel32 | value = pci->pmm[1].pcila;
|
220 | 825bb581 | aurel32 | break;
|
221 | 825bb581 | aurel32 | |
222 | 825bb581 | aurel32 | case PCIL0_PMM2LA:
|
223 | 825bb581 | aurel32 | value = pci->pmm[2].la;
|
224 | 825bb581 | aurel32 | break;
|
225 | 825bb581 | aurel32 | case PCIL0_PMM2MA:
|
226 | 825bb581 | aurel32 | value = pci->pmm[2].ma;
|
227 | 825bb581 | aurel32 | break;
|
228 | 825bb581 | aurel32 | case PCIL0_PMM2PCIHA:
|
229 | 825bb581 | aurel32 | value = pci->pmm[2].pciha;
|
230 | 825bb581 | aurel32 | break;
|
231 | 825bb581 | aurel32 | case PCIL0_PMM2PCILA:
|
232 | 825bb581 | aurel32 | value = pci->pmm[2].pcila;
|
233 | 825bb581 | aurel32 | break;
|
234 | 825bb581 | aurel32 | |
235 | 825bb581 | aurel32 | case PCIL0_PTM1MS:
|
236 | 825bb581 | aurel32 | value = pci->ptm[0].ms;
|
237 | 825bb581 | aurel32 | break;
|
238 | 825bb581 | aurel32 | case PCIL0_PTM1LA:
|
239 | 825bb581 | aurel32 | value = pci->ptm[0].la;
|
240 | 825bb581 | aurel32 | break;
|
241 | 825bb581 | aurel32 | case PCIL0_PTM2MS:
|
242 | 825bb581 | aurel32 | value = pci->ptm[1].ms;
|
243 | 825bb581 | aurel32 | break;
|
244 | 825bb581 | aurel32 | case PCIL0_PTM2LA:
|
245 | 825bb581 | aurel32 | value = pci->ptm[1].la;
|
246 | 825bb581 | aurel32 | break;
|
247 | 825bb581 | aurel32 | |
248 | 825bb581 | aurel32 | default:
|
249 | 825bb581 | aurel32 | printf("%s: invalid PCI internal register 0x%lx\n", __func__,
|
250 | 825bb581 | aurel32 | (unsigned long)offset); |
251 | 825bb581 | aurel32 | value = 0;
|
252 | 825bb581 | aurel32 | } |
253 | 825bb581 | aurel32 | |
254 | 825bb581 | aurel32 | #ifdef TARGET_WORDS_BIGENDIAN
|
255 | 825bb581 | aurel32 | value = bswap32(value); |
256 | 825bb581 | aurel32 | #endif
|
257 | 825bb581 | aurel32 | |
258 | 825bb581 | aurel32 | return value;
|
259 | 825bb581 | aurel32 | } |
260 | 825bb581 | aurel32 | |
261 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pci_reg_read[] = { |
262 | 825bb581 | aurel32 | &ppc4xx_pci_reg_read4, |
263 | 825bb581 | aurel32 | &ppc4xx_pci_reg_read4, |
264 | 825bb581 | aurel32 | &ppc4xx_pci_reg_read4, |
265 | 825bb581 | aurel32 | }; |
266 | 825bb581 | aurel32 | |
267 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pci_reg_write[] = { |
268 | 825bb581 | aurel32 | &ppc4xx_pci_reg_write4, |
269 | 825bb581 | aurel32 | &ppc4xx_pci_reg_write4, |
270 | 825bb581 | aurel32 | &ppc4xx_pci_reg_write4, |
271 | 825bb581 | aurel32 | }; |
272 | 825bb581 | aurel32 | |
273 | 825bb581 | aurel32 | static void ppc4xx_pci_reset(void *opaque) |
274 | 825bb581 | aurel32 | { |
275 | 825bb581 | aurel32 | struct PPC4xxPCIState *pci = opaque;
|
276 | 825bb581 | aurel32 | |
277 | 825bb581 | aurel32 | memset(pci->pmm, 0, sizeof(pci->pmm)); |
278 | 825bb581 | aurel32 | memset(pci->ptm, 0, sizeof(pci->ptm)); |
279 | 825bb581 | aurel32 | } |
280 | 825bb581 | aurel32 | |
281 | 825bb581 | aurel32 | /* On Bamboo, all pins from each slot are tied to a single board IRQ. This
|
282 | 825bb581 | aurel32 | * may need further refactoring for other boards. */
|
283 | 825bb581 | aurel32 | static int ppc4xx_pci_map_irq(PCIDevice *pci_dev, int irq_num) |
284 | 825bb581 | aurel32 | { |
285 | 825bb581 | aurel32 | int slot = pci_dev->devfn >> 3; |
286 | 825bb581 | aurel32 | |
287 | 825bb581 | aurel32 | DPRINTF("%s: devfn %x irq %d -> %d\n", __func__,
|
288 | 825bb581 | aurel32 | pci_dev->devfn, irq_num, slot); |
289 | 825bb581 | aurel32 | |
290 | 825bb581 | aurel32 | return slot - 1; |
291 | 825bb581 | aurel32 | } |
292 | 825bb581 | aurel32 | |
293 | 5d4e84c8 | Juan Quintela | static void ppc4xx_pci_set_irq(void *opaque, int irq_num, int level) |
294 | 825bb581 | aurel32 | { |
295 | 5d4e84c8 | Juan Quintela | qemu_irq *pci_irqs = opaque; |
296 | 5d4e84c8 | Juan Quintela | |
297 | 825bb581 | aurel32 | DPRINTF("%s: PCI irq %d\n", __func__, irq_num);
|
298 | 825bb581 | aurel32 | qemu_set_irq(pci_irqs[irq_num], level); |
299 | 825bb581 | aurel32 | } |
300 | 825bb581 | aurel32 | |
301 | 825bb581 | aurel32 | static void ppc4xx_pci_save(QEMUFile *f, void *opaque) |
302 | 825bb581 | aurel32 | { |
303 | 825bb581 | aurel32 | PPC4xxPCIState *controller = opaque; |
304 | 825bb581 | aurel32 | int i;
|
305 | 825bb581 | aurel32 | |
306 | 3476f891 | aurel32 | pci_device_save(controller->pci_dev, f); |
307 | 825bb581 | aurel32 | |
308 | 825bb581 | aurel32 | for (i = 0; i < PPC4xx_PCI_NR_PMMS; i++) { |
309 | 825bb581 | aurel32 | qemu_put_be32s(f, &controller->pmm[i].la); |
310 | 825bb581 | aurel32 | qemu_put_be32s(f, &controller->pmm[i].ma); |
311 | 825bb581 | aurel32 | qemu_put_be32s(f, &controller->pmm[i].pcila); |
312 | 825bb581 | aurel32 | qemu_put_be32s(f, &controller->pmm[i].pciha); |
313 | 825bb581 | aurel32 | } |
314 | 825bb581 | aurel32 | |
315 | 825bb581 | aurel32 | for (i = 0; i < PPC4xx_PCI_NR_PTMS; i++) { |
316 | 825bb581 | aurel32 | qemu_put_be32s(f, &controller->ptm[i].ms); |
317 | 825bb581 | aurel32 | qemu_put_be32s(f, &controller->ptm[i].la); |
318 | 825bb581 | aurel32 | } |
319 | 825bb581 | aurel32 | } |
320 | 825bb581 | aurel32 | |
321 | 825bb581 | aurel32 | static int ppc4xx_pci_load(QEMUFile *f, void *opaque, int version_id) |
322 | 825bb581 | aurel32 | { |
323 | 825bb581 | aurel32 | PPC4xxPCIState *controller = opaque; |
324 | 825bb581 | aurel32 | int i;
|
325 | 825bb581 | aurel32 | |
326 | 825bb581 | aurel32 | if (version_id != 1) |
327 | 825bb581 | aurel32 | return -EINVAL;
|
328 | 825bb581 | aurel32 | |
329 | 3476f891 | aurel32 | pci_device_load(controller->pci_dev, f); |
330 | 825bb581 | aurel32 | |
331 | 825bb581 | aurel32 | for (i = 0; i < PPC4xx_PCI_NR_PMMS; i++) { |
332 | 825bb581 | aurel32 | qemu_get_be32s(f, &controller->pmm[i].la); |
333 | 825bb581 | aurel32 | qemu_get_be32s(f, &controller->pmm[i].ma); |
334 | 825bb581 | aurel32 | qemu_get_be32s(f, &controller->pmm[i].pcila); |
335 | 825bb581 | aurel32 | qemu_get_be32s(f, &controller->pmm[i].pciha); |
336 | 825bb581 | aurel32 | } |
337 | 825bb581 | aurel32 | |
338 | 825bb581 | aurel32 | for (i = 0; i < PPC4xx_PCI_NR_PTMS; i++) { |
339 | 825bb581 | aurel32 | qemu_get_be32s(f, &controller->ptm[i].ms); |
340 | 825bb581 | aurel32 | qemu_get_be32s(f, &controller->ptm[i].la); |
341 | 825bb581 | aurel32 | } |
342 | 825bb581 | aurel32 | |
343 | 825bb581 | aurel32 | return 0; |
344 | 825bb581 | aurel32 | } |
345 | 825bb581 | aurel32 | |
346 | 825bb581 | aurel32 | /* XXX Interrupt acknowledge cycles not supported. */
|
347 | 825bb581 | aurel32 | PCIBus *ppc4xx_pci_init(CPUState *env, qemu_irq pci_irqs[4],
|
348 | c227f099 | Anthony Liguori | target_phys_addr_t config_space, |
349 | c227f099 | Anthony Liguori | target_phys_addr_t int_ack, |
350 | c227f099 | Anthony Liguori | target_phys_addr_t special_cycle, |
351 | c227f099 | Anthony Liguori | target_phys_addr_t registers) |
352 | 825bb581 | aurel32 | { |
353 | 825bb581 | aurel32 | PPC4xxPCIState *controller; |
354 | 825bb581 | aurel32 | int index;
|
355 | 825bb581 | aurel32 | static int ppc4xx_pci_id; |
356 | deb54399 | aliguori | uint8_t *pci_conf; |
357 | 825bb581 | aurel32 | |
358 | 825bb581 | aurel32 | controller = qemu_mallocz(sizeof(PPC4xxPCIState));
|
359 | 825bb581 | aurel32 | |
360 | 02e2da45 | Paul Brook | controller->pci_state.bus = pci_register_bus(NULL, "pci", |
361 | 02e2da45 | Paul Brook | ppc4xx_pci_set_irq, |
362 | 825bb581 | aurel32 | ppc4xx_pci_map_irq, |
363 | 825bb581 | aurel32 | pci_irqs, 0, 4); |
364 | 825bb581 | aurel32 | |
365 | 825bb581 | aurel32 | controller->pci_dev = pci_register_device(controller->pci_state.bus, |
366 | 825bb581 | aurel32 | "host bridge", sizeof(PCIDevice), |
367 | 825bb581 | aurel32 | 0, NULL, NULL); |
368 | deb54399 | aliguori | pci_conf = controller->pci_dev->config; |
369 | deb54399 | aliguori | pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_IBM); |
370 | a770dc7e | aliguori | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_IBM_440GX); |
371 | 173a543b | blueswir1 | pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_OTHER); |
372 | 825bb581 | aurel32 | |
373 | 825bb581 | aurel32 | /* CFGADDR */
|
374 | 1eed09cb | Avi Kivity | index = cpu_register_io_memory(pci4xx_cfgaddr_read, |
375 | 825bb581 | aurel32 | pci4xx_cfgaddr_write, controller); |
376 | 825bb581 | aurel32 | if (index < 0) |
377 | 825bb581 | aurel32 | goto free;
|
378 | 825bb581 | aurel32 | cpu_register_physical_memory(config_space + PCIC0_CFGADDR, 4, index);
|
379 | 825bb581 | aurel32 | |
380 | 825bb581 | aurel32 | /* CFGDATA */
|
381 | f08b32fe | Isaku Yamahata | index = pci_host_data_register_mmio(&controller->pci_state); |
382 | 825bb581 | aurel32 | if (index < 0) |
383 | 825bb581 | aurel32 | goto free;
|
384 | 825bb581 | aurel32 | cpu_register_physical_memory(config_space + PCIC0_CFGDATA, 4, index);
|
385 | 825bb581 | aurel32 | |
386 | 825bb581 | aurel32 | /* Internal registers */
|
387 | 1eed09cb | Avi Kivity | index = cpu_register_io_memory(pci_reg_read, pci_reg_write, controller); |
388 | 825bb581 | aurel32 | if (index < 0) |
389 | 825bb581 | aurel32 | goto free;
|
390 | 825bb581 | aurel32 | cpu_register_physical_memory(registers, PCI_REG_SIZE, index); |
391 | 825bb581 | aurel32 | |
392 | a08d4367 | Jan Kiszka | qemu_register_reset(ppc4xx_pci_reset, controller); |
393 | 825bb581 | aurel32 | |
394 | 825bb581 | aurel32 | /* XXX load/save code not tested. */
|
395 | 825bb581 | aurel32 | register_savevm("ppc4xx_pci", ppc4xx_pci_id++, 1, |
396 | 825bb581 | aurel32 | ppc4xx_pci_save, ppc4xx_pci_load, controller); |
397 | 825bb581 | aurel32 | |
398 | 825bb581 | aurel32 | return controller->pci_state.bus;
|
399 | 825bb581 | aurel32 | |
400 | 825bb581 | aurel32 | free:
|
401 | 825bb581 | aurel32 | printf("%s error\n", __func__);
|
402 | 825bb581 | aurel32 | qemu_free(controller); |
403 | 825bb581 | aurel32 | return NULL; |
404 | 825bb581 | aurel32 | } |