4
* This file implements all the ioctl operations required on the sysmemmgr
7
* Copyright (C) 2008-2009 Texas Instruments, Inc.
9
* This package is free software; you can redistribute it and/or modify
10
* it under the terms of the GNU General Public License version 2 as
11
* published by the Free Software Foundation.
13
* THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
19
/* Standard headers */
20
#include <linux/types.h>
23
#include <linux/uaccess.h>
24
#include <linux/bug.h>
29
#include <sysmemmgr.h>
30
#include <sysmemmgr_ioctl.h>
34
* ======== sysmemmgr_ioctl_get_config ========
36
* This ioctl interface to sysmemmgr_get_config function
38
static inline int sysmemmgr_ioctl_get_config(struct sysmemmgr_cmd_args *cargs)
42
struct sysmemmgr_config config;
44
sysmemmgr_get_config(&config);
45
size = copy_to_user(cargs->args.get_config.config, &config,
46
sizeof(struct sysmemmgr_config));
52
cargs->api_status = 0;
58
* ======== sysmemmgr_ioctl_setup ========
60
* This ioctl interface to sysmemmgr_setup function
62
static inline int sysmemmgr_ioctl_setup(struct sysmemmgr_cmd_args *cargs)
66
struct sysmemmgr_config config;
68
if (cargs->args.setup.config == NULL) {
69
cargs->api_status = sysmemmgr_setup(NULL);
73
size = copy_from_user(&config, cargs->args.setup.config,
74
sizeof(struct sysmemmgr_config));
80
cargs->api_status = sysmemmgr_setup(&config);
87
* ======== sysmemmgr_ioctl_destroy ========
89
* This ioctl interface to sysmemmgr_destroy function
91
static inline int sysmemmgr_ioctl_destroy(struct sysmemmgr_cmd_args *cargs)
93
cargs->api_status = sysmemmgr_destroy();
98
* ======== sysmemmgr_ioctl_alloc ========
100
* This ioctl interface to sysmemmgr_alloc function
102
static inline int sysmemmgr_ioctl_alloc(struct sysmemmgr_cmd_args *cargs)
107
kbuf = sysmemmgr_alloc(cargs->args.alloc.size,
108
cargs->args.alloc.flags);
109
if (unlikely(kbuf == NULL))
112
/* If the flag is not virtually contiguous */
113
if (cargs->args.alloc.flags != sysmemmgr_allocflag_virtual)
114
phys = sysmemmgr_translate(kbuf, sysmemmgr_xltflag_kvirt2phys);
115
cargs->api_status = 0;
118
cargs->args.alloc.kbuf = kbuf;
119
cargs->args.alloc.kbuf = phys;
124
* ======== sysmemmgr_ioctl_free ========
126
* This ioctl interface to sysmemmgr_free function
128
static inline int sysmemmgr_ioctl_free(struct sysmemmgr_cmd_args *cargs)
130
cargs->api_status = sysmemmgr_free(cargs->args.free.kbuf,
131
cargs->args.free.size,
132
cargs->args.alloc.flags);
137
* ======== sysmemmgr_ioctl_translate ========
139
* This ioctl interface to sysmemmgr_translate function
141
static inline int sysmemmgr_ioctl_translate(struct sysmemmgr_cmd_args *cargs)
143
cargs->args.translate.ret_ptr = sysmemmgr_translate(
144
cargs->args.translate.buf,
145
cargs->args.translate.flags);
146
WARN_ON(cargs->args.translate.ret_ptr == NULL);
147
cargs->api_status = 0;
152
* ======== sysmemmgr_ioctl ========
154
* ioctl interface function for sysmemmgr module
156
int sysmemmgr_ioctl(struct inode *inode, struct file *filp,
157
unsigned int cmd, unsigned long args)
160
struct sysmemmgr_cmd_args __user *uarg =
161
(struct sysmemmgr_cmd_args __user *)args;
162
struct sysmemmgr_cmd_args cargs;
165
if (_IOC_DIR(cmd) & _IOC_READ)
166
os_status = !access_ok(VERIFY_WRITE, uarg, _IOC_SIZE(cmd));
167
else if (_IOC_DIR(cmd) & _IOC_WRITE)
168
os_status = !access_ok(VERIFY_READ, uarg, _IOC_SIZE(cmd));
174
/* Copy the full args from user-side */
175
size = copy_from_user(&cargs, uarg, sizeof(struct sysmemmgr_cmd_args));
182
case CMD_SYSMEMMGR_GETCONFIG:
183
os_status = sysmemmgr_ioctl_get_config(&cargs);
186
case CMD_SYSMEMMGR_SETUP:
187
os_status = sysmemmgr_ioctl_setup(&cargs);
190
case CMD_SYSMEMMGR_DESTROY:
191
os_status = sysmemmgr_ioctl_destroy(&cargs);
194
case CMD_SYSMEMMGR_ALLOC:
195
os_status = sysmemmgr_ioctl_alloc(&cargs);
198
case CMD_SYSMEMMGR_FREE:
199
os_status = sysmemmgr_ioctl_free(&cargs);
202
case CMD_SYSMEMMGR_TRANSLATE:
203
os_status = sysmemmgr_ioctl_translate(&cargs);
212
if ((cargs.api_status == -ERESTARTSYS) || (cargs.api_status == -EINTR))
213
os_status = -ERESTARTSYS;
218
/* Copy the full args to the user-side. */
219
size = copy_to_user(uarg, &cargs, sizeof(struct sysmemmgr_cmd_args));