env: Move malloc/free wrappers into env
Change-Id: Ief591f5e23c4ae06cb77fab647a7afd082450a73 Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
a4747c6048
commit
b9fbdd189a
@ -42,8 +42,23 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Allocate a pinned, physically contiguous memory buffer with the
|
||||||
|
* given size and alignment. The buffer will be zeroed.
|
||||||
|
*/
|
||||||
|
void *
|
||||||
|
spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Free a memory buffer previously allocated with spdk_malloc.
|
||||||
|
* This call is never made from the performance path.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
spdk_free(void *buf);
|
||||||
|
|
||||||
#define SPDK_VTOPHYS_ERROR (0xFFFFFFFFFFFFFFFFULL)
|
#define SPDK_VTOPHYS_ERROR (0xFFFFFFFFFFFFFFFFULL)
|
||||||
|
|
||||||
uint64_t spdk_vtophys(void *buf);
|
uint64_t spdk_vtophys(void *buf);
|
||||||
|
2
lib/env/Makefile
vendored
2
lib/env/Makefile
vendored
@ -35,7 +35,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
|
|||||||
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk
|
||||||
|
|
||||||
CFLAGS += $(DPDK_INC)
|
CFLAGS += $(DPDK_INC)
|
||||||
C_SRCS = vtophys.c
|
C_SRCS = env.c vtophys.c
|
||||||
LIBNAME = env
|
LIBNAME = env
|
||||||
|
|
||||||
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
|
include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk
|
||||||
|
56
lib/env/env.c
vendored
Normal file
56
lib/env/env.c
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*-
|
||||||
|
* BSD LICENSE
|
||||||
|
*
|
||||||
|
* Copyright (c) Intel Corporation.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in
|
||||||
|
* the documentation and/or other materials provided with the
|
||||||
|
* distribution.
|
||||||
|
* * Neither the name of Intel Corporation nor the names of its
|
||||||
|
* contributors may be used to endorse or promote products derived
|
||||||
|
* from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||||
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||||
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "spdk/env.h"
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <rte_config.h>
|
||||||
|
#include <rte_malloc.h>
|
||||||
|
|
||||||
|
void *
|
||||||
|
spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr)
|
||||||
|
{
|
||||||
|
void *buf = rte_malloc(NULL, size, align);
|
||||||
|
if (buf) {
|
||||||
|
memset(buf, 0, size);
|
||||||
|
*phys_addr = rte_malloc_virt2phy(buf);
|
||||||
|
}
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
spdk_free(void *buf)
|
||||||
|
{
|
||||||
|
return rte_free(buf);
|
||||||
|
}
|
@ -402,7 +402,7 @@ ioat_channel_start(struct spdk_ioat_chan *ioat)
|
|||||||
ioat->max_xfer_size = 1U << xfercap;
|
ioat->max_xfer_size = 1U << xfercap;
|
||||||
}
|
}
|
||||||
|
|
||||||
ioat->comp_update = ioat_zmalloc(NULL, sizeof(*ioat->comp_update), SPDK_IOAT_CHANCMP_ALIGN,
|
ioat->comp_update = ioat_zmalloc(sizeof(*ioat->comp_update), SPDK_IOAT_CHANCMP_ALIGN,
|
||||||
&comp_update_bus_addr);
|
&comp_update_bus_addr);
|
||||||
if (ioat->comp_update == NULL) {
|
if (ioat->comp_update == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -417,7 +417,7 @@ ioat_channel_start(struct spdk_ioat_chan *ioat)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ioat->hw_ring = ioat_zmalloc(NULL, num_descriptors * sizeof(union spdk_ioat_hw_desc), 64,
|
ioat->hw_ring = ioat_zmalloc(num_descriptors * sizeof(union spdk_ioat_hw_desc), 64,
|
||||||
&ioat->hw_ring_phys_addr);
|
&ioat->hw_ring_phys_addr);
|
||||||
if (!ioat->hw_ring) {
|
if (!ioat->hw_ring) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -30,22 +30,12 @@
|
|||||||
* Allocate a pinned, physically contiguous memory buffer with the
|
* Allocate a pinned, physically contiguous memory buffer with the
|
||||||
* given size and alignment.
|
* given size and alignment.
|
||||||
*/
|
*/
|
||||||
static inline void *
|
#define ioat_zmalloc spdk_zmalloc
|
||||||
ioat_zmalloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
|
||||||
{
|
|
||||||
void *buf = rte_malloc(tag, size, align);
|
|
||||||
|
|
||||||
if (buf) {
|
|
||||||
memset(buf, 0, size);
|
|
||||||
*phys_addr = rte_malloc_virt2phy(buf);
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free a memory buffer previously allocated with ioat_zmalloc.
|
* Free a memory buffer previously allocated with ioat_zmalloc.
|
||||||
*/
|
*/
|
||||||
#define ioat_free(buf) rte_free(buf)
|
#define ioat_free spdk_free
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the physical address for the specified virtual address.
|
* Return the physical address for the specified virtual address.
|
||||||
|
@ -51,7 +51,7 @@ nvme_attach(void *devhandle)
|
|||||||
int status;
|
int status;
|
||||||
uint64_t phys_addr = 0;
|
uint64_t phys_addr = 0;
|
||||||
|
|
||||||
ctrlr = nvme_malloc("nvme_ctrlr", sizeof(struct spdk_nvme_ctrlr),
|
ctrlr = nvme_malloc(sizeof(struct spdk_nvme_ctrlr),
|
||||||
64, &phys_addr);
|
64, &phys_addr);
|
||||||
if (ctrlr == NULL) {
|
if (ctrlr == NULL) {
|
||||||
SPDK_ERRLOG("could not allocate ctrlr\n");
|
SPDK_ERRLOG("could not allocate ctrlr\n");
|
||||||
@ -178,7 +178,7 @@ nvme_allocate_request_user_copy(void *buffer, uint32_t payload_size, spdk_nvme_c
|
|||||||
uint64_t phys_addr;
|
uint64_t phys_addr;
|
||||||
|
|
||||||
if (buffer && payload_size) {
|
if (buffer && payload_size) {
|
||||||
contig_buffer = nvme_malloc("nvme_user_copy", payload_size, 4096, &phys_addr);
|
contig_buffer = nvme_malloc(payload_size, 4096, &phys_addr);
|
||||||
if (!contig_buffer) {
|
if (!contig_buffer) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -247,8 +247,7 @@ static int nvme_ctrlr_set_intel_support_log_pages(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
struct nvme_completion_poll_status status;
|
struct nvme_completion_poll_status status;
|
||||||
struct spdk_nvme_intel_log_page_directory *log_page_directory;
|
struct spdk_nvme_intel_log_page_directory *log_page_directory;
|
||||||
|
|
||||||
log_page_directory = nvme_malloc("nvme_log_page_directory",
|
log_page_directory = nvme_malloc(sizeof(struct spdk_nvme_intel_log_page_directory),
|
||||||
sizeof(struct spdk_nvme_intel_log_page_directory),
|
|
||||||
64, &phys_addr);
|
64, &phys_addr);
|
||||||
if (log_page_directory == NULL) {
|
if (log_page_directory == NULL) {
|
||||||
SPDK_ERRLOG("could not allocate log_page_directory\n");
|
SPDK_ERRLOG("could not allocate log_page_directory\n");
|
||||||
@ -375,8 +374,7 @@ nvme_ctrlr_construct_io_qpairs(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
*/
|
*/
|
||||||
num_trackers = nvme_min(NVME_IO_TRACKERS, (num_entries - 1));
|
num_trackers = nvme_min(NVME_IO_TRACKERS, (num_entries - 1));
|
||||||
|
|
||||||
ctrlr->ioq = nvme_malloc("nvme_ioq",
|
ctrlr->ioq = nvme_malloc(ctrlr->opts.num_io_queues * sizeof(struct spdk_nvme_qpair),
|
||||||
ctrlr->opts.num_io_queues * sizeof(struct spdk_nvme_qpair),
|
|
||||||
64, &phys_addr);
|
64, &phys_addr);
|
||||||
|
|
||||||
if (ctrlr->ioq == NULL)
|
if (ctrlr->ioq == NULL)
|
||||||
@ -695,8 +693,7 @@ nvme_ctrlr_construct_namespaces(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctrlr->nsdata = nvme_malloc("nvme_namespaces",
|
ctrlr->nsdata = nvme_malloc(nn * sizeof(struct spdk_nvme_ns_data), 64,
|
||||||
nn * sizeof(struct spdk_nvme_ns_data), 64,
|
|
||||||
&phys_addr);
|
&phys_addr);
|
||||||
if (ctrlr->nsdata == NULL) {
|
if (ctrlr->nsdata == NULL) {
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -81,21 +81,12 @@
|
|||||||
* given size and alignment.
|
* given size and alignment.
|
||||||
* Note: these calls are only made during driver initialization.
|
* Note: these calls are only made during driver initialization.
|
||||||
*/
|
*/
|
||||||
static inline void *
|
#define nvme_malloc spdk_zmalloc
|
||||||
nvme_malloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
|
||||||
{
|
|
||||||
void *buf = rte_malloc(tag, size, align);
|
|
||||||
if (buf) {
|
|
||||||
memset(buf, 0, size);
|
|
||||||
*phys_addr = rte_malloc_virt2phy(buf);
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free a memory buffer previously allocated with nvme_malloc.
|
* Free a memory buffer previously allocated with nvme_malloc.
|
||||||
*/
|
*/
|
||||||
#define nvme_free(buf) rte_free(buf)
|
#define nvme_free spdk_free
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reserve a named, process shared memory zone with the given size,
|
* Reserve a named, process shared memory zone with the given size,
|
||||||
|
@ -556,8 +556,7 @@ nvme_qpair_construct(struct spdk_nvme_qpair *qpair, uint16_t id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (qpair->sq_in_cmb == false) {
|
if (qpair->sq_in_cmb == false) {
|
||||||
qpair->cmd = nvme_malloc("qpair_cmd",
|
qpair->cmd = nvme_malloc(qpair->num_entries * sizeof(struct spdk_nvme_cmd),
|
||||||
qpair->num_entries * sizeof(struct spdk_nvme_cmd),
|
|
||||||
0x1000,
|
0x1000,
|
||||||
&qpair->cmd_bus_addr);
|
&qpair->cmd_bus_addr);
|
||||||
if (qpair->cmd == NULL) {
|
if (qpair->cmd == NULL) {
|
||||||
@ -566,8 +565,7 @@ nvme_qpair_construct(struct spdk_nvme_qpair *qpair, uint16_t id,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
qpair->cpl = nvme_malloc("qpair_cpl",
|
qpair->cpl = nvme_malloc(qpair->num_entries * sizeof(struct spdk_nvme_cpl),
|
||||||
qpair->num_entries * sizeof(struct spdk_nvme_cpl),
|
|
||||||
0x1000,
|
0x1000,
|
||||||
&qpair->cpl_bus_addr);
|
&qpair->cpl_bus_addr);
|
||||||
if (qpair->cpl == NULL) {
|
if (qpair->cpl == NULL) {
|
||||||
@ -589,7 +587,7 @@ nvme_qpair_construct(struct spdk_nvme_qpair *qpair, uint16_t id,
|
|||||||
* This ensures the PRP list embedded in the nvme_tracker object will not span a
|
* This ensures the PRP list embedded in the nvme_tracker object will not span a
|
||||||
* 4KB boundary, while allowing access to trackers in tr[] via normal array indexing.
|
* 4KB boundary, while allowing access to trackers in tr[] via normal array indexing.
|
||||||
*/
|
*/
|
||||||
qpair->tr = nvme_malloc("nvme_tr", num_trackers * sizeof(*tr), sizeof(*tr), &phys_addr);
|
qpair->tr = nvme_malloc(num_trackers * sizeof(*tr), sizeof(*tr), &phys_addr);
|
||||||
if (qpair->tr == NULL) {
|
if (qpair->tr == NULL) {
|
||||||
SPDK_ERRLOG("nvme_tr failed\n");
|
SPDK_ERRLOG("nvme_tr failed\n");
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
struct spdk_pci_device;
|
struct spdk_pci_device;
|
||||||
|
|
||||||
static inline void *
|
static inline void *
|
||||||
ioat_zmalloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
ioat_zmalloc(size_t size, unsigned align, uint64_t *phys_addr)
|
||||||
{
|
{
|
||||||
return calloc(1, size);
|
return calloc(1, size);
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
struct spdk_pci_device;
|
struct spdk_pci_device;
|
||||||
|
|
||||||
static inline void *
|
static inline void *
|
||||||
nvme_malloc(const char *tag, size_t size, unsigned align, uint64_t *phys_addr)
|
nvme_malloc(size_t size, unsigned align, uint64_t *phys_addr)
|
||||||
{
|
{
|
||||||
void *buf = NULL;
|
void *buf = NULL;
|
||||||
if (posix_memalign(&buf, align, size)) {
|
if (posix_memalign(&buf, align, size)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user