xref: /freebsd/sys/dev/qat/qat_api/common/utils/lac_mem.c (revision 71625ec9)
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright(c) 2007-2022 Intel Corporation */
3 /**
4  *****************************************************************************
5  * @file lac_mem.c  Implementation of Memory Functions
6  *
7  * @ingroup LacMem
8  *
9  *****************************************************************************/
10 
11 /*
12 *******************************************************************************
13 * Include header files
14 *******************************************************************************
15 */
16 #include "qat_utils.h"
17 #include "cpa.h"
18 
19 #include "icp_accel_devices.h"
20 #include "icp_adf_init.h"
21 #include "icp_adf_transport.h"
22 #include "icp_adf_debug.h"
23 #include "icp_sal_iommu.h"
24 
25 #include "lac_mem.h"
26 #include "lac_mem_pools.h"
27 #include "lac_common.h"
28 #include "lac_list.h"
29 #include "icp_qat_fw_la.h"
30 #include "lac_sal_types.h"
31 
32 /*
33 ********************************************************************************
34 * Static Variables
35 ********************************************************************************
36 */
37 
38 #define MAX_BUFFER_SIZE (LAC_BITS_TO_BYTES(4096))
39 /**< @ingroup LacMem
40  * Maximum size of the buffers used in the resize function */
41 
42 /*
43 *******************************************************************************
44 * Define public/global function definitions
45 *******************************************************************************
46 */
47 /**
48  * @ingroup LacMem
49  */
50 CpaStatus
icp_LacBufferRestore(Cpa8U * pUserBuffer,Cpa32U userLen,Cpa8U * pWorkingBuffer,Cpa32U workingLen,CpaBoolean copyBuf)51 icp_LacBufferRestore(Cpa8U *pUserBuffer,
52 		     Cpa32U userLen,
53 		     Cpa8U *pWorkingBuffer,
54 		     Cpa32U workingLen,
55 		     CpaBoolean copyBuf)
56 {
57 	Cpa32U padSize = 0;
58 
59 	/* NULL is a valid value for working buffer as this function may be
60 	 * called to clean up in an error case where all the resize operations
61 	 * were not completed */
62 	if (NULL == pWorkingBuffer) {
63 		return CPA_STATUS_SUCCESS;
64 	}
65 
66 	if (workingLen < userLen) {
67 		QAT_UTILS_LOG("Invalid buffer sizes\n");
68 		return CPA_STATUS_INVALID_PARAM;
69 	}
70 
71 	if (pUserBuffer != pWorkingBuffer) {
72 
73 		if (CPA_TRUE == copyBuf) {
74 			/* Copy from internal buffer to user buffer */
75 			padSize = workingLen - userLen;
76 			memcpy(pUserBuffer, pWorkingBuffer + padSize, userLen);
77 		}
78 
79 		Lac_MemPoolEntryFree(pWorkingBuffer);
80 	}
81 	return CPA_STATUS_SUCCESS;
82 }
83 
84 /**
85  * @ingroup LacMem
86  */
87 CpaPhysicalAddr
SalMem_virt2PhysExternal(void * pVirtAddr,void * pServiceGen)88 SalMem_virt2PhysExternal(void *pVirtAddr, void *pServiceGen)
89 {
90 	sal_service_t *pService = (sal_service_t *)pServiceGen;
91 
92 	if (NULL != pService->virt2PhysClient) {
93 		return pService->virt2PhysClient(pVirtAddr);
94 	} else {
95 		/* Use internal QAT Utils virt to phys */
96 		/* Ok for kernel space probably should not use for user */
97 		return LAC_OS_VIRT_TO_PHYS_INTERNAL(pVirtAddr);
98 	}
99 }
100 
101 size_t
icp_sal_iommu_get_remap_size(size_t size)102 icp_sal_iommu_get_remap_size(size_t size)
103 {
104 	return size;
105 }
106 
107 CpaStatus
icp_sal_iommu_map(Cpa64U phaddr,Cpa64U iova,size_t size)108 icp_sal_iommu_map(Cpa64U phaddr, Cpa64U iova, size_t size)
109 {
110 	return CPA_STATUS_SUCCESS;
111 }
112 
113 CpaStatus
icp_sal_iommu_unmap(Cpa64U iova,size_t size)114 icp_sal_iommu_unmap(Cpa64U iova, size_t size)
115 {
116 	return CPA_STATUS_SUCCESS;
117 }
118