diff options
author | Josep Puigdemont <josep.puigdemont@linaro.org> | 2018-01-02 15:47:50 +0100 |
---|---|---|
committer | Josep Puigdemont <josep.puigdemont@linaro.org> | 2018-01-16 13:39:01 +0100 |
commit | d99b3beb5ba18f061b4baa2debd46d674e542403 (patch) | |
tree | 16c4a18a30072c759827d44f0313e4202593beed | |
parent | 217b610fa1c7c14e0e8f4a33a94dba6f50c79328 (diff) |
physmem: change API, alloc now does a mapping toodevel/native-drivers
We add the _reserve() function to the API to do what was previously
achieved with _alloc(), which is to reserve a set of huge pages that are
physically contiguous.
We changed _alloc() so it now calls _reserve() and _map() and it returns
a block that is already mapped in the process' virtual address space.
Signed-off-by: Josep Puigdemont <josep.puigdemont@linaro.org>
Reviewed-by: Yi He <yi.he@linaro.org>
-rw-r--r-- | platform/linux-generic/pktio/physmem/physmem.c | 19 | ||||
-rw-r--r-- | platform/linux-generic/pktio/physmem/physmem.h | 1 |
2 files changed, 18 insertions, 2 deletions
diff --git a/platform/linux-generic/pktio/physmem/physmem.c b/platform/linux-generic/pktio/physmem/physmem.c index 297ff2fa6..a01b54fef 100644 --- a/platform/linux-generic/pktio/physmem/physmem.c +++ b/platform/linux-generic/pktio/physmem/physmem.c @@ -251,7 +251,7 @@ static struct physmem_block *block_get(void) return block; } -struct physmem_block *physmem_block_alloc(uint64_t size) +struct physmem_block *physmem_block_reserve(uint64_t size) { struct physmem_block *block; struct physmem_block *ret = NULL; @@ -331,6 +331,22 @@ struct physmem_block *physmem_block_alloc(uint64_t size) return ret; } +struct physmem_block *physmem_block_alloc(uint64_t size) +{ + struct physmem_block *block; + + block = physmem_block_reserve(size); + if (block == NULL) + return NULL; + + if (physmem_block_map(block, NULL)) { + physmem_block_free(block); + return NULL; + } + + return block; +} + void physmem_block_free(struct physmem_block *block) { if (block == NULL) @@ -547,7 +563,6 @@ exit_failure: block->va_reserved = NULL; block->va_reserved_size = 0; - while (mapped_cnt--) { hp = &pages[block->first + mapped_cnt]; munmap(hp->va, hp->size); diff --git a/platform/linux-generic/pktio/physmem/physmem.h b/platform/linux-generic/pktio/physmem/physmem.h index 77dcb3894..ea3e65674 100644 --- a/platform/linux-generic/pktio/physmem/physmem.h +++ b/platform/linux-generic/pktio/physmem/physmem.h @@ -37,6 +37,7 @@ struct physmem_block { int physmem_block_init_global(void); int physmem_block_term_global(void); +struct physmem_block *physmem_block_reserve(uint64_t size); struct physmem_block *physmem_block_alloc(uint64_t size); void physmem_block_free(struct physmem_block *block); int physmem_block_map(struct physmem_block *block, void *addr); |