1 /* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef __QCAMERA3HWI_MEM_H__ 31 #define __QCAMERA3HWI_MEM_H__ 32 #include <hardware/camera3.h> 33 #include <utils/Mutex.h> 34 #include <qdMetaData.h> 35 36 extern "C" { 37 #include <sys/types.h> 38 #include <linux/msm_ion.h> 39 #include <mm_camera_interface.h> 40 } 41 42 namespace qcamera { 43 44 // Base class for all memory types. Abstract. 45 class QCamera3Memory { 46 47 public: 48 int cleanCache(int index) {return cacheOps(index, ION_IOC_CLEAN_CACHES);} 49 int invalidateCache(int index) {return cacheOps(index, ION_IOC_INV_CACHES);} 50 int cleanInvalidateCache(int index) {return cacheOps(index, ION_IOC_CLEAN_INV_CACHES);} 51 int getFd(int index) const; 52 int getSize(int index) const; 53 int getCnt() const; 54 55 virtual int cacheOps(int index, unsigned int cmd) = 0; 56 virtual int getRegFlags(uint8_t *regFlags) const = 0; 57 virtual int getMatchBufIndex(void *object) = 0; 58 virtual void *getPtr(int index) const= 0; 59 60 QCamera3Memory(); 61 virtual ~QCamera3Memory(); 62 63 int32_t getBufDef(const cam_frame_len_offset_t &offset, 64 mm_camera_buf_def_t &bufDef, int index) const; 65 66 protected: 67 struct QCamera3MemInfo { 68 int fd; 69 int main_ion_fd; 70 ion_user_handle_t handle; 71 uint32_t size; 72 }; 73 74 int cacheOpsInternal(int index, unsigned int cmd, void *vaddr); 75 76 int mBufferCount; 77 struct QCamera3MemInfo mMemInfo[MM_CAMERA_MAX_NUM_FRAMES]; 78 void *mPtr[MM_CAMERA_MAX_NUM_FRAMES]; 79 }; 80 81 // Internal heap memory is used for memories used internally 82 // They are allocated from /dev/ion. Examples are: capabilities, 83 // parameters, metadata, and internal YUV data for jpeg encoding. 84 class QCamera3HeapMemory : public QCamera3Memory { 85 public: 86 QCamera3HeapMemory(); 87 virtual ~QCamera3HeapMemory(); 88 89 int allocate(int count, int size, bool queueAll); 90 void deallocate(); 91 92 virtual int cacheOps(int index, unsigned int cmd); 93 virtual int getRegFlags(uint8_t *regFlags) const; 94 virtual int getMatchBufIndex(void *object); 95 virtual void *getPtr(int index) const; 96 private: 97 int alloc(int count, int size, int heap_id); 98 void dealloc(); 99 100 int allocOneBuffer(struct QCamera3MemInfo &memInfo, int heap_id, int size); 101 void deallocOneBuffer(struct QCamera3MemInfo &memInfo); 102 bool mQueueAll; 103 }; 104 105 // Gralloc Memory shared with frameworks 106 class QCamera3GrallocMemory : public QCamera3Memory { 107 public: 108 QCamera3GrallocMemory(); 109 virtual ~QCamera3GrallocMemory(); 110 111 int registerBuffer(buffer_handle_t *buffer); 112 void unregisterBuffers(); 113 virtual int cacheOps(int index, unsigned int cmd); 114 virtual int getRegFlags(uint8_t *regFlags) const; 115 virtual int getMatchBufIndex(void *object); 116 virtual void *getPtr(int index) const; 117 int32_t markFrameNumber(int index, uint32_t frameNumber); 118 int32_t getFrameNumber(int index); 119 void *getBufferHandle(int index); 120 int32_t setColorSpace(uint8_t intent); 121 private: 122 buffer_handle_t *mBufferHandle[MM_CAMERA_MAX_NUM_FRAMES]; 123 struct private_handle_t *mPrivateHandle[MM_CAMERA_MAX_NUM_FRAMES]; 124 uint32_t mCurrentFrameNumbers[MM_CAMERA_MAX_NUM_FRAMES]; 125 enum ColorSpace_t mColorSpace; 126 }; 127 128 }; 129 #endif 130