2006-05-13 18:11:23 +02:00
|
|
|
/*
|
2018-01-21 09:59:45 +01:00
|
|
|
* QEMU Ultrasparc Sabre PCI host (PBM)
|
2006-05-13 18:11:23 +02:00
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Fabrice Bellard
|
2013-04-27 07:55:12 +02:00
|
|
|
* Copyright (c) 2012,2013 Artyom Tarasenko
|
2018-01-21 09:59:45 +01:00
|
|
|
* Copyright (c) 2018 Mark Cave-Ayland
|
2007-09-16 23:08:06 +02:00
|
|
|
*
|
2006-05-13 18:11:23 +02: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-24 19:01:44 +02:00
|
|
|
|
2016-01-26 19:17:15 +01:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 15:40:22 +01: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 09:59:45 +01:00
|
|
|
#include "hw/pci-bridge/simba.h"
|
2018-01-21 09:59:45 +01:00
|
|
|
#include "hw/pci-host/sabre.h"
|
2012-12-17 18:20:04 +01:00
|
|
|
#include "sysemu/sysemu.h"
|
2012-12-17 18:19:49 +01:00
|
|
|
#include "exec/address-spaces.h"
|
2015-12-15 13:16:16 +01:00
|
|
|
#include "qemu/log.h"
|
2018-01-21 09:59:45 +01:00
|
|
|
#include "trace.h"
|
2009-01-09 21:53:30 +01:00
|
|
|
|
2009-10-13 20:56:27 +02:00
|
|
|
/*
|
|
|
|
* Chipset docs:
|
|
|
|
* PBM: "UltraSPARC IIi User's Manual",
|
|
|
|
* http://www.sun.com/processors/manuals/805-0087.pdf
|
|
|
|
*/
|
|
|
|
|
2010-01-30 20:48:12 +01:00
|
|
|
#define PBM_PCI_IMR_MASK 0x7fffffff
|
|
|
|
#define PBM_PCI_IMR_ENABLED 0x80000000
|
|
|
|
|
2014-03-17 17:00:41 +01: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-30 20:48:12 +01:00
|
|
|
#define RESET_MASK 0xf8000000
|
|
|
|
#define RESET_WCMASK 0x98000000
|
|
|
|
#define RESET_WMASK 0x60000000
|
|
|
|
|
2013-04-27 07:55:12 +02:00
|
|
|
#define NO_IRQ_REQUEST (MAX_IVEC + 1)
|
2012-03-10 21:37:00 +01:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static inline void sabre_set_request(SabreState *s, unsigned int irq_num)
|
2013-04-27 07:55:12 +02:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
trace_sabre_set_request(irq_num);
|
2013-04-27 07:55:12 +02:00
|
|
|
s->irq_request = irq_num;
|
|
|
|
qemu_set_irq(s->ivec_irqs[irq_num], 1);
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static inline void sabre_check_irqs(SabreState *s)
|
2013-04-27 07:55:12 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Previous request is not acknowledged, resubmit */
|
|
|
|
if (s->irq_request != NO_IRQ_REQUEST) {
|
2018-01-21 09:59:45 +01:00
|
|
|
sabre_set_request(s, s->irq_request);
|
2013-04-27 07:55:12 +02: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 09:59:45 +01:00
|
|
|
sabre_set_request(s, i);
|
2013-04-27 07:55:12 +02: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 09:59:45 +01:00
|
|
|
sabre_set_request(s, i);
|
2013-04-27 07:55:12 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static inline void sabre_clear_request(SabreState *s, unsigned int irq_num)
|
2013-04-27 07:55:12 +02:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
trace_sabre_clear_request(irq_num);
|
2013-04-27 07:55:12 +02:00
|
|
|
qemu_set_irq(s->ivec_irqs[irq_num], 0);
|
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
}
|
2012-05-12 11:15:23 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static AddressSpace *sabre_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
|
2014-05-28 09:28:22 +02:00
|
|
|
{
|
|
|
|
IOMMUState *is = opaque;
|
|
|
|
|
|
|
|
return &is->iommu_as;
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_config_write(void *opaque, hwaddr addr,
|
2011-08-15 16:17:15 +02:00
|
|
|
uint64_t val, unsigned size)
|
2006-05-13 18:11:23 +02:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
SabreState *s = opaque;
|
2010-01-30 20:48:12 +01:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
trace_sabre_config_write(addr, val);
|
2010-01-30 20:48:12 +01: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 07:55:12 +02: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 09:59:45 +01:00
|
|
|
sabre_clear_request(s, ino);
|
2013-04-27 07:55:12 +02:00
|
|
|
}
|
2018-01-21 09:59:45 +01:00
|
|
|
sabre_check_irqs(s);
|
2010-01-30 20:48:12 +01:00
|
|
|
}
|
|
|
|
break;
|
2014-09-05 15:50:56 +02:00
|
|
|
case 0x1000 ... 0x107f: /* OBIO interrupt control */
|
2012-03-10 21:37:00 +01:00
|
|
|
if (addr & 4) {
|
2013-04-27 07:55:12 +02: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 09:59:45 +01:00
|
|
|
sabre_clear_request(s, ino | 0x20);
|
2013-04-27 07:55:12 +02:00
|
|
|
}
|
2018-01-21 09:59:45 +01:00
|
|
|
sabre_check_irqs(s);
|
2012-03-10 21:37:00 +01:00
|
|
|
}
|
|
|
|
break;
|
2013-04-27 07:55:12 +02:00
|
|
|
case 0x1400 ... 0x14ff: /* PCI interrupt clear */
|
2012-05-12 11:15:23 +02:00
|
|
|
if (addr & 4) {
|
2013-04-27 07:55:12 +02:00
|
|
|
unsigned int ino = (addr & 0xff) >> 5;
|
|
|
|
if ((s->irq_request / 4) == ino) {
|
2018-01-21 09:59:45 +01:00
|
|
|
sabre_clear_request(s, s->irq_request);
|
|
|
|
sabre_check_irqs(s);
|
2013-04-27 07:55:12 +02:00
|
|
|
}
|
2012-05-12 11:15:23 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x1800 ... 0x1860: /* OBIO interrupt clear */
|
|
|
|
if (addr & 4) {
|
2013-04-27 07:55:12 +02:00
|
|
|
unsigned int ino = ((addr & 0xff) >> 3) | 0x20;
|
|
|
|
if (s->irq_request == ino) {
|
2018-01-21 09:59:45 +01:00
|
|
|
sabre_clear_request(s, ino);
|
|
|
|
sabre_check_irqs(s);
|
2013-04-27 07:55:12 +02:00
|
|
|
}
|
2012-05-12 11:15:23 +02:00
|
|
|
}
|
|
|
|
break;
|
2010-01-30 20:48:12 +01: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-12 21:27:23 +02:00
|
|
|
s->nr_resets = 0;
|
2017-05-15 23:41:13 +02:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2010-01-30 20:48:12 +01:00
|
|
|
} else if (val & SOFT_XIR) {
|
2017-05-15 23:41:13 +02:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2010-01-30 20:48:12 +01: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-13 18:11:23 +02:00
|
|
|
default:
|
2007-10-06 13:28:21 +02:00
|
|
|
break;
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static uint64_t sabre_config_read(void *opaque,
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr addr, unsigned size)
|
2006-05-13 18:11:23 +02:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
SabreState *s = opaque;
|
2006-05-13 18:11:23 +02:00
|
|
|
uint32_t val;
|
|
|
|
|
2010-01-30 20:48:12 +01: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 15:50:56 +02:00
|
|
|
case 0x1000 ... 0x107f: /* OBIO interrupt control */
|
2012-03-10 21:37:00 +01:00
|
|
|
if (addr & 4) {
|
|
|
|
val = s->obio_irq_map[(addr & 0xff) >> 3];
|
|
|
|
} else {
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-09-05 15:50:56 +02: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-30 20:48:12 +01: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-13 18:11:23 +02:00
|
|
|
default:
|
2007-10-06 13:28:21 +02:00
|
|
|
val = 0;
|
|
|
|
break;
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
2018-01-21 09:59:45 +01:00
|
|
|
trace_sabre_config_read(addr, val);
|
2010-01-30 20:48:12 +01:00
|
|
|
|
2006-05-13 18:11:23 +02:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static const MemoryRegionOps sabre_config_ops = {
|
|
|
|
.read = sabre_config_read,
|
|
|
|
.write = sabre_config_write,
|
2017-09-04 19:41:01 +02:00
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
2006-05-13 18:11:23 +02:00
|
|
|
};
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_pci_config_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2010-01-11 22:20:53 +01:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
SabreState *s = opaque;
|
2013-07-22 15:54:30 +02:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2010-02-22 11:38:25 +01:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
trace_sabre_pci_config_write(addr, val);
|
2013-07-22 15:54:30 +02:00
|
|
|
pci_data_write(phb->bus, addr, val, size);
|
2010-01-11 22:20:53 +01:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static uint64_t sabre_pci_config_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2010-01-11 22:20:53 +01:00
|
|
|
{
|
|
|
|
uint32_t ret;
|
2018-01-21 09:59:45 +01:00
|
|
|
SabreState *s = opaque;
|
2013-07-22 15:54:30 +02:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2010-01-11 22:20:53 +01:00
|
|
|
|
2013-07-22 15:54:30 +02:00
|
|
|
ret = pci_data_read(phb->bus, addr, size);
|
2018-01-21 09:59:45 +01:00
|
|
|
trace_sabre_pci_config_read(addr, ret);
|
2010-01-11 22:20:53 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01: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-13 18:11:23 +02:00
|
|
|
{
|
2017-06-11 11:12:08 +02:00
|
|
|
/* Return the irq as swizzled by the PBM */
|
|
|
|
return irq_num;
|
2006-09-24 19:01:44 +02:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static int pci_simbaA_map_irq(PCIDevice *pci_dev, int irq_num)
|
2006-09-24 19:01:44 +02:00
|
|
|
{
|
2017-12-21 08:32:57 +01:00
|
|
|
/* The on-board devices have fixed (legacy) OBIO intnos */
|
|
|
|
switch (PCI_SLOT(pci_dev->devfn)) {
|
|
|
|
case 1:
|
|
|
|
/* Onboard NIC */
|
2017-12-21 08:32:57 +01:00
|
|
|
return OBIO_NIC_IRQ;
|
2017-12-21 08:32:57 +01:00
|
|
|
case 3:
|
|
|
|
/* Onboard IDE */
|
2017-12-21 08:32:57 +01:00
|
|
|
return OBIO_HDD_IRQ;
|
2017-12-21 08:32:57 +01:00
|
|
|
default:
|
|
|
|
/* Normal intno, fall through */
|
|
|
|
break;
|
2017-06-11 11:12:08 +02:00
|
|
|
}
|
|
|
|
|
2017-12-21 08:32:57 +01:00
|
|
|
return ((PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f;
|
|
|
|
}
|
2017-06-11 11:12:08 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static int pci_simbaB_map_irq(PCIDevice *pci_dev, int irq_num)
|
2017-12-21 08:32:57 +01:00
|
|
|
{
|
|
|
|
return (0x10 + (PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f;
|
2006-09-24 02:16:34 +02:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void pci_sabre_set_irq(void *opaque, int irq_num, int level)
|
2006-09-24 02:16:34 +02:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
SabreState *s = opaque;
|
2009-08-28 15:28:17 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
trace_sabre_pci_set_irq(irq_num, level);
|
|
|
|
|
2006-09-24 19:01:44 +02:00
|
|
|
/* PCI IRQ map onto the first 32 INO. */
|
2010-01-30 20:48:12 +01:00
|
|
|
if (irq_num < 32) {
|
2013-04-27 07:55:12 +02: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 09:59:45 +01:00
|
|
|
sabre_set_request(s, irq_num);
|
2013-04-27 07:55:12 +02:00
|
|
|
}
|
2012-03-10 21:37:00 +01:00
|
|
|
} else {
|
2013-04-27 07:55:12 +02:00
|
|
|
s->pci_irq_in &= ~(1ULL << irq_num);
|
2012-03-10 21:37:00 +01:00
|
|
|
}
|
|
|
|
} else {
|
2013-04-27 07:55:12 +02:00
|
|
|
/* OBIO IRQ map onto the next 32 INO. */
|
|
|
|
if (level) {
|
2018-01-21 09:59:45 +01:00
|
|
|
trace_sabre_pci_set_obio_irq(irq_num, level);
|
2013-04-27 07:55:12 +02: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 09:59:45 +01:00
|
|
|
sabre_set_request(s, irq_num);
|
2013-04-27 07:55:12 +02:00
|
|
|
}
|
2010-01-30 20:48:12 +01:00
|
|
|
} else {
|
2013-04-27 07:55:12 +02:00
|
|
|
s->pci_irq_in &= ~(1ULL << irq_num);
|
2010-01-30 20:48:12 +01:00
|
|
|
}
|
|
|
|
}
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_reset(DeviceState *d)
|
2009-07-21 10:36:37 +02:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
SabreState *s = SABRE_DEVICE(d);
|
2017-12-21 08:32:57 +01:00
|
|
|
PCIDevice *pci_dev;
|
|
|
|
unsigned int i;
|
|
|
|
uint16_t cmd;
|
2009-07-21 10:36:37 +02:00
|
|
|
|
2010-01-30 20:48:12 +01:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
s->pci_irq_map[i] &= PBM_PCI_IMR_MASK;
|
|
|
|
}
|
2012-05-12 11:15:22 +02:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
s->obio_irq_map[i] &= PBM_PCI_IMR_MASK;
|
|
|
|
}
|
2010-01-30 20:48:12 +01:00
|
|
|
|
2013-04-27 07:55:12 +02:00
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
s->pci_irq_in = 0ULL;
|
|
|
|
|
2010-05-12 21:27:23 +02:00
|
|
|
if (s->nr_resets++ == 0) {
|
2010-01-30 20:48:12 +01:00
|
|
|
/* Power on reset */
|
|
|
|
s->reset_control = POR;
|
|
|
|
}
|
2017-12-21 08:32:57 +01: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-30 20:48:12 +01:00
|
|
|
}
|
|
|
|
|
2011-08-15 16:17:15 +02:00
|
|
|
static const MemoryRegionOps pci_config_ops = {
|
2018-01-21 09:59:45 +01:00
|
|
|
.read = sabre_pci_config_read,
|
|
|
|
.write = sabre_pci_config_write,
|
2017-09-04 19:41:01 +02:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-15 16:17:15 +02:00
|
|
|
};
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_realize(DeviceState *dev, Error **errp)
|
2010-01-30 20:48:12 +01:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
SabreState *s = SABRE_DEVICE(dev);
|
2017-12-21 08:32:57 +01:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(dev);
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(s);
|
2010-07-13 06:01:42 +02:00
|
|
|
PCIDevice *pci_dev;
|
2006-05-13 18:11:23 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
/* sabre_config */
|
2017-12-21 08:32:57 +01:00
|
|
|
sysbus_mmio_map(sbd, 0, s->special_base);
|
2010-05-25 14:09:03 +02:00
|
|
|
/* PCI configuration space */
|
2017-12-21 08:32:57 +01:00
|
|
|
sysbus_mmio_map(sbd, 1, s->special_base + 0x1000000ULL);
|
2009-07-21 10:36:37 +02:00
|
|
|
/* pci_ioport */
|
2017-12-21 08:32:57 +01:00
|
|
|
sysbus_mmio_map(sbd, 2, s->special_base + 0x2000000ULL);
|
2010-05-25 14:09:03 +02:00
|
|
|
|
2017-12-21 08:32:57 +01: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-11 21:01:17 +01:00
|
|
|
phb->bus = pci_register_root_bus(dev, "pci",
|
2018-01-21 09:59:45 +01:00
|
|
|
pci_sabre_set_irq, pci_sabre_map_irq, s,
|
2018-01-11 21:01:17 +01:00
|
|
|
&s->pci_mmio,
|
|
|
|
&s->pci_ioport,
|
|
|
|
0, 32, TYPE_PCI_BUS);
|
2011-09-03 18:38:02 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
pci_create_simple(phb->bus, 0, TYPE_SABRE_PCI_DEVICE);
|
2010-05-25 14:09:03 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
/* IOMMU */
|
2018-01-21 09:59:45 +01:00
|
|
|
memory_region_add_subregion_overlap(&s->sabre_config, 0x200,
|
2018-01-08 19:16:34 +01:00
|
|
|
sysbus_mmio_get_region(SYS_BUS_DEVICE(s->iommu), 0), 1);
|
2018-01-21 09:59:45 +01:00
|
|
|
pci_setup_iommu(phb->bus, sabre_pci_dma_iommu, s->iommu);
|
2014-05-28 09:28:22 +02:00
|
|
|
|
2009-07-21 10:36:37 +02:00
|
|
|
/* APB secondary busses */
|
2013-07-22 15:54:30 +02:00
|
|
|
pci_dev = pci_create_multifunction(phb->bus, PCI_DEVFN(1, 0), true,
|
2018-01-21 09:59:45 +01:00
|
|
|
TYPE_SIMBA_PCI_BRIDGE);
|
2017-12-21 08:32:57 +01:00
|
|
|
s->bridgeB = PCI_BRIDGE(pci_dev);
|
2018-01-21 09:59:45 +01:00
|
|
|
pci_bridge_map_irq(s->bridgeB, "pciB", pci_simbaB_map_irq);
|
2010-07-13 06:01:42 +02:00
|
|
|
qdev_init_nofail(&pci_dev->qdev);
|
|
|
|
|
2013-07-22 15:54:30 +02:00
|
|
|
pci_dev = pci_create_multifunction(phb->bus, PCI_DEVFN(1, 1), true,
|
2018-01-21 09:59:45 +01:00
|
|
|
TYPE_SIMBA_PCI_BRIDGE);
|
2017-12-21 08:32:57 +01:00
|
|
|
s->bridgeA = PCI_BRIDGE(pci_dev);
|
2018-01-21 09:59:45 +01:00
|
|
|
pci_bridge_map_irq(s->bridgeA, "pciA", pci_simbaA_map_irq);
|
2010-07-13 06:01:42 +02:00
|
|
|
qdev_init_nofail(&pci_dev->qdev);
|
2010-01-30 20:48:12 +01:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_init(Object *obj)
|
2010-01-30 20:48:12 +01:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
SabreState *s = SABRE_DEVICE(obj);
|
2017-12-21 08:32:57 +01:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2010-01-30 20:48:12 +01:00
|
|
|
unsigned int i;
|
2009-07-21 10:36:37 +02:00
|
|
|
|
2010-01-30 20:48:12 +01:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
s->pci_irq_map[i] = (0x1f << 6) | (i << 2);
|
|
|
|
}
|
2014-09-05 15:50:56 +02:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
s->pci_err_irq_map[i] = (0x1f << 6) | 0x30;
|
|
|
|
}
|
2012-05-12 11:15:22 +02:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
s->obio_irq_map[i] = ((0x1f << 6) | 0x20) + i;
|
|
|
|
}
|
2018-01-21 09:59:45 +01:00
|
|
|
qdev_init_gpio_in_named(DEVICE(s), pci_sabre_set_irq, "pbm-irq", MAX_IVEC);
|
2017-12-21 08:32:57 +01:00
|
|
|
qdev_init_gpio_out_named(DEVICE(s), s->ivec_irqs, "ivec-irq", MAX_IVEC);
|
2013-04-27 07:55:12 +02:00
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
s->pci_irq_in = 0ULL;
|
2010-01-30 20:48:12 +01:00
|
|
|
|
2018-01-08 19:16:34 +01:00
|
|
|
/* IOMMU */
|
|
|
|
object_property_add_link(obj, "iommu", TYPE_SUN4U_IOMMU,
|
|
|
|
(Object **) &s->iommu,
|
|
|
|
qdev_prop_allow_set_link_before_realize,
|
|
|
|
0, NULL);
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
/* sabre_config */
|
|
|
|
memory_region_init_io(&s->sabre_config, OBJECT(s), &sabre_config_ops, s,
|
|
|
|
"sabre-config", 0x10000);
|
2010-05-25 14:09:03 +02:00
|
|
|
/* at region 0 */
|
2018-01-21 09:59:45 +01:00
|
|
|
sysbus_init_mmio(sbd, &s->sabre_config);
|
2010-05-25 14:09:03 +02:00
|
|
|
|
2013-06-07 03:25:08 +02:00
|
|
|
memory_region_init_io(&s->pci_config, OBJECT(s), &pci_config_ops, s,
|
2018-01-21 09:59:45 +01:00
|
|
|
"sabre-pci-config", 0x1000000);
|
2010-05-25 14:09:03 +02:00
|
|
|
/* at region 1 */
|
2017-12-21 08:32:57 +01:00
|
|
|
sysbus_init_mmio(sbd, &s->pci_config);
|
2010-05-25 14:09:03 +02:00
|
|
|
|
|
|
|
/* pci_ioport */
|
2018-01-21 09:59:45 +01:00
|
|
|
memory_region_init(&s->pci_ioport, OBJECT(s), "sabre-pci-ioport",
|
|
|
|
0x1000000);
|
2017-06-11 11:12:08 +02:00
|
|
|
|
2010-05-25 14:09:03 +02:00
|
|
|
/* at region 2 */
|
2017-12-21 08:32:57 +01:00
|
|
|
sysbus_init_mmio(sbd, &s->pci_ioport);
|
2009-07-21 10:36:37 +02:00
|
|
|
}
|
2006-05-13 18:11:23 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_pci_realize(PCIDevice *d, Error **errp)
|
2009-07-21 10:36:37 +02:00
|
|
|
{
|
2010-02-14 09:27:19 +01: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 10:36:37 +02:00
|
|
|
}
|
2006-09-24 19:01:44 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_pci_class_init(ObjectClass *klass, void *data)
|
2011-12-04 19:22:06 +01: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-28 17:26:58 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 19:22:06 +01:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
k->realize = sabre_pci_realize;
|
2011-12-04 19:22:06 +01: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-28 17:26:58 +01: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-03 22:35:44 +02:00
|
|
|
dc->user_creatable = false;
|
2011-12-04 19:22:06 +01:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static const TypeInfo sabre_pci_info = {
|
2018-01-21 09:59:45 +01:00
|
|
|
.name = TYPE_SABRE_PCI_DEVICE,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
2018-01-21 09:59:45 +01:00
|
|
|
.instance_size = sizeof(SabrePCIState),
|
2018-01-21 09:59:45 +01:00
|
|
|
.class_init = sabre_pci_class_init,
|
2017-09-27 21:56:34 +02:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2009-07-21 10:36:37 +02:00
|
|
|
};
|
|
|
|
|
2018-08-29 18:33:45 +02:00
|
|
|
static char *sabre_ofw_unit_address(const SysBusDevice *dev)
|
|
|
|
{
|
|
|
|
SabreState *s = SABRE_DEVICE(dev);
|
|
|
|
|
|
|
|
return g_strdup_printf("%x,%x",
|
|
|
|
(uint32_t)((s->special_base >> 32) & 0xffffffff),
|
|
|
|
(uint32_t)(s->special_base & 0xffffffff));
|
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static Property sabre_properties[] = {
|
2018-01-21 09:59:45 +01:00
|
|
|
DEFINE_PROP_UINT64("special-base", SabreState, special_base, 0),
|
|
|
|
DEFINE_PROP_UINT64("mem-base", SabreState, mem_base, 0),
|
2017-12-21 08:32:57 +01:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_class_init(ObjectClass *klass, void *data)
|
2012-01-24 20:12:29 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2018-08-29 18:33:45 +02:00
|
|
|
SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
dc->realize = sabre_realize;
|
|
|
|
dc->reset = sabre_reset;
|
|
|
|
dc->props = sabre_properties;
|
2017-12-21 08:32:57 +01:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2018-08-29 18:33:45 +02:00
|
|
|
dc->fw_name = "pci";
|
|
|
|
sbc->explicit_ofw_unit_address = sabre_ofw_unit_address;
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static const TypeInfo sabre_info = {
|
2018-01-21 09:59:45 +01:00
|
|
|
.name = TYPE_SABRE,
|
2013-07-22 15:54:30 +02:00
|
|
|
.parent = TYPE_PCI_HOST_BRIDGE,
|
2018-01-21 09:59:45 +01:00
|
|
|
.instance_size = sizeof(SabreState),
|
2018-01-21 09:59:45 +01:00
|
|
|
.instance_init = sabre_init,
|
|
|
|
.class_init = sabre_class_init,
|
2010-01-30 20:48:12 +01:00
|
|
|
};
|
2010-07-13 06:01:42 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
static void sabre_register_types(void)
|
2009-07-21 10:36:37 +02:00
|
|
|
{
|
2018-01-21 09:59:45 +01:00
|
|
|
type_register_static(&sabre_info);
|
2018-01-21 09:59:45 +01:00
|
|
|
type_register_static(&sabre_pci_info);
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
2009-07-21 10:36:37 +02:00
|
|
|
|
2018-01-21 09:59:45 +01:00
|
|
|
type_init(sabre_register_types)
|