Re: [PATCH v4] mmc : general purpose partition support.

From: Andrei E. Warkentin
Date: Fri Sep 30 2011 - 13:35:01 EST


Hi Namjae,

Why don't you update card->nr_parts inside mmc_part_add? You're making
this too complicated. There
is also no need for the part_cfg array.

2011/9/30 Namjae Jeon <linkinjeon@xxxxxxxxx>:
> It allows gerneral purpose partitions in MMC Device.
> And I try to simpliy make mmc_blk_alloc_parts using mmc_part structure suggested by Andrei Warkentin.
> After patching, we can see general purpose partitions like this.
>> cat /proc/partitions
> Â Â Â Â Â179 0 847872 mmcblk0
> Â Â Â Â Â179 192 4096 mmcblk0gp3
> Â Â Â Â Â179 160 4096 mmcblk0gp2
> Â Â Â Â Â179 128 4096 mmcblk0gp1
> Â Â Â Â Â179 96 Â1052672 mmcblk0gp0
> Â Â Â Â Â179 64 Â1024 mmcblk0boot1
> Â Â Â Â Â179 32 Â1024 mmcblk0boot0
>
> Signed-off-by: Namjae Jeon <linkinjeon@xxxxxxxxx>
> ---

>
> +/* partition configuration array */
> +static const unsigned int part_cfg[] = {
> + Â Â Â 0x1, Â Â0x2, Â Â0x4, Â Â0x5, Â Â0x6, Â Â7,
> +};
> +

No need. Plus this is obscure.

> - Â Â Â Â Â Â Â card->ext_csd.boot_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
> + Â Â Â Â Â Â Â if (ext_csd[EXT_CSD_BOOT_MULT]) {
> + Â Â Â Â Â Â Â Â Â Â Â card->nr_parts = MMC_NUM_BOOT_PARTITION;
> + Â Â Â Â Â Â Â Â Â Â Â for (idx = 0, part_num = 0;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â idx < MMC_NUM_BOOT_PARTITION; idx++,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â part_num++) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â mmc_part_add(card, part_size, part_cfg[idx],
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "boot%d", idx, part_num, true);
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â }
> Â Â Â Â}

There is no need for part_num (you have idx for that). And there is no
need for passing the actual array
index either - that's why you have mmc_part_add: it will do
card->parts[card->nr_parts++] = new_part.

if (ext_csd[EXT_CSD_BOOT_MULT]) {
for (idx = 0, part_num = 0;
idx < MMC_NUM_BOOT_PARTITION; idx++) {
part_size = ext_csd[EXT_CSD_BOOT_MULT] << 17;
mmc_part_add(card, part_size,
EXT_CSD_PART_CONFIG_ACC_BOOT0 + idx,
"boot%d", idx, true);
}
}


> + Â Â Â Â Â Â Â if (ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x1) {
> + Â Â Â Â Â Â Â Â Â Â Â u8 hc_erase_grp_sz =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
> + Â Â Â Â Â Â Â Â Â Â Â u8 hc_wp_grp_sz =
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
> +
> + Â Â Â Â Â Â Â Â Â Â Â card->ext_csd.enhanced_area_en = 1;
> +
> + Â Â Â Â Â Â Â Â Â Â Â card->nr_parts += MMC_NUM_GP_PARTITION;
> + Â Â Â Â Â Â Â Â Â Â Â for (part_num = 0, gp_size_mult = 143;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â idx < card->nr_parts;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â idx++, part_num++, gp_size_mult += 3) {
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (!ext_csd[gp_size_mult] &&
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â !ext_csd[gp_size_mult + 1] &&
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â !ext_csd[gp_size_mult + 2])
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â part_size = (ext_csd[gp_size_mult + 2] << 16) +
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (ext_csd[gp_size_mult + 1] << 8) +
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ext_csd[gp_size_mult];
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â part_size *= (size_t)(hc_erase_grp_sz *
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hc_wp_grp_sz);
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â part_size <<= 19;
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â mmc_part_add(card, part_size, part_cfg[idx],
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "gp%d", idx, part_num, false);
> + Â Â Â Â Â Â Â Â Â Â Â }
> + Â Â Â Â Â Â Â }

Same story: get rid of part_num, don't touch card->nr_parts, and get
rid of part_cfg array access.

card->ext_csd.enhanced_area_en = 1;
for (idx = 0, gp_size_mult = 143;
idx < MMC_NUM_GP_PARTITION;
idx++, gp_size_mult += 3) {
if (!ext_csd[gp_size_mult] &&
!ext_csd[gp_size_mult + 1] &&
!ext_csd[gp_size_mult + 2])
continue;
part_size = (ext_csd[gp_size_mult + 2] << 16) +
(ext_csd[gp_size_mult + 1] << 8) +
ext_csd[gp_size_mult];
part_size *= (size_t)(hc_erase_grp_sz *
hc_wp_grp_sz);
part_size <<= 19;
mmc_part_add(card, part_size, idx +
EXT_CSD_PART_CONFIG_ACC_GP0,
"gp%d", idx, false);
}
}


> /*
> + * This function fill contents in mmc_part.
> + */
> +static inline void mmc_part_add(struct mmc_card *card, unsigned int size,
> + unsigned int part_cfg, char *name, int idx, int part_num, bool ro)
> +{
> + card->part[idx].size = size;
> + card->part[idx].cookie = part_cfg;
> + sprintf(card->part[idx].name, name, part_num);
> + card->part[idx].force_ro = ro;
> +}

static inline void mmc_part_add(struct mmc_card *card, unsigned int size,
unsigned int part_cfg, char *name, int idx, bool ro)
{
card->part[card->nr_parts].size = size;
card->part[card->nr_parts].cookie = part_cfg;
sprintf(card->part[card->nr_parts].name, name, idx);
card->part[card->nr_parts].force_ro = ro;
card->nr_parts++;
}

> Â#define EXT_CSD_PART_CONFIG_ACC_MASK Â (0x7)
> -#define EXT_CSD_PART_CONFIG_ACC_BOOT0 Â(0x1)
> -#define EXT_CSD_PART_CONFIG_ACC_BOOT1 Â(0x2)
>

I'd also keep the MMC_NUM_BOOT_PARTITION and MMC_NUM_GP_PARTITION defs
at the same location.

/* The number of MMC physical partitions
* It consist of boot partitions(2), general purpose partitions(4) in MMC v4.4
*/
#define MMC_NUM_BOOT_PARTITION 2
#define MMC_NUM_GP_PARTITION 4

#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1)
#define EXT_CSD_PART_CONFIG_ACC_GP0 (0x4)

A
--
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/