um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2020 Intel Corporation
|
|
|
|
* Author: Johannes Berg <johannes@sipsolutions.net>
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/logic_iomem.h>
|
2023-01-27 15:30:27 +01:00
|
|
|
#include <linux/of_platform.h>
|
2025-06-30 08:51:16 +02:00
|
|
|
#include <linux/irqchip/irq-msi-lib.h>
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
#include <linux/irqdomain.h>
|
|
|
|
#include <linux/msi.h>
|
2024-10-01 15:35:57 -04:00
|
|
|
#include <linux/unaligned.h>
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
#include <irq_kern.h>
|
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
#include "virt-pci.h"
|
|
|
|
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
#define MAX_DEVICES 8
|
|
|
|
#define MAX_MSI_VECTORS 32
|
|
|
|
#define CFG_SPACE_SIZE 4096
|
|
|
|
|
|
|
|
struct um_pci_device_reg {
|
|
|
|
struct um_pci_device *dev;
|
|
|
|
void __iomem *iomem;
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pci_host_bridge *bridge;
|
|
|
|
static DEFINE_MUTEX(um_pci_mtx);
|
2023-01-27 15:30:27 +01:00
|
|
|
static struct um_pci_device *um_pci_platform_device;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
static struct um_pci_device_reg um_pci_devices[MAX_DEVICES];
|
|
|
|
static struct fwnode_handle *um_pci_fwnode;
|
|
|
|
static struct irq_domain *um_pci_inner_domain;
|
|
|
|
static unsigned long um_pci_msi_used[BITS_TO_LONGS(MAX_MSI_VECTORS)];
|
|
|
|
|
|
|
|
static unsigned long um_pci_cfgspace_read(void *priv, unsigned int offset,
|
|
|
|
int size)
|
|
|
|
{
|
|
|
|
struct um_pci_device_reg *reg = priv;
|
|
|
|
struct um_pci_device *dev = reg->dev;
|
|
|
|
|
|
|
|
if (!dev)
|
2021-09-15 20:30:20 +02:00
|
|
|
return ULONG_MAX;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
case 8:
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
WARN(1, "invalid config space read size %d\n", size);
|
2025-01-10 13:54:04 +01:00
|
|
|
return ULONG_MAX;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
return dev->ops->cfgspace_read(dev, offset, size);
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void um_pci_cfgspace_write(void *priv, unsigned int offset, int size,
|
|
|
|
unsigned long val)
|
|
|
|
{
|
|
|
|
struct um_pci_device_reg *reg = priv;
|
|
|
|
struct um_pci_device *dev = reg->dev;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
case 8:
|
|
|
|
#endif
|
2025-03-16 00:19:09 +08:00
|
|
|
break;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
default:
|
|
|
|
WARN(1, "invalid config space write size %d\n", size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
dev->ops->cfgspace_write(dev, offset, size, val);
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct logic_iomem_ops um_pci_device_cfgspace_ops = {
|
|
|
|
.read = um_pci_cfgspace_read,
|
|
|
|
.write = um_pci_cfgspace_write,
|
|
|
|
};
|
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
static unsigned long um_pci_bar_read(void *priv, unsigned int offset,
|
|
|
|
int size)
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
{
|
|
|
|
u8 *resptr = priv;
|
|
|
|
struct um_pci_device *dev = container_of(resptr - *resptr,
|
|
|
|
struct um_pci_device,
|
|
|
|
resptr[0]);
|
2025-03-16 00:19:09 +08:00
|
|
|
u8 bar = *resptr;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
case 8:
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
2025-03-16 00:19:09 +08:00
|
|
|
WARN(1, "invalid bar read size %d\n", size);
|
2025-01-10 13:54:04 +01:00
|
|
|
return ULONG_MAX;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
return dev->ops->bar_read(dev, bar, offset, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void um_pci_bar_write(void *priv, unsigned int offset, int size,
|
|
|
|
unsigned long val)
|
|
|
|
{
|
|
|
|
u8 *resptr = priv;
|
|
|
|
struct um_pci_device *dev = container_of(resptr - *resptr,
|
|
|
|
struct um_pci_device,
|
|
|
|
resptr[0]);
|
|
|
|
u8 bar = *resptr;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
|
|
|
switch (size) {
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 4:
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
case 8:
|
|
|
|
#endif
|
2025-03-16 00:19:09 +08:00
|
|
|
break;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
default:
|
2025-03-16 00:19:09 +08:00
|
|
|
WARN(1, "invalid bar write size %d\n", size);
|
|
|
|
return;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
2025-03-16 00:19:09 +08:00
|
|
|
|
|
|
|
dev->ops->bar_write(dev, bar, offset, size, val);
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
static void um_pci_bar_copy_from(void *priv, void *buffer,
|
|
|
|
unsigned int offset, int size)
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
{
|
|
|
|
u8 *resptr = priv;
|
|
|
|
struct um_pci_device *dev = container_of(resptr - *resptr,
|
|
|
|
struct um_pci_device,
|
|
|
|
resptr[0]);
|
2025-03-16 00:19:09 +08:00
|
|
|
u8 bar = *resptr;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
dev->ops->bar_copy_from(dev, bar, buffer, offset, size);
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
static void um_pci_bar_copy_to(void *priv, unsigned int offset,
|
|
|
|
const void *buffer, int size)
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
{
|
2025-03-16 00:19:09 +08:00
|
|
|
u8 *resptr = priv;
|
|
|
|
struct um_pci_device *dev = container_of(resptr - *resptr,
|
|
|
|
struct um_pci_device,
|
|
|
|
resptr[0]);
|
|
|
|
u8 bar = *resptr;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
dev->ops->bar_copy_to(dev, bar, offset, buffer, size);
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void um_pci_bar_set(void *priv, unsigned int offset, u8 value, int size)
|
|
|
|
{
|
|
|
|
u8 *resptr = priv;
|
|
|
|
struct um_pci_device *dev = container_of(resptr - *resptr,
|
|
|
|
struct um_pci_device,
|
|
|
|
resptr[0]);
|
2025-03-16 00:19:09 +08:00
|
|
|
u8 bar = *resptr;
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
dev->ops->bar_set(dev, bar, offset, value, size);
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct logic_iomem_ops um_pci_device_bar_ops = {
|
|
|
|
.read = um_pci_bar_read,
|
|
|
|
.write = um_pci_bar_write,
|
|
|
|
.set = um_pci_bar_set,
|
|
|
|
.copy_from = um_pci_bar_copy_from,
|
|
|
|
.copy_to = um_pci_bar_copy_to,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __iomem *um_pci_map_bus(struct pci_bus *bus, unsigned int devfn,
|
|
|
|
int where)
|
|
|
|
{
|
|
|
|
struct um_pci_device_reg *dev;
|
|
|
|
unsigned int busn = bus->number;
|
|
|
|
|
|
|
|
if (busn > 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* not allowing functions for now ... */
|
|
|
|
if (devfn % 8)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (devfn / 8 >= ARRAY_SIZE(um_pci_devices))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
dev = &um_pci_devices[devfn / 8];
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
return (void __iomem *)((unsigned long)dev->iomem + where);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct pci_ops um_pci_ops = {
|
|
|
|
.map_bus = um_pci_map_bus,
|
|
|
|
.read = pci_generic_config_read,
|
|
|
|
.write = pci_generic_config_write,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void um_pci_rescan(void)
|
|
|
|
{
|
|
|
|
pci_lock_rescan_remove();
|
|
|
|
pci_rescan_bus(bridge->bus);
|
|
|
|
pci_unlock_rescan_remove();
|
|
|
|
}
|
|
|
|
|
2023-08-23 12:40:44 +02:00
|
|
|
#ifdef CONFIG_OF
|
2023-01-20 09:02:32 +01:00
|
|
|
/* Copied from arch/x86/kernel/devicetree.c */
|
|
|
|
struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
struct device_node *np;
|
|
|
|
|
|
|
|
for_each_node_by_type(np, "pci") {
|
|
|
|
const void *prop;
|
|
|
|
unsigned int bus_min;
|
|
|
|
|
|
|
|
prop = of_get_property(np, "bus-range", NULL);
|
|
|
|
if (!prop)
|
|
|
|
continue;
|
|
|
|
bus_min = be32_to_cpup(prop);
|
|
|
|
if (bus->number == bus_min)
|
|
|
|
return np;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
2023-08-23 12:40:44 +02:00
|
|
|
#endif
|
2023-01-20 09:02:32 +01:00
|
|
|
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
static struct resource virt_cfgspace_resource = {
|
|
|
|
.name = "PCI config space",
|
|
|
|
.start = 0xf0000000 - MAX_DEVICES * CFG_SPACE_SIZE,
|
|
|
|
.end = 0xf0000000 - 1,
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
};
|
|
|
|
|
|
|
|
static long um_pci_map_cfgspace(unsigned long offset, size_t size,
|
|
|
|
const struct logic_iomem_ops **ops,
|
|
|
|
void **priv)
|
|
|
|
{
|
|
|
|
if (WARN_ON(size > CFG_SPACE_SIZE || offset % CFG_SPACE_SIZE))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (offset / CFG_SPACE_SIZE < MAX_DEVICES) {
|
|
|
|
*ops = &um_pci_device_cfgspace_ops;
|
|
|
|
*priv = &um_pci_devices[offset / CFG_SPACE_SIZE];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN(1, "cannot map offset 0x%lx/0x%zx\n", offset, size);
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct logic_iomem_region_ops um_pci_cfgspace_ops = {
|
|
|
|
.map = um_pci_map_cfgspace,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource virt_iomem_resource = {
|
|
|
|
.name = "PCI iomem",
|
|
|
|
.start = 0xf0000000,
|
|
|
|
.end = 0xffffffff,
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct um_pci_map_iomem_data {
|
|
|
|
unsigned long offset;
|
|
|
|
size_t size;
|
|
|
|
const struct logic_iomem_ops **ops;
|
|
|
|
void **priv;
|
|
|
|
long ret;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int um_pci_map_iomem_walk(struct pci_dev *pdev, void *_data)
|
|
|
|
{
|
|
|
|
struct um_pci_map_iomem_data *data = _data;
|
|
|
|
struct um_pci_device_reg *reg = &um_pci_devices[pdev->devfn / 8];
|
|
|
|
struct um_pci_device *dev;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!reg->dev)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dev->resptr); i++) {
|
|
|
|
struct resource *r = &pdev->resource[i];
|
|
|
|
|
|
|
|
if ((r->flags & IORESOURCE_TYPE_BITS) != IORESOURCE_MEM)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* must be the whole or part of the resource,
|
|
|
|
* not allowed to only overlap
|
|
|
|
*/
|
|
|
|
if (data->offset < r->start || data->offset > r->end)
|
|
|
|
continue;
|
|
|
|
if (data->offset + data->size - 1 > r->end)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dev = reg->dev;
|
|
|
|
*data->ops = &um_pci_device_bar_ops;
|
|
|
|
dev->resptr[i] = i;
|
|
|
|
*data->priv = &dev->resptr[i];
|
|
|
|
data->ret = data->offset - r->start;
|
|
|
|
|
|
|
|
/* no need to continue */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long um_pci_map_iomem(unsigned long offset, size_t size,
|
|
|
|
const struct logic_iomem_ops **ops,
|
|
|
|
void **priv)
|
|
|
|
{
|
|
|
|
struct um_pci_map_iomem_data data = {
|
|
|
|
/* we want the full address here */
|
|
|
|
.offset = offset + virt_iomem_resource.start,
|
|
|
|
.size = size,
|
|
|
|
.ops = ops,
|
|
|
|
.priv = priv,
|
|
|
|
.ret = -ENOENT,
|
|
|
|
};
|
|
|
|
|
|
|
|
pci_walk_bus(bridge->bus, um_pci_map_iomem_walk, &data);
|
|
|
|
return data.ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct logic_iomem_region_ops um_pci_iomem_ops = {
|
|
|
|
.map = um_pci_map_iomem,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void um_pci_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* This is a very low address and not actually valid 'physical' memory
|
|
|
|
* in UML, so we can simply map MSI(-X) vectors to there, it cannot be
|
|
|
|
* legitimately written to by the device in any other way.
|
|
|
|
* We use the (virtual) IRQ number here as the message to simplify the
|
|
|
|
* code that receives the message, where for now we simply trust the
|
|
|
|
* device to send the correct message.
|
|
|
|
*/
|
|
|
|
msg->address_hi = 0;
|
|
|
|
msg->address_lo = 0xa0000;
|
|
|
|
msg->data = data->irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irq_chip um_pci_msi_bottom_irq_chip = {
|
2025-03-16 00:19:09 +08:00
|
|
|
.name = "UM virtual MSI",
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
.irq_compose_msi_msg = um_pci_compose_msi_msg,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int um_pci_inner_domain_alloc(struct irq_domain *domain,
|
|
|
|
unsigned int virq, unsigned int nr_irqs,
|
|
|
|
void *args)
|
|
|
|
{
|
|
|
|
unsigned long bit;
|
|
|
|
|
|
|
|
WARN_ON(nr_irqs != 1);
|
|
|
|
|
|
|
|
mutex_lock(&um_pci_mtx);
|
|
|
|
bit = find_first_zero_bit(um_pci_msi_used, MAX_MSI_VECTORS);
|
|
|
|
if (bit >= MAX_MSI_VECTORS) {
|
|
|
|
mutex_unlock(&um_pci_mtx);
|
|
|
|
return -ENOSPC;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_bit(bit, um_pci_msi_used);
|
|
|
|
mutex_unlock(&um_pci_mtx);
|
|
|
|
|
|
|
|
irq_domain_set_info(domain, virq, bit, &um_pci_msi_bottom_irq_chip,
|
|
|
|
domain->host_data, handle_simple_irq,
|
|
|
|
NULL, NULL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void um_pci_inner_domain_free(struct irq_domain *domain,
|
|
|
|
unsigned int virq, unsigned int nr_irqs)
|
|
|
|
{
|
|
|
|
struct irq_data *d = irq_domain_get_irq_data(domain, virq);
|
|
|
|
|
|
|
|
mutex_lock(&um_pci_mtx);
|
|
|
|
|
|
|
|
if (!test_bit(d->hwirq, um_pci_msi_used))
|
|
|
|
pr_err("trying to free unused MSI#%lu\n", d->hwirq);
|
|
|
|
else
|
|
|
|
__clear_bit(d->hwirq, um_pci_msi_used);
|
|
|
|
|
|
|
|
mutex_unlock(&um_pci_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct irq_domain_ops um_pci_inner_domain_ops = {
|
2025-06-30 08:51:16 +02:00
|
|
|
.select = msi_lib_irq_domain_select,
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
.alloc = um_pci_inner_domain_alloc,
|
|
|
|
.free = um_pci_inner_domain_free,
|
|
|
|
};
|
|
|
|
|
2025-06-30 08:51:16 +02:00
|
|
|
#define UM_PCI_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \
|
|
|
|
MSI_FLAG_USE_DEF_CHIP_OPS | \
|
|
|
|
MSI_FLAG_NO_AFFINITY)
|
|
|
|
#define UM_PCI_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | \
|
|
|
|
MSI_FLAG_PCI_MSIX)
|
|
|
|
|
|
|
|
static const struct msi_parent_ops um_pci_msi_parent_ops = {
|
|
|
|
.required_flags = UM_PCI_MSI_FLAGS_REQUIRED,
|
|
|
|
.supported_flags = UM_PCI_MSI_FLAGS_SUPPORTED,
|
|
|
|
.bus_select_token = DOMAIN_BUS_NEXUS,
|
|
|
|
.bus_select_mask = MATCH_PCI_MSI,
|
|
|
|
.prefix = "UM-virtual-",
|
|
|
|
.init_dev_msi_info = msi_lib_init_dev_msi_info,
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource busn_resource = {
|
|
|
|
.name = "PCI busn",
|
|
|
|
.start = 0,
|
|
|
|
.end = 0,
|
|
|
|
.flags = IORESOURCE_BUS,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int um_pci_map_irq(const struct pci_dev *pdev, u8 slot, u8 pin)
|
|
|
|
{
|
|
|
|
struct um_pci_device_reg *reg = &um_pci_devices[pdev->devfn / 8];
|
|
|
|
|
|
|
|
if (WARN_ON(!reg->dev))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
/* Yes, we map all pins to the same IRQ ... doesn't matter for now. */
|
|
|
|
return reg->dev->irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *pci_root_bus_fwnode(struct pci_bus *bus)
|
|
|
|
{
|
|
|
|
return um_pci_fwnode;
|
|
|
|
}
|
|
|
|
|
2023-01-27 15:30:27 +01:00
|
|
|
static long um_pci_map_platform(unsigned long offset, size_t size,
|
|
|
|
const struct logic_iomem_ops **ops,
|
|
|
|
void **priv)
|
|
|
|
{
|
|
|
|
if (!um_pci_platform_device)
|
|
|
|
return -ENOENT;
|
|
|
|
|
|
|
|
*ops = &um_pci_device_bar_ops;
|
|
|
|
*priv = &um_pci_platform_device->resptr[0];
|
|
|
|
|
2023-09-01 15:35:43 +02:00
|
|
|
return offset;
|
2023-01-27 15:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct logic_iomem_region_ops um_pci_platform_ops = {
|
|
|
|
.map = um_pci_map_platform,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct resource virt_platform_resource = {
|
|
|
|
.name = "platform",
|
|
|
|
.start = 0x10000000,
|
|
|
|
.end = 0x1fffffff,
|
|
|
|
.flags = IORESOURCE_MEM,
|
|
|
|
};
|
|
|
|
|
2025-03-16 00:19:09 +08:00
|
|
|
int um_pci_device_register(struct um_pci_device *dev)
|
|
|
|
{
|
|
|
|
int i, free = -1;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
mutex_lock(&um_pci_mtx);
|
|
|
|
for (i = 0; i < MAX_DEVICES; i++) {
|
|
|
|
if (um_pci_devices[i].dev)
|
|
|
|
continue;
|
|
|
|
free = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (free < 0) {
|
|
|
|
err = -ENOSPC;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev->irq = irq_alloc_desc(numa_node_id());
|
|
|
|
if (dev->irq < 0) {
|
|
|
|
err = dev->irq;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
um_pci_devices[free].dev = dev;
|
|
|
|
|
|
|
|
out:
|
|
|
|
mutex_unlock(&um_pci_mtx);
|
|
|
|
if (!err)
|
|
|
|
um_pci_rescan();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
void um_pci_device_unregister(struct um_pci_device *dev)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
mutex_lock(&um_pci_mtx);
|
|
|
|
for (i = 0; i < MAX_DEVICES; i++) {
|
|
|
|
if (um_pci_devices[i].dev != dev)
|
|
|
|
continue;
|
|
|
|
um_pci_devices[i].dev = NULL;
|
|
|
|
irq_free_desc(dev->irq);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
mutex_unlock(&um_pci_mtx);
|
|
|
|
|
|
|
|
if (i < MAX_DEVICES) {
|
|
|
|
struct pci_dev *pci_dev;
|
|
|
|
|
|
|
|
pci_dev = pci_get_slot(bridge->bus, i);
|
|
|
|
if (pci_dev)
|
|
|
|
pci_stop_and_remove_bus_device_locked(pci_dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int um_pci_platform_device_register(struct um_pci_device *dev)
|
|
|
|
{
|
|
|
|
guard(mutex)(&um_pci_mtx);
|
|
|
|
if (um_pci_platform_device)
|
|
|
|
return -EBUSY;
|
|
|
|
um_pci_platform_device = dev;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void um_pci_platform_device_unregister(struct um_pci_device *dev)
|
|
|
|
{
|
|
|
|
guard(mutex)(&um_pci_mtx);
|
|
|
|
if (um_pci_platform_device == dev)
|
|
|
|
um_pci_platform_device = NULL;
|
|
|
|
}
|
|
|
|
|
2022-09-11 10:51:40 +08:00
|
|
|
static int __init um_pci_init(void)
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
{
|
|
|
|
int err, i;
|
|
|
|
|
|
|
|
WARN_ON(logic_iomem_add_region(&virt_cfgspace_resource,
|
|
|
|
&um_pci_cfgspace_ops));
|
|
|
|
WARN_ON(logic_iomem_add_region(&virt_iomem_resource,
|
|
|
|
&um_pci_iomem_ops));
|
2023-01-27 15:30:27 +01:00
|
|
|
WARN_ON(logic_iomem_add_region(&virt_platform_resource,
|
|
|
|
&um_pci_platform_ops));
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
2021-08-11 16:58:25 +02:00
|
|
|
bridge = pci_alloc_host_bridge(0);
|
|
|
|
if (!bridge) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
um_pci_fwnode = irq_domain_alloc_named_fwnode("um-pci");
|
|
|
|
if (!um_pci_fwnode) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
2025-06-30 08:51:16 +02:00
|
|
|
struct irq_domain_info info = {
|
|
|
|
.fwnode = um_pci_fwnode,
|
|
|
|
.ops = &um_pci_inner_domain_ops,
|
|
|
|
.size = MAX_MSI_VECTORS,
|
|
|
|
};
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
2025-06-30 08:51:16 +02:00
|
|
|
um_pci_inner_domain = msi_create_parent_irq_domain(&info, &um_pci_msi_parent_ops);
|
|
|
|
if (!um_pci_inner_domain) {
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
|
|
|
|
pci_add_resource(&bridge->windows, &virt_iomem_resource);
|
|
|
|
pci_add_resource(&bridge->windows, &busn_resource);
|
|
|
|
bridge->ops = &um_pci_ops;
|
|
|
|
bridge->map_irq = um_pci_map_irq;
|
|
|
|
|
|
|
|
for (i = 0; i < MAX_DEVICES; i++) {
|
|
|
|
resource_size_t start;
|
|
|
|
|
|
|
|
start = virt_cfgspace_resource.start + i * CFG_SPACE_SIZE;
|
|
|
|
um_pci_devices[i].iomem = ioremap(start, CFG_SPACE_SIZE);
|
|
|
|
if (WARN(!um_pci_devices[i].iomem, "failed to map %d\n", i)) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto free;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
err = pci_host_probe(bridge);
|
|
|
|
if (err)
|
|
|
|
goto free;
|
|
|
|
|
|
|
|
return 0;
|
2025-03-16 00:19:09 +08:00
|
|
|
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
free:
|
2025-04-15 12:47:13 +02:00
|
|
|
if (um_pci_inner_domain)
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
irq_domain_remove(um_pci_inner_domain);
|
|
|
|
if (um_pci_fwnode)
|
|
|
|
irq_domain_free_fwnode(um_pci_fwnode);
|
2021-08-11 16:58:25 +02:00
|
|
|
if (bridge) {
|
|
|
|
pci_free_resource_list(&bridge->windows);
|
|
|
|
pci_free_host_bridge(bridge);
|
|
|
|
}
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
return err;
|
|
|
|
}
|
2025-03-16 00:19:09 +08:00
|
|
|
device_initcall(um_pci_init);
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
|
2022-09-11 10:51:40 +08:00
|
|
|
static void __exit um_pci_exit(void)
|
um: add PCI over virtio emulation driver
To support testing of PCI/PCIe drivers in UML, add a PCI bus
support driver. This driver uses virtio, which in UML is really
just vhost-user, to talk to devices, and adds the devices to
the virtual PCI bus in the system.
Since virtio already allows DMA/bus mastering this really isn't
all that hard, of course we need the logic_iomem infrastructure
that was added by a previous patch.
The protocol to talk to the device is has a few fairly simple
messages for reading to/writing from config and IO spaces, and
messages for the device to send the various interrupts (INT#,
MSI/MSI-X and while suspended PME#).
Note that currently no offical virtio device ID is assigned for
this protocol, as a consequence this patch requires defining it
in the Kconfig, with a default that makes the driver refuse to
work at all.
Finally, in order to add support for MSI/MSI-X interrupts, some
small changes are needed in the UML IRQ code, it needs to have
more interrupts, changing NR_IRQS from 64 to 128 if this driver
is enabled, but not actually use them for anything so that the
generic IRQ domain/MSI infrastructure can allocate IRQ numbers.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
2021-03-05 13:19:58 +01:00
|
|
|
{
|
|
|
|
irq_domain_remove(um_pci_inner_domain);
|
|
|
|
pci_free_resource_list(&bridge->windows);
|
|
|
|
pci_free_host_bridge(bridge);
|
|
|
|
}
|
|
|
|
module_exit(um_pci_exit);
|