2006-05-13 18:11:23 +02:00
|
|
|
/*
|
|
|
|
* QEMU PREP PCI host
|
|
|
|
*
|
|
|
|
* Copyright (c) 2006 Fabrice Bellard
|
2012-05-26 19:14:52 +02:00
|
|
|
* Copyright (c) 2011-2013 Andreas Färber
|
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.
|
|
|
|
*/
|
|
|
|
|
2016-01-26 19:16:58 +01:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 09:01:28 +01:00
|
|
|
#include "qapi/error.h"
|
2013-02-04 15:40:22 +01:00
|
|
|
#include "hw/hw.h"
|
|
|
|
#include "hw/pci/pci.h"
|
|
|
|
#include "hw/pci/pci_bus.h"
|
|
|
|
#include "hw/pci/pci_host.h"
|
2013-02-05 17:06:20 +01:00
|
|
|
#include "hw/i386/pc.h"
|
2013-11-05 00:09:45 +01:00
|
|
|
#include "hw/loader.h"
|
2012-12-17 18:19:49 +01:00
|
|
|
#include "exec/address-spaces.h"
|
2013-11-05 00:09:45 +01:00
|
|
|
#include "elf.h"
|
2006-05-13 18:11:23 +02:00
|
|
|
|
2012-05-26 19:14:52 +02:00
|
|
|
#define TYPE_RAVEN_PCI_DEVICE "raven"
|
2012-08-20 19:08:04 +02:00
|
|
|
#define TYPE_RAVEN_PCI_HOST_BRIDGE "raven-pcihost"
|
|
|
|
|
2012-05-26 19:14:52 +02:00
|
|
|
#define RAVEN_PCI_DEVICE(obj) \
|
|
|
|
OBJECT_CHECK(RavenPCIState, (obj), TYPE_RAVEN_PCI_DEVICE)
|
|
|
|
|
|
|
|
typedef struct RavenPCIState {
|
|
|
|
PCIDevice dev;
|
2013-11-05 00:09:45 +01:00
|
|
|
|
|
|
|
uint32_t elf_machine;
|
|
|
|
char *bios_name;
|
|
|
|
MemoryRegion bios;
|
2012-05-26 19:14:52 +02:00
|
|
|
} RavenPCIState;
|
|
|
|
|
2012-08-20 19:08:04 +02:00
|
|
|
#define RAVEN_PCI_HOST_BRIDGE(obj) \
|
|
|
|
OBJECT_CHECK(PREPPCIState, (obj), TYPE_RAVEN_PCI_HOST_BRIDGE)
|
|
|
|
|
2012-01-03 02:42:46 +01:00
|
|
|
typedef struct PRePPCIState {
|
2012-08-20 19:08:09 +02:00
|
|
|
PCIHostState parent_obj;
|
2012-08-20 19:08:04 +02:00
|
|
|
|
2013-11-05 00:09:44 +01:00
|
|
|
qemu_irq irq[PCI_NUM_PINS];
|
2012-05-26 19:14:52 +02:00
|
|
|
PCIBus pci_bus;
|
2014-03-17 23:00:20 +01:00
|
|
|
AddressSpace pci_io_as;
|
2014-03-17 23:00:21 +01:00
|
|
|
MemoryRegion pci_io;
|
2014-03-17 23:00:20 +01:00
|
|
|
MemoryRegion pci_io_non_contiguous;
|
2014-03-17 23:00:22 +01:00
|
|
|
MemoryRegion pci_memory;
|
2014-03-17 23:00:19 +01:00
|
|
|
MemoryRegion pci_intack;
|
2014-03-17 23:00:23 +01:00
|
|
|
MemoryRegion bm;
|
|
|
|
MemoryRegion bm_ram_alias;
|
|
|
|
MemoryRegion bm_pci_memory_alias;
|
|
|
|
AddressSpace bm_as;
|
2012-05-26 19:14:52 +02:00
|
|
|
RavenPCIState pci_dev;
|
2014-03-17 23:00:20 +01:00
|
|
|
|
|
|
|
int contiguous_map;
|
2012-01-03 02:42:46 +01:00
|
|
|
} PREPPCIState;
|
2006-05-13 18:11:23 +02:00
|
|
|
|
2013-11-05 00:09:45 +01:00
|
|
|
#define BIOS_SIZE (1024 * 1024)
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
static inline uint32_t raven_pci_io_config(hwaddr addr)
|
2006-05-13 18:11:23 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2012-08-20 19:08:04 +02:00
|
|
|
for (i = 0; i < 11; i++) {
|
|
|
|
if ((addr & (1 << (11 + i))) != 0) {
|
2006-05-13 18:11:23 +02:00
|
|
|
break;
|
2012-08-20 19:08:04 +02:00
|
|
|
}
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
|
|
|
return (addr & 0x7ff) | (i << 11);
|
|
|
|
}
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
static void raven_pci_io_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned int size)
|
2006-05-13 18:11:23 +02:00
|
|
|
{
|
|
|
|
PREPPCIState *s = opaque;
|
2012-08-20 19:08:09 +02:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2014-03-17 23:00:25 +01:00
|
|
|
pci_data_write(phb->bus, raven_pci_io_config(addr), val, size);
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
static uint64_t raven_pci_io_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned int size)
|
2006-05-13 18:11:23 +02:00
|
|
|
{
|
|
|
|
PREPPCIState *s = opaque;
|
2012-08-20 19:08:09 +02:00
|
|
|
PCIHostState *phb = PCI_HOST_BRIDGE(s);
|
2014-03-17 23:00:25 +01:00
|
|
|
return pci_data_read(phb->bus, raven_pci_io_config(addr), size);
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
static const MemoryRegionOps raven_pci_io_ops = {
|
|
|
|
.read = raven_pci_io_read,
|
|
|
|
.write = raven_pci_io_write,
|
2012-01-12 03:44:42 +01:00
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
2006-05-13 18:11:23 +02:00
|
|
|
};
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
static uint64_t raven_intack_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned int size)
|
2012-04-14 22:48:37 +02:00
|
|
|
{
|
|
|
|
return pic_read_irq(isa_pic);
|
|
|
|
}
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
static const MemoryRegionOps raven_intack_ops = {
|
|
|
|
.read = raven_intack_read,
|
2012-04-14 22:48:37 +02:00
|
|
|
.valid = {
|
|
|
|
.max_access_size = 1,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2014-03-17 23:00:20 +01:00
|
|
|
static inline hwaddr raven_io_address(PREPPCIState *s,
|
|
|
|
hwaddr addr)
|
|
|
|
{
|
|
|
|
if (s->contiguous_map == 0) {
|
|
|
|
/* 64 KB contiguous space for IOs */
|
|
|
|
addr &= 0xFFFF;
|
|
|
|
} else {
|
|
|
|
/* 8 MB non-contiguous space for IOs */
|
|
|
|
addr = (addr & 0x1F) | ((addr & 0x007FFF000) >> 7);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: handle endianness switch */
|
|
|
|
|
|
|
|
return addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t raven_io_read(void *opaque, hwaddr addr,
|
|
|
|
unsigned int size)
|
|
|
|
{
|
|
|
|
PREPPCIState *s = opaque;
|
|
|
|
uint8_t buf[4];
|
|
|
|
|
|
|
|
addr = raven_io_address(s, addr);
|
2015-04-26 17:49:24 +02:00
|
|
|
address_space_read(&s->pci_io_as, addr + 0x80000000,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, buf, size);
|
2014-03-17 23:00:20 +01:00
|
|
|
|
|
|
|
if (size == 1) {
|
|
|
|
return buf[0];
|
|
|
|
} else if (size == 2) {
|
2014-04-08 17:51:11 +02:00
|
|
|
return lduw_le_p(buf);
|
2014-03-17 23:00:20 +01:00
|
|
|
} else if (size == 4) {
|
2014-04-08 17:51:11 +02:00
|
|
|
return ldl_le_p(buf);
|
2014-03-17 23:00:20 +01:00
|
|
|
} else {
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void raven_io_write(void *opaque, hwaddr addr,
|
|
|
|
uint64_t val, unsigned int size)
|
|
|
|
{
|
|
|
|
PREPPCIState *s = opaque;
|
|
|
|
uint8_t buf[4];
|
|
|
|
|
|
|
|
addr = raven_io_address(s, addr);
|
|
|
|
|
|
|
|
if (size == 1) {
|
|
|
|
buf[0] = val;
|
|
|
|
} else if (size == 2) {
|
2014-04-08 17:51:11 +02:00
|
|
|
stw_le_p(buf, val);
|
2014-03-17 23:00:20 +01:00
|
|
|
} else if (size == 4) {
|
2014-04-08 17:51:11 +02:00
|
|
|
stl_le_p(buf, val);
|
2014-03-17 23:00:20 +01:00
|
|
|
} else {
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
|
|
|
|
2015-04-26 17:49:24 +02:00
|
|
|
address_space_write(&s->pci_io_as, addr + 0x80000000,
|
|
|
|
MEMTXATTRS_UNSPECIFIED, buf, size);
|
2014-03-17 23:00:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps raven_io_ops = {
|
|
|
|
.read = raven_io_read,
|
|
|
|
.write = raven_io_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
.impl.max_access_size = 4,
|
|
|
|
.valid.unaligned = true,
|
|
|
|
};
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
static int raven_map_irq(PCIDevice *pci_dev, int irq_num)
|
2006-05-13 18:11:23 +02:00
|
|
|
{
|
2006-09-24 19:01:44 +02:00
|
|
|
return (irq_num + (pci_dev->devfn >> 3)) & 1;
|
2006-09-24 02:16:34 +02:00
|
|
|
}
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
static void raven_set_irq(void *opaque, int irq_num, int level)
|
2006-09-24 02:16:34 +02:00
|
|
|
{
|
2009-08-28 15:28:17 +02:00
|
|
|
qemu_irq *pic = opaque;
|
|
|
|
|
2012-01-03 02:42:46 +01:00
|
|
|
qemu_set_irq(pic[irq_num] , level);
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
|
|
|
|
2014-03-17 23:00:23 +01:00
|
|
|
static AddressSpace *raven_pcihost_set_iommu(PCIBus *bus, void *opaque,
|
|
|
|
int devfn)
|
|
|
|
{
|
|
|
|
PREPPCIState *s = opaque;
|
|
|
|
|
|
|
|
return &s->bm_as;
|
|
|
|
}
|
|
|
|
|
2014-03-17 23:00:20 +01:00
|
|
|
static void raven_change_gpio(void *opaque, int n, int level)
|
|
|
|
{
|
|
|
|
PREPPCIState *s = opaque;
|
|
|
|
|
|
|
|
s->contiguous_map = level;
|
|
|
|
}
|
|
|
|
|
2013-01-16 15:45:34 +01:00
|
|
|
static void raven_pcihost_realizefn(DeviceState *d, Error **errp)
|
2006-05-13 18:11:23 +02:00
|
|
|
{
|
2013-01-16 15:45:34 +01:00
|
|
|
SysBusDevice *dev = SYS_BUS_DEVICE(d);
|
2012-08-20 19:08:08 +02:00
|
|
|
PCIHostState *h = PCI_HOST_BRIDGE(dev);
|
2012-08-20 19:08:04 +02:00
|
|
|
PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(dev);
|
2012-01-03 02:42:46 +01:00
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
|
|
|
int i;
|
|
|
|
|
2013-11-05 00:09:44 +01:00
|
|
|
for (i = 0; i < PCI_NUM_PINS; i++) {
|
2012-01-03 02:42:46 +01:00
|
|
|
sysbus_init_irq(dev, &s->irq[i]);
|
|
|
|
}
|
2006-05-13 18:11:23 +02:00
|
|
|
|
2014-03-17 23:00:20 +01:00
|
|
|
qdev_init_gpio_in(d, raven_change_gpio, 1);
|
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
pci_bus_irqs(&s->pci_bus, raven_set_irq, raven_map_irq, s->irq,
|
|
|
|
PCI_NUM_PINS);
|
2006-05-13 18:11:23 +02:00
|
|
|
|
2014-03-17 23:00:24 +01:00
|
|
|
memory_region_init_io(&h->conf_mem, OBJECT(h), &pci_host_conf_le_ops, s,
|
|
|
|
"pci-conf-idx", 4);
|
2014-03-17 23:00:21 +01:00
|
|
|
memory_region_add_subregion(&s->pci_io, 0xcf8, &h->conf_mem);
|
2011-07-24 16:47:18 +02:00
|
|
|
|
2014-03-17 23:00:24 +01:00
|
|
|
memory_region_init_io(&h->data_mem, OBJECT(h), &pci_host_data_le_ops, s,
|
|
|
|
"pci-conf-data", 4);
|
2014-03-17 23:00:21 +01:00
|
|
|
memory_region_add_subregion(&s->pci_io, 0xcfc, &h->data_mem);
|
2006-05-13 18:11:23 +02:00
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
memory_region_init_io(&h->mmcfg, OBJECT(s), &raven_pci_io_ops, s,
|
|
|
|
"pciio", 0x00400000);
|
2012-01-03 02:42:46 +01:00
|
|
|
memory_region_add_subregion(address_space_mem, 0x80800000, &h->mmcfg);
|
2006-05-13 18:11:23 +02:00
|
|
|
|
2014-03-17 23:00:25 +01:00
|
|
|
memory_region_init_io(&s->pci_intack, OBJECT(s), &raven_intack_ops, s,
|
2014-03-17 23:00:19 +01:00
|
|
|
"pci-intack", 1);
|
|
|
|
memory_region_add_subregion(address_space_mem, 0xbffffff0, &s->pci_intack);
|
2012-01-03 01:50:07 +01:00
|
|
|
|
2012-05-26 19:14:52 +02:00
|
|
|
/* TODO Remove once realize propagates to child devices. */
|
2016-07-14 15:43:45 +02:00
|
|
|
object_property_set_bool(OBJECT(&s->pci_bus), true, "realized", errp);
|
2013-01-16 15:45:34 +01:00
|
|
|
object_property_set_bool(OBJECT(&s->pci_dev), true, "realized", errp);
|
2012-05-26 19:14:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void raven_pcihost_initfn(Object *obj)
|
|
|
|
{
|
|
|
|
PCIHostState *h = PCI_HOST_BRIDGE(obj);
|
|
|
|
PREPPCIState *s = RAVEN_PCI_HOST_BRIDGE(obj);
|
|
|
|
MemoryRegion *address_space_mem = get_system_memory();
|
|
|
|
DeviceState *pci_dev;
|
|
|
|
|
2014-03-17 23:00:21 +01:00
|
|
|
memory_region_init(&s->pci_io, obj, "pci-io", 0x3f800000);
|
2014-03-17 23:00:20 +01:00
|
|
|
memory_region_init_io(&s->pci_io_non_contiguous, obj, &raven_io_ops, s,
|
|
|
|
"pci-io-non-contiguous", 0x00800000);
|
2014-04-01 23:19:15 +02:00
|
|
|
memory_region_init(&s->pci_memory, obj, "pci-memory", 0x3f000000);
|
2014-03-17 23:00:21 +01:00
|
|
|
address_space_init(&s->pci_io_as, &s->pci_io, "raven-io");
|
2014-03-17 23:00:20 +01:00
|
|
|
|
|
|
|
/* CPU address space */
|
2014-03-17 23:00:21 +01:00
|
|
|
memory_region_add_subregion(address_space_mem, 0x80000000, &s->pci_io);
|
2014-03-17 23:00:20 +01:00
|
|
|
memory_region_add_subregion_overlap(address_space_mem, 0x80000000,
|
|
|
|
&s->pci_io_non_contiguous, 1);
|
2014-03-17 23:00:22 +01:00
|
|
|
memory_region_add_subregion(address_space_mem, 0xc0000000, &s->pci_memory);
|
2017-11-29 09:46:22 +01:00
|
|
|
pci_root_bus_new_inplace(&s->pci_bus, sizeof(s->pci_bus), DEVICE(obj), NULL,
|
|
|
|
&s->pci_memory, &s->pci_io, 0, TYPE_PCI_BUS);
|
2014-03-17 23:00:21 +01:00
|
|
|
|
2014-03-17 23:00:23 +01:00
|
|
|
/* Bus master address space */
|
|
|
|
memory_region_init(&s->bm, obj, "bm-raven", UINT32_MAX);
|
|
|
|
memory_region_init_alias(&s->bm_pci_memory_alias, obj, "bm-pci-memory",
|
|
|
|
&s->pci_memory, 0,
|
|
|
|
memory_region_size(&s->pci_memory));
|
|
|
|
memory_region_init_alias(&s->bm_ram_alias, obj, "bm-system",
|
|
|
|
get_system_memory(), 0, 0x80000000);
|
|
|
|
memory_region_add_subregion(&s->bm, 0 , &s->bm_pci_memory_alias);
|
|
|
|
memory_region_add_subregion(&s->bm, 0x80000000, &s->bm_ram_alias);
|
|
|
|
address_space_init(&s->bm_as, &s->bm, "raven-bm");
|
|
|
|
pci_setup_iommu(&s->pci_bus, raven_pcihost_set_iommu, s);
|
|
|
|
|
2012-05-26 19:14:52 +02:00
|
|
|
h->bus = &s->pci_bus;
|
|
|
|
|
2013-08-23 19:37:12 +02:00
|
|
|
object_initialize(&s->pci_dev, sizeof(s->pci_dev), TYPE_RAVEN_PCI_DEVICE);
|
2012-05-26 19:14:52 +02:00
|
|
|
pci_dev = DEVICE(&s->pci_dev);
|
|
|
|
qdev_set_parent_bus(pci_dev, BUS(&s->pci_bus));
|
|
|
|
object_property_set_int(OBJECT(&s->pci_dev), PCI_DEVFN(0, 0), "addr",
|
|
|
|
NULL);
|
|
|
|
qdev_prop_set_bit(pci_dev, "multifunction", false);
|
2012-01-03 01:50:07 +01:00
|
|
|
}
|
|
|
|
|
2015-01-19 15:52:30 +01:00
|
|
|
static void raven_realize(PCIDevice *d, Error **errp)
|
2012-01-03 01:50:07 +01:00
|
|
|
{
|
2013-11-05 00:09:45 +01:00
|
|
|
RavenPCIState *s = RAVEN_PCI_DEVICE(d);
|
|
|
|
char *filename;
|
|
|
|
int bios_size = -1;
|
|
|
|
|
2006-05-13 18:11:23 +02:00
|
|
|
d->config[0x0C] = 0x08; // cache_line_size
|
|
|
|
d->config[0x0D] = 0x10; // latency_timer
|
|
|
|
d->config[0x34] = 0x00; // capabilities_pointer
|
|
|
|
|
2017-07-07 16:42:49 +02:00
|
|
|
memory_region_init_ram_nomigrate(&s->bios, OBJECT(s), "bios", BIOS_SIZE,
|
Fix bad error handling after memory_region_init_ram()
Symptom:
$ qemu-system-x86_64 -m 10000000
Unexpected error in ram_block_add() at /work/armbru/qemu/exec.c:1456:
upstream-qemu: cannot set up guest memory 'pc.ram': Cannot allocate memory
Aborted (core dumped)
Root cause: commit ef701d7 screwed up handling of out-of-memory
conditions. Before the commit, we report the error and exit(1), in
one place, ram_block_add(). The commit lifts the error handling up
the call chain some, to three places. Fine. Except it uses
&error_abort in these places, changing the behavior from exit(1) to
abort(), and thus undoing the work of commit 3922825 "exec: Don't
abort when we can't allocate guest memory".
The three places are:
* memory_region_init_ram()
Commit 4994653 (right after commit ef701d7) lifted the error
handling further, through memory_region_init_ram(), multiplying the
incorrect use of &error_abort. Later on, imitation of existing
(bad) code may have created more.
* memory_region_init_ram_ptr()
The &error_abort is still there.
* memory_region_init_rom_device()
Doesn't need fixing, because commit 33e0eb5 (soon after commit
ef701d7) lifted the error handling further, and in the process
changed it from &error_abort to passing it up the call chain.
Correct, because the callers are realize() methods.
Fix the error handling after memory_region_init_ram() with a
Coccinelle semantic patch:
@r@
expression mr, owner, name, size, err;
position p;
@@
memory_region_init_ram(mr, owner, name, size,
(
- &error_abort
+ &error_fatal
|
err@p
)
);
@script:python@
p << r.p;
@@
print "%s:%s:%s" % (p[0].file, p[0].line, p[0].column)
When the last argument is &error_abort, it gets replaced by
&error_fatal. This is the fix.
If the last argument is anything else, its position is reported. This
lets us check the fix is complete. Four positions get reported:
* ram_backend_memory_alloc()
Error is passed up the call chain, ultimately through
user_creatable_complete(). As far as I can tell, it's callers all
handle the error sanely.
* fsl_imx25_realize(), fsl_imx31_realize(), dp8393x_realize()
DeviceClass.realize() methods, errors handled sanely further up the
call chain.
We're good. Test case again behaves:
$ qemu-system-x86_64 -m 10000000
qemu-system-x86_64: cannot set up guest memory 'pc.ram': Cannot allocate memory
[Exit 1 ]
The next commits will repair the rest of commit ef701d7's damage.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <1441983105-26376-3-git-send-email-armbru@redhat.com>
Reviewed-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
2015-09-11 16:51:43 +02:00
|
|
|
&error_fatal);
|
2013-11-05 00:09:45 +01:00
|
|
|
memory_region_set_readonly(&s->bios, true);
|
|
|
|
memory_region_add_subregion(get_system_memory(), (uint32_t)(-BIOS_SIZE),
|
|
|
|
&s->bios);
|
|
|
|
if (s->bios_name) {
|
|
|
|
filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, s->bios_name);
|
|
|
|
if (filename) {
|
|
|
|
if (s->elf_machine != EM_NONE) {
|
|
|
|
bios_size = load_elf(filename, NULL, NULL, NULL,
|
2016-03-04 12:30:21 +01:00
|
|
|
NULL, NULL, 1, s->elf_machine, 0, 0);
|
2013-11-05 00:09:45 +01:00
|
|
|
}
|
|
|
|
if (bios_size < 0) {
|
|
|
|
bios_size = get_image_size(filename);
|
|
|
|
if (bios_size > 0 && bios_size <= BIOS_SIZE) {
|
|
|
|
hwaddr bios_addr;
|
|
|
|
bios_size = (bios_size + 0xfff) & ~0xfff;
|
|
|
|
bios_addr = (uint32_t)(-BIOS_SIZE);
|
|
|
|
bios_size = load_image_targphys(filename, bios_addr,
|
|
|
|
bios_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-02-09 12:14:41 +01:00
|
|
|
g_free(filename);
|
2013-11-05 00:09:45 +01:00
|
|
|
if (bios_size < 0 || bios_size > BIOS_SIZE) {
|
2017-02-09 12:14:41 +01:00
|
|
|
memory_region_del_subregion(get_system_memory(), &s->bios);
|
|
|
|
error_setg(errp, "Could not load bios image '%s'", s->bios_name);
|
|
|
|
return;
|
2013-11-05 00:09:45 +01:00
|
|
|
}
|
|
|
|
}
|
2017-02-09 12:14:41 +01:00
|
|
|
|
|
|
|
vmstate_register_ram_global(&s->bios);
|
2006-05-13 18:11:23 +02:00
|
|
|
}
|
2012-01-03 01:50:07 +01:00
|
|
|
|
|
|
|
static const VMStateDescription vmstate_raven = {
|
|
|
|
.name = "raven",
|
|
|
|
.version_id = 0,
|
|
|
|
.minimum_version_id = 0,
|
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_PCI_DEVICE(dev, RavenPCIState),
|
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-12-04 19:22:06 +01:00
|
|
|
static void raven_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2011-12-04 19:22:06 +01:00
|
|
|
|
2015-01-19 15:52:30 +01:00
|
|
|
k->realize = raven_realize;
|
2011-12-04 19:22:06 +01:00
|
|
|
k->vendor_id = PCI_VENDOR_ID_MOTOROLA;
|
|
|
|
k->device_id = PCI_DEVICE_ID_MOTOROLA_RAVEN;
|
|
|
|
k->revision = 0x00;
|
|
|
|
k->class_id = PCI_CLASS_BRIDGE_HOST;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->desc = "PReP Host Bridge - Motorola Raven";
|
|
|
|
dc->vmsd = &vmstate_raven;
|
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
|
|
|
/*
|
2015-12-17 17:35:13 +01:00
|
|
|
* Reason: PCI-facing part of the host bridge, not usable without
|
|
|
|
* the host-facing part, which can't be device_add'ed, yet.
|
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
|
|
|
*/
|
2017-05-03 22:35:44 +02:00
|
|
|
dc->user_creatable = false;
|
2011-12-04 19:22:06 +01:00
|
|
|
}
|
|
|
|
|
2012-08-20 19:07:56 +02:00
|
|
|
static const TypeInfo raven_info = {
|
2012-05-26 19:14:52 +02:00
|
|
|
.name = TYPE_RAVEN_PCI_DEVICE,
|
2011-12-08 04:34:16 +01:00
|
|
|
.parent = TYPE_PCI_DEVICE,
|
|
|
|
.instance_size = sizeof(RavenPCIState),
|
2011-12-04 19:22:06 +01:00
|
|
|
.class_init = raven_class_init,
|
2017-09-27 21:56:34 +02:00
|
|
|
.interfaces = (InterfaceInfo[]) {
|
|
|
|
{ INTERFACE_CONVENTIONAL_PCI_DEVICE },
|
|
|
|
{ },
|
|
|
|
},
|
2012-01-03 01:50:07 +01:00
|
|
|
};
|
|
|
|
|
2013-11-05 00:09:45 +01:00
|
|
|
static Property raven_pcihost_properties[] = {
|
|
|
|
DEFINE_PROP_UINT32("elf-machine", PREPPCIState, pci_dev.elf_machine,
|
|
|
|
EM_NONE),
|
|
|
|
DEFINE_PROP_STRING("bios-name", PREPPCIState, pci_dev.bios_name),
|
|
|
|
DEFINE_PROP_END_OF_LIST()
|
|
|
|
};
|
|
|
|
|
2012-01-24 20:12:29 +01:00
|
|
|
static void raven_pcihost_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
2012-01-24 20:12:29 +01:00
|
|
|
|
2013-07-29 16:17:45 +02:00
|
|
|
set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
|
2013-01-16 15:45:34 +01:00
|
|
|
dc->realize = raven_pcihost_realizefn;
|
2013-11-05 00:09:45 +01:00
|
|
|
dc->props = raven_pcihost_properties;
|
2011-12-08 04:34:16 +01:00
|
|
|
dc->fw_name = "pci";
|
2012-01-24 20:12:29 +01:00
|
|
|
}
|
|
|
|
|
2012-08-20 19:07:56 +02:00
|
|
|
static const TypeInfo raven_pcihost_info = {
|
2012-08-20 19:08:04 +02:00
|
|
|
.name = TYPE_RAVEN_PCI_HOST_BRIDGE,
|
2012-08-20 19:08:08 +02:00
|
|
|
.parent = TYPE_PCI_HOST_BRIDGE,
|
2011-12-08 04:34:16 +01:00
|
|
|
.instance_size = sizeof(PREPPCIState),
|
2012-05-26 19:14:52 +02:00
|
|
|
.instance_init = raven_pcihost_initfn,
|
2012-01-24 20:12:29 +01:00
|
|
|
.class_init = raven_pcihost_class_init,
|
2012-01-03 02:42:46 +01:00
|
|
|
};
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
static void raven_register_types(void)
|
2012-01-03 01:50:07 +01:00
|
|
|
{
|
2011-12-08 04:34:16 +01:00
|
|
|
type_register_static(&raven_pcihost_info);
|
|
|
|
type_register_static(&raven_info);
|
2012-01-03 01:50:07 +01:00
|
|
|
}
|
|
|
|
|
2012-02-09 15:20:55 +01:00
|
|
|
type_init(raven_register_types)
|