From ffa9953a1434f1a576ea3fd5584e190d364f8c1d Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Thu, 4 Aug 2022 08:28:05 +0200 Subject: [PATCH] vmd: add attach_device() This patch implements the callback for attaching devices behind the VMD with a given PCI address. Signed-off-by: Konrad Sztyber Change-Id: I07cf92c94cc7e6d3c8e31af7a8615e9a4ca641bf Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13886 Tested-by: SPDK CI Jenkins Reviewed-by: Tomasz Zawadzki Reviewed-by: Jim Harris Reviewed-by: Tom Nabarro --- lib/vmd/vmd.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lib/vmd/vmd.c b/lib/vmd/vmd.c index e490fe126..788ab5455 100644 --- a/lib/vmd/vmd.c +++ b/lib/vmd/vmd.c @@ -1423,6 +1423,62 @@ spdk_vmd_hotplug_monitor(void) return num_hotplugs; } +static int +vmd_attach_device(const struct spdk_pci_addr *addr) +{ + struct vmd_pci_bus *bus; + struct vmd_adapter *vmd; + struct vmd_pci_device *dev; + uint32_t i; + int rc; + + /* VMD always sets function to zero */ + if (addr->func != 0) { + return -ENODEV; + } + + for (i = 0; i < g_vmd_container.count; ++i) { + vmd = &g_vmd_container.vmd[i]; + if (vmd->domain != addr->domain) { + continue; + } + + TAILQ_FOREACH(bus, &vmd->bus_list, tailq) { + if (bus->bus_number != addr->bus) { + continue; + } + + dev = vmd_alloc_dev(bus, addr->dev); + if (dev == NULL) { + return -ENODEV; + } + + /* Only allow attaching endpoint devices */ + if (dev->header->common.header_type & PCI_HEADER_TYPE_BRIDGE) { + free(dev); + return -ENODEV; + } + + rc = vmd_init_end_device(dev); + if (rc != 0) { + free(dev); + return -ENODEV; + } + + return 0; + } + } + + return -ENODEV; +} + +static struct spdk_pci_device_provider g_vmd_device_provider = { + .name = "vmd", + .attach_cb = vmd_attach_device, +}; + +SPDK_PCI_REGISTER_DEVICE_PROVIDER(vmd, &g_vmd_device_provider); + int spdk_vmd_init(void) {