2 * QEMU PowerPC E500 embedded processors pci controller emulation
4 * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
6 * Author: Yu Liu, <yu.liu@freescale.com>
8 * This file is derived from hw/ppc4xx_pci.c,
9 * the copyright for that material belongs to the original owners.
11 * This is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
20 typedef target_phys_addr_t pci_addr_t
;
27 #define pci_debug(fmt, arg...) fprintf(stderr, fmt, ##arg)
29 #define pci_debug(fmt, arg...)
32 #define PCIE500_CFGADDR 0x0
33 #define PCIE500_CFGDATA 0x4
34 #define PCIE500_REG_BASE 0xC00
35 #define PCIE500_REG_SIZE (0x1000 - PCIE500_REG_BASE)
37 #define PPCE500_PCI_CONFIG_ADDR 0x0
38 #define PPCE500_PCI_CONFIG_DATA 0x4
39 #define PPCE500_PCI_INTACK 0x8
41 #define PPCE500_PCI_OW1 (0xC20 - PCIE500_REG_BASE)
42 #define PPCE500_PCI_OW2 (0xC40 - PCIE500_REG_BASE)
43 #define PPCE500_PCI_OW3 (0xC60 - PCIE500_REG_BASE)
44 #define PPCE500_PCI_OW4 (0xC80 - PCIE500_REG_BASE)
45 #define PPCE500_PCI_IW3 (0xDA0 - PCIE500_REG_BASE)
46 #define PPCE500_PCI_IW2 (0xDC0 - PCIE500_REG_BASE)
47 #define PPCE500_PCI_IW1 (0xDE0 - PCIE500_REG_BASE)
49 #define PPCE500_PCI_GASKET_TIMR (0xE20 - PCIE500_REG_BASE)
52 #define PCI_POTEAR 0x4
53 #define PCI_POWBAR 0x8
54 #define PCI_POWAR 0x10
57 #define PCI_PIWBAR 0x8
58 #define PCI_PIWBEAR 0xC
59 #define PCI_PIWAR 0x10
61 #define PPCE500_PCI_NR_POBS 5
62 #define PPCE500_PCI_NR_PIBS 3
78 struct PPCE500PCIState
{
79 struct pci_outbound pob
[PPCE500_PCI_NR_POBS
];
80 struct pci_inbound pib
[PPCE500_PCI_NR_PIBS
];
82 PCIHostState pci_state
;
86 typedef struct PPCE500PCIState PPCE500PCIState
;
88 static uint32_t pcie500_cfgaddr_readl(void *opaque
, target_phys_addr_t addr
)
90 PPCE500PCIState
*pci
= opaque
;
92 pci_debug("%s: (addr:%Lx) -> value:%x\n", __func__
, addr
,
93 pci
->pci_state
.config_reg
);
94 return pci
->pci_state
.config_reg
;
97 static CPUReadMemoryFunc
*pcie500_cfgaddr_read
[] = {
98 &pcie500_cfgaddr_readl
,
99 &pcie500_cfgaddr_readl
,
100 &pcie500_cfgaddr_readl
,
103 static void pcie500_cfgaddr_writel(void *opaque
, target_phys_addr_t addr
,
106 PPCE500PCIState
*controller
= opaque
;
108 pci_debug("%s: value:%x -> (addr%Lx)\n", __func__
, value
, addr
);
109 controller
->pci_state
.config_reg
= value
& ~0x3;
112 static CPUWriteMemoryFunc
*pcie500_cfgaddr_write
[] = {
113 &pcie500_cfgaddr_writel
,
114 &pcie500_cfgaddr_writel
,
115 &pcie500_cfgaddr_writel
,
118 static CPUReadMemoryFunc
*pcie500_cfgdata_read
[] = {
119 &pci_host_data_readb
,
120 &pci_host_data_readw
,
121 &pci_host_data_readl
,
124 static CPUWriteMemoryFunc
*pcie500_cfgdata_write
[] = {
125 &pci_host_data_writeb
,
126 &pci_host_data_writew
,
127 &pci_host_data_writel
,
130 static uint32_t pci_reg_read4(void *opaque
, target_phys_addr_t addr
)
132 PPCE500PCIState
*pci
= opaque
;
139 case PPCE500_PCI_OW1
:
140 case PPCE500_PCI_OW2
:
141 case PPCE500_PCI_OW3
:
142 case PPCE500_PCI_OW4
:
143 switch (addr
& 0xC) {
144 case PCI_POTAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].potar
; break;
145 case PCI_POTEAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].potear
; break;
146 case PCI_POWBAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].powbar
; break;
147 case PCI_POWAR
: value
= pci
->pob
[(addr
>> 5) & 0x7].powar
; break;
152 case PPCE500_PCI_IW3
:
153 case PPCE500_PCI_IW2
:
154 case PPCE500_PCI_IW1
:
155 switch (addr
& 0xC) {
156 case PCI_PITAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].pitar
; break;
157 case PCI_PIWBAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwbar
; break;
158 case PCI_PIWBEAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwbear
; break;
159 case PCI_PIWAR
: value
= pci
->pib
[(addr
>> 5) & 0x3].piwar
; break;
164 case PPCE500_PCI_GASKET_TIMR
:
165 value
= pci
->gasket_time
;
172 pci_debug("%s: win:%lx(addr:%Lx) -> value:%x\n",__func__
,win
,addr
,value
);
176 static CPUReadMemoryFunc
*e500_pci_reg_read
[] = {
182 static void pci_reg_write4(void *opaque
, target_phys_addr_t addr
,
185 PPCE500PCIState
*pci
= opaque
;
190 pci_debug("%s: value:%x -> win:%lx(addr:%Lx)\n",__func__
,value
,win
,addr
);
193 case PPCE500_PCI_OW1
:
194 case PPCE500_PCI_OW2
:
195 case PPCE500_PCI_OW3
:
196 case PPCE500_PCI_OW4
:
197 switch (addr
& 0xC) {
198 case PCI_POTAR
: pci
->pob
[(addr
>> 5) & 0x7].potar
= value
; break;
199 case PCI_POTEAR
: pci
->pob
[(addr
>> 5) & 0x7].potear
= value
; break;
200 case PCI_POWBAR
: pci
->pob
[(addr
>> 5) & 0x7].powbar
= value
; break;
201 case PCI_POWAR
: pci
->pob
[(addr
>> 5) & 0x7].powar
= value
; break;
206 case PPCE500_PCI_IW3
:
207 case PPCE500_PCI_IW2
:
208 case PPCE500_PCI_IW1
:
209 switch (addr
& 0xC) {
210 case PCI_PITAR
: pci
->pib
[(addr
>> 5) & 0x3].pitar
= value
; break;
211 case PCI_PIWBAR
: pci
->pib
[(addr
>> 5) & 0x3].piwbar
= value
; break;
212 case PCI_PIWBEAR
: pci
->pib
[(addr
>> 5) & 0x3].piwbear
= value
; break;
213 case PCI_PIWAR
: pci
->pib
[(addr
>> 5) & 0x3].piwar
= value
; break;
218 case PPCE500_PCI_GASKET_TIMR
:
219 pci
->gasket_time
= value
;
227 static CPUWriteMemoryFunc
*e500_pci_reg_write
[] = {
233 static int mpc85xx_pci_map_irq(PCIDevice
*pci_dev
, int irq_num
)
235 int devno
= pci_dev
->devfn
>> 3, ret
= 0;
241 ret
= (irq_num
+ devno
- 0x10) % 4;
244 printf("Error:%s:unknow dev number\n", __func__
);
247 pci_debug("%s: devfn %x irq %d -> %d devno:%x\n", __func__
,
248 pci_dev
->devfn
, irq_num
, ret
, devno
);
253 static void mpc85xx_pci_set_irq(qemu_irq
*pic
, int irq_num
, int level
)
255 pci_debug("%s: PCI irq %d, level:%d\n", __func__
, irq_num
, level
);
257 qemu_set_irq(pic
[irq_num
], level
);
260 static void ppce500_pci_save(QEMUFile
*f
, void *opaque
)
262 PPCE500PCIState
*controller
= opaque
;
265 pci_device_save(controller
->pci_dev
, f
);
267 for (i
= 0; i
< PPCE500_PCI_NR_POBS
; i
++) {
268 qemu_put_be32s(f
, &controller
->pob
[i
].potar
);
269 qemu_put_be32s(f
, &controller
->pob
[i
].potear
);
270 qemu_put_be32s(f
, &controller
->pob
[i
].powbar
);
271 qemu_put_be32s(f
, &controller
->pob
[i
].powar
);
274 for (i
= 0; i
< PPCE500_PCI_NR_PIBS
; i
++) {
275 qemu_put_be32s(f
, &controller
->pib
[i
].pitar
);
276 qemu_put_be32s(f
, &controller
->pib
[i
].piwbar
);
277 qemu_put_be32s(f
, &controller
->pib
[i
].piwbear
);
278 qemu_put_be32s(f
, &controller
->pib
[i
].piwar
);
280 qemu_put_be32s(f
, &controller
->gasket_time
);
283 static int ppce500_pci_load(QEMUFile
*f
, void *opaque
, int version_id
)
285 PPCE500PCIState
*controller
= opaque
;
291 pci_device_load(controller
->pci_dev
, f
);
293 for (i
= 0; i
< PPCE500_PCI_NR_POBS
; i
++) {
294 qemu_get_be32s(f
, &controller
->pob
[i
].potar
);
295 qemu_get_be32s(f
, &controller
->pob
[i
].potear
);
296 qemu_get_be32s(f
, &controller
->pob
[i
].powbar
);
297 qemu_get_be32s(f
, &controller
->pob
[i
].powar
);
300 for (i
= 0; i
< PPCE500_PCI_NR_PIBS
; i
++) {
301 qemu_get_be32s(f
, &controller
->pib
[i
].pitar
);
302 qemu_get_be32s(f
, &controller
->pib
[i
].piwbar
);
303 qemu_get_be32s(f
, &controller
->pib
[i
].piwbear
);
304 qemu_get_be32s(f
, &controller
->pib
[i
].piwar
);
306 qemu_get_be32s(f
, &controller
->gasket_time
);
311 PCIBus
*ppce500_pci_init(qemu_irq pci_irqs
[4], target_phys_addr_t registers
)
313 PPCE500PCIState
*controller
;
316 static int ppce500_pci_id
;
318 controller
= qemu_mallocz(sizeof(PPCE500PCIState
));
320 controller
->pci_state
.bus
= pci_register_bus(mpc85xx_pci_set_irq
,
323 d
= pci_register_device(controller
->pci_state
.bus
,
324 "host bridge", sizeof(PCIDevice
),
327 pci_config_set_vendor_id(d
->config
, PCI_VENDOR_ID_FSL
);
328 pci_config_set_device_id(d
->config
, PCI_DEVICE_ID_FSL_E500
);
329 pci_config_set_class(d
->config
, PCI_CLASS_PROCESSOR_POWERPC
);
331 controller
->pci_dev
= d
;
334 index
= cpu_register_io_memory(0, pcie500_cfgaddr_read
,
335 pcie500_cfgaddr_write
, controller
);
338 cpu_register_physical_memory(registers
+ PCIE500_CFGADDR
, 4, index
);
341 index
= cpu_register_io_memory(0, pcie500_cfgdata_read
,
342 pcie500_cfgdata_write
,
343 &controller
->pci_state
);
346 cpu_register_physical_memory(registers
+ PCIE500_CFGDATA
, 4, index
);
348 index
= cpu_register_io_memory(0, e500_pci_reg_read
,
349 e500_pci_reg_write
, controller
);
352 cpu_register_physical_memory(registers
+ PCIE500_REG_BASE
,
353 PCIE500_REG_SIZE
, index
);
355 /* XXX load/save code not tested. */
356 register_savevm("ppce500_pci", ppce500_pci_id
++, 1,
357 ppce500_pci_save
, ppce500_pci_load
, controller
);
359 return controller
->pci_state
.bus
;
362 printf("%s error\n", __func__
);
363 qemu_free(controller
);