mmc : general purpose partition support.
PATCH v4 1/1 mmc : general purpose partition support.
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.
Quoted 1 line
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--- drivers/mmc/card/block.c | 31 +++++++++++++++------------ drivers/mmc/core/mmc.c | 52 ++++++++++++++++++++++++++++++++++++++++++++- include/linux/mmc/card.h | 32 +++++++++++++++++++++++++++- include/linux/mmc/mmc.h | 3 -- 4 files changed, 98 insertions(+), 20 deletions(-)
drivers/mmc/card/block.c +17 -14
@@ -1377,26 +1377,29 @@ 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 idx, 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 (idx =0 ; idx < card->nr_parts; idx++) { +if (card->part[idx].size) { + ret =mmc_blk_alloc_part (card, md, + card->part[idx].cookie, + card->part[idx].size >>9 , + card->part[idx].force_ro, + card->part[idx].name); +if (ret) +return ret; + } }return ret;
drivers/mmc/core/mmc.c +50 -2
76 lines not on this page · raw message
include/linux/mmc/card.h +31 -1
@@ -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_NUM_GP_PARTITION 4 + +/* +* 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,9 +232,23 @@ struct mmc_card {unsigned int sd_bus_speed;/* Bus Speed Mode set for the card */ struct dentry *debugfs_root; +struct mmc_part part[MMC_NUM_BOOT_PARTITION +MMC_NUM_GP_PARTITION ];/* mmc physical partitions */ +unsigned int nr_parts; };/* +* 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; +} + +/* * The world is not perfect and supplies us with broken mmc/sdio devices. * For at least some of these bugs we need a work-around. */
include/linux/mmc/mmc.h +0 -3
@@ -299,10 +299,7 @@ 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)
Signature · 1 line
1.7.4.4
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 <[email protected]>:
Quoted 16 lines
It allows gerneral purpose partitions in MMC Device.
And I try to simpliy makemmc_blk_alloc_partsusingmmc_partstructure suggested by Andrei Warkentin. After patching, we can see general purpose partitions like this.Quoted 1 line
cat
/proc/partitions179 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 mmcblk0boot0Signed-off-by Namjae Jeon <[email protected]>---
drivers/mmc/core/mmc.c static const unsigned int tacc_mant[] = { · line 48
Quoted 5 lines
drivers/mmc/core/mmc.c +5
-0+/* partition configuration array */ +static const unsigned int part_cfg[] = { + 0x1, 0x2, 0x4, 0x5, 0x6, 7, +}; +
No need. Plus this is obscure.
Quoted 4 lines
-
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;
Quoted 8 lines
+ 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);
}
}Quoted 16 lines
+ if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
0x1) {
+ u8hc_erase_grp_sz=
+ ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
+ u8hc_wp_grp_sz=
+ ext_csd[EXT_CSD_HC_WP_GRP_SIZE];drivers/mmc/core/mmc.c +11
-0+ + 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;
drivers/mmc/core/mmc.c static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) · line 442
Quoted 10 lines
drivers/mmc/core/mmc.c +10
-0+ 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);
}
}include/linux/mmc/card.h struct mmc_card { · line 249
Quoted 11 lines
/*
+ * This function fill contents inmmc_part.
+ */include/linux/mmc/card.h +8
-0+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++;
}include/linux/mmc/mmc.h struct _mmc_csd { · line 305
Quoted 4 lines
#define
EXT_CSD_PART_CONFIG_ACC_MASK(0x7)include/linux/mmc/mmc.h +0
-2-#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
2011/10/1 Andrei E. Warkentin <[email protected]>:
Quoted 133 lines
Hi Namjae,
Why don't you update
card->nr_partsinsidemmc_part_add? You're making this too complicated. There
is also no need for thepart_cfgarray.2011/9/30 Namjae Jeon <[email protected]>:
Quoted 16 lines
It allows gerneral purpose partitions in MMC Device.
And I try to simpliy makemmc_blk_alloc_partsusingmmc_partstructure suggested by Andrei Warkentin. After patching, we can see general purpose partitions like this.Quoted 1 line
cat
/proc/partitions179 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 mmcblk0boot0Signed-off-by Namjae Jeon <[email protected]>---
drivers/mmc/core/mmc.c static const unsigned int tacc_mant[] = { · line 48
Quoted 5 lines
drivers/mmc/core/mmc.c +5
-0+/* partition configuration array */ +static const unsigned int part_cfg[] = { + 0x1, 0x2, 0x4, 0x5, 0x6, 7, +}; +No need. Plus this is obscure.
Quoted 4 lines
-
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;Quoted 8 lines
+ 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 havemmc_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);
}
}Quoted 16 lines
+ if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
0x1) {
+ u8hc_erase_grp_sz=
+ ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
+ u8hc_wp_grp_sz=
+ ext_csd[EXT_CSD_HC_WP_GRP_SIZE];drivers/mmc/core/mmc.c +11
-0+ + 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;drivers/mmc/core/mmc.c static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd) · line 442
Quoted 10 lines
drivers/mmc/core/mmc.c +10
-0+ 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 touchcard->nr_parts, and get rid ofpart_cfgarray 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);
}
}include/linux/mmc/card.h struct mmc_card { · line 249
Quoted 11 lines
/*
+ * This function fill contents inmmc_part.
+ */include/linux/mmc/card.h +8
-0+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++;
}
Quoted 7 lines
include/linux/mmc/mmc.h struct _mmc_csd { · line 305
Quoted 4 lines
#define
EXT_CSD_PART_CONFIG_ACC_MASK(0x7)include/linux/mmc/mmc.h +0
-2-#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) -#define EXT_CSD_PART_CONFIG_ACC_BOOT1 (0x2)I'd also keep the
MMC_NUM_BOOT_PARTITIONandMMC_NUM_GP_PARTITIONdefs at the same location.
Why should this def move to mmc.h ?
this area where there are ext csd fields.
Quoted 12 lines
/* The number of MMC physical partitions
* It consist of boot partitions(2), general purpose partitions(4) in MMC v4.4 */
#defineMMC_NUM_BOOT_PARTITION2
#defineMMC_NUM_GP_PARTITION4#define
EXT_CSD_PART_CONFIG_ACC_BOOT0(0x1)
#defineEXT_CSD_PART_CONFIG_ACC_GP0(0x4)A