Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2019-2021 Intel Corporation 3 : : */ 4 : : 5 : : #include <stdio.h> 6 : : #include <inttypes.h> 7 : : 8 : : #include <rte_common.h> 9 : : #include <rte_malloc.h> 10 : : #include <rte_memzone.h> 11 : : 12 : : #include "iavf_type.h" 13 : : #include "iavf_prototype.h" 14 : : 15 : : enum iavf_status 16 : 0 : iavf_allocate_dma_mem_d(__rte_unused struct iavf_hw *hw, 17 : : struct iavf_dma_mem *mem, 18 : : u64 size, 19 : : u32 alignment) 20 : : { 21 : : static RTE_ATOMIC(uint64_t) iavf_dma_memzone_id; 22 : : const struct rte_memzone *mz = NULL; 23 : : char z_name[RTE_MEMZONE_NAMESIZE]; 24 : : 25 [ # # ]: 0 : if (!mem) 26 : : return IAVF_ERR_PARAM; 27 : : 28 : 0 : snprintf(z_name, sizeof(z_name), "iavf_dma_%" PRIu64, 29 : : rte_atomic_fetch_add_explicit(&iavf_dma_memzone_id, 1, rte_memory_order_relaxed)); 30 : 0 : mz = rte_memzone_reserve_bounded(z_name, size, SOCKET_ID_ANY, 31 : : RTE_MEMZONE_IOVA_CONTIG, alignment, 32 : : RTE_PGSIZE_2M); 33 [ # # ]: 0 : if (!mz) 34 : : return IAVF_ERR_NO_MEMORY; 35 : : 36 : 0 : mem->size = size; 37 : 0 : mem->va = mz->addr; 38 : 0 : mem->pa = mz->iova; 39 : 0 : mem->zone = (const void *)mz; 40 : : 41 : 0 : return IAVF_SUCCESS; 42 : : } 43 : : 44 : : enum iavf_status 45 : 0 : iavf_free_dma_mem_d(__rte_unused struct iavf_hw *hw, 46 : : struct iavf_dma_mem *mem) 47 : : { 48 [ # # ]: 0 : if (!mem) 49 : : return IAVF_ERR_PARAM; 50 : : 51 : 0 : rte_memzone_free((const struct rte_memzone *)mem->zone); 52 : 0 : mem->zone = NULL; 53 : 0 : mem->va = NULL; 54 : 0 : mem->pa = (u64)0; 55 : : 56 : 0 : return IAVF_SUCCESS; 57 : : } 58 : : 59 : : enum iavf_status 60 : 0 : iavf_allocate_virt_mem_d(__rte_unused struct iavf_hw *hw, 61 : : struct iavf_virt_mem *mem, 62 : : u32 size) 63 : : { 64 [ # # ]: 0 : if (!mem) 65 : : return IAVF_ERR_PARAM; 66 : : 67 : 0 : mem->size = size; 68 : 0 : mem->va = rte_zmalloc("iavf", size, 0); 69 : : 70 [ # # ]: 0 : if (mem->va) 71 : : return IAVF_SUCCESS; 72 : : else 73 : 0 : return IAVF_ERR_NO_MEMORY; 74 : : } 75 : : 76 : : enum iavf_status 77 : 0 : iavf_free_virt_mem_d(__rte_unused struct iavf_hw *hw, 78 : : struct iavf_virt_mem *mem) 79 : : { 80 [ # # ]: 0 : if (!mem) 81 : : return IAVF_ERR_PARAM; 82 : : 83 : 0 : rte_free(mem->va); 84 : 0 : mem->va = NULL; 85 : : 86 : 0 : return IAVF_SUCCESS; 87 : : } 88 : : 89 [ - + ]: 252 : RTE_LOG_REGISTER_DEFAULT(iavf_common_logger, NOTICE);