summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/binder/IMemory.h3
-rw-r--r--include/binder/MemoryHeapBaseIon.h51
-rw-r--r--libs/binder/Android.mk13
-rw-r--r--libs/binder/IMemory.cpp29
-rw-r--r--libs/binder/MemoryHeapBaseIon.cpp96
5 files changed, 189 insertions, 3 deletions
diff --git a/include/binder/IMemory.h b/include/binder/IMemory.h
index 2d0db00..62ac9e3 100644
--- a/include/binder/IMemory.h
+++ b/include/binder/IMemory.h
@@ -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;
diff --git a/include/binder/MemoryHeapBaseIon.h b/include/binder/MemoryHeapBaseIon.h
new file mode 100644
index 0000000..0fe99c7
--- /dev/null
+++ b/include/binder/MemoryHeapBaseIon.h
@@ -0,0 +1,51 @@
+/*
+ * 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
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;
+ }
+}
+
+};