[PATCH 2/4] media: dvb-fe changes to use tuner token

From: Shuah Khan
Date: Tue Apr 29 2014 - 15:51:04 EST


Add a new field tuner_tkn to struct dvb_frontend. Drivers can
create tuner token using devm_token_create() and initialize
the tuner_tkn when frontend is registered with the dvb-core.
This change enables drivers to provide a token devres for tuner
access control.

Change dvb_frontend to lock tuner token for exclusive access to
tuner function for digital TV function use. When Tuner token is
present, dvb_frontend_start() calls devm_token_lock() to lock
the token. If token is busy, -EBUSY is returned to the user-space.
Tuner token is unlocked if kdvb adapter fe kthread fails to start.
This token is held in use as long as the kdvb adapter fe kthread
is running. Tuner token is unlocked in dvb_frontend_thread() when
kdvb adapter fe thread exits.

Signed-off-by: Shuah Khan <shuah.kh@xxxxxxxxxxx>
---
drivers/media/dvb-core/dvb_frontend.c | 15 +++++++++++++++
drivers/media/dvb-core/dvb_frontend.h | 1 +
2 files changed, 16 insertions(+)

diff --git a/drivers/media/dvb-core/dvb_frontend.c b/drivers/media/dvb-core/dvb_frontend.c
index 6ce435a..2b35e3f 100644
--- a/drivers/media/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb-core/dvb_frontend.c
@@ -41,6 +41,7 @@
#include <linux/jiffies.h>
#include <linux/kthread.h>
#include <asm/processor.h>
+#include <linux/token_devres.h>

#include "dvb_frontend.h"
#include "dvbdev.h"
@@ -747,6 +748,9 @@ restart:
if (semheld)
up(&fepriv->sem);
dvb_frontend_wakeup(fe);
+
+ if (fe->tuner_tkn)
+ devm_token_unlock(fe->dvb->device, fe->tuner_tkn);
return 0;
}

@@ -840,6 +844,15 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
fepriv->state = FESTATE_IDLE;
fepriv->exit = DVB_FE_NO_EXIT;
fepriv->thread = NULL;
+
+ if (fe->tuner_tkn) {
+ ret = devm_token_lock(fe->dvb->device, fe->tuner_tkn);
+ if (ret) {
+ dev_info(fe->dvb->device, "Tuner is busy %d\n", ret);
+ return ret;
+ }
+ }
+
mb();

fe_thread = kthread_run(dvb_frontend_thread, fe,
@@ -850,6 +863,8 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
"dvb_frontend_start: failed to start kthread (%d)\n",
ret);
up(&fepriv->sem);
+ if (fe->tuner_tkn)
+ devm_token_unlock(fe->dvb->device, fe->tuner_tkn);
return ret;
}
fepriv->thread = fe_thread;
diff --git a/drivers/media/dvb-core/dvb_frontend.h b/drivers/media/dvb-core/dvb_frontend.h
index 371b6ca..c9ba5fd 100644
--- a/drivers/media/dvb-core/dvb_frontend.h
+++ b/drivers/media/dvb-core/dvb_frontend.h
@@ -418,6 +418,7 @@ struct dvb_frontend {
#define DVB_FRONTEND_COMPONENT_DEMOD 1
int (*callback)(void *adapter_priv, int component, int cmd, int arg);
int id;
+ char *tuner_tkn;
};

extern int dvb_register_frontend(struct dvb_adapter *dvb,
--
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/