Commit 40dd8dd2 authored by Suman Anna's avatar Suman Anna Committed by Hari Kanigeri

SYSLINK: ipc - sharedregion fixes for sysmgr validation

This patch includes fixes in the sharedregion module for issues
found during sysmgr validation. The main change is to return
success if a add request is for an exact duplicate sharedregion entry.
The other change is to return success instead of failure if the
sharedregion module is already setup.
Signed-off-by: default avatarSuman Anna <s-anna@ti.com>
parent cd7989ab
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
/* Macro to make a correct module magic number with refCount */ /* Macro to make a correct module magic number with refCount */
#define SHAREDREGION_MAKE_MAGICSTAMP(x) ((SHAREDREGION_MODULEID << 16u) | (x)) #define SHAREDREGION_MAKE_MAGICSTAMP(x) ((SHAREDREGION_MODULEID << 16u) | (x))
#define SHAREDREGION_MAX_REGIONS_DEFAULT 256 #define SHAREDREGION_MAX_REGIONS_DEFAULT 4
/* /*
* Module state object * Module state object
...@@ -109,8 +109,7 @@ int sharedregion_setup(const struct sharedregion_config *config) ...@@ -109,8 +109,7 @@ int sharedregion_setup(const struct sharedregion_config *config)
if (atomic_inc_return(&sharedregion_state.ref_count) if (atomic_inc_return(&sharedregion_state.ref_count)
!= SHAREDREGION_MAKE_MAGICSTAMP(1)) { != SHAREDREGION_MAKE_MAGICSTAMP(1)) {
retval = -EEXIST; return 1;
goto error;
} }
if (config != NULL) { if (config != NULL) {
...@@ -223,6 +222,7 @@ int sharedregion_add(u32 index, void *base, u32 len) ...@@ -223,6 +222,7 @@ int sharedregion_add(u32 index, void *base, u32 len)
u32 i; u32 i;
u16 myproc_id; u16 myproc_id;
bool overlap = false; bool overlap = false;
bool same = false;
if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count), if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0), SHAREDREGION_MAKE_MAGICSTAMP(0),
...@@ -249,6 +249,12 @@ int sharedregion_add(u32 index, void *base, u32 len) ...@@ -249,6 +249,12 @@ int sharedregion_add(u32 index, void *base, u32 len)
+ (myproc_id * sharedregion_state.cfg.max_regions) + (myproc_id * sharedregion_state.cfg.max_regions)
+ i); + i);
if (entry->is_valid) { if (entry->is_valid) {
/* Handle duplicate entry */
if((base == entry->base) && (len == entry->len)) {
same = true;
break;
}
if ((base >= entry->base) && if ((base >= entry->base) &&
(base < (void *)((u32)entry->base + entry->len))) { (base < (void *)((u32)entry->base + entry->len))) {
overlap = true; overlap = true;
...@@ -263,6 +269,11 @@ int sharedregion_add(u32 index, void *base, u32 len) ...@@ -263,6 +269,11 @@ int sharedregion_add(u32 index, void *base, u32 len)
} }
} }
if (same) {
retval = 1;
goto success;
}
if (overlap) { if (overlap) {
retval = -EPERM; retval = -EPERM;
goto mem_overlap_error; goto mem_overlap_error;
...@@ -281,6 +292,7 @@ int sharedregion_add(u32 index, void *base, u32 len) ...@@ -281,6 +292,7 @@ int sharedregion_add(u32 index, void *base, u32 len)
goto dup_entry_error; goto dup_entry_error;
} }
success:
mutex_unlock(sharedregion_state.gate_handle); mutex_unlock(sharedregion_state.gate_handle);
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment