2 * This file is part of OMAP DSP driver (DSP Gateway version 3.3.1)
4 * Copyright (C) 2002-2006 Nokia Corporation. All rights reserved.
6 * Contact: Toshihiro Kobayashi <toshihiro.kobayashi@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/major.h>
29 #include <linux/poll.h>
30 #include <linux/platform_device.h>
31 #include <linux/slab.h>
32 #include <linux/sched.h>
34 #include <linux/mutex.h>
35 #include <linux/interrupt.h>
36 #include <asm/uaccess.h>
38 #include <asm/arch/mailbox.h>
39 #include "uaccess_dsp.h"
40 #include "dsp_mbcmd.h"
47 #define is_aligned(adr,align) (!((adr)&((align)-1)))
50 * devstate: task device state machine
51 * NOTASK: task is not attached.
52 * ATTACHED: task is attached.
53 * GARBAGE: task is detached. waiting for all processes to close this device.
54 * ADDREQ: requesting for tadd
55 * DELREQ: requesting for tdel. no process is opening this device.
56 * FREEZED: task is attached, but reserved to be killed.
57 * ADDFAIL: tadd failed.
58 * ADDING: tadd in process.
59 * DELING: tdel in process.
60 * KILLING: tkill in process.
62 #define TASKDEV_ST_NOTASK 0x00000001
63 #define TASKDEV_ST_ATTACHED 0x00000002
64 #define TASKDEV_ST_GARBAGE 0x00000004
65 #define TASKDEV_ST_INVALID 0x00000008
66 #define TASKDEV_ST_ADDREQ 0x00000100
67 #define TASKDEV_ST_DELREQ 0x00000200
68 #define TASKDEV_ST_FREEZED 0x00000400
69 #define TASKDEV_ST_ADDFAIL 0x00001000
70 #define TASKDEV_ST_ADDING 0x00010000
71 #define TASKDEV_ST_DELING 0x00020000
72 #define TASKDEV_ST_KILLING 0x00040000
73 #define TASKDEV_ST_STATE_MASK 0x7fffffff
74 #define TASKDEV_ST_STALE 0x80000000
80 { TASKDEV_ST_NOTASK, "notask" },
81 { TASKDEV_ST_ATTACHED, "attached" },
82 { TASKDEV_ST_GARBAGE, "garbage" },
83 { TASKDEV_ST_INVALID, "invalid" },
84 { TASKDEV_ST_ADDREQ, "addreq" },
85 { TASKDEV_ST_DELREQ, "delreq" },
86 { TASKDEV_ST_FREEZED, "freezed" },
87 { TASKDEV_ST_ADDFAIL, "addfail" },
88 { TASKDEV_ST_ADDING, "adding" },
89 { TASKDEV_ST_DELING, "deling" },
90 { TASKDEV_ST_KILLING, "killing" },
93 static char *devstate_name(long state) {
95 int max = ARRAY_SIZE(devstate_desc);
97 for (i = 0; i < max; i++) {
98 if (state & devstate_desc[i].state)
99 return devstate_desc[i].name;
104 struct rcvdt_bk_struct {
110 struct bus_type *bus;
111 // struct device_driver *driver;
112 struct device dev; /* Generic device interface */
115 struct rw_semaphore state_sem;
116 wait_queue_head_t state_wait_q;
117 struct mutex usecount_lock;
118 unsigned int usecount;
120 struct file_operations fops;
121 spinlock_t proc_list_lock;
122 struct list_head proc_list;
123 struct dsptask *task;
126 wait_queue_head_t read_wait_q;
127 struct mutex read_mutex;
129 struct fifo_struct fifo; /* for active word */
130 struct rcvdt_bk_struct bk;
134 wait_queue_head_t write_wait_q;
135 struct mutex write_mutex;
140 wait_queue_head_t tctl_wait_q;
141 struct mutex tctl_mutex;
143 int tctl_ret; /* return value for tctl_show() */
150 #define to_taskdev(n) container_of(n, struct taskdev, dev)
164 struct ipbuf_p *ipbuf_pvt_r;
167 struct ipbuf_p *ipbuf_pvt_w;
174 #define sndtyp_acv(ttyp) ((ttyp) & TTYP_ASND)
175 #define sndtyp_psv(ttyp) (!((ttyp) & TTYP_ASND))
176 #define sndtyp_bk(ttyp) ((ttyp) & TTYP_BKDM)
177 #define sndtyp_wd(ttyp) (!((ttyp) & TTYP_BKDM))
178 #define sndtyp_pvt(ttyp) ((ttyp) & TTYP_PVDM)
179 #define sndtyp_gbl(ttyp) (!((ttyp) & TTYP_PVDM))
180 #define rcvtyp_acv(ttyp) ((ttyp) & TTYP_ARCV)
181 #define rcvtyp_psv(ttyp) (!((ttyp) & TTYP_ARCV))
182 #define rcvtyp_bk(ttyp) ((ttyp) & TTYP_BKMD)
183 #define rcvtyp_wd(ttyp) (!((ttyp) & TTYP_BKMD))
184 #define rcvtyp_pvt(ttyp) ((ttyp) & TTYP_PVMD)
185 #define rcvtyp_gbl(ttyp) (!((ttyp) & TTYP_PVMD))
187 static __inline__ int has_taskdev_lock(struct taskdev *dev);
188 static int dsp_rmdev_minor(unsigned char minor);
189 static int taskdev_init(struct taskdev *dev, char *name, unsigned char minor);
190 static void taskdev_delete(unsigned char minor);
191 static int taskdev_attach_task(struct taskdev *dev, struct dsptask *task);
192 static int dsp_tdel_bh(struct taskdev *dev, u16 type);
194 static struct bus_type dsptask_bus = {
198 static struct class *dsp_task_class;
199 static DEFINE_MUTEX(devmgr_lock);
200 static struct taskdev *taskdev[TASKDEV_MAX];
201 static struct dsptask *dsptask[TASKDEV_MAX];
202 static DEFINE_MUTEX(cfg_lock);
205 static DECLARE_WAIT_QUEUE_HEAD(cfg_wait_q);
206 static u8 n_task; /* static task count */
209 #define is_dynamic_task(tid) ((tid) >= n_task)
211 #define devstate_read_lock(dev, devstate) \
212 devstate_read_lock_timeout(dev, devstate, 0)
213 #define devstate_read_unlock(dev) up_read(&(dev)->state_sem)
214 #define devstate_write_lock(dev, devstate) \
215 devstate_write_lock_timeout(dev, devstate, 0)
216 #define devstate_write_unlock(dev) up_write(&(dev)->state_sem)
218 static ssize_t devname_show(struct device *d, struct device_attribute *attr,
220 static ssize_t devstate_show(struct device *d, struct device_attribute *attr,
222 static ssize_t proc_list_show(struct device *d, struct device_attribute *attr,
224 static ssize_t taskname_show(struct device *d, struct device_attribute *attr,
226 static ssize_t ttyp_show(struct device *d, struct device_attribute *attr,
228 static ssize_t fifosz_show(struct device *d, struct device_attribute *attr,
230 static int fifosz_store(struct device *d, struct device_attribute *attr,
231 const char *buf, size_t count);
232 static ssize_t fifocnt_show(struct device *d, struct device_attribute *attr,
234 static ssize_t ipblink_show(struct device *d, struct device_attribute *attr,
236 static ssize_t wsz_show(struct device *d, struct device_attribute *attr,
238 static ssize_t mmap_show(struct device *d, struct device_attribute *attr,
241 #define __ATTR_RW(_name,_mode) { \
242 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
243 .show = _name##_show, \
244 .store = _name##_store, \
247 static struct device_attribute dev_attr_devname = __ATTR_RO(devname);
248 static struct device_attribute dev_attr_devstate = __ATTR_RO(devstate);
249 static struct device_attribute dev_attr_proc_list = __ATTR_RO(proc_list);
250 static struct device_attribute dev_attr_taskname = __ATTR_RO(taskname);
251 static struct device_attribute dev_attr_ttyp = __ATTR_RO(ttyp);
252 static struct device_attribute dev_attr_fifosz = __ATTR_RW(fifosz, 0666);
253 static struct device_attribute dev_attr_fifocnt = __ATTR_RO(fifocnt);
254 static struct device_attribute dev_attr_ipblink = __ATTR_RO(ipblink);
255 static struct device_attribute dev_attr_wsz = __ATTR_RO(wsz);
256 static struct device_attribute dev_attr_mmap = __ATTR_RO(mmap);
259 * devstate_read_lock_timeout()
260 * devstate_write_lock_timeout():
261 * timeout != 0: dev->state can be diffeent from what you want.
262 * timeout == 0: no timeout
264 static int devstate_read_lock_timeout(struct taskdev *dev, long devstate,
267 DECLARE_WAITQUEUE(wait, current);
268 long current_state = current->state;
271 down_read(&dev->state_sem);
272 if (dev->state & devstate)
275 add_wait_queue(&dev->state_wait_q, &wait);
277 set_current_state(TASK_INTERRUPTIBLE);
278 up_read(&dev->state_sem);
280 if ((timeout = schedule_timeout(timeout)) == 0) {
282 down_read(&dev->state_sem);
287 if (signal_pending(current)) {
291 down_read(&dev->state_sem);
292 } while (!(dev->state & devstate));
293 remove_wait_queue(&dev->state_wait_q, &wait);
294 set_current_state(current_state);
298 static int devstate_read_lock_and_test(struct taskdev *dev, long devstate)
300 down_read(&dev->state_sem);
301 if (dev->state & devstate)
302 return 1; /* success */
304 up_read(&dev->state_sem);
308 static int devstate_write_lock_timeout(struct taskdev *dev, long devstate,
311 DECLARE_WAITQUEUE(wait, current);
312 long current_state = current->state;
315 down_write(&dev->state_sem);
316 if (dev->state & devstate)
319 add_wait_queue(&dev->state_wait_q, &wait);
321 set_current_state(TASK_INTERRUPTIBLE);
322 up_write(&dev->state_sem);
324 if ((timeout = schedule_timeout(timeout)) == 0) {
326 down_write(&dev->state_sem);
331 if (signal_pending(current)) {
335 down_write(&dev->state_sem);
336 } while (!(dev->state & devstate));
337 remove_wait_queue(&dev->state_wait_q, &wait);
338 set_current_state(current_state);
342 static int devstate_write_lock_and_test(struct taskdev *dev, long devstate)
344 down_write(&dev->state_sem);
345 if (dev->state & devstate) /* success */
349 up_write(&dev->state_sem);
353 static int taskdev_lock_interruptible(struct taskdev *dev,
358 if (has_taskdev_lock(dev))
359 ret = mutex_lock_interruptible(lock);
361 if ((ret = mutex_lock_interruptible(&dev->lock)) != 0)
363 ret = mutex_lock_interruptible(lock);
364 mutex_unlock(&dev->lock);
370 static int taskdev_lock_and_statelock_attached(struct taskdev *dev,
375 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
378 if ((ret = taskdev_lock_interruptible(dev, lock)) != 0)
379 devstate_read_unlock(dev);
384 static __inline__ void taskdev_unlock_and_stateunlock(struct taskdev *dev,
388 devstate_read_unlock(dev);
392 * taskdev_flush_buf()
393 * must be called under state_lock(ATTACHED) and dev->read_mutex.
395 static int taskdev_flush_buf(struct taskdev *dev)
397 u16 ttyp = dev->task->ttyp;
399 if (sndtyp_wd(ttyp)) {
401 flush_fifo(&dev->rcvdt.fifo);
403 /* block receiving */
404 struct rcvdt_bk_struct *rcvdt = &dev->rcvdt.bk;
406 if (sndtyp_gbl(ttyp))
407 ipblink_flush(&rcvdt->link);
409 ipblink_flush_pvt(&rcvdt->link);
410 release_ipbuf_pvt(dev->task->ipbuf_pvt_r);
418 * taskdev_set_fifosz()
419 * must be called under dev->read_mutex.
421 static int taskdev_set_fifosz(struct taskdev *dev, unsigned long sz)
423 u16 ttyp = dev->task->ttyp;
426 if (!(sndtyp_wd(ttyp) && sndtyp_acv(ttyp))) {
428 "omapdsp: buffer size can be changed only for "
429 "active word sending task.\n");
432 if ((sz == 0) || (sz & 1)) {
433 printk(KERN_ERR "omapdsp: illegal buffer size! (%ld)\n"
434 "it must be even and non-zero value.\n", sz);
438 stat = realloc_fifo(&dev->rcvdt.fifo, sz);
439 if (stat == -EBUSY) {
440 printk(KERN_ERR "omapdsp: buffer is not empty!\n");
442 } else if (stat < 0) {
444 "omapdsp: unable to change receive buffer size. "
445 "(%ld bytes for %s)\n", sz, dev->name);
452 static __inline__ int has_taskdev_lock(struct taskdev *dev)
454 return (dev->lock_pid == current->pid);
457 static int taskdev_lock(struct taskdev *dev)
459 if (mutex_lock_interruptible(&dev->lock))
461 dev->lock_pid = current->pid;
465 static int taskdev_unlock(struct taskdev *dev)
467 if (!has_taskdev_lock(dev)) {
469 "omapdsp: an illegal process attempted to "
470 "unlock the dsptask lock!\n");
474 mutex_unlock(&dev->lock);
478 static int dsp_task_config(struct dsptask *task, u8 tid)
487 task->state = TASK_ST_CFGREQ;
488 if (mutex_lock_interruptible(&cfg_lock)) {
492 cfg_cmd = MBOX_CMD_DSP_TCFG;
493 mbcompose_send_and_wait(TCFG, tid, 0, &cfg_wait_q);
495 mutex_unlock(&cfg_lock);
497 if (task->state != TASK_ST_READY) {
498 printk(KERN_ERR "omapdsp: task %d configuration error!\n", tid);
503 if (strlen(task->name) <= 1)
504 sprintf(task->name, "%d", tid);
505 printk(KERN_INFO "omapdsp: task %d: name %s\n", tid, task->name);
510 * task info sanity check
513 /* task type check */
514 if (rcvtyp_psv(ttyp) && rcvtyp_pvt(ttyp)) {
515 printk(KERN_ERR "omapdsp: illegal task type(0x%04x), tid=%d\n",
521 /* private buffer address check */
522 if (sndtyp_pvt(ttyp) &&
523 (ipbuf_p_validate(task->ipbuf_pvt_r, DIR_D2A) < 0)) {
527 if (rcvtyp_pvt(ttyp) &&
528 (ipbuf_p_validate(task->ipbuf_pvt_w, DIR_A2D) < 0)) {
533 /* mmap buffer configuration check */
534 if ((task->map_length > 0) &&
535 ((!is_aligned((unsigned long)task->map_base, PAGE_SIZE)) ||
536 (!is_aligned(task->map_length, PAGE_SIZE)) ||
537 (dsp_mem_type(task->map_base, task->map_length) != MEM_TYPE_EXTERN))) {
539 "omapdsp: illegal mmap buffer address(0x%p) or "
541 " It needs to be page-aligned and located at "
542 "external memory.\n",
543 task->map_base, task->map_length);
555 static void dsp_task_init(struct dsptask *task)
557 mbcompose_send(TCTL, task->tid, TCTL_TINIT);
560 int dsp_task_config_all(u8 n)
563 struct taskdev *devheap;
564 struct dsptask *taskheap;
565 size_t devheapsz, taskheapsz;
567 memset(taskdev, 0, sizeof(void *) * TASKDEV_MAX);
568 memset(dsptask, 0, sizeof(void *) * TASKDEV_MAX);
570 printk(KERN_INFO "omapdsp: found %d task(s)\n", n);
577 devheapsz = sizeof(struct taskdev) * n;
578 taskheapsz = sizeof(struct dsptask) * n;
579 heap = kzalloc(devheapsz + taskheapsz, GFP_KERNEL);
583 taskheap = heap + devheapsz;
586 for (i = 0; i < n; i++) {
587 struct taskdev *dev = &devheap[i];
588 struct dsptask *task = &taskheap[i];
590 if ((ret = dsp_task_config(task, i)) < 0)
592 if ((ret = taskdev_init(dev, task->name, i)) < 0)
594 if ((ret = taskdev_attach_task(dev, task)) < 0)
597 printk(KERN_INFO "omapdsp: taskdev %s enabled.\n", dev->name);
603 static void dsp_task_unconfig(struct dsptask *task)
605 dsptask[task->tid] = NULL;
608 void dsp_task_unconfig_all(void)
612 struct dsptask *task;
614 for (minor = 0; minor < n_task; minor++) {
616 * taskdev[minor] can be NULL in case of
617 * configuration failure
620 taskdev_delete(minor);
622 for (; minor < TASKDEV_MAX; minor++) {
624 dsp_rmdev_minor(minor);
627 for (tid = 0; tid < n_task; tid++) {
629 * dsptask[tid] can be NULL in case of
630 * configuration failure
634 dsp_task_unconfig(task);
636 for (; tid < TASKDEV_MAX; tid++) {
640 * on-demand tasks should be deleted in
641 * rmdev_minor(), but just in case.
643 dsp_task_unconfig(task);
656 static struct device_driver dsptask_driver = {
661 u8 dsp_task_count(void)
666 int dsp_taskmod_busy(void)
670 unsigned int usecount;
672 for (minor = 0; minor < TASKDEV_MAX; minor++) {
673 dev = taskdev[minor];
676 if ((usecount = dev->usecount) > 0) {
677 printk("dsp_taskmod_busy(): %s: usecount=%d\n",
678 dev->name, usecount);
682 if ((dev->state & (TASKDEV_ST_ADDREQ |
683 TASKDEV_ST_DELREQ)) {
685 if (dev->state & TASKDEV_ST_ADDREQ) {
686 printk("dsp_taskmod_busy(): %s is in %s\n",
687 dev->name, devstate_name(dev->state));
695 * DSP task device file operations
697 static ssize_t dsp_task_read_wd_acv(struct file *file, char __user *buf,
698 size_t count, loff_t *ppos)
700 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
701 struct taskdev *dev = taskdev[minor];
706 } else if (count & 0x1) {
708 "omapdsp: odd count is illegal for DSP task device.\n");
712 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
715 if (fifo_empty(&dev->rcvdt.fifo)) {
716 long current_state = current->state;
717 DECLARE_WAITQUEUE(wait, current);
719 set_current_state(TASK_INTERRUPTIBLE);
720 add_wait_queue(&dev->read_wait_q, &wait);
721 if (fifo_empty(&dev->rcvdt.fifo)) /* last check */
723 set_current_state(current_state);
724 remove_wait_queue(&dev->read_wait_q, &wait);
725 if (fifo_empty(&dev->rcvdt.fifo)) {
727 if (signal_pending(current))
733 ret = copy_to_user_fm_fifo(buf, &dev->rcvdt.fifo, count);
736 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
740 static ssize_t dsp_task_read_bk_acv(struct file *file, char __user *buf,
741 size_t count, loff_t *ppos)
743 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
744 struct taskdev *dev = taskdev[minor];
745 struct rcvdt_bk_struct *rcvdt = &dev->rcvdt.bk;
750 } else if (count & 0x1) {
752 "omapdsp: odd count is illegal for DSP task device.\n");
754 } else if ((int)buf & 0x1) {
756 "omapdsp: buf should be word aligned for "
757 "dsp_task_read().\n");
761 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
764 if (ipblink_empty(&rcvdt->link)) {
766 DECLARE_WAITQUEUE(wait, current);
768 add_wait_queue(&dev->read_wait_q, &wait);
769 current_state = current->state;
770 set_current_state(TASK_INTERRUPTIBLE);
771 if (ipblink_empty(&rcvdt->link)) /* last check */
773 set_current_state(current_state);
774 remove_wait_queue(&dev->read_wait_q, &wait);
775 if (ipblink_empty(&rcvdt->link)) {
777 if (signal_pending(current))
783 /* copy from delayed IPBUF */
784 if (sndtyp_pvt(dev->task->ttyp)) {
786 if (!ipblink_empty(&rcvdt->link)) {
787 struct ipbuf_p *ipbp = dev->task->ipbuf_pvt_r;
788 unsigned char *base, *src;
791 if (dsp_mem_enable(ipbp) < 0) {
795 base = MKVIRT(ipbp->ah, ipbp->al);
796 bkcnt = ((unsigned long)ipbp->c) * 2 - rcvdt->rp;
797 if (dsp_address_validate(base, bkcnt,
798 "task %s read buffer",
799 dev->task->name) < 0) {
803 if (dsp_mem_enable(base) < 0) {
807 src = base + rcvdt->rp;
809 if (copy_to_user_dsp(buf, src, count)) {
816 if (copy_to_user_dsp(buf, src, bkcnt)) {
821 ipblink_del_pvt(&rcvdt->link);
822 release_ipbuf_pvt(ipbp);
826 dsp_mem_disable(src);
828 dsp_mem_disable(ipbp);
832 if (dsp_mem_enable_ipbuf() < 0) {
836 while (!ipblink_empty(&rcvdt->link)) {
839 struct ipbuf_head *ipb_h = bid_to_ipbuf(rcvdt->link.top);
841 src = ipb_h->p->d + rcvdt->rp;
842 bkcnt = ((unsigned long)ipb_h->p->c) * 2 - rcvdt->rp;
844 if (copy_to_user_dsp(buf, src, count)) {
852 if (copy_to_user_dsp(buf, src, bkcnt)) {
859 ipblink_del_top(&rcvdt->link);
865 dsp_mem_disable_ipbuf();
869 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
873 static ssize_t dsp_task_read_wd_psv(struct file *file, char __user *buf,
874 size_t count, loff_t *ppos)
876 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
877 struct taskdev *dev = taskdev[minor];
882 } else if (count & 0x1) {
884 "omapdsp: odd count is illegal for DSP task device.\n");
891 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
894 mbcompose_send_and_wait(WDREQ, dev->task->tid, 0, &dev->read_wait_q);
896 if (fifo_empty(&dev->rcvdt.fifo)) {
898 if (signal_pending(current))
903 ret = copy_to_user_fm_fifo(buf, &dev->rcvdt.fifo, count);
906 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
910 static ssize_t dsp_task_read_bk_psv(struct file *file, char __user *buf,
911 size_t count, loff_t *ppos)
913 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
914 struct taskdev *dev = taskdev[minor];
915 struct rcvdt_bk_struct *rcvdt = &dev->rcvdt.bk;
920 } else if (count & 0x1) {
922 "omapdsp: odd count is illegal for DSP task device.\n");
924 } else if ((int)buf & 0x1) {
926 "omapdsp: buf should be word aligned for "
927 "dsp_task_read().\n");
931 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
934 mbcompose_send_and_wait(BKREQ, dev->task->tid, count/2,
937 if (ipblink_empty(&rcvdt->link)) {
939 if (signal_pending(current))
945 * We will not receive more than requested count.
947 if (sndtyp_pvt(dev->task->ttyp)) {
949 struct ipbuf_p *ipbp = dev->task->ipbuf_pvt_r;
953 if (dsp_mem_enable(ipbp) < 0) {
957 src = MKVIRT(ipbp->ah, ipbp->al);
958 rcvcnt = ((unsigned long)ipbp->c) * 2;
959 if (dsp_address_validate(src, rcvcnt, "task %s read buffer",
960 dev->task->name) < 0) {
964 if (dsp_mem_enable(src) < 0) {
970 if (copy_to_user_dsp(buf, src, count)) {
974 ipblink_del_pvt(&rcvdt->link);
975 release_ipbuf_pvt(ipbp);
978 dsp_mem_disable(src);
980 dsp_mem_disable(ipbp);
983 struct ipbuf_head *ipb_h = bid_to_ipbuf(rcvdt->link.top);
986 if (dsp_mem_enable_ipbuf() < 0) {
990 rcvcnt = ((unsigned long)ipb_h->p->c) * 2;
993 if (copy_to_user_dsp(buf, ipb_h->p->d, count)) {
997 ipblink_del_top(&rcvdt->link);
1001 dsp_mem_disable_ipbuf();
1005 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
1009 static ssize_t dsp_task_write_wd(struct file *file, const char __user *buf,
1010 size_t count, loff_t *ppos)
1012 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1013 struct taskdev *dev = taskdev[minor];
1019 } else if (count & 0x1) {
1021 "omapdsp: odd count is illegal for DSP task device.\n");
1028 if (taskdev_lock_and_statelock_attached(dev, &dev->write_mutex))
1031 if (dev->wsz == 0) {
1033 DECLARE_WAITQUEUE(wait, current);
1035 add_wait_queue(&dev->write_wait_q, &wait);
1036 current_state = current->state;
1037 set_current_state(TASK_INTERRUPTIBLE);
1038 if (dev->wsz == 0) /* last check */
1040 set_current_state(current_state);
1041 remove_wait_queue(&dev->write_wait_q, &wait);
1042 if (dev->wsz == 0) {
1044 if (signal_pending(current))
1050 if (copy_from_user(&wd, buf, count)) {
1055 spin_lock(&dev->wsz_lock);
1056 if (mbcompose_send(WDSND, dev->task->tid, wd) < 0) {
1057 spin_unlock(&dev->wsz_lock);
1061 if (rcvtyp_acv(dev->task->ttyp))
1063 spin_unlock(&dev->wsz_lock);
1066 taskdev_unlock_and_stateunlock(dev, &dev->write_mutex);
1070 static ssize_t dsp_task_write_bk(struct file *file, const char __user *buf,
1071 size_t count, loff_t *ppos)
1073 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1074 struct taskdev *dev = taskdev[minor];
1079 } else if (count & 0x1) {
1081 "omapdsp: odd count is illegal for DSP task device.\n");
1083 } else if ((int)buf & 0x1) {
1085 "omapdsp: buf should be word aligned for "
1086 "dsp_task_write().\n");
1090 if (taskdev_lock_and_statelock_attached(dev, &dev->write_mutex))
1093 if (dev->wsz == 0) {
1095 DECLARE_WAITQUEUE(wait, current);
1097 add_wait_queue(&dev->write_wait_q, &wait);
1098 current_state = current->state;
1099 set_current_state(TASK_INTERRUPTIBLE);
1100 if (dev->wsz == 0) /* last check */
1102 set_current_state(current_state);
1103 remove_wait_queue(&dev->write_wait_q, &wait);
1104 if (dev->wsz == 0) {
1106 if (signal_pending(current))
1112 if (count > dev->wsz)
1115 if (rcvtyp_pvt(dev->task->ttyp)) {
1117 struct ipbuf_p *ipbp = dev->task->ipbuf_pvt_w;
1120 if (dsp_mem_enable(ipbp) < 0) {
1124 dst = MKVIRT(ipbp->ah, ipbp->al);
1125 if (dsp_address_validate(dst, count, "task %s write buffer",
1126 dev->task->name) < 0) {
1130 if (dsp_mem_enable(dst) < 0) {
1134 if (copy_from_user_dsp(dst, buf, count)) {
1139 ipbp->s = dev->task->tid;
1140 spin_lock(&dev->wsz_lock);
1141 if (mbcompose_send(BKSNDP, dev->task->tid, 0) == 0) {
1142 if (rcvtyp_acv(dev->task->ttyp))
1146 spin_unlock(&dev->wsz_lock);
1148 dsp_mem_disable(dst);
1150 dsp_mem_disable(ipbp);
1153 struct ipbuf_head *ipb_h;
1155 if (dsp_mem_enable_ipbuf() < 0) {
1159 if ((ipb_h = get_free_ipbuf(dev->task->tid)) == NULL)
1161 if (copy_from_user_dsp(ipb_h->p->d, buf, count)) {
1162 release_ipbuf(ipb_h);
1166 ipb_h->p->c = count/2;
1167 ipb_h->p->sa = dev->task->tid;
1168 spin_lock(&dev->wsz_lock);
1169 if (mbcompose_send(BKSND, dev->task->tid, ipb_h->bid) == 0) {
1170 if (rcvtyp_acv(dev->task->ttyp))
1173 ipb_bsycnt_inc(&ipbcfg);
1175 release_ipbuf(ipb_h);
1176 spin_unlock(&dev->wsz_lock);
1178 dsp_mem_disable_ipbuf();
1182 taskdev_unlock_and_stateunlock(dev, &dev->write_mutex);
1186 static unsigned int dsp_task_poll(struct file * file, poll_table * wait)
1188 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1189 struct taskdev *dev = taskdev[minor];
1190 struct dsptask *task = dev->task;
1191 unsigned int mask = 0;
1193 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
1195 poll_wait(file, &dev->read_wait_q, wait);
1196 poll_wait(file, &dev->write_wait_q, wait);
1197 if (sndtyp_psv(task->ttyp) ||
1198 (sndtyp_wd(task->ttyp) && !fifo_empty(&dev->rcvdt.fifo)) ||
1199 (sndtyp_bk(task->ttyp) && !ipblink_empty(&dev->rcvdt.bk.link)))
1200 mask |= POLLIN | POLLRDNORM;
1202 mask |= POLLOUT | POLLWRNORM;
1203 devstate_read_unlock(dev);
1208 static int dsp_tctl_issue(struct taskdev *dev, u16 cmd, int argc, u16 argv[])
1211 struct mb_exarg mbarg, *mbargp;
1219 * system reserved TCTL commands
1233 * user-defined TCTL commands
1235 else if (cmd < 0x8100) {
1236 /* 0x8000-0x80ff: no arg, non-interactive */
1239 } else if (cmd < 0x8200) {
1240 /* 0x8100-0x81ff: 1 arg, non-interactive */
1243 } else if (cmd < 0x9000) {
1244 /* 0x8200-0x8fff: reserved */
1246 } else if (cmd < 0x9100) {
1247 /* 0x9000-0x90ff: no arg, interactive */
1250 } else if (cmd < 0x9200) {
1251 /* 0x9100-0x91ff: 1 arg, interactive */
1255 /* 0x9200-0xffff: reserved */
1260 * if argc < 0, use tctl_argc as is.
1261 * if argc >= 0, check arg count.
1263 if ((argc >= 0) && (argc != tctl_argc))
1269 if (taskdev_lock_interruptible(dev, &dev->tctl_mutex))
1272 tid = dev->task->tid;
1273 if (tctl_argc > 0) {
1274 mbarg.argc = tctl_argc;
1282 dev->tctl_stat = -EINVAL;
1284 mbcompose_send_and_wait_exarg(TCTL, tid, cmd, mbargp,
1286 if (signal_pending(current)) {
1290 if ((ret = dev->tctl_stat) < 0) {
1291 printk(KERN_ERR "omapdsp: TCTL not responding.\n");
1295 mbcompose_send_exarg(TCTL, tid, cmd, mbargp);
1298 mutex_unlock(&dev->tctl_mutex);
1302 static int dsp_task_ioctl(struct inode *inode, struct file *file,
1303 unsigned int cmd, unsigned long arg)
1305 unsigned int minor = MINOR(inode->i_rdev);
1306 struct taskdev *dev = taskdev[minor];
1309 if (cmd < 0x10000) {
1313 mbargv[0] = arg & 0xffff;
1314 return dsp_tctl_issue(dev, cmd, -1, mbargv);
1317 /* non TCTL ioctls */
1320 case TASK_IOCTL_LOCK:
1321 ret = taskdev_lock(dev);
1324 case TASK_IOCTL_UNLOCK:
1325 ret = taskdev_unlock(dev);
1328 case TASK_IOCTL_BFLSH:
1329 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
1331 ret = taskdev_flush_buf(dev);
1332 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
1335 case TASK_IOCTL_SETBSZ:
1336 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
1338 ret = taskdev_set_fifosz(dev, arg);
1339 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
1342 case TASK_IOCTL_GETNAME:
1344 if (copy_to_user((void __user *)arg, dev->name,
1345 strlen(dev->name) + 1))
1357 static void dsp_task_mmap_open(struct vm_area_struct *vma)
1359 struct taskdev *dev = (struct taskdev *)vma->vm_private_data;
1360 struct dsptask *task;
1361 size_t len = vma->vm_end - vma->vm_start;
1363 BUG_ON(!(dev->state & TASKDEV_ST_ATTACHED));
1365 exmap_use(task->map_base, len);
1368 static void dsp_task_mmap_close(struct vm_area_struct *vma)
1370 struct taskdev *dev = (struct taskdev *)vma->vm_private_data;
1371 struct dsptask *task;
1372 size_t len = vma->vm_end - vma->vm_start;
1374 BUG_ON(!(dev->state & TASKDEV_ST_ATTACHED));
1376 exmap_unuse(task->map_base, len);
1380 * On demand page allocation is not allowed. The mapping area is defined by
1381 * corresponding DSP tasks.
1383 static struct page *dsp_task_mmap_nopage(struct vm_area_struct *vma,
1384 unsigned long address, int *type)
1386 return NOPAGE_SIGBUS;
1389 static struct vm_operations_struct dsp_task_vm_ops = {
1390 .open = dsp_task_mmap_open,
1391 .close = dsp_task_mmap_close,
1392 .nopage = dsp_task_mmap_nopage,
1395 static int dsp_task_mmap(struct file *filp, struct vm_area_struct *vma)
1398 unsigned long tmp_padr, tmp_vmadr, off;
1399 size_t req_len, tmp_len;
1400 unsigned int minor = MINOR(filp->f_dentry->d_inode->i_rdev);
1401 struct taskdev *dev = taskdev[minor];
1402 struct dsptask *task;
1405 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
1410 * Don't swap this area out
1411 * Don't dump this area to a core file
1413 vma->vm_flags |= VM_RESERVED | VM_IO;
1415 /* Do not cache this area */
1416 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1418 req_len = vma->vm_end - vma->vm_start;
1419 off = vma->vm_pgoff << PAGE_SHIFT;
1420 tmp_vmadr = vma->vm_start;
1421 tmp_vadr = task->map_base + off;
1423 tmp_padr = dsp_virt_to_phys(tmp_vadr, &tmp_len);
1424 if (tmp_padr == 0) {
1426 "omapdsp: task %s: illegal address "
1427 "for mmap: %p", task->name, tmp_vadr);
1428 /* partial mapping will be cleared in upper layer */
1432 if (tmp_len > req_len)
1436 "omapdsp: mmap info: "
1437 "vmadr = %08lx, padr = %08lx, len = %x\n",
1438 tmp_vmadr, tmp_padr, tmp_len);
1439 if (remap_pfn_range(vma, tmp_vmadr, tmp_padr >> PAGE_SHIFT,
1440 tmp_len, vma->vm_page_prot) != 0) {
1442 "omapdsp: task %s: remap_page_range() failed.\n",
1444 /* partial mapping will be cleared in upper layer */
1450 tmp_vmadr += tmp_len;
1451 tmp_vadr += tmp_len;
1454 vma->vm_ops = &dsp_task_vm_ops;
1455 vma->vm_private_data = dev;
1456 exmap_use(task->map_base, vma->vm_end - vma->vm_start);
1459 devstate_read_unlock(dev);
1463 static int dsp_task_open(struct inode *inode, struct file *file)
1465 unsigned int minor = MINOR(inode->i_rdev);
1466 struct taskdev *dev;
1469 if ((minor >= TASKDEV_MAX) || ((dev = taskdev[minor]) == NULL))
1473 mutex_lock(&dev->usecount_lock);
1474 down_write(&dev->state_sem);
1476 /* state can be NOTASK, ATTACHED/FREEZED, KILLING, GARBAGE or INVALID here. */
1477 switch (dev->state & TASKDEV_ST_STATE_MASK) {
1478 case TASKDEV_ST_NOTASK:
1480 case TASKDEV_ST_ATTACHED:
1483 case TASKDEV_ST_INVALID:
1484 up_write(&dev->state_sem);
1485 mutex_unlock(&dev->usecount_lock);
1488 case TASKDEV_ST_FREEZED:
1489 case TASKDEV_ST_KILLING:
1490 case TASKDEV_ST_GARBAGE:
1491 case TASKDEV_ST_DELREQ:
1492 /* on the kill process. wait until it becomes NOTASK. */
1493 up_write(&dev->state_sem);
1494 mutex_unlock(&dev->usecount_lock);
1495 if (devstate_write_lock(dev, TASKDEV_ST_NOTASK) < 0)
1497 devstate_write_unlock(dev);
1502 dev->state = TASKDEV_ST_ADDREQ;
1503 /* wake up twch daemon for tadd */
1505 up_write(&dev->state_sem);
1506 if (devstate_write_lock(dev, TASKDEV_ST_ATTACHED |
1507 TASKDEV_ST_ADDFAIL) < 0) {
1509 if (!devstate_write_lock_and_test(dev, TASKDEV_ST_ADDREQ)) {
1510 mutex_unlock(&dev->usecount_lock);
1511 /* out of control ??? */
1514 dev->state = TASKDEV_ST_NOTASK;
1518 if (dev->state & TASKDEV_ST_ADDFAIL) {
1519 printk(KERN_ERR "omapdsp: task attach failed for %s!\n",
1522 dev->state = TASKDEV_ST_NOTASK;
1528 #ifndef CONFIG_OMAP_DSP_TASK_MULTIOPEN
1529 if (dev->usecount > 0) {
1530 up_write(&dev->state_sem);
1535 proc_list_add(&dev->proc_list_lock, &dev->proc_list, current, file);
1536 file->f_op = &dev->fops;
1537 up_write(&dev->state_sem);
1538 mutex_unlock(&dev->usecount_lock);
1540 #ifdef DSP_PTE_FREE /* not used currently. */
1541 dsp_map_update(current);
1542 dsp_cur_users_add(current);
1543 #endif /* DSP_PTE_FREE */
1547 wake_up_interruptible_all(&dev->state_wait_q);
1548 up_write(&dev->state_sem);
1549 mutex_unlock(&dev->usecount_lock);
1553 static int dsp_task_release(struct inode *inode, struct file *file)
1555 unsigned int minor = MINOR(inode->i_rdev);
1556 struct taskdev *dev = taskdev[minor];
1558 #ifdef DSP_PTE_FREE /* not used currently. */
1559 dsp_cur_users_del(current);
1560 #endif /* DSP_PTE_FREE */
1562 if (has_taskdev_lock(dev))
1563 taskdev_unlock(dev);
1565 proc_list_del(&dev->proc_list_lock, &dev->proc_list, current, file);
1566 mutex_lock(&dev->usecount_lock);
1567 if (--dev->usecount > 0) {
1568 /* other processes are using this device. no state change. */
1569 mutex_unlock(&dev->usecount_lock);
1574 down_write(&dev->state_sem);
1576 /* state can be ATTACHED/FREEZED, KILLING or GARBAGE here. */
1577 switch (dev->state & TASKDEV_ST_STATE_MASK) {
1579 case TASKDEV_ST_KILLING:
1582 case TASKDEV_ST_GARBAGE:
1583 dev->state = TASKDEV_ST_NOTASK;
1584 wake_up_interruptible_all(&dev->state_wait_q);
1587 case TASKDEV_ST_ATTACHED:
1588 case TASKDEV_ST_FREEZED:
1589 if (is_dynamic_task(minor)) {
1590 dev->state = TASKDEV_ST_DELREQ;
1591 /* wake up twch daemon for tdel */
1598 up_write(&dev->state_sem);
1599 mutex_unlock(&dev->usecount_lock);
1606 int dsp_mkdev(char *name)
1608 struct taskdev *dev;
1610 unsigned char minor;
1613 if (dsp_cfgstat_get_stat() != CFGSTAT_READY) {
1614 printk(KERN_ERR "omapdsp: dsp has not been configured.\n");
1618 if (mutex_lock_interruptible(&devmgr_lock))
1622 for (minor = 0; minor < TASKDEV_MAX; minor++) {
1623 if (taskdev[minor] && !strcmp(taskdev[minor]->name, name)) {
1625 "omapdsp: task device name %s is already "
1632 /* find free minor number */
1633 for (minor = n_task; minor < TASKDEV_MAX; minor++) {
1634 if (taskdev[minor] == NULL)
1637 printk(KERN_ERR "omapdsp: Too many task devices.\n");
1642 if ((dev = kzalloc(sizeof(struct taskdev), GFP_KERNEL)) == NULL) {
1646 if ((status = taskdev_init(dev, name, minor)) < 0) {
1654 mutex_unlock(&devmgr_lock);
1658 int dsp_rmdev(char *name)
1660 unsigned char minor;
1664 if (dsp_cfgstat_get_stat() != CFGSTAT_READY) {
1665 printk(KERN_ERR "omapdsp: dsp has not been configured.\n");
1669 if (mutex_lock_interruptible(&devmgr_lock))
1672 /* find in dynamic devices */
1673 for (minor = n_task; minor < TASKDEV_MAX; minor++) {
1674 if (taskdev[minor] && !strcmp(taskdev[minor]->name, name))
1678 /* find in static devices */
1679 for (minor = 0; minor < n_task; minor++) {
1680 if (taskdev[minor] && !strcmp(taskdev[minor]->name, name)) {
1682 "omapdsp: task device %s is static.\n", name);
1688 printk(KERN_ERR "omapdsp: task device %s not found.\n", name);
1693 if ((status = dsp_rmdev_minor(minor)) < 0)
1696 mutex_unlock(&devmgr_lock);
1700 static int dsp_rmdev_minor(unsigned char minor)
1702 struct taskdev *dev = taskdev[minor];
1704 while (!down_write_trylock(&dev->state_sem)) {
1705 down_read(&dev->state_sem);
1706 if (dev->state & (TASKDEV_ST_ATTACHED |
1707 TASKDEV_ST_FREEZED)) {
1709 * task is working. kill it.
1710 * ATTACHED -> FREEZED can be changed under
1711 * down_read of state_sem..
1713 dev->state = TASKDEV_ST_FREEZED;
1714 wake_up_interruptible_all(&dev->read_wait_q);
1715 wake_up_interruptible_all(&dev->write_wait_q);
1716 wake_up_interruptible_all(&dev->tctl_wait_q);
1718 up_read(&dev->state_sem);
1722 switch (dev->state & TASKDEV_ST_STATE_MASK) {
1724 case TASKDEV_ST_NOTASK:
1728 case TASKDEV_ST_ATTACHED:
1729 case TASKDEV_ST_FREEZED:
1730 /* task is working. kill it. */
1731 dev->state = TASKDEV_ST_KILLING;
1732 up_write(&dev->state_sem);
1733 dsp_tdel_bh(dev, TDEL_KILL);
1736 case TASKDEV_ST_ADDREQ:
1737 /* open() is waiting. drain it. */
1738 dev->state = TASKDEV_ST_ADDFAIL;
1739 wake_up_interruptible_all(&dev->state_wait_q);
1742 case TASKDEV_ST_DELREQ:
1743 /* nobody is waiting. */
1744 dev->state = TASKDEV_ST_NOTASK;
1745 wake_up_interruptible_all(&dev->state_wait_q);
1748 case TASKDEV_ST_ADDING:
1749 case TASKDEV_ST_DELING:
1750 case TASKDEV_ST_KILLING:
1751 case TASKDEV_ST_GARBAGE:
1752 case TASKDEV_ST_ADDFAIL:
1753 /* transient state. wait for a moment. */
1758 up_write(&dev->state_sem);
1761 /* wait for some time and hope the state is settled */
1762 devstate_read_lock_timeout(dev, TASKDEV_ST_NOTASK, 5 * HZ);
1763 if (!(dev->state & TASKDEV_ST_NOTASK)) {
1765 "omapdsp: illegal device state (%s) on rmdev %s.\n",
1766 devstate_name(dev->state), dev->name);
1769 dev->state = TASKDEV_ST_INVALID;
1770 devstate_read_unlock(dev);
1772 taskdev_delete(minor);
1778 struct file_operations dsp_task_fops = {
1779 .owner = THIS_MODULE,
1780 .poll = dsp_task_poll,
1781 .ioctl = dsp_task_ioctl,
1782 .open = dsp_task_open,
1783 .release = dsp_task_release,
1786 static void dsptask_dev_release(struct device *dev)
1790 static int taskdev_init(struct taskdev *dev, char *name, unsigned char minor)
1792 taskdev[minor] = dev;
1794 spin_lock_init(&dev->proc_list_lock);
1795 INIT_LIST_HEAD(&dev->proc_list);
1796 init_waitqueue_head(&dev->read_wait_q);
1797 init_waitqueue_head(&dev->write_wait_q);
1798 init_waitqueue_head(&dev->tctl_wait_q);
1799 mutex_init(&dev->read_mutex);
1800 mutex_init(&dev->write_mutex);
1801 mutex_init(&dev->tctl_mutex);
1802 mutex_init(&dev->lock);
1803 spin_lock_init(&dev->wsz_lock);
1804 dev->tctl_ret = -EINVAL;
1807 strncpy(dev->name, name, TNM_LEN);
1808 dev->name[TNM_LEN-1] = '\0';
1809 dev->state = (minor < n_task) ? TASKDEV_ST_ATTACHED : TASKDEV_ST_NOTASK;
1811 mutex_init(&dev->usecount_lock);
1812 memcpy(&dev->fops, &dsp_task_fops, sizeof(struct file_operations));
1814 dev->dev.parent = dsp_device;
1815 dev->dev.bus = &dsptask_bus;
1816 sprintf(dev->dev.bus_id, "dsptask%d", minor);
1817 dev->dev.release = dsptask_dev_release;
1818 device_register(&dev->dev);
1819 device_create_file(&dev->dev, &dev_attr_devname);
1820 device_create_file(&dev->dev, &dev_attr_devstate);
1821 device_create_file(&dev->dev, &dev_attr_proc_list);
1822 class_device_create(dsp_task_class, NULL,
1823 MKDEV(OMAP_DSP_TASK_MAJOR, minor),
1824 NULL, "dsptask%d", minor);
1826 init_waitqueue_head(&dev->state_wait_q);
1827 init_rwsem(&dev->state_sem);
1832 static void taskdev_delete(unsigned char minor)
1834 struct taskdev *dev = taskdev[minor];
1838 device_remove_file(&dev->dev, &dev_attr_devname);
1839 device_remove_file(&dev->dev, &dev_attr_devstate);
1840 device_remove_file(&dev->dev, &dev_attr_proc_list);
1841 class_device_destroy(dsp_task_class, MKDEV(OMAP_DSP_TASK_MAJOR, minor));
1842 device_unregister(&dev->dev);
1843 proc_list_flush(&dev->proc_list_lock, &dev->proc_list);
1844 taskdev[minor] = NULL;
1847 static int taskdev_attach_task(struct taskdev *dev, struct dsptask *task)
1849 u16 ttyp = task->ttyp;
1853 sndtyp_wd(ttyp) ? dsp_task_read_wd_acv:
1854 /* sndtyp_bk */ dsp_task_read_bk_acv:
1856 sndtyp_wd(ttyp) ? dsp_task_read_wd_psv:
1857 /* sndtyp_bk */ dsp_task_read_bk_psv;
1858 if (sndtyp_wd(ttyp)) {
1862 fifosz = sndtyp_psv(ttyp) ? 2 : /* passive */
1864 if (init_fifo(&dev->rcvdt.fifo, fifosz) < 0) {
1866 "omapdsp: unable to allocate receive buffer. "
1867 "(%d bytes for %s)\n", fifosz, dev->name);
1872 INIT_IPBLINK(&dev->rcvdt.bk.link);
1873 dev->rcvdt.bk.rp = 0;
1877 rcvtyp_wd(ttyp) ? dsp_task_write_wd:
1878 /* rcvbyp_bk */ dsp_task_write_bk;
1879 dev->wsz = rcvtyp_acv(ttyp) ? 0 : /* active */
1880 rcvtyp_wd(ttyp) ? 2 : /* passive word */
1881 ipbcfg.lsz*2; /* passive block */
1883 if (task->map_length)
1884 dev->fops.mmap = dsp_task_mmap;
1886 device_create_file(&dev->dev, &dev_attr_taskname);
1887 device_create_file(&dev->dev, &dev_attr_ttyp);
1888 if (sndtyp_wd(ttyp)) {
1889 device_create_file(&dev->dev, &dev_attr_fifosz);
1890 device_create_file(&dev->dev, &dev_attr_fifocnt);
1892 device_create_file(&dev->dev, &dev_attr_ipblink);
1893 device_create_file(&dev->dev, &dev_attr_wsz);
1894 if (task->map_length)
1895 device_create_file(&dev->dev, &dev_attr_mmap);
1903 static void taskdev_detach_task(struct taskdev *dev)
1905 u16 ttyp = dev->task->ttyp;
1907 device_remove_file(&dev->dev, &dev_attr_taskname);
1908 device_remove_file(&dev->dev, &dev_attr_ttyp);
1909 if (sndtyp_wd(ttyp)) {
1910 device_remove_file(&dev->dev, &dev_attr_fifosz);
1911 device_remove_file(&dev->dev, &dev_attr_fifocnt);
1913 device_remove_file(&dev->dev, &dev_attr_ipblink);
1914 device_remove_file(&dev->dev, &dev_attr_wsz);
1915 if (dev->task->map_length)
1916 device_remove_file(&dev->dev, &dev_attr_mmap);
1918 dev->fops.read = NULL;
1919 taskdev_flush_buf(dev);
1920 if (sndtyp_wd(ttyp))
1921 free_fifo(&dev->rcvdt.fifo);
1923 dev->fops.write = NULL;
1926 printk(KERN_INFO "omapdsp: taskdev %s disabled.\n", dev->name);
1931 * tadd / tdel / tkill
1933 static int dsp_tadd(struct taskdev *dev, dsp_long_t adr)
1935 struct dsptask *task;
1936 struct mb_exarg arg;
1937 u8 tid, tid_response;
1941 if (!devstate_write_lock_and_test(dev, TASKDEV_ST_ADDREQ)) {
1943 "omapdsp: taskdev %s is not requesting for tadd. "
1944 "(state is %s)\n", dev->name, devstate_name(dev->state));
1947 dev->state = TASKDEV_ST_ADDING;
1948 devstate_write_unlock(dev);
1950 if (adr == TADD_ABORTADR) {
1951 /* aborting tadd intentionally */
1952 printk(KERN_INFO "omapdsp: tadd address is ABORTADR.\n");
1955 if (adr >= DSPSPACE_SIZE) {
1957 "omapdsp: illegal address 0x%08x for tadd\n", adr);
1962 adr >>= 1; /* word address */
1963 argv[0] = adr >> 16; /* addrh */
1964 argv[1] = adr & 0xffff; /* addrl */
1966 if (mutex_lock_interruptible(&cfg_lock)) {
1971 cfg_cmd = MBOX_CMD_DSP_TADD;
1976 if (dsp_mem_sync_inc() < 0) {
1977 printk(KERN_ERR "omapdsp: memory sync failed!\n");
1981 mbcompose_send_and_wait_exarg(TADD, 0, 0, &arg, &cfg_wait_q);
1986 mutex_unlock(&cfg_lock);
1988 if (tid == TID_ANON) {
1989 printk(KERN_ERR "omapdsp: tadd failed!\n");
1993 if ((tid < n_task) || dsptask[tid]) {
1994 printk(KERN_ERR "omapdsp: illegal tid (%d)!\n", tid);
1998 if ((task = kzalloc(sizeof(struct dsptask), GFP_KERNEL)) == NULL) {
2003 if ((ret = dsp_task_config(task, tid)) < 0)
2006 if (strcmp(dev->name, task->name)) {
2008 "omapdsp: task name (%s) doesn't match with "
2009 "device name (%s).\n", task->name, dev->name);
2014 if ((ret = taskdev_attach_task(dev, task)) < 0)
2017 dsp_task_init(task);
2018 printk(KERN_INFO "omapdsp: taskdev %s enabled.\n", dev->name);
2019 dev->state = TASKDEV_ST_ATTACHED;
2020 wake_up_interruptible_all(&dev->state_wait_q);
2027 printk(KERN_ERR "omapdsp: deleting the task...\n");
2029 dev->state = TASKDEV_ST_DELING;
2031 if (mutex_lock_interruptible(&cfg_lock)) {
2032 printk(KERN_ERR "omapdsp: aborting tdel process. "
2033 "DSP side could be corrupted.\n");
2037 cfg_cmd = MBOX_CMD_DSP_TDEL;
2038 mbcompose_send_and_wait(TDEL, tid, TDEL_KILL, &cfg_wait_q);
2039 tid_response = cfg_tid;
2042 mutex_unlock(&cfg_lock);
2044 if (tid_response != tid)
2045 printk(KERN_ERR "omapdsp: tdel failed. "
2046 "DSP side could be corrupted.\n");
2049 dev->state = TASKDEV_ST_ADDFAIL;
2050 wake_up_interruptible_all(&dev->state_wait_q);
2054 int dsp_tadd_minor(unsigned char minor, dsp_long_t adr)
2056 struct taskdev *dev;
2060 if (mutex_lock_interruptible(&devmgr_lock))
2063 if ((minor >= TASKDEV_MAX) || ((dev = taskdev[minor]) == NULL)) {
2065 "omapdsp: no task device with minor %d\n", minor);
2070 if ((status = dsp_tadd(dev, adr)) < 0)
2074 mutex_unlock(&devmgr_lock);
2078 static int dsp_tdel(struct taskdev *dev)
2080 if (!devstate_write_lock_and_test(dev, TASKDEV_ST_DELREQ)) {
2082 "omapdsp: taskdev %s is not requesting for tdel. "
2083 "(state is %s)\n", dev->name, devstate_name(dev->state));
2086 dev->state = TASKDEV_ST_DELING;
2087 devstate_write_unlock(dev);
2089 return dsp_tdel_bh(dev, TDEL_SAFE);
2092 int dsp_tdel_minor(unsigned char minor)
2094 struct taskdev *dev;
2098 if (mutex_lock_interruptible(&devmgr_lock))
2101 if ((minor >= TASKDEV_MAX) || ((dev = taskdev[minor]) == NULL)) {
2103 "omapdsp: no task device with minor %d\n", minor);
2109 if ((status = dsp_tdel(dev)) < 0)
2113 mutex_unlock(&devmgr_lock);
2117 static int dsp_tkill(struct taskdev *dev)
2119 while (!down_write_trylock(&dev->state_sem)) {
2120 if (!devstate_read_lock_and_test(dev, (TASKDEV_ST_ATTACHED |
2121 TASKDEV_ST_FREEZED))) {
2123 "omapdsp: task has not been attached for "
2124 "taskdev %s\n", dev->name);
2127 /* ATTACHED -> FREEZED can be changed under read semaphore. */
2128 dev->state = TASKDEV_ST_FREEZED;
2129 wake_up_interruptible_all(&dev->read_wait_q);
2130 wake_up_interruptible_all(&dev->write_wait_q);
2131 wake_up_interruptible_all(&dev->tctl_wait_q);
2132 devstate_read_unlock(dev);
2136 if (!(dev->state & (TASKDEV_ST_ATTACHED |
2137 TASKDEV_ST_FREEZED))) {
2139 "omapdsp: task has not been attached for taskdev %s\n",
2141 devstate_write_unlock(dev);
2144 if (!is_dynamic_task(dev->task->tid)) {
2145 printk(KERN_ERR "omapdsp: task %s is not a dynamic task.\n",
2147 devstate_write_unlock(dev);
2150 dev->state = TASKDEV_ST_KILLING;
2151 devstate_write_unlock(dev);
2153 return dsp_tdel_bh(dev, TDEL_KILL);
2156 int dsp_tkill_minor(unsigned char minor)
2158 struct taskdev *dev;
2162 if (mutex_lock_interruptible(&devmgr_lock))
2165 if ((minor >= TASKDEV_MAX) || ((dev = taskdev[minor]) == NULL)) {
2167 "omapdsp: no task device with minor %d\n", minor);
2173 if ((status = dsp_tkill(dev)) < 0)
2177 mutex_unlock(&devmgr_lock);
2181 static int dsp_tdel_bh(struct taskdev *dev, u16 type)
2183 struct dsptask *task;
2184 u8 tid, tid_response;
2189 if (mutex_lock_interruptible(&cfg_lock)) {
2190 if (type == TDEL_SAFE) {
2191 dev->state = TASKDEV_ST_DELREQ;
2194 tid_response = TID_ANON;
2200 cfg_cmd = MBOX_CMD_DSP_TDEL;
2201 mbcompose_send_and_wait(TDEL, tid, type, &cfg_wait_q);
2202 tid_response = cfg_tid;
2205 mutex_unlock(&cfg_lock);
2208 taskdev_detach_task(dev);
2209 dsp_task_unconfig(task);
2212 if (tid_response != tid) {
2213 printk(KERN_ERR "omapdsp: %s failed!\n",
2214 (type == TDEL_SAFE) ? "tdel" : "tkill");
2217 down_write(&dev->state_sem);
2218 dev->state = (dev->usecount > 0) ? TASKDEV_ST_GARBAGE :
2220 wake_up_interruptible_all(&dev->state_wait_q);
2221 up_write(&dev->state_sem);
2229 long taskdev_state_stale(unsigned char minor)
2231 if (taskdev[minor]) {
2232 long state = taskdev[minor]->state;
2233 taskdev[minor]->state |= TASKDEV_ST_STALE;
2236 return TASKDEV_ST_NOTASK;
2240 * functions called from mailbox interrupt routine
2242 void mbox_wdsnd(struct mbcmd *mb)
2245 struct dsptask *task = dsptask[tid];
2247 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2248 printk(KERN_ERR "mbox: WDSND with illegal tid! %d\n", tid);
2251 if (sndtyp_bk(task->ttyp)) {
2253 "mbox: WDSND from block sending task! (task%d)\n", tid);
2256 if (sndtyp_psv(task->ttyp) &&
2257 !waitqueue_active(&task->dev->read_wait_q)) {
2259 "mbox: WDSND from passive sending task (task%d) "
2260 "without request!\n", tid);
2264 write_word_to_fifo(&task->dev->rcvdt.fifo, mb->data);
2265 wake_up_interruptible(&task->dev->read_wait_q);
2268 void mbox_wdreq(struct mbcmd *mb)
2271 struct dsptask *task = dsptask[tid];
2272 struct taskdev *dev;
2274 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2275 printk(KERN_ERR "mbox: WDREQ with illegal tid! %d\n", tid);
2278 if (rcvtyp_psv(task->ttyp)) {
2280 "mbox: WDREQ from passive receiving task! (task%d)\n",
2286 spin_lock(&dev->wsz_lock);
2288 spin_unlock(&dev->wsz_lock);
2289 wake_up_interruptible(&dev->write_wait_q);
2292 void mbox_bksnd(struct mbcmd *mb)
2296 struct dsptask *task = dsptask[tid];
2297 struct ipbuf_head *ipb_h;
2300 if (bid >= ipbcfg.ln) {
2301 printk(KERN_ERR "mbox: BKSND with illegal bid! %d\n", bid);
2304 ipb_h = bid_to_ipbuf(bid);
2305 ipb_bsycnt_dec(&ipbcfg);
2306 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2307 printk(KERN_ERR "mbox: BKSND with illegal tid! %d\n", tid);
2308 goto unuse_ipbuf_out;
2310 if (sndtyp_wd(task->ttyp)) {
2312 "mbox: BKSND from word sending task! (task%d)\n", tid);
2313 goto unuse_ipbuf_out;
2315 if (sndtyp_pvt(task->ttyp)) {
2317 "mbox: BKSND from private sending task! (task%d)\n", tid);
2318 goto unuse_ipbuf_out;
2320 if (sync_with_dsp(&ipb_h->p->sd, tid, 10) < 0) {
2321 printk(KERN_ERR "mbox: BKSND - IPBUF sync failed!\n");
2325 /* should be done in DSP, but just in case. */
2326 ipb_h->p->next = BID_NULL;
2329 if (cnt > ipbcfg.lsz) {
2330 printk(KERN_ERR "mbox: BKSND cnt(%d) > ipbuf line size(%d)!\n",
2332 goto unuse_ipbuf_out;
2336 /* 0-byte send from DSP */
2337 unuse_ipbuf_nowait(ipb_h);
2340 ipblink_add_tail(&task->dev->rcvdt.bk.link, bid);
2341 /* we keep coming bid and return alternative line to DSP. */
2345 wake_up_interruptible(&task->dev->read_wait_q);
2349 unuse_ipbuf_nowait(ipb_h);
2353 void mbox_bkreq(struct mbcmd *mb)
2357 struct dsptask *task = dsptask[tid];
2358 struct taskdev *dev;
2360 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2361 printk(KERN_ERR "mbox: BKREQ with illegal tid! %d\n", tid);
2364 if (rcvtyp_wd(task->ttyp)) {
2366 "mbox: BKREQ from word receiving task! (task%d)\n", tid);
2369 if (rcvtyp_pvt(task->ttyp)) {
2371 "mbox: BKREQ from private receiving task! (task%d)\n",
2375 if (rcvtyp_psv(task->ttyp)) {
2377 "mbox: BKREQ from passive receiving task! (task%d)\n",
2383 spin_lock(&dev->wsz_lock);
2385 spin_unlock(&dev->wsz_lock);
2386 wake_up_interruptible(&dev->write_wait_q);
2389 void mbox_bkyld(struct mbcmd *mb)
2392 struct ipbuf_head *ipb_h;
2394 if (bid >= ipbcfg.ln) {
2395 printk(KERN_ERR "mbox: BKYLD with illegal bid! %d\n", bid);
2398 ipb_h = bid_to_ipbuf(bid);
2400 /* should be done in DSP, but just in case. */
2401 ipb_h->p->next = BID_NULL;
2403 /* we don't need to sync with DSP */
2404 ipb_bsycnt_dec(&ipbcfg);
2405 release_ipbuf(ipb_h);
2408 void mbox_bksndp(struct mbcmd *mb)
2411 struct dsptask *task = dsptask[tid];
2412 struct ipbuf_p *ipbp;
2414 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2415 printk(KERN_ERR "mbox: BKSNDP with illegal tid! %d\n", tid);
2418 if (sndtyp_wd(task->ttyp)) {
2420 "mbox: BKSNDP from word sending task! (task%d)\n", tid);
2423 if (sndtyp_gbl(task->ttyp)) {
2425 "mbox: BKSNDP from non-private sending task! (task%d)\n",
2431 * we should not have delayed block at this point
2432 * because read() routine releases the lock of the buffer and
2433 * until then DSP can't send next data.
2436 ipbp = task->ipbuf_pvt_r;
2437 if (sync_with_dsp(&ipbp->s, tid, 10) < 0) {
2438 printk(KERN_ERR "mbox: BKSNDP - IPBUF sync failed!\n");
2441 printk(KERN_DEBUG "mbox: ipbuf_pvt_r->a = 0x%08lx\n",
2442 MKLONG(ipbp->ah, ipbp->al));
2443 ipblink_add_pvt(&task->dev->rcvdt.bk.link);
2444 wake_up_interruptible(&task->dev->read_wait_q);
2447 void mbox_bkreqp(struct mbcmd *mb)
2450 struct dsptask *task = dsptask[tid];
2451 struct taskdev *dev;
2452 struct ipbuf_p *ipbp;
2454 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2455 printk(KERN_ERR "mbox: BKREQP with illegal tid! %d\n", tid);
2458 if (rcvtyp_wd(task->ttyp)) {
2460 "mbox: BKREQP from word receiving task! (task%d)\n", tid);
2463 if (rcvtyp_gbl(task->ttyp)) {
2465 "mbox: BKREQP from non-private receiving task! (task%d)\n", tid);
2468 if (rcvtyp_psv(task->ttyp)) {
2470 "mbox: BKREQP from passive receiving task! (task%d)\n", tid);
2474 ipbp = task->ipbuf_pvt_w;
2475 if (sync_with_dsp(&ipbp->s, TID_FREE, 10) < 0) {
2476 printk(KERN_ERR "mbox: BKREQP - IPBUF sync failed!\n");
2479 printk(KERN_DEBUG "mbox: ipbuf_pvt_w->a = 0x%08lx\n",
2480 MKLONG(ipbp->ah, ipbp->al));
2482 spin_lock(&dev->wsz_lock);
2483 dev->wsz = ipbp->c*2;
2484 spin_unlock(&dev->wsz_lock);
2485 wake_up_interruptible(&dev->write_wait_q);
2488 void mbox_tctl(struct mbcmd *mb)
2491 struct dsptask *task = dsptask[tid];
2493 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2494 printk(KERN_ERR "mbox: TCTL with illegal tid! %d\n", tid);
2498 if (!waitqueue_active(&task->dev->tctl_wait_q)) {
2499 printk(KERN_WARNING "mbox: unexpected TCTL from DSP!\n");
2503 task->dev->tctl_stat = mb->data;
2504 wake_up_interruptible(&task->dev->tctl_wait_q);
2507 void mbox_tcfg(struct mbcmd *mb)
2510 struct dsptask *task = dsptask[tid];
2515 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2516 printk(KERN_ERR "mbox: TCFG with illegal tid! %d\n", tid);
2519 if ((task->state != TASK_ST_CFGREQ) || (cfg_cmd != MBOX_CMD_DSP_TCFG)) {
2520 printk(KERN_WARNING "mbox: unexpected TCFG from DSP!\n");
2524 if (dsp_mem_enable(ipbuf_sys_da) < 0) {
2525 printk(KERN_ERR "mbox: TCFG - ipbuf_sys_da read failed!\n");
2526 dsp_mem_disable(ipbuf_sys_da);
2529 if (sync_with_dsp(&ipbuf_sys_da->s, tid, 10) < 0) {
2530 printk(KERN_ERR "mbox: TCFG - IPBUF sync failed!\n");
2531 dsp_mem_disable(ipbuf_sys_da);
2536 * read configuration data on system IPBUF
2538 buf = ipbuf_sys_da->d;
2539 task->ttyp = buf[0];
2540 task->ipbuf_pvt_r = MKVIRT(buf[1], buf[2]);
2541 task->ipbuf_pvt_w = MKVIRT(buf[3], buf[4]);
2542 task->map_base = MKVIRT(buf[5], buf[6]);
2543 task->map_length = MKLONG(buf[7], buf[8]) << 1; /* word -> byte */
2544 tnm = MKVIRT(buf[9], buf[10]);
2545 release_ipbuf_pvt(ipbuf_sys_da);
2546 dsp_mem_disable(ipbuf_sys_da);
2549 * copy task name string
2551 if (dsp_address_validate(tnm, TNM_LEN, "task name buffer") < 0) {
2552 task->name[0] = '\0';
2556 for (i = 0; i < TNM_LEN-1; i++) {
2557 /* avoiding byte access */
2559 task->name[i] = tmp & 0x00ff;
2563 task->name[TNM_LEN-1] = '\0';
2565 task->state = TASK_ST_READY;
2567 wake_up_interruptible(&cfg_wait_q);
2570 void mbox_tadd(struct mbcmd *mb)
2574 if ((!waitqueue_active(&cfg_wait_q)) || (cfg_cmd != MBOX_CMD_DSP_TADD)) {
2575 printk(KERN_WARNING "mbox: unexpected TADD from DSP!\n");
2579 wake_up_interruptible(&cfg_wait_q);
2582 void mbox_tdel(struct mbcmd *mb)
2586 if ((!waitqueue_active(&cfg_wait_q)) || (cfg_cmd != MBOX_CMD_DSP_TDEL)) {
2587 printk(KERN_WARNING "mbox: unexpected TDEL from DSP!\n");
2591 wake_up_interruptible(&cfg_wait_q);
2594 void mbox_err_fatal(u8 tid)
2596 struct dsptask *task = dsptask[tid];
2597 struct taskdev *dev;
2599 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2600 printk(KERN_ERR "mbox: FATAL ERR with illegal tid! %d\n", tid);
2604 /* wake up waiting processes */
2606 wake_up_interruptible_all(&dev->read_wait_q);
2607 wake_up_interruptible_all(&dev->write_wait_q);
2608 wake_up_interruptible_all(&dev->tctl_wait_q);
2611 static u16 *dbg_buf;
2612 static u16 dbg_buf_sz, dbg_line_sz;
2615 int dsp_dbg_config(u16 *buf, u16 sz, u16 lsz)
2617 #ifdef OLD_BINARY_SUPPORT
2618 if ((mbox_revision == MBREV_3_0) || (mbox_revision == MBREV_3_2)) {
2627 if (dsp_address_validate(buf, sz, "debug buffer") < 0)
2632 "omapdsp: dbg_buf lsz (%d) is greater than its "
2633 "buffer size (%d)\n", lsz, sz);
2645 void dsp_dbg_stop(void)
2650 #ifdef OLD_BINARY_SUPPORT
2651 static void mbox_dbg_old(struct mbcmd *mb);
2654 void mbox_dbg(struct mbcmd *mb)
2658 char s[80], *s_end = &s[79], *p;
2662 #ifdef OLD_BINARY_SUPPORT
2663 if ((mbox_revision == MBREV_3_0) || (mbox_revision == MBREV_3_2)) {
2669 if (((tid >= TASKDEV_MAX) || (dsptask[tid] == NULL)) &&
2670 (tid != TID_ANON)) {
2671 printk(KERN_ERR "mbox: DBG with illegal tid! %d\n", tid);
2674 if (dbg_buf == NULL) {
2675 printk(KERN_ERR "mbox: DBG command received, but "
2676 "dbg_buf has not been configured yet.\n");
2680 if (dsp_mem_enable(dbg_buf) < 0)
2683 src = &dbg_buf[dbg_rp];
2685 for (i = 0; i < cnt; i++) {
2688 * Be carefull that dbg_buf should not be read with
2689 * 1-byte access since it might be placed in DARAM/SARAM
2690 * and it can cause unexpected byteswap.
2692 * *(p++) = *(src++) & 0xff;
2693 * causes 1-byte access!
2696 *(p++) = tmp & 0xff;
2697 if (*(p-1) == '\n') {
2699 printk(KERN_INFO "%s", s);
2705 printk(KERN_INFO "%s\n", s);
2712 printk(KERN_INFO "%s\n", s);
2714 if ((dbg_rp += cnt + 1) > dbg_buf_sz - dbg_line_sz)
2717 dsp_mem_disable(dbg_buf);
2720 #ifdef OLD_BINARY_SUPPORT
2721 static void mbox_dbg_old(struct mbcmd *mb)
2724 char s[80], *s_end = &s[79], *p;
2730 if (((tid >= TASKDEV_MAX) || (dsptask[tid] == NULL)) &&
2731 (tid != TID_ANON)) {
2732 printk(KERN_ERR "mbox: DBG with illegal tid! %d\n", tid);
2735 if (dsp_mem_enable(ipbuf_sys_da) < 0) {
2736 printk(KERN_ERR "mbox: DBG - ipbuf_sys_da read failed!\n");
2739 if (sync_with_dsp(&ipbuf_sys_da->s, tid, 10) < 0) {
2740 printk(KERN_ERR "mbox: DBG - IPBUF sync failed!\n");
2743 buf = ipbuf_sys_da->d;
2745 src = MKVIRT(buf[1], buf[2]);
2746 if (dsp_address_validate(src, cnt, "dbg buffer") < 0)
2749 if (dsp_mem_enable(src) < 0)
2753 for (i = 0; i < cnt; i++) {
2756 * Be carefull that ipbuf should not be read with
2757 * 1-byte access since it might be placed in DARAM/SARAM
2758 * and it can cause unexpected byteswap.
2760 * *(p++) = *(src++) & 0xff;
2761 * causes 1-byte access!
2764 *(p++) = tmp & 0xff;
2765 if (*(p-1) == '\n') {
2767 printk(KERN_INFO "%s", s);
2773 printk(KERN_INFO "%s\n", s);
2780 printk(KERN_INFO "%s\n", s);
2783 dsp_mem_disable(src);
2785 release_ipbuf_pvt(ipbuf_sys_da);
2787 dsp_mem_disable(ipbuf_sys_da);
2789 #endif /* OLD_BINARY_SUPPORT */
2792 * sysfs files: for each device
2796 static ssize_t devname_show(struct device *d, struct device_attribute *attr,
2799 return sprintf(buf, "%s\n", to_taskdev(d)->name);
2803 static ssize_t devstate_show(struct device *d, struct device_attribute *attr,
2806 return sprintf(buf, "%s\n", devstate_name(to_taskdev(d)->state));
2810 static ssize_t proc_list_show(struct device *d, struct device_attribute *attr,
2813 struct taskdev *dev;
2814 struct proc_list *pl;
2817 dev = to_taskdev(d);
2818 spin_lock(&dev->proc_list_lock);
2819 list_for_each_entry(pl, &dev->proc_list, list_head) {
2820 /* need to lock tasklist_lock before calling
2821 * find_task_by_pid_type. */
2822 if (find_task_by_pid_type(PIDTYPE_PID, pl->pid) != NULL)
2823 len += sprintf(buf + len, "%d\n", pl->pid);
2824 read_unlock(&tasklist_lock);
2826 spin_unlock(&dev->proc_list_lock);
2832 static ssize_t taskname_show(struct device *d, struct device_attribute *attr,
2835 struct taskdev *dev = to_taskdev(d);
2838 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
2841 len = sprintf(buf, "%s\n", dev->task->name);
2843 devstate_read_unlock(dev);
2848 static ssize_t ttyp_show(struct device *d, struct device_attribute *attr,
2851 struct taskdev *dev = to_taskdev(d);
2855 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
2858 ttyp = dev->task->ttyp;
2859 len += sprintf(buf + len, "0x%04x\n", ttyp);
2860 len += sprintf(buf + len, "%s %s send\n",
2861 (sndtyp_acv(ttyp)) ? "active" :
2863 (sndtyp_wd(ttyp)) ? "word" :
2864 (sndtyp_pvt(ttyp)) ? "private block" :
2866 len += sprintf(buf + len, "%s %s receive\n",
2867 (rcvtyp_acv(ttyp)) ? "active" :
2869 (rcvtyp_wd(ttyp)) ? "word" :
2870 (rcvtyp_pvt(ttyp)) ? "private block" :
2873 devstate_read_unlock(dev);
2878 static ssize_t fifosz_show(struct device *d, struct device_attribute *attr,
2881 struct fifo_struct *fifo = &to_taskdev(d)->rcvdt.fifo;
2882 return sprintf(buf, "%d\n", fifo->sz);
2885 static int fifosz_store(struct device *d, struct device_attribute *attr,
2886 const char *buf, size_t count)
2888 struct taskdev *dev = to_taskdev(d);
2889 unsigned long fifosz;
2892 fifosz = simple_strtol(buf, NULL, 10);
2893 ret = taskdev_set_fifosz(dev, fifosz);
2895 return (ret < 0) ? ret : strlen(buf);
2899 static ssize_t fifocnt_show(struct device *d, struct device_attribute *attr,
2902 struct fifo_struct *fifo = &to_taskdev(d)->rcvdt.fifo;
2903 return sprintf(buf, "%d\n", fifo->cnt);
2907 static __inline__ char *bid_name(u16 bid)
2917 sprintf(s, "%d", bid);
2922 static ssize_t ipblink_show(struct device *d, struct device_attribute *attr,
2925 struct rcvdt_bk_struct *rcvdt = &to_taskdev(d)->rcvdt.bk;
2928 spin_lock(&rcvdt->link.lock);
2929 len = sprintf(buf, "top %s\ntail %s\n",
2930 bid_name(rcvdt->link.top), bid_name(rcvdt->link.tail));
2931 spin_unlock(&rcvdt->link.lock);
2937 static ssize_t wsz_show(struct device *d, struct device_attribute *attr,
2940 return sprintf(buf, "%d\n", to_taskdev(d)->wsz);
2944 static ssize_t mmap_show(struct device *d, struct device_attribute *attr,
2947 struct dsptask *task = to_taskdev(d)->task;
2948 return sprintf(buf, "0x%p 0x%x\n", task->map_base, task->map_length);
2952 * called from ipbuf_show()
2954 int ipbuf_is_held(u8 tid, u16 bid)
2956 struct dsptask *task = dsptask[tid];
2957 struct ipblink *link;
2964 link = &task->dev->rcvdt.bk.link;
2965 spin_lock(&link->lock);
2966 ipblink_for_each(b, link) {
2967 if (b == bid) { /* found */
2972 spin_unlock(&link->lock);
2977 int __init dsp_taskmod_init(void)
2981 memset(taskdev, 0, sizeof(void *) * TASKDEV_MAX);
2982 memset(dsptask, 0, sizeof(void *) * TASKDEV_MAX);
2984 retval = register_chrdev(OMAP_DSP_TASK_MAJOR, "dsptask",
2988 "omapdsp: failed to register task device: %d\n", retval);
2992 bus_register(&dsptask_bus);
2993 retval = driver_register(&dsptask_driver);
2996 "omapdsp: failed to register DSP task driver: %d\n",
2998 bus_unregister(&dsptask_bus);
2999 unregister_chrdev(OMAP_DSP_TASK_MAJOR, "dsptask");
3002 dsp_task_class = class_create(THIS_MODULE, "dsptask");
3007 void dsp_taskmod_exit(void)
3009 class_destroy(dsp_task_class);
3010 driver_unregister(&dsptask_driver);
3011 bus_unregister(&dsptask_bus);
3012 unregister_chrdev(OMAP_DSP_TASK_MAJOR, "dsptask");