Commit 71f5bf9a authored by Suman Anna's avatar Suman Anna Committed by Hari Kanigeri

SYSLINK: ipc - Add SysMgr & SysMemMgr

This patch adds the preliminary source code for SysMgr & SysMemMgr.
This patch includes only the source code and needs revisions to
adapt to the latest loader and OMAP4430.

The patch has one checkpatch warnings due to the usage of volatile keyword.
The warnings were minimized by using a macro for volatile.
Signed-off-by: default avatarSuman Anna <s-anna@ti.com>
parent 5d036924
/*
* _sysmgr.h
*
* Defines for system manager functions
*
* Copyright (C) 2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#ifndef __SYSMGR_H_
#define __SYSMGR_H_
/* Function to set the boot load page address for a slave */
void sysmgr_set_boot_load_page(u16 proc_id, u32 boot_load_page);
/* Function to get configuration values for a host object(component/instance) */
u32 sysmgr_get_object_config(u16 proc_id, void *config, u32 cmd_id, u32 size);
/* Function to put configuration values for a slave object(component/instance)*/
u32 sysmgr_put_object_config(u16 proc_id, void *config, u32 cmd_id, u32 size);
/* Function to wait for scalability handshake value. */
void sysmgr_wait_for_scalability_info(u16 proc_id);
/* Function to wait for slave to complete setup */
void sysmgr_wait_for_slave_setup(u16 proc_id);
#endif /* ifndef __SYSMGR_H_ */
/*
* platform.h
*
* Defines the platform functions to be used by SysMgr module.
*
* Copyright (C) 2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#ifndef _PLATFORM_H_
#define _PLATFORM_H_
/* Module headers */
#include <sysmgr.h>
/* =============================================================================
* APIs
* =============================================================================
*/
/* Function to setup the platform */
s32 platform_setup(struct sysmgr_config *config);
/* Function to destroy the platform */
s32 platform_destroy(void);
/* Function called when slave is loaded with executable */
void platform_load_callback(void *arg);
/* Function called when slave is in started state*/
void platform_start_callback(void *arg);
/* Function called when slave is stopped state */
void platform_stop_callback(void *arg);
s32 platform_override_config(struct sysmgr_config *config);
#endif /* ifndef _PLATFORM_H_ */
/*
* sysmemmgr.h
*
* Manager for the Slave system memory. Slave system level memory is allocated
* through this module.
*
* Copyright (C) 2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#ifndef _SYSTEMMEMORYMANAGER_H_
#define _SYSTEMMEMORYMANAGER_H_
/*!
* @def SYSMEMMGR_MODULEID
* @brief Module identifier for System memory manager.
*/
#define SYSMEMMGR_MODULEID (0xb53d)
/*!
* @def SYSMEMMGR_STATUSCODEBASE
* @brief Error code base for system memory manager module.
*/
#define SYSMEMMGR_STATUSCODEBASE (SYSMEMMGR_MODULEID << 12u)
/*!
* @def SYSMEMMGR_MAKE_ERROR
* @brief Macro to make error code.
*/
#define SYSMEMMGR_MAKE_ERROR(x) ((int)(0x80000000 + \
(SYSMEMMGR_STATUSCODEBASE + \
(x))))
/*!
* @def SYSMEMMGR_MAKE_SUCCESS
* @brief Macro to make success code.
*/
#define SYSMEMMGR_MAKE_SUCCESS(x) (SYSMEMMGR_STATUSCODEBASE + (x))
/*!
* @def SYSMEMMGR_E_CREATEALLOCATOR
* @brief Static allocator creation failed.
*/
#define SYSMEMMGR_E_CREATEALLOCATOR SYSMEMMGR_MAKE_ERROR(1)
/*!
* @def SYSMEMMGR_E_CREATELOCK
* @brief Mutex lock creation failed.
*/
#define SYSMEMMGR_E_CREATELOCK SYSMEMMGR_MAKE_ERROR(2)
/*!
* @def SYSMEMMGR_E_INVALIDSTATE
* @brief Module is not initialized.
*/
#define SYSMEMMGR_E_INVALIDSTATE SYSMEMMGR_MAKE_ERROR(3)
/*!
* @def SYSMEMMGR_E_INVALIDARG
* @brief Argument passed to a function is invalid.
*/
#define SYSMEMMGR_E_INVALIDARG SYSMEMMGR_MAKE_ERROR(4)
/*!
* @def SYSMEMMGR_E_BPAFREE
* @brief Freeing to buddy allocator failed.
*/
#define SYSMEMMGR_E_BPAFREE SYSMEMMGR_MAKE_ERROR(5)
/*!
* @def SYSMEMMGR_E_MEMORY
* @brief Memory allocation failed.
*/
#define SYSMEMMGR_E_MEMORY SYSMEMMGR_MAKE_ERROR(6)
/*!
* @def SYSMEMMGR_SUCCESS
* @brief Operation successful.
*/
#define SYSMEMMGR_SUCCESS SYSMEMMGR_MAKE_SUCCESS(0)
/*!
* @def SYSMEMMGR_S_ALREADYSETUP
* @brief Module already initialized.
*/
#define SYSMEMMGR_S_ALREADYSETUP SYSMEMMGR_MAKE_SUCCESS(1)
/*!
* @def SYSMEMMGR_S_DRVALREADYOPENED
* @brief Internal OS Driver is already opened.
*/
#define SYSMEMMGR_S_DRVALREADYOPENED SYSMEMMGR_MAKE_SUCCESS(2)
/*!
* @brief Configuration data structure of system memory manager.
*/
struct sysmemmgr_config {
u32 sizeof_valloc;
/* Total size for virtual memory allocation */
u32 sizeof_palloc;
/* Total size for physical memory allocation */
u32 static_phys_base_addr;
/* Physical address of static memory region */
u32 static_virt_base_addr;
/* Virtual address of static memory region */
u32 static_mem_size;
/* size of static memory region */
u32 page_size;
/* Page size */
u32 event_no;
/* Event number to be used */
};
/*!
* @brief Flag used for allocating memory blocks.
*/
enum sysmemmgr_allocflag {
sysmemmgr_allocflag_uncached = 0u,
/* Flag used for allocating uncacheable block */
sysmemmgr_allocflag_cached = 1u,
/* Flag used for allocating cacheable block */
sysmemmgr_allocflag_physical = 2u,
/* Flag used for allocating physically contiguous block */
sysmemmgr_allocflag_virtual = 3u,
/* Flag used for allocating virtually contiguous block */
sysmemmgr_allocflag_dma = 4u
/* Flag used for allocating DMAable (physically contiguous) block */
};
/*!
* @brief Flag used for translating address.
*/
enum sysmemmgr_xltflag {
sysmemmgr_xltflag_kvirt2phys = 0x0001u,
/* Flag used for converting Kernel virtual address to physical
* address */
sysmemmgr_xltflag_kvirt2uvirt = 0x0002u,
/* Flag used for converting Kernel virtual address to user virtual
* address */
sysmemmgr_xltflag_uvirt2phys = 0x0003u,
/* Flag used for converting user virtual address to physical address */
sysmemmgr_xltflag_uvirt2kvirt = 0x0004u,
/* Flag used for converting user virtual address to Kernel virtual
* address */
sysmemmgr_xltflag_phys2kvirt = 0x0005u,
/* Flag used for converting physical address to user virtual address */
sysmemmgr_xltflag_phys2uvirt = 0x0006u
/* Flag used for converting physical address to Kernel virtual
* address */
};
/* Function prototypes */
void sysmemmgr_get_config(struct sysmemmgr_config *config);
int sysmemmgr_setup(struct sysmemmgr_config *params);
int sysmemmgr_destroy(void);
int sysmemmgr_attach(u16 slave_id);
void *sysmemmgr_alloc(u32 size, enum sysmemmgr_allocflag flag);
int sysmemmgr_free(void *blk, u32 size, enum sysmemmgr_allocflag flag);
void *sysmemmgr_translate(void *srcAddr, enum sysmemmgr_xltflag flag);
#endif /* _SYSTEMMEMORYMANAGER_H_ */
/*
* sysmemmgr_ioctl.h
*
* Definitions of sysmemmgr driver types and structures..
*
* Copyright (C) 2008-2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#ifndef _SYSMEMMGR_IOCTL_H_
#define _SYSMEMMGR_IOCTL_H_
/* Standard headers */
#include <linux/types.h>
/* Syslink headers */
#include <ipc_ioctl.h>
#include <sysmgr.h>
/* =============================================================================
* Macros and types
* =============================================================================
*/
/* ----------------------------------------------------------------------------
* IOCTL command IDs for sysmemmgr
* ----------------------------------------------------------------------------
*/
/* IOC Magic Number for sysmemmgr */
#define SYSMEMMGR_IOC_MAGIC IPC_IOC_MAGIC
/* IOCTL command numbers for sysmemmgr */
enum sysmemmgr_drv_cmd {
SYSMEMMGR_GETCONFIG = SYSMEMMGR_BASE_CMD,
SYSMEMMGR_SETUP,
SYSMEMMGR_DESTROY,
SYSMEMMGR_ALLOC,
SYSMEMMGR_FREE,
SYSMEMMGR_TRANSLATE
};
/* Command for sysmemmgr_getConfig */
#define CMD_SYSMEMMGR_GETCONFIG \
_IOWR(SYSMEMMGR_IOC_MAGIC, SYSMEMMGR_GETCONFIG, \
struct sysmemmgr_cmd_args)
/* Command for sysmemmgr_setup */
#define CMD_SYSMEMMGR_SETUP \
_IOWR(SYSMEMMGR_IOC_MAGIC, SYSMEMMGR_SETUP, \
struct sysmemmgr_cmd_args)
/* Command for sysmemmgr_destroy */
#define CMD_SYSMEMMGR_DESTROY \
_IOWR(SYSMEMMGR_IOC_MAGIC, SYSMEMMGR_DESTROY, \
struct sysmemmgr_cmd_args)
/* Command for sysmemmgr_alloc */
#define CMD_SYSMEMMGR_ALLOC \
_IOWR(SYSMEMMGR_IOC_MAGIC, SYSMEMMGR_ALLOC, \
struct sysmemmgr_cmd_args)
/* Command for sysmemmgr_free */
#define CMD_SYSMEMMGR_FREE \
_IOWR(SYSMEMMGR_IOC_MAGIC, SYSMEMMGR_FREE, \
struct sysmemmgr_cmd_args)
/* Command for sysmemmgr_translate */
#define CMD_SYSMEMMGR_TRANSLATE \
_IOWR(SYSMEMMGR_IOC_MAGIC, SYSMEMMGR_TRANSLATE, \
struct sysmemmgr_cmd_args)
/* ----------------------------------------------------------------------------
* Command arguments for sysmemmgr
* ----------------------------------------------------------------------------
*/
/* Command arguments for sysmemmgr */
struct sysmemmgr_cmd_args {
union {
struct {
struct sysmemmgr_config *config;
} get_config;
struct {
struct sysmemmgr_config *config;
} setup;
struct {
u32 size;
void *buf;
void *phys;
void *kbuf;
enum sysmemmgr_allocflag flags;
} alloc;
struct {
u32 size;
void *buf;
void *phys;
void *kbuf;
enum sysmemmgr_allocflag flags;
} free;
struct {
void *buf;
void *ret_ptr;
enum sysmemmgr_xltflag flags;
} translate;
} args;
s32 api_status;
};
/* ----------------------------------------------------------------------------
* IOCTL functions for sysmemmgr module
* ----------------------------------------------------------------------------
*/
/* ioctl interface function for sysmemmgr */
int sysmemmgr_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long args);
#endif /* SYSMEMMGR_DRVDEFS_H_0xF414 */
/*
* sysmgr.h
*
* Defines for System manager.
*
* Copyright (C) 2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#ifndef _SYSMGR_H_
#define _SYSMGR_H_
/* Module headers */
#include <multiproc.h>
#include <gatepeterson.h>
#include <sharedregion.h>
#include <listmp.h>
#include <listmp_sharedmemory.h>
#include <messageq.h>
#include <messageq_transportshm.h>
#include <notify.h>
#include <notify_ducatidriver.h>
#include <nameserver.h>
#include <nameserver_remote.h>
#include <nameserver_remotenotify.h>
#include <procmgr.h>
#include <heap.h>
#include <heapbuf.h>
#include <sysmemmgr.h>
/*!
* @def SYSMGR_MODULEID
* @brief Unique module ID.
*/
#define SYSMGR_MODULEID (0xF086)
/* =============================================================================
* Module Success and Failure codes
* =============================================================================
*/
/*!
* @def SYSMGR_STATUSCODEBASE
* @brief Error code base for System manager.
*/
#define SYSMGR_STATUSCODEBASE (SYSMGR_MODULEID << 12u)
/*!
* @def SYSMGR_MAKE_FAILURE
* @brief Macro to make error code.
*/
#define SYSMGR_MAKE_FAILURE(x) ((s32)(0x80000000 + \
(SYSMGR_STATUSCODEBASE + \
(x))))
/*!
* @def SYSMGR_MAKE_SUCCESS
* @brief Macro to make success code.
*/
#define SYSMGR_MAKE_SUCCESS(x) (SYSMGR_STATUSCODEBASE + (x))
/*!
* @def SYSMGR_E_INVALIDARG
* @brief Argument passed to a function is invalid.
*/
#define SYSMGR_E_INVALIDARG SYSMGR_MAKE_FAILURE(1)
/*!
* @def SYSMGR_E_MEMORY
* @brief Memory allocation failed.
*/
#define SYSMGR_E_MEMORY SYSMGR_MAKE_FAILURE(2)
/*!
* @def SYSMGR_E_FAIL
* @brief General failure.
*/
#define SYSMGR_E_FAIL SYSMGR_MAKE_FAILURE(3)
/*!
* @def SYSMGR_E_INVALIDSTATE
* @brief Module is in invalid state.
*/
#define SYSMGR_E_INVALIDSTATE SYSMGR_MAKE_FAILURE(4)
/*!
* @def SYSMGR_E_OSFAILURE
* @brief Failure in OS call.
*/
#define SYSMGR_E_OSFAILURE SYSMGR_MAKE_FAILURE(5)
/*!
* @def SYSMGR_S_ALREADYSETUP
* @brief Module is already initialized.
*/
#define SYSMGR_S_ALREADYSETUP SYSMGR_MAKE_SUCCESS(1)
/*!
* @def SYSMGR_CMD_SCALABILITY
* @brief Command ID for scalability info.
*/
#define SYSMGR_CMD_SCALABILITY (0x00000000)
/*!
* @def SYSMGR_CMD_SHAREDREGION_ENTRY_BASE
* @brief Base of command IDs for entries used by Shared region.
*/
#define SYSMGR_CMD_SHAREDREGION_ENTRY_START (0x00000001)
#define SYSMGR_CMD_SHAREDREGION_ENTRY_END (0x00001000)
/* =============================================================================
* Structures & Enums
* =============================================================================
*/
/*!
* @brief Structure defining config parameters for overall System.
*/
struct sysmgr_config {
struct sysmemmgr_config sysmemmgr_cfg;
/*!< System memory manager config parameter */
struct multiproc_config multiproc_cfg;
/*!< Multiproc config parameter */
struct gatepeterson_config gatepeterson_cfg;
/*!< Gatepeterson config parameter */
struct sharedregion_config sharedregion_cfg;
/*!< SharedRegion config parameter */
struct messageq_config messageq_cfg;
/*!< MessageQ config parameter */
struct notify_config notify_cfg;
/*!< Notify config parameter */
struct proc_mgr_config proc_mgr_cfg;
/*!< Processor manager config parameter */
struct heapbuf_config heapbuf_cfg;
/*!< Heap Buf config parameter */
struct listmp_config listmp_sharedmemory_cfg;
/*!< ListMPSharedMemory config parameter */
struct messageq_transportshm_config messageq_transportshm_cfg;
/*!< MessageQTransportShm config parameter */
struct notify_ducatidrv_config notify_ducatidrv_cfg;
/*!< NotifyDriverShm config parameter */
struct nameserver_remotenotify_config nameserver_remotenotify_cfg;
/*!< NameServerRemoteNotify config parameter */
};
/* =============================================================================
* APIs
* =============================================================================
*/
/* Function to initialize the parameter structure */
void sysmgr_get_config(struct sysmgr_config *config);
/* Function to initialize sysmgr module */
s32 sysmgr_setup(const struct sysmgr_config *config);
/* Function to Finalize sysmgr module */
s32 sysmgr_destroy(void);
#endif /* ifndef SYSMGR_H_0xF086 */
/*
* sysmgr_ioctl.h
*
* Definitions of sysmgr driver types and structures..
*
* Copyright (C) 2008-2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
#ifndef _SYSMGR_IOCTL_H_
#define _SYSMGR_IOCTL_H_
/* Standard headers */
#include <linux/types.h>
/* Syslink headers */
#include <ipc_ioctl.h>
#include <sysmgr.h>
/* =============================================================================
* Macros and types
* =============================================================================
*/
/* ----------------------------------------------------------------------------
* IOCTL command IDs for sysmgr
* ----------------------------------------------------------------------------
*/
/* IOC Magic Number for sysmgr */
#define SYSMGR_IOC_MAGIC IPC_IOC_MAGIC
/* IOCTL command numbers for sysmgr */
enum sysmgr_drv_cmd {
SYSMGR_SETUP = SYSMGR_BASE_CMD,
SYSMGR_DESTROY
};
/* Command for sysmgr_setup */
#define CMD_SYSMGR_SETUP \
_IOWR(SYSMGR_IOC_MAGIC, SYSMGR_SETUP, \
struct sysmgr_cmd_args)
/* Command for sysmgr_destroy */
#define CMD_SYSMGR_DESTROY \
_IOWR(SYSMGR_IOC_MAGIC, SYSMGR_DESTROY, \
struct sysmgr_cmd_args)
/* ----------------------------------------------------------------------------
* Command arguments for sysmgr
* ----------------------------------------------------------------------------
*/
/* Command arguments for sysmgr */
struct sysmgr_cmd_args {
union {
struct {
struct sysmgr_config *config;
} setup;
} args;
s32 api_status;
};
/* ----------------------------------------------------------------------------
* IOCTL functions for sysmgr module
* ----------------------------------------------------------------------------
*/
/* ioctl interface function for sysmgr */
int sysmgr_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long args);
#endif /* _SYSMGR_IOCTL_H_ */
This diff is collapsed.
/*
* platformcfg.c
*
* Implementation of platform specific configuration for Syslink.
*
* Copyright (C) 2008-2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/* Standard headers */
#include <linux/types.h>
#include <linux/module.h>
/* Utilities headers */
#include <linux/string.h>
/* Module headers */
#include <sysmgr.h>
/* =============================================================================
* APIS
* =============================================================================
*/
/*
* ======== platform_override_config ========
* Purpose:
* Function to override the default confiuration values.
*/
int platform_override_config(struct sysmgr_config *config)
{
int status = 0;
if (WARN_ON(config == NULL)) {
status = -EINVAL;
goto failure;
}
/* Override the multiproc default config */
config->multiproc_cfg.max_processors = 4;
config->multiproc_cfg.id = 0;
strcpy(config->multiproc_cfg.name_list[0], "MPU");
strcpy(config->multiproc_cfg.name_list[1], "Tesla");
strcpy(config->multiproc_cfg.name_list[2], "SysM3");
strcpy(config->multiproc_cfg.name_list[3], "AppM3");
/* Override the gatepeterson default config */
/* Override the sharedregion default config */
config->sharedregion_cfg.gate_handle = NULL;
config->sharedregion_cfg.heap_handle = NULL;
config->sharedregion_cfg.max_regions = 4;
/* Override the listmp default config */
/* Override the messageq default config */
/* Override the notify default config */
config->notify_cfg.maxDrivers = 2;
/* Override the procmgr default config */
/* Override the heapbuf default config */
/* Override the listmp_sharedmemory default config */
/* Override the messageq_transportshm default config */
/* Override the notify ducati driver default config */
/* Override the nameserver remotenotify default config */
goto success;
failure:
printk(KERN_ERR "platform_override_config failed [0x%x]", status);
success:
return status;
}
This diff is collapsed.
/*
* sysmemmgr_ioctl.c
*
* This file implements all the ioctl operations required on the sysmemmgr
* module.
*
* Copyright (C) 2008-2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/* Standard headers */
#include <linux/types.h>
/* Linux headers */
#include <linux/uaccess.h>
#include <linux/bug.h>
#include <linux/fs.h>
#include <linux/mm.h>
/* Module Headers */
#include <sysmemmgr.h>
#include <sysmemmgr_ioctl.h>
/*
* ======== sysmemmgr_ioctl_get_config ========
* Purpose:
* This ioctl interface to sysmemmgr_get_config function
*/
static inline int sysmemmgr_ioctl_get_config(struct sysmemmgr_cmd_args *cargs)
{
s32 retval = 0;
unsigned long size;
struct sysmemmgr_config config;
sysmemmgr_get_config(&config);
size = copy_to_user(cargs->args.get_config.config, &config,
sizeof(struct sysmemmgr_config));
if (size) {
retval = -EFAULT;
goto exit;
}
cargs->api_status = 0;
exit:
return retval;
}
/*
* ======== sysmemmgr_ioctl_setup ========
* Purpose:
* This ioctl interface to sysmemmgr_setup function
*/
static inline int sysmemmgr_ioctl_setup(struct sysmemmgr_cmd_args *cargs)
{
s32 retval = 0;
unsigned long size;
struct sysmemmgr_config config;
if (cargs->args.setup.config == NULL) {
cargs->api_status = sysmemmgr_setup(NULL);
goto exit;
}
size = copy_from_user(&config, cargs->args.setup.config,
sizeof(struct sysmemmgr_config));
if (size) {
retval = -EFAULT;
goto exit;
}
cargs->api_status = sysmemmgr_setup(&config);
exit:
return retval;
}
/*
* ======== sysmemmgr_ioctl_destroy ========
* Purpose:
* This ioctl interface to sysmemmgr_destroy function
*/
static inline int sysmemmgr_ioctl_destroy(struct sysmemmgr_cmd_args *cargs)
{
cargs->api_status = sysmemmgr_destroy();
return 0;
}
/*
* ======== sysmemmgr_ioctl_alloc ========
* Purpose:
* This ioctl interface to sysmemmgr_alloc function
*/
static inline int sysmemmgr_ioctl_alloc(struct sysmemmgr_cmd_args *cargs)
{
void *kbuf = NULL;
void *phys = NULL;
kbuf = sysmemmgr_alloc(cargs->args.alloc.size,
cargs->args.alloc.flags);
if (unlikely(kbuf == NULL))
goto exit;
/* If the flag is not virtually contiguous */
if (cargs->args.alloc.flags != sysmemmgr_allocflag_virtual)
phys = sysmemmgr_translate(kbuf, sysmemmgr_xltflag_kvirt2phys);
cargs->api_status = 0;
exit:
cargs->args.alloc.kbuf = kbuf;
cargs->args.alloc.kbuf = phys;
return 0;
}
/*
* ======== sysmemmgr_ioctl_free ========
* Purpose:
* This ioctl interface to sysmemmgr_free function
*/
static inline int sysmemmgr_ioctl_free(struct sysmemmgr_cmd_args *cargs)
{
cargs->api_status = sysmemmgr_free(cargs->args.free.kbuf,
cargs->args.free.size,
cargs->args.alloc.flags);
return 0;
}
/*
* ======== sysmemmgr_ioctl_translate ========
* Purpose:
* This ioctl interface to sysmemmgr_translate function
*/
static inline int sysmemmgr_ioctl_translate(struct sysmemmgr_cmd_args *cargs)
{
cargs->args.translate.ret_ptr = sysmemmgr_translate(
cargs->args.translate.buf,
cargs->args.translate.flags);
WARN_ON(cargs->args.translate.ret_ptr == NULL);
cargs->api_status = 0;
return 0;
}
/*
* ======== sysmemmgr_ioctl ========
* Purpose:
* ioctl interface function for sysmemmgr module
*/
int sysmemmgr_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long args)
{
int os_status = 0;
struct sysmemmgr_cmd_args __user *uarg =
(struct sysmemmgr_cmd_args __user *)args;
struct sysmemmgr_cmd_args cargs;
unsigned long size;
if (_IOC_DIR(cmd) & _IOC_READ)
os_status = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
os_status = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
if (os_status) {
os_status = -EFAULT;
goto exit;
}
/* Copy the full args from user-side */
size = copy_from_user(&cargs, uarg, sizeof(struct sysmemmgr_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
switch (cmd) {
case CMD_SYSMEMMGR_GETCONFIG:
os_status = sysmemmgr_ioctl_get_config(&cargs);
break;
case CMD_SYSMEMMGR_SETUP:
os_status = sysmemmgr_ioctl_setup(&cargs);
break;
case CMD_SYSMEMMGR_DESTROY:
os_status = sysmemmgr_ioctl_destroy(&cargs);
break;
case CMD_SYSMEMMGR_ALLOC:
os_status = sysmemmgr_ioctl_alloc(&cargs);
break;
case CMD_SYSMEMMGR_FREE:
os_status = sysmemmgr_ioctl_free(&cargs);
break;
case CMD_SYSMEMMGR_TRANSLATE:
os_status = sysmemmgr_ioctl_translate(&cargs);
break;
default:
WARN_ON(cmd);
os_status = -ENOTTY;
break;
}
if (os_status < 0)
goto exit;
/* Copy the full args to the user-side. */
size = copy_to_user(uarg, &cargs, sizeof(struct sysmemmgr_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
exit:
return os_status;
}
This diff is collapsed.
/*
* sysmgr_ioctl.c
*
* This file implements all the ioctl operations required on the sysmgr
* module.
*
* Copyright (C) 2008-2009 Texas Instruments, Inc.
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE.
*/
/* Standard headers */
#include <linux/types.h>
/* Linux headers */
#include <linux/uaccess.h>
#include <linux/bug.h>
#include <linux/fs.h>
#include <linux/mm.h>
/* Module Headers */
#include <sysmgr.h>
#include <sysmgr_ioctl.h>
/*
* ======== sysmgr_ioctl_setup ========
* Purpose:
* This ioctl interface to sysmgr_setup function
*/
static inline int sysmgr_ioctl_setup(struct sysmgr_cmd_args *cargs)
{
s32 retval = 0;
unsigned long size;
struct sysmgr_config config;
size = copy_from_user(&config, cargs->args.setup.config,
sizeof(struct sysmgr_config));
if (size) {
retval = -EFAULT;
goto exit;
}
cargs->api_status = sysmgr_setup(&config);
exit:
return retval;
}
/*
* ======== sysmgr_ioctl_destroy ========
* Purpose:
* This ioctl interface to sysmgr_destroy function
*/
static inline int sysmgr_ioctl_destroy(struct sysmgr_cmd_args *cargs)
{
cargs->api_status = sysmgr_destroy();
return 0;
}
/*
* ======== sysmgr_ioctl ========
* Purpose:
* ioctl interface function for sysmgr module
*/
int sysmgr_ioctl(struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long args)
{
int os_status = 0;
struct sysmgr_cmd_args __user *uarg =
(struct sysmgr_cmd_args __user *)args;
struct sysmgr_cmd_args cargs;
unsigned long size;
if (_IOC_DIR(cmd) & _IOC_READ)
os_status = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
else if (_IOC_DIR(cmd) & _IOC_WRITE)
os_status = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
if (os_status) {
os_status = -EFAULT;
goto exit;
}
/* Copy the full args from user-side */
size = copy_from_user(&cargs, uarg, sizeof(struct sysmgr_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
switch (cmd) {
case CMD_SYSMGR_SETUP:
os_status = sysmgr_ioctl_setup(&cargs);
break;
case CMD_SYSMGR_DESTROY:
os_status = sysmgr_ioctl_destroy(&cargs);
break;
default:
WARN_ON(cmd);
os_status = -ENOTTY;
break;
}
if (os_status < 0)
goto exit;
/* Copy the full args to the user-side. */
size = copy_to_user(uarg, &cargs, sizeof(struct sysmgr_cmd_args));
if (size) {
os_status = -EFAULT;
goto exit;
}
exit:
return os_status;
}
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