~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/dsp/syslink/multicore_ipc/sysmemmgr_ioctl.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *  sysmemmgr_ioctl.c
3
 
 *
4
 
 *  This file implements all the ioctl operations required on the sysmemmgr
5
 
 *  module.
6
 
 *
7
 
 *  Copyright (C) 2008-2009 Texas Instruments, Inc.
8
 
 *
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.
12
 
 *
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
16
 
 *  PURPOSE.
17
 
 */
18
 
 
19
 
/* Standard headers */
20
 
#include <linux/types.h>
21
 
 
22
 
/* Linux headers */
23
 
#include <linux/uaccess.h>
24
 
#include <linux/bug.h>
25
 
#include <linux/fs.h>
26
 
#include <linux/mm.h>
27
 
 
28
 
/* Module Headers */
29
 
#include <sysmemmgr.h>
30
 
#include <sysmemmgr_ioctl.h>
31
 
 
32
 
 
33
 
/*
34
 
 * ======== sysmemmgr_ioctl_get_config ========
35
 
 *  Purpose:
36
 
 *  This ioctl interface to sysmemmgr_get_config function
37
 
 */
38
 
static inline int sysmemmgr_ioctl_get_config(struct sysmemmgr_cmd_args *cargs)
39
 
{
40
 
        s32 retval = 0;
41
 
        unsigned long size;
42
 
        struct sysmemmgr_config config;
43
 
 
44
 
        sysmemmgr_get_config(&config);
45
 
        size = copy_to_user(cargs->args.get_config.config, &config,
46
 
                                sizeof(struct sysmemmgr_config));
47
 
        if (size) {
48
 
                retval = -EFAULT;
49
 
                goto exit;
50
 
        }
51
 
 
52
 
        cargs->api_status = 0;
53
 
exit:
54
 
        return retval;
55
 
}
56
 
 
57
 
/*
58
 
 * ======== sysmemmgr_ioctl_setup ========
59
 
 *  Purpose:
60
 
 *  This ioctl interface to sysmemmgr_setup function
61
 
 */
62
 
static inline int sysmemmgr_ioctl_setup(struct sysmemmgr_cmd_args *cargs)
63
 
{
64
 
        s32 retval = 0;
65
 
        unsigned long size;
66
 
        struct sysmemmgr_config config;
67
 
 
68
 
        if (cargs->args.setup.config == NULL) {
69
 
                cargs->api_status = sysmemmgr_setup(NULL);
70
 
                goto exit;
71
 
        }
72
 
 
73
 
        size = copy_from_user(&config, cargs->args.setup.config,
74
 
                                        sizeof(struct sysmemmgr_config));
75
 
        if (size) {
76
 
                retval = -EFAULT;
77
 
                goto exit;
78
 
        }
79
 
 
80
 
        cargs->api_status = sysmemmgr_setup(&config);
81
 
 
82
 
exit:
83
 
        return retval;
84
 
}
85
 
 
86
 
/*
87
 
 * ======== sysmemmgr_ioctl_destroy ========
88
 
 *  Purpose:
89
 
 *  This ioctl interface to sysmemmgr_destroy function
90
 
 */
91
 
static inline int sysmemmgr_ioctl_destroy(struct sysmemmgr_cmd_args *cargs)
92
 
{
93
 
        cargs->api_status = sysmemmgr_destroy();
94
 
        return 0;
95
 
}
96
 
 
97
 
/*
98
 
 * ======== sysmemmgr_ioctl_alloc ========
99
 
 *  Purpose:
100
 
 *  This ioctl interface to sysmemmgr_alloc function
101
 
 */
102
 
static inline int sysmemmgr_ioctl_alloc(struct sysmemmgr_cmd_args *cargs)
103
 
{
104
 
        void *kbuf = NULL;
105
 
        void *phys = NULL;
106
 
 
107
 
        kbuf = sysmemmgr_alloc(cargs->args.alloc.size,
108
 
                                cargs->args.alloc.flags);
109
 
        if (unlikely(kbuf == NULL))
110
 
                goto exit;
111
 
 
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;
116
 
 
117
 
exit:
118
 
        cargs->args.alloc.kbuf = kbuf;
119
 
        cargs->args.alloc.kbuf = phys;
120
 
        return 0;
121
 
}
122
 
 
123
 
/*
124
 
 * ======== sysmemmgr_ioctl_free ========
125
 
 *  Purpose:
126
 
 *  This ioctl interface to sysmemmgr_free function
127
 
 */
128
 
static inline int sysmemmgr_ioctl_free(struct sysmemmgr_cmd_args *cargs)
129
 
{
130
 
        cargs->api_status = sysmemmgr_free(cargs->args.free.kbuf,
131
 
                                                cargs->args.free.size,
132
 
                                                cargs->args.alloc.flags);
133
 
        return 0;
134
 
}
135
 
 
136
 
/*
137
 
 * ======== sysmemmgr_ioctl_translate ========
138
 
 *  Purpose:
139
 
 *  This ioctl interface to sysmemmgr_translate function
140
 
 */
141
 
static inline int sysmemmgr_ioctl_translate(struct sysmemmgr_cmd_args *cargs)
142
 
{
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;
148
 
        return 0;
149
 
}
150
 
 
151
 
/*
152
 
 * ======== sysmemmgr_ioctl ========
153
 
 *  Purpose:
154
 
 *  ioctl interface function for sysmemmgr module
155
 
 */
156
 
int sysmemmgr_ioctl(struct inode *inode, struct file *filp,
157
 
                                unsigned int cmd, unsigned long args)
158
 
{
159
 
        int os_status = 0;
160
 
        struct sysmemmgr_cmd_args __user *uarg =
161
 
                                (struct sysmemmgr_cmd_args __user *)args;
162
 
        struct sysmemmgr_cmd_args cargs;
163
 
        unsigned long size;
164
 
 
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));
169
 
        if (os_status) {
170
 
                os_status = -EFAULT;
171
 
                goto exit;
172
 
        }
173
 
 
174
 
        /* Copy the full args from user-side */
175
 
        size = copy_from_user(&cargs, uarg, sizeof(struct sysmemmgr_cmd_args));
176
 
        if (size) {
177
 
                os_status = -EFAULT;
178
 
                goto exit;
179
 
        }
180
 
 
181
 
        switch (cmd) {
182
 
        case CMD_SYSMEMMGR_GETCONFIG:
183
 
                os_status = sysmemmgr_ioctl_get_config(&cargs);
184
 
                break;
185
 
 
186
 
        case CMD_SYSMEMMGR_SETUP:
187
 
                os_status = sysmemmgr_ioctl_setup(&cargs);
188
 
                break;
189
 
 
190
 
        case CMD_SYSMEMMGR_DESTROY:
191
 
                os_status = sysmemmgr_ioctl_destroy(&cargs);
192
 
                break;
193
 
 
194
 
        case CMD_SYSMEMMGR_ALLOC:
195
 
                os_status = sysmemmgr_ioctl_alloc(&cargs);
196
 
                break;
197
 
 
198
 
        case CMD_SYSMEMMGR_FREE:
199
 
                os_status = sysmemmgr_ioctl_free(&cargs);
200
 
                break;
201
 
 
202
 
        case CMD_SYSMEMMGR_TRANSLATE:
203
 
                os_status = sysmemmgr_ioctl_translate(&cargs);
204
 
                break;
205
 
 
206
 
        default:
207
 
                WARN_ON(cmd);
208
 
                os_status = -ENOTTY;
209
 
                break;
210
 
        }
211
 
 
212
 
        if ((cargs.api_status == -ERESTARTSYS) || (cargs.api_status == -EINTR))
213
 
                os_status = -ERESTARTSYS;
214
 
 
215
 
        if (os_status < 0)
216
 
                goto exit;
217
 
 
218
 
        /* Copy the full args to the user-side. */
219
 
        size = copy_to_user(uarg, &cargs, sizeof(struct sysmemmgr_cmd_args));
220
 
        if (size) {
221
 
                os_status = -EFAULT;
222
 
                goto exit;
223
 
        }
224
 
 
225
 
exit:
226
 
        return os_status;
227
 
}