2017-10-08 23:47:27 +03:00
|
|
|
/*
|
2023-07-14 14:27:04 +03:00
|
|
|
* HP-PARISC Dino PCI chipset emulation, as in B160L and similar machines
|
2017-10-08 23:47:27 +03:00
|
|
|
*
|
2019-12-21 00:15:07 +03:00
|
|
|
* (C) 2017-2019 by Helge Deller <deller@gmx.de>
|
2017-10-08 23:47:27 +03:00
|
|
|
*
|
|
|
|
* This work is licensed under the GNU GPL license version 2 or later.
|
|
|
|
*
|
|
|
|
* Documentation available at:
|
|
|
|
* https://parisc.wiki.kernel.org/images-parisc/9/91/Dino_ers.pdf
|
|
|
|
* https://parisc.wiki.kernel.org/images-parisc/7/70/Dino_3_1_Errata.pdf
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2018-06-25 15:42:11 +03:00
|
|
|
#include "qemu/units.h"
|
2017-10-08 23:47:27 +03:00
|
|
|
#include "qapi/error.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2022-12-22 13:03:28 +03:00
|
|
|
#include "hw/pci/pci_device.h"
|
2017-10-08 23:47:27 +03:00
|
|
|
#include "hw/pci/pci_bus.h"
|
2022-05-04 12:25:15 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2022-05-04 12:25:32 +03:00
|
|
|
#include "hw/pci-host/dino.h"
|
2019-08-12 08:23:45 +03:00
|
|
|
#include "migration/vmstate.h"
|
2019-12-21 00:15:07 +03:00
|
|
|
#include "trace.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2017-10-08 23:47:27 +03:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dino can forward memory accesses from the CPU in the range between
|
|
|
|
* 0xf0800000 and 0xff000000 to the PCI bus.
|
|
|
|
*/
|
|
|
|
static void gsc_to_pci_forwarding(DinoState *s)
|
|
|
|
{
|
|
|
|
uint32_t io_addr_en, tmp;
|
|
|
|
int enabled, i;
|
|
|
|
|
|
|
|
tmp = extract32(s->io_control, 7, 2);
|
|
|
|
enabled = (tmp == 0x01);
|
|
|
|
io_addr_en = s->io_addr_en;
|
2019-12-21 00:15:07 +03:00
|
|
|
/* Mask out first (=firmware) and last (=Dino) areas. */
|
|
|
|
io_addr_en &= ~(BIT(31) | BIT(0));
|
2017-10-08 23:47:27 +03:00
|
|
|
|
|
|
|
memory_region_transaction_begin();
|
|
|
|
for (i = 1; i < 31; i++) {
|
|
|
|
MemoryRegion *mem = &s->pci_mem_alias[i];
|
|
|
|
if (enabled && (io_addr_en & (1U << i))) {
|
|
|
|
if (!memory_region_is_mapped(mem)) {
|
|
|
|
uint32_t addr = 0xf0000000 + i * DINO_MEM_CHUNK_SIZE;
|
|
|
|
memory_region_add_subregion(get_system_memory(), addr, mem);
|
|
|
|
}
|
|
|
|
} else if (memory_region_is_mapped(mem)) {
|
|
|
|
memory_region_del_subregion(get_system_memory(), mem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
memory_region_transaction_commit();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool dino_chip_mem_valid(void *opaque, hwaddr addr,
|
2018-05-31 16:50:52 +03:00
|
|
|
unsigned size, bool is_write,
|
|
|
|
MemTxAttrs attrs)
|
2017-10-08 23:47:27 +03:00
|
|
|
{
|
2019-12-21 00:15:07 +03:00
|
|
|
bool ret = false;
|
|
|
|
|
2017-10-08 23:47:27 +03:00
|
|
|
switch (addr) {
|
|
|
|
case DINO_IAR0:
|
|
|
|
case DINO_IAR1:
|
|
|
|
case DINO_IRR0:
|
|
|
|
case DINO_IRR1:
|
|
|
|
case DINO_IMR:
|
|
|
|
case DINO_IPR:
|
|
|
|
case DINO_ICR:
|
|
|
|
case DINO_ILR:
|
|
|
|
case DINO_IO_CONTROL:
|
2019-12-21 00:15:07 +03:00
|
|
|
case DINO_IO_FBB_EN:
|
2017-10-08 23:47:27 +03:00
|
|
|
case DINO_IO_ADDR_EN:
|
|
|
|
case DINO_PCI_IO_DATA:
|
2019-12-21 00:15:07 +03:00
|
|
|
case DINO_TOC_ADDR:
|
2020-02-18 09:33:55 +03:00
|
|
|
case DINO_GMASK ... DINO_PCISTS:
|
|
|
|
case DINO_MLTIM ... DINO_PCIWOR:
|
|
|
|
case DINO_TLTIM:
|
2019-12-21 00:15:07 +03:00
|
|
|
ret = true;
|
|
|
|
break;
|
2017-10-08 23:47:27 +03:00
|
|
|
case DINO_PCI_IO_DATA + 2:
|
2019-12-21 00:15:07 +03:00
|
|
|
ret = (size <= 2);
|
|
|
|
break;
|
2017-10-08 23:47:27 +03:00
|
|
|
case DINO_PCI_IO_DATA + 1:
|
|
|
|
case DINO_PCI_IO_DATA + 3:
|
2019-12-21 00:15:07 +03:00
|
|
|
ret = (size == 1);
|
2017-10-08 23:47:27 +03:00
|
|
|
}
|
2019-12-21 00:15:07 +03:00
|
|
|
trace_dino_chip_mem_valid(addr, ret);
|
|
|
|
return ret;
|
2017-10-08 23:47:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static MemTxResult dino_chip_read_with_attrs(void *opaque, hwaddr addr,
|
|
|
|
uint64_t *data, unsigned size,
|
|
|
|
MemTxAttrs attrs)
|
|
|
|
{
|
|
|
|
DinoState *s = opaque;
|
2022-05-04 12:25:19 +03:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2017-10-08 23:47:27 +03:00
|
|
|
MemTxResult ret = MEMTX_OK;
|
|
|
|
AddressSpace *io;
|
|
|
|
uint16_t ioaddr;
|
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case DINO_PCI_IO_DATA ... DINO_PCI_IO_DATA + 3:
|
|
|
|
/* Read from PCI IO space. */
|
|
|
|
io = &address_space_io;
|
2022-05-04 12:25:19 +03:00
|
|
|
ioaddr = phb->config_reg + (addr & 3);
|
2017-10-08 23:47:27 +03:00
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
val = address_space_ldub(io, ioaddr, attrs, &ret);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
val = address_space_lduw_be(io, ioaddr, attrs, &ret);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
val = address_space_ldl_be(io, ioaddr, attrs, &ret);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2019-12-21 00:15:07 +03:00
|
|
|
case DINO_IO_FBB_EN:
|
|
|
|
val = s->io_fbb_en;
|
|
|
|
break;
|
2017-10-08 23:47:27 +03:00
|
|
|
case DINO_IO_ADDR_EN:
|
|
|
|
val = s->io_addr_en;
|
|
|
|
break;
|
|
|
|
case DINO_IO_CONTROL:
|
|
|
|
val = s->io_control;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DINO_IAR0:
|
|
|
|
val = s->iar0;
|
|
|
|
break;
|
|
|
|
case DINO_IAR1:
|
|
|
|
val = s->iar1;
|
|
|
|
break;
|
|
|
|
case DINO_IMR:
|
|
|
|
val = s->imr;
|
|
|
|
break;
|
|
|
|
case DINO_ICR:
|
|
|
|
val = s->icr;
|
|
|
|
break;
|
|
|
|
case DINO_IPR:
|
|
|
|
val = s->ipr;
|
|
|
|
/* Any read to IPR clears the register. */
|
|
|
|
s->ipr = 0;
|
|
|
|
break;
|
|
|
|
case DINO_ILR:
|
|
|
|
val = s->ilr;
|
|
|
|
break;
|
|
|
|
case DINO_IRR0:
|
|
|
|
val = s->ilr & s->imr & ~s->icr;
|
|
|
|
break;
|
|
|
|
case DINO_IRR1:
|
|
|
|
val = s->ilr & s->imr & s->icr;
|
|
|
|
break;
|
2019-12-21 00:15:07 +03:00
|
|
|
case DINO_TOC_ADDR:
|
|
|
|
val = s->toc_addr;
|
|
|
|
break;
|
|
|
|
case DINO_GMASK ... DINO_TLTIM:
|
|
|
|
val = s->reg800[(addr - DINO_GMASK) / 4];
|
|
|
|
if (addr == DINO_PAMR) {
|
|
|
|
val &= ~0x01; /* LSB is hardwired to 0 */
|
|
|
|
}
|
|
|
|
if (addr == DINO_MLTIM) {
|
|
|
|
val &= ~0x07; /* 3 LSB are hardwired to 0 */
|
|
|
|
}
|
|
|
|
if (addr == DINO_BRDG_FEAT) {
|
|
|
|
val &= ~(0x10710E0ul | 8); /* bits 5-7, 24 & 15 reserved */
|
|
|
|
}
|
|
|
|
break;
|
2017-10-08 23:47:27 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
/* Controlled by dino_chip_mem_valid above. */
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2019-12-21 00:15:07 +03:00
|
|
|
trace_dino_chip_read(addr, val);
|
2017-10-08 23:47:27 +03:00
|
|
|
*data = val;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static MemTxResult dino_chip_write_with_attrs(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size,
|
|
|
|
MemTxAttrs attrs)
|
|
|
|
{
|
|
|
|
DinoState *s = opaque;
|
2022-05-04 12:25:19 +03:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2017-10-08 23:47:27 +03:00
|
|
|
AddressSpace *io;
|
|
|
|
MemTxResult ret;
|
|
|
|
uint16_t ioaddr;
|
2019-12-21 00:15:07 +03:00
|
|
|
int i;
|
|
|
|
|
|
|
|
trace_dino_chip_write(addr, val);
|
2017-10-08 23:47:27 +03:00
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
case DINO_IO_DATA ... DINO_PCI_IO_DATA + 3:
|
|
|
|
/* Write into PCI IO space. */
|
|
|
|
io = &address_space_io;
|
2022-05-04 12:25:19 +03:00
|
|
|
ioaddr = phb->config_reg + (addr & 3);
|
2017-10-08 23:47:27 +03:00
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
address_space_stb(io, ioaddr, val, attrs, &ret);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
address_space_stw_be(io, ioaddr, val, attrs, &ret);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
address_space_stl_be(io, ioaddr, val, attrs, &ret);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
|
2019-12-21 00:15:07 +03:00
|
|
|
case DINO_IO_FBB_EN:
|
|
|
|
s->io_fbb_en = val & 0x03;
|
|
|
|
break;
|
2017-10-08 23:47:27 +03:00
|
|
|
case DINO_IO_ADDR_EN:
|
2019-12-21 00:15:07 +03:00
|
|
|
s->io_addr_en = val;
|
2017-10-08 23:47:27 +03:00
|
|
|
gsc_to_pci_forwarding(s);
|
|
|
|
break;
|
|
|
|
case DINO_IO_CONTROL:
|
|
|
|
s->io_control = val;
|
|
|
|
gsc_to_pci_forwarding(s);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DINO_IAR0:
|
|
|
|
s->iar0 = val;
|
|
|
|
break;
|
|
|
|
case DINO_IAR1:
|
|
|
|
s->iar1 = val;
|
|
|
|
break;
|
|
|
|
case DINO_IMR:
|
|
|
|
s->imr = val;
|
|
|
|
break;
|
|
|
|
case DINO_ICR:
|
|
|
|
s->icr = val;
|
|
|
|
break;
|
|
|
|
case DINO_IPR:
|
|
|
|
/* Any write to IPR clears the register. */
|
|
|
|
s->ipr = 0;
|
|
|
|
break;
|
2019-12-21 00:15:07 +03:00
|
|
|
case DINO_TOC_ADDR:
|
|
|
|
/* IO_COMMAND of CPU with client_id bits */
|
|
|
|
s->toc_addr = 0xFFFA0030 | (val & 0x1e000);
|
|
|
|
break;
|
2017-10-08 23:47:27 +03:00
|
|
|
|
|
|
|
case DINO_ILR:
|
|
|
|
case DINO_IRR0:
|
|
|
|
case DINO_IRR1:
|
|
|
|
/* These registers are read-only. */
|
|
|
|
break;
|
|
|
|
|
2019-12-21 00:15:07 +03:00
|
|
|
case DINO_GMASK ... DINO_TLTIM:
|
|
|
|
i = (addr - DINO_GMASK) / 4;
|
|
|
|
val &= reg800_keep_bits[i];
|
|
|
|
s->reg800[i] = val;
|
|
|
|
break;
|
|
|
|
|
2017-10-08 23:47:27 +03:00
|
|
|
default:
|
|
|
|
/* Controlled by dino_chip_mem_valid above. */
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
return MEMTX_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps dino_chip_ops = {
|
|
|
|
.read_with_attrs = dino_chip_read_with_attrs,
|
|
|
|
.write_with_attrs = dino_chip_write_with_attrs,
|
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 4,
|
|
|
|
.accepts = dino_chip_mem_valid,
|
|
|
|
},
|
|
|
|
.impl = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
static const VMStateDescription vmstate_dino = {
|
|
|
|
.name = "Dino",
|
2019-12-21 00:15:07 +03:00
|
|
|
.version_id = 2,
|
2017-10-08 23:47:27 +03:00
|
|
|
.minimum_version_id = 1,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(iar0, DinoState),
|
|
|
|
VMSTATE_UINT32(iar1, DinoState),
|
|
|
|
VMSTATE_UINT32(imr, DinoState),
|
|
|
|
VMSTATE_UINT32(ipr, DinoState),
|
|
|
|
VMSTATE_UINT32(icr, DinoState),
|
|
|
|
VMSTATE_UINT32(ilr, DinoState),
|
2019-12-21 00:15:07 +03:00
|
|
|
VMSTATE_UINT32(io_fbb_en, DinoState),
|
2017-10-08 23:47:27 +03:00
|
|
|
VMSTATE_UINT32(io_addr_en, DinoState),
|
|
|
|
VMSTATE_UINT32(io_control, DinoState),
|
2019-12-21 00:15:07 +03:00
|
|
|
VMSTATE_UINT32(toc_addr, DinoState),
|
2017-10-08 23:47:27 +03:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Unlike pci_config_data_le_ops, no check of high bit set in config_reg. */
|
|
|
|
|
|
|
|
static uint64_t dino_config_data_read(void *opaque, hwaddr addr, unsigned len)
|
|
|
|
{
|
|
|
|
PCIHostState *s = opaque;
|
|
|
|
return pci_data_read(s->bus, s->config_reg | (addr & 3), len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dino_config_data_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned len)
|
|
|
|
{
|
|
|
|
PCIHostState *s = opaque;
|
|
|
|
pci_data_write(s->bus, s->config_reg | (addr & 3), val, len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps dino_config_data_ops = {
|
|
|
|
.read = dino_config_data_read,
|
|
|
|
.write = dino_config_data_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2019-02-18 21:33:14 +03:00
|
|
|
static uint64_t dino_config_addr_read(void *opaque, hwaddr addr, unsigned len)
|
|
|
|
{
|
2019-12-21 00:15:07 +03:00
|
|
|
DinoState *s = opaque;
|
|
|
|
return s->config_reg_dino;
|
2019-02-18 21:33:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void dino_config_addr_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned len)
|
|
|
|
{
|
|
|
|
PCIHostState *s = opaque;
|
2019-12-21 00:15:07 +03:00
|
|
|
DinoState *ds = opaque;
|
|
|
|
ds->config_reg_dino = val; /* keep a copy of original value */
|
2019-02-18 21:33:14 +03:00
|
|
|
s->config_reg = val & ~3U;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps dino_config_addr_ops = {
|
|
|
|
.read = dino_config_addr_read,
|
|
|
|
.write = dino_config_addr_write,
|
|
|
|
.valid.min_access_size = 4,
|
|
|
|
.valid.max_access_size = 4,
|
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2017-10-08 23:47:27 +03:00
|
|
|
static AddressSpace *dino_pcihost_set_iommu(PCIBus *bus, void *opaque,
|
|
|
|
int devfn)
|
|
|
|
{
|
|
|
|
DinoState *s = opaque;
|
|
|
|
|
|
|
|
return &s->bm_as;
|
|
|
|
}
|
|
|
|
|
2023-10-17 19:14:04 +03:00
|
|
|
static const PCIIOMMUOps dino_iommu_ops = {
|
|
|
|
.get_address_space = dino_pcihost_set_iommu,
|
|
|
|
};
|
|
|
|
|
2017-10-08 23:47:27 +03:00
|
|
|
/*
|
|
|
|
* Dino interrupts are connected as shown on Page 78, Table 23
|
|
|
|
* (Little-endian bit numbers)
|
|
|
|
* 0 PCI INTA
|
|
|
|
* 1 PCI INTB
|
|
|
|
* 2 PCI INTC
|
|
|
|
* 3 PCI INTD
|
|
|
|
* 4 PCI INTE
|
|
|
|
* 5 PCI INTF
|
|
|
|
* 6 GSC External Interrupt
|
|
|
|
* 7 Bus Error for "less than fatal" mode
|
|
|
|
* 8 PS2
|
|
|
|
* 9 Unused
|
|
|
|
* 10 RS232
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void dino_set_irq(void *opaque, int irq, int level)
|
|
|
|
{
|
|
|
|
DinoState *s = opaque;
|
|
|
|
uint32_t bit = 1u << irq;
|
|
|
|
uint32_t old_ilr = s->ilr;
|
|
|
|
|
|
|
|
if (level) {
|
|
|
|
uint32_t ena = bit & ~old_ilr;
|
|
|
|
s->ipr |= ena;
|
|
|
|
s->ilr = old_ilr | bit;
|
|
|
|
if (ena & s->imr) {
|
|
|
|
uint32_t iar = (ena & s->icr ? s->iar1 : s->iar0);
|
|
|
|
stl_be_phys(&address_space_memory, iar & -32, iar & 31);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s->ilr = old_ilr & ~bit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dino_pci_map_irq(PCIDevice *d, int irq_num)
|
|
|
|
{
|
2020-10-11 18:04:23 +03:00
|
|
|
int slot = PCI_SLOT(d->devfn);
|
2017-10-08 23:47:27 +03:00
|
|
|
|
|
|
|
assert(irq_num >= 0 && irq_num <= 3);
|
|
|
|
|
2018-03-23 17:32:02 +03:00
|
|
|
return slot & 0x03;
|
2017-10-08 23:47:27 +03:00
|
|
|
}
|
|
|
|
|
2022-05-04 12:25:18 +03:00
|
|
|
static void dino_pcihost_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
DinoState *s = DINO_PCI_HOST_BRIDGE(dev);
|
|
|
|
|
2022-05-04 12:25:30 +03:00
|
|
|
s->iar0 = s->iar1 = 0xFFFB0000 + 3; /* CPU_HPA + 3 */
|
2022-05-04 12:25:18 +03:00
|
|
|
s->toc_addr = 0xFFFA0030; /* IO_COMMAND of CPU */
|
|
|
|
}
|
|
|
|
|
2022-05-04 12:25:17 +03:00
|
|
|
static void dino_pcihost_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
DinoState *s = DINO_PCI_HOST_BRIDGE(dev);
|
|
|
|
|
2017-10-08 23:47:27 +03:00
|
|
|
/* Set up PCI view of memory: Bus master address space. */
|
2020-06-01 17:29:28 +03:00
|
|
|
memory_region_init(&s->bm, OBJECT(s), "bm-dino", 4 * GiB);
|
2017-10-08 23:47:27 +03:00
|
|
|
memory_region_init_alias(&s->bm_ram_alias, OBJECT(s),
|
2022-05-04 12:25:17 +03:00
|
|
|
"bm-system", s->memory_as, 0,
|
2017-10-08 23:47:27 +03:00
|
|
|
0xf0000000 + DINO_MEM_CHUNK_SIZE);
|
|
|
|
memory_region_init_alias(&s->bm_pci_alias, OBJECT(s),
|
|
|
|
"bm-pci", &s->pci_mem,
|
|
|
|
0xf0000000 + DINO_MEM_CHUNK_SIZE,
|
2019-02-11 22:20:39 +03:00
|
|
|
30 * DINO_MEM_CHUNK_SIZE);
|
|
|
|
memory_region_init_alias(&s->bm_cpu_alias, OBJECT(s),
|
2022-05-04 12:25:17 +03:00
|
|
|
"bm-cpu", s->memory_as, 0xfff00000,
|
2019-02-11 22:20:39 +03:00
|
|
|
0xfffff);
|
2017-10-08 23:47:27 +03:00
|
|
|
memory_region_add_subregion(&s->bm, 0,
|
|
|
|
&s->bm_ram_alias);
|
|
|
|
memory_region_add_subregion(&s->bm,
|
|
|
|
0xf0000000 + DINO_MEM_CHUNK_SIZE,
|
|
|
|
&s->bm_pci_alias);
|
2019-02-11 22:20:39 +03:00
|
|
|
memory_region_add_subregion(&s->bm, 0xfff00000,
|
|
|
|
&s->bm_cpu_alias);
|
2022-05-04 12:25:17 +03:00
|
|
|
|
2017-10-08 23:47:27 +03:00
|
|
|
address_space_init(&s->bm_as, &s->bm, "pci-bm");
|
2022-05-04 12:25:17 +03:00
|
|
|
}
|
2017-10-08 23:47:27 +03:00
|
|
|
|
2022-05-04 12:25:17 +03:00
|
|
|
static void dino_pcihost_unrealize(DeviceState *dev)
|
|
|
|
{
|
|
|
|
DinoState *s = DINO_PCI_HOST_BRIDGE(dev);
|
2017-10-08 23:47:27 +03:00
|
|
|
|
2022-05-04 12:25:17 +03:00
|
|
|
address_space_destroy(&s->bm_as);
|
2017-10-08 23:47:27 +03:00
|
|
|
}
|
|
|
|
|
2022-05-04 12:25:12 +03:00
|
|
|
static void dino_pcihost_init(Object *obj)
|
|
|
|
{
|
|
|
|
DinoState *s = DINO_PCI_HOST_BRIDGE(obj);
|
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(obj);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2022-05-04 12:25:14 +03:00
|
|
|
int i;
|
2022-05-04 12:25:12 +03:00
|
|
|
|
|
|
|
/* Dino PCI access from main memory. */
|
|
|
|
memory_region_init_io(&s->this_mem, OBJECT(s), &dino_chip_ops,
|
|
|
|
s, "dino", 4096);
|
|
|
|
|
|
|
|
/* Dino PCI config. */
|
|
|
|
memory_region_init_io(&phb->conf_mem, OBJECT(phb),
|
|
|
|
&dino_config_addr_ops, DEVICE(s),
|
|
|
|
"pci-conf-idx", 4);
|
|
|
|
memory_region_init_io(&phb->data_mem, OBJECT(phb),
|
|
|
|
&dino_config_data_ops, DEVICE(s),
|
|
|
|
"pci-conf-data", 4);
|
|
|
|
memory_region_add_subregion(&s->this_mem, DINO_PCI_CONFIG_ADDR,
|
|
|
|
&phb->conf_mem);
|
|
|
|
memory_region_add_subregion(&s->this_mem, DINO_CONFIG_DATA,
|
|
|
|
&phb->data_mem);
|
|
|
|
|
2022-05-04 12:25:13 +03:00
|
|
|
/* Dino PCI bus memory. */
|
|
|
|
memory_region_init(&s->pci_mem, OBJECT(s), "pci-memory", 4 * GiB);
|
|
|
|
|
|
|
|
phb->bus = pci_register_root_bus(DEVICE(s), "pci",
|
|
|
|
dino_set_irq, dino_pci_map_irq, s,
|
|
|
|
&s->pci_mem, get_system_io(),
|
|
|
|
PCI_DEVFN(0, 0), 32, TYPE_PCI_BUS);
|
|
|
|
|
2022-05-04 12:25:14 +03:00
|
|
|
/* Set up windows into PCI bus memory. */
|
|
|
|
for (i = 1; i < 31; i++) {
|
|
|
|
uint32_t addr = 0xf0000000 + i * DINO_MEM_CHUNK_SIZE;
|
|
|
|
char *name = g_strdup_printf("PCI Outbound Window %d", i);
|
|
|
|
memory_region_init_alias(&s->pci_mem_alias[i], OBJECT(s),
|
|
|
|
name, &s->pci_mem, addr,
|
|
|
|
DINO_MEM_CHUNK_SIZE);
|
|
|
|
g_free(name);
|
|
|
|
}
|
|
|
|
|
2023-10-17 19:14:04 +03:00
|
|
|
pci_setup_iommu(phb->bus, &dino_iommu_ops, s);
|
2022-05-04 12:25:16 +03:00
|
|
|
|
2022-05-04 12:25:12 +03:00
|
|
|
sysbus_init_mmio(sbd, &s->this_mem);
|
2022-05-04 12:25:26 +03:00
|
|
|
|
|
|
|
qdev_init_gpio_in(DEVICE(obj), dino_set_irq, DINO_IRQS);
|
2022-05-04 12:25:12 +03:00
|
|
|
}
|
|
|
|
|
2022-05-04 12:25:15 +03:00
|
|
|
static Property dino_pcihost_properties[] = {
|
|
|
|
DEFINE_PROP_LINK("memory-as", DinoState, memory_as, TYPE_MEMORY_REGION,
|
|
|
|
MemoryRegion *),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2017-10-08 23:47:27 +03:00
|
|
|
static void dino_pcihost_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
2022-05-04 12:25:18 +03:00
|
|
|
dc->reset = dino_pcihost_reset;
|
2022-05-04 12:25:17 +03:00
|
|
|
dc->realize = dino_pcihost_realize;
|
|
|
|
dc->unrealize = dino_pcihost_unrealize;
|
2022-05-04 12:25:15 +03:00
|
|
|
device_class_set_props(dc, dino_pcihost_properties);
|
2017-10-08 23:47:27 +03:00
|
|
|
dc->vmsd = &vmstate_dino;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo dino_pcihost_info = {
|
|
|
|
.name = TYPE_DINO_PCI_HOST_BRIDGE,
|
|
|
|
.parent = TYPE_PCI_HOST_BRIDGE,
|
2022-05-04 12:25:12 +03:00
|
|
|
.instance_init = dino_pcihost_init,
|
2017-10-08 23:47:27 +03:00
|
|
|
.instance_size = sizeof(DinoState),
|
|
|
|
.class_init = dino_pcihost_class_init,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dino_register_types(void)
|
|
|
|
{
|
|
|
|
type_register_static(&dino_pcihost_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
type_init(dino_register_types)
|