Merge "hikey960: Update UEFI bootloader binaries to latest build"
diff --git a/gralloc/Android.mk b/gralloc/Android.mk
index fc62685..7f682fc 100644
--- a/gralloc/Android.mk
+++ b/gralloc/Android.mk
@@ -1,4 +1,6 @@
+# 
 # Copyright (C) 2010 ARM Limited. All rights reserved.
+# 
 # Copyright (C) 2008 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
@@ -13,15 +15,35 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+
 LOCAL_PATH := $(call my-dir)
 
 # HAL module implemenation, not prelinked and stored in
 # hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
 include $(CLEAR_VARS)
+LOCAL_PRELINK_MODULE := false
 
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -ge 21 && echo OK),OK)
+	LOCAL_MODULE_RELATIVE_PATH := hw
+else
+	LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
+endif
+
+MALI_DDK_TEST_PATH := hardware/arm/
+
+LOCAL_MODULE := gralloc.hikey
+#LOCAL_MODULE_TAGS := optional
+
+# Mali-200/300/400MP DDK
+MALI_DDK_PATH := hardware/arm/mali
+#SHARED_MEM_LIBS := libUMP
 SHARED_MEM_LIBS := libion libhardware
-LOCAL_SHARED_LIBRARIES := liblog libcutils libGLESv1_CM $(SHARED_MEM_LIBS)
-LOCAL_C_INCLUDES := system/core/include/
+LOCAL_SHARED_LIBRARIES := liblog libsync libGLESv1_CM $(SHARED_MEM_LIBS)
+
+LOCAL_C_INCLUDES := system/core/include/ $(MALI_DDK_PATH)/include 
+# Include the UMP header files
+LOCAL_C_INCLUDES += $(MALI_DDK_PATH)/src/ump/include
+
 LOCAL_CFLAGS := -DLOG_TAG=\"gralloc\" -DGRALLOC_32_BITS -DSTANDARD_LINUX_SCREEN -DPLATFORM_SDK_VERSION=$(PLATFORM_SDK_VERSION)
 
 LOCAL_SRC_FILES := \
@@ -29,7 +51,5 @@
 	alloc_device.cpp \
 	framebuffer_device.cpp
 
-LOCAL_MODULE := gralloc.hikey
-LOCAL_MODULE_RELATIVE_PATH := hw
-
+#LOCAL_CFLAGS+= -DMALI_VSYNC_EVENT_REPORT_ENABLE
 include $(BUILD_SHARED_LIBRARY)
diff --git a/gralloc/alloc_device.cpp b/gralloc/alloc_device.cpp
index 488e47c..076cb5c 100644
--- a/gralloc/alloc_device.cpp
+++ b/gralloc/alloc_device.cpp
@@ -44,8 +44,6 @@
 #include "ion_4.12.h"
 #endif
 
-#define GRALLOC_ALIGN( value, base ) (((value) + ((base) - 1)) & ~((base) - 1))
-
 #if GRALLOC_SIMULATE_FAILURES
 #include <cutils/properties.h>
 
@@ -96,6 +94,27 @@
 }
 #endif
 
+#ifdef FBIOGET_DMABUF
+static int fb_get_framebuffer_dmabuf(private_module_t *m, private_handle_t *hnd)
+{
+	struct fb_dmabuf_export fb_dma_buf;
+	int res;
+	res = ioctl(m->framebuffer->fd, FBIOGET_DMABUF, &fb_dma_buf);
+
+	if (res == 0)
+	{
+		hnd->share_fd = fb_dma_buf.fd;
+		return 0;
+	}
+	else
+	{
+		AINF("FBIOGET_DMABUF ioctl failed(%d). See gralloc_priv.h and the integration manual for vendor framebuffer "
+		     "integration",
+		     res);
+		return -1;
+	}
+}
+#endif
 
 static int gralloc_alloc_buffer(alloc_device_t *dev, size_t size, int usage, buffer_handle_t *pHandle)
 {
@@ -103,9 +122,26 @@
 	{
 		private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module);
 		ion_user_handle_t ion_hnd;
-		unsigned char *cpu_ptr;
+		void *cpu_ptr = MAP_FAILED;
 		int shared_fd;
 		int ret;
+		unsigned int heap_mask;
+		int lock_state = 0;
+		int map_mask = 0;
+
+		if (usage & GRALLOC_USAGE_PROTECTED)
+		{
+#if defined(ION_HEAP_SECURE_MASK)
+			heap_mask = ION_HEAP_SECURE_MASK;
+#else
+			AERR("The platform does NOT support protected ION memory.");
+			return -1;
+#endif
+		}
+		else
+		{
+			heap_mask = ION_HEAP_SYSTEM_MASK;
+		}
 
 		if (m->gralloc_legacy_ion)
 		{
@@ -149,7 +185,16 @@
 			}
 		}
 
-		cpu_ptr = (unsigned char *)mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, shared_fd, 0);
+		if (!(usage & GRALLOC_USAGE_PROTECTED))
+		{
+			map_mask = PROT_READ | PROT_WRITE;
+		}
+		else
+		{
+			map_mask = PROT_WRITE;
+		}
+
+		cpu_ptr = mmap(NULL, size, map_mask, MAP_SHARED, shared_fd, 0);
 
 		if (MAP_FAILED == cpu_ptr)
 		{
@@ -159,7 +204,9 @@
 			return -1;
 		}
 
-		private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_ION, usage, size, cpu_ptr, private_handle_t::LOCK_STATE_MAPPED);
+		lock_state = private_handle_t::LOCK_STATE_MAPPED;
+
+		private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_ION, usage, size, cpu_ptr, lock_state);
 
 		if (NULL != hnd)
 		{
@@ -173,6 +220,7 @@
 		}
 
 		close(shared_fd);
+
 		ret = munmap(cpu_ptr, size);
 
 		if (0 != ret)
@@ -213,48 +261,55 @@
 		else
 #endif
 		{
-			ump_mem_handle = ump_ref_drv_allocate(size, constraints);
-
-			if (UMP_INVALID_MEMORY_HANDLE != ump_mem_handle)
+			if (usage & GRALLOC_USAGE_PROTECTED)
 			{
-				cpu_ptr = ump_mapped_pointer_get(ump_mem_handle);
-
-				if (NULL != cpu_ptr)
-				{
-					ump_id = ump_secure_id_get(ump_mem_handle);
-
-					if (UMP_INVALID_SECURE_ID != ump_id)
-					{
-						private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_UMP, usage, size, cpu_ptr,
-						        private_handle_t::LOCK_STATE_MAPPED, ump_id, ump_mem_handle);
-
-						if (NULL != hnd)
-						{
-							*pHandle = hnd;
-							return 0;
-						}
-						else
-						{
-							AERR("gralloc_alloc_buffer() failed to allocate handle. ump_handle = %p, ump_id = %d", ump_mem_handle, ump_id);
-						}
-					}
-					else
-					{
-						AERR("gralloc_alloc_buffer() failed to retrieve valid secure id. ump_handle = %p", ump_mem_handle);
-					}
-
-					ump_mapped_pointer_release(ump_mem_handle);
-				}
-				else
-				{
-					AERR("gralloc_alloc_buffer() failed to map UMP memory. ump_handle = %p", ump_mem_handle);
-				}
-
-				ump_reference_release(ump_mem_handle);
+				AERR("gralloc_alloc_buffer() does not support to allocate protected UMP memory.");
 			}
 			else
 			{
-				AERR("gralloc_alloc_buffer() failed to allocate UMP memory. size:%d constraints: %d", size, constraints);
+				ump_mem_handle = ump_ref_drv_allocate(size, constraints);
+
+				if (UMP_INVALID_MEMORY_HANDLE != ump_mem_handle)
+				{
+					cpu_ptr = ump_mapped_pointer_get(ump_mem_handle);
+
+					if (NULL != cpu_ptr)
+					{
+						ump_id = ump_secure_id_get(ump_mem_handle);
+
+						if (UMP_INVALID_SECURE_ID != ump_id)
+						{
+							private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_USES_UMP, usage, size, cpu_ptr,
+							        private_handle_t::LOCK_STATE_MAPPED, ump_id, ump_mem_handle);
+
+							if (NULL != hnd)
+							{
+								*pHandle = hnd;
+								return 0;
+							}
+							else
+							{
+								AERR("gralloc_alloc_buffer() failed to allocate handle. ump_handle = %p, ump_id = %d", ump_mem_handle, ump_id);
+							}
+						}
+						else
+						{
+							AERR("gralloc_alloc_buffer() failed to retrieve valid secure id. ump_handle = %p", ump_mem_handle);
+						}
+
+						ump_mapped_pointer_release(ump_mem_handle);
+					}
+					else
+					{
+						AERR("gralloc_alloc_buffer() failed to map UMP memory. ump_handle = %p", ump_mem_handle);
+					}
+
+					ump_reference_release(ump_mem_handle);
+				}
+				else
+				{
+					AERR("gralloc_alloc_buffer() failed to allocate UMP memory. size:%d constraints: %d", size, constraints);
+				}
 			}
 		}
 
@@ -280,7 +335,7 @@
 		}
 	}
 
-	const uint32_t bufferMask = m->bufferMask;
+	uint32_t bufferMask = m->bufferMask;
 	const uint32_t numBuffers = m->numBuffers;
 	const size_t bufferSize = m->finfo.line_length * m->info.yres;
 
@@ -296,8 +351,9 @@
 
 	if (bufferMask >= ((1LU << numBuffers) - 1))
 	{
-		// We ran out of buffers.
-		return -ENOMEM;
+		// We ran out of buffers, reset bufferMask.
+		bufferMask = 0;
+		m->bufferMask = 0;
 	}
 
 	void *vaddr = m->framebuffer->base;
@@ -314,10 +370,10 @@
 		vaddr = (void *)((uintptr_t)vaddr + bufferSize);
 	}
 
-	int fbdev_fd = m->framebuffer->shallow_fbdev_fd;
 	// The entire framebuffer memory is already mapped, now create a buffer object for parts of this memory
 	private_handle_t *hnd = new private_handle_t(private_handle_t::PRIV_FLAGS_FRAMEBUFFER, usage, size, vaddr,
-	        0, fbdev_fd, (uintptr_t)vaddr - (uintptr_t) m->framebuffer->base);
+	        0, m->framebuffer->fd, (uintptr_t)vaddr - (uintptr_t) m->framebuffer->base, m->framebuffer->fb_paddr);
+	
 #if GRALLOC_ARM_UMP_MODULE
 	hnd->ump_id = m->framebuffer->ump_id;
 
@@ -337,19 +393,23 @@
 #if GRALLOC_ARM_DMA_BUF_MODULE
 	{
 #ifdef FBIOGET_DMABUF
-		struct fb_dmabuf_export fb_dma_buf;
-
-		if (ioctl(fbdev_fd, FBIOGET_DMABUF, &fb_dma_buf) == 0)
+		/*
+		 * Perform allocator specific actions. If these fail we fall back to a regular buffer
+		 * which will be memcpy'ed to the main screen when fb_post is called.
+		 */
+		if (fb_get_framebuffer_dmabuf(m, hnd) == -1)
 		{
-			AINF("framebuffer accessed with dma buf (fd 0x%x)\n", (int)fb_dma_buf.fd);
-			hnd->share_fd = fb_dma_buf.fd;
-		}
+			int newUsage = (usage & ~GRALLOC_USAGE_HW_FB) | GRALLOC_USAGE_HW_2D;
 
+			AINF("Fallback to single buffering. Unable to map framebuffer memory to handle:%p", hnd);
+			return gralloc_alloc_buffer(dev, bufferSize, newUsage, pHandle);
+		}
 #endif
 	}
 
 	// correct numFds/numInts when there is no dmabuf fd
-	if (hnd->share_fd < 0) {
+	if (hnd->share_fd < 0)
+	{
 		hnd->numFds--;
 		hnd->numInts++;
 	}
@@ -400,7 +460,12 @@
 #ifdef SUPPORT_LEGACY_FORMAT
 			case HAL_PIXEL_FORMAT_YCbCr_420_P:
 #endif
-				stride = GRALLOC_ALIGN(w, 16);
+				/*
+				 * Since Utgard has limitation that "64-byte alignment is enforced on texture and mipmap addresses", here to make sure
+				 * the v, u plane start addresses are 64-byte aligned.
+				 */
+				stride = GRALLOC_ALIGN(w, (h % 8 == 0) ? GRALLOC_ALIGN_BASE_16 :
+										 ((h % 4 == 0) ? GRALLOC_ALIGN_BASE_64 : GRALLOC_ALIGN_BASE_128));
 				size = GRALLOC_ALIGN(h, 2) * (stride + GRALLOC_ALIGN(stride / 2, 16));
 
 				break;
@@ -530,7 +595,7 @@
 	return 0;
 }
 
-static int alloc_device_free(alloc_device_t *dev, buffer_handle_t handle)
+static int alloc_device_free(alloc_device_t __unused *dev, buffer_handle_t handle)
 {
 	if (private_handle_t::validate(handle) < 0)
 	{
@@ -541,12 +606,6 @@
 
 	if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)
 	{
-		// free this buffer
-		private_module_t *m = reinterpret_cast<private_module_t *>(dev->common.module);
-		const size_t bufferSize = m->finfo.line_length * m->info.yres;
-		int index = ((uintptr_t)hnd->base - (uintptr_t)m->framebuffer->base) / bufferSize;
-		m->bufferMask &= ~(1 << index);
-
 #if GRALLOC_ARM_UMP_MODULE
 
 		if ((int)UMP_INVALID_MEMORY_HANDLE != hnd->ump_mem_handle)
@@ -568,7 +627,7 @@
 		}
 
 #else
-		AERR("Can't free ump memory for handle:0x%p. Not supported.", hnd);
+		AERR("Can't free ump memory for handle:%p. Not supported.", hnd);
 #endif
 	}
 	else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION)
@@ -579,7 +638,7 @@
 		{
 			if (0 != munmap((void *)hnd->base, hnd->size))
 			{
-				AERR("Failed to munmap handle 0x%p", hnd);
+				AERR("Failed to munmap handle %p", hnd);
 			}
 		}
 
diff --git a/gralloc/alloc_device.h b/gralloc/alloc_device.h
index 534a0d6..563c27c 100644
--- a/gralloc/alloc_device.h
+++ b/gralloc/alloc_device.h
@@ -19,17 +19,23 @@
 #include <hardware/hardware.h>
 
 #ifndef AWAR
-#define AWAR(fmt, args...) __android_log_print(ANDROID_LOG_WARN, "[Gralloc-Warning]", "%s:%d " fmt,__func__,__LINE__,args)
+#define AWAR(fmt, args...) __android_log_print(ANDROID_LOG_WARN, "[Gralloc-Warning]", "%s:%d " fmt,__func__,__LINE__,##args)
 #endif
 #ifndef AINF
-#define AINF(fmt, args...) __android_log_print(ANDROID_LOG_INFO, "[Gralloc]", fmt,args)
+#define AINF(fmt, args...) __android_log_print(ANDROID_LOG_INFO, "[Gralloc]", fmt,##args)
 #endif
 #ifndef AERR
-#define AERR(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, "[Gralloc-ERROR]", "%s:%d " fmt,__func__,__LINE__,args)
+#define AERR(fmt, args...) __android_log_print(ANDROID_LOG_ERROR, "[Gralloc-ERROR]", "%s:%d " fmt,__func__,__LINE__,##args)
 #endif
 #ifndef AERR_IF
 #define AERR_IF( eq, fmt, args...) if ( (eq) ) AERR( fmt, args )
 #endif
 
+#define GRALLOC_ALIGN( value, base ) (((value) + ((base) - 1)) & ~((base) - 1))
+
+#define	GRALLOC_ALIGN_BASE_16   16
+#define	GRALLOC_ALIGN_BASE_64   64
+#define	GRALLOC_ALIGN_BASE_128  128
+
 // Create an alloc device
 int alloc_device_open(hw_module_t const *module, const char *name, hw_device_t **device);
diff --git a/gralloc/framebuffer_device.cpp b/gralloc/framebuffer_device.cpp
index bacefee..6ab88a5 100644
--- a/gralloc/framebuffer_device.cpp
+++ b/gralloc/framebuffer_device.cpp
@@ -22,6 +22,7 @@
 #include <sys/ioctl.h>
 #include <linux/fb.h>
 #include <stdlib.h>
+
 #include <cutils/log.h>
 #include <cutils/atomic.h>
 #include <hardware/hardware.h>
@@ -85,20 +86,17 @@
 		m->base.lock(&m->base, buffer, private_module_t::PRIV_USAGE_LOCKED_FOR_POST,
 		             0, 0, m->info.xres, m->info.yres, NULL);
 
-		const size_t offset = (uintptr_t)hnd->base - (uintptr_t)m->framebuffer->base;
 		int interrupt;
 		m->info.activate = FB_ACTIVATE_VBL;
-		m->info.yoffset = offset / m->finfo.line_length;
+		m->info.yoffset = hnd->offset / m->finfo.line_length;
 
 #ifdef STANDARD_LINUX_SCREEN
 #define FBIO_WAITFORVSYNC       _IOW('F', 0x20, __u32)
 #define S3CFB_SET_VSYNC_INT _IOW('F', 206, unsigned int)
 
-		int fbdev_fd = m->framebuffer->shallow_fbdev_fd;
-
-		if (ioctl(fbdev_fd, FBIOPAN_DISPLAY, &m->info) == -1)
+		if (ioctl(m->framebuffer->fd, FBIOPAN_DISPLAY, &m->info) == -1)
 		{
-			AERR("FBIOPAN_DISPLAY failed for fd: %d", fbdev_fd);
+			AERR("FBIOPAN_DISPLAY failed for fd: %d", m->framebuffer->fd);
 			m->base.unlock(&m->base, buffer);
 			return 0;
 		}
@@ -108,9 +106,9 @@
 			// enable VSYNC
 			interrupt = 1;
 
-			if (ioctl(fbdev_fd, S3CFB_SET_VSYNC_INT, &interrupt) < 0)
+			if (ioctl(m->framebuffer->fd, S3CFB_SET_VSYNC_INT, &interrupt) < 0)
 			{
-				//      AERR("S3CFB_SET_VSYNC_INT enable failed for fd: %d", fbdev_fd);
+				//      AERR("S3CFB_SET_VSYNC_INT enable failed for fd: %d", m->framebuffer->fd);
 				return 0;
 			}
 
@@ -120,9 +118,9 @@
 #endif
 			int crtc = 0;
 
-			if (ioctl(fbdev_fd, FBIO_WAITFORVSYNC, &crtc) < 0)
+			if (ioctl(m->framebuffer->fd, FBIO_WAITFORVSYNC, &crtc) < 0)
 			{
-				AERR("FBIO_WAITFORVSYNC failed for fd: %d", fbdev_fd);
+				AERR("FBIO_WAITFORVSYNC failed for fd: %d", m->framebuffer->fd);
 #ifdef MALI_VSYNC_EVENT_REPORT_ENABLE
 				gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT);
 #endif
@@ -135,9 +133,9 @@
 			// disable VSYNC
 			interrupt = 0;
 
-			if (ioctl(fbdev_fd, S3CFB_SET_VSYNC_INT, &interrupt) < 0)
+			if (ioctl(m->framebuffer->fd, S3CFB_SET_VSYNC_INT, &interrupt) < 0)
 			{
-				AERR("S3CFB_SET_VSYNC_INT disable failed for fd: %d", fbdev_fd);
+				AERR("S3CFB_SET_VSYNC_INT disable failed for fd: %d", m->framebuffer->fd);
 				return 0;
 			}
 		}
@@ -148,9 +146,9 @@
 		gralloc_mali_vsync_report(MALI_VSYNC_EVENT_BEGIN_WAIT);
 #endif
 
-		if (ioctl(fbdev_fd, FBIOPUT_VSCREENINFO, &m->info) == -1)
+		if (ioctl(m->framebuffer->fd, FBIOPUT_VSCREENINFO, &m->info) == -1)
 		{
-			AERR("FBIOPUT_VSCREENINFO failed for fd: %d", fbdev_fd);
+			AERR("FBIOPUT_VSCREENINFO failed for fd: %d", m->framebuffer->fd);
 #ifdef MALI_VSYNC_EVENT_REPORT_ENABLE
 			gralloc_mali_vsync_report(MALI_VSYNC_EVENT_END_WAIT);
 #endif
@@ -254,14 +252,14 @@
 	 * Explicitly request 8/8/8
 	 */
 	info.bits_per_pixel = 32;
-	info.red.offset     = 0;
+	info.red.offset     = 16;
 	info.red.length     = 8;
 	info.green.offset   = 8;
 	info.green.length   = 8;
-	info.blue.offset    = 16;
+	info.blue.offset    = 0;
 	info.blue.length    = 8;
-	info.transp.offset  = 24;
-	info.transp.length  = 8;
+	info.transp.offset  = 0;
+	info.transp.length  = 0;
 #endif
 
 	/*
@@ -385,7 +383,11 @@
 
 	// Create a "fake" buffer object for the entire frame buffer memory, and store it in the module
 	module->framebuffer = new private_handle_t(private_handle_t::PRIV_FLAGS_FRAMEBUFFER, 0, fbSize, vaddr,
-	        0, fd, 0);
+	        0, fd, 0, (void *)finfo.smem_start);
+
+	/* There is no share_fd in framebuffer handle, correct numFds/numInts */
+	module->framebuffer->numFds--;
+	module->framebuffer->numInts++;
 
 	module->numBuffers = info.yres_virtual / info.yres;
 	module->bufferMask = 0;
@@ -471,12 +473,6 @@
 
 	/* initialize our state here */
 	framebuffer_device_t *dev = (framebuffer_device_t *)malloc(sizeof(framebuffer_device_t));
-	if (dev == NULL)
-	{
-		AERR("Error to malloc the framebuffer (%s)", strerror(errno));
-		gralloc_close(gralloc_device);
-		return -ENOMEM;
-	}
 	memset(dev, 0, sizeof(*dev));
 
 	/* initialize the procs */
@@ -497,7 +493,7 @@
 #ifdef GRALLOC_16_BITS
 	const_cast<int &>(dev->format) = HAL_PIXEL_FORMAT_RGB_565;
 #else
-	const_cast<int &>(dev->format) = HAL_PIXEL_FORMAT_RGBA_8888;
+	const_cast<int &>(dev->format) = HAL_PIXEL_FORMAT_BGRA_8888;
 #endif
 	const_cast<float &>(dev->xdpi) = m->xdpi;
 	const_cast<float &>(dev->ydpi) = m->ydpi;
diff --git a/gralloc/gralloc_module.cpp b/gralloc/gralloc_module.cpp
index 38ed3da..8405473 100644
--- a/gralloc/gralloc_module.cpp
+++ b/gralloc/gralloc_module.cpp
@@ -19,6 +19,8 @@
 #include <errno.h>
 #include <pthread.h>
 #include <string.h>
+//#include <sync/sync.h>
+#include <android/sync.h>
 
 #include <cutils/log.h>
 #include <cutils/atomic.h>
@@ -64,7 +66,7 @@
 
 	if (private_handle_t::validate(handle) < 0)
 	{
-		AERR("Registering invalid buffer 0x%p, returning error", handle);
+		AERR("Registering invalid buffer %p, returning error", handle);
 		return -EINVAL;
 	}
 
@@ -97,9 +99,8 @@
 
 	if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)
 	{
-		AINF("Register framebuffer 0x%p is no-op", handle);
+		AINF("Register buffer %p although it will be treated as a nop", handle);
 		retval = 0;
-
 	}
 	else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP)
 	{
@@ -114,6 +115,7 @@
 			{
 				hnd->writeOwner = 0;
 				hnd->lockState &= ~(private_handle_t::LOCK_STATE_UNREGISTERED);
+
 				pthread_mutex_unlock(&s_map_lock);
 				return 0;
 			}
@@ -130,7 +132,7 @@
 		}
 
 #else
-		AERR("Gralloc does not support UMP. Unable to register UMP memory for handle 0x%p", hnd);
+		AERR("Gralloc does not support UMP. Unable to register UMP memory for handle %p", hnd);
 #endif
 	}
 	else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION)
@@ -147,7 +149,7 @@
 		}
 		else
 		{
-			AERR("Could not get gralloc module for handle: 0x%p", hnd);
+			AERR("Could not get gralloc module for handle: %p", hnd);
 			retval = -errno;
 			goto cleanup;
 		}
@@ -163,7 +165,7 @@
 
 			if (m->ion_client < 0)
 			{
-				AERR("Could not open ion device for handle: 0x%p", hnd);
+				AERR("Could not open ion device for handle: %p", hnd);
 				retval = -errno;
 				goto cleanup;
 			}
@@ -180,6 +182,7 @@
 
 		hnd->base = mappedAddress + hnd->offset;
 		hnd->lockState &= ~(private_handle_t::LOCK_STATE_UNREGISTERED);
+
 		pthread_mutex_unlock(&s_map_lock);
 		return 0;
 #endif
@@ -189,7 +192,9 @@
 		AERR("registering non-UMP buffer not supported. flags = %d", hnd->flags);
 	}
 
+#if GRALLOC_ARM_DMA_BUF_MODULE
 cleanup:
+#endif
 	pthread_mutex_unlock(&s_map_lock);
 	return retval;
 }
@@ -203,7 +208,7 @@
 		ump_reference_release((ump_handle)hnd->ump_mem_handle);
 		hnd->ump_mem_handle = (int)UMP_INVALID_MEMORY_HANDLE;
 #else
-		AERR("Can't unregister UMP buffer for handle 0x%p. Not supported", hnd);
+		AERR("Can't unregister UMP buffer for handle %p. Not supported", hnd);
 #endif
 	}
 	else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION)
@@ -214,7 +219,7 @@
 
 		if (munmap(base, size) < 0)
 		{
-			AERR("Could not munmap base:0x%p size:%lu '%s'", base, (unsigned long)size, strerror(errno));
+			AERR("Could not munmap base:%p size:%lu '%s'", base, (unsigned long)size, strerror(errno));
 		}
 
 #else
@@ -238,7 +243,7 @@
 
 	if (private_handle_t::validate(handle) < 0)
 	{
-		AERR("unregistering invalid buffer 0x%p, returning error", handle);
+		AERR("unregistering invalid buffer %p, returning error", handle);
 		return -EINVAL;
 	}
 
@@ -248,7 +253,7 @@
 
 	if (hnd->flags & private_handle_t::PRIV_FLAGS_FRAMEBUFFER)
 	{
-		AERR("Can't unregister buffer 0x%p as it is a framebuffer", handle);
+		AERR("Can't unregister buffer %p as it is a framebuffer", handle);
 	}
 	else if (hnd->pid == getpid()) // never unmap buffers that were not registered in this process
 	{
@@ -268,7 +273,7 @@
 	}
 	else
 	{
-		AERR("Trying to unregister buffer 0x%p from process %d that was not created in current process: %d", hnd, hnd->pid, getpid());
+		AERR("Trying to unregister buffer %p from process %d that was not created in current process: %d", hnd, hnd->pid, getpid());
 	}
 
 	return 0;
@@ -276,19 +281,27 @@
 
 static int gralloc_lock(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h, void **vaddr)
 {
+
+
 	if (private_handle_t::validate(handle) < 0)
 	{
-		AERR("Locking invalid buffer 0x%p, returning error", handle);
+		AERR("Locking invalid buffer %p, returning error", handle);
 		return -EINVAL;
 	}
 
 	private_handle_t *hnd = (private_handle_t *)handle;
 
+	if (hnd->format == HAL_PIXEL_FORMAT_YCbCr_420_888)
+	{
+		AERR("Buffer with format HAL_PIXEL_FORMAT_YCbCr_*_888 must be locked by lock_ycbcr()");
+		return -EINVAL;
+	}
+
 	pthread_mutex_lock(&s_map_lock);
 
 	if (hnd->lockState & private_handle_t::LOCK_STATE_UNREGISTERED)
 	{
-		AERR("Locking on an unregistered buffer 0x%p, returning error", hnd);
+		AERR("Locking on an unregistered buffer %p, returning error", hnd);
 		pthread_mutex_unlock(&s_map_lock);
 		return -EINVAL;
 	}
@@ -315,13 +328,93 @@
 	return 0;
 }
 
+static int gralloc_lock_ycbcr(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h, struct android_ycbcr *ycbcr)
+{
+	int retval = 0;
+	int ystride, cstride;
+
+	if (private_handle_t::validate(handle) < 0)
+	{
+		AERR("Locking invalid buffer %p, returning error", handle);
+		return -EINVAL;
+	}
+
+	private_handle_t *hnd = (private_handle_t *)handle;
+
+	pthread_mutex_lock(&s_map_lock);
+
+	if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_UMP || hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION)
+	{
+		hnd->writeOwner = usage & GRALLOC_USAGE_SW_WRITE_MASK;
+	}
+
+	hnd->lockState |= private_handle_t::LOCK_STATE_WRITE;
+
+	pthread_mutex_unlock(&s_map_lock);
+
+
+	if (usage & (GRALLOC_USAGE_SW_READ_MASK | GRALLOC_USAGE_SW_WRITE_MASK))
+	{
+		switch (hnd->format)
+		{
+			case HAL_PIXEL_FORMAT_YCrCb_420_SP:
+				ystride = cstride = GRALLOC_ALIGN(hnd->width, 16);
+				ycbcr->y  = (void *)hnd->base;
+				ycbcr->cr = (void *)((unsigned char *)hnd->base + ystride * hnd->height);
+				ycbcr->cb = (void *)((unsigned char *)hnd->base + ystride * hnd->height + 1);
+				ycbcr->ystride = ystride;
+				ycbcr->cstride = cstride;
+				ycbcr->chroma_step = 2;
+				break;
+
+			case HAL_PIXEL_FORMAT_YV12:
+				/* Here to keep consistency with YV12 alignment, define the ystride according to image height. */
+				ystride = GRALLOC_ALIGN(hnd->width, (hnd->height % 8 == 0) ? GRALLOC_ALIGN_BASE_16 :
+										  		   ((hnd->height % 4 == 0) ? GRALLOC_ALIGN_BASE_64 : GRALLOC_ALIGN_BASE_128));
+				cstride = GRALLOC_ALIGN(ystride / 2, 16);
+				ycbcr->y  = (void *)hnd->base;
+				/* the ystride calc is assuming the height can at least be divided by 2 */
+				ycbcr->cr = (void *)((unsigned char *)hnd->base + ystride * GRALLOC_ALIGN(hnd->height, 2));
+				ycbcr->cb = (void *)((unsigned char *)hnd->base + ystride * GRALLOC_ALIGN(hnd->height, 2) + cstride * hnd->height / 2);
+				ycbcr->ystride = ystride;
+				ycbcr->cstride = cstride;
+				ycbcr->chroma_step = 1;
+				break;
+
+#ifdef SUPPORT_LEGACY_FORMAT
+
+			case HAL_PIXEL_FORMAT_YCbCr_420_SP:
+				ystride = cstride = GRALLOC_ALIGN(hnd->width, 16);
+				ycbcr->y  = (void *)hnd->base;
+				ycbcr->cb = (void *)((unsigned char *)hnd->base + ystride * hnd->height);
+				ycbcr->cr = (void *)((unsigned char *)hnd->base + ystride * hnd->height + 1);
+				ycbcr->ystride = ystride;
+				ycbcr->cstride = cstride;
+				ycbcr->chroma_step = 2;
+				break;
+#endif
+
+			default:
+				AERR("Can not lock buffer, invalid format: 0x%x", hnd->format);
+				retval = -EINVAL;
+		}
+	}
+
+	MALI_IGNORE(module);
+	MALI_IGNORE(l);
+	MALI_IGNORE(t);
+	MALI_IGNORE(w);
+	MALI_IGNORE(h);
+	return retval;
+}
+
 static int gralloc_unlock(gralloc_module_t const *module, buffer_handle_t handle)
 {
 	MALI_IGNORE(module);
 
 	if (private_handle_t::validate(handle) < 0)
 	{
-		AERR("Unlocking invalid buffer 0x%p, returning error", handle);
+		AERR("Unlocking invalid buffer %p, returning error", handle);
 		return -EINVAL;
 	}
 
@@ -332,18 +425,25 @@
 #if GRALLOC_ARM_UMP_MODULE
 		ump_cpu_msync_now((ump_handle)hnd->ump_mem_handle, UMP_MSYNC_CLEAN_AND_INVALIDATE, (void *)hnd->base, hnd->size);
 #else
-		AERR("Buffer 0x%p is UMP type but it is not supported", hnd);
+		AERR("Buffer %p is UMP type but it is not supported", hnd);
 #endif
 	}
 	else if (hnd->flags & private_handle_t::PRIV_FLAGS_USES_ION && hnd->writeOwner)
 	{
 #if GRALLOC_ARM_DMA_BUF_MODULE
 		hw_module_t *pmodule = NULL;
+		private_module_t *m = NULL;
 
-		if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&pmodule) != 0)
+		if (hw_get_module(GRALLOC_HARDWARE_MODULE_ID, (const hw_module_t **)&pmodule) == 0)
 		{
-			AERR("Couldnot get gralloc module for handle 0x%p\n", handle);
+			m = reinterpret_cast<private_module_t *>(pmodule);
+			//ion_sync_fd(m->ion_client, hnd->share_fd);
 		}
+		else
+		{
+			AERR("Couldnot get gralloc module for handle %p\n", handle);
+		}
+
 #endif
 	}
 
@@ -362,11 +462,48 @@
 	return 0;
 }
 
+#if defined(GRALLOC_MODULE_API_VERSION_0_3)
+static int gralloc_lock_async (gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h, void **vaddr, int fenceFD)
+{
+	if (fenceFD >= 0)
+	{
+		sync_wait(fenceFD, -1);
+		close(fenceFD);
+	}
+
+	return gralloc_lock(module, handle, usage, l, t, w, h, vaddr);
+}
+
+static int gralloc_unlock_async(gralloc_module_t const *module, buffer_handle_t handle, int *fenceFD)
+{
+	*fenceFD = -1;
+
+	if (gralloc_unlock(module, handle) < 0)
+	{
+		return -EINVAL;
+	}
+
+	return 0;
+
+}
+
+static int gralloc_lock_async_ycbcr(gralloc_module_t const *module, buffer_handle_t handle, int usage, int l, int t, int w, int h, struct android_ycbcr *ycbcr, int fenceFD)
+{
+	if (fenceFD >= 0)
+	{
+		sync_wait(fenceFD, -1);
+		close(fenceFD);
+	}
+
+	return gralloc_lock_ycbcr(module, handle, usage, l, t, w, h, ycbcr);
+}
+#endif
+
 // There is one global instance of the module
 
 static struct hw_module_methods_t gralloc_module_methods =
 {
-	.open =	gralloc_device_open,
+	.open = gralloc_device_open
 };
 
 private_module_t::private_module_t()
@@ -374,7 +511,11 @@
 #define INIT_ZERO(obj) (memset(&(obj),0,sizeof((obj))))
 
 	base.common.tag = HARDWARE_MODULE_TAG;
-	base.common.version_major = 1;
+#if defined(GRALLOC_MODULE_API_VERSION_0_3)
+	base.common.version_major = GRALLOC_MODULE_API_VERSION_0_3;
+#else
+	base.common.version_major = GRALLOC_MODULE_API_VERSION_0_2;
+#endif
 	base.common.version_minor = 0;
 	base.common.id = GRALLOC_HARDWARE_MODULE_ID;
 	base.common.name = "Graphics Memory Allocator Module";
@@ -388,6 +529,12 @@
 	base.lock = gralloc_lock;
 	base.unlock = gralloc_unlock;
 	base.perform = NULL;
+	base.lock_ycbcr = gralloc_lock_ycbcr;
+#if defined(GRALLOC_MODULE_API_VERSION_0_3)
+	base.lockAsync = gralloc_lock_async;
+	base.unlockAsync = gralloc_unlock_async;
+	base.lockAsync_ycbcr = gralloc_lock_async_ycbcr;
+#endif
 	INIT_ZERO(base.reserved_proc);
 
 	framebuffer = NULL;
diff --git a/gralloc/gralloc_priv.h b/gralloc/gralloc_priv.h
index 582c487..71920e0 100644
--- a/gralloc/gralloc_priv.h
+++ b/gralloc/gralloc_priv.h
@@ -60,6 +60,8 @@
 	__u32 fd;
 	__u32 flags;
 };
+
+/* Un-comment this line to use dma_buf framebuffer */
 /*#define FBIOGET_DMABUF    _IOR('F', 0x21, struct fb_dmabuf_export)*/
 
 #if PLATFORM_SDK_VERSION >= 21
@@ -150,7 +152,7 @@
 		LOCK_STATE_WRITE     =   1 << 31,
 		LOCK_STATE_MAPPED    =   1 << 30,
 		LOCK_STATE_UNREGISTERED  =   1 << 29,
-		LOCK_STATE_READ_MASK =   0x1FFFFFFF
+		LOCK_STATE_READ_MASK =   0x3FFFFFFF
 	};
 
 	// ints
@@ -184,11 +186,15 @@
 #endif
 
 	// Following members is for framebuffer only
-	int     shallow_fbdev_fd; // shallow copy, not dup'ed
+	int     fd; //Shallow copy, DO NOT duplicate
 	int     offset;
-
+	union
+	{
+		void *fb_paddr;
+		uint64_t fb_paddr_padding;
+	};
 #if GRALLOC_ARM_DMA_BUF_MODULE
-	ion_user_handle_t ion_hnd_UNUSED;
+	ion_user_handle_t ion_hnd;
 #endif
 
 #if GRALLOC_ARM_DMA_BUF_MODULE
@@ -221,11 +227,12 @@
 		yuv_info(MALI_YUV_NO_INFO),
 		ump_id((int)secure_id),
 		ump_mem_handle((int)handle),
-		shallow_fbdev_fd(0),
-		offset(0)
+		fd(0),
+		offset(0),
+		fb_paddr(NULL)
 #if GRALLOC_ARM_DMA_BUF_MODULE
 		,
-		ion_hnd_UNUSED(ION_INVALID_HANDLE)
+		ion_hnd(ION_INVALID_HANDLE)
 #endif
 
 	{
@@ -255,9 +262,10 @@
 		ump_id((int)UMP_INVALID_SECURE_ID),
 		ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE),
 #endif
-		shallow_fbdev_fd(0),
+		fd(0),
 		offset(0),
-		ion_hnd_UNUSED(ION_INVALID_HANDLE)
+		fb_paddr(NULL),
+		ion_hnd(ION_INVALID_HANDLE)
 
 	{
 		version = sizeof(native_handle);
@@ -267,7 +275,7 @@
 
 #endif
 
-	private_handle_t(int flags, int usage, int size, void *base, int lock_state, int fb_file, int fb_offset):
+	private_handle_t(int flags, int usage, int size, void *base, int lock_state, int fb_file, int fb_offset, void *fb_paddr):
 #if GRALLOC_ARM_DMA_BUF_MODULE
 		share_fd(-1),
 #endif
@@ -288,11 +296,12 @@
 		ump_id((int)UMP_INVALID_SECURE_ID),
 		ump_mem_handle((int)UMP_INVALID_MEMORY_HANDLE),
 #endif
-		shallow_fbdev_fd(fb_file),
-		offset(fb_offset)
+		fd(fb_file),
+		offset(fb_offset),
+		fb_paddr(fb_paddr)
 #if GRALLOC_ARM_DMA_BUF_MODULE
 		,
-		ion_hnd_UNUSED(ION_INVALID_HANDLE)
+		ion_hnd(ION_INVALID_HANDLE)
 #endif
 
 	{
@@ -315,21 +324,23 @@
 	{
 		const private_handle_t *hnd = (const private_handle_t *)h;
 
-		if (!h || h->version != sizeof(native_handle) || hnd->magic != sMagic)
+		if (!hnd || hnd->version != sizeof(native_handle) || hnd->magic != sMagic)
 		{
 			return -EINVAL;
 		}
 
 		int numFds = sNumFds;
 		int numInts = (sizeof(private_handle_t) - sizeof(native_handle)) / sizeof(int) - sNumFds;
+
 #if GRALLOC_ARM_DMA_BUF_MODULE
-		if (hnd->share_fd < 0) {
+		if (hnd->share_fd < 0)
+		{
 			numFds--;
 			numInts++;
 		}
 #endif
 
-		if (h->numFds != numFds || h->numInts != numInts)
+		if (hnd->numFds != numFds || hnd->numInts != numInts)
 		{
 			return -EINVAL;
 		}
diff --git a/hikey/device-hikey.mk b/hikey/device-hikey.mk
index fe6b6b6..79c8d1b 100644
--- a/hikey/device-hikey.mk
+++ b/hikey/device-hikey.mk
@@ -41,5 +41,5 @@
 # Sensors HAL
 PRODUCT_PACKAGES += sensors.hikey
 
-# Include vendor binaries
-$(call inherit-product-if-exists, vendor/linaro/hikey/device-vendor.mk)
+# Include mali blobs from ARM
+PRODUCT_PACKAGES += libGLES_mali.so END_USER_LICENCE_AGREEMENT.txt
diff --git a/mali/utgard/Android.mk b/mali/utgard/Android.mk
new file mode 100644
index 0000000..09aaf31
--- /dev/null
+++ b/mali/utgard/Android.mk
@@ -0,0 +1,26 @@
+ifneq ($(filter hikey, $(TARGET_DEVICE)),)
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := END_USER_LICENCE_AGREEMENT.txt
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_STRIP_MODULE := false
+LOCAL_SRC_FILES_arm := $(LOCAL_MODULE)
+LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)
+LOCAL_MULTILIB := 32
+include $(BUILD_PREBUILT)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libGLES_mali.so
+LOCAL_MODULE_CLASS := SHARED_LIBRARIES
+LOCAL_STRIP_MODULE := false
+LOCAL_SRC_FILES_arm := lib/egl/$(LOCAL_MODULE)
+LOCAL_SRC_FILES_arm64 := lib64/egl/$(LOCAL_MODULE)
+LOCAL_MODULE_PATH_32 := $(TARGET_OUT_VENDOR)/lib/egl/
+LOCAL_MODULE_PATH_64 := $(TARGET_OUT_VENDOR)/lib64/egl/
+LOCAL_MULTILIB := both
+include $(BUILD_PREBUILT)
+
+endif
+
+
diff --git a/mali/utgard/END_USER_LICENCE_AGREEMENT.txt b/mali/utgard/END_USER_LICENCE_AGREEMENT.txt
new file mode 100644
index 0000000..34da5f8
--- /dev/null
+++ b/mali/utgard/END_USER_LICENCE_AGREEMENT.txt
@@ -0,0 +1,194 @@
+LES-PRE-20769

+SP-Version: 1.0

+25 November 2015

+

+END USER LICENCE AGREEMENT FOR THE MALI USERSPACE DRIVER ("Mali DRIVER")

+

+THIS END USER LICENCE AGREEMENT ("LICENCE") IS A LEGAL AGREEMENT

+BETWEEN YOU (EITHER A SINGLE INDIVIDUAL, OR SINGLE LEGAL ENTITY) AND

+ARM LIMITED ("ARM") FOR THE USE OF THE SOFTWARE ACCOMPANYING THIS

+LICENCE. ARM IS ONLY WILLING TO LICENSE THE SOFTWARE TO YOU ON

+CONDITION THAT YOU ACCEPT ALL OF THE TERMS IN THIS LICENCE. BY

+INSTALLING OR OTHERWISE USING OR COPYING THE SOFTWARE YOU INDICATE

+THAT YOU AGREE TO BE BOUND BY ALL OF THE TERMS OF THIS LICENCE. IF YOU

+DO NOT AGREE TO THE TERMS OF THIS LICENCE, ARM IS UNWILLING TO LICENSE

+THE SOFTWARE TO YOU AND YOU MAY NOT INSTALL, USE OR COPY THE SOFTWARE,

+AND YOU SHOULD PROMPTLY RETURN THE SOFTWARE TO YOUR SUPPLIER.

+

+"Applications" means applications for use solely in conjunction with

+Mali-based products manufactured under licence from ARM.

+

+"Output" means data resulting from your use of the Software and all

+direct and indirect derivatives thereof.

+

+"Software" means any software, firmware and data accompanying this

+Licence, any printed, electronic or online documentation supplied with

+it under the terms of this Licence for the Mali Driver.

+

+1. LICENCE GRANTS TO YOU.

+

+1.1 ARM hereby grants to you, subject to the terms and conditions of

+this Licence, a non-exclusive, non-transferable, revocable, worldwide

+licence to:

+

+(i)	use and copy the Software or certain components or optional

+	functionality in the Software, as applicable, solely for the

+	purposes of running, designing or developing Applications; and

+

+(ii)	subject to Clause 1.2, distribute the whole of the Software;

+	and/or (b) the whole or any part of the Software together

+	with, or as incorporated into, Applications; and

+

+1.2 If you choose to redistribute the whole or any part of the

+Software pursuant to the licences granted in Clause 1.1(ii), you

+agree: (i) not to use ARM's or any of its licensors names, logos or

+trademarks to market Applications; (ii) to retain any and all

+copyright notices and other notices (whether ARM's or its licensor's)

+which are included with the Software; and (iii) include a copy of this

+Licence with such redistribution.

+

+2. RESTRICTIONS ON USE OF THE SOFTWARE.

+

+BENCHMARKING: This Licence does not prevent you from using the

+Software for benchmarking purposes. However, you shall ensure that any

+and all benchmarking data relating to the Software, and any other

+results of your use or testing of the Software which are indicative of

+its performance, efficacy, reliability or quality, shall not be used

+to disparage ARM, its products or services, or in a manner that, in

+ARM's reasonable judgment, may diminish or otherwise damage the

+reputation of ARM.

+

+COPYRIGHT AND RESERVATION OF RIGHTS: The Software is owned by ARM or

+its licensors and is protected by copyright and other intellectual

+property laws and international treaties. The Software is licensed not

+sold. You acquire no rights to the Software other than as expressly

+provided by this Licence. You shall not remove from the Software any

+copyright notice or other notice and shall ensure that any such notice

+is reproduced in any copies of the whole or any part of the Software

+made by you or other permitted users.

+

+REVERSE ENGINEERING: Except to the extent that such activity is

+permitted by applicable law you shall not reverse engineer, decompile

+or disassemble any of the Software. If the Software was provided to

+you in Europe you shall not reverse engineer, decompile or disassemble

+any of the Software for the purposes of error correction.

+

+RESTRICTED USE: You agree that you shall not use the Software or the

+Output other than pursuant to and in accordance with the exercise of

+any of the licences granted under this Licence. Without limiting the

+generality of the foregoing, you shall not use the Software or any

+Output: (a) for determining if any features, functions or processes

+provided by the Software are covered by any patents or patent

+applications owned by you or a third party; or (b) for developing

+technology, applications or products which avoid any of ARM's

+intellectual property in the Software licensed hereunder; or (c) as a

+reference for modifying existing patents or patent applications or

+creating any continuation, continuation in part, or extension of

+existing patents or patent applications.

+

+3. SUPPORT.

+

+ARM is not under an obligation to provide support, but it may do so at

+its own discretion, and if it does, it will only be in respect of the

+Software as delivered.

+

+4. NO WARRANTIES.

+

+YOU AGREE THAT THE SOFTWARE IS LICENSED "AS IS", AND THAT ARM

+EXPRESSLY DISCLAIMS ALL REPRESENTATIONS, WARRANTIES, CONDITIONS OR

+OTHER TERMS, EXPRESS OR IMPLIED OR STATUTORY, INCLUDING WITHOUT

+LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, SATISFACTORY

+QUALITY, AND FITNESS FOR A PARTICULAR PURPOSE.

+

+YOU EXPRESSLY ASSUME ALL LIABILITIES AND RISKS, FOR USE OR OPERATION

+OF APPLICATIONS, INCLUDING WITHOUT LIMITATION, APPLICATIONS DESIGNED

+OR INTENDED FOR MISSION CRITICAL APPLICATIONS, SUCH AS PACEMAKERS,

+WEAPONRY, AIRCRAFT NAVIGATION, FACTORY CONTROL SYSTEMS, ETC. SHOULD

+THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE ENTIRE COST OF ALL

+NECESSARY SERVICING, REPAIR OR CORRECTION.

+

+5. LIMITATION OF LIABILITY.

+

+TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL

+ARM BE LIABLE FOR ANY INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL

+DAMAGES (INCLUDING LOSS OF PROFITS) ARISING OUT OF THE USE OR

+INABILITY TO USE THE SOFTWARE WHETHER BASED ON A CLAIM UNDER CONTRACT,

+TORT OR OTHER LEGAL THEORY, EVEN IF ARM WAS ADVISED OF THE POSSIBILITY

+OF SUCH DAMAGES.

+

+ARM does not seek to limit or exclude liability for death or personal

+injury arising from ARM's negligence or ARM's fraud and because some

+jurisdictions do not permit the exclusion or limitation of liability

+for consequential or incidental damages the above limitation relating

+to liability for consequential damages may not apply to you.

+

+NOTWITHSTANDING ANYTHING TO THE CONTRARY CONTAINED IN THIS LICENCE,

+THE MAXIMUM LIABILITY OF ARM TO YOU IN AGGREGATE FOR ALL CLAIMS MADE

+AGAINST ARM IN CONTRACT TORT OR OTHERWISE UNDER OR IN CONNECTION WITH

+THE SUBJECT MATTER OF THIS LICENCE SHALL NOT EXCEED THE GREATER OF:

+(I) THE TOTAL OF SUMS PAID BY YOU TO ARM (IF ANY) FOR THIS LICENCE;

+AND (II) $10.00 USD. THE EXISTENCE OF MORE THAN ONE CLAIM WILL NOT

+ENLARGE OR EXTEND THE LIMIT.

+

+6. U.S. GOVERNMENT END USERS.

+

+US Government Restrictions: Use, duplication, reproduction, release,

+modification, disclosure or transfer of the Software is restricted in

+accordance with the terms of this Licence.

+

+7. TERM AND TERMINATION.

+

+This Licence shall remain in force until terminated by you or by ARM.

+Without prejudice to any of its other rights if you are in breach of

+any of the terms and conditions of this Licence then ARM may terminate

+this Licence immediately upon giving written notice to you or on

+thirty (30) days written notice without cause. You may terminate this

+Licence at any time. Upon termination of this Licence by you or by ARM

+, you shall stop using the Software and destroy all copies of the

+Software in your possession, together with all documentation and

+related materials. The provisions of clauses 2, 3, 4, 5, 6, 7, and 8

+shall survive termination of this Licence.

+

+8. GENERAL.

+

+This Licence is governed by English Law. Except where ARM agrees

+otherwise in: (i) a written contract signed by you and ARM; or (ii) a

+written contract provided by ARM and accepted by you, this is the only

+agreement between you and ARM relating to the Software and it may only

+be modified by written agreement between you and ARM. Except as

+expressly agreed in writing, this Licence may not be modified by

+purchase orders, advertising or other representation by any person. If

+any clause or sentence in this Licence is held by a court of law to be

+illegal or unenforceable the remaining provisions of this Licence

+shall not be affected thereby. The failure by ARM to enforce any of

+the provisions of this Licence, unless waived in writing, shall not

+constitute a waiver of ARM's rights to enforce such provision or any

+other provision of this Licence in the future.

+

+At ARM's request, you agree to check your computers for installations

+of the Software and any other information requested by ARM relating to

+Software installation and to provide this information to ARM. You

+agree that auditors nominated by ARM may also perform such checking

+and reporting on behalf of ARM by prior appointment during your normal

+business hours on seven (7) days' notice. ARM shall bear the auditors'

+costs for that audit unless it reveals unlicensed usage in which case

+you shall promptly reimburse ARM for all reasonable costs and

+expenses, including professional fees, relating to such audit. Any

+information which is disclosed to ARM or such auditors during checking

+or audit shall be treated as your confidential information and shall

+only be used by ARM for licence management, compliance and enforcement

+purposes.

+

+The Software provided under this Agreement is subject to U.K.,

+European Union, and U.S. export control laws and regulations,

+including the U.S. Export Administration Act and its associated

+regulations (hereafter collectively referred to as "Export

+Regulations").  LICENSEE agrees to comply fully with all such Export

+Regulations and LICENSEE agrees that it shall not, either directly or

+indirectly, export in breach of the Export Regulations, any Software

+received under this Agreement, nor any direct products thereof; (i) to

+any country, company or person subject to export restrictions or

+sanctions under the Export Regulations; or (ii) for any prohibited end

+use, which at the time of export requires an export license or other

+governmental approval, without first obtaining such license or

+approval.

diff --git a/mali/utgard/lib/egl/libGLES_mali.so b/mali/utgard/lib/egl/libGLES_mali.so
new file mode 100755
index 0000000..f86da7e
--- /dev/null
+++ b/mali/utgard/lib/egl/libGLES_mali.so
Binary files differ
diff --git a/mali/utgard/lib64/egl/libGLES_mali.so b/mali/utgard/lib64/egl/libGLES_mali.so
new file mode 100755
index 0000000..5c0af47
--- /dev/null
+++ b/mali/utgard/lib64/egl/libGLES_mali.so
Binary files differ