1ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson/*
215c7eb9ba46119290695b650d23180884f1156faArun Kumar K.R * Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
3ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
4ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * Redistribution and use in source and binary forms, with or without
5ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * modification, are permitted provided that the following conditions are
6ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * met:
7ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *   * Redistributions of source code must retain the above copyright
8ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *     notice, this list of conditions and the following disclaimer.
9ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *   * Redistributions in binary form must reproduce the above
10ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *     copyright notice, this list of conditions and the following
11ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *     disclaimer in the documentation and/or other materials provided
12ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *     with the distribution.
13ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *   * Neither the name of The Linux Foundation nor the names of its
14ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *     contributors may be used to endorse or promote products derived
15ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *     from this software without specific prior written permission.
16ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson *
17ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson */
29ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
30ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#ifndef GRALLOC_MEMALLOC_H
31ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#define GRALLOC_MEMALLOC_H
32ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
33ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#include <stdlib.h>
34ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
35ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonnamespace gralloc {
36ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
37ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonenum {
38ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    CACHE_CLEAN = 0x1,
39ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    CACHE_INVALIDATE,
40ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    CACHE_CLEAN_AND_INVALIDATE,
41ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson};
42ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
43ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonstruct alloc_data {
44ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    void           *base;
45ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int            fd;
4692e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah    unsigned int   offset;
4792e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah    unsigned int   size;
4892e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah    unsigned int   align;
4915c7eb9ba46119290695b650d23180884f1156faArun Kumar K.R    uintptr_t      pHandle;
50ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    bool           uncached;
51ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    unsigned int   flags;
52ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    int            allocType;
53ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson};
54ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
55ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilsonclass IMemAlloc {
56ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
57ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    public:
58ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    // Allocate buffer - fill in the alloc_data
59ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    // structure and pass it in. Mapped address
60ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    // and fd are returned in the alloc_data struct
61ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    virtual int alloc_buffer(alloc_data& data) = 0;
62ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
63ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    // Free buffer
6492e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah    virtual int free_buffer(void *base, unsigned int size,
6592e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah                            unsigned int offset, int fd) = 0;
66ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
67ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    // Map buffer
6892e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah    virtual int map_buffer(void **pBase, unsigned int size,
6992e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah                           unsigned int offset, int fd) = 0;
70ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
71ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    // Unmap buffer
7292e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah    virtual int unmap_buffer(void *base, unsigned int size,
7392e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah                             unsigned int offset) = 0;
74ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
75ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    // Clean and invalidate
7692e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah    virtual int clean_buffer(void *base, unsigned int size,
7792e456fd92a6231dbf5d9de5289ed2f84841a804Saurabh Shah                             unsigned int offset, int fd, int op) = 0;
78ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
79ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    // Destructor
80ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    virtual ~IMemAlloc() {};
81ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
82ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    enum {
83ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson        FD_INIT = -1,
84ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson    };
85ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
86ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson};
87ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson
88ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson} // end gralloc namespace
89ef53c1c84ec55ed50f607d52b7abfbb86239408eSimon Wilson#endif // GRALLOC_MEMALLOC_H
90