2009-03-02 16:42:23 +00:00
|
|
|
/*
|
|
|
|
* QEMU PowerPC E500 embedded processors pci controller emulation
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Author: Yu Liu, <yu.liu@freescale.com>
|
|
|
|
*
|
|
|
|
* This file is derived from hw/ppc4xx_pci.c,
|
|
|
|
* the copyright for that material belongs to the original owners.
|
|
|
|
*
|
|
|
|
* This is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hw.h"
|
|
|
|
#include "pci.h"
|
|
|
|
#include "pci_host.h"
|
|
|
|
#include "bswap.h"
|
|
|
|
|
|
|
|
#ifdef DEBUG_PCI
|
2009-05-13 17:53:17 +00:00
|
|
|
#define pci_debug(fmt, ...) fprintf(stderr, fmt, ## __VA_ARGS__)
|
2009-03-02 16:42:23 +00:00
|
|
|
#else
|
2009-05-13 17:53:17 +00:00
|
|
|
#define pci_debug(fmt, ...)
|
2009-03-02 16:42:23 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#define PCIE500_CFGADDR 0x0
|
|
|
|
#define PCIE500_CFGDATA 0x4
|
|
|
|
#define PCIE500_REG_BASE 0xC00
|
2010-08-30 22:22:28 +00:00
|
|
|
#define PCIE500_ALL_SIZE 0x1000
|
|
|
|
#define PCIE500_REG_SIZE (PCIE500_ALL_SIZE - PCIE500_REG_BASE)
|
2009-03-02 16:42:23 +00:00
|
|
|
|
|
|
|
#define PPCE500_PCI_CONFIG_ADDR 0x0
|
|
|
|
#define PPCE500_PCI_CONFIG_DATA 0x4
|
|
|
|
#define PPCE500_PCI_INTACK 0x8
|
|
|
|
|
|
|
|
#define PPCE500_PCI_OW1 (0xC20 - PCIE500_REG_BASE)
|
|
|
|
#define PPCE500_PCI_OW2 (0xC40 - PCIE500_REG_BASE)
|
|
|
|
#define PPCE500_PCI_OW3 (0xC60 - PCIE500_REG_BASE)
|
|
|
|
#define PPCE500_PCI_OW4 (0xC80 - PCIE500_REG_BASE)
|
|
|
|
#define PPCE500_PCI_IW3 (0xDA0 - PCIE500_REG_BASE)
|
|
|
|
#define PPCE500_PCI_IW2 (0xDC0 - PCIE500_REG_BASE)
|
|
|
|
#define PPCE500_PCI_IW1 (0xDE0 - PCIE500_REG_BASE)
|
|
|
|
|
|
|
|
#define PPCE500_PCI_GASKET_TIMR (0xE20 - PCIE500_REG_BASE)
|
|
|
|
|
|
|
|
#define PCI_POTAR 0x0
|
|
|
|
#define PCI_POTEAR 0x4
|
|
|
|
#define PCI_POWBAR 0x8
|
|
|
|
#define PCI_POWAR 0x10
|
|
|
|
|
|
|
|
#define PCI_PITAR 0x0
|
|
|
|
#define PCI_PIWBAR 0x8
|
|
|
|
#define PCI_PIWBEAR 0xC
|
|
|
|
#define PCI_PIWAR 0x10
|
|
|
|
|
|
|
|
#define PPCE500_PCI_NR_POBS 5
|
|
|
|
#define PPCE500_PCI_NR_PIBS 3
|
|
|
|
|
|
|
|
struct pci_outbound {
|
|
|
|
uint32_t potar;
|
|
|
|
uint32_t potear;
|
|
|
|
uint32_t powbar;
|
|
|
|
uint32_t powar;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct pci_inbound {
|
|
|
|
uint32_t pitar;
|
|
|
|
uint32_t piwbar;
|
|
|
|
uint32_t piwbear;
|
|
|
|
uint32_t piwar;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PPCE500PCIState {
|
2010-08-30 22:22:28 +00:00
|
|
|
PCIHostState pci_state;
|
2009-03-02 16:42:23 +00:00
|
|
|
struct pci_outbound pob[PPCE500_PCI_NR_POBS];
|
|
|
|
struct pci_inbound pib[PPCE500_PCI_NR_PIBS];
|
|
|
|
uint32_t gasket_time;
|
2010-08-30 22:22:28 +00:00
|
|
|
qemu_irq irq[4];
|
|
|
|
/* mmio maps */
|
2011-11-20 09:52:58 +00:00
|
|
|
MemoryRegion iomem;
|
2009-03-02 16:42:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct PPCE500PCIState PPCE500PCIState;
|
|
|
|
|
2011-11-20 09:52:58 +00:00
|
|
|
static uint64_t pci_reg_read4(void *opaque, target_phys_addr_t addr,
|
|
|
|
unsigned size)
|
2009-03-02 16:42:23 +00:00
|
|
|
{
|
|
|
|
PPCE500PCIState *pci = opaque;
|
|
|
|
unsigned long win;
|
|
|
|
uint32_t value = 0;
|
2011-09-29 17:52:50 +00:00
|
|
|
int idx;
|
2009-03-02 16:42:23 +00:00
|
|
|
|
|
|
|
win = addr & 0xfe0;
|
|
|
|
|
|
|
|
switch (win) {
|
|
|
|
case PPCE500_PCI_OW1:
|
|
|
|
case PPCE500_PCI_OW2:
|
|
|
|
case PPCE500_PCI_OW3:
|
|
|
|
case PPCE500_PCI_OW4:
|
2011-09-29 17:52:50 +00:00
|
|
|
idx = (addr >> 5) & 0x7;
|
2009-03-02 16:42:23 +00:00
|
|
|
switch (addr & 0xC) {
|
2011-09-29 17:52:49 +00:00
|
|
|
case PCI_POTAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
value = pci->pob[idx].potar;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_POTEAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
value = pci->pob[idx].potear;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_POWBAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
value = pci->pob[idx].powbar;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_POWAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
value = pci->pob[idx].powar;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-03-02 16:42:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPCE500_PCI_IW3:
|
|
|
|
case PPCE500_PCI_IW2:
|
|
|
|
case PPCE500_PCI_IW1:
|
2011-09-29 17:52:50 +00:00
|
|
|
idx = ((addr >> 5) & 0x3) - 1;
|
2009-03-02 16:42:23 +00:00
|
|
|
switch (addr & 0xC) {
|
2011-09-29 17:52:49 +00:00
|
|
|
case PCI_PITAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
value = pci->pib[idx].pitar;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_PIWBAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
value = pci->pib[idx].piwbar;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_PIWBEAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
value = pci->pib[idx].piwbear;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_PIWAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
value = pci->pib[idx].piwar;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-03-02 16:42:23 +00:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPCE500_PCI_GASKET_TIMR:
|
|
|
|
value = pci->gasket_time;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-07-20 10:37:51 +00:00
|
|
|
pci_debug("%s: win:%lx(addr:" TARGET_FMT_plx ") -> value:%x\n", __func__,
|
|
|
|
win, addr, value);
|
2009-03-02 16:42:23 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2009-10-01 21:12:16 +00:00
|
|
|
static void pci_reg_write4(void *opaque, target_phys_addr_t addr,
|
2011-11-20 09:52:58 +00:00
|
|
|
uint64_t value, unsigned size)
|
2009-03-02 16:42:23 +00:00
|
|
|
{
|
|
|
|
PPCE500PCIState *pci = opaque;
|
|
|
|
unsigned long win;
|
2011-09-29 17:52:50 +00:00
|
|
|
int idx;
|
2009-03-02 16:42:23 +00:00
|
|
|
|
|
|
|
win = addr & 0xfe0;
|
|
|
|
|
2009-07-20 10:37:51 +00:00
|
|
|
pci_debug("%s: value:%x -> win:%lx(addr:" TARGET_FMT_plx ")\n",
|
2011-11-20 09:52:58 +00:00
|
|
|
__func__, (unsigned)value, win, addr);
|
2009-03-02 16:42:23 +00:00
|
|
|
|
|
|
|
switch (win) {
|
|
|
|
case PPCE500_PCI_OW1:
|
|
|
|
case PPCE500_PCI_OW2:
|
|
|
|
case PPCE500_PCI_OW3:
|
|
|
|
case PPCE500_PCI_OW4:
|
2011-09-29 17:52:50 +00:00
|
|
|
idx = (addr >> 5) & 0x7;
|
2009-03-02 16:42:23 +00:00
|
|
|
switch (addr & 0xC) {
|
2011-09-29 17:52:49 +00:00
|
|
|
case PCI_POTAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
pci->pob[idx].potar = value;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_POTEAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
pci->pob[idx].potear = value;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_POWBAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
pci->pob[idx].powbar = value;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_POWAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
pci->pob[idx].powar = value;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-03-02 16:42:23 +00:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPCE500_PCI_IW3:
|
|
|
|
case PPCE500_PCI_IW2:
|
|
|
|
case PPCE500_PCI_IW1:
|
2011-09-29 17:52:50 +00:00
|
|
|
idx = ((addr >> 5) & 0x3) - 1;
|
2009-03-02 16:42:23 +00:00
|
|
|
switch (addr & 0xC) {
|
2011-09-29 17:52:49 +00:00
|
|
|
case PCI_PITAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
pci->pib[idx].pitar = value;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_PIWBAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
pci->pib[idx].piwbar = value;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_PIWBEAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
pci->pib[idx].piwbear = value;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
case PCI_PIWAR:
|
2011-09-29 17:52:50 +00:00
|
|
|
pci->pib[idx].piwar = value;
|
2011-09-29 17:52:49 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2009-03-02 16:42:23 +00:00
|
|
|
};
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PPCE500_PCI_GASKET_TIMR:
|
|
|
|
pci->gasket_time = value;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2011-11-20 09:52:58 +00:00
|
|
|
static const MemoryRegionOps e500_pci_reg_ops = {
|
|
|
|
.read = pci_reg_read4,
|
|
|
|
.write = pci_reg_write4,
|
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
2009-03-02 16:42:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int irq_num)
|
|
|
|
{
|
|
|
|
int devno = pci_dev->devfn >> 3, ret = 0;
|
|
|
|
|
|
|
|
switch (devno) {
|
|
|
|
/* Two PCI slot */
|
|
|
|
case 0x11:
|
|
|
|
case 0x12:
|
|
|
|
ret = (irq_num + devno - 0x10) % 4;
|
|
|
|
break;
|
|
|
|
default:
|
2011-04-08 22:06:37 +00:00
|
|
|
printf("Error:%s:unknown dev number\n", __func__);
|
2009-03-02 16:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pci_debug("%s: devfn %x irq %d -> %d devno:%x\n", __func__,
|
|
|
|
pci_dev->devfn, irq_num, ret, devno);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-08-28 13:28:17 +00:00
|
|
|
static void mpc85xx_pci_set_irq(void *opaque, int irq_num, int level)
|
2009-03-02 16:42:23 +00:00
|
|
|
{
|
2009-08-28 13:28:17 +00:00
|
|
|
qemu_irq *pic = opaque;
|
|
|
|
|
2009-03-02 16:42:23 +00:00
|
|
|
pci_debug("%s: PCI irq %d, level:%d\n", __func__, irq_num, level);
|
|
|
|
|
|
|
|
qemu_set_irq(pic[irq_num], level);
|
|
|
|
}
|
|
|
|
|
2010-12-02 14:29:42 +00:00
|
|
|
static const VMStateDescription vmstate_pci_outbound = {
|
|
|
|
.name = "pci_outbound",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.minimum_version_id_old = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(potar, struct pci_outbound),
|
|
|
|
VMSTATE_UINT32(potear, struct pci_outbound),
|
|
|
|
VMSTATE_UINT32(powbar, struct pci_outbound),
|
|
|
|
VMSTATE_UINT32(powar, struct pci_outbound),
|
|
|
|
VMSTATE_END_OF_LIST()
|
2009-03-02 16:42:23 +00:00
|
|
|
}
|
2010-12-02 14:29:42 +00:00
|
|
|
};
|
2009-03-02 16:42:23 +00:00
|
|
|
|
2010-12-02 14:29:42 +00:00
|
|
|
static const VMStateDescription vmstate_pci_inbound = {
|
|
|
|
.name = "pci_inbound",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.minimum_version_id_old = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(pitar, struct pci_inbound),
|
|
|
|
VMSTATE_UINT32(piwbar, struct pci_inbound),
|
|
|
|
VMSTATE_UINT32(piwbear, struct pci_inbound),
|
|
|
|
VMSTATE_UINT32(piwar, struct pci_inbound),
|
|
|
|
VMSTATE_END_OF_LIST()
|
2009-03-02 16:42:23 +00:00
|
|
|
}
|
2010-12-02 14:29:42 +00:00
|
|
|
};
|
2009-03-02 16:42:23 +00:00
|
|
|
|
2010-12-02 14:29:42 +00:00
|
|
|
static const VMStateDescription vmstate_ppce500_pci = {
|
|
|
|
.name = "ppce500_pci",
|
|
|
|
.version_id = 1,
|
|
|
|
.minimum_version_id = 1,
|
|
|
|
.minimum_version_id_old = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_STRUCT_ARRAY(pob, PPCE500PCIState, PPCE500_PCI_NR_POBS, 1,
|
|
|
|
vmstate_pci_outbound, struct pci_outbound),
|
|
|
|
VMSTATE_STRUCT_ARRAY(pib, PPCE500PCIState, PPCE500_PCI_NR_PIBS, 1,
|
|
|
|
vmstate_pci_outbound, struct pci_inbound),
|
|
|
|
VMSTATE_UINT32(gasket_time, PPCE500PCIState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
2009-03-02 16:42:23 +00:00
|
|
|
}
|
2010-12-02 14:29:42 +00:00
|
|
|
};
|
2009-03-02 16:42:23 +00:00
|
|
|
|
2010-08-30 22:22:28 +00:00
|
|
|
static void e500_pci_map(SysBusDevice *dev, target_phys_addr_t base)
|
|
|
|
{
|
|
|
|
PCIHostState *h = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
|
|
|
|
PPCE500PCIState *s = DO_UPCAST(PPCE500PCIState, pci_state, h);
|
|
|
|
|
2011-07-24 14:47:18 +00:00
|
|
|
sysbus_add_memory(dev, base + PCIE500_CFGADDR, &h->conf_mem);
|
|
|
|
sysbus_add_memory(dev, base + PCIE500_CFGDATA, &h->data_mem);
|
2011-11-20 09:52:58 +00:00
|
|
|
sysbus_add_memory(dev, base + PCIE500_REG_BASE, &s->iomem);
|
2010-08-30 22:22:28 +00:00
|
|
|
}
|
|
|
|
|
2011-08-15 14:17:33 +00:00
|
|
|
static void e500_pci_unmap(SysBusDevice *dev, target_phys_addr_t base)
|
|
|
|
{
|
2011-07-24 14:47:18 +00:00
|
|
|
PCIHostState *h = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
|
2011-11-20 09:52:58 +00:00
|
|
|
PPCE500PCIState *s = DO_UPCAST(PPCE500PCIState, pci_state, h);
|
2011-07-24 14:47:18 +00:00
|
|
|
|
|
|
|
sysbus_del_memory(dev, &h->conf_mem);
|
|
|
|
sysbus_del_memory(dev, &h->data_mem);
|
2011-11-20 09:52:58 +00:00
|
|
|
sysbus_del_memory(dev, &s->iomem);
|
2011-08-15 14:17:33 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 11:26:19 +00:00
|
|
|
#include "exec-memory.h"
|
|
|
|
|
2010-08-30 22:22:28 +00:00
|
|
|
static int e500_pcihost_initfn(SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
PCIHostState *h;
|
|
|
|
PPCE500PCIState *s;
|
|
|
|
PCIBus *b;
|
|
|
|
int i;
|
2011-08-08 13:09:04 +00:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
|
|
|
MemoryRegion *address_space_io = get_system_io();
|
2010-08-30 22:22:28 +00:00
|
|
|
|
|
|
|
h = FROM_SYSBUS(PCIHostState, sysbus_from_qdev(dev));
|
|
|
|
s = DO_UPCAST(PPCE500PCIState, pci_state, h);
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(s->irq); i++) {
|
|
|
|
sysbus_init_irq(dev, &s->irq[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
b = pci_register_bus(&s->pci_state.busdev.qdev, NULL, mpc85xx_pci_set_irq,
|
2011-08-08 13:09:04 +00:00
|
|
|
mpc85xx_pci_map_irq, s->irq, address_space_mem,
|
|
|
|
address_space_io, PCI_DEVFN(0x11, 0), 4);
|
2010-08-30 22:22:28 +00:00
|
|
|
s->pci_state.bus = b;
|
|
|
|
|
|
|
|
pci_create_simple(b, 0, "e500-host-bridge");
|
|
|
|
|
2011-07-24 14:47:18 +00:00
|
|
|
memory_region_init_io(&h->conf_mem, &pci_host_conf_be_ops, h,
|
|
|
|
"pci-conf-idx", 4);
|
|
|
|
memory_region_init_io(&h->data_mem, &pci_host_data_le_ops, h,
|
|
|
|
"pci-conf-data", 4);
|
2011-11-20 09:52:58 +00:00
|
|
|
memory_region_init_io(&s->iomem, &e500_pci_reg_ops, s,
|
|
|
|
"pci.reg", PCIE500_REG_SIZE);
|
2011-08-15 14:17:33 +00:00
|
|
|
sysbus_init_mmio_cb2(dev, e500_pci_map, e500_pci_unmap);
|
2010-08-30 22:22:28 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PCIDeviceInfo e500_host_bridge_info = {
|
|
|
|
.qdev.name = "e500-host-bridge",
|
|
|
|
.qdev.desc = "Host bridge",
|
|
|
|
.qdev.size = sizeof(PCIDevice),
|
2011-06-14 14:14:52 +00:00
|
|
|
.vendor_id = PCI_VENDOR_ID_FREESCALE,
|
|
|
|
.device_id = PCI_DEVICE_ID_MPC8533E,
|
|
|
|
.class_id = PCI_CLASS_PROCESSOR_POWERPC,
|
2010-08-30 22:22:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static SysBusDeviceInfo e500_pcihost_info = {
|
|
|
|
.init = e500_pcihost_initfn,
|
|
|
|
.qdev.name = "e500-pcihost",
|
|
|
|
.qdev.size = sizeof(PPCE500PCIState),
|
|
|
|
.qdev.vmsd = &vmstate_ppce500_pci,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void e500_pci_register(void)
|
2009-03-02 16:42:23 +00:00
|
|
|
{
|
2010-08-30 22:22:28 +00:00
|
|
|
sysbus_register_withprop(&e500_pcihost_info);
|
|
|
|
pci_qdev_register(&e500_host_bridge_info);
|
2009-03-02 16:42:23 +00:00
|
|
|
}
|
2010-08-30 22:22:28 +00:00
|
|
|
device_init(e500_pci_register);
|