mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-06 05:13:18 +00:00
mmc: core: Add wp_grp_size sysfs node
The eMMC card can be set into write-protected mode to prevent data from being accidentally modified or deleted. Wp_grp_size (Write Protect Group Size) refers to an attribute of the eMMC card, used to manage write protection and is the CSD register [36:32] of the eMMC device. Wp_grp_size (Write Protect Group Size) indicates how many eMMC blocks are contained in each write protection group on the eMMC card. To allow userspace easy access of the CSD register bits, let's add sysfs node "wp_grp_size". Signed-off-by: Lin Gui <lin.gui@mediatek.com> Signed-off-by: Bo Ye <bo.ye@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://lore.kernel.org/r/20231218230532.82427-1-bo.ye@mediatek.com Signed-off-by: Ulf Hansson <ulf.hansson@linaro.org>
This commit is contained in:
parent
b062136d0d
commit
e4df56ad0b
@ -136,6 +136,17 @@ static void mmc_set_erase_size(struct mmc_card *card)
|
||||
mmc_init_erase(card);
|
||||
}
|
||||
|
||||
|
||||
static void mmc_set_wp_grp_size(struct mmc_card *card)
|
||||
{
|
||||
if (card->ext_csd.erase_group_def & 1)
|
||||
card->wp_grp_size = card->ext_csd.hc_erase_size *
|
||||
card->ext_csd.raw_hc_erase_gap_size;
|
||||
else
|
||||
card->wp_grp_size = card->csd.erase_size *
|
||||
(card->csd.wp_grp_size + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a 128-bit response, decode to our card CSD structure.
|
||||
*/
|
||||
@ -186,6 +197,7 @@ static int mmc_decode_csd(struct mmc_card *card)
|
||||
b = UNSTUFF_BITS(resp, 37, 5);
|
||||
csd->erase_size = (a + 1) * (b + 1);
|
||||
csd->erase_size <<= csd->write_blkbits - 9;
|
||||
csd->wp_grp_size = UNSTUFF_BITS(resp, 32, 5);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -785,6 +797,7 @@ MMC_DEV_ATTR(csd, "%08x%08x%08x%08x\n", card->raw_csd[0], card->raw_csd[1],
|
||||
MMC_DEV_ATTR(date, "%02d/%04d\n", card->cid.month, card->cid.year);
|
||||
MMC_DEV_ATTR(erase_size, "%u\n", card->erase_size << 9);
|
||||
MMC_DEV_ATTR(preferred_erase_size, "%u\n", card->pref_erase << 9);
|
||||
MMC_DEV_ATTR(wp_grp_size, "%u\n", card->wp_grp_size << 9);
|
||||
MMC_DEV_ATTR(ffu_capable, "%d\n", card->ext_csd.ffu_capable);
|
||||
MMC_DEV_ATTR(hwrev, "0x%x\n", card->cid.hwrev);
|
||||
MMC_DEV_ATTR(manfid, "0x%06x\n", card->cid.manfid);
|
||||
@ -845,6 +858,7 @@ static struct attribute *mmc_std_attrs[] = {
|
||||
&dev_attr_date.attr,
|
||||
&dev_attr_erase_size.attr,
|
||||
&dev_attr_preferred_erase_size.attr,
|
||||
&dev_attr_wp_grp_size.attr,
|
||||
&dev_attr_fwrev.attr,
|
||||
&dev_attr_ffu_capable.attr,
|
||||
&dev_attr_hwrev.attr,
|
||||
@ -1759,7 +1773,7 @@ static int mmc_init_card(struct mmc_host *host, u32 ocr,
|
||||
mmc_set_erase_size(card);
|
||||
}
|
||||
}
|
||||
|
||||
mmc_set_wp_grp_size(card);
|
||||
/*
|
||||
* Ensure eMMC user default partition is enabled
|
||||
*/
|
||||
|
@ -32,6 +32,7 @@ struct mmc_csd {
|
||||
unsigned int r2w_factor;
|
||||
unsigned int max_dtr;
|
||||
unsigned int erase_size; /* In sectors */
|
||||
unsigned int wp_grp_size;
|
||||
unsigned int read_blkbits;
|
||||
unsigned int write_blkbits;
|
||||
unsigned int capacity;
|
||||
@ -303,6 +304,7 @@ struct mmc_card {
|
||||
unsigned int eg_boundary; /* don't cross erase-group boundaries */
|
||||
unsigned int erase_arg; /* erase / trim / discard */
|
||||
u8 erased_byte; /* value of erased bytes */
|
||||
unsigned int wp_grp_size; /* write group size in sectors */
|
||||
|
||||
u32 raw_cid[4]; /* raw card CID */
|
||||
u32 raw_csd[4]; /* raw card CSD */
|
||||
|
Loading…
Reference in New Issue
Block a user