[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/ipc/shm_ctrl.c b/ap/os/linux/linux-3.4.x/ipc/shm_ctrl.c
index 598cb28..183a8bd 100755
--- a/ap/os/linux/linux-3.4.x/ipc/shm_ctrl.c
+++ b/ap/os/linux/linux-3.4.x/ipc/shm_ctrl.c
@@ -23,6 +23,10 @@
#define SHM_UNIT_BUFF_ORDER (12)
#define SHM_KEYS_STATUS_LEN (4*1024)
#define SHM_REMOTE_BUFF_LEN (128*1024)
+#define SHM_POSIX_HASH_CHARS (26)
+#define SHM_POSIX_HASH_BASE (62)
+#define SHM_POSIX_HASH_MASK (0x7FF)
+
#define SHM_BUFF_BASE_PHY_ADDR (g_shm_phyAddr)
#define SHM_UNIT_BUFF_SIZE (1UL<<SHM_UNIT_BUFF_ORDER) /*4KB*/
@@ -51,6 +55,36 @@
struct shm_entity *shm_remote_manager;
/*******************************************************************************
+* ¹¦ÄÜÃèÊö: shm_hash_name_to_key
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) name: ¹²ÏíÄÚ´æÃû³Æ
+* (´«Èë²ÎÊý) len: ¹²ÏíÄÚ´æÃû³Æ³¤¶È
+* (´«³ö²ÎÊý) ÎÞ
+* ·µ »Ø Öµ:
+* ÆäËü˵Ã÷: This function is used for calc hash value of the name(-2048~-4096)
+*******************************************************************************/
+key_t shm_hash_name_to_key(const char *name, int len)
+{
+ int i = 0;
+ key_t tmp_key = 0;
+ key_t hash_key = 0;
+ unsigned long long id = 0;
+
+ for (; i < len; i++)
+ {
+ if (name[i] >= 'A' && name[i] <= 'Z')
+ id = id*SHM_POSIX_HASH_BASE + name[i]-'A';
+ else if (name[i] >= 'a' && name[i] <= 'z')
+ id = id*SHM_POSIX_HASH_BASE + name[i]-'a' + SHM_POSIX_HASH_CHARS;
+ else if (name[i] >= '0' && name[i] <= '9')
+ id = id*SHM_POSIX_HASH_BASE + name[i]-'0' + 2*SHM_POSIX_HASH_CHARS;
+ }
+ tmp_key =(id & SHM_POSIX_HASH_MASK) + (SHM_POSIX_HASH_MASK + 1);
+ hash_key = ~tmp_key + 1;
+ return hash_key;
+}
+
+/*******************************************************************************
* ¹¦ÄÜÃèÊö: shm_quary_keyArray
* ²ÎÊý˵Ã÷:
* (´«Èë²ÎÊý) void
@@ -330,6 +364,58 @@
}
/*******************************************************************************
+* ¹¦ÄÜÃèÊö: shm_do_newseg_check
+* ²ÎÊý˵Ã÷:
+* (´«Èë²ÎÊý) void
+* (´«³ö²ÎÊý) void
+* ·µ »Ø Öµ: SHM_CTRL_OK or SHM_CTRL_ERROR
+* ÆäËü˵Ã÷: This function is used for check key and len
+*******************************************************************************/
+int shm_do_newseg_check(key_t key, unsigned long len)
+{
+ int ret = 0;
+ int key_index = 0;
+ unsigned int shm_weight = 0;
+ unsigned int shm_pages = 0;
+ struct shm_key_node *key_node = NULL;
+
+ if(g_shm_region == NULL)
+ {
+ printk("shm_do_newsg_check:Shm region is not ready\n");
+ return SHM_CTRL_ERROR;
+ }
+ soft_spin_lock(SHM_SFLOCK);
+
+ key_index = shm_quary_keyArray(key);
+
+ if (key_index < 0)
+ {
+ soft_spin_unlock(SHM_SFLOCK);
+ return SHM_CTRL_OK;
+ }
+
+ if ((0 <= key_index) && (key_index < SHM_UNIT_NUM_BITS))
+ {
+ key_node = &shm_remote_manager->keys_info_head[key_index];
+ }
+ else
+ {
+ soft_spin_unlock(SHM_SFLOCK);
+ panic("key_index out of range: failed\n");
+ }
+
+ shm_pages = PAGE_ALIGN(len) >> PAGE_SHIFT;
+ shm_weight = bitmap_weight(key_node->shm_inuse_index, SHM_UNIT_NUM_BITS);
+ soft_spin_unlock(SHM_SFLOCK);
+
+ /*APºÍCAP¹²ÏíÄÚ´æ´óСӦƥÅä*/
+ if(shm_weight != shm_pages)
+ return -EINVAL;
+ else
+ return SHM_CTRL_OK;
+}
+
+/*******************************************************************************
* ¹¦ÄÜÃèÊö: shm_do_remote_map_vma
* ²ÎÊý˵Ã÷:
* (´«Èë²ÎÊý) void
@@ -374,9 +460,14 @@
vm_addr = vma->vm_start;
if ((0 <= key_index) && (key_index < SHM_UNIT_NUM_BITS))
+ {
key_node = &shm_remote_manager->keys_info_head[key_index];
+ }
else
+ {
+ soft_spin_unlock(SHM_SFLOCK);
panic("key_index out of range: failed\n");
+ }
memcpy(shm_inuse_tmp, key_node->shm_inuse_index, sizeof(shm_inuse_tmp));