2006-05-14 00:11:23 +08:00
|
|
|
/*
|
|
|
|
* QEMU Ultrasparc APB PCI host
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Fabrice Bellard
|
2013-04-27 13:55:12 +08:00
|
|
|
* Copyright (c) 2012,2013 Artyom Tarasenko
|
2007-09-17 05:08:06 +08:00
|
|
|
*
|
2006-05-14 00:11:23 +08:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2006-09-25 01:01:44 +08:00
|
|
|
|
2009-01-10 04:53:30 +08:00
|
|
|
/* XXX This file and most of its contents are somewhat misnamed. The
|
2006-09-25 01:01:44 +08:00
|
|
|
Ultrasparc PCI host is called the PCI Bus Module (PBM). The APB is
|
|
|
|
the secondary PCI bridge. */
|
|
|
|
|
2016-01-27 02:17:15 +08:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 22:40:22 +08:00
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "hw/pci/pci.h"
|
|
|
|
#include "hw/pci/pci_host.h"
|
|
|
|
#include "hw/pci/pci_bridge.h"
|
|
|
|
#include "hw/pci/pci_bus.h"
|
2018-01-21 16:59:45 +08:00
|
|
|
#include "hw/pci-bridge/simba.h"
|
2013-02-06 00:06:20 +08:00
|
|
|
#include "hw/pci-host/apb.h"
|
2012-12-18 01:20:04 +08:00
|
|
|
#include "sysemu/sysemu.h"
|
2012-12-18 01:19:49 +08:00
|
|
|
#include "exec/address-spaces.h"
|
2018-01-09 02:16:34 +08:00
|
|
|
#include "qapi/error.h"
|
2015-12-15 20:16:16 +08:00
|
|
|
#include "qemu/log.h"
|
2009-01-10 04:53:30 +08:00
|
|
|
|
|
|
|
/* debug APB */
|
|
|
|
//#define DEBUG_APB
|
|
|
|
|
|
|
|
#ifdef DEBUG_APB
|
2009-05-14 01:53:17 +08:00
|
|
|
#define APB_DPRINTF(fmt, ...) \
|
|
|
|
do { printf("APB: " fmt , ## __VA_ARGS__); } while (0)
|
2009-01-10 04:53:30 +08:00
|
|
|
#else
|
2009-05-14 01:53:17 +08:00
|
|
|
#define APB_DPRINTF(fmt, ...)
|
2009-01-10 04:53:30 +08:00
|
|
|
#endif
|
|
|
|
|
2009-10-14 02:56:27 +08:00
|
|
|
/*
|
|
|
|
* Chipset docs:
|
|
|
|
* PBM: "UltraSPARC IIi User's Manual",
|
|
|
|
* http://www.sun.com/processors/manuals/805-0087.pdf
|
|
|
|
*/
|
|
|
|
|
2010-01-31 03:48:12 +08:00
|
|
|
#define PBM_PCI_IMR_MASK 0x7fffffff
|
|
|
|
#define PBM_PCI_IMR_ENABLED 0x80000000
|
|
|
|
|
2014-03-18 00:00:41 +08:00
|
|
|
#define POR (1U << 31)
|
|
|
|
#define SOFT_POR (1U << 30)
|
|
|
|
#define SOFT_XIR (1U << 29)
|
|
|
|
#define BTN_POR (1U << 28)
|
|
|
|
#define BTN_XIR (1U << 27)
|
2010-01-31 03:48:12 +08:00
|
|
|
#define RESET_MASK 0xf8000000
|
|
|
|
#define RESET_WCMASK 0x98000000
|
|
|
|
#define RESET_WMASK 0x60000000
|
|
|
|
|
2013-04-27 13:55:12 +08:00
|
|
|
#define NO_IRQ_REQUEST (MAX_IVEC + 1)
|
2012-03-11 04:37:00 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static inline void sabre_set_request(SabreState *s, unsigned int irq_num)
|
2013-04-27 13:55:12 +08:00
|
|
|
{
|
|
|
|
APB_DPRINTF("%s: request irq %d\n", __func__, irq_num);
|
|
|
|
|
|
|
|
s->irq_request = irq_num;
|
|
|
|
qemu_set_irq(s->ivec_irqs[irq_num], 1);
|
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static inline void sabre_check_irqs(SabreState *s)
|
2013-04-27 13:55:12 +08:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Previous request is not acknowledged, resubmit */
|
|
|
|
if (s->irq_request != NO_IRQ_REQUEST) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_set_request(s, s->irq_request);
|
2013-04-27 13:55:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* no request pending */
|
|
|
|
if (s->pci_irq_in == 0ULL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
if (s->pci_irq_in & (1ULL << i)) {
|
|
|
|
if (s->pci_irq_map[i >> 2] & PBM_PCI_IMR_ENABLED) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_set_request(s, i);
|
2013-04-27 13:55:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (i = 32; i < 64; i++) {
|
|
|
|
if (s->pci_irq_in & (1ULL << i)) {
|
|
|
|
if (s->obio_irq_map[i - 32] & PBM_PCI_IMR_ENABLED) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_set_request(s, i);
|
2013-04-27 13:55:12 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static inline void sabre_clear_request(SabreState *s, unsigned int irq_num)
|
2013-04-27 13:55:12 +08:00
|
|
|
{
|
|
|
|
APB_DPRINTF("%s: clear request irq %d\n", __func__, irq_num);
|
|
|
|
qemu_set_irq(s->ivec_irqs[irq_num], 0);
|
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
}
|
2012-05-12 17:15:23 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static AddressSpace *sabre_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
|
2014-05-28 15:28:22 +08:00
|
|
|
{
|
|
|
|
IOMMUState *is = opaque;
|
|
|
|
|
|
|
|
return &is->iommu_as;
|
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_config_write(void *opaque, hwaddr addr,
|
2011-08-15 22:17:15 +08:00
|
|
|
uint64_t val, unsigned size)
|
2006-05-14 00:11:23 +08:00
|
|
|
{
|
2018-01-21 16:59:45 +08:00
|
|
|
SabreState *s = opaque;
|
2010-01-31 03:48:12 +08:00
|
|
|
|
2013-02-05 22:06:20 +08:00
|
|
|
APB_DPRINTF("%s: addr " TARGET_FMT_plx " val %" PRIx64 "\n", __func__, addr, val);
|
2010-01-31 03:48:12 +08:00
|
|
|
|
|
|
|
switch (addr & 0xffff) {
|
|
|
|
case 0x30 ... 0x4f: /* DMA error registers */
|
|
|
|
/* XXX: not implemented yet */
|
|
|
|
break;
|
|
|
|
case 0xc00 ... 0xc3f: /* PCI interrupt control */
|
|
|
|
if (addr & 4) {
|
2013-04-27 13:55:12 +08:00
|
|
|
unsigned int ino = (addr & 0x3f) >> 3;
|
|
|
|
s->pci_irq_map[ino] &= PBM_PCI_IMR_MASK;
|
|
|
|
s->pci_irq_map[ino] |= val & ~PBM_PCI_IMR_MASK;
|
|
|
|
if ((s->irq_request == ino) && !(val & ~PBM_PCI_IMR_MASK)) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_clear_request(s, ino);
|
2013-04-27 13:55:12 +08:00
|
|
|
}
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_check_irqs(s);
|
2010-01-31 03:48:12 +08:00
|
|
|
}
|
|
|
|
break;
|
2014-09-05 21:50:56 +08:00
|
|
|
case 0x1000 ... 0x107f: /* OBIO interrupt control */
|
2012-03-11 04:37:00 +08:00
|
|
|
if (addr & 4) {
|
2013-04-27 13:55:12 +08:00
|
|
|
unsigned int ino = ((addr & 0xff) >> 3);
|
|
|
|
s->obio_irq_map[ino] &= PBM_PCI_IMR_MASK;
|
|
|
|
s->obio_irq_map[ino] |= val & ~PBM_PCI_IMR_MASK;
|
|
|
|
if ((s->irq_request == (ino | 0x20))
|
|
|
|
&& !(val & ~PBM_PCI_IMR_MASK)) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_clear_request(s, ino | 0x20);
|
2013-04-27 13:55:12 +08:00
|
|
|
}
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_check_irqs(s);
|
2012-03-11 04:37:00 +08:00
|
|
|
}
|
|
|
|
break;
|
2013-04-27 13:55:12 +08:00
|
|
|
case 0x1400 ... 0x14ff: /* PCI interrupt clear */
|
2012-05-12 17:15:23 +08:00
|
|
|
if (addr & 4) {
|
2013-04-27 13:55:12 +08:00
|
|
|
unsigned int ino = (addr & 0xff) >> 5;
|
|
|
|
if ((s->irq_request / 4) == ino) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_clear_request(s, s->irq_request);
|
|
|
|
sabre_check_irqs(s);
|
2013-04-27 13:55:12 +08:00
|
|
|
}
|
2012-05-12 17:15:23 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x1800 ... 0x1860: /* OBIO interrupt clear */
|
|
|
|
if (addr & 4) {
|
2013-04-27 13:55:12 +08:00
|
|
|
unsigned int ino = ((addr & 0xff) >> 3) | 0x20;
|
|
|
|
if (s->irq_request == ino) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_clear_request(s, ino);
|
|
|
|
sabre_check_irqs(s);
|
2013-04-27 13:55:12 +08:00
|
|
|
}
|
2012-05-12 17:15:23 +08:00
|
|
|
}
|
|
|
|
break;
|
2010-01-31 03:48:12 +08:00
|
|
|
case 0x2000 ... 0x202f: /* PCI control */
|
|
|
|
s->pci_control[(addr & 0x3f) >> 2] = val;
|
|
|
|
break;
|
|
|
|
case 0xf020 ... 0xf027: /* Reset control */
|
|
|
|
if (addr & 4) {
|
|
|
|
val &= RESET_MASK;
|
|
|
|
s->reset_control &= ~(val & RESET_WCMASK);
|
|
|
|
s->reset_control |= val & RESET_WMASK;
|
|
|
|
if (val & SOFT_POR) {
|
2010-05-13 03:27:23 +08:00
|
|
|
s->nr_resets = 0;
|
2017-05-16 05:41:13 +08:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2010-01-31 03:48:12 +08:00
|
|
|
} else if (val & SOFT_XIR) {
|
2017-05-16 05:41:13 +08:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2010-01-31 03:48:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */
|
|
|
|
case 0xa400 ... 0xa67f: /* IOMMU diagnostics */
|
|
|
|
case 0xa800 ... 0xa80f: /* Interrupt diagnostics */
|
|
|
|
case 0xf000 ... 0xf01f: /* FFB config, memory control */
|
|
|
|
/* we don't care */
|
2006-05-14 00:11:23 +08:00
|
|
|
default:
|
2007-10-06 19:28:21 +08:00
|
|
|
break;
|
2006-05-14 00:11:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static uint64_t sabre_config_read(void *opaque,
|
2012-10-23 18:30:10 +08:00
|
|
|
hwaddr addr, unsigned size)
|
2006-05-14 00:11:23 +08:00
|
|
|
{
|
2018-01-21 16:59:45 +08:00
|
|
|
SabreState *s = opaque;
|
2006-05-14 00:11:23 +08:00
|
|
|
uint32_t val;
|
|
|
|
|
2010-01-31 03:48:12 +08:00
|
|
|
switch (addr & 0xffff) {
|
|
|
|
case 0x30 ... 0x4f: /* DMA error registers */
|
|
|
|
val = 0;
|
|
|
|
/* XXX: not implemented yet */
|
|
|
|
break;
|
|
|
|
case 0xc00 ... 0xc3f: /* PCI interrupt control */
|
|
|
|
if (addr & 4) {
|
|
|
|
val = s->pci_irq_map[(addr & 0x3f) >> 3];
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-09-05 21:50:56 +08:00
|
|
|
case 0x1000 ... 0x107f: /* OBIO interrupt control */
|
2012-03-11 04:37:00 +08:00
|
|
|
if (addr & 4) {
|
|
|
|
val = s->obio_irq_map[(addr & 0xff) >> 3];
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-09-05 21:50:56 +08:00
|
|
|
case 0x1080 ... 0x108f: /* PCI bus error */
|
|
|
|
if (addr & 4) {
|
|
|
|
val = s->pci_err_irq_map[(addr & 0xf) >> 3];
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
break;
|
2010-01-31 03:48:12 +08:00
|
|
|
case 0x2000 ... 0x202f: /* PCI control */
|
|
|
|
val = s->pci_control[(addr & 0x3f) >> 2];
|
|
|
|
break;
|
|
|
|
case 0xf020 ... 0xf027: /* Reset control */
|
|
|
|
if (addr & 4) {
|
|
|
|
val = s->reset_control;
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x5000 ... 0x51cf: /* PIO/DMA diagnostics */
|
|
|
|
case 0xa400 ... 0xa67f: /* IOMMU diagnostics */
|
|
|
|
case 0xa800 ... 0xa80f: /* Interrupt diagnostics */
|
|
|
|
case 0xf000 ... 0xf01f: /* FFB config, memory control */
|
|
|
|
/* we don't care */
|
2006-05-14 00:11:23 +08:00
|
|
|
default:
|
2007-10-06 19:28:21 +08:00
|
|
|
val = 0;
|
|
|
|
break;
|
2006-05-14 00:11:23 +08:00
|
|
|
}
|
2013-02-05 22:06:20 +08:00
|
|
|
APB_DPRINTF("%s: addr " TARGET_FMT_plx " -> %x\n", __func__, addr, val);
|
2010-01-31 03:48:12 +08:00
|
|
|
|
2006-05-14 00:11:23 +08:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static const MemoryRegionOps sabre_config_ops = {
|
|
|
|
.read = sabre_config_read,
|
|
|
|
.write = sabre_config_write,
|
2017-09-05 01:41:01 +08:00
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
2006-05-14 00:11:23 +08:00
|
|
|
};
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_pci_config_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2010-01-12 05:20:53 +08:00
|
|
|
{
|
2018-01-21 16:59:45 +08:00
|
|
|
SabreState *s = opaque;
|
2013-07-22 21:54:30 +08:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2010-02-22 18:38:25 +08:00
|
|
|
|
2013-02-05 22:06:20 +08:00
|
|
|
APB_DPRINTF("%s: addr " TARGET_FMT_plx " val %" PRIx64 "\n", __func__, addr, val);
|
2013-07-22 21:54:30 +08:00
|
|
|
pci_data_write(phb->bus, addr, val, size);
|
2010-01-12 05:20:53 +08:00
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static uint64_t sabre_pci_config_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2010-01-12 05:20:53 +08:00
|
|
|
{
|
|
|
|
uint32_t ret;
|
2018-01-21 16:59:45 +08:00
|
|
|
SabreState *s = opaque;
|
2013-07-22 21:54:30 +08:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2010-01-12 05:20:53 +08:00
|
|
|
|
2013-07-22 21:54:30 +08:00
|
|
|
ret = pci_data_read(phb->bus, addr, size);
|
2013-02-05 22:06:20 +08:00
|
|
|
APB_DPRINTF("%s: addr " TARGET_FMT_plx " -> %x\n", __func__, addr, ret);
|
2010-01-12 05:20:53 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
/* The sabre host has an IRQ line for each IRQ line of each slot. */
|
|
|
|
static int pci_sabre_map_irq(PCIDevice *pci_dev, int irq_num)
|
2006-05-14 00:11:23 +08:00
|
|
|
{
|
2017-06-11 17:12:08 +08:00
|
|
|
/* Return the irq as swizzled by the PBM */
|
|
|
|
return irq_num;
|
2006-09-25 01:01:44 +08:00
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static int pci_simbaA_map_irq(PCIDevice *pci_dev, int irq_num)
|
2006-09-25 01:01:44 +08:00
|
|
|
{
|
2017-12-21 15:32:57 +08:00
|
|
|
/* The on-board devices have fixed (legacy) OBIO intnos */
|
|
|
|
switch (PCI_SLOT(pci_dev->devfn)) {
|
|
|
|
case 1:
|
|
|
|
/* Onboard NIC */
|
2017-12-21 15:32:57 +08:00
|
|
|
return OBIO_NIC_IRQ;
|
2017-12-21 15:32:57 +08:00
|
|
|
case 3:
|
|
|
|
/* Onboard IDE */
|
2017-12-21 15:32:57 +08:00
|
|
|
return OBIO_HDD_IRQ;
|
2017-12-21 15:32:57 +08:00
|
|
|
default:
|
|
|
|
/* Normal intno, fall through */
|
|
|
|
break;
|
2017-06-11 17:12:08 +08:00
|
|
|
}
|
|
|
|
|
2017-12-21 15:32:57 +08:00
|
|
|
return ((PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f;
|
|
|
|
}
|
2017-06-11 17:12:08 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static int pci_simbaB_map_irq(PCIDevice *pci_dev, int irq_num)
|
2017-12-21 15:32:57 +08:00
|
|
|
{
|
|
|
|
return (0x10 + (PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f;
|
2006-09-24 08:16:34 +08:00
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void pci_sabre_set_irq(void *opaque, int irq_num, int level)
|
2006-09-24 08:16:34 +08:00
|
|
|
{
|
2018-01-21 16:59:45 +08:00
|
|
|
SabreState *s = opaque;
|
2009-08-28 21:28:17 +08:00
|
|
|
|
2013-04-27 13:55:12 +08:00
|
|
|
APB_DPRINTF("%s: set irq_in %d level %d\n", __func__, irq_num, level);
|
2006-09-25 01:01:44 +08:00
|
|
|
/* PCI IRQ map onto the first 32 INO. */
|
2010-01-31 03:48:12 +08:00
|
|
|
if (irq_num < 32) {
|
2013-04-27 13:55:12 +08:00
|
|
|
if (level) {
|
|
|
|
s->pci_irq_in |= 1ULL << irq_num;
|
|
|
|
if (s->pci_irq_map[irq_num >> 2] & PBM_PCI_IMR_ENABLED) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_set_request(s, irq_num);
|
2013-04-27 13:55:12 +08:00
|
|
|
}
|
2012-03-11 04:37:00 +08:00
|
|
|
} else {
|
2013-04-27 13:55:12 +08:00
|
|
|
s->pci_irq_in &= ~(1ULL << irq_num);
|
2012-03-11 04:37:00 +08:00
|
|
|
}
|
|
|
|
} else {
|
2013-04-27 13:55:12 +08:00
|
|
|
/* OBIO IRQ map onto the next 32 INO. */
|
|
|
|
if (level) {
|
2012-03-11 04:37:00 +08:00
|
|
|
APB_DPRINTF("%s: set irq %d level %d\n", __func__, irq_num, level);
|
2013-04-27 13:55:12 +08:00
|
|
|
s->pci_irq_in |= 1ULL << irq_num;
|
|
|
|
if ((s->irq_request == NO_IRQ_REQUEST)
|
|
|
|
&& (s->obio_irq_map[irq_num - 32] & PBM_PCI_IMR_ENABLED)) {
|
2018-01-21 16:59:45 +08:00
|
|
|
sabre_set_request(s, irq_num);
|
2013-04-27 13:55:12 +08:00
|
|
|
}
|
2010-01-31 03:48:12 +08:00
|
|
|
} else {
|
2013-04-27 13:55:12 +08:00
|
|
|
s->pci_irq_in &= ~(1ULL << irq_num);
|
2010-01-31 03:48:12 +08:00
|
|
|
}
|
|
|
|
}
|
2006-05-14 00:11:23 +08:00
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_reset(DeviceState *d)
|
2009-07-21 16:36:37 +08:00
|
|
|
{
|
2018-01-21 16:59:45 +08:00
|
|
|
SabreState *s = SABRE_DEVICE(d);
|
2017-12-21 15:32:57 +08:00
|
|
|
PCIDevice *pci_dev;
|
|
|
|
unsigned int i;
|
|
|
|
uint16_t cmd;
|
2009-07-21 16:36:37 +08:00
|
|
|
|
2010-01-31 03:48:12 +08:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
s->pci_irq_map[i] &= PBM_PCI_IMR_MASK;
|
|
|
|
}
|
2012-05-12 17:15:22 +08:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
s->obio_irq_map[i] &= PBM_PCI_IMR_MASK;
|
|
|
|
}
|
2010-01-31 03:48:12 +08:00
|
|
|
|
2013-04-27 13:55:12 +08:00
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
s->pci_irq_in = 0ULL;
|
|
|
|
|
2010-05-13 03:27:23 +08:00
|
|
|
if (s->nr_resets++ == 0) {
|
2010-01-31 03:48:12 +08:00
|
|
|
/* Power on reset */
|
|
|
|
s->reset_control = POR;
|
|
|
|
}
|
2017-12-21 15:32:57 +08:00
|
|
|
|
|
|
|
/* As this is the busA PCI bridge which contains the on-board devices
|
|
|
|
* attached to the ebus, ensure that we initially allow IO transactions
|
|
|
|
* so that we get the early serial console until OpenBIOS can properly
|
|
|
|
* configure the PCI bridge itself */
|
|
|
|
pci_dev = PCI_DEVICE(s->bridgeA);
|
|
|
|
cmd = pci_get_word(pci_dev->config + PCI_COMMAND);
|
|
|
|
pci_set_word(pci_dev->config + PCI_COMMAND, cmd | PCI_COMMAND_IO);
|
|
|
|
pci_bridge_update_mappings(PCI_BRIDGE(pci_dev));
|
2010-01-31 03:48:12 +08:00
|
|
|
}
|
|
|
|
|
2011-08-15 22:17:15 +08:00
|
|
|
static const MemoryRegionOps pci_config_ops = {
|
2018-01-21 16:59:45 +08:00
|
|
|
.read = sabre_pci_config_read,
|
|
|
|
.write = sabre_pci_config_write,
|
2017-09-05 01:41:01 +08:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-15 22:17:15 +08:00
|
|
|
};
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_realize(DeviceState *dev, Error **errp)
|
2010-01-31 03:48:12 +08:00
|
|
|
{
|
2018-01-21 16:59:45 +08:00
|
|
|
SabreState *s = SABRE_DEVICE(dev);
|
2017-12-21 15:32:57 +08:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(dev);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(s);
|
2010-07-13 12:01:42 +08:00
|
|
|
PCIDevice *pci_dev;
|
2006-05-14 00:11:23 +08:00
|
|
|
|
2009-07-21 16:36:37 +08:00
|
|
|
/* apb_config */
|
2017-12-21 15:32:57 +08:00
|
|
|
sysbus_mmio_map(sbd, 0, s->special_base);
|
2010-05-25 20:09:03 +08:00
|
|
|
/* PCI configuration space */
|
2017-12-21 15:32:57 +08:00
|
|
|
sysbus_mmio_map(sbd, 1, s->special_base + 0x1000000ULL);
|
2009-07-21 16:36:37 +08:00
|
|
|
/* pci_ioport */
|
2017-12-21 15:32:57 +08:00
|
|
|
sysbus_mmio_map(sbd, 2, s->special_base + 0x2000000ULL);
|
2010-05-25 20:09:03 +08:00
|
|
|
|
2017-12-21 15:32:57 +08:00
|
|
|
memory_region_init(&s->pci_mmio, OBJECT(s), "pci-mmio", 0x100000000ULL);
|
|
|
|
memory_region_add_subregion(get_system_memory(), s->mem_base,
|
|
|
|
&s->pci_mmio);
|
|
|
|
|
2018-01-12 04:01:17 +08:00
|
|
|
phb->bus = pci_register_root_bus(dev, "pci",
|
2018-01-21 16:59:45 +08:00
|
|
|
pci_sabre_set_irq, pci_sabre_map_irq, s,
|
2018-01-12 04:01:17 +08:00
|
|
|
&s->pci_mmio,
|
|
|
|
&s->pci_ioport,
|
|
|
|
0, 32, TYPE_PCI_BUS);
|
2011-09-04 00:38:02 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
pci_create_simple(phb->bus, 0, TYPE_SABRE_PCI_DEVICE);
|
2010-05-25 20:09:03 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
/* IOMMU */
|
2018-01-09 02:16:34 +08:00
|
|
|
memory_region_add_subregion_overlap(&s->apb_config, 0x200,
|
|
|
|
sysbus_mmio_get_region(SYS_BUS_DEVICE(s->iommu), 0), 1);
|
2018-01-21 16:59:45 +08:00
|
|
|
pci_setup_iommu(phb->bus, sabre_pci_dma_iommu, s->iommu);
|
2014-05-28 15:28:22 +08:00
|
|
|
|
2009-07-21 16:36:37 +08:00
|
|
|
/* APB secondary busses */
|
2013-07-22 21:54:30 +08:00
|
|
|
pci_dev = pci_create_multifunction(phb->bus, PCI_DEVFN(1, 0), true,
|
2018-01-21 16:59:45 +08:00
|
|
|
TYPE_SIMBA_PCI_BRIDGE);
|
2017-12-21 15:32:57 +08:00
|
|
|
s->bridgeB = PCI_BRIDGE(pci_dev);
|
2018-01-21 16:59:45 +08:00
|
|
|
pci_bridge_map_irq(s->bridgeB, "pciB", pci_simbaB_map_irq);
|
2010-07-13 12:01:42 +08:00
|
|
|
qdev_init_nofail(&pci_dev->qdev);
|
|
|
|
|
2013-07-22 21:54:30 +08:00
|
|
|
pci_dev = pci_create_multifunction(phb->bus, PCI_DEVFN(1, 1), true,
|
2018-01-21 16:59:45 +08:00
|
|
|
TYPE_SIMBA_PCI_BRIDGE);
|
2017-12-21 15:32:57 +08:00
|
|
|
s->bridgeA = PCI_BRIDGE(pci_dev);
|
2018-01-21 16:59:45 +08:00
|
|
|
pci_bridge_map_irq(s->bridgeA, "pciA", pci_simbaA_map_irq);
|
2010-07-13 12:01:42 +08:00
|
|
|
qdev_init_nofail(&pci_dev->qdev);
|
2010-01-31 03:48:12 +08:00
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_init(Object *obj)
|
2010-01-31 03:48:12 +08:00
|
|
|
{
|
2018-01-21 16:59:45 +08:00
|
|
|
SabreState *s = SABRE_DEVICE(obj);
|
2017-12-21 15:32:57 +08:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2010-01-31 03:48:12 +08:00
|
|
|
unsigned int i;
|
2009-07-21 16:36:37 +08:00
|
|
|
|
2010-01-31 03:48:12 +08:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
s->pci_irq_map[i] = (0x1f << 6) | (i << 2);
|
|
|
|
}
|
2014-09-05 21:50:56 +08:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
s->pci_err_irq_map[i] = (0x1f << 6) | 0x30;
|
|
|
|
}
|
2012-05-12 17:15:22 +08:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
s->obio_irq_map[i] = ((0x1f << 6) | 0x20) + i;
|
|
|
|
}
|
2018-01-21 16:59:45 +08:00
|
|
|
qdev_init_gpio_in_named(DEVICE(s), pci_sabre_set_irq, "pbm-irq", MAX_IVEC);
|
2017-12-21 15:32:57 +08:00
|
|
|
qdev_init_gpio_out_named(DEVICE(s), s->ivec_irqs, "ivec-irq", MAX_IVEC);
|
2013-04-27 13:55:12 +08:00
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
s->pci_irq_in = 0ULL;
|
2010-01-31 03:48:12 +08:00
|
|
|
|
2018-01-09 02:16:34 +08:00
|
|
|
/* IOMMU */
|
|
|
|
object_property_add_link(obj, "iommu", TYPE_SUN4U_IOMMU,
|
|
|
|
(Object **) &s->iommu,
|
|
|
|
qdev_prop_allow_set_link_before_realize,
|
|
|
|
0, NULL);
|
|
|
|
|
2009-07-21 16:36:37 +08:00
|
|
|
/* apb_config */
|
2018-01-21 16:59:45 +08:00
|
|
|
memory_region_init_io(&s->apb_config, OBJECT(s), &sabre_config_ops, s,
|
2013-06-07 09:25:08 +08:00
|
|
|
"apb-config", 0x10000);
|
2010-05-25 20:09:03 +08:00
|
|
|
/* at region 0 */
|
2017-12-21 15:32:57 +08:00
|
|
|
sysbus_init_mmio(sbd, &s->apb_config);
|
2010-05-25 20:09:03 +08:00
|
|
|
|
2013-06-07 09:25:08 +08:00
|
|
|
memory_region_init_io(&s->pci_config, OBJECT(s), &pci_config_ops, s,
|
|
|
|
"apb-pci-config", 0x1000000);
|
2010-05-25 20:09:03 +08:00
|
|
|
/* at region 1 */
|
2017-12-21 15:32:57 +08:00
|
|
|
sysbus_init_mmio(sbd, &s->pci_config);
|
2010-05-25 20:09:03 +08:00
|
|
|
|
|
|
|
/* pci_ioport */
|
2017-06-11 17:12:08 +08:00
|
|
|
memory_region_init(&s->pci_ioport, OBJECT(s), "apb-pci-ioport", 0x1000000);
|
|
|
|
|
2010-05-25 20:09:03 +08:00
|
|
|
/* at region 2 */
|
2017-12-21 15:32:57 +08:00
|
|
|
sysbus_init_mmio(sbd, &s->pci_ioport);
|
2009-07-21 16:36:37 +08:00
|
|
|
}
|
2006-05-14 00:11:23 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_pci_realize(PCIDevice *d, Error **errp)
|
2009-07-21 16:36:37 +08:00
|
|
|
{
|
2010-02-14 16:27:19 +08:00
|
|
|
pci_set_word(d->config + PCI_COMMAND,
|
|
|
|
PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
|
|
|
|
pci_set_word(d->config + PCI_STATUS,
|
|
|
|
PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ |
|
|
|
|
PCI_STATUS_DEVSEL_MEDIUM);
|
2009-07-21 16:36:37 +08:00
|
|
|
}
|
2006-09-25 01:01:44 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_pci_class_init(ObjectClass *klass, void *data)
|
2011-12-05 02:22:06 +08:00
|
|
|
{
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
pci-host: Consistently set cannot_instantiate_with_device_add_yet
Many PCI host bridges consist of a sysbus device and a PCI device.
You need both for the thing to work. Arguably, these bridges should
be modelled as a single, composite devices instead of pairs of
seemingly independent devices you can only use together, but we're not
there, yet.
Since the sysbus part can't be instantiated with device_add, yet,
permitting it with the PCI part is useless. We shouldn't offer
useless options to the user, so let's set
cannot_instantiate_with_device_add_yet for them.
It's already set for Bonito, Grackle, i440FX and Raven. Document why.
Set it for the others: dec-21154, e500-host-bridge, gt64120_pci, mch,
pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
uni-north-internal-pci, uni-north-pci, and versatile_pci_host.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
2013-11-29 00:26:58 +08:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-05 02:22:06 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
k->realize = sabre_pci_realize;
|
2011-12-05 02:22:06 +08:00
|
|
|
k->vendor_id = PCI_VENDOR_ID_SUN;
|
|
|
|
k->device_id = PCI_DEVICE_ID_SUN_SABRE;
|
|
|
|
k->class_id = PCI_CLASS_BRIDGE_HOST;
|
pci-host: Consistently set cannot_instantiate_with_device_add_yet
Many PCI host bridges consist of a sysbus device and a PCI device.
You need both for the thing to work. Arguably, these bridges should
be modelled as a single, composite devices instead of pairs of
seemingly independent devices you can only use together, but we're not
there, yet.
Since the sysbus part can't be instantiated with device_add, yet,
permitting it with the PCI part is useless. We shouldn't offer
useless options to the user, so let's set
cannot_instantiate_with_device_add_yet for them.
It's already set for Bonito, Grackle, i440FX and Raven. Document why.
Set it for the others: dec-21154, e500-host-bridge, gt64120_pci, mch,
pbm-pci, ppc4xx-host-bridge, sh_pci_host, u3-agp, uni-north-agp,
uni-north-internal-pci, uni-north-pci, and versatile_pci_host.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel.a@redhat.com>
Signed-off-by: Andreas Färber <afaerber@suse.de>
2013-11-29 00:26:58 +08:00
|
|
|
/*
|
|
|
|
* PCI-facing part of the host bridge, not usable without the
|
|
|
|
* host-facing part, which can't be device_add'ed, yet.
|
|
|
|
*/
|
2017-05-04 04:35:44 +08:00
|
|
|
dc->user_creatable = false;
|
2011-12-05 02:22:06 +08:00
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static const TypeInfo sabre_pci_info = {
|
2018-01-21 16:59:45 +08:00
|
|
|
.name = TYPE_SABRE_PCI_DEVICE,
|
2011-12-08 11:34:16 +08:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
2018-01-21 16:59:45 +08:00
|
|
|
.instance_size = sizeof(SabrePCIState),
|
2018-01-21 16:59:45 +08:00
|
|
|
.class_init = sabre_pci_class_init,
|
2017-09-28 03:56:34 +08:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2009-07-21 16:36:37 +08:00
|
|
|
};
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static Property sabre_properties[] = {
|
2018-01-21 16:59:45 +08:00
|
|
|
DEFINE_PROP_UINT64("special-base", SabreState, special_base, 0),
|
|
|
|
DEFINE_PROP_UINT64("mem-base", SabreState, mem_base, 0),
|
2017-12-21 15:32:57 +08:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_class_init(ObjectClass *klass, void *data)
|
2012-01-25 03:12:29 +08:00
|
|
|
{
|
2011-12-08 11:34:16 +08:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-25 03:12:29 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
dc->realize = sabre_realize;
|
|
|
|
dc->reset = sabre_reset;
|
|
|
|
dc->props = sabre_properties;
|
2017-12-21 15:32:57 +08:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2012-01-25 03:12:29 +08:00
|
|
|
}
|
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static const TypeInfo sabre_info = {
|
2018-01-21 16:59:45 +08:00
|
|
|
.name = TYPE_SABRE,
|
2013-07-22 21:54:30 +08:00
|
|
|
.parent = TYPE_PCI_HOST_BRIDGE,
|
2018-01-21 16:59:45 +08:00
|
|
|
.instance_size = sizeof(SabreState),
|
2018-01-21 16:59:45 +08:00
|
|
|
.instance_init = sabre_init,
|
|
|
|
.class_init = sabre_class_init,
|
2010-01-31 03:48:12 +08:00
|
|
|
};
|
2010-07-13 12:01:42 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
static void sabre_register_types(void)
|
2009-07-21 16:36:37 +08:00
|
|
|
{
|
2018-01-21 16:59:45 +08:00
|
|
|
type_register_static(&sabre_info);
|
2018-01-21 16:59:45 +08:00
|
|
|
type_register_static(&sabre_pci_info);
|
2006-05-14 00:11:23 +08:00
|
|
|
}
|
2009-07-21 16:36:37 +08:00
|
|
|
|
2018-01-21 16:59:45 +08:00
|
|
|
type_init(sabre_register_types)
|