Commit d87225f0 authored by Arun Gopalakrishnan's avatar Arun Gopalakrishnan Committed by Hari Kanigeri

ARM OMAP4 Syslink IPC Shared Region Changes

This patch can be used to synk with the syslink drop 2.0.0.6
The major changes are
1. The atomic function usage related changes
2. The ioctl argument changes
Signed-off-by: default avatarArun M G <arunmg@ti.com>
parent d37403e3
...@@ -22,6 +22,12 @@ ...@@ -22,6 +22,12 @@
#include <linux/types.h> #include <linux/types.h>
/*
* SHAREDREGION_MODULEID
* Module ID for Shared region manager
*/
#define SHAREDREGION_MODULEID (0x5D8A)
/* /*
* Name of the reserved nameserver used for application * Name of the reserved nameserver used for application
*/ */
......
...@@ -119,6 +119,8 @@ union sharedregion_arg { ...@@ -119,6 +119,8 @@ union sharedregion_arg {
struct { struct {
struct sharedregion_config *config; struct sharedregion_config *config;
struct sharedregion_config *default_cfg;
struct sharedregion_info *table;
} setup; } setup;
struct { struct {
......
...@@ -20,18 +20,23 @@ ...@@ -20,18 +20,23 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <syslink/atomic_linux.h>
#include <gt.h> #include <gt.h>
#include <multiproc.h> #include <multiproc.h>
#include <nameserver.h> #include <nameserver.h>
#include <sharedregion.h> #include <sharedregion.h>
/* Macro to make a correct module magic number with refCount */
#define SHAREDREGION_MAKE_MAGICSTAMP(x) ((SHAREDREGION_MODULEID << 16u) | (x))
#define SHAREDREGION_MAX_REGIONS_DEFAULT 256 #define SHAREDREGION_MAX_REGIONS_DEFAULT 256
/* /*
* Module state object * Module state object
*/ */
struct sharedregion_object { struct sharedregion_module_object {
atomic_t ref_count; /* Reference count */
struct mutex *gate_handle; struct mutex *gate_handle;
struct sharedregion_info *table; /* Ptr to the table */ struct sharedregion_info *table; /* Ptr to the table */
u32 bitOffset; /* Index bit offset */ u32 bitOffset; /* Index bit offset */
...@@ -42,7 +47,7 @@ struct sharedregion_object { ...@@ -42,7 +47,7 @@ struct sharedregion_object {
/* /*
* Shared region state object variable with default settings * Shared region state object variable with default settings
*/ */
static struct sharedregion_object sharedregion_state = { static struct sharedregion_module_object sharedregion_state = {
.cfg.heap_handle = NULL, .cfg.heap_handle = NULL,
.cfg.gate_handle = NULL, .cfg.gate_handle = NULL,
.cfg.max_regions = SHAREDREGION_MAX_REGIONS_DEFAULT .cfg.max_regions = SHAREDREGION_MAX_REGIONS_DEFAULT
...@@ -95,6 +100,19 @@ int sharedregion_setup(const struct sharedregion_config *config) ...@@ -95,6 +100,19 @@ int sharedregion_setup(const struct sharedregion_config *config)
s32 retval = 0; s32 retval = 0;
u16 proc_count; u16 proc_count;
/* This sets the refCount variable is not initialized, upper 16 bits is
* written with module Id to ensure correctness of refCount variable
*/
atomic_cmpmask_and_set(&sharedregion_state.ref_count,
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(0));
if (atomic_inc_return(&sharedregion_state.ref_count)
!= SHAREDREGION_MAKE_MAGICSTAMP(1)) {
retval = -EEXIST;
goto error;
}
if (config != NULL) { if (config != NULL) {
if (WARN_ON(config->max_regions == 0)) { if (WARN_ON(config->max_regions == 0)) {
retval = -EINVAL; retval = -EINVAL;
...@@ -139,7 +157,8 @@ table_alloc_fail: ...@@ -139,7 +157,8 @@ table_alloc_fail:
kfree(sharedregion_state.gate_handle); kfree(sharedregion_state.gate_handle);
gate_create_fail: gate_create_fail:
memset(&sharedregion_state, 0, sizeof(struct sharedregion_object)); memset(&sharedregion_state, 0,
sizeof(struct sharedregion_module_object));
sharedregion_state.cfg.max_regions = SHAREDREGION_MAX_REGIONS_DEFAULT; sharedregion_state.cfg.max_regions = SHAREDREGION_MAX_REGIONS_DEFAULT;
error: error:
...@@ -158,18 +177,27 @@ int sharedregion_destroy(void) ...@@ -158,18 +177,27 @@ int sharedregion_destroy(void)
s32 retval = 0; s32 retval = 0;
void *gate_handle = NULL; void *gate_handle = NULL;
if (WARN_ON(sharedregion_state.table == NULL)) { if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(1)) == true) {
retval = -ENODEV; retval = -ENODEV;
goto error; goto error;
} }
if (!(atomic_dec_return(&sharedregion_state.ref_count)
== SHAREDREGION_MAKE_MAGICSTAMP(0))) {
retval = -EBUSY; /* Syslink is not handling this on 2.0.0.06 */
goto error;
}
retval = mutex_lock_interruptible(sharedregion_state.gate_handle); retval = mutex_lock_interruptible(sharedregion_state.gate_handle);
if (retval) if (retval)
goto error; goto error;
kfree(sharedregion_state.table); kfree(sharedregion_state.table);
gate_handle = sharedregion_state.gate_handle; /* backup gate handle */ gate_handle = sharedregion_state.gate_handle; /* backup gate handle */
memset(&sharedregion_state, 0, sizeof(struct sharedregion_object)); memset(&sharedregion_state, 0,
sizeof(struct sharedregion_module_object));
sharedregion_state.cfg.max_regions = SHAREDREGION_MAX_REGIONS_DEFAULT; sharedregion_state.cfg.max_regions = SHAREDREGION_MAX_REGIONS_DEFAULT;
mutex_unlock(gate_handle); mutex_unlock(gate_handle);
kfree(gate_handle); kfree(gate_handle);
...@@ -196,7 +224,9 @@ int sharedregion_add(u32 index, void *base, u32 len) ...@@ -196,7 +224,9 @@ int sharedregion_add(u32 index, void *base, u32 len)
u16 myproc_id; u16 myproc_id;
bool overlap = false; bool overlap = false;
if (WARN_ON(sharedregion_state.table == NULL)) { if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(1)) == true) {
retval = -ENODEV; retval = -ENODEV;
goto error; goto error;
} }
...@@ -276,7 +306,9 @@ int sharedregion_remove(u32 index) ...@@ -276,7 +306,9 @@ int sharedregion_remove(u32 index)
struct sharedregion_info *table = NULL; struct sharedregion_info *table = NULL;
s32 retval = 0; s32 retval = 0;
if (WARN_ON(sharedregion_state.table == NULL)) { if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(1)) == true) {
retval = -ENODEV; retval = -ENODEV;
goto error; goto error;
} }
...@@ -318,7 +350,9 @@ int sharedregion_get_index(void *addr) ...@@ -318,7 +350,9 @@ int sharedregion_get_index(void *addr)
u16 myproc_id; u16 myproc_id;
s32 retval = 0; s32 retval = 0;
if (WARN_ON(sharedregion_state.table == NULL)) { if (WARN_ON(atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(1)) == true)) {
retval = -ENODEV; retval = -ENODEV;
goto exit; goto exit;
} }
...@@ -369,8 +403,12 @@ void *sharedregion_get_ptr(u32 *srptr) ...@@ -369,8 +403,12 @@ void *sharedregion_get_ptr(u32 *srptr)
u16 myproc_id; u16 myproc_id;
s32 retval = 0; s32 retval = 0;
if (WARN_ON(sharedregion_state.table == NULL)) if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(1)) == true) {
retval = -ENODEV;
goto error; goto error;
}
if (srptr == SHAREDREGION_INVALIDSRPTR) if (srptr == SHAREDREGION_INVALIDSRPTR)
goto error; goto error;
...@@ -410,8 +448,12 @@ u32 *sharedregion_get_srptr(void *addr, s32 index) ...@@ -410,8 +448,12 @@ u32 *sharedregion_get_srptr(void *addr, s32 index)
u32 myproc_id; u32 myproc_id;
s32 retval = 0; s32 retval = 0;
if (WARN_ON(sharedregion_state.table == NULL)) if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(1)) == true) {
retval = -ENODEV;
goto error; goto error;
}
if (WARN_ON(addr == NULL)) if (WARN_ON(addr == NULL))
goto error; goto error;
...@@ -453,7 +495,9 @@ int sharedregion_get_table_info(u32 index, u16 proc_id, ...@@ -453,7 +495,9 @@ int sharedregion_get_table_info(u32 index, u16 proc_id,
s32 retval = 0; s32 retval = 0;
BUG_ON(info != NULL); BUG_ON(info != NULL);
if (WARN_ON(sharedregion_state.table == NULL)) { if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(1)) == true) {
retval = -ENODEV; retval = -ENODEV;
goto error; goto error;
} }
...@@ -499,7 +543,9 @@ int sharedregion_set_table_info(u32 index, u16 proc_id, ...@@ -499,7 +543,9 @@ int sharedregion_set_table_info(u32 index, u16 proc_id,
s32 retval = 0; s32 retval = 0;
BUG_ON(info != NULL); BUG_ON(info != NULL);
if (WARN_ON(sharedregion_state.table == NULL)) { if (atomic_cmpmask_and_lt(&(sharedregion_state.ref_count),
SHAREDREGION_MAKE_MAGICSTAMP(0),
SHAREDREGION_MAKE_MAGICSTAMP(1)) == true) {
retval = -ENODEV; retval = -ENODEV;
goto error; goto error;
} }
......
...@@ -22,9 +22,17 @@ ...@@ -22,9 +22,17 @@
#include <linux/bug.h> #include <linux/bug.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <multiproc.h>
#include <sharedregion.h> #include <sharedregion.h>
#include <sharedregion_ioctl.h> #include <sharedregion_ioctl.h>
#define memory_translate(x, y) 0 /* To avoid comp error, remove when
memory module is ready */
#define Memory_XltFlags_Phys2Virt 0 /* To avoid comp error, remove when
memory module is ready */
#define memoryos_translate(x, y) 0
#define Memory_XltFlags_Virt2Phys 0
/* /*
* ======== sharedregion_ioctl_get_config ======== * ======== sharedregion_ioctl_get_config ========
...@@ -56,6 +64,12 @@ static int sharedregion_ioctl_get_config(struct sharedregion_cmd_args *cargs) ...@@ -56,6 +64,12 @@ static int sharedregion_ioctl_get_config(struct sharedregion_cmd_args *cargs)
static int sharedregion_ioctl_setup(struct sharedregion_cmd_args *cargs) static int sharedregion_ioctl_setup(struct sharedregion_cmd_args *cargs)
{ {
struct sharedregion_config config; struct sharedregion_config config;
struct sharedregion_config defaultcfg;
struct sharedregion_info info;
struct sharedregion_info *table;
u32 proc_count = 0;
u32 i;
u32 j;
s32 status = 0; s32 status = 0;
s32 size; s32 size;
...@@ -67,6 +81,41 @@ static int sharedregion_ioctl_setup(struct sharedregion_cmd_args *cargs) ...@@ -67,6 +81,41 @@ static int sharedregion_ioctl_setup(struct sharedregion_cmd_args *cargs)
} }
cargs->api_status = sharedregion_setup(&config); cargs->api_status = sharedregion_setup(&config);
if (cargs->api_status != 0)
goto exit;
cargs->api_status = sharedregion_get_config(&defaultcfg);
size = copy_to_user(cargs->args.setup.default_cfg,
&defaultcfg,
sizeof(struct sharedregion_config));
if (size) {
status = -EFAULT;
goto exit;
}
proc_count = multiproc_get_max_processors();
table = cargs->args.setup.table;
for (i = 0; i < config.max_regions; i++) {
for (j = 0; j < (proc_count + 1); j++) {
sharedregion_get_table_info(i, j, &info);
if (info.is_valid == true) {
/* Convert kernel virtual address to physical
* addresses */
info.base = memoryos_translate(info.base,
Memory_XltFlags_Virt2Phys);
size = copy_to_user((void *) (table
+ (j * config.max_regions)
+ i),
(void *) &info,
sizeof(
struct sharedregion_info));
if (size) {
status = -EFAULT;
goto exit;
} /* End of inner if */
} /* End of outer if */
} /* End of inner for loop */
}
exit: exit:
return status; return status;
...@@ -91,9 +140,10 @@ static int sharedregion_ioctl_destroy( ...@@ -91,9 +140,10 @@ static int sharedregion_ioctl_destroy(
*/ */
static int sharedregion_ioctl_add(struct sharedregion_cmd_args *cargs) static int sharedregion_ioctl_add(struct sharedregion_cmd_args *cargs)
{ {
u32 base = (u32)memory_translate(cargs->args.add.base,
Memory_XltFlags_Phys2Virt);
cargs->api_status = sharedregion_add(cargs->args.add.index, cargs->api_status = sharedregion_add(cargs->args.add.index,
cargs->args.add.base, (void *)base, cargs->args.add.len);
cargs->args.add.len);
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