]> rtime.felk.cvut.cz Git - jailhouse.git/blobdiff - hypervisor/pci.c
Merge remote-tracking branch 'kiszka/master'
[jailhouse.git] / hypervisor / pci.c
index 1282287468e759d731a9bf7ce34747e60618178a..12424666b5c874a09513e1b8171fabecda24ef90 100644 (file)
@@ -360,25 +360,24 @@ int pci_init(void)
 {
        int err;
 
-       err = pci_cell_init(&root_cell);
-       if (err)
-               return err;
-
        mmcfg_start = system_config->platform_info.x86.mmconfig_base;
-       if (mmcfg_start == 0)
-               return 0;
+       if (mmcfg_start != 0) {
+               end_bus = system_config->platform_info.x86.mmconfig_end_bus;
+               mmcfg_size = (end_bus + 1) * 256 * 4096;
 
-       end_bus = system_config->platform_info.x86.mmconfig_end_bus;
-       mmcfg_size = (end_bus + 1) * 256 * 4096;
+               pci_space = page_alloc(&remap_pool, mmcfg_size / PAGE_SIZE);
+               if (!pci_space)
+                       return trace_error(-ENOMEM);
 
-       pci_space = page_alloc(&remap_pool, mmcfg_size / PAGE_SIZE);
-       if (!pci_space)
-               return trace_error(-ENOMEM);
+               err = paging_create(&hv_paging_structs, mmcfg_start,
+                                   mmcfg_size, (unsigned long)pci_space,
+                                   PAGE_DEFAULT_FLAGS | PAGE_FLAG_DEVICE,
+                                   PAGING_NON_COHERENT);
+               if (err)
+                       return err;
+       }
 
-       return paging_create(&hv_paging_structs, mmcfg_start, mmcfg_size,
-                            (unsigned long)pci_space,
-                            PAGE_DEFAULT_FLAGS | PAGE_FLAG_DEVICE,
-                            PAGING_NON_COHERENT);
+       return pci_cell_init(&root_cell);
 }
 
 static enum mmio_result pci_msix_access_handler(void *arg,
@@ -459,7 +458,7 @@ static enum mmio_result pci_mmconfig_access_handler(void *arg,
 
 invalid_access:
        panic_printk("FATAL: Invalid PCI MMCONFIG write, device %02x:%02x.%x, "
-                    "reg: %\n", PCI_BDF_PARAMS(mmio->address >> 12),
+                    "reg: %x\n", PCI_BDF_PARAMS(mmio->address >> 12),
                     reg_addr);
        return MMIO_ERROR;
 
@@ -597,8 +596,6 @@ static int pci_add_physical_device(struct cell *cell, struct pci_device *device)
                        }
                }
 
-               device->next_msix_device = cell->msix_device_list;
-               cell->msix_device_list = device;
                mmio_region_register(cell, device->info->msix_address, size,
                                     pci_msix_access_handler, device);
        }
@@ -618,7 +615,6 @@ error_remove_dev:
 static void pci_remove_physical_device(struct pci_device *device)
 {
        unsigned int size = device->info->msix_region_size;
-       struct pci_device *prev_msix_device;
 
        printk("Removing PCI device %02x:%02x.%x from cell \"%s\"\n",
               PCI_BDF_PARAMS(device->info->bdf), device->cell->config->name);
@@ -639,14 +635,6 @@ static void pci_remove_physical_device(struct pci_device *device)
                          PAGES(sizeof(union pci_msix_vector) *
                                device->info->num_msix_vectors));
 
-       prev_msix_device = device->cell->msix_device_list;
-       if (prev_msix_device == device) {
-               device->cell->msix_device_list = device->next_msix_device;
-       } else {
-               while (prev_msix_device->next_msix_device != device)
-                       prev_msix_device = prev_msix_device->next_msix_device;
-               prev_msix_device->next_msix_device = device->next_msix_device;
-       }
        mmio_region_unregister(device->cell, device->info->msix_address);
 }
 
@@ -673,6 +661,9 @@ int pci_cell_init(struct cell *cell)
                mmio_region_register(cell, mmcfg_start, mmcfg_size,
                                     pci_mmconfig_access_handler, NULL);
 
+       if (cell->config->num_pci_devices == 0)
+               return 0;
+
        cell->pci_devices = page_alloc(&mem_pool, devlist_pages);
        if (!cell->pci_devices)
                return -ENOMEM;