Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5fbf4fbd authored by codeworkx's avatar codeworkx Committed by Ricardo Cerqueira
Browse files

binder: Add MemoryHeapBaseIon

parent 4ab1691d
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -36,7 +36,8 @@ public:

    // flags returned by getFlags()
    enum {
        READ_ONLY   = 0x00000001
        READ_ONLY   = 0x00000001,
        USE_ION_FD  = 0x00000008
    };

    virtual int         getHeapID() const = 0;
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2008 The Android Open Source Project
 * Copyright 2011, Samsung Electronics Co. LTD
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*!
 * \file MemoryHeapBaseIon.h
 * \brief header file for MemoryHeapBaseIon
 * \author MinGu, Jeon(mingu85.jeon)
 * \date 2011/11/20
 *
 * <b>Revision History: </b>
 * - 2011/11/21 : MinGu, Jeon(mingu85.jeon)) \n
 * Initial version
 */

#ifndef ANDROID_MEMORY_HEAP_BASE_ION_H
#define ANDROID_MEMORY_HEAP_BASE_ION_H

#include <binder/IMemory.h>
#include <binder/MemoryHeapBase.h>
#include <stdlib.h>

namespace android {

class MemoryHeapBaseIon : public MemoryHeapBase
{
public:
    enum {
        USE_ION_FD = IMemoryHeap::USE_ION_FD
    };
    MemoryHeapBaseIon(size_t size, uint32_t flags = 0, char const* name = NULL);
    MemoryHeapBaseIon(int fd, size_t size, uint32_t flags = 0, uint32_t offset = 0);
    ~MemoryHeapBaseIon();
private:
    int mIonClient;
};

};
#endif
+12 −1
Original line number Diff line number Diff line
@@ -43,10 +43,20 @@ endif
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

ifeq ($(BOARD_USE_V4L2_ION), true)
LOCAL_CFLAGS += -DUSE_V4L2_ION
sources += \
	MemoryHeapBaseIon.cpp
LOCAL_C_INCLUDES := hardware/samsung/exynos4/hal/include
LOCAL_SHARED_LIBRARIES := libsecion
endif

LOCAL_LDLIBS += -lpthread
LOCAL_MODULE := libbinder
LOCAL_SHARED_LIBRARIES := liblog libcutils libutils
LOCAL_SHARED_LIBRARIES += liblog libcutils libutils
LOCAL_SRC_FILES := $(sources)

include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
@@ -54,4 +64,5 @@ LOCAL_LDLIBS += -lpthread
LOCAL_MODULE := libbinder
LOCAL_STATIC_LIBRARIES += libutils
LOCAL_SRC_FILES := $(sources)

include $(BUILD_STATIC_LIBRARY)
+28 −1
Original line number Diff line number Diff line
@@ -32,6 +32,10 @@
#include <binder/Parcel.h>
#include <utils/CallStack.h>

#ifdef USE_V4L2_ION
#include "ion.h"
#endif

#define VERBOSE   0

namespace android {
@@ -299,6 +303,14 @@ void BpMemoryHeap::assertReallyMapped() const
        ALOGE_IF(err, "binder=%p transaction failed fd=%d, size=%ld, err=%d (%s)",
                asBinder().get(), parcel_fd, size, err, strerror(-err));

#ifdef USE_V4L2_ION
        int ion_client = -1;
        if (flags & USE_ION_FD) {
            ion_client = ion_client_create();
            ALOGE_IF(ion_client < 0, "BpMemoryHeap : ion client creation error");
        }
#endif

        int fd = dup( parcel_fd );
        ALOGE_IF(fd==-1, "cannot dup fd=%d, size=%ld, err=%d (%s)",
                parcel_fd, size, err, strerror(errno));
@@ -311,6 +323,15 @@ void BpMemoryHeap::assertReallyMapped() const
        Mutex::Autolock _l(mLock);
        if (mHeapId == -1) {
            mRealHeap = true;

#ifdef USE_V4L2_ION
        if (flags & USE_ION_FD) {
            if (ion_client < 0)
                mBase = MAP_FAILED;
            else
                mBase = ion_map(fd, size, offset);
            } else
#endif
                mBase = mmap(0, size, access, MAP_SHARED, fd, offset);
            if (mBase == MAP_FAILED) {
                ALOGE("cannot map BpMemoryHeap (binder=%p), size=%ld, fd=%d (%s)",
@@ -323,6 +344,12 @@ void BpMemoryHeap::assertReallyMapped() const
                android_atomic_write(fd, &mHeapId);
            }
        }
#ifdef USE_V4L2_ION
        if (ion_client < 0)
            ion_client = -1;
        else
            ion_client_destroy(ion_client);
#endif
    }
}

+96 −0
Original line number Diff line number Diff line
/*
 * Copyright Samsung Electronics Co.,LTD.
 * Copyright (C) 2011 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*!
 * \file MemoryHeapBaseIon.cpp
 * \brief source file for MemoryHeapBaseIon
 * \author MinGu, Jeon(mingu85.jeon)
 * \date 2011/11/20
 *
 * <b>Revision History: </b>
 * - 2011/11/20 : MinGu, Jeon(mingu85.jeon)) \n
 * Initial version
 */

#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <cutils/log.h>
#include <binder/MemoryHeapBase.h>
#include <binder/IMemory.h>
#include <binder/MemoryHeapBaseIon.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include "ion.h"

namespace android {

MemoryHeapBaseIon::MemoryHeapBaseIon(size_t size, uint32_t flags, char const *name)
{
    mIonClient = ion_client_create();
    if (mIonClient < 0) {
        mIonClient = -1;
        ALOGE("MemoryHeapBaseIon : ION client creation failed");
    }
    void* base = NULL;
    int fd = ion_alloc(mIonClient, size, 0, ION_HEAP_EXYNOS_MASK);

    if (fd < 0) {
        ALOGE("MemoryHeapBaseIon : ION memory allocation failed");
    } else {
        flags |= USE_ION_FD;
        base = ion_map(fd, size, 0);
        if (base != MAP_FAILED)
            init(fd, base, size, flags, NULL);
        else
            ALOGE("MemoryHeapBaseIon : mmap failed");
    }
}

MemoryHeapBaseIon::MemoryHeapBaseIon(int fd, size_t size, uint32_t flags, uint32_t offset)
{
    ALOGE_IF(fd < 0, "MemoryHeapBaseIon : file discriptor error. fd is not for ION Memory");
    mIonClient = ion_client_create();
    if (mIonClient < 0) {
        mIonClient = -1;
        ALOGE("MemoryHeapBaseIon : ION client creation failed");
    }
    void* base = NULL;
    if (fd >= 0) {
        int dup_fd = dup(fd);
        flags |= USE_ION_FD;
        base = ion_map(dup_fd, size, 0);
        if (base != MAP_FAILED)
            init(dup_fd, base, size, flags, NULL);
        else
            ALOGE("MemoryHeapBaseIon : mmap failed");
    }
}

MemoryHeapBaseIon::~MemoryHeapBaseIon()
{
    if (mIonClient != -1) {
        ion_unmap(getBase(), getSize());
        ion_free(getHeapID());
        ion_client_destroy(mIonClient);
        mIonClient = -1;
    }
}

};