root / hw / ppce500_pci.c @ a46007a0
History | View | Annotate | Download (10.8 kB)
1 | 74c62ba8 | aurel32 | /*
|
---|---|---|---|
2 | 74c62ba8 | aurel32 | * QEMU PowerPC E500 embedded processors pci controller emulation
|
3 | 74c62ba8 | aurel32 | *
|
4 | 74c62ba8 | aurel32 | * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
|
5 | 74c62ba8 | aurel32 | *
|
6 | 74c62ba8 | aurel32 | * Author: Yu Liu, <yu.liu@freescale.com>
|
7 | 74c62ba8 | aurel32 | *
|
8 | 74c62ba8 | aurel32 | * This file is derived from hw/ppc4xx_pci.c,
|
9 | 74c62ba8 | aurel32 | * the copyright for that material belongs to the original owners.
|
10 | 74c62ba8 | aurel32 | *
|
11 | 74c62ba8 | aurel32 | * This is free software; you can redistribute it and/or modify
|
12 | 74c62ba8 | aurel32 | * it under the terms of the GNU General Public License as published by
|
13 | 74c62ba8 | aurel32 | * the Free Software Foundation; either version 2 of the License, or
|
14 | 74c62ba8 | aurel32 | * (at your option) any later version.
|
15 | 74c62ba8 | aurel32 | */
|
16 | 74c62ba8 | aurel32 | |
17 | 74c62ba8 | aurel32 | #include "hw.h" |
18 | 74c62ba8 | aurel32 | #include "ppc.h" |
19 | 74c62ba8 | aurel32 | #include "ppce500.h" |
20 | 74c62ba8 | aurel32 | typedef target_phys_addr_t pci_addr_t;
|
21 | 74c62ba8 | aurel32 | #include "pci.h" |
22 | 74c62ba8 | aurel32 | #include "pci_host.h" |
23 | 74c62ba8 | aurel32 | #include "bswap.h" |
24 | 74c62ba8 | aurel32 | #include "qemu-log.h" |
25 | 74c62ba8 | aurel32 | |
26 | 74c62ba8 | aurel32 | #ifdef DEBUG_PCI
|
27 | 001faf32 | Blue Swirl | #define pci_debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__) |
28 | 74c62ba8 | aurel32 | #else
|
29 | 001faf32 | Blue Swirl | #define pci_debug(fmt, ...)
|
30 | 74c62ba8 | aurel32 | #endif
|
31 | 74c62ba8 | aurel32 | |
32 | 74c62ba8 | aurel32 | #define PCIE500_CFGADDR 0x0 |
33 | 74c62ba8 | aurel32 | #define PCIE500_CFGDATA 0x4 |
34 | 74c62ba8 | aurel32 | #define PCIE500_REG_BASE 0xC00 |
35 | 74c62ba8 | aurel32 | #define PCIE500_REG_SIZE (0x1000 - PCIE500_REG_BASE) |
36 | 74c62ba8 | aurel32 | |
37 | 74c62ba8 | aurel32 | #define PPCE500_PCI_CONFIG_ADDR 0x0 |
38 | 74c62ba8 | aurel32 | #define PPCE500_PCI_CONFIG_DATA 0x4 |
39 | 74c62ba8 | aurel32 | #define PPCE500_PCI_INTACK 0x8 |
40 | 74c62ba8 | aurel32 | |
41 | 74c62ba8 | aurel32 | #define PPCE500_PCI_OW1 (0xC20 - PCIE500_REG_BASE) |
42 | 74c62ba8 | aurel32 | #define PPCE500_PCI_OW2 (0xC40 - PCIE500_REG_BASE) |
43 | 74c62ba8 | aurel32 | #define PPCE500_PCI_OW3 (0xC60 - PCIE500_REG_BASE) |
44 | 74c62ba8 | aurel32 | #define PPCE500_PCI_OW4 (0xC80 - PCIE500_REG_BASE) |
45 | 74c62ba8 | aurel32 | #define PPCE500_PCI_IW3 (0xDA0 - PCIE500_REG_BASE) |
46 | 74c62ba8 | aurel32 | #define PPCE500_PCI_IW2 (0xDC0 - PCIE500_REG_BASE) |
47 | 74c62ba8 | aurel32 | #define PPCE500_PCI_IW1 (0xDE0 - PCIE500_REG_BASE) |
48 | 74c62ba8 | aurel32 | |
49 | 74c62ba8 | aurel32 | #define PPCE500_PCI_GASKET_TIMR (0xE20 - PCIE500_REG_BASE) |
50 | 74c62ba8 | aurel32 | |
51 | 74c62ba8 | aurel32 | #define PCI_POTAR 0x0 |
52 | 74c62ba8 | aurel32 | #define PCI_POTEAR 0x4 |
53 | 74c62ba8 | aurel32 | #define PCI_POWBAR 0x8 |
54 | 74c62ba8 | aurel32 | #define PCI_POWAR 0x10 |
55 | 74c62ba8 | aurel32 | |
56 | 74c62ba8 | aurel32 | #define PCI_PITAR 0x0 |
57 | 74c62ba8 | aurel32 | #define PCI_PIWBAR 0x8 |
58 | 74c62ba8 | aurel32 | #define PCI_PIWBEAR 0xC |
59 | 74c62ba8 | aurel32 | #define PCI_PIWAR 0x10 |
60 | 74c62ba8 | aurel32 | |
61 | 74c62ba8 | aurel32 | #define PPCE500_PCI_NR_POBS 5 |
62 | 74c62ba8 | aurel32 | #define PPCE500_PCI_NR_PIBS 3 |
63 | 74c62ba8 | aurel32 | |
64 | 74c62ba8 | aurel32 | struct pci_outbound {
|
65 | 74c62ba8 | aurel32 | uint32_t potar; |
66 | 74c62ba8 | aurel32 | uint32_t potear; |
67 | 74c62ba8 | aurel32 | uint32_t powbar; |
68 | 74c62ba8 | aurel32 | uint32_t powar; |
69 | 74c62ba8 | aurel32 | }; |
70 | 74c62ba8 | aurel32 | |
71 | 74c62ba8 | aurel32 | struct pci_inbound {
|
72 | 74c62ba8 | aurel32 | uint32_t pitar; |
73 | 74c62ba8 | aurel32 | uint32_t piwbar; |
74 | 74c62ba8 | aurel32 | uint32_t piwbear; |
75 | 74c62ba8 | aurel32 | uint32_t piwar; |
76 | 74c62ba8 | aurel32 | }; |
77 | 74c62ba8 | aurel32 | |
78 | 74c62ba8 | aurel32 | struct PPCE500PCIState {
|
79 | 74c62ba8 | aurel32 | struct pci_outbound pob[PPCE500_PCI_NR_POBS];
|
80 | 74c62ba8 | aurel32 | struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
|
81 | 74c62ba8 | aurel32 | uint32_t gasket_time; |
82 | 74c62ba8 | aurel32 | PCIHostState pci_state; |
83 | 74c62ba8 | aurel32 | PCIDevice *pci_dev; |
84 | 74c62ba8 | aurel32 | }; |
85 | 74c62ba8 | aurel32 | |
86 | 74c62ba8 | aurel32 | typedef struct PPCE500PCIState PPCE500PCIState; |
87 | 74c62ba8 | aurel32 | |
88 | 74c62ba8 | aurel32 | static uint32_t pcie500_cfgaddr_readl(void *opaque, target_phys_addr_t addr) |
89 | 74c62ba8 | aurel32 | { |
90 | 74c62ba8 | aurel32 | PPCE500PCIState *pci = opaque; |
91 | 74c62ba8 | aurel32 | |
92 | c0a2a096 | Blue Swirl | pci_debug("%s: (addr:" TARGET_FMT_plx ") -> value:%x\n", __func__, addr, |
93 | c0a2a096 | Blue Swirl | pci->pci_state.config_reg); |
94 | 74c62ba8 | aurel32 | return pci->pci_state.config_reg;
|
95 | 74c62ba8 | aurel32 | } |
96 | 74c62ba8 | aurel32 | |
97 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pcie500_cfgaddr_read[] = { |
98 | 74c62ba8 | aurel32 | &pcie500_cfgaddr_readl, |
99 | 74c62ba8 | aurel32 | &pcie500_cfgaddr_readl, |
100 | 74c62ba8 | aurel32 | &pcie500_cfgaddr_readl, |
101 | 74c62ba8 | aurel32 | }; |
102 | 74c62ba8 | aurel32 | |
103 | 74c62ba8 | aurel32 | static void pcie500_cfgaddr_writel(void *opaque, target_phys_addr_t addr, |
104 | 74c62ba8 | aurel32 | uint32_t value) |
105 | 74c62ba8 | aurel32 | { |
106 | 74c62ba8 | aurel32 | PPCE500PCIState *controller = opaque; |
107 | 74c62ba8 | aurel32 | |
108 | c0a2a096 | Blue Swirl | pci_debug("%s: value:%x -> (addr:" TARGET_FMT_plx ")\n", __func__, value, |
109 | c0a2a096 | Blue Swirl | addr); |
110 | 74c62ba8 | aurel32 | controller->pci_state.config_reg = value & ~0x3;
|
111 | 74c62ba8 | aurel32 | } |
112 | 74c62ba8 | aurel32 | |
113 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pcie500_cfgaddr_write[] = { |
114 | 74c62ba8 | aurel32 | &pcie500_cfgaddr_writel, |
115 | 74c62ba8 | aurel32 | &pcie500_cfgaddr_writel, |
116 | 74c62ba8 | aurel32 | &pcie500_cfgaddr_writel, |
117 | 74c62ba8 | aurel32 | }; |
118 | 74c62ba8 | aurel32 | |
119 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pcie500_cfgdata_read[] = { |
120 | 74c62ba8 | aurel32 | &pci_host_data_readb, |
121 | 74c62ba8 | aurel32 | &pci_host_data_readw, |
122 | 74c62ba8 | aurel32 | &pci_host_data_readl, |
123 | 74c62ba8 | aurel32 | }; |
124 | 74c62ba8 | aurel32 | |
125 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pcie500_cfgdata_write[] = { |
126 | 74c62ba8 | aurel32 | &pci_host_data_writeb, |
127 | 74c62ba8 | aurel32 | &pci_host_data_writew, |
128 | 74c62ba8 | aurel32 | &pci_host_data_writel, |
129 | 74c62ba8 | aurel32 | }; |
130 | 74c62ba8 | aurel32 | |
131 | 74c62ba8 | aurel32 | static uint32_t pci_reg_read4(void *opaque, target_phys_addr_t addr) |
132 | 74c62ba8 | aurel32 | { |
133 | 74c62ba8 | aurel32 | PPCE500PCIState *pci = opaque; |
134 | 74c62ba8 | aurel32 | unsigned long win; |
135 | 74c62ba8 | aurel32 | uint32_t value = 0;
|
136 | 74c62ba8 | aurel32 | |
137 | 74c62ba8 | aurel32 | win = addr & 0xfe0;
|
138 | 74c62ba8 | aurel32 | |
139 | 74c62ba8 | aurel32 | switch (win) {
|
140 | 74c62ba8 | aurel32 | case PPCE500_PCI_OW1:
|
141 | 74c62ba8 | aurel32 | case PPCE500_PCI_OW2:
|
142 | 74c62ba8 | aurel32 | case PPCE500_PCI_OW3:
|
143 | 74c62ba8 | aurel32 | case PPCE500_PCI_OW4:
|
144 | 74c62ba8 | aurel32 | switch (addr & 0xC) { |
145 | 74c62ba8 | aurel32 | case PCI_POTAR: value = pci->pob[(addr >> 5) & 0x7].potar; break; |
146 | 74c62ba8 | aurel32 | case PCI_POTEAR: value = pci->pob[(addr >> 5) & 0x7].potear; break; |
147 | 74c62ba8 | aurel32 | case PCI_POWBAR: value = pci->pob[(addr >> 5) & 0x7].powbar; break; |
148 | 74c62ba8 | aurel32 | case PCI_POWAR: value = pci->pob[(addr >> 5) & 0x7].powar; break; |
149 | 74c62ba8 | aurel32 | default: break; |
150 | 74c62ba8 | aurel32 | } |
151 | 74c62ba8 | aurel32 | break;
|
152 | 74c62ba8 | aurel32 | |
153 | 74c62ba8 | aurel32 | case PPCE500_PCI_IW3:
|
154 | 74c62ba8 | aurel32 | case PPCE500_PCI_IW2:
|
155 | 74c62ba8 | aurel32 | case PPCE500_PCI_IW1:
|
156 | 74c62ba8 | aurel32 | switch (addr & 0xC) { |
157 | 74c62ba8 | aurel32 | case PCI_PITAR: value = pci->pib[(addr >> 5) & 0x3].pitar; break; |
158 | 74c62ba8 | aurel32 | case PCI_PIWBAR: value = pci->pib[(addr >> 5) & 0x3].piwbar; break; |
159 | 74c62ba8 | aurel32 | case PCI_PIWBEAR: value = pci->pib[(addr >> 5) & 0x3].piwbear; break; |
160 | 74c62ba8 | aurel32 | case PCI_PIWAR: value = pci->pib[(addr >> 5) & 0x3].piwar; break; |
161 | 74c62ba8 | aurel32 | default: break; |
162 | 74c62ba8 | aurel32 | }; |
163 | 74c62ba8 | aurel32 | break;
|
164 | 74c62ba8 | aurel32 | |
165 | 74c62ba8 | aurel32 | case PPCE500_PCI_GASKET_TIMR:
|
166 | 74c62ba8 | aurel32 | value = pci->gasket_time; |
167 | 74c62ba8 | aurel32 | break;
|
168 | 74c62ba8 | aurel32 | |
169 | 74c62ba8 | aurel32 | default:
|
170 | 74c62ba8 | aurel32 | break;
|
171 | 74c62ba8 | aurel32 | } |
172 | 74c62ba8 | aurel32 | |
173 | c0a2a096 | Blue Swirl | pci_debug("%s: win:%lx(addr:" TARGET_FMT_plx ") -> value:%x\n", __func__, |
174 | c0a2a096 | Blue Swirl | win, addr, value); |
175 | 74c62ba8 | aurel32 | return value;
|
176 | 74c62ba8 | aurel32 | } |
177 | 74c62ba8 | aurel32 | |
178 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const e500_pci_reg_read[] = { |
179 | 74c62ba8 | aurel32 | &pci_reg_read4, |
180 | 74c62ba8 | aurel32 | &pci_reg_read4, |
181 | 74c62ba8 | aurel32 | &pci_reg_read4, |
182 | 74c62ba8 | aurel32 | }; |
183 | 74c62ba8 | aurel32 | |
184 | 74c62ba8 | aurel32 | static void pci_reg_write4(void *opaque, target_phys_addr_t addr, |
185 | 74c62ba8 | aurel32 | uint32_t value) |
186 | 74c62ba8 | aurel32 | { |
187 | 74c62ba8 | aurel32 | PPCE500PCIState *pci = opaque; |
188 | 74c62ba8 | aurel32 | unsigned long win; |
189 | 74c62ba8 | aurel32 | |
190 | 74c62ba8 | aurel32 | win = addr & 0xfe0;
|
191 | 74c62ba8 | aurel32 | |
192 | c0a2a096 | Blue Swirl | pci_debug("%s: value:%x -> win:%lx(addr:" TARGET_FMT_plx ")\n", |
193 | c0a2a096 | Blue Swirl | __func__, value, win, addr); |
194 | 74c62ba8 | aurel32 | |
195 | 74c62ba8 | aurel32 | switch (win) {
|
196 | 74c62ba8 | aurel32 | case PPCE500_PCI_OW1:
|
197 | 74c62ba8 | aurel32 | case PPCE500_PCI_OW2:
|
198 | 74c62ba8 | aurel32 | case PPCE500_PCI_OW3:
|
199 | 74c62ba8 | aurel32 | case PPCE500_PCI_OW4:
|
200 | 74c62ba8 | aurel32 | switch (addr & 0xC) { |
201 | 74c62ba8 | aurel32 | case PCI_POTAR: pci->pob[(addr >> 5) & 0x7].potar = value; break; |
202 | 74c62ba8 | aurel32 | case PCI_POTEAR: pci->pob[(addr >> 5) & 0x7].potear = value; break; |
203 | 74c62ba8 | aurel32 | case PCI_POWBAR: pci->pob[(addr >> 5) & 0x7].powbar = value; break; |
204 | 74c62ba8 | aurel32 | case PCI_POWAR: pci->pob[(addr >> 5) & 0x7].powar = value; break; |
205 | 74c62ba8 | aurel32 | default: break; |
206 | 74c62ba8 | aurel32 | }; |
207 | 74c62ba8 | aurel32 | break;
|
208 | 74c62ba8 | aurel32 | |
209 | 74c62ba8 | aurel32 | case PPCE500_PCI_IW3:
|
210 | 74c62ba8 | aurel32 | case PPCE500_PCI_IW2:
|
211 | 74c62ba8 | aurel32 | case PPCE500_PCI_IW1:
|
212 | 74c62ba8 | aurel32 | switch (addr & 0xC) { |
213 | 74c62ba8 | aurel32 | case PCI_PITAR: pci->pib[(addr >> 5) & 0x3].pitar = value; break; |
214 | 74c62ba8 | aurel32 | case PCI_PIWBAR: pci->pib[(addr >> 5) & 0x3].piwbar = value; break; |
215 | 74c62ba8 | aurel32 | case PCI_PIWBEAR: pci->pib[(addr >> 5) & 0x3].piwbear = value; break; |
216 | 74c62ba8 | aurel32 | case PCI_PIWAR: pci->pib[(addr >> 5) & 0x3].piwar = value; break; |
217 | 74c62ba8 | aurel32 | default: break; |
218 | 74c62ba8 | aurel32 | }; |
219 | 74c62ba8 | aurel32 | break;
|
220 | 74c62ba8 | aurel32 | |
221 | 74c62ba8 | aurel32 | case PPCE500_PCI_GASKET_TIMR:
|
222 | 74c62ba8 | aurel32 | pci->gasket_time = value; |
223 | 74c62ba8 | aurel32 | break;
|
224 | 74c62ba8 | aurel32 | |
225 | 74c62ba8 | aurel32 | default:
|
226 | 74c62ba8 | aurel32 | break;
|
227 | 74c62ba8 | aurel32 | }; |
228 | 74c62ba8 | aurel32 | } |
229 | 74c62ba8 | aurel32 | |
230 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const e500_pci_reg_write[] = { |
231 | 74c62ba8 | aurel32 | &pci_reg_write4, |
232 | 74c62ba8 | aurel32 | &pci_reg_write4, |
233 | 74c62ba8 | aurel32 | &pci_reg_write4, |
234 | 74c62ba8 | aurel32 | }; |
235 | 74c62ba8 | aurel32 | |
236 | 74c62ba8 | aurel32 | static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int irq_num) |
237 | 74c62ba8 | aurel32 | { |
238 | 74c62ba8 | aurel32 | int devno = pci_dev->devfn >> 3, ret = 0; |
239 | 74c62ba8 | aurel32 | |
240 | 74c62ba8 | aurel32 | switch (devno) {
|
241 | 74c62ba8 | aurel32 | /* Two PCI slot */
|
242 | 74c62ba8 | aurel32 | case 0x11: |
243 | 74c62ba8 | aurel32 | case 0x12: |
244 | 74c62ba8 | aurel32 | ret = (irq_num + devno - 0x10) % 4; |
245 | 74c62ba8 | aurel32 | break;
|
246 | 74c62ba8 | aurel32 | default:
|
247 | 74c62ba8 | aurel32 | printf("Error:%s:unknow dev number\n", __func__);
|
248 | 74c62ba8 | aurel32 | } |
249 | 74c62ba8 | aurel32 | |
250 | 74c62ba8 | aurel32 | pci_debug("%s: devfn %x irq %d -> %d devno:%x\n", __func__,
|
251 | 74c62ba8 | aurel32 | pci_dev->devfn, irq_num, ret, devno); |
252 | 74c62ba8 | aurel32 | |
253 | 74c62ba8 | aurel32 | return ret;
|
254 | 74c62ba8 | aurel32 | } |
255 | 74c62ba8 | aurel32 | |
256 | 5d4e84c8 | Juan Quintela | static void mpc85xx_pci_set_irq(void *opaque, int irq_num, int level) |
257 | 74c62ba8 | aurel32 | { |
258 | 5d4e84c8 | Juan Quintela | qemu_irq *pic = opaque; |
259 | 5d4e84c8 | Juan Quintela | |
260 | 74c62ba8 | aurel32 | pci_debug("%s: PCI irq %d, level:%d\n", __func__, irq_num, level);
|
261 | 74c62ba8 | aurel32 | |
262 | 74c62ba8 | aurel32 | qemu_set_irq(pic[irq_num], level); |
263 | 74c62ba8 | aurel32 | } |
264 | 74c62ba8 | aurel32 | |
265 | 74c62ba8 | aurel32 | static void ppce500_pci_save(QEMUFile *f, void *opaque) |
266 | 74c62ba8 | aurel32 | { |
267 | 74c62ba8 | aurel32 | PPCE500PCIState *controller = opaque; |
268 | 74c62ba8 | aurel32 | int i;
|
269 | 74c62ba8 | aurel32 | |
270 | 74c62ba8 | aurel32 | pci_device_save(controller->pci_dev, f); |
271 | 74c62ba8 | aurel32 | |
272 | 74c62ba8 | aurel32 | for (i = 0; i < PPCE500_PCI_NR_POBS; i++) { |
273 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->pob[i].potar); |
274 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->pob[i].potear); |
275 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->pob[i].powbar); |
276 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->pob[i].powar); |
277 | 74c62ba8 | aurel32 | } |
278 | 74c62ba8 | aurel32 | |
279 | 74c62ba8 | aurel32 | for (i = 0; i < PPCE500_PCI_NR_PIBS; i++) { |
280 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->pib[i].pitar); |
281 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->pib[i].piwbar); |
282 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->pib[i].piwbear); |
283 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->pib[i].piwar); |
284 | 74c62ba8 | aurel32 | } |
285 | 74c62ba8 | aurel32 | qemu_put_be32s(f, &controller->gasket_time); |
286 | 74c62ba8 | aurel32 | } |
287 | 74c62ba8 | aurel32 | |
288 | 74c62ba8 | aurel32 | static int ppce500_pci_load(QEMUFile *f, void *opaque, int version_id) |
289 | 74c62ba8 | aurel32 | { |
290 | 74c62ba8 | aurel32 | PPCE500PCIState *controller = opaque; |
291 | 74c62ba8 | aurel32 | int i;
|
292 | 74c62ba8 | aurel32 | |
293 | 74c62ba8 | aurel32 | if (version_id != 1) |
294 | 74c62ba8 | aurel32 | return -EINVAL;
|
295 | 74c62ba8 | aurel32 | |
296 | 74c62ba8 | aurel32 | pci_device_load(controller->pci_dev, f); |
297 | 74c62ba8 | aurel32 | |
298 | 74c62ba8 | aurel32 | for (i = 0; i < PPCE500_PCI_NR_POBS; i++) { |
299 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->pob[i].potar); |
300 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->pob[i].potear); |
301 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->pob[i].powbar); |
302 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->pob[i].powar); |
303 | 74c62ba8 | aurel32 | } |
304 | 74c62ba8 | aurel32 | |
305 | 74c62ba8 | aurel32 | for (i = 0; i < PPCE500_PCI_NR_PIBS; i++) { |
306 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->pib[i].pitar); |
307 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->pib[i].piwbar); |
308 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->pib[i].piwbear); |
309 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->pib[i].piwar); |
310 | 74c62ba8 | aurel32 | } |
311 | 74c62ba8 | aurel32 | qemu_get_be32s(f, &controller->gasket_time); |
312 | 74c62ba8 | aurel32 | |
313 | 74c62ba8 | aurel32 | return 0; |
314 | 74c62ba8 | aurel32 | } |
315 | 74c62ba8 | aurel32 | |
316 | 74c62ba8 | aurel32 | PCIBus *ppce500_pci_init(qemu_irq pci_irqs[4], target_phys_addr_t registers)
|
317 | 74c62ba8 | aurel32 | { |
318 | 74c62ba8 | aurel32 | PPCE500PCIState *controller; |
319 | 74c62ba8 | aurel32 | PCIDevice *d; |
320 | 74c62ba8 | aurel32 | int index;
|
321 | 74c62ba8 | aurel32 | static int ppce500_pci_id; |
322 | 74c62ba8 | aurel32 | |
323 | 74c62ba8 | aurel32 | controller = qemu_mallocz(sizeof(PPCE500PCIState));
|
324 | 74c62ba8 | aurel32 | |
325 | 02e2da45 | Paul Brook | controller->pci_state.bus = pci_register_bus(NULL, "pci", |
326 | 02e2da45 | Paul Brook | mpc85xx_pci_set_irq, |
327 | 74c62ba8 | aurel32 | mpc85xx_pci_map_irq, |
328 | 74c62ba8 | aurel32 | pci_irqs, 0x88, 4); |
329 | 74c62ba8 | aurel32 | d = pci_register_device(controller->pci_state.bus, |
330 | 74c62ba8 | aurel32 | "host bridge", sizeof(PCIDevice), |
331 | 74c62ba8 | aurel32 | 0, NULL, NULL); |
332 | 74c62ba8 | aurel32 | |
333 | a770dc7e | aliguori | pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_FREESCALE); |
334 | a770dc7e | aliguori | pci_config_set_device_id(d->config, PCI_DEVICE_ID_MPC8533E); |
335 | 74c62ba8 | aurel32 | pci_config_set_class(d->config, PCI_CLASS_PROCESSOR_POWERPC); |
336 | 74c62ba8 | aurel32 | |
337 | 74c62ba8 | aurel32 | controller->pci_dev = d; |
338 | 74c62ba8 | aurel32 | |
339 | 74c62ba8 | aurel32 | /* CFGADDR */
|
340 | 1eed09cb | Avi Kivity | index = cpu_register_io_memory(pcie500_cfgaddr_read, |
341 | 74c62ba8 | aurel32 | pcie500_cfgaddr_write, controller); |
342 | 74c62ba8 | aurel32 | if (index < 0) |
343 | 74c62ba8 | aurel32 | goto free;
|
344 | 74c62ba8 | aurel32 | cpu_register_physical_memory(registers + PCIE500_CFGADDR, 4, index);
|
345 | 74c62ba8 | aurel32 | |
346 | 74c62ba8 | aurel32 | /* CFGDATA */
|
347 | 1eed09cb | Avi Kivity | index = cpu_register_io_memory(pcie500_cfgdata_read, |
348 | 74c62ba8 | aurel32 | pcie500_cfgdata_write, |
349 | 74c62ba8 | aurel32 | &controller->pci_state); |
350 | 74c62ba8 | aurel32 | if (index < 0) |
351 | 74c62ba8 | aurel32 | goto free;
|
352 | 74c62ba8 | aurel32 | cpu_register_physical_memory(registers + PCIE500_CFGDATA, 4, index);
|
353 | 74c62ba8 | aurel32 | |
354 | 1eed09cb | Avi Kivity | index = cpu_register_io_memory(e500_pci_reg_read, |
355 | 74c62ba8 | aurel32 | e500_pci_reg_write, controller); |
356 | 74c62ba8 | aurel32 | if (index < 0) |
357 | 74c62ba8 | aurel32 | goto free;
|
358 | 74c62ba8 | aurel32 | cpu_register_physical_memory(registers + PCIE500_REG_BASE, |
359 | 74c62ba8 | aurel32 | PCIE500_REG_SIZE, index); |
360 | 74c62ba8 | aurel32 | |
361 | 74c62ba8 | aurel32 | /* XXX load/save code not tested. */
|
362 | 74c62ba8 | aurel32 | register_savevm("ppce500_pci", ppce500_pci_id++, 1, |
363 | 74c62ba8 | aurel32 | ppce500_pci_save, ppce500_pci_load, controller); |
364 | 74c62ba8 | aurel32 | |
365 | 74c62ba8 | aurel32 | return controller->pci_state.bus;
|
366 | 74c62ba8 | aurel32 | |
367 | 74c62ba8 | aurel32 | free:
|
368 | 74c62ba8 | aurel32 | printf("%s error\n", __func__);
|
369 | 74c62ba8 | aurel32 | qemu_free(controller); |
370 | 74c62ba8 | aurel32 | return NULL; |
371 | 74c62ba8 | aurel32 | } |