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 dev; /* Generic device interface */
114 struct rw_semaphore state_sem;
115 wait_queue_head_t state_wait_q;
116 struct mutex usecount_lock;
117 unsigned int usecount;
119 struct file_operations fops;
120 spinlock_t proc_list_lock;
121 struct list_head proc_list;
122 struct dsptask *task;
125 wait_queue_head_t read_wait_q;
126 struct mutex read_mutex;
128 struct fifo_struct fifo; /* for active word */
129 struct rcvdt_bk_struct bk;
133 wait_queue_head_t write_wait_q;
134 struct mutex write_mutex;
139 wait_queue_head_t tctl_wait_q;
140 struct mutex tctl_mutex;
142 int tctl_ret; /* return value for tctl_show() */
149 #define to_taskdev(n) container_of(n, struct taskdev, dev)
163 struct ipbuf_p *ipbuf_pvt_r;
166 struct ipbuf_p *ipbuf_pvt_w;
173 #define sndtyp_acv(ttyp) ((ttyp) & TTYP_ASND)
174 #define sndtyp_psv(ttyp) (!((ttyp) & TTYP_ASND))
175 #define sndtyp_bk(ttyp) ((ttyp) & TTYP_BKDM)
176 #define sndtyp_wd(ttyp) (!((ttyp) & TTYP_BKDM))
177 #define sndtyp_pvt(ttyp) ((ttyp) & TTYP_PVDM)
178 #define sndtyp_gbl(ttyp) (!((ttyp) & TTYP_PVDM))
179 #define rcvtyp_acv(ttyp) ((ttyp) & TTYP_ARCV)
180 #define rcvtyp_psv(ttyp) (!((ttyp) & TTYP_ARCV))
181 #define rcvtyp_bk(ttyp) ((ttyp) & TTYP_BKMD)
182 #define rcvtyp_wd(ttyp) (!((ttyp) & TTYP_BKMD))
183 #define rcvtyp_pvt(ttyp) ((ttyp) & TTYP_PVMD)
184 #define rcvtyp_gbl(ttyp) (!((ttyp) & TTYP_PVMD))
186 static __inline__ int has_taskdev_lock(struct taskdev *dev);
187 static int dsp_rmdev_minor(unsigned char minor);
188 static int taskdev_init(struct taskdev *dev, char *name, unsigned char minor);
189 static void taskdev_delete(unsigned char minor);
190 static int taskdev_attach_task(struct taskdev *dev, struct dsptask *task);
191 static int dsp_tdel_bh(struct taskdev *dev, u16 type);
193 static struct bus_type dsptask_bus = {
197 static struct class *dsp_task_class;
198 static DEFINE_MUTEX(devmgr_lock);
199 static struct taskdev *taskdev[TASKDEV_MAX];
200 static struct dsptask *dsptask[TASKDEV_MAX];
201 static DEFINE_MUTEX(cfg_lock);
204 static DECLARE_WAIT_QUEUE_HEAD(cfg_wait_q);
205 static u8 n_task; /* static task count */
208 #define is_dynamic_task(tid) ((tid) >= n_task)
210 #define devstate_read_lock(dev, devstate) \
211 devstate_read_lock_timeout(dev, devstate, 0)
212 #define devstate_read_unlock(dev) up_read(&(dev)->state_sem)
213 #define devstate_write_lock(dev, devstate) \
214 devstate_write_lock_timeout(dev, devstate, 0)
215 #define devstate_write_unlock(dev) up_write(&(dev)->state_sem)
217 static ssize_t devname_show(struct device *d, struct device_attribute *attr,
219 static ssize_t devstate_show(struct device *d, struct device_attribute *attr,
221 static ssize_t proc_list_show(struct device *d, struct device_attribute *attr,
223 static ssize_t taskname_show(struct device *d, struct device_attribute *attr,
225 static ssize_t ttyp_show(struct device *d, struct device_attribute *attr,
227 static ssize_t fifosz_show(struct device *d, struct device_attribute *attr,
229 static int fifosz_store(struct device *d, struct device_attribute *attr,
230 const char *buf, size_t count);
231 static ssize_t fifocnt_show(struct device *d, struct device_attribute *attr,
233 static ssize_t ipblink_show(struct device *d, struct device_attribute *attr,
235 static ssize_t wsz_show(struct device *d, struct device_attribute *attr,
237 static ssize_t mmap_show(struct device *d, struct device_attribute *attr,
240 #define __ATTR_RW(_name,_mode) { \
241 .attr = {.name = __stringify(_name), .mode = _mode, .owner = THIS_MODULE }, \
242 .show = _name##_show, \
243 .store = _name##_store, \
246 static struct device_attribute dev_attr_devname = __ATTR_RO(devname);
247 static struct device_attribute dev_attr_devstate = __ATTR_RO(devstate);
248 static struct device_attribute dev_attr_proc_list = __ATTR_RO(proc_list);
249 static struct device_attribute dev_attr_taskname = __ATTR_RO(taskname);
250 static struct device_attribute dev_attr_ttyp = __ATTR_RO(ttyp);
251 static struct device_attribute dev_attr_fifosz = __ATTR_RW(fifosz, 0666);
252 static struct device_attribute dev_attr_fifocnt = __ATTR_RO(fifocnt);
253 static struct device_attribute dev_attr_ipblink = __ATTR_RO(ipblink);
254 static struct device_attribute dev_attr_wsz = __ATTR_RO(wsz);
255 static struct device_attribute dev_attr_mmap = __ATTR_RO(mmap);
258 * devstate_read_lock_timeout()
259 * devstate_write_lock_timeout():
260 * timeout != 0: dev->state can be diffeent from what you want.
261 * timeout == 0: no timeout
263 static int devstate_read_lock_timeout(struct taskdev *dev, long devstate,
266 DECLARE_WAITQUEUE(wait, current);
267 long current_state = current->state;
270 down_read(&dev->state_sem);
271 if (dev->state & devstate)
274 add_wait_queue(&dev->state_wait_q, &wait);
276 set_current_state(TASK_INTERRUPTIBLE);
277 up_read(&dev->state_sem);
279 if ((timeout = schedule_timeout(timeout)) == 0) {
281 down_read(&dev->state_sem);
286 if (signal_pending(current)) {
290 down_read(&dev->state_sem);
291 } while (!(dev->state & devstate));
292 remove_wait_queue(&dev->state_wait_q, &wait);
293 set_current_state(current_state);
297 static int devstate_read_lock_and_test(struct taskdev *dev, long devstate)
299 down_read(&dev->state_sem);
300 if (dev->state & devstate)
301 return 1; /* success */
303 up_read(&dev->state_sem);
307 static int devstate_write_lock_timeout(struct taskdev *dev, long devstate,
310 DECLARE_WAITQUEUE(wait, current);
311 long current_state = current->state;
314 down_write(&dev->state_sem);
315 if (dev->state & devstate)
318 add_wait_queue(&dev->state_wait_q, &wait);
320 set_current_state(TASK_INTERRUPTIBLE);
321 up_write(&dev->state_sem);
323 if ((timeout = schedule_timeout(timeout)) == 0) {
325 down_write(&dev->state_sem);
330 if (signal_pending(current)) {
334 down_write(&dev->state_sem);
335 } while (!(dev->state & devstate));
336 remove_wait_queue(&dev->state_wait_q, &wait);
337 set_current_state(current_state);
341 static int devstate_write_lock_and_test(struct taskdev *dev, long devstate)
343 down_write(&dev->state_sem);
344 if (dev->state & devstate) /* success */
348 up_write(&dev->state_sem);
352 static int taskdev_lock_interruptible(struct taskdev *dev,
357 if (has_taskdev_lock(dev))
358 ret = mutex_lock_interruptible(lock);
360 if ((ret = mutex_lock_interruptible(&dev->lock)) != 0)
362 ret = mutex_lock_interruptible(lock);
363 mutex_unlock(&dev->lock);
369 static int taskdev_lock_and_statelock_attached(struct taskdev *dev,
374 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
377 if ((ret = taskdev_lock_interruptible(dev, lock)) != 0)
378 devstate_read_unlock(dev);
383 static __inline__ void taskdev_unlock_and_stateunlock(struct taskdev *dev,
387 devstate_read_unlock(dev);
391 * taskdev_flush_buf()
392 * must be called under state_lock(ATTACHED) and dev->read_mutex.
394 static int taskdev_flush_buf(struct taskdev *dev)
396 u16 ttyp = dev->task->ttyp;
398 if (sndtyp_wd(ttyp)) {
400 flush_fifo(&dev->rcvdt.fifo);
402 /* block receiving */
403 struct rcvdt_bk_struct *rcvdt = &dev->rcvdt.bk;
405 if (sndtyp_gbl(ttyp))
406 ipblink_flush(&rcvdt->link);
408 ipblink_flush_pvt(&rcvdt->link);
409 release_ipbuf_pvt(dev->task->ipbuf_pvt_r);
417 * taskdev_set_fifosz()
418 * must be called under dev->read_mutex.
420 static int taskdev_set_fifosz(struct taskdev *dev, unsigned long sz)
422 u16 ttyp = dev->task->ttyp;
425 if (!(sndtyp_wd(ttyp) && sndtyp_acv(ttyp))) {
427 "omapdsp: buffer size can be changed only for "
428 "active word sending task.\n");
431 if ((sz == 0) || (sz & 1)) {
432 printk(KERN_ERR "omapdsp: illegal buffer size! (%ld)\n"
433 "it must be even and non-zero value.\n", sz);
437 stat = realloc_fifo(&dev->rcvdt.fifo, sz);
438 if (stat == -EBUSY) {
439 printk(KERN_ERR "omapdsp: buffer is not empty!\n");
441 } else if (stat < 0) {
443 "omapdsp: unable to change receive buffer size. "
444 "(%ld bytes for %s)\n", sz, dev->name);
451 static __inline__ int has_taskdev_lock(struct taskdev *dev)
453 return (dev->lock_pid == current->pid);
456 static int taskdev_lock(struct taskdev *dev)
458 if (mutex_lock_interruptible(&dev->lock))
460 dev->lock_pid = current->pid;
464 static int taskdev_unlock(struct taskdev *dev)
466 if (!has_taskdev_lock(dev)) {
468 "omapdsp: an illegal process attempted to "
469 "unlock the dsptask lock!\n");
473 mutex_unlock(&dev->lock);
477 static int dsp_task_config(struct dsptask *task, u8 tid)
486 task->state = TASK_ST_CFGREQ;
487 if (mutex_lock_interruptible(&cfg_lock)) {
491 cfg_cmd = MBOX_CMD_DSP_TCFG;
492 mbcompose_send_and_wait(TCFG, tid, 0, &cfg_wait_q);
494 mutex_unlock(&cfg_lock);
496 if (task->state != TASK_ST_READY) {
497 printk(KERN_ERR "omapdsp: task %d configuration error!\n", tid);
502 if (strlen(task->name) <= 1)
503 sprintf(task->name, "%d", tid);
504 printk(KERN_INFO "omapdsp: task %d: name %s\n", tid, task->name);
509 * task info sanity check
512 /* task type check */
513 if (rcvtyp_psv(ttyp) && rcvtyp_pvt(ttyp)) {
514 printk(KERN_ERR "omapdsp: illegal task type(0x%04x), tid=%d\n",
520 /* private buffer address check */
521 if (sndtyp_pvt(ttyp) &&
522 (ipbuf_p_validate(task->ipbuf_pvt_r, DIR_D2A) < 0)) {
526 if (rcvtyp_pvt(ttyp) &&
527 (ipbuf_p_validate(task->ipbuf_pvt_w, DIR_A2D) < 0)) {
532 /* mmap buffer configuration check */
533 if ((task->map_length > 0) &&
534 ((!is_aligned((unsigned long)task->map_base, PAGE_SIZE)) ||
535 (!is_aligned(task->map_length, PAGE_SIZE)) ||
536 (dsp_mem_type(task->map_base, task->map_length) != MEM_TYPE_EXTERN))) {
538 "omapdsp: illegal mmap buffer address(0x%p) or "
540 " It needs to be page-aligned and located at "
541 "external memory.\n",
542 task->map_base, task->map_length);
554 static void dsp_task_init(struct dsptask *task)
556 mbcompose_send(TCTL, task->tid, TCTL_TINIT);
559 int dsp_task_config_all(u8 n)
562 struct taskdev *devheap;
563 struct dsptask *taskheap;
564 size_t devheapsz, taskheapsz;
566 printk(KERN_INFO "omapdsp: found %d task(s)\n", n);
573 devheapsz = sizeof(struct taskdev) * n;
574 taskheapsz = sizeof(struct dsptask) * n;
575 heap = kzalloc(devheapsz + taskheapsz, GFP_KERNEL);
579 taskheap = heap + devheapsz;
582 for (i = 0; i < n; i++) {
583 struct taskdev *dev = &devheap[i];
584 struct dsptask *task = &taskheap[i];
586 if ((ret = dsp_task_config(task, i)) < 0)
588 if ((ret = taskdev_init(dev, task->name, i)) < 0)
590 if ((ret = taskdev_attach_task(dev, task)) < 0)
593 printk(KERN_INFO "omapdsp: taskdev %s enabled.\n", dev->name);
599 static void dsp_task_unconfig(struct dsptask *task)
601 dsptask[task->tid] = NULL;
604 void dsp_task_unconfig_all(void)
608 struct dsptask *task;
610 for (minor = 0; minor < n_task; minor++) {
612 * taskdev[minor] can be NULL in case of
613 * configuration failure
616 taskdev_delete(minor);
618 for (; minor < TASKDEV_MAX; minor++) {
620 dsp_rmdev_minor(minor);
623 for (tid = 0; tid < n_task; tid++) {
625 * dsptask[tid] can be NULL in case of
626 * configuration failure
630 dsp_task_unconfig(task);
632 for (; tid < TASKDEV_MAX; tid++) {
636 * on-demand tasks should be deleted in
637 * rmdev_minor(), but just in case.
639 dsp_task_unconfig(task);
652 static struct device_driver dsptask_driver = {
657 u8 dsp_task_count(void)
662 int dsp_taskmod_busy(void)
666 unsigned int usecount;
668 for (minor = 0; minor < TASKDEV_MAX; minor++) {
669 dev = taskdev[minor];
672 if ((usecount = dev->usecount) > 0) {
673 printk("dsp_taskmod_busy(): %s: usecount=%d\n",
674 dev->name, usecount);
678 if ((dev->state & (TASKDEV_ST_ADDREQ |
679 TASKDEV_ST_DELREQ)) {
681 if (dev->state & TASKDEV_ST_ADDREQ) {
682 printk("dsp_taskmod_busy(): %s is in %s\n",
683 dev->name, devstate_name(dev->state));
691 * DSP task device file operations
693 static ssize_t dsp_task_read_wd_acv(struct file *file, char __user *buf,
694 size_t count, loff_t *ppos)
696 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
697 struct taskdev *dev = taskdev[minor];
702 } else if (count & 0x1) {
704 "omapdsp: odd count is illegal for DSP task device.\n");
708 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
711 if (fifo_empty(&dev->rcvdt.fifo)) {
712 long current_state = current->state;
713 DECLARE_WAITQUEUE(wait, current);
715 set_current_state(TASK_INTERRUPTIBLE);
716 add_wait_queue(&dev->read_wait_q, &wait);
717 if (fifo_empty(&dev->rcvdt.fifo)) /* last check */
719 set_current_state(current_state);
720 remove_wait_queue(&dev->read_wait_q, &wait);
721 if (fifo_empty(&dev->rcvdt.fifo)) {
723 if (signal_pending(current))
729 ret = copy_to_user_fm_fifo(buf, &dev->rcvdt.fifo, count);
732 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
736 static ssize_t dsp_task_read_bk_acv(struct file *file, char __user *buf,
737 size_t count, loff_t *ppos)
739 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
740 struct taskdev *dev = taskdev[minor];
741 struct rcvdt_bk_struct *rcvdt = &dev->rcvdt.bk;
746 } else if (count & 0x1) {
748 "omapdsp: odd count is illegal for DSP task device.\n");
750 } else if ((int)buf & 0x1) {
752 "omapdsp: buf should be word aligned for "
753 "dsp_task_read().\n");
757 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
760 if (ipblink_empty(&rcvdt->link)) {
762 DECLARE_WAITQUEUE(wait, current);
764 add_wait_queue(&dev->read_wait_q, &wait);
765 current_state = current->state;
766 set_current_state(TASK_INTERRUPTIBLE);
767 if (ipblink_empty(&rcvdt->link)) /* last check */
769 set_current_state(current_state);
770 remove_wait_queue(&dev->read_wait_q, &wait);
771 if (ipblink_empty(&rcvdt->link)) {
773 if (signal_pending(current))
779 /* copy from delayed IPBUF */
780 if (sndtyp_pvt(dev->task->ttyp)) {
782 if (!ipblink_empty(&rcvdt->link)) {
783 struct ipbuf_p *ipbp = dev->task->ipbuf_pvt_r;
784 unsigned char *base, *src;
787 if (dsp_mem_enable(ipbp) < 0) {
791 base = MKVIRT(ipbp->ah, ipbp->al);
792 bkcnt = ((unsigned long)ipbp->c) * 2 - rcvdt->rp;
793 if (dsp_address_validate(base, bkcnt,
794 "task %s read buffer",
795 dev->task->name) < 0) {
799 if (dsp_mem_enable(base) < 0) {
803 src = base + rcvdt->rp;
805 if (copy_to_user_dsp(buf, src, count)) {
812 if (copy_to_user_dsp(buf, src, bkcnt)) {
817 ipblink_del_pvt(&rcvdt->link);
818 release_ipbuf_pvt(ipbp);
822 dsp_mem_disable(src);
824 dsp_mem_disable(ipbp);
828 if (dsp_mem_enable_ipbuf() < 0) {
832 while (!ipblink_empty(&rcvdt->link)) {
835 struct ipbuf_head *ipb_h = bid_to_ipbuf(rcvdt->link.top);
837 src = ipb_h->p->d + rcvdt->rp;
838 bkcnt = ((unsigned long)ipb_h->p->c) * 2 - rcvdt->rp;
840 if (copy_to_user_dsp(buf, src, count)) {
848 if (copy_to_user_dsp(buf, src, bkcnt)) {
855 ipblink_del_top(&rcvdt->link);
861 dsp_mem_disable_ipbuf();
865 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
869 static ssize_t dsp_task_read_wd_psv(struct file *file, char __user *buf,
870 size_t count, loff_t *ppos)
872 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
873 struct taskdev *dev = taskdev[minor];
878 } else if (count & 0x1) {
880 "omapdsp: odd count is illegal for DSP task device.\n");
887 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
890 mbcompose_send_and_wait(WDREQ, dev->task->tid, 0, &dev->read_wait_q);
892 if (fifo_empty(&dev->rcvdt.fifo)) {
894 if (signal_pending(current))
899 ret = copy_to_user_fm_fifo(buf, &dev->rcvdt.fifo, count);
902 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
906 static ssize_t dsp_task_read_bk_psv(struct file *file, char __user *buf,
907 size_t count, loff_t *ppos)
909 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
910 struct taskdev *dev = taskdev[minor];
911 struct rcvdt_bk_struct *rcvdt = &dev->rcvdt.bk;
916 } else if (count & 0x1) {
918 "omapdsp: odd count is illegal for DSP task device.\n");
920 } else if ((int)buf & 0x1) {
922 "omapdsp: buf should be word aligned for "
923 "dsp_task_read().\n");
927 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
930 mbcompose_send_and_wait(BKREQ, dev->task->tid, count/2,
933 if (ipblink_empty(&rcvdt->link)) {
935 if (signal_pending(current))
941 * We will not receive more than requested count.
943 if (sndtyp_pvt(dev->task->ttyp)) {
945 struct ipbuf_p *ipbp = dev->task->ipbuf_pvt_r;
949 if (dsp_mem_enable(ipbp) < 0) {
953 src = MKVIRT(ipbp->ah, ipbp->al);
954 rcvcnt = ((unsigned long)ipbp->c) * 2;
955 if (dsp_address_validate(src, rcvcnt, "task %s read buffer",
956 dev->task->name) < 0) {
960 if (dsp_mem_enable(src) < 0) {
966 if (copy_to_user_dsp(buf, src, count)) {
970 ipblink_del_pvt(&rcvdt->link);
971 release_ipbuf_pvt(ipbp);
974 dsp_mem_disable(src);
976 dsp_mem_disable(ipbp);
979 struct ipbuf_head *ipb_h = bid_to_ipbuf(rcvdt->link.top);
982 if (dsp_mem_enable_ipbuf() < 0) {
986 rcvcnt = ((unsigned long)ipb_h->p->c) * 2;
989 if (copy_to_user_dsp(buf, ipb_h->p->d, count)) {
993 ipblink_del_top(&rcvdt->link);
997 dsp_mem_disable_ipbuf();
1001 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
1005 static ssize_t dsp_task_write_wd(struct file *file, const char __user *buf,
1006 size_t count, loff_t *ppos)
1008 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1009 struct taskdev *dev = taskdev[minor];
1015 } else if (count & 0x1) {
1017 "omapdsp: odd count is illegal for DSP task device.\n");
1024 if (taskdev_lock_and_statelock_attached(dev, &dev->write_mutex))
1027 if (dev->wsz == 0) {
1029 DECLARE_WAITQUEUE(wait, current);
1031 add_wait_queue(&dev->write_wait_q, &wait);
1032 current_state = current->state;
1033 set_current_state(TASK_INTERRUPTIBLE);
1034 if (dev->wsz == 0) /* last check */
1036 set_current_state(current_state);
1037 remove_wait_queue(&dev->write_wait_q, &wait);
1038 if (dev->wsz == 0) {
1040 if (signal_pending(current))
1046 if (copy_from_user(&wd, buf, count)) {
1051 spin_lock(&dev->wsz_lock);
1052 if (mbcompose_send(WDSND, dev->task->tid, wd) < 0) {
1053 spin_unlock(&dev->wsz_lock);
1057 if (rcvtyp_acv(dev->task->ttyp))
1059 spin_unlock(&dev->wsz_lock);
1062 taskdev_unlock_and_stateunlock(dev, &dev->write_mutex);
1066 static ssize_t dsp_task_write_bk(struct file *file, const char __user *buf,
1067 size_t count, loff_t *ppos)
1069 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1070 struct taskdev *dev = taskdev[minor];
1075 } else if (count & 0x1) {
1077 "omapdsp: odd count is illegal for DSP task device.\n");
1079 } else if ((int)buf & 0x1) {
1081 "omapdsp: buf should be word aligned for "
1082 "dsp_task_write().\n");
1086 if (taskdev_lock_and_statelock_attached(dev, &dev->write_mutex))
1089 if (dev->wsz == 0) {
1091 DECLARE_WAITQUEUE(wait, current);
1093 add_wait_queue(&dev->write_wait_q, &wait);
1094 current_state = current->state;
1095 set_current_state(TASK_INTERRUPTIBLE);
1096 if (dev->wsz == 0) /* last check */
1098 set_current_state(current_state);
1099 remove_wait_queue(&dev->write_wait_q, &wait);
1100 if (dev->wsz == 0) {
1102 if (signal_pending(current))
1108 if (count > dev->wsz)
1111 if (rcvtyp_pvt(dev->task->ttyp)) {
1113 struct ipbuf_p *ipbp = dev->task->ipbuf_pvt_w;
1116 if (dsp_mem_enable(ipbp) < 0) {
1120 dst = MKVIRT(ipbp->ah, ipbp->al);
1121 if (dsp_address_validate(dst, count, "task %s write buffer",
1122 dev->task->name) < 0) {
1126 if (dsp_mem_enable(dst) < 0) {
1130 if (copy_from_user_dsp(dst, buf, count)) {
1135 ipbp->s = dev->task->tid;
1136 spin_lock(&dev->wsz_lock);
1137 if (mbcompose_send(BKSNDP, dev->task->tid, 0) == 0) {
1138 if (rcvtyp_acv(dev->task->ttyp))
1142 spin_unlock(&dev->wsz_lock);
1144 dsp_mem_disable(dst);
1146 dsp_mem_disable(ipbp);
1149 struct ipbuf_head *ipb_h;
1151 if (dsp_mem_enable_ipbuf() < 0) {
1155 if ((ipb_h = get_free_ipbuf(dev->task->tid)) == NULL)
1157 if (copy_from_user_dsp(ipb_h->p->d, buf, count)) {
1158 release_ipbuf(ipb_h);
1162 ipb_h->p->c = count/2;
1163 ipb_h->p->sa = dev->task->tid;
1164 spin_lock(&dev->wsz_lock);
1165 if (mbcompose_send(BKSND, dev->task->tid, ipb_h->bid) == 0) {
1166 if (rcvtyp_acv(dev->task->ttyp))
1169 ipb_bsycnt_inc(&ipbcfg);
1171 release_ipbuf(ipb_h);
1172 spin_unlock(&dev->wsz_lock);
1174 dsp_mem_disable_ipbuf();
1178 taskdev_unlock_and_stateunlock(dev, &dev->write_mutex);
1182 static unsigned int dsp_task_poll(struct file * file, poll_table * wait)
1184 unsigned int minor = MINOR(file->f_dentry->d_inode->i_rdev);
1185 struct taskdev *dev = taskdev[minor];
1186 struct dsptask *task = dev->task;
1187 unsigned int mask = 0;
1189 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
1191 poll_wait(file, &dev->read_wait_q, wait);
1192 poll_wait(file, &dev->write_wait_q, wait);
1193 if (sndtyp_psv(task->ttyp) ||
1194 (sndtyp_wd(task->ttyp) && !fifo_empty(&dev->rcvdt.fifo)) ||
1195 (sndtyp_bk(task->ttyp) && !ipblink_empty(&dev->rcvdt.bk.link)))
1196 mask |= POLLIN | POLLRDNORM;
1198 mask |= POLLOUT | POLLWRNORM;
1199 devstate_read_unlock(dev);
1204 static int dsp_tctl_issue(struct taskdev *dev, u16 cmd, int argc, u16 argv[])
1207 struct mb_exarg mbarg, *mbargp;
1215 * system reserved TCTL commands
1229 * user-defined TCTL commands
1231 else if (cmd < 0x8100) {
1232 /* 0x8000-0x80ff: no arg, non-interactive */
1235 } else if (cmd < 0x8200) {
1236 /* 0x8100-0x81ff: 1 arg, non-interactive */
1239 } else if (cmd < 0x9000) {
1240 /* 0x8200-0x8fff: reserved */
1242 } else if (cmd < 0x9100) {
1243 /* 0x9000-0x90ff: no arg, interactive */
1246 } else if (cmd < 0x9200) {
1247 /* 0x9100-0x91ff: 1 arg, interactive */
1251 /* 0x9200-0xffff: reserved */
1256 * if argc < 0, use tctl_argc as is.
1257 * if argc >= 0, check arg count.
1259 if ((argc >= 0) && (argc != tctl_argc))
1265 if (taskdev_lock_interruptible(dev, &dev->tctl_mutex))
1268 tid = dev->task->tid;
1269 if (tctl_argc > 0) {
1270 mbarg.argc = tctl_argc;
1278 dev->tctl_stat = -EINVAL;
1280 mbcompose_send_and_wait_exarg(TCTL, tid, cmd, mbargp,
1282 if (signal_pending(current)) {
1286 if ((ret = dev->tctl_stat) < 0) {
1287 printk(KERN_ERR "omapdsp: TCTL not responding.\n");
1291 mbcompose_send_exarg(TCTL, tid, cmd, mbargp);
1294 mutex_unlock(&dev->tctl_mutex);
1298 static int dsp_task_ioctl(struct inode *inode, struct file *file,
1299 unsigned int cmd, unsigned long arg)
1301 unsigned int minor = MINOR(inode->i_rdev);
1302 struct taskdev *dev = taskdev[minor];
1305 if (cmd < 0x10000) {
1309 mbargv[0] = arg & 0xffff;
1310 return dsp_tctl_issue(dev, cmd, -1, mbargv);
1313 /* non TCTL ioctls */
1316 case TASK_IOCTL_LOCK:
1317 ret = taskdev_lock(dev);
1320 case TASK_IOCTL_UNLOCK:
1321 ret = taskdev_unlock(dev);
1324 case TASK_IOCTL_BFLSH:
1325 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
1327 ret = taskdev_flush_buf(dev);
1328 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
1331 case TASK_IOCTL_SETBSZ:
1332 if (taskdev_lock_and_statelock_attached(dev, &dev->read_mutex))
1334 ret = taskdev_set_fifosz(dev, arg);
1335 taskdev_unlock_and_stateunlock(dev, &dev->read_mutex);
1338 case TASK_IOCTL_GETNAME:
1340 if (copy_to_user((void __user *)arg, dev->name,
1341 strlen(dev->name) + 1))
1353 static void dsp_task_mmap_open(struct vm_area_struct *vma)
1355 struct taskdev *dev = (struct taskdev *)vma->vm_private_data;
1356 struct dsptask *task;
1357 size_t len = vma->vm_end - vma->vm_start;
1359 BUG_ON(!(dev->state & TASKDEV_ST_ATTACHED));
1361 exmap_use(task->map_base, len);
1364 static void dsp_task_mmap_close(struct vm_area_struct *vma)
1366 struct taskdev *dev = (struct taskdev *)vma->vm_private_data;
1367 struct dsptask *task;
1368 size_t len = vma->vm_end - vma->vm_start;
1370 BUG_ON(!(dev->state & TASKDEV_ST_ATTACHED));
1372 exmap_unuse(task->map_base, len);
1376 * On demand page allocation is not allowed. The mapping area is defined by
1377 * corresponding DSP tasks.
1379 static struct page *dsp_task_mmap_nopage(struct vm_area_struct *vma,
1380 unsigned long address, int *type)
1382 return NOPAGE_SIGBUS;
1385 static struct vm_operations_struct dsp_task_vm_ops = {
1386 .open = dsp_task_mmap_open,
1387 .close = dsp_task_mmap_close,
1388 .nopage = dsp_task_mmap_nopage,
1391 static int dsp_task_mmap(struct file *filp, struct vm_area_struct *vma)
1394 unsigned long tmp_padr, tmp_vmadr, off;
1395 size_t req_len, tmp_len;
1396 unsigned int minor = MINOR(filp->f_dentry->d_inode->i_rdev);
1397 struct taskdev *dev = taskdev[minor];
1398 struct dsptask *task;
1401 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
1406 * Don't swap this area out
1407 * Don't dump this area to a core file
1409 vma->vm_flags |= VM_RESERVED | VM_IO;
1411 /* Do not cache this area */
1412 vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
1414 req_len = vma->vm_end - vma->vm_start;
1415 off = vma->vm_pgoff << PAGE_SHIFT;
1416 tmp_vmadr = vma->vm_start;
1417 tmp_vadr = task->map_base + off;
1419 tmp_padr = dsp_virt_to_phys(tmp_vadr, &tmp_len);
1420 if (tmp_padr == 0) {
1422 "omapdsp: task %s: illegal address "
1423 "for mmap: %p", task->name, tmp_vadr);
1424 /* partial mapping will be cleared in upper layer */
1428 if (tmp_len > req_len)
1432 "omapdsp: mmap info: "
1433 "vmadr = %08lx, padr = %08lx, len = %x\n",
1434 tmp_vmadr, tmp_padr, tmp_len);
1435 if (remap_pfn_range(vma, tmp_vmadr, tmp_padr >> PAGE_SHIFT,
1436 tmp_len, vma->vm_page_prot) != 0) {
1438 "omapdsp: task %s: remap_page_range() failed.\n",
1440 /* partial mapping will be cleared in upper layer */
1446 tmp_vmadr += tmp_len;
1447 tmp_vadr += tmp_len;
1450 vma->vm_ops = &dsp_task_vm_ops;
1451 vma->vm_private_data = dev;
1452 exmap_use(task->map_base, vma->vm_end - vma->vm_start);
1455 devstate_read_unlock(dev);
1459 static int dsp_task_open(struct inode *inode, struct file *file)
1461 unsigned int minor = MINOR(inode->i_rdev);
1462 struct taskdev *dev;
1465 if ((minor >= TASKDEV_MAX) || ((dev = taskdev[minor]) == NULL))
1469 mutex_lock(&dev->usecount_lock);
1470 down_write(&dev->state_sem);
1472 /* state can be NOTASK, ATTACHED/FREEZED, KILLING, GARBAGE or INVALID here. */
1473 switch (dev->state & TASKDEV_ST_STATE_MASK) {
1474 case TASKDEV_ST_NOTASK:
1476 case TASKDEV_ST_ATTACHED:
1479 case TASKDEV_ST_INVALID:
1480 up_write(&dev->state_sem);
1481 mutex_unlock(&dev->usecount_lock);
1484 case TASKDEV_ST_FREEZED:
1485 case TASKDEV_ST_KILLING:
1486 case TASKDEV_ST_GARBAGE:
1487 case TASKDEV_ST_DELREQ:
1488 /* on the kill process. wait until it becomes NOTASK. */
1489 up_write(&dev->state_sem);
1490 mutex_unlock(&dev->usecount_lock);
1491 if (devstate_write_lock(dev, TASKDEV_ST_NOTASK) < 0)
1493 devstate_write_unlock(dev);
1498 dev->state = TASKDEV_ST_ADDREQ;
1499 /* wake up twch daemon for tadd */
1501 up_write(&dev->state_sem);
1502 if (devstate_write_lock(dev, TASKDEV_ST_ATTACHED |
1503 TASKDEV_ST_ADDFAIL) < 0) {
1505 if (!devstate_write_lock_and_test(dev, TASKDEV_ST_ADDREQ)) {
1506 mutex_unlock(&dev->usecount_lock);
1507 /* out of control ??? */
1510 dev->state = TASKDEV_ST_NOTASK;
1514 if (dev->state & TASKDEV_ST_ADDFAIL) {
1515 printk(KERN_ERR "omapdsp: task attach failed for %s!\n",
1518 dev->state = TASKDEV_ST_NOTASK;
1524 #ifndef CONFIG_OMAP_DSP_TASK_MULTIOPEN
1525 if (dev->usecount > 0) {
1526 up_write(&dev->state_sem);
1531 proc_list_add(&dev->proc_list_lock, &dev->proc_list, current, file);
1532 file->f_op = &dev->fops;
1533 up_write(&dev->state_sem);
1534 mutex_unlock(&dev->usecount_lock);
1536 #ifdef DSP_PTE_FREE /* not used currently. */
1537 dsp_map_update(current);
1538 dsp_cur_users_add(current);
1539 #endif /* DSP_PTE_FREE */
1543 wake_up_interruptible_all(&dev->state_wait_q);
1544 up_write(&dev->state_sem);
1545 mutex_unlock(&dev->usecount_lock);
1549 static int dsp_task_release(struct inode *inode, struct file *file)
1551 unsigned int minor = MINOR(inode->i_rdev);
1552 struct taskdev *dev = taskdev[minor];
1554 #ifdef DSP_PTE_FREE /* not used currently. */
1555 dsp_cur_users_del(current);
1556 #endif /* DSP_PTE_FREE */
1558 if (has_taskdev_lock(dev))
1559 taskdev_unlock(dev);
1561 proc_list_del(&dev->proc_list_lock, &dev->proc_list, current, file);
1562 mutex_lock(&dev->usecount_lock);
1563 if (--dev->usecount > 0) {
1564 /* other processes are using this device. no state change. */
1565 mutex_unlock(&dev->usecount_lock);
1570 down_write(&dev->state_sem);
1572 /* state can be ATTACHED/FREEZED, KILLING or GARBAGE here. */
1573 switch (dev->state & TASKDEV_ST_STATE_MASK) {
1575 case TASKDEV_ST_KILLING:
1578 case TASKDEV_ST_GARBAGE:
1579 dev->state = TASKDEV_ST_NOTASK;
1580 wake_up_interruptible_all(&dev->state_wait_q);
1583 case TASKDEV_ST_ATTACHED:
1584 case TASKDEV_ST_FREEZED:
1585 if (is_dynamic_task(minor)) {
1586 dev->state = TASKDEV_ST_DELREQ;
1587 /* wake up twch daemon for tdel */
1594 up_write(&dev->state_sem);
1595 mutex_unlock(&dev->usecount_lock);
1602 int dsp_mkdev(char *name)
1604 struct taskdev *dev;
1606 unsigned char minor;
1609 if (dsp_cfgstat_get_stat() != CFGSTAT_READY) {
1610 printk(KERN_ERR "omapdsp: dsp has not been configured.\n");
1614 if (mutex_lock_interruptible(&devmgr_lock))
1618 for (minor = 0; minor < TASKDEV_MAX; minor++) {
1619 if (taskdev[minor] && !strcmp(taskdev[minor]->name, name)) {
1621 "omapdsp: task device name %s is already "
1628 /* find free minor number */
1629 for (minor = n_task; minor < TASKDEV_MAX; minor++) {
1630 if (taskdev[minor] == NULL)
1633 printk(KERN_ERR "omapdsp: Too many task devices.\n");
1638 if ((dev = kzalloc(sizeof(struct taskdev), GFP_KERNEL)) == NULL) {
1642 if ((status = taskdev_init(dev, name, minor)) < 0) {
1650 mutex_unlock(&devmgr_lock);
1654 int dsp_rmdev(char *name)
1656 unsigned char minor;
1660 if (dsp_cfgstat_get_stat() != CFGSTAT_READY) {
1661 printk(KERN_ERR "omapdsp: dsp has not been configured.\n");
1665 if (mutex_lock_interruptible(&devmgr_lock))
1668 /* find in dynamic devices */
1669 for (minor = n_task; minor < TASKDEV_MAX; minor++) {
1670 if (taskdev[minor] && !strcmp(taskdev[minor]->name, name))
1674 /* find in static devices */
1675 for (minor = 0; minor < n_task; minor++) {
1676 if (taskdev[minor] && !strcmp(taskdev[minor]->name, name)) {
1678 "omapdsp: task device %s is static.\n", name);
1684 printk(KERN_ERR "omapdsp: task device %s not found.\n", name);
1689 if ((status = dsp_rmdev_minor(minor)) < 0)
1692 mutex_unlock(&devmgr_lock);
1696 static int dsp_rmdev_minor(unsigned char minor)
1698 struct taskdev *dev = taskdev[minor];
1700 while (!down_write_trylock(&dev->state_sem)) {
1701 down_read(&dev->state_sem);
1702 if (dev->state & (TASKDEV_ST_ATTACHED |
1703 TASKDEV_ST_FREEZED)) {
1705 * task is working. kill it.
1706 * ATTACHED -> FREEZED can be changed under
1707 * down_read of state_sem..
1709 dev->state = TASKDEV_ST_FREEZED;
1710 wake_up_interruptible_all(&dev->read_wait_q);
1711 wake_up_interruptible_all(&dev->write_wait_q);
1712 wake_up_interruptible_all(&dev->tctl_wait_q);
1714 up_read(&dev->state_sem);
1718 switch (dev->state & TASKDEV_ST_STATE_MASK) {
1720 case TASKDEV_ST_NOTASK:
1724 case TASKDEV_ST_ATTACHED:
1725 case TASKDEV_ST_FREEZED:
1726 /* task is working. kill it. */
1727 dev->state = TASKDEV_ST_KILLING;
1728 up_write(&dev->state_sem);
1729 dsp_tdel_bh(dev, TDEL_KILL);
1732 case TASKDEV_ST_ADDREQ:
1733 /* open() is waiting. drain it. */
1734 dev->state = TASKDEV_ST_ADDFAIL;
1735 wake_up_interruptible_all(&dev->state_wait_q);
1738 case TASKDEV_ST_DELREQ:
1739 /* nobody is waiting. */
1740 dev->state = TASKDEV_ST_NOTASK;
1741 wake_up_interruptible_all(&dev->state_wait_q);
1744 case TASKDEV_ST_ADDING:
1745 case TASKDEV_ST_DELING:
1746 case TASKDEV_ST_KILLING:
1747 case TASKDEV_ST_GARBAGE:
1748 case TASKDEV_ST_ADDFAIL:
1749 /* transient state. wait for a moment. */
1754 up_write(&dev->state_sem);
1757 /* wait for some time and hope the state is settled */
1758 devstate_read_lock_timeout(dev, TASKDEV_ST_NOTASK, 5 * HZ);
1759 if (!(dev->state & TASKDEV_ST_NOTASK)) {
1761 "omapdsp: illegal device state (%s) on rmdev %s.\n",
1762 devstate_name(dev->state), dev->name);
1765 dev->state = TASKDEV_ST_INVALID;
1766 devstate_read_unlock(dev);
1768 taskdev_delete(minor);
1774 struct file_operations dsp_task_fops = {
1775 .owner = THIS_MODULE,
1776 .poll = dsp_task_poll,
1777 .ioctl = dsp_task_ioctl,
1778 .open = dsp_task_open,
1779 .release = dsp_task_release,
1782 static void dsptask_dev_release(struct device *dev)
1786 static int taskdev_init(struct taskdev *dev, char *name, unsigned char minor)
1790 taskdev[minor] = dev;
1792 spin_lock_init(&dev->proc_list_lock);
1793 INIT_LIST_HEAD(&dev->proc_list);
1794 init_waitqueue_head(&dev->read_wait_q);
1795 init_waitqueue_head(&dev->write_wait_q);
1796 init_waitqueue_head(&dev->tctl_wait_q);
1797 mutex_init(&dev->read_mutex);
1798 mutex_init(&dev->write_mutex);
1799 mutex_init(&dev->tctl_mutex);
1800 mutex_init(&dev->lock);
1801 spin_lock_init(&dev->wsz_lock);
1802 dev->tctl_ret = -EINVAL;
1805 strncpy(dev->name, name, TNM_LEN);
1806 dev->name[TNM_LEN-1] = '\0';
1807 dev->state = (minor < n_task) ? TASKDEV_ST_ATTACHED : TASKDEV_ST_NOTASK;
1809 mutex_init(&dev->usecount_lock);
1810 memcpy(&dev->fops, &dsp_task_fops, sizeof(struct file_operations));
1812 dev->dev.parent = omap_dsp->dev;
1813 dev->dev.bus = &dsptask_bus;
1814 sprintf(dev->dev.bus_id, "dsptask%d", minor);
1815 dev->dev.release = dsptask_dev_release;
1816 ret = device_register(&dev->dev);
1818 printk(KERN_ERR "device_register failed: %d\n", ret);
1819 ret = device_create_file(&dev->dev, &dev_attr_devname);
1820 ret |= device_create_file(&dev->dev, &dev_attr_devstate);
1821 ret |= device_create_file(&dev->dev, &dev_attr_proc_list);
1823 printk(KERN_ERR "device_create_file failed: %d\n", ret);
1824 device_create(dsp_task_class, NULL,
1825 MKDEV(OMAP_DSP_TASK_MAJOR, minor),
1826 "dsptask%d", minor);
1828 init_waitqueue_head(&dev->state_wait_q);
1829 init_rwsem(&dev->state_sem);
1834 static void taskdev_delete(unsigned char minor)
1836 struct taskdev *dev = taskdev[minor];
1840 device_remove_file(&dev->dev, &dev_attr_devname);
1841 device_remove_file(&dev->dev, &dev_attr_devstate);
1842 device_remove_file(&dev->dev, &dev_attr_proc_list);
1843 device_destroy(dsp_task_class, MKDEV(OMAP_DSP_TASK_MAJOR, minor));
1844 device_unregister(&dev->dev);
1845 proc_list_flush(&dev->proc_list_lock, &dev->proc_list);
1846 taskdev[minor] = NULL;
1849 static int taskdev_attach_task(struct taskdev *dev, struct dsptask *task)
1851 u16 ttyp = task->ttyp;
1856 sndtyp_wd(ttyp) ? dsp_task_read_wd_acv:
1857 /* sndtyp_bk */ dsp_task_read_bk_acv:
1859 sndtyp_wd(ttyp) ? dsp_task_read_wd_psv:
1860 /* sndtyp_bk */ dsp_task_read_bk_psv;
1861 if (sndtyp_wd(ttyp)) {
1865 fifosz = sndtyp_psv(ttyp) ? 2 : /* passive */
1867 if (init_fifo(&dev->rcvdt.fifo, fifosz) < 0) {
1869 "omapdsp: unable to allocate receive buffer. "
1870 "(%d bytes for %s)\n", fifosz, dev->name);
1875 INIT_IPBLINK(&dev->rcvdt.bk.link);
1876 dev->rcvdt.bk.rp = 0;
1880 rcvtyp_wd(ttyp) ? dsp_task_write_wd:
1881 /* rcvbyp_bk */ dsp_task_write_bk;
1882 dev->wsz = rcvtyp_acv(ttyp) ? 0 : /* active */
1883 rcvtyp_wd(ttyp) ? 2 : /* passive word */
1884 ipbcfg.lsz*2; /* passive block */
1886 if (task->map_length)
1887 dev->fops.mmap = dsp_task_mmap;
1889 ret = device_create_file(&dev->dev, &dev_attr_taskname);
1890 ret |= device_create_file(&dev->dev, &dev_attr_ttyp);
1891 if (sndtyp_wd(ttyp)) {
1892 ret |= device_create_file(&dev->dev, &dev_attr_fifosz);
1893 ret |= device_create_file(&dev->dev, &dev_attr_fifocnt);
1895 ret |= device_create_file(&dev->dev, &dev_attr_ipblink);
1896 ret |= device_create_file(&dev->dev, &dev_attr_wsz);
1897 if (task->map_length)
1898 ret |= device_create_file(&dev->dev, &dev_attr_mmap);
1900 printk(KERN_ERR "device_create_file failed: %d\n", ret);
1908 static void taskdev_detach_task(struct taskdev *dev)
1910 u16 ttyp = dev->task->ttyp;
1912 device_remove_file(&dev->dev, &dev_attr_taskname);
1913 device_remove_file(&dev->dev, &dev_attr_ttyp);
1914 if (sndtyp_wd(ttyp)) {
1915 device_remove_file(&dev->dev, &dev_attr_fifosz);
1916 device_remove_file(&dev->dev, &dev_attr_fifocnt);
1918 device_remove_file(&dev->dev, &dev_attr_ipblink);
1919 device_remove_file(&dev->dev, &dev_attr_wsz);
1920 if (dev->task->map_length)
1921 device_remove_file(&dev->dev, &dev_attr_mmap);
1923 dev->fops.read = NULL;
1924 taskdev_flush_buf(dev);
1925 if (sndtyp_wd(ttyp))
1926 free_fifo(&dev->rcvdt.fifo);
1928 dev->fops.write = NULL;
1931 printk(KERN_INFO "omapdsp: taskdev %s disabled.\n", dev->name);
1936 * tadd / tdel / tkill
1938 static int dsp_tadd(struct taskdev *dev, dsp_long_t adr)
1940 struct dsptask *task;
1941 struct mb_exarg arg;
1942 u8 tid, tid_response;
1946 if (!devstate_write_lock_and_test(dev, TASKDEV_ST_ADDREQ)) {
1948 "omapdsp: taskdev %s is not requesting for tadd. "
1949 "(state is %s)\n", dev->name, devstate_name(dev->state));
1952 dev->state = TASKDEV_ST_ADDING;
1953 devstate_write_unlock(dev);
1955 if (adr == TADD_ABORTADR) {
1956 /* aborting tadd intentionally */
1957 printk(KERN_INFO "omapdsp: tadd address is ABORTADR.\n");
1960 if (adr >= DSPSPACE_SIZE) {
1962 "omapdsp: illegal address 0x%08x for tadd\n", adr);
1967 adr >>= 1; /* word address */
1968 argv[0] = adr >> 16; /* addrh */
1969 argv[1] = adr & 0xffff; /* addrl */
1971 if (mutex_lock_interruptible(&cfg_lock)) {
1976 cfg_cmd = MBOX_CMD_DSP_TADD;
1981 if (dsp_mem_sync_inc() < 0) {
1982 printk(KERN_ERR "omapdsp: memory sync failed!\n");
1986 mbcompose_send_and_wait_exarg(TADD, 0, 0, &arg, &cfg_wait_q);
1991 mutex_unlock(&cfg_lock);
1993 if (tid == TID_ANON) {
1994 printk(KERN_ERR "omapdsp: tadd failed!\n");
1998 if ((tid < n_task) || dsptask[tid]) {
1999 printk(KERN_ERR "omapdsp: illegal tid (%d)!\n", tid);
2003 if ((task = kzalloc(sizeof(struct dsptask), GFP_KERNEL)) == NULL) {
2008 if ((ret = dsp_task_config(task, tid)) < 0)
2011 if (strcmp(dev->name, task->name)) {
2013 "omapdsp: task name (%s) doesn't match with "
2014 "device name (%s).\n", task->name, dev->name);
2019 if ((ret = taskdev_attach_task(dev, task)) < 0)
2022 dsp_task_init(task);
2023 printk(KERN_INFO "omapdsp: taskdev %s enabled.\n", dev->name);
2024 dev->state = TASKDEV_ST_ATTACHED;
2025 wake_up_interruptible_all(&dev->state_wait_q);
2032 printk(KERN_ERR "omapdsp: deleting the task...\n");
2034 dev->state = TASKDEV_ST_DELING;
2036 if (mutex_lock_interruptible(&cfg_lock)) {
2037 printk(KERN_ERR "omapdsp: aborting tdel process. "
2038 "DSP side could be corrupted.\n");
2042 cfg_cmd = MBOX_CMD_DSP_TDEL;
2043 mbcompose_send_and_wait(TDEL, tid, TDEL_KILL, &cfg_wait_q);
2044 tid_response = cfg_tid;
2047 mutex_unlock(&cfg_lock);
2049 if (tid_response != tid)
2050 printk(KERN_ERR "omapdsp: tdel failed. "
2051 "DSP side could be corrupted.\n");
2054 dev->state = TASKDEV_ST_ADDFAIL;
2055 wake_up_interruptible_all(&dev->state_wait_q);
2059 int dsp_tadd_minor(unsigned char minor, dsp_long_t adr)
2061 struct taskdev *dev;
2065 if (mutex_lock_interruptible(&devmgr_lock))
2068 if ((minor >= TASKDEV_MAX) || ((dev = taskdev[minor]) == NULL)) {
2070 "omapdsp: no task device with minor %d\n", minor);
2075 if ((status = dsp_tadd(dev, adr)) < 0)
2079 mutex_unlock(&devmgr_lock);
2083 static int dsp_tdel(struct taskdev *dev)
2085 if (!devstate_write_lock_and_test(dev, TASKDEV_ST_DELREQ)) {
2087 "omapdsp: taskdev %s is not requesting for tdel. "
2088 "(state is %s)\n", dev->name, devstate_name(dev->state));
2091 dev->state = TASKDEV_ST_DELING;
2092 devstate_write_unlock(dev);
2094 return dsp_tdel_bh(dev, TDEL_SAFE);
2097 int dsp_tdel_minor(unsigned char minor)
2099 struct taskdev *dev;
2103 if (mutex_lock_interruptible(&devmgr_lock))
2106 if ((minor >= TASKDEV_MAX) || ((dev = taskdev[minor]) == NULL)) {
2108 "omapdsp: no task device with minor %d\n", minor);
2114 if ((status = dsp_tdel(dev)) < 0)
2118 mutex_unlock(&devmgr_lock);
2122 static int dsp_tkill(struct taskdev *dev)
2124 while (!down_write_trylock(&dev->state_sem)) {
2125 if (!devstate_read_lock_and_test(dev, (TASKDEV_ST_ATTACHED |
2126 TASKDEV_ST_FREEZED))) {
2128 "omapdsp: task has not been attached for "
2129 "taskdev %s\n", dev->name);
2132 /* ATTACHED -> FREEZED can be changed under read semaphore. */
2133 dev->state = TASKDEV_ST_FREEZED;
2134 wake_up_interruptible_all(&dev->read_wait_q);
2135 wake_up_interruptible_all(&dev->write_wait_q);
2136 wake_up_interruptible_all(&dev->tctl_wait_q);
2137 devstate_read_unlock(dev);
2141 if (!(dev->state & (TASKDEV_ST_ATTACHED |
2142 TASKDEV_ST_FREEZED))) {
2144 "omapdsp: task has not been attached for taskdev %s\n",
2146 devstate_write_unlock(dev);
2149 if (!is_dynamic_task(dev->task->tid)) {
2150 printk(KERN_ERR "omapdsp: task %s is not a dynamic task.\n",
2152 devstate_write_unlock(dev);
2155 dev->state = TASKDEV_ST_KILLING;
2156 devstate_write_unlock(dev);
2158 return dsp_tdel_bh(dev, TDEL_KILL);
2161 int dsp_tkill_minor(unsigned char minor)
2163 struct taskdev *dev;
2167 if (mutex_lock_interruptible(&devmgr_lock))
2170 if ((minor >= TASKDEV_MAX) || ((dev = taskdev[minor]) == NULL)) {
2172 "omapdsp: no task device with minor %d\n", minor);
2178 if ((status = dsp_tkill(dev)) < 0)
2182 mutex_unlock(&devmgr_lock);
2186 static int dsp_tdel_bh(struct taskdev *dev, u16 type)
2188 struct dsptask *task;
2189 u8 tid, tid_response;
2194 if (mutex_lock_interruptible(&cfg_lock)) {
2195 if (type == TDEL_SAFE) {
2196 dev->state = TASKDEV_ST_DELREQ;
2199 tid_response = TID_ANON;
2205 cfg_cmd = MBOX_CMD_DSP_TDEL;
2206 mbcompose_send_and_wait(TDEL, tid, type, &cfg_wait_q);
2207 tid_response = cfg_tid;
2210 mutex_unlock(&cfg_lock);
2213 taskdev_detach_task(dev);
2214 dsp_task_unconfig(task);
2217 if (tid_response != tid) {
2218 printk(KERN_ERR "omapdsp: %s failed!\n",
2219 (type == TDEL_SAFE) ? "tdel" : "tkill");
2222 down_write(&dev->state_sem);
2223 dev->state = (dev->usecount > 0) ? TASKDEV_ST_GARBAGE :
2225 wake_up_interruptible_all(&dev->state_wait_q);
2226 up_write(&dev->state_sem);
2234 long taskdev_state_stale(unsigned char minor)
2236 if (taskdev[minor]) {
2237 long state = taskdev[minor]->state;
2238 taskdev[minor]->state |= TASKDEV_ST_STALE;
2241 return TASKDEV_ST_NOTASK;
2245 * functions called from mailbox interrupt routine
2247 void mbox_wdsnd(struct mbcmd *mb)
2250 struct dsptask *task = dsptask[tid];
2252 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2253 printk(KERN_ERR "mbox: WDSND with illegal tid! %d\n", tid);
2256 if (sndtyp_bk(task->ttyp)) {
2258 "mbox: WDSND from block sending task! (task%d)\n", tid);
2261 if (sndtyp_psv(task->ttyp) &&
2262 !waitqueue_active(&task->dev->read_wait_q)) {
2264 "mbox: WDSND from passive sending task (task%d) "
2265 "without request!\n", tid);
2269 write_word_to_fifo(&task->dev->rcvdt.fifo, mb->data);
2270 wake_up_interruptible(&task->dev->read_wait_q);
2273 void mbox_wdreq(struct mbcmd *mb)
2276 struct dsptask *task = dsptask[tid];
2277 struct taskdev *dev;
2279 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2280 printk(KERN_ERR "mbox: WDREQ with illegal tid! %d\n", tid);
2283 if (rcvtyp_psv(task->ttyp)) {
2285 "mbox: WDREQ from passive receiving task! (task%d)\n",
2291 spin_lock(&dev->wsz_lock);
2293 spin_unlock(&dev->wsz_lock);
2294 wake_up_interruptible(&dev->write_wait_q);
2297 void mbox_bksnd(struct mbcmd *mb)
2301 struct dsptask *task = dsptask[tid];
2302 struct ipbuf_head *ipb_h;
2305 if (bid >= ipbcfg.ln) {
2306 printk(KERN_ERR "mbox: BKSND with illegal bid! %d\n", bid);
2309 ipb_h = bid_to_ipbuf(bid);
2310 ipb_bsycnt_dec(&ipbcfg);
2311 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2312 printk(KERN_ERR "mbox: BKSND with illegal tid! %d\n", tid);
2313 goto unuse_ipbuf_out;
2315 if (sndtyp_wd(task->ttyp)) {
2317 "mbox: BKSND from word sending task! (task%d)\n", tid);
2318 goto unuse_ipbuf_out;
2320 if (sndtyp_pvt(task->ttyp)) {
2322 "mbox: BKSND from private sending task! (task%d)\n", tid);
2323 goto unuse_ipbuf_out;
2325 if (sync_with_dsp(&ipb_h->p->sd, tid, 10) < 0) {
2326 printk(KERN_ERR "mbox: BKSND - IPBUF sync failed!\n");
2330 /* should be done in DSP, but just in case. */
2331 ipb_h->p->next = BID_NULL;
2334 if (cnt > ipbcfg.lsz) {
2335 printk(KERN_ERR "mbox: BKSND cnt(%d) > ipbuf line size(%d)!\n",
2337 goto unuse_ipbuf_out;
2341 /* 0-byte send from DSP */
2342 unuse_ipbuf_nowait(ipb_h);
2345 ipblink_add_tail(&task->dev->rcvdt.bk.link, bid);
2346 /* we keep coming bid and return alternative line to DSP. */
2350 wake_up_interruptible(&task->dev->read_wait_q);
2354 unuse_ipbuf_nowait(ipb_h);
2358 void mbox_bkreq(struct mbcmd *mb)
2362 struct dsptask *task = dsptask[tid];
2363 struct taskdev *dev;
2365 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2366 printk(KERN_ERR "mbox: BKREQ with illegal tid! %d\n", tid);
2369 if (rcvtyp_wd(task->ttyp)) {
2371 "mbox: BKREQ from word receiving task! (task%d)\n", tid);
2374 if (rcvtyp_pvt(task->ttyp)) {
2376 "mbox: BKREQ from private receiving task! (task%d)\n",
2380 if (rcvtyp_psv(task->ttyp)) {
2382 "mbox: BKREQ from passive receiving task! (task%d)\n",
2388 spin_lock(&dev->wsz_lock);
2390 spin_unlock(&dev->wsz_lock);
2391 wake_up_interruptible(&dev->write_wait_q);
2394 void mbox_bkyld(struct mbcmd *mb)
2397 struct ipbuf_head *ipb_h;
2399 if (bid >= ipbcfg.ln) {
2400 printk(KERN_ERR "mbox: BKYLD with illegal bid! %d\n", bid);
2403 ipb_h = bid_to_ipbuf(bid);
2405 /* should be done in DSP, but just in case. */
2406 ipb_h->p->next = BID_NULL;
2408 /* we don't need to sync with DSP */
2409 ipb_bsycnt_dec(&ipbcfg);
2410 release_ipbuf(ipb_h);
2413 void mbox_bksndp(struct mbcmd *mb)
2416 struct dsptask *task = dsptask[tid];
2417 struct ipbuf_p *ipbp;
2419 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2420 printk(KERN_ERR "mbox: BKSNDP with illegal tid! %d\n", tid);
2423 if (sndtyp_wd(task->ttyp)) {
2425 "mbox: BKSNDP from word sending task! (task%d)\n", tid);
2428 if (sndtyp_gbl(task->ttyp)) {
2430 "mbox: BKSNDP from non-private sending task! (task%d)\n",
2436 * we should not have delayed block at this point
2437 * because read() routine releases the lock of the buffer and
2438 * until then DSP can't send next data.
2441 ipbp = task->ipbuf_pvt_r;
2442 if (sync_with_dsp(&ipbp->s, tid, 10) < 0) {
2443 printk(KERN_ERR "mbox: BKSNDP - IPBUF sync failed!\n");
2446 printk(KERN_DEBUG "mbox: ipbuf_pvt_r->a = 0x%08lx\n",
2447 MKLONG(ipbp->ah, ipbp->al));
2448 ipblink_add_pvt(&task->dev->rcvdt.bk.link);
2449 wake_up_interruptible(&task->dev->read_wait_q);
2452 void mbox_bkreqp(struct mbcmd *mb)
2455 struct dsptask *task = dsptask[tid];
2456 struct taskdev *dev;
2457 struct ipbuf_p *ipbp;
2459 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2460 printk(KERN_ERR "mbox: BKREQP with illegal tid! %d\n", tid);
2463 if (rcvtyp_wd(task->ttyp)) {
2465 "mbox: BKREQP from word receiving task! (task%d)\n", tid);
2468 if (rcvtyp_gbl(task->ttyp)) {
2470 "mbox: BKREQP from non-private receiving task! (task%d)\n", tid);
2473 if (rcvtyp_psv(task->ttyp)) {
2475 "mbox: BKREQP from passive receiving task! (task%d)\n", tid);
2479 ipbp = task->ipbuf_pvt_w;
2480 if (sync_with_dsp(&ipbp->s, TID_FREE, 10) < 0) {
2481 printk(KERN_ERR "mbox: BKREQP - IPBUF sync failed!\n");
2484 printk(KERN_DEBUG "mbox: ipbuf_pvt_w->a = 0x%08lx\n",
2485 MKLONG(ipbp->ah, ipbp->al));
2487 spin_lock(&dev->wsz_lock);
2488 dev->wsz = ipbp->c*2;
2489 spin_unlock(&dev->wsz_lock);
2490 wake_up_interruptible(&dev->write_wait_q);
2493 void mbox_tctl(struct mbcmd *mb)
2496 struct dsptask *task = dsptask[tid];
2498 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2499 printk(KERN_ERR "mbox: TCTL with illegal tid! %d\n", tid);
2503 if (!waitqueue_active(&task->dev->tctl_wait_q)) {
2504 printk(KERN_WARNING "mbox: unexpected TCTL from DSP!\n");
2508 task->dev->tctl_stat = mb->data;
2509 wake_up_interruptible(&task->dev->tctl_wait_q);
2512 void mbox_tcfg(struct mbcmd *mb)
2515 struct dsptask *task = dsptask[tid];
2520 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2521 printk(KERN_ERR "mbox: TCFG with illegal tid! %d\n", tid);
2524 if ((task->state != TASK_ST_CFGREQ) || (cfg_cmd != MBOX_CMD_DSP_TCFG)) {
2525 printk(KERN_WARNING "mbox: unexpected TCFG from DSP!\n");
2529 if (dsp_mem_enable(ipbuf_sys_da) < 0) {
2530 printk(KERN_ERR "mbox: TCFG - ipbuf_sys_da read failed!\n");
2531 dsp_mem_disable(ipbuf_sys_da);
2534 if (sync_with_dsp(&ipbuf_sys_da->s, tid, 10) < 0) {
2535 printk(KERN_ERR "mbox: TCFG - IPBUF sync failed!\n");
2536 dsp_mem_disable(ipbuf_sys_da);
2541 * read configuration data on system IPBUF
2543 buf = ipbuf_sys_da->d;
2544 task->ttyp = buf[0];
2545 task->ipbuf_pvt_r = MKVIRT(buf[1], buf[2]);
2546 task->ipbuf_pvt_w = MKVIRT(buf[3], buf[4]);
2547 task->map_base = MKVIRT(buf[5], buf[6]);
2548 task->map_length = MKLONG(buf[7], buf[8]) << 1; /* word -> byte */
2549 tnm = MKVIRT(buf[9], buf[10]);
2550 release_ipbuf_pvt(ipbuf_sys_da);
2551 dsp_mem_disable(ipbuf_sys_da);
2554 * copy task name string
2556 if (dsp_address_validate(tnm, TNM_LEN, "task name buffer") < 0) {
2557 task->name[0] = '\0';
2561 for (i = 0; i < TNM_LEN-1; i++) {
2562 /* avoiding byte access */
2564 task->name[i] = tmp & 0x00ff;
2568 task->name[TNM_LEN-1] = '\0';
2570 task->state = TASK_ST_READY;
2572 wake_up_interruptible(&cfg_wait_q);
2575 void mbox_tadd(struct mbcmd *mb)
2579 if ((!waitqueue_active(&cfg_wait_q)) || (cfg_cmd != MBOX_CMD_DSP_TADD)) {
2580 printk(KERN_WARNING "mbox: unexpected TADD from DSP!\n");
2584 wake_up_interruptible(&cfg_wait_q);
2587 void mbox_tdel(struct mbcmd *mb)
2591 if ((!waitqueue_active(&cfg_wait_q)) || (cfg_cmd != MBOX_CMD_DSP_TDEL)) {
2592 printk(KERN_WARNING "mbox: unexpected TDEL from DSP!\n");
2596 wake_up_interruptible(&cfg_wait_q);
2599 void mbox_err_fatal(u8 tid)
2601 struct dsptask *task = dsptask[tid];
2602 struct taskdev *dev;
2604 if ((tid >= TASKDEV_MAX) || (task == NULL)) {
2605 printk(KERN_ERR "mbox: FATAL ERR with illegal tid! %d\n", tid);
2609 /* wake up waiting processes */
2611 wake_up_interruptible_all(&dev->read_wait_q);
2612 wake_up_interruptible_all(&dev->write_wait_q);
2613 wake_up_interruptible_all(&dev->tctl_wait_q);
2616 static u16 *dbg_buf;
2617 static u16 dbg_buf_sz, dbg_line_sz;
2620 int dsp_dbg_config(u16 *buf, u16 sz, u16 lsz)
2622 #ifdef OLD_BINARY_SUPPORT
2623 if ((mbox_revision == MBREV_3_0) || (mbox_revision == MBREV_3_2)) {
2632 if (dsp_address_validate(buf, sz, "debug buffer") < 0)
2637 "omapdsp: dbg_buf lsz (%d) is greater than its "
2638 "buffer size (%d)\n", lsz, sz);
2650 void dsp_dbg_stop(void)
2655 #ifdef OLD_BINARY_SUPPORT
2656 static void mbox_dbg_old(struct mbcmd *mb);
2659 void mbox_dbg(struct mbcmd *mb)
2663 char s[80], *s_end = &s[79], *p;
2667 #ifdef OLD_BINARY_SUPPORT
2668 if ((mbox_revision == MBREV_3_0) || (mbox_revision == MBREV_3_2)) {
2674 if (((tid >= TASKDEV_MAX) || (dsptask[tid] == NULL)) &&
2675 (tid != TID_ANON)) {
2676 printk(KERN_ERR "mbox: DBG with illegal tid! %d\n", tid);
2679 if (dbg_buf == NULL) {
2680 printk(KERN_ERR "mbox: DBG command received, but "
2681 "dbg_buf has not been configured yet.\n");
2685 if (dsp_mem_enable(dbg_buf) < 0)
2688 src = &dbg_buf[dbg_rp];
2690 for (i = 0; i < cnt; i++) {
2693 * Be carefull that dbg_buf should not be read with
2694 * 1-byte access since it might be placed in DARAM/SARAM
2695 * and it can cause unexpected byteswap.
2697 * *(p++) = *(src++) & 0xff;
2698 * causes 1-byte access!
2701 *(p++) = tmp & 0xff;
2702 if (*(p-1) == '\n') {
2704 printk(KERN_INFO "%s", s);
2710 printk(KERN_INFO "%s\n", s);
2717 printk(KERN_INFO "%s\n", s);
2719 if ((dbg_rp += cnt + 1) > dbg_buf_sz - dbg_line_sz)
2722 dsp_mem_disable(dbg_buf);
2725 #ifdef OLD_BINARY_SUPPORT
2726 static void mbox_dbg_old(struct mbcmd *mb)
2729 char s[80], *s_end = &s[79], *p;
2735 if (((tid >= TASKDEV_MAX) || (dsptask[tid] == NULL)) &&
2736 (tid != TID_ANON)) {
2737 printk(KERN_ERR "mbox: DBG with illegal tid! %d\n", tid);
2740 if (dsp_mem_enable(ipbuf_sys_da) < 0) {
2741 printk(KERN_ERR "mbox: DBG - ipbuf_sys_da read failed!\n");
2744 if (sync_with_dsp(&ipbuf_sys_da->s, tid, 10) < 0) {
2745 printk(KERN_ERR "mbox: DBG - IPBUF sync failed!\n");
2748 buf = ipbuf_sys_da->d;
2750 src = MKVIRT(buf[1], buf[2]);
2751 if (dsp_address_validate(src, cnt, "dbg buffer") < 0)
2754 if (dsp_mem_enable(src) < 0)
2758 for (i = 0; i < cnt; i++) {
2761 * Be carefull that ipbuf should not be read with
2762 * 1-byte access since it might be placed in DARAM/SARAM
2763 * and it can cause unexpected byteswap.
2765 * *(p++) = *(src++) & 0xff;
2766 * causes 1-byte access!
2769 *(p++) = tmp & 0xff;
2770 if (*(p-1) == '\n') {
2772 printk(KERN_INFO "%s", s);
2778 printk(KERN_INFO "%s\n", s);
2785 printk(KERN_INFO "%s\n", s);
2788 dsp_mem_disable(src);
2790 release_ipbuf_pvt(ipbuf_sys_da);
2792 dsp_mem_disable(ipbuf_sys_da);
2794 #endif /* OLD_BINARY_SUPPORT */
2797 * sysfs files: for each device
2801 static ssize_t devname_show(struct device *d, struct device_attribute *attr,
2804 return sprintf(buf, "%s\n", to_taskdev(d)->name);
2808 static ssize_t devstate_show(struct device *d, struct device_attribute *attr,
2811 return sprintf(buf, "%s\n", devstate_name(to_taskdev(d)->state));
2815 static ssize_t proc_list_show(struct device *d, struct device_attribute *attr,
2818 struct taskdev *dev;
2819 struct proc_list *pl;
2822 dev = to_taskdev(d);
2823 spin_lock(&dev->proc_list_lock);
2824 list_for_each_entry(pl, &dev->proc_list, list_head) {
2825 /* need to lock tasklist_lock before calling
2826 * find_task_by_pid_type. */
2827 if (find_task_by_pid_type(PIDTYPE_PID, pl->pid) != NULL)
2828 len += sprintf(buf + len, "%d\n", pl->pid);
2829 read_unlock(&tasklist_lock);
2831 spin_unlock(&dev->proc_list_lock);
2837 static ssize_t taskname_show(struct device *d, struct device_attribute *attr,
2840 struct taskdev *dev = to_taskdev(d);
2843 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
2846 len = sprintf(buf, "%s\n", dev->task->name);
2848 devstate_read_unlock(dev);
2853 static ssize_t ttyp_show(struct device *d, struct device_attribute *attr,
2856 struct taskdev *dev = to_taskdev(d);
2860 if (!devstate_read_lock_and_test(dev, TASKDEV_ST_ATTACHED))
2863 ttyp = dev->task->ttyp;
2864 len += sprintf(buf + len, "0x%04x\n", ttyp);
2865 len += sprintf(buf + len, "%s %s send\n",
2866 (sndtyp_acv(ttyp)) ? "active" :
2868 (sndtyp_wd(ttyp)) ? "word" :
2869 (sndtyp_pvt(ttyp)) ? "private block" :
2871 len += sprintf(buf + len, "%s %s receive\n",
2872 (rcvtyp_acv(ttyp)) ? "active" :
2874 (rcvtyp_wd(ttyp)) ? "word" :
2875 (rcvtyp_pvt(ttyp)) ? "private block" :
2878 devstate_read_unlock(dev);
2883 static ssize_t fifosz_show(struct device *d, struct device_attribute *attr,
2886 struct fifo_struct *fifo = &to_taskdev(d)->rcvdt.fifo;
2887 return sprintf(buf, "%d\n", fifo->sz);
2890 static int fifosz_store(struct device *d, struct device_attribute *attr,
2891 const char *buf, size_t count)
2893 struct taskdev *dev = to_taskdev(d);
2894 unsigned long fifosz;
2897 fifosz = simple_strtol(buf, NULL, 10);
2898 ret = taskdev_set_fifosz(dev, fifosz);
2900 return (ret < 0) ? ret : strlen(buf);
2904 static ssize_t fifocnt_show(struct device *d, struct device_attribute *attr,
2907 struct fifo_struct *fifo = &to_taskdev(d)->rcvdt.fifo;
2908 return sprintf(buf, "%d\n", fifo->cnt);
2912 static __inline__ char *bid_name(u16 bid)
2922 sprintf(s, "%d", bid);
2927 static ssize_t ipblink_show(struct device *d, struct device_attribute *attr,
2930 struct rcvdt_bk_struct *rcvdt = &to_taskdev(d)->rcvdt.bk;
2933 spin_lock(&rcvdt->link.lock);
2934 len = sprintf(buf, "top %s\ntail %s\n",
2935 bid_name(rcvdt->link.top), bid_name(rcvdt->link.tail));
2936 spin_unlock(&rcvdt->link.lock);
2942 static ssize_t wsz_show(struct device *d, struct device_attribute *attr,
2945 return sprintf(buf, "%d\n", to_taskdev(d)->wsz);
2949 static ssize_t mmap_show(struct device *d, struct device_attribute *attr,
2952 struct dsptask *task = to_taskdev(d)->task;
2953 return sprintf(buf, "0x%p 0x%x\n", task->map_base, task->map_length);
2957 * called from ipbuf_show()
2959 int ipbuf_is_held(u8 tid, u16 bid)
2961 struct dsptask *task = dsptask[tid];
2962 struct ipblink *link;
2969 link = &task->dev->rcvdt.bk.link;
2970 spin_lock(&link->lock);
2971 ipblink_for_each(b, link) {
2972 if (b == bid) { /* found */
2977 spin_unlock(&link->lock);
2982 int __init dsp_taskmod_init(void)
2986 memset(taskdev, 0, sizeof(void *) * TASKDEV_MAX);
2987 memset(dsptask, 0, sizeof(void *) * TASKDEV_MAX);
2989 retval = register_chrdev(OMAP_DSP_TASK_MAJOR, "dsptask",
2993 "omapdsp: failed to register task device: %d\n", retval);
2997 retval = bus_register(&dsptask_bus);
3000 "omapdsp: failed to register DSP task bus: %d\n",
3002 unregister_chrdev(OMAP_DSP_TASK_MAJOR, "dsptask");
3005 retval = driver_register(&dsptask_driver);
3008 "omapdsp: failed to register DSP task driver: %d\n",
3010 bus_unregister(&dsptask_bus);
3011 unregister_chrdev(OMAP_DSP_TASK_MAJOR, "dsptask");
3014 dsp_task_class = class_create(THIS_MODULE, "dsptask");
3019 void dsp_taskmod_exit(void)
3021 class_destroy(dsp_task_class);
3022 driver_unregister(&dsptask_driver);
3023 bus_unregister(&dsptask_bus);
3024 unregister_chrdev(OMAP_DSP_TASK_MAJOR, "dsptask");