Skip to contentSkip to conversation

ARM: OMAP: dspgateway sem2mutex conversion.

PATCH In review Paul Mundt 2 participants 2 messages May 3, 2006 – May 4, 2006

Subsystems (2)
lore
Share & tools
lore

Paul Mundt

author
#0 lore raw

PATCH 1/1 ARM: OMAP: dspgateway sem2mutex conversion.

This has been lagging behind a bit, primarily due to the fact that the OMAP tree has gotten a bit out of sync with the DSP gateway updates (we'll leave that for another patch).

This is a quick and simple sem2mutex conversion, after this dspgateway is essentially down to a single rwsem for the exmap cases, and that will remain as it is.

Against current git.

---

 arch/arm/plat-omap/dsp/dsp_common.c |   44 ++++++++++---------
 arch/arm/plat-omap/dsp/dsp_core.c   |    9 ++--
 arch/arm/plat-omap/dsp/dsp_ctl.c    |   33 +++++++-------
 arch/arm/plat-omap/dsp/task.c       |   81 ++++++++++++++++++------------------
 arch/arm/plat-omap/dsp/taskwatch.c  |    7 +--
 5 files changed, 90 insertions(+), 84 deletions(-)
arch/arm/plat-omap/dsp/dsp_common.c +23 -21
index 9c70156..03f9134 100644
@@ -31,6 +31,7 @@ #include <linux/sched.h>
 #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>
@@ -45,7 +46,7 @@ unsigned long dspmem_base, dspmem_size,
 	      saram_base, saram_size;
 
 struct cpustat {
-	struct semaphore sem;
+	struct mutex lock;
 	enum e_cpustat stat;
 	enum e_cpustat req;
 	unsigned short icrmask;
@@ -58,7 +59,7 @@ struct cpustat {
 	void (*mem_rel_cb)(void);
 };
 struct cpustat cpustat = {
-	.sem = __SEMAPHORE_INIT(cpustat.sem, 1),
+	.lock = __MUTEX_INITIALIZER(cpustat.lock),
 	.stat = CPUSTAT_RESET,
 	.icrmask = 0xffff,
 };
@@ -364,10 +365,10 @@ static void dsp_cpustat_update(void)
 
 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)
@@ -382,23 +383,23 @@ unsigned short dsp_cpustat_get_icrmask(v
 
 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"
@@ -408,14 +409,14 @@ void omap_dsp_release_mpui(void)
 	}
 	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) {
@@ -427,7 +428,7 @@ int omap_dsp_request_mem(void)
 		dsp_cpustat_update();
 	}
 out:
-	up(&cpustat.sem);
+	mutex_unlock(&cpustat.lock);
 
 	return ret;
 }
@@ -435,22 +436,23 @@ out:
 /*
  * 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);
@@ -468,14 +470,14 @@ int omap_dsp_release_mem(void)
 		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;
@@ -485,15 +487,15 @@ void dsp_register_mem_cb(int (*req_cb)(v
 	 */
 	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);
 }
 
 /*
arch/arm/plat-omap/dsp/dsp_core.c +5 -4
index 4256577..65ce664 100644
@@ -32,6 +32,7 @@ #include <linux/devfs_fs_kernel.h>
 #include <linux/sched.h>
 #include <linux/interrupt.h>
 #include <linux/proc_fs.h>
+#include <linux/mutex.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/signal.h>
@@ -248,7 +249,7 @@ int __mbcmd_send(struct mbcmd *mb)
  */
 int __dsp_mbcmd_send(struct mbcmd *mb, struct mb_exarg *arg, int recovery_flag)
 {
-	static DECLARE_MUTEX(mbsend_sem);
+	static DEFINE_MUTEX(mbsend_lock);
 	int ret = 0;
 
 	/*
@@ -260,14 +261,14 @@ int __dsp_mbcmd_send(struct mbcmd *mb, s
 		return -1;
 	}
 
-	if (down_interruptible(&mbsend_sem) < 0)
+	if (mutex_lock_interruptible(&mbsend_lock) < 0)
 		return -1;
 
 	if (arg) {	/* we have extra argument */
 		int i;
 
 		/*
-		 * even if ipbuf_sys_ad is in DSP internal memory, 
+		 * even if ipbuf_sys_ad is in DSP internal memory,
 		 * dsp_mem_enable() never cause to call PM mailbox command
 		 * because in that case DSP memory should be always enabled.
 		 * (see ipbuf_sys_hold_mem_active in ipbuf.c)
@@ -291,7 +292,7 @@ int __dsp_mbcmd_send(struct mbcmd *mb, s
 	ret = __mbcmd_send(mb);
 
 out:
-	up(&mbsend_sem);
+	mutex_unlock(&mbsend_lock);
 	return ret;
 }
 
arch/arm/plat-omap/dsp/dsp_ctl.c +17 -16
index fbe2f5c..3fab948 100644
@@ -35,6 +35,7 @@ #include <linux/sched.h>
 #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>
@@ -56,7 +57,7 @@ static enum cfgstat {
 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;
 
@@ -71,7 +72,7 @@ static int dsp_regread(unsigned short cm
 	struct mbcmd mb;
 	int ret = 0;
 
-	if (down_interruptible(&ioctl_sem))
+	if (mutex_lock_interruptible(&ioctl_lock))
 		return -ERESTARTSYS;
 
 	ioctl_wait_cmd = MBCMD(REGRW);
@@ -87,7 +88,7 @@ static int dsp_regread(unsigned short cm
 	*val = varread_val[0];
 
 up_out:
-	up(&ioctl_sem);
+	mutex_unlock(&ioctl_lock);
 	return ret;
 }
 
@@ -111,7 +112,7 @@ static int dsp_getvar(unsigned char vari
 	struct mbcmd mb;
 	int ret = 0;
 
-	if (down_interruptible(&ioctl_sem))
+	if (mutex_lock_interruptible(&ioctl_lock))
 		return -ERESTARTSYS;
 
 	ioctl_wait_cmd = MBCMD(GETVAR);
@@ -127,7 +128,7 @@ static int dsp_getvar(unsigned char vari
 	memcpy(val, varread_val, sz * sizeof(short));
 
 up_out:
-	up(&ioctl_sem);
+	mutex_unlock(&ioctl_lock);
 	return ret;
 }
 
@@ -142,7 +143,7 @@ static int dspcfg(void)
 	struct mbcmd mb;
 	int ret = 0;
 
-	if (down_interruptible(&ioctl_sem))
+	if (mutex_lock_interruptible(&ioctl_lock))
 		return -ERESTARTSYS;
 
 	if (cfgstat != CFG_ERR) {
@@ -192,7 +193,7 @@ #ifdef OLD_BINARY_SUPPORT
 #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;
@@ -211,7 +212,7 @@ #endif
 
 up_out:
 	dsp_mem_disable((void *)dspmem_base);
-	up(&ioctl_sem);
+	mutex_unlock(&ioctl_lock);
 	return ret;
 }
 
@@ -222,7 +223,7 @@ int dspuncfg(void)
 		return -EBUSY;
 	}
 
-	if (down_interruptible(&ioctl_sem))
+	if (mutex_lock_interruptible(&ioctl_lock))
 		return -ERESTARTSYS;
 
 	/* FIXME: lock task module */
@@ -240,7 +241,7 @@ int dspuncfg(void)
 	ipbuf_stop();
 	cfgstat = CFG_ERR;
 
-	up(&ioctl_sem);
+	mutex_unlock(&ioctl_lock);
 	return 0;
 }
 
@@ -257,7 +258,7 @@ int dsp_poll(void)
 	struct mbcmd mb;
 	int ret = 0;
 
-	if (down_interruptible(&ioctl_sem))
+	if (mutex_lock_interruptible(&ioctl_lock))
 		return -ERESTARTSYS;
 
 	ioctl_wait_cmd = MBCMD(POLL);
@@ -271,7 +272,7 @@ int dsp_poll(void)
 	}
 
 up_out:
-	up(&ioctl_sem);
+	mutex_unlock(&ioctl_lock);
 	return ret;
 }
 
@@ -301,7 +302,7 @@ int dsp_suspend(void)
 		return -EINVAL;
 	}
 
-	if (down_interruptible(&ioctl_sem))
+	if (mutex_lock_interruptible(&ioctl_lock))
 		return -ERESTARTSYS;
 
 	cfgstat_save_suspend = cfgstat;
@@ -330,7 +331,7 @@ int dsp_suspend(void)
 transition:
 	cfgstat = CFG_SUSPEND;
 up_out:
-	up(&ioctl_sem);
+	mutex_unlock(&ioctl_lock);
 	return ret;
 }
 
@@ -356,7 +357,7 @@ static int dsp_fbctl_disable(void)
 	int ret = 0;
 	struct mbcmd mb;
 
-	if (down_interruptible(&ioctl_sem))
+	if (mutex_lock_interruptible(&ioctl_lock))
 		return -ERESTARTSYS;
 
 	ioctl_wait_cmd = MBCMD(KFUNC);
@@ -367,7 +368,7 @@ static int dsp_fbctl_disable(void)
 		printk(KERN_ERR "omapdsp: fb disable error!\n");
 		ret = -EINVAL;
 	}
-	up(&ioctl_sem);
+	mutex_unlock(&ioctl_lock);
 
 	return ret;
 }
arch/arm/plat-omap/dsp/task.c +41 -40

271 lines not on this page · raw message

arch/arm/plat-omap/dsp/taskwatch.c +4 -3
index b09c59d..cdd7182 100644
@@ -31,6 +31,7 @@ #include <linux/fs.h>
 #include <linux/poll.h>
 #include <linux/interrupt.h>
 #include <linux/sched.h>
+#include <linux/mutex.h>
 #include <asm/uaccess.h>
 #include <asm/io.h>
 #include <asm/arch/dsp.h>
@@ -111,10 +112,10 @@ static unsigned int dsp_twch_poll(struct
 static int dsp_twch_ioctl(struct inode *inode, struct file *file,
 			  unsigned int cmd, unsigned long arg)
 {
-	static DECLARE_MUTEX(ioctl_sem);
+	static DEFINE_MUTEX(ioctl_lock);
 	int ret;
 
-	if (down_interruptible(&ioctl_sem))
+	if (mutex_lock_interruptible(&ioctl_lock))
 		return -ERESTARTSYS;
 
 	switch (cmd) {
@@ -166,7 +167,7 @@ static int dsp_twch_ioctl(struct inode *
 	}
 
 up_out:
-	up(&ioctl_sem);
+	mutex_unlock(&ioctl_lock);
 	return ret;
 }
 
#1 lore raw
Quoted 9 lines · Paul Mundt

This has been lagging behind a bit, primarily due to the fact that the OMAP tree has gotten a bit out of sync with the DSP gateway updates (we'll leave that for another patch).

This is a quick and simple sem2mutex conversion, after this dspgateway is essentially down to a single rwsem for the exmap cases, and that will remain as it is.

Against current git.

Thanks & pushed.

Tony