Commit 5e71b7a64cb4c6cff75ca42b535d8227526ec592

Authored by Olof Johansson
Committed by Chris Ball
1 parent 061c6c847e

mmc: make number of mmcblk minors configurable

The old limit of number of minor numbers per mmcblk device was hardcoded
at 8.  This isn't enough for some of the more elaborate partitioning
schemes, for example those used by Chrome OS.

Since there might be a bunch of systems out there with static /dev
contents that relies on the old numbering scheme, let's make it a
build-time option with the default set to the previous 8.

Also provide a boot/modprobe-time parameter to override the config
default: mmcblk.perdev_minors.

Signed-off-by: Olof Johansson <olof@lixom.net>
Cc: Mandeep Baines <msb@chromium.org>
Cc: <linux-mmc@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Chris Ball <cjb@laptop.org>

Showing 3 changed files with 54 additions and 12 deletions Side-by-side Diff

Documentation/devices.txt
... ... @@ -2520,6 +2520,12 @@
2520 2520 8 = /dev/mmcblk1 Second SD/MMC card
2521 2521 ...
2522 2522  
  2523 + The start of next SD/MMC card can be configured with
  2524 + CONFIG_MMC_BLOCK_MINORS, or overridden at boot/modprobe
  2525 + time using the mmcblk.perdev_minors option. That would
  2526 + bump the offset between each card to be the configured
  2527 + value instead of the default 8.
  2528 +
2523 2529 179 char CCube DVXChip-based PCI products
2524 2530 0 = /dev/dvxirq0 First DVX device
2525 2531 1 = /dev/dvxirq1 Second DVX device
drivers/mmc/card/Kconfig
... ... @@ -14,6 +14,23 @@
14 14 mount the filesystem. Almost everyone wishing MMC support
15 15 should say Y or M here.
16 16  
  17 +config MMC_BLOCK_MINORS
  18 + int "Number of minors per block device"
  19 + range 4 256
  20 + default 8
  21 + help
  22 + Number of minors per block device. One is needed for every
  23 + partition on the disk (plus one for the whole disk).
  24 +
  25 + Number of total MMC minors available is 256, so your number
  26 + of supported block devices will be limited to 256 divided
  27 + by this number.
  28 +
  29 + Default is 8 to be backwards compatible with previous
  30 + hardwired device numbering.
  31 +
  32 + If unsure, say 8 here.
  33 +
17 34 config MMC_BLOCK_BOUNCE
18 35 bool "Use bounce buffer for simple hosts"
19 36 depends on MMC_BLOCK
drivers/mmc/card/block.c
... ... @@ -43,16 +43,28 @@
43 43 #include "queue.h"
44 44  
45 45 MODULE_ALIAS("mmc:block");
  46 +#ifdef MODULE_PARAM_PREFIX
  47 +#undef MODULE_PARAM_PREFIX
  48 +#endif
  49 +#define MODULE_PARAM_PREFIX "mmcblk."
46 50  
  51 +static DEFINE_MUTEX(block_mutex);
  52 +
47 53 /*
48   - * max 8 partitions per card
  54 + * The defaults come from config options but can be overriden by module
  55 + * or bootarg options.
49 56 */
50   -#define MMC_SHIFT 3
51   -#define MMC_NUM_MINORS (256 >> MMC_SHIFT)
  57 +static int perdev_minors = CONFIG_MMC_BLOCK_MINORS;
52 58  
53   -static DEFINE_MUTEX(block_mutex);
54   -static DECLARE_BITMAP(dev_use, MMC_NUM_MINORS);
  59 +/*
  60 + * We've only got one major, so number of mmcblk devices is
  61 + * limited to 256 / number of minors per device.
  62 + */
  63 +static int max_devices;
55 64  
  65 +/* 256 minors, so at most 256 separate devices */
  66 +static DECLARE_BITMAP(dev_use, 256);
  67 +
56 68 /*
57 69 * There is one mmc_blk_data per slot.
58 70 */
... ... @@ -67,6 +79,9 @@
67 79  
68 80 static DEFINE_MUTEX(open_lock);
69 81  
  82 +module_param(perdev_minors, int, 0444);
  83 +MODULE_PARM_DESC(perdev_minors, "Minors numbers to allocate per device");
  84 +
70 85 static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk)
71 86 {
72 87 struct mmc_blk_data *md;
73 88  
... ... @@ -88,10 +103,10 @@
88 103 md->usage--;
89 104 if (md->usage == 0) {
90 105 int devmaj = MAJOR(disk_devt(md->disk));
91   - int devidx = MINOR(disk_devt(md->disk)) >> MMC_SHIFT;
  106 + int devidx = MINOR(disk_devt(md->disk)) / perdev_minors;
92 107  
93 108 if (!devmaj)
94   - devidx = md->disk->first_minor >> MMC_SHIFT;
  109 + devidx = md->disk->first_minor / perdev_minors;
95 110  
96 111 blk_cleanup_queue(md->queue.queue);
97 112  
... ... @@ -566,8 +581,8 @@
566 581 struct mmc_blk_data *md;
567 582 int devidx, ret;
568 583  
569   - devidx = find_first_zero_bit(dev_use, MMC_NUM_MINORS);
570   - if (devidx >= MMC_NUM_MINORS)
  584 + devidx = find_first_zero_bit(dev_use, max_devices);
  585 + if (devidx >= max_devices)
571 586 return ERR_PTR(-ENOSPC);
572 587 __set_bit(devidx, dev_use);
573 588  
... ... @@ -584,7 +599,7 @@
584 599 */
585 600 md->read_only = mmc_blk_readonly(card);
586 601  
587   - md->disk = alloc_disk(1 << MMC_SHIFT);
  602 + md->disk = alloc_disk(perdev_minors);
588 603 if (md->disk == NULL) {
589 604 ret = -ENOMEM;
590 605 goto err_kfree;
... ... @@ -601,7 +616,7 @@
601 616 md->queue.data = md;
602 617  
603 618 md->disk->major = MMC_BLOCK_MAJOR;
604   - md->disk->first_minor = devidx << MMC_SHIFT;
  619 + md->disk->first_minor = devidx * perdev_minors;
605 620 md->disk->fops = &mmc_bdops;
606 621 md->disk->private_data = md;
607 622 md->disk->queue = md->queue.queue;
... ... @@ -670,7 +685,6 @@
670 685 {
671 686 struct mmc_blk_data *md;
672 687 int err;
673   -
674 688 char cap_str[10];
675 689  
676 690 /*
... ... @@ -759,6 +773,11 @@
759 773 static int __init mmc_blk_init(void)
760 774 {
761 775 int res;
  776 +
  777 + if (perdev_minors != CONFIG_MMC_BLOCK_MINORS)
  778 + pr_info("mmcblk: using %d minors per device\n", perdev_minors);
  779 +
  780 + max_devices = 256 / perdev_minors;
762 781  
763 782 res = register_blkdev(MMC_BLOCK_MAJOR, "mmc");
764 783 if (res)