107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani/* 207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. 307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * Redistribution and use in source and binary forms, with or without 507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * modification, are permitted provided that the following conditions are 607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * met: 707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * * Redistributions of source code must retain the above copyright 807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * notice, this list of conditions and the following disclaimer. 907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * * Redistributions in binary form must reproduce the above 1007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * copyright notice, this list of conditions and the following 1107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * disclaimer in the documentation and/or other materials provided 1207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * with the distribution. 1307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * * Neither the name of The Linux Foundation nor the names of its 1407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * contributors may be used to endorse or promote products derived 1507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * from this software without specific prior written permission. 1607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * 1707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 1807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 1907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 2007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 2107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 2407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 2507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 2607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 2707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani */ 2907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 3007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#ifndef GRALLOC_MEMALLOC_H 3107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#define GRALLOC_MEMALLOC_H 3207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 3307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#include <stdlib.h> 3407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 3507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaninamespace gralloc { 3607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 3707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malanienum { 3807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani CACHE_CLEAN = 0x1, 3907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani CACHE_INVALIDATE, 4007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani CACHE_CLEAN_AND_INVALIDATE, 4107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani}; 4207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 4307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malanistruct alloc_data { 4407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani void *base; 4507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani int fd; 4607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani unsigned int offset; 4707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani unsigned int size; 4807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani unsigned int align; 4907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani uintptr_t pHandle; 5007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani bool uncached; 5107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani unsigned int flags; 52d39a514dd0540cf47e121775a77e9ac1b578bdb1Ben Fennema unsigned int heapId; 5307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani int allocType; 5407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani}; 5507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 5607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malaniclass IMemAlloc { 5707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 5807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani public: 5907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // Allocate buffer - fill in the alloc_data 6007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // structure and pass it in. Mapped address 6107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // and fd are returned in the alloc_data struct 6207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int alloc_buffer(alloc_data& data) = 0; 6307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 6407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // Free buffer 6507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int free_buffer(void *base, unsigned int size, 6607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani unsigned int offset, int fd) = 0; 6707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 6807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // Map buffer 6907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int map_buffer(void **pBase, unsigned int size, 7007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani unsigned int offset, int fd) = 0; 7107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 7207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // Unmap buffer 7307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int unmap_buffer(void *base, unsigned int size, 7407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani unsigned int offset) = 0; 7507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 7607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // Clean and invalidate 7707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual int clean_buffer(void *base, unsigned int size, 7807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani unsigned int offset, int fd, int op) = 0; 7907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 8007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani // Destructor 8107bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani virtual ~IMemAlloc() {}; 8207bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 8307bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani enum { 8407bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani FD_INIT = -1, 8507bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani }; 8607bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 8707bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani}; 8807bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani 8907bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani} // end gralloc namespace 9007bbf1e89c031a5d41a7561433e832d396c311a5Prashant Malani#endif // GRALLOC_MEMALLOC_H 91