1202a77d28ac251545f6f998a974690212309b927Iliyan Malchev/*
2a43fb8fce6d9be5577de1e0f49c99bd4fe2f6d44Duy Truong * Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
3202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
4202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * Redistribution and use in source and binary forms, with or without
5202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * modification, are permitted provided that the following conditions are
6202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * met:
7202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *   * Redistributions of source code must retain the above copyright
8202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *     notice, this list of conditions and the following disclaimer.
9202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *   * Redistributions in binary form must reproduce the above
10202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *     copyright notice, this list of conditions and the following
11202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *     disclaimer in the documentation and/or other materials provided
12202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *     with the distribution.
13a43fb8fce6d9be5577de1e0f49c99bd4fe2f6d44Duy Truong *   * Neither the name of The Linux Foundation nor the names of its
14202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *     contributors may be used to endorse or promote products derived
15202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *     from this software without specific prior written permission.
16202a77d28ac251545f6f998a974690212309b927Iliyan Malchev *
17202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27202a77d28ac251545f6f998a974690212309b927Iliyan Malchev * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28202a77d28ac251545f6f998a974690212309b927Iliyan Malchev */
29202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
30202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#ifndef GRALLOC_MEMALLOC_H
31202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#define GRALLOC_MEMALLOC_H
32202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
33202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#include <stdlib.h>
34202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
35202a77d28ac251545f6f998a974690212309b927Iliyan Malchevnamespace gralloc {
36202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
370b5054e40d055687b036b626538e79bf160beebbNaseer Ahmedenum {
380b5054e40d055687b036b626538e79bf160beebbNaseer Ahmed    CACHE_CLEAN = 0x1,
390b5054e40d055687b036b626538e79bf160beebbNaseer Ahmed    CACHE_INVALIDATE,
400b5054e40d055687b036b626538e79bf160beebbNaseer Ahmed    CACHE_CLEAN_AND_INVALIDATE,
410b5054e40d055687b036b626538e79bf160beebbNaseer Ahmed};
420b5054e40d055687b036b626538e79bf160beebbNaseer Ahmed
4329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmedstruct alloc_data {
4429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    void           *base;
4529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int            fd;
4629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int            offset;
4729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    size_t         size;
4829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    size_t         align;
4929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    unsigned int   pHandle;
5029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    bool           uncached;
5129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    unsigned int   flags;
5229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    int            allocType;
5329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
54202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
5501d3fd3318a767e6ba75492ed08d57896df95d63Naseer Ahmedclass IMemAlloc {
56202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
5729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    public:
5829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // Allocate buffer - fill in the alloc_data
5929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // structure and pass it in. Mapped address
6029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // and fd are returned in the alloc_data struct
6129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    virtual int alloc_buffer(alloc_data& data) = 0;
62202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
6329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // Free buffer
6429a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    virtual int free_buffer(void *base, size_t size,
6529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                            int offset, int fd) = 0;
66202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
6729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // Map buffer
6829a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    virtual int map_buffer(void **pBase, size_t size,
6929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                           int offset, int fd) = 0;
70202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
7129a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // Unmap buffer
7229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    virtual int unmap_buffer(void *base, size_t size,
7329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed                             int offset) = 0;
74202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
7529a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // Clean and invalidate
7629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    virtual int clean_buffer(void *base, size_t size,
770b5054e40d055687b036b626538e79bf160beebbNaseer Ahmed                             int offset, int fd, int op) = 0;
78202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
7929a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    // Destructor
8029a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    virtual ~IMemAlloc() {};
81202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
8229a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed    enum {
8329a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed        FD_INIT = -1,
84202a77d28ac251545f6f998a974690212309b927Iliyan Malchev    };
85202a77d28ac251545f6f998a974690212309b927Iliyan Malchev
8629a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed};
8729a26818d7294055539167b2fbfdaa168bcf725cNaseer Ahmed
88202a77d28ac251545f6f998a974690212309b927Iliyan Malchev} // end gralloc namespace
89202a77d28ac251545f6f998a974690212309b927Iliyan Malchev#endif // GRALLOC_MEMALLOC_H
90