cannot_instantiate_with_device_add_yet was introduced by commit
efec3dd631d94160288392721a5f9c39e50fb2bc to replace no_user. It was
supposed to be a temporary measure.
When it was introduced, we had 54
cannot_instantiate_with_device_add_yet=true lines in the code.
Today (3 years later) this number has not shrunk: we now have
57 cannot_instantiate_with_device_add_yet=true lines. I think it
is safe to say it is not a temporary measure, and we won't see
the flag go away soon.
Instead of a long field name that misleads people to believe it
is temporary, replace it a shorter and less misleading field:
user_creatable.
Except for code comments, changes were generated using the
following Coccinelle patch:
  @@
  expression DC;
  @@
  (
  -DC->cannot_instantiate_with_device_add_yet = false;
  +DC->user_creatable = true;
  |
  -DC->cannot_instantiate_with_device_add_yet = true;
  +DC->user_creatable = false;
  )
  @@
  typedef ObjectClass;
  expression dc;
  identifier class, data;
  @@
   static void device_class_init(ObjectClass *class, void *data)
   {
   ...
   dc->hotpluggable = true;
  +dc->user_creatable = true;
   ...
   }
  @@
  @@
   struct DeviceClass {
   ...
  -bool cannot_instantiate_with_device_add_yet;
  +bool user_creatable;
   ...
  }
  @@
  expression DC;
  @@
  (
  -!DC->cannot_instantiate_with_device_add_yet
  +DC->user_creatable
  |
  -DC->cannot_instantiate_with_device_add_yet
  +!DC->user_creatable
  )
Cc: Alistair Francis <alistair.francis@xilinx.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Marcel Apfelbaum <marcel@redhat.com>
Cc: Markus Armbruster <armbru@redhat.com>
Cc: Peter Maydell <peter.maydell@linaro.org>
Cc: Thomas Huth <thuth@redhat.com>
Acked-by: Alistair Francis <alistair.francis@xilinx.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Marcel Apfelbaum <marcel@redhat.com>
Acked-by: Marcel Apfelbaum <marcel@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Message-Id: <20170503203604.31462-2-ehabkost@redhat.com>
[ehabkost: kept "TODO remove once we're there" comment]
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
		
	
			
		
			
				
	
	
		
			156 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			156 lines
		
	
	
		
			5.0 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/*
 | 
						|
 * QEMU Generic PCI Express Bridge Emulation
 | 
						|
 *
 | 
						|
 * Copyright (C) 2015 Alexander Graf <agraf@suse.de>
 | 
						|
 *
 | 
						|
 * Code loosely based on q35.c.
 | 
						|
 *
 | 
						|
 * 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.
 | 
						|
 *
 | 
						|
 * Check out these documents for more information on the device:
 | 
						|
 *
 | 
						|
 * http://www.kernel.org/doc/Documentation/devicetree/bindings/pci/host-generic-pci.txt
 | 
						|
 * http://www.firmware.org/1275/practice/imap/imap0_9d.pdf
 | 
						|
 */
 | 
						|
#include "qemu/osdep.h"
 | 
						|
#include "hw/hw.h"
 | 
						|
#include "hw/pci-host/gpex.h"
 | 
						|
 | 
						|
/****************************************************************************
 | 
						|
 * GPEX host
 | 
						|
 */
 | 
						|
 | 
						|
static void gpex_set_irq(void *opaque, int irq_num, int level)
 | 
						|
{
 | 
						|
    GPEXHost *s = opaque;
 | 
						|
 | 
						|
    qemu_set_irq(s->irq[irq_num], level);
 | 
						|
}
 | 
						|
 | 
						|
static void gpex_host_realize(DeviceState *dev, Error **errp)
 | 
						|
{
 | 
						|
    PCIHostState *pci = PCI_HOST_BRIDGE(dev);
 | 
						|
    GPEXHost *s = GPEX_HOST(dev);
 | 
						|
    SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
 | 
						|
    PCIExpressHost *pex = PCIE_HOST_BRIDGE(dev);
 | 
						|
    int i;
 | 
						|
 | 
						|
    pcie_host_mmcfg_init(pex, PCIE_MMCFG_SIZE_MAX);
 | 
						|
    memory_region_init(&s->io_mmio, OBJECT(s), "gpex_mmio", UINT64_MAX);
 | 
						|
    memory_region_init(&s->io_ioport, OBJECT(s), "gpex_ioport", 64 * 1024);
 | 
						|
 | 
						|
    sysbus_init_mmio(sbd, &pex->mmio);
 | 
						|
    sysbus_init_mmio(sbd, &s->io_mmio);
 | 
						|
    sysbus_init_mmio(sbd, &s->io_ioport);
 | 
						|
    for (i = 0; i < GPEX_NUM_IRQS; i++) {
 | 
						|
        sysbus_init_irq(sbd, &s->irq[i]);
 | 
						|
    }
 | 
						|
 | 
						|
    pci->bus = pci_register_bus(dev, "pcie.0", gpex_set_irq,
 | 
						|
                                pci_swizzle_map_irq_fn, s, &s->io_mmio,
 | 
						|
                                &s->io_ioport, 0, 4, TYPE_PCIE_BUS);
 | 
						|
 | 
						|
    qdev_set_parent_bus(DEVICE(&s->gpex_root), BUS(pci->bus));
 | 
						|
    qdev_init_nofail(DEVICE(&s->gpex_root));
 | 
						|
}
 | 
						|
 | 
						|
static const char *gpex_host_root_bus_path(PCIHostState *host_bridge,
 | 
						|
                                          PCIBus *rootbus)
 | 
						|
{
 | 
						|
    return "0000:00";
 | 
						|
}
 | 
						|
 | 
						|
static void gpex_host_class_init(ObjectClass *klass, void *data)
 | 
						|
{
 | 
						|
    DeviceClass *dc = DEVICE_CLASS(klass);
 | 
						|
    PCIHostBridgeClass *hc = PCI_HOST_BRIDGE_CLASS(klass);
 | 
						|
 | 
						|
    hc->root_bus_path = gpex_host_root_bus_path;
 | 
						|
    dc->realize = gpex_host_realize;
 | 
						|
    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 | 
						|
    dc->fw_name = "pci";
 | 
						|
}
 | 
						|
 | 
						|
static void gpex_host_initfn(Object *obj)
 | 
						|
{
 | 
						|
    GPEXHost *s = GPEX_HOST(obj);
 | 
						|
    GPEXRootState *root = &s->gpex_root;
 | 
						|
 | 
						|
    object_initialize(root, sizeof(*root), TYPE_GPEX_ROOT_DEVICE);
 | 
						|
    object_property_add_child(obj, "gpex_root", OBJECT(root), NULL);
 | 
						|
    qdev_prop_set_uint32(DEVICE(root), "addr", PCI_DEVFN(0, 0));
 | 
						|
    qdev_prop_set_bit(DEVICE(root), "multifunction", false);
 | 
						|
}
 | 
						|
 | 
						|
static const TypeInfo gpex_host_info = {
 | 
						|
    .name       = TYPE_GPEX_HOST,
 | 
						|
    .parent     = TYPE_PCIE_HOST_BRIDGE,
 | 
						|
    .instance_size = sizeof(GPEXHost),
 | 
						|
    .instance_init = gpex_host_initfn,
 | 
						|
    .class_init = gpex_host_class_init,
 | 
						|
};
 | 
						|
 | 
						|
/****************************************************************************
 | 
						|
 * GPEX Root D0:F0
 | 
						|
 */
 | 
						|
 | 
						|
static const VMStateDescription vmstate_gpex_root = {
 | 
						|
    .name = "gpex_root",
 | 
						|
    .version_id = 1,
 | 
						|
    .minimum_version_id = 1,
 | 
						|
    .fields = (VMStateField[]) {
 | 
						|
        VMSTATE_PCI_DEVICE(parent_obj, GPEXRootState),
 | 
						|
        VMSTATE_END_OF_LIST()
 | 
						|
    }
 | 
						|
};
 | 
						|
 | 
						|
static void gpex_root_class_init(ObjectClass *klass, void *data)
 | 
						|
{
 | 
						|
    PCIDeviceClass *k = PCI_DEVICE_CLASS(klass);
 | 
						|
    DeviceClass *dc = DEVICE_CLASS(klass);
 | 
						|
 | 
						|
    set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories);
 | 
						|
    dc->desc = "QEMU generic PCIe host bridge";
 | 
						|
    dc->vmsd = &vmstate_gpex_root;
 | 
						|
    k->vendor_id = PCI_VENDOR_ID_REDHAT;
 | 
						|
    k->device_id = PCI_DEVICE_ID_REDHAT_PCIE_HOST;
 | 
						|
    k->revision = 0;
 | 
						|
    k->class_id = PCI_CLASS_BRIDGE_HOST;
 | 
						|
    /*
 | 
						|
     * PCI-facing part of the host bridge, not usable without the
 | 
						|
     * host-facing part, which can't be device_add'ed, yet.
 | 
						|
     */
 | 
						|
    dc->user_creatable = false;
 | 
						|
}
 | 
						|
 | 
						|
static const TypeInfo gpex_root_info = {
 | 
						|
    .name = TYPE_GPEX_ROOT_DEVICE,
 | 
						|
    .parent = TYPE_PCI_DEVICE,
 | 
						|
    .instance_size = sizeof(GPEXRootState),
 | 
						|
    .class_init = gpex_root_class_init,
 | 
						|
};
 | 
						|
 | 
						|
static void gpex_register(void)
 | 
						|
{
 | 
						|
    type_register_static(&gpex_root_info);
 | 
						|
    type_register_static(&gpex_host_info);
 | 
						|
}
 | 
						|
 | 
						|
type_init(gpex_register)
 |