Merge master.kernel.org:/pub/scm/linux/kernel/git/mchehab/v4l-dvb
[deliverable/linux.git] / drivers / mmc / mmc_queue.c
CommitLineData
1da177e4
LT
1/*
2 * linux/drivers/mmc/mmc_queue.c
3 *
4 * Copyright (C) 2003 Russell King, All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11#include <linux/module.h>
12#include <linux/blkdev.h>
13
14#include <linux/mmc/card.h>
15#include <linux/mmc/host.h>
16#include "mmc_queue.h"
17
18#define MMC_QUEUE_EXIT (1 << 0)
19#define MMC_QUEUE_SUSPENDED (1 << 1)
20
21/*
22 * Prepare a MMC request. Essentially, this means passing the
23 * preparation off to the media driver. The media driver will
24 * create a mmc_io_request in req->special.
25 */
26static int mmc_prep_request(struct request_queue *q, struct request *req)
27{
28 struct mmc_queue *mq = q->queuedata;
29 int ret = BLKPREP_KILL;
30
31 if (req->flags & REQ_SPECIAL) {
32 /*
33 * Special commands already have the command
34 * blocks already setup in req->special.
35 */
36 BUG_ON(!req->special);
37
38 ret = BLKPREP_OK;
39 } else if (req->flags & (REQ_CMD | REQ_BLOCK_PC)) {
40 /*
41 * Block I/O requests need translating according
42 * to the protocol.
43 */
44 ret = mq->prep_fn(mq, req);
45 } else {
46 /*
47 * Everything else is invalid.
48 */
49 blk_dump_rq_flags(req, "MMC bad request");
50 }
51
52 if (ret == BLKPREP_OK)
53 req->flags |= REQ_DONTPREP;
54
55 return ret;
56}
57
58static int mmc_queue_thread(void *d)
59{
60 struct mmc_queue *mq = d;
61 struct request_queue *q = mq->queue;
62 DECLARE_WAITQUEUE(wait, current);
63
64 /*
65 * Set iothread to ensure that we aren't put to sleep by
66 * the process freezing. We handle suspension ourselves.
67 */
68 current->flags |= PF_MEMALLOC|PF_NOFREEZE;
69
70 daemonize("mmcqd");
71
72 complete(&mq->thread_complete);
73
74 down(&mq->thread_sem);
75 add_wait_queue(&mq->thread_wq, &wait);
76 do {
77 struct request *req = NULL;
78
79 spin_lock_irq(q->queue_lock);
80 set_current_state(TASK_INTERRUPTIBLE);
81 if (!blk_queue_plugged(q))