2015-09-21 15:52:41 +00:00
|
|
|
/*-
|
|
|
|
* BSD LICENSE
|
|
|
|
*
|
2016-01-26 17:47:22 +00:00
|
|
|
* Copyright (c) Intel Corporation.
|
2017-04-11 04:36:05 +00:00
|
|
|
* Copyright (c) NetApp, Inc.
|
2015-09-21 15:52:41 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2016-04-29 18:04:33 +00:00
|
|
|
/** \file
|
2016-08-10 17:21:45 +00:00
|
|
|
* Encapsulated third-party dependencies
|
2016-04-29 18:04:33 +00:00
|
|
|
*/
|
|
|
|
|
2016-08-10 17:21:45 +00:00
|
|
|
#ifndef SPDK_ENV_H
|
|
|
|
#define SPDK_ENV_H
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2017-05-01 20:22:48 +00:00
|
|
|
#include "spdk/stdinc.h"
|
2018-12-01 16:49:52 +00:00
|
|
|
#include "spdk/queue.h"
|
2017-05-01 20:22:48 +00:00
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-27 17:04:08 +00:00
|
|
|
#define SPDK_ENV_SOCKET_ID_ANY (-1)
|
2017-10-10 16:30:57 +00:00
|
|
|
#define SPDK_ENV_LCORE_ID_ANY (UINT32_MAX)
|
2017-01-27 17:04:08 +00:00
|
|
|
|
2018-02-23 06:43:28 +00:00
|
|
|
/**
|
|
|
|
* Memory is dma-safe.
|
|
|
|
*/
|
|
|
|
#define SPDK_MALLOC_DMA 0x01
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Memory is sharable across process boundries.
|
|
|
|
*/
|
|
|
|
#define SPDK_MALLOC_SHARE 0x02
|
|
|
|
|
2018-06-27 07:31:22 +00:00
|
|
|
#define SPDK_MAX_MEMZONE_NAME_LEN 32
|
|
|
|
#define SPDK_MAX_MEMPOOL_NAME_LEN 29
|
|
|
|
|
2018-06-27 08:29:22 +00:00
|
|
|
/**
|
|
|
|
* Memzone flags
|
|
|
|
*/
|
|
|
|
#define SPDK_MEMZONE_NO_IOVA_CONTIG 0x00100000 /**< no iova contiguity */
|
|
|
|
|
2017-01-12 18:25:17 +00:00
|
|
|
/**
|
|
|
|
* \brief Environment initialization options
|
|
|
|
*/
|
|
|
|
struct spdk_env_opts {
|
2018-03-02 19:49:36 +00:00
|
|
|
const char *name;
|
|
|
|
const char *core_mask;
|
|
|
|
int shm_id;
|
|
|
|
int mem_channel;
|
|
|
|
int master_core;
|
2017-06-16 08:41:13 +00:00
|
|
|
int mem_size;
|
2017-06-14 07:31:55 +00:00
|
|
|
bool no_pci;
|
2018-02-23 08:19:09 +00:00
|
|
|
bool hugepage_single_segments;
|
2018-07-12 07:58:59 +00:00
|
|
|
bool unlink_hugepage;
|
2018-03-30 17:39:37 +00:00
|
|
|
size_t num_pci_addr;
|
2018-11-06 06:10:11 +00:00
|
|
|
const char *hugedir;
|
2018-03-30 17:39:37 +00:00
|
|
|
struct spdk_pci_addr *pci_blacklist;
|
|
|
|
struct spdk_pci_addr *pci_whitelist;
|
2017-10-10 20:35:44 +00:00
|
|
|
|
|
|
|
/** Opaque context for use of the env implementation. */
|
|
|
|
void *env_context;
|
2017-01-12 18:25:17 +00:00
|
|
|
};
|
|
|
|
|
2018-02-23 06:43:28 +00:00
|
|
|
/**
|
2018-10-29 07:02:30 +00:00
|
|
|
* Allocate dma/sharable memory based on a given dma_flg. It is a memory buffer
|
|
|
|
* with the given size, alignment and socket id.
|
2018-02-23 06:43:28 +00:00
|
|
|
*
|
|
|
|
* \param size Size in bytes.
|
|
|
|
* \param align Alignment value for the allocated memory. If '0', the allocated
|
|
|
|
* buffer is suitably aligned (in the same manner as malloc()). Otherwise, the
|
|
|
|
* allocated buffer is aligned to the multiple of align. In this case, it must
|
|
|
|
* be a power of two.
|
2019-03-15 13:13:46 +00:00
|
|
|
* \param phys_addr **Deprecated**. Please use spdk_vtophys() for retrieving physical
|
|
|
|
* addresses. A pointer to the variable to hold the physical address of
|
2018-02-23 06:43:28 +00:00
|
|
|
* the allocated buffer is passed. If NULL, the physical address is not returned.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
|
|
|
* \param flags Combination of SPDK_MALLOC flags (\ref SPDK_MALLOC_DMA, \ref SPDK_MALLOC_SHARE).
|
2018-05-08 18:06:01 +00:00
|
|
|
* At least one flag must be specified.
|
2018-02-23 06:43:28 +00:00
|
|
|
*
|
|
|
|
* \return a pointer to the allocated memory buffer.
|
|
|
|
*/
|
|
|
|
void *spdk_malloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint32_t flags);
|
|
|
|
|
|
|
|
/**
|
2018-10-29 07:02:30 +00:00
|
|
|
* Allocate dma/sharable memory based on a given dma_flg. It is a memory buffer
|
|
|
|
* with the given size, alignment and socket id. Also, the buffer will be zeroed.
|
2018-02-23 06:43:28 +00:00
|
|
|
*
|
|
|
|
* \param size Size in bytes.
|
|
|
|
* \param align Alignment value for the allocated memory. If '0', the allocated
|
|
|
|
* buffer is suitably aligned (in the same manner as malloc()). Otherwise, the
|
|
|
|
* allocated buffer is aligned to the multiple of align. In this case, it must
|
|
|
|
* be a power of two.
|
2019-03-15 13:13:46 +00:00
|
|
|
* \param phys_addr **Deprecated**. Please use spdk_vtophys() for retrieving physical
|
|
|
|
* addresses. A pointer to the variable to hold the physical address of
|
2018-02-23 06:43:28 +00:00
|
|
|
* the allocated buffer is passed. If NULL, the physical address is not returned.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
|
|
|
* \param flags Combination of SPDK_MALLOC flags (\ref SPDK_MALLOC_DMA, \ref SPDK_MALLOC_SHARE).
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated memory buffer.
|
|
|
|
*/
|
|
|
|
void *spdk_zmalloc(size_t size, size_t align, uint64_t *phys_addr, int socket_id, uint32_t flags);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free buffer memory that was previously allocated with spdk_malloc() or spdk_zmalloc().
|
|
|
|
*
|
|
|
|
* \param buf Buffer to free.
|
|
|
|
*/
|
|
|
|
void spdk_free(void *buf);
|
|
|
|
|
2017-01-12 18:25:17 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Initialize the default value of opts.
|
|
|
|
*
|
|
|
|
* \param opts Data structure where SPDK will initialize the default options.
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2017-01-12 18:25:17 +00:00
|
|
|
void spdk_env_opts_init(struct spdk_env_opts *opts);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Initialize the environment library. This must be called prior to using
|
2017-01-12 18:25:17 +00:00
|
|
|
* any other functions in this library.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param opts Environment initialization options.
|
|
|
|
* \return 0 on success, or negative errno on failure.
|
2017-04-25 17:35:22 +00:00
|
|
|
*/
|
2017-12-18 19:57:01 +00:00
|
|
|
int spdk_env_init(const struct spdk_env_opts *opts);
|
2017-01-12 18:25:17 +00:00
|
|
|
|
2016-10-21 22:31:31 +00:00
|
|
|
/**
|
2018-10-29 07:02:30 +00:00
|
|
|
* Allocate a pinned memory buffer with the given size and alignment.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param size Size in bytes.
|
|
|
|
* \param align Alignment value for the allocated memory. If '0', the allocated
|
|
|
|
* buffer is suitably aligned (in the same manner as malloc()). Otherwise, the
|
|
|
|
* allocated buffer is aligned to the multiple of align. In this case, it must
|
|
|
|
* be a power of two.
|
|
|
|
* \param phys_addr A pointer to the variable to hold the physical address of
|
|
|
|
* the allocated buffer is passed. If NULL, the physical address is not returned.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated memory buffer.
|
2016-10-21 22:31:31 +00:00
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_malloc(size_t size, size_t align, uint64_t *phys_addr);
|
2016-10-21 22:31:31 +00:00
|
|
|
|
2017-05-04 17:31:53 +00:00
|
|
|
/**
|
2018-10-29 07:02:30 +00:00
|
|
|
* Allocate a pinned, memory buffer with the given size, alignment and socket id.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param size Size in bytes.
|
|
|
|
* \param align Alignment value for the allocated memory. If '0', the allocated
|
|
|
|
* buffer is suitably aligned (in the same manner as malloc()). Otherwise, the
|
|
|
|
* allocated buffer is aligned to the multiple of align. In this case, it must
|
|
|
|
* be a power of two.
|
|
|
|
* \param phys_addr A pointer to the variable to hold the physical address of
|
|
|
|
* the allocated buffer is passed. If NULL, the physical address is not returned.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated memory buffer.
|
2017-05-04 17:31:53 +00:00
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_malloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id);
|
2017-05-04 17:31:53 +00:00
|
|
|
|
2016-08-10 17:37:12 +00:00
|
|
|
/**
|
2018-10-29 07:02:30 +00:00
|
|
|
* Allocate a pinned memory buffer with the given size and alignment. The buffer
|
|
|
|
* will be zeroed.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param size Size in bytes.
|
|
|
|
* \param align Alignment value for the allocated memory. If '0', the allocated
|
|
|
|
* buffer is suitably aligned (in the same manner as malloc()). Otherwise, the
|
|
|
|
* allocated buffer is aligned to the multiple of align. In this case, it must
|
|
|
|
* be a power of two.
|
|
|
|
* \param phys_addr A pointer to the variable to hold the physical address of
|
|
|
|
* the allocated buffer is passed. If NULL, the physical address is not returned.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated memory buffer.
|
2016-08-10 17:37:12 +00:00
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_zmalloc(size_t size, size_t align, uint64_t *phys_addr);
|
2016-08-10 17:37:12 +00:00
|
|
|
|
2017-05-04 17:31:53 +00:00
|
|
|
/**
|
2018-10-29 07:02:30 +00:00
|
|
|
* Allocate a pinned memory buffer with the given size, alignment and socket id.
|
|
|
|
* The buffer will be zeroed.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param size Size in bytes.
|
|
|
|
* \param align Alignment value for the allocated memory. If '0', the allocated
|
|
|
|
* buffer is suitably aligned (in the same manner as malloc()). Otherwise, the
|
|
|
|
* allocated buffer is aligned to the multiple of align. In this case, it must
|
|
|
|
* be a power of two.
|
|
|
|
* \param phys_addr A pointer to the variable to hold the physical address of
|
|
|
|
* the allocated buffer is passed. If NULL, the physical address is not returned.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated memory buffer.
|
2017-05-04 17:31:53 +00:00
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_zmalloc_socket(size_t size, size_t align, uint64_t *phys_addr, int socket_id);
|
2017-05-04 17:31:53 +00:00
|
|
|
|
2016-11-07 08:19:31 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Resize the allocated and pinned memory buffer with the given new size and
|
|
|
|
* alignment. Existing contents are preserved.
|
|
|
|
*
|
|
|
|
* \param buf Buffer to resize.
|
|
|
|
* \param size Size in bytes.
|
|
|
|
* \param align Alignment value for the allocated memory. If '0', the allocated
|
|
|
|
* buffer is suitably aligned (in the same manner as malloc()). Otherwise, the
|
|
|
|
* allocated buffer is aligned to the multiple of align. In this case, it must
|
|
|
|
* be a power of two.
|
|
|
|
* \param phys_addr A pointer to the variable to hold the physical address of
|
|
|
|
* the allocated buffer is passed. If NULL, the physical address is not returned.
|
|
|
|
*
|
|
|
|
* \return a pointer to the resized memory buffer.
|
2016-11-07 08:19:31 +00:00
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void *spdk_dma_realloc(void *buf, size_t size, size_t align, uint64_t *phys_addr);
|
2016-11-07 08:19:31 +00:00
|
|
|
|
2016-08-10 17:37:12 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Free a memory buffer previously allocated, for example from spdk_dma_zmalloc().
|
|
|
|
* This call is never made from the performance path.
|
|
|
|
*
|
|
|
|
* \param buf Buffer to free.
|
2016-08-10 17:37:12 +00:00
|
|
|
*/
|
2017-05-25 18:21:30 +00:00
|
|
|
void spdk_dma_free(void *buf);
|
2016-08-10 17:37:12 +00:00
|
|
|
|
2016-09-08 21:30:58 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Reserve a named, process shared memory zone with the given size, socket_id
|
2018-10-29 07:02:30 +00:00
|
|
|
* and flags. Unless `SPDK_MEMZONE_NO_IOVA_CONTIG` flag is provided, the returned
|
|
|
|
* memory will be IOVA contiguous.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param name Name to set for this memory zone.
|
|
|
|
* \param len Length in bytes.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
|
|
|
* \param flags Flags to set for this memory zone.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated memory address on success, or NULL on failure.
|
2016-09-08 21:30:58 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void *spdk_memzone_reserve(const char *name, size_t len, int socket_id, unsigned flags);
|
2016-09-08 21:30:58 +00:00
|
|
|
|
2018-06-27 09:25:36 +00:00
|
|
|
/**
|
|
|
|
* Reserve a named, process shared memory zone with the given size, socket_id,
|
2018-10-29 07:02:30 +00:00
|
|
|
* flags and alignment. Unless `SPDK_MEMZONE_NO_IOVA_CONTIG` flag is provided,
|
|
|
|
* the returned memory will be IOVA contiguous.
|
2018-06-27 09:25:36 +00:00
|
|
|
*
|
|
|
|
* \param name Name to set for this memory zone.
|
|
|
|
* \param len Length in bytes.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
|
|
|
* \param flags Flags to set for this memory zone.
|
|
|
|
* \param align Alignment for resulting memzone. Must be a power of 2.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated memory address on success, or NULL on failure.
|
|
|
|
*/
|
|
|
|
void *spdk_memzone_reserve_aligned(const char *name, size_t len, int socket_id,
|
|
|
|
unsigned flags, unsigned align);
|
|
|
|
|
2016-09-08 21:30:58 +00:00
|
|
|
/**
|
|
|
|
* Lookup the memory zone identified by the given name.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param name Name of the memory zone.
|
|
|
|
*
|
|
|
|
* \return a pointer to the reserved memory address on success, or NULL on failure.
|
2016-09-08 21:30:58 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void *spdk_memzone_lookup(const char *name);
|
2016-09-08 21:30:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the memory zone identified by the given name.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
2016-09-08 21:30:58 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
int spdk_memzone_free(const char *name);
|
2016-09-08 21:30:58 +00:00
|
|
|
|
2016-10-03 21:26:07 +00:00
|
|
|
/**
|
|
|
|
* Dump debug information about all memzones.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param f File to write debug information to.
|
2016-10-03 21:26:07 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void spdk_memzone_dump(FILE *f);
|
2016-10-03 21:26:07 +00:00
|
|
|
|
2016-09-28 14:58:51 +00:00
|
|
|
struct spdk_mempool;
|
|
|
|
|
2017-08-16 17:05:24 +00:00
|
|
|
#define SPDK_MEMPOOL_DEFAULT_CACHE_SIZE SIZE_MAX
|
|
|
|
|
2016-09-28 14:58:51 +00:00
|
|
|
/**
|
2017-08-16 17:05:24 +00:00
|
|
|
* Create a thread-safe memory pool.
|
2017-01-25 20:35:40 +00:00
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param name Name for the memory pool.
|
|
|
|
* \param count Count of elements.
|
|
|
|
* \param ele_size Element size in bytes.
|
2017-08-16 17:05:24 +00:00
|
|
|
* \param cache_size How many elements may be cached in per-core caches. Use
|
2018-03-12 05:10:49 +00:00
|
|
|
* SPDK_MEMPOOL_DEFAULT_CACHE_SIZE for a reasonable default, or 0 for no per-core cache.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
|
|
|
*
|
|
|
|
* \return a pointer to the created memory pool.
|
2016-09-28 14:58:51 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
struct spdk_mempool *spdk_mempool_create(const char *name, size_t count,
|
2017-01-25 20:35:40 +00:00
|
|
|
size_t ele_size, size_t cache_size, int socket_id);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
2017-12-11 04:37:27 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* An object callback function for memory pool.
|
2017-12-11 04:37:27 +00:00
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* Used by spdk_mempool_create_ctor().
|
2017-12-11 04:37:27 +00:00
|
|
|
*/
|
|
|
|
typedef void (spdk_mempool_obj_cb_t)(struct spdk_mempool *mp,
|
|
|
|
void *opaque, void *obj, unsigned obj_idx);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Create a thread-safe memory pool with user provided initialization function
|
|
|
|
* and argument.
|
2017-12-11 04:37:27 +00:00
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param name Name for the memory pool.
|
|
|
|
* \param count Count of elements.
|
|
|
|
* \param ele_size Element size in bytes.
|
2017-12-11 04:37:27 +00:00
|
|
|
* \param cache_size How many elements may be cached in per-core caches. Use
|
2018-03-12 05:10:49 +00:00
|
|
|
* SPDK_MEMPOOL_DEFAULT_CACHE_SIZE for a reasonable default, or 0 for no per-core cache.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
2017-12-20 10:58:33 +00:00
|
|
|
* \param obj_init User provided object calllback initialization function.
|
|
|
|
* \param obj_init_arg User provided callback initialization function argument.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return a pointer to the created memory pool.
|
2017-12-11 04:37:27 +00:00
|
|
|
*/
|
|
|
|
struct spdk_mempool *spdk_mempool_create_ctor(const char *name, size_t count,
|
|
|
|
size_t ele_size, size_t cache_size, int socket_id,
|
|
|
|
spdk_mempool_obj_cb_t *obj_init, void *obj_init_arg);
|
|
|
|
|
2017-12-08 09:01:12 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Get the name of a memory pool.
|
|
|
|
*
|
|
|
|
* \param mp Memory pool to query.
|
|
|
|
*
|
|
|
|
* \return the name of the memory pool.
|
2017-12-08 09:01:12 +00:00
|
|
|
*/
|
|
|
|
char *spdk_mempool_get_name(struct spdk_mempool *mp);
|
|
|
|
|
2016-09-28 14:58:51 +00:00
|
|
|
/**
|
|
|
|
* Free a memory pool.
|
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void spdk_mempool_free(struct spdk_mempool *mp);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an element from a memory pool. If no elements remain, return NULL.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param mp Memory pool to query.
|
|
|
|
*
|
|
|
|
* \return a pointer to the element.
|
2016-09-28 14:58:51 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void *spdk_mempool_get(struct spdk_mempool *mp);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
2018-04-18 23:25:05 +00:00
|
|
|
/**
|
|
|
|
* Get multiple elements from a memory pool.
|
|
|
|
*
|
|
|
|
* \param mp Memory pool to get multiple elements from.
|
|
|
|
* \param ele_arr Array of the elements to fill.
|
|
|
|
* \param count Count of elements to get.
|
|
|
|
*
|
|
|
|
* \return 0 on success, negative errno on failure.
|
|
|
|
*/
|
|
|
|
int spdk_mempool_get_bulk(struct spdk_mempool *mp, void **ele_arr, size_t count);
|
|
|
|
|
2016-09-28 14:58:51 +00:00
|
|
|
/**
|
|
|
|
* Put an element back into the memory pool.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param mp Memory pool to put element back into.
|
|
|
|
* \param ele Element to put.
|
2016-09-28 14:58:51 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
void spdk_mempool_put(struct spdk_mempool *mp, void *ele);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
2016-11-02 20:31:33 +00:00
|
|
|
/**
|
|
|
|
* Put multiple elements back into the memory pool.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param mp Memory pool to put multiple elements back into.
|
|
|
|
* \param ele_arr Array of the elements to put.
|
|
|
|
* \param count Count of elements to put.
|
2016-11-02 20:31:33 +00:00
|
|
|
*/
|
2018-06-28 21:03:43 +00:00
|
|
|
void spdk_mempool_put_bulk(struct spdk_mempool *mp, void **ele_arr, size_t count);
|
2016-11-02 20:31:33 +00:00
|
|
|
|
2017-04-11 04:36:05 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Get the number of entries in the memory pool.
|
|
|
|
*
|
|
|
|
* \param pool Memory pool to query.
|
|
|
|
*
|
|
|
|
* \return the number of entries in the memory pool.
|
2017-04-11 04:36:05 +00:00
|
|
|
*/
|
|
|
|
size_t spdk_mempool_count(const struct spdk_mempool *pool);
|
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Get the number of dedicated CPU cores utilized by this env abstraction.
|
|
|
|
*
|
|
|
|
* \return the number of dedicated CPU cores.
|
2017-03-27 19:59:40 +00:00
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_core_count(void);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Get the CPU core index of the current thread.
|
2017-10-10 16:30:57 +00:00
|
|
|
*
|
|
|
|
* This will only function when called from threads set up by
|
2018-03-12 05:10:49 +00:00
|
|
|
* this environment abstraction. For any other threads \c SPDK_ENV_LCORE_ID_ANY
|
|
|
|
* will be returned.
|
|
|
|
*
|
|
|
|
* \return the CPU core index of the current thread.
|
2017-03-27 19:59:40 +00:00
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_current_core(void);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Get the index of the first dedicated CPU core for this application.
|
|
|
|
*
|
|
|
|
* \return the index of the first dedicated CPU core.
|
2017-03-27 19:59:40 +00:00
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_first_core(void);
|
|
|
|
|
2017-12-22 00:21:35 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Get the index of the last dedicated CPU core for this application.
|
|
|
|
*
|
|
|
|
* \return the index of the last dedicated CPU core.
|
2017-12-22 00:21:35 +00:00
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_last_core(void);
|
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Get the index of the next dedicated CPU core for this application.
|
|
|
|
*
|
|
|
|
* If there is no next core, return UINT32_MAX.
|
|
|
|
*
|
|
|
|
* \param prev_core Index of previous core.
|
|
|
|
*
|
|
|
|
* \return the index of the next dedicated CPU core.
|
2017-03-27 19:59:40 +00:00
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_next_core(uint32_t prev_core);
|
|
|
|
|
2017-04-03 22:02:49 +00:00
|
|
|
#define SPDK_ENV_FOREACH_CORE(i) \
|
|
|
|
for (i = spdk_env_get_first_core(); \
|
|
|
|
i < UINT32_MAX; \
|
|
|
|
i = spdk_env_get_next_core(i))
|
|
|
|
|
2017-03-27 19:59:40 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Get the socket ID for the given core.
|
|
|
|
*
|
|
|
|
* \param core CPU core to query.
|
|
|
|
*
|
|
|
|
* \return the socket ID for the given core.
|
2017-03-27 19:59:40 +00:00
|
|
|
*/
|
|
|
|
uint32_t spdk_env_get_socket_id(uint32_t core);
|
2016-09-28 14:58:51 +00:00
|
|
|
|
2017-06-02 18:40:23 +00:00
|
|
|
typedef int (*thread_start_fn)(void *);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Launch a thread pinned to the given core. Only a single pinned thread may be
|
|
|
|
* launched per core. Subsequent attempts to launch pinned threads on that core
|
|
|
|
* will fail.
|
2017-06-02 18:40:23 +00:00
|
|
|
*
|
|
|
|
* \param core The core to pin the thread to.
|
|
|
|
* \param fn Entry point on the new thread.
|
|
|
|
* \param arg Argument apssed to thread_start_fn
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, negative errno on failure.
|
2017-06-02 18:40:23 +00:00
|
|
|
*/
|
|
|
|
int spdk_env_thread_launch_pinned(uint32_t core, thread_start_fn fn, void *arg);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Wait for all threads to exit before returning.
|
2017-06-02 18:40:23 +00:00
|
|
|
*/
|
|
|
|
void spdk_env_thread_wait_all(void);
|
|
|
|
|
2016-09-08 21:30:58 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Check whether the calling process is primary process.
|
|
|
|
*
|
|
|
|
* \return true if the calling process is primary process, or false otherwise.
|
2016-09-08 21:30:58 +00:00
|
|
|
*/
|
2016-11-15 20:35:07 +00:00
|
|
|
bool spdk_process_is_primary(void);
|
2016-09-08 21:30:58 +00:00
|
|
|
|
2016-08-10 20:12:33 +00:00
|
|
|
/**
|
|
|
|
* Get a monotonic timestamp counter.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return the monotonic timestamp counter.
|
2016-08-10 20:12:33 +00:00
|
|
|
*/
|
|
|
|
uint64_t spdk_get_ticks(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the tick rate of spdk_get_ticks() per second.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return the tick rate of spdk_get_ticks() per second.
|
2016-08-10 20:12:33 +00:00
|
|
|
*/
|
|
|
|
uint64_t spdk_get_ticks_hz(void);
|
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Delay the given number of microseconds.
|
|
|
|
*
|
|
|
|
* \param us Number of microseconds.
|
2016-08-10 20:12:33 +00:00
|
|
|
*/
|
|
|
|
void spdk_delay_us(unsigned int us);
|
|
|
|
|
2018-12-07 19:04:03 +00:00
|
|
|
/**
|
|
|
|
* Pause CPU execution for a short while
|
|
|
|
*/
|
|
|
|
void spdk_pause(void);
|
|
|
|
|
2017-05-09 17:48:16 +00:00
|
|
|
struct spdk_ring;
|
|
|
|
|
|
|
|
enum spdk_ring_type {
|
2017-05-24 12:34:12 +00:00
|
|
|
SPDK_RING_TYPE_SP_SC, /* Single-producer, single-consumer */
|
2017-05-09 17:48:16 +00:00
|
|
|
SPDK_RING_TYPE_MP_SC, /* Multi-producer, single-consumer */
|
2018-09-19 23:15:24 +00:00
|
|
|
SPDK_RING_TYPE_MP_MC, /* Multi-producer, multi-consumer */
|
2017-05-09 17:48:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Create a ring.
|
|
|
|
*
|
|
|
|
* \param type Type for the ring. (SPDK_RING_TYPE_SP_SC or SPDK_RING_TYPE_MP_SC).
|
|
|
|
* \param count Size of the ring in elements.
|
|
|
|
* \param socket_id Socket ID to allocate memory on, or SPDK_ENV_SOCKET_ID_ANY
|
|
|
|
* for any socket.
|
|
|
|
*
|
|
|
|
* \return a pointer to the created ring.
|
2017-05-09 17:48:16 +00:00
|
|
|
*/
|
2017-05-24 12:46:55 +00:00
|
|
|
struct spdk_ring *spdk_ring_create(enum spdk_ring_type type, size_t count, int socket_id);
|
2017-05-09 17:48:16 +00:00
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Free the ring.
|
|
|
|
*
|
|
|
|
* \param ring Ring to free.
|
2017-05-09 17:48:16 +00:00
|
|
|
*/
|
|
|
|
void spdk_ring_free(struct spdk_ring *ring);
|
|
|
|
|
2017-10-18 06:07:26 +00:00
|
|
|
/**
|
|
|
|
* Get the number of objects in the ring.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param ring the ring.
|
|
|
|
*
|
|
|
|
* \return the number of objects in the ring.
|
2017-10-18 06:07:26 +00:00
|
|
|
*/
|
|
|
|
size_t spdk_ring_count(struct spdk_ring *ring);
|
|
|
|
|
2017-05-09 17:48:16 +00:00
|
|
|
/**
|
|
|
|
* Queue the array of objects (with length count) on the ring.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param ring A pointer to the ring.
|
|
|
|
* \param objs A pointer to the array to be queued.
|
|
|
|
* \param count Length count of the array of objects.
|
|
|
|
*
|
|
|
|
* \return the number of objects enqueued.
|
2017-05-09 17:48:16 +00:00
|
|
|
*/
|
|
|
|
size_t spdk_ring_enqueue(struct spdk_ring *ring, void **objs, size_t count);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dequeue count objects from the ring into the array objs.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param ring A pointer to the ring.
|
|
|
|
* \param objs A pointer to the array to be dequeued.
|
|
|
|
* \param count Maximum number of elements to be dequeued.
|
|
|
|
*
|
|
|
|
* \return the number of objects dequeued which is less than 'count'.
|
2017-05-09 17:48:16 +00:00
|
|
|
*/
|
|
|
|
size_t spdk_ring_dequeue(struct spdk_ring *ring, void **objs, size_t count);
|
|
|
|
|
2019-02-28 23:57:03 +00:00
|
|
|
/**
|
|
|
|
* Reports whether the SPDK application is using the IOMMU for DMA
|
|
|
|
*
|
|
|
|
* \return True if we are using the IOMMU, false otherwise.
|
|
|
|
*/
|
|
|
|
bool spdk_iommu_is_enabled(void);
|
|
|
|
|
2016-02-08 21:17:04 +00:00
|
|
|
#define SPDK_VTOPHYS_ERROR (0xFFFFFFFFFFFFFFFFULL)
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
|
|
|
* Get the physical address of a buffer.
|
|
|
|
*
|
|
|
|
* \param buf A pointer to a buffer.
|
2018-12-28 11:59:21 +00:00
|
|
|
* \param size Contains the size of the memory region pointed to by vaddr.
|
|
|
|
* If vaddr is successfully translated, then this is updated with the size of
|
|
|
|
* the memory region for which the translation is valid.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return the physical address of this buffer on success, or SPDK_VTOPHYS_ERROR
|
|
|
|
* on failure.
|
|
|
|
*/
|
2018-12-28 11:59:21 +00:00
|
|
|
uint64_t spdk_vtophys(void *buf, uint64_t *size);
|
2015-09-21 15:52:41 +00:00
|
|
|
|
2016-10-08 00:01:54 +00:00
|
|
|
struct spdk_pci_addr {
|
2017-06-21 22:05:47 +00:00
|
|
|
uint32_t domain;
|
2016-10-08 00:01:54 +00:00
|
|
|
uint8_t bus;
|
|
|
|
uint8_t dev;
|
|
|
|
uint8_t func;
|
|
|
|
};
|
|
|
|
|
2016-10-28 18:11:45 +00:00
|
|
|
struct spdk_pci_id {
|
|
|
|
uint16_t vendor_id;
|
|
|
|
uint16_t device_id;
|
|
|
|
uint16_t subvendor_id;
|
|
|
|
uint16_t subdevice_id;
|
|
|
|
};
|
|
|
|
|
2018-12-01 16:49:52 +00:00
|
|
|
struct spdk_pci_device {
|
|
|
|
void *dev_handle;
|
|
|
|
struct spdk_pci_addr addr;
|
|
|
|
struct spdk_pci_id id;
|
|
|
|
int socket_id;
|
|
|
|
|
2018-11-29 09:24:05 +00:00
|
|
|
int (*map_bar)(struct spdk_pci_device *dev, uint32_t bar,
|
|
|
|
void **mapped_addr, uint64_t *phys_addr, uint64_t *size);
|
|
|
|
int (*unmap_bar)(struct spdk_pci_device *dev, uint32_t bar,
|
|
|
|
void *addr);
|
|
|
|
int (*cfg_read)(struct spdk_pci_device *dev, void *value,
|
|
|
|
uint32_t len, uint32_t offset);
|
|
|
|
int (*cfg_write)(struct spdk_pci_device *dev, void *value,
|
|
|
|
uint32_t len, uint32_t offset);
|
|
|
|
void (*detach)(struct spdk_pci_device *dev);
|
|
|
|
|
2018-12-01 16:49:52 +00:00
|
|
|
struct _spdk_pci_device_internal {
|
|
|
|
struct spdk_pci_driver *driver;
|
|
|
|
bool attached;
|
|
|
|
TAILQ_ENTRY(spdk_pci_device) tailq;
|
|
|
|
} internal;
|
|
|
|
};
|
|
|
|
|
2016-08-10 17:41:12 +00:00
|
|
|
typedef int (*spdk_pci_enum_cb)(void *enum_ctx, struct spdk_pci_device *pci_dev);
|
|
|
|
|
2018-11-29 09:24:05 +00:00
|
|
|
/**
|
|
|
|
* Get the NVMe PCI driver object.
|
|
|
|
*
|
|
|
|
* \return PCI driver.
|
|
|
|
*/
|
|
|
|
struct spdk_pci_driver *spdk_pci_nvme_get_driver(void);
|
|
|
|
|
2018-12-07 10:47:55 +00:00
|
|
|
/**
|
|
|
|
* Get the I/OAT PCI driver object.
|
|
|
|
*
|
|
|
|
* \return PCI driver.
|
|
|
|
*/
|
|
|
|
struct spdk_pci_driver *spdk_pci_ioat_get_driver(void);
|
|
|
|
|
2018-12-07 10:51:02 +00:00
|
|
|
/**
|
|
|
|
* Get the Virtio PCI driver object.
|
|
|
|
*
|
|
|
|
* \return PCI driver.
|
|
|
|
*/
|
|
|
|
struct spdk_pci_driver *spdk_pci_virtio_get_driver(void);
|
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-02 14:16:19 +00:00
|
|
|
* Enumerate all PCI devices supported by the provided driver and try to
|
|
|
|
* attach those that weren't attached yet. The provided callback will be
|
|
|
|
* called for each such device and its return code will decide whether that
|
|
|
|
* device is attached or not. Attached devices have to be manually detached
|
|
|
|
* with spdk_pci_device_detach() to be attach-able again.
|
|
|
|
*
|
|
|
|
* \param driver Driver for a specific device type.
|
|
|
|
* \param enum_cb Callback to be called for each non-attached PCI device.
|
2018-12-01 12:54:37 +00:00
|
|
|
* The return code can be as follows:
|
|
|
|
* -1 - device was not attached, the enumeration is stopped
|
|
|
|
* 0 - device attached successfully, enumeration continues
|
|
|
|
* 1 - device was not attached, enumeration continues
|
|
|
|
* \param enum_ctx Additional context passed to the callback function.
|
|
|
|
*
|
|
|
|
* \return -1 if an internal error occured or the provided callback returned -1,
|
|
|
|
* 0 otherwise
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2018-12-02 14:16:19 +00:00
|
|
|
int spdk_pci_enumerate(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb, void *enum_ctx);
|
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Map a PCI BAR in the current process.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param bar BAR number.
|
|
|
|
* \param mapped_addr A variable to store the virtual address of the mapping.
|
|
|
|
* \param phys_addr A variable to store the physical address of the mapping.
|
|
|
|
* \param size A variable to store the size of the bar (in bytes).
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success.
|
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_map_bar(struct spdk_pci_device *dev, uint32_t bar,
|
|
|
|
void **mapped_addr, uint64_t *phys_addr, uint64_t *size);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Unmap a PCI BAR from the current process. This happens automatically when
|
|
|
|
* the PCI device is detached.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param bar BAR number.
|
|
|
|
* \param mapped_addr Virtual address of the bar.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success.
|
|
|
|
*/
|
2018-12-01 12:54:37 +00:00
|
|
|
int spdk_pci_device_unmap_bar(struct spdk_pci_device *dev, uint32_t bar,
|
|
|
|
void *mapped_addr);
|
2016-08-10 17:41:12 +00:00
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Get the domain of a PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return PCI device domain.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2017-06-21 22:05:47 +00:00
|
|
|
uint32_t spdk_pci_device_get_domain(struct spdk_pci_device *dev);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Get the bus number of a PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return PCI bus number.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
uint8_t spdk_pci_device_get_bus(struct spdk_pci_device *dev);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Get the device number within the PCI bus the device is on.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return PCI device number.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
uint8_t spdk_pci_device_get_dev(struct spdk_pci_device *dev);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Get the particular function number represented by struct spdk_pci_device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return PCI function number.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
uint8_t spdk_pci_device_get_func(struct spdk_pci_device *dev);
|
2016-10-28 18:00:18 +00:00
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Get the full DomainBDF address of a PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return PCI address.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-10-28 18:00:18 +00:00
|
|
|
struct spdk_pci_addr spdk_pci_device_get_addr(struct spdk_pci_device *dev);
|
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
|
|
|
* Get the vendor ID of a PCI device.
|
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return vendor ID.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
uint16_t spdk_pci_device_get_vendor_id(struct spdk_pci_device *dev);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the device ID of a PCI device.
|
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return device ID.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
uint16_t spdk_pci_device_get_device_id(struct spdk_pci_device *dev);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the subvendor ID of a PCI device.
|
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return subvendor ID.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
uint16_t spdk_pci_device_get_subvendor_id(struct spdk_pci_device *dev);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the subdevice ID of a PCI device.
|
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return subdevice ID.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
uint16_t spdk_pci_device_get_subdevice_id(struct spdk_pci_device *dev);
|
2016-10-28 18:11:45 +00:00
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Get the PCI ID of a PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return PCI ID.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-10-28 18:11:45 +00:00
|
|
|
struct spdk_pci_id spdk_pci_device_get_id(struct spdk_pci_device *dev);
|
|
|
|
|
2017-01-31 00:39:23 +00:00
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Get the NUMA node the PCI device is on.
|
2017-01-31 00:39:23 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
2017-01-31 00:39:23 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return NUMA node index (>= 0).
|
2017-01-31 00:39:23 +00:00
|
|
|
*/
|
|
|
|
int spdk_pci_device_get_socket_id(struct spdk_pci_device *dev);
|
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Serialize the PCIe Device Serial Number into the provided buffer.
|
|
|
|
* The buffer will contain a 16-character-long serial number followed by
|
|
|
|
* a NULL terminator.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param dev PCI device.
|
|
|
|
* \param sn Buffer to store the serial number in.
|
|
|
|
* \param len Length of buffer. Must be at least 17.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_get_serial_number(struct spdk_pci_device *dev, char *sn, size_t len);
|
2017-11-02 23:54:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Claim a PCI device for exclusive SPDK userspace access.
|
|
|
|
*
|
|
|
|
* Uses F_SETLK on a shared memory file with the PCI address embedded in its name.
|
2018-03-12 05:10:49 +00:00
|
|
|
* As long as this file remains open with the lock acquired, other processes will
|
|
|
|
* not be able to successfully call this function on the same PCI device.
|
2017-11-02 23:54:51 +00:00
|
|
|
*
|
|
|
|
* \param pci_addr PCI address of the device to claim
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \return -1 if the device has already been claimed, an fd otherwise. This fd
|
|
|
|
* should be closed when the application no longer needs access to the PCI device
|
|
|
|
* (including when it is hot removed).
|
2017-11-02 23:54:51 +00:00
|
|
|
*/
|
2016-10-31 23:01:52 +00:00
|
|
|
int spdk_pci_device_claim(const struct spdk_pci_addr *pci_addr);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Release all resources associated with the given device and detach it. As long
|
|
|
|
* as the PCI device is physically available, it will attachable again.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param device PCI device.
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2016-11-15 01:53:14 +00:00
|
|
|
void spdk_pci_device_detach(struct spdk_pci_device *device);
|
2016-12-05 17:20:20 +00:00
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-02 14:16:19 +00:00
|
|
|
* Attach a PCI device. This will bypass all blacklist rules and explicitly
|
|
|
|
* attach a device at the provided address. The return code of the provided
|
|
|
|
* callback will decide whether that device is attached or not. Attached
|
|
|
|
* devices have to be manually detached with spdk_pci_device_detach() to be
|
|
|
|
* attach-able again.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-02 14:16:19 +00:00
|
|
|
* \param driver Driver for a specific device type. The device will only be
|
|
|
|
* attached if it's supported by this driver.
|
|
|
|
* \param enum_cb Callback to be called for the PCI device once it's found.
|
2018-12-01 12:54:37 +00:00
|
|
|
* The return code can be as follows:
|
|
|
|
* -1, 1 - an error occured, fail the attach request entirely
|
|
|
|
* 0 - device attached successfully
|
|
|
|
* \param enum_ctx Additional context passed to the callback function.
|
|
|
|
* \param pci_address Address of the device to attach.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-12-01 12:54:37 +00:00
|
|
|
* \return -1 if a device at the provided PCI address couldn't be found,
|
|
|
|
* -1 if an internal error happened or the provided callback returned non-zero,
|
|
|
|
* 0 otherwise
|
2018-03-12 05:10:49 +00:00
|
|
|
*/
|
2018-12-02 14:16:19 +00:00
|
|
|
int spdk_pci_device_attach(struct spdk_pci_driver *driver, spdk_pci_enum_cb enum_cb,
|
|
|
|
void *enum_ctx, struct spdk_pci_addr *pci_address);
|
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Read \c len bytes from the PCI configuration space.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param buf A buffer to copy the data into.
|
|
|
|
* \param len Number of bytes to read.
|
|
|
|
* \param offset Offset (in bytes) in the PCI config space to start reading from.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2018-12-01 12:54:37 +00:00
|
|
|
int spdk_pci_device_cfg_read(struct spdk_pci_device *dev, void *buf, uint32_t len,
|
2017-09-21 16:59:10 +00:00
|
|
|
uint32_t offset);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Write \c len bytes into the PCI configuration space.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param buf A buffer to copy the data from.
|
|
|
|
* \param len Number of bytes to write.
|
|
|
|
* \param offset Offset (in bytes) in the PCI config space to start writing to.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2018-12-01 12:54:37 +00:00
|
|
|
int spdk_pci_device_cfg_write(struct spdk_pci_device *dev, void *buf, uint32_t len,
|
2017-09-21 16:59:10 +00:00
|
|
|
uint32_t offset);
|
2018-12-01 12:54:37 +00:00
|
|
|
|
2018-03-12 05:10:49 +00:00
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Read 1 byte from the PCI configuration space.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param value A buffer to copy the data into.
|
|
|
|
* \param offset Offset (in bytes) in the PCI config space to start reading from.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_cfg_read8(struct spdk_pci_device *dev, uint8_t *value, uint32_t offset);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Write 1 byte into the PCI configuration space.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
|
|
|
* \param value A value to write.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param offset Offset (in bytes) in the PCI config space to start writing to.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_cfg_write8(struct spdk_pci_device *dev, uint8_t value, uint32_t offset);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Read 2 bytes from the PCI configuration space.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param value A buffer to copy the data into.
|
|
|
|
* \param offset Offset (in bytes) in the PCI config space to start reading from.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_cfg_read16(struct spdk_pci_device *dev, uint16_t *value, uint32_t offset);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Write 2 bytes into the PCI configuration space.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
|
|
|
* \param value A value to write.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param offset Offset (in bytes) in the PCI config space to start writing to.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_cfg_write16(struct spdk_pci_device *dev, uint16_t value, uint32_t offset);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Read 4 bytes from the PCI configuration space.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param value A buffer to copy the data into.
|
|
|
|
* \param offset Offset (in bytes) in the PCI config space to start reading from.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_cfg_read32(struct spdk_pci_device *dev, uint32_t *value, uint32_t offset);
|
2018-03-12 05:10:49 +00:00
|
|
|
|
|
|
|
/**
|
2018-12-01 12:54:37 +00:00
|
|
|
* Write 4 bytes into the PCI configuration space.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param dev PCI device.
|
|
|
|
* \param value A value to write.
|
2018-12-01 12:54:37 +00:00
|
|
|
* \param offset Offset (in bytes) in the PCI config space to start writing to.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, -1 on failure.
|
|
|
|
*/
|
2016-08-10 17:41:12 +00:00
|
|
|
int spdk_pci_device_cfg_write32(struct spdk_pci_device *dev, uint32_t value, uint32_t offset);
|
|
|
|
|
2016-10-28 18:00:18 +00:00
|
|
|
/**
|
|
|
|
* Compare two PCI addresses.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param a1 PCI address 1.
|
|
|
|
* \param a2 PCI address 2.
|
|
|
|
*
|
2016-10-28 18:00:18 +00:00
|
|
|
* \return 0 if a1 == a2, less than 0 if a1 < a2, greater than 0 if a1 > a2
|
|
|
|
*/
|
|
|
|
int spdk_pci_addr_compare(const struct spdk_pci_addr *a1, const struct spdk_pci_addr *a2);
|
2016-10-08 00:01:54 +00:00
|
|
|
|
2016-10-31 23:29:52 +00:00
|
|
|
/**
|
|
|
|
* Convert a string representation of a PCI address into a struct spdk_pci_addr.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param addr PCI adddress output on success.
|
2017-04-17 02:01:55 +00:00
|
|
|
* \param bdf PCI address in domain:bus:device.function format or
|
2018-03-12 05:10:49 +00:00
|
|
|
* domain.bus.device.function format.
|
2016-10-31 23:29:52 +00:00
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \return 0 on success, negative errno on failure.
|
2016-10-31 23:29:52 +00:00
|
|
|
*/
|
|
|
|
int spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf);
|
|
|
|
|
2016-12-02 18:00:55 +00:00
|
|
|
/**
|
|
|
|
* Convert a struct spdk_pci_addr to a string.
|
|
|
|
*
|
|
|
|
* \param bdf String into which a string will be output in the format
|
2018-03-12 05:10:49 +00:00
|
|
|
* domain:bus:device.function. The string must be at least 14 characters in size.
|
|
|
|
* \param sz Size of bdf in bytes. Must be at least 14.
|
|
|
|
* \param addr PCI address.
|
2016-12-02 18:00:55 +00:00
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \return 0 on success, or a negated errno on failure.
|
2016-12-02 18:00:55 +00:00
|
|
|
*/
|
|
|
|
int spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr);
|
|
|
|
|
2018-11-29 09:24:05 +00:00
|
|
|
/**
|
|
|
|
* Hook a custom PCI device into the PCI layer. The device will be attachable,
|
|
|
|
* enumerable, and will call provided callbacks on each PCI resource access
|
|
|
|
* request.
|
|
|
|
*
|
|
|
|
* \param drv driver that will be able to attach the device
|
|
|
|
* \param dev fully initialized PCI device struct
|
|
|
|
*/
|
|
|
|
void spdk_pci_hook_device(struct spdk_pci_driver *drv, struct spdk_pci_device *dev);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Un-hook a custom PCI device from the PCI layer. The device must not be attached.
|
|
|
|
*
|
|
|
|
* \param dev fully initialized PCI device struct
|
|
|
|
*/
|
|
|
|
void spdk_pci_unhook_device(struct spdk_pci_device *dev);
|
|
|
|
|
2017-06-22 19:48:33 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Remove any CPU affinity from the current thread.
|
2017-06-22 19:48:33 +00:00
|
|
|
*/
|
|
|
|
void spdk_unaffinitize_thread(void);
|
|
|
|
|
2016-11-07 17:08:11 +00:00
|
|
|
/**
|
|
|
|
* Call a function with CPU affinity unset.
|
|
|
|
*
|
|
|
|
* This can be used to run a function that creates other threads without inheriting the calling
|
|
|
|
* thread's CPU affinity.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param cb Function to call
|
|
|
|
* \param arg Parameter to the function cb().
|
2016-11-07 17:08:11 +00:00
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \return the return value of cb().
|
2016-11-07 17:08:11 +00:00
|
|
|
*/
|
|
|
|
void *spdk_call_unaffinitized(void *cb(void *arg), void *arg);
|
|
|
|
|
2017-03-02 21:50:04 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Page-granularity memory address translation table.
|
2017-03-02 21:50:04 +00:00
|
|
|
*/
|
|
|
|
struct spdk_mem_map;
|
|
|
|
|
|
|
|
enum spdk_mem_map_notify_action {
|
|
|
|
SPDK_MEM_MAP_NOTIFY_REGISTER,
|
|
|
|
SPDK_MEM_MAP_NOTIFY_UNREGISTER,
|
|
|
|
};
|
|
|
|
|
2017-08-08 10:54:37 +00:00
|
|
|
typedef int (*spdk_mem_map_notify_cb)(void *cb_ctx, struct spdk_mem_map *map,
|
|
|
|
enum spdk_mem_map_notify_action action,
|
|
|
|
void *vaddr, size_t size);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
2018-09-11 23:05:50 +00:00
|
|
|
typedef int (*spdk_mem_map_contiguous_translations)(uint64_t addr_1, uint64_t addr_2);
|
|
|
|
|
2018-09-11 21:32:54 +00:00
|
|
|
/**
|
|
|
|
* A function table to be implemented by each memory map.
|
|
|
|
*/
|
|
|
|
struct spdk_mem_map_ops {
|
|
|
|
spdk_mem_map_notify_cb notify_cb;
|
2018-09-11 23:05:50 +00:00
|
|
|
spdk_mem_map_contiguous_translations are_contiguous;
|
2018-09-11 21:32:54 +00:00
|
|
|
};
|
|
|
|
|
2017-03-02 21:50:04 +00:00
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Allocate a virtual memory address translation map.
|
|
|
|
*
|
|
|
|
* \param default_translation Default translation for the map.
|
2018-09-11 22:03:31 +00:00
|
|
|
* \param ops Table of callback functions for map operations.
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param cb_ctx Argument passed to the callback function.
|
|
|
|
*
|
|
|
|
* \return a pointer to the allocated virtual memory address translation map.
|
2017-03-02 21:50:04 +00:00
|
|
|
*/
|
|
|
|
struct spdk_mem_map *spdk_mem_map_alloc(uint64_t default_translation,
|
2018-09-11 22:03:31 +00:00
|
|
|
const struct spdk_mem_map_ops *ops, void *cb_ctx);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
2018-03-12 05:10:49 +00:00
|
|
|
* Free a memory map previously allocated by spdk_mem_map_alloc().
|
|
|
|
*
|
|
|
|
* \param pmap Memory map to free.
|
2017-03-02 21:50:04 +00:00
|
|
|
*/
|
|
|
|
void spdk_mem_map_free(struct spdk_mem_map **pmap);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register an address translation for a range of virtual memory.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param map Memory map.
|
2017-03-02 21:50:04 +00:00
|
|
|
* \param vaddr Virtual address of the region to register - must be 2 MB aligned.
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param size Size of the region in bytes - must be multiple of 2 MB in the
|
|
|
|
* current implementation.
|
2017-03-02 21:50:04 +00:00
|
|
|
* \param translation Translation to store in the map for this address range.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \sa spdk_mem_map_clear_translation().
|
|
|
|
*
|
|
|
|
* \return 0 on success, negative errno on failure.
|
2017-03-02 21:50:04 +00:00
|
|
|
*/
|
2017-08-08 10:54:37 +00:00
|
|
|
int spdk_mem_map_set_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t size,
|
|
|
|
uint64_t translation);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister an address translation.
|
|
|
|
*
|
2018-03-12 05:10:49 +00:00
|
|
|
* \param map Memory map.
|
|
|
|
* \param vaddr Virtual address of the region to unregister - must be 2 MB aligned.
|
|
|
|
* \param size Size of the region in bytes - must be multiple of 2 MB in the
|
|
|
|
* current implementation.
|
|
|
|
*
|
|
|
|
* \sa spdk_mem_map_set_translation().
|
|
|
|
*
|
|
|
|
* \return 0 on success, negative errno on failure.
|
2017-03-02 21:50:04 +00:00
|
|
|
*/
|
2017-08-08 10:54:37 +00:00
|
|
|
int spdk_mem_map_clear_translation(struct spdk_mem_map *map, uint64_t vaddr, uint64_t size);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Look up the translation of a virtual address in a memory map.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param map Memory map.
|
|
|
|
* \param vaddr Virtual address.
|
2018-09-06 20:07:42 +00:00
|
|
|
* \param size Contains the size of the memory region pointed to by vaddr.
|
2018-12-28 09:29:42 +00:00
|
|
|
* If vaddr is successfully translated, then this is updated with the size of
|
|
|
|
* the memory region for which the translation is valid.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2018-05-31 21:44:49 +00:00
|
|
|
* \return the translation of vaddr stored in the map, or default_translation
|
|
|
|
* as specified in spdk_mem_map_alloc() if vaddr is not present in the map.
|
2017-03-02 21:50:04 +00:00
|
|
|
*/
|
2018-09-06 20:07:42 +00:00
|
|
|
uint64_t spdk_mem_map_translate(const struct spdk_mem_map *map, uint64_t vaddr, uint64_t *size);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register the specified memory region for address translation.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2017-03-02 21:50:04 +00:00
|
|
|
* The memory region must map to pinned huge pages (2MB or greater).
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \param vaddr Virtual address to register.
|
|
|
|
* \param len Length in bytes of the vaddr.
|
|
|
|
*
|
|
|
|
* \return 0 on success, negative errno on failure.
|
2017-03-02 21:50:04 +00:00
|
|
|
*/
|
2017-08-08 10:54:37 +00:00
|
|
|
int spdk_mem_register(void *vaddr, size_t len);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregister the specified memory region from vtophys address translation.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
2017-03-02 21:50:04 +00:00
|
|
|
* The caller must ensure all in-flight DMA operations to this memory region
|
2018-03-12 05:10:49 +00:00
|
|
|
* are completed or cancelled before calling this function.
|
|
|
|
*
|
|
|
|
* \param vaddr Virtual address to unregister.
|
2018-06-18 14:39:39 +00:00
|
|
|
* \param len Length in bytes of the vaddr.
|
2018-03-12 05:10:49 +00:00
|
|
|
*
|
|
|
|
* \return 0 on success, negative errno on failure.
|
2017-03-02 21:50:04 +00:00
|
|
|
*/
|
2017-08-08 10:54:37 +00:00
|
|
|
int spdk_mem_unregister(void *vaddr, size_t len);
|
2017-03-02 21:50:04 +00:00
|
|
|
|
2015-09-21 15:52:41 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|