aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/dsp/syslink
diff options
context:
space:
mode:
authorHari Kanigeri <h-kanigeri2@ti.com>2010-09-09 11:36:29 -0400
committerPaolo Pisati <paolo.pisati@canonical.com>2012-08-17 04:19:07 -0400
commitf253a61db3fa11113c9fdeb576252f62acabc993 (patch)
tree68ccfdd25f2d9821d49e936dfcc4b05903d0438c /drivers/dsp/syslink
parent98d7943220835ab9699035b36736123a406cd40a (diff)
SYSLINK:ProcMgr-Add ProcMgr to Syslink
Add ProcMgr to Syslink Signed-off-by: Hari Kanigeri <h-kanigeri2@ti.com> Signed-off-by: Ramesh Gupta G <grgupta@ti.com> Signed-off-by: Suman Anna <s-anna@ti.com> Signed-off-by: Arun M G <arunmg@ti.com> Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
Diffstat (limited to 'drivers/dsp/syslink')
-rw-r--r--drivers/dsp/syslink/procmgr/Kbuild9
-rw-r--r--drivers/dsp/syslink/procmgr/proc4430/Kbuild9
-rw-r--r--drivers/dsp/syslink/procmgr/proc4430/proc4430.c834
-rw-r--r--drivers/dsp/syslink/procmgr/proc4430/proc4430.h133
-rw-r--r--drivers/dsp/syslink/procmgr/proc4430/proc4430_drv.c434
-rw-r--r--drivers/dsp/syslink/procmgr/proc4430/proc4430_drvdefs.h169
-rw-r--r--drivers/dsp/syslink/procmgr/procdefs.h155
-rw-r--r--drivers/dsp/syslink/procmgr/processor.c293
-rw-r--r--drivers/dsp/syslink/procmgr/processor.h70
-rw-r--r--drivers/dsp/syslink/procmgr/procmgr.c790
-rw-r--r--drivers/dsp/syslink/procmgr/procmgr_drv.c731
-rw-r--r--drivers/dsp/syslink/procmgr/procmgr_drvdefs.h491
12 files changed, 4118 insertions, 0 deletions
diff --git a/drivers/dsp/syslink/procmgr/Kbuild b/drivers/dsp/syslink/procmgr/Kbuild
new file mode 100644
index 00000000000..33622e8425b
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/Kbuild
@@ -0,0 +1,9 @@
1libomap_syslink_proc = processor.o procmgr.o procmgr_drv.o
2
3obj-$(CONFIG_SYSLINK_PROC) += syslink_proc.o
4syslink_proc-objs = $(libomap_syslink_proc)
5
6ccflags-y += -Wno-strict-prototypes
7
8#Header files
9ccflags-y += -Iarch/arm/plat-omap/include/syslink
diff --git a/drivers/dsp/syslink/procmgr/proc4430/Kbuild b/drivers/dsp/syslink/procmgr/proc4430/Kbuild
new file mode 100644
index 00000000000..3dee46d956d
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/proc4430/Kbuild
@@ -0,0 +1,9 @@
1libomap_proc4430 = proc4430.o proc4430_drv.o
2
3obj-$(CONFIG_SYSLINK_PROC) += syslink_proc4430.o
4syslink_proc4430-objs = $(libomap_proc4430)
5
6ccflags-y += -Wno-strict-prototypes -DUSE_LEVEL_1_MACROS
7
8#Header files
9ccflags-y += -Iarch/arm/plat-omap/include/syslink
diff --git a/drivers/dsp/syslink/procmgr/proc4430/proc4430.c b/drivers/dsp/syslink/procmgr/proc4430/proc4430.c
new file mode 100644
index 00000000000..44c66c6a444
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/proc4430/proc4430.c
@@ -0,0 +1,834 @@
1/*
2 * proc4430.c
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#include <linux/types.h>
18#include <linux/mm.h>
19#include <linux/sched.h>
20#include <linux/module.h>
21#include <linux/mutex.h>
22#include <linux/vmalloc.h>
23#include <linux/uaccess.h>
24#include <linux/io.h>
25#include <linux/delay.h>
26#include <linux/slab.h>
27
28/* Module level headers */
29#include "../procdefs.h"
30#include "../processor.h"
31#include <procmgr.h>
32#include "../procmgr_drvdefs.h"
33#include "proc4430.h"
34#include "../../ipu_pm/ipu_pm.h"
35#include <syslink/multiproc.h>
36#include <syslink/platform_mem.h>
37#include <syslink/atomic_linux.h>
38
39
40#define OMAP4430PROC_MODULEID (u16) 0xbbec
41
42/* Macro to make a correct module magic number with refCount */
43#define OMAP4430PROC_MAKE_MAGICSTAMP(x) ((OMAP4430PROC_MODULEID << 12u) | (x))
44
45#define PG_MASK(pg_size) (~((pg_size)-1))
46#define PG_ALIGN_LOW(addr, pg_size) ((addr) & PG_MASK(pg_size))
47
48/*OMAP4430 Module state object */
49struct proc4430_module_object {
50 u32 config_size;
51 /* Size of configuration structure */
52 struct proc4430_config cfg;
53 /* OMAP4430 configuration structure */
54 struct proc4430_config def_cfg;
55 /* Default module configuration */
56 struct proc4430_params def_inst_params;
57 /* Default parameters for the OMAP4430 instances */
58 void *proc_handles[MULTIPROC_MAXPROCESSORS];
59 /* Processor handle array. */
60 struct mutex *gate_handle;
61 /* void * of gate to be used for local thread safety */
62 atomic_t ref_count;
63};
64
65/*
66 OMAP4430 instance object.
67 */
68struct proc4430_object {
69 struct proc4430_params params;
70 /* Instance parameters (configuration values) */
71 atomic_t attach_count;
72 /* attach reference count */
73};
74
75
76/* =================================
77 * Globals
78 * =================================
79 */
80/*
81 OMAP4430 state object variable
82 */
83
84static struct proc4430_module_object proc4430_state = {
85 .config_size = sizeof(struct proc4430_config),
86 .gate_handle = NULL,
87 .def_inst_params.num_mem_entries = 0u,
88 .def_inst_params.mem_entries = NULL,
89 .def_inst_params.reset_vector_mem_entry = 0
90};
91
92
93/* =================================
94 * APIs directly called by applications
95 * =================================
96 */
97/*
98 * Function to get the default configuration for the OMAP4430
99 * module.
100 *
101 * This function can be called by the application to get their
102 * configuration parameter to proc4430_setup filled in by the
103 * OMAP4430 module with the default parameters. If the user
104 * does not wish to make any change in the default parameters, this
105 * API is not required to be called.
106 */
107void proc4430_get_config(struct proc4430_config *cfg)
108{
109 BUG_ON(cfg == NULL);
110 memcpy(cfg, &(proc4430_state.def_cfg),
111 sizeof(struct proc4430_config));
112}
113EXPORT_SYMBOL(proc4430_get_config);
114
115/*
116 * Function to setup the OMAP4430 module.
117 *
118 * This function sets up the OMAP4430 module. This function
119 * must be called before any other instance-level APIs can be
120 * invoked.
121 * Module-level configuration needs to be provided to this
122 * function. If the user wishes to change some specific config
123 * parameters, then proc4430_get_config can be called to get the
124 * configuration filled with the default values. After this, only
125 * the required configuration values can be changed. If the user
126 * does not wish to make any change in the default parameters, the
127 * application can simply call proc4430_setup with NULL
128 * parameters. The default parameters would get automatically used.
129 */
130int proc4430_setup(struct proc4430_config *cfg)
131{
132 int retval = 0;
133 struct proc4430_config tmp_cfg;
134 atomic_cmpmask_and_set(&proc4430_state.ref_count,
135 OMAP4430PROC_MAKE_MAGICSTAMP(0),
136 OMAP4430PROC_MAKE_MAGICSTAMP(0));
137
138 if (atomic_inc_return(&proc4430_state.ref_count) !=
139 OMAP4430PROC_MAKE_MAGICSTAMP(1)) {
140 return 1;
141 }
142
143 if (cfg == NULL) {
144 proc4430_get_config(&tmp_cfg);
145 cfg = &tmp_cfg;
146 }
147
148 /* Create a default gate handle for local module protection. */
149 proc4430_state.gate_handle =
150 kmalloc(sizeof(struct mutex), GFP_KERNEL);
151 if (proc4430_state.gate_handle == NULL) {
152 retval = -ENOMEM;
153 goto error;
154 }
155
156 mutex_init(proc4430_state.gate_handle);
157
158 /* Initialize the name to handles mapping array. */
159 memset(&proc4430_state.proc_handles, 0,
160 (sizeof(void *) * MULTIPROC_MAXPROCESSORS));
161
162 /* Copy the user provided values into the state object. */
163 memcpy(&proc4430_state.cfg, cfg,
164 sizeof(struct proc4430_config));
165
166 return 0;
167
168error:
169 atomic_dec_return(&proc4430_state.ref_count);
170
171 return retval;
172}
173EXPORT_SYMBOL(proc4430_setup);
174
175/*
176 * Function to destroy the OMAP4430 module.
177 *
178 * Once this function is called, other OMAP4430 module APIs,
179 * except for the proc4430_get_config API cannot be called
180 * anymore.
181 */
182int proc4430_destroy(void)
183{
184 int retval = 0;
185 u16 i;
186
187 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
188 OMAP4430PROC_MAKE_MAGICSTAMP(0),
189 OMAP4430PROC_MAKE_MAGICSTAMP(1))
190 == true) {
191 retval = -ENODEV;
192 goto exit;
193 }
194 if (!(atomic_dec_return(&proc4430_state.ref_count)
195 == OMAP4430PROC_MAKE_MAGICSTAMP(0))) {
196
197 retval = 1;
198 goto exit;
199 }
200
201 /* Check if any OMAP4430 instances have not been
202 * deleted so far. If not,delete them.
203 */
204
205 for (i = 0; i < MULTIPROC_MAXPROCESSORS; i++) {
206 if (proc4430_state.proc_handles[i] == NULL)
207 continue;
208 proc4430_delete(&(proc4430_state.proc_handles[i]));
209 }
210
211 /* Check if the gate_handle was created internally. */
212 if (proc4430_state.gate_handle != NULL) {
213 mutex_destroy(proc4430_state.gate_handle);
214 kfree(proc4430_state.gate_handle);
215 }
216
217exit:
218 return retval;
219}
220EXPORT_SYMBOL(proc4430_destroy);
221
222/*=================================================
223 * Function to initialize the parameters for this Processor
224 * instance.
225 */
226void proc4430_params_init(void *handle, struct proc4430_params *params)
227{
228 struct proc4430_object *proc_object = (struct proc4430_object *)handle;
229
230 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
231 OMAP4430PROC_MAKE_MAGICSTAMP(0),
232 OMAP4430PROC_MAKE_MAGICSTAMP(1))
233 == true) {
234 printk(KERN_ERR "proc4430_params_init failed "
235 "Module not initialized");
236 return;
237 }
238
239 if (WARN_ON(params == NULL)) {
240 printk(KERN_ERR "proc4430_params_init failed "
241 "Argument of type proc4430_params * "
242 "is NULL");
243 return;
244 }
245
246 if (handle == NULL)
247 memcpy(params, &(proc4430_state.def_inst_params),
248 sizeof(struct proc4430_params));
249 else
250 memcpy(params, &(proc_object->params),
251 sizeof(struct proc4430_params));
252}
253EXPORT_SYMBOL(proc4430_params_init);
254
255/*===================================================
256 *Function to create an instance of this Processor.
257 *
258 */
259void *proc4430_create(u16 proc_id, const struct proc4430_params *params)
260{
261 struct processor_object *handle = NULL;
262 struct proc4430_object *object = NULL;
263
264 BUG_ON(!IS_VALID_PROCID(proc_id));
265 BUG_ON(params == NULL);
266
267 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
268 OMAP4430PROC_MAKE_MAGICSTAMP(0),
269 OMAP4430PROC_MAKE_MAGICSTAMP(1))
270 == true) {
271 printk(KERN_ERR "proc4430_create failed "
272 "Module not initialized");
273 goto error;
274 }
275
276 /* Enter critical section protection. */
277 WARN_ON(mutex_lock_interruptible(proc4430_state.gate_handle));
278 if (proc4430_state.proc_handles[proc_id] != NULL) {
279 handle = proc4430_state.proc_handles[proc_id];
280 goto func_end;
281 } else {
282 handle = (struct processor_object *)
283 vmalloc(sizeof(struct processor_object));
284 if (WARN_ON(handle == NULL))
285 goto func_end;
286
287 handle->proc_fxn_table.attach = &proc4430_attach;
288 handle->proc_fxn_table.detach = &proc4430_detach;
289 handle->proc_fxn_table.read = &proc4430_read;
290 handle->proc_fxn_table.write = &proc4430_write;
291 handle->proc_fxn_table.control = &proc4430_control;
292 handle->proc_fxn_table.translateAddr =
293 &proc4430_translate_addr;
294 handle->proc_fxn_table.procinfo = &proc4430_proc_info;
295 handle->proc_fxn_table.virt_to_phys = &proc4430_virt_to_phys;
296 handle->state = PROC_MGR_STATE_UNKNOWN;
297 handle->object = vmalloc(sizeof(struct proc4430_object));
298 handle->proc_id = proc_id;
299 object = (struct proc4430_object *)handle->object;
300 if (params != NULL) {
301 /* Copy params into instance object. */
302 memcpy(&(object->params), (void *)params,
303 sizeof(struct proc4430_params));
304 }
305 if ((params != NULL) && (params->mem_entries != NULL)
306 && (params->num_mem_entries > 0)) {
307 /* Allocate memory for, and copy mem_entries table*/
308 object->params.mem_entries = vmalloc(sizeof(struct
309 proc4430_mem_entry) *
310 params->num_mem_entries);
311 memcpy(object->params.mem_entries,
312 params->mem_entries,
313 (sizeof(struct proc4430_mem_entry) *
314 params->num_mem_entries));
315 }
316 handle->boot_mode = PROC_MGR_BOOTMODE_NOLOAD;
317 /* Set the handle in the state object. */
318 proc4430_state.proc_handles[proc_id] = handle;
319 }
320
321func_end:
322 mutex_unlock(proc4430_state.gate_handle);
323error:
324 return (void *)handle;
325}
326EXPORT_SYMBOL(proc4430_create);
327
328/*=================================================
329 * Function to delete an instance of this Processor.
330 *
331 * The user provided pointer to the handle is reset after
332 * successful completion of this function.
333 *
334 */
335int proc4430_delete(void **handle_ptr)
336{
337 int retval = 0;
338 struct proc4430_object *object = NULL;
339 struct processor_object *handle;
340
341 BUG_ON(handle_ptr == NULL);
342 BUG_ON(*handle_ptr == NULL);
343
344 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
345 OMAP4430PROC_MAKE_MAGICSTAMP(0),
346 OMAP4430PROC_MAKE_MAGICSTAMP(1))
347 == true) {
348 printk(KERN_ERR "proc4430_delete failed "
349 "Module not initialized");
350 return -ENODEV;
351 }
352
353 handle = (struct processor_object *)(*handle_ptr);
354 BUG_ON(!IS_VALID_PROCID(handle->proc_id));
355 /* Enter critical section protection. */
356 WARN_ON(mutex_lock_interruptible(proc4430_state.gate_handle));
357 /* Reset handle in PwrMgr handle array. */
358 proc4430_state.proc_handles[handle->proc_id] = NULL;
359 /* Free memory used for the OMAP4430 object. */
360 if (handle->object != NULL) {
361 object = (struct proc4430_object *)handle->object;
362 if (object->params.mem_entries != NULL) {
363 vfree(object->params.mem_entries);
364 object->params.mem_entries = NULL;
365 }
366 vfree(handle->object);
367 handle->object = NULL;
368 }
369 /* Free memory used for the Processor object. */
370 vfree(handle);
371 *handle_ptr = NULL;
372 /* Leave critical section protection. */
373 mutex_unlock(proc4430_state.gate_handle);
374 return retval;
375}
376EXPORT_SYMBOL(proc4430_delete);
377
378/*===================================================
379 * Function to open a handle to an instance of this Processor. This
380 * function is called when access to the Processor is required from
381 * a different process.
382 */
383int proc4430_open(void **handle_ptr, u16 proc_id)
384{
385 int retval = 0;
386
387 BUG_ON(handle_ptr == NULL);
388 BUG_ON(!IS_VALID_PROCID(proc_id));
389
390 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
391 OMAP4430PROC_MAKE_MAGICSTAMP(0),
392 OMAP4430PROC_MAKE_MAGICSTAMP(1))
393 == true) {
394 printk(KERN_ERR "proc4430_open failed "
395 "Module not initialized");
396 return -ENODEV;
397 }
398
399 /* Initialize return parameter handle. */
400 *handle_ptr = NULL;
401
402 /* Check if the PwrMgr exists and return the handle if found. */
403 if (proc4430_state.proc_handles[proc_id] == NULL) {
404 retval = -ENODEV;
405 goto func_exit;
406 } else
407 *handle_ptr = proc4430_state.proc_handles[proc_id];
408func_exit:
409 return retval;
410}
411EXPORT_SYMBOL(proc4430_open);
412
413/*===============================================
414 * Function to close a handle to an instance of this Processor.
415 *
416 */
417int proc4430_close(void *handle)
418{
419 int retval = 0;
420
421 BUG_ON(handle == NULL);
422
423 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
424 OMAP4430PROC_MAKE_MAGICSTAMP(0),
425 OMAP4430PROC_MAKE_MAGICSTAMP(1))
426 == true) {
427 printk(KERN_ERR "proc4430_close failed "
428 "Module not initialized");
429 return -ENODEV;
430 }
431
432 /* nothing to be done for now */
433 return retval;
434}
435EXPORT_SYMBOL(proc4430_close);
436
437/* =================================
438 * APIs called by Processor module (part of function table interface)
439 * =================================
440 */
441/*================================
442 * Function to initialize the slave processor
443 *
444 */
445int proc4430_attach(void *handle, struct processor_attach_params *params)
446{
447 int retval = 0;
448
449 struct processor_object *proc_handle = NULL;
450 struct proc4430_object *object = NULL;
451 u32 map_count = 0;
452 u32 i;
453 memory_map_info map_info;
454
455 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
456 OMAP4430PROC_MAKE_MAGICSTAMP(0),
457 OMAP4430PROC_MAKE_MAGICSTAMP(1))
458 == true) {
459 printk(KERN_ERR "proc4430_attach failed"
460 "Module not initialized");
461 return -ENODEV;
462 }
463
464 if (WARN_ON(handle == NULL)) {
465 printk(KERN_ERR "proc4430_attach failed"
466 "Driver handle is NULL");
467 return -EINVAL;
468 }
469
470 if (WARN_ON(params == NULL)) {
471 printk(KERN_ERR "proc4430_attach failed"
472 "Argument processor_attach_params * is NULL");
473 return -EINVAL;
474 }
475
476 proc_handle = (struct processor_object *)handle;
477
478 object = (struct proc4430_object *)proc_handle->object;
479
480 atomic_cmpmask_and_set(&object->attach_count,
481 OMAP4430PROC_MAKE_MAGICSTAMP(0),
482 OMAP4430PROC_MAKE_MAGICSTAMP(0));
483 atomic_inc_return(&object->attach_count);
484
485 printk(KERN_ERR "proc4430_attach num_mem_entries = %d",
486 object->params.num_mem_entries);
487 /* Return memory information in params. */
488 for (i = 0; (i < object->params.num_mem_entries); i++) {
489 /* If the configured master virtual address is invalid, get the
490 * actual address by mapping the physical address into master
491 * kernel memory space.
492 */
493 if ((object->params.mem_entries[i].master_virt_addr == (u32)-1)
494 && (object->params.mem_entries[i].shared == true)) {
495 map_info.src = object->params.mem_entries[i].phys_addr;
496 map_info.size = object->params.mem_entries[i].size;
497 map_info.is_cached = false;
498 retval = platform_mem_map(&map_info);
499 if (retval != 0) {
500 printk(KERN_ERR "proc4430_attach failed\n");
501 return -EFAULT;
502 }
503 map_count++;
504 object->params.mem_entries[i].master_virt_addr =
505 map_info.dst;
506 params->mem_entries[i].addr
507 [PROC_MGR_ADDRTYPE_MASTERKNLVIRT] =
508 map_info.dst;
509 params->mem_entries[i].addr
510 [PROC_MGR_ADDRTYPE_SLAVEVIRT] =
511 (object->params.mem_entries[i].slave_virt_addr);
512 /* User virtual will be filled by user side. For now,
513 fill in the physical address so that it can be used
514 by mmap to remap this region into user-space */
515 params->mem_entries[i].addr
516 [PROC_MGR_ADDRTYPE_MASTERUSRVIRT] = \
517 object->params.mem_entries[i].phys_addr;
518 params->mem_entries[i].size =
519 object->params.mem_entries[i].size;
520 }
521 }
522 params->num_mem_entries = map_count;
523 return retval;
524}
525
526
527/*==========================================
528 * Function to detach from the Processor.
529 *
530 */
531int proc4430_detach(void *handle)
532{
533 struct processor_object *proc_handle = NULL;
534 struct proc4430_object *object = NULL;
535 u32 i;
536 memory_unmap_info unmap_info;
537
538 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
539 OMAP4430PROC_MAKE_MAGICSTAMP(0),
540 OMAP4430PROC_MAKE_MAGICSTAMP(1))
541 == true) {
542
543 printk(KERN_ERR "proc4430_detach failed "
544 "Module not initialized");
545 return -ENODEV;
546 }
547 if (WARN_ON(handle == NULL)) {
548 printk(KERN_ERR "proc4430_detach failed "
549 "Argument Driverhandle is NULL");
550 return -EINVAL;
551 }
552
553 proc_handle = (struct processor_object *)handle;
554 object = (struct proc4430_object *)proc_handle->object;
555
556 if (!(atomic_dec_return(&object->attach_count) == \
557 OMAP4430PROC_MAKE_MAGICSTAMP(0)))
558 return 1;
559
560 for (i = 0; (i < object->params.num_mem_entries); i++) {
561 if ((object->params.mem_entries[i].master_virt_addr > 0)
562 && (object->params.mem_entries[i].shared == true)) {
563 unmap_info.addr =
564 object->params.mem_entries[i].master_virt_addr;
565 unmap_info.size = object->params.mem_entries[i].size;
566 platform_mem_unmap(&unmap_info);
567 object->params.mem_entries[i].master_virt_addr =
568 (u32)-1;
569 }
570 }
571 return 0;
572}
573
574
575/*==============================================
576 * Function to read from the slave processor's memory.
577 *
578 * Read from the slave processor's memory and copy into the
579 * provided buffer.
580 */
581int proc4430_read(void *handle, u32 proc_addr, u32 *num_bytes,
582 void *buffer)
583{
584 int retval = 0;
585 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
586 OMAP4430PROC_MAKE_MAGICSTAMP(0),
587 OMAP4430PROC_MAKE_MAGICSTAMP(1))
588 == true) {
589 printk(KERN_ERR "proc4430_read failed "
590 "Module not initialized");
591 return -ENODEV;
592 }
593
594 buffer = memcpy(buffer, (void *)proc_addr, *num_bytes);
595
596 return retval;
597}
598
599
600/*==============================================
601 * Function to write into the slave processor's memory.
602 *
603 * Read from the provided buffer and copy into the slave
604 * processor's memory.
605 *
606 */
607int proc4430_write(void *handle, u32 proc_addr, u32 *num_bytes,
608 void *buffer)
609{
610 int retval = 0;
611
612 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
613 OMAP4430PROC_MAKE_MAGICSTAMP(0),
614 OMAP4430PROC_MAKE_MAGICSTAMP(1))
615 == true) {
616 printk(KERN_ERR "proc4430_write failed "
617 "Module not initialized");
618 return -ENODEV;
619 }
620
621 proc_addr = (u32)memcpy((void *)proc_addr, buffer, *num_bytes);
622
623 return retval;
624}
625
626
627/*=========================================================
628 * Function to perform device-dependent operations.
629 *
630 * Performs device-dependent control operations as exposed by this
631 * implementation of the Processor module.
632 */
633int proc4430_control(void *handle, int cmd, void *arg)
634{
635 int retval = 0;
636
637 /*FIXME: Remove handle,etc if not used */
638
639#ifdef CONFIG_SYSLINK_DUCATI_PM
640 /* For purpose testing */
641 switch (cmd) {
642 case PM_SUSPEND:
643 case PM_RESUME:
644 retval = ipu_pm_notifications(cmd, NULL);
645 break;
646 default:
647 printk(KERN_ERR "Invalid notification\n");
648 }
649 if (retval != PM_SUCCESS)
650 printk(KERN_ERR "Error in notifications\n");
651#endif
652
653 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
654 OMAP4430PROC_MAKE_MAGICSTAMP(0),
655 OMAP4430PROC_MAKE_MAGICSTAMP(1))
656 == true) {
657 printk(KERN_ERR "proc4430_control failed "
658 "Module not initialized");
659 return -ENODEV;
660 }
661
662 return retval;
663}
664
665
666/*=====================================================
667 * Function to translate between two types of address spaces.
668 *
669 * Translate between the specified address spaces.
670 */
671int proc4430_translate_addr(void *handle,
672 void **dst_addr, enum proc_mgr_addr_type dst_addr_type,
673 void *src_addr, enum proc_mgr_addr_type src_addr_type)
674{
675 int retval = 0;
676 struct processor_object *proc_handle = NULL;
677 struct proc4430_object *object = NULL;
678 struct proc4430_mem_entry *entry = NULL;
679 bool found = false;
680 u32 fm_addr_base = (u32)NULL;
681 u32 to_addr_base = (u32)NULL;
682 u32 i;
683
684 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
685 OMAP4430PROC_MAKE_MAGICSTAMP(0),
686 OMAP4430PROC_MAKE_MAGICSTAMP(1))
687 == true) {
688 printk(KERN_ERR "proc4430_translate_addr failed "
689 "Module not initialized");
690 retval = -ENODEV;
691 goto error_exit;
692 }
693
694 if (WARN_ON(handle == NULL)) {
695 retval = -EINVAL;
696 goto error_exit;
697 }
698 if (WARN_ON(dst_addr == NULL)) {
699 retval = -EINVAL;
700 goto error_exit;
701 }
702 if (WARN_ON(dst_addr_type > PROC_MGR_ADDRTYPE_ENDVALUE)) {
703 retval = -EINVAL;
704 goto error_exit;
705 }
706 if (WARN_ON(src_addr == NULL)) {
707 retval = -EINVAL;
708 goto error_exit;
709 }
710 if (WARN_ON(src_addr_type > PROC_MGR_ADDRTYPE_ENDVALUE)) {
711 retval = -EINVAL;
712 goto error_exit;
713 }
714
715 proc_handle = (struct processor_object *)handle;
716 object = (struct proc4430_object *)proc_handle->object;
717 *dst_addr = NULL;
718 for (i = 0 ; i < object->params.num_mem_entries ; i++) {
719 entry = &(object->params.mem_entries[i]);
720 fm_addr_base =
721 (src_addr_type == PROC_MGR_ADDRTYPE_MASTERKNLVIRT) ?
722 entry->master_virt_addr : entry->slave_virt_addr;
723 to_addr_base =
724 (dst_addr_type == PROC_MGR_ADDRTYPE_MASTERKNLVIRT) ?
725 entry->master_virt_addr : entry->slave_virt_addr;
726 /* Determine whether which way to convert */
727 if (((u32)src_addr < (fm_addr_base + entry->size)) &&
728 ((u32)src_addr >= fm_addr_base)) {
729 found = true;
730 *dst_addr = (void *)(((u32)src_addr - fm_addr_base)
731 + to_addr_base);
732 break;
733 }
734 }
735
736 /* This check must not be removed even with build optimize. */
737 if (WARN_ON(found == false)) {
738 /*Failed to translate address. */
739 retval = -ENXIO;
740 goto error_exit;
741 }
742 return 0;
743
744error_exit:
745 return retval;
746}
747
748
749/*=================================================
750 * Function to return list of translated mem entries
751 *
752 * This function takes the remote processor address as
753 * an input and returns the mapped Page entries in the
754 * buffer passed
755 */
756int proc4430_virt_to_phys(void *handle, u32 da, u32 *mapped_entries,
757 u32 num_of_entries)
758{
759 int da_align;
760 int i;
761 int ret_val = 0;
762
763 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
764 OMAP4430PROC_MAKE_MAGICSTAMP(0),
765 OMAP4430PROC_MAKE_MAGICSTAMP(1))
766 == true) {
767 printk(KERN_ERR "proc4430_virt_to_phys failed "
768 "Module not initialized");
769 ret_val = -EFAULT;
770 goto error_exit;
771 }
772
773 if (handle == NULL || mapped_entries == NULL || num_of_entries == 0) {
774 ret_val = -EFAULT;
775 goto error_exit;
776 }
777 da_align = PG_ALIGN_LOW((u32)da, PAGE_SIZE);
778 for (i = 0; i < num_of_entries; i++) {
779 mapped_entries[i] = da_align;
780 da_align += PAGE_SIZE;
781 }
782 return 0;
783
784error_exit:
785 printk(KERN_WARNING "proc4430_virtToPhys failed !!!!\n");
786 return ret_val;
787}
788
789
790/*=================================================
791 * Function to return PROC4430 mem_entries info
792 *
793 */
794int proc4430_proc_info(void *handle, struct proc_mgr_proc_info *procinfo)
795{
796 struct processor_object *proc_handle = NULL;
797 struct proc4430_object *object = NULL;
798 struct proc4430_mem_entry *entry = NULL;
799 int i;
800
801 if (atomic_cmpmask_and_lt(&proc4430_state.ref_count,
802 OMAP4430PROC_MAKE_MAGICSTAMP(0),
803 OMAP4430PROC_MAKE_MAGICSTAMP(1))
804 == true) {
805 printk(KERN_ERR "proc4430_proc_info failed "
806 "Module not initialized");
807 goto error_exit;
808 }
809
810 if (WARN_ON(handle == NULL))
811 goto error_exit;
812 if (WARN_ON(procinfo == NULL))
813 goto error_exit;
814
815 proc_handle = (struct processor_object *)handle;
816
817 object = (struct proc4430_object *)proc_handle->object;
818
819 for (i = 0 ; i < object->params.num_mem_entries ; i++) {
820 entry = &(object->params.mem_entries[i]);
821 procinfo->mem_entries[i].addr[PROC_MGR_ADDRTYPE_MASTERKNLVIRT]
822 = entry->master_virt_addr;
823 procinfo->mem_entries[i].addr[PROC_MGR_ADDRTYPE_SLAVEVIRT]
824 = entry->slave_virt_addr;
825 procinfo->mem_entries[i].size = entry->size;
826 }
827 procinfo->num_mem_entries = object->params.num_mem_entries;
828 procinfo->boot_mode = proc_handle->boot_mode;
829 return 0;
830
831error_exit:
832 printk(KERN_WARNING "proc4430_proc_info failed !!!!\n");
833 return -EFAULT;
834}
diff --git a/drivers/dsp/syslink/procmgr/proc4430/proc4430.h b/drivers/dsp/syslink/procmgr/proc4430/proc4430.h
new file mode 100644
index 00000000000..e264f473aa0
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/proc4430/proc4430.h
@@ -0,0 +1,133 @@
1/*
2 * proc4430.h
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17
18
19
20#ifndef _SYSLINK_PROC_4430_H_
21#define _SYSLINK_PROC_4430_H_
22
23
24/* Module headers */
25#include <procmgr.h>
26#include "../procdefs.h"
27#include <linux/types.h>
28
29/*
30 Module configuration structure.
31 */
32struct proc4430_config {
33 struct mutex *gate_handle;
34 /* void * of gate to be used for local thread safety */
35};
36
37/*
38 Memory entry for slave memory map configuration
39 */
40struct proc4430_mem_entry {
41 char name[PROCMGR_MAX_STRLEN];
42 /* Name identifying the memory region. */
43 u32 phys_addr;
44 /* Physical address of the memory region. */
45 u32 slave_virt_addr;
46 /* Slave virtual address of the memory region. */
47 u32 master_virt_addr;
48 /* Master virtual address of the memory region. If specified as -1,
49 * the master virtual address is assumed to be invalid, and shall be
50 * set internally within the Processor module. */
51 u32 size;
52 /* Size (in bytes) of the memory region. */
53 bool shared;
54 /* Flag indicating whether the memory region is shared between master
55 * and slave. */
56};
57
58/*
59 Configuration parameters specific to this processor.
60 */
61struct proc4430_params {
62 int num_mem_entries;
63 /* Number of memory regions to be configured. */
64 struct proc4430_mem_entry *mem_entries;
65 /* Array of information structures for memory regions
66 * to be configured. */
67 u32 reset_vector_mem_entry;
68 /* Index of the memory entry within the mem_entries array,
69 * which is the resetVector memory region. */
70};
71
72
73/* Function to initialize the slave processor */
74int proc4430_attach(void *handle, struct processor_attach_params *params);
75
76/* Function to finalize the slave processor */
77int proc4430_detach(void *handle);
78
79
80/* Function to read from the slave processor's memory. */
81int proc4430_read(void *handle, u32 proc_addr, u32 *num_bytes,
82 void *buffer);
83
84/* Function to write into the slave processor's memory. */
85int proc4430_write(void *handle, u32 proc_addr, u32 *num_bytes,
86 void *buffer);
87
88/* Function to perform device-dependent operations. */
89int proc4430_control(void *handle, int cmd, void *arg);
90
91/* Function to translate between two types of address spaces. */
92int proc4430_translate_addr(void *handle, void **dst_addr,
93 enum proc_mgr_addr_type dst_addr_type,
94 void *src_addr, enum proc_mgr_addr_type src_addr_type);
95
96/* Function to retrive physical address translations */
97int proc4430_virt_to_phys(void *handle, u32 da, u32 *mapped_entries,
98 u32 num_of_entries);
99
100/* =================================================
101 * APIs
102 * =================================================
103 */
104
105/* Function to get the default configuration for the OMAP4430PROC module */
106void proc4430_get_config(struct proc4430_config *cfg);
107
108/* Function to setup the OMAP4430PROC module. */
109int proc4430_setup(struct proc4430_config *cfg);
110
111/* Function to destroy the OMAP4430PROC module. */
112int proc4430_destroy(void);
113
114/* Function to initialize the parameters for this processor instance. */
115void proc4430_params_init(void *handle,
116 struct proc4430_params *params);
117
118/* Function to create an instance of this processor. */
119void *proc4430_create(u16 proc_id, const struct proc4430_params *params);
120
121/* Function to delete an instance of this processor. */
122int proc4430_delete(void **handle_ptr);
123
124/* Function to open an instance of this processor. */
125int proc4430_open(void **handle_ptr, u16 proc_id);
126
127/* Function to close an instance of this processor. */
128int proc4430_close(void *handle);
129
130/* Function to get the proc info */
131int proc4430_proc_info(void *handle, struct proc_mgr_proc_info *procinfo);
132
133#endif
diff --git a/drivers/dsp/syslink/procmgr/proc4430/proc4430_drv.c b/drivers/dsp/syslink/procmgr/proc4430/proc4430_drv.c
new file mode 100644
index 00000000000..f7d75db0e6d
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/proc4430/proc4430_drv.c
@@ -0,0 +1,434 @@
1/*
2 * proc4430_drv.c
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#include <generated/autoconf.h>
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/cdev.h>
21#include <linux/device.h>
22#include <linux/fs.h>
23#include <linux/mm.h>
24#include <linux/slab.h>
25#include <linux/vmalloc.h>
26#include <linux/uaccess.h>
27#include <linux/platform_device.h>
28
29
30/* Module headers */
31#include "proc4430.h"
32#include "proc4430_drvdefs.h"
33
34
35
36/** ============================================================================
37 * Macros and types
38 * ============================================================================
39 */
40#define PROC4430_NAME "syslink-proc4430"
41
42static char *driver_name = PROC4430_NAME;
43
44static s32 driver_major;
45
46static s32 driver_minor;
47
48struct proc_4430_dev {
49 struct cdev cdev;
50};
51
52static struct proc_4430_dev *proc_4430_device;
53
54static struct class *proc_4430_class;
55
56
57
58/** ============================================================================
59 * Forward declarations of internal functions
60 * ============================================================================
61 */
62/* Linux driver function to open the driver object. */
63static int proc4430_drv_open(struct inode *inode, struct file *filp);
64
65/* Linux driver function to close the driver object. */
66static int proc4430_drv_release(struct inode *inode, struct file *filp);
67
68/* Linux driver function to invoke the APIs through ioctl. */
69static int proc4430_drv_ioctl(struct inode *inode,
70 struct file *filp, unsigned int cmd,
71 unsigned long args);
72
73/* Linux driver function to map memory regions to user space. */
74static int proc4430_drv_mmap(struct file *filp,
75 struct vm_area_struct *vma);
76
77/* Module initialization function for Linux driver. */
78static int __init proc4430_drv_initializeModule(void);
79
80/* Module finalization function for Linux driver. */
81static void __exit proc4430_drv_finalizeModule(void);
82
83
84/* Process Context */
85struct proc4430_process_context {
86 u32 setup_count;
87};
88
89/** ============================================================================
90 * Globals
91 * ============================================================================
92 */
93
94/*
95 File operations table for PROC4430.
96 */
97static const struct file_operations proc_4430_fops = {
98 .open = proc4430_drv_open,
99 .release = proc4430_drv_release,
100 .ioctl = proc4430_drv_ioctl,
101 .mmap = proc4430_drv_mmap,
102};
103
104static int proc4430_drv_open(struct inode *inode, struct file *filp)
105{
106 s32 retval = 0;
107 struct proc4430_process_context *pr_ctxt = NULL;
108
109 pr_ctxt = kzalloc(sizeof(struct proc4430_process_context), GFP_KERNEL);
110 if (!pr_ctxt)
111 retval = -ENOMEM;
112
113 filp->private_data = pr_ctxt;
114 return retval;
115}
116
117static int proc4430_drv_release(struct inode *inode, struct file *filp)
118{
119 s32 retval = 0;
120 struct proc4430_process_context *pr_ctxt;
121
122 if (!filp->private_data) {
123 retval = -EIO;
124 goto err;
125 }
126
127 pr_ctxt = filp->private_data;
128 while (pr_ctxt->setup_count-- > 0) {
129 /* Destroy has not been called. Call destroy now. */
130 proc4430_destroy();
131 }
132 kfree(pr_ctxt);
133
134 filp->private_data = NULL;
135err:
136 return retval;
137}
138
139
140/*
141 Linux driver function to invoke the APIs through ioctl.
142 *
143 */
144static int proc4430_drv_ioctl(struct inode *inode, struct file *filp,
145 unsigned int cmd, unsigned long args)
146{
147 int retval = 0;
148 struct proc_mgr_cmd_args *cmd_args = (struct proc_mgr_cmd_args *)args;
149 struct proc_mgr_cmd_args command_args;
150 struct proc4430_process_context *pr_ctxt =
151 (struct proc4430_process_context *)filp->private_data;
152
153 switch (cmd) {
154 case CMD_PROC4430_GETCONFIG:
155 {
156 struct proc4430_cmd_args_get_config *src_args =
157 (struct proc4430_cmd_args_get_config *)args;
158 struct proc4430_config cfg;
159
160 /* copy_from_useris not needed for
161 * proc4430_get_config, since the
162 * user's config is not used.
163 */
164 proc4430_get_config(&cfg);
165
166 retval = copy_to_user((void __user *)(src_args->cfg),
167 (const void *)&cfg,
168 sizeof(struct proc4430_config));
169 if (WARN_ON(retval < 0))
170 goto func_exit;
171 }
172 break;
173
174 case CMD_PROC4430_SETUP:
175 {
176 struct proc4430_cmd_args_setup *src_args =
177 (struct proc4430_cmd_args_setup *)args;
178 struct proc4430_config cfg;
179
180 retval = copy_from_user((void *)&cfg,
181 (const void __user *)(src_args->cfg),
182 sizeof(struct proc4430_config));
183 if (WARN_ON(retval < 0))
184 goto func_exit;
185 proc4430_setup(&cfg);
186 pr_ctxt->setup_count++;
187 }
188 break;
189
190 case CMD_PROC4430_DESTROY:
191 {
192 proc4430_destroy();
193 pr_ctxt->setup_count--;
194 }
195 break;
196
197 case CMD_PROC4430_PARAMS_INIT:
198 {
199 struct proc4430_cmd_args_params_init src_args;
200 struct proc4430_params params;
201
202 /* Copy the full args from user-side. */
203 retval = copy_from_user((void *)&src_args,
204 (const void __user *)(args),
205 sizeof(struct proc4430_cmd_args_params_init));
206 if (WARN_ON(retval < 0))
207 goto func_exit;
208 proc4430_params_init(src_args.handle, &params);
209 retval = copy_to_user((void __user *)(src_args.params),
210 (const void *) &params,
211 sizeof(struct proc4430_params));
212 if (WARN_ON(retval < 0))
213 goto func_exit;
214 }
215 break;
216
217 case CMD_PROC4430_CREATE:
218 {
219 struct proc4430_cmd_args_create src_args;
220 struct proc4430_params params;
221 struct proc4430_mem_entry *entries = NULL;
222
223 /* Copy the full args from user-side. */
224 retval = copy_from_user((void *)&src_args,
225 (const void __user *)(args),
226 sizeof(struct proc4430_cmd_args_create));
227 if (WARN_ON(retval < 0))
228 goto func_exit;
229 retval = copy_from_user((void *) &params,
230 (const void __user *)(src_args.params),
231 sizeof(struct proc4430_params));
232 if (WARN_ON(retval < 0))
233 goto func_exit;
234 /* Copy the contents of mem_entries from user-side */
235 if (params.num_mem_entries) {
236 entries = vmalloc(params.num_mem_entries * \
237 sizeof(struct proc4430_mem_entry));
238 if (WARN_ON(!entries))
239 goto func_exit;
240 retval = copy_from_user((void *) (entries),
241 (const void __user *)(params.mem_entries),
242 params.num_mem_entries * \
243 sizeof(struct proc4430_mem_entry));
244 if (WARN_ON(retval < 0)) {
245 vfree(entries);
246 goto func_exit;
247 }
248 params.mem_entries = entries;
249 }
250 src_args.handle = proc4430_create(src_args.proc_id,
251 &params);
252 if (WARN_ON(src_args.handle == NULL))
253 goto func_exit;
254 retval = copy_to_user((void __user *)(args),
255 (const void *)&src_args,
256 sizeof(struct proc4430_cmd_args_create));
257 /* Free the memory created */
258 if (params.num_mem_entries)
259 vfree(entries);
260 }
261 break;
262
263 case CMD_PROC4430_DELETE:
264 {
265 struct proc4430_cmd_args_delete src_args;
266
267 /* Copy the full args from user-side. */
268 retval = copy_from_user((void *)&src_args,
269 (const void __user *)(args),
270 sizeof(struct proc4430_cmd_args_delete));
271 if (WARN_ON(retval < 0))
272 goto func_exit;
273 retval = proc4430_delete(&(src_args.handle));
274 WARN_ON(retval < 0);
275 }
276 break;
277
278 case CMD_PROC4430_OPEN:
279 {
280 struct proc4430_cmd_args_open src_args;
281
282 /*Copy the full args from user-side. */
283 retval = copy_from_user((void *)&src_args,
284 (const void __user *)(args),
285 sizeof(struct proc4430_cmd_args_open));
286 if (WARN_ON(retval < 0))
287 goto func_exit;
288 retval = proc4430_open(&(src_args.handle),
289 src_args.proc_id);
290 retval = copy_to_user((void __user *)(args),
291 (const void *)&src_args,
292 sizeof(struct proc4430_cmd_args_open));
293 WARN_ON(retval < 0);
294 }
295 break;
296
297 case CMD_PROC4430_CLOSE:
298 {
299 struct proc4430_cmd_args_close src_args;
300
301 /*Copy the full args from user-side. */
302 retval = copy_from_user((void *)&src_args,
303 (const void __user *)(args),
304 sizeof(struct proc4430_cmd_args_close));
305 if (WARN_ON(retval < 0))
306 goto func_exit;
307 retval = proc4430_close(src_args.handle);
308 WARN_ON(retval < 0);
309 }
310 break;
311
312 default:
313 {
314 printk(KERN_ERR "unsupported ioctl\n");
315 }
316 break;
317 }
318func_exit:
319 /* Set the status and copy the common args to user-side. */
320 command_args.api_status = retval;
321 retval = copy_to_user((void __user *) cmd_args,
322 (const void *) &command_args,
323 sizeof(struct proc_mgr_cmd_args));
324 WARN_ON(retval < 0);
325 return retval;
326}
327
328
329/*
330 Linux driver function to map memory regions to user space.
331 *
332 */
333static int proc4430_drv_mmap(struct file *filp, struct vm_area_struct *vma)
334{
335 vma->vm_page_prot = pgprot_dmacoherent(vma->vm_page_prot);
336
337 if (remap_pfn_range(vma,
338 vma->vm_start,
339 vma->vm_pgoff,
340 vma->vm_end - vma->vm_start,
341 vma->vm_page_prot)) {
342 return -EAGAIN;
343 }
344 return 0;
345}
346
347
348/** ==================================================================
349 * Functions required for multiple .ko modules configuration
350 * ==================================================================
351 */
352/*
353 Module initialization function for Linux driver.
354 */
355static int __init proc4430_drv_initializeModule(void)
356{
357 dev_t dev = 0 ;
358 int retval;
359
360 /* Display the version info and created date/time */
361 printk(KERN_INFO "proc4430_drv_initializeModule\n");
362
363 if (driver_major) {
364 dev = MKDEV(driver_major, driver_minor);
365 retval = register_chrdev_region(dev, 1, driver_name);
366 } else {
367 retval = alloc_chrdev_region(&dev, driver_minor, 1,
368 driver_name);
369 driver_major = MAJOR(dev);
370 }
371
372 proc_4430_device = kmalloc(sizeof(struct proc_4430_dev), GFP_KERNEL);
373 if (!proc_4430_device) {
374 retval = -ENOMEM;
375 unregister_chrdev_region(dev, 1);
376 goto exit;
377 }
378 memset(proc_4430_device, 0, sizeof(struct proc_4430_dev));
379 cdev_init(&proc_4430_device->cdev, &proc_4430_fops);
380 proc_4430_device->cdev.owner = THIS_MODULE;
381 proc_4430_device->cdev.ops = &proc_4430_fops;
382
383 retval = cdev_add(&proc_4430_device->cdev, dev, 1);
384
385 if (retval) {
386 printk(KERN_ERR "Failed to add the syslink proc_4430 device\n");
387 goto exit;
388 }
389
390 /* udev support */
391 proc_4430_class = class_create(THIS_MODULE, "syslink-proc4430");
392
393 if (IS_ERR(proc_4430_class)) {
394 printk(KERN_ERR "Error creating bridge class\n");
395 goto exit;
396 }
397 device_create(proc_4430_class, NULL, MKDEV(driver_major, driver_minor),
398 NULL, PROC4430_NAME);
399exit:
400 return 0;
401}
402
403/*
404 function to finalize the driver module.
405 */
406static void __exit proc4430_drv_finalizeModule(void)
407{
408 dev_t devno = 0;
409
410 /* FIX ME: THIS MIGHT NOT BE THE RIGHT PLACE TO CALL THE SETUP */
411 proc4430_destroy();
412
413 devno = MKDEV(driver_major, driver_minor);
414 if (proc_4430_device) {
415 cdev_del(&proc_4430_device->cdev);
416 kfree(proc_4430_device);
417 }
418 unregister_chrdev_region(devno, 1);
419 if (proc_4430_class) {
420 /* remove the device from sysfs */
421 device_destroy(proc_4430_class, MKDEV(driver_major,
422 driver_minor));
423 class_destroy(proc_4430_class);
424 }
425 return;
426}
427
428/*
429 Macro calls that indicate initialization and finalization functions
430 * to the kernel.
431 */
432MODULE_LICENSE("GPL v2");
433module_init(proc4430_drv_initializeModule);
434module_exit(proc4430_drv_finalizeModule);
diff --git a/drivers/dsp/syslink/procmgr/proc4430/proc4430_drvdefs.h b/drivers/dsp/syslink/procmgr/proc4430/proc4430_drvdefs.h
new file mode 100644
index 00000000000..4176d731f1d
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/proc4430/proc4430_drvdefs.h
@@ -0,0 +1,169 @@
1/*
2 * proc4430_drvdefs.h
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17
18#ifndef _SYSLINK_PROC4430_H
19#define _SYSLINK_PROC4430_H
20
21
22/* Module headers */
23#include "../procmgr_drvdefs.h"
24#include "proc4430.h"
25
26
27/* ----------------------------------------------------------------------------
28 * IOCTL command IDs for OMAP4430PROC
29 * ----------------------------------------------------------------------------
30 */
31/*
32 * Base command ID for OMAP4430PROC
33 */
34#define PROC4430_BASE_CMD 0x200
35
36/*
37 * Command for PROC4430_getConfig
38 */
39#define CMD_PROC4430_GETCONFIG (PROC4430_BASE_CMD + 1)
40
41/*
42 * Command for PROC4430_setup
43 */
44#define CMD_PROC4430_SETUP (PROC4430_BASE_CMD + 2)
45
46/*
47 * Command for PROC4430_setup
48 */
49#define CMD_PROC4430_DESTROY (PROC4430_BASE_CMD + 3)
50
51/*
52 * Command for PROC4430_destroy
53 */
54#define CMD_PROC4430_PARAMS_INIT (PROC4430_BASE_CMD + 4)
55
56/*
57 * Command for PROC4430_create
58 */
59#define CMD_PROC4430_CREATE (PROC4430_BASE_CMD + 5)
60
61/*
62 * Command for PROC4430_delete
63 */
64#define CMD_PROC4430_DELETE (PROC4430_BASE_CMD + 6)
65
66/*
67 * Command for PROC4430_open
68 */
69#define CMD_PROC4430_OPEN (PROC4430_BASE_CMD + 7)
70
71/*
72 * Command for PROC4430_close
73 */
74#define CMD_PROC4430_CLOSE (PROC4430_BASE_CMD + 8)
75
76
77/* ---------------------------------------------------
78 * Command arguments for OMAP4430PROC
79 * ---------------------------------------------------
80 */
81/*
82 * Command arguments for PROC4430_getConfig
83 */
84struct proc4430_cmd_args_get_config {
85 struct proc_mgr_cmd_args command_args;
86 /* Common command args */
87 struct proc4430_config *cfg;
88 /* Pointer to the OMAP4430PROC module configuration structure
89 * in which the default config is to be returned. */
90};
91
92/*
93 * Command arguments for PROC4430_setup
94 */
95struct proc4430_cmd_args_setup {
96 struct proc_mgr_cmd_args command_args;
97 /* Common command args */
98 struct proc4430_config *cfg;
99 /* Optional OMAP4430PROC module configuration. If provided as NULL,
100 * default configuration is used. */
101};
102
103/*
104 * Command arguments for PROC4430_destroy
105 */
106struct proc4430_cmd_args_destroy {
107 struct proc_mgr_cmd_args command_args;
108 /* Common command args */
109};
110
111/*
112 * Command arguments for struct struct proc4430_params_init
113 */
114struct proc4430_cmd_args_params_init {
115 struct proc_mgr_cmd_args command_args;
116 /* Common command args */
117 void *handle;
118 /* void * to the processor instance. */
119 struct proc4430_params *params;
120 /* Configuration parameters. */
121};
122
123/*
124 * Command arguments for PROC4430_create
125 */
126struct proc4430_cmd_args_create {
127 struct proc_mgr_cmd_args command_args;
128 /* Common command args */
129 u16 proc_id;
130 /* Processor ID for which this processor instance is required. */
131 struct proc4430_params *params;
132 /*Configuration parameters. */
133 void *handle;
134 /* void * to the created processor instance. */
135};
136
137/*
138 * Command arguments for PROC4430_delete
139 */
140struct proc4430_cmd_args_delete {
141 struct proc_mgr_cmd_args command_args;
142 /* Common command args */
143 void *handle;
144 /* Pointer to handle to the processor instance */
145};
146
147/*
148 * Command arguments for PROC4430_open
149 */
150struct proc4430_cmd_args_open {
151 struct proc_mgr_cmd_args command_args;
152 /* Common command args */
153 u16 proc_id;
154 /* Processor ID addressed by this OMAP4430PROC instance. */
155 void *handle;
156 /* Return parameter: void * to the processor instance */
157};
158
159/*
160 * Command arguments for PROC4430_close
161 */
162struct proc4430_cmd_args_close {
163 struct proc_mgr_cmd_args command_args;
164 /* Common command args */
165 void *handle;
166 /* void * to the processor instance */
167};
168
169#endif
diff --git a/drivers/dsp/syslink/procmgr/procdefs.h b/drivers/dsp/syslink/procmgr/procdefs.h
new file mode 100644
index 00000000000..d28025835aa
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/procdefs.h
@@ -0,0 +1,155 @@
1/*
2 * procdefs.h
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#ifndef SYSLINK_PROCDEFS_H
18#define SYSLINK_PROCDEFS_H
19
20#include <linux/types.h>
21
22/* Module level headers */
23#include <procmgr.h>
24
25
26/* =============================
27 * Macros and types
28 * =============================
29 */
30/*
31 * Enumerates the types of Endianism of slave processor.
32 */
33enum processor_endian{
34 PROCESSOR_ENDIAN_DEFAULT = 0,
35 /* Default endianism (no conversion required) */
36 PROCESSOR_ENDIAN_BIG = 1,
37 /* Big endian */
38 PROCESSOR_ENDIAN_LITTLE = 2,
39 /* Little endian */
40 PROCESSOR_ENDIAN_ENDVALUE = 3
41 /* End delimiter indicating start of invalid values for this enum */
42};
43
44
45/*
46 * Configuration parameters for attaching to the slave Processor
47 */
48struct processor_attach_params {
49 struct proc_mgr_attach_params *params;
50 /* Common attach parameters for ProcMgr */
51 u16 num_mem_entries;
52 /* Number of valid memory entries */
53 struct proc_mgr_addr_info mem_entries[PROCMGR_MAX_MEMORY_REGIONS];
54 /* Configuration of memory regions */
55};
56
57/*
58 * Function pointer type for the function to attach to the processor.
59 */
60typedef int (*processor_attach_fxn) (void *handle,
61 struct processor_attach_params *params);
62
63/*
64 * Function pointer type for the function to detach from the
65 * procssor
66 */
67typedef int (*processor_detach_fxn) (void *handle);
68
69/*
70 * Function pointer type for the function to read from the slave
71 * processor's memory.
72 */
73typedef int (*processor_read_fxn) (void *handle, u32 proc_addr,
74 u32 *num_bytes, void *buffer);
75
76/*
77 *Function pointer type for the function to write into the slave
78 *processor's memory.
79 */
80typedef int (*processor_write_fxn) (void *handle, u32 proc_addr,
81 u32 *num_bytes, void *buffer);
82
83/*
84 *Function pointer type for the function to perform device-dependent
85 * operations.
86 */
87typedef int (*processor_control_fxn) (void *handle, int cmd, void *arg);
88
89/*
90 *Function pointer type for the function to translate between
91 * two types of address spaces.
92 */
93typedef int (*processor_translate_addr_fxn) (void *handle, void **dst_addr,
94 enum proc_mgr_addr_type dstAddrType, void *srcAddr,
95 enum proc_mgr_addr_type srcAddrType);
96
97/*
98 *Function pointer type for the function that returns proc info
99 */
100typedef int (*processor_proc_info) (void *handle,
101 struct proc_mgr_proc_info *proc_info);
102
103/*
104 *Function pointer type for the function that returns proc info
105 */
106typedef int (*processor_virt_to_phys_fxn) (void *handle, u32 da,
107 u32 *mapped_entries, u32 num_of_entries);
108
109
110/* =============================
111 * Function table interface
112 * =============================
113 */
114/*
115 *Function table interface for Processor.
116 */
117struct processor_fxn_table {
118 processor_attach_fxn attach;
119 /* Function to attach to the slave processor */
120 processor_detach_fxn detach;
121 /* Function to detach from the slave processor */
122 processor_read_fxn read;
123 /* Function to read from the slave processor's memory */
124 processor_write_fxn write;
125 /* Function to write into the slave processor's memory */
126 processor_control_fxn control;
127 /* Function to perform device-dependent control function */
128 processor_translate_addr_fxn translateAddr;
129 /* Function to translate between address ranges */
130 processor_proc_info procinfo;
131 /* Function to convert Virtual to Physical pages */
132 processor_virt_to_phys_fxn virt_to_phys;
133};
134
135/* =============================
136 * Processor structure
137 * =============================
138 */
139/*
140 * Generic Processor object. This object defines the handle type for all
141 * Processor operations.
142 */
143struct processor_object {
144 struct processor_fxn_table proc_fxn_table;
145 /* interface function table to plug into the generic Processor. */
146 enum proc_mgr_state state;
147 /* State of the slave processor */
148 enum proc_mgr_boot_mode boot_mode;
149 /* Boot mode for the slave processor. */
150 void *object;
151 /* Pointer to Processor-specific object. */
152 u16 proc_id;
153 /* Processor ID addressed by this Processor instance. */
154};
155#endif
diff --git a/drivers/dsp/syslink/procmgr/processor.c b/drivers/dsp/syslink/procmgr/processor.c
new file mode 100644
index 00000000000..34a2d252b3f
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/processor.c
@@ -0,0 +1,293 @@
1/*
2 * processor.c
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#include <linux/types.h>
18#include <linux/module.h>
19
20/* Module level headers */
21#include "procdefs.h"
22#include "processor.h"
23
24
25
26/* =========================================
27 * Functions called by ProcMgr
28 * =========================================
29 */
30/*
31 * Function to attach to the Processor.
32 *
33 * This function calls into the specific Processor implementation
34 * to attach to it.
35 * This function is called from the ProcMgr attach function, and
36 * hence is used to perform any activities that may be required
37 * once the slave is powered up.
38 * Depending on the type of Processor, this function may or may not
39 * perform any activities.
40 */
41inline int processor_attach(void *handle,
42 struct processor_attach_params *params)
43{
44 int retval = 0;
45 struct processor_object *proc_handle =
46 (struct processor_object *)handle;
47
48 BUG_ON(handle == NULL);
49 BUG_ON(params == NULL);
50 BUG_ON(proc_handle->proc_fxn_table.attach == NULL);
51
52 proc_handle->boot_mode = params->params->boot_mode;
53 retval = proc_handle->proc_fxn_table.attach(handle, params);
54
55 if (proc_handle->boot_mode == PROC_MGR_BOOTMODE_BOOT)
56 proc_handle->state = PROC_MGR_STATE_POWERED;
57 else if (proc_handle->boot_mode == PROC_MGR_BOOTMODE_NOLOAD)
58 proc_handle->state = PROC_MGR_STATE_LOADED;
59 else if (proc_handle->boot_mode == PROC_MGR_BOOTMODE_NOBOOT)
60 proc_handle->state = PROC_MGR_STATE_RUNNNING;
61 return retval;
62}
63
64
65/*
66 * Function to detach from the Processor.
67 *
68 * This function calls into the specific Processor implementation
69 * to detach from it.
70 * This function is called from the ProcMgr detach function, and
71 * hence is useful to perform any activities that may be required
72 * before the slave is powered down.
73 * Depending on the type of Processor, this function may or may not
74 * perform any activities.
75 */
76inline int processor_detach(void *handle)
77{
78 int retval = 0;
79 struct processor_object *proc_handle =
80 (struct processor_object *)handle;
81
82 BUG_ON(handle == NULL);
83 BUG_ON(proc_handle->proc_fxn_table.detach == NULL);
84
85 retval = proc_handle->proc_fxn_table.detach(handle);
86 /* For all boot modes, at the end of detach, the Processor is in
87 * unknown state.
88 */
89 proc_handle->state = PROC_MGR_STATE_UNKNOWN;
90 return retval;
91}
92
93
94/*
95 * Function to read from the slave processor's memory.
96 *
97 * This function calls into the specific Processor implementation
98 * to read from the slave processor's memory. It reads from the
99 * specified address in the processor's address space and copies
100 * the required number of bytes into the specified buffer.
101 * It returns the number of bytes actually read in the num_bytes
102 * parameter.
103 * Depending on the processor implementation, it may result in
104 * reading from shared memory or across a peripheral physical
105 * connectivity.
106 * The handle specifies the specific Processor instance to be used.
107 */
108inline int processor_read(void *handle, u32 proc_addr,
109 u32 *num_bytes, void *buffer)
110{
111 int retval = 0;
112 struct processor_object *proc_handle =
113 (struct processor_object *)handle;
114
115 BUG_ON(handle == NULL);
116 BUG_ON(proc_addr == 0);
117 BUG_ON(num_bytes == 0);
118 BUG_ON(buffer == NULL);
119 BUG_ON(proc_handle->proc_fxn_table.read == NULL);
120
121 retval = proc_handle->proc_fxn_table.read(handle, proc_addr,
122 num_bytes, buffer);
123 return retval;
124}
125
126
127/*
128 * Function to write into the slave processor's memory.
129 *
130 * This function calls into the specific Processor implementation
131 * to write into the slave processor's memory. It writes into the
132 * specified address in the processor's address space and copies
133 * the required number of bytes from the specified buffer.
134 * It returns the number of bytes actually written in the num_bytes
135 * parameter.
136 * Depending on the processor implementation, it may result in
137 * writing into shared memory or across a peripheral physical
138 * connectivity.
139 * The handle specifies the specific Processor instance to be used.
140 */
141inline int processor_write(void *handle, u32 proc_addr, u32 *num_bytes,
142 void *buffer)
143{
144 int retval = 0;
145 struct processor_object *proc_handle =
146 (struct processor_object *)handle;
147 BUG_ON(handle == NULL);
148 BUG_ON(proc_addr == 0);
149 BUG_ON(num_bytes == 0);
150 BUG_ON(buffer == NULL);
151 BUG_ON(proc_handle->proc_fxn_table.write == NULL);
152
153 retval = proc_handle->proc_fxn_table.write(handle, proc_addr,
154 num_bytes, buffer);
155 return retval;
156}
157
158
159/*
160 * Function to get the current state of the slave Processor.
161 *
162 * This function gets the state of the slave processor as
163 * maintained on the master Processor state machine. It does not
164 * go to the slave processor to get its actual state at the time
165 * when this API is called.
166 */
167enum proc_mgr_state processor_get_state(void *handle)
168{
169 struct processor_object *proc_handle =
170 (struct processor_object *)handle;
171
172 BUG_ON(handle == NULL);
173
174 return proc_handle->state;
175}
176
177
178/*
179 * Function to set the current state of the slave Processor
180 * to specified value.
181 *
182 * This function is used to set the state of the processor to the
183 * value as specified. This function may be used by external
184 * entities that affect the state of the slave processor, such as
185 * PwrMgr, error handler, or ProcMgr.
186 */
187void processor_set_state(void *handle, enum proc_mgr_state state)
188{
189 struct processor_object *proc_handle =
190 (struct processor_object *)handle;
191
192 BUG_ON(handle == NULL);
193 proc_handle->state = state;
194}
195
196
197/*
198 * Function to perform device-dependent operations.
199 *
200 * This function calls into the specific Processor implementation
201 * to perform device dependent control operations. The control
202 * operations supported by the device are exposed directly by the
203 * specific implementation of the Processor interface. These
204 * commands and their specific argument types are used with this
205 * function.
206 */
207inline int processor_control(void *handle, int cmd, void *arg)
208{
209 int retval = 0;
210 struct processor_object *proc_handle =
211 (struct processor_object *)handle;
212
213 BUG_ON(handle == NULL);
214 BUG_ON(proc_handle->proc_fxn_table.control == NULL);
215
216 retval = proc_handle->proc_fxn_table.control(handle, cmd, arg);
217 return retval;
218}
219
220
221/*
222 * Function to translate between two types of address spaces.
223 *
224 * This function translates addresses between two types of address
225 * spaces. The destination and source address types are indicated
226 * through parameters specified in this function.
227 */
228inline int processor_translate_addr(void *handle, void **dst_addr,
229 enum proc_mgr_addr_type dst_addr_type, void *src_addr,
230 enum proc_mgr_addr_type src_addr_type)
231{
232 int retval = 0;
233 struct processor_object *proc_handle =
234 (struct processor_object *)handle;
235
236 BUG_ON(handle == NULL);
237 BUG_ON(dst_addr == NULL);
238 BUG_ON(src_addr == NULL);
239 BUG_ON(dst_addr_type >= PROC_MGR_ADDRTYPE_ENDVALUE);
240 BUG_ON(src_addr_type >= PROC_MGR_ADDRTYPE_ENDVALUE);
241 BUG_ON(proc_handle->proc_fxn_table.translateAddr == NULL);
242
243 retval = proc_handle->proc_fxn_table.translateAddr(handle,
244 dst_addr, dst_addr_type, src_addr, src_addr_type);
245 return retval;
246}
247
248
249/*
250 * Function that registers for notification when the slave
251 * processor transitions to any of the states specified.
252 *
253 * This function allows the user application to register for
254 * changes in processor state and take actions accordingly.
255
256 */
257inline int processor_register_notify(void *handle, proc_mgr_callback_fxn fxn,
258 void *args, enum proc_mgr_state state[])
259{
260 int retval = 0;
261
262 BUG_ON(handle == NULL);
263 BUG_ON(fxn == NULL);
264
265 /* TODO: TBD: To be implemented. */
266 return retval;
267}
268
269/*
270 * Function that returns the proc instance mem info
271 */
272int processor_get_proc_info(void *handle, struct proc_mgr_proc_info *procinfo)
273{
274 struct processor_object *proc_handle =
275 (struct processor_object *)handle;
276 int retval;
277 retval = proc_handle->proc_fxn_table.procinfo(proc_handle, procinfo);
278 return retval;
279}
280
281/*
282 * Function that returns the address translations
283 */
284int processor_virt_to_phys(void *handle, u32 da, u32 *mapped_entries,
285 u32 num_of_entries)
286{
287 struct processor_object *proc_handle =
288 (struct processor_object *)handle;
289 int retval;
290 retval = proc_handle->proc_fxn_table.virt_to_phys(handle, da,
291 mapped_entries, num_of_entries);
292 return retval;
293}
diff --git a/drivers/dsp/syslink/procmgr/processor.h b/drivers/dsp/syslink/procmgr/processor.h
new file mode 100644
index 00000000000..13942e91e84
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/processor.h
@@ -0,0 +1,70 @@
1/*
2 * processor.h
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#ifndef SYSLINK_PROCESSOR_H_
18#define SYSLINK_PROCESSOR_H_
19
20#include <linux/types.h>
21
22/* Module level headers */
23#include "procdefs.h"
24
25/* ===================================
26 * APIs
27 * ===================================
28 */
29/* Function to attach to the Processor. */
30int processor_attach(void *handle, struct processor_attach_params *params);
31
32/* Function to detach from the Processor. */
33int processor_detach(void *handle);
34
35/* Function to read from the slave processor's memory. */
36int processor_read(void *handle, u32 proc_addr, u32 *num_bytes, void *buffer);
37
38/* Function to read write into the slave processor's memory. */
39int processor_write(void *handle, u32 proc_addr, u32 *num_bytes, void *buffer);
40
41/* Function to get the current state of the slave Processor as maintained on
42 * the master Processor state machine.
43 */
44enum proc_mgr_state processor_get_state(void *handle);
45
46/* Function to set the current state of the slave Processor to specified value.
47 */
48void processor_set_state(void *handle, enum proc_mgr_state state);
49
50/* Function to perform device-dependent operations. */
51int processor_control(void *handle, int cmd, void *arg);
52
53/* Function to translate between two types of address spaces. */
54int processor_translate_addr(void *handle, void **dst_addr,
55 enum proc_mgr_addr_type dst_addr_type, void *src_addr,
56 enum proc_mgr_addr_type src_addr_type);
57
58/* Function that registers for notification when the slave processor
59 * transitions to any of the states specified.
60 */
61int processor_register_notify(void *handle, proc_mgr_callback_fxn fxn,
62 void *args, enum proc_mgr_state state[]);
63
64/* Function that returns the return value of specific processor info
65 */
66int processor_get_proc_info(void *handle, struct proc_mgr_proc_info *procinfo);
67
68int processor_virt_to_phys(void *handle, u32 da, u32 *mapped_entries,
69 u32 num_of_entries);
70#endif
diff --git a/drivers/dsp/syslink/procmgr/procmgr.c b/drivers/dsp/syslink/procmgr/procmgr.c
new file mode 100644
index 00000000000..b0ce1d1dc3d
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/procmgr.c
@@ -0,0 +1,790 @@
1/*
2 * procmgr.c
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17#include <linux/types.h>
18#include <linux/module.h>
19#include <linux/mutex.h>
20#include <linux/vmalloc.h>
21#include <linux/slab.h>
22#include <asm/atomic.h>
23
24/* Module level headers */
25#include <procmgr.h>
26#include "procdefs.h"
27#include "processor.h"
28#include <syslink/atomic_linux.h>
29
30/* ================================
31 * Macros and types
32 * ================================
33 */
34/*! @brief Macro to make a correct module magic number with refCount */
35#define PROCMGR_MAKE_MAGICSTAMP(x) ((PROCMGR_MODULEID << 12u) | (x))
36
37/*
38 * ProcMgr Module state object
39 */
40struct proc_mgr_module_object {
41 atomic_t ref_count;
42 u32 config_size;
43 /* Size of configuration structure */
44 struct proc_mgr_config cfg;
45 /* ProcMgr configuration structure */
46 struct proc_mgr_config def_cfg;
47 /* Default module configuration */
48 struct proc_mgr_params def_inst_params;
49 /* Default parameters for the ProcMgr instances */
50 struct proc_mgr_attach_params def_attach_params;
51 /* Default parameters for the ProcMgr attach function */
52 struct mutex *gate_handle;
53 /* handle of gate to be used for local thread safety */
54 void *proc_handles[MULTIPROC_MAXPROCESSORS];
55 /* Array of handles of ProcMgr instances */
56};
57
58/*
59 * ProcMgr instance object
60 */
61struct proc_mgr_object {
62 u16 proc_id;
63 /* Processor ID associated with this ProcMgr. */
64 struct processor_object *proc_handle;
65 /* Processor ID of the processor being represented by this instance. */
66 void *loader_handle;
67 /*!< Handle to the Loader object associated with this ProcMgr. */
68 void *pwr_handle;
69 /*!< Handle to the PwrMgr object associated with this ProcMgr. */
70 /*!< Processor ID of the processor being represented by this instance */
71 struct proc_mgr_params params;
72 /* ProcMgr instance params structure */
73 struct proc_mgr_attach_params attach_params;
74 /* ProcMgr attach params structure */
75 u32 file_id;
76 /*!< File ID of the loaded static executable */
77 u16 num_mem_entries;
78 /* Number of valid memory entries */
79 struct proc_mgr_addr_info mem_entries[PROCMGR_MAX_MEMORY_REGIONS];
80 /* Configuration of memory regions */
81};
82
83static struct proc_mgr_module_object proc_mgr_obj_state = {
84 .config_size = sizeof(struct proc_mgr_config),
85 .def_cfg.gate_handle = NULL,
86 .gate_handle = NULL,
87 .def_inst_params.proc_handle = NULL,
88 .def_attach_params.boot_mode = PROC_MGR_BOOTMODE_BOOT,
89};
90
91
92/*======================================
93 * Function to get the default configuration for the ProcMgr
94 * module.
95 *
96* This function can be called by the application to get their
97* configuration parameter to ProcMgr_setup filled in by the
98* ProcMgr module with the default parameters. If the user does
99* not wish to make any change in the default parameters, this API
100* is not required to be called.
101 */
102void proc_mgr_get_config(struct proc_mgr_config *cfg)
103{
104 BUG_ON(cfg == NULL);
105 memcpy(cfg, &proc_mgr_obj_state.def_cfg,
106 sizeof(struct proc_mgr_config));
107 return;
108}
109EXPORT_SYMBOL(proc_mgr_get_config);
110
111/*
112 * Function to setup the ProcMgr module.
113 *
114 *This function sets up the ProcMgr module. This function must
115 *be called before any other instance-level APIs can be invoked.
116 *Module-level configuration needs to be provided to this
117 *function. If the user wishes to change some specific config
118 *parameters, then ProcMgr_getConfig can be called to get the
119 *configuration filled with the default values. After this, only
120 *the required configuration values can be changed. If the user
121 *does not wish to make any change in the default parameters, the
122 *application can simply call ProcMgr_setup with NULL parameters.
123 *The default parameters would get automatically used.
124 */
125int proc_mgr_setup(struct proc_mgr_config *cfg)
126{
127 int retval = 0;
128 struct proc_mgr_config tmp_cfg;
129
130 /* This sets the refCount variable is not initialized, upper 16 bits is
131 * written with module Id to ensure correctness of refCount variable.
132 */
133 atomic_cmpmask_and_set(&proc_mgr_obj_state.ref_count,
134 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(0));
135
136 if (atomic_inc_return(&proc_mgr_obj_state.ref_count)
137 != PROCMGR_MAKE_MAGICSTAMP(1u))
138 return 0;
139 if (cfg == NULL) {
140 proc_mgr_get_config(&tmp_cfg);
141 cfg = &tmp_cfg;
142 }
143 if (cfg->gate_handle != NULL) {
144 proc_mgr_obj_state.gate_handle = cfg->gate_handle;
145 } else {
146 /* User has not provided any gate handle, so create a
147 *default handle.
148 */
149 proc_mgr_obj_state.gate_handle = kmalloc(sizeof(struct mutex),
150 GFP_KERNEL);
151 mutex_init(proc_mgr_obj_state.gate_handle);
152 }
153 memcpy(&proc_mgr_obj_state.cfg, cfg, sizeof(struct proc_mgr_config));
154 /* Initialize the procHandles array. */
155 memset(&proc_mgr_obj_state.proc_handles, 0,
156 (sizeof(void *) * MULTIPROC_MAXPROCESSORS));
157 return retval;
158}
159EXPORT_SYMBOL(proc_mgr_setup);
160
161/*==================================
162 * Function to destroy the ProcMgr module.
163 *
164 * Once this function is called, other ProcMgr module APIs, except
165 * for the proc_mgr_get_config API cannot be called anymore.
166 */
167int proc_mgr_destroy(void)
168{
169 int retval = 0;
170 int i;
171
172 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
173 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
174 == true) {
175 printk(KERN_ERR "proc_mgr_destroy: Error - module not initialized\n");
176 return -EFAULT;
177 }
178 if (atomic_dec_return(&proc_mgr_obj_state.ref_count)
179 == PROCMGR_MAKE_MAGICSTAMP(0)) {
180
181 /* Check if any ProcMgr instances have not been deleted so far
182 *. If not,delete them
183 */
184 for (i = 0 ; i < MULTIPROC_MAXPROCESSORS; i++) {
185 if (proc_mgr_obj_state.proc_handles[i] != NULL)
186 proc_mgr_delete
187 (&(proc_mgr_obj_state.proc_handles[i]));
188 }
189
190 mutex_destroy(proc_mgr_obj_state.gate_handle);
191 kfree(proc_mgr_obj_state.gate_handle);
192 /* Decrease the refCount */
193 atomic_set(&proc_mgr_obj_state.ref_count,
194 PROCMGR_MAKE_MAGICSTAMP(0));
195 }
196 return retval;;
197}
198EXPORT_SYMBOL(proc_mgr_destroy);
199
200/*=====================================
201 * Function to initialize the parameters for the ProcMgr instance.
202 *
203 * This function can be called by the application to get their
204 * configuration parameter to ProcMgr_create filled in by the
205 * ProcMgr module with the default parameters.
206 */
207void proc_mgr_params_init(void *handle, struct proc_mgr_params *params)
208{
209 struct proc_mgr_object *proc_handle = (struct proc_mgr_object *)handle;
210
211 if (WARN_ON(params == NULL))
212 goto exit;
213 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
214 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
215 == true) {
216 printk(KERN_ERR "proc_mgr_params_init: Error - module not initialized\n");
217 }
218 if (handle == NULL) {
219 memcpy(params, &(proc_mgr_obj_state.def_inst_params),
220 sizeof(struct proc_mgr_params));
221 } else {
222 /* Return updated ProcMgr instance specific parameters. */
223 memcpy(params, &(proc_handle->params),
224 sizeof(struct proc_mgr_params));
225 }
226exit:
227 return;
228}
229EXPORT_SYMBOL(proc_mgr_params_init);
230
231/*=====================================
232 * Function to create a ProcMgr object for a specific slave
233 * processor.
234 *
235 * This function creates an instance of the ProcMgr module and
236 * returns an instance handle, which is used to access the
237 * specified slave processor. The processor ID specified here is
238 * the ID of the slave processor as configured with the MultiProc
239 * module.
240 * Instance-level configuration needs to be provided to this
241 * function. If the user wishes to change some specific config
242 * parameters, then struct proc_mgr_params_init can be called to get the
243 * configuration filled with the default values. After this, only
244 * the required configuration values can be changed. For this
245 * API, the params argument is not optional, since the user needs
246 * to provide some essential values such as loader, PwrMgr and
247 * Processor instances to be used with this ProcMgr instance.
248 */
249void *proc_mgr_create(u16 proc_id, const struct proc_mgr_params *params)
250{
251 struct proc_mgr_object *handle = NULL;
252
253 BUG_ON(!IS_VALID_PROCID(proc_id));
254 BUG_ON(params == NULL);
255 BUG_ON(params->proc_handle == NULL);
256 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
257 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
258 == true) {
259 printk(KERN_ERR "proc_mgr_create: Error - module not initialized\n");
260 return NULL;
261 }
262 if (proc_mgr_obj_state.proc_handles[proc_id] != NULL) {
263 handle = proc_mgr_obj_state.proc_handles[proc_id];
264 printk(KERN_WARNING "proc_mgr_create:"
265 "Processor already exists for specified"
266 "%d proc_id, handle = 0x%x\n", proc_id, (u32)handle);
267 return handle;
268 }
269 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
270 handle = (struct proc_mgr_object *)
271 vmalloc(sizeof(struct proc_mgr_object));
272 BUG_ON(handle == NULL);
273 memset(handle, 0, sizeof(struct proc_mgr_object));
274 memcpy(&(handle->params), params, sizeof(struct proc_mgr_params));
275 handle->proc_id = proc_id;
276 handle->proc_handle = params->proc_handle;
277 handle->loader_handle = params->loader_handle;
278 handle->pwr_handle = params->pwr_handle;
279 proc_mgr_obj_state.proc_handles[proc_id] = handle;
280 mutex_unlock(proc_mgr_obj_state.gate_handle);
281 return handle;
282}
283EXPORT_SYMBOL(proc_mgr_create);
284
285/*===================================
286 * Function to delete a ProcMgr object for a specific slave
287 * processor.
288 *
289 * Once this function is called, other ProcMgr instance level APIs
290 * that require the instance handle cannot be called.
291 *
292 */
293int
294proc_mgr_delete(void **handle_ptr)
295{
296 int retval = 0;
297 struct proc_mgr_object *handle;
298
299 BUG_ON(handle_ptr == NULL);
300 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
301 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
302 == true) {
303 printk(KERN_ERR "proc_mgr_delete: Error - module not initialized\n");
304 return -EFAULT;
305 }
306
307 handle = (struct proc_mgr_object *)(*handle_ptr);
308 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
309 proc_mgr_obj_state.proc_handles[handle->proc_id] = NULL;
310 vfree(handle);
311 *handle_ptr = NULL;
312 mutex_unlock(proc_mgr_obj_state.gate_handle);
313 return retval;
314}
315EXPORT_SYMBOL(proc_mgr_delete);
316
317/*======================================
318 * Function to open a handle to an existing ProcMgr object handling
319 * the proc_id.
320 *
321 * This function returns a handle to an existing ProcMgr instance
322 * created for this proc_id. It enables other entities to access
323 * and use this ProcMgr instance.
324 */
325int proc_mgr_open(void **handle_ptr, u16 proc_id)
326{
327 int retval = 0;
328
329 BUG_ON(handle_ptr == NULL);
330 BUG_ON(!IS_VALID_PROCID(proc_id));
331 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
332 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
333 == true) {
334 printk(KERN_ERR "proc_mgr_open: Error - module not initialized\n");
335 return -EFAULT;
336 }
337
338 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
339 *handle_ptr = proc_mgr_obj_state.proc_handles[proc_id];
340 mutex_unlock(proc_mgr_obj_state.gate_handle);
341 return retval;
342}
343EXPORT_SYMBOL(proc_mgr_open);
344
345/*=====================================
346 * Function to close this handle to the ProcMgr instance.
347 *
348 * This function closes the handle to the ProcMgr instance
349 * obtained through proc_mgr_open call made earlier.
350 */
351int proc_mgr_close(void *handle)
352{
353 int retval = 0;
354
355 BUG_ON(handle == NULL);
356 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
357 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
358 == true) {
359 printk(KERN_ERR "proc_mgr_close: Error - module not initialized\n");
360 return -EFAULT;
361 }
362 /* Nothing to be done for closing the handle. */
363 return retval;
364}
365EXPORT_SYMBOL(proc_mgr_close);
366
367/*========================================
368 * Function to initialize the parameters for the ProcMgr attach
369 * function.
370 *
371 * This function can be called by the application to get their
372 * configuration parameter to proc_mgr_attach filled in by the
373 * ProcMgr module with the default parameters. If the user does
374 * not wish to make any change in the default parameters, this API
375 * is not required to be called.
376 */
377void proc_mgr_get_attach_params(void *handle,
378 struct proc_mgr_attach_params *params)
379{
380 struct proc_mgr_object *proc_mgr_handle =
381 (struct proc_mgr_object *)handle;
382 BUG_ON(params == NULL);
383 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
384 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
385 == true) {
386 printk(KERN_ERR "proc_mgr_get_attach_params:"
387 "Error - module not initialized\n");
388 }
389 if (handle == NULL) {
390 memcpy(params, &(proc_mgr_obj_state.def_attach_params),
391 sizeof(struct proc_mgr_attach_params));
392 } else {
393 /* Return updated ProcMgr instance specific parameters. */
394 memcpy(params, &(proc_mgr_handle->attach_params),
395 sizeof(struct proc_mgr_attach_params));
396 }
397 return;
398}
399EXPORT_SYMBOL(proc_mgr_get_attach_params);
400
401/*
402 * Function to attach the client to the specified slave and also
403 * initialize the slave (if required).
404 *
405 * This function attaches to an instance of the ProcMgr module and
406 * performs any hardware initialization required to power up the
407 * slave device. This function also performs the required state
408 * transitions for this ProcMgr instance to ensure that the local
409 * object representing the slave device correctly indicates the
410 * state of the slave device. Depending on the slave boot mode
411 * being used, the slave may be powered up, in reset, or even
412 * running state.
413 * Configuration parameters need to be provided to this
414 * function. If the user wishes to change some specific config
415 * parameters, then proc_mgr_get_attach_params can be called to get
416 * the configuration filled with the default values. After this,
417 * only the required configuration values can be changed. If the
418 * user does not wish to make any change in the default parameters,
419 * the application can simply call proc_mgr_attach with NULL
420 * parameters.
421 * The default parameters would get automatically used.
422 */
423int proc_mgr_attach(void *handle, struct proc_mgr_attach_params *params)
424{
425 int retval = 0;
426 struct proc_mgr_object *proc_mgr_handle =
427 (struct proc_mgr_object *)handle;
428 struct proc_mgr_attach_params tmp_params;
429 struct processor_attach_params proc_attach_params;
430
431 if (params == NULL) {
432 proc_mgr_get_attach_params(handle, &tmp_params);
433 params = &tmp_params;
434 }
435 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
436 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
437 == true) {
438 printk(KERN_ERR "proc_mgr_attach:"
439 "Error - module not initialized\n");
440 return -EFAULT;
441 }
442 if (WARN_ON(handle == NULL)) {
443 retval = -EFAULT;
444 goto exit;
445 }
446 if (WARN_ON(params->boot_mode == PROC_MGR_BOOTMODE_ENDVALUE)) {
447 retval = -EINVAL;
448 goto exit;
449 }
450 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
451 /* Copy the user provided values into the instance object. */
452 memcpy(&(proc_mgr_handle->attach_params), params,
453 sizeof(struct proc_mgr_attach_params));
454 proc_attach_params.params = params;
455 proc_attach_params.num_mem_entries = 0;
456 /* Attach to the specified Processor instance. */
457 retval = processor_attach(proc_mgr_handle->proc_handle,
458 &proc_attach_params);
459 proc_mgr_handle->num_mem_entries = proc_attach_params.num_mem_entries;
460 printk(KERN_INFO "proc_mgr_attach:proc_mgr_handle->num_mem_entries = %d\n",
461 proc_mgr_handle->num_mem_entries);
462 /* Store memory information in local object.*/
463 memcpy(&(proc_mgr_handle->mem_entries),
464 &(proc_attach_params.mem_entries),
465 sizeof(proc_mgr_handle->mem_entries));
466 mutex_unlock(proc_mgr_obj_state.gate_handle);
467exit:
468 return retval;
469}
470EXPORT_SYMBOL(proc_mgr_attach);
471
472/*===================================
473 * Function to detach the client from the specified slave and also
474 * finalze the slave (if required).
475 *
476 * This function detaches from an instance of the ProcMgr module
477 * and performs any hardware finalization required to power down
478 * the slave device. This function also performs the required state
479 * transitions for this ProcMgr instance to ensure that the local
480 * object representing the slave device correctly indicates the
481 * state of the slave device. Depending on the slave boot mode
482 * being used, the slave may be powered down, in reset, or left in
483 * its original state.
484*/
485int proc_mgr_detach(void *handle)
486{
487 int retval = 0;
488 struct proc_mgr_object *proc_mgr_handle =
489 (struct proc_mgr_object *)handle;
490 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
491 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
492 == true) {
493 printk(KERN_ERR "proc_mgr_detach:"
494 "Error - module not initialized\n");
495 return -EFAULT;
496 }
497 BUG_ON(handle == NULL);
498 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
499 /* Detach from the Processor. */
500 retval = processor_detach(proc_mgr_handle->proc_handle);
501 mutex_unlock(proc_mgr_obj_state.gate_handle);
502 return retval;
503}
504EXPORT_SYMBOL(proc_mgr_detach);
505
506/*===================================
507 * Function to get the current state of the slave Processor.
508 *
509 * This function gets the state of the slave processor as
510 * maintained on the master Processor state machine. It does not
511 * go to the slave processor to get its actual state at the time
512 * when this API is called.
513 *
514 */
515enum proc_mgr_state proc_mgr_get_state(void *handle)
516{
517 struct proc_mgr_object *proc_mgr_handle =
518 (struct proc_mgr_object *)handle;
519 enum proc_mgr_state state = PROC_MGR_STATE_UNKNOWN;
520 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
521 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
522 == true) {
523 printk(KERN_ERR "proc_mgr_get_state:"
524 "Error - module not initialized\n");
525 return -EFAULT;
526 }
527 BUG_ON(handle == NULL);
528
529 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
530 state = processor_get_state(proc_mgr_handle->proc_handle);
531 mutex_unlock(proc_mgr_obj_state.gate_handle);
532 return state;
533}
534EXPORT_SYMBOL(proc_mgr_get_state);
535
536/*==================================================
537 * Function to read from the slave processor's memory.
538 *
539 * This function reads from the specified address in the
540 * processor's address space and copies the required number of
541 * bytes into the specified buffer.
542 * It returns the number of bytes actually read in thenum_bytes
543 * parameter.
544 */
545int proc_mgr_read(void *handle, u32 proc_addr, u32 *num_bytes, void *buffer)
546{
547 int retval = 0;
548 struct proc_mgr_object *proc_mgr_handle =
549 (struct proc_mgr_object *)handle;
550 void *addr;
551
552 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
553 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
554 == true) {
555 printk(KERN_ERR "proc_mgr_read:"
556 "Error - module not initialized\n");
557 return -EFAULT;
558 }
559 BUG_ON(handle == NULL);
560 BUG_ON(proc_addr == 0);
561 BUG_ON(num_bytes == NULL);
562 BUG_ON(buffer == NULL);
563
564 /* Check if the address is already mapped */
565 retval = proc_mgr_translate_addr(handle,
566 (void **) &addr,
567 PROC_MGR_ADDRTYPE_MASTERKNLVIRT,
568 (void *) proc_addr,
569 PROC_MGR_ADDRTYPE_SLAVEVIRT);
570
571
572 if (retval >= 0) {
573 /* Enter critical section protection. */
574 WARN_ON(mutex_lock_interruptible(
575 proc_mgr_obj_state.gate_handle));
576
577 retval = processor_read(proc_mgr_handle->proc_handle, (u32)addr,
578 num_bytes, buffer);
579
580 /* Leave critical section protection. */
581 mutex_unlock(proc_mgr_obj_state.gate_handle);
582 }
583
584 WARN_ON(retval < 0);
585 return retval;
586}
587EXPORT_SYMBOL(proc_mgr_read);
588
589/*
590 * Function to write into the slave processor's memory.
591 *
592 * This function writes into the specified address in the
593 * processor's address space and copies the required number of
594 * bytes from the specified buffer.
595 * It returns the number of bytes actually written in thenum_bytes
596 * parameter.
597 */
598int proc_mgr_write(void *handle, u32 proc_addr, u32 *num_bytes, void *buffer)
599{
600 int retval = 0;
601 struct proc_mgr_object *proc_mgr_handle =
602 (struct proc_mgr_object *)handle;
603 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
604 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
605 == true) {
606 printk(KERN_ERR "proc_mgr_write:"
607 "Error - module not initialized\n");
608 return -EFAULT;
609 }
610 BUG_ON(proc_addr == 0);
611 BUG_ON(num_bytes == NULL);
612 BUG_ON(buffer == NULL);
613
614 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
615 retval = processor_write(proc_mgr_handle->proc_handle, proc_addr,
616 num_bytes, buffer);
617 WARN_ON(retval < 0);
618 mutex_unlock(proc_mgr_obj_state.gate_handle);
619 return retval;;
620}
621EXPORT_SYMBOL(proc_mgr_write);
622
623
624/*===================================
625 * Function to perform device-dependent operations.
626 *
627 * This function performs control operations supported by the
628 * as exposed directly by the specific implementation of the
629 * Processor interface. These commands and their specific argument
630 * types are used with this function.
631 */
632int proc_mgr_control(void *handle, int cmd, void *arg)
633{
634 int retval = 0;
635 struct proc_mgr_object *proc_mgr_handle
636 = (struct proc_mgr_object *)handle;
637 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
638 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
639 == true) {
640 printk(KERN_ERR "proc_mgr_control:"
641 "Error - module not initialized\n");
642 return -EFAULT;
643 }
644 BUG_ON(handle == NULL);
645 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
646 /* Perform device-dependent control operation. */
647 retval = processor_control(proc_mgr_handle->proc_handle, cmd, arg);
648 WARN_ON(retval < 0);
649 mutex_unlock(proc_mgr_obj_state.gate_handle);
650 return retval;;
651}
652EXPORT_SYMBOL(proc_mgr_control);
653
654/*========================================
655 * Function to translate between two types of address spaces.
656 *
657 * This function translates addresses between two types of address
658 * spaces. The destination and source address types are indicated
659 * through parameters specified in this function.
660 */
661int proc_mgr_translate_addr(void *handle, void **dst_addr,
662 enum proc_mgr_addr_type dst_addr_type, void *src_addr,
663 enum proc_mgr_addr_type src_addr_type)
664{
665 int retval = 0;
666 struct proc_mgr_object *proc_mgr_handle =
667 (struct proc_mgr_object *)handle;
668
669 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
670 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
671 == true) {
672 printk(KERN_ERR "proc_mgr_translate_addr:"
673 "Error - module not initialized\n");
674 return -EFAULT;
675 }
676 BUG_ON(dst_addr == NULL);
677 BUG_ON(handle == NULL);
678 BUG_ON(dst_addr_type > PROC_MGR_ADDRTYPE_ENDVALUE);
679 BUG_ON(src_addr == NULL);
680 BUG_ON(src_addr_type > PROC_MGR_ADDRTYPE_ENDVALUE);
681
682 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
683 /* Translate the address. */
684 retval = processor_translate_addr(proc_mgr_handle->proc_handle,
685 dst_addr, dst_addr_type, src_addr, src_addr_type);
686 WARN_ON(retval < 0);
687 mutex_unlock(proc_mgr_obj_state.gate_handle);
688 return retval;;
689}
690EXPORT_SYMBOL(proc_mgr_translate_addr);
691
692/*=================================
693 * Function that registers for notification when the slave
694 * processor transitions to any of the states specified.
695 *
696 * This function allows the user application to register for
697 * changes in processor state and take actions accordingly.
698 *
699 */
700int proc_mgr_register_notify(void *handle, proc_mgr_callback_fxn fxn,
701 void *args, enum proc_mgr_state state[])
702{
703 int retval = 0;
704 struct proc_mgr_object *proc_mgr_handle
705 = (struct proc_mgr_object *)handle;
706 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
707 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
708 == true) {
709 printk(KERN_ERR "proc_mgr_register_notify:"
710 "Error - module not initialized\n");
711 return -EFAULT;
712 }
713 BUG_ON(handle == NULL);
714 BUG_ON(fxn == NULL);
715 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
716 retval = processor_register_notify(proc_mgr_handle->proc_handle, fxn,
717 args, state);
718 WARN_ON(retval < 0);
719 mutex_unlock(proc_mgr_obj_state.gate_handle);
720 return retval;
721}
722EXPORT_SYMBOL(proc_mgr_register_notify);
723
724/*
725 * Function that returns information about the characteristics of
726 * the slave processor.
727 */
728int proc_mgr_get_proc_info(void *handle, struct proc_mgr_proc_info *proc_info)
729{
730 struct proc_mgr_object *proc_mgr_handle =
731 (struct proc_mgr_object *)handle;
732 struct processor_object *proc_handle;
733
734 struct proc_mgr_proc_info proc_info_test;
735
736 if (atomic_cmpmask_and_lt(&(proc_mgr_obj_state.ref_count),
737 PROCMGR_MAKE_MAGICSTAMP(0), PROCMGR_MAKE_MAGICSTAMP(1))
738 == true) {
739 printk(KERN_ERR "proc_mgr_get_proc_info:"
740 "Error - module not initialized\n");
741 return -EFAULT;
742 }
743 if (WARN_ON(handle == NULL))
744 goto error_exit;
745 if (WARN_ON(proc_info == NULL))
746 goto error_exit;
747 proc_handle = proc_mgr_handle->proc_handle;
748 if (WARN_ON(proc_handle == NULL))
749 goto error_exit;
750
751 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
752
753 processor_get_proc_info(proc_handle, &proc_info_test);
754 /* Return bootMode information. */
755 proc_info->boot_mode = proc_mgr_handle->attach_params.boot_mode;
756 /* Return memory information. */
757 proc_info->num_mem_entries = proc_mgr_handle->num_mem_entries;
758 memcpy(&(proc_info->mem_entries),
759 &(proc_mgr_handle->mem_entries),
760 sizeof(proc_mgr_handle->mem_entries));
761 mutex_unlock(proc_mgr_obj_state.gate_handle);
762 return 0;
763error_exit:
764 return -EFAULT;
765}
766EXPORT_SYMBOL(proc_mgr_get_proc_info);
767
768/*============================================
769 * Function to get virtual to physical address translations
770 *
771 * This function retrieves physical entries
772 *
773 */
774int proc_mgr_virt_to_phys(void *handle, u32 da, u32 *mapped_entries,
775 u32 num_of_entries)
776{
777 int retval = 0;
778 struct proc_mgr_object *proc_mgr_handle =
779 (struct proc_mgr_object *)handle;
780
781 WARN_ON(mutex_lock_interruptible(proc_mgr_obj_state.gate_handle));
782
783 /* Map to host address space. */
784 retval = processor_virt_to_phys(proc_mgr_handle->proc_handle, da,
785 mapped_entries, num_of_entries);
786 WARN_ON(retval < 0);
787 mutex_unlock(proc_mgr_obj_state.gate_handle);
788 return retval;;
789}
790EXPORT_SYMBOL(proc_mgr_virt_to_phys);
diff --git a/drivers/dsp/syslink/procmgr/procmgr_drv.c b/drivers/dsp/syslink/procmgr/procmgr_drv.c
new file mode 100644
index 00000000000..6bb6e7ab594
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/procmgr_drv.c
@@ -0,0 +1,731 @@
1/*
2 * procmgr_drv.c
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17
18#include <generated/autoconf.h>
19#include <linux/kernel.h>
20#include <linux/module.h>
21#include <linux/cdev.h>
22#include <linux/device.h>
23#include <linux/fs.h>
24#include <linux/mm.h>
25#include <linux/slab.h>
26#include <linux/uaccess.h>
27#include <linux/platform_device.h>
28
29#include <plat/cpu.h>
30
31/* Module headers */
32#include <procmgr.h>
33#include "procmgr_drvdefs.h"
34
35#define PROCMGR_NAME "syslink-procmgr"
36
37static char *driver_name = PROCMGR_NAME;
38
39static s32 driver_major;
40
41static s32 driver_minor;
42
43struct procmgr_dev {
44 struct cdev cdev;
45};
46
47static struct platform_device *omap_proc_dev;
48static struct platform_device *procmgr_pdev;
49static struct procmgr_dev *procmgr_device;
50
51static struct class *proc_mgr_class;
52
53
54/** ====================================
55 * Forward declarations of internal functions
56 * ====================================
57 */
58/* Linux driver function to open the driver object. */
59static int proc_mgr_drv_open(struct inode *inode, struct file *filp);
60
61/* Linux driver function to close the driver object. */
62static int proc_mgr_drv_release(struct inode *inode, struct file *filp);
63
64/* Linux driver function to invoke the APIs through ioctl. */
65static int proc_mgr_drv_ioctl(struct inode *inode,
66 struct file *filp,
67 unsigned int cmd,
68 unsigned long args);
69
70/* Linux driver function to map memory regions to user space. */
71static int proc_mgr_drv_mmap(struct file *filp, struct vm_area_struct *vma);
72
73/* Module initialization function for Linux driver. */
74static int __init proc_mgr_drv_initialize_module(void);
75
76/* Module finalization function for Linux driver. */
77static void __exit proc_mgr_drv_finalize_module(void);
78
79/* Platform driver probe function */
80static int __devinit proc_mgr_probe(struct platform_device *pdev);
81
82/* Platform driver remove function */
83static int __devexit proc_mgr_remove(struct platform_device *pdev);
84
85/*
86 * name DriverOps
87 *
88 * desc Function to invoke the APIs through ioctl
89 *
90 */
91static const struct file_operations procmgr_fops = {
92 .open = proc_mgr_drv_open,
93 .ioctl = proc_mgr_drv_ioctl,
94 .release = proc_mgr_drv_release,
95 .mmap = proc_mgr_drv_mmap,
96} ;
97
98/* Imtiaz changed places */
99static struct platform_driver procmgr_driver = {
100 .driver = {
101 .owner = THIS_MODULE,
102 .name = PROCMGR_NAME,
103 },
104 .probe = proc_mgr_probe,
105 .remove = __devexit_p(proc_mgr_remove),
106 .shutdown = NULL,
107 .suspend = NULL,
108 .resume = NULL,
109};
110
111/* Process Context */
112struct procmgr_process_context {
113 u32 setup_count;
114};
115
116/*
117* brief Linux specific function to open the driver.
118 */
119static int proc_mgr_drv_open(struct inode *inode, struct file *filp)
120{
121 s32 retval = 0;
122 struct procmgr_process_context *pr_ctxt = NULL;
123
124 pr_ctxt = kzalloc(sizeof(struct procmgr_process_context), GFP_KERNEL);
125 if (!pr_ctxt)
126 retval = -ENOMEM;
127
128 filp->private_data = pr_ctxt;
129 return retval;
130}
131
132/*
133* brief Linux driver function to close the driver object.
134 */
135static int proc_mgr_drv_release(struct inode *inode, struct file *filp)
136{
137 s32 retval = 0;
138 struct procmgr_process_context *pr_ctxt;
139
140 if (!filp->private_data) {
141 retval = -EIO;
142 goto err;
143 }
144
145 pr_ctxt = filp->private_data;
146 while (pr_ctxt->setup_count-- > 0) {
147 /* Destroy has not been called. Call destroy now. */
148 printk(KERN_ERR "proc_mgr_drv_release: "
149 "proc_mgr_destroy %d\n", pr_ctxt->setup_count);
150 proc_mgr_destroy();
151 }
152 kfree(pr_ctxt);
153
154 filp->private_data = NULL;
155err:
156 return retval;
157}
158
159/*
160* Linux driver function to invoke the APIs through ioctl.
161 */
162static int proc_mgr_drv_ioctl(struct inode *inode, struct file *filp,
163 unsigned int cmd, unsigned long args)
164{
165 int retval = 0;
166 struct proc_mgr_cmd_args *cmd_args = (struct proc_mgr_cmd_args *)args;
167 struct proc_mgr_cmd_args command_args;
168 struct procmgr_process_context *pr_ctxt =
169 (struct procmgr_process_context *)filp->private_data;
170
171 switch (cmd) {
172 case CMD_PROCMGR_GETCONFIG:
173 {
174 struct proc_mgr_cmd_args_get_config *src_args =
175 (struct proc_mgr_cmd_args_get_config *)args;
176 struct proc_mgr_config cfg;
177
178 /* copy_from_user is not needed for proc_mgr_get_config,
179 * since the user's config is not used.
180 */
181 proc_mgr_get_config(&cfg);
182
183 retval = copy_to_user((void __user *)(src_args->cfg),
184 (const void *)&cfg,
185 sizeof(struct proc_mgr_config));
186
187 WARN_ON(retval < 0);
188 }
189 break;
190
191 case CMD_PROCMGR_SETUP:
192 {
193 struct proc_mgr_cmd_args_setup *src_args =
194 (struct proc_mgr_cmd_args_setup *)args;
195 struct proc_mgr_config cfg;
196
197 retval = copy_from_user((void *)&cfg,
198 (const void __user *)(src_args->cfg),
199 sizeof(struct proc_mgr_config));
200
201 /* This check is needed at run-time also since it
202 * depends on run environment.
203 * It must not be optimized out.
204 */
205 if (WARN_ON(retval != 0))
206 goto func_exit;
207
208 retval = proc_mgr_setup(&cfg);
209 if (retval >= 0)
210 pr_ctxt->setup_count++;
211 }
212 break;
213
214 case CMD_PROCMGR_DESTROY:
215 {
216 retval = proc_mgr_destroy();
217 pr_ctxt->setup_count--;
218 WARN_ON(retval < 0);
219 }
220 break;
221
222 case CMD_PROCMGR_PARAMS_INIT:
223 {
224 struct proc_mgr_cmd_args_params_init src_args;
225 struct proc_mgr_params params;
226
227 /* Copy the full args from user-side. */
228 retval = copy_from_user((void *)&src_args,
229 (const void __user *)(args),
230 sizeof(struct proc_mgr_cmd_args_params_init));
231
232 if (WARN_ON(retval != 0))
233 goto func_exit;
234
235 proc_mgr_params_init(src_args.handle, &params);
236
237 /* Copy only the params to user-side */
238 retval = copy_to_user((void __user *)(src_args.params),
239 (const void *)&params,
240 sizeof(struct proc_mgr_params));
241 WARN_ON(retval < 0);
242 }
243 break;
244
245 case CMD_PROCMGR_CREATE:
246 {
247 struct proc_mgr_cmd_args_create src_args;
248
249 /* Copy the full args from user-side. */
250 retval = copy_from_user((void *)&src_args,
251 (const void __user *)(args),
252 sizeof(struct proc_mgr_cmd_args_create));
253
254 src_args.handle = proc_mgr_create(src_args.proc_id,
255 &(src_args.params));
256 if (src_args.handle == NULL) {
257 retval = -EFAULT;
258 goto func_exit;
259 }
260 retval = copy_to_user((void __user *)(args),
261 (const void *)&src_args,
262 sizeof(struct proc_mgr_cmd_args_create));
263 WARN_ON(retval < 0);
264 }
265 break;
266
267 case CMD_PROCMGR_DELETE:
268 {
269 struct proc_mgr_cmd_args_delete src_args;
270
271 /* Copy the full args from user-side. */
272 retval = copy_from_user((void *)&src_args,
273 (const void __user *)(args),
274 sizeof(struct proc_mgr_cmd_args_delete));
275 if (WARN_ON(retval != 0))
276 goto func_exit;
277
278 retval = proc_mgr_delete(&(src_args.handle));
279 }
280 break;
281
282 case CMD_PROCMGR_OPEN:
283 {
284 struct proc_mgr_cmd_args_open src_args;
285
286 /* Copy the full args from user-side. */
287 retval = copy_from_user((void *)&src_args,
288 (const void __user *)(args),
289 sizeof(struct proc_mgr_cmd_args_open));
290
291 if (WARN_ON(retval != 0))
292 goto func_exit;
293 retval = proc_mgr_open(&(src_args.handle),
294 src_args.proc_id);
295 if (WARN_ON(retval < 0))
296 goto func_exit;
297 retval = proc_mgr_get_proc_info(src_args.handle,
298 &(src_args.proc_info));
299 if (WARN_ON(retval < 0))
300 goto func_exit;
301 retval = copy_to_user((void __user *)(args),
302 (const void *)&src_args,
303 sizeof(struct proc_mgr_cmd_args_open));
304 WARN_ON(retval);
305 }
306 break;
307
308 case CMD_PROCMGR_CLOSE:
309 {
310 struct proc_mgr_cmd_args_close src_args;
311
312 /* Copy the full args from user-side. */
313 retval = copy_from_user((void *)&src_args,
314 (const void __user *)(args),
315 sizeof(struct proc_mgr_cmd_args_close));
316 if (WARN_ON(retval != 0))
317 goto func_exit;
318 retval = proc_mgr_close(&(src_args.handle));
319 }
320 break;
321
322 case CMD_PROCMGR_GETATTACHPARAMS:
323 {
324 struct proc_mgr_cmd_args_get_attach_params src_args;
325 struct proc_mgr_attach_params params;
326
327 /* Copy the full args from user-side. */
328 retval = copy_from_user((void *)&src_args,
329 (const void __user *)(args),
330 sizeof(struct proc_mgr_cmd_args_get_attach_params));
331 if (WARN_ON(retval != 0))
332 goto func_exit;
333 proc_mgr_get_attach_params(src_args.handle, &params);
334 retval = copy_to_user((void __user *)(src_args.params),
335 (const void *)&params,
336 sizeof(struct proc_mgr_attach_params));
337 WARN_ON(retval);
338 }
339 break;
340
341 case CMD_PROCMGR_ATTACH:
342 {
343 struct proc_mgr_cmd_args_attach src_args;
344 struct proc_mgr_attach_params params;
345
346 /* Copy the full args from user-side. */
347 retval = copy_from_user((void *)&src_args,
348 (const void __user *)(args),
349 sizeof(struct proc_mgr_cmd_args_attach));
350 if (WARN_ON(retval != 0))
351 goto func_exit;
352 /* Copy params from user-side. */
353 retval = copy_from_user((void *)&params,
354 (const void __user *)(src_args.params),
355 sizeof(struct proc_mgr_attach_params));
356 retval = proc_mgr_attach(src_args.handle, &params);
357 if (WARN_ON(retval < 0))
358 goto func_exit;
359 /* Get memory information. */
360 retval = proc_mgr_get_proc_info(src_args.handle,
361 &(src_args.proc_info));
362 if (WARN_ON(retval < 0))
363 goto func_exit;
364 retval = copy_to_user((void __user *)(args),
365 (const void *)&src_args,
366 sizeof(struct proc_mgr_cmd_args_attach));
367 }
368 break;
369
370 case CMD_PROCMGR_DETACH:
371 {
372 struct proc_mgr_cmd_args_detach src_args;
373
374 /* Copy the full args from user-side. */
375 retval = copy_from_user((void *)&src_args,
376 (const void __user *)(args),
377 sizeof(struct proc_mgr_cmd_args_detach));
378 if (WARN_ON(retval != 0))
379 goto func_exit;
380 retval = proc_mgr_detach(src_args.handle);
381 if (WARN_ON(retval < 0))
382 goto func_exit;
383 }
384 break;
385
386 case CMD_PROCMGR_GETSTATE:
387 {
388 struct proc_mgr_cmd_args_get_state src_args;
389 enum proc_mgr_state procmgrstate;
390
391 /* Copy the full args from user-side. */
392 retval = copy_from_user((void *)&src_args,
393 (const __user void *)(args),
394 sizeof(struct proc_mgr_cmd_args_get_state));
395 if (WARN_ON(retval != 0))
396 goto func_exit;
397 procmgrstate = proc_mgr_get_state(src_args.handle);
398 src_args.proc_mgr_state = procmgrstate;
399 retval = copy_to_user((void __user *)(args),
400 (const void *)&src_args,
401 sizeof(struct proc_mgr_cmd_args_get_state));
402 WARN_ON(retval < 0);
403 }
404 break;
405
406 case CMD_PROCMGR_READ:
407 {
408 struct proc_mgr_cmd_args_read src_args;
409
410 /* Copy the full args from user-side. */
411 retval = copy_from_user((void *)&src_args,
412 (const void __user *)(args),
413 sizeof(struct proc_mgr_cmd_args_read));
414 if (WARN_ON(retval != 0))
415 goto func_exit;
416 retval = proc_mgr_read(src_args.handle,
417 src_args.proc_addr, &(src_args.num_bytes),
418 src_args.buffer);
419 if (WARN_ON(retval < 0))
420 goto func_exit;
421 retval = copy_to_user((void __user *)(args),
422 (const void *)&src_args,
423 sizeof(struct proc_mgr_cmd_args_read));
424 WARN_ON(retval < 0);
425 }
426 break;
427
428 case CMD_PROCMGR_WRITE:
429 {
430 struct proc_mgr_cmd_args_write src_args;
431
432 /* Copy the full args from user-side. */
433 retval = copy_from_user((void *)&src_args,
434 (const void __user *)(args),
435 sizeof(struct proc_mgr_cmd_args_write));
436 if (WARN_ON(retval != 0))
437 goto func_exit;
438 retval = proc_mgr_write(src_args.handle,
439 src_args.proc_addr, &(src_args.num_bytes),
440 src_args.buffer);
441 if (WARN_ON(retval < 0))
442 goto func_exit;
443 retval = copy_to_user((void __user *)(args),
444 (const void *)&src_args,
445 sizeof(struct proc_mgr_cmd_args_write));
446 WARN_ON(retval < 0);
447 }
448 break;
449
450 case CMD_PROCMGR_CONTROL:
451 {
452 struct proc_mgr_cmd_args_control src_args;
453
454 /* Copy the full args from user-side. */
455 retval = copy_from_user((void *)&src_args,
456 (const void __user *)(args),
457 sizeof(struct proc_mgr_cmd_args_control));
458 if (WARN_ON(retval != 0))
459 goto func_exit;
460 retval = proc_mgr_control(src_args.handle,
461 src_args.cmd, src_args.arg);
462 WARN_ON(retval < 0);
463 }
464 break;
465
466 case CMD_PROCMGR_TRANSLATEADDR:
467 {
468 struct proc_mgr_cmd_args_translate_addr src_args;
469
470 /* Copy the full args from user-side. */
471 retval = copy_from_user((void *)&src_args,
472 (const void __user *)(args),
473 sizeof(struct proc_mgr_cmd_args_translate_addr));
474 if (WARN_ON(retval != 0))
475 goto func_exit;
476 retval = proc_mgr_translate_addr(src_args.handle,
477 &(src_args.dst_addr), src_args.dst_addr_type,
478 src_args.src_addr, src_args.src_addr_type);
479 if (WARN_ON(retval < 0))
480 goto func_exit;
481 retval = copy_to_user((void __user *)(args),
482 (const void *)&src_args, sizeof
483 (struct proc_mgr_cmd_args_translate_addr));
484 WARN_ON(retval < 0);
485 }
486 break;
487
488 case CMD_PROCMGR_REGISTERNOTIFY:
489 {
490 struct proc_mgr_cmd_args_register_notify src_args;
491
492 /* Copy the full args from user-side. */
493 retval = copy_from_user((void *)&src_args,
494 (const void __user *)(args),
495 sizeof(struct proc_mgr_cmd_args_register_notify));
496 if (WARN_ON(retval != 0))
497 goto func_exit;
498 retval = proc_mgr_register_notify(src_args.handle,
499 src_args.callback_fxn,
500 src_args.args, src_args.state);
501 WARN_ON(retval < 0);
502 }
503 break;
504
505 case CMD_PROCMGR_GETPROCINFO:
506 {
507 struct proc_mgr_cmd_args_get_proc_info src_args;
508 struct proc_mgr_proc_info *proc_info;
509
510 /* Copy the full args from user-side. */
511 retval = copy_from_user((void *)&src_args,
512 (const void __user *)(args),
513 sizeof(struct proc_mgr_cmd_args_get_proc_info));
514 if (WARN_ON(retval != 0))
515 goto func_exit;
516
517 proc_info = kzalloc(sizeof(struct proc_mgr_proc_info),
518 GFP_KERNEL);
519 retval = proc_mgr_get_proc_info
520 (src_args.handle, proc_info);
521 if (WARN_ON(retval < 0)) {
522 kfree(proc_info);
523 goto func_exit;
524 }
525 retval = copy_to_user((void __user *)(src_args.proc_info),
526 (const void *) proc_info,
527 sizeof(struct proc_mgr_proc_info));
528 WARN_ON(retval < 0);
529 kfree(proc_info);
530 }
531 break;
532
533 case CMD_PROCMGR_GETVIRTTOPHYS:
534 {
535 struct proc_mgr_cmd_args_get_virt_to_phys src_args;
536
537 retval = copy_from_user((void *)&src_args,
538 (const void __user *)(args),
539 sizeof(struct proc_mgr_cmd_args_get_virt_to_phys));
540 retval = proc_mgr_virt_to_phys(src_args.handle,
541 src_args.da, (src_args.mem_entries),
542 src_args.num_of_entries);
543 if (WARN_ON(retval < 0))
544 goto func_exit;
545 retval = copy_to_user((void __user *)(args),
546 (const void *)&src_args,
547 sizeof(struct proc_mgr_cmd_args_get_virt_to_phys));
548 WARN_ON(retval < 0);
549 }
550 break;
551
552 /*
553 * This is added to provide the information whether to enable
554 * lock all entries in TLB or not. ES1.0 requires all the entries
555 * to be locked, so the loader in userspace makes the decision on
556 * how the entries should be programmed based on ES revision. This
557 * case is meant for temporary purpose and can be removed once ES1.0
558 * boards are phased out
559 */
560 case CMD_PROCMGR_GETBOARDREV:
561 {
562 int rev;
563 struct proc_mgr_cmd_args_cpurev src_args;
564 retval = copy_from_user((void *)&src_args,
565 (const void __user *)(args),
566 sizeof(struct proc_mgr_cmd_args_cpurev));
567 if (WARN_ON(retval < 0))
568 goto func_exit;
569
570 rev = GET_OMAP_REVISION();
571 *(src_args.cpu_rev) = rev;
572 retval = copy_to_user((void __user *)(args),
573 (const void *)&src_args,
574 sizeof(struct proc_mgr_cmd_args_cpurev));
575 if (WARN_ON(retval < 0))
576 goto func_exit;
577 }
578 break;
579 default:
580 printk(KERN_ERR"PROC_MGR_DRV: WRONG IOCTL !!!!\n");
581 BUG_ON(1);
582 break;
583 }
584func_exit:
585 /* Set the retval and copy the common args to user-side. */
586 command_args.api_status = retval;
587 retval = copy_to_user((void __user *)cmd_args,
588 (const void *)&command_args, sizeof(struct proc_mgr_cmd_args));
589
590 WARN_ON(retval < 0);
591 return retval;
592}
593
594
595/*
596 Driver function to map memory regions to user space.
597 */
598static int proc_mgr_drv_mmap(struct file *filp, struct vm_area_struct *vma)
599{
600 vma->vm_page_prot = pgprot_dmacoherent(vma->vm_page_prot);
601 vma->vm_flags |= VM_RESERVED;
602
603 if (remap_pfn_range(vma,
604 vma->vm_start,
605 vma->vm_pgoff,
606 vma->vm_end - vma->vm_start,
607 vma->vm_page_prot)) {
608 return -EAGAIN;
609 }
610 return 0;
611}
612
613static int __devinit proc_mgr_probe(struct platform_device *pdev)
614{
615 dev_t dev = 0 ;
616 int retval = -ENOMEM;
617
618 /* Display the version info and created date/time */
619 dev_dbg(&omap_proc_dev->dev, "Entering %s function\n\n", __func__);
620
621 if (driver_major) {
622 dev = MKDEV(driver_major, driver_minor);
623 retval = register_chrdev_region(dev, 1, driver_name);
624 } else {
625 retval = alloc_chrdev_region(&dev, driver_minor, 1,
626 driver_name);
627 driver_major = MAJOR(dev);
628 }
629
630 procmgr_device = kmalloc(sizeof(struct procmgr_dev), GFP_KERNEL);
631 if (!procmgr_device) {
632 retval = -ENOMEM;
633 unregister_chrdev_region(dev, 1);
634 goto exit;
635 }
636 memset(procmgr_device, 0, sizeof(struct procmgr_dev));
637 cdev_init(&procmgr_device->cdev, &procmgr_fops);
638 procmgr_device->cdev.owner = THIS_MODULE;
639 procmgr_device->cdev.ops = &procmgr_fops;
640
641 retval = cdev_add(&procmgr_device->cdev, dev, 1);
642
643 if (retval) {
644 printk(KERN_ERR "Failed to add the syslink procmgr device\n");
645 goto exit;
646 }
647
648 /* udev support */
649 proc_mgr_class = class_create(THIS_MODULE, "syslink-procmgr");
650
651 if (IS_ERR(proc_mgr_class)) {
652 printk(KERN_ERR "Error creating bridge class\n");
653 goto exit;
654 }
655 device_create(proc_mgr_class, NULL, MKDEV(driver_major, driver_minor),
656 NULL, PROCMGR_NAME);
657
658exit:
659 dev_dbg(&omap_proc_dev->dev, "Leaving %s function\n\n", __func__);
660 return retval;
661}
662
663
664static int __devexit proc_mgr_remove(struct platform_device *pdev)
665{
666 dev_t devno = 0;
667
668 dev_dbg(&omap_proc_dev->dev, "Entering %s function\n", __func__);
669 devno = MKDEV(driver_major, driver_minor);
670 if (procmgr_device) {
671 cdev_del(&procmgr_device->cdev);
672 kfree(procmgr_device);
673 }
674 unregister_chrdev_region(devno, 1);
675 if (proc_mgr_class) {
676 /* remove the device from sysfs */
677 device_destroy(proc_mgr_class, MKDEV(driver_major,
678 driver_minor));
679 class_destroy(proc_mgr_class);
680 }
681 dev_dbg(&omap_proc_dev->dev, "Entering %s function\n", __func__);
682 return 0;
683}
684
685/*
686* Module initialization function for Linux driver.
687 */
688static int __init proc_mgr_drv_initialize_module(void)
689{
690 int retval = -ENOMEM;
691
692 procmgr_pdev = platform_device_alloc(PROCMGR_NAME, -1);
693 if (!procmgr_pdev) {
694 printk(KERN_ERR "%s:device allocation failed\n", __func__);
695 return -ENOMEM;
696 }
697 retval = platform_device_add(procmgr_pdev);
698 if (retval)
699 goto err_out;
700
701 /*Saving the context for future use*/
702 omap_proc_dev = procmgr_pdev;
703
704 retval = platform_driver_register(&procmgr_driver);
705 if (!retval)
706 return retval;
707err_out:
708 platform_device_put(procmgr_pdev);
709 return retval;
710}
711
712/*
713* driver function to finalize the driver module.
714 */
715static void __exit proc_mgr_drv_finalize_module(void)
716{
717
718 dev_dbg(&omap_proc_dev->dev, "Entering %s function\n", __func__);
719 platform_device_unregister(procmgr_pdev);
720 platform_driver_unregister(&procmgr_driver);
721 dev_dbg(&omap_proc_dev->dev, "Leaving %s function\n", __func__);
722}
723
724/*
725* brief Macro calls that indicate initialization and finalization functions
726 * to the kernel.
727 */
728MODULE_LICENSE("GPL v2");
729MODULE_AUTHOR("Mugdha Kamoolkar");
730module_init(proc_mgr_drv_initialize_module);
731module_exit(proc_mgr_drv_finalize_module);
diff --git a/drivers/dsp/syslink/procmgr/procmgr_drvdefs.h b/drivers/dsp/syslink/procmgr/procmgr_drvdefs.h
new file mode 100644
index 00000000000..fc0015d5882
--- /dev/null
+++ b/drivers/dsp/syslink/procmgr/procmgr_drvdefs.h
@@ -0,0 +1,491 @@
1/*
2 * procmgr_drvdefs.h
3 *
4 * Syslink driver support functions for TI OMAP processors.
5 *
6 * Copyright (C) 2009-2010 Texas Instruments, Inc.
7 *
8 * This package is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
13 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
14 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15 */
16
17
18#ifndef SYSLINK_PROCMGR_DRVDEFS_H
19#define SYSLINK_PROCMGR_DRVDEFS_H
20
21#include <linux/types.h>
22
23/* Module headers */
24#include <procmgr.h>
25
26
27/* =================================
28 * Macros and types
29 * =================================
30 */
31/*
32 * Base structure for ProcMgr command args. This needs to be the first
33 * field in all command args structures.
34 */
35struct proc_mgr_cmd_args {
36 int api_status;
37 /*Status of the API being called. */
38};
39
40/* --------------------------------------
41 * IOCTL command IDs for ProcMgr
42 * ---------------------------------------
43 */
44/*
45 * Base command ID for ProcMgr
46 */
47#define PROCMGR_BASE_CMD 0x100
48
49/*
50 * Command for ProcMgr_getConfig
51 */
52#define CMD_PROCMGR_GETCONFIG (PROCMGR_BASE_CMD + 1)
53
54/*
55 * Command for ProcMgr_setup
56 */
57#define CMD_PROCMGR_SETUP (PROCMGR_BASE_CMD + 2)
58
59/*
60 * Command for ProcMgr_setup
61 */
62#define CMD_PROCMGR_DESTROY (PROCMGR_BASE_CMD + 3)
63
64/*
65 * Command for ProcMgr_destroy
66 */
67#define CMD_PROCMGR_PARAMS_INIT (PROCMGR_BASE_CMD + 4)
68
69/*
70 * Command for ProcMgr_create
71 */
72#define CMD_PROCMGR_CREATE (PROCMGR_BASE_CMD + 5)
73
74/*
75 * Command for ProcMgr_delete
76 */
77#define CMD_PROCMGR_DELETE (PROCMGR_BASE_CMD + 6)
78
79/*
80 * Command for ProcMgr_open
81 */
82#define CMD_PROCMGR_OPEN (PROCMGR_BASE_CMD + 7)
83
84/*
85 * Command for ProcMgr_close
86 */
87#define CMD_PROCMGR_CLOSE (PROCMGR_BASE_CMD + 8)
88
89/*
90 * Command for ProcMgr_getAttachParams
91 */
92#define CMD_PROCMGR_GETATTACHPARAMS (PROCMGR_BASE_CMD + 9)
93
94/*
95 * Command for ProcMgr_attach
96 */
97#define CMD_PROCMGR_ATTACH (PROCMGR_BASE_CMD + 10)
98
99/*
100 * Command for ProcMgr_detach
101 */
102#define CMD_PROCMGR_DETACH (PROCMGR_BASE_CMD + 11)
103
104/*
105 * Command for ProcMgr_load
106 */
107#define CMD_PROCMGR_LOAD (PROCMGR_BASE_CMD + 12)
108
109/*
110 * Command for ProcMgr_unload
111 */
112#define CMD_PROCMGR_UNLOAD (PROCMGR_BASE_CMD + 13)
113
114/*
115 * Command for ProcMgr_getStartParams
116 */
117#define CMD_PROCMGR_GETSTARTPARAMS (PROCMGR_BASE_CMD + 14)
118
119/*
120 * Command for ProcMgr_start
121 */
122#define CMD_PROCMGR_START (PROCMGR_BASE_CMD + 15)
123
124/*
125 * Command for ProcMgr_stop
126 */
127#define CMD_PROCMGR_STOP (PROCMGR_BASE_CMD + 16)
128
129/*
130 * Command for ProcMgr_getState
131 */
132#define CMD_PROCMGR_GETSTATE (PROCMGR_BASE_CMD + 17)
133
134/*
135 * Command for ProcMgr_read
136 */
137#define CMD_PROCMGR_READ (PROCMGR_BASE_CMD + 18)
138
139/*
140 * Command for ProcMgr_write
141 */
142#define CMD_PROCMGR_WRITE (PROCMGR_BASE_CMD + 19)
143
144/*
145 * Command for ProcMgr_control
146 */
147#define CMD_PROCMGR_CONTROL (PROCMGR_BASE_CMD + 20)
148
149/*
150 * Command for ProcMgr_translateAddr
151 */
152#define CMD_PROCMGR_TRANSLATEADDR (PROCMGR_BASE_CMD + 22)
153
154/*
155 * Command for ProcMgr_getSymbolAddress
156 */
157#define CMD_PROCMGR_GETSYMBOLADDRESS (PROCMGR_BASE_CMD + 23)
158
159/*
160 * Command for ProcMgr_map
161 */
162#define CMD_PROCMGR_MAP (PROCMGR_BASE_CMD + 24)
163
164/*
165 * Command for ProcMgr_registerNotify
166 */
167#define CMD_PROCMGR_REGISTERNOTIFY (PROCMGR_BASE_CMD + 25)
168
169/*
170 * Command for ProcMgr_getProcInfo
171 */
172#define CMD_PROCMGR_GETPROCINFO (PROCMGR_BASE_CMD + 26)
173
174/*
175 * Command for ProcMgr_unmap
176 */
177#define CMD_PROCMGR_UNMAP (PROCMGR_BASE_CMD + 27)
178
179/*
180 * Command for ProcMgr_getVirtToPhysPages
181 */
182#define CMD_PROCMGR_GETVIRTTOPHYS (PROCMGR_BASE_CMD + 28)
183
184
185/*
186 * Command to get Board revision
187 */
188#define CMD_PROCMGR_GETBOARDREV (PROCMGR_BASE_CMD + 31)
189
190
191
192/* ----------------------------------------------------------------------------
193 * Command arguments for ProcMgr
194 * ----------------------------------------------------------------------------
195 */
196/*
197 * Command arguments for ProcMgr_getConfig
198 */
199struct proc_mgr_cmd_args_get_config {
200 struct proc_mgr_cmd_args commond_args;
201 /*Common command args */
202 struct proc_mgr_config *cfg;
203 /*Pointer to the ProcMgr module configuration structure in which the
204 default config is to be returned. */
205};
206
207/*
208 * Command arguments for ProcMgr_setup
209 */
210struct proc_mgr_cmd_args_setup {
211 struct proc_mgr_cmd_args commond_args;
212 /*Common command args */
213 struct proc_mgr_config *cfg;
214 /*Optional ProcMgr module configuration. If provided as NULL, default
215 configuration is used. */
216};
217
218/*
219 * Command arguments for ProcMgr_destroy
220 */
221struct proc_mgr_cmd_args_destroy {
222 struct proc_mgr_cmd_args commond_args;
223 /*Common command args */
224};
225
226/*
227 * Command arguments for ProcMgr_Params_init
228 */
229struct proc_mgr_cmd_args_params_init {
230 struct proc_mgr_cmd_args commond_args;
231 /*Common command args */
232 void *handle;
233 /*Handle to the ProcMgr object. */
234 struct proc_mgr_params *params;
235 /*Pointer to the ProcMgr instance params structure in which the default
236 params is to be returned. */
237};
238
239/*
240 * Command arguments for ProcMgr_create
241 */
242struct proc_mgr_cmd_args_create {
243 struct proc_mgr_cmd_args commond_args;
244 /*Common command args */
245 u16 proc_id;
246 /*Processor ID represented by this ProcMgr instance */
247 struct proc_mgr_params params;
248 /*ProcMgr instance configuration parameters. */
249 void *handle;
250 /*Handle to the created ProcMgr object */
251};
252
253/*
254 * Command arguments for ProcMgr_delete
255 */
256struct proc_mgr_cmd_args_delete{
257 struct proc_mgr_cmd_args commond_args;
258 /*Common command args */
259 void *handle;
260 /*Pointer to Handle to the ProcMgr object */
261};
262
263/*
264 * Command arguments for ProcMgr_open
265 */
266struct proc_mgr_cmd_args_open {
267 struct proc_mgr_cmd_args commond_args;
268 /*Common command args */
269 u16 proc_id;
270 /*Processor ID represented by this ProcMgr instance */
271 void *handle;
272 /*Handle to the opened ProcMgr object. */
273 struct proc_mgr_proc_info proc_info;
274 /*Processor information. */
275};
276
277/*
278 * Command arguments for ProcMgr_close
279 */
280struct proc_mgr_cmd_args_close{
281 struct proc_mgr_cmd_args commond_args;
282 /*Common command args */
283 void *handle;
284 /*Handle to the ProcMgr object */
285 struct proc_mgr_proc_info proc_info;
286 /*Processor information. */
287};
288
289/*
290 * Command arguments for ProcMgr_getAttachParams
291 */
292struct proc_mgr_cmd_args_get_attach_params{
293 struct proc_mgr_cmd_args commond_args;
294 /*Common command args */
295 void *handle;
296 /*Handle to the ProcMgr object. */
297 struct proc_mgr_attach_params *params;
298 /*Pointer to the ProcMgr attach params structure in which the default
299 params is to be returned. */
300};
301
302/*
303 * Command arguments for ProcMgr_attach
304 */
305struct proc_mgr_cmd_args_attach {
306 struct proc_mgr_cmd_args commond_args;
307 /*Common command args */
308 void *handle;
309 /*Handle to the ProcMgr object. */
310 struct proc_mgr_attach_params *params;
311 /*Optional ProcMgr attach parameters. */
312 struct proc_mgr_proc_info proc_info;
313 /*Processor information. */
314};
315
316/*
317 * Command arguments for ProcMgr_detach
318 */
319struct proc_mgr_cmd_args_detach {
320 struct proc_mgr_cmd_args commond_args;
321 /*Common command args */
322 void *handle;
323 /*Handle to the ProcMgr object */
324 struct proc_mgr_proc_info proc_info;
325 /*Processor information. */
326};
327
328
329/*
330 * Command arguments for ProcMgr_getStartParams
331 */
332struct proc_mgr_cmd_args_get_start_params {
333 struct proc_mgr_cmd_args commond_args;
334 /*Common command args */
335 void *handle;
336 /*Entry point for the image*/
337 u32 entry_point;
338 /*Handle to the ProcMgr object */
339 struct proc_mgr_start_params *params;
340 /*Pointer to the ProcMgr start params structure in which the default
341 params is to be returned. */
342};
343
344/*
345 * Command arguments for ProcMgr_getState
346 */
347struct proc_mgr_cmd_args_get_state {
348 struct proc_mgr_cmd_args commond_args;
349 /*Common command args */
350 void *handle;
351 /* Handle to the ProcMgr object */
352 enum proc_mgr_state proc_mgr_state;
353 /*Current state of the ProcMgr object. */
354};
355
356/*
357 * Command arguments for ProcMgr_read
358 */
359struct proc_mgr_cmd_args_read {
360 struct proc_mgr_cmd_args commond_args;
361 /*Common command args */
362 void *handle;
363 /*Handle to the ProcMgr object */
364 u32 proc_addr;
365 /*Address in space processor's address space of the memory region to
366 read from. */
367 u32 num_bytes;
368 /*IN/OUT parameter. As an IN-parameter, it takes in the number of bytes
369 to be read. When the function returns, this parameter contains the
370 number of bytes actually read. */
371 void *buffer;
372 /*User-provided buffer in which the slave processor's memory contents
373 are to be copied. */
374};
375
376/*
377 * Command arguments for ProcMgr_write
378 */
379struct proc_mgr_cmd_args_write {
380 struct proc_mgr_cmd_args commond_args;
381 /*Common command args */
382 void *handle;
383 /*Handle to the ProcMgr object */
384 u32 proc_addr;
385 /*Address in space processor's address space of the memory region to
386 write into. */
387 u32 num_bytes;
388 /*IN/OUT parameter. As an IN-parameter, it takes in the number of bytes
389 to be written. When the function returns, this parameter contains the
390 number of bytes actually written. */
391 void *buffer;
392 /*User-provided buffer from which the data is to be written into the
393 slave processor's memory. */
394};
395
396/*
397 * Command arguments for ProcMgr_control
398 */
399struct proc_mgr_cmd_args_control {
400 struct proc_mgr_cmd_args commond_args;
401 /*Common command args */
402 void *handle;
403 /*Handle to the ProcMgr object */
404 int cmd;
405 /*Device specific processor command */
406 void *arg;
407 /*Arguments specific to the type of command. */
408};
409
410/*
411 * Command arguments for ProcMgr_translateAddr
412 */
413struct proc_mgr_cmd_args_translate_addr {
414 struct proc_mgr_cmd_args commond_args;
415 /*Common command args */
416 void *handle;
417 /*Handle to the ProcMgr object */
418 void *dst_addr;
419 /*Return parameter: Pointer to receive the translated address. */
420 enum proc_mgr_addr_type dst_addr_type;
421 /*Destination address type requested */
422 void *src_addr;
423 /*Source address in the source address space */
424 enum proc_mgr_addr_type src_addr_type;
425 /*Source address type */
426};
427
428/*
429 * Command arguments for ProcMgr_getSymbolAddress
430 */
431struct proc_mgr_cmd_args_get_symbol_address {
432 struct proc_mgr_cmd_args commond_args;
433 /*Common command args */
434 void *handle;
435 /*Handle to the ProcMgr object */
436 u32 file_id;
437 /*ID of the file received from the load function */
438 char *symbol_name;
439 /*Name of the symbol */
440 u32 sym_value;
441 /*Return parameter: Symbol address */
442};
443
444/*
445 * Command arguments for ProcMgr_registerNotify
446 */
447struct proc_mgr_cmd_args_register_notify {
448 struct proc_mgr_cmd_args commond_args;
449 /*Common command args */
450 void *handle;
451 /*Handle to the ProcMgr object */
452 int (*callback_fxn)(u16 proc_id, void *handle,
453 enum proc_mgr_state from_state, enum proc_mgr_state to_state);
454 /*Handling function to be registered. */
455 void *args;
456 /*Optional arguments associated with the handler fxn. */
457 enum proc_mgr_state state[];
458 /*Array of target states for which registration is required. */
459};
460
461/*
462 * Command arguments for ProcMgr_getProcInfo
463 */
464struct proc_mgr_cmd_args_get_proc_info {
465 struct proc_mgr_cmd_args commond_args;
466 /*Common command args */
467 void *handle;
468 /*Handle to the ProcMgr object */
469 struct proc_mgr_proc_info *proc_info;
470 /*Pointer to the ProcInfo object to be populated. */
471};
472
473/*
474 * Command arguments for ProcMgr_virtToPhys
475 */
476struct proc_mgr_cmd_args_get_virt_to_phys {
477 struct proc_mgr_cmd_args commond_args;
478 /*Common command args */
479 void *handle;
480 u32 da;
481 /* mem entries buffer */
482 u32 *mem_entries;
483 /* number of entries */
484 u32 num_of_entries;
485};
486
487struct proc_mgr_cmd_args_cpurev {
488 struct proc_mgr_cmd_args commond_args;
489 u32 *cpu_rev;
490};
491#endif