Statistics
| Branch: | Revision:

root / hw / ppc4xx_pci.c @ 44a99354

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