1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * 4 * HDF is dual licensed: you can use it either under the terms of 5 * the GPL, or the BSD license, at your option. 6 * See the LICENSE file in the root of this repository for complete details. 7 */ 8 9 #ifndef CAMERA_BUFFER_MANAGER_ADAPTER_H 10 #define CAMERA_BUFFER_MANAGER_ADAPTER_H 11 12 #include <hdf_dlist.h> 13 #include <osal_atomic.h> 14 #include <osal_mutex.h> 15 #include <osal_spinlock.h> 16 #include <linux/wait.h> 17 #include <linux/dma-buf.h> 18 #include "buffer_queue.h" 19 20 /* struct BufferQueue is the first variable in struct BufferQueueImp */ 21 struct BufferQueueImp { 22 struct BufferQueue queue; 23 struct device *dev; 24 struct device *allocDev[MAX_PLANES]; 25 gfp_t gfpFlags; 26 enum dma_data_direction dmaDir; 27 struct mutex *lock; 28 unsigned long dmaAttrs; 29 }; 30 31 struct VmareaHandler { 32 refcount_t *refCount; 33 void (*free)(void *arg); 34 void *arg; 35 }; 36 37 /* interface used in the memory operations */ 38 struct frame_vector *CreateFrameVec(unsigned long start, unsigned long length); 39 void DestroyFrameVec(struct frame_vector *vec); 40 const struct vm_operations_struct *GetVmOps(void); 41 42 /* interface for kernel function */ 43 void MemoryAdapterQueueImpInit(struct BufferQueue *queue); 44 void MemoryAdapterDriverMutexLock(struct BufferQueue *queue); 45 void MemoryAdapterDriverMutexUnLock(struct BufferQueue *queue); 46 bool MemoryAdapterIsErrOrNullPtr(void *ptr); 47 bool MemoryAdapterIsErrPtr(void *ptr); 48 int32_t MemoryAdapterPtrErr(void *ptr); 49 unsigned long MemoryAdapterPageAlign(unsigned long size); 50 void *MemoryAdapterGetDmaBuffer(uint32_t fd); 51 void MemoryAdapterPutDmaBuffer(void *dmaBuf); 52 uint32_t MemoryAdapterDmaBufSize(void *dmaBuf); 53 54 #endif /* CAMERA_BUFFER_MANAGER_ADAPTER_H */ 55