1 /* 2 * dma_buffer.h - DMA Buffer Implementation 3 * 4 * Copyright (c) 2021 Rockchip Electronics Co., Ltd 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * Author: Cody Xie <cody.xie@rock-chips.com> 19 */ 20 #ifndef _DMA_BUFFER_H_ 21 #define _DMA_BUFFER_H_ 22 23 #include <memory> 24 25 #include "unique_fd.h" 26 #include "xcam_common.h" 27 28 namespace XCam { 29 30 enum class DmaBufferDirection { kBidirectional, kDeviceToCPU, kCPUToDevice, kNone }; 31 32 class DmaBuffer { 33 public: 34 DmaBuffer(int fd, size_t size); 35 virtual ~DmaBuffer(); 36 DmaBuffer(const DmaBuffer&) = delete; 37 DmaBuffer& operator=(const DmaBuffer&) = delete; 38 39 static XCamReturn sync(int fd, DmaBufferDirection direction, bool start); 40 41 XCamReturn beginCpuAccess(DmaBufferDirection direction); 42 XCamReturn endCpuAccess(DmaBufferDirection direction); 43 44 void* map(); 45 void unmap(); 46 int getFd(); 47 size_t getSize(); 48 int release(); 49 bool mapped(); 50 51 private: 52 53 UniqueFd fd_; 54 size_t size_; 55 void* ptr_; 56 // TODO(Cody): modern implement of dma_buf 57 // does not need name to import/export? 58 // std::string name_; 59 }; 60 61 } // namespace XCam 62 63 #endif // _DMA_BUFFER_H_ 64 65