Move PCI initialization functions from x86 into the core, effectively
enabling it for all architectures.

PCI is now initialized last, both during common setup as well as on cell
creation. This means an ordering change for x86, but that is without
side effects.

Signed-off-by: Jan Kiszka <[email protected]>
---
 hypervisor/arch/x86/control.c          | 13 +------------
 hypervisor/arch/x86/mmio.c             |  3 +--
 hypervisor/arch/x86/setup.c            |  5 -----
 hypervisor/control.c                   | 22 ++++++++++++++++++++--
 hypervisor/include/jailhouse/control.h |  2 ++
 hypervisor/mmio.c                      |  3 ++-
 hypervisor/setup.c                     |  6 +++++-
 7 files changed, 31 insertions(+), 23 deletions(-)

diff --git a/hypervisor/arch/x86/control.c b/hypervisor/arch/x86/control.c
index 560ffc5..a33b007 100644
--- a/hypervisor/arch/x86/control.c
+++ b/hypervisor/arch/x86/control.c
@@ -11,7 +11,6 @@
  */
 
 #include <jailhouse/control.h>
-#include <jailhouse/pci.h>
 #include <jailhouse/printk.h>
 #include <jailhouse/processor.h>
 #include <asm/apic.h>
@@ -44,13 +43,9 @@ int arch_cell_create(struct cell *cell)
        if (err)
                goto error_vm_exit;
 
-       err = pci_cell_init(cell);
-       if (err)
-               goto error_iommu_exit;
-
        err = ioapic_cell_init(cell);
        if (err)
-               goto error_pci_exit;
+               goto error_iommu_exit;
 
        err = cat_cell_init(cell);
        if (err)
@@ -66,8 +61,6 @@ int arch_cell_create(struct cell *cell)
 
 error_ioapic_exit:
        ioapic_cell_exit(cell);
-error_pci_exit:
-       pci_cell_exit(cell);
 error_iommu_exit:
        iommu_cell_exit(cell);
 error_vm_exit:
@@ -122,7 +115,6 @@ void arch_cell_destroy(struct cell *cell)
 {
        cat_cell_exit(cell);
        ioapic_cell_exit(cell);
-       pci_cell_exit(cell);
        iommu_cell_exit(cell);
        vcpu_cell_exit(cell);
 }
@@ -134,17 +126,14 @@ void arch_cell_reset(struct cell *cell)
 void arch_config_commit(struct cell *cell_added_removed)
 {
        iommu_config_commit(cell_added_removed);
-       pci_config_commit(cell_added_removed);
        ioapic_config_commit(cell_added_removed);
 }
 
 void arch_shutdown(void)
 {
-       pci_prepare_handover();
        ioapic_prepare_handover();
 
        iommu_shutdown();
-       pci_shutdown();
        ioapic_shutdown();
 }
 
diff --git a/hypervisor/arch/x86/mmio.c b/hypervisor/arch/x86/mmio.c
index a5209db..ef9a292 100644
--- a/hypervisor/arch/x86/mmio.c
+++ b/hypervisor/arch/x86/mmio.c
@@ -178,6 +178,5 @@ error:
 
 unsigned int arch_mmio_count_regions(struct cell *cell)
 {
-       return pci_mmio_count_regions(cell) + ioapic_mmio_count_regions(cell) +
-               iommu_mmio_count_regions(cell);
+       return ioapic_mmio_count_regions(cell) + iommu_mmio_count_regions(cell);
 }
diff --git a/hypervisor/arch/x86/setup.c b/hypervisor/arch/x86/setup.c
index 0c7b00d..d43925f 100644
--- a/hypervisor/arch/x86/setup.c
+++ b/hypervisor/arch/x86/setup.c
@@ -14,7 +14,6 @@
 
 #include <jailhouse/entry.h>
 #include <jailhouse/paging.h>
-#include <jailhouse/pci.h>
 #include <jailhouse/processor.h>
 #include <asm/apic.h>
 #include <asm/bitops.h>
@@ -226,10 +225,6 @@ int arch_init_late(void)
        if (err)
                return err;
 
-       err = pci_init();
-       if (err)
-               return err;
-
        err = ioapic_init();
        if (err)
                return err;
diff --git a/hypervisor/control.c b/hypervisor/control.c
index 6885689..d6a5a7d 100644
--- a/hypervisor/control.c
+++ b/hypervisor/control.c
@@ -214,6 +214,7 @@ void config_commit(struct cell *cell_added_removed)
                arch_flush_cell_vcpu_caches(cell_added_removed);
 
        arch_config_commit(cell_added_removed);
+       pci_config_commit(cell_added_removed);
 }
 
 static bool address_in_region(unsigned long addr,
@@ -312,6 +313,7 @@ static void cell_destroy_internal(struct per_cpu *cpu_data, 
struct cell *cell)
                        remap_to_root_cell(mem, WARN_ON_ERROR);
        }
 
+       pci_cell_exit(cell);
        arch_cell_destroy(cell);
 
        config_commit(cell);
@@ -408,6 +410,10 @@ static int cell_create(struct per_cpu *cpu_data, unsigned 
long config_address)
        if (err)
                goto err_cell_exit;
 
+       err = pci_cell_init(cell);
+       if (err)
+               goto err_arch_destroy;
+
        /*
         * Shrinking: the new cell's CPUs are parked, then removed from the root
         * cell, assigned to the new cell and get their stats cleared.
@@ -467,8 +473,10 @@ static int cell_create(struct per_cpu *cpu_data, unsigned 
long config_address)
 
 err_destroy_cell:
        cell_destroy_internal(cpu_data, cell);
-       /* cell_destroy_internal already calls cell_exit */
+       /* cell_destroy_internal already calls arch_cell_destroy & cell_exit */
        goto err_free_cell;
+err_arch_destroy:
+       arch_cell_destroy(cell);
 err_cell_exit:
        cell_exit(cell);
 err_free_cell:
@@ -663,6 +671,16 @@ static int cell_get_state(struct per_cpu *cpu_data, 
unsigned long id)
        return -ENOENT;
 }
 
+/**
+ * Perform all CPU-unrelated hypervisor shutdown steps.
+ */
+void shutdown(void)
+{
+       pci_prepare_handover();
+       arch_shutdown();
+       pci_shutdown();
+}
+
 static int hypervisor_disable(struct per_cpu *cpu_data)
 {
        unsigned int this_cpu = cpu_data->cpu_id;
@@ -703,7 +721,7 @@ static int hypervisor_disable(struct per_cpu *cpu_data)
        if (cpu_data->shutdown_state == SHUTDOWN_NONE) {
                if (num_cells == 1) {
                        printk("Shutting down hypervisor\n");
-                       arch_shutdown();
+                       shutdown();
                        state = SHUTDOWN_STARTED;
                } else {
                        state = -EBUSY;
diff --git a/hypervisor/include/jailhouse/control.h 
b/hypervisor/include/jailhouse/control.h
index 4538250..8f14979 100644
--- a/hypervisor/include/jailhouse/control.h
+++ b/hypervisor/include/jailhouse/control.h
@@ -129,6 +129,8 @@ void config_commit(struct cell *cell_added_removed);
 
 long hypercall(unsigned long code, unsigned long arg1, unsigned long arg2);
 
+void shutdown(void);
+
 void __attribute__((noreturn)) panic_stop(void);
 void panic_park(void);
 
diff --git a/hypervisor/mmio.c b/hypervisor/mmio.c
index 2c58f58..5fdcc31 100644
--- a/hypervisor/mmio.c
+++ b/hypervisor/mmio.c
@@ -31,7 +31,8 @@ int mmio_cell_init(struct cell *cell)
        unsigned int n;
        void *pages;
 
-       cell->max_mmio_regions = arch_mmio_count_regions(cell);
+       cell->max_mmio_regions = arch_mmio_count_regions(cell) +
+               pci_mmio_count_regions(cell);
 
        for_each_mem_region(mem, cell->config, n)
                if (JAILHOUSE_MEMORY_IS_SUBPAGE(mem))
diff --git a/hypervisor/setup.c b/hypervisor/setup.c
index 0e2be9c..a55e4b9 100644
--- a/hypervisor/setup.c
+++ b/hypervisor/setup.c
@@ -147,6 +147,10 @@ static void init_late(void)
        if (error)
                return;
 
+       error = pci_init();
+       if (error)
+               return;
+
        config_commit(&root_cell);
 
        paging_dump_stats("after late setup");
@@ -197,7 +201,7 @@ int entry(unsigned int cpu_id, struct per_cpu *cpu_data)
 
        if (error) {
                if (master)
-                       arch_shutdown();
+                       shutdown();
                arch_cpu_restore(cpu_data, error);
                return error;
        }
-- 
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.

Reply via email to