]> rtime.felk.cvut.cz Git - jailhouse.git/commitdiff
core: Introduce and use PAGES macro
authorJan Kiszka <jan.kiszka@siemens.com>
Thu, 21 Aug 2014 09:01:45 +0000 (11:01 +0200)
committerJan Kiszka <jan.kiszka@siemens.com>
Thu, 28 Aug 2014 06:36:09 +0000 (08:36 +0200)
PAGES(s) = PAGE_ALIGN(s) / PAGE_SIZE, a common pattern that can be
wrapped to avoid continuous open-coding.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
hypervisor/arch/x86/vtd.c
hypervisor/control.c
hypervisor/include/jailhouse/paging.h
hypervisor/paging.c
hypervisor/pci.c

index 699e6d83969feec74b8e077943e239f92ad420a0..fb1b83f3502e61320382b7f986e28fe5e726f83e 100644 (file)
@@ -252,7 +252,7 @@ static void vtd_init_unit(void *reg_base, void *inv_queue)
 
 int vtd_init(void)
 {
-       unsigned long size, version, caps, ecaps, sllps_caps = ~0UL;
+       unsigned long version, caps, ecaps, sllps_caps = ~0UL;
        unsigned int pt_levels, num_did, n;
        unsigned int units = 0;
        void *reg_base;
@@ -265,8 +265,8 @@ int vtd_init(void)
        if (n >= 16)
                return -EINVAL;
 
-       size = PAGE_ALIGN(sizeof(union vtd_irte) << n);
-       int_remap_table = page_alloc(&mem_pool, size / PAGE_SIZE);
+       int_remap_table =
+               page_alloc(&mem_pool, PAGES(sizeof(union vtd_irte) << n));
        if (!int_remap_table)
                return -ENOMEM;
 
index 05d2d8430e6f0dad48dba2410e8fc6d3cd875b69..c97cb11ce5403c52e1703f705c1b0e294bef25b9 100644 (file)
@@ -309,8 +309,7 @@ static int cell_create(struct per_cpu *cpu_data, unsigned long config_address)
                goto err_resume;
        }
 
-       cfg_pages = PAGE_ALIGN(sizeof(struct jailhouse_cell_desc) +
-                              cfg_page_offs) / PAGE_SIZE;
+       cfg_pages = PAGES(cfg_page_offs + sizeof(struct jailhouse_cell_desc));
        cfg_mapping = page_map_get_guest_pages(NULL, config_address, cfg_pages,
                                               PAGE_READONLY_FLAGS);
        if (!cfg_mapping) {
@@ -327,7 +326,7 @@ static int cell_create(struct per_cpu *cpu_data, unsigned long config_address)
                }
 
        cfg_total_size = jailhouse_cell_config_size(cfg);
-       cfg_pages = PAGE_ALIGN(cfg_total_size + cfg_page_offs) / PAGE_SIZE;
+       cfg_pages = PAGES(cfg_page_offs + cfg_total_size);
        if (cfg_pages > NUM_TEMPORARY_PAGES) {
                err = -E2BIG;
                goto err_resume;
@@ -343,7 +342,7 @@ static int cell_create(struct per_cpu *cpu_data, unsigned long config_address)
        if (err)
                goto err_resume;
 
-       cell_pages = PAGE_ALIGN(sizeof(*cell) + cfg_total_size) / PAGE_SIZE;
+       cell_pages = PAGES(sizeof(*cell) + cfg_total_size);
        cell = page_alloc(&mem_pool, cell_pages);
        if (!cell) {
                err = -ENOMEM;
index a94641fe0e50e96c51cf01ee7275d9481c745ae3..041db387753dbb5ebfc625a0f7571b243fb61a53 100644 (file)
@@ -18,6 +18,7 @@
 #include <asm/paging.h>
 
 #define PAGE_ALIGN(s)          (((s) + PAGE_SIZE-1) & PAGE_MASK)
+#define PAGES(s)               (((s) + PAGE_SIZE-1) / PAGE_SIZE)
 
 #define TEMPORARY_MAPPING_BASE REMAP_BASE
 
index 28b72ca42c451da065b8d41114f14baae0bb3f5c..05dbfec92722236bda1e157760531f9a30998e12 100644 (file)
@@ -365,8 +365,7 @@ int paging_init(void)
 
        system_config = (struct jailhouse_system *)
                (__page_pool + per_cpu_pages * PAGE_SIZE);
-       config_pages = (jailhouse_system_config_size(system_config) +
-                       PAGE_SIZE - 1) / PAGE_SIZE;
+       config_pages = PAGES(jailhouse_system_config_size(system_config));
 
        page_offset = JAILHOUSE_BASE -
                system_config->hypervisor_memory.phys_start;
index 322961693df816ad68dae61a16260b5a2bd3bbee..85924c2671f3967d66e58be56f82d82f3529276f 100644 (file)
@@ -571,8 +571,8 @@ static void pci_remove_device(struct pci_device *device)
 
 int pci_cell_init(struct cell *cell)
 {
-       unsigned long array_size = PAGE_ALIGN(cell->config->num_pci_devices *
-                                             sizeof(struct pci_device));
+       unsigned int devlist_pages = PAGES(cell->config->num_pci_devices *
+                                          sizeof(struct pci_device));
        const struct jailhouse_pci_device *dev_infos =
                jailhouse_cell_pci_devices(cell->config);
        const struct jailhouse_pci_capability *cap;
@@ -580,7 +580,7 @@ int pci_cell_init(struct cell *cell)
        unsigned int ndev, ncap;
        int err;
 
-       cell->pci_devices = page_alloc(&mem_pool, array_size / PAGE_SIZE);
+       cell->pci_devices = page_alloc(&mem_pool, devlist_pages);
        if (!cell->pci_devices)
                return -ENOMEM;
 
@@ -645,8 +645,8 @@ static void pci_return_device_to_root_cell(struct pci_device *device)
 
 void pci_cell_exit(struct cell *cell)
 {
-       unsigned long array_size = PAGE_ALIGN(cell->config->num_pci_devices *
-                                             sizeof(struct pci_device));
+       unsigned int devlist_pages = PAGES(cell->config->num_pci_devices *
+                                          sizeof(struct pci_device));
        struct pci_device *device;
 
        /*
@@ -662,7 +662,7 @@ void pci_cell_exit(struct cell *cell)
                        pci_return_device_to_root_cell(device);
                }
 
-       page_free(&mem_pool, cell->pci_devices, array_size / PAGE_SIZE);
+       page_free(&mem_pool, cell->pci_devices, devlist_pages);
 }
 
 void pci_config_commit(struct cell *cell_added_removed)