Commit 6108490c authored by Hari Kanigeri's avatar Hari Kanigeri

SYSLINK:proc changes to adapt to sys manager and ipc

This patch adds support to sys mananager and adapting
to new IPC.
Signed-off-by: default avatarHari Kanigeri <h-kanigeri2@ti.com>
parent 1414cfbe
......@@ -31,6 +31,7 @@
#include "dmm4430.h"
#include <syslink/multiproc.h>
#include <syslink/ducatienabler.h>
#include <syslink/platform_mem.h>
#define DUCATI_DMM_START_ADDR 0xa0000000
#define DUCATI_DMM_POOL_SIZE 0x6000000
......@@ -83,7 +84,6 @@ struct proc4430_object {
static struct proc4430_module_object proc4430_state = {
.is_setup = false,
.config_size = sizeof(struct proc4430_config),
.def_cfg.gate_handle = NULL,
.gate_handle = NULL,
.def_inst_params.num_mem_entries = 0u,
.def_inst_params.mem_entries = NULL,
......@@ -142,16 +142,13 @@ int proc4430_setup(struct proc4430_config *cfg)
if (proc4430_state.is_setup == false) {
dmm_create();
dmm_create_tables(DUCATI_DMM_START_ADDR, DUCATI_DMM_POOL_SIZE);
if (cfg->gate_handle != NULL) {
proc4430_state.gate_handle = cfg->gate_handle;
} else {
/* User has not provided any gate handle, so create a
* default handle. */
/* Create a default gate handle for local module protection. */
proc4430_state.gate_handle =
kmalloc(sizeof(struct mutex), GFP_KERNEL);
mutex_init(proc4430_state.gate_handle);
ducati_setup();
}
/* Initialize the name to handles mapping array. */
memset(&proc4430_state.proc_handles, 0,
(sizeof(void *) * MULTIPROC_MAXPROCESSORS));
......@@ -186,12 +183,11 @@ int proc4430_destroy(void)
}
/* Check if the gate_handle was created internally. */
if (proc4430_state.cfg.gate_handle == NULL) {
if (proc4430_state.gate_handle != NULL) {
mutex_destroy(proc4430_state.gate_handle);
kfree(proc4430_state.gate_handle);
}
}
ducati_destroy();
proc4430_state.is_setup = false;
return retval;
......@@ -382,7 +378,7 @@ int proc4430_attach(void *handle, struct processor_attach_params *params)
struct proc4430_object *object = NULL;
u32 map_count = 0;
u32 i;
u32 dst_addr;
memory_map_info map_info;
object = (struct proc4430_object *)proc_handle->object;
/* Return memory information in params. */
......@@ -394,13 +390,19 @@ int proc4430_attach(void *handle, struct processor_attach_params *params)
if ((object->params.mem_entries[i].master_virt_addr == (u32)-1)
&& (object->params.mem_entries[i].shared == true)) {
map_count++;
dst_addr = (u32)ioremap_nocache((dma_addr_t)
(object->params.mem_entries[i].phys_addr),
object->params.mem_entries[i].size);
map_info.src = object->params.mem_entries[i].phys_addr;
map_info.size = object->params.mem_entries[i].size;
map_info.is_cached = false;
retval = platform_mem_map(&map_info);
if (retval != 0) {
printk(KERN_ERR "proc4430_attach failed\n");
return -EFAULT;
}
object->params.mem_entries[i].master_virt_addr =
dst_addr;
map_info.dst;
params->mem_entries[i].addr
[PROC_MGR_ADDRTYPE_MASTERKNLVIRT] = dst_addr;
[PROC_MGR_ADDRTYPE_MASTERKNLVIRT] =
map_info.dst;
params->mem_entries[i].addr
[PROC_MGR_ADDRTYPE_SLAVEVIRT] =
(object->params.mem_entries[i].slave_virt_addr);
......@@ -429,13 +431,17 @@ int proc4430_detach(void *handle)
(struct processor_object *)handle;
struct proc4430_object *object = NULL;
u32 i;
memory_unmap_info unmap_info;
object = (struct proc4430_object *)proc_handle->object;
for (i = 0; (i < object->params.num_mem_entries); i++) {
if ((object->params.mem_entries[i].master_virt_addr == (u32)-1)
&& (object->params.mem_entries[i].shared == true)) {
iounmap((void *)object->params.mem_entries[i].
master_virt_addr);
unmap_info.addr =
object->params.mem_entries[i].master_virt_addr;
unmap_info.size = object->params.mem_entries[i].size;
if (unmap_info.addr != 0)
platform_mem_unmap(&unmap_info);
object->params.mem_entries[i].master_virt_addr =
(u32)-1;
}
......
......@@ -83,9 +83,10 @@ inline int processor_detach(void *handle)
BUG_ON(proc_handle->proc_fxn_table.detach == NULL);
retval = proc_handle->proc_fxn_table.detach(handle);
if ((proc_handle->boot_mode == PROC_MGR_BOOTMODE_BOOT)
|| (proc_handle->boot_mode == PROC_MGR_BOOTMODE_NOLOAD))
proc_handle->state = PROC_MGR_STATE_RESET;
/* For all boot modes, at the end of detach, the Processor is in
* unknown state.
*/
proc_handle->state = PROC_MGR_STATE_UNKNOWN;
return retval;
}
......
......@@ -18,21 +18,38 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/vmalloc.h>
#include <asm/atomic.h>
/* Module level headers */
#include "procmgr.h"
#include "procdefs.h"
#include "processor.h"
#include <syslink/atomic_linux.h>
#if defined SYSLINK_USE_SYSMGR
#include <sysmgr.h>
#include <platform.h>
#endif /* if defined (SYSLINK_USE_SYSMGR) */
/* ================================
* Macros and types
* ================================
*/
/*! @brief Macro to make a correct module magic number with refCount */
#define PROCMGR_MAKE_MAGICSTAMP(x) ((PROCMGR_MODULEID << 12u) | (x))
#if defined SYSLINK_USE_SYSMGR
/* HACK - replace once the platform.c file is ready */
int dummy() {return 0; };
#define platform_start_callback(pid) dummy()
#define platform_stop_callback(pid) dummy()
#endif /* if defined (SYSLINK_USE_SYSMGR) */
/*
* ProcMgr Module state object
*/
struct proc_mgr_module_object {
atomic_t ref_count;
u32 config_size;
/* Size of configuration structure */
struct proc_mgr_config cfg;
......@@ -126,8 +143,15 @@ int proc_mgr_setup(struct proc_mgr_config *cfg)
int retval = 0;
struct proc_mgr_config tmp_cfg;
BUG_ON(cfg == NULL);
/* 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(&proc_mgr_obj_state.ref_count,
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(0));
if (atomic_inc_return(&proc_mgr_obj_state.ref_count)
!= PROCMGR_MAKE_MAGICSTAMP(1u))
return 0;
if (cfg == NULL) {
proc_mgr_get_config(&tmp_cfg);
cfg = &tmp_cfg;
......@@ -161,16 +185,30 @@ int proc_mgr_destroy(void)
int retval = 0;
int i;
/* Check if any ProcMgr instances have not been deleted so far. If not,
* delete them.
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_destroy: Error - module not initialized\n");
return -EFAULT;
}
if (atomic_dec_return(&proc_mgr_obj_state.ref_count)
== PROCMGR_MAKE_MAGICSTAMP(0)) {
/* Check if any ProcMgr instances have not been deleted so far
*. If not,delete them
*/
for (i = 0 ; i < MULTIPROC_MAXPROCESSORS; i++) {
if (proc_mgr_obj_state.proc_handles[i] != NULL)
proc_mgr_delete(&(proc_mgr_obj_state.proc_handles[i]));
proc_mgr_delete
(&(proc_mgr_obj_state.proc_handles[i]));
}
mutex_destroy(proc_mgr_obj_state.gate_handle);
kfree(proc_mgr_obj_state.gate_handle);
/* Decrease the refCount */
atomic_set(&proc_mgr_obj_state.ref_count,
PROCMGR_MAKE_MAGICSTAMP(0));
}
return retval;;
}
EXPORT_SYMBOL(proc_mgr_destroy);
......@@ -188,6 +226,11 @@ void proc_mgr_params_init(void *handle, struct proc_mgr_params *params)
if (WARN_ON(params == NULL))
goto exit;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_params_init: Error - module not initialized\n");
}
if (handle == NULL) {
memcpy(params, &(proc_mgr_obj_state.def_inst_params),
sizeof(struct proc_mgr_params));
......@@ -226,7 +269,12 @@ void *proc_mgr_create(u16 proc_id, const struct proc_mgr_params *params)
BUG_ON(!IS_VALID_PROCID(proc_id));
BUG_ON(params == NULL);
BUG_ON(params->proc_handle == NULL);
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_create: Error - module not initialized\n");
return NULL;
}
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
handle = (struct proc_mgr_object *)
vmalloc(sizeof(struct proc_mgr_object));
......@@ -258,6 +306,12 @@ proc_mgr_delete(void **handle_ptr)
struct proc_mgr_object *handle;
BUG_ON(handle_ptr == NULL);
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_delete: Error - module not initialized\n");
return -EFAULT;
}
handle = (struct proc_mgr_object *)(*handle_ptr);
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
......@@ -283,6 +337,12 @@ int proc_mgr_open(void **handle_ptr, u16 proc_id)
BUG_ON(handle_ptr == NULL);
BUG_ON(!IS_VALID_PROCID(proc_id));
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_open: Error - module not initialized\n");
return -EFAULT;
}
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
*handle_ptr = proc_mgr_obj_state.proc_handles[proc_id];
......@@ -302,6 +362,12 @@ int proc_mgr_close(void *handle)
int retval = 0;
BUG_ON(handle == NULL);
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_close: Error - module not initialized\n");
return -EFAULT;
}
/* Nothing to be done for closing the handle. */
return retval;
}
......@@ -323,7 +389,12 @@ void proc_mgr_get_attach_params(void *handle,
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
BUG_ON(params == NULL);
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_get_attach_params:"
"Error - module not initialized\n");
}
if (handle == NULL) {
memcpy(params, &(proc_mgr_obj_state.def_attach_params),
sizeof(struct proc_mgr_attach_params));
......@@ -370,7 +441,13 @@ int proc_mgr_attach(void *handle, struct proc_mgr_attach_params *params)
proc_mgr_get_attach_params(handle, &tmp_params);
params = &tmp_params;
}
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_attach:"
"Error - module not initialized\n");
return -EFAULT;
}
if (WARN_ON(handle == NULL)) {
retval = -EFAULT;
goto exit;
......@@ -417,7 +494,13 @@ int proc_mgr_detach(void *handle)
int retval = 0;
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_detach:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(handle == NULL);
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
/* Detach from the Processor. */
......@@ -443,6 +526,12 @@ void proc_mgr_get_start_params(void *handle,
{
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_get_start_params:"
"Error - module not initialized\n");
}
BUG_ON(params == NULL);
if (handle == NULL) {
......@@ -476,6 +565,13 @@ proc_mgr_start(void *handle, struct proc_mgr_start_params *params)
struct proc_mgr_start_params tmp_params;
struct processor_start_params proc_params;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_start:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(handle == NULL);
if (params == NULL) {
......@@ -490,6 +586,13 @@ proc_mgr_start(void *handle, struct proc_mgr_start_params *params)
retval = processor_start(proc_mgr_handle->proc_handle,
entryPt, &proc_params);
mutex_unlock(proc_mgr_obj_state.gate_handle);
#if defined SYSLINK_USE_SYSMGR
if (retval == 0) {
/* TBD: should be removed when notify local is implemepented */
platform_start_callback(proc_mgr_handle->proc_id);
}
#endif /* defined (SYSLINK_USE_SYSMGR)*/
return retval;;
}
EXPORT_SYMBOL(proc_mgr_start);
......@@ -508,7 +611,19 @@ int proc_mgr_stop(void *handle)
int retval = 0;
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_stop:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(handle == NULL);
#if defined SYSLINK_USE_SYSMGR
/* TBD: should be removed when notify local is implemepented */
platform_stop_callback(proc_mgr_handle->proc_id);
#endif /* #if defined (SYSLINK_USE_SYSMGR) */
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
retval = processor_stop(proc_mgr_handle->proc_handle);
mutex_unlock(proc_mgr_obj_state.gate_handle);
......@@ -530,6 +645,13 @@ enum proc_mgr_state proc_mgr_get_state(void *handle)
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
enum proc_mgr_state state = PROC_MGR_STATE_UNKNOWN;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_get_state:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(handle == NULL);
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
......@@ -553,7 +675,13 @@ int proc_mgr_read(void *handle, u32 proc_addr, u32 *num_bytes, void *buffer)
int retval = 0;
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_read:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(handle == NULL);
BUG_ON(proc_addr == 0);
BUG_ON(num_bytes == NULL);
......@@ -583,7 +711,13 @@ int proc_mgr_write(void *handle, u32 proc_addr, u32 *num_bytes, void *buffer)
int retval = 0;
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_write:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(proc_addr == 0);
BUG_ON(num_bytes == NULL);
BUG_ON(buffer == NULL);
......@@ -611,7 +745,13 @@ int proc_mgr_control(void *handle, int cmd, void *arg)
int retval = 0;
struct proc_mgr_object *proc_mgr_handle
= (struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_control:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(handle == NULL);
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
/* Perform device-dependent control operation. */
......@@ -636,6 +776,13 @@ int proc_mgr_translate_addr(void *handle, void **dst_addr,
int retval = 0;
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_translate_addr:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(dst_addr == NULL);
BUG_ON(handle == NULL);
BUG_ON(dst_addr_type > PROC_MGR_ADDRTYPE_ENDVALUE);
......@@ -665,6 +812,13 @@ int proc_mgr_map(void *handle, u32 proc_addr, u32 size, u32 *mapped_addr,
int retval = 0;
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_map:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(handle == NULL);
BUG_ON(proc_addr == 0);
BUG_ON(mapped_addr == NULL);
......@@ -692,7 +846,13 @@ int proc_mgr_unmap(void *handle, u32 mapped_addr)
int retval = 0;
struct proc_mgr_object *proc_mgr_handle =
(struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_unmap:"
"Error - module not initialized\n");
return -EFAULT;
}
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
/* Map to host address space. */
......@@ -717,7 +877,13 @@ int proc_mgr_register_notify(void *handle, proc_mgr_callback_fxn fxn,
int retval = 0;
struct proc_mgr_object *proc_mgr_handle
= (struct proc_mgr_object *)handle;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_register_notify:"
"Error - module not initialized\n");
return -EFAULT;
}
BUG_ON(handle == NULL);
BUG_ON(fxn == NULL);
WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
......@@ -741,6 +907,13 @@ int proc_mgr_get_proc_info(void *handle, struct proc_mgr_proc_info *proc_info)
struct proc_mgr_proc_info proc_info_test;
if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
== true) {
printk(KERN_ERR "proc_mgr_get_proc_info:"
"Error - module not initialized\n");
return -EFAULT;
}
if (WARN_ON(handle == NULL))
goto error_exit;
if (WARN_ON(proc_info == NULL))
......
......@@ -19,6 +19,8 @@
#include <linux/types.h>
#include <syslink/multiproc.h>
#define PROCMGR_MODULEID 0xf2ba
/*
* Maximum name length for ProcMgr module strings.
*/
......
......@@ -263,7 +263,7 @@ static int proc_mgr_drv_ioctl(struct inode *inode, struct file *filp,
sizeof(struct proc_mgr_cmd_args_close));
if (WARN_ON(retval != 0))
goto func_exit;
retval = proc_mgr_close(src_args.handle);
retval = proc_mgr_close(&(src_args.handle));
}
break;
......@@ -400,6 +400,7 @@ static int proc_mgr_drv_ioctl(struct inode *inode, struct file *filp,
if (WARN_ON(retval != 0))
goto func_exit;
procmgrstate = proc_mgr_get_state(src_args.handle);
src_args.proc_mgr_state = procmgrstate;
retval = copy_to_user((void *)(args), (const void *)&src_args,
sizeof(struct proc_mgr_cmd_args_get_state));
WARN_ON(retval < 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