From: Jan Kiszka <[email protected]> In order to reuse upcoming device reset functions during initialization, we will have to set device->cell earlier than so far. To make things consistent, give the control over that field into the respective device addition/removal functions.
This has the side effect of curing cell initialization in case re-assignment of a physical device to the root cell fails: the field should be NULL then (no owner). Signed-off-by: Jan Kiszka <[email protected]> --- hypervisor/ivshmem.c | 2 ++ hypervisor/pci.c | 28 +++++++++++++++------------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/hypervisor/ivshmem.c b/hypervisor/ivshmem.c index d9ce40f..a9259cf 100644 --- a/hypervisor/ivshmem.c +++ b/hypervisor/ivshmem.c @@ -395,6 +395,8 @@ int ivshmem_init(struct cell *cell, struct pci_device *device) remote->remote = ive; } + device->cell = cell; + return 0; } diff --git a/hypervisor/pci.c b/hypervisor/pci.c index 95ba6e1..3df3c83 100644 --- a/hypervisor/pci.c +++ b/hypervisor/pci.c @@ -565,8 +565,10 @@ static int pci_add_physical_device(struct cell *cell, struct pci_device *device) PCI_CFG_BAR + n * 4, 4); err = arch_pci_add_physical_device(cell, device); + if (err) + return err; - if (!err && device->info->msix_address) { + if (device->info->msix_address) { device->msix_table = paging_map_device(device->info->msix_address, size); if (!device->msix_table) { @@ -587,7 +589,10 @@ static int pci_add_physical_device(struct cell *cell, struct pci_device *device) mmio_region_register(cell, device->info->msix_address, size, pci_msix_access_handler, device); } - return err; + + device->cell = cell; + + return 0; error_unmap_table: paging_unmap_device(device->info->msix_address, device->msix_table, @@ -599,12 +604,17 @@ error_remove_dev: static void pci_remove_physical_device(struct pci_device *device) { + struct cell *cell = device->cell; + printk("Removing PCI device %02x:%02x.%x from cell \"%s\"\n", - PCI_BDF_PARAMS(device->info->bdf), device->cell->config->name); + PCI_BDF_PARAMS(device->info->bdf), cell->config->name); + arch_pci_remove_physical_device(device); pci_write_config(device->info->bdf, PCI_CFG_COMMAND, PCI_CMD_INTX_OFF, 2); + device->cell = NULL; + if (!device->msix_table) return; @@ -616,7 +626,7 @@ static void pci_remove_physical_device(struct pci_device *device) PAGES(sizeof(union pci_msix_vector) * device->info->num_msix_vectors)); - mmio_region_unregister(device->cell, device->info->msix_address); + mmio_region_unregister(cell, device->info->msix_address); } /** @@ -665,24 +675,18 @@ int pci_cell_init(struct cell *cell) if (err) goto error; - device->cell = cell; - continue; } root_device = pci_get_assigned_device(&root_cell, dev_infos[ndev].bdf); - if (root_device) { + if (root_device) pci_remove_physical_device(root_device); - root_device->cell = NULL; - } err = pci_add_physical_device(cell, device); if (err) goto error; - device->cell = cell; - for_each_pci_cap(cap, device, ncap) if (cap->id == PCI_CAP_MSI) pci_save_msi(device, cap); @@ -710,8 +714,6 @@ static void pci_return_device_to_root_cell(struct pci_device *device) root_device) < 0) printk("WARNING: Failed to re-assign PCI " "device to root cell\n"); - else - root_device->cell = &root_cell; break; } } -- 2.1.4 -- You received this message because you are subscribed to the Google Groups "Jailhouse" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
