Commit 76f0d569 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 1e92a8df
......@@ -22,6 +22,12 @@
#include <linux/types.h>
/*
* SHAREDREGION_MODULEID
* Module ID for Shared region manager
*/
#define SHAREDREGION_MODULEID (0x5D8A)
/*
* Name of the reserved nameserver used for application
*/
......
......@@ -119,6 +119,8 @@ union sharedregion_arg {
struct {
struct sharedregion_config *config;
struct sharedregion_config *default_cfg;
struct sharedregion_info *table;
} setup;
struct {
......
......@@ -20,18 +20,23 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <syslink/atomic_linux.h>
#include <gt.h>
#include <multiproc.h>
#include <nameserver.h>
#include <sharedregion.h>
#define SHAREDREGION_MAX_REGIONS_DEFAULT 256
/* 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
/*
* Module state object
*/
struct sharedregion_object {
struct sharedregion_module_object {
atomic_t ref_count; /* Reference count */
struct mutex *gate_handle;
struct sharedregion_info *table; /* Ptr to the table */
u32 bitOffset; /* Index bit offset */
......@@ -42,7 +47,7 @@ struct sharedregion_object {
/*
* 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.gate_handle = NULL,
.cfg.max_regions = SHAREDREGION_MAX_REGIONS_DEFAULT
......@@ -95,17 +100,30 @@ int sharedregion_setup(const struct sharedregion_config *config)
s32 retval = 0;
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 (WARN_ON(config->max_regions == 0)) {
retval = -EINVAL;
goto error;
}
memcpy(&sharedregion_state.cfg, config,
sizeof(struct sharedregion_config));
sizeof(struct sharedregion_config));
}
sharedregion_state.gate_handle = kmalloc(sizeof(struct mutex),
GFP_KERNEL);
GFP_KERNEL);
if (sharedregion_state.gate_handle == NULL)
goto gate_create_fail;
......@@ -139,7 +157,8 @@ table_alloc_fail:
kfree(sharedregion_state.gate_handle);
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;
error:
......@@ -158,18 +177,27 @@ int sharedregion_destroy(void)
s32 retval = 0;
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;
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);
if (retval)
goto error;
kfree(sharedregion_state.table);
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;
mutex_unlock(gate_handle);
kfree(gate_handle);
......@@ -196,7 +224,9 @@ int sharedregion_add(u32 index, void *base, u32 len)
u16 myproc_id;
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;
goto error;
}
......@@ -276,7 +306,9 @@ int sharedregion_remove(u32 index)
struct sharedregion_info *table = NULL;
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;
}
......@@ -318,7 +350,9 @@ int sharedregion_get_index(void *addr)
u16 myproc_id;
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;
goto exit;
}
......@@ -369,8 +403,12 @@ void *sharedregion_get_ptr(u32 *srptr)
u16 myproc_id;
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;
}
if (srptr == SHAREDREGION_INVALIDSRPTR)
goto error;
......@@ -410,8 +448,12 @@ u32 *sharedregion_get_srptr(void *addr, s32 index)
u32 myproc_id;
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;
}
if (WARN_ON(addr == NULL))
goto error;
......@@ -453,7 +495,9 @@ int sharedregion_get_table_info(u32 index, u16 proc_id,
s32 retval = 0;
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;
goto error;
}
......@@ -499,7 +543,9 @@ int sharedregion_set_table_info(u32 index, u16 proc_id,
s32 retval = 0;
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;
goto error;
}
......
......@@ -22,9 +22,17 @@
#include <linux/bug.h>
#include <linux/fs.h>
#include <multiproc.h>
#include <sharedregion.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 ========
......@@ -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)
{
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 size;
......@@ -67,6 +81,41 @@ static int sharedregion_ioctl_setup(struct sharedregion_cmd_args *cargs)
}
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:
return status;
......@@ -91,9 +140,10 @@ static int sharedregion_ioctl_destroy(
*/
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->args.add.base,
cargs->args.add.len);
(void *)base, cargs->args.add.len);
return 0;
}
......@@ -290,7 +340,7 @@ int sharedregion_ioctl(struct inode *inode, struct file *filp,
WARN_ON(cmd);
status = -ENOTTY;
break;
}
}
/* Copy the full args to the user-side. */
......
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