target-arm: convert NEON VZIP/VUZP/VTRN helper functions to pure TCG
[qemu/aliguori-queue.git] / hw / ppce500_pci.c
blob64fccfdbc6fc502a702b68ea0b2564b4d8954534
1 /*
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.
17 #include "hw.h"
18 #include "ppc.h"
19 #include "ppce500.h"
20 typedef target_phys_addr_t pci_addr_t;
21 #include "pci.h"
22 #include "pci_host.h"
23 #include "bswap.h"
24 #include "qemu-log.h"
26 #ifdef DEBUG_PCI
27 #define pci_debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
28 #else
29 #define pci_debug(fmt, ...)
30 #endif
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)
51 #define PCI_POTAR 0x0
52 #define PCI_POTEAR 0x4
53 #define PCI_POWBAR 0x8
54 #define PCI_POWAR 0x10
56 #define PCI_PITAR 0x0
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
64 struct pci_outbound {
65 uint32_t potar;
66 uint32_t potear;
67 uint32_t powbar;
68 uint32_t powar;
71 struct pci_inbound {
72 uint32_t pitar;
73 uint32_t piwbar;
74 uint32_t piwbear;
75 uint32_t piwar;
78 struct PPCE500PCIState {
79 struct pci_outbound pob[PPCE500_PCI_NR_POBS];
80 struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
81 uint32_t gasket_time;
82 PCIHostState pci_state;
83 PCIDevice *pci_dev;
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:" TARGET_FMT_plx ") -> value:%x\n", __func__, addr,
93 pci->pci_state.config_reg);
94 return pci->pci_state.config_reg;
97 static CPUReadMemoryFunc * const 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,
104 uint32_t value)
106 PPCE500PCIState *controller = opaque;
108 pci_debug("%s: value:%x -> (addr:" TARGET_FMT_plx ")\n", __func__, value,
109 addr);
110 controller->pci_state.config_reg = value & ~0x3;
113 static CPUWriteMemoryFunc * const pcie500_cfgaddr_write[] = {
114 &pcie500_cfgaddr_writel,
115 &pcie500_cfgaddr_writel,
116 &pcie500_cfgaddr_writel,
119 static CPUReadMemoryFunc * const pcie500_cfgdata_read[] = {
120 &pci_host_data_readb,
121 &pci_host_data_readw,
122 &pci_host_data_readl,
125 static CPUWriteMemoryFunc * const pcie500_cfgdata_write[] = {
126 &pci_host_data_writeb,
127 &pci_host_data_writew,
128 &pci_host_data_writel,
131 static uint32_t pci_reg_read4(void *opaque, target_phys_addr_t addr)
133 PPCE500PCIState *pci = opaque;
134 unsigned long win;
135 uint32_t value = 0;
137 win = addr & 0xfe0;
139 switch (win) {
140 case PPCE500_PCI_OW1:
141 case PPCE500_PCI_OW2:
142 case PPCE500_PCI_OW3:
143 case PPCE500_PCI_OW4:
144 switch (addr & 0xC) {
145 case PCI_POTAR: value = pci->pob[(addr >> 5) & 0x7].potar; break;
146 case PCI_POTEAR: value = pci->pob[(addr >> 5) & 0x7].potear; break;
147 case PCI_POWBAR: value = pci->pob[(addr >> 5) & 0x7].powbar; break;
148 case PCI_POWAR: value = pci->pob[(addr >> 5) & 0x7].powar; break;
149 default: break;
151 break;
153 case PPCE500_PCI_IW3:
154 case PPCE500_PCI_IW2:
155 case PPCE500_PCI_IW1:
156 switch (addr & 0xC) {
157 case PCI_PITAR: value = pci->pib[(addr >> 5) & 0x3].pitar; break;
158 case PCI_PIWBAR: value = pci->pib[(addr >> 5) & 0x3].piwbar; break;
159 case PCI_PIWBEAR: value = pci->pib[(addr >> 5) & 0x3].piwbear; break;
160 case PCI_PIWAR: value = pci->pib[(addr >> 5) & 0x3].piwar; break;
161 default: break;
163 break;
165 case PPCE500_PCI_GASKET_TIMR:
166 value = pci->gasket_time;
167 break;
169 default:
170 break;
173 pci_debug("%s: win:%lx(addr:" TARGET_FMT_plx ") -> value:%x\n", __func__,
174 win, addr, value);
175 return value;
178 static CPUReadMemoryFunc * const e500_pci_reg_read[] = {
179 &pci_reg_read4,
180 &pci_reg_read4,
181 &pci_reg_read4,
184 static void pci_reg_write4(void *opaque, target_phys_addr_t addr,
185 uint32_t value)
187 PPCE500PCIState *pci = opaque;
188 unsigned long win;
190 win = addr & 0xfe0;
192 pci_debug("%s: value:%x -> win:%lx(addr:" TARGET_FMT_plx ")\n",
193 __func__, value, win, addr);
195 switch (win) {
196 case PPCE500_PCI_OW1:
197 case PPCE500_PCI_OW2:
198 case PPCE500_PCI_OW3:
199 case PPCE500_PCI_OW4:
200 switch (addr & 0xC) {
201 case PCI_POTAR: pci->pob[(addr >> 5) & 0x7].potar = value; break;
202 case PCI_POTEAR: pci->pob[(addr >> 5) & 0x7].potear = value; break;
203 case PCI_POWBAR: pci->pob[(addr >> 5) & 0x7].powbar = value; break;
204 case PCI_POWAR: pci->pob[(addr >> 5) & 0x7].powar = value; break;
205 default: break;
207 break;
209 case PPCE500_PCI_IW3:
210 case PPCE500_PCI_IW2:
211 case PPCE500_PCI_IW1:
212 switch (addr & 0xC) {
213 case PCI_PITAR: pci->pib[(addr >> 5) & 0x3].pitar = value; break;
214 case PCI_PIWBAR: pci->pib[(addr >> 5) & 0x3].piwbar = value; break;
215 case PCI_PIWBEAR: pci->pib[(addr >> 5) & 0x3].piwbear = value; break;
216 case PCI_PIWAR: pci->pib[(addr >> 5) & 0x3].piwar = value; break;
217 default: break;
219 break;
221 case PPCE500_PCI_GASKET_TIMR:
222 pci->gasket_time = value;
223 break;
225 default:
226 break;
230 static CPUWriteMemoryFunc * const e500_pci_reg_write[] = {
231 &pci_reg_write4,
232 &pci_reg_write4,
233 &pci_reg_write4,
236 static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int irq_num)
238 int devno = pci_dev->devfn >> 3, ret = 0;
240 switch (devno) {
241 /* Two PCI slot */
242 case 0x11:
243 case 0x12:
244 ret = (irq_num + devno - 0x10) % 4;
245 break;
246 default:
247 printf("Error:%s:unknow dev number\n", __func__);
250 pci_debug("%s: devfn %x irq %d -> %d devno:%x\n", __func__,
251 pci_dev->devfn, irq_num, ret, devno);
253 return ret;
256 static void mpc85xx_pci_set_irq(void *opaque, int irq_num, int level)
258 qemu_irq *pic = opaque;
260 pci_debug("%s: PCI irq %d, level:%d\n", __func__, irq_num, level);
262 qemu_set_irq(pic[irq_num], level);
265 static void ppce500_pci_save(QEMUFile *f, void *opaque)
267 PPCE500PCIState *controller = opaque;
268 int i;
270 pci_device_save(controller->pci_dev, f);
272 for (i = 0; i < PPCE500_PCI_NR_POBS; i++) {
273 qemu_put_be32s(f, &controller->pob[i].potar);
274 qemu_put_be32s(f, &controller->pob[i].potear);
275 qemu_put_be32s(f, &controller->pob[i].powbar);
276 qemu_put_be32s(f, &controller->pob[i].powar);
279 for (i = 0; i < PPCE500_PCI_NR_PIBS; i++) {
280 qemu_put_be32s(f, &controller->pib[i].pitar);
281 qemu_put_be32s(f, &controller->pib[i].piwbar);
282 qemu_put_be32s(f, &controller->pib[i].piwbear);
283 qemu_put_be32s(f, &controller->pib[i].piwar);
285 qemu_put_be32s(f, &controller->gasket_time);
288 static int ppce500_pci_load(QEMUFile *f, void *opaque, int version_id)
290 PPCE500PCIState *controller = opaque;
291 int i;
293 if (version_id != 1)
294 return -EINVAL;
296 pci_device_load(controller->pci_dev, f);
298 for (i = 0; i < PPCE500_PCI_NR_POBS; i++) {
299 qemu_get_be32s(f, &controller->pob[i].potar);
300 qemu_get_be32s(f, &controller->pob[i].potear);
301 qemu_get_be32s(f, &controller->pob[i].powbar);
302 qemu_get_be32s(f, &controller->pob[i].powar);
305 for (i = 0; i < PPCE500_PCI_NR_PIBS; i++) {
306 qemu_get_be32s(f, &controller->pib[i].pitar);
307 qemu_get_be32s(f, &controller->pib[i].piwbar);
308 qemu_get_be32s(f, &controller->pib[i].piwbear);
309 qemu_get_be32s(f, &controller->pib[i].piwar);
311 qemu_get_be32s(f, &controller->gasket_time);
313 return 0;
316 PCIBus *ppce500_pci_init(qemu_irq pci_irqs[4], target_phys_addr_t registers)
318 PPCE500PCIState *controller;
319 PCIDevice *d;
320 int index;
321 static int ppce500_pci_id;
323 controller = qemu_mallocz(sizeof(PPCE500PCIState));
325 controller->pci_state.bus = pci_register_bus(NULL, "pci",
326 mpc85xx_pci_set_irq,
327 mpc85xx_pci_map_irq,
328 pci_irqs, 0x88, 4);
329 d = pci_register_device(controller->pci_state.bus,
330 "host bridge", sizeof(PCIDevice),
331 0, NULL, NULL);
333 pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_FREESCALE);
334 pci_config_set_device_id(d->config, PCI_DEVICE_ID_MPC8533E);
335 pci_config_set_class(d->config, PCI_CLASS_PROCESSOR_POWERPC);
337 controller->pci_dev = d;
339 /* CFGADDR */
340 index = cpu_register_io_memory(pcie500_cfgaddr_read,
341 pcie500_cfgaddr_write, controller);
342 if (index < 0)
343 goto free;
344 cpu_register_physical_memory(registers + PCIE500_CFGADDR, 4, index);
346 /* CFGDATA */
347 index = cpu_register_io_memory(pcie500_cfgdata_read,
348 pcie500_cfgdata_write,
349 &controller->pci_state);
350 if (index < 0)
351 goto free;
352 cpu_register_physical_memory(registers + PCIE500_CFGDATA, 4, index);
354 index = cpu_register_io_memory(e500_pci_reg_read,
355 e500_pci_reg_write, controller);
356 if (index < 0)
357 goto free;
358 cpu_register_physical_memory(registers + PCIE500_REG_BASE,
359 PCIE500_REG_SIZE, index);
361 /* XXX load/save code not tested. */
362 register_savevm("ppce500_pci", ppce500_pci_id++, 1,
363 ppce500_pci_save, ppce500_pci_load, controller);
365 return controller->pci_state.bus;
367 free:
368 printf("%s error\n", __func__);
369 qemu_free(controller);
370 return NULL;