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