#include <linux/delay.h>
#include <linux/mm.h>
#include <linux/clk.h>
+#include <linux/mutex.h>
#include <asm/io.h>
#include <asm/tlbflush.h>
#include <asm/irq.h>
saram_base, saram_size;
struct cpustat {
- struct semaphore sem;
+ struct mutex lock;
enum e_cpustat stat;
enum e_cpustat req;
unsigned short icrmask;
void (*mem_rel_cb)(void);
};
struct cpustat cpustat = {
- .sem = __SEMAPHORE_INIT(cpustat.sem, 1),
+ .lock = __MUTEX_INITIALIZER(cpustat.lock),
.stat = CPUSTAT_RESET,
.icrmask = 0xffff,
};
void dsp_cpustat_request(enum e_cpustat req)
{
- down(&cpustat.sem);
+ mutex_lock(&cpustat.lock);
cpustat.req = req;
dsp_cpustat_update();
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
}
enum e_cpustat dsp_cpustat_get_stat(void)
void dsp_cpustat_set_icrmask(unsigned short mask)
{
- down(&cpustat.sem);
+ mutex_lock(&cpustat.lock);
cpustat.icrmask = mask;
dsp_cpustat_update();
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
}
void omap_dsp_request_mpui(void)
{
- down(&cpustat.sem);
+ mutex_lock(&cpustat.lock);
if (cpustat.usecount.mpui++ == 0)
dsp_cpustat_update();
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
}
void omap_dsp_release_mpui(void)
{
- down(&cpustat.sem);
+ mutex_lock(&cpustat.lock);
if (cpustat.usecount.mpui-- == 0) {
printk(KERN_ERR
"omapdsp: unbalanced mpui request/release detected.\n"
}
if (cpustat.usecount.mpui == 0)
dsp_cpustat_update();
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
}
int omap_dsp_request_mem(void)
{
int ret = 0;
- down(&cpustat.sem);
+ mutex_lock(&cpustat.lock);
if ((cpustat.usecount.mem++ == 0) &&
(cpustat.usecount.mem_delayed == 0)) {
if (cpustat.mem_req_cb) {
dsp_cpustat_update();
}
out:
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
return ret;
}
/*
* release_mem will be delayed.
*/
-static void do_release_mem(void) {
- down(&cpustat.sem);
+static void do_release_mem(void)
+{
+ mutex_lock(&cpustat.lock);
cpustat.usecount.mem_delayed = 0;
if (cpustat.usecount.mem == 0) {
dsp_cpustat_update();
if (cpustat.mem_rel_cb)
cpustat.mem_rel_cb();
}
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
}
static DECLARE_WORK(mem_rel_work, (void (*)(void *))do_release_mem, NULL);
int omap_dsp_release_mem(void)
{
- down(&cpustat.sem);
+ mutex_lock(&cpustat.lock);
/* cancel previous release work */
cancel_delayed_work(&mem_rel_work);
schedule_delayed_work(&mem_rel_work, HZ);
}
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
return 0;
}
void dsp_register_mem_cb(int (*req_cb)(void), void (*rel_cb)(void))
{
- down(&cpustat.sem);
+ mutex_lock(&cpustat.lock);
cpustat.mem_req_cb = req_cb;
cpustat.mem_rel_cb = rel_cb;
*/
BUG_ON(cpustat.usecount.mem == 0);
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
}
void dsp_unregister_mem_cb(void)
{
- down(&cpustat.sem);
+ mutex_lock(&cpustat.lock);
cpustat.mem_req_cb = NULL;
cpustat.mem_rel_cb = NULL;
- up(&cpustat.sem);
+ mutex_unlock(&cpustat.lock);
}
/*
#include <linux/delay.h>
#include <linux/platform_device.h>
#include <linux/clk.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/ioctls.h>
int mbx_revision;
static DECLARE_WAIT_QUEUE_HEAD(ioctl_wait_q);
static unsigned short ioctl_wait_cmd;
-static DECLARE_MUTEX(ioctl_sem);
+static DEFINE_MUTEX(ioctl_lock);
static unsigned char n_stask;
struct mbcmd mb;
int ret = 0;
- if (down_interruptible(&ioctl_sem))
+ if (mutex_lock_interruptible(&ioctl_lock))
return -ERESTARTSYS;
ioctl_wait_cmd = MBCMD(REGRW);
*val = varread_val[0];
up_out:
- up(&ioctl_sem);
+ mutex_unlock(&ioctl_lock);
return ret;
}
struct mbcmd mb;
int ret = 0;
- if (down_interruptible(&ioctl_sem))
+ if (mutex_lock_interruptible(&ioctl_lock))
return -ERESTARTSYS;
ioctl_wait_cmd = MBCMD(GETVAR);
memcpy(val, varread_val, sz * sizeof(short));
up_out:
- up(&ioctl_sem);
+ mutex_unlock(&ioctl_lock);
return ret;
}
struct mbcmd mb;
int ret = 0;
- if (down_interruptible(&ioctl_sem))
+ if (mutex_lock_interruptible(&ioctl_lock))
return -ERESTARTSYS;
if (cfgstat != CFG_ERR) {
#endif
if ((ret = dsp_task_config_all(n_stask)) < 0) {
- up(&ioctl_sem);
+ mutex_unlock(&ioctl_lock);
dspuncfg();
dsp_mem_disable((void *)dspmem_base);
return -EINVAL;
up_out:
dsp_mem_disable((void *)dspmem_base);
- up(&ioctl_sem);
+ mutex_unlock(&ioctl_lock);
return ret;
}
return -EBUSY;
}
- if (down_interruptible(&ioctl_sem))
+ if (mutex_lock_interruptible(&ioctl_lock))
return -ERESTARTSYS;
/* FIXME: lock task module */
ipbuf_stop();
cfgstat = CFG_ERR;
- up(&ioctl_sem);
+ mutex_unlock(&ioctl_lock);
return 0;
}
struct mbcmd mb;
int ret = 0;
- if (down_interruptible(&ioctl_sem))
+ if (mutex_lock_interruptible(&ioctl_lock))
return -ERESTARTSYS;
ioctl_wait_cmd = MBCMD(POLL);
}
up_out:
- up(&ioctl_sem);
+ mutex_unlock(&ioctl_lock);
return ret;
}
return -EINVAL;
}
- if (down_interruptible(&ioctl_sem))
+ if (mutex_lock_interruptible(&ioctl_lock))
return -ERESTARTSYS;
cfgstat_save_suspend = cfgstat;
transition:
cfgstat = CFG_SUSPEND;
up_out:
- up(&ioctl_sem);
+ mutex_unlock(&ioctl_lock);
return ret;
}
int ret = 0;
struct mbcmd mb;
- if (down_interruptible(&ioctl_sem))
+ if (mutex_lock_interruptible(&ioctl_lock))
return -ERESTARTSYS;
ioctl_wait_cmd = MBCMD(KFUNC);
printk(KERN_ERR "omapdsp: fb disable error!\n");
ret = -EINVAL;
}
- up(&ioctl_sem);
+ mutex_unlock(&ioctl_lock);
return ret;
}
#include <linux/sched.h>
#include <linux/mm.h>
#include <linux/proc_fs.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <asm/signal.h>
/* read stuff */
wait_queue_head_t read_wait_q;
- struct semaphore read_sem;
+ struct mutex read_mutex;
/* write stuff */
wait_queue_head_t write_wait_q;
- struct semaphore write_sem;
+ struct mutex write_mutex;
/* ioctl stuff */
wait_queue_head_t ioctl_wait_q;
- struct semaphore ioctl_sem;
+ struct mutex ioctl_mutex;
/* device lock */
- struct semaphore lock_sem;
+ struct mutex lock;
pid_t lock_pid;
};
static struct class *dsp_task_class;
static struct taskdev *taskdev[TASKDEV_MAX];
static struct dsptask *dsptask[TASKDEV_MAX];
-static DECLARE_MUTEX(cfg_sem);
+static DEFINE_MUTEX(cfg_lock);
static unsigned short cfg_cmd;
static unsigned char cfg_tid;
static DECLARE_WAIT_QUEUE_HEAD(cfg_wait_q);
spin_unlock(&dev->state_lock);
}
-static __inline__ int down_tasksem_interruptible(struct taskdev *dev,
- struct semaphore *sem)
+static inline int taskdev_lock_interruptible(struct taskdev *dev,
+ struct mutex *lock)
{
int ret;
if (dev->lock_pid == current->pid) {
/* this process has lock */
- ret = down_interruptible(sem);
+ ret = mutex_lock_interruptible(lock);
} else {
- if ((ret = down_interruptible(&dev->lock_sem)) != 0)
+ if ((ret = mutex_lock_interruptible(&dev->lock)) != 0)
return ret;
- ret = down_interruptible(sem);
- up(&dev->lock_sem);
+ ret = mutex_lock_interruptible(lock);
+ mutex_unlock(&dev->lock);
}
return ret;
}
static int taskdev_lock(struct taskdev *dev)
{
- if (down_interruptible(&dev->lock_sem))
+ if (mutex_lock_interruptible(&dev->lock))
return -ERESTARTSYS;
dev->lock_pid = current->pid;
return 0;
return -EINVAL;
}
dev->lock_pid = 0;
- up(&dev->lock_sem);
+ mutex_unlock(&dev->lock);
return 0;
}
/* TCFG request */
task->state = TASK_STATE_CFGREQ;
- if (down_interruptible(&cfg_sem)) {
+ if (mutex_lock_interruptible(&cfg_lock)) {
ret = -ERESTARTSYS;
goto fail_out;
}
mbcmd_set(mb, MBCMD(TCFG), tid, 0);
dsp_mbcmd_send_and_wait(&mb, &cfg_wait_q);
cfg_cmd = 0;
- up(&cfg_sem);
+ mutex_unlock(&cfg_lock);
if (task->state != TASK_STATE_READY) {
printk(KERN_ERR "omapdsp: task %d configuration error!\n", tid);
return -EINVAL;
}
- if (down_tasksem_interruptible(dev, &dev->read_sem))
+ if (taskdev_lock_interruptible(dev, &dev->read_mutex))
return -ERESTARTSYS;
if (devstate_lock(dev, OMAP_DSP_DEVSTATE_ATTACHED) < 0) {
ret = -ERESTARTSYS;
up_out:
if (have_devstate_lock)
devstate_unlock(dev);
- up(&dev->read_sem);
+ mutex_unlock(&dev->read_mutex);
return ret;
}
return -EINVAL;
}
- if (down_tasksem_interruptible(dev, &dev->read_sem))
+ if (taskdev_lock_interruptible(dev, &dev->read_mutex))
return -ERESTARTSYS;
if (devstate_lock(dev, OMAP_DSP_DEVSTATE_ATTACHED) < 0) {
ret = -ERESTARTSYS;
up_out:
if (have_devstate_lock)
devstate_unlock(dev);
- up(&dev->read_sem);
+ mutex_unlock(&dev->read_mutex);
return ret;
}
count = 2;
}
- if (down_tasksem_interruptible(dev, &dev->read_sem))
+ if (taskdev_lock_interruptible(dev, &dev->read_mutex))
return -ERESTARTSYS;
if (devstate_lock(dev, OMAP_DSP_DEVSTATE_ATTACHED) < 0) {
ret = -ERESTARTSYS;
unlock_out:
devstate_unlock(dev);
up_out:
- up(&dev->read_sem);
+ mutex_unlock(&dev->read_mutex);
return ret;
}
return -EINVAL;
}
- if (down_tasksem_interruptible(dev, &dev->read_sem))
+ if (taskdev_lock_interruptible(dev, &dev->read_mutex))
return -ERESTARTSYS;
if (devstate_lock(dev, OMAP_DSP_DEVSTATE_ATTACHED) < 0) {
ret = -ERESTARTSYS;
unlock_out:
devstate_unlock(dev);
up_out:
- up(&dev->read_sem);
+ mutex_unlock(&dev->read_mutex);
return ret;
}
count = 2;
}
- if (down_tasksem_interruptible(dev, &dev->write_sem))
+ if (taskdev_lock_interruptible(dev, &dev->write_mutex))
return -ERESTARTSYS;
if (devstate_lock(dev, OMAP_DSP_DEVSTATE_ATTACHED) < 0) {
ret = -ERESTARTSYS;
up_out:
if (have_devstate_lock)
devstate_unlock(dev);
- up(&dev->write_sem);
+ mutex_unlock(&dev->write_mutex);
return ret;
}
return -EINVAL;
}
- if (down_tasksem_interruptible(dev, &dev->write_sem))
+ if (taskdev_lock_interruptible(dev, &dev->write_mutex))
return -ERESTARTSYS;
if (devstate_lock(dev, OMAP_DSP_DEVSTATE_ATTACHED) < 0) {
ret = -ERESTARTSYS;
up_out:
if (have_devstate_lock)
devstate_unlock(dev);
- up(&dev->write_sem);
+ mutex_unlock(&dev->write_mutex);
return ret;
}
/*
* actually only interractive commands need to lock
- * the semaphore, but here all commands do it for simplicity.
+ * the mutex, but here all commands do it for simplicity.
*/
- if (down_tasksem_interruptible(dev, &dev->ioctl_sem))
+ if (taskdev_lock_interruptible(dev, &dev->ioctl_mutex))
return -ERESTARTSYS;
if (devstate_lock(dev, OMAP_DSP_DEVSTATE_ATTACHED) < 0) {
ret = -ERESTARTSYS;
unlock_out:
devstate_unlock(dev);
up_out:
- up(&dev->ioctl_sem);
+ mutex_unlock(&dev->ioctl_mutex);
return ret;
}
init_waitqueue_head(&dev->read_wait_q);
init_waitqueue_head(&dev->write_wait_q);
init_waitqueue_head(&dev->ioctl_wait_q);
- init_MUTEX(&dev->read_sem);
- init_MUTEX(&dev->write_sem);
- init_MUTEX(&dev->ioctl_sem);
- init_MUTEX(&dev->lock_sem);
+ mutex_init(&dev->read_mutex);
+ mutex_init(&dev->write_mutex);
+ mutex_init(&dev->ioctl_mutex);
+ mutex_init(&dev->lock);
dev->lock_pid = 0;
strncpy(dev->name, name, OMAP_DSP_TNM_LEN);
argv[0] = adr >> 16; /* addrh */
argv[1] = adr & 0xffff; /* addrl */
- if (down_interruptible(&cfg_sem)) {
+ if (mutex_lock_interruptible(&cfg_lock)) {
ret = -ERESTARTSYS;
goto fail_out;
}
tid = cfg_tid;
cfg_tid = OMAP_DSP_TID_ANON;
cfg_cmd = 0;
- up(&cfg_sem);
+ mutex_unlock(&cfg_lock);
if (tid == OMAP_DSP_TID_ANON) {
printk(KERN_ERR "omapdsp: tadd failed!\n");
dev->state = OMAP_DSP_DEVSTATE_DELING;
- if (down_interruptible(&cfg_sem)) {
+ if (mutex_lock_interruptible(&cfg_lock)) {
printk(KERN_ERR "omapdsp: aborting tdel process. "
"DSP side could be corrupted.\n");
goto fail_out;
tid_response = cfg_tid;
cfg_tid = OMAP_DSP_TID_ANON;
cfg_cmd = 0;
- up(&cfg_sem);
+ mutex_unlock(&cfg_lock);
if (tid_response != tid)
printk(KERN_ERR "omapdsp: tdel failed. "
task = dev->task;
tid = task->tid;
- if (down_interruptible(&cfg_sem)) {
+ if (mutex_lock_interruptible(&cfg_lock)) {
if (type == OMAP_DSP_MBCMD_TDEL_SAFE) {
dev->state = OMAP_DSP_DEVSTATE_DELREQ;
return -ERESTARTSYS;
tid_response = cfg_tid;
cfg_tid = OMAP_DSP_TID_ANON;
cfg_cmd = 0;
- up(&cfg_sem);
+ mutex_unlock(&cfg_lock);
detach_out:
taskdev_detach_task(dev);