From: Jan Kiszka <[email protected]>

This registers pci as unit with the core. As it should be initialized
last, we have to ensure this via adjusting the linking order.

Signed-off-by: Jan Kiszka <[email protected]>
---
 hypervisor/Makefile                |  2 +-
 hypervisor/control.c               | 10 +---------
 hypervisor/include/jailhouse/pci.h |  7 -------
 hypervisor/mmio.c                  |  3 +--
 hypervisor/pci.c                   | 15 ++++++++++-----
 hypervisor/setup.c                 |  4 ----
 6 files changed, 13 insertions(+), 28 deletions(-)

diff --git a/hypervisor/Makefile b/hypervisor/Makefile
index 2257848d6..4ba2df6af 100644
--- a/hypervisor/Makefile
+++ b/hypervisor/Makefile
@@ -94,7 +94,7 @@ always += jailhouse$(1).bin
 
 $$(obj)/arch/$$(SRCARCH)/built-in$(1).o: $$(obj)/arch/$$(SRCARCH)
 
-hypervisor$(1)-y := $$(CORE_OBJECTS) arch/$$(SRCARCH)/built-in$(1).o \
+hypervisor$(1)-y := arch/$$(SRCARCH)/built-in$(1).o $$(CORE_OBJECTS) \
        hypervisor.lds
 targets += $$(hypervisor$(1)-y)
 
diff --git a/hypervisor/control.c b/hypervisor/control.c
index c71cb82b7..889457653 100644
--- a/hypervisor/control.c
+++ b/hypervisor/control.c
@@ -330,7 +330,6 @@ static void cell_destroy_internal(struct per_cpu *cpu_data, 
struct cell *cell)
 
        for_each_unit_reverse(unit)
                unit->cell_exit(cell);
-       pci_cell_exit(cell);
        arch_cell_destroy(cell);
 
        config_commit(cell);
@@ -428,16 +427,12 @@ 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;
-
        for_each_unit(unit) {
                err = unit->cell_init(cell);
                if (err) {
                        for_each_unit_before_reverse(unit, unit)
                                unit->cell_exit(cell);
-                       goto err_pci_exit;
+                       goto err_arch_destroy;
                }
        }
 
@@ -502,8 +497,6 @@ err_destroy_cell:
        cell_destroy_internal(cpu_data, cell);
        /* cell_destroy_internal already calls arch_cell_destroy & cell_exit */
        goto err_free_cell;
-err_pci_exit:
-       pci_cell_exit(cell);
 err_arch_destroy:
        arch_cell_destroy(cell);
 err_cell_exit:
@@ -714,7 +707,6 @@ void shutdown(void)
 
        pci_prepare_handover();
        arch_shutdown();
-       pci_shutdown();
 
        for_each_unit_reverse(unit)
                unit->shutdown();
diff --git a/hypervisor/include/jailhouse/pci.h 
b/hypervisor/include/jailhouse/pci.h
index c0c10e96b..c1dd69f23 100644
--- a/hypervisor/include/jailhouse/pci.h
+++ b/hypervisor/include/jailhouse/pci.h
@@ -145,10 +145,6 @@ struct pci_device {
        union pci_msix_vector msix_vector_array[PCI_EMBEDDED_MSIX_VECTS];
 };
 
-unsigned int pci_mmio_count_regions(struct cell *cell);
-
-int pci_init(void);
-
 u32 pci_read_config(u16 bdf, u16 address, unsigned int size);
 void pci_write_config(u16 bdf, u16 address, u32 value, unsigned int size);
 
@@ -161,16 +157,13 @@ enum pci_access pci_cfg_write_moderate(struct pci_device 
*device, u16 address,
 
 void pci_reset_device(struct pci_device *device);
 
-int pci_cell_init(struct cell *cell);
 void pci_cell_reset(struct cell *cell);
-void pci_cell_exit(struct cell *cell);
 
 void pci_config_commit(struct cell *cell_added_removed);
 
 unsigned int pci_enabled_msi_vectors(struct pci_device *device);
 
 void pci_prepare_handover(void);
-void pci_shutdown(void);
 
 /**
  * Read from PCI config space via architecture-specific method.
diff --git a/hypervisor/mmio.c b/hypervisor/mmio.c
index ec7cd40cf..a50012553 100644
--- a/hypervisor/mmio.c
+++ b/hypervisor/mmio.c
@@ -33,8 +33,7 @@ int mmio_cell_init(struct cell *cell)
        unsigned int n;
        void *pages;
 
-       cell->max_mmio_regions = arch_mmio_count_regions(cell) +
-               pci_mmio_count_regions(cell);
+       cell->max_mmio_regions = arch_mmio_count_regions(cell);
        for_each_unit(unit)
                cell->max_mmio_regions += unit->mmio_count_regions(cell);
 
diff --git a/hypervisor/pci.c b/hypervisor/pci.c
index 1db147899..5ec3097f0 100644
--- a/hypervisor/pci.c
+++ b/hypervisor/pci.c
@@ -17,6 +17,7 @@
 #include <jailhouse/pci.h>
 #include <jailhouse/printk.h>
 #include <jailhouse/string.h>
+#include <jailhouse/unit.h>
 #include <jailhouse/utils.h>
 
 #define MSIX_VECTOR_CTRL_DWORD         3
@@ -69,7 +70,7 @@ static void *pci_space;
 static u64 mmcfg_start, mmcfg_size;
 static u8 end_bus;
 
-unsigned int pci_mmio_count_regions(struct cell *cell)
+static unsigned int pci_mmio_count_regions(struct cell *cell)
 {
        const struct jailhouse_pci_device *dev_infos =
                jailhouse_cell_pci_devices(cell->config);
@@ -647,6 +648,8 @@ static void pci_remove_physical_device(struct pci_device 
*device)
        mmio_region_unregister(cell, device->info->msix_address);
 }
 
+static void pci_cell_exit(struct cell *cell);
+
 /**
  * Perform PCI-specific initialization for a new cell.
  * @param cell Cell to be initialized.
@@ -655,7 +658,7 @@ static void pci_remove_physical_device(struct pci_device 
*device)
  *
  * @see pci_cell_exit
  */
-int pci_cell_init(struct cell *cell)
+static int pci_cell_init(struct cell *cell)
 {
        unsigned int devlist_pages = PAGES(cell->config->num_pci_devices *
                                           sizeof(struct pci_device));
@@ -751,7 +754,7 @@ static void pci_return_device_to_root_cell(struct 
pci_device *device)
  *
  * @see pci_cell_init
  */
-void pci_cell_exit(struct cell *cell)
+static void pci_cell_exit(struct cell *cell)
 {
        unsigned int devlist_pages = PAGES(cell->config->num_pci_devices *
                                           sizeof(struct pci_device));
@@ -831,7 +834,7 @@ error:
  *
  * @return 0 on success, negative error code otherwise.
  */
-int pci_init(void)
+static int pci_init(void)
 {
        mmcfg_start = system_config->platform_info.pci_mmconfig_base;
        end_bus = system_config->platform_info.pci_mmconfig_end_bus;
@@ -849,7 +852,7 @@ int pci_init(void)
 /**
  * Shut down the PCI layer during hypervisor deactivation.
  */
-void pci_shutdown(void)
+static void pci_shutdown(void)
 {
        const struct jailhouse_pci_capability *cap;
        struct pci_device *device;
@@ -873,3 +876,5 @@ void pci_shutdown(void)
                                         PCI_CMD_INTX_OFF, 2);
        }
 }
+
+DEFINE_UNIT(pci, "PCI");
diff --git a/hypervisor/setup.c b/hypervisor/setup.c
index a7936c983..31277a598 100644
--- a/hypervisor/setup.c
+++ b/hypervisor/setup.c
@@ -147,10 +147,6 @@ static void init_late(void)
        if (error)
                return;
 
-       error = pci_init();
-       if (error)
-               return;
-
        for_each_unit(unit) {
                printk("Initializing unit: %s\n", unit->name);
                error = unit->init();
-- 
2.13.6

-- 
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