]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - block/blk-map.c
i2c: Convert the pca9539 driver to a new-style i2c driver
[linux-2.6-omap-h63xx.git] / block / blk-map.c
index ab43533ba641be51a8ed02129054d4d8530d684f..ddd96fb11a7d71638a32e3e9060aac1f1adac808 100644 (file)
@@ -141,25 +141,8 @@ int blk_rq_map_user(struct request_queue *q, struct request *rq,
                ubuf += ret;
        }
 
-       /*
-        * __blk_rq_map_user() copies the buffers if starting address
-        * or length isn't aligned to dma_pad_mask.  As the copied
-        * buffer is always page aligned, we know that there's enough
-        * room for padding.  Extend the last bio and update
-        * rq->data_len accordingly.
-        *
-        * On unmap, bio_uncopy_user() will use unmodified
-        * bio_map_data pointed to by bio->bi_private.
-        */
-       if (len & q->dma_pad_mask) {
-               unsigned int pad_len = (q->dma_pad_mask & ~len) + 1;
-               struct bio *tail = rq->biotail;
-
-               tail->bi_io_vec[tail->bi_vcnt - 1].bv_len += pad_len;
-               tail->bi_size += pad_len;
-
-               rq->extra_len += pad_len;
-       }
+       if (!bio_flagged(bio, BIO_USER_MAPPED))
+               rq->cmd_flags |= REQ_COPY_USER;
 
        rq->buffer = rq->data = NULL;
        return 0;
@@ -224,6 +207,10 @@ int blk_rq_map_user_iov(struct request_queue *q, struct request *rq,
                return -EINVAL;
        }
 
+       if (!bio_flagged(bio, BIO_USER_MAPPED))
+               rq->cmd_flags |= REQ_COPY_USER;
+
+       blk_queue_bounce(q, &bio);
        bio_get(bio);
        blk_rq_bio_prep(q, rq, bio);
        rq->buffer = rq->data = NULL;
@@ -269,24 +256,48 @@ EXPORT_SYMBOL(blk_rq_unmap_user);
  * @kbuf:      the kernel buffer
  * @len:       length of user data
  * @gfp_mask:  memory allocation flags
+ *
+ * Description:
+ *    Data will be mapped directly if possible. Otherwise a bounce
+ *    buffer is used.
  */
 int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
                    unsigned int len, gfp_t gfp_mask)
 {
+       unsigned long kaddr;
+       unsigned int alignment;
+       int reading = rq_data_dir(rq) == READ;
+       int do_copy = 0;
        struct bio *bio;
+       unsigned long stack_mask = ~(THREAD_SIZE - 1);
 
        if (len > (q->max_hw_sectors << 9))
                return -EINVAL;
        if (!len || !kbuf)
                return -EINVAL;
 
-       bio = bio_map_kern(q, kbuf, len, gfp_mask);
+       kaddr = (unsigned long)kbuf;
+       alignment = queue_dma_alignment(q) | q->dma_pad_mask;
+       do_copy = ((kaddr & alignment) || (len & alignment));
+
+       if (!((kaddr & stack_mask) ^
+             ((unsigned long)current->stack & stack_mask)))
+               do_copy = 1;
+
+       if (do_copy)
+               bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
+       else
+               bio = bio_map_kern(q, kbuf, len, gfp_mask);
+
        if (IS_ERR(bio))
                return PTR_ERR(bio);
 
        if (rq_data_dir(rq) == WRITE)
                bio->bi_rw |= (1 << BIO_RW);
 
+       if (do_copy)
+               rq->cmd_flags |= REQ_COPY_USER;
+
        blk_rq_bio_prep(q, rq, bio);
        blk_queue_bounce(q, &rq->bio);
        rq->buffer = rq->data = NULL;