2006-05-13 20:11:23 +04:00
|
|
|
/*
|
2018-01-21 11:59:45 +03:00
|
|
|
* QEMU Ultrasparc Sabre PCI host (PBM)
|
2006-05-13 20:11:23 +04:00
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Fabrice Bellard
|
2013-04-27 09:55:12 +04:00
|
|
|
* Copyright (c) 2012,2013 Artyom Tarasenko
|
2018-01-21 11:59:45 +03:00
|
|
|
* Copyright (c) 2018 Mark Cave-Ayland
|
2007-09-17 01:08:06 +04:00
|
|
|
*
|
2006-05-13 20:11:23 +04: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 21:01:44 +04:00
|
|
|
|
2016-01-26 21:17:15 +03:00
|
|
|
#include "qemu/osdep.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/sysbus.h"
|
|
|
|
#include "hw/pci/pci.h"
|
|
|
|
#include "hw/pci/pci_host.h"
|
2019-08-12 08:23:51 +03:00
|
|
|
#include "hw/qdev-properties.h"
|
2013-02-04 18:40:22 +04:00
|
|
|
#include "hw/pci/pci_bridge.h"
|
|
|
|
#include "hw/pci/pci_bus.h"
|
2019-08-12 08:23:42 +03:00
|
|
|
#include "hw/irq.h"
|
2018-01-21 11:59:45 +03:00
|
|
|
#include "hw/pci-bridge/simba.h"
|
2018-01-21 11:59:45 +03:00
|
|
|
#include "hw/pci-host/sabre.h"
|
2012-12-17 21:19:49 +04:00
|
|
|
#include "exec/address-spaces.h"
|
pci: Convert uses of pci_create() etc. with Coccinelle
Replace
dev = pci_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = pci_new(type_name);
...
pci_realize_and_unref(dev, bus, &error_fatal);
and similarly for pci_create_multifunction().
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(pci_create(bus, args));
+ PCIDevice *pci_dev; // TODO move
+ pci_dev = pci_new(args);
+ dev = DEVICE(pci_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ pci_realize_and_unref(pci_dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, expr;
expression list args;
identifier dev;
@@
- PCIDevice *dev = pci_create_multifunction(bus, args);
+ PCIDevice *dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually, @pci_dev declarations moved manually.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-16-armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
2020-06-10 08:32:04 +03:00
|
|
|
#include "qapi/error.h"
|
2015-12-15 15:16:16 +03:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 17:35:07 +03:00
|
|
|
#include "qemu/module.h"
|
2019-08-12 08:23:59 +03:00
|
|
|
#include "sysemu/runstate.h"
|
2018-01-21 11:59:45 +03:00
|
|
|
#include "trace.h"
|
2009-01-09 23:53:30 +03:00
|
|
|
|
2009-10-13 22:56:27 +04:00
|
|
|
/*
|
|
|
|
* Chipset docs:
|
|
|
|
* PBM: "UltraSPARC IIi User's Manual",
|
2020-10-12 20:09:45 +03:00
|
|
|
* https://web.archive.org/web/20030403110020/http://www.sun.com/processors/manuals/805-0087.pdf
|
2009-10-13 22:56:27 +04:00
|
|
|
*/
|
|
|
|
|
2010-01-30 22:48:12 +03:00
|
|
|
#define PBM_PCI_IMR_MASK 0x7fffffff
|
|
|
|
#define PBM_PCI_IMR_ENABLED 0x80000000
|
|
|
|
|
2014-03-17 20:00:41 +04: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 22:48:12 +03:00
|
|
|
#define RESET_MASK 0xf8000000
|
|
|
|
#define RESET_WCMASK 0x98000000
|
|
|
|
#define RESET_WMASK 0x60000000
|
|
|
|
|
2013-04-27 09:55:12 +04:00
|
|
|
#define NO_IRQ_REQUEST (MAX_IVEC + 1)
|
2012-03-11 00:37:00 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static inline void sabre_set_request(SabreState *s, unsigned int irq_num)
|
2013-04-27 09:55:12 +04:00
|
|
|
{
|
2018-01-21 11:59:45 +03:00
|
|
|
trace_sabre_set_request(irq_num);
|
2013-04-27 09:55:12 +04:00
|
|
|
s->irq_request = irq_num;
|
|
|
|
qemu_set_irq(s->ivec_irqs[irq_num], 1);
|
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static inline void sabre_check_irqs(SabreState *s)
|
2013-04-27 09:55:12 +04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
/* Previous request is not acknowledged, resubmit */
|
|
|
|
if (s->irq_request != NO_IRQ_REQUEST) {
|
2018-01-21 11:59:45 +03:00
|
|
|
sabre_set_request(s, s->irq_request);
|
2013-04-27 09:55:12 +04: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 11:59:45 +03:00
|
|
|
sabre_set_request(s, i);
|
2013-04-27 09:55:12 +04: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 11:59:45 +03:00
|
|
|
sabre_set_request(s, i);
|
2013-04-27 09:55:12 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static inline void sabre_clear_request(SabreState *s, unsigned int irq_num)
|
2013-04-27 09:55:12 +04:00
|
|
|
{
|
2018-01-21 11:59:45 +03:00
|
|
|
trace_sabre_clear_request(irq_num);
|
2013-04-27 09:55:12 +04:00
|
|
|
qemu_set_irq(s->ivec_irqs[irq_num], 0);
|
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
}
|
2012-05-12 13:15:23 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static AddressSpace *sabre_pci_dma_iommu(PCIBus *bus, void *opaque, int devfn)
|
2014-05-28 11:28:22 +04:00
|
|
|
{
|
|
|
|
IOMMUState *is = opaque;
|
|
|
|
|
|
|
|
return &is->iommu_as;
|
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_config_write(void *opaque, hwaddr addr,
|
2011-08-15 18:17:15 +04:00
|
|
|
uint64_t val, unsigned size)
|
2006-05-13 20:11:23 +04:00
|
|
|
{
|
2018-01-21 11:59:45 +03:00
|
|
|
SabreState *s = opaque;
|
2010-01-30 22:48:12 +03:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
trace_sabre_config_write(addr, val);
|
2010-01-30 22:48:12 +03:00
|
|
|
|
2020-10-12 20:09:46 +03:00
|
|
|
switch (addr) {
|
2010-01-30 22:48:12 +03:00
|
|
|
case 0x30 ... 0x4f: /* DMA error registers */
|
|
|
|
/* XXX: not implemented yet */
|
|
|
|
break;
|
|
|
|
case 0xc00 ... 0xc3f: /* PCI interrupt control */
|
|
|
|
if (addr & 4) {
|
2013-04-27 09:55:12 +04: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 11:59:45 +03:00
|
|
|
sabre_clear_request(s, ino);
|
2013-04-27 09:55:12 +04:00
|
|
|
}
|
2018-01-21 11:59:45 +03:00
|
|
|
sabre_check_irqs(s);
|
2010-01-30 22:48:12 +03:00
|
|
|
}
|
|
|
|
break;
|
2014-09-05 17:50:56 +04:00
|
|
|
case 0x1000 ... 0x107f: /* OBIO interrupt control */
|
2012-03-11 00:37:00 +04:00
|
|
|
if (addr & 4) {
|
2013-04-27 09:55:12 +04: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 11:59:45 +03:00
|
|
|
sabre_clear_request(s, ino | 0x20);
|
2013-04-27 09:55:12 +04:00
|
|
|
}
|
2018-01-21 11:59:45 +03:00
|
|
|
sabre_check_irqs(s);
|
2012-03-11 00:37:00 +04:00
|
|
|
}
|
|
|
|
break;
|
2013-04-27 09:55:12 +04:00
|
|
|
case 0x1400 ... 0x14ff: /* PCI interrupt clear */
|
2012-05-12 13:15:23 +04:00
|
|
|
if (addr & 4) {
|
2013-04-27 09:55:12 +04:00
|
|
|
unsigned int ino = (addr & 0xff) >> 5;
|
|
|
|
if ((s->irq_request / 4) == ino) {
|
2018-01-21 11:59:45 +03:00
|
|
|
sabre_clear_request(s, s->irq_request);
|
|
|
|
sabre_check_irqs(s);
|
2013-04-27 09:55:12 +04:00
|
|
|
}
|
2012-05-12 13:15:23 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 0x1800 ... 0x1860: /* OBIO interrupt clear */
|
|
|
|
if (addr & 4) {
|
2013-04-27 09:55:12 +04:00
|
|
|
unsigned int ino = ((addr & 0xff) >> 3) | 0x20;
|
|
|
|
if (s->irq_request == ino) {
|
2018-01-21 11:59:45 +03:00
|
|
|
sabre_clear_request(s, ino);
|
|
|
|
sabre_check_irqs(s);
|
2013-04-27 09:55:12 +04:00
|
|
|
}
|
2012-05-12 13:15:23 +04:00
|
|
|
}
|
|
|
|
break;
|
2010-01-30 22:48:12 +03: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 23:27:23 +04:00
|
|
|
s->nr_resets = 0;
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2010-01-30 22:48:12 +03:00
|
|
|
} else if (val & SOFT_XIR) {
|
2017-05-16 00:41:13 +03:00
|
|
|
qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
|
2010-01-30 22:48:12 +03: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 20:11:23 +04:00
|
|
|
default:
|
2007-10-06 15:28:21 +04:00
|
|
|
break;
|
2006-05-13 20:11:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static uint64_t sabre_config_read(void *opaque,
|
2012-10-23 14:30:10 +04:00
|
|
|
hwaddr addr, unsigned size)
|
2006-05-13 20:11:23 +04:00
|
|
|
{
|
2018-01-21 11:59:45 +03:00
|
|
|
SabreState *s = opaque;
|
2020-10-12 20:09:47 +03:00
|
|
|
uint32_t val = 0;
|
2006-05-13 20:11:23 +04:00
|
|
|
|
2020-10-12 20:09:46 +03:00
|
|
|
switch (addr) {
|
2010-01-30 22:48:12 +03:00
|
|
|
case 0x30 ... 0x4f: /* DMA error registers */
|
|
|
|
/* XXX: not implemented yet */
|
|
|
|
break;
|
|
|
|
case 0xc00 ... 0xc3f: /* PCI interrupt control */
|
|
|
|
if (addr & 4) {
|
|
|
|
val = s->pci_irq_map[(addr & 0x3f) >> 3];
|
|
|
|
}
|
|
|
|
break;
|
2014-09-05 17:50:56 +04:00
|
|
|
case 0x1000 ... 0x107f: /* OBIO interrupt control */
|
2012-03-11 00:37:00 +04:00
|
|
|
if (addr & 4) {
|
|
|
|
val = s->obio_irq_map[(addr & 0xff) >> 3];
|
|
|
|
}
|
|
|
|
break;
|
2014-09-05 17:50:56 +04:00
|
|
|
case 0x1080 ... 0x108f: /* PCI bus error */
|
|
|
|
if (addr & 4) {
|
|
|
|
val = s->pci_err_irq_map[(addr & 0xf) >> 3];
|
|
|
|
}
|
|
|
|
break;
|
2010-01-30 22:48:12 +03: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;
|
|
|
|
}
|
|
|
|
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 20:11:23 +04:00
|
|
|
default:
|
2007-10-06 15:28:21 +04:00
|
|
|
break;
|
2006-05-13 20:11:23 +04:00
|
|
|
}
|
2018-01-21 11:59:45 +03:00
|
|
|
trace_sabre_config_read(addr, val);
|
2010-01-30 22:48:12 +03:00
|
|
|
|
2006-05-13 20:11:23 +04:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static const MemoryRegionOps sabre_config_ops = {
|
|
|
|
.read = sabre_config_read,
|
|
|
|
.write = sabre_config_write,
|
2017-09-04 20:41:01 +03:00
|
|
|
.endianness = DEVICE_BIG_ENDIAN,
|
2006-05-13 20:11:23 +04:00
|
|
|
};
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_pci_config_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned size)
|
2010-01-12 00:20:53 +03:00
|
|
|
{
|
2018-01-21 11:59:45 +03:00
|
|
|
SabreState *s = opaque;
|
2013-07-22 17:54:30 +04:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2010-02-22 13:38:25 +03:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
trace_sabre_pci_config_write(addr, val);
|
2013-07-22 17:54:30 +04:00
|
|
|
pci_data_write(phb->bus, addr, val, size);
|
2010-01-12 00:20:53 +03:00
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static uint64_t sabre_pci_config_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned size)
|
2010-01-12 00:20:53 +03:00
|
|
|
{
|
|
|
|
uint32_t ret;
|
2018-01-21 11:59:45 +03:00
|
|
|
SabreState *s = opaque;
|
2013-07-22 17:54:30 +04:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2010-01-12 00:20:53 +03:00
|
|
|
|
2013-07-22 17:54:30 +04:00
|
|
|
ret = pci_data_read(phb->bus, addr, size);
|
2018-01-21 11:59:45 +03:00
|
|
|
trace_sabre_pci_config_read(addr, ret);
|
2010-01-12 00:20:53 +03:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03: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 20:11:23 +04:00
|
|
|
{
|
2017-06-11 12:12:08 +03:00
|
|
|
/* Return the irq as swizzled by the PBM */
|
|
|
|
return irq_num;
|
2006-09-24 21:01:44 +04:00
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static int pci_simbaA_map_irq(PCIDevice *pci_dev, int irq_num)
|
2006-09-24 21:01:44 +04:00
|
|
|
{
|
2017-12-21 10:32:57 +03:00
|
|
|
/* The on-board devices have fixed (legacy) OBIO intnos */
|
|
|
|
switch (PCI_SLOT(pci_dev->devfn)) {
|
|
|
|
case 1:
|
|
|
|
/* Onboard NIC */
|
2017-12-21 10:32:57 +03:00
|
|
|
return OBIO_NIC_IRQ;
|
2017-12-21 10:32:57 +03:00
|
|
|
case 3:
|
|
|
|
/* Onboard IDE */
|
2017-12-21 10:32:57 +03:00
|
|
|
return OBIO_HDD_IRQ;
|
2017-12-21 10:32:57 +03:00
|
|
|
default:
|
|
|
|
/* Normal intno, fall through */
|
|
|
|
break;
|
2017-06-11 12:12:08 +03:00
|
|
|
}
|
|
|
|
|
2017-12-21 10:32:57 +03:00
|
|
|
return ((PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f;
|
|
|
|
}
|
2017-06-11 12:12:08 +03:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static int pci_simbaB_map_irq(PCIDevice *pci_dev, int irq_num)
|
2017-12-21 10:32:57 +03:00
|
|
|
{
|
|
|
|
return (0x10 + (PCI_SLOT(pci_dev->devfn) << 2) + irq_num) & 0x1f;
|
2006-09-24 04:16:34 +04:00
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void pci_sabre_set_irq(void *opaque, int irq_num, int level)
|
2006-09-24 04:16:34 +04:00
|
|
|
{
|
2018-01-21 11:59:45 +03:00
|
|
|
SabreState *s = opaque;
|
2009-08-28 17:28:17 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
trace_sabre_pci_set_irq(irq_num, level);
|
|
|
|
|
2006-09-24 21:01:44 +04:00
|
|
|
/* PCI IRQ map onto the first 32 INO. */
|
2010-01-30 22:48:12 +03:00
|
|
|
if (irq_num < 32) {
|
2013-04-27 09:55:12 +04: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 11:59:45 +03:00
|
|
|
sabre_set_request(s, irq_num);
|
2013-04-27 09:55:12 +04:00
|
|
|
}
|
2012-03-11 00:37:00 +04:00
|
|
|
} else {
|
2013-04-27 09:55:12 +04:00
|
|
|
s->pci_irq_in &= ~(1ULL << irq_num);
|
2012-03-11 00:37:00 +04:00
|
|
|
}
|
|
|
|
} else {
|
2013-04-27 09:55:12 +04:00
|
|
|
/* OBIO IRQ map onto the next 32 INO. */
|
|
|
|
if (level) {
|
2018-01-21 11:59:45 +03:00
|
|
|
trace_sabre_pci_set_obio_irq(irq_num, level);
|
2013-04-27 09:55:12 +04: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 11:59:45 +03:00
|
|
|
sabre_set_request(s, irq_num);
|
2013-04-27 09:55:12 +04:00
|
|
|
}
|
2010-01-30 22:48:12 +03:00
|
|
|
} else {
|
2013-04-27 09:55:12 +04:00
|
|
|
s->pci_irq_in &= ~(1ULL << irq_num);
|
2010-01-30 22:48:12 +03:00
|
|
|
}
|
|
|
|
}
|
2006-05-13 20:11:23 +04:00
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_reset(DeviceState *d)
|
2009-07-21 12:36:37 +04:00
|
|
|
{
|
2020-09-03 01:42:56 +03:00
|
|
|
SabreState *s = SABRE(d);
|
2017-12-21 10:32:57 +03:00
|
|
|
PCIDevice *pci_dev;
|
|
|
|
unsigned int i;
|
|
|
|
uint16_t cmd;
|
2009-07-21 12:36:37 +04:00
|
|
|
|
2010-01-30 22:48:12 +03:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
s->pci_irq_map[i] &= PBM_PCI_IMR_MASK;
|
|
|
|
}
|
2012-05-12 13:15:22 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
s->obio_irq_map[i] &= PBM_PCI_IMR_MASK;
|
|
|
|
}
|
2010-01-30 22:48:12 +03:00
|
|
|
|
2013-04-27 09:55:12 +04:00
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
s->pci_irq_in = 0ULL;
|
|
|
|
|
2010-05-12 23:27:23 +04:00
|
|
|
if (s->nr_resets++ == 0) {
|
2010-01-30 22:48:12 +03:00
|
|
|
/* Power on reset */
|
|
|
|
s->reset_control = POR;
|
|
|
|
}
|
2017-12-21 10:32:57 +03: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 22:48:12 +03:00
|
|
|
}
|
|
|
|
|
2011-08-15 18:17:15 +04:00
|
|
|
static const MemoryRegionOps pci_config_ops = {
|
2018-01-21 11:59:45 +03:00
|
|
|
.read = sabre_pci_config_read,
|
|
|
|
.write = sabre_pci_config_write,
|
2017-09-04 20:41:01 +03:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2011-08-15 18:17:15 +04:00
|
|
|
};
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_realize(DeviceState *dev, Error **errp)
|
2010-01-30 22:48:12 +03:00
|
|
|
{
|
2020-09-03 01:42:56 +03:00
|
|
|
SabreState *s = SABRE(dev);
|
2017-12-21 10:32:57 +03:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(dev);
|
2010-07-13 08:01:42 +04:00
|
|
|
PCIDevice *pci_dev;
|
2006-05-13 20:11:23 +04:00
|
|
|
|
2017-12-21 10:32:57 +03: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 23:01:17 +03:00
|
|
|
phb->bus = pci_register_root_bus(dev, "pci",
|
2018-01-21 11:59:45 +03:00
|
|
|
pci_sabre_set_irq, pci_sabre_map_irq, s,
|
2018-01-11 23:01:17 +03:00
|
|
|
&s->pci_mmio,
|
|
|
|
&s->pci_ioport,
|
2020-10-11 11:13:47 +03:00
|
|
|
0, 0x40, TYPE_PCI_BUS);
|
2011-09-03 20:38:02 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
pci_create_simple(phb->bus, 0, TYPE_SABRE_PCI_DEVICE);
|
2010-05-25 16:09:03 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
/* IOMMU */
|
2018-01-21 11:59:45 +03:00
|
|
|
memory_region_add_subregion_overlap(&s->sabre_config, 0x200,
|
2018-01-08 21:16:34 +03:00
|
|
|
sysbus_mmio_get_region(SYS_BUS_DEVICE(s->iommu), 0), 1);
|
2018-01-21 11:59:45 +03:00
|
|
|
pci_setup_iommu(phb->bus, sabre_pci_dma_iommu, s->iommu);
|
2014-05-28 11:28:22 +04:00
|
|
|
|
2009-07-21 12:36:37 +04:00
|
|
|
/* APB secondary busses */
|
pci: Convert uses of pci_create() etc. with Coccinelle
Replace
dev = pci_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = pci_new(type_name);
...
pci_realize_and_unref(dev, bus, &error_fatal);
and similarly for pci_create_multifunction().
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(pci_create(bus, args));
+ PCIDevice *pci_dev; // TODO move
+ pci_dev = pci_new(args);
+ dev = DEVICE(pci_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ pci_realize_and_unref(pci_dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, expr;
expression list args;
identifier dev;
@@
- PCIDevice *dev = pci_create_multifunction(bus, args);
+ PCIDevice *dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually, @pci_dev declarations moved manually.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-16-armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
2020-06-10 08:32:04 +03:00
|
|
|
pci_dev = pci_new_multifunction(PCI_DEVFN(1, 0), true,
|
|
|
|
TYPE_SIMBA_PCI_BRIDGE);
|
2017-12-21 10:32:57 +03:00
|
|
|
s->bridgeB = PCI_BRIDGE(pci_dev);
|
2018-01-21 11:59:45 +03:00
|
|
|
pci_bridge_map_irq(s->bridgeB, "pciB", pci_simbaB_map_irq);
|
pci: Convert uses of pci_create() etc. with Coccinelle
Replace
dev = pci_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = pci_new(type_name);
...
pci_realize_and_unref(dev, bus, &error_fatal);
and similarly for pci_create_multifunction().
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(pci_create(bus, args));
+ PCIDevice *pci_dev; // TODO move
+ pci_dev = pci_new(args);
+ dev = DEVICE(pci_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ pci_realize_and_unref(pci_dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, expr;
expression list args;
identifier dev;
@@
- PCIDevice *dev = pci_create_multifunction(bus, args);
+ PCIDevice *dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually, @pci_dev declarations moved manually.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-16-armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
2020-06-10 08:32:04 +03:00
|
|
|
pci_realize_and_unref(pci_dev, phb->bus, &error_fatal);
|
2010-07-13 08:01:42 +04:00
|
|
|
|
pci: Convert uses of pci_create() etc. with Coccinelle
Replace
dev = pci_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = pci_new(type_name);
...
pci_realize_and_unref(dev, bus, &error_fatal);
and similarly for pci_create_multifunction().
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(pci_create(bus, args));
+ PCIDevice *pci_dev; // TODO move
+ pci_dev = pci_new(args);
+ dev = DEVICE(pci_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ pci_realize_and_unref(pci_dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, expr;
expression list args;
identifier dev;
@@
- PCIDevice *dev = pci_create_multifunction(bus, args);
+ PCIDevice *dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually, @pci_dev declarations moved manually.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-16-armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
2020-06-10 08:32:04 +03:00
|
|
|
pci_dev = pci_new_multifunction(PCI_DEVFN(1, 1), true,
|
|
|
|
TYPE_SIMBA_PCI_BRIDGE);
|
2017-12-21 10:32:57 +03:00
|
|
|
s->bridgeA = PCI_BRIDGE(pci_dev);
|
2018-01-21 11:59:45 +03:00
|
|
|
pci_bridge_map_irq(s->bridgeA, "pciA", pci_simbaA_map_irq);
|
pci: Convert uses of pci_create() etc. with Coccinelle
Replace
dev = pci_create(bus, type_name);
...
qdev_init_nofail(dev);
by
dev = pci_new(type_name);
...
pci_realize_and_unref(dev, bus, &error_fatal);
and similarly for pci_create_multifunction().
Recent commit "qdev: New qdev_new(), qdev_realize(), etc." explains
why.
Coccinelle script:
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
expression d;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
(
d = &dev->qdev;
|
d = DEVICE(dev);
)
... when != dev = expr
- qdev_init_nofail(d);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create(bus, args);
+ dev = pci_new(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = DEVICE(pci_create(bus, args));
+ PCIDevice *pci_dev; // TODO move
+ pci_dev = pci_new(args);
+ dev = DEVICE(pci_dev);
... when != dev = expr
- qdev_init_nofail(dev);
+ pci_realize_and_unref(pci_dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression bus, expr;
expression list args;
identifier dev;
@@
- PCIDevice *dev = pci_create_multifunction(bus, args);
+ PCIDevice *dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(&dev->qdev);
+ pci_realize_and_unref(dev, bus, &error_fatal);
@@
expression dev, bus, expr;
expression list args;
@@
- dev = pci_create_multifunction(bus, args);
+ dev = pci_new_multifunction(args);
... when != dev = expr
- qdev_init_nofail(DEVICE(dev));
+ pci_realize_and_unref(dev, bus, &error_fatal);
Missing #include "qapi/error.h" added manually, whitespace changes
minimized manually, @pci_dev declarations moved manually.
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200610053247.1583243-16-armbru@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
2020-06-10 08:32:04 +03:00
|
|
|
pci_realize_and_unref(pci_dev, phb->bus, &error_fatal);
|
2010-01-30 22:48:12 +03:00
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_init(Object *obj)
|
2010-01-30 22:48:12 +03:00
|
|
|
{
|
2020-09-03 01:42:56 +03:00
|
|
|
SabreState *s = SABRE(obj);
|
2017-12-21 10:32:57 +03:00
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
|
2010-01-30 22:48:12 +03:00
|
|
|
unsigned int i;
|
2009-07-21 12:36:37 +04:00
|
|
|
|
2010-01-30 22:48:12 +03:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
s->pci_irq_map[i] = (0x1f << 6) | (i << 2);
|
|
|
|
}
|
2014-09-05 17:50:56 +04:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
s->pci_err_irq_map[i] = (0x1f << 6) | 0x30;
|
|
|
|
}
|
2012-05-12 13:15:22 +04:00
|
|
|
for (i = 0; i < 32; i++) {
|
|
|
|
s->obio_irq_map[i] = ((0x1f << 6) | 0x20) + i;
|
|
|
|
}
|
2018-01-21 11:59:45 +03:00
|
|
|
qdev_init_gpio_in_named(DEVICE(s), pci_sabre_set_irq, "pbm-irq", MAX_IVEC);
|
2017-12-21 10:32:57 +03:00
|
|
|
qdev_init_gpio_out_named(DEVICE(s), s->ivec_irqs, "ivec-irq", MAX_IVEC);
|
2013-04-27 09:55:12 +04:00
|
|
|
s->irq_request = NO_IRQ_REQUEST;
|
|
|
|
s->pci_irq_in = 0ULL;
|
2010-01-30 22:48:12 +03:00
|
|
|
|
2018-01-08 21:16:34 +03:00
|
|
|
/* IOMMU */
|
|
|
|
object_property_add_link(obj, "iommu", TYPE_SUN4U_IOMMU,
|
|
|
|
(Object **) &s->iommu,
|
|
|
|
qdev_prop_allow_set_link_before_realize,
|
qom: Drop parameter @errp of object_property_add() & friends
The only way object_property_add() can fail is when a property with
the same name already exists. Since our property names are all
hardcoded, failure is a programming error, and the appropriate way to
handle it is passing &error_abort.
Same for its variants, except for object_property_add_child(), which
additionally fails when the child already has a parent. Parentage is
also under program control, so this is a programming error, too.
We have a bit over 500 callers. Almost half of them pass
&error_abort, slightly fewer ignore errors, one test case handles
errors, and the remaining few callers pass them to their own callers.
The previous few commits demonstrated once again that ignoring
programming errors is a bad idea.
Of the few ones that pass on errors, several violate the Error API.
The Error ** argument must be NULL, &error_abort, &error_fatal, or a
pointer to a variable containing NULL. Passing an argument of the
latter kind twice without clearing it in between is wrong: if the
first call sets an error, it no longer points to NULL for the second
call. ich9_pm_add_properties(), sparc32_ledma_realize(),
sparc32_dma_realize(), xilinx_axidma_realize(), xilinx_enet_realize()
are wrong that way.
When the one appropriate choice of argument is &error_abort, letting
users pick the argument is a bad idea.
Drop parameter @errp and assert the preconditions instead.
There's one exception to "duplicate property name is a programming
error": the way object_property_add() implements the magic (and
undocumented) "automatic arrayification". Don't drop @errp there.
Instead, rename object_property_add() to object_property_try_add(),
and add the obvious wrapper object_property_add().
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-Id: <20200505152926.18877-15-armbru@redhat.com>
[Two semantic rebase conflicts resolved]
2020-05-05 18:29:22 +03:00
|
|
|
0);
|
2018-01-08 21:16:34 +03:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
/* sabre_config */
|
|
|
|
memory_region_init_io(&s->sabre_config, OBJECT(s), &sabre_config_ops, s,
|
|
|
|
"sabre-config", 0x10000);
|
2010-05-25 16:09:03 +04:00
|
|
|
/* at region 0 */
|
2018-01-21 11:59:45 +03:00
|
|
|
sysbus_init_mmio(sbd, &s->sabre_config);
|
2010-05-25 16:09:03 +04:00
|
|
|
|
2013-06-07 05:25:08 +04:00
|
|
|
memory_region_init_io(&s->pci_config, OBJECT(s), &pci_config_ops, s,
|
2018-01-21 11:59:45 +03:00
|
|
|
"sabre-pci-config", 0x1000000);
|
2010-05-25 16:09:03 +04:00
|
|
|
/* at region 1 */
|
2017-12-21 10:32:57 +03:00
|
|
|
sysbus_init_mmio(sbd, &s->pci_config);
|
2010-05-25 16:09:03 +04:00
|
|
|
|
|
|
|
/* pci_ioport */
|
2018-01-21 11:59:45 +03:00
|
|
|
memory_region_init(&s->pci_ioport, OBJECT(s), "sabre-pci-ioport",
|
|
|
|
0x1000000);
|
2017-06-11 12:12:08 +03:00
|
|
|
|
2010-05-25 16:09:03 +04:00
|
|
|
/* at region 2 */
|
2017-12-21 10:32:57 +03:00
|
|
|
sysbus_init_mmio(sbd, &s->pci_ioport);
|
2009-07-21 12:36:37 +04:00
|
|
|
}
|
2006-05-13 20:11:23 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_pci_realize(PCIDevice *d, Error **errp)
|
2009-07-21 12:36:37 +04:00
|
|
|
{
|
2010-02-14 11:27:19 +03: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 12:36:37 +04:00
|
|
|
}
|
2006-09-24 21:01:44 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_pci_class_init(ObjectClass *klass, void *data)
|
2011-12-04 22:22:06 +04: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 20:26:58 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 22:22:06 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
k->realize = sabre_pci_realize;
|
2011-12-04 22:22:06 +04: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 20:26:58 +04: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 23:35:44 +03:00
|
|
|
dc->user_creatable = false;
|
2011-12-04 22:22:06 +04:00
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static const TypeInfo sabre_pci_info = {
|
2018-01-21 11:59:45 +03:00
|
|
|
.name = TYPE_SABRE_PCI_DEVICE,
|
2011-12-08 07:34:16 +04:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
2018-01-21 11:59:45 +03:00
|
|
|
.instance_size = sizeof(SabrePCIState),
|
2018-01-21 11:59:45 +03:00
|
|
|
.class_init = sabre_pci_class_init,
|
2017-09-27 22:56:34 +03:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2009-07-21 12:36:37 +04:00
|
|
|
};
|
|
|
|
|
2018-08-29 19:33:45 +03:00
|
|
|
static char *sabre_ofw_unit_address(const SysBusDevice *dev)
|
|
|
|
{
|
2020-09-03 01:42:56 +03:00
|
|
|
SabreState *s = SABRE(dev);
|
2018-08-29 19:33:45 +03:00
|
|
|
|
|
|
|
return g_strdup_printf("%x,%x",
|
|
|
|
(uint32_t)((s->special_base >> 32) & 0xffffffff),
|
|
|
|
(uint32_t)(s->special_base & 0xffffffff));
|
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static Property sabre_properties[] = {
|
2018-01-21 11:59:45 +03:00
|
|
|
DEFINE_PROP_UINT64("special-base", SabreState, special_base, 0),
|
|
|
|
DEFINE_PROP_UINT64("mem-base", SabreState, mem_base, 0),
|
2017-12-21 10:32:57 +03:00
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_class_init(ObjectClass *klass, void *data)
|
2012-01-24 23:12:29 +04:00
|
|
|
{
|
2011-12-08 07:34:16 +04:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2018-08-29 19:33:45 +03:00
|
|
|
SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass);
|
2012-01-24 23:12:29 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
dc->realize = sabre_realize;
|
|
|
|
dc->reset = sabre_reset;
|
2020-01-10 18:30:32 +03:00
|
|
|
device_class_set_props(dc, sabre_properties);
|
2017-12-21 10:32:57 +03:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2018-08-29 19:33:45 +03:00
|
|
|
dc->fw_name = "pci";
|
|
|
|
sbc->explicit_ofw_unit_address = sabre_ofw_unit_address;
|
2012-01-24 23:12:29 +04:00
|
|
|
}
|
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static const TypeInfo sabre_info = {
|
2018-01-21 11:59:45 +03:00
|
|
|
.name = TYPE_SABRE,
|
2013-07-22 17:54:30 +04:00
|
|
|
.parent = TYPE_PCI_HOST_BRIDGE,
|
2018-01-21 11:59:45 +03:00
|
|
|
.instance_size = sizeof(SabreState),
|
2018-01-21 11:59:45 +03:00
|
|
|
.instance_init = sabre_init,
|
|
|
|
.class_init = sabre_class_init,
|
2010-01-30 22:48:12 +03:00
|
|
|
};
|
2010-07-13 08:01:42 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
static void sabre_register_types(void)
|
2009-07-21 12:36:37 +04:00
|
|
|
{
|
2018-01-21 11:59:45 +03:00
|
|
|
type_register_static(&sabre_info);
|
2018-01-21 11:59:45 +03:00
|
|
|
type_register_static(&sabre_pci_info);
|
2006-05-13 20:11:23 +04:00
|
|
|
}
|
2009-07-21 12:36:37 +04:00
|
|
|
|
2018-01-21 11:59:45 +03:00
|
|
|
type_init(sabre_register_types)
|