env: add spdk_malloc

Signed-off-by: Jim Harris <james.r.harris@intel.com>
Change-Id: Ieaca9fdded2231c6d01101b345ac6c9a01608eef
This commit is contained in:
Jim Harris 2016-10-21 15:31:31 -07:00 committed by Ben Walker
parent cc1146a8b5
commit 1732eeb4bb
2 changed files with 18 additions and 4 deletions

View File

@ -49,6 +49,13 @@ extern "C" {
struct spdk_pci_device;
/**
* Allocate a pinned, physically contiguous memory buffer with the
* given size and alignment.
*/
void *
spdk_malloc(size_t size, size_t align, uint64_t *phys_addr);
/**
* Allocate a pinned, physically contiguous memory buffer with the
* given size and alignment. The buffer will be zeroed.

15
lib/env/env.c vendored
View File

@ -43,14 +43,21 @@
#include <rte_version.h>
void *
spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr)
spdk_malloc(size_t size, size_t align, uint64_t *phys_addr)
{
void *buf = rte_malloc(NULL, size, align);
if (buf && phys_addr) {
*phys_addr = rte_malloc_virt2phy(buf);
}
return buf;
}
void *
spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr)
{
void *buf = spdk_malloc(size, align, phys_addr);
if (buf) {
memset(buf, 0, size);
if (phys_addr) {
*phys_addr = rte_malloc_virt2phy(buf);
}
}
return buf;
}