All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v10] mmc : general purpose partition support.
@ 2011-10-04 17:45 Namjae Jeon
  2011-10-04 18:19 ` S, Venkatraman
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Namjae Jeon @ 2011-10-04 17:45 UTC (permalink / raw)
  To: cjb, linux-mmc
  Cc: linux-kernel, awarkentin, adrian.hunter, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm, Namjae Jeon

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@gmail.com>
---
 drivers/mmc/card/block.c |   34 +++++++++++++++++------------
 drivers/mmc/core/mmc.c   |   52 ++++++++++++++++++++++++++++++++++++++++++---
 include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
 include/linux/mmc/mmc.h  |    5 +++-
 4 files changed, 105 insertions(+), 20 deletions(-)

diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
index 782d5f8..fb6f1e9 100644
--- a/drivers/mmc/card/block.c
+++ b/drivers/mmc/card/block.c
@@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card *card,
 	return 0;
 }
 
+/* MMC Physical partition consist of two boot partitions and
+ * up to four general purpose partitions.
+ * For each partitions enabled in EXT_CSD
+ * The block device will allocated to provide access to the partition.
+ */
+
 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 && mmc_boot_partition_access(card->host)) {
-		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 ((idx == 0 || idx == 1) &&
+			!mmc_boot_partition_access(card->host))
+			continue;
+		if (card->part[idx].size) {
+			ret = mmc_blk_alloc_part(card, md,
+				card->part[idx].part_cfg,
+				card->part[idx].size >> 9,
+				card->part[idx].force_ro,
+				card->part[idx].name);
+			if (ret)
+				return ret;
+		}
 	}
 
 	return ret;
diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
index c632b1f..2f458a0 100644
--- a/drivers/mmc/core/mmc.c
+++ b/drivers/mmc/core/mmc.c
@@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
  */
 static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
 {
-	int err = 0;
+	int err = 0, idx;
+	unsigned int part_size;
+	u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
 
 	BUG_ON(!card);
 
@@ -340,7 +342,14 @@ 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;
+		if (ext_csd[EXT_CSD_BOOT_MULT]) {
+			for (idx = 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);
+			}
+		}
 	}
 
 	card->ext_csd.raw_hc_erase_gap_size =
@@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
 		card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
 		if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
 		    (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
-			u8 hc_erase_grp_sz =
+			hc_erase_grp_sz =
 				ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
-			u8 hc_wp_grp_sz =
+			hc_wp_grp_sz =
 				ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
 
 			card->ext_csd.enhanced_area_en = 1;
@@ -393,6 +402,41 @@ 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;
 		}
+
+		/*
+		 * General purpose partition feature support --
+		 * If ext_csd have the size of general purpose partitions,
+		 * set size, part_cfg, partition name in mmc_part.
+		 */
+		if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
+			EXT_CSD_PART_SUPPORT_PART_EN) {
+			if (card->ext_csd.enhanced_area_en != 1) {
+				hc_erase_grp_sz =
+					ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
+				hc_wp_grp_sz =
+					ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
+
+				card->ext_csd.enhanced_area_en = 1;
+			}
+
+			for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) {
+				if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] &&
+				!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] &&
+				!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2])
+					continue;
+				part_size =
+				(ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]
+					<< 16) +
+				(ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
+					<< 8) +
+				ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
+				part_size *= (size_t)(hc_erase_grp_sz *
+					hc_wp_grp_sz);
+				mmc_part_add(card, part_size << 19,
+					EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
+					"gp%d", idx, 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 5294ddf..0522627 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;
@@ -64,7 +65,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 */
@@ -158,6 +158,23 @@ 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
+#define MMC_NUM_PHY_PARTITION	6
+
+/*
+ * MMC Physical partitions
+ */
+struct mmc_part {
+	unsigned int	size;	/* partition size (in bytes) */
+	unsigned int	part_cfg;	/* it used to part_type */
+	char	name[DISK_NAME_LEN];
+	bool	force_ro;	/* to make boot parts RO by default */
+};
+
 /*
  * MMC device
  */
@@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool ro)
+{
+	card->part[card->nr_parts].size = size;
+	card->part[card->nr_parts].part_cfg = part_cfg;
+	sprintf(card->part[card->nr_parts].name, name, idx);
+	card->part[card->nr_parts].force_ro = ro;
+	card->nr_parts++;
+}
+
+/*
  *  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.
  */
diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
index 50af227..ea558eb 100644
--- a/include/linux/mmc/mmc.h
+++ b/include/linux/mmc/mmc.h
@@ -270,6 +270,7 @@ struct _mmc_csd {
  * EXT_CSD fields
  */
 
+#define EXT_CSD_GP_SIZE_MULT		143	/* R/W */
 #define EXT_CSD_PARTITION_ATTRIBUTE	156	/* R/W */
 #define EXT_CSD_PARTITION_SUPPORT	160	/* RO */
 #define EXT_CSD_RST_N_FUNCTION		162	/* R/W */
@@ -313,7 +314,9 @@ struct _mmc_csd {
 
 #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_PART_CONFIG_ACC_GP0	(0x4)
+
+#define EXT_CSD_PART_SUPPORT_PART_EN	(0x1)
 
 #define EXT_CSD_CMD_SET_NORMAL		(1<<0)
 #define EXT_CSD_CMD_SET_SECURE		(1<<1)
-- 
1.7.4.4


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-04 17:45 [PATCH v10] mmc : general purpose partition support Namjae Jeon
@ 2011-10-04 18:19 ` S, Venkatraman
  2011-10-04 18:25     ` Chris Ball
  2011-10-04 20:20 ` Andrei Warkentin
  2011-10-05  9:12 ` Adrian Hunter
  2 siblings, 1 reply; 16+ messages in thread
From: S, Venkatraman @ 2011-10-04 18:19 UTC (permalink / raw)
  To: Namjae Jeon
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, adrian.hunter,
	linus.walleij, james_p_freyensee, sebras, Ulf.Hansson,
	stefan.xk.nilsson, per.forlin, johan.rudholm

On Tue, Oct 4, 2011 at 11:15 PM, Namjae Jeon <linkinjeon@gmail.com> 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 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@gmail.com>
> ---
>  drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>  drivers/mmc/core/mmc.c   |   52 ++++++++++++++++++++++++++++++++++++++++++---
>  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>  include/linux/mmc/mmc.h  |    5 +++-
>  4 files changed, 105 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index 782d5f8..fb6f1e9 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card *card,
>        return 0;
>  }
>
> +/* MMC Physical partition consist of two boot partitions and
> + * up to four general purpose partitions.
> + * For each partitions enabled in EXT_CSD
> + * The block device will allocated to provide access to the partition.
> + */
> +
>  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 && mmc_boot_partition_access(card->host)) {
> -               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 ((idx == 0 || idx == 1) &&
> +                       !mmc_boot_partition_access(card->host))
> +                       continue;
> +               if (card->part[idx].size) {
> +                       ret = mmc_blk_alloc_part(card, md,
> +                               card->part[idx].part_cfg,
> +                               card->part[idx].size >> 9,
> +                               card->part[idx].force_ro,
> +                               card->part[idx].name);
> +                       if (ret)
> +                               return ret;
> +               }
>        }
>
>        return ret;
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> index c632b1f..2f458a0 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
>  */
>  static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>  {
> -       int err = 0;
> +       int err = 0, idx;
> +       unsigned int part_size;
> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>
>        BUG_ON(!card);
>
> @@ -340,7 +342,14 @@ 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;
> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
> +                       for (idx = 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);
> +                       }
> +               }
>        }
>
>        card->ext_csd.raw_hc_erase_gap_size =
> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>                card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
>                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT] & 0x2) &&
>                    (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE] & 0x1)) {
> -                       u8 hc_erase_grp_sz =
> +                       hc_erase_grp_sz =
>                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
> -                       u8 hc_wp_grp_sz =
> +                       hc_wp_grp_sz =
>                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>
>                        card->ext_csd.enhanced_area_en = 1;
> @@ -393,6 +402,41 @@ 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;
>                }
> +
> +               /*
> +                * General purpose partition feature support --
> +                * If ext_csd have the size of general purpose partitions,
> +                * set size, part_cfg, partition name in mmc_part.
> +                */
> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT] &
> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
> +                       if (card->ext_csd.enhanced_area_en != 1) {
> +                               hc_erase_grp_sz =
> +                                       ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
> +                               hc_wp_grp_sz =
> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
> +
> +                               card->ext_csd.enhanced_area_en = 1;
> +                       }
> +
> +                       for (idx = 0; idx < MMC_NUM_GP_PARTITION; idx++) {
> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3] &&
> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1] &&
> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2])
> +                                       continue;
> +                               part_size =
> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]
> +                                       << 16) +
> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
> +                                       << 8) +
> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
> +                               part_size *= (size_t)(hc_erase_grp_sz *
> +                                       hc_wp_grp_sz);
> +                               mmc_part_add(card, part_size << 19,
> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
> @@ -64,7 +65,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 */
> @@ -158,6 +158,23 @@ 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
> +#define MMC_NUM_PHY_PARTITION  6
> +
> +/*
> + * MMC Physical partitions
> + */
> +struct mmc_part {
> +       unsigned int    size;   /* partition size (in bytes) */
> +       unsigned int    part_cfg;       /* it used to part_type */
> +       char    name[DISK_NAME_LEN];
> +       bool    force_ro;       /* to make boot parts RO by default */
> +};
> +
>  /*
>  * MMC device
>  */
> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool ro)
> +{
> +       card->part[card->nr_parts].size = size;
> +       card->part[card->nr_parts].part_cfg = part_cfg;
> +       sprintf(card->part[card->nr_parts].name, name, idx);
> +       card->part[card->nr_parts].force_ro = ro;
> +       card->nr_parts++;
> +}
> +
> +/*
>  *  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.
>  */
> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
> index 50af227..ea558eb 100644
> --- a/include/linux/mmc/mmc.h
> +++ b/include/linux/mmc/mmc.h
> @@ -270,6 +270,7 @@ struct _mmc_csd {
>  * EXT_CSD fields
>  */
>
> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>  #define EXT_CSD_PARTITION_ATTRIBUTE    156     /* R/W */
>  #define EXT_CSD_PARTITION_SUPPORT      160     /* RO */
>  #define EXT_CSD_RST_N_FUNCTION         162     /* R/W */
> @@ -313,7 +314,9 @@ struct _mmc_csd {
>
>  #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_PART_CONFIG_ACC_GP0    (0x4)
> +
> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>
>  #define EXT_CSD_CMD_SET_NORMAL         (1<<0)
>  #define EXT_CSD_CMD_SET_SECURE         (1<<1)
> --
> 1.7.4.4
>

Stupid question - This will affect all MMC instances, right ? Doesn't
this constitute a ABI breakage for user space scripts ?

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-04 18:19 ` S, Venkatraman
@ 2011-10-04 18:25     ` Chris Ball
  0 siblings, 0 replies; 16+ messages in thread
From: Chris Ball @ 2011-10-04 18:25 UTC (permalink / raw)
  To: S, Venkatraman
  Cc: Namjae Jeon, linux-mmc, linux-kernel, awarkentin, adrian.hunter,
	linus.walleij, james_p_freyensee, sebras, Ulf.Hansson,
	stefan.xk.nilsson, per.forlin, johan.rudholm

Hi,

On Tue, Oct 04 2011, S, Venkatraman wrote:
> Stupid question - This will affect all MMC instances, right ? Doesn't
> this constitute a ABI breakage for user space scripts ?

As I understand it, these partitions were simply not accessible before
this patch:  we're not renaming mmcblkNpY to anything else, we're adding
support for mmcblkNgpY partitions, which are part of the "MMC General
Purpose Partition" spec, and are partitioned separately and not
currently available to userspace.

So, I don't see what would constitute breakage.  Does that clear it up?

Thanks,

- Chris.
-- 
Chris Ball   <cjb@laptop.org>   <http://printf.net/>
One Laptop Per Child

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
@ 2011-10-04 18:25     ` Chris Ball
  0 siblings, 0 replies; 16+ messages in thread
From: Chris Ball @ 2011-10-04 18:25 UTC (permalink / raw)
  To: S, Venkatraman
  Cc: Namjae Jeon, linux-mmc, linux-kernel, awarkentin, adrian.hunter,
	linus.walleij, james_p_freyensee, sebras, Ulf.Hansson,
	stefan.xk.nilsson, per.forlin, johan.rudholm

Hi,

On Tue, Oct 04 2011, S, Venkatraman wrote:
> Stupid question - This will affect all MMC instances, right ? Doesn't
> this constitute a ABI breakage for user space scripts ?

As I understand it, these partitions were simply not accessible before
this patch:  we're not renaming mmcblkNpY to anything else, we're adding
support for mmcblkNgpY partitions, which are part of the "MMC General
Purpose Partition" spec, and are partitioned separately and not
currently available to userspace.

So, I don't see what would constitute breakage.  Does that clear it up?

Thanks,

- Chris.
-- 
Chris Ball   <cjb@laptop.org>   <http://printf.net/>
One Laptop Per Child

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-04 18:25     ` Chris Ball
  (?)
@ 2011-10-04 18:27     ` S, Venkatraman
  -1 siblings, 0 replies; 16+ messages in thread
From: S, Venkatraman @ 2011-10-04 18:27 UTC (permalink / raw)
  To: Chris Ball
  Cc: Namjae Jeon, linux-mmc, linux-kernel, awarkentin, adrian.hunter,
	linus.walleij, james_p_freyensee, sebras, Ulf.Hansson,
	stefan.xk.nilsson, per.forlin, johan.rudholm

On Tue, Oct 4, 2011 at 11:55 PM, Chris Ball <cjb@laptop.org> wrote:
> Hi,
>
> On Tue, Oct 04 2011, S, Venkatraman wrote:
>> Stupid question - This will affect all MMC instances, right ? Doesn't
>> this constitute a ABI breakage for user space scripts ?
>
> As I understand it, these partitions were simply not accessible before
> this patch:  we're not renaming mmcblkNpY to anything else, we're adding
> support for mmcblkNgpY partitions, which are part of the "MMC General
> Purpose Partition" spec, and are partitioned separately and not
> currently available to userspace.
>
> So, I don't see what would constitute breakage.  Does that clear it up?
>
It does - thanks !!

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-04 17:45 [PATCH v10] mmc : general purpose partition support Namjae Jeon
  2011-10-04 18:19 ` S, Venkatraman
@ 2011-10-04 20:20 ` Andrei Warkentin
  2011-10-05  9:12 ` Adrian Hunter
  2 siblings, 0 replies; 16+ messages in thread
From: Andrei Warkentin @ 2011-10-04 20:20 UTC (permalink / raw)
  To: Namjae Jeon
  Cc: linux-kernel, adrian hunter, linus walleij, james p freyensee,
	sebras, Ulf Hansson, stefan xk nilsson, per forlin,
	johan rudholm, cjb, linux-mmc

Hi,

----- Original Message -----
> From: "Namjae Jeon" <linkinjeon@gmail.com>
> To: cjb@laptop.org, linux-mmc@vger.kernel.org
> Cc: linux-kernel@vger.kernel.org, awarkentin@vmware.com, "adrian hunter" <adrian.hunter@intel.com>, "linus walleij"
> <linus.walleij@linaro.org>, "james p freyensee" <james_p_freyensee@linux.intel.com>, sebras@gmail.com, "Ulf Hansson"
> <Ulf.Hansson@stericsson.com>, "stefan xk nilsson" <stefan.xk.nilsson@stericsson.com>, "per forlin"
> <per.forlin@stericsson.com>, "johan rudholm" <johan.rudholm@stericsson.com>, "Namjae Jeon" <linkinjeon@gmail.com>
> Sent: Tuesday, October 4, 2011 1:45:17 PM
> Subject: [PATCH v10] 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.
> > 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@gmail.com>
> ---

Acked-by: Andrei Warkentin <andrey.warkentin@gmail.com>

A

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-04 17:45 [PATCH v10] mmc : general purpose partition support Namjae Jeon
  2011-10-04 18:19 ` S, Venkatraman
  2011-10-04 20:20 ` Andrei Warkentin
@ 2011-10-05  9:12 ` Adrian Hunter
  2011-10-05 10:21     ` NamJae Jeon
  2 siblings, 1 reply; 16+ messages in thread
From: Adrian Hunter @ 2011-10-05  9:12 UTC (permalink / raw)
  To: Namjae Jeon
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

On 04/10/11 20:45, 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 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@gmail.com>
> ---
>   drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>   drivers/mmc/core/mmc.c   |   52 ++++++++++++++++++++++++++++++++++++++++++---
>   include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>   include/linux/mmc/mmc.h  |    5 +++-
>   4 files changed, 105 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
> index 782d5f8..fb6f1e9 100644
> --- a/drivers/mmc/card/block.c
> +++ b/drivers/mmc/card/block.c
> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card *card,
>   	return 0;
>   }
>
> +/* MMC Physical partition consist of two boot partitions and
> + * up to four general purpose partitions.
> + * For each partitions enabled in EXT_CSD
> + * The block device will allocated to provide access to the partition.
> + */
> +
>   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&&  mmc_boot_partition_access(card->host)) {
> -		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 ((idx == 0 || idx == 1)&&
> +			!mmc_boot_partition_access(card->host))
> +			continue;

Seems a bit fragile.  What if someone decided to put the gp
partitions before the boot partitions.  What about:

		if (mmc_is_boot_partition(&part[idx]) &&
		    !mmc_boot_partition_access(card->host)
			continue;

And:

int mmc_is_boot_partition(struct mmc_part *part)
{
	return part->part_cfg >= EXT_CSD_PART_CONFIG_ACC_BOOT0 &&
	       part->part_cfg <= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
				 MMC_NUM_BOOT_PARTITION;
}

> +		if (card->part[idx].size) {
> +			ret = mmc_blk_alloc_part(card, md,
> +				card->part[idx].part_cfg,
> +				card->part[idx].size>>  9,
> +				card->part[idx].force_ro,
> +				card->part[idx].name);
> +			if (ret)
> +				return ret;
> +		}
>   	}
>
>   	return ret;
> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
> index c632b1f..2f458a0 100644
> --- a/drivers/mmc/core/mmc.c
> +++ b/drivers/mmc/core/mmc.c
> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd)
>    */
>   static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>   {
> -	int err = 0;
> +	int err = 0, idx;
> +	unsigned int part_size;
> +	u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>
>   	BUG_ON(!card);
>
> @@ -340,7 +342,14 @@ 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;
> +		if (ext_csd[EXT_CSD_BOOT_MULT]) {
> +			for (idx = 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);
> +			}
> +		}
>   	}
>
>   	card->ext_csd.raw_hc_erase_gap_size =
> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>   		card->ext_csd.raw_partition_support = ext_csd[EXT_CSD_PARTITION_SUPPORT];
>   		if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&  0x2)&&
>   		(ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&  0x1)) {
> -			u8 hc_erase_grp_sz =
> +			hc_erase_grp_sz =
>   				ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
> -			u8 hc_wp_grp_sz =
> +			hc_wp_grp_sz =
>   				ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>
>   			card->ext_csd.enhanced_area_en = 1;
> @@ -393,6 +402,41 @@ 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;
>   		}
> +
> +		/*
> +		 * General purpose partition feature support --
> +		 * If ext_csd have the size of general purpose partitions,
> +		 * set size, part_cfg, partition name in mmc_part.
> +		 */
> +		if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
> +			EXT_CSD_PART_SUPPORT_PART_EN) {
> +			if (card->ext_csd.enhanced_area_en != 1) {
> +				hc_erase_grp_sz =
> +					ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
> +				hc_wp_grp_sz =
> +					ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
> +
> +				card->ext_csd.enhanced_area_en = 1;
> +			}
> +
> +			for (idx = 0; idx<  MMC_NUM_GP_PARTITION; idx++) {
> +				if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3]&&
> +				!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]&&
> +				!ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2])
> +					continue;
> +				part_size =
> +				(ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 2]
> +					<<  16) +
> +				(ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 + 1]
> +					<<  8) +
> +				ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
> +				part_size *= (size_t)(hc_erase_grp_sz *
> +					hc_wp_grp_sz);
> +				mmc_part_add(card, part_size<<  19,
> +					EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
> +					"gp%d", idx, 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 5294ddf..0522627 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;
> @@ -64,7 +65,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 */
> @@ -158,6 +158,23 @@ 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
> +#define MMC_NUM_PHY_PARTITION	6
> +
> +/*
> + * MMC Physical partitions
> + */
> +struct mmc_part {
> +	unsigned int	size;	/* partition size (in bytes) */
> +	unsigned int	part_cfg;	/* it used to part_type */
> +	char	name[DISK_NAME_LEN];
> +	bool	force_ro;	/* to make boot parts RO by default */
> +};
> +
>   /*
>    * MMC device
>    */
> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool ro)
> +{
> +	card->part[card->nr_parts].size = size;
> +	card->part[card->nr_parts].part_cfg = part_cfg;
> +	sprintf(card->part[card->nr_parts].name, name, idx);
> +	card->part[card->nr_parts].force_ro = ro;
> +	card->nr_parts++;
> +}
> +
> +/*
>    *  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.
>    */
> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
> index 50af227..ea558eb 100644
> --- a/include/linux/mmc/mmc.h
> +++ b/include/linux/mmc/mmc.h
> @@ -270,6 +270,7 @@ struct _mmc_csd {
>    * EXT_CSD fields
>    */
>
> +#define EXT_CSD_GP_SIZE_MULT		143	/* R/W */
>   #define EXT_CSD_PARTITION_ATTRIBUTE	156	/* R/W */
>   #define EXT_CSD_PARTITION_SUPPORT	160	/* RO */
>   #define EXT_CSD_RST_N_FUNCTION		162	/* R/W */
> @@ -313,7 +314,9 @@ struct _mmc_csd {
>
>   #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_PART_CONFIG_ACC_GP0	(0x4)
> +
> +#define EXT_CSD_PART_SUPPORT_PART_EN	(0x1)
>
>   #define EXT_CSD_CMD_SET_NORMAL		(1<<0)
>   #define EXT_CSD_CMD_SET_SECURE		(1<<1)


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-05  9:12 ` Adrian Hunter
@ 2011-10-05 10:21     ` NamJae Jeon
  0 siblings, 0 replies; 16+ messages in thread
From: NamJae Jeon @ 2011-10-05 10:21 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 13538 bytes --]

2011/10/5 Adrian Hunter <adrian.hunter@intel.com>:
> On 04/10/11 20:45, 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 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@gmail.com>
>> ---
>>  drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>  drivers/mmc/core/mmc.c   |   52
>> ++++++++++++++++++++++++++++++++++++++++++---
>>  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>  include/linux/mmc/mmc.h  |    5 +++-
>>  4 files changed, 105 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>> index 782d5f8..fb6f1e9 100644
>> --- a/drivers/mmc/card/block.c
>> +++ b/drivers/mmc/card/block.c
>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>> *card,
>>        return 0;
>>  }
>>
>> +/* MMC Physical partition consist of two boot partitions and
>> + * up to four general purpose partitions.
>> + * For each partitions enabled in EXT_CSD
>> + * The block device will allocated to provide access to the partition.
>> + */
>> +
>>  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&&
>>  mmc_boot_partition_access(card->host)) {
>> -               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 ((idx == 0 || idx == 1)&&
>> +                       !mmc_boot_partition_access(card->host))
>> +                       continue;
>
> Seems a bit fragile.  What if someone decided to put the gp
> partitions before the boot partitions.  What about:
There are the default two boot partition in mmc spec. I think that
this case can not be happened.
And boot partition size of EXT CSD is read-only.
Can you explain which is case put to gp partitions before the boot partition ?

>
>                if (mmc_is_boot_partition(&part[idx]) &&
>                    !mmc_boot_partition_access(card->host)
>                        continue;
>
> And:
>
> int mmc_is_boot_partition(struct mmc_part *part)
> {
>        return part->part_cfg >= EXT_CSD_PART_CONFIG_ACC_BOOT0 &&
>               part->part_cfg <= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>                                 MMC_NUM_BOOT_PARTITION;
> }
>
>> +               if (card->part[idx].size) {
>> +                       ret = mmc_blk_alloc_part(card, md,
>> +                               card->part[idx].part_cfg,
>> +                               card->part[idx].size>>  9,
>> +                               card->part[idx].force_ro,
>> +                               card->part[idx].name);
>> +                       if (ret)
>> +                               return ret;
>> +               }
>>        }
>>
>>        return ret;
>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>> index c632b1f..2f458a0 100644
>> --- a/drivers/mmc/core/mmc.c
>> +++ b/drivers/mmc/core/mmc.c
>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8
>> **new_ext_csd)
>>   */
>>  static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>  {
>> -       int err = 0;
>> +       int err = 0, idx;
>> +       unsigned int part_size;
>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>
>>        BUG_ON(!card);
>>
>> @@ -340,7 +342,14 @@ 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;
>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>> +                       for (idx = 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);
>> +                       }
>> +               }
>>        }
>>
>>        card->ext_csd.raw_hc_erase_gap_size =
>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8
>> *ext_csd)
>>                card->ext_csd.raw_partition_support =
>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&  0x2)&&
>>                (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&  0x1)) {
>> -                       u8 hc_erase_grp_sz =
>> +                       hc_erase_grp_sz =
>>                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>> -                       u8 hc_wp_grp_sz =
>> +                       hc_wp_grp_sz =
>>                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>
>>                        card->ext_csd.enhanced_area_en = 1;
>> @@ -393,6 +402,41 @@ 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;
>>                }
>> +
>> +               /*
>> +                * General purpose partition feature support --
>> +                * If ext_csd have the size of general purpose partitions,
>> +                * set size, part_cfg, partition name in mmc_part.
>> +                */
>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>> +                               hc_erase_grp_sz =
>> +
>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>> +                               hc_wp_grp_sz =
>> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>> +
>> +                               card->ext_csd.enhanced_area_en = 1;
>> +                       }
>> +
>> +                       for (idx = 0; idx<  MMC_NUM_GP_PARTITION; idx++) {
>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx *
>> 3]&&
>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>> 1]&&
>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>> 2])
>> +                                       continue;
>> +                               part_size =
>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>> 2]
>> +                                       <<  16) +
>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>> 1]
>> +                                       <<  8) +
>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>> +                               part_size *= (size_t)(hc_erase_grp_sz *
>> +                                       hc_wp_grp_sz);
>> +                               mmc_part_add(card, part_size<<  19,
>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>> @@ -64,7 +65,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 */
>> @@ -158,6 +158,23 @@ 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
>> +#define MMC_NUM_PHY_PARTITION  6
>> +
>> +/*
>> + * MMC Physical partitions
>> + */
>> +struct mmc_part {
>> +       unsigned int    size;   /* partition size (in bytes) */
>> +       unsigned int    part_cfg;       /* it used to part_type */
>> +       char    name[DISK_NAME_LEN];
>> +       bool    force_ro;       /* to make boot parts RO by default */
>> +};
>> +
>>  /*
>>   * MMC device
>>   */
>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool
>> ro)
>> +{
>> +       card->part[card->nr_parts].size = size;
>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>> +       card->part[card->nr_parts].force_ro = ro;
>> +       card->nr_parts++;
>> +}
>> +
>> +/*
>>   *  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.
>>   */
>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>> index 50af227..ea558eb 100644
>> --- a/include/linux/mmc/mmc.h
>> +++ b/include/linux/mmc/mmc.h
>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>   * EXT_CSD fields
>>   */
>>
>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>  #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>  #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>  #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>
>>  #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_PART_CONFIG_ACC_GP0    (0x4)
>> +
>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>
>>  #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>  #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>
>
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
@ 2011-10-05 10:21     ` NamJae Jeon
  0 siblings, 0 replies; 16+ messages in thread
From: NamJae Jeon @ 2011-10-05 10:21 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

2011/10/5 Adrian Hunter <adrian.hunter@intel.com>:
> On 04/10/11 20:45, 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 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@gmail.com>
>> ---
>>  drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>  drivers/mmc/core/mmc.c   |   52
>> ++++++++++++++++++++++++++++++++++++++++++---
>>  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>  include/linux/mmc/mmc.h  |    5 +++-
>>  4 files changed, 105 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>> index 782d5f8..fb6f1e9 100644
>> --- a/drivers/mmc/card/block.c
>> +++ b/drivers/mmc/card/block.c
>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>> *card,
>>        return 0;
>>  }
>>
>> +/* MMC Physical partition consist of two boot partitions and
>> + * up to four general purpose partitions.
>> + * For each partitions enabled in EXT_CSD
>> + * The block device will allocated to provide access to the partition.
>> + */
>> +
>>  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&&
>>  mmc_boot_partition_access(card->host)) {
>> -               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 ((idx == 0 || idx == 1)&&
>> +                       !mmc_boot_partition_access(card->host))
>> +                       continue;
>
> Seems a bit fragile.  What if someone decided to put the gp
> partitions before the boot partitions.  What about:
There are the default two boot partition in mmc spec. I think that
this case can not be happened.
And boot partition size of EXT CSD is read-only.
Can you explain which is case put to gp partitions before the boot partition ?

>
>                if (mmc_is_boot_partition(&part[idx]) &&
>                    !mmc_boot_partition_access(card->host)
>                        continue;
>
> And:
>
> int mmc_is_boot_partition(struct mmc_part *part)
> {
>        return part->part_cfg >= EXT_CSD_PART_CONFIG_ACC_BOOT0 &&
>               part->part_cfg <= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>                                 MMC_NUM_BOOT_PARTITION;
> }
>
>> +               if (card->part[idx].size) {
>> +                       ret = mmc_blk_alloc_part(card, md,
>> +                               card->part[idx].part_cfg,
>> +                               card->part[idx].size>>  9,
>> +                               card->part[idx].force_ro,
>> +                               card->part[idx].name);
>> +                       if (ret)
>> +                               return ret;
>> +               }
>>        }
>>
>>        return ret;
>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>> index c632b1f..2f458a0 100644
>> --- a/drivers/mmc/core/mmc.c
>> +++ b/drivers/mmc/core/mmc.c
>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8
>> **new_ext_csd)
>>   */
>>  static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>  {
>> -       int err = 0;
>> +       int err = 0, idx;
>> +       unsigned int part_size;
>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>
>>        BUG_ON(!card);
>>
>> @@ -340,7 +342,14 @@ 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;
>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>> +                       for (idx = 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);
>> +                       }
>> +               }
>>        }
>>
>>        card->ext_csd.raw_hc_erase_gap_size =
>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8
>> *ext_csd)
>>                card->ext_csd.raw_partition_support =
>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&  0x2)&&
>>                (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&  0x1)) {
>> -                       u8 hc_erase_grp_sz =
>> +                       hc_erase_grp_sz =
>>                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>> -                       u8 hc_wp_grp_sz =
>> +                       hc_wp_grp_sz =
>>                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>
>>                        card->ext_csd.enhanced_area_en = 1;
>> @@ -393,6 +402,41 @@ 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;
>>                }
>> +
>> +               /*
>> +                * General purpose partition feature support --
>> +                * If ext_csd have the size of general purpose partitions,
>> +                * set size, part_cfg, partition name in mmc_part.
>> +                */
>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>> +                               hc_erase_grp_sz =
>> +
>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>> +                               hc_wp_grp_sz =
>> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>> +
>> +                               card->ext_csd.enhanced_area_en = 1;
>> +                       }
>> +
>> +                       for (idx = 0; idx<  MMC_NUM_GP_PARTITION; idx++) {
>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx *
>> 3]&&
>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>> 1]&&
>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>> 2])
>> +                                       continue;
>> +                               part_size =
>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>> 2]
>> +                                       <<  16) +
>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>> 1]
>> +                                       <<  8) +
>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>> +                               part_size *= (size_t)(hc_erase_grp_sz *
>> +                                       hc_wp_grp_sz);
>> +                               mmc_part_add(card, part_size<<  19,
>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>> @@ -64,7 +65,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 */
>> @@ -158,6 +158,23 @@ 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
>> +#define MMC_NUM_PHY_PARTITION  6
>> +
>> +/*
>> + * MMC Physical partitions
>> + */
>> +struct mmc_part {
>> +       unsigned int    size;   /* partition size (in bytes) */
>> +       unsigned int    part_cfg;       /* it used to part_type */
>> +       char    name[DISK_NAME_LEN];
>> +       bool    force_ro;       /* to make boot parts RO by default */
>> +};
>> +
>>  /*
>>   * MMC device
>>   */
>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool
>> ro)
>> +{
>> +       card->part[card->nr_parts].size = size;
>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>> +       card->part[card->nr_parts].force_ro = ro;
>> +       card->nr_parts++;
>> +}
>> +
>> +/*
>>   *  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.
>>   */
>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>> index 50af227..ea558eb 100644
>> --- a/include/linux/mmc/mmc.h
>> +++ b/include/linux/mmc/mmc.h
>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>   * EXT_CSD fields
>>   */
>>
>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>  #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>  #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>  #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>
>>  #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_PART_CONFIG_ACC_GP0    (0x4)
>> +
>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>
>>  #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>  #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-05 10:21     ` NamJae Jeon
  (?)
@ 2011-10-05 10:53     ` Adrian Hunter
  2011-10-05 11:21         ` NamJae Jeon
  -1 siblings, 1 reply; 16+ messages in thread
From: Adrian Hunter @ 2011-10-05 10:53 UTC (permalink / raw)
  To: NamJae Jeon
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

On 05/10/11 13:21, NamJae Jeon wrote:
> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>> On 04/10/11 20:45, 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 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@gmail.com>
>>> ---
>>>   drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>>   drivers/mmc/core/mmc.c   |   52
>>> ++++++++++++++++++++++++++++++++++++++++++---
>>>   include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>>   include/linux/mmc/mmc.h  |    5 +++-
>>>   4 files changed, 105 insertions(+), 20 deletions(-)
>>>
>>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>>> index 782d5f8..fb6f1e9 100644
>>> --- a/drivers/mmc/card/block.c
>>> +++ b/drivers/mmc/card/block.c
>>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>>> *card,
>>>         return 0;
>>>   }
>>>
>>> +/* MMC Physical partition consist of two boot partitions and
>>> + * up to four general purpose partitions.
>>> + * For each partitions enabled in EXT_CSD
>>> + * The block device will allocated to provide access to the partition.
>>> + */
>>> +
>>>   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&&
>>>   mmc_boot_partition_access(card->host)) {
>>> -               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 ((idx == 0 || idx == 1)&&
>>> +                       !mmc_boot_partition_access(card->host))
>>> +                       continue;
>>
>> Seems a bit fragile.  What if someone decided to put the gp
>> partitions before the boot partitions.  What about:
> There are the default two boot partition in mmc spec. I think that
> this case can not be happened.
> And boot partition size of EXT CSD is read-only.
> Can you explain which is case put to gp partitions before the boot partition ?

Relying on the partition order in the partition array is fragile.
You cannot predict how someone may want to change it in the future,
and that person will not expect that certain positions have certain meaning.

>
>>
>>                 if (mmc_is_boot_partition(&part[idx])&&
>>                     !mmc_boot_partition_access(card->host)
>>                         continue;
>>
>> And:
>>
>> int mmc_is_boot_partition(struct mmc_part *part)
>> {
>>         return part->part_cfg>= EXT_CSD_PART_CONFIG_ACC_BOOT0&&
>>                part->part_cfg<= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>>                                  MMC_NUM_BOOT_PARTITION;
>> }
>>
>>> +               if (card->part[idx].size) {
>>> +                       ret = mmc_blk_alloc_part(card, md,
>>> +                               card->part[idx].part_cfg,
>>> +                               card->part[idx].size>>    9,
>>> +                               card->part[idx].force_ro,
>>> +                               card->part[idx].name);
>>> +                       if (ret)
>>> +                               return ret;
>>> +               }
>>>         }
>>>
>>>         return ret;
>>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>>> index c632b1f..2f458a0 100644
>>> --- a/drivers/mmc/core/mmc.c
>>> +++ b/drivers/mmc/core/mmc.c
>>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8
>>> **new_ext_csd)
>>>    */
>>>   static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>>   {
>>> -       int err = 0;
>>> +       int err = 0, idx;
>>> +       unsigned int part_size;
>>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>>
>>>         BUG_ON(!card);
>>>
>>> @@ -340,7 +342,14 @@ 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;
>>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>>> +                       for (idx = 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);
>>> +                       }
>>> +               }
>>>         }
>>>
>>>         card->ext_csd.raw_hc_erase_gap_size =
>>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card, u8
>>> *ext_csd)
>>>                 card->ext_csd.raw_partition_support =
>>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>>                 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&    0x2)&&
>>>                 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&    0x1)) {
>>> -                       u8 hc_erase_grp_sz =
>>> +                       hc_erase_grp_sz =
>>>                                 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>> -                       u8 hc_wp_grp_sz =
>>> +                       hc_wp_grp_sz =
>>>                                 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>
>>>                         card->ext_csd.enhanced_area_en = 1;
>>> @@ -393,6 +402,41 @@ 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;
>>>                 }
>>> +
>>> +               /*
>>> +                * General purpose partition feature support --
>>> +                * If ext_csd have the size of general purpose partitions,
>>> +                * set size, part_cfg, partition name in mmc_part.
>>> +                */
>>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>>> +                               hc_erase_grp_sz =
>>> +
>>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>> +                               hc_wp_grp_sz =
>>> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>> +
>>> +                               card->ext_csd.enhanced_area_en = 1;
>>> +                       }
>>> +
>>> +                       for (idx = 0; idx<    MMC_NUM_GP_PARTITION; idx++) {
>>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx *
>>> 3]&&
>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>>> 1]&&
>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>>> 2])
>>> +                                       continue;
>>> +                               part_size =
>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>>> 2]
>>> +<<    16) +
>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3 +
>>> 1]
>>> +<<    8) +
>>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>>> +                               part_size *= (size_t)(hc_erase_grp_sz *
>>> +                                       hc_wp_grp_sz);
>>> +                               mmc_part_add(card, part_size<<    19,
>>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 + idx,
>>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>>> @@ -64,7 +65,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 */
>>> @@ -158,6 +158,23 @@ 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
>>> +#define MMC_NUM_PHY_PARTITION  6
>>> +
>>> +/*
>>> + * MMC Physical partitions
>>> + */
>>> +struct mmc_part {
>>> +       unsigned int    size;   /* partition size (in bytes) */
>>> +       unsigned int    part_cfg;       /* it used to part_type */
>>> +       char    name[DISK_NAME_LEN];
>>> +       bool    force_ro;       /* to make boot parts RO by default */
>>> +};
>>> +
>>>   /*
>>>    * MMC device
>>>    */
>>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool
>>> ro)
>>> +{
>>> +       card->part[card->nr_parts].size = size;
>>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>>> +       card->part[card->nr_parts].force_ro = ro;
>>> +       card->nr_parts++;
>>> +}
>>> +
>>> +/*
>>>    *  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.
>>>    */
>>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>>> index 50af227..ea558eb 100644
>>> --- a/include/linux/mmc/mmc.h
>>> +++ b/include/linux/mmc/mmc.h
>>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>>    * EXT_CSD fields
>>>    */
>>>
>>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>>   #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>>   #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>>   #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>>
>>>   #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_PART_CONFIG_ACC_GP0    (0x4)
>>> +
>>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>>
>>>   #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>>   #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>>
>>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-05 10:53     ` Adrian Hunter
@ 2011-10-05 11:21         ` NamJae Jeon
  0 siblings, 0 replies; 16+ messages in thread
From: NamJae Jeon @ 2011-10-05 11:21 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 14620 bytes --]

2011/10/5 Adrian Hunter <adrian.hunter@intel.com>:
> On 05/10/11 13:21, NamJae Jeon wrote:
>>
>> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>>>
>>> On 04/10/11 20:45, 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 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@gmail.com>
>>>> ---
>>>>  drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>>>  drivers/mmc/core/mmc.c   |   52
>>>> ++++++++++++++++++++++++++++++++++++++++++---
>>>>  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>>>  include/linux/mmc/mmc.h  |    5 +++-
>>>>  4 files changed, 105 insertions(+), 20 deletions(-)
>>>>
>>>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>>>> index 782d5f8..fb6f1e9 100644
>>>> --- a/drivers/mmc/card/block.c
>>>> +++ b/drivers/mmc/card/block.c
>>>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>>>> *card,
>>>>        return 0;
>>>>  }
>>>>
>>>> +/* MMC Physical partition consist of two boot partitions and
>>>> + * up to four general purpose partitions.
>>>> + * For each partitions enabled in EXT_CSD
>>>> + * The block device will allocated to provide access to the partition.
>>>> + */
>>>> +
>>>>  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&&
>>>>  mmc_boot_partition_access(card->host)) {
>>>> -               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 ((idx == 0 || idx == 1)&&
>>>> +                       !mmc_boot_partition_access(card->host))
>>>> +                       continue;
>>>
>>> Seems a bit fragile.  What if someone decided to put the gp
>>> partitions before the boot partitions.  What about:
>>
>> There are the default two boot partition in mmc spec. I think that
>> this case can not be happened.
>> And boot partition size of EXT CSD is read-only.
>> Can you explain which is case put to gp partitions before the boot
>> partition ?
>
> Relying on the partition order in the partition array is fragile.
> You cannot predict how someone may want to change it in the future,
> and that person will not expect that certain positions have certain meaning.
 0,1 of Boot partition is fixed if spec is changed over. but gp
partition is variable in 2,3,4,5,6 of array.
If How someone change code, problem occur ?
>
>>
>>>
>>>                if (mmc_is_boot_partition(&part[idx])&&
>>>                    !mmc_boot_partition_access(card->host)
>>>                        continue;
>>>
>>> And:
>>>
>>> int mmc_is_boot_partition(struct mmc_part *part)
>>> {
>>>        return part->part_cfg>= EXT_CSD_PART_CONFIG_ACC_BOOT0&&
>>>               part->part_cfg<= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>>>                                 MMC_NUM_BOOT_PARTITION;
>>> }
>>>
>>>> +               if (card->part[idx].size) {
>>>> +                       ret = mmc_blk_alloc_part(card, md,
>>>> +                               card->part[idx].part_cfg,
>>>> +                               card->part[idx].size>>    9,
>>>> +                               card->part[idx].force_ro,
>>>> +                               card->part[idx].name);
>>>> +                       if (ret)
>>>> +                               return ret;
>>>> +               }
>>>>        }
>>>>
>>>>        return ret;
>>>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>>>> index c632b1f..2f458a0 100644
>>>> --- a/drivers/mmc/core/mmc.c
>>>> +++ b/drivers/mmc/core/mmc.c
>>>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8
>>>> **new_ext_csd)
>>>>   */
>>>>  static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>>>  {
>>>> -       int err = 0;
>>>> +       int err = 0, idx;
>>>> +       unsigned int part_size;
>>>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>>>
>>>>        BUG_ON(!card);
>>>>
>>>> @@ -340,7 +342,14 @@ 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;
>>>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>>>> +                       for (idx = 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);
>>>> +                       }
>>>> +               }
>>>>        }
>>>>
>>>>        card->ext_csd.raw_hc_erase_gap_size =
>>>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card,
>>>> u8
>>>> *ext_csd)
>>>>                card->ext_csd.raw_partition_support =
>>>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>>>                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&    0x2)&&
>>>>                (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&    0x1)) {
>>>> -                       u8 hc_erase_grp_sz =
>>>> +                       hc_erase_grp_sz =
>>>>                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>> -                       u8 hc_wp_grp_sz =
>>>> +                       hc_wp_grp_sz =
>>>>                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>
>>>>                        card->ext_csd.enhanced_area_en = 1;
>>>> @@ -393,6 +402,41 @@ 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;
>>>>                }
>>>> +
>>>> +               /*
>>>> +                * General purpose partition feature support --
>>>> +                * If ext_csd have the size of general purpose
>>>> partitions,
>>>> +                * set size, part_cfg, partition name in mmc_part.
>>>> +                */
>>>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>>>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>>>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>>>> +                               hc_erase_grp_sz =
>>>> +
>>>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>> +                               hc_wp_grp_sz =
>>>> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>> +
>>>> +                               card->ext_csd.enhanced_area_en = 1;
>>>> +                       }
>>>> +
>>>> +                       for (idx = 0; idx<    MMC_NUM_GP_PARTITION;
>>>> idx++) {
>>>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx
>>>> *
>>>> 3]&&
>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>> +
>>>> 1]&&
>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>> +
>>>> 2])
>>>> +                                       continue;
>>>> +                               part_size =
>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>> +
>>>> 2]
>>>> +<<    16) +
>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>> +
>>>> 1]
>>>> +<<    8) +
>>>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>>>> +                               part_size *= (size_t)(hc_erase_grp_sz *
>>>> +                                       hc_wp_grp_sz);
>>>> +                               mmc_part_add(card, part_size<<    19,
>>>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 +
>>>> idx,
>>>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>>>> @@ -64,7 +65,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 */
>>>> @@ -158,6 +158,23 @@ 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
>>>> +#define MMC_NUM_PHY_PARTITION  6
>>>> +
>>>> +/*
>>>> + * MMC Physical partitions
>>>> + */
>>>> +struct mmc_part {
>>>> +       unsigned int    size;   /* partition size (in bytes) */
>>>> +       unsigned int    part_cfg;       /* it used to part_type */
>>>> +       char    name[DISK_NAME_LEN];
>>>> +       bool    force_ro;       /* to make boot parts RO by default */
>>>> +};
>>>> +
>>>>  /*
>>>>   * MMC device
>>>>   */
>>>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool
>>>> ro)
>>>> +{
>>>> +       card->part[card->nr_parts].size = size;
>>>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>>>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>>>> +       card->part[card->nr_parts].force_ro = ro;
>>>> +       card->nr_parts++;
>>>> +}
>>>> +
>>>> +/*
>>>>   *  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.
>>>>   */
>>>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>>>> index 50af227..ea558eb 100644
>>>> --- a/include/linux/mmc/mmc.h
>>>> +++ b/include/linux/mmc/mmc.h
>>>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>>>   * EXT_CSD fields
>>>>   */
>>>>
>>>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>>>  #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>>>  #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>>>  #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>>>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>>>
>>>>  #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_PART_CONFIG_ACC_GP0    (0x4)
>>>> +
>>>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>>>
>>>>  #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>>>  #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>>>
>>>
>
>
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
@ 2011-10-05 11:21         ` NamJae Jeon
  0 siblings, 0 replies; 16+ messages in thread
From: NamJae Jeon @ 2011-10-05 11:21 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

2011/10/5 Adrian Hunter <adrian.hunter@intel.com>:
> On 05/10/11 13:21, NamJae Jeon wrote:
>>
>> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>>>
>>> On 04/10/11 20:45, 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 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@gmail.com>
>>>> ---
>>>>  drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>>>  drivers/mmc/core/mmc.c   |   52
>>>> ++++++++++++++++++++++++++++++++++++++++++---
>>>>  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>>>  include/linux/mmc/mmc.h  |    5 +++-
>>>>  4 files changed, 105 insertions(+), 20 deletions(-)
>>>>
>>>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>>>> index 782d5f8..fb6f1e9 100644
>>>> --- a/drivers/mmc/card/block.c
>>>> +++ b/drivers/mmc/card/block.c
>>>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>>>> *card,
>>>>        return 0;
>>>>  }
>>>>
>>>> +/* MMC Physical partition consist of two boot partitions and
>>>> + * up to four general purpose partitions.
>>>> + * For each partitions enabled in EXT_CSD
>>>> + * The block device will allocated to provide access to the partition.
>>>> + */
>>>> +
>>>>  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&&
>>>>  mmc_boot_partition_access(card->host)) {
>>>> -               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 ((idx == 0 || idx == 1)&&
>>>> +                       !mmc_boot_partition_access(card->host))
>>>> +                       continue;
>>>
>>> Seems a bit fragile.  What if someone decided to put the gp
>>> partitions before the boot partitions.  What about:
>>
>> There are the default two boot partition in mmc spec. I think that
>> this case can not be happened.
>> And boot partition size of EXT CSD is read-only.
>> Can you explain which is case put to gp partitions before the boot
>> partition ?
>
> Relying on the partition order in the partition array is fragile.
> You cannot predict how someone may want to change it in the future,
> and that person will not expect that certain positions have certain meaning.
 0,1 of Boot partition is fixed if spec is changed over. but gp
partition is variable in 2,3,4,5,6 of array.
If How someone change code, problem occur ?
>
>>
>>>
>>>                if (mmc_is_boot_partition(&part[idx])&&
>>>                    !mmc_boot_partition_access(card->host)
>>>                        continue;
>>>
>>> And:
>>>
>>> int mmc_is_boot_partition(struct mmc_part *part)
>>> {
>>>        return part->part_cfg>= EXT_CSD_PART_CONFIG_ACC_BOOT0&&
>>>               part->part_cfg<= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>>>                                 MMC_NUM_BOOT_PARTITION;
>>> }
>>>
>>>> +               if (card->part[idx].size) {
>>>> +                       ret = mmc_blk_alloc_part(card, md,
>>>> +                               card->part[idx].part_cfg,
>>>> +                               card->part[idx].size>>    9,
>>>> +                               card->part[idx].force_ro,
>>>> +                               card->part[idx].name);
>>>> +                       if (ret)
>>>> +                               return ret;
>>>> +               }
>>>>        }
>>>>
>>>>        return ret;
>>>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>>>> index c632b1f..2f458a0 100644
>>>> --- a/drivers/mmc/core/mmc.c
>>>> +++ b/drivers/mmc/core/mmc.c
>>>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8
>>>> **new_ext_csd)
>>>>   */
>>>>  static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>>>  {
>>>> -       int err = 0;
>>>> +       int err = 0, idx;
>>>> +       unsigned int part_size;
>>>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>>>
>>>>        BUG_ON(!card);
>>>>
>>>> @@ -340,7 +342,14 @@ 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;
>>>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>>>> +                       for (idx = 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);
>>>> +                       }
>>>> +               }
>>>>        }
>>>>
>>>>        card->ext_csd.raw_hc_erase_gap_size =
>>>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card,
>>>> u8
>>>> *ext_csd)
>>>>                card->ext_csd.raw_partition_support =
>>>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>>>                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&    0x2)&&
>>>>                (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&    0x1)) {
>>>> -                       u8 hc_erase_grp_sz =
>>>> +                       hc_erase_grp_sz =
>>>>                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>> -                       u8 hc_wp_grp_sz =
>>>> +                       hc_wp_grp_sz =
>>>>                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>
>>>>                        card->ext_csd.enhanced_area_en = 1;
>>>> @@ -393,6 +402,41 @@ 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;
>>>>                }
>>>> +
>>>> +               /*
>>>> +                * General purpose partition feature support --
>>>> +                * If ext_csd have the size of general purpose
>>>> partitions,
>>>> +                * set size, part_cfg, partition name in mmc_part.
>>>> +                */
>>>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>>>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>>>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>>>> +                               hc_erase_grp_sz =
>>>> +
>>>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>> +                               hc_wp_grp_sz =
>>>> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>> +
>>>> +                               card->ext_csd.enhanced_area_en = 1;
>>>> +                       }
>>>> +
>>>> +                       for (idx = 0; idx<    MMC_NUM_GP_PARTITION;
>>>> idx++) {
>>>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx
>>>> *
>>>> 3]&&
>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>> +
>>>> 1]&&
>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>> +
>>>> 2])
>>>> +                                       continue;
>>>> +                               part_size =
>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>> +
>>>> 2]
>>>> +<<    16) +
>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>> +
>>>> 1]
>>>> +<<    8) +
>>>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>>>> +                               part_size *= (size_t)(hc_erase_grp_sz *
>>>> +                                       hc_wp_grp_sz);
>>>> +                               mmc_part_add(card, part_size<<    19,
>>>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 +
>>>> idx,
>>>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>>>> @@ -64,7 +65,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 */
>>>> @@ -158,6 +158,23 @@ 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
>>>> +#define MMC_NUM_PHY_PARTITION  6
>>>> +
>>>> +/*
>>>> + * MMC Physical partitions
>>>> + */
>>>> +struct mmc_part {
>>>> +       unsigned int    size;   /* partition size (in bytes) */
>>>> +       unsigned int    part_cfg;       /* it used to part_type */
>>>> +       char    name[DISK_NAME_LEN];
>>>> +       bool    force_ro;       /* to make boot parts RO by default */
>>>> +};
>>>> +
>>>>  /*
>>>>   * MMC device
>>>>   */
>>>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool
>>>> ro)
>>>> +{
>>>> +       card->part[card->nr_parts].size = size;
>>>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>>>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>>>> +       card->part[card->nr_parts].force_ro = ro;
>>>> +       card->nr_parts++;
>>>> +}
>>>> +
>>>> +/*
>>>>   *  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.
>>>>   */
>>>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>>>> index 50af227..ea558eb 100644
>>>> --- a/include/linux/mmc/mmc.h
>>>> +++ b/include/linux/mmc/mmc.h
>>>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>>>   * EXT_CSD fields
>>>>   */
>>>>
>>>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>>>  #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>>>  #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>>>  #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>>>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>>>
>>>>  #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_PART_CONFIG_ACC_GP0    (0x4)
>>>> +
>>>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>>>
>>>>  #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>>>  #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>>>
>>>
>
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-05 11:21         ` NamJae Jeon
@ 2011-10-05 11:22           ` NamJae Jeon
  -1 siblings, 0 replies; 16+ messages in thread
From: NamJae Jeon @ 2011-10-05 11:22 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset=UTF-8, Size: 15004 bytes --]

2011/10/5 NamJae Jeon <linkinjeon@gmail.com>:
> 2011/10/5 Adrian Hunter <adrian.hunter@intel.com>:
>> On 05/10/11 13:21, NamJae Jeon wrote:
>>>
>>> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>>>>
>>>> On 04/10/11 20:45, 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 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@gmail.com>
>>>>> ---
>>>>>  drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>>>>  drivers/mmc/core/mmc.c   |   52
>>>>> ++++++++++++++++++++++++++++++++++++++++++---
>>>>>  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>>>>  include/linux/mmc/mmc.h  |    5 +++-
>>>>>  4 files changed, 105 insertions(+), 20 deletions(-)
>>>>>
>>>>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>>>>> index 782d5f8..fb6f1e9 100644
>>>>> --- a/drivers/mmc/card/block.c
>>>>> +++ b/drivers/mmc/card/block.c
>>>>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>>>>> *card,
>>>>>        return 0;
>>>>>  }
>>>>>
>>>>> +/* MMC Physical partition consist of two boot partitions and
>>>>> + * up to four general purpose partitions.
>>>>> + * For each partitions enabled in EXT_CSD
>>>>> + * The block device will allocated to provide access to the partition.
>>>>> + */
>>>>> +
>>>>>  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&&
>>>>>  mmc_boot_partition_access(card->host)) {
>>>>> -               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 ((idx == 0 || idx == 1)&&
>>>>> +                       !mmc_boot_partition_access(card->host))
>>>>> +                       continue;
>>>>
>>>> Seems a bit fragile.  What if someone decided to put the gp
>>>> partitions before the boot partitions.  What about:
>>>
>>> There are the default two boot partition in mmc spec. I think that
>>> this case can not be happened.
>>> And boot partition size of EXT CSD is read-only.
>>> Can you explain which is case put to gp partitions before the boot
>>> partition ?
>>
>> Relying on the partition order in the partition array is fragile.
>> You cannot predict how someone may want to change it in the future,
>> and that person will not expect that certain positions have certain meaning.
0,1 of Boot partition is fixed if spec is not changed over. but gp
partition is variable in 2,3,4,5,6 of array.
If How someone change code, problem occur ?
>>
>>>
>>>>
>>>>                if (mmc_is_boot_partition(&part[idx])&&
>>>>                    !mmc_boot_partition_access(card->host)
>>>>                        continue;
>>>>
>>>> And:
>>>>
>>>> int mmc_is_boot_partition(struct mmc_part *part)
>>>> {
>>>>        return part->part_cfg>= EXT_CSD_PART_CONFIG_ACC_BOOT0&&
>>>>               part->part_cfg<= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>>>>                                 MMC_NUM_BOOT_PARTITION;
>>>> }
>>>>
>>>>> +               if (card->part[idx].size) {
>>>>> +                       ret = mmc_blk_alloc_part(card, md,
>>>>> +                               card->part[idx].part_cfg,
>>>>> +                               card->part[idx].size>>    9,
>>>>> +                               card->part[idx].force_ro,
>>>>> +                               card->part[idx].name);
>>>>> +                       if (ret)
>>>>> +                               return ret;
>>>>> +               }
>>>>>        }
>>>>>
>>>>>        return ret;
>>>>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>>>>> index c632b1f..2f458a0 100644
>>>>> --- a/drivers/mmc/core/mmc.c
>>>>> +++ b/drivers/mmc/core/mmc.c
>>>>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8
>>>>> **new_ext_csd)
>>>>>   */
>>>>>  static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>>>>  {
>>>>> -       int err = 0;
>>>>> +       int err = 0, idx;
>>>>> +       unsigned int part_size;
>>>>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>>>>
>>>>>        BUG_ON(!card);
>>>>>
>>>>> @@ -340,7 +342,14 @@ 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;
>>>>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>>>>> +                       for (idx = 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);
>>>>> +                       }
>>>>> +               }
>>>>>        }
>>>>>
>>>>>        card->ext_csd.raw_hc_erase_gap_size =
>>>>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card,
>>>>> u8
>>>>> *ext_csd)
>>>>>                card->ext_csd.raw_partition_support =
>>>>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>>>>                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&    0x2)&&
>>>>>                (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&    0x1)) {
>>>>> -                       u8 hc_erase_grp_sz =
>>>>> +                       hc_erase_grp_sz =
>>>>>                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>>> -                       u8 hc_wp_grp_sz =
>>>>> +                       hc_wp_grp_sz =
>>>>>                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>>
>>>>>                        card->ext_csd.enhanced_area_en = 1;
>>>>> @@ -393,6 +402,41 @@ 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;
>>>>>                }
>>>>> +
>>>>> +               /*
>>>>> +                * General purpose partition feature support --
>>>>> +                * If ext_csd have the size of general purpose
>>>>> partitions,
>>>>> +                * set size, part_cfg, partition name in mmc_part.
>>>>> +                */
>>>>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>>>>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>>>>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>>>>> +                               hc_erase_grp_sz =
>>>>> +
>>>>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>>> +                               hc_wp_grp_sz =
>>>>> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>> +
>>>>> +                               card->ext_csd.enhanced_area_en = 1;
>>>>> +                       }
>>>>> +
>>>>> +                       for (idx = 0; idx<    MMC_NUM_GP_PARTITION;
>>>>> idx++) {
>>>>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx
>>>>> *
>>>>> 3]&&
>>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>> +
>>>>> 1]&&
>>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>> +
>>>>> 2])
>>>>> +                                       continue;
>>>>> +                               part_size =
>>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>> +
>>>>> 2]
>>>>> +<<    16) +
>>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>> +
>>>>> 1]
>>>>> +<<    8) +
>>>>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>>>>> +                               part_size *= (size_t)(hc_erase_grp_sz *
>>>>> +                                       hc_wp_grp_sz);
>>>>> +                               mmc_part_add(card, part_size<<    19,
>>>>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 +
>>>>> idx,
>>>>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>>>>> @@ -64,7 +65,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 */
>>>>> @@ -158,6 +158,23 @@ 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
>>>>> +#define MMC_NUM_PHY_PARTITION  6
>>>>> +
>>>>> +/*
>>>>> + * MMC Physical partitions
>>>>> + */
>>>>> +struct mmc_part {
>>>>> +       unsigned int    size;   /* partition size (in bytes) */
>>>>> +       unsigned int    part_cfg;       /* it used to part_type */
>>>>> +       char    name[DISK_NAME_LEN];
>>>>> +       bool    force_ro;       /* to make boot parts RO by default */
>>>>> +};
>>>>> +
>>>>>  /*
>>>>>   * MMC device
>>>>>   */
>>>>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool
>>>>> ro)
>>>>> +{
>>>>> +       card->part[card->nr_parts].size = size;
>>>>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>>>>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>>>>> +       card->part[card->nr_parts].force_ro = ro;
>>>>> +       card->nr_parts++;
>>>>> +}
>>>>> +
>>>>> +/*
>>>>>   *  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.
>>>>>   */
>>>>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>>>>> index 50af227..ea558eb 100644
>>>>> --- a/include/linux/mmc/mmc.h
>>>>> +++ b/include/linux/mmc/mmc.h
>>>>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>>>>   * EXT_CSD fields
>>>>>   */
>>>>>
>>>>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>>>>  #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>>>>  #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>>>>  #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>>>>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>>>>
>>>>>  #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_PART_CONFIG_ACC_GP0    (0x4)
>>>>> +
>>>>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>>>>
>>>>>  #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>>>>  #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>>>>
>>>>
>>
>>
>
ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±þG«éÿŠ{ayº\x1dʇڙë,j\a­¢f£¢·hšïêÿ‘êçz_è®\x03(­éšŽŠÝ¢j"ú\x1a¶^[m§ÿÿ¾\a«þG«éÿ¢¸?™¨è­Ú&£ø§~á¶iO•æ¬z·švØ^\x14\x04\x1a¶^[m§ÿÿÃ\fÿ¶ìÿ¢¸?–I¥

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
@ 2011-10-05 11:22           ` NamJae Jeon
  0 siblings, 0 replies; 16+ messages in thread
From: NamJae Jeon @ 2011-10-05 11:22 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

2011/10/5 NamJae Jeon <linkinjeon@gmail.com>:
> 2011/10/5 Adrian Hunter <adrian.hunter@intel.com>:
>> On 05/10/11 13:21, NamJae Jeon wrote:
>>>
>>> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>>>>
>>>> On 04/10/11 20:45, 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 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@gmail.com>
>>>>> ---
>>>>>  drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>>>>  drivers/mmc/core/mmc.c   |   52
>>>>> ++++++++++++++++++++++++++++++++++++++++++---
>>>>>  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>>>>  include/linux/mmc/mmc.h  |    5 +++-
>>>>>  4 files changed, 105 insertions(+), 20 deletions(-)
>>>>>
>>>>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>>>>> index 782d5f8..fb6f1e9 100644
>>>>> --- a/drivers/mmc/card/block.c
>>>>> +++ b/drivers/mmc/card/block.c
>>>>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>>>>> *card,
>>>>>        return 0;
>>>>>  }
>>>>>
>>>>> +/* MMC Physical partition consist of two boot partitions and
>>>>> + * up to four general purpose partitions.
>>>>> + * For each partitions enabled in EXT_CSD
>>>>> + * The block device will allocated to provide access to the partition.
>>>>> + */
>>>>> +
>>>>>  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&&
>>>>>  mmc_boot_partition_access(card->host)) {
>>>>> -               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 ((idx == 0 || idx == 1)&&
>>>>> +                       !mmc_boot_partition_access(card->host))
>>>>> +                       continue;
>>>>
>>>> Seems a bit fragile.  What if someone decided to put the gp
>>>> partitions before the boot partitions.  What about:
>>>
>>> There are the default two boot partition in mmc spec. I think that
>>> this case can not be happened.
>>> And boot partition size of EXT CSD is read-only.
>>> Can you explain which is case put to gp partitions before the boot
>>> partition ?
>>
>> Relying on the partition order in the partition array is fragile.
>> You cannot predict how someone may want to change it in the future,
>> and that person will not expect that certain positions have certain meaning.
0,1 of Boot partition is fixed if spec is not changed over. but gp
partition is variable in 2,3,4,5,6 of array.
If How someone change code, problem occur ?
>>
>>>
>>>>
>>>>                if (mmc_is_boot_partition(&part[idx])&&
>>>>                    !mmc_boot_partition_access(card->host)
>>>>                        continue;
>>>>
>>>> And:
>>>>
>>>> int mmc_is_boot_partition(struct mmc_part *part)
>>>> {
>>>>        return part->part_cfg>= EXT_CSD_PART_CONFIG_ACC_BOOT0&&
>>>>               part->part_cfg<= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>>>>                                 MMC_NUM_BOOT_PARTITION;
>>>> }
>>>>
>>>>> +               if (card->part[idx].size) {
>>>>> +                       ret = mmc_blk_alloc_part(card, md,
>>>>> +                               card->part[idx].part_cfg,
>>>>> +                               card->part[idx].size>>    9,
>>>>> +                               card->part[idx].force_ro,
>>>>> +                               card->part[idx].name);
>>>>> +                       if (ret)
>>>>> +                               return ret;
>>>>> +               }
>>>>>        }
>>>>>
>>>>>        return ret;
>>>>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>>>>> index c632b1f..2f458a0 100644
>>>>> --- a/drivers/mmc/core/mmc.c
>>>>> +++ b/drivers/mmc/core/mmc.c
>>>>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8
>>>>> **new_ext_csd)
>>>>>   */
>>>>>  static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>>>>  {
>>>>> -       int err = 0;
>>>>> +       int err = 0, idx;
>>>>> +       unsigned int part_size;
>>>>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>>>>
>>>>>        BUG_ON(!card);
>>>>>
>>>>> @@ -340,7 +342,14 @@ 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;
>>>>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>>>>> +                       for (idx = 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);
>>>>> +                       }
>>>>> +               }
>>>>>        }
>>>>>
>>>>>        card->ext_csd.raw_hc_erase_gap_size =
>>>>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card,
>>>>> u8
>>>>> *ext_csd)
>>>>>                card->ext_csd.raw_partition_support =
>>>>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>>>>                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&    0x2)&&
>>>>>                (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&    0x1)) {
>>>>> -                       u8 hc_erase_grp_sz =
>>>>> +                       hc_erase_grp_sz =
>>>>>                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>>> -                       u8 hc_wp_grp_sz =
>>>>> +                       hc_wp_grp_sz =
>>>>>                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>>
>>>>>                        card->ext_csd.enhanced_area_en = 1;
>>>>> @@ -393,6 +402,41 @@ 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;
>>>>>                }
>>>>> +
>>>>> +               /*
>>>>> +                * General purpose partition feature support --
>>>>> +                * If ext_csd have the size of general purpose
>>>>> partitions,
>>>>> +                * set size, part_cfg, partition name in mmc_part.
>>>>> +                */
>>>>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>>>>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>>>>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>>>>> +                               hc_erase_grp_sz =
>>>>> +
>>>>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>>> +                               hc_wp_grp_sz =
>>>>> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>> +
>>>>> +                               card->ext_csd.enhanced_area_en = 1;
>>>>> +                       }
>>>>> +
>>>>> +                       for (idx = 0; idx<    MMC_NUM_GP_PARTITION;
>>>>> idx++) {
>>>>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx
>>>>> *
>>>>> 3]&&
>>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>> +
>>>>> 1]&&
>>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>> +
>>>>> 2])
>>>>> +                                       continue;
>>>>> +                               part_size =
>>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>> +
>>>>> 2]
>>>>> +<<    16) +
>>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>> +
>>>>> 1]
>>>>> +<<    8) +
>>>>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>>>>> +                               part_size *= (size_t)(hc_erase_grp_sz *
>>>>> +                                       hc_wp_grp_sz);
>>>>> +                               mmc_part_add(card, part_size<<    19,
>>>>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 +
>>>>> idx,
>>>>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>>>>> @@ -64,7 +65,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 */
>>>>> @@ -158,6 +158,23 @@ 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
>>>>> +#define MMC_NUM_PHY_PARTITION  6
>>>>> +
>>>>> +/*
>>>>> + * MMC Physical partitions
>>>>> + */
>>>>> +struct mmc_part {
>>>>> +       unsigned int    size;   /* partition size (in bytes) */
>>>>> +       unsigned int    part_cfg;       /* it used to part_type */
>>>>> +       char    name[DISK_NAME_LEN];
>>>>> +       bool    force_ro;       /* to make boot parts RO by default */
>>>>> +};
>>>>> +
>>>>>  /*
>>>>>   * MMC device
>>>>>   */
>>>>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool
>>>>> ro)
>>>>> +{
>>>>> +       card->part[card->nr_parts].size = size;
>>>>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>>>>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>>>>> +       card->part[card->nr_parts].force_ro = ro;
>>>>> +       card->nr_parts++;
>>>>> +}
>>>>> +
>>>>> +/*
>>>>>   *  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.
>>>>>   */
>>>>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>>>>> index 50af227..ea558eb 100644
>>>>> --- a/include/linux/mmc/mmc.h
>>>>> +++ b/include/linux/mmc/mmc.h
>>>>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>>>>   * EXT_CSD fields
>>>>>   */
>>>>>
>>>>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>>>>  #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>>>>  #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>>>>  #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>>>>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>>>>
>>>>>  #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_PART_CONFIG_ACC_GP0    (0x4)
>>>>> +
>>>>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>>>>
>>>>>  #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>>>>  #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>>>>
>>>>
>>
>>
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-05 11:22           ` NamJae Jeon
  (?)
@ 2011-10-05 11:37           ` Adrian Hunter
  2011-10-05 11:49             ` NamJae Jeon
  -1 siblings, 1 reply; 16+ messages in thread
From: Adrian Hunter @ 2011-10-05 11:37 UTC (permalink / raw)
  To: NamJae Jeon
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

On 05/10/11 14:22, NamJae Jeon wrote:
> 2011/10/5 NamJae Jeon<linkinjeon@gmail.com>:
>> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>>> On 05/10/11 13:21, NamJae Jeon wrote:
>>>>
>>>> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>>>>>
>>>>> On 04/10/11 20:45, 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 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@gmail.com>
>>>>>> ---
>>>>>>   drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>>>>>   drivers/mmc/core/mmc.c   |   52
>>>>>> ++++++++++++++++++++++++++++++++++++++++++---
>>>>>>   include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>>>>>   include/linux/mmc/mmc.h  |    5 +++-
>>>>>>   4 files changed, 105 insertions(+), 20 deletions(-)
>>>>>>
>>>>>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>>>>>> index 782d5f8..fb6f1e9 100644
>>>>>> --- a/drivers/mmc/card/block.c
>>>>>> +++ b/drivers/mmc/card/block.c
>>>>>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>>>>>> *card,
>>>>>>         return 0;
>>>>>>   }
>>>>>>
>>>>>> +/* MMC Physical partition consist of two boot partitions and
>>>>>> + * up to four general purpose partitions.
>>>>>> + * For each partitions enabled in EXT_CSD
>>>>>> + * The block device will allocated to provide access to the partition.
>>>>>> + */
>>>>>> +
>>>>>>   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&&
>>>>>>   mmc_boot_partition_access(card->host)) {
>>>>>> -               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 ((idx == 0 || idx == 1)&&
>>>>>> +                       !mmc_boot_partition_access(card->host))
>>>>>> +                       continue;
>>>>>
>>>>> Seems a bit fragile.  What if someone decided to put the gp
>>>>> partitions before the boot partitions.  What about:
>>>>
>>>> There are the default two boot partition in mmc spec. I think that
>>>> this case can not be happened.
>>>> And boot partition size of EXT CSD is read-only.
>>>> Can you explain which is case put to gp partitions before the boot
>>>> partition ?
>>>
>>> Relying on the partition order in the partition array is fragile.
>>> You cannot predict how someone may want to change it in the future,
>>> and that person will not expect that certain positions have certain meaning.
> 0,1 of Boot partition is fixed if spec is not changed over. but gp

No. 0,1 are an accidental result of the order in which ext-csd is
parsed.

> partition is variable in 2,3,4,5,6 of array.
> If How someone change code, problem occur ?

If you move code around in mmc_read_ext_csd() the order can change,
hence it is fragile.

>>>
>>>>
>>>>>
>>>>>                 if (mmc_is_boot_partition(&part[idx])&&
>>>>>                     !mmc_boot_partition_access(card->host)
>>>>>                         continue;
>>>>>
>>>>> And:
>>>>>
>>>>> int mmc_is_boot_partition(struct mmc_part *part)
>>>>> {
>>>>>         return part->part_cfg>= EXT_CSD_PART_CONFIG_ACC_BOOT0&&
>>>>>                part->part_cfg<= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>>>>>                                  MMC_NUM_BOOT_PARTITION;
>>>>> }
>>>>>
>>>>>> +               if (card->part[idx].size) {
>>>>>> +                       ret = mmc_blk_alloc_part(card, md,
>>>>>> +                               card->part[idx].part_cfg,
>>>>>> +                               card->part[idx].size>>      9,
>>>>>> +                               card->part[idx].force_ro,
>>>>>> +                               card->part[idx].name);
>>>>>> +                       if (ret)
>>>>>> +                               return ret;
>>>>>> +               }
>>>>>>         }
>>>>>>
>>>>>>         return ret;
>>>>>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>>>>>> index c632b1f..2f458a0 100644
>>>>>> --- a/drivers/mmc/core/mmc.c
>>>>>> +++ b/drivers/mmc/core/mmc.c
>>>>>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card, u8
>>>>>> **new_ext_csd)
>>>>>>    */
>>>>>>   static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>>>>>   {
>>>>>> -       int err = 0;
>>>>>> +       int err = 0, idx;
>>>>>> +       unsigned int part_size;
>>>>>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>>>>>
>>>>>>         BUG_ON(!card);
>>>>>>
>>>>>> @@ -340,7 +342,14 @@ 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;
>>>>>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>>>>>> +                       for (idx = 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);
>>>>>> +                       }
>>>>>> +               }
>>>>>>         }
>>>>>>
>>>>>>         card->ext_csd.raw_hc_erase_gap_size =
>>>>>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card *card,
>>>>>> u8
>>>>>> *ext_csd)
>>>>>>                 card->ext_csd.raw_partition_support =
>>>>>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>>>>>                 if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&      0x2)&&
>>>>>>                 (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&      0x1)) {
>>>>>> -                       u8 hc_erase_grp_sz =
>>>>>> +                       hc_erase_grp_sz =
>>>>>>                                 ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>>>> -                       u8 hc_wp_grp_sz =
>>>>>> +                       hc_wp_grp_sz =
>>>>>>                                 ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>>>
>>>>>>                         card->ext_csd.enhanced_area_en = 1;
>>>>>> @@ -393,6 +402,41 @@ 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;
>>>>>>                 }
>>>>>> +
>>>>>> +               /*
>>>>>> +                * General purpose partition feature support --
>>>>>> +                * If ext_csd have the size of general purpose
>>>>>> partitions,
>>>>>> +                * set size, part_cfg, partition name in mmc_part.
>>>>>> +                */
>>>>>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>>>>>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>>>>>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>>>>>> +                               hc_erase_grp_sz =
>>>>>> +
>>>>>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>>>> +                               hc_wp_grp_sz =
>>>>>> +                                       ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>>> +
>>>>>> +                               card->ext_csd.enhanced_area_en = 1;
>>>>>> +                       }
>>>>>> +
>>>>>> +                       for (idx = 0; idx<      MMC_NUM_GP_PARTITION;
>>>>>> idx++) {
>>>>>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT + idx
>>>>>> *
>>>>>> 3]&&
>>>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>>> +
>>>>>> 1]&&
>>>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>>> +
>>>>>> 2])
>>>>>> +                                       continue;
>>>>>> +                               part_size =
>>>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>>> +
>>>>>> 2]
>>>>>> +<<      16) +
>>>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3
>>>>>> +
>>>>>> 1]
>>>>>> +<<      8) +
>>>>>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx * 3];
>>>>>> +                               part_size *= (size_t)(hc_erase_grp_sz *
>>>>>> +                                       hc_wp_grp_sz);
>>>>>> +                               mmc_part_add(card, part_size<<      19,
>>>>>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 +
>>>>>> idx,
>>>>>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>>>>>> @@ -64,7 +65,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 */
>>>>>> @@ -158,6 +158,23 @@ 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
>>>>>> +#define MMC_NUM_PHY_PARTITION  6
>>>>>> +
>>>>>> +/*
>>>>>> + * MMC Physical partitions
>>>>>> + */
>>>>>> +struct mmc_part {
>>>>>> +       unsigned int    size;   /* partition size (in bytes) */
>>>>>> +       unsigned int    part_cfg;       /* it used to part_type */
>>>>>> +       char    name[DISK_NAME_LEN];
>>>>>> +       bool    force_ro;       /* to make boot parts RO by default */
>>>>>> +};
>>>>>> +
>>>>>>   /*
>>>>>>    * MMC device
>>>>>>    */
>>>>>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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, bool
>>>>>> ro)
>>>>>> +{
>>>>>> +       card->part[card->nr_parts].size = size;
>>>>>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>>>>>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>>>>>> +       card->part[card->nr_parts].force_ro = ro;
>>>>>> +       card->nr_parts++;
>>>>>> +}
>>>>>> +
>>>>>> +/*
>>>>>>    *  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.
>>>>>>    */
>>>>>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>>>>>> index 50af227..ea558eb 100644
>>>>>> --- a/include/linux/mmc/mmc.h
>>>>>> +++ b/include/linux/mmc/mmc.h
>>>>>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>>>>>    * EXT_CSD fields
>>>>>>    */
>>>>>>
>>>>>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>>>>>   #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>>>>>   #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>>>>>   #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>>>>>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>>>>>
>>>>>>   #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_PART_CONFIG_ACC_GP0    (0x4)
>>>>>> +
>>>>>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>>>>>
>>>>>>   #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>>>>>   #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>>>>>
>>>>>
>>>
>>>
>>


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v10] mmc : general purpose partition support.
  2011-10-05 11:37           ` Adrian Hunter
@ 2011-10-05 11:49             ` NamJae Jeon
  0 siblings, 0 replies; 16+ messages in thread
From: NamJae Jeon @ 2011-10-05 11:49 UTC (permalink / raw)
  To: Adrian Hunter
  Cc: cjb, linux-mmc, linux-kernel, awarkentin, linus.walleij,
	james_p_freyensee, sebras, Ulf.Hansson, stefan.xk.nilsson,
	per.forlin, johan.rudholm

2011/10/5 Adrian Hunter <adrian.hunter@intel.com>:
> On 05/10/11 14:22, NamJae Jeon wrote:
>>
>> 2011/10/5 NamJae Jeon<linkinjeon@gmail.com>:
>>>
>>> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>>>>
>>>> On 05/10/11 13:21, NamJae Jeon wrote:
>>>>>
>>>>> 2011/10/5 Adrian Hunter<adrian.hunter@intel.com>:
>>>>>>
>>>>>> On 04/10/11 20:45, 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 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@gmail.com>
>>>>>>> ---
>>>>>>>  drivers/mmc/card/block.c |   34 +++++++++++++++++------------
>>>>>>>  drivers/mmc/core/mmc.c   |   52
>>>>>>> ++++++++++++++++++++++++++++++++++++++++++---
>>>>>>>  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
>>>>>>>  include/linux/mmc/mmc.h  |    5 +++-
>>>>>>>  4 files changed, 105 insertions(+), 20 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
>>>>>>> index 782d5f8..fb6f1e9 100644
>>>>>>> --- a/drivers/mmc/card/block.c
>>>>>>> +++ b/drivers/mmc/card/block.c
>>>>>>> @@ -1470,26 +1470,32 @@ static int mmc_blk_alloc_part(struct mmc_card
>>>>>>> *card,
>>>>>>>        return 0;
>>>>>>>  }
>>>>>>>
>>>>>>> +/* MMC Physical partition consist of two boot partitions and
>>>>>>> + * up to four general purpose partitions.
>>>>>>> + * For each partitions enabled in EXT_CSD
>>>>>>> + * The block device will allocated to provide access to the
>>>>>>> partition.
>>>>>>> + */
>>>>>>> +
>>>>>>>  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&&
>>>>>>>  mmc_boot_partition_access(card->host)) {
>>>>>>> -               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 ((idx == 0 || idx == 1)&&
>>>>>>> +                       !mmc_boot_partition_access(card->host))
>>>>>>> +                       continue;
>>>>>>
>>>>>> Seems a bit fragile.  What if someone decided to put the gp
>>>>>> partitions before the boot partitions.  What about:
>>>>>
>>>>> There are the default two boot partition in mmc spec. I think that
>>>>> this case can not be happened.
>>>>> And boot partition size of EXT CSD is read-only.
>>>>> Can you explain which is case put to gp partitions before the boot
>>>>> partition ?
>>>>
>>>> Relying on the partition order in the partition array is fragile.
>>>> You cannot predict how someone may want to change it in the future,
>>>> and that person will not expect that certain positions have certain
>>>> meaning.
>>
>> 0,1 of Boot partition is fixed if spec is not changed over. but gp
>
> No. 0,1 are an accidental result of the order in which ext-csd is
> parsed.
>
>> partition is variable in 2,3,4,5,6 of array.
>> If How someone change code, problem occur ?
>
> If you move code around in mmc_read_ext_csd() the order can change,
> hence it is fragile.
As I remember, boot size can be default zero in the mmc device 4.3 of
some chip vendor.
and it should set proper size using vendor cmd. but gp partition is
not support in mmc 4.3.
um.. I will add your suggested code to avoid vendor specific part in MMC 4.4.
Thanks Adrian~

>
>>>>
>>>>>
>>>>>>
>>>>>>                if (mmc_is_boot_partition(&part[idx])&&
>>>>>>                    !mmc_boot_partition_access(card->host)
>>>>>>                        continue;
>>>>>>
>>>>>> And:
>>>>>>
>>>>>> int mmc_is_boot_partition(struct mmc_part *part)
>>>>>> {
>>>>>>        return part->part_cfg>= EXT_CSD_PART_CONFIG_ACC_BOOT0&&
>>>>>>               part->part_cfg<= EXT_CSD_PART_CONFIG_ACC_BOOT0 +
>>>>>>                                 MMC_NUM_BOOT_PARTITION;
>>>>>> }
>>>>>>
>>>>>>> +               if (card->part[idx].size) {
>>>>>>> +                       ret = mmc_blk_alloc_part(card, md,
>>>>>>> +                               card->part[idx].part_cfg,
>>>>>>> +                               card->part[idx].size>>      9,
>>>>>>> +                               card->part[idx].force_ro,
>>>>>>> +                               card->part[idx].name);
>>>>>>> +                       if (ret)
>>>>>>> +                               return ret;
>>>>>>> +               }
>>>>>>>        }
>>>>>>>
>>>>>>>        return ret;
>>>>>>> diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c
>>>>>>> index c632b1f..2f458a0 100644
>>>>>>> --- a/drivers/mmc/core/mmc.c
>>>>>>> +++ b/drivers/mmc/core/mmc.c
>>>>>>> @@ -239,7 +239,9 @@ static int mmc_get_ext_csd(struct mmc_card *card,
>>>>>>> u8
>>>>>>> **new_ext_csd)
>>>>>>>   */
>>>>>>>  static int mmc_read_ext_csd(struct mmc_card *card, u8 *ext_csd)
>>>>>>>  {
>>>>>>> -       int err = 0;
>>>>>>> +       int err = 0, idx;
>>>>>>> +       unsigned int part_size;
>>>>>>> +       u8 hc_erase_grp_sz = 0, hc_wp_grp_sz = 0;
>>>>>>>
>>>>>>>        BUG_ON(!card);
>>>>>>>
>>>>>>> @@ -340,7 +342,14 @@ 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;
>>>>>>> +               if (ext_csd[EXT_CSD_BOOT_MULT]) {
>>>>>>> +                       for (idx = 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);
>>>>>>> +                       }
>>>>>>> +               }
>>>>>>>        }
>>>>>>>
>>>>>>>        card->ext_csd.raw_hc_erase_gap_size =
>>>>>>> @@ -362,9 +371,9 @@ static int mmc_read_ext_csd(struct mmc_card
>>>>>>> *card,
>>>>>>> u8
>>>>>>> *ext_csd)
>>>>>>>                card->ext_csd.raw_partition_support =
>>>>>>> ext_csd[EXT_CSD_PARTITION_SUPPORT];
>>>>>>>                if ((ext_csd[EXT_CSD_PARTITION_SUPPORT]&      0x2)&&
>>>>>>>                (ext_csd[EXT_CSD_PARTITION_ATTRIBUTE]&      0x1)) {
>>>>>>> -                       u8 hc_erase_grp_sz =
>>>>>>> +                       hc_erase_grp_sz =
>>>>>>>                                ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>>>>> -                       u8 hc_wp_grp_sz =
>>>>>>> +                       hc_wp_grp_sz =
>>>>>>>                                ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>>>>
>>>>>>>                        card->ext_csd.enhanced_area_en = 1;
>>>>>>> @@ -393,6 +402,41 @@ 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;
>>>>>>>                }
>>>>>>> +
>>>>>>> +               /*
>>>>>>> +                * General purpose partition feature support --
>>>>>>> +                * If ext_csd have the size of general purpose
>>>>>>> partitions,
>>>>>>> +                * set size, part_cfg, partition name in mmc_part.
>>>>>>> +                */
>>>>>>> +               if (ext_csd[EXT_CSD_PARTITION_SUPPORT]&
>>>>>>> +                       EXT_CSD_PART_SUPPORT_PART_EN) {
>>>>>>> +                       if (card->ext_csd.enhanced_area_en != 1) {
>>>>>>> +                               hc_erase_grp_sz =
>>>>>>> +
>>>>>>> ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
>>>>>>> +                               hc_wp_grp_sz =
>>>>>>> +
>>>>>>> ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
>>>>>>> +
>>>>>>> +                               card->ext_csd.enhanced_area_en = 1;
>>>>>>> +                       }
>>>>>>> +
>>>>>>> +                       for (idx = 0; idx<      MMC_NUM_GP_PARTITION;
>>>>>>> idx++) {
>>>>>>> +                               if (!ext_csd[EXT_CSD_GP_SIZE_MULT +
>>>>>>> idx
>>>>>>> *
>>>>>>> 3]&&
>>>>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx *
>>>>>>> 3
>>>>>>> +
>>>>>>> 1]&&
>>>>>>> +                               !ext_csd[EXT_CSD_GP_SIZE_MULT + idx *
>>>>>>> 3
>>>>>>> +
>>>>>>> 2])
>>>>>>> +                                       continue;
>>>>>>> +                               part_size =
>>>>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx *
>>>>>>> 3
>>>>>>> +
>>>>>>> 2]
>>>>>>> +<<      16) +
>>>>>>> +                               (ext_csd[EXT_CSD_GP_SIZE_MULT + idx *
>>>>>>> 3
>>>>>>> +
>>>>>>> 1]
>>>>>>> +<<      8) +
>>>>>>> +                               ext_csd[EXT_CSD_GP_SIZE_MULT + idx *
>>>>>>> 3];
>>>>>>> +                               part_size *= (size_t)(hc_erase_grp_sz
>>>>>>> *
>>>>>>> +                                       hc_wp_grp_sz);
>>>>>>> +                               mmc_part_add(card, part_size<<
>>>>>>>  19,
>>>>>>> +                                       EXT_CSD_PART_CONFIG_ACC_GP0 +
>>>>>>> idx,
>>>>>>> +                                       "gp%d", idx, 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 5294ddf..0522627 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;
>>>>>>> @@ -64,7 +65,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 */
>>>>>>> @@ -158,6 +158,23 @@ 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
>>>>>>> +#define MMC_NUM_PHY_PARTITION  6
>>>>>>> +
>>>>>>> +/*
>>>>>>> + * MMC Physical partitions
>>>>>>> + */
>>>>>>> +struct mmc_part {
>>>>>>> +       unsigned int    size;   /* partition size (in bytes) */
>>>>>>> +       unsigned int    part_cfg;       /* it used to part_type */
>>>>>>> +       char    name[DISK_NAME_LEN];
>>>>>>> +       bool    force_ro;       /* to make boot parts RO by default
>>>>>>> */
>>>>>>> +};
>>>>>>> +
>>>>>>>  /*
>>>>>>>   * MMC device
>>>>>>>   */
>>>>>>> @@ -219,9 +236,24 @@ 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_PHY_PARTITION]; /* 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,
>>>>>>> bool
>>>>>>> ro)
>>>>>>> +{
>>>>>>> +       card->part[card->nr_parts].size = size;
>>>>>>> +       card->part[card->nr_parts].part_cfg = part_cfg;
>>>>>>> +       sprintf(card->part[card->nr_parts].name, name, idx);
>>>>>>> +       card->part[card->nr_parts].force_ro = ro;
>>>>>>> +       card->nr_parts++;
>>>>>>> +}
>>>>>>> +
>>>>>>> +/*
>>>>>>>   *  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.
>>>>>>>   */
>>>>>>> diff --git a/include/linux/mmc/mmc.h b/include/linux/mmc/mmc.h
>>>>>>> index 50af227..ea558eb 100644
>>>>>>> --- a/include/linux/mmc/mmc.h
>>>>>>> +++ b/include/linux/mmc/mmc.h
>>>>>>> @@ -270,6 +270,7 @@ struct _mmc_csd {
>>>>>>>   * EXT_CSD fields
>>>>>>>   */
>>>>>>>
>>>>>>> +#define EXT_CSD_GP_SIZE_MULT           143     /* R/W */
>>>>>>>  #define EXT_CSD_PARTITION_ATTRIBUTE   156     /* R/W */
>>>>>>>  #define EXT_CSD_PARTITION_SUPPORT     160     /* RO */
>>>>>>>  #define EXT_CSD_RST_N_FUNCTION                162     /* R/W */
>>>>>>> @@ -313,7 +314,9 @@ struct _mmc_csd {
>>>>>>>
>>>>>>>  #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_PART_CONFIG_ACC_GP0    (0x4)
>>>>>>> +
>>>>>>> +#define EXT_CSD_PART_SUPPORT_PART_EN   (0x1)
>>>>>>>
>>>>>>>  #define EXT_CSD_CMD_SET_NORMAL                (1<<0)
>>>>>>>  #define EXT_CSD_CMD_SET_SECURE                (1<<1)
>>>>>>
>>>>>>
>>>>
>>>>
>>>
>
>

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2011-10-05 11:49 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-10-04 17:45 [PATCH v10] mmc : general purpose partition support Namjae Jeon
2011-10-04 18:19 ` S, Venkatraman
2011-10-04 18:25   ` Chris Ball
2011-10-04 18:25     ` Chris Ball
2011-10-04 18:27     ` S, Venkatraman
2011-10-04 20:20 ` Andrei Warkentin
2011-10-05  9:12 ` Adrian Hunter
2011-10-05 10:21   ` NamJae Jeon
2011-10-05 10:21     ` NamJae Jeon
2011-10-05 10:53     ` Adrian Hunter
2011-10-05 11:21       ` NamJae Jeon
2011-10-05 11:21         ` NamJae Jeon
2011-10-05 11:22         ` NamJae Jeon
2011-10-05 11:22           ` NamJae Jeon
2011-10-05 11:37           ` Adrian Hunter
2011-10-05 11:49             ` NamJae Jeon

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.