[Feature][ZXW-88]merge P50 version

Only Configure: No
Affected branch: master
Affected module: unknown
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No

Change-Id: I34667719d9e0e7e29e8e4368848601cde0a48408
diff --git a/ap/os/linux/linux-3.4.x/mm/mmap.c b/ap/os/linux/linux-3.4.x/mm/mmap.c
index 88d133b..702f65d 100755
--- a/ap/os/linux/linux-3.4.x/mm/mmap.c
+++ b/ap/os/linux/linux-3.4.x/mm/mmap.c
@@ -41,9 +41,11 @@
 
 #ifdef CONFIG_SYSVIPC_CROSS_SHM
 #include <../ipc/shm_ctrl.h>
-extern void shm_mmap_pagetable(struct vm_area_struct *vma, struct file *file);
-extern void shm_unmap_page_range(struct mm_struct *mm, struct vm_area_struct *vma,
-			                      unsigned long addr, unsigned long end);
+extern key_t shm_do_remote_analy_key(struct file *file);
+extern int   shm_ipc_mmap_pagetable(struct vm_area_struct *vma, struct file *file);
+static void  shm_delete_vma_from_mm(struct vm_area_struct *vma);
+static void  shm_delete_vma(struct mm_struct *mm, struct vm_area_struct *vma);
+
 #define kenter(FMT, ...) \
 	no_printk(KERN_DEBUG "==> %s("FMT")\n", __func__, ##__VA_ARGS__)
 #define kleave(FMT, ...) \
@@ -1435,11 +1437,18 @@
 		make_pages_present(addr, addr + len);
 	
 #ifdef CONFIG_SYSVIPC_CROSS_SHM 
-	/*Get real phy pgae*/
-	if (file && (file->f_flags == SHM_REMOTE_ATTR_YES))
-	{		
-		shm_mmap_pagetable(vma, file);		
-	}
+	if (file && ((file->shm_flags == SHM_REMOTE_SYSV_YES)
+		      || (file->shm_flags == SHM_REMOTE_POSIX_YES))) {
+		/*Get real phy pgae*/
+		error = shm_ipc_mmap_pagetable(vma, file);	
+		if (error < 0)
+		{
+			shm_delete_vma_from_mm(vma);
+			shm_delete_vma(mm, vma);
+			return error;
+		}
+	}	
+
 #endif
 	return addr;
 
@@ -2147,6 +2156,18 @@
 }
 
 #ifdef CONFIG_SYSVIPC_CROSS_SHM
+int shm_try_to_free_pages(struct file *file)
+{
+	int ret = 0;
+	key_t shm_key;
+
+	shm_key = shm_do_remote_analy_key(file);
+	ret     = shm_remote_free_pages(shm_key);
+	if (ret < 0)
+		printk("shm_try_to_free_pages Error\n");
+	return ret;
+}
+
 /*
  * delete a VMA from its owning mm_struct and address space
  */
@@ -2270,7 +2291,8 @@
 	}
 
 erase_whole_vma:
-	shm_unmap_page_range(mm, vma, start, end);
+	shm_unmap_page_range(mm, vma, start, end);	
+	shm_try_to_free_pages(vma->vm_file);
 	shm_delete_vma_from_mm(vma);
 	shm_delete_vma(mm, vma);
 	return 0;
@@ -2340,7 +2362,9 @@
 	vma = prev? prev->vm_next: mm->mmap;
 		
 #ifdef CONFIG_SYSVIPC_CROSS_SHM
-	if (vma->vm_file && (vma->vm_file->f_flags == SHM_REMOTE_ATTR_YES)) {
+	if (vma->vm_file && 
+		((vma->vm_file->shm_flags == SHM_REMOTE_SYSV_YES)
+		|| (vma->vm_file->shm_flags == SHM_REMOTE_POSIX_YES))) {
 		shm_ctrl_do_munmap(mm, start, len);
 		return 0;
 	}
@@ -2527,7 +2551,8 @@
 	vma_shm = mm->mmap;
 	while (vma_shm) {		
 		if ((vma_shm->vm_file) && 
-		   (vma_shm->vm_file->f_flags == SHM_REMOTE_ATTR_YES)) {
+		   ((vma_shm->vm_file->shm_flags == SHM_REMOTE_SYSV_YES)
+		    ||(vma_shm->vm_file->shm_flags == SHM_REMOTE_POSIX_YES))) {
 			vma = vma_shm->vm_next;
 			shm_ctrl_do_munmap(mm, vma_shm->vm_start, (vma_shm->vm_end - vma_shm->vm_start));
 			vma_shm = vma;