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

From: NamJae Jeon
Date: Tue Sep 27 2011 - 21:13:42 EST


2011/9/27 J Freyensee <james_p_freyensee@xxxxxxxxxxxxxxx>:
> On 09/23/2011 10:07 PM, Namjae Jeon wrote:
>>
>> 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 mmcblk0gp4
>> Â Â Â Â Â 179 160 4096 mmcblk0gp3
>> Â Â Â Â Â 179 128 4096 mmcblk0gp2
>> Â Â Â Â Â 179 96 Â1052672 mmcblk0gp1
>> Â Â Â Â Â 179 64 Â1024 mmcblk0boot1
>> Â Â Â Â Â 179 32 Â1024 mmcblk0boot0
>
> Looks reasonable to me.
Thanks for your review.
I want to know how the opinion of others.

>
>
>>
>> Signed-off-by: Namjae Jeon<linkinjeon@xxxxxxxxx>
>> ---
>> Âdrivers/mmc/card/block.c | Â 30 ++++++++++++++++--------------
>> Âdrivers/mmc/core/mmc.c  |  46
>> +++++++++++++++++++++++++++++++++++++++++++++-
>> Âinclude/linux/mmc/card.h | Â 19 ++++++++++++++++++-
>> Âinclude/linux/mmc/mmc.h Â| Â Â2 --
>> Â4 files changed, 79 insertions(+), 18 deletions(-)
>>
>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>> index 1ff5486..8ec7cfd 100644
>> --- a/drivers/mmc/card/block.c
>> +++ b/drivers/mmc/card/block.c
>> @@ -1377,26 +1377,28 @@ static int mmc_blk_alloc_part(struct mmc_card
>> *card,
>> Â Â Â Âreturn 0;
>> Â}
>>
>> +/* MMC Physical partition consist of two boot partitons and
>> + * four general purpose partitions.
>> + * if the register of respective partitions is set in ext_csd,
>> + * it allocate block device to be accessed.
>> + */
>> +
>> Âstatic int mmc_blk_alloc_parts(struct mmc_card *card, struct mmc_blk_data
>> *md)
>> Â{
>> - Â Â Â int ret = 0;
>> + Â Â Â int i, ret = 0;
>>
>> Â Â Â Âif (!mmc_card_mmc(card))
>> Â Â Â Â Â Â Â Âreturn 0;
>>
>> - Â Â Â if (card->ext_csd.boot_size) {
>> - Â Â Â Â Â Â Â ret = mmc_blk_alloc_part(card, md,
>> EXT_CSD_PART_CONFIG_ACC_BOOT0,
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âcard->ext_csd.boot_size>> Â9,
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âtrue,
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"boot0");
>> - Â Â Â Â Â Â Â if (ret)
>> - Â Â Â Â Â Â Â Â Â Â Â return ret;
>> - Â Â Â Â Â Â Â ret = mmc_blk_alloc_part(card, md,
>> EXT_CSD_PART_CONFIG_ACC_BOOT1,
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âcard->ext_csd.boot_size>> Â9,
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âtrue,
>> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â"boot1");
>> - Â Â Â Â Â Â Â if (ret)
>> - Â Â Â Â Â Â Â Â Â Â Â return ret;
>> + Â Â Â for (i = 0; i< ÂMMC_MAX_NUM_PHY_PARTITION; i++) {
>> + Â Â Â Â Â Â Â if (card->part[i].size) {
>> + Â Â Â Â Â Â Â Â Â Â Â ret = mmc_blk_alloc_part(card, md,
>> card->part[i].cookie,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].size>> Â9,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].force_ro,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].name);
>> + Â Â Â Â Â Â Â Â Â Â Â if (ret)
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â return ret;
>> + Â Â Â Â Â Â Â }
>> Â Â Â Â}
>>
>> Â Â Â Âreturn ret;
>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>> index 5700b1c..56c4b9e 100644
>> --- a/drivers/mmc/core/mmc.c
>> +++ b/drivers/mmc/core/mmc.c
>> @@ -340,7 +340,18 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8
>> *ext_csd)
>> Â Â Â Â Â Â Â Â * There are two boot regions of equal size, defined in
>> Â Â Â Â Â Â Â Â * multiples of 128K.
>> Â Â Â Â Â Â Â Â */
>> - Â Â Â Â Â Â Â card->ext_csd.boot_size = ext_csd[EXT_CSD_BOOT_MULT]<<
>> Â17;
>> + Â Â Â Â Â Â Â int i, boot_part_config;
>> + Â Â Â Â Â Â Â if (ext_csd[EXT_CSD_BOOT_MULT]) {
>> + Â Â Â Â Â Â Â Â Â Â Â for (i = 0, boot_part_config = 0x1;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â i< ÂMMC_NUM_BOOT_PARTITION;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â i++, boot_part_config++) {
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].size =
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ext_csd[EXT_CSD_BOOT_MULT]<< Â17;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].cookie = boot_part_config;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sprintf(card->part[i].name, "boot%d", i);
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].force_ro = true;
>> + Â Â Â Â Â Â Â Â Â Â Â }
>> + Â Â Â Â Â Â Â }
>> Â Â Â Â}
>>
>> Â Â Â Âcard->ext_csd.raw_hc_erase_gap_size =
>> @@ -392,6 +403,39 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8
>> *ext_csd)
>> Â Â Â Â Â Â Â Â Â Â Â Âcard->ext_csd.enhanced_area_offset = -EINVAL;
>> Â Â Â Â Â Â Â Â Â Â Â Âcard->ext_csd.enhanced_area_size = -EINVAL;
>> Â Â Â Â Â Â Â Â}
>> +
>> + Â Â Â Â Â Â Â 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;
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â int i, gp_num, gp_part_config, gp_size_mult;
>> + Â Â Â Â Â Â Â Â Â Â Â for (i = 2, gp_num = 1, gp_part_config = 0x4,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gp_size_mult = 143;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â i< ÂMMC_MAX_NUM_PHY_PARTITION;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â i++, gp_num++, gp_part_config++,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â gp_size_mult += 3) {
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â if (!ext_csd[gp_size_mult]&&
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â !ext_csd[gp_size_mult +
>> 1]&&
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â !ext_csd[gp_size_mult +
>> 2])
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â continue;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].size =
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (ext_csd[gp_size_mult + 2]<< Â16)
>> +
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (ext_csd[gp_size_mult + 1]<< Â8) +
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â ext_csd[gp_size_mult];
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].size *=
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â (size_t)(hc_erase_grp_sz *
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â hc_wp_grp_sz);
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].size<<= 19;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].cookie = gp_part_config;
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â sprintf(card->part[i].name,
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â "gp%d", gp_num);
>> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â card->part[i].force_ro = false;
>> + Â Â Â Â Â Â Â Â Â Â Â }
>> + Â Â Â Â Â Â Â }
>> Â Â Â Â Â Â Â Âcard->ext_csd.sec_trim_mult =
>> Â Â Â Â Â Â Â Â Â Â Â Âext_csd[EXT_CSD_SEC_TRIM_MULT];
>> Â Â Â Â Â Â Â Âcard->ext_csd.sec_erase_mult =
>> diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h
>> index b460fc2..842f702 100644
>> --- a/include/linux/mmc/card.h
>> +++ b/include/linux/mmc/card.h
>> @@ -12,6 +12,7 @@
>>
>> Â#include<linux/mmc/core.h>
>> Â#include<linux/mod_devicetable.h>
>> +#include<linux/genhd.h>
>>
>> Âstruct mmc_cid {
>>    Âunsigned int      Âmanfid;
>> @@ -63,7 +64,6 @@ struct mmc_ext_csd {
>>    Âbool          Âenhanced_area_en;    /* enable bit */
>>    Âunsigned long long   Âenhanced_area_offset;  /* Units: Byte */
>>    Âunsigned int      Âenhanced_area_size;   /* Units: KB */
>> -    unsigned int      Âboot_size;       Â/* in bytes */
>> Â Â Â Âu8 Â Â Â Â Â Â Â Â Â Â Âraw_partition_support; Â/* 160 */
>> Â Â Â Âu8 Â Â Â Â Â Â Â Â Â Â Âraw_erased_mem_count; Â /* 181 */
>> Â Â Â Âu8 Â Â Â Â Â Â Â Â Â Â Âraw_ext_csd_structure; Â/* 194 */
>> @@ -157,6 +157,22 @@ struct sdio_func_tuple;
>>
>> Â#define SDIO_MAX_FUNCS Â Â Â Â Â Â Â Â7
>>
>> +/* 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_MAX_NUM_PHY_PARTITION Â Â Â6
>> +
>> +/*
>> + * MMC Physical partitions
>> + */
>> +struct mmc_part {
>> +    unsigned int  Âsize;  /* partition size (in bytes) */
>> +    unsigned int  Âcookie; /* it used to part_type */
>> +    char  Âname[DISK_NAME_LEN];
>> +    bool  Âforce_ro;    /* to make boot parts RO by default */
>> +};
>> +
>> Â/*
>> Â * MMC device
>> Â */
>> @@ -216,6 +232,7 @@ struct mmc_card {
>>    Âunsigned int      Âsd_bus_speed;  /* Bus Speed Mode set for
>> the card */
>>
>>    Âstruct dentry      *debugfs_root;
>> + Â Â Â struct Âmmc_part part[MMC_MAX_NUM_PHY_PARTITION]; Â Â Â /* mmc
>> physical partitions */
>> Â};
>>
>> Â/*
>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>> index 5a794cb..33eae3d 100644
>> --- a/include/linux/mmc/mmc.h
>> +++ b/include/linux/mmc/mmc.h
>> @@ -301,8 +301,6 @@ struct _mmc_csd {
>> Â#define EXT_CSD_WR_REL_PARAM_EN Â Â Â Â Â Â Â (1<<2)
>>
>> Â#define EXT_CSD_PART_CONFIG_ACC_MASK Â(0x7)
>> -#define EXT_CSD_PART_CONFIG_ACC_BOOT0 Â(0x1)
>> -#define EXT_CSD_PART_CONFIG_ACC_BOOT1 Â(0x2)
>>
>> Â#define EXT_CSD_CMD_SET_NORMAL Â Â Â Â Â Â Â Â(1<<0)
>> Â#define EXT_CSD_CMD_SET_SECURE Â Â Â Â Â Â Â Â(1<<1)
>
>
> --
> J (James/Jay) Freyensee
> Storage Technology Group
> Intel Corporation
>
¢éì®&Þ~º&¶¬–+-±éÝ¥Šw®žË±Êâmébžìdz¹Þ)í…æèw*jg¬±¨¶‰šŽŠÝj/êäz¹ÞŠà2ŠÞ¨è­Ú&¢)ß«a¶Úþø®G«éh®æj:+v‰¨Šwè†Ù>Wš±êÞiÛaxPjØm¶Ÿÿà -»+ƒùdš_