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;
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;
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) {
}
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;
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;
#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
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;
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;
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;
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;
/*
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)