Skip to contentSkip to conversation

mmc : general purpose partition support.

PATCH Superseded Namjae Jeon 4 participants 5 messages Oct 5, 2011 – Oct 6, 2011 MMC, SD and SDIO

v11 of 12 Superseded Latest is v12 →

lore
Share & tools
lore
#0 lore raw

PATCH v11 1/1 mmc : general purpose partition support.

It allows gerneral purpose partitions in MMC Device.
And I try to simpliy make mmc_blk_alloc_parts using mmc_part structure suggested by Andrei Warkentin. After patching, we can see general purpose partitions like this.

Quoted 1 line

cat /proc/partitions

          179 0 847872 mmcblk0
          179 192 4096 mmcblk0gp3
          179 160 4096 mmcblk0gp2
          179 128 4096 mmcblk0gp1
          179 96  1052672 mmcblk0gp0
          179 64  1024 mmcblk0boot1
          179 32  1024 mmcblk0boot0
---
 drivers/mmc/card/block.c |   41 +++++++++++++++++++++++------------
 drivers/mmc/core/mmc.c   |   52 ++++++++++++++++++++++++++++++++++++++++++---
 include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
 include/linux/mmc/mmc.h  |    5 +++-
 4 files changed, 112 insertions(+), 20 deletions(-)
drivers/mmc/card/block.c +27 -14
index 782d5f8..6091f13 100644
@@ -1470,26 +1470,39 @@ static int mmc_blk_alloc_part(struct mmc_card *card,
 	return 0;
 }
 
+static 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));
+}
+
+/* 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 (mmc_is_boot_partition(&card->part[idx]) &&
+			!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;
drivers/mmc/core/mmc.c +48 -4

77 lines not on this page · raw message

include/linux/mmc/card.h +33 -1
index 5294ddf..0522627 100644
@@ -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.
  */
include/linux/mmc/mmc.h +4 -1
index 50af227..ea558eb 100644
@@ -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)
Signature · 1 line
1.7.4.4
#1 lore raw

Hi,

----- Original Message -----

Quoted 36 lines

From: "Namjae Jeon" <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], "adrian hunter" <[email protected]>, "linus walleij" <[email protected]>, "james p freyensee" <[email protected]>, [email protected], "Ulf Hansson" <[email protected]>, "stefan xk nilsson" <[email protected]>, "per forlin" <[email protected]>, "johan rudholm" <[email protected]>, "Namjae Jeon" <[email protected]>
Sent: Wednesday, October 5, 2011 10:45:45 AM
Subject: [PATCH v11] mmc : general purpose partition support.

It allows gerneral purpose partitions in MMC Device. And I try to simpliy make mmc_blk_alloc_parts using mmc_part structure suggested by Andrei Warkentin.
After patching, we can see general purpose partitions like this.

Quoted 1 line

cat /proc/partitions

          179 0 847872 mmcblk0
          179 192 4096 mmcblk0gp3
          179 160 4096 mmcblk0gp2
          179 128 4096 mmcblk0gp1
          179 96  1052672 mmcblk0gp0
          179 64  1024 mmcblk0boot1
          179 32  1024 mmcblk0boot0
---
 drivers/mmc/card/block.c |   41 +++++++++++++++++++++++------------
 drivers/mmc/core/mmc.c   |   52
 ++++++++++++++++++++++++++++++++++++++++++---
 include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
 include/linux/mmc/mmc.h  |    5 +++-
 4 files changed, 112 insertions(+), 20 deletions(-)
drivers/mmc/card/block.c +4 -0
+	for (idx = 0; idx < card->nr_parts; idx++) {
+		if (mmc_is_boot_partition(&card->part[idx]) &&
+			!mmc_boot_partition_access(card->host))
+			continue;

drivers/mmc/card/block.c static int mmc_blk_alloc_part(struct mmc_card *card, · line 1506

Quoted 10 lines
drivers/mmc/card/block.c +9 -0
+		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;
+		}
 	}

Is there any reason for putting the mmc_boot_partition_access() logic here? If boot partitions are not allowed by host, then just don't add the mmc_parts to the parts array, no? Such minutae should belong in core mmc code, not block driver, IMHO.

A

#2 lore raw

2011/10/6 Andrei Warkentin <[email protected]>:

Quoted 45 lines

Hi,

----- Original Message -----

Quoted 42 lines

From: "Namjae Jeon" <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], "adrian hunter" <[email protected]>, "linus walleij" <[email protected]>, "james p freyensee" <[email protected]>, [email protected], "Ulf Hansson" <[email protected]>, "stefan xk nilsson" <[email protected]>, "per forlin" <[email protected]>, "johan rudholm" <[email protected]>, "Namjae Jeon" <[email protected]>
Sent: Wednesday, October 5, 2011 10:45:45 AM
Subject: [PATCH v11] mmc : general purpose partition support.

It allows gerneral purpose partitions in MMC Device. And I try to simpliy make mmc_blk_alloc_parts using mmc_part structure suggested by Andrei Warkentin.
After patching, we can see general purpose partitions like this.

Quoted 1 line

cat /proc/partitions

          179 0 847872 mmcblk0
          179 192 4096 mmcblk0gp3
          179 160 4096 mmcblk0gp2
          179 128 4096 mmcblk0gp1
          179 96  1052672 mmcblk0gp0
          179 64  1024 mmcblk0boot1
          179 32  1024 mmcblk0boot0

---
 drivers/mmc/card/block.c |   41 +++++++++++++++++++++++------------ drivers/mmc/core/mmc.c   |   52
 ++++++++++++++++++++++++++++++++++++++++++---
 include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++- include/linux/mmc/mmc.h  |    5 +++-

 4 files changed, 112 insertions(+), 20 deletions(-)
drivers/mmc/card/block.c +10 -0
+     for (idx = 0; idx < card->nr_parts; idx++) {
+             if (mmc_is_boot_partition(&card->part[idx]) &&
+                     !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);
Quoted 8 lines
Quoted 4 lines

+                     if (ret)
+                             return ret;
+             }
      }

Is there any reason for putting the mmc_boot_partition_access() logic here? If boot partitions are not allowed by host, then just don't add the mmc_parts to the parts array, no? Such minutae should belong in core mmc code, not block driver, IMHO.

Hi.

How about changing patch like this ?

if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) {
                        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);
                        }
                }

I want to hear the opinion from andrei and
adrian(mmc_boot_partition_access patch's author)
Thanks.

Quoted 3 lines

A

#3 lore raw

HI NamJae,

2011/10/5 NamJae Jeon <[email protected]>:

Quoted 12 lines

How about changing patch like this ?

if (ext_csd[EXT_CSD_BOOT_MULT] && mmc_boot_partition_access(card->host)) { 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);
                       }
               }

Quoted 3 lines

I want to hear the opinion from andrei and
adrian(mmc_boot_partition_access patch's author)
Thanks.

I like this.

A

#4 lore raw
In reply to Andrei Warkentin
Quoted 45 lines · Andrei Warkentin

Hi,

----- Original Message -----

Quoted 42 lines

From: "Namjae Jeon"<[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected], "adrian hunter"<[email protected]>, "linus walleij" <[email protected]>, "james p freyensee"<[email protected]>, [email protected], "Ulf Hansson" <[email protected]>, "stefan xk nilsson"<[email protected]>, "per forlin" <[email protected]>, "johan rudholm"<[email protected]>, "Namjae Jeon"<[email protected]>
Sent: Wednesday, October 5, 2011 10:45:45 AM
Subject: [PATCH v11] mmc : general purpose partition support.

It allows gerneral purpose partitions in MMC Device. And I try to simpliy make mmc_blk_alloc_parts using mmc_part structure suggested by Andrei Warkentin.
After patching, we can see general purpose partitions like this.

Quoted 1 line

cat /proc/partitions

           179 0 847872 mmcblk0
           179 192 4096 mmcblk0gp3
           179 160 4096 mmcblk0gp2
           179 128 4096 mmcblk0gp1
           179 96  1052672 mmcblk0gp0
           179 64  1024 mmcblk0boot1
           179 32  1024 mmcblk0boot0
---
  drivers/mmc/card/block.c |   41 +++++++++++++++++++++++------------
  drivers/mmc/core/mmc.c   |   52
  ++++++++++++++++++++++++++++++++++++++++++---
  include/linux/mmc/card.h |   34 +++++++++++++++++++++++++++++-
  include/linux/mmc/mmc.h  |    5 +++-
  4 files changed, 112 insertions(+), 20 deletions(-)
drivers/mmc/card/block.c +10 -0
+	for (idx = 0; idx<  card->nr_parts; idx++) {
+		if (mmc_is_boot_partition(&card->part[idx])&&
+			!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);
Quoted 8 lines

drivers/mmc/card/block.c static int mmc_blk_alloc_part(struct mmc_card *card, · line 1506

Quoted 4 lines
drivers/mmc/card/block.c +3 -0
+			if (ret)
+				return ret;
+		}
  	}

Is there any reason for putting the mmc_boot_partition_access() logic here? If boot partitions are not allowed by host, then just don't add the mmc_parts to the parts array, no? Such minutae should belong in core mmc code, not block driver, IMHO.

I like data structures to model reality i.e. the partitions exist but are not accessible. However I am not fussed - change it or not.

Quoted 3 lines

A