Statistics
| Branch: | Revision:

root / hw / ppc4xx_pci.c @ b79e1752

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