diff options
author | codeworkx <codeworkx@cyanogenmod.org> | 2012-12-04 18:51:36 +0100 |
---|---|---|
committer | Espen Fjellvær Olsen <espen@mrfjo.org> | 2012-12-11 14:04:26 +0100 |
commit | 9a3063ed1b718190845ab1326d27261a5eebfd11 (patch) | |
tree | 185caf9dd64b1f6c8bb7e1c969c58fd5404415ab /libs | |
parent | a1aa229340e805da8cbd1edaaf2e6fcb380a1070 (diff) | |
download | frameworks_native-9a3063ed1b718190845ab1326d27261a5eebfd11.zip frameworks_native-9a3063ed1b718190845ab1326d27261a5eebfd11.tar.gz frameworks_native-9a3063ed1b718190845ab1326d27261a5eebfd11.tar.bz2 |
binder: Add MemoryHeapBaseIon
Source:
http://git.insignal.co.kr/samsung/exynos/android/platform/frameworks/native/commit/?h=exynos-jb&id=dc4cd25cc41e4358debd0c7d1a2706d208a58df6
Change-Id: Ib06cc37a2a25c78a061ee2bad48eec2d01b07833
Diffstat (limited to 'libs')
-rw-r--r-- | libs/binder/Android.mk | 13 | ||||
-rw-r--r-- | libs/binder/IMemory.cpp | 29 | ||||
-rw-r--r-- | libs/binder/MemoryHeapBaseIon.cpp | 96 |
3 files changed, 136 insertions, 2 deletions
diff --git a/libs/binder/Android.mk b/libs/binder/Android.mk index 9136c66..c72e930 100644 --- a/libs/binder/Android.mk +++ b/libs/binder/Android.mk @@ -37,14 +37,25 @@ 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) LOCAL_LDLIBS += -lpthread LOCAL_MODULE := libbinder LOCAL_SRC_FILES := $(sources) + include $(BUILD_STATIC_LIBRARY) diff --git a/libs/binder/IMemory.cpp b/libs/binder/IMemory.cpp index cd2451a..8fea1b2 100644 --- a/libs/binder/IMemory.cpp +++ b/libs/binder/IMemory.cpp @@ -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 { @@ -301,6 +305,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)); @@ -313,7 +325,16 @@ void BpMemoryHeap::assertReallyMapped() const Mutex::Autolock _l(mLock); if (mHeapId == -1) { mRealHeap = true; - mBase = mmap(0, size, access, MAP_SHARED, fd, offset); + +#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)", asBinder().get(), size, fd, strerror(errno)); @@ -325,6 +346,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 } } diff --git a/libs/binder/MemoryHeapBaseIon.cpp b/libs/binder/MemoryHeapBaseIon.cpp new file mode 100644 index 0000000..fe7dbb8 --- /dev/null +++ b/libs/binder/MemoryHeapBaseIon.cpp @@ -0,0 +1,96 @@ +/* + * 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; + } +} + +}; |