]> err.no Git - linux-2.6/blobdiff - drivers/block/brd.c
V4L/DVB (7858): video: build fix for drivers/media/video/mt9v022.c
[linux-2.6] / drivers / block / brd.c
index 50b659bedc8fe57893de5f52635b989037210b3c..a196ef7f147fa234ead35696b8c115dd9ea69927 100644 (file)
@@ -89,6 +89,7 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
 {
        pgoff_t idx;
        struct page *page;
+       gfp_t gfp_flags;
 
        page = brd_lookup_page(brd, sector);
        if (page)
@@ -97,8 +98,17 @@ static struct page *brd_insert_page(struct brd_device *brd, sector_t sector)
        /*
         * Must use NOIO because we don't want to recurse back into the
         * block or filesystem layers from page reclaim.
+        *
+        * Cannot support XIP and highmem, because our ->direct_access
+        * routine for XIP must return memory that is always addressable.
+        * If XIP was reworked to use pfns and kmap throughout, this
+        * restriction might be able to be lifted.
         */
-       page = alloc_page(GFP_NOIO | __GFP_HIGHMEM | __GFP_ZERO);
+       gfp_flags = GFP_NOIO | __GFP_ZERO;
+#ifndef CONFIG_BLK_DEV_XIP
+       gfp_flags |= __GFP_HIGHMEM;
+#endif
+       page = alloc_page(gfp_flags);
        if (!page)
                return NULL;
 
@@ -307,6 +317,29 @@ out:
        return 0;
 }
 
+#ifdef CONFIG_BLK_DEV_XIP
+static int brd_direct_access (struct block_device *bdev, sector_t sector,
+                       void **kaddr, unsigned long *pfn)
+{
+       struct brd_device *brd = bdev->bd_disk->private_data;
+       struct page *page;
+
+       if (!brd)
+               return -ENODEV;
+       if (sector & (PAGE_SECTORS-1))
+               return -EINVAL;
+       if (sector + PAGE_SECTORS > get_capacity(bdev->bd_disk))
+               return -ERANGE;
+       page = brd_insert_page(brd, sector);
+       if (!page)
+               return -ENOMEM;
+       *kaddr = page_address(page);
+       *pfn = page_to_pfn(page);
+
+       return 0;
+}
+#endif
+
 static int brd_ioctl(struct inode *inode, struct file *file,
                        unsigned int cmd, unsigned long arg)
 {
@@ -342,8 +375,11 @@ static int brd_ioctl(struct inode *inode, struct file *file,
 }
 
 static struct block_device_operations brd_fops = {
-       .owner =        THIS_MODULE,
-       .ioctl =        brd_ioctl,
+       .owner =                THIS_MODULE,
+       .ioctl =                brd_ioctl,
+#ifdef CONFIG_BLK_DEV_XIP
+       .direct_access =        brd_direct_access,
+#endif
 };
 
 /*
@@ -351,10 +387,14 @@ static struct block_device_operations brd_fops = {
  */
 static int rd_nr;
 int rd_size = CONFIG_BLK_DEV_RAM_SIZE;
+static int max_part;
+static int part_shift;
 module_param(rd_nr, int, 0);
 MODULE_PARM_DESC(rd_nr, "Maximum number of brd devices");
 module_param(rd_size, int, 0);
 MODULE_PARM_DESC(rd_size, "Size of each RAM disk in kbytes.");
+module_param(max_part, int, 0);
+MODULE_PARM_DESC(max_part, "Maximum number of partitions per RAM disk");
 MODULE_LICENSE("GPL");
 MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR);
 
@@ -399,11 +439,11 @@ static struct brd_device *brd_alloc(int i)
        blk_queue_max_sectors(brd->brd_queue, 1024);
        blk_queue_bounce_limit(brd->brd_queue, BLK_BOUNCE_ANY);
 
-       disk = brd->brd_disk = alloc_disk(1);
+       disk = brd->brd_disk = alloc_disk(1 << part_shift);
        if (!disk)
                goto out_free_queue;
        disk->major             = RAMDISK_MAJOR;
-       disk->first_minor       = i;
+       disk->first_minor       = i << part_shift;
        disk->fops              = &brd_fops;
        disk->private_data      = brd;
        disk->queue             = brd->brd_queue;
@@ -487,7 +527,12 @@ static int __init brd_init(void)
         *     themselves and have kernel automatically instantiate actual
         *     device on-demand.
         */
-       if (rd_nr > 1UL << MINORBITS)
+
+       part_shift = 0;
+       if (max_part > 0)
+               part_shift = fls(max_part);
+
+       if (rd_nr > 1UL << (MINORBITS - part_shift))
                return -EINVAL;
 
        if (rd_nr) {
@@ -495,7 +540,7 @@ static int __init brd_init(void)
                range = rd_nr;
        } else {
                nr = CONFIG_BLK_DEV_RAM_COUNT;
-               range = 1UL << MINORBITS;
+               range = 1UL << (MINORBITS - part_shift);
        }
 
        if (register_blkdev(RAMDISK_MAJOR, "ramdisk"))
@@ -534,7 +579,7 @@ static void __exit brd_exit(void)
        unsigned long range;
        struct brd_device *brd, *next;
 
-       range = rd_nr ? rd_nr :  1UL << MINORBITS;
+       range = rd_nr ? rd_nr :  1UL << (MINORBITS - part_shift);
 
        list_for_each_entry_safe(brd, next, &brd_devices, brd_list)
                brd_del_one(brd);